Loading...
1/******************************************************************************
2 *
3 * Module Name: tbutils - ACPI Table utilities
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2016, Intel Corp.
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 "accommon.h"
46#include "actables.h"
47
48#define _COMPONENT ACPI_TABLES
49ACPI_MODULE_NAME("tbutils")
50
51/* Local prototypes */
52static acpi_physical_address
53acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size);
54
55#if (!ACPI_REDUCED_HARDWARE)
56/*******************************************************************************
57 *
58 * FUNCTION: acpi_tb_initialize_facs
59 *
60 * PARAMETERS: None
61 *
62 * RETURN: Status
63 *
64 * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global
65 * for accessing the Global Lock and Firmware Waking Vector
66 *
67 ******************************************************************************/
68
69acpi_status acpi_tb_initialize_facs(void)
70{
71 struct acpi_table_facs *facs;
72
73 /* If Hardware Reduced flag is set, there is no FACS */
74
75 if (acpi_gbl_reduced_hardware) {
76 acpi_gbl_FACS = NULL;
77 return (AE_OK);
78 } else if (acpi_gbl_FADT.Xfacs &&
79 (!acpi_gbl_FADT.facs
80 || !acpi_gbl_use32_bit_facs_addresses)) {
81 (void)acpi_get_table_by_index(acpi_gbl_xfacs_index,
82 ACPI_CAST_INDIRECT_PTR(struct
83 acpi_table_header,
84 &facs));
85 acpi_gbl_FACS = facs;
86 } else if (acpi_gbl_FADT.facs) {
87 (void)acpi_get_table_by_index(acpi_gbl_facs_index,
88 ACPI_CAST_INDIRECT_PTR(struct
89 acpi_table_header,
90 &facs));
91 acpi_gbl_FACS = facs;
92 }
93
94 /* If there is no FACS, just continue. There was already an error msg */
95
96 return (AE_OK);
97}
98#endif /* !ACPI_REDUCED_HARDWARE */
99
100/*******************************************************************************
101 *
102 * FUNCTION: acpi_tb_check_dsdt_header
103 *
104 * PARAMETERS: None
105 *
106 * RETURN: None
107 *
108 * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect
109 * if the DSDT has been replaced from outside the OS and/or if
110 * the DSDT header has been corrupted.
111 *
112 ******************************************************************************/
113
114void acpi_tb_check_dsdt_header(void)
115{
116
117 /* Compare original length and checksum to current values */
118
119 if (acpi_gbl_original_dsdt_header.length != acpi_gbl_DSDT->length ||
120 acpi_gbl_original_dsdt_header.checksum != acpi_gbl_DSDT->checksum) {
121 ACPI_BIOS_ERROR((AE_INFO,
122 "The DSDT has been corrupted or replaced - "
123 "old, new headers below"));
124
125 acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header);
126 acpi_tb_print_table_header(0, acpi_gbl_DSDT);
127
128 ACPI_ERROR((AE_INFO,
129 "Please send DMI info to linux-acpi@vger.kernel.org\n"
130 "If system does not work as expected, please boot with acpi=copy_dsdt"));
131
132 /* Disable further error messages */
133
134 acpi_gbl_original_dsdt_header.length = acpi_gbl_DSDT->length;
135 acpi_gbl_original_dsdt_header.checksum =
136 acpi_gbl_DSDT->checksum;
137 }
138}
139
140/*******************************************************************************
141 *
142 * FUNCTION: acpi_tb_copy_dsdt
143 *
144 * PARAMETERS: table_desc - Installed table to copy
145 *
146 * RETURN: None
147 *
148 * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory.
149 * Some very bad BIOSs are known to either corrupt the DSDT or
150 * install a new, bad DSDT. This copy works around the problem.
151 *
152 ******************************************************************************/
153
154struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index)
155{
156 struct acpi_table_header *new_table;
157 struct acpi_table_desc *table_desc;
158
159 table_desc = &acpi_gbl_root_table_list.tables[table_index];
160
161 new_table = ACPI_ALLOCATE(table_desc->length);
162 if (!new_table) {
163 ACPI_ERROR((AE_INFO, "Could not copy DSDT of length 0x%X",
164 table_desc->length));
165 return (NULL);
166 }
167
168 memcpy(new_table, table_desc->pointer, table_desc->length);
169 acpi_tb_uninstall_table(table_desc);
170
171 acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.
172 tables[acpi_gbl_dsdt_index],
173 ACPI_PTR_TO_PHYSADDR(new_table),
174 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL,
175 new_table);
176
177 ACPI_INFO(("Forced DSDT copy: length 0x%05X copied locally, original unmapped", new_table->length));
178
179 return (new_table);
180}
181
182/*******************************************************************************
183 *
184 * FUNCTION: acpi_tb_get_root_table_entry
185 *
186 * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry
187 * table_entry_size - sizeof 32 or 64 (RSDT or XSDT)
188 *
189 * RETURN: Physical address extracted from the root table
190 *
191 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
192 * both 32-bit and 64-bit platforms
193 *
194 * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
195 * 64-bit platforms.
196 *
197 ******************************************************************************/
198
199static acpi_physical_address
200acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
201{
202 u64 address64;
203
204 /*
205 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
206 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
207 */
208 if (table_entry_size == ACPI_RSDT_ENTRY_SIZE) {
209 /*
210 * 32-bit platform, RSDT: Return 32-bit table entry
211 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
212 */
213 return ((acpi_physical_address)
214 (*ACPI_CAST_PTR(u32, table_entry)));
215 } else {
216 /*
217 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
218 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
219 * return 64-bit
220 */
221 ACPI_MOVE_64_TO_64(&address64, table_entry);
222
223#if ACPI_MACHINE_WIDTH == 32
224 if (address64 > ACPI_UINT32_MAX) {
225
226 /* Will truncate 64-bit address to 32 bits, issue warning */
227
228 ACPI_BIOS_WARNING((AE_INFO,
229 "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
230 " truncating",
231 ACPI_FORMAT_UINT64(address64)));
232 }
233#endif
234 return ((acpi_physical_address)(address64));
235 }
236}
237
238/*******************************************************************************
239 *
240 * FUNCTION: acpi_tb_parse_root_table
241 *
242 * PARAMETERS: rsdp - Pointer to the RSDP
243 *
244 * RETURN: Status
245 *
246 * DESCRIPTION: This function is called to parse the Root System Description
247 * Table (RSDT or XSDT)
248 *
249 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
250 * be mapped and cannot be copied because it contains the actual
251 * memory location of the ACPI Global Lock.
252 *
253 ******************************************************************************/
254
255acpi_status ACPI_INIT_FUNCTION
256acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
257{
258 struct acpi_table_rsdp *rsdp;
259 u32 table_entry_size;
260 u32 i;
261 u32 table_count;
262 struct acpi_table_header *table;
263 acpi_physical_address address;
264 u32 length;
265 u8 *table_entry;
266 acpi_status status;
267 u32 table_index;
268
269 ACPI_FUNCTION_TRACE(tb_parse_root_table);
270
271 /* Map the entire RSDP and extract the address of the RSDT or XSDT */
272
273 rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp));
274 if (!rsdp) {
275 return_ACPI_STATUS(AE_NO_MEMORY);
276 }
277
278 acpi_tb_print_table_header(rsdp_address,
279 ACPI_CAST_PTR(struct acpi_table_header,
280 rsdp));
281
282 /* Use XSDT if present and not overridden. Otherwise, use RSDT */
283
284 if ((rsdp->revision > 1) &&
285 rsdp->xsdt_physical_address && !acpi_gbl_do_not_use_xsdt) {
286 /*
287 * RSDP contains an XSDT (64-bit physical addresses). We must use
288 * the XSDT if the revision is > 1 and the XSDT pointer is present,
289 * as per the ACPI specification.
290 */
291 address = (acpi_physical_address)rsdp->xsdt_physical_address;
292 table_entry_size = ACPI_XSDT_ENTRY_SIZE;
293 } else {
294 /* Root table is an RSDT (32-bit physical addresses) */
295
296 address = (acpi_physical_address)rsdp->rsdt_physical_address;
297 table_entry_size = ACPI_RSDT_ENTRY_SIZE;
298 }
299
300 /*
301 * It is not possible to map more than one entry in some environments,
302 * so unmap the RSDP here before mapping other tables
303 */
304 acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp));
305
306 /* Map the RSDT/XSDT table header to get the full table length */
307
308 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
309 if (!table) {
310 return_ACPI_STATUS(AE_NO_MEMORY);
311 }
312
313 acpi_tb_print_table_header(address, table);
314
315 /*
316 * Validate length of the table, and map entire table.
317 * Minimum length table must contain at least one entry.
318 */
319 length = table->length;
320 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
321
322 if (length < (sizeof(struct acpi_table_header) + table_entry_size)) {
323 ACPI_BIOS_ERROR((AE_INFO,
324 "Invalid table length 0x%X in RSDT/XSDT",
325 length));
326 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
327 }
328
329 table = acpi_os_map_memory(address, length);
330 if (!table) {
331 return_ACPI_STATUS(AE_NO_MEMORY);
332 }
333
334 /* Validate the root table checksum */
335
336 status = acpi_tb_verify_checksum(table, length);
337 if (ACPI_FAILURE(status)) {
338 acpi_os_unmap_memory(table, length);
339 return_ACPI_STATUS(status);
340 }
341
342 /* Get the number of entries and pointer to first entry */
343
344 table_count = (u32)((table->length - sizeof(struct acpi_table_header)) /
345 table_entry_size);
346 table_entry = ACPI_ADD_PTR(u8, table, sizeof(struct acpi_table_header));
347
348 /* Initialize the root table array from the RSDT/XSDT */
349
350 for (i = 0; i < table_count; i++) {
351
352 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
353
354 address =
355 acpi_tb_get_root_table_entry(table_entry, table_entry_size);
356
357 /* Skip NULL entries in RSDT/XSDT */
358
359 if (!address) {
360 goto next_table;
361 }
362
363 status = acpi_tb_install_standard_table(address,
364 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL,
365 FALSE, TRUE,
366 &table_index);
367
368 if (ACPI_SUCCESS(status) &&
369 ACPI_COMPARE_NAME(&acpi_gbl_root_table_list.
370 tables[table_index].signature,
371 ACPI_SIG_FADT)) {
372 acpi_gbl_fadt_index = table_index;
373 acpi_tb_parse_fadt();
374 }
375
376next_table:
377
378 table_entry += table_entry_size;
379 }
380
381 acpi_os_unmap_memory(table, length);
382 return_ACPI_STATUS(AE_OK);
383}
384
385/*******************************************************************************
386 *
387 * FUNCTION: acpi_tb_get_table
388 *
389 * PARAMETERS: table_desc - Table descriptor
390 * out_table - Where the pointer to the table is returned
391 *
392 * RETURN: Status and pointer to the requested table
393 *
394 * DESCRIPTION: Increase a reference to a table descriptor and return the
395 * validated table pointer.
396 * If the table descriptor is an entry of the root table list,
397 * this API must be invoked with ACPI_MTX_TABLES acquired.
398 *
399 ******************************************************************************/
400
401acpi_status
402acpi_tb_get_table(struct acpi_table_desc *table_desc,
403 struct acpi_table_header **out_table)
404{
405 acpi_status status;
406
407 ACPI_FUNCTION_TRACE(acpi_tb_get_table);
408
409 if (table_desc->validation_count == 0) {
410
411 /* Table need to be "VALIDATED" */
412
413 status = acpi_tb_validate_table(table_desc);
414 if (ACPI_FAILURE(status)) {
415 return_ACPI_STATUS(status);
416 }
417 }
418
419 table_desc->validation_count++;
420 if (table_desc->validation_count == 0) {
421 ACPI_ERROR((AE_INFO,
422 "Table %p, Validation count is zero after increment\n",
423 table_desc));
424 table_desc->validation_count--;
425 return_ACPI_STATUS(AE_LIMIT);
426 }
427
428 *out_table = table_desc->pointer;
429 return_ACPI_STATUS(AE_OK);
430}
431
432/*******************************************************************************
433 *
434 * FUNCTION: acpi_tb_put_table
435 *
436 * PARAMETERS: table_desc - Table descriptor
437 *
438 * RETURN: None
439 *
440 * DESCRIPTION: Decrease a reference to a table descriptor and release the
441 * validated table pointer if no references.
442 * If the table descriptor is an entry of the root table list,
443 * this API must be invoked with ACPI_MTX_TABLES acquired.
444 *
445 ******************************************************************************/
446
447void acpi_tb_put_table(struct acpi_table_desc *table_desc)
448{
449
450 ACPI_FUNCTION_TRACE(acpi_tb_put_table);
451
452 if (table_desc->validation_count == 0) {
453 ACPI_WARNING((AE_INFO,
454 "Table %p, Validation count is zero before decrement\n",
455 table_desc));
456 return_VOID;
457 }
458 table_desc->validation_count--;
459
460 if (table_desc->validation_count == 0) {
461
462 /* Table need to be "INVALIDATED" */
463
464 acpi_tb_invalidate_table(table_desc);
465 }
466
467 return_VOID;
468}
1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2/******************************************************************************
3 *
4 * Module Name: tbutils - ACPI Table utilities
5 *
6 * Copyright (C) 2000 - 2023, Intel Corp.
7 *
8 *****************************************************************************/
9
10#include <acpi/acpi.h>
11#include "accommon.h"
12#include "actables.h"
13
14#define _COMPONENT ACPI_TABLES
15ACPI_MODULE_NAME("tbutils")
16
17/* Local prototypes */
18static acpi_physical_address
19acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size);
20
21#if (!ACPI_REDUCED_HARDWARE)
22/*******************************************************************************
23 *
24 * FUNCTION: acpi_tb_initialize_facs
25 *
26 * PARAMETERS: None
27 *
28 * RETURN: Status
29 *
30 * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global
31 * for accessing the Global Lock and Firmware Waking Vector
32 *
33 ******************************************************************************/
34
35acpi_status acpi_tb_initialize_facs(void)
36{
37 struct acpi_table_facs *facs;
38
39 /* If Hardware Reduced flag is set, there is no FACS */
40
41 if (acpi_gbl_reduced_hardware) {
42 acpi_gbl_FACS = NULL;
43 return (AE_OK);
44 } else if (acpi_gbl_FADT.Xfacs &&
45 (!acpi_gbl_FADT.facs
46 || !acpi_gbl_use32_bit_facs_addresses)) {
47 (void)acpi_get_table_by_index(acpi_gbl_xfacs_index,
48 ACPI_CAST_INDIRECT_PTR(struct
49 acpi_table_header,
50 &facs));
51 acpi_gbl_FACS = facs;
52 } else if (acpi_gbl_FADT.facs) {
53 (void)acpi_get_table_by_index(acpi_gbl_facs_index,
54 ACPI_CAST_INDIRECT_PTR(struct
55 acpi_table_header,
56 &facs));
57 acpi_gbl_FACS = facs;
58 }
59
60 /* If there is no FACS, just continue. There was already an error msg */
61
62 return (AE_OK);
63}
64#endif /* !ACPI_REDUCED_HARDWARE */
65
66/*******************************************************************************
67 *
68 * FUNCTION: acpi_tb_check_dsdt_header
69 *
70 * PARAMETERS: None
71 *
72 * RETURN: None
73 *
74 * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect
75 * if the DSDT has been replaced from outside the OS and/or if
76 * the DSDT header has been corrupted.
77 *
78 ******************************************************************************/
79
80void acpi_tb_check_dsdt_header(void)
81{
82
83 /* Compare original length and checksum to current values */
84
85 if (acpi_gbl_original_dsdt_header.length != acpi_gbl_DSDT->length ||
86 acpi_gbl_original_dsdt_header.checksum != acpi_gbl_DSDT->checksum) {
87 ACPI_BIOS_ERROR((AE_INFO,
88 "The DSDT has been corrupted or replaced - "
89 "old, new headers below"));
90
91 acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header);
92 acpi_tb_print_table_header(0, acpi_gbl_DSDT);
93
94 ACPI_ERROR((AE_INFO,
95 "Please send DMI info to linux-acpi@vger.kernel.org\n"
96 "If system does not work as expected, please boot with acpi=copy_dsdt"));
97
98 /* Disable further error messages */
99
100 acpi_gbl_original_dsdt_header.length = acpi_gbl_DSDT->length;
101 acpi_gbl_original_dsdt_header.checksum =
102 acpi_gbl_DSDT->checksum;
103 }
104}
105
106/*******************************************************************************
107 *
108 * FUNCTION: acpi_tb_copy_dsdt
109 *
110 * PARAMETERS: table_index - Index of installed table to copy
111 *
112 * RETURN: The copied DSDT
113 *
114 * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory.
115 * Some very bad BIOSs are known to either corrupt the DSDT or
116 * install a new, bad DSDT. This copy works around the problem.
117 *
118 ******************************************************************************/
119
120struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index)
121{
122 struct acpi_table_header *new_table;
123 struct acpi_table_desc *table_desc;
124
125 table_desc = &acpi_gbl_root_table_list.tables[table_index];
126
127 new_table = ACPI_ALLOCATE(table_desc->length);
128 if (!new_table) {
129 ACPI_ERROR((AE_INFO, "Could not copy DSDT of length 0x%X",
130 table_desc->length));
131 return (NULL);
132 }
133
134 memcpy(new_table, table_desc->pointer, table_desc->length);
135 acpi_tb_uninstall_table(table_desc);
136
137 acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.
138 tables[acpi_gbl_dsdt_index],
139 ACPI_PTR_TO_PHYSADDR(new_table),
140 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL,
141 new_table);
142
143 ACPI_INFO(("Forced DSDT copy: length 0x%05X copied locally, original unmapped", new_table->length));
144
145 return (new_table);
146}
147
148/*******************************************************************************
149 *
150 * FUNCTION: acpi_tb_get_root_table_entry
151 *
152 * PARAMETERS: table_entry - Pointer to the RSDT/XSDT table entry
153 * table_entry_size - sizeof 32 or 64 (RSDT or XSDT)
154 *
155 * RETURN: Physical address extracted from the root table
156 *
157 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
158 * both 32-bit and 64-bit platforms
159 *
160 * NOTE: acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
161 * 64-bit platforms.
162 *
163 ******************************************************************************/
164
165static acpi_physical_address
166acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
167{
168 u32 address32;
169 u64 address64;
170
171 /*
172 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
173 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
174 */
175 if (table_entry_size == ACPI_RSDT_ENTRY_SIZE) {
176 /*
177 * 32-bit platform, RSDT: Return 32-bit table entry
178 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
179 */
180 ACPI_MOVE_32_TO_32(&address32, table_entry);
181 return address32;
182 } else {
183 /*
184 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
185 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
186 * return 64-bit
187 */
188 ACPI_MOVE_64_TO_64(&address64, table_entry);
189
190#if ACPI_MACHINE_WIDTH == 32
191 if (address64 > ACPI_UINT32_MAX) {
192
193 /* Will truncate 64-bit address to 32 bits, issue warning */
194
195 ACPI_BIOS_WARNING((AE_INFO,
196 "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
197 " truncating",
198 ACPI_FORMAT_UINT64(address64)));
199 }
200#endif
201 return ((acpi_physical_address)(address64));
202 }
203}
204
205/*******************************************************************************
206 *
207 * FUNCTION: acpi_tb_parse_root_table
208 *
209 * PARAMETERS: rsdp_address - Pointer to the RSDP
210 *
211 * RETURN: Status
212 *
213 * DESCRIPTION: This function is called to parse the Root System Description
214 * Table (RSDT or XSDT)
215 *
216 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
217 * be mapped and cannot be copied because it contains the actual
218 * memory location of the ACPI Global Lock.
219 *
220 ******************************************************************************/
221
222acpi_status ACPI_INIT_FUNCTION
223acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
224{
225 struct acpi_table_rsdp *rsdp;
226 u32 table_entry_size;
227 u32 i;
228 u32 table_count;
229 struct acpi_table_header *table;
230 acpi_physical_address address;
231 u32 length;
232 u8 *table_entry;
233 acpi_status status;
234 u32 table_index;
235
236 ACPI_FUNCTION_TRACE(tb_parse_root_table);
237
238 /* Map the entire RSDP and extract the address of the RSDT or XSDT */
239
240 rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp));
241 if (!rsdp) {
242 return_ACPI_STATUS(AE_NO_MEMORY);
243 }
244
245 acpi_tb_print_table_header(rsdp_address,
246 ACPI_CAST_PTR(struct acpi_table_header,
247 rsdp));
248
249 /* Use XSDT if present and not overridden. Otherwise, use RSDT */
250
251 if ((rsdp->revision > 1) &&
252 rsdp->xsdt_physical_address && !acpi_gbl_do_not_use_xsdt) {
253 /*
254 * RSDP contains an XSDT (64-bit physical addresses). We must use
255 * the XSDT if the revision is > 1 and the XSDT pointer is present,
256 * as per the ACPI specification.
257 */
258 address = (acpi_physical_address)rsdp->xsdt_physical_address;
259 table_entry_size = ACPI_XSDT_ENTRY_SIZE;
260 } else {
261 /* Root table is an RSDT (32-bit physical addresses) */
262
263 address = (acpi_physical_address)rsdp->rsdt_physical_address;
264 table_entry_size = ACPI_RSDT_ENTRY_SIZE;
265 }
266
267 /*
268 * It is not possible to map more than one entry in some environments,
269 * so unmap the RSDP here before mapping other tables
270 */
271 acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp));
272
273 /* Map the RSDT/XSDT table header to get the full table length */
274
275 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
276 if (!table) {
277 return_ACPI_STATUS(AE_NO_MEMORY);
278 }
279
280 acpi_tb_print_table_header(address, table);
281
282 /*
283 * Validate length of the table, and map entire table.
284 * Minimum length table must contain at least one entry.
285 */
286 length = table->length;
287 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
288
289 if (length < (sizeof(struct acpi_table_header) + table_entry_size)) {
290 ACPI_BIOS_ERROR((AE_INFO,
291 "Invalid table length 0x%X in RSDT/XSDT",
292 length));
293 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
294 }
295
296 table = acpi_os_map_memory(address, length);
297 if (!table) {
298 return_ACPI_STATUS(AE_NO_MEMORY);
299 }
300
301 /* Validate the root table checksum */
302
303 status = acpi_ut_verify_checksum(table, length);
304 if (ACPI_FAILURE(status)) {
305 acpi_os_unmap_memory(table, length);
306 return_ACPI_STATUS(status);
307 }
308
309 /* Get the number of entries and pointer to first entry */
310
311 table_count = (u32)((table->length - sizeof(struct acpi_table_header)) /
312 table_entry_size);
313 table_entry = ACPI_ADD_PTR(u8, table, sizeof(struct acpi_table_header));
314
315 /* Initialize the root table array from the RSDT/XSDT */
316
317 for (i = 0; i < table_count; i++) {
318
319 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
320
321 address =
322 acpi_tb_get_root_table_entry(table_entry, table_entry_size);
323
324 /* Skip NULL entries in RSDT/XSDT */
325
326 if (!address) {
327 goto next_table;
328 }
329
330 status = acpi_tb_install_standard_table(address,
331 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL,
332 NULL, FALSE, TRUE,
333 &table_index);
334
335 if (ACPI_SUCCESS(status) &&
336 ACPI_COMPARE_NAMESEG(&acpi_gbl_root_table_list.
337 tables[table_index].signature,
338 ACPI_SIG_FADT)) {
339 acpi_gbl_fadt_index = table_index;
340 acpi_tb_parse_fadt();
341 }
342
343next_table:
344
345 table_entry += table_entry_size;
346 }
347
348 acpi_os_unmap_memory(table, length);
349 return_ACPI_STATUS(AE_OK);
350}
351
352/*******************************************************************************
353 *
354 * FUNCTION: acpi_tb_get_table
355 *
356 * PARAMETERS: table_desc - Table descriptor
357 * out_table - Where the pointer to the table is returned
358 *
359 * RETURN: Status and pointer to the requested table
360 *
361 * DESCRIPTION: Increase a reference to a table descriptor and return the
362 * validated table pointer.
363 * If the table descriptor is an entry of the root table list,
364 * this API must be invoked with ACPI_MTX_TABLES acquired.
365 *
366 ******************************************************************************/
367
368acpi_status
369acpi_tb_get_table(struct acpi_table_desc *table_desc,
370 struct acpi_table_header **out_table)
371{
372 acpi_status status;
373
374 ACPI_FUNCTION_TRACE(acpi_tb_get_table);
375
376 if (table_desc->validation_count == 0) {
377
378 /* Table need to be "VALIDATED" */
379
380 status = acpi_tb_validate_table(table_desc);
381 if (ACPI_FAILURE(status)) {
382 return_ACPI_STATUS(status);
383 }
384 }
385
386 if (table_desc->validation_count < ACPI_MAX_TABLE_VALIDATIONS) {
387 table_desc->validation_count++;
388
389 /*
390 * Detect validation_count overflows to ensure that the warning
391 * message will only be printed once.
392 */
393 if (table_desc->validation_count >= ACPI_MAX_TABLE_VALIDATIONS) {
394 ACPI_WARNING((AE_INFO,
395 "Table %p, Validation count overflows\n",
396 table_desc));
397 }
398 }
399
400 *out_table = table_desc->pointer;
401 return_ACPI_STATUS(AE_OK);
402}
403
404/*******************************************************************************
405 *
406 * FUNCTION: acpi_tb_put_table
407 *
408 * PARAMETERS: table_desc - Table descriptor
409 *
410 * RETURN: None
411 *
412 * DESCRIPTION: Decrease a reference to a table descriptor and release the
413 * validated table pointer if no references.
414 * If the table descriptor is an entry of the root table list,
415 * this API must be invoked with ACPI_MTX_TABLES acquired.
416 *
417 ******************************************************************************/
418
419void acpi_tb_put_table(struct acpi_table_desc *table_desc)
420{
421
422 ACPI_FUNCTION_TRACE(acpi_tb_put_table);
423
424 if (table_desc->validation_count < ACPI_MAX_TABLE_VALIDATIONS) {
425 table_desc->validation_count--;
426
427 /*
428 * Detect validation_count underflows to ensure that the warning
429 * message will only be printed once.
430 */
431 if (table_desc->validation_count >= ACPI_MAX_TABLE_VALIDATIONS) {
432 ACPI_WARNING((AE_INFO,
433 "Table %p, Validation count underflows\n",
434 table_desc));
435 return_VOID;
436 }
437 }
438
439 if (table_desc->validation_count == 0) {
440
441 /* Table need to be "INVALIDATED" */
442
443 acpi_tb_invalidate_table(table_desc);
444 }
445
446 return_VOID;
447}