xref: /onnv-gate/usr/src/uts/intel/io/acpica/tables/tbxfroot.c (revision 3446:5903aece022d)
1*3446Smrj /******************************************************************************
2*3446Smrj  *
3*3446Smrj  * Module Name: tbxfroot - Find the root ACPI table (RSDT)
4*3446Smrj  *              $Revision: 1.102 $
5*3446Smrj  *
6*3446Smrj  *****************************************************************************/
7*3446Smrj 
8*3446Smrj /******************************************************************************
9*3446Smrj  *
10*3446Smrj  * 1. Copyright Notice
11*3446Smrj  *
12*3446Smrj  * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
13*3446Smrj  * All rights reserved.
14*3446Smrj  *
15*3446Smrj  * 2. License
16*3446Smrj  *
17*3446Smrj  * 2.1. This is your license from Intel Corp. under its intellectual property
18*3446Smrj  * rights.  You may have additional license terms from the party that provided
19*3446Smrj  * you this software, covering your right to use that party's intellectual
20*3446Smrj  * property rights.
21*3446Smrj  *
22*3446Smrj  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23*3446Smrj  * copy of the source code appearing in this file ("Covered Code") an
24*3446Smrj  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25*3446Smrj  * base code distributed originally by Intel ("Original Intel Code") to copy,
26*3446Smrj  * make derivatives, distribute, use and display any portion of the Covered
27*3446Smrj  * Code in any form, with the right to sublicense such rights; and
28*3446Smrj  *
29*3446Smrj  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30*3446Smrj  * license (with the right to sublicense), under only those claims of Intel
31*3446Smrj  * patents that are infringed by the Original Intel Code, to make, use, sell,
32*3446Smrj  * offer to sell, and import the Covered Code and derivative works thereof
33*3446Smrj  * solely to the minimum extent necessary to exercise the above copyright
34*3446Smrj  * license, and in no event shall the patent license extend to any additions
35*3446Smrj  * to or modifications of the Original Intel Code.  No other license or right
36*3446Smrj  * is granted directly or by implication, estoppel or otherwise;
37*3446Smrj  *
38*3446Smrj  * The above copyright and patent license is granted only if the following
39*3446Smrj  * conditions are met:
40*3446Smrj  *
41*3446Smrj  * 3. Conditions
42*3446Smrj  *
43*3446Smrj  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44*3446Smrj  * Redistribution of source code of any substantial portion of the Covered
45*3446Smrj  * Code or modification with rights to further distribute source must include
46*3446Smrj  * the above Copyright Notice, the above License, this list of Conditions,
47*3446Smrj  * and the following Disclaimer and Export Compliance provision.  In addition,
48*3446Smrj  * Licensee must cause all Covered Code to which Licensee contributes to
49*3446Smrj  * contain a file documenting the changes Licensee made to create that Covered
50*3446Smrj  * Code and the date of any change.  Licensee must include in that file the
51*3446Smrj  * documentation of any changes made by any predecessor Licensee.  Licensee
52*3446Smrj  * must include a prominent statement that the modification is derived,
53*3446Smrj  * directly or indirectly, from Original Intel Code.
54*3446Smrj  *
55*3446Smrj  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56*3446Smrj  * Redistribution of source code of any substantial portion of the Covered
57*3446Smrj  * Code or modification without rights to further distribute source must
58*3446Smrj  * include the following Disclaimer and Export Compliance provision in the
59*3446Smrj  * documentation and/or other materials provided with distribution.  In
60*3446Smrj  * addition, Licensee may not authorize further sublicense of source of any
61*3446Smrj  * portion of the Covered Code, and must include terms to the effect that the
62*3446Smrj  * license from Licensee to its licensee is limited to the intellectual
63*3446Smrj  * property embodied in the software Licensee provides to its licensee, and
64*3446Smrj  * not to intellectual property embodied in modifications its licensee may
65*3446Smrj  * make.
66*3446Smrj  *
67*3446Smrj  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68*3446Smrj  * substantial portion of the Covered Code or modification must reproduce the
69*3446Smrj  * above Copyright Notice, and the following Disclaimer and Export Compliance
70*3446Smrj  * provision in the documentation and/or other materials provided with the
71*3446Smrj  * distribution.
72*3446Smrj  *
73*3446Smrj  * 3.4. Intel retains all right, title, and interest in and to the Original
74*3446Smrj  * Intel Code.
75*3446Smrj  *
76*3446Smrj  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77*3446Smrj  * Intel shall be used in advertising or otherwise to promote the sale, use or
78*3446Smrj  * other dealings in products derived from or relating to the Covered Code
79*3446Smrj  * without prior written authorization from Intel.
80*3446Smrj  *
81*3446Smrj  * 4. Disclaimer and Export Compliance
82*3446Smrj  *
83*3446Smrj  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84*3446Smrj  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85*3446Smrj  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86*3446Smrj  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87*3446Smrj  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88*3446Smrj  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89*3446Smrj  * PARTICULAR PURPOSE.
90*3446Smrj  *
91*3446Smrj  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92*3446Smrj  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93*3446Smrj  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94*3446Smrj  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95*3446Smrj  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96*3446Smrj  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97*3446Smrj  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98*3446Smrj  * LIMITED REMEDY.
99*3446Smrj  *
100*3446Smrj  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101*3446Smrj  * software or system incorporating such software without first obtaining any
102*3446Smrj  * required license or other approval from the U. S. Department of Commerce or
103*3446Smrj  * any other agency or department of the United States Government.  In the
104*3446Smrj  * event Licensee exports any such software from the United States or
105*3446Smrj  * re-exports any such software from a foreign destination, Licensee shall
106*3446Smrj  * ensure that the distribution and export/re-export of the software is in
107*3446Smrj  * compliance with all laws, regulations, orders, or other restrictions of the
108*3446Smrj  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109*3446Smrj  * any of its subsidiaries will export/re-export any technical data, process,
110*3446Smrj  * software, or service, directly or indirectly, to any country for which the
111*3446Smrj  * United States government or any agency thereof requires an export license,
112*3446Smrj  * other governmental approval, or letter of assurance, without first obtaining
113*3446Smrj  * such license, approval or letter.
114*3446Smrj  *
115*3446Smrj  *****************************************************************************/
116*3446Smrj 
117*3446Smrj #define __TBXFROOT_C__
118*3446Smrj 
119*3446Smrj #include "acpi.h"
120*3446Smrj #include "actables.h"
121*3446Smrj 
122*3446Smrj 
123*3446Smrj #define _COMPONENT          ACPI_TABLES
124*3446Smrj         ACPI_MODULE_NAME    ("tbxfroot")
125*3446Smrj 
126*3446Smrj /* Local prototypes */
127*3446Smrj 
128*3446Smrj static ACPI_STATUS
129*3446Smrj AcpiTbFindRsdp (
130*3446Smrj     ACPI_TABLE_DESC         *TableInfo,
131*3446Smrj     UINT32                  Flags);
132*3446Smrj 
133*3446Smrj static UINT8 *
134*3446Smrj AcpiTbScanMemoryForRsdp (
135*3446Smrj     UINT8                   *StartAddress,
136*3446Smrj     UINT32                  Length);
137*3446Smrj 
138*3446Smrj 
139*3446Smrj /*******************************************************************************
140*3446Smrj  *
141*3446Smrj  * FUNCTION:    AcpiTbValidateRsdp
142*3446Smrj  *
143*3446Smrj  * PARAMETERS:  Rsdp        - Pointer to unvalidated RSDP
144*3446Smrj  *
145*3446Smrj  * RETURN:      Status
146*3446Smrj  *
147*3446Smrj  * DESCRIPTION: Validate the RSDP (ptr)
148*3446Smrj  *
149*3446Smrj  ******************************************************************************/
150*3446Smrj 
151*3446Smrj ACPI_STATUS
152*3446Smrj AcpiTbValidateRsdp (
153*3446Smrj     RSDP_DESCRIPTOR         *Rsdp)
154*3446Smrj {
155*3446Smrj     ACPI_FUNCTION_ENTRY ();
156*3446Smrj 
157*3446Smrj 
158*3446Smrj     /*
159*3446Smrj      *  The signature and checksum must both be correct
160*3446Smrj      */
161*3446Smrj     if (ACPI_STRNCMP ((char *) Rsdp, RSDP_SIG, sizeof (RSDP_SIG)-1) != 0)
162*3446Smrj     {
163*3446Smrj         /* Nope, BAD Signature */
164*3446Smrj 
165*3446Smrj         return (AE_BAD_SIGNATURE);
166*3446Smrj     }
167*3446Smrj 
168*3446Smrj     /* Check the standard checksum */
169*3446Smrj 
170*3446Smrj     if (AcpiTbSumTable (Rsdp, ACPI_RSDP_CHECKSUM_LENGTH) != 0)
171*3446Smrj     {
172*3446Smrj         return (AE_BAD_CHECKSUM);
173*3446Smrj     }
174*3446Smrj 
175*3446Smrj     /* Check extended checksum if table version >= 2 */
176*3446Smrj 
177*3446Smrj     if ((Rsdp->Revision >= 2) &&
178*3446Smrj         (AcpiTbSumTable (Rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0))
179*3446Smrj     {
180*3446Smrj         return (AE_BAD_CHECKSUM);
181*3446Smrj     }
182*3446Smrj 
183*3446Smrj     return (AE_OK);
184*3446Smrj }
185*3446Smrj 
186*3446Smrj 
187*3446Smrj /*******************************************************************************
188*3446Smrj  *
189*3446Smrj  * FUNCTION:    AcpiTbFindTable
190*3446Smrj  *
191*3446Smrj  * PARAMETERS:  Signature           - String with ACPI table signature
192*3446Smrj  *              OemId               - String with the table OEM ID
193*3446Smrj  *              OemTableId          - String with the OEM Table ID
194*3446Smrj  *              TablePtr            - Where the table pointer is returned
195*3446Smrj  *
196*3446Smrj  * RETURN:      Status
197*3446Smrj  *
198*3446Smrj  * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
199*3446Smrj  *              Signature, OEM ID and OEM Table ID.
200*3446Smrj  *
201*3446Smrj  ******************************************************************************/
202*3446Smrj 
203*3446Smrj ACPI_STATUS
204*3446Smrj AcpiTbFindTable (
205*3446Smrj     char                    *Signature,
206*3446Smrj     char                    *OemId,
207*3446Smrj     char                    *OemTableId,
208*3446Smrj     ACPI_TABLE_HEADER       **TablePtr)
209*3446Smrj {
210*3446Smrj     ACPI_STATUS             Status;
211*3446Smrj     ACPI_TABLE_HEADER       *Table;
212*3446Smrj 
213*3446Smrj 
214*3446Smrj     ACPI_FUNCTION_TRACE (TbFindTable);
215*3446Smrj 
216*3446Smrj 
217*3446Smrj     /* Validate string lengths */
218*3446Smrj 
219*3446Smrj     if ((ACPI_STRLEN (Signature)  > ACPI_NAME_SIZE) ||
220*3446Smrj         (ACPI_STRLEN (OemId)      > sizeof (Table->OemId)) ||
221*3446Smrj         (ACPI_STRLEN (OemTableId) > sizeof (Table->OemTableId)))
222*3446Smrj     {
223*3446Smrj         return_ACPI_STATUS (AE_AML_STRING_LIMIT);
224*3446Smrj     }
225*3446Smrj 
226*3446Smrj     if (ACPI_COMPARE_NAME (Signature, DSDT_SIG))
227*3446Smrj     {
228*3446Smrj         /*
229*3446Smrj          * The DSDT pointer is contained in the FADT, not the RSDT.
230*3446Smrj          * This code should suffice, because the only code that would perform
231*3446Smrj          * a "find" on the DSDT is the DataTableRegion() AML opcode -- in
232*3446Smrj          * which case, the DSDT is guaranteed to be already loaded.
233*3446Smrj          * If this becomes insufficient, the FADT will have to be found first.
234*3446Smrj          */
235*3446Smrj         if (!AcpiGbl_DSDT)
236*3446Smrj         {
237*3446Smrj             return_ACPI_STATUS (AE_NO_ACPI_TABLES);
238*3446Smrj         }
239*3446Smrj         Table = AcpiGbl_DSDT;
240*3446Smrj     }
241*3446Smrj     else
242*3446Smrj     {
243*3446Smrj         /* Find the table */
244*3446Smrj 
245*3446Smrj         Status = AcpiGetFirmwareTable (Signature, 1,
246*3446Smrj                     ACPI_LOGICAL_ADDRESSING, &Table);
247*3446Smrj         if (ACPI_FAILURE (Status))
248*3446Smrj         {
249*3446Smrj             return_ACPI_STATUS (Status);
250*3446Smrj         }
251*3446Smrj     }
252*3446Smrj 
253*3446Smrj     /* Check OemId and OemTableId */
254*3446Smrj 
255*3446Smrj     if ((OemId[0] &&
256*3446Smrj         ACPI_STRNCMP (
257*3446Smrj             OemId, Table->OemId,
258*3446Smrj             sizeof (Table->OemId))) ||
259*3446Smrj 
260*3446Smrj         (OemTableId[0] &&
261*3446Smrj         ACPI_STRNCMP (
262*3446Smrj             OemTableId, Table->OemTableId,
263*3446Smrj             sizeof (Table->OemTableId))))
264*3446Smrj     {
265*3446Smrj         return_ACPI_STATUS (AE_AML_NAME_NOT_FOUND);
266*3446Smrj     }
267*3446Smrj 
268*3446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "Found table [%4.4s]\n",
269*3446Smrj         Table->Signature));
270*3446Smrj 
271*3446Smrj     *TablePtr = Table;
272*3446Smrj     return_ACPI_STATUS (AE_OK);
273*3446Smrj }
274*3446Smrj 
275*3446Smrj 
276*3446Smrj /*******************************************************************************
277*3446Smrj  *
278*3446Smrj  * FUNCTION:    AcpiGetFirmwareTable
279*3446Smrj  *
280*3446Smrj  * PARAMETERS:  Signature       - Any ACPI table signature
281*3446Smrj  *              Instance        - the non zero instance of the table, allows
282*3446Smrj  *                                support for multiple tables of the same type
283*3446Smrj  *              Flags           - Physical/Virtual support
284*3446Smrj  *              TablePointer    - Where a buffer containing the table is
285*3446Smrj  *                                returned
286*3446Smrj  *
287*3446Smrj  * RETURN:      Status
288*3446Smrj  *
289*3446Smrj  * DESCRIPTION: This function is called to get an ACPI table. A buffer is
290*3446Smrj  *              allocated for the table and returned in TablePointer.
291*3446Smrj  *              This table will be a complete table including the header.
292*3446Smrj  *
293*3446Smrj  ******************************************************************************/
294*3446Smrj 
295*3446Smrj ACPI_STATUS
296*3446Smrj AcpiGetFirmwareTable (
297*3446Smrj     ACPI_STRING             Signature,
298*3446Smrj     UINT32                  Instance,
299*3446Smrj     UINT32                  Flags,
300*3446Smrj     ACPI_TABLE_HEADER       **TablePointer)
301*3446Smrj {
302*3446Smrj     ACPI_STATUS             Status;
303*3446Smrj     ACPI_POINTER            Address;
304*3446Smrj     ACPI_TABLE_HEADER       *Header = NULL;
305*3446Smrj     ACPI_TABLE_DESC         *TableInfo = NULL;
306*3446Smrj     ACPI_TABLE_DESC         *RsdtInfo;
307*3446Smrj     UINT32                  TableCount;
308*3446Smrj     UINT32                  i;
309*3446Smrj     UINT32                  j;
310*3446Smrj 
311*3446Smrj 
312*3446Smrj     ACPI_FUNCTION_TRACE (AcpiGetFirmwareTable);
313*3446Smrj 
314*3446Smrj 
315*3446Smrj     /*
316*3446Smrj      * Ensure that at least the table manager is initialized.  We don't
317*3446Smrj      * require that the entire ACPI subsystem is up for this interface.
318*3446Smrj      * If we have a buffer, we must have a length too
319*3446Smrj      */
320*3446Smrj     if ((Instance == 0)     ||
321*3446Smrj         (!Signature)        ||
322*3446Smrj         (!TablePointer))
323*3446Smrj     {
324*3446Smrj         return_ACPI_STATUS (AE_BAD_PARAMETER);
325*3446Smrj     }
326*3446Smrj 
327*3446Smrj     /* Ensure that we have a RSDP */
328*3446Smrj 
329*3446Smrj     if (!AcpiGbl_RSDP)
330*3446Smrj     {
331*3446Smrj         /* Get the RSDP */
332*3446Smrj 
333*3446Smrj         Status = AcpiOsGetRootPointer (Flags, &Address);
334*3446Smrj         if (ACPI_FAILURE (Status))
335*3446Smrj         {
336*3446Smrj             ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "RSDP not found\n"));
337*3446Smrj             return_ACPI_STATUS (AE_NO_ACPI_TABLES);
338*3446Smrj         }
339*3446Smrj 
340*3446Smrj         /* Map and validate the RSDP */
341*3446Smrj 
342*3446Smrj         if ((Flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING)
343*3446Smrj         {
344*3446Smrj             Status = AcpiOsMapMemory (Address.Pointer.Physical,
345*3446Smrj                         sizeof (RSDP_DESCRIPTOR), (void *) &AcpiGbl_RSDP);
346*3446Smrj             if (ACPI_FAILURE (Status))
347*3446Smrj             {
348*3446Smrj                 return_ACPI_STATUS (Status);
349*3446Smrj             }
350*3446Smrj         }
351*3446Smrj         else
352*3446Smrj         {
353*3446Smrj             AcpiGbl_RSDP = Address.Pointer.Logical;
354*3446Smrj         }
355*3446Smrj 
356*3446Smrj         /* The RDSP signature and checksum must both be correct */
357*3446Smrj 
358*3446Smrj         Status = AcpiTbValidateRsdp (AcpiGbl_RSDP);
359*3446Smrj         if (ACPI_FAILURE (Status))
360*3446Smrj         {
361*3446Smrj             return_ACPI_STATUS (Status);
362*3446Smrj         }
363*3446Smrj     }
364*3446Smrj 
365*3446Smrj     /* Get the RSDT address via the RSDP */
366*3446Smrj 
367*3446Smrj     AcpiTbGetRsdtAddress (&Address);
368*3446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
369*3446Smrj         "RSDP located at %p, RSDT physical=%8.8X%8.8X\n",
370*3446Smrj         AcpiGbl_RSDP,
371*3446Smrj         ACPI_FORMAT_UINT64 (Address.Pointer.Value)));
372*3446Smrj 
373*3446Smrj     /* Insert ProcessorMode flags */
374*3446Smrj 
375*3446Smrj     Address.PointerType |= Flags;
376*3446Smrj 
377*3446Smrj     /* Get and validate the RSDT */
378*3446Smrj 
379*3446Smrj     RsdtInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_TABLE_DESC));
380*3446Smrj     if (!RsdtInfo)
381*3446Smrj     {
382*3446Smrj         return_ACPI_STATUS (AE_NO_MEMORY);
383*3446Smrj     }
384*3446Smrj 
385*3446Smrj     Status = AcpiTbGetTable (&Address, RsdtInfo);
386*3446Smrj     if (ACPI_FAILURE (Status))
387*3446Smrj     {
388*3446Smrj         goto Cleanup;
389*3446Smrj     }
390*3446Smrj 
391*3446Smrj     Status = AcpiTbValidateRsdt (RsdtInfo->Pointer);
392*3446Smrj     if (ACPI_FAILURE (Status))
393*3446Smrj     {
394*3446Smrj         goto Cleanup;
395*3446Smrj     }
396*3446Smrj 
397*3446Smrj     /* Allocate a scratch table header and table descriptor */
398*3446Smrj 
399*3446Smrj     Header = ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER));
400*3446Smrj     if (!Header)
401*3446Smrj     {
402*3446Smrj         Status = AE_NO_MEMORY;
403*3446Smrj         goto Cleanup;
404*3446Smrj     }
405*3446Smrj 
406*3446Smrj     TableInfo = ACPI_ALLOCATE (sizeof (ACPI_TABLE_DESC));
407*3446Smrj     if (!TableInfo)
408*3446Smrj     {
409*3446Smrj         Status = AE_NO_MEMORY;
410*3446Smrj         goto Cleanup;
411*3446Smrj     }
412*3446Smrj 
413*3446Smrj     /* Get the number of table pointers within the RSDT */
414*3446Smrj 
415*3446Smrj     TableCount = AcpiTbGetTableCount (AcpiGbl_RSDP, RsdtInfo->Pointer);
416*3446Smrj     Address.PointerType = AcpiGbl_TableFlags | Flags;
417*3446Smrj 
418*3446Smrj     /*
419*3446Smrj      * Search the RSDT/XSDT for the correct instance of the
420*3446Smrj      * requested table
421*3446Smrj      */
422*3446Smrj     for (i = 0, j = 0; i < TableCount; i++)
423*3446Smrj     {
424*3446Smrj         /*
425*3446Smrj          * Get the next table pointer, handle RSDT vs. XSDT
426*3446Smrj          * RSDT pointers are 32 bits, XSDT pointers are 64 bits
427*3446Smrj          */
428*3446Smrj         if (AcpiGbl_RootTableType == ACPI_TABLE_TYPE_RSDT)
429*3446Smrj         {
430*3446Smrj             Address.Pointer.Value = (ACPI_CAST_PTR (
431*3446Smrj                 RSDT_DESCRIPTOR, RsdtInfo->Pointer))->TableOffsetEntry[i];
432*3446Smrj         }
433*3446Smrj         else
434*3446Smrj         {
435*3446Smrj             Address.Pointer.Value = ACPI_GET_ADDRESS ((ACPI_CAST_PTR (
436*3446Smrj                 XSDT_DESCRIPTOR, RsdtInfo->Pointer))->TableOffsetEntry[i]);
437*3446Smrj         }
438*3446Smrj 
439*3446Smrj         /* Get the table header */
440*3446Smrj 
441*3446Smrj         Status = AcpiTbGetTableHeader (&Address, Header);
442*3446Smrj         if (ACPI_FAILURE (Status))
443*3446Smrj         {
444*3446Smrj             goto Cleanup;
445*3446Smrj         }
446*3446Smrj 
447*3446Smrj         /* Compare table signatures and table instance */
448*3446Smrj 
449*3446Smrj         if (ACPI_COMPARE_NAME (Header->Signature, Signature))
450*3446Smrj         {
451*3446Smrj             /* An instance of the table was found */
452*3446Smrj 
453*3446Smrj             j++;
454*3446Smrj             if (j >= Instance)
455*3446Smrj             {
456*3446Smrj                 /* Found the correct instance, get the entire table */
457*3446Smrj 
458*3446Smrj                 Status = AcpiTbGetTableBody (&Address, Header, TableInfo);
459*3446Smrj                 if (ACPI_FAILURE (Status))
460*3446Smrj                 {
461*3446Smrj                     goto Cleanup;
462*3446Smrj                 }
463*3446Smrj 
464*3446Smrj                 *TablePointer = TableInfo->Pointer;
465*3446Smrj                 goto Cleanup;
466*3446Smrj             }
467*3446Smrj         }
468*3446Smrj     }
469*3446Smrj 
470*3446Smrj     /* Did not find the table */
471*3446Smrj 
472*3446Smrj     Status = AE_NOT_EXIST;
473*3446Smrj 
474*3446Smrj 
475*3446Smrj Cleanup:
476*3446Smrj     if (RsdtInfo->Pointer)
477*3446Smrj     {
478*3446Smrj         AcpiOsUnmapMemory (RsdtInfo->Pointer,
479*3446Smrj             (ACPI_SIZE) RsdtInfo->Pointer->Length);
480*3446Smrj     }
481*3446Smrj     ACPI_FREE (RsdtInfo);
482*3446Smrj 
483*3446Smrj     if (Header)
484*3446Smrj     {
485*3446Smrj         ACPI_FREE (Header);
486*3446Smrj     }
487*3446Smrj     if (TableInfo)
488*3446Smrj     {
489*3446Smrj         ACPI_FREE (TableInfo);
490*3446Smrj     }
491*3446Smrj     return_ACPI_STATUS (Status);
492*3446Smrj }
493*3446Smrj 
494*3446Smrj ACPI_EXPORT_SYMBOL (AcpiGetFirmwareTable)
495*3446Smrj 
496*3446Smrj 
497*3446Smrj /* TBD: Move to a new file */
498*3446Smrj 
499*3446Smrj #if ACPI_MACHINE_WIDTH != 16
500*3446Smrj 
501*3446Smrj /*******************************************************************************
502*3446Smrj  *
503*3446Smrj  * FUNCTION:    AcpiFindRootPointer
504*3446Smrj  *
505*3446Smrj  * PARAMETERS:  Flags                   - Logical/Physical addressing
506*3446Smrj  *              RsdpAddress             - Where to place the RSDP address
507*3446Smrj  *
508*3446Smrj  * RETURN:      Status, Physical address of the RSDP
509*3446Smrj  *
510*3446Smrj  * DESCRIPTION: Find the RSDP
511*3446Smrj  *
512*3446Smrj  ******************************************************************************/
513*3446Smrj 
514*3446Smrj ACPI_STATUS
515*3446Smrj AcpiFindRootPointer (
516*3446Smrj     UINT32                  Flags,
517*3446Smrj     ACPI_POINTER            *RsdpAddress)
518*3446Smrj {
519*3446Smrj     ACPI_TABLE_DESC         TableInfo;
520*3446Smrj     ACPI_STATUS             Status;
521*3446Smrj 
522*3446Smrj 
523*3446Smrj     ACPI_FUNCTION_TRACE (AcpiFindRootPointer);
524*3446Smrj 
525*3446Smrj 
526*3446Smrj     /* Get the RSDP */
527*3446Smrj 
528*3446Smrj     Status = AcpiTbFindRsdp (&TableInfo, Flags);
529*3446Smrj     if (ACPI_FAILURE (Status))
530*3446Smrj     {
531*3446Smrj         ACPI_EXCEPTION ((AE_INFO, Status,
532*3446Smrj             "RSDP structure not found - Flags=%X", Flags));
533*3446Smrj 
534*3446Smrj         return_ACPI_STATUS (AE_NO_ACPI_TABLES);
535*3446Smrj     }
536*3446Smrj 
537*3446Smrj     RsdpAddress->PointerType = ACPI_PHYSICAL_POINTER;
538*3446Smrj     RsdpAddress->Pointer.Physical = TableInfo.PhysicalAddress;
539*3446Smrj     return_ACPI_STATUS (AE_OK);
540*3446Smrj }
541*3446Smrj 
542*3446Smrj ACPI_EXPORT_SYMBOL (AcpiFindRootPointer)
543*3446Smrj 
544*3446Smrj 
545*3446Smrj /*******************************************************************************
546*3446Smrj  *
547*3446Smrj  * FUNCTION:    AcpiTbScanMemoryForRsdp
548*3446Smrj  *
549*3446Smrj  * PARAMETERS:  StartAddress        - Starting pointer for search
550*3446Smrj  *              Length              - Maximum length to search
551*3446Smrj  *
552*3446Smrj  * RETURN:      Pointer to the RSDP if found, otherwise NULL.
553*3446Smrj  *
554*3446Smrj  * DESCRIPTION: Search a block of memory for the RSDP signature
555*3446Smrj  *
556*3446Smrj  ******************************************************************************/
557*3446Smrj 
558*3446Smrj static UINT8 *
559*3446Smrj AcpiTbScanMemoryForRsdp (
560*3446Smrj     UINT8                   *StartAddress,
561*3446Smrj     UINT32                  Length)
562*3446Smrj {
563*3446Smrj     ACPI_STATUS             Status;
564*3446Smrj     UINT8                   *MemRover;
565*3446Smrj     UINT8                   *EndAddress;
566*3446Smrj 
567*3446Smrj 
568*3446Smrj     ACPI_FUNCTION_TRACE (TbScanMemoryForRsdp);
569*3446Smrj 
570*3446Smrj 
571*3446Smrj     EndAddress = StartAddress + Length;
572*3446Smrj 
573*3446Smrj     /* Search from given start address for the requested length */
574*3446Smrj 
575*3446Smrj     for (MemRover = StartAddress; MemRover < EndAddress;
576*3446Smrj          MemRover += ACPI_RSDP_SCAN_STEP)
577*3446Smrj     {
578*3446Smrj         /* The RSDP signature and checksum must both be correct */
579*3446Smrj 
580*3446Smrj         Status = AcpiTbValidateRsdp (ACPI_CAST_PTR (RSDP_DESCRIPTOR, MemRover));
581*3446Smrj         if (ACPI_SUCCESS (Status))
582*3446Smrj         {
583*3446Smrj             /* Sig and checksum valid, we have found a real RSDP */
584*3446Smrj 
585*3446Smrj             ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
586*3446Smrj                 "RSDP located at physical address %p\n", MemRover));
587*3446Smrj             return_PTR (MemRover);
588*3446Smrj         }
589*3446Smrj 
590*3446Smrj         /* No sig match or bad checksum, keep searching */
591*3446Smrj     }
592*3446Smrj 
593*3446Smrj     /* Searched entire block, no RSDP was found */
594*3446Smrj 
595*3446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
596*3446Smrj         "Searched entire block from %p, valid RSDP was not found\n",
597*3446Smrj         StartAddress));
598*3446Smrj     return_PTR (NULL);
599*3446Smrj }
600*3446Smrj 
601*3446Smrj 
602*3446Smrj /*******************************************************************************
603*3446Smrj  *
604*3446Smrj  * FUNCTION:    AcpiTbFindRsdp
605*3446Smrj  *
606*3446Smrj  * PARAMETERS:  TableInfo               - Where the table info is returned
607*3446Smrj  *              Flags                   - Current memory mode (logical vs.
608*3446Smrj  *                                        physical addressing)
609*3446Smrj  *
610*3446Smrj  * RETURN:      Status, RSDP physical address
611*3446Smrj  *
612*3446Smrj  * DESCRIPTION: Search lower 1Mbyte of memory for the root system descriptor
613*3446Smrj  *              pointer structure.  If it is found, set *RSDP to point to it.
614*3446Smrj  *
615*3446Smrj  *              NOTE1: The RSDP must be either in the first 1K of the Extended
616*3446Smrj  *              BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
617*3446Smrj  *              Only a 32-bit physical address is necessary.
618*3446Smrj  *
619*3446Smrj  *              NOTE2: This function is always available, regardless of the
620*3446Smrj  *              initialization state of the rest of ACPI.
621*3446Smrj  *
622*3446Smrj  ******************************************************************************/
623*3446Smrj 
624*3446Smrj static ACPI_STATUS
625*3446Smrj AcpiTbFindRsdp (
626*3446Smrj     ACPI_TABLE_DESC         *TableInfo,
627*3446Smrj     UINT32                  Flags)
628*3446Smrj {
629*3446Smrj     UINT8                   *TablePtr;
630*3446Smrj     UINT8                   *MemRover;
631*3446Smrj     UINT32                  PhysicalAddress;
632*3446Smrj     ACPI_STATUS             Status;
633*3446Smrj 
634*3446Smrj 
635*3446Smrj     ACPI_FUNCTION_TRACE (TbFindRsdp);
636*3446Smrj 
637*3446Smrj 
638*3446Smrj     /*
639*3446Smrj      * Scan supports either logical addressing or physical addressing
640*3446Smrj      */
641*3446Smrj     if ((Flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING)
642*3446Smrj     {
643*3446Smrj         /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
644*3446Smrj 
645*3446Smrj         Status = AcpiOsMapMemory (
646*3446Smrj                     (ACPI_PHYSICAL_ADDRESS) ACPI_EBDA_PTR_LOCATION,
647*3446Smrj                     ACPI_EBDA_PTR_LENGTH, (void *) &TablePtr);
648*3446Smrj         if (ACPI_FAILURE (Status))
649*3446Smrj         {
650*3446Smrj             ACPI_ERROR ((AE_INFO,
651*3446Smrj                 "Could not map memory at %8.8X for length %X",
652*3446Smrj                 ACPI_EBDA_PTR_LOCATION, ACPI_EBDA_PTR_LENGTH));
653*3446Smrj 
654*3446Smrj             return_ACPI_STATUS (Status);
655*3446Smrj         }
656*3446Smrj 
657*3446Smrj         ACPI_MOVE_16_TO_32 (&PhysicalAddress, TablePtr);
658*3446Smrj 
659*3446Smrj         /* Convert segment part to physical address */
660*3446Smrj 
661*3446Smrj         PhysicalAddress <<= 4;
662*3446Smrj         AcpiOsUnmapMemory (TablePtr, ACPI_EBDA_PTR_LENGTH);
663*3446Smrj 
664*3446Smrj         /* EBDA present? */
665*3446Smrj 
666*3446Smrj         if (PhysicalAddress > 0x400)
667*3446Smrj         {
668*3446Smrj             /*
669*3446Smrj              * 1b) Search EBDA paragraphs (EBDA is required to be a
670*3446Smrj              *     minimum of 1K length)
671*3446Smrj              */
672*3446Smrj             Status = AcpiOsMapMemory (
673*3446Smrj                         (ACPI_PHYSICAL_ADDRESS) PhysicalAddress,
674*3446Smrj                         ACPI_EBDA_WINDOW_SIZE, (void *) &TablePtr);
675*3446Smrj             if (ACPI_FAILURE (Status))
676*3446Smrj             {
677*3446Smrj                 ACPI_ERROR ((AE_INFO,
678*3446Smrj                     "Could not map memory at %8.8X for length %X",
679*3446Smrj                     PhysicalAddress, ACPI_EBDA_WINDOW_SIZE));
680*3446Smrj 
681*3446Smrj                 return_ACPI_STATUS (Status);
682*3446Smrj             }
683*3446Smrj 
684*3446Smrj             MemRover = AcpiTbScanMemoryForRsdp (TablePtr,
685*3446Smrj                             ACPI_EBDA_WINDOW_SIZE);
686*3446Smrj             AcpiOsUnmapMemory (TablePtr, ACPI_EBDA_WINDOW_SIZE);
687*3446Smrj 
688*3446Smrj             if (MemRover)
689*3446Smrj             {
690*3446Smrj                 /* Return the physical address */
691*3446Smrj 
692*3446Smrj                 PhysicalAddress += (UINT32) ACPI_PTR_DIFF (MemRover, TablePtr);
693*3446Smrj 
694*3446Smrj                 TableInfo->PhysicalAddress =
695*3446Smrj                     (ACPI_PHYSICAL_ADDRESS) PhysicalAddress;
696*3446Smrj                 return_ACPI_STATUS (AE_OK);
697*3446Smrj             }
698*3446Smrj         }
699*3446Smrj 
700*3446Smrj         /*
701*3446Smrj          * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
702*3446Smrj          */
703*3446Smrj         Status = AcpiOsMapMemory (
704*3446Smrj                     (ACPI_PHYSICAL_ADDRESS) ACPI_HI_RSDP_WINDOW_BASE,
705*3446Smrj                     ACPI_HI_RSDP_WINDOW_SIZE, (void *) &TablePtr);
706*3446Smrj 
707*3446Smrj         if (ACPI_FAILURE (Status))
708*3446Smrj         {
709*3446Smrj             ACPI_ERROR ((AE_INFO,
710*3446Smrj                 "Could not map memory at %8.8X for length %X",
711*3446Smrj                 ACPI_HI_RSDP_WINDOW_BASE, ACPI_HI_RSDP_WINDOW_SIZE));
712*3446Smrj 
713*3446Smrj             return_ACPI_STATUS (Status);
714*3446Smrj         }
715*3446Smrj 
716*3446Smrj         MemRover = AcpiTbScanMemoryForRsdp (TablePtr, ACPI_HI_RSDP_WINDOW_SIZE);
717*3446Smrj         AcpiOsUnmapMemory (TablePtr, ACPI_HI_RSDP_WINDOW_SIZE);
718*3446Smrj 
719*3446Smrj         if (MemRover)
720*3446Smrj         {
721*3446Smrj             /* Return the physical address */
722*3446Smrj 
723*3446Smrj             PhysicalAddress = (UINT32)
724*3446Smrj                 (ACPI_HI_RSDP_WINDOW_BASE + ACPI_PTR_DIFF (MemRover, TablePtr));
725*3446Smrj 
726*3446Smrj             TableInfo->PhysicalAddress =
727*3446Smrj                 (ACPI_PHYSICAL_ADDRESS) PhysicalAddress;
728*3446Smrj             return_ACPI_STATUS (AE_OK);
729*3446Smrj         }
730*3446Smrj     }
731*3446Smrj 
732*3446Smrj     /*
733*3446Smrj      * Physical addressing
734*3446Smrj      */
735*3446Smrj     else
736*3446Smrj     {
737*3446Smrj         /* 1a) Get the location of the EBDA */
738*3446Smrj 
739*3446Smrj         ACPI_MOVE_16_TO_32 (&PhysicalAddress, ACPI_EBDA_PTR_LOCATION);
740*3446Smrj         PhysicalAddress <<= 4;      /* Convert segment to physical address */
741*3446Smrj 
742*3446Smrj         /* EBDA present? */
743*3446Smrj 
744*3446Smrj         if (PhysicalAddress > 0x400)
745*3446Smrj         {
746*3446Smrj             /*
747*3446Smrj              * 1b) Search EBDA paragraphs (EBDA is required to be a minimum of
748*3446Smrj              *     1K length)
749*3446Smrj              */
750*3446Smrj             MemRover = AcpiTbScanMemoryForRsdp (
751*3446Smrj                             ACPI_PHYSADDR_TO_PTR (PhysicalAddress),
752*3446Smrj                             ACPI_EBDA_WINDOW_SIZE);
753*3446Smrj             if (MemRover)
754*3446Smrj             {
755*3446Smrj                 /* Return the physical address */
756*3446Smrj 
757*3446Smrj                 TableInfo->PhysicalAddress = ACPI_TO_INTEGER (MemRover);
758*3446Smrj                 return_ACPI_STATUS (AE_OK);
759*3446Smrj             }
760*3446Smrj         }
761*3446Smrj 
762*3446Smrj         /* 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh */
763*3446Smrj 
764*3446Smrj         MemRover = AcpiTbScanMemoryForRsdp (
765*3446Smrj                         ACPI_PHYSADDR_TO_PTR (ACPI_HI_RSDP_WINDOW_BASE),
766*3446Smrj                         ACPI_HI_RSDP_WINDOW_SIZE);
767*3446Smrj         if (MemRover)
768*3446Smrj         {
769*3446Smrj             /* Found it, return the physical address */
770*3446Smrj 
771*3446Smrj             TableInfo->PhysicalAddress = ACPI_TO_INTEGER (MemRover);
772*3446Smrj             return_ACPI_STATUS (AE_OK);
773*3446Smrj         }
774*3446Smrj     }
775*3446Smrj 
776*3446Smrj     /* A valid RSDP was not found */
777*3446Smrj 
778*3446Smrj     ACPI_ERROR ((AE_INFO, "No valid RSDP was found"));
779*3446Smrj     return_ACPI_STATUS (AE_NOT_FOUND);
780*3446Smrj }
781*3446Smrj 
782*3446Smrj #endif
783*3446Smrj 
784