1 /******************************************************************************
3 * Module Name: osbsdtbl - BSD OSL for obtaining ACPI tables
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include "acpidump.h"
154 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined (__DragonFly__)
158 #include <sys/param.h>
159 #include <sys/sysctl.h>
162 #define _COMPONENT ACPI_OS_SERVICES
163 ACPI_MODULE_NAME ("osbsdtbl")
166 /* Local prototypes */
176 ACPI_TABLE_HEADER
**Table
);
186 ACPI_TABLE_HEADER
**Table
,
187 ACPI_PHYSICAL_ADDRESS
*Address
);
191 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
192 #define SYSTEM_KENV "hint.acpi.0.rsdp"
193 #define SYSTEM_SYSCTL "machdep.acpi_root"
194 #elif defined(__NetBSD__)
195 #define SYSTEM_SYSCTL "hw.acpi.root"
198 /* Initialization flags */
200 UINT8 Gbl_TableListInitialized
= FALSE
;
201 UINT8 Gbl_MainTableObtained
= FALSE
;
203 /* Local copies of main ACPI tables */
205 ACPI_TABLE_RSDP Gbl_Rsdp
;
206 ACPI_TABLE_FADT
*Gbl_Fadt
;
207 ACPI_TABLE_RSDT
*Gbl_Rsdt
;
208 ACPI_TABLE_XSDT
*Gbl_Xsdt
;
212 ACPI_PHYSICAL_ADDRESS Gbl_FadtAddress
;
214 /* Revision of RSD PTR */
218 /* List of information about obtained ACPI tables */
220 typedef struct table_info
222 struct table_info
*Next
;
225 ACPI_PHYSICAL_ADDRESS Address
;
229 OSL_TABLE_INFO
*Gbl_TableListHead
= NULL
;
232 /******************************************************************************
234 * FUNCTION: AcpiOsGetTableByAddress
236 * PARAMETERS: Address - Physical address of the ACPI table
237 * Table - Where a pointer to the table is returned
239 * RETURN: Status; Table buffer is returned if AE_OK.
240 * AE_NOT_FOUND: A valid table was not found at the address
242 * DESCRIPTION: Get an ACPI table via a physical memory address.
244 *****************************************************************************/
247 AcpiOsGetTableByAddress (
248 ACPI_PHYSICAL_ADDRESS Address
,
249 ACPI_TABLE_HEADER
**Table
)
251 ACPI_TABLE_HEADER
*MappedTable
;
252 ACPI_TABLE_HEADER
*LocalTable
;
256 /* Validate the input physical address to avoid program crash */
258 if (Address
< ACPI_HI_RSDP_WINDOW_BASE
)
260 fprintf (stderr
, "Invalid table address: 0x%8.8X%8.8X\n",
261 ACPI_FORMAT_UINT64 (Address
));
262 return (AE_BAD_ADDRESS
);
265 /* Map the table and validate it */
267 Status
= OslMapTable (Address
, NULL
, &MappedTable
);
268 if (ACPI_FAILURE (Status
))
273 /* Copy table to local buffer and return it */
275 LocalTable
= calloc (1, MappedTable
->Length
);
278 AcpiOsUnmapMemory (MappedTable
, MappedTable
->Length
);
279 return (AE_NO_MEMORY
);
282 memcpy (LocalTable
, MappedTable
, MappedTable
->Length
);
283 AcpiOsUnmapMemory (MappedTable
, MappedTable
->Length
);
290 /******************************************************************************
292 * FUNCTION: AcpiOsGetTableByName
294 * PARAMETERS: Signature - ACPI Signature for desired table. Must be
295 * a null terminated 4-character string.
296 * Instance - Multiple table support for SSDT/UEFI (0...n)
297 * Must be 0 for other tables.
298 * Table - Where a pointer to the table is returned
299 * Address - Where the table physical address is returned
301 * RETURN: Status; Table buffer and physical address returned if AE_OK.
302 * AE_LIMIT: Instance is beyond valid limit
303 * AE_NOT_FOUND: A table with the signature was not found
305 * NOTE: Assumes the input signature is uppercase.
307 *****************************************************************************/
310 AcpiOsGetTableByName (
313 ACPI_TABLE_HEADER
**Table
,
314 ACPI_PHYSICAL_ADDRESS
*Address
)
319 /* Instance is only valid for SSDT/UEFI tables */
322 !ACPI_COMPARE_NAME (Signature
, ACPI_SIG_SSDT
) &&
323 !ACPI_COMPARE_NAME (Signature
, ACPI_SIG_UEFI
))
328 /* Initialize main tables */
330 Status
= OslTableInitialize ();
331 if (ACPI_FAILURE (Status
))
337 * If one of the main ACPI tables was requested (RSDT/XSDT/FADT),
338 * simply return it immediately.
340 if (ACPI_COMPARE_NAME (Signature
, ACPI_SIG_XSDT
))
344 return (AE_NOT_FOUND
);
347 *Address
= Gbl_Rsdp
.XsdtPhysicalAddress
;
348 *Table
= (ACPI_TABLE_HEADER
*) Gbl_Xsdt
;
352 if (ACPI_COMPARE_NAME (Signature
, ACPI_SIG_RSDT
))
354 if (!Gbl_Rsdp
.RsdtPhysicalAddress
)
356 return (AE_NOT_FOUND
);
359 *Address
= Gbl_Rsdp
.RsdtPhysicalAddress
;
360 *Table
= (ACPI_TABLE_HEADER
*) Gbl_Rsdt
;
364 if (ACPI_COMPARE_NAME (Signature
, ACPI_SIG_FADT
))
366 *Address
= Gbl_FadtAddress
;
367 *Table
= (ACPI_TABLE_HEADER
*) Gbl_Fadt
;
371 /* Not a main ACPI table, attempt to extract it from the RSDT/XSDT */
373 Status
= OslGetTableViaRoot (Signature
, Instance
, Table
, Address
);
374 if (ACPI_FAILURE (Status
))
383 /******************************************************************************
385 * FUNCTION: AcpiOsGetTableByIndex
387 * PARAMETERS: Index - Which table to get
388 * Table - Where a pointer to the table is returned
389 * Instance - Where a pointer to the table instance no. is
391 * Address - Where the table physical address is returned
393 * RETURN: Status; Table buffer and physical address returned if AE_OK.
394 * AE_LIMIT: Index is beyond valid limit
396 * DESCRIPTION: Get an ACPI table via an index value (0 through n). Returns
397 * AE_LIMIT when an invalid index is reached. Index is not
398 * necessarily an index into the RSDT/XSDT.
400 *****************************************************************************/
403 AcpiOsGetTableByIndex (
405 ACPI_TABLE_HEADER
**Table
,
407 ACPI_PHYSICAL_ADDRESS
*Address
)
409 OSL_TABLE_INFO
*Info
;
414 /* Initialize main tables */
416 Status
= OslTableInitialize ();
417 if (ACPI_FAILURE (Status
))
422 /* Add all tables to list */
424 Status
= OslAddTablesToList ();
425 if (ACPI_FAILURE (Status
))
432 if (Index
>= Gbl_TableListHead
->Instance
)
437 /* Point to the table list entry specified by the Index argument */
439 Info
= Gbl_TableListHead
;
440 for (i
= 0; i
<= Index
; i
++)
445 /* Now we can just get the table via the address or name */
449 Status
= AcpiOsGetTableByAddress (Info
->Address
, Table
);
450 if (ACPI_SUCCESS (Status
))
452 *Address
= Info
->Address
;
457 Status
= AcpiOsGetTableByName (Info
->Signature
, Info
->Instance
,
461 if (ACPI_SUCCESS (Status
))
463 *Instance
= Info
->Instance
;
469 /******************************************************************************
471 * FUNCTION: OslTableInitialize
477 * DESCRIPTION: Initialize ACPI table data. Get and store main ACPI tables to
478 * local variables. Main ACPI tables include RSDP, FADT, RSDT,
481 *****************************************************************************/
487 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
490 ACPI_TABLE_HEADER
*MappedTable
;
493 ACPI_PHYSICAL_ADDRESS RsdpBase
;
497 #if defined(SYSTEM_SYSCTL)
498 size_t Length
= sizeof (Address
);
502 /* Get main ACPI tables from memory on first invocation of this function */
504 if (Gbl_MainTableObtained
)
509 /* Attempt to use kenv or sysctl to find RSD PTR record. */
513 Address
= Gbl_RsdpBase
;
515 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined (__DragonFly__)
516 else if (kenv (KENV_GET
, SYSTEM_KENV
, Buffer
, sizeof (Buffer
)) > 0)
518 Address
= strtoul (Buffer
, NULL
, 0);
521 #if defined(SYSTEM_SYSCTL)
524 if (sysctlbyname (SYSTEM_SYSCTL
, &Address
, &Length
, NULL
, 0) != 0)
533 RsdpSize
= sizeof (Gbl_Rsdp
);
537 RsdpBase
= ACPI_HI_RSDP_WINDOW_BASE
;
538 RsdpSize
= ACPI_HI_RSDP_WINDOW_SIZE
;
541 /* Get RSDP from memory */
543 RsdpAddress
= AcpiOsMapMemory (RsdpBase
, RsdpSize
);
546 return (AE_BAD_ADDRESS
);
549 /* Search low memory for the RSDP */
551 TableAddress
= AcpiTbScanMemoryForRsdp (RsdpAddress
, RsdpSize
);
554 AcpiOsUnmapMemory (RsdpAddress
, RsdpSize
);
558 memcpy (&Gbl_Rsdp
, TableAddress
, sizeof (Gbl_Rsdp
));
559 AcpiOsUnmapMemory (RsdpAddress
, RsdpSize
);
561 /* Get XSDT from memory */
563 if (Gbl_Rsdp
.Revision
)
565 Status
= OslMapTable (Gbl_Rsdp
.XsdtPhysicalAddress
,
566 ACPI_SIG_XSDT
, &MappedTable
);
567 if (ACPI_FAILURE (Status
))
573 Gbl_Xsdt
= calloc (1, MappedTable
->Length
);
577 "XSDT: Could not allocate buffer for table of length %X\n",
578 MappedTable
->Length
);
579 AcpiOsUnmapMemory (MappedTable
, MappedTable
->Length
);
580 return (AE_NO_MEMORY
);
583 memcpy (Gbl_Xsdt
, MappedTable
, MappedTable
->Length
);
584 AcpiOsUnmapMemory (MappedTable
, MappedTable
->Length
);
587 /* Get RSDT from memory */
589 if (Gbl_Rsdp
.RsdtPhysicalAddress
)
591 Status
= OslMapTable (Gbl_Rsdp
.RsdtPhysicalAddress
,
592 ACPI_SIG_RSDT
, &MappedTable
);
593 if (ACPI_FAILURE (Status
))
598 Gbl_Rsdt
= calloc (1, MappedTable
->Length
);
602 "RSDT: Could not allocate buffer for table of length %X\n",
603 MappedTable
->Length
);
604 AcpiOsUnmapMemory (MappedTable
, MappedTable
->Length
);
605 return (AE_NO_MEMORY
);
608 memcpy (Gbl_Rsdt
, MappedTable
, MappedTable
->Length
);
609 AcpiOsUnmapMemory (MappedTable
, MappedTable
->Length
);
612 /* Get FADT from memory */
616 Gbl_FadtAddress
= Gbl_Xsdt
->TableOffsetEntry
[0];
620 Gbl_FadtAddress
= Gbl_Rsdt
->TableOffsetEntry
[0];
623 if (!Gbl_FadtAddress
)
625 fprintf(stderr
, "FADT: Table could not be found\n");
629 Status
= OslMapTable (Gbl_FadtAddress
, ACPI_SIG_FADT
, &MappedTable
);
630 if (ACPI_FAILURE (Status
))
635 Gbl_Fadt
= calloc (1, MappedTable
->Length
);
639 "FADT: Could not allocate buffer for table of length %X\n",
640 MappedTable
->Length
);
641 AcpiOsUnmapMemory (MappedTable
, MappedTable
->Length
);
642 return (AE_NO_MEMORY
);
645 memcpy (Gbl_Fadt
, MappedTable
, MappedTable
->Length
);
646 AcpiOsUnmapMemory (MappedTable
, MappedTable
->Length
);
647 Gbl_MainTableObtained
= TRUE
;
652 /******************************************************************************
654 * FUNCTION: OslGetTableViaRoot
656 * PARAMETERS: Signature - ACPI Signature for common table. Must be
657 * a null terminated 4-character string.
658 * Instance - Multiple table support for SSDT/UEFI (0...n)
659 * Must be 0 for other tables.
660 * Table - Where a pointer to the table is returned
661 * Address - Where the table physical address is returned
663 * RETURN: Status; Table buffer and physical address returned if AE_OK.
664 * AE_LIMIT: Instance is beyond valid limit
665 * AE_NOT_FOUND: A table with the signature was not found
667 * DESCRIPTION: Get an ACPI table via the root table (RSDT/XSDT)
669 * NOTE: Assumes the input signature is uppercase.
671 *****************************************************************************/
677 ACPI_TABLE_HEADER
**Table
,
678 ACPI_PHYSICAL_ADDRESS
*Address
)
680 ACPI_TABLE_HEADER
*LocalTable
= NULL
;
681 ACPI_TABLE_HEADER
*MappedTable
= NULL
;
682 UINT8 NumberOfTables
;
683 UINT32 CurrentInstance
= 0;
684 ACPI_PHYSICAL_ADDRESS TableAddress
= 0;
689 /* DSDT and FACS address must be extracted from the FADT */
691 if (ACPI_COMPARE_NAME (Signature
, ACPI_SIG_DSDT
) ||
692 ACPI_COMPARE_NAME (Signature
, ACPI_SIG_FACS
))
695 * Get the appropriate address, either 32-bit or 64-bit. Be very
696 * careful about the FADT length and validate table addresses.
697 * Note: The 64-bit addresses have priority.
699 if (ACPI_COMPARE_NAME (Signature
, ACPI_SIG_DSDT
))
701 if ((Gbl_Fadt
->Header
.Length
>= MIN_FADT_FOR_XDSDT
) &&
704 TableAddress
= (ACPI_PHYSICAL_ADDRESS
) Gbl_Fadt
->XDsdt
;
706 else if ((Gbl_Fadt
->Header
.Length
>= MIN_FADT_FOR_DSDT
) &&
709 TableAddress
= (ACPI_PHYSICAL_ADDRESS
) Gbl_Fadt
->Dsdt
;
714 if ((Gbl_Fadt
->Header
.Length
>= MIN_FADT_FOR_XFACS
) &&
717 TableAddress
= (ACPI_PHYSICAL_ADDRESS
) Gbl_Fadt
->XFacs
;
719 else if ((Gbl_Fadt
->Header
.Length
>= MIN_FADT_FOR_FACS
) &&
722 TableAddress
= (ACPI_PHYSICAL_ADDRESS
) Gbl_Fadt
->Facs
;
726 else /* Case for a normal ACPI table */
731 (Gbl_Xsdt
->Header
.Length
- sizeof (Gbl_Xsdt
->Header
))
732 / sizeof (Gbl_Xsdt
->TableOffsetEntry
[0]);
734 else /* Use RSDT if XSDT is not available */
737 (Gbl_Rsdt
->Header
.Length
- sizeof (Gbl_Rsdt
->Header
))
738 / sizeof (Gbl_Rsdt
->TableOffsetEntry
[0]);
741 /* Search RSDT/XSDT for the requested table */
743 for (i
= 0; i
< NumberOfTables
; i
++)
747 TableAddress
= Gbl_Xsdt
->TableOffsetEntry
[i
];
751 TableAddress
= Gbl_Rsdt
->TableOffsetEntry
[i
];
754 MappedTable
= AcpiOsMapMemory (TableAddress
, sizeof (*MappedTable
));
757 return (AE_BAD_ADDRESS
);
760 /* Does this table match the requested signature? */
762 if (ACPI_COMPARE_NAME (MappedTable
->Signature
, Signature
))
765 /* Match table instance (for SSDT/UEFI tables) */
767 if (CurrentInstance
== Instance
)
769 AcpiOsUnmapMemory (MappedTable
, sizeof (*MappedTable
));
776 AcpiOsUnmapMemory (MappedTable
, MappedTable
->Length
);
787 return (AE_NOT_FOUND
);
790 /* Now we can get the requested table */
792 Status
= OslMapTable (TableAddress
, Signature
, &MappedTable
);
793 if (ACPI_FAILURE (Status
))
798 /* Copy table to local buffer and return it */
800 LocalTable
= calloc (1, MappedTable
->Length
);
803 AcpiOsUnmapMemory (MappedTable
, MappedTable
->Length
);
804 return (AE_NO_MEMORY
);
807 memcpy (LocalTable
, MappedTable
, MappedTable
->Length
);
808 AcpiOsUnmapMemory (MappedTable
, MappedTable
->Length
);
810 *Address
= TableAddress
;
815 /******************************************************************************
817 * FUNCTION: OslAddTablesToList
821 * RETURN: Status; Table list is initialized if AE_OK.
823 * DESCRIPTION: Add ACPI tables to the table list.
825 *****************************************************************************/
831 ACPI_PHYSICAL_ADDRESS TableAddress
;
832 OSL_TABLE_INFO
*Info
= NULL
;
833 OSL_TABLE_INFO
*NewInfo
;
834 ACPI_TABLE_HEADER
*Table
;
836 UINT8 NumberOfTables
;
840 /* Initialize the table list on first invocation */
842 if (Gbl_TableListInitialized
)
847 /* Add mandatory tables to global table list first */
849 for (i
= 0; i
< 4; i
++)
851 NewInfo
= calloc (1, sizeof (*NewInfo
));
854 return (AE_NO_MEMORY
);
860 Gbl_TableListHead
= Info
= NewInfo
;
865 ACPI_MOVE_NAME (NewInfo
->Signature
,
866 Gbl_Revision
? ACPI_SIG_XSDT
: ACPI_SIG_RSDT
);
871 ACPI_MOVE_NAME (NewInfo
->Signature
, ACPI_SIG_FACS
);
876 ACPI_MOVE_NAME (NewInfo
->Signature
, ACPI_SIG_DSDT
);
880 Info
->Next
= NewInfo
;
882 Gbl_TableListHead
->Instance
++;
885 /* Add normal tables from RSDT/XSDT to global list */
890 (Gbl_Xsdt
->Header
.Length
- sizeof (Gbl_Xsdt
->Header
))
891 / sizeof (Gbl_Xsdt
->TableOffsetEntry
[0]);
896 (Gbl_Rsdt
->Header
.Length
- sizeof (Gbl_Rsdt
->Header
))
897 / sizeof (Gbl_Rsdt
->TableOffsetEntry
[0]);
900 for (i
= 0; i
< NumberOfTables
; i
++)
904 TableAddress
= Gbl_Xsdt
->TableOffsetEntry
[i
];
908 TableAddress
= Gbl_Rsdt
->TableOffsetEntry
[i
];
911 Table
= AcpiOsMapMemory (TableAddress
, sizeof (*Table
));
914 return (AE_BAD_ADDRESS
);
918 NewInfo
= Gbl_TableListHead
;
919 while (NewInfo
->Next
!= NULL
)
921 NewInfo
= NewInfo
->Next
;
922 if (ACPI_COMPARE_NAME (Table
->Signature
, NewInfo
->Signature
))
928 NewInfo
= calloc (1, sizeof (*NewInfo
));
931 AcpiOsUnmapMemory (Table
, sizeof (*Table
));
932 return (AE_NO_MEMORY
);
935 ACPI_MOVE_NAME (NewInfo
->Signature
, Table
->Signature
);
937 AcpiOsUnmapMemory (Table
, sizeof (*Table
));
939 NewInfo
->Instance
= Instance
;
940 NewInfo
->Address
= TableAddress
;
941 Info
->Next
= NewInfo
;
943 Gbl_TableListHead
->Instance
++;
946 Gbl_TableListInitialized
= TRUE
;
951 /******************************************************************************
953 * FUNCTION: OslMapTable
955 * PARAMETERS: Address - Address of the table in memory
956 * Signature - Optional ACPI Signature for desired table.
957 * Null terminated 4-character string.
958 * Table - Where a pointer to the mapped table is
961 * RETURN: Status; Mapped table is returned if AE_OK.
963 * DESCRIPTION: Map entire ACPI table into caller's address space. Also
964 * validates the table and checksum.
966 *****************************************************************************/
972 ACPI_TABLE_HEADER
**Table
)
974 ACPI_TABLE_HEADER
*MappedTable
;
978 /* Map the header so we can get the table length */
980 MappedTable
= AcpiOsMapMemory (Address
, sizeof (*MappedTable
));
983 return (AE_BAD_ADDRESS
);
986 /* Check if table is valid */
988 if (!ApIsValidHeader (MappedTable
))
990 AcpiOsUnmapMemory (MappedTable
, sizeof (*MappedTable
));
991 return (AE_BAD_HEADER
);
994 /* If specified, signature must match */
997 !ACPI_COMPARE_NAME (Signature
, MappedTable
->Signature
))
999 AcpiOsUnmapMemory (MappedTable
, sizeof (*MappedTable
));
1000 return (AE_NOT_EXIST
);
1003 /* Map the entire table */
1005 Length
= MappedTable
->Length
;
1006 AcpiOsUnmapMemory (MappedTable
, sizeof (*MappedTable
));
1008 MappedTable
= AcpiOsMapMemory (Address
, Length
);
1011 return (AE_BAD_ADDRESS
);
1014 (void) ApIsValidChecksum (MappedTable
);
1016 *Table
= MappedTable
;