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