1 /******************************************************************************
3 * Module Name: tbfadt - FADT table utilities
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2006, 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.
44 #include <acpi/acpi.h>
45 #include <acpi/actables.h>
47 #define _COMPONENT ACPI_TABLES
48 ACPI_MODULE_NAME("tbfadt")
50 /* Local prototypes */
52 acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
53 u8 bit_width, u64 address);
55 /* Table for conversion of FADT to common internal format and FADT validation */
57 typedef struct acpi_fadt_info {
66 #define ACPI_FADT_REQUIRED 1
67 #define ACPI_FADT_SEPARATE_LENGTH 2
69 static struct acpi_fadt_info fadt_info_table[] = {
70 {"Pm1aEventBlock", ACPI_FADT_OFFSET(xpm1a_event_block),
71 ACPI_FADT_OFFSET(pm1a_event_block),
72 ACPI_FADT_OFFSET(pm1_event_length), ACPI_FADT_REQUIRED},
74 {"Pm1bEventBlock", ACPI_FADT_OFFSET(xpm1b_event_block),
75 ACPI_FADT_OFFSET(pm1b_event_block),
76 ACPI_FADT_OFFSET(pm1_event_length), 0},
78 {"Pm1aControlBlock", ACPI_FADT_OFFSET(xpm1a_control_block),
79 ACPI_FADT_OFFSET(pm1a_control_block),
80 ACPI_FADT_OFFSET(pm1_control_length), ACPI_FADT_REQUIRED},
82 {"Pm1bControlBlock", ACPI_FADT_OFFSET(xpm1b_control_block),
83 ACPI_FADT_OFFSET(pm1b_control_block),
84 ACPI_FADT_OFFSET(pm1_control_length), 0},
86 {"Pm2ControlBlock", ACPI_FADT_OFFSET(xpm2_control_block),
87 ACPI_FADT_OFFSET(pm2_control_block),
88 ACPI_FADT_OFFSET(pm2_control_length), ACPI_FADT_SEPARATE_LENGTH},
90 {"PmTimerBlock", ACPI_FADT_OFFSET(xpm_timer_block),
91 ACPI_FADT_OFFSET(pm_timer_block),
92 ACPI_FADT_OFFSET(pm_timer_length), ACPI_FADT_REQUIRED},
94 {"Gpe0Block", ACPI_FADT_OFFSET(xgpe0_block),
95 ACPI_FADT_OFFSET(gpe0_block),
96 ACPI_FADT_OFFSET(gpe0_block_length), ACPI_FADT_SEPARATE_LENGTH},
98 {"Gpe1Block", ACPI_FADT_OFFSET(xgpe1_block),
99 ACPI_FADT_OFFSET(gpe1_block),
100 ACPI_FADT_OFFSET(gpe1_block_length), ACPI_FADT_SEPARATE_LENGTH}
103 #define ACPI_FADT_INFO_ENTRIES (sizeof (fadt_info_table) / sizeof (struct acpi_fadt_info))
105 /*******************************************************************************
107 * FUNCTION: acpi_tb_init_generic_address
109 * PARAMETERS: generic_address - GAS struct to be initialized
110 * bit_width - Width of this register
111 * Address - Address of the register
115 * DESCRIPTION: Initialize a Generic Address Structure (GAS)
116 * See the ACPI specification for a full description and
117 * definition of this structure.
119 ******************************************************************************/
122 acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
123 u8 bit_width, u64 address)
127 * The 64-bit Address field is non-aligned in the byte packed
130 ACPI_MOVE_64_TO_64(&generic_address->address, &address);
132 /* All other fields are byte-wide */
134 generic_address->space_id = ACPI_ADR_SPACE_SYSTEM_IO;
135 generic_address->bit_width = bit_width;
136 generic_address->bit_offset = 0;
137 generic_address->access_width = 0;
140 /*******************************************************************************
142 * FUNCTION: acpi_tb_parse_fadt
144 * PARAMETERS: table_index - Index for the FADT
149 * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
150 * (FADT contains the addresses of the DSDT and FACS)
152 ******************************************************************************/
154 void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags)
157 struct acpi_table_header *table;
160 * The FADT has multiple versions with different lengths,
161 * and it contains pointers to both the DSDT and FACS tables.
163 * Get a local copy of the FADT and convert it to a common format
164 * Map entire FADT, assumed to be smaller than one page.
166 length = acpi_gbl_root_table_list.tables[table_index].length;
169 acpi_os_map_memory(acpi_gbl_root_table_list.tables[table_index].
176 * Validate the FADT checksum before we copy the table. Ignore
177 * checksum error as we want to try to get the DSDT and FACS.
179 (void)acpi_tb_verify_checksum(table, length);
182 * If the FADT is larger than what we know about, we have a problem.
183 * Truncate the table, but make some noise.
185 if (length > sizeof(struct acpi_table_fadt)) {
186 ACPI_WARNING((AE_INFO,
187 "FADT (revision %u) is too large, truncating length 0x%X to 0x%X",
188 table->revision, length,
189 sizeof(struct acpi_table_fadt)));
192 /* Copy the entire FADT locally. Zero first for tb_convert_fadt */
194 ACPI_MEMSET(&acpi_gbl_FADT, 0, sizeof(struct acpi_table_fadt));
195 ACPI_MEMCPY(&acpi_gbl_FADT, table,
196 ACPI_MIN(length, sizeof(struct acpi_table_fadt)));
198 /* All done with the real FADT, unmap it */
200 acpi_os_unmap_memory(table, length);
203 * 1) Convert the local copy of the FADT to the common internal format
204 * 2) Validate some of the important values within the FADT
206 acpi_tb_convert_fadt();
207 acpi_tb_validate_fadt(&acpi_gbl_FADT);
209 /* Obtain the DSDT and FACS tables via their addresses within the FADT */
211 acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xdsdt,
212 flags, ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
214 acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xfacs,
215 flags, ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS);
218 /*******************************************************************************
220 * FUNCTION: acpi_tb_convert_fadt
222 * PARAMETERS: None, uses acpi_gbl_FADT
226 * DESCRIPTION: Converts all versions of the FADT to a common internal format.
227 * -> Expand all 32-bit addresses to 64-bit.
229 * NOTE: acpi_gbl_FADT must be of size (struct acpi_table_fadt),
230 * and must contain a copy of the actual FADT.
232 * ACPICA will use the "X" fields of the FADT for all addresses.
234 * "X" fields are optional extensions to the original V1.0 fields. Even if
235 * they are present in the structure, they can be optionally not used by
236 * setting them to zero. Therefore, we must selectively expand V1.0 fields
237 * if the corresponding X field is zero.
239 * For ACPI 1.0 FADTs, all address fields are expanded to the corresponding
242 * For ACPI 2.0 FADTs, any "X" fields that are NULL are filled in by
243 * expanding the corresponding ACPI 1.0 field.
245 ******************************************************************************/
247 void acpi_tb_convert_fadt(void)
249 u8 pm1_register_length;
250 struct acpi_generic_address *target;
253 /* Update the local FADT table header length */
255 acpi_gbl_FADT.header.length = sizeof(struct acpi_table_fadt);
257 /* Expand the 32-bit FACS and DSDT addresses to 64-bit as necessary */
259 if (!acpi_gbl_FADT.Xfacs) {
260 acpi_gbl_FADT.Xfacs = (u64) acpi_gbl_FADT.facs;
263 if (!acpi_gbl_FADT.Xdsdt) {
264 acpi_gbl_FADT.Xdsdt = (u64) acpi_gbl_FADT.dsdt;
268 * Expand the 32-bit V1.0 addresses to the 64-bit "X" generic address
269 * structures as necessary.
271 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
273 ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT,
274 fadt_info_table[i].target);
276 /* Expand only if the X target is null */
278 if (!target->address) {
279 acpi_tb_init_generic_address(target,
284 (u64) * ACPI_ADD_PTR(u32,
293 * Calculate separate GAS structs for the PM1 Enable registers.
294 * These addresses do not appear (directly) in the FADT, so it is
295 * useful to calculate them once, here.
297 * The PM event blocks are split into two register blocks, first is the
298 * PM Status Register block, followed immediately by the PM Enable Register
299 * block. Each is of length (pm1_event_length/2)
301 pm1_register_length = (u8) ACPI_DIV_2(acpi_gbl_FADT.pm1_event_length);
303 /* The PM1A register block is required */
305 acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
307 (acpi_gbl_FADT.xpm1a_event_block.address +
308 pm1_register_length));
310 /* The PM1B register block is optional, ignore if not present */
312 if (acpi_gbl_FADT.xpm1b_event_block.address) {
313 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
315 (acpi_gbl_FADT.xpm1b_event_block.
316 address + pm1_register_length));
320 /******************************************************************************
322 * FUNCTION: acpi_tb_validate_fadt
324 * PARAMETERS: Table - Pointer to the FADT to be validated
328 * DESCRIPTION: Validate various important fields within the FADT. If a problem
329 * is found, issue a message, but no status is returned.
330 * Used by both the table manager and the disassembler.
332 * Possible additional checks:
333 * (acpi_gbl_FADT.pm1_event_length >= 4)
334 * (acpi_gbl_FADT.pm1_control_length >= 2)
335 * (acpi_gbl_FADT.pm_timer_length >= 4)
336 * Gpe block lengths must be multiple of 2
338 ******************************************************************************/
340 void acpi_tb_validate_fadt(struct acpi_table_fadt *table)
343 struct acpi_generic_address *address64;
347 /* Examine all of the 64-bit extended address fields (X fields) */
349 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
351 /* Generate pointers to the 32-bit and 64-bit addresses and get the length */
354 ACPI_ADD_PTR(struct acpi_generic_address, table,
355 fadt_info_table[i].target);
356 address32 = ACPI_ADD_PTR(u32, table, fadt_info_table[i].source);
357 length = *ACPI_ADD_PTR(u8, table, fadt_info_table[i].length);
359 if (fadt_info_table[i].type & ACPI_FADT_REQUIRED) {
361 * Field is required (Pm1a_event, Pm1a_control, pm_timer).
362 * Both the address and length must be non-zero.
364 if (!address64->address || !length) {
366 "Required field \"%s\" has zero address and/or length: %8.8X%8.8X/%X",
367 fadt_info_table[i].name,
368 ACPI_FORMAT_UINT64(address64->
372 } else if (fadt_info_table[i].type & ACPI_FADT_SEPARATE_LENGTH) {
374 * Field is optional (PM2Control, GPE0, GPE1) AND has its own
375 * length field. If present, both the address and length must be valid.
377 if ((address64->address && !length)
378 || (!address64->address && length)) {
379 ACPI_WARNING((AE_INFO,
380 "Optional field \"%s\" has zero address or length: %8.8X%8.8X/%X",
381 fadt_info_table[i].name,
382 ACPI_FORMAT_UINT64(address64->
388 /* If both 32- and 64-bit addresses are valid (non-zero), they must match */
390 if (address64->address && *address32 &&
391 (address64->address != (u64) * address32)) {
393 "32/64X address mismatch in \"%s\": [%8.8X] [%8.8X%8.8X], using 64X",
394 fadt_info_table[i].name, *address32,
395 ACPI_FORMAT_UINT64(address64->address)));