1 /******************************************************************************
3 * Module Name: tbget - ACPI Table get* routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2004, 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 return_ACPI_STATUS (AE_OK
);
174 /*******************************************************************************
176 * FUNCTION: acpi_tb_get_table_body
178 * PARAMETERS: Address - Address of table to retrieve. Can be
179 * Logical or Physical
180 * Header - Header of the table to retrieve
181 * table_info - Where the table info is returned
185 * DESCRIPTION: Get an entire ACPI table with support to allow the host OS to
186 * replace the table with a newer version (table override.)
187 * Works in both physical or virtual
188 * addressing mode. Works with both physical or logical pointers.
189 * Table is either copied or mapped, depending on the pointer
190 * type and mode of the processor.
192 ******************************************************************************/
195 acpi_tb_get_table_body (
196 struct acpi_pointer
*address
,
197 struct acpi_table_header
*header
,
198 struct acpi_table_desc
*table_info
)
203 ACPI_FUNCTION_TRACE ("tb_get_table_body");
206 if (!table_info
|| !address
) {
207 return_ACPI_STATUS (AE_BAD_PARAMETER
);
211 * Attempt table override.
213 status
= acpi_tb_table_override (header
, table_info
);
214 if (ACPI_SUCCESS (status
)) {
215 /* Table was overridden by the host OS */
217 return_ACPI_STATUS (status
);
220 /* No override, get the original table */
222 status
= acpi_tb_get_this_table (address
, header
, table_info
);
223 return_ACPI_STATUS (status
);
227 /*******************************************************************************
229 * FUNCTION: acpi_tb_table_override
231 * PARAMETERS: Header - Pointer to table header
232 * table_info - Return info if table is overridden
236 * DESCRIPTION: Attempts override of current table with a new one if provided
239 ******************************************************************************/
242 acpi_tb_table_override (
243 struct acpi_table_header
*header
,
244 struct acpi_table_desc
*table_info
)
246 struct acpi_table_header
*new_table
;
248 struct acpi_pointer address
;
251 ACPI_FUNCTION_TRACE ("tb_table_override");
255 * The OSL will examine the header and decide whether to override this
256 * table. If it decides to override, a table will be returned in new_table,
257 * which we will then copy.
259 status
= acpi_os_table_override (header
, &new_table
);
260 if (ACPI_FAILURE (status
)) {
261 /* Some severe error from the OSL, but we basically ignore it */
263 ACPI_REPORT_ERROR (("Could not override ACPI table, %s\n",
264 acpi_format_exception (status
)));
265 return_ACPI_STATUS (status
);
269 /* No table override */
271 return_ACPI_STATUS (AE_NO_ACPI_TABLES
);
275 * We have a new table to override the old one. Get a copy of
276 * the new one. We know that the new table has a logical pointer.
278 address
.pointer_type
= ACPI_LOGICAL_POINTER
| ACPI_LOGICAL_ADDRESSING
;
279 address
.pointer
.logical
= new_table
;
281 status
= acpi_tb_get_this_table (&address
, new_table
, table_info
);
282 if (ACPI_FAILURE (status
)) {
283 ACPI_REPORT_ERROR (("Could not copy override ACPI table, %s\n",
284 acpi_format_exception (status
)));
285 return_ACPI_STATUS (status
);
288 /* Copy the table info */
290 ACPI_REPORT_INFO (("Table [%4.4s] replaced by host OS\n",
291 table_info
->pointer
->signature
));
293 return_ACPI_STATUS (AE_OK
);
297 /*******************************************************************************
299 * FUNCTION: acpi_tb_get_this_table
301 * PARAMETERS: Address - Address of table to retrieve. Can be
302 * Logical or Physical
303 * Header - Header of the table to retrieve
304 * table_info - Where the table info is returned
308 * DESCRIPTION: Get an entire ACPI table. Works in both physical or virtual
309 * addressing mode. Works with both physical or logical pointers.
310 * Table is either copied or mapped, depending on the pointer
311 * type and mode of the processor.
313 ******************************************************************************/
316 acpi_tb_get_this_table (
317 struct acpi_pointer
*address
,
318 struct acpi_table_header
*header
,
319 struct acpi_table_desc
*table_info
)
321 struct acpi_table_header
*full_table
= NULL
;
323 acpi_status status
= AE_OK
;
326 ACPI_FUNCTION_TRACE ("tb_get_this_table");
330 * Flags contains the current processor mode (Virtual or Physical addressing)
331 * The pointer_type is either Logical or Physical
333 switch (address
->pointer_type
) {
334 case ACPI_PHYSMODE_PHYSPTR
:
335 case ACPI_LOGMODE_LOGPTR
:
337 /* Pointer matches processor mode, copy the table to a new buffer */
339 full_table
= ACPI_MEM_ALLOCATE (header
->length
);
341 ACPI_REPORT_ERROR (("Could not allocate table memory for [%4.4s] length %X\n",
342 header
->signature
, header
->length
));
343 return_ACPI_STATUS (AE_NO_MEMORY
);
346 /* Copy the entire table (including header) to the local buffer */
348 ACPI_MEMCPY (full_table
, address
->pointer
.logical
, header
->length
);
350 /* Save allocation type */
352 allocation
= ACPI_MEM_ALLOCATED
;
356 case ACPI_LOGMODE_PHYSPTR
:
359 * Just map the table's physical memory
360 * into our address space.
362 status
= acpi_os_map_memory (address
->pointer
.physical
, (acpi_size
) header
->length
,
363 (void *) &full_table
);
364 if (ACPI_FAILURE (status
)) {
365 ACPI_REPORT_ERROR (("Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X\n",
367 ACPI_FORMAT_UINT64 (address
->pointer
.physical
), header
->length
));
371 /* Save allocation type */
373 allocation
= ACPI_MEM_MAPPED
;
379 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Invalid address flags %X\n",
380 address
->pointer_type
));
381 return_ACPI_STATUS (AE_BAD_PARAMETER
);
385 * Validate checksum for _most_ tables,
386 * even the ones whose signature we don't recognize
388 if (table_info
->type
!= ACPI_TABLE_FACS
) {
389 status
= acpi_tb_verify_table_checksum (full_table
);
391 #if (!ACPI_CHECKSUM_ABORT)
392 if (ACPI_FAILURE (status
)) {
393 /* Ignore the error if configuration says so */
402 table_info
->pointer
= full_table
;
403 table_info
->length
= (acpi_size
) header
->length
;
404 table_info
->allocation
= allocation
;
406 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
407 "Found table [%4.4s] at %8.8X%8.8X, mapped/copied to %p\n",
408 full_table
->signature
,
409 ACPI_FORMAT_UINT64 (address
->pointer
.physical
), full_table
));
411 return_ACPI_STATUS (status
);
415 /*******************************************************************************
417 * FUNCTION: acpi_tb_get_table_ptr
419 * PARAMETERS: table_type - one of the defined table types
420 * Instance - Which table of this type
421 * table_ptr_loc - pointer to location to place the pointer for
426 * DESCRIPTION: This function is called to get the pointer to an ACPI table.
428 ******************************************************************************/
431 acpi_tb_get_table_ptr (
432 acpi_table_type table_type
,
434 struct acpi_table_header
**table_ptr_loc
)
436 struct acpi_table_desc
*table_desc
;
440 ACPI_FUNCTION_TRACE ("tb_get_table_ptr");
443 if (!acpi_gbl_DSDT
) {
444 return_ACPI_STATUS (AE_NO_ACPI_TABLES
);
447 if (table_type
> ACPI_TABLE_MAX
) {
448 return_ACPI_STATUS (AE_BAD_PARAMETER
);
452 * For all table types (Single/Multiple), the first
453 * instance is always in the list head.
458 *table_ptr_loc
= NULL
;
459 if (acpi_gbl_table_lists
[table_type
].next
) {
460 *table_ptr_loc
= acpi_gbl_table_lists
[table_type
].next
->pointer
;
462 return_ACPI_STATUS (AE_OK
);
466 * Check for instance out of range
468 if (instance
> acpi_gbl_table_lists
[table_type
].count
) {
469 return_ACPI_STATUS (AE_NOT_EXIST
);
472 /* Walk the list to get the desired table
473 * Since the if (Instance == 1) check above checked for the
474 * first table, setting table_desc equal to the .Next member
475 * is actually pointing to the second table. Therefore, we
476 * need to walk from the 2nd table until we reach the Instance
477 * that the user is looking for and return its table pointer.
479 table_desc
= acpi_gbl_table_lists
[table_type
].next
;
480 for (i
= 2; i
< instance
; i
++) {
481 table_desc
= table_desc
->next
;
484 /* We are now pointing to the requested table's descriptor */
486 *table_ptr_loc
= table_desc
->pointer
;
488 return_ACPI_STATUS (AE_OK
);