blob: d697fcb35d521e3757ff8632c709a2c3bb448523 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: tbconvrt - ACPI Table conversion utilities
4 *
5 *****************************************************************************/
6
7/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/actables.h>
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define _COMPONENT ACPI_TABLES
Len Brown4be44fc2005-08-05 00:44:28 -040048ACPI_MODULE_NAME("tbconvrt")
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Robert Moore44f6c012005-04-18 22:49:35 -040050/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040051static void
52acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct,
53 u8 register_bit_width,
54 acpi_physical_address address);
Robert Moore44f6c012005-04-18 22:49:35 -040055
56static void
Bob Moore793c2382006-03-31 00:00:00 -050057acpi_tb_convert_fadt1(struct fadt_descriptor *local_fadt,
Len Brown4be44fc2005-08-05 00:44:28 -040058 struct fadt_descriptor_rev1 *original_fadt);
Robert Moore44f6c012005-04-18 22:49:35 -040059
60static void
Bob Moore793c2382006-03-31 00:00:00 -050061acpi_tb_convert_fadt2(struct fadt_descriptor *local_fadt,
62 struct fadt_descriptor *original_fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64u8 acpi_fadt_is_v1;
Bob Moore83135242006-10-03 00:00:00 -040065ACPI_EXPORT_SYMBOL(acpi_fadt_is_v1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67/*******************************************************************************
68 *
69 * FUNCTION: acpi_tb_get_table_count
70 *
71 * PARAMETERS: RSDP - Pointer to the RSDP
72 * RSDT - Pointer to the RSDT/XSDT
73 *
74 * RETURN: The number of tables pointed to by the RSDT or XSDT.
75 *
76 * DESCRIPTION: Calculate the number of tables. Automatically handles either
77 * an RSDT or XSDT.
78 *
79 ******************************************************************************/
80
81u32
Len Brown4be44fc2005-08-05 00:44:28 -040082acpi_tb_get_table_count(struct rsdp_descriptor *RSDP,
83 struct acpi_table_header *RSDT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Len Brown4be44fc2005-08-05 00:44:28 -040085 u32 pointer_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Len Brown4be44fc2005-08-05 00:44:28 -040087 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Robert Moore73459f72005-06-24 00:00:00 -040089 /* RSDT pointers are 32 bits, XSDT pointers are 64 bits */
90
91 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
Len Brown4be44fc2005-08-05 00:44:28 -040092 pointer_size = sizeof(u32);
93 } else {
94 pointer_size = sizeof(u64);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 }
96
97 /*
98 * Determine the number of tables pointed to by the RSDT/XSDT.
99 * This is defined by the ACPI Specification to be the number of
100 * pointers contained within the RSDT/XSDT. The size of the pointers
101 * is architecture-dependent.
102 */
Len Brown4be44fc2005-08-05 00:44:28 -0400103 return ((RSDT->length -
104 sizeof(struct acpi_table_header)) / pointer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107/*******************************************************************************
108 *
109 * FUNCTION: acpi_tb_convert_to_xsdt
110 *
111 * PARAMETERS: table_info - Info about the RSDT
112 *
113 * RETURN: Status
114 *
115 * DESCRIPTION: Convert an RSDT to an XSDT (internal common format)
116 *
117 ******************************************************************************/
118
Len Brown4be44fc2005-08-05 00:44:28 -0400119acpi_status acpi_tb_convert_to_xsdt(struct acpi_table_desc *table_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120{
Len Brown4be44fc2005-08-05 00:44:28 -0400121 acpi_size table_size;
122 u32 i;
Bob Moore793c2382006-03-31 00:00:00 -0500123 struct xsdt_descriptor *new_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Len Brown4be44fc2005-08-05 00:44:28 -0400125 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127 /* Compute size of the converted XSDT */
128
Len Brown4be44fc2005-08-05 00:44:28 -0400129 table_size = ((acpi_size) acpi_gbl_rsdt_table_count * sizeof(u64)) +
130 sizeof(struct acpi_table_header);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 /* Allocate an XSDT */
133
Bob Moore83135242006-10-03 00:00:00 -0400134 new_table = ACPI_ALLOCATE_ZEROED(table_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 if (!new_table) {
136 return (AE_NO_MEMORY);
137 }
138
139 /* Copy the header and set the length */
140
Len Brown4be44fc2005-08-05 00:44:28 -0400141 ACPI_MEMCPY(new_table, table_info->pointer,
142 sizeof(struct acpi_table_header));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 new_table->length = (u32) table_size;
144
145 /* Copy the table pointers */
146
147 for (i = 0; i < acpi_gbl_rsdt_table_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400148
Robert Moore73459f72005-06-24 00:00:00 -0400149 /* RSDT pointers are 32 bits, XSDT pointers are 64 bits */
150
151 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
Len Brown4be44fc2005-08-05 00:44:28 -0400152 ACPI_STORE_ADDRESS(new_table->table_offset_entry[i],
153 (ACPI_CAST_PTR
Bob Moore793c2382006-03-31 00:00:00 -0500154 (struct rsdt_descriptor,
Len Brown4be44fc2005-08-05 00:44:28 -0400155 table_info->pointer))->
156 table_offset_entry[i]);
157 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 new_table->table_offset_entry[i] =
Bob Moore793c2382006-03-31 00:00:00 -0500159 (ACPI_CAST_PTR(struct xsdt_descriptor,
Len Brown4be44fc2005-08-05 00:44:28 -0400160 table_info->pointer))->
161 table_offset_entry[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 }
163 }
164
165 /* Delete the original table (either mapped or in a buffer) */
166
Len Brown4be44fc2005-08-05 00:44:28 -0400167 acpi_tb_delete_single_table(table_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 /* Point the table descriptor to the new table */
170
Len Brown4be44fc2005-08-05 00:44:28 -0400171 table_info->pointer =
172 ACPI_CAST_PTR(struct acpi_table_header, new_table);
173 table_info->length = table_size;
174 table_info->allocation = ACPI_MEM_ALLOCATED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176 return (AE_OK);
177}
178
Robert Moore44f6c012005-04-18 22:49:35 -0400179/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 *
181 * FUNCTION: acpi_tb_init_generic_address
182 *
183 * PARAMETERS: new_gas_struct - GAS struct to be initialized
184 * register_bit_width - Width of this register
185 * Address - Address of the register
186 *
187 * RETURN: None
188 *
189 * DESCRIPTION: Initialize a GAS structure.
190 *
191 ******************************************************************************/
192
193static void
Len Brown4be44fc2005-08-05 00:44:28 -0400194acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct,
195 u8 register_bit_width,
196 acpi_physical_address address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
198
Len Brown4be44fc2005-08-05 00:44:28 -0400199 ACPI_STORE_ADDRESS(new_gas_struct->address, address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 new_gas_struct->address_space_id = ACPI_ADR_SPACE_SYSTEM_IO;
202 new_gas_struct->register_bit_width = register_bit_width;
203 new_gas_struct->register_bit_offset = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400204 new_gas_struct->access_width = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207/*******************************************************************************
208 *
209 * FUNCTION: acpi_tb_convert_fadt1
210 *
211 * PARAMETERS: local_fadt - Pointer to new FADT
212 * original_fadt - Pointer to old FADT
213 *
Robert Moore44f6c012005-04-18 22:49:35 -0400214 * RETURN: None, populates local_fadt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 *
216 * DESCRIPTION: Convert an ACPI 1.0 FADT to common internal format
217 *
218 ******************************************************************************/
219
220static void
Bob Moore793c2382006-03-31 00:00:00 -0500221acpi_tb_convert_fadt1(struct fadt_descriptor *local_fadt,
Len Brown4be44fc2005-08-05 00:44:28 -0400222 struct fadt_descriptor_rev1 *original_fadt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 /* ACPI 1.0 FACS */
226 /* The BIOS stored FADT should agree with Revision 1.0 */
227 acpi_fadt_is_v1 = 1;
228
229 /*
230 * Copy the table header and the common part of the tables.
231 *
232 * The 2.0 table is an extension of the 1.0 table, so the entire 1.0
233 * table can be copied first, then expand some fields to 64 bits.
234 */
Len Brown4be44fc2005-08-05 00:44:28 -0400235 ACPI_MEMCPY(local_fadt, original_fadt,
236 sizeof(struct fadt_descriptor_rev1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238 /* Convert table pointers to 64-bit fields */
239
Len Brown4be44fc2005-08-05 00:44:28 -0400240 ACPI_STORE_ADDRESS(local_fadt->xfirmware_ctrl,
241 local_fadt->V1_firmware_ctrl);
242 ACPI_STORE_ADDRESS(local_fadt->Xdsdt, local_fadt->V1_dsdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400245 * System Interrupt Model isn't used in ACPI 2.0
246 * (local_fadt->Reserved1 = 0;)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 */
248
249 /*
250 * This field is set by the OEM to convey the preferred power management
251 * profile to OSPM. It doesn't have any 1.0 equivalence. Since we don't
252 * know what kind of 32-bit system this is, we will use "unspecified".
253 */
254 local_fadt->prefer_PM_profile = PM_UNSPECIFIED;
255
256 /*
257 * Processor Performance State Control. This is the value OSPM writes to
258 * the SMI_CMD register to assume processor performance state control
259 * responsibility. There isn't any equivalence in 1.0, but as many 1.x
260 * ACPI tables contain _PCT and _PSS we also keep this value, unless
261 * acpi_strict is set.
262 */
263 if (acpi_strict)
264 local_fadt->pstate_cnt = 0;
265
266 /*
267 * Support for the _CST object and C States change notification.
268 * This data item hasn't any 1.0 equivalence so leave it zero.
269 */
270 local_fadt->cst_cnt = 0;
271
272 /*
273 * FADT Rev 2 was an interim FADT released between ACPI 1.0 and ACPI 2.0.
274 * It primarily adds the FADT reset mechanism.
275 */
276 if ((original_fadt->revision == 2) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400277 (original_fadt->length ==
278 sizeof(struct fadt_descriptor_rev2_minus))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 /*
280 * Grab the entire generic address struct, plus the 1-byte reset value
281 * that immediately follows.
282 */
Len Brown4be44fc2005-08-05 00:44:28 -0400283 ACPI_MEMCPY(&local_fadt->reset_register,
284 &(ACPI_CAST_PTR(struct fadt_descriptor_rev2_minus,
285 original_fadt))->reset_register,
286 sizeof(struct acpi_generic_address) + 1);
287 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 /*
289 * Since there isn't any equivalence in 1.0 and since it is highly
290 * likely that a 1.0 system has legacy support.
291 */
292 local_fadt->iapc_boot_arch = BAF_LEGACY_DEVICES;
293 }
294
295 /*
296 * Convert the V1.0 block addresses to V2.0 GAS structures
297 */
Len Brown4be44fc2005-08-05 00:44:28 -0400298 acpi_tb_init_generic_address(&local_fadt->xpm1a_evt_blk,
299 local_fadt->pm1_evt_len,
300 (acpi_physical_address) local_fadt->
301 V1_pm1a_evt_blk);
302 acpi_tb_init_generic_address(&local_fadt->xpm1b_evt_blk,
303 local_fadt->pm1_evt_len,
304 (acpi_physical_address) local_fadt->
305 V1_pm1b_evt_blk);
306 acpi_tb_init_generic_address(&local_fadt->xpm1a_cnt_blk,
307 local_fadt->pm1_cnt_len,
308 (acpi_physical_address) local_fadt->
309 V1_pm1a_cnt_blk);
310 acpi_tb_init_generic_address(&local_fadt->xpm1b_cnt_blk,
311 local_fadt->pm1_cnt_len,
312 (acpi_physical_address) local_fadt->
313 V1_pm1b_cnt_blk);
314 acpi_tb_init_generic_address(&local_fadt->xpm2_cnt_blk,
315 local_fadt->pm2_cnt_len,
316 (acpi_physical_address) local_fadt->
317 V1_pm2_cnt_blk);
318 acpi_tb_init_generic_address(&local_fadt->xpm_tmr_blk,
319 local_fadt->pm_tm_len,
320 (acpi_physical_address) local_fadt->
321 V1_pm_tmr_blk);
322 acpi_tb_init_generic_address(&local_fadt->xgpe0_blk, 0,
323 (acpi_physical_address) local_fadt->
324 V1_gpe0_blk);
325 acpi_tb_init_generic_address(&local_fadt->xgpe1_blk, 0,
326 (acpi_physical_address) local_fadt->
327 V1_gpe1_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 /* Create separate GAS structs for the PM1 Enable registers */
330
Len Brown4be44fc2005-08-05 00:44:28 -0400331 acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
332 (u8) ACPI_DIV_2(acpi_gbl_FADT->
333 pm1_evt_len),
334 (acpi_physical_address)
335 (local_fadt->xpm1a_evt_blk.address +
336 ACPI_DIV_2(acpi_gbl_FADT->pm1_evt_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
338 /* PM1B is optional; leave null if not present */
339
340 if (local_fadt->xpm1b_evt_blk.address) {
Len Brown4be44fc2005-08-05 00:44:28 -0400341 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
342 (u8) ACPI_DIV_2(acpi_gbl_FADT->
343 pm1_evt_len),
344 (acpi_physical_address)
345 (local_fadt->xpm1b_evt_blk.
346 address +
347 ACPI_DIV_2(acpi_gbl_FADT->
348 pm1_evt_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
350}
351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352/*******************************************************************************
353 *
354 * FUNCTION: acpi_tb_convert_fadt2
355 *
356 * PARAMETERS: local_fadt - Pointer to new FADT
357 * original_fadt - Pointer to old FADT
358 *
Robert Moore44f6c012005-04-18 22:49:35 -0400359 * RETURN: None, populates local_fadt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 *
361 * DESCRIPTION: Convert an ACPI 2.0 FADT to common internal format.
362 * Handles optional "X" fields.
363 *
364 ******************************************************************************/
365
366static void
Bob Moore793c2382006-03-31 00:00:00 -0500367acpi_tb_convert_fadt2(struct fadt_descriptor *local_fadt,
368 struct fadt_descriptor *original_fadt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369{
370
371 /* We have an ACPI 2.0 FADT but we must copy it to our local buffer */
372
Bob Moore793c2382006-03-31 00:00:00 -0500373 ACPI_MEMCPY(local_fadt, original_fadt, sizeof(struct fadt_descriptor));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
375 /*
376 * "X" fields are optional extensions to the original V1.0 fields, so
377 * we must selectively expand V1.0 fields if the corresponding X field
378 * is zero.
379 */
380 if (!(local_fadt->xfirmware_ctrl)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400381 ACPI_STORE_ADDRESS(local_fadt->xfirmware_ctrl,
382 local_fadt->V1_firmware_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 }
384
385 if (!(local_fadt->Xdsdt)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400386 ACPI_STORE_ADDRESS(local_fadt->Xdsdt, local_fadt->V1_dsdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 }
388
389 if (!(local_fadt->xpm1a_evt_blk.address)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400390 acpi_tb_init_generic_address(&local_fadt->xpm1a_evt_blk,
391 local_fadt->pm1_evt_len,
392 (acpi_physical_address)
393 local_fadt->V1_pm1a_evt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 }
395
396 if (!(local_fadt->xpm1b_evt_blk.address)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400397 acpi_tb_init_generic_address(&local_fadt->xpm1b_evt_blk,
398 local_fadt->pm1_evt_len,
399 (acpi_physical_address)
400 local_fadt->V1_pm1b_evt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 }
402
403 if (!(local_fadt->xpm1a_cnt_blk.address)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400404 acpi_tb_init_generic_address(&local_fadt->xpm1a_cnt_blk,
405 local_fadt->pm1_cnt_len,
406 (acpi_physical_address)
407 local_fadt->V1_pm1a_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 }
409
410 if (!(local_fadt->xpm1b_cnt_blk.address)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400411 acpi_tb_init_generic_address(&local_fadt->xpm1b_cnt_blk,
412 local_fadt->pm1_cnt_len,
413 (acpi_physical_address)
414 local_fadt->V1_pm1b_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416
417 if (!(local_fadt->xpm2_cnt_blk.address)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400418 acpi_tb_init_generic_address(&local_fadt->xpm2_cnt_blk,
419 local_fadt->pm2_cnt_len,
420 (acpi_physical_address)
421 local_fadt->V1_pm2_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 }
423
424 if (!(local_fadt->xpm_tmr_blk.address)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400425 acpi_tb_init_generic_address(&local_fadt->xpm_tmr_blk,
426 local_fadt->pm_tm_len,
427 (acpi_physical_address)
428 local_fadt->V1_pm_tmr_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 }
430
431 if (!(local_fadt->xgpe0_blk.address)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400432 acpi_tb_init_generic_address(&local_fadt->xgpe0_blk,
433 0,
434 (acpi_physical_address)
435 local_fadt->V1_gpe0_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 }
437
438 if (!(local_fadt->xgpe1_blk.address)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400439 acpi_tb_init_generic_address(&local_fadt->xgpe1_blk,
440 0,
441 (acpi_physical_address)
442 local_fadt->V1_gpe1_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 }
444
445 /* Create separate GAS structs for the PM1 Enable registers */
446
Len Brown4be44fc2005-08-05 00:44:28 -0400447 acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
448 (u8) ACPI_DIV_2(acpi_gbl_FADT->
449 pm1_evt_len),
450 (acpi_physical_address)
451 (local_fadt->xpm1a_evt_blk.address +
452 ACPI_DIV_2(acpi_gbl_FADT->pm1_evt_len)));
Robert Moore44f6c012005-04-18 22:49:35 -0400453
454 acpi_gbl_xpm1a_enable.address_space_id =
Len Brown4be44fc2005-08-05 00:44:28 -0400455 local_fadt->xpm1a_evt_blk.address_space_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
457 /* PM1B is optional; leave null if not present */
458
459 if (local_fadt->xpm1b_evt_blk.address) {
Len Brown4be44fc2005-08-05 00:44:28 -0400460 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
461 (u8) ACPI_DIV_2(acpi_gbl_FADT->
462 pm1_evt_len),
463 (acpi_physical_address)
464 (local_fadt->xpm1b_evt_blk.
465 address +
466 ACPI_DIV_2(acpi_gbl_FADT->
467 pm1_evt_len)));
Robert Moore44f6c012005-04-18 22:49:35 -0400468
469 acpi_gbl_xpm1b_enable.address_space_id =
Len Brown4be44fc2005-08-05 00:44:28 -0400470 local_fadt->xpm1b_evt_blk.address_space_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 }
472}
473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474/*******************************************************************************
475 *
476 * FUNCTION: acpi_tb_convert_table_fadt
477 *
478 * PARAMETERS: None
479 *
480 * RETURN: Status
481 *
482 * DESCRIPTION: Converts a BIOS supplied ACPI 1.0 FADT to a local
483 * ACPI 2.0 FADT. If the BIOS supplied a 2.0 FADT then it is simply
484 * copied to the local FADT. The ACPI CA software uses this
485 * local FADT. Thus a significant amount of special #ifdef
486 * type codeing is saved.
487 *
488 ******************************************************************************/
489
Len Brown4be44fc2005-08-05 00:44:28 -0400490acpi_status acpi_tb_convert_table_fadt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
Bob Moore793c2382006-03-31 00:00:00 -0500492 struct fadt_descriptor *local_fadt;
Len Brown4be44fc2005-08-05 00:44:28 -0400493 struct acpi_table_desc *table_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Bob Mooreb229cf92006-04-21 17:15:00 -0400495 ACPI_FUNCTION_TRACE(tb_convert_table_fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497 /*
498 * acpi_gbl_FADT is valid. Validate the FADT length. The table must be
499 * at least as long as the version 1.0 FADT
500 */
Len Brown4be44fc2005-08-05 00:44:28 -0400501 if (acpi_gbl_FADT->length < sizeof(struct fadt_descriptor_rev1)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500502 ACPI_ERROR((AE_INFO, "FADT is invalid, too short: 0x%X",
503 acpi_gbl_FADT->length));
Len Brown4be44fc2005-08-05 00:44:28 -0400504 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 }
506
507 /* Allocate buffer for the ACPI 2.0(+) FADT */
508
Bob Moore793c2382006-03-31 00:00:00 -0500509 local_fadt = ACPI_ALLOCATE_ZEROED(sizeof(struct fadt_descriptor));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 if (!local_fadt) {
Len Brown4be44fc2005-08-05 00:44:28 -0400511 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 }
513
514 if (acpi_gbl_FADT->revision >= FADT2_REVISION_ID) {
Bob Moore793c2382006-03-31 00:00:00 -0500515 if (acpi_gbl_FADT->length < sizeof(struct fadt_descriptor)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 /* Length is too short to be a V2.0 table */
518
Bob Mooreb8e4d892006-01-27 16:43:00 -0500519 ACPI_WARNING((AE_INFO,
520 "Inconsistent FADT length (0x%X) and revision (0x%X), using FADT V1.0 portion of table",
521 acpi_gbl_FADT->length,
522 acpi_gbl_FADT->revision));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Len Brown4be44fc2005-08-05 00:44:28 -0400524 acpi_tb_convert_fadt1(local_fadt,
525 (void *)acpi_gbl_FADT);
526 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 /* Valid V2.0 table */
528
Len Brown4be44fc2005-08-05 00:44:28 -0400529 acpi_tb_convert_fadt2(local_fadt, acpi_gbl_FADT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 }
Len Brown4be44fc2005-08-05 00:44:28 -0400531 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 /* Valid V1.0 table */
533
Len Brown4be44fc2005-08-05 00:44:28 -0400534 acpi_tb_convert_fadt1(local_fadt, (void *)acpi_gbl_FADT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 }
536
Robert Moore44f6c012005-04-18 22:49:35 -0400537 /* Global FADT pointer will point to the new common V2.0 FADT */
538
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 acpi_gbl_FADT = local_fadt;
Bob Moore793c2382006-03-31 00:00:00 -0500540 acpi_gbl_FADT->length = sizeof(struct fadt_descriptor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
542 /* Free the original table */
543
Bob Mooreb229cf92006-04-21 17:15:00 -0400544 table_desc = acpi_gbl_table_lists[ACPI_TABLE_ID_FADT].next;
Len Brown4be44fc2005-08-05 00:44:28 -0400545 acpi_tb_delete_single_table(table_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
547 /* Install the new table */
548
Len Brown4be44fc2005-08-05 00:44:28 -0400549 table_desc->pointer =
550 ACPI_CAST_PTR(struct acpi_table_header, acpi_gbl_FADT);
551 table_desc->allocation = ACPI_MEM_ALLOCATED;
Bob Moore793c2382006-03-31 00:00:00 -0500552 table_desc->length = sizeof(struct fadt_descriptor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
554 /* Dump the entire FADT */
555
Len Brown4be44fc2005-08-05 00:44:28 -0400556 ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
557 "Hex dump of common internal FADT, size %d (%X)\n",
558 acpi_gbl_FADT->length, acpi_gbl_FADT->length));
Bob Moorec51a4de2005-11-17 13:07:00 -0500559
560 ACPI_DUMP_BUFFER(ACPI_CAST_PTR(u8, acpi_gbl_FADT),
561 acpi_gbl_FADT->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Len Brown4be44fc2005-08-05 00:44:28 -0400563 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564}
565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566/*******************************************************************************
567 *
Robert Moore44f6c012005-04-18 22:49:35 -0400568 * FUNCTION: acpi_tb_build_common_facs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 *
570 * PARAMETERS: table_info - Info for currently installed FACS
571 *
572 * RETURN: Status
573 *
574 * DESCRIPTION: Convert ACPI 1.0 and ACPI 2.0 FACS to a common internal
575 * table format.
576 *
577 ******************************************************************************/
578
Len Brown4be44fc2005-08-05 00:44:28 -0400579acpi_status acpi_tb_build_common_facs(struct acpi_table_desc *table_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
581
Bob Mooreb229cf92006-04-21 17:15:00 -0400582 ACPI_FUNCTION_TRACE(tb_build_common_facs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
584 /* Absolute minimum length is 24, but the ACPI spec says 64 */
585
586 if (acpi_gbl_FACS->length < 24) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500587 ACPI_ERROR((AE_INFO, "Invalid FACS table length: 0x%X",
588 acpi_gbl_FACS->length));
Len Brown4be44fc2005-08-05 00:44:28 -0400589 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 }
591
592 if (acpi_gbl_FACS->length < 64) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500593 ACPI_WARNING((AE_INFO,
594 "FACS is shorter than the ACPI specification allows: 0x%X, using anyway",
595 acpi_gbl_FACS->length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 }
597
598 /* Copy fields to the new FACS */
599
600 acpi_gbl_common_fACS.global_lock = &(acpi_gbl_FACS->global_lock);
601
602 if ((acpi_gbl_RSDP->revision < 2) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400603 (acpi_gbl_FACS->length < 32) ||
604 (!(acpi_gbl_FACS->xfirmware_waking_vector))) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400605
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 /* ACPI 1.0 FACS or short table or optional X_ field is zero */
607
Len Brown4be44fc2005-08-05 00:44:28 -0400608 acpi_gbl_common_fACS.firmware_waking_vector = ACPI_CAST_PTR(u64,
609 &
610 (acpi_gbl_FACS->
611 firmware_waking_vector));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 acpi_gbl_common_fACS.vector_width = 32;
Len Brown4be44fc2005-08-05 00:44:28 -0400613 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 /* ACPI 2.0 FACS with valid X_ field */
615
Len Brown4be44fc2005-08-05 00:44:28 -0400616 acpi_gbl_common_fACS.firmware_waking_vector =
617 &acpi_gbl_FACS->xfirmware_waking_vector;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 acpi_gbl_common_fACS.vector_width = 64;
619 }
620
Len Brown4be44fc2005-08-05 00:44:28 -0400621 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622}