1 /******************************************************************************
3 * Module Name: tbget - ACPI Table get* routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2005, 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 ("tbget")
53 /*******************************************************************************
55 * FUNCTION: acpi_tb_get_table
57 * PARAMETERS: Address - Address of table to retrieve. Can be
59 * table_info - Where table info is returned
63 * DESCRIPTION: Get entire table of unknown size.
65 ******************************************************************************/
69 struct acpi_pointer
*address
,
70 struct acpi_table_desc
*table_info
)
73 struct acpi_table_header header
;
76 ACPI_FUNCTION_TRACE ("tb_get_table");
80 * Get the header in order to get signature and table size
82 status
= acpi_tb_get_table_header (address
, &header
);
83 if (ACPI_FAILURE (status
)) {
84 return_ACPI_STATUS (status
);
87 /* Get the entire table */
89 status
= acpi_tb_get_table_body (address
, &header
, table_info
);
90 if (ACPI_FAILURE (status
)) {
91 ACPI_REPORT_ERROR (("Could not get ACPI table (size %X), %s\n",
92 header
.length
, acpi_format_exception (status
)));
93 return_ACPI_STATUS (status
);
96 return_ACPI_STATUS (AE_OK
);
100 /*******************************************************************************
102 * FUNCTION: acpi_tb_get_table_header
104 * PARAMETERS: Address - Address of table to retrieve. Can be
105 * Logical or Physical
106 * return_header - Where the table header is returned
110 * DESCRIPTION: Get an ACPI table header. Works in both physical or virtual
111 * addressing mode. Works with both physical or logical pointers.
112 * Table is either copied or mapped, depending on the pointer
113 * type and mode of the processor.
115 ******************************************************************************/
118 acpi_tb_get_table_header (
119 struct acpi_pointer
*address
,
120 struct acpi_table_header
*return_header
)
122 acpi_status status
= AE_OK
;
123 struct acpi_table_header
*header
= NULL
;
126 ACPI_FUNCTION_TRACE ("tb_get_table_header");
130 * Flags contains the current processor mode (Virtual or Physical addressing)
131 * The pointer_type is either Logical or Physical
133 switch (address
->pointer_type
) {
134 case ACPI_PHYSMODE_PHYSPTR
:
135 case ACPI_LOGMODE_LOGPTR
:
137 /* Pointer matches processor mode, copy the header */
139 ACPI_MEMCPY (return_header
, address
->pointer
.logical
, sizeof (struct acpi_table_header
));
143 case ACPI_LOGMODE_PHYSPTR
:
145 /* Create a logical address for the physical pointer*/
147 status
= acpi_os_map_memory (address
->pointer
.physical
, sizeof (struct acpi_table_header
),
149 if (ACPI_FAILURE (status
)) {
150 ACPI_REPORT_ERROR (("Could not map memory at %8.8X%8.8X for length %X\n",
151 ACPI_FORMAT_UINT64 (address
->pointer
.physical
),
152 sizeof (struct acpi_table_header
)));
153 return_ACPI_STATUS (status
);
156 /* Copy header and delete mapping */
158 ACPI_MEMCPY (return_header
, header
, sizeof (struct acpi_table_header
));
159 acpi_os_unmap_memory (header
, sizeof (struct acpi_table_header
));
165 ACPI_REPORT_ERROR (("Invalid address flags %X\n",
166 address
->pointer_type
));
167 return_ACPI_STATUS (AE_BAD_PARAMETER
);
170 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES
, "Table Signature: [%4.4s]\n",
171 return_header
->signature
));
173 return_ACPI_STATUS (AE_OK
);
177 /*******************************************************************************
179 * FUNCTION: acpi_tb_get_table_body
181 * PARAMETERS: Address - Address of table to retrieve. Can be
182 * Logical or Physical
183 * Header - Header of the table to retrieve
184 * table_info - Where the table info is returned
188 * DESCRIPTION: Get an entire ACPI table with support to allow the host OS to
189 * replace the table with a newer version (table override.)
190 * Works in both physical or virtual
191 * addressing mode. Works with both physical or logical pointers.
192 * Table is either copied or mapped, depending on the pointer
193 * type and mode of the processor.
195 ******************************************************************************/
198 acpi_tb_get_table_body (
199 struct acpi_pointer
*address
,
200 struct acpi_table_header
*header
,
201 struct acpi_table_desc
*table_info
)
206 ACPI_FUNCTION_TRACE ("tb_get_table_body");
209 if (!table_info
|| !address
) {
210 return_ACPI_STATUS (AE_BAD_PARAMETER
);
214 * Attempt table override.
216 status
= acpi_tb_table_override (header
, table_info
);
217 if (ACPI_SUCCESS (status
)) {
218 /* Table was overridden by the host OS */
220 return_ACPI_STATUS (status
);
223 /* No override, get the original table */
225 status
= acpi_tb_get_this_table (address
, header
, table_info
);
226 return_ACPI_STATUS (status
);
230 /*******************************************************************************
232 * FUNCTION: acpi_tb_table_override
234 * PARAMETERS: Header - Pointer to table header
235 * table_info - Return info if table is overridden
239 * DESCRIPTION: Attempts override of current table with a new one if provided
242 ******************************************************************************/
245 acpi_tb_table_override (
246 struct acpi_table_header
*header
,
247 struct acpi_table_desc
*table_info
)
249 struct acpi_table_header
*new_table
;
251 struct acpi_pointer address
;
254 ACPI_FUNCTION_TRACE ("tb_table_override");
258 * The OSL will examine the header and decide whether to override this
259 * table. If it decides to override, a table will be returned in new_table,
260 * which we will then copy.
262 status
= acpi_os_table_override (header
, &new_table
);
263 if (ACPI_FAILURE (status
)) {
264 /* Some severe error from the OSL, but we basically ignore it */
266 ACPI_REPORT_ERROR (("Could not override ACPI table, %s\n",
267 acpi_format_exception (status
)));
268 return_ACPI_STATUS (status
);
272 /* No table override */
274 return_ACPI_STATUS (AE_NO_ACPI_TABLES
);
278 * We have a new table to override the old one. Get a copy of
279 * the new one. We know that the new table has a logical pointer.
281 address
.pointer_type
= ACPI_LOGICAL_POINTER
| ACPI_LOGICAL_ADDRESSING
;
282 address
.pointer
.logical
= new_table
;
284 status
= acpi_tb_get_this_table (&address
, new_table
, table_info
);
285 if (ACPI_FAILURE (status
)) {
286 ACPI_REPORT_ERROR (("Could not copy override ACPI table, %s\n",
287 acpi_format_exception (status
)));
288 return_ACPI_STATUS (status
);
291 /* Copy the table info */
293 ACPI_REPORT_INFO (("Table [%4.4s] replaced by host OS\n",
294 table_info
->pointer
->signature
));
296 return_ACPI_STATUS (AE_OK
);
300 /*******************************************************************************
302 * FUNCTION: acpi_tb_get_this_table
304 * PARAMETERS: Address - Address of table to retrieve. Can be
305 * Logical or Physical
306 * Header - Header of the table to retrieve
307 * table_info - Where the table info is returned
311 * DESCRIPTION: Get an entire ACPI table. Works in both physical or virtual
312 * addressing mode. Works with both physical or logical pointers.
313 * Table is either copied or mapped, depending on the pointer
314 * type and mode of the processor.
316 ******************************************************************************/
319 acpi_tb_get_this_table (
320 struct acpi_pointer
*address
,
321 struct acpi_table_header
*header
,
322 struct acpi_table_desc
*table_info
)
324 struct acpi_table_header
*full_table
= NULL
;
326 acpi_status status
= AE_OK
;
329 ACPI_FUNCTION_TRACE ("tb_get_this_table");
333 * Flags contains the current processor mode (Virtual or Physical addressing)
334 * The pointer_type is either Logical or Physical
336 switch (address
->pointer_type
) {
337 case ACPI_PHYSMODE_PHYSPTR
:
338 case ACPI_LOGMODE_LOGPTR
:
340 /* Pointer matches processor mode, copy the table to a new buffer */
342 full_table
= ACPI_MEM_ALLOCATE (header
->length
);
344 ACPI_REPORT_ERROR (("Could not allocate table memory for [%4.4s] length %X\n",
345 header
->signature
, header
->length
));
346 return_ACPI_STATUS (AE_NO_MEMORY
);
349 /* Copy the entire table (including header) to the local buffer */
351 ACPI_MEMCPY (full_table
, address
->pointer
.logical
, header
->length
);
353 /* Save allocation type */
355 allocation
= ACPI_MEM_ALLOCATED
;
359 case ACPI_LOGMODE_PHYSPTR
:
362 * Just map the table's physical memory
363 * into our address space.
365 status
= acpi_os_map_memory (address
->pointer
.physical
, (acpi_size
) header
->length
,
366 (void *) &full_table
);
367 if (ACPI_FAILURE (status
)) {
368 ACPI_REPORT_ERROR (("Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X\n",
370 ACPI_FORMAT_UINT64 (address
->pointer
.physical
), header
->length
));
374 /* Save allocation type */
376 allocation
= ACPI_MEM_MAPPED
;
382 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Invalid address flags %X\n",
383 address
->pointer_type
));
384 return_ACPI_STATUS (AE_BAD_PARAMETER
);
388 * Validate checksum for _most_ tables,
389 * even the ones whose signature we don't recognize
391 if (table_info
->type
!= ACPI_TABLE_FACS
) {
392 status
= acpi_tb_verify_table_checksum (full_table
);
394 #if (!ACPI_CHECKSUM_ABORT)
395 if (ACPI_FAILURE (status
)) {
396 /* Ignore the error if configuration says so */
405 table_info
->pointer
= full_table
;
406 table_info
->length
= (acpi_size
) header
->length
;
407 table_info
->allocation
= allocation
;
409 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
410 "Found table [%4.4s] at %8.8X%8.8X, mapped/copied to %p\n",
411 full_table
->signature
,
412 ACPI_FORMAT_UINT64 (address
->pointer
.physical
), full_table
));
414 return_ACPI_STATUS (status
);
418 /*******************************************************************************
420 * FUNCTION: acpi_tb_get_table_ptr
422 * PARAMETERS: table_type - one of the defined table types
423 * Instance - Which table of this type
424 * table_ptr_loc - pointer to location to place the pointer for
429 * DESCRIPTION: This function is called to get the pointer to an ACPI table.
431 ******************************************************************************/
434 acpi_tb_get_table_ptr (
435 acpi_table_type table_type
,
437 struct acpi_table_header
**table_ptr_loc
)
439 struct acpi_table_desc
*table_desc
;
443 ACPI_FUNCTION_TRACE ("tb_get_table_ptr");
446 if (!acpi_gbl_DSDT
) {
447 return_ACPI_STATUS (AE_NO_ACPI_TABLES
);
450 if (table_type
> ACPI_TABLE_MAX
) {
451 return_ACPI_STATUS (AE_BAD_PARAMETER
);
455 * For all table types (Single/Multiple), the first
456 * instance is always in the list head.
461 *table_ptr_loc
= NULL
;
462 if (acpi_gbl_table_lists
[table_type
].next
) {
463 *table_ptr_loc
= acpi_gbl_table_lists
[table_type
].next
->pointer
;
465 return_ACPI_STATUS (AE_OK
);
469 * Check for instance out of range
471 if (instance
> acpi_gbl_table_lists
[table_type
].count
) {
472 return_ACPI_STATUS (AE_NOT_EXIST
);
475 /* Walk the list to get the desired table
476 * Since the if (Instance == 1) check above checked for the
477 * first table, setting table_desc equal to the .Next member
478 * is actually pointing to the second table. Therefore, we
479 * need to walk from the 2nd table until we reach the Instance
480 * that the user is looking for and return its table pointer.
482 table_desc
= acpi_gbl_table_lists
[table_type
].next
;
483 for (i
= 2; i
< instance
; i
++) {
484 table_desc
= table_desc
->next
;
487 /* We are now pointing to the requested table's descriptor */
489 *table_ptr_loc
= table_desc
->pointer
;
491 return_ACPI_STATUS (AE_OK
);