Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
f3d2e786 | 3 | * Module Name: tbutils - table utilities |
1da177e4 LT |
4 | * |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
4a90c7e8 | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
1da177e4 LT |
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 | ||
1da177e4 LT |
44 | #include <acpi/acpi.h> |
45 | #include <acpi/actables.h> | |
46 | ||
1da177e4 | 47 | #define _COMPONENT ACPI_TABLES |
4be44fcd | 48 | ACPI_MODULE_NAME("tbutils") |
1da177e4 | 49 | |
44f6c012 | 50 | /* Local prototypes */ |
c5fc42ac BM |
51 | static void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags); |
52 | ||
53 | static void acpi_tb_convert_fadt(void); | |
54 | ||
55 | static void | |
56 | acpi_tb_install_table(acpi_physical_address address, | |
57 | u8 flags, char *signature, acpi_native_uint table_index); | |
f3d2e786 BM |
58 | |
59 | static void inline | |
60 | acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct, | |
c5fc42ac BM |
61 | u8 bit_width, u64 address); |
62 | ||
63 | /* Table used for conversion of FADT to common format */ | |
64 | ||
65 | typedef struct acpi_fadt_conversion { | |
66 | u8 target; | |
67 | u8 source; | |
68 | u8 length; | |
69 | ||
70 | } acpi_fadt_conversion; | |
71 | ||
72 | static struct acpi_fadt_conversion fadt_conversion_table[] = { | |
73 | {ACPI_FADT_OFFSET(xpm1a_event_block), | |
74 | ACPI_FADT_OFFSET(pm1a_event_block), | |
75 | ACPI_FADT_OFFSET(pm1_event_length)}, | |
76 | {ACPI_FADT_OFFSET(xpm1b_event_block), | |
77 | ACPI_FADT_OFFSET(pm1b_event_block), | |
78 | ACPI_FADT_OFFSET(pm1_event_length)}, | |
79 | {ACPI_FADT_OFFSET(xpm1a_control_block), | |
80 | ACPI_FADT_OFFSET(pm1a_control_block), | |
81 | ACPI_FADT_OFFSET(pm1_control_length)}, | |
82 | {ACPI_FADT_OFFSET(xpm1b_control_block), | |
83 | ACPI_FADT_OFFSET(pm1b_control_block), | |
84 | ACPI_FADT_OFFSET(pm1_control_length)}, | |
85 | {ACPI_FADT_OFFSET(xpm2_control_block), | |
86 | ACPI_FADT_OFFSET(pm2_control_block), | |
87 | ACPI_FADT_OFFSET(pm2_control_length)}, | |
88 | {ACPI_FADT_OFFSET(xpm_timer_block), ACPI_FADT_OFFSET(pm_timer_block), | |
89 | ACPI_FADT_OFFSET(pm_timer_length)}, | |
90 | {ACPI_FADT_OFFSET(xgpe0_block), ACPI_FADT_OFFSET(gpe0_block), | |
91 | ACPI_FADT_OFFSET(gpe0_block_length)}, | |
92 | {ACPI_FADT_OFFSET(xgpe1_block), ACPI_FADT_OFFSET(gpe1_block), | |
93 | ACPI_FADT_OFFSET(gpe1_block_length)} | |
94 | }; | |
95 | ||
96 | #define ACPI_FADT_CONVERSION_ENTRIES (sizeof (fadt_conversion_table) / sizeof (struct acpi_fadt_conversion)) | |
1da177e4 | 97 | |
0c9938cc RM |
98 | /******************************************************************************* |
99 | * | |
f3d2e786 | 100 | * FUNCTION: acpi_tb_print_table_header |
0c9938cc | 101 | * |
f3d2e786 BM |
102 | * PARAMETERS: Address - Table physical address |
103 | * Header - Table header | |
0c9938cc | 104 | * |
f3d2e786 | 105 | * RETURN: None |
0c9938cc | 106 | * |
c5fc42ac | 107 | * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP. |
0c9938cc RM |
108 | * |
109 | ******************************************************************************/ | |
110 | ||
f3d2e786 BM |
111 | void |
112 | acpi_tb_print_table_header(acpi_physical_address address, | |
113 | struct acpi_table_header *header) | |
0c9938cc | 114 | { |
0c9938cc | 115 | |
c5fc42ac BM |
116 | if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) { |
117 | ||
118 | /* FACS only has signature and length fields of common table header */ | |
119 | ||
120 | ACPI_INFO((AE_INFO, "%4.4s @ 0x%p/0x%04X", | |
121 | header->signature, ACPI_CAST_PTR(void, address), | |
122 | header->length)); | |
123 | } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) { | |
124 | ||
125 | /* RSDP has no common fields */ | |
126 | ||
127 | ACPI_INFO((AE_INFO, "RSDP @ 0x%p/0x%04X (v%3.3d %6.6s)", | |
128 | ACPI_CAST_PTR(void, address), | |
129 | (((struct acpi_table_rsdp *)header)->revision > 0) ? | |
130 | ((struct acpi_table_rsdp *)header)->length : 20, | |
131 | ((struct acpi_table_rsdp *)header)->revision, | |
132 | ((struct acpi_table_rsdp *)header)->oem_id)); | |
133 | } else { | |
4bf27393 BM |
134 | /* Standard ACPI table with full common header */ |
135 | ||
c5fc42ac BM |
136 | ACPI_INFO((AE_INFO, |
137 | "%4.4s @ 0x%p/0x%04X (v%3.3d %6.6s %8.8s 0x%08X %4.4s 0x%08X)", | |
138 | header->signature, ACPI_CAST_PTR(void, address), | |
139 | header->length, header->revision, header->oem_id, | |
140 | header->oem_table_id, header->oem_revision, | |
141 | header->asl_compiler_id, | |
142 | header->asl_compiler_revision)); | |
143 | } | |
0c9938cc RM |
144 | } |
145 | ||
1da177e4 LT |
146 | /******************************************************************************* |
147 | * | |
f3d2e786 | 148 | * FUNCTION: acpi_tb_init_generic_address |
1da177e4 | 149 | * |
f3d2e786 BM |
150 | * PARAMETERS: new_gas_struct - GAS struct to be initialized |
151 | * bit_width - Width of this register | |
152 | * Address - Address of the register | |
1da177e4 | 153 | * |
f3d2e786 | 154 | * RETURN: None |
1da177e4 | 155 | * |
f3d2e786 | 156 | * DESCRIPTION: Initialize a GAS structure. |
1da177e4 LT |
157 | * |
158 | ******************************************************************************/ | |
159 | ||
f3d2e786 BM |
160 | static void inline |
161 | acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct, | |
c5fc42ac | 162 | u8 bit_width, u64 address) |
1da177e4 | 163 | { |
44f6c012 | 164 | |
4bf27393 | 165 | ACPI_MOVE_64_TO_64(&new_gas_struct->address, &address); |
f3d2e786 BM |
166 | new_gas_struct->space_id = ACPI_ADR_SPACE_SYSTEM_IO; |
167 | new_gas_struct->bit_width = bit_width; | |
168 | new_gas_struct->bit_offset = 0; | |
169 | new_gas_struct->access_width = 0; | |
1da177e4 LT |
170 | } |
171 | ||
c5fc42ac BM |
172 | /******************************************************************************* |
173 | * | |
174 | * FUNCTION: acpi_tb_validate_checksum | |
175 | * | |
176 | * PARAMETERS: Table - ACPI table to verify | |
177 | * Length - Length of entire table | |
178 | * | |
179 | * RETURN: Status | |
180 | * | |
181 | * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns | |
182 | * exception on bad checksum. | |
183 | * | |
184 | ******************************************************************************/ | |
185 | ||
186 | acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length) | |
187 | { | |
188 | u8 checksum; | |
189 | ||
190 | /* Compute the checksum on the table */ | |
191 | ||
192 | checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length); | |
193 | ||
194 | /* Checksum ok? (should be zero) */ | |
195 | ||
196 | if (checksum) { | |
197 | ACPI_WARNING((AE_INFO, | |
198 | "Incorrect checksum in table [%4.4s] - %2.2X, should be %2.2X", | |
199 | table->signature, table->checksum, | |
200 | (u8) (table->checksum - checksum))); | |
201 | ||
202 | #if (ACPI_CHECKSUM_ABORT) | |
203 | ||
204 | return (AE_BAD_CHECKSUM); | |
205 | #endif | |
206 | } | |
207 | ||
208 | return (AE_OK); | |
209 | } | |
210 | ||
1da177e4 LT |
211 | /******************************************************************************* |
212 | * | |
f3d2e786 | 213 | * FUNCTION: acpi_tb_checksum |
1da177e4 | 214 | * |
f3d2e786 BM |
215 | * PARAMETERS: Buffer - Pointer to memory region to be checked |
216 | * Length - Length of this memory region | |
1da177e4 | 217 | * |
f3d2e786 | 218 | * RETURN: Checksum (u8) |
1da177e4 | 219 | * |
f3d2e786 | 220 | * DESCRIPTION: Calculates circular checksum of memory region. |
1da177e4 LT |
221 | * |
222 | ******************************************************************************/ | |
223 | ||
f3d2e786 | 224 | u8 acpi_tb_checksum(u8 * buffer, acpi_native_uint length) |
793c2388 | 225 | { |
793c2388 | 226 | u8 sum = 0; |
f3d2e786 | 227 | u8 *end = buffer + length; |
793c2388 | 228 | |
f3d2e786 BM |
229 | while (buffer < end) { |
230 | sum = (u8) (sum + *(buffer++)); | |
793c2388 BM |
231 | } |
232 | ||
f3d2e786 | 233 | return sum; |
793c2388 BM |
234 | } |
235 | ||
236 | /******************************************************************************* | |
237 | * | |
f3d2e786 | 238 | * FUNCTION: acpi_tb_convert_fadt |
793c2388 | 239 | * |
c5fc42ac | 240 | * PARAMETERS: None, uses acpi_gbl_FADT |
793c2388 | 241 | * |
f3d2e786 | 242 | * RETURN: None |
793c2388 | 243 | * |
c5fc42ac BM |
244 | * DESCRIPTION: Converts all versions of the FADT to a common internal format. |
245 | * | |
246 | * NOTE: acpi_gbl_FADT must be of size (struct acpi_table_fadt), and must contain | |
247 | * a copy of the actual FADT. | |
248 | * | |
249 | * ACPICA will use the "X" fields of the FADT for all addresses. | |
250 | * | |
251 | * "X" fields are optional extensions to the original V1.0 fields. Even if | |
252 | * they are present in the structure, they can be optionally not used by | |
253 | * setting them to zero. Therefore, we must selectively expand V1.0 fields | |
254 | * if the corresponding X field is zero. | |
255 | * | |
256 | * For ACPI 1.0 FADTs, all address fields are expanded to the corresponding | |
257 | * "X" fields. | |
258 | * | |
259 | * For ACPI 2.0 FADTs, any "X" fields that are NULL are filled in by | |
260 | * expanding the corresponding ACPI 1.0 field. | |
793c2388 BM |
261 | * |
262 | ******************************************************************************/ | |
263 | ||
c5fc42ac | 264 | static void acpi_tb_convert_fadt(void) |
1da177e4 | 265 | { |
c5fc42ac BM |
266 | u8 pm1_register_length; |
267 | struct acpi_generic_address *target; | |
268 | acpi_native_uint i; | |
269 | ||
270 | /* Expand the FACS and DSDT addresses as necessary */ | |
1da177e4 | 271 | |
f3d2e786 BM |
272 | if (!acpi_gbl_FADT.Xfacs) { |
273 | acpi_gbl_FADT.Xfacs = (u64) acpi_gbl_FADT.facs; | |
274 | } | |
1da177e4 | 275 | |
f3d2e786 BM |
276 | if (!acpi_gbl_FADT.Xdsdt) { |
277 | acpi_gbl_FADT.Xdsdt = (u64) acpi_gbl_FADT.dsdt; | |
278 | } | |
1da177e4 | 279 | |
f3d2e786 | 280 | /* |
c5fc42ac BM |
281 | * Expand the V1.0 addresses to the "X" generic address structs, |
282 | * as necessary. | |
f3d2e786 | 283 | */ |
c5fc42ac BM |
284 | for (i = 0; i < ACPI_FADT_CONVERSION_ENTRIES; i++) { |
285 | target = | |
286 | ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT, | |
287 | fadt_conversion_table[i].target); | |
288 | ||
4bf27393 BM |
289 | /* Expand only if the X target is null */ |
290 | ||
c5fc42ac BM |
291 | if (!target->address) { |
292 | acpi_tb_init_generic_address(target, | |
293 | *ACPI_ADD_PTR(u8, | |
294 | &acpi_gbl_FADT, | |
295 | fadt_conversion_table | |
296 | [i].length), | |
4bf27393 | 297 | *ACPI_ADD_PTR(u32, |
c5fc42ac BM |
298 | &acpi_gbl_FADT, |
299 | fadt_conversion_table | |
300 | [i].source)); | |
301 | } | |
302 | } | |
f3d2e786 BM |
303 | |
304 | /* | |
c5fc42ac BM |
305 | * Calculate separate GAS structs for the PM1 Enable registers. |
306 | * These addresses do not appear (directly) in the FADT, so it is | |
307 | * useful to calculate them once, here. | |
4bf27393 BM |
308 | * |
309 | * The PM event blocks are split into two register blocks, first is the | |
310 | * PM Status Register block, followed immediately by the PM Enable Register | |
311 | * block. Each is of length (pm1_event_length/2) | |
f3d2e786 | 312 | */ |
c5fc42ac BM |
313 | pm1_register_length = (u8) ACPI_DIV_2(acpi_gbl_FADT.pm1_event_length); |
314 | ||
315 | /* PM1A is required */ | |
316 | ||
f3d2e786 | 317 | acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable, |
c5fc42ac | 318 | pm1_register_length, |
4bf27393 BM |
319 | (acpi_gbl_FADT.xpm1a_event_block.address + |
320 | pm1_register_length)); | |
c5fc42ac BM |
321 | |
322 | /* PM1B is optional; leave null if not present */ | |
f3d2e786 | 323 | |
f3d2e786 BM |
324 | if (acpi_gbl_FADT.xpm1b_event_block.address) { |
325 | acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable, | |
c5fc42ac | 326 | pm1_register_length, |
4bf27393 BM |
327 | (acpi_gbl_FADT.xpm1b_event_block. |
328 | address + pm1_register_length)); | |
f3d2e786 | 329 | } |
1da177e4 | 330 | |
f3d2e786 | 331 | /* Global FADT is the new common V2.0 FADT */ |
1da177e4 | 332 | |
f3d2e786 | 333 | acpi_gbl_FADT.header.length = sizeof(struct acpi_table_fadt); |
1da177e4 LT |
334 | } |
335 | ||
1da177e4 LT |
336 | /******************************************************************************* |
337 | * | |
c5fc42ac | 338 | * FUNCTION: acpi_tb_install_table |
1da177e4 | 339 | * |
c5fc42ac BM |
340 | * PARAMETERS: Address - Physical address of DSDT or FACS |
341 | * Flags - Flags | |
342 | * Signature - Table signature, NULL if no need to | |
343 | * match | |
344 | * table_index - Index into root table array | |
1da177e4 | 345 | * |
c5fc42ac | 346 | * RETURN: None |
1da177e4 | 347 | * |
c5fc42ac | 348 | * DESCRIPTION: Install an ACPI table into the global data structure. |
1da177e4 LT |
349 | * |
350 | ******************************************************************************/ | |
351 | ||
c5fc42ac BM |
352 | static void |
353 | acpi_tb_install_table(acpi_physical_address address, | |
354 | u8 flags, char *signature, acpi_native_uint table_index) | |
1da177e4 | 355 | { |
f3d2e786 BM |
356 | struct acpi_table_header *table; |
357 | ||
c5fc42ac BM |
358 | if (!address) { |
359 | ACPI_ERROR((AE_INFO, | |
360 | "Null physical address for ACPI table [%s]", | |
361 | signature)); | |
362 | return; | |
f3d2e786 BM |
363 | } |
364 | ||
c5fc42ac BM |
365 | /* Map just the table header */ |
366 | ||
367 | table = acpi_os_map_memory(address, sizeof(struct acpi_table_header)); | |
f3d2e786 | 368 | if (!table) { |
c5fc42ac BM |
369 | return; |
370 | } | |
371 | ||
372 | /* If a particular signature is expected, signature must match */ | |
373 | ||
374 | if (signature && !ACPI_COMPARE_NAME(table->signature, signature)) { | |
375 | ACPI_ERROR((AE_INFO, | |
376 | "Invalid signature 0x%X for ACPI table [%s]", | |
377 | *ACPI_CAST_PTR(u32, table->signature), signature)); | |
378 | goto unmap_and_exit; | |
f3d2e786 BM |
379 | } |
380 | ||
c5fc42ac BM |
381 | /* Initialize the table entry */ |
382 | ||
383 | acpi_gbl_root_table_list.tables[table_index].address = address; | |
384 | acpi_gbl_root_table_list.tables[table_index].length = table->length; | |
385 | acpi_gbl_root_table_list.tables[table_index].flags = flags; | |
f3d2e786 BM |
386 | |
387 | ACPI_MOVE_32_TO_32(& | |
c5fc42ac BM |
388 | (acpi_gbl_root_table_list.tables[table_index]. |
389 | signature), table->signature); | |
f3d2e786 | 390 | |
c5fc42ac | 391 | acpi_tb_print_table_header(address, table); |
f3d2e786 | 392 | |
c5fc42ac | 393 | if (table_index == ACPI_TABLE_INDEX_DSDT) { |
f3d2e786 | 394 | |
c5fc42ac | 395 | /* Global integer width is based upon revision of the DSDT */ |
f3d2e786 | 396 | |
c5fc42ac BM |
397 | acpi_ut_set_integer_width(table->revision); |
398 | } | |
399 | ||
400 | unmap_and_exit: | |
f3d2e786 | 401 | acpi_os_unmap_memory(table, sizeof(struct acpi_table_header)); |
c5fc42ac | 402 | } |
f3d2e786 | 403 | |
c5fc42ac BM |
404 | /******************************************************************************* |
405 | * | |
406 | * FUNCTION: acpi_tb_parse_fadt | |
407 | * | |
408 | * PARAMETERS: table_index - Index for the FADT | |
409 | * Flags - Flags | |
410 | * | |
411 | * RETURN: None | |
412 | * | |
413 | * DESCRIPTION: Initialize the FADT, DSDT and FACS tables | |
414 | * (FADT contains the addresses of the DSDT and FACS) | |
415 | * | |
416 | ******************************************************************************/ | |
417 | ||
418 | static void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags) | |
419 | { | |
420 | u32 length; | |
421 | struct acpi_table_header *table; | |
422 | ||
423 | /* | |
424 | * Special case for the FADT because of multiple versions and the fact | |
425 | * that it contains pointers to both the DSDT and FACS tables. | |
426 | * | |
427 | * Get a local copy of the FADT and convert it to a common format | |
428 | * Map entire FADT, assumed to be smaller than one page. | |
429 | */ | |
430 | length = acpi_gbl_root_table_list.tables[table_index].length; | |
1da177e4 | 431 | |
f3d2e786 | 432 | table = |
c5fc42ac BM |
433 | acpi_os_map_memory(acpi_gbl_root_table_list.tables[table_index]. |
434 | address, length); | |
f3d2e786 BM |
435 | if (!table) { |
436 | return; | |
437 | } | |
438 | ||
c5fc42ac BM |
439 | /* |
440 | * Validate the FADT checksum before we copy the table. Ignore | |
441 | * checksum error as we want to try to get the DSDT and FACS. | |
442 | */ | |
443 | (void)acpi_tb_verify_checksum(table, length); | |
f3d2e786 | 444 | |
c5fc42ac | 445 | /* Copy the entire FADT locally */ |
f3d2e786 | 446 | |
c5fc42ac | 447 | ACPI_MEMSET(&acpi_gbl_FADT, sizeof(struct acpi_table_fadt), 0); |
f3d2e786 | 448 | |
c5fc42ac BM |
449 | ACPI_MEMCPY(&acpi_gbl_FADT, table, |
450 | ACPI_MIN(length, sizeof(struct acpi_table_fadt))); | |
451 | acpi_os_unmap_memory(table, length); | |
f3d2e786 | 452 | |
c5fc42ac BM |
453 | /* Convert local FADT to the common internal format */ |
454 | ||
455 | acpi_tb_convert_fadt(); | |
456 | ||
457 | /* Extract the DSDT and FACS tables from the FADT */ | |
458 | ||
459 | acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xdsdt, | |
460 | flags, ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT); | |
461 | ||
462 | acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xfacs, | |
463 | flags, ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS); | |
793c2388 BM |
464 | } |
465 | ||
466 | /******************************************************************************* | |
467 | * | |
f3d2e786 | 468 | * FUNCTION: acpi_tb_parse_root_table |
793c2388 | 469 | * |
f3d2e786 BM |
470 | * PARAMETERS: Rsdp - Pointer to the RSDP |
471 | * Flags - Flags | |
472 | * | |
473 | * RETURN: Status | |
793c2388 | 474 | * |
f3d2e786 BM |
475 | * DESCRIPTION: This function is called to parse the Root System Description |
476 | * Table (RSDT or XSDT) | |
793c2388 | 477 | * |
f3d2e786 BM |
478 | * NOTE: Tables are mapped (not copied) for efficiency. The FACS must |
479 | * be mapped and cannot be copied because it contains the actual | |
480 | * memory location of the ACPI Global Lock. | |
793c2388 BM |
481 | * |
482 | ******************************************************************************/ | |
483 | ||
c5fc42ac BM |
484 | acpi_status |
485 | acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags) | |
793c2388 | 486 | { |
c5fc42ac BM |
487 | struct acpi_table_rsdp *rsdp; |
488 | acpi_native_uint table_entry_size; | |
489 | acpi_native_uint i; | |
490 | u32 table_count; | |
f3d2e786 BM |
491 | struct acpi_table_header *table; |
492 | acpi_physical_address address; | |
493 | u32 length; | |
494 | u8 *table_entry; | |
f3d2e786 BM |
495 | acpi_status status; |
496 | ||
497 | ACPI_FUNCTION_TRACE(tb_parse_root_table); | |
498 | ||
c5fc42ac BM |
499 | /* |
500 | * Map the entire RSDP and extract the address of the RSDT or XSDT | |
501 | */ | |
502 | rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp)); | |
503 | if (!rsdp) { | |
504 | return_ACPI_STATUS(AE_NO_MEMORY); | |
505 | } | |
506 | ||
507 | acpi_tb_print_table_header(rsdp_address, | |
508 | ACPI_CAST_PTR(struct acpi_table_header, | |
509 | rsdp)); | |
510 | ||
f3d2e786 BM |
511 | /* Differentiate between RSDT and XSDT root tables */ |
512 | ||
513 | if (rsdp->revision > 1 && rsdp->xsdt_physical_address) { | |
514 | /* | |
515 | * Root table is an XSDT (64-bit physical addresses). We must use the | |
516 | * XSDT if the revision is > 1 and the XSDT pointer is present, as per | |
517 | * the ACPI specification. | |
518 | */ | |
c5fc42ac BM |
519 | address = (acpi_physical_address) rsdp->xsdt_physical_address; |
520 | table_entry_size = sizeof(u64); | |
f3d2e786 BM |
521 | } else { |
522 | /* Root table is an RSDT (32-bit physical addresses) */ | |
523 | ||
c5fc42ac BM |
524 | address = (acpi_physical_address) rsdp->rsdt_physical_address; |
525 | table_entry_size = sizeof(u32); | |
f3d2e786 | 526 | } |
793c2388 | 527 | |
c5fc42ac BM |
528 | /* |
529 | * It is not possible to map more than one entry in some environments, | |
530 | * so unmap the RSDP here before mapping other tables | |
531 | */ | |
532 | acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp)); | |
533 | ||
534 | /* Map the RSDT/XSDT table header to get the full table length */ | |
793c2388 | 535 | |
f3d2e786 BM |
536 | table = acpi_os_map_memory(address, sizeof(struct acpi_table_header)); |
537 | if (!table) { | |
c5fc42ac | 538 | return_ACPI_STATUS(AE_NO_MEMORY); |
f3d2e786 BM |
539 | } |
540 | ||
c5fc42ac BM |
541 | acpi_tb_print_table_header(address, table); |
542 | ||
f3d2e786 BM |
543 | /* Get the length of the full table, verify length and map entire table */ |
544 | ||
545 | length = table->length; | |
546 | acpi_os_unmap_memory(table, sizeof(struct acpi_table_header)); | |
547 | ||
548 | if (length < sizeof(struct acpi_table_header)) { | |
549 | ACPI_ERROR((AE_INFO, "Invalid length 0x%X in RSDT/XSDT", | |
550 | length)); | |
c5fc42ac | 551 | return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH); |
f3d2e786 BM |
552 | } |
553 | ||
554 | table = acpi_os_map_memory(address, length); | |
555 | if (!table) { | |
c5fc42ac | 556 | return_ACPI_STATUS(AE_NO_MEMORY); |
f3d2e786 BM |
557 | } |
558 | ||
559 | /* Validate the root table checksum */ | |
560 | ||
c5fc42ac BM |
561 | status = acpi_tb_verify_checksum(table, length); |
562 | if (ACPI_FAILURE(status)) { | |
f3d2e786 | 563 | acpi_os_unmap_memory(table, length); |
c5fc42ac | 564 | return_ACPI_STATUS(status); |
f3d2e786 | 565 | } |
f3d2e786 BM |
566 | |
567 | /* Calculate the number of tables described in the root table */ | |
568 | ||
569 | table_count = | |
c5fc42ac BM |
570 | (table->length - |
571 | sizeof(struct acpi_table_header)) / table_entry_size; | |
52fc0b02 | 572 | |
c5fc42ac BM |
573 | /* |
574 | * First two entries in the table array are reserved for the DSDT and FACS, | |
575 | * which are not actually present in the RSDT/XSDT - they come from the FADT | |
576 | */ | |
f3d2e786 BM |
577 | table_entry = |
578 | ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header); | |
579 | acpi_gbl_root_table_list.count = 2; | |
1da177e4 | 580 | |
f3d2e786 | 581 | /* |
c5fc42ac | 582 | * Initialize the root table array from the RSDT/XSDT |
f3d2e786 | 583 | */ |
c5fc42ac | 584 | for (i = 0; i < table_count; i++) { |
f3d2e786 BM |
585 | if (acpi_gbl_root_table_list.count >= |
586 | acpi_gbl_root_table_list.size) { | |
c5fc42ac BM |
587 | |
588 | /* There is no more room in the root table array, attempt resize */ | |
589 | ||
f3d2e786 BM |
590 | status = acpi_tb_resize_root_table_list(); |
591 | if (ACPI_FAILURE(status)) { | |
592 | ACPI_WARNING((AE_INFO, | |
593 | "Truncating %u table entries!", | |
594 | (unsigned) | |
595 | (acpi_gbl_root_table_list.size - | |
596 | acpi_gbl_root_table_list. | |
597 | count))); | |
598 | break; | |
599 | } | |
600 | } | |
601 | ||
c5fc42ac BM |
602 | /* |
603 | * Get the table physical address (32-bit for RSDT, 64-bit for XSDT) | |
604 | */ | |
605 | if ((table_entry_size == sizeof(u32)) || | |
606 | (sizeof(acpi_physical_address) == sizeof(u32))) { | |
607 | /* | |
608 | * 32-bit platform, RSDT: Move 32-bit to 32-bit | |
609 | * 32-bit platform, XSDT: Truncate 64-bit to 32-bit | |
610 | * 64-bit platform, RSDT: Expand 32-bit to 64-bit | |
611 | * | |
612 | * Note: Addresses are 32-bit aligned in both RSDT and XSDT | |
613 | */ | |
f3d2e786 BM |
614 | acpi_gbl_root_table_list. |
615 | tables[acpi_gbl_root_table_list.count].address = | |
616 | (acpi_physical_address) (*ACPI_CAST_PTR | |
617 | (u32, table_entry)); | |
618 | } else { | |
c5fc42ac BM |
619 | /* |
620 | * 64-bit platform, XSDT: Move 64-bit to 64-bit | |
621 | * | |
622 | * Note: 64-bit addresses are only 32-bit aligned in the XSDT | |
623 | */ | |
624 | ACPI_MOVE_64_TO_64(&acpi_gbl_root_table_list. | |
625 | tables[acpi_gbl_root_table_list. | |
626 | count].address, table_entry); | |
f3d2e786 BM |
627 | } |
628 | ||
c5fc42ac | 629 | table_entry += table_entry_size; |
f3d2e786 | 630 | acpi_gbl_root_table_list.count++; |
1da177e4 | 631 | } |
793c2388 | 632 | |
f3d2e786 BM |
633 | /* |
634 | * It is not possible to map more than one entry in some environments, | |
635 | * so unmap the root table here before mapping other tables | |
636 | */ | |
637 | acpi_os_unmap_memory(table, length); | |
638 | ||
c5fc42ac BM |
639 | /* |
640 | * Complete the initialization of the root table array by examining | |
641 | * the header of each table | |
642 | */ | |
f3d2e786 | 643 | for (i = 2; i < acpi_gbl_root_table_list.count; i++) { |
c5fc42ac BM |
644 | acpi_tb_install_table(acpi_gbl_root_table_list.tables[i]. |
645 | address, flags, NULL, i); | |
f3d2e786 | 646 | |
c5fc42ac | 647 | /* Special case for FADT - get the DSDT and FACS */ |
f3d2e786 | 648 | |
c5fc42ac BM |
649 | if (ACPI_COMPARE_NAME |
650 | (&acpi_gbl_root_table_list.tables[i].signature, | |
651 | ACPI_SIG_FADT)) { | |
652 | acpi_tb_parse_fadt(i, flags); | |
f3d2e786 BM |
653 | } |
654 | } | |
655 | ||
656 | return_ACPI_STATUS(AE_OK); | |
1da177e4 LT |
657 | } |
658 | ||
f3d2e786 | 659 | /****************************************************************************** |
44f6c012 | 660 | * |
f3d2e786 | 661 | * FUNCTION: acpi_tb_map |
44f6c012 | 662 | * |
f3d2e786 BM |
663 | * PARAMETERS: Address - Address to be mapped |
664 | * Length - Length to be mapped | |
665 | * Flags - Logical or physical addressing mode | |
44f6c012 | 666 | * |
f3d2e786 | 667 | * RETURN: Pointer to mapped region |
44f6c012 | 668 | * |
f3d2e786 BM |
669 | * DESCRIPTION: Maps memory according to flag |
670 | * | |
671 | *****************************************************************************/ | |
44f6c012 | 672 | |
f3d2e786 | 673 | void *acpi_tb_map(acpi_physical_address address, u32 length, u32 flags) |
44f6c012 | 674 | { |
44f6c012 | 675 | |
f3d2e786 BM |
676 | if (flags == ACPI_TABLE_ORIGIN_MAPPED) { |
677 | return (acpi_os_map_memory(address, length)); | |
678 | } else { | |
679 | return (ACPI_CAST_PTR(void, address)); | |
680 | } | |
681 | } | |
44f6c012 | 682 | |
f3d2e786 BM |
683 | /****************************************************************************** |
684 | * | |
685 | * FUNCTION: acpi_tb_unmap | |
686 | * | |
687 | * PARAMETERS: Pointer - To mapped region | |
688 | * Length - Length to be unmapped | |
689 | * Flags - Logical or physical addressing mode | |
690 | * | |
691 | * RETURN: None | |
692 | * | |
693 | * DESCRIPTION: Unmaps memory according to flag | |
694 | * | |
695 | *****************************************************************************/ | |
44f6c012 | 696 | |
f3d2e786 BM |
697 | void acpi_tb_unmap(void *pointer, u32 length, u32 flags) |
698 | { | |
44f6c012 | 699 | |
f3d2e786 BM |
700 | if (flags == ACPI_TABLE_ORIGIN_MAPPED) { |
701 | acpi_os_unmap_memory(pointer, length); | |
702 | } | |
44f6c012 | 703 | } |