1 /******************************************************************************
3 * Module Name: tbconvrt - ACPI Table conversion utilities
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2004, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
45 #include <acpi/acpi.h>
46 #include <acpi/actables.h>
49 #define _COMPONENT ACPI_TABLES
50 ACPI_MODULE_NAME ("tbconvrt")
53 /*******************************************************************************
55 * FUNCTION: acpi_tb_get_table_count
57 * PARAMETERS: RSDP - Pointer to the RSDP
58 * RSDT - Pointer to the RSDT/XSDT
60 * RETURN: The number of tables pointed to by the RSDT or XSDT.
62 * DESCRIPTION: Calculate the number of tables. Automatically handles either
65 ******************************************************************************/
68 acpi_tb_get_table_count (
69 struct rsdp_descriptor *RSDP,
70 struct acpi_table_header *RSDT)
75 ACPI_FUNCTION_ENTRY ();
78 if (RSDP->revision < 2) {
79 pointer_size = sizeof (u32);
82 pointer_size = sizeof (u64);
86 * Determine the number of tables pointed to by the RSDT/XSDT.
87 * This is defined by the ACPI Specification to be the number of
88 * pointers contained within the RSDT/XSDT. The size of the pointers
89 * is architecture-dependent.
91 return ((RSDT->length - sizeof (struct acpi_table_header)) / pointer_size);
95 /*******************************************************************************
97 * FUNCTION: acpi_tb_convert_to_xsdt
99 * PARAMETERS: table_info - Info about the RSDT
103 * DESCRIPTION: Convert an RSDT to an XSDT (internal common format)
105 ******************************************************************************/
108 acpi_tb_convert_to_xsdt (
109 struct acpi_table_desc *table_info)
111 acpi_size table_size;
113 XSDT_DESCRIPTOR *new_table;
116 ACPI_FUNCTION_ENTRY ();
119 /* Compute size of the converted XSDT */
121 table_size = ((acpi_size) acpi_gbl_rsdt_table_count * sizeof (u64)) +
122 sizeof (struct acpi_table_header);
124 /* Allocate an XSDT */
126 new_table = ACPI_MEM_CALLOCATE (table_size);
128 return (AE_NO_MEMORY);
131 /* Copy the header and set the length */
133 ACPI_MEMCPY (new_table, table_info->pointer, sizeof (struct acpi_table_header));
134 new_table->length = (u32) table_size;
136 /* Copy the table pointers */
138 for (i = 0; i < acpi_gbl_rsdt_table_count; i++) {
139 if (acpi_gbl_RSDP->revision < 2) {
140 ACPI_STORE_ADDRESS (new_table->table_offset_entry[i],
141 (ACPI_CAST_PTR (struct rsdt_descriptor_rev1, table_info->pointer))->table_offset_entry[i]);
144 new_table->table_offset_entry[i] =
145 (ACPI_CAST_PTR (XSDT_DESCRIPTOR, table_info->pointer))->table_offset_entry[i];
149 /* Delete the original table (either mapped or in a buffer) */
151 acpi_tb_delete_single_table (table_info);
153 /* Point the table descriptor to the new table */
155 table_info->pointer = ACPI_CAST_PTR (struct acpi_table_header, new_table);
156 table_info->length = table_size;
157 table_info->allocation = ACPI_MEM_ALLOCATED;
163 /******************************************************************************
165 * FUNCTION: acpi_tb_init_generic_address
167 * PARAMETERS: new_gas_struct - GAS struct to be initialized
168 * register_bit_width - Width of this register
169 * Address - Address of the register
173 * DESCRIPTION: Initialize a GAS structure.
175 ******************************************************************************/
178 acpi_tb_init_generic_address (
179 struct acpi_generic_address *new_gas_struct,
180 u8 register_bit_width,
181 acpi_physical_address address)
184 ACPI_STORE_ADDRESS (new_gas_struct->address, address);
186 new_gas_struct->address_space_id = ACPI_ADR_SPACE_SYSTEM_IO;
187 new_gas_struct->register_bit_width = register_bit_width;
188 new_gas_struct->register_bit_offset = 0;
189 new_gas_struct->reserved = 0;
193 /*******************************************************************************
195 * FUNCTION: acpi_tb_convert_fadt1
197 * PARAMETERS: local_fadt - Pointer to new FADT
198 * original_fadt - Pointer to old FADT
200 * RETURN: Populates local_fadt
202 * DESCRIPTION: Convert an ACPI 1.0 FADT to common internal format
204 ******************************************************************************/
207 acpi_tb_convert_fadt1 (
208 struct fadt_descriptor_rev2 *local_fadt,
209 struct fadt_descriptor_rev1 *original_fadt)
214 /* The BIOS stored FADT should agree with Revision 1.0 */
217 * Copy the table header and the common part of the tables.
219 * The 2.0 table is an extension of the 1.0 table, so the entire 1.0
220 * table can be copied first, then expand some fields to 64 bits.
222 ACPI_MEMCPY (local_fadt, original_fadt, sizeof (struct fadt_descriptor_rev1));
224 /* Convert table pointers to 64-bit fields */
226 ACPI_STORE_ADDRESS (local_fadt->xfirmware_ctrl, local_fadt->V1_firmware_ctrl);
227 ACPI_STORE_ADDRESS (local_fadt->Xdsdt, local_fadt->V1_dsdt);
230 * System Interrupt Model isn't used in ACPI 2.0 (local_fadt->Reserved1 = 0;)
234 * This field is set by the OEM to convey the preferred power management
235 * profile to OSPM. It doesn't have any 1.0 equivalence. Since we don't
236 * know what kind of 32-bit system this is, we will use "unspecified".
238 local_fadt->prefer_PM_profile = PM_UNSPECIFIED;
241 * Processor Performance State Control. This is the value OSPM writes to
242 * the SMI_CMD register to assume processor performance state control
243 * responsibility. There isn't any equivalence in 1.0, leave it zeroed.
245 local_fadt->pstate_cnt = 0;
248 * Support for the _CST object and C States change notification.
249 * This data item hasn't any 1.0 equivalence so leave it zero.
251 local_fadt->cst_cnt = 0;
254 * Support for ACPI system reset mechanism was introduced between
255 * Spec revisions 1.0b and 2.0, for legacy free systems..
257 if (original_fadt->revision == FADT2_INTERIM_REVISION_ID && original_fadt->length == FADT2_INTERIM_LENGTH) {
259 * Copy the entire GAS, plus the 1-byte reset value that
260 * immediately follows.
262 ACPI_MEMCPY (&local_fadt->reset_register, &((FADT_DESCRIPTOR *)original_fadt)->reset_register, sizeof(struct acpi_generic_address) + 1);
265 * Otherwise, there isn't any equivalence in 1.0 and it's
266 * highly likely that a 1.0 system has legacy support.
268 local_fadt->iapc_boot_arch = BAF_LEGACY_DEVICES;
272 * Convert the V1.0 block addresses to V2.0 GAS structures
274 acpi_tb_init_generic_address (&local_fadt->xpm1a_evt_blk, local_fadt->pm1_evt_len,
275 (acpi_physical_address) local_fadt->V1_pm1a_evt_blk);
276 acpi_tb_init_generic_address (&local_fadt->xpm1b_evt_blk, local_fadt->pm1_evt_len,
277 (acpi_physical_address) local_fadt->V1_pm1b_evt_blk);
278 acpi_tb_init_generic_address (&local_fadt->xpm1a_cnt_blk, local_fadt->pm1_cnt_len,
279 (acpi_physical_address) local_fadt->V1_pm1a_cnt_blk);
280 acpi_tb_init_generic_address (&local_fadt->xpm1b_cnt_blk, local_fadt->pm1_cnt_len,
281 (acpi_physical_address) local_fadt->V1_pm1b_cnt_blk);
282 acpi_tb_init_generic_address (&local_fadt->xpm2_cnt_blk, local_fadt->pm2_cnt_len,
283 (acpi_physical_address) local_fadt->V1_pm2_cnt_blk);
284 acpi_tb_init_generic_address (&local_fadt->xpm_tmr_blk, local_fadt->pm_tm_len,
285 (acpi_physical_address) local_fadt->V1_pm_tmr_blk);
286 acpi_tb_init_generic_address (&local_fadt->xgpe0_blk, 0,
287 (acpi_physical_address) local_fadt->V1_gpe0_blk);
288 acpi_tb_init_generic_address (&local_fadt->xgpe1_blk, 0,
289 (acpi_physical_address) local_fadt->V1_gpe1_blk);
291 /* Create separate GAS structs for the PM1 Enable registers */
293 acpi_tb_init_generic_address (&acpi_gbl_xpm1a_enable,
294 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len),
295 (acpi_physical_address) (local_fadt->xpm1a_evt_blk.address +
296 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len)));
298 /* PM1B is optional; leave null if not present */
300 if (local_fadt->xpm1b_evt_blk.address) {
301 acpi_tb_init_generic_address (&acpi_gbl_xpm1b_enable,
302 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len),
303 (acpi_physical_address) (local_fadt->xpm1b_evt_blk.address +
304 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len)));
309 /*******************************************************************************
311 * FUNCTION: acpi_tb_convert_fadt2
313 * PARAMETERS: local_fadt - Pointer to new FADT
314 * original_fadt - Pointer to old FADT
316 * RETURN: Populates local_fadt
318 * DESCRIPTION: Convert an ACPI 2.0 FADT to common internal format.
319 * Handles optional "X" fields.
321 ******************************************************************************/
324 acpi_tb_convert_fadt2 (
325 struct fadt_descriptor_rev2 *local_fadt,
326 struct fadt_descriptor_rev2 *original_fadt)
329 /* We have an ACPI 2.0 FADT but we must copy it to our local buffer */
331 ACPI_MEMCPY (local_fadt, original_fadt, sizeof (struct fadt_descriptor_rev2));
334 * "X" fields are optional extensions to the original V1.0 fields, so
335 * we must selectively expand V1.0 fields if the corresponding X field
338 if (!(local_fadt->xfirmware_ctrl)) {
339 ACPI_STORE_ADDRESS (local_fadt->xfirmware_ctrl, local_fadt->V1_firmware_ctrl);
342 if (!(local_fadt->Xdsdt)) {
343 ACPI_STORE_ADDRESS (local_fadt->Xdsdt, local_fadt->V1_dsdt);
346 if (!(local_fadt->xpm1a_evt_blk.address)) {
347 acpi_tb_init_generic_address (&local_fadt->xpm1a_evt_blk,
348 local_fadt->pm1_evt_len, (acpi_physical_address) local_fadt->V1_pm1a_evt_blk);
351 if (!(local_fadt->xpm1b_evt_blk.address)) {
352 acpi_tb_init_generic_address (&local_fadt->xpm1b_evt_blk,
353 local_fadt->pm1_evt_len, (acpi_physical_address) local_fadt->V1_pm1b_evt_blk);
356 if (!(local_fadt->xpm1a_cnt_blk.address)) {
357 acpi_tb_init_generic_address (&local_fadt->xpm1a_cnt_blk,
358 local_fadt->pm1_cnt_len, (acpi_physical_address) local_fadt->V1_pm1a_cnt_blk);
361 if (!(local_fadt->xpm1b_cnt_blk.address)) {
362 acpi_tb_init_generic_address (&local_fadt->xpm1b_cnt_blk,
363 local_fadt->pm1_cnt_len, (acpi_physical_address) local_fadt->V1_pm1b_cnt_blk);
366 if (!(local_fadt->xpm2_cnt_blk.address)) {
367 acpi_tb_init_generic_address (&local_fadt->xpm2_cnt_blk,
368 local_fadt->pm2_cnt_len, (acpi_physical_address) local_fadt->V1_pm2_cnt_blk);
371 if (!(local_fadt->xpm_tmr_blk.address)) {
372 acpi_tb_init_generic_address (&local_fadt->xpm_tmr_blk,
373 local_fadt->pm_tm_len, (acpi_physical_address) local_fadt->V1_pm_tmr_blk);
376 if (!(local_fadt->xgpe0_blk.address)) {
377 acpi_tb_init_generic_address (&local_fadt->xgpe0_blk,
378 0, (acpi_physical_address) local_fadt->V1_gpe0_blk);
381 if (!(local_fadt->xgpe1_blk.address)) {
382 acpi_tb_init_generic_address (&local_fadt->xgpe1_blk,
383 0, (acpi_physical_address) local_fadt->V1_gpe1_blk);
386 /* Create separate GAS structs for the PM1 Enable registers */
388 acpi_tb_init_generic_address (&acpi_gbl_xpm1a_enable,
389 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len),
390 (acpi_physical_address) (local_fadt->xpm1a_evt_blk.address +
391 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len)));
392 acpi_gbl_xpm1a_enable.address_space_id = local_fadt->xpm1a_evt_blk.address_space_id;
394 /* PM1B is optional; leave null if not present */
396 if (local_fadt->xpm1b_evt_blk.address) {
397 acpi_tb_init_generic_address (&acpi_gbl_xpm1b_enable,
398 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len),
399 (acpi_physical_address) (local_fadt->xpm1b_evt_blk.address +
400 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len)));
401 acpi_gbl_xpm1b_enable.address_space_id = local_fadt->xpm1b_evt_blk.address_space_id;
406 /*******************************************************************************
408 * FUNCTION: acpi_tb_convert_table_fadt
414 * DESCRIPTION: Converts a BIOS supplied ACPI 1.0 FADT to a local
415 * ACPI 2.0 FADT. If the BIOS supplied a 2.0 FADT then it is simply
416 * copied to the local FADT. The ACPI CA software uses this
417 * local FADT. Thus a significant amount of special #ifdef
418 * type codeing is saved.
420 ******************************************************************************/
423 acpi_tb_convert_table_fadt (void)
425 struct fadt_descriptor_rev2 *local_fadt;
426 struct acpi_table_desc *table_desc;
429 ACPI_FUNCTION_TRACE ("tb_convert_table_fadt");
433 * acpi_gbl_FADT is valid
434 * Allocate and zero the 2.0 FADT buffer
436 local_fadt = ACPI_MEM_CALLOCATE (sizeof (struct fadt_descriptor_rev2));
437 if (local_fadt == NULL) {
438 return_ACPI_STATUS (AE_NO_MEMORY);
442 * FADT length and version validation. The table must be at least as
443 * long as the version 1.0 FADT
445 if (acpi_gbl_FADT->length < sizeof (struct fadt_descriptor_rev1)) {
446 ACPI_REPORT_ERROR (("Invalid FADT table length: 0x%X\n", acpi_gbl_FADT->length));
447 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
450 if (acpi_gbl_FADT->revision >= FADT2_REVISION_ID) {
451 if (acpi_gbl_FADT->length < sizeof (struct fadt_descriptor_rev2)) {
452 /* Length is too short to be a V2.0 table */
454 ACPI_REPORT_WARNING (("Inconsistent FADT length (0x%X) and revision (0x%X), using FADT V1.0 portion of table\n",
455 acpi_gbl_FADT->length, acpi_gbl_FADT->revision));
457 acpi_tb_convert_fadt1 (local_fadt, (void *) acpi_gbl_FADT);
460 /* Valid V2.0 table */
462 acpi_tb_convert_fadt2 (local_fadt, acpi_gbl_FADT);
466 /* Valid V1.0 table */
468 acpi_tb_convert_fadt1 (local_fadt, (void *) acpi_gbl_FADT);
472 * Global FADT pointer will point to the new common V2.0 FADT
474 acpi_gbl_FADT = local_fadt;
475 acpi_gbl_FADT->length = sizeof (FADT_DESCRIPTOR);
477 /* Free the original table */
479 table_desc = acpi_gbl_table_lists[ACPI_TABLE_FADT].next;
480 acpi_tb_delete_single_table (table_desc);
482 /* Install the new table */
484 table_desc->pointer = ACPI_CAST_PTR (struct acpi_table_header, acpi_gbl_FADT);
485 table_desc->allocation = ACPI_MEM_ALLOCATED;
486 table_desc->length = sizeof (struct fadt_descriptor_rev2);
488 /* Dump the entire FADT */
490 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES,
491 "Hex dump of common internal FADT, size %d (%X)\n",
492 acpi_gbl_FADT->length, acpi_gbl_FADT->length));
493 ACPI_DUMP_BUFFER ((u8 *) (acpi_gbl_FADT), acpi_gbl_FADT->length);
495 return_ACPI_STATUS (AE_OK);
499 /*******************************************************************************
501 * FUNCTION: acpi_tb_convert_table_facs
503 * PARAMETERS: table_info - Info for currently installad FACS
507 * DESCRIPTION: Convert ACPI 1.0 and ACPI 2.0 FACS to a common internal
510 ******************************************************************************/
513 acpi_tb_build_common_facs (
514 struct acpi_table_desc *table_info)
517 ACPI_FUNCTION_TRACE ("tb_build_common_facs");
520 /* Absolute minimum length is 24, but the ACPI spec says 64 */
522 if (acpi_gbl_FACS->length < 24) {
523 ACPI_REPORT_ERROR (("Invalid FACS table length: 0x%X\n", acpi_gbl_FACS->length));
524 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
527 if (acpi_gbl_FACS->length < 64) {
528 ACPI_REPORT_WARNING (("FACS is shorter than the ACPI specification allows: 0x%X, using anyway\n",
529 acpi_gbl_FACS->length));
532 /* Copy fields to the new FACS */
534 acpi_gbl_common_fACS.global_lock = &(acpi_gbl_FACS->global_lock);
536 if ((acpi_gbl_RSDP->revision < 2) ||
537 (acpi_gbl_FACS->length < 32) ||
538 (!(acpi_gbl_FACS->xfirmware_waking_vector))) {
539 /* ACPI 1.0 FACS or short table or optional X_ field is zero */
541 acpi_gbl_common_fACS.firmware_waking_vector = ACPI_CAST_PTR (u64, &(acpi_gbl_FACS->firmware_waking_vector));
542 acpi_gbl_common_fACS.vector_width = 32;
545 /* ACPI 2.0 FACS with valid X_ field */
547 acpi_gbl_common_fACS.firmware_waking_vector = &acpi_gbl_FACS->xfirmware_waking_vector;
548 acpi_gbl_common_fACS.vector_width = 64;
551 return_ACPI_STATUS (AE_OK);