xref: /titanic_44/usr/src/cmd/acpi/acpidump/tbxfroot.c (revision cb56572868bfc488bbd3ab847b09db2a25554d44)
1*cb565728SJerry Jelinek /******************************************************************************
2*cb565728SJerry Jelinek  *
3*cb565728SJerry Jelinek  * Module Name: tbxfroot - Find the root ACPI table (RSDT)
4*cb565728SJerry Jelinek  *
5*cb565728SJerry Jelinek  *****************************************************************************/
6*cb565728SJerry Jelinek 
7*cb565728SJerry Jelinek /*
8*cb565728SJerry Jelinek  * Copyright (C) 2000 - 2016, Intel Corp.
9*cb565728SJerry Jelinek  * All rights reserved.
10*cb565728SJerry Jelinek  *
11*cb565728SJerry Jelinek  * Redistribution and use in source and binary forms, with or without
12*cb565728SJerry Jelinek  * modification, are permitted provided that the following conditions
13*cb565728SJerry Jelinek  * are met:
14*cb565728SJerry Jelinek  * 1. Redistributions of source code must retain the above copyright
15*cb565728SJerry Jelinek  *    notice, this list of conditions, and the following disclaimer,
16*cb565728SJerry Jelinek  *    without modification.
17*cb565728SJerry Jelinek  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*cb565728SJerry Jelinek  *    substantially similar to the "NO WARRANTY" disclaimer below
19*cb565728SJerry Jelinek  *    ("Disclaimer") and any redistribution must be conditioned upon
20*cb565728SJerry Jelinek  *    including a substantially similar Disclaimer requirement for further
21*cb565728SJerry Jelinek  *    binary redistribution.
22*cb565728SJerry Jelinek  * 3. Neither the names of the above-listed copyright holders nor the names
23*cb565728SJerry Jelinek  *    of any contributors may be used to endorse or promote products derived
24*cb565728SJerry Jelinek  *    from this software without specific prior written permission.
25*cb565728SJerry Jelinek  *
26*cb565728SJerry Jelinek  * Alternatively, this software may be distributed under the terms of the
27*cb565728SJerry Jelinek  * GNU General Public License ("GPL") version 2 as published by the Free
28*cb565728SJerry Jelinek  * Software Foundation.
29*cb565728SJerry Jelinek  *
30*cb565728SJerry Jelinek  * NO WARRANTY
31*cb565728SJerry Jelinek  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*cb565728SJerry Jelinek  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*cb565728SJerry Jelinek  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*cb565728SJerry Jelinek  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*cb565728SJerry Jelinek  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*cb565728SJerry Jelinek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*cb565728SJerry Jelinek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*cb565728SJerry Jelinek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*cb565728SJerry Jelinek  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*cb565728SJerry Jelinek  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*cb565728SJerry Jelinek  * POSSIBILITY OF SUCH DAMAGES.
42*cb565728SJerry Jelinek  */
43*cb565728SJerry Jelinek 
44*cb565728SJerry Jelinek #include "acpi.h"
45*cb565728SJerry Jelinek #include "accommon.h"
46*cb565728SJerry Jelinek #include "actables.h"
47*cb565728SJerry Jelinek 
48*cb565728SJerry Jelinek 
49*cb565728SJerry Jelinek #define _COMPONENT          ACPI_TABLES
50*cb565728SJerry Jelinek         ACPI_MODULE_NAME    ("tbxfroot")
51*cb565728SJerry Jelinek 
52*cb565728SJerry Jelinek 
53*cb565728SJerry Jelinek /*******************************************************************************
54*cb565728SJerry Jelinek  *
55*cb565728SJerry Jelinek  * FUNCTION:    AcpiTbGetRsdpLength
56*cb565728SJerry Jelinek  *
57*cb565728SJerry Jelinek  * PARAMETERS:  Rsdp                - Pointer to RSDP
58*cb565728SJerry Jelinek  *
59*cb565728SJerry Jelinek  * RETURN:      Table length
60*cb565728SJerry Jelinek  *
61*cb565728SJerry Jelinek  * DESCRIPTION: Get the length of the RSDP
62*cb565728SJerry Jelinek  *
63*cb565728SJerry Jelinek  ******************************************************************************/
64*cb565728SJerry Jelinek 
65*cb565728SJerry Jelinek UINT32
AcpiTbGetRsdpLength(ACPI_TABLE_RSDP * Rsdp)66*cb565728SJerry Jelinek AcpiTbGetRsdpLength (
67*cb565728SJerry Jelinek     ACPI_TABLE_RSDP         *Rsdp)
68*cb565728SJerry Jelinek {
69*cb565728SJerry Jelinek 
70*cb565728SJerry Jelinek     if (!ACPI_VALIDATE_RSDP_SIG (Rsdp->Signature))
71*cb565728SJerry Jelinek     {
72*cb565728SJerry Jelinek         /* BAD Signature */
73*cb565728SJerry Jelinek 
74*cb565728SJerry Jelinek         return (0);
75*cb565728SJerry Jelinek     }
76*cb565728SJerry Jelinek 
77*cb565728SJerry Jelinek     /* "Length" field is available if table version >= 2 */
78*cb565728SJerry Jelinek 
79*cb565728SJerry Jelinek     if (Rsdp->Revision >= 2)
80*cb565728SJerry Jelinek     {
81*cb565728SJerry Jelinek         return (Rsdp->Length);
82*cb565728SJerry Jelinek     }
83*cb565728SJerry Jelinek     else
84*cb565728SJerry Jelinek     {
85*cb565728SJerry Jelinek         return (ACPI_RSDP_CHECKSUM_LENGTH);
86*cb565728SJerry Jelinek     }
87*cb565728SJerry Jelinek }
88*cb565728SJerry Jelinek 
89*cb565728SJerry Jelinek 
90*cb565728SJerry Jelinek /*******************************************************************************
91*cb565728SJerry Jelinek  *
92*cb565728SJerry Jelinek  * FUNCTION:    AcpiTbValidateRsdp
93*cb565728SJerry Jelinek  *
94*cb565728SJerry Jelinek  * PARAMETERS:  Rsdp                - Pointer to unvalidated RSDP
95*cb565728SJerry Jelinek  *
96*cb565728SJerry Jelinek  * RETURN:      Status
97*cb565728SJerry Jelinek  *
98*cb565728SJerry Jelinek  * DESCRIPTION: Validate the RSDP (ptr)
99*cb565728SJerry Jelinek  *
100*cb565728SJerry Jelinek  ******************************************************************************/
101*cb565728SJerry Jelinek 
102*cb565728SJerry Jelinek ACPI_STATUS
AcpiTbValidateRsdp(ACPI_TABLE_RSDP * Rsdp)103*cb565728SJerry Jelinek AcpiTbValidateRsdp (
104*cb565728SJerry Jelinek     ACPI_TABLE_RSDP         *Rsdp)
105*cb565728SJerry Jelinek {
106*cb565728SJerry Jelinek 
107*cb565728SJerry Jelinek     /*
108*cb565728SJerry Jelinek      * The signature and checksum must both be correct
109*cb565728SJerry Jelinek      *
110*cb565728SJerry Jelinek      * Note: Sometimes there exists more than one RSDP in memory; the valid
111*cb565728SJerry Jelinek      * RSDP has a valid checksum, all others have an invalid checksum.
112*cb565728SJerry Jelinek      */
113*cb565728SJerry Jelinek     if (!ACPI_VALIDATE_RSDP_SIG (Rsdp->Signature))
114*cb565728SJerry Jelinek     {
115*cb565728SJerry Jelinek         /* Nope, BAD Signature */
116*cb565728SJerry Jelinek 
117*cb565728SJerry Jelinek         return (AE_BAD_SIGNATURE);
118*cb565728SJerry Jelinek     }
119*cb565728SJerry Jelinek 
120*cb565728SJerry Jelinek     /* Check the standard checksum */
121*cb565728SJerry Jelinek 
122*cb565728SJerry Jelinek     if (AcpiTbChecksum ((UINT8 *) Rsdp, ACPI_RSDP_CHECKSUM_LENGTH) != 0)
123*cb565728SJerry Jelinek     {
124*cb565728SJerry Jelinek         return (AE_BAD_CHECKSUM);
125*cb565728SJerry Jelinek     }
126*cb565728SJerry Jelinek 
127*cb565728SJerry Jelinek     /* Check extended checksum if table version >= 2 */
128*cb565728SJerry Jelinek 
129*cb565728SJerry Jelinek     if ((Rsdp->Revision >= 2) &&
130*cb565728SJerry Jelinek         (AcpiTbChecksum ((UINT8 *) Rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0))
131*cb565728SJerry Jelinek     {
132*cb565728SJerry Jelinek         return (AE_BAD_CHECKSUM);
133*cb565728SJerry Jelinek     }
134*cb565728SJerry Jelinek 
135*cb565728SJerry Jelinek     return (AE_OK);
136*cb565728SJerry Jelinek }
137*cb565728SJerry Jelinek 
138*cb565728SJerry Jelinek 
139*cb565728SJerry Jelinek /*******************************************************************************
140*cb565728SJerry Jelinek  *
141*cb565728SJerry Jelinek  * FUNCTION:    AcpiFindRootPointer
142*cb565728SJerry Jelinek  *
143*cb565728SJerry Jelinek  * PARAMETERS:  TableAddress            - Where the table pointer is returned
144*cb565728SJerry Jelinek  *
145*cb565728SJerry Jelinek  * RETURN:      Status, RSDP physical address
146*cb565728SJerry Jelinek  *
147*cb565728SJerry Jelinek  * DESCRIPTION: Search lower 1Mbyte of memory for the root system descriptor
148*cb565728SJerry Jelinek  *              pointer structure. If it is found, set *RSDP to point to it.
149*cb565728SJerry Jelinek  *
150*cb565728SJerry Jelinek  * NOTE1:       The RSDP must be either in the first 1K of the Extended
151*cb565728SJerry Jelinek  *              BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
152*cb565728SJerry Jelinek  *              Only a 32-bit physical address is necessary.
153*cb565728SJerry Jelinek  *
154*cb565728SJerry Jelinek  * NOTE2:       This function is always available, regardless of the
155*cb565728SJerry Jelinek  *              initialization state of the rest of ACPI.
156*cb565728SJerry Jelinek  *
157*cb565728SJerry Jelinek  ******************************************************************************/
158*cb565728SJerry Jelinek 
159*cb565728SJerry Jelinek ACPI_STATUS
AcpiFindRootPointer(ACPI_PHYSICAL_ADDRESS * TableAddress)160*cb565728SJerry Jelinek AcpiFindRootPointer (
161*cb565728SJerry Jelinek     ACPI_PHYSICAL_ADDRESS   *TableAddress)
162*cb565728SJerry Jelinek {
163*cb565728SJerry Jelinek     UINT8                   *TablePtr;
164*cb565728SJerry Jelinek     UINT8                   *MemRover;
165*cb565728SJerry Jelinek     UINT32                  PhysicalAddress;
166*cb565728SJerry Jelinek 
167*cb565728SJerry Jelinek 
168*cb565728SJerry Jelinek     ACPI_FUNCTION_TRACE (AcpiFindRootPointer);
169*cb565728SJerry Jelinek 
170*cb565728SJerry Jelinek 
171*cb565728SJerry Jelinek     /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
172*cb565728SJerry Jelinek 
173*cb565728SJerry Jelinek     TablePtr = AcpiOsMapMemory (
174*cb565728SJerry Jelinek         (ACPI_PHYSICAL_ADDRESS) ACPI_EBDA_PTR_LOCATION,
175*cb565728SJerry Jelinek         ACPI_EBDA_PTR_LENGTH);
176*cb565728SJerry Jelinek     if (!TablePtr)
177*cb565728SJerry Jelinek     {
178*cb565728SJerry Jelinek         ACPI_ERROR ((AE_INFO,
179*cb565728SJerry Jelinek             "Could not map memory at 0x%8.8X for length %u",
180*cb565728SJerry Jelinek             ACPI_EBDA_PTR_LOCATION, ACPI_EBDA_PTR_LENGTH));
181*cb565728SJerry Jelinek 
182*cb565728SJerry Jelinek         return_ACPI_STATUS (AE_NO_MEMORY);
183*cb565728SJerry Jelinek     }
184*cb565728SJerry Jelinek 
185*cb565728SJerry Jelinek     ACPI_MOVE_16_TO_32 (&PhysicalAddress, TablePtr);
186*cb565728SJerry Jelinek 
187*cb565728SJerry Jelinek     /* Convert segment part to physical address */
188*cb565728SJerry Jelinek 
189*cb565728SJerry Jelinek     PhysicalAddress <<= 4;
190*cb565728SJerry Jelinek     AcpiOsUnmapMemory (TablePtr, ACPI_EBDA_PTR_LENGTH);
191*cb565728SJerry Jelinek 
192*cb565728SJerry Jelinek     /* EBDA present? */
193*cb565728SJerry Jelinek 
194*cb565728SJerry Jelinek     if (PhysicalAddress > 0x400)
195*cb565728SJerry Jelinek     {
196*cb565728SJerry Jelinek         /*
197*cb565728SJerry Jelinek          * 1b) Search EBDA paragraphs (EBDA is required to be a
198*cb565728SJerry Jelinek          *     minimum of 1K length)
199*cb565728SJerry Jelinek          */
200*cb565728SJerry Jelinek         TablePtr = AcpiOsMapMemory (
201*cb565728SJerry Jelinek             (ACPI_PHYSICAL_ADDRESS) PhysicalAddress,
202*cb565728SJerry Jelinek             ACPI_EBDA_WINDOW_SIZE);
203*cb565728SJerry Jelinek         if (!TablePtr)
204*cb565728SJerry Jelinek         {
205*cb565728SJerry Jelinek             ACPI_ERROR ((AE_INFO,
206*cb565728SJerry Jelinek                 "Could not map memory at 0x%8.8X for length %u",
207*cb565728SJerry Jelinek                 PhysicalAddress, ACPI_EBDA_WINDOW_SIZE));
208*cb565728SJerry Jelinek 
209*cb565728SJerry Jelinek             return_ACPI_STATUS (AE_NO_MEMORY);
210*cb565728SJerry Jelinek         }
211*cb565728SJerry Jelinek 
212*cb565728SJerry Jelinek         MemRover = AcpiTbScanMemoryForRsdp (
213*cb565728SJerry Jelinek             TablePtr, ACPI_EBDA_WINDOW_SIZE);
214*cb565728SJerry Jelinek         AcpiOsUnmapMemory (TablePtr, ACPI_EBDA_WINDOW_SIZE);
215*cb565728SJerry Jelinek 
216*cb565728SJerry Jelinek         if (MemRover)
217*cb565728SJerry Jelinek         {
218*cb565728SJerry Jelinek             /* Return the physical address */
219*cb565728SJerry Jelinek 
220*cb565728SJerry Jelinek             PhysicalAddress +=
221*cb565728SJerry Jelinek                 (UINT32) ACPI_PTR_DIFF (MemRover, TablePtr);
222*cb565728SJerry Jelinek 
223*cb565728SJerry Jelinek             *TableAddress = (ACPI_PHYSICAL_ADDRESS) PhysicalAddress;
224*cb565728SJerry Jelinek             return_ACPI_STATUS (AE_OK);
225*cb565728SJerry Jelinek         }
226*cb565728SJerry Jelinek     }
227*cb565728SJerry Jelinek 
228*cb565728SJerry Jelinek     /*
229*cb565728SJerry Jelinek      * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
230*cb565728SJerry Jelinek      */
231*cb565728SJerry Jelinek     TablePtr = AcpiOsMapMemory (
232*cb565728SJerry Jelinek         (ACPI_PHYSICAL_ADDRESS) ACPI_HI_RSDP_WINDOW_BASE,
233*cb565728SJerry Jelinek         ACPI_HI_RSDP_WINDOW_SIZE);
234*cb565728SJerry Jelinek 
235*cb565728SJerry Jelinek     if (!TablePtr)
236*cb565728SJerry Jelinek     {
237*cb565728SJerry Jelinek         ACPI_ERROR ((AE_INFO,
238*cb565728SJerry Jelinek             "Could not map memory at 0x%8.8X for length %u",
239*cb565728SJerry Jelinek             ACPI_HI_RSDP_WINDOW_BASE, ACPI_HI_RSDP_WINDOW_SIZE));
240*cb565728SJerry Jelinek 
241*cb565728SJerry Jelinek         return_ACPI_STATUS (AE_NO_MEMORY);
242*cb565728SJerry Jelinek     }
243*cb565728SJerry Jelinek 
244*cb565728SJerry Jelinek     MemRover = AcpiTbScanMemoryForRsdp (
245*cb565728SJerry Jelinek         TablePtr, ACPI_HI_RSDP_WINDOW_SIZE);
246*cb565728SJerry Jelinek     AcpiOsUnmapMemory (TablePtr, ACPI_HI_RSDP_WINDOW_SIZE);
247*cb565728SJerry Jelinek 
248*cb565728SJerry Jelinek     if (MemRover)
249*cb565728SJerry Jelinek     {
250*cb565728SJerry Jelinek         /* Return the physical address */
251*cb565728SJerry Jelinek 
252*cb565728SJerry Jelinek         PhysicalAddress = (UINT32)
253*cb565728SJerry Jelinek             (ACPI_HI_RSDP_WINDOW_BASE + ACPI_PTR_DIFF (MemRover, TablePtr));
254*cb565728SJerry Jelinek 
255*cb565728SJerry Jelinek         *TableAddress = (ACPI_PHYSICAL_ADDRESS) PhysicalAddress;
256*cb565728SJerry Jelinek         return_ACPI_STATUS (AE_OK);
257*cb565728SJerry Jelinek     }
258*cb565728SJerry Jelinek 
259*cb565728SJerry Jelinek     /* A valid RSDP was not found */
260*cb565728SJerry Jelinek 
261*cb565728SJerry Jelinek     ACPI_BIOS_ERROR ((AE_INFO, "A valid RSDP was not found"));
262*cb565728SJerry Jelinek     return_ACPI_STATUS (AE_NOT_FOUND);
263*cb565728SJerry Jelinek }
264*cb565728SJerry Jelinek 
ACPI_EXPORT_SYMBOL(AcpiFindRootPointer)265*cb565728SJerry Jelinek ACPI_EXPORT_SYMBOL (AcpiFindRootPointer)
266*cb565728SJerry Jelinek 
267*cb565728SJerry Jelinek 
268*cb565728SJerry Jelinek /*******************************************************************************
269*cb565728SJerry Jelinek  *
270*cb565728SJerry Jelinek  * FUNCTION:    AcpiTbScanMemoryForRsdp
271*cb565728SJerry Jelinek  *
272*cb565728SJerry Jelinek  * PARAMETERS:  StartAddress        - Starting pointer for search
273*cb565728SJerry Jelinek  *              Length              - Maximum length to search
274*cb565728SJerry Jelinek  *
275*cb565728SJerry Jelinek  * RETURN:      Pointer to the RSDP if found, otherwise NULL.
276*cb565728SJerry Jelinek  *
277*cb565728SJerry Jelinek  * DESCRIPTION: Search a block of memory for the RSDP signature
278*cb565728SJerry Jelinek  *
279*cb565728SJerry Jelinek  ******************************************************************************/
280*cb565728SJerry Jelinek 
281*cb565728SJerry Jelinek UINT8 *
282*cb565728SJerry Jelinek AcpiTbScanMemoryForRsdp (
283*cb565728SJerry Jelinek     UINT8                   *StartAddress,
284*cb565728SJerry Jelinek     UINT32                  Length)
285*cb565728SJerry Jelinek {
286*cb565728SJerry Jelinek     ACPI_STATUS             Status;
287*cb565728SJerry Jelinek     UINT8                   *MemRover;
288*cb565728SJerry Jelinek     UINT8                   *EndAddress;
289*cb565728SJerry Jelinek 
290*cb565728SJerry Jelinek 
291*cb565728SJerry Jelinek     ACPI_FUNCTION_TRACE (TbScanMemoryForRsdp);
292*cb565728SJerry Jelinek 
293*cb565728SJerry Jelinek 
294*cb565728SJerry Jelinek     EndAddress = StartAddress + Length;
295*cb565728SJerry Jelinek 
296*cb565728SJerry Jelinek     /* Search from given start address for the requested length */
297*cb565728SJerry Jelinek 
298*cb565728SJerry Jelinek     for (MemRover = StartAddress; MemRover < EndAddress;
299*cb565728SJerry Jelinek          MemRover += ACPI_RSDP_SCAN_STEP)
300*cb565728SJerry Jelinek     {
301*cb565728SJerry Jelinek         /* The RSDP signature and checksum must both be correct */
302*cb565728SJerry Jelinek 
303*cb565728SJerry Jelinek         Status = AcpiTbValidateRsdp (
304*cb565728SJerry Jelinek             ACPI_CAST_PTR (ACPI_TABLE_RSDP, MemRover));
305*cb565728SJerry Jelinek         if (ACPI_SUCCESS (Status))
306*cb565728SJerry Jelinek         {
307*cb565728SJerry Jelinek             /* Sig and checksum valid, we have found a real RSDP */
308*cb565728SJerry Jelinek 
309*cb565728SJerry Jelinek             ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
310*cb565728SJerry Jelinek                 "RSDP located at physical address %p\n", MemRover));
311*cb565728SJerry Jelinek             return_PTR (MemRover);
312*cb565728SJerry Jelinek         }
313*cb565728SJerry Jelinek 
314*cb565728SJerry Jelinek         /* No sig match or bad checksum, keep searching */
315*cb565728SJerry Jelinek     }
316*cb565728SJerry Jelinek 
317*cb565728SJerry Jelinek     /* Searched entire block, no RSDP was found */
318*cb565728SJerry Jelinek 
319*cb565728SJerry Jelinek     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
320*cb565728SJerry Jelinek         "Searched entire block from %p, valid RSDP was not found\n",
321*cb565728SJerry Jelinek         StartAddress));
322*cb565728SJerry Jelinek     return_PTR (NULL);
323*cb565728SJerry Jelinek }
324