1 /******************************************************************************
3 * Module Name: tbget - ACPI Table get* routines
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
120 #include "actables.h"
123 #define _COMPONENT ACPI_TABLES
124 ACPI_MODULE_NAME ("tbget")
127 /*******************************************************************************
129 * FUNCTION: AcpiTbGetTable
131 * PARAMETERS: Address - Address of table to retrieve. Can be
132 * Logical or Physical
133 * TableInfo - Where table info is returned
137 * DESCRIPTION: Get entire table of unknown size.
139 ******************************************************************************/
143 ACPI_POINTER
*Address
,
144 ACPI_TABLE_DESC
*TableInfo
)
147 ACPI_TABLE_HEADER Header
;
150 ACPI_FUNCTION_TRACE ("TbGetTable");
154 * Get the header in order to get signature and table size
156 Status
= AcpiTbGetTableHeader (Address
, &Header
);
157 if (ACPI_FAILURE (Status
))
159 return_ACPI_STATUS (Status
);
162 /* Get the entire table */
164 Status
= AcpiTbGetTableBody (Address
, &Header
, TableInfo
);
165 if (ACPI_FAILURE (Status
))
167 ACPI_REPORT_ERROR (("Could not get ACPI table (size %X), %s\n",
168 Header
.Length
, AcpiFormatException (Status
)));
169 return_ACPI_STATUS (Status
);
172 return_ACPI_STATUS (AE_OK
);
176 /*******************************************************************************
178 * FUNCTION: AcpiTbGetTableHeader
180 * PARAMETERS: Address - Address of table to retrieve. Can be
181 * Logical or Physical
182 * ReturnHeader - Where the table header is returned
186 * DESCRIPTION: Get an ACPI table header. Works in both physical or virtual
187 * addressing mode. Works with both physical or logical pointers.
188 * Table is either copied or mapped, depending on the pointer
189 * type and mode of the processor.
191 ******************************************************************************/
194 AcpiTbGetTableHeader (
195 ACPI_POINTER
*Address
,
196 ACPI_TABLE_HEADER
*ReturnHeader
)
198 ACPI_STATUS Status
= AE_OK
;
199 ACPI_TABLE_HEADER
*Header
= NULL
;
202 ACPI_FUNCTION_TRACE ("TbGetTableHeader");
206 * Flags contains the current processor mode (Virtual or Physical addressing)
207 * The PointerType is either Logical or Physical
209 switch (Address
->PointerType
)
211 case ACPI_PHYSMODE_PHYSPTR
:
212 case ACPI_LOGMODE_LOGPTR
:
214 /* Pointer matches processor mode, copy the header */
216 ACPI_MEMCPY (ReturnHeader
, Address
->Pointer
.Logical
, sizeof (ACPI_TABLE_HEADER
));
220 case ACPI_LOGMODE_PHYSPTR
:
222 /* Create a logical address for the physical pointer*/
224 Status
= AcpiOsMapMemory (Address
->Pointer
.Physical
, sizeof (ACPI_TABLE_HEADER
),
226 if (ACPI_FAILURE (Status
))
228 ACPI_REPORT_ERROR (("Could not map memory at %8.8X%8.8X for length %X\n",
229 ACPI_FORMAT_UINT64 (Address
->Pointer
.Physical
),
230 sizeof (ACPI_TABLE_HEADER
)));
231 return_ACPI_STATUS (Status
);
234 /* Copy header and delete mapping */
236 ACPI_MEMCPY (ReturnHeader
, Header
, sizeof (ACPI_TABLE_HEADER
));
237 AcpiOsUnmapMemory (Header
, sizeof (ACPI_TABLE_HEADER
));
243 ACPI_REPORT_ERROR (("Invalid address flags %X\n",
244 Address
->PointerType
));
245 return_ACPI_STATUS (AE_BAD_PARAMETER
);
248 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES
, "Table Signature: [%4.4s]\n",
249 ReturnHeader
->Signature
));
251 return_ACPI_STATUS (AE_OK
);
255 /*******************************************************************************
257 * FUNCTION: AcpiTbGetTableBody
259 * PARAMETERS: Address - Address of table to retrieve. Can be
260 * Logical or Physical
261 * Header - Header of the table to retrieve
262 * TableInfo - Where the table info is returned
266 * DESCRIPTION: Get an entire ACPI table with support to allow the host OS to
267 * replace the table with a newer version (table override.)
268 * Works in both physical or virtual
269 * addressing mode. Works with both physical or logical pointers.
270 * Table is either copied or mapped, depending on the pointer
271 * type and mode of the processor.
273 ******************************************************************************/
277 ACPI_POINTER
*Address
,
278 ACPI_TABLE_HEADER
*Header
,
279 ACPI_TABLE_DESC
*TableInfo
)
284 ACPI_FUNCTION_TRACE ("TbGetTableBody");
287 if (!TableInfo
|| !Address
)
289 return_ACPI_STATUS (AE_BAD_PARAMETER
);
293 * Attempt table override.
295 Status
= AcpiTbTableOverride (Header
, TableInfo
);
296 if (ACPI_SUCCESS (Status
))
298 /* Table was overridden by the host OS */
300 return_ACPI_STATUS (Status
);
303 /* No override, get the original table */
305 Status
= AcpiTbGetThisTable (Address
, Header
, TableInfo
);
306 return_ACPI_STATUS (Status
);
310 /*******************************************************************************
312 * FUNCTION: AcpiTbTableOverride
314 * PARAMETERS: Header - Pointer to table header
315 * TableInfo - Return info if table is overridden
319 * DESCRIPTION: Attempts override of current table with a new one if provided
322 ******************************************************************************/
325 AcpiTbTableOverride (
326 ACPI_TABLE_HEADER
*Header
,
327 ACPI_TABLE_DESC
*TableInfo
)
329 ACPI_TABLE_HEADER
*NewTable
;
331 ACPI_POINTER Address
;
334 ACPI_FUNCTION_TRACE ("TbTableOverride");
338 * The OSL will examine the header and decide whether to override this
339 * table. If it decides to override, a table will be returned in NewTable,
340 * which we will then copy.
342 Status
= AcpiOsTableOverride (Header
, &NewTable
);
343 if (ACPI_FAILURE (Status
))
345 /* Some severe error from the OSL, but we basically ignore it */
347 ACPI_REPORT_ERROR (("Could not override ACPI table, %s\n",
348 AcpiFormatException (Status
)));
349 return_ACPI_STATUS (Status
);
354 /* No table override */
356 return_ACPI_STATUS (AE_NO_ACPI_TABLES
);
360 * We have a new table to override the old one. Get a copy of
361 * the new one. We know that the new table has a logical pointer.
363 Address
.PointerType
= ACPI_LOGICAL_POINTER
| ACPI_LOGICAL_ADDRESSING
;
364 Address
.Pointer
.Logical
= NewTable
;
366 Status
= AcpiTbGetThisTable (&Address
, NewTable
, TableInfo
);
367 if (ACPI_FAILURE (Status
))
369 ACPI_REPORT_ERROR (("Could not copy override ACPI table, %s\n",
370 AcpiFormatException (Status
)));
371 return_ACPI_STATUS (Status
);
374 /* Copy the table info */
376 ACPI_REPORT_INFO (("Table [%4.4s] replaced by host OS\n",
377 TableInfo
->Pointer
->Signature
));
379 return_ACPI_STATUS (AE_OK
);
383 /*******************************************************************************
385 * FUNCTION: AcpiTbGetThisTable
387 * PARAMETERS: Address - Address of table to retrieve. Can be
388 * Logical or Physical
389 * Header - Header of the table to retrieve
390 * TableInfo - Where the table info is returned
394 * DESCRIPTION: Get an entire ACPI table. Works in both physical or virtual
395 * addressing mode. Works with both physical or logical pointers.
396 * Table is either copied or mapped, depending on the pointer
397 * type and mode of the processor.
399 ******************************************************************************/
403 ACPI_POINTER
*Address
,
404 ACPI_TABLE_HEADER
*Header
,
405 ACPI_TABLE_DESC
*TableInfo
)
407 ACPI_TABLE_HEADER
*FullTable
= NULL
;
409 ACPI_STATUS Status
= AE_OK
;
412 ACPI_FUNCTION_TRACE ("TbGetThisTable");
416 * Flags contains the current processor mode (Virtual or Physical addressing)
417 * The PointerType is either Logical or Physical
419 switch (Address
->PointerType
)
421 case ACPI_PHYSMODE_PHYSPTR
:
422 case ACPI_LOGMODE_LOGPTR
:
424 /* Pointer matches processor mode, copy the table to a new buffer */
426 FullTable
= ACPI_MEM_ALLOCATE (Header
->Length
);
429 ACPI_REPORT_ERROR (("Could not allocate table memory for [%4.4s] length %X\n",
430 Header
->Signature
, Header
->Length
));
431 return_ACPI_STATUS (AE_NO_MEMORY
);
434 /* Copy the entire table (including header) to the local buffer */
436 ACPI_MEMCPY (FullTable
, Address
->Pointer
.Logical
, Header
->Length
);
438 /* Save allocation type */
440 Allocation
= ACPI_MEM_ALLOCATED
;
444 case ACPI_LOGMODE_PHYSPTR
:
447 * Just map the table's physical memory
448 * into our address space.
450 Status
= AcpiOsMapMemory (Address
->Pointer
.Physical
, (ACPI_SIZE
) Header
->Length
,
451 (void *) &FullTable
);
452 if (ACPI_FAILURE (Status
))
454 ACPI_REPORT_ERROR (("Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X\n",
456 ACPI_FORMAT_UINT64 (Address
->Pointer
.Physical
), Header
->Length
));
460 /* Save allocation type */
462 Allocation
= ACPI_MEM_MAPPED
;
468 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Invalid address flags %X\n",
469 Address
->PointerType
));
470 return_ACPI_STATUS (AE_BAD_PARAMETER
);
474 * Validate checksum for _most_ tables,
475 * even the ones whose signature we don't recognize
477 if (TableInfo
->Type
!= ACPI_TABLE_FACS
)
479 Status
= AcpiTbVerifyTableChecksum (FullTable
);
481 #if (!ACPI_CHECKSUM_ABORT)
482 if (ACPI_FAILURE (Status
))
484 /* Ignore the error if configuration says so */
493 TableInfo
->Pointer
= FullTable
;
494 TableInfo
->Length
= (ACPI_SIZE
) Header
->Length
;
495 TableInfo
->Allocation
= Allocation
;
497 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
498 "Found table [%4.4s] at %8.8X%8.8X, mapped/copied to %p\n",
499 FullTable
->Signature
,
500 ACPI_FORMAT_UINT64 (Address
->Pointer
.Physical
), FullTable
));
502 return_ACPI_STATUS (Status
);
506 /*******************************************************************************
508 * FUNCTION: AcpiTbGetTablePtr
510 * PARAMETERS: TableType - one of the defined table types
511 * Instance - Which table of this type
512 * TablePtrLoc - pointer to location to place the pointer for
517 * DESCRIPTION: This function is called to get the pointer to an ACPI table.
519 ******************************************************************************/
523 ACPI_TABLE_TYPE TableType
,
525 ACPI_TABLE_HEADER
**TablePtrLoc
)
527 ACPI_TABLE_DESC
*TableDesc
;
531 ACPI_FUNCTION_TRACE ("TbGetTablePtr");
536 return_ACPI_STATUS (AE_NO_ACPI_TABLES
);
539 if (TableType
> ACPI_TABLE_MAX
)
541 return_ACPI_STATUS (AE_BAD_PARAMETER
);
545 * For all table types (Single/Multiple), the first
546 * instance is always in the list head.
553 if (AcpiGbl_TableLists
[TableType
].Next
)
555 *TablePtrLoc
= AcpiGbl_TableLists
[TableType
].Next
->Pointer
;
557 return_ACPI_STATUS (AE_OK
);
561 * Check for instance out of range
563 if (Instance
> AcpiGbl_TableLists
[TableType
].Count
)
565 return_ACPI_STATUS (AE_NOT_EXIST
);
568 /* Walk the list to get the desired table
569 * Since the if (Instance == 1) check above checked for the
570 * first table, setting TableDesc equal to the .Next member
571 * is actually pointing to the second table. Therefore, we
572 * need to walk from the 2nd table until we reach the Instance
573 * that the user is looking for and return its table pointer.
575 TableDesc
= AcpiGbl_TableLists
[TableType
].Next
;
576 for (i
= 2; i
< Instance
; i
++)
578 TableDesc
= TableDesc
->Next
;
581 /* We are now pointing to the requested table's descriptor */
583 *TablePtrLoc
= TableDesc
->Pointer
;
585 return_ACPI_STATUS (AE_OK
);