blob: 8816bab0fe0e73912f409e5c3e0e46883466a987 [file] [log] [blame]
Bob Moore95befdb2007-02-02 19:48:20 +03001/******************************************************************************
2 *
3 * Module Name: tbfadt - FADT table utilities
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2006, R. Byron Moore
9 * 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
44#include <acpi/acpi.h>
45#include <acpi/actables.h>
46
47#define _COMPONENT ACPI_TABLES
48ACPI_MODULE_NAME("tbfadt")
49
50/* Local prototypes */
51static void inline
Bob Mooreea5d8eb2007-02-02 19:48:20 +030052acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
Bob Moore95befdb2007-02-02 19:48:20 +030053 u8 bit_width, u64 address);
54
Bob Mooreea5d8eb2007-02-02 19:48:20 +030055/* Table for conversion of FADT to common internal format and FADT validation */
Bob Moore95befdb2007-02-02 19:48:20 +030056
Bob Mooreea5d8eb2007-02-02 19:48:20 +030057typedef struct acpi_fadt_info {
58 char *name;
Bob Moore95befdb2007-02-02 19:48:20 +030059 u8 target;
60 u8 source;
61 u8 length;
Bob Mooreea5d8eb2007-02-02 19:48:20 +030062 u8 type;
Bob Moore95befdb2007-02-02 19:48:20 +030063
Bob Mooreea5d8eb2007-02-02 19:48:20 +030064} acpi_fadt_info;
Bob Moore95befdb2007-02-02 19:48:20 +030065
Bob Mooreea5d8eb2007-02-02 19:48:20 +030066#define ACPI_FADT_REQUIRED 1
67#define ACPI_FADT_SEPARATE_LENGTH 2
68
69static struct acpi_fadt_info fadt_info_table[] = {
70 {"Pm1aEventBlock", ACPI_FADT_OFFSET(xpm1a_event_block),
Bob Moore95befdb2007-02-02 19:48:20 +030071 ACPI_FADT_OFFSET(pm1a_event_block),
Bob Mooreea5d8eb2007-02-02 19:48:20 +030072 ACPI_FADT_OFFSET(pm1_event_length), ACPI_FADT_REQUIRED},
73
74 {"Pm1bEventBlock", ACPI_FADT_OFFSET(xpm1b_event_block),
Bob Moore95befdb2007-02-02 19:48:20 +030075 ACPI_FADT_OFFSET(pm1b_event_block),
Bob Mooreea5d8eb2007-02-02 19:48:20 +030076 ACPI_FADT_OFFSET(pm1_event_length), 0},
77
78 {"Pm1aControlBlock", ACPI_FADT_OFFSET(xpm1a_control_block),
Bob Moore95befdb2007-02-02 19:48:20 +030079 ACPI_FADT_OFFSET(pm1a_control_block),
Bob Mooreea5d8eb2007-02-02 19:48:20 +030080 ACPI_FADT_OFFSET(pm1_control_length), ACPI_FADT_REQUIRED},
81
82 {"Pm1bControlBlock", ACPI_FADT_OFFSET(xpm1b_control_block),
Bob Moore95befdb2007-02-02 19:48:20 +030083 ACPI_FADT_OFFSET(pm1b_control_block),
Bob Mooreea5d8eb2007-02-02 19:48:20 +030084 ACPI_FADT_OFFSET(pm1_control_length), 0},
85
86 {"Pm2ControlBlock", ACPI_FADT_OFFSET(xpm2_control_block),
Bob Moore95befdb2007-02-02 19:48:20 +030087 ACPI_FADT_OFFSET(pm2_control_block),
Bob Mooreea5d8eb2007-02-02 19:48:20 +030088 ACPI_FADT_OFFSET(pm2_control_length), ACPI_FADT_SEPARATE_LENGTH},
89
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},
93
94 {"Gpe0Block", ACPI_FADT_OFFSET(xgpe0_block),
95 ACPI_FADT_OFFSET(gpe0_block),
96 ACPI_FADT_OFFSET(gpe0_block_length), ACPI_FADT_SEPARATE_LENGTH},
97
98 {"Gpe1Block", ACPI_FADT_OFFSET(xgpe1_block),
99 ACPI_FADT_OFFSET(gpe1_block),
100 ACPI_FADT_OFFSET(gpe1_block_length), ACPI_FADT_SEPARATE_LENGTH}
Bob Moore95befdb2007-02-02 19:48:20 +0300101};
102
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300103#define ACPI_FADT_INFO_ENTRIES (sizeof (fadt_info_table) / sizeof (struct acpi_fadt_info))
Bob Moore95befdb2007-02-02 19:48:20 +0300104
105/*******************************************************************************
106 *
107 * FUNCTION: acpi_tb_init_generic_address
108 *
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300109 * PARAMETERS: generic_address - GAS struct to be initialized
Bob Moore95befdb2007-02-02 19:48:20 +0300110 * bit_width - Width of this register
111 * Address - Address of the register
112 *
113 * RETURN: None
114 *
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300115 * DESCRIPTION: Initialize a Generic Address Structure (GAS)
116 * See the ACPI specification for a full description and
117 * definition of this structure.
Bob Moore95befdb2007-02-02 19:48:20 +0300118 *
119 ******************************************************************************/
120
121static void inline
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300122acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
Bob Moore95befdb2007-02-02 19:48:20 +0300123 u8 bit_width, u64 address)
124{
125
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300126 /*
127 * The 64-bit Address field is non-aligned in the byte packed
128 * GAS struct.
129 */
130 ACPI_MOVE_64_TO_64(&generic_address->address, &address);
131
132 /* All other fields are byte-wide */
133
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;
Bob Moore95befdb2007-02-02 19:48:20 +0300138}
139
140/*******************************************************************************
141 *
142 * FUNCTION: acpi_tb_parse_fadt
143 *
144 * PARAMETERS: table_index - Index for the FADT
145 * Flags - Flags
146 *
147 * RETURN: None
148 *
149 * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
150 * (FADT contains the addresses of the DSDT and FACS)
151 *
152 ******************************************************************************/
153
154void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags)
155{
156 u32 length;
157 struct acpi_table_header *table;
158
159 /*
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300160 * The FADT has multiple versions with different lengths,
161 * and it contains pointers to both the DSDT and FACS tables.
Bob Moore95befdb2007-02-02 19:48:20 +0300162 *
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.
165 */
166 length = acpi_gbl_root_table_list.tables[table_index].length;
167
168 table =
169 acpi_os_map_memory(acpi_gbl_root_table_list.tables[table_index].
170 address, length);
171 if (!table) {
172 return;
173 }
174
175 /*
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.
178 */
179 (void)acpi_tb_verify_checksum(table, length);
180
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300181 /*
182 * If the FADT is larger than what we know about, we have a problem.
183 * Truncate the table, but make some noise.
184 */
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)));
190 }
191
192 /* Copy the entire FADT locally. Zero first for tb_convert_fadt */
Bob Moore95befdb2007-02-02 19:48:20 +0300193
194 ACPI_MEMSET(&acpi_gbl_FADT, 0, sizeof(struct acpi_table_fadt));
Bob Moore95befdb2007-02-02 19:48:20 +0300195 ACPI_MEMCPY(&acpi_gbl_FADT, table,
196 ACPI_MIN(length, sizeof(struct acpi_table_fadt)));
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300197
198 /* All done with the real FADT, unmap it */
199
Bob Moore95befdb2007-02-02 19:48:20 +0300200 acpi_os_unmap_memory(table, length);
201
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300202 /*
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
205 */
Bob Moore95befdb2007-02-02 19:48:20 +0300206 acpi_tb_convert_fadt();
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300207 acpi_tb_validate_fadt(&acpi_gbl_FADT);
Bob Moore95befdb2007-02-02 19:48:20 +0300208
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300209 /* Obtain the DSDT and FACS tables via their addresses within the FADT */
Bob Moore95befdb2007-02-02 19:48:20 +0300210
211 acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xdsdt,
212 flags, ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
213
214 acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xfacs,
215 flags, ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS);
Bob Moore95befdb2007-02-02 19:48:20 +0300216}
217
218/*******************************************************************************
219 *
220 * FUNCTION: acpi_tb_convert_fadt
221 *
222 * PARAMETERS: None, uses acpi_gbl_FADT
223 *
224 * RETURN: None
225 *
226 * DESCRIPTION: Converts all versions of the FADT to a common internal format.
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300227 * -> Expand all 32-bit addresses to 64-bit.
Bob Moore95befdb2007-02-02 19:48:20 +0300228 *
Bob Mooree56b6382007-02-02 19:48:20 +0300229 * NOTE: acpi_gbl_FADT must be of size (struct acpi_table_fadt),
230 * and must contain a copy of the actual FADT.
Bob Moore95befdb2007-02-02 19:48:20 +0300231 *
232 * ACPICA will use the "X" fields of the FADT for all addresses.
233 *
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.
238 *
239 * For ACPI 1.0 FADTs, all address fields are expanded to the corresponding
240 * "X" fields.
241 *
242 * For ACPI 2.0 FADTs, any "X" fields that are NULL are filled in by
243 * expanding the corresponding ACPI 1.0 field.
244 *
245 ******************************************************************************/
246
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300247void acpi_tb_convert_fadt(void)
Bob Moore95befdb2007-02-02 19:48:20 +0300248{
249 u8 pm1_register_length;
250 struct acpi_generic_address *target;
251 acpi_native_uint i;
252
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300253 /* Update the local FADT table header length */
254
255 acpi_gbl_FADT.header.length = sizeof(struct acpi_table_fadt);
256
257 /* Expand the 32-bit FACS and DSDT addresses to 64-bit as necessary */
Bob Moore95befdb2007-02-02 19:48:20 +0300258
259 if (!acpi_gbl_FADT.Xfacs) {
260 acpi_gbl_FADT.Xfacs = (u64) acpi_gbl_FADT.facs;
261 }
262
263 if (!acpi_gbl_FADT.Xdsdt) {
264 acpi_gbl_FADT.Xdsdt = (u64) acpi_gbl_FADT.dsdt;
265 }
266
267 /*
268 * Expand the 32-bit V1.0 addresses to the 64-bit "X" generic address
269 * structures as necessary.
270 */
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300271 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
Bob Moore95befdb2007-02-02 19:48:20 +0300272 target =
273 ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT,
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300274 fadt_info_table[i].target);
Bob Moore95befdb2007-02-02 19:48:20 +0300275
276 /* Expand only if the X target is null */
277
278 if (!target->address) {
279 acpi_tb_init_generic_address(target,
280 *ACPI_ADD_PTR(u8,
281 &acpi_gbl_FADT,
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300282 fadt_info_table
Bob Moore95befdb2007-02-02 19:48:20 +0300283 [i].length),
284 (u64) * ACPI_ADD_PTR(u32,
285 &acpi_gbl_FADT,
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300286 fadt_info_table
Bob Moore95befdb2007-02-02 19:48:20 +0300287 [i].
288 source));
289 }
290 }
291
292 /*
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.
296 *
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)
300 */
301 pm1_register_length = (u8) ACPI_DIV_2(acpi_gbl_FADT.pm1_event_length);
302
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300303 /* The PM1A register block is required */
Bob Moore95befdb2007-02-02 19:48:20 +0300304
305 acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
306 pm1_register_length,
307 (acpi_gbl_FADT.xpm1a_event_block.address +
308 pm1_register_length));
309
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300310 /* The PM1B register block is optional, ignore if not present */
Bob Moore95befdb2007-02-02 19:48:20 +0300311
312 if (acpi_gbl_FADT.xpm1b_event_block.address) {
313 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
314 pm1_register_length,
315 (acpi_gbl_FADT.xpm1b_event_block.
316 address + pm1_register_length));
317 }
Bob Moore95befdb2007-02-02 19:48:20 +0300318}
319
320/******************************************************************************
321 *
322 * FUNCTION: acpi_tb_validate_fadt
323 *
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300324 * PARAMETERS: Table - Pointer to the FADT to be validated
Bob Moore95befdb2007-02-02 19:48:20 +0300325 *
Bob Mooree56b6382007-02-02 19:48:20 +0300326 * RETURN: None
Bob Moore95befdb2007-02-02 19:48:20 +0300327 *
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300328 * 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.
331 *
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
Bob Moore95befdb2007-02-02 19:48:20 +0300337 *
338 ******************************************************************************/
339
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300340void acpi_tb_validate_fadt(struct acpi_table_fadt *table)
Bob Moore95befdb2007-02-02 19:48:20 +0300341{
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300342 u32 *address32;
343 struct acpi_generic_address *address64;
344 u8 length;
345 acpi_native_uint i;
Bob Moore95befdb2007-02-02 19:48:20 +0300346
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300347 /* Examine all of the 64-bit extended address fields (X fields) */
Bob Moore95befdb2007-02-02 19:48:20 +0300348
Bob Mooreea5d8eb2007-02-02 19:48:20 +0300349 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
350
351 /* Generate pointers to the 32-bit and 64-bit addresses and get the length */
352
353 address64 =
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);
358
359 if (fadt_info_table[i].type & ACPI_FADT_REQUIRED) {
360 /*
361 * Field is required (Pm1a_event, Pm1a_control, pm_timer).
362 * Both the address and length must be non-zero.
363 */
364 if (!address64->address || !length) {
365 ACPI_ERROR((AE_INFO,
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->
369 address),
370 length));
371 }
372 } else if (fadt_info_table[i].type & ACPI_FADT_SEPARATE_LENGTH) {
373 /*
374 * Field is optional (PM2Control, GPE0, GPE1) AND has its own
375 * length field. If present, both the address and length must be valid.
376 */
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->
383 address),
384 length));
385 }
386 }
387
388 /* If both 32- and 64-bit addresses are valid (non-zero), they must match */
389
390 if (address64->address && *address32 &&
391 (address64->address != (u64) * address32)) {
392 ACPI_ERROR((AE_INFO,
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)));
396 }
Bob Moore95befdb2007-02-02 19:48:20 +0300397 }
Bob Moore95befdb2007-02-02 19:48:20 +0300398}