tbxfroot.c revision 91116
1/******************************************************************************
2 *
3 * Module Name: tbxfroot - Find the root ACPI table (RSDT)
4 *              $Revision: 58 $
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
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
20 * property rights.
21 *
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
28 *
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;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
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.
54 *
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
65 * make.
66 *
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
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
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.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
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
89 * PARTICULAR PURPOSE.
90 *
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
98 * LIMITED REMEDY.
99 *
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.
114 *
115 *****************************************************************************/
116
117#define __TBXFROOT_C__
118
119#include "acpi.h"
120#include "actables.h"
121
122
123#define _COMPONENT          ACPI_TABLES
124        ACPI_MODULE_NAME    ("tbxfroot")
125
126
127/*******************************************************************************
128 *
129 * FUNCTION:    AcpiTbFindTable
130 *
131 * PARAMETERS:  Signature           - String with ACPI table signature
132 *              OemId               - String with the table OEM ID
133 *              OemTableId          - String with the OEM Table ID.
134 *
135 * RETURN:      Status
136 *
137 * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
138 *              Signature, OEM ID and OEM Table ID.
139 *
140 ******************************************************************************/
141
142ACPI_STATUS
143AcpiTbFindTable (
144    NATIVE_CHAR             *Signature,
145    NATIVE_CHAR             *OemId,
146    NATIVE_CHAR             *OemTableId,
147    ACPI_TABLE_HEADER       **TablePtr)
148{
149    ACPI_STATUS             Status;
150    ACPI_TABLE_HEADER       *Table;
151
152
153    ACPI_FUNCTION_TRACE ("TbFindTable");
154
155
156    /* Validate string lengths */
157
158    if ((ACPI_STRLEN (Signature)  > 4) ||
159        (ACPI_STRLEN (OemId)      > 6) ||
160        (ACPI_STRLEN (OemTableId) > 8))
161    {
162        return_ACPI_STATUS (AE_AML_STRING_LIMIT);
163    }
164
165    /* Find the table */
166
167    Status = AcpiGetFirmwareTable (Signature, 1,
168                        ACPI_LOGICAL_ADDRESSING, &Table);
169    if (ACPI_FAILURE (Status))
170    {
171        return_ACPI_STATUS (Status);
172    }
173
174    /* Check OemId and OemTableId */
175
176    if ((OemId[0]      && ACPI_STRCMP (OemId, Table->OemId)) ||
177        (OemTableId[0] && ACPI_STRCMP (OemTableId, Table->OemTableId)))
178    {
179        return_ACPI_STATUS (AE_AML_NAME_NOT_FOUND);
180    }
181
182    *TablePtr = Table;
183    return_ACPI_STATUS (AE_OK);
184}
185
186
187/*******************************************************************************
188 *
189 * FUNCTION:    AcpiGetFirmwareTable
190 *
191 * PARAMETERS:  Signature       - Any ACPI table signature
192 *              Instance        - the non zero instance of the table, allows
193 *                                support for multiple tables of the same type
194 *              Flags           - 0: Physical/Virtual support
195 *              RetBuffer       - pointer to a structure containing a buffer to
196 *                                receive the table
197 *
198 * RETURN:      Status
199 *
200 * DESCRIPTION: This function is called to get an ACPI table.  The caller
201 *              supplies an OutBuffer large enough to contain the entire ACPI
202 *              table.  Upon completion
203 *              the OutBuffer->Length field will indicate the number of bytes
204 *              copied into the OutBuffer->BufPtr buffer.  This table will be
205 *              a complete table including the header.
206 *
207 ******************************************************************************/
208
209ACPI_STATUS
210AcpiGetFirmwareTable (
211    ACPI_STRING             Signature,
212    UINT32                  Instance,
213    UINT32                  Flags,
214    ACPI_TABLE_HEADER       **TablePointer)
215{
216    ACPI_PHYSICAL_ADDRESS   PhysicalAddress;
217    ACPI_TABLE_HEADER       *RsdtPtr = NULL;
218    ACPI_TABLE_HEADER       *TablePtr;
219    ACPI_STATUS             Status;
220    UINT32                  RsdtSize = 0;
221    UINT32                  TableSize;
222    UINT32                  TableCount;
223    UINT32                  i;
224    UINT32                  j;
225
226
227    ACPI_FUNCTION_TRACE ("AcpiGetFirmwareTable");
228
229
230    /*
231     * Ensure that at least the table manager is initialized.  We don't
232     * require that the entire ACPI subsystem is up for this interface
233     */
234
235    /*
236     *  If we have a buffer, we must have a length too
237     */
238    if ((Instance == 0)                 ||
239        (!Signature)                    ||
240        (!TablePointer))
241    {
242        return_ACPI_STATUS (AE_BAD_PARAMETER);
243    }
244
245    if (!AcpiGbl_RSDP)
246    {
247        /* Get the RSDP */
248
249        Status = AcpiOsGetRootPointer (Flags, &PhysicalAddress);
250        if (ACPI_FAILURE (Status))
251        {
252            ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "RSDP  not found\n"));
253            return_ACPI_STATUS (AE_NO_ACPI_TABLES);
254        }
255
256        /* Map and validate the RSDP */
257
258        if ((Flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING)
259        {
260            Status = AcpiOsMapMemory (PhysicalAddress, sizeof (RSDP_DESCRIPTOR),
261                                        (void **) &AcpiGbl_RSDP);
262            if (ACPI_FAILURE (Status))
263            {
264                return_ACPI_STATUS (Status);
265            }
266        }
267        else
268        {
269            AcpiGbl_RSDP = ACPI_PHYSADDR_TO_PTR (PhysicalAddress);
270        }
271
272        /*
273         *  The signature and checksum must both be correct
274         */
275        if (ACPI_STRNCMP ((NATIVE_CHAR *) AcpiGbl_RSDP, RSDP_SIG, sizeof (RSDP_SIG)-1) != 0)
276        {
277            /* Nope, BAD Signature */
278
279            Status = AE_BAD_SIGNATURE;
280            goto Cleanup;
281        }
282
283        if (AcpiTbChecksum (AcpiGbl_RSDP, ACPI_RSDP_CHECKSUM_LENGTH) != 0)
284        {
285            /* Nope, BAD Checksum */
286
287            Status = AE_BAD_CHECKSUM;
288            goto Cleanup;
289        }
290    }
291
292    ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
293        "RSDP located at %p, RSDT physical=%8.8X%8.8X \n",
294        AcpiGbl_RSDP,
295        ACPI_HIDWORD (AcpiGbl_RSDP->RsdtPhysicalAddress),
296        ACPI_LODWORD (AcpiGbl_RSDP->RsdtPhysicalAddress)));
297
298    /* Get the RSDT and validate it */
299
300    PhysicalAddress = AcpiTbGetRsdtAddress ();
301    Status = AcpiTbGetTablePointer (PhysicalAddress, Flags, &RsdtSize, &RsdtPtr);
302    if (ACPI_FAILURE (Status))
303    {
304        return_ACPI_STATUS (Status);
305    }
306
307    Status = AcpiTbValidateRsdt (RsdtPtr);
308    if (ACPI_FAILURE (Status))
309    {
310        goto Cleanup;
311    }
312
313    /* Get the number of table pointers within the RSDT */
314
315    TableCount = AcpiTbGetTableCount (AcpiGbl_RSDP, RsdtPtr);
316
317
318    /*
319     * Search the RSDT/XSDT for the correct instance of the
320     * requested table
321     */
322    for (i = 0, j = 0; i < TableCount; i++)
323    {
324        /* Get the next table pointer */
325
326        if (AcpiGbl_RSDP->Revision < 2)
327        {
328            PhysicalAddress = (ACPI_PHYSICAL_ADDRESS)
329                ((RSDT_DESCRIPTOR *) RsdtPtr)->TableOffsetEntry[i];
330        }
331        else
332        {
333            PhysicalAddress = (ACPI_PHYSICAL_ADDRESS)
334                ACPI_GET_ADDRESS (((XSDT_DESCRIPTOR *) RsdtPtr)->TableOffsetEntry[i]);
335        }
336
337        /* Get addressibility if necessary */
338
339        Status = AcpiTbGetTablePointer (PhysicalAddress, Flags, &TableSize, &TablePtr);
340        if (ACPI_FAILURE (Status))
341        {
342            goto Cleanup;
343        }
344
345        /* Compare table signatures and table instance */
346
347        if (!ACPI_STRNCMP ((char *) TablePtr, Signature, ACPI_STRLEN (Signature)))
348        {
349            /* An instance of the table was found */
350
351            j++;
352            if (j >= Instance)
353            {
354                /* Found the correct instance */
355
356                *TablePointer = TablePtr;
357                goto Cleanup;
358            }
359        }
360
361        /* Delete table mapping if using virtual addressing */
362
363        if ((TableSize) &&
364            ((Flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING))
365        {
366            AcpiOsUnmapMemory (TablePtr, TableSize);
367        }
368    }
369
370    /* Did not find the table */
371
372    Status = AE_NOT_EXIST;
373
374
375Cleanup:
376    if (RsdtSize)
377    {
378        AcpiOsUnmapMemory (RsdtPtr, RsdtSize);
379    }
380    return_ACPI_STATUS (Status);
381}
382
383
384/* TBD: Move to a new file */
385
386#ifndef _IA16
387
388/*******************************************************************************
389 *
390 * FUNCTION:    AcpiFindRootPointer
391 *
392 * PARAMETERS:  **RsdpPhysicalAddress       - Where to place the RSDP address
393 *              Flags                       - Logical/Physical addressing
394 *
395 * RETURN:      Status, Physical address of the RSDP
396 *
397 * DESCRIPTION: Find the RSDP
398 *
399 ******************************************************************************/
400
401ACPI_STATUS
402AcpiFindRootPointer (
403    UINT32                  Flags,
404    ACPI_PHYSICAL_ADDRESS   *RsdpPhysicalAddress)
405{
406    ACPI_TABLE_DESC         TableInfo;
407    ACPI_STATUS             Status;
408
409
410    ACPI_FUNCTION_TRACE ("AcpiFindRootPointer");
411
412
413    /* Get the RSDP */
414
415    Status = AcpiTbFindRsdp (&TableInfo, Flags);
416    if (ACPI_FAILURE (Status))
417    {
418        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "RSDP structure not found\n"));
419        return_ACPI_STATUS (AE_NO_ACPI_TABLES);
420    }
421
422    *RsdpPhysicalAddress = TableInfo.PhysicalAddress;
423    return_ACPI_STATUS (AE_OK);
424}
425
426
427/*******************************************************************************
428 *
429 * FUNCTION:    AcpiTbScanMemoryForRsdp
430 *
431 * PARAMETERS:  StartAddress        - Starting pointer for search
432 *              Length              - Maximum length to search
433 *
434 * RETURN:      Pointer to the RSDP if found, otherwise NULL.
435 *
436 * DESCRIPTION: Search a block of memory for the RSDP signature
437 *
438 ******************************************************************************/
439
440UINT8 *
441AcpiTbScanMemoryForRsdp (
442    UINT8                   *StartAddress,
443    UINT32                  Length)
444{
445    UINT32                  Offset;
446    UINT8                   *MemRover;
447
448
449    ACPI_FUNCTION_TRACE ("TbScanMemoryForRsdp");
450
451
452    /* Search from given start addr for the requested length  */
453
454    for (Offset = 0, MemRover = StartAddress;
455         Offset < Length;
456         Offset += RSDP_SCAN_STEP, MemRover += RSDP_SCAN_STEP)
457    {
458
459        /* The signature and checksum must both be correct */
460
461        if (ACPI_STRNCMP ((NATIVE_CHAR *) MemRover,
462                RSDP_SIG, sizeof (RSDP_SIG)-1) == 0 &&
463            AcpiTbChecksum (MemRover, ACPI_RSDP_CHECKSUM_LENGTH) == 0)
464        {
465            /* If so, we have found the RSDP */
466
467            ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
468                "RSDP located at physical address %p\n",MemRover));
469            return_PTR (MemRover);
470        }
471    }
472
473    /* Searched entire block, no RSDP was found */
474
475    ACPI_DEBUG_PRINT ((ACPI_DB_INFO,"Searched entire block, no RSDP was found.\n"));
476    return_PTR (NULL);
477}
478
479
480/*******************************************************************************
481 *
482 * FUNCTION:    AcpiTbFindRsdp
483 *
484 * PARAMETERS:  *TableInfo              - Where the table info is returned
485 *              Flags                   - Current memory mode (logical vs.
486 *                                        physical addressing)
487 *
488 * RETURN:      Status
489 *
490 * DESCRIPTION: Search lower 1Mbyte of memory for the root system descriptor
491 *              pointer structure.  If it is found, set *RSDP to point to it.
492 *
493 *              NOTE: The RSDP must be either in the first 1K of the Extended
494 *              BIOS Data Area or between E0000 and FFFFF (ACPI 1.0 section
495 *              5.2.2; assertion #421).
496 *
497 ******************************************************************************/
498
499ACPI_STATUS
500AcpiTbFindRsdp (
501    ACPI_TABLE_DESC         *TableInfo,
502    UINT32                  Flags)
503{
504    UINT8                   *TablePtr;
505    UINT8                   *MemRover;
506    UINT64                  PhysAddr;
507    ACPI_STATUS             Status = AE_OK;
508
509
510    ACPI_FUNCTION_TRACE ("TbFindRsdp");
511
512
513    /*
514     * Scan supports either 1) Logical addressing or 2) Physical addressing
515     */
516    if ((Flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING)
517    {
518        /*
519         * 1) Search EBDA (low memory) paragraphs
520         */
521        Status = AcpiOsMapMemory ((UINT64) LO_RSDP_WINDOW_BASE, LO_RSDP_WINDOW_SIZE,
522                                    (void **) &TablePtr);
523        if (ACPI_FAILURE (Status))
524        {
525            return_ACPI_STATUS (Status);
526        }
527
528        MemRover = AcpiTbScanMemoryForRsdp (TablePtr, LO_RSDP_WINDOW_SIZE);
529        AcpiOsUnmapMemory (TablePtr, LO_RSDP_WINDOW_SIZE);
530
531        if (MemRover)
532        {
533            /* Found it, return the physical address */
534
535            PhysAddr = LO_RSDP_WINDOW_BASE;
536            PhysAddr += (MemRover - TablePtr);
537
538            TableInfo->PhysicalAddress = PhysAddr;
539            return_ACPI_STATUS (AE_OK);
540        }
541
542        /*
543         * 2) Search upper memory: 16-byte boundaries in E0000h-F0000h
544         */
545        Status = AcpiOsMapMemory ((UINT64) HI_RSDP_WINDOW_BASE, HI_RSDP_WINDOW_SIZE,
546                                    (void **) &TablePtr);
547        if (ACPI_FAILURE (Status))
548        {
549            return_ACPI_STATUS (Status);
550        }
551
552        MemRover = AcpiTbScanMemoryForRsdp (TablePtr, HI_RSDP_WINDOW_SIZE);
553        AcpiOsUnmapMemory (TablePtr, HI_RSDP_WINDOW_SIZE);
554
555        if (MemRover)
556        {
557            /* Found it, return the physical address */
558
559            PhysAddr = HI_RSDP_WINDOW_BASE;
560            PhysAddr += (MemRover - TablePtr);
561
562            TableInfo->PhysicalAddress = PhysAddr;
563            return_ACPI_STATUS (AE_OK);
564        }
565    }
566
567    /*
568     * Physical addressing
569     */
570    else
571    {
572        /*
573         * 1) Search EBDA (low memory) paragraphs
574         */
575        MemRover = AcpiTbScanMemoryForRsdp (ACPI_PHYSADDR_TO_PTR (LO_RSDP_WINDOW_BASE),
576                        LO_RSDP_WINDOW_SIZE);
577        if (MemRover)
578        {
579            /* Found it, return the physical address */
580
581            TableInfo->PhysicalAddress = ACPI_TO_INTEGER (MemRover);
582            return_ACPI_STATUS (AE_OK);
583        }
584
585        /*
586         * 2) Search upper memory: 16-byte boundaries in E0000h-F0000h
587         */
588        MemRover = AcpiTbScanMemoryForRsdp (ACPI_PHYSADDR_TO_PTR (HI_RSDP_WINDOW_BASE),
589                        HI_RSDP_WINDOW_SIZE);
590        if (MemRover)
591        {
592            /* Found it, return the physical address */
593
594            TableInfo->PhysicalAddress = ACPI_TO_INTEGER (MemRover);
595            return_ACPI_STATUS (AE_OK);
596        }
597    }
598
599    /* RSDP signature was not found */
600
601    return_ACPI_STATUS (AE_NOT_FOUND);
602}
603
604#endif
605
606