Deleted Added
full compact
tbxfroot.c (126372) tbxfroot.c (131440)
1/******************************************************************************
2 *
3 * Module Name: tbxfroot - Find the root ACPI table (RSDT)
1/******************************************************************************
2 *
3 * Module Name: tbxfroot - Find the root ACPI table (RSDT)
4 * $Revision: 72 $
4 * $Revision: 73 $
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2004, 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 char *Signature,
145 char *OemId,
146 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) > ACPI_NAME_SIZE) ||
159 (ACPI_STRLEN (OemId) > sizeof (Table->OemId)) ||
160 (ACPI_STRLEN (OemTableId) > sizeof (Table->OemTableId)))
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 - 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_POINTER RsdpAddress;
217 ACPI_POINTER Address;
218 ACPI_STATUS Status;
219 ACPI_TABLE_HEADER Header;
220 ACPI_TABLE_DESC TableInfo;
221 ACPI_TABLE_DESC RsdtInfo;
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 RsdtInfo.Pointer = NULL;
246
247 if (!AcpiGbl_RSDP)
248 {
249 /* Get the RSDP */
250
251 Status = AcpiOsGetRootPointer (Flags, &RsdpAddress);
252 if (ACPI_FAILURE (Status))
253 {
254 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "RSDP not found\n"));
255 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
256 }
257
258 /* Map and validate the RSDP */
259
260 if ((Flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING)
261 {
262 Status = AcpiOsMapMemory (RsdpAddress.Pointer.Physical, sizeof (RSDP_DESCRIPTOR),
263 (void *) &AcpiGbl_RSDP);
264 if (ACPI_FAILURE (Status))
265 {
266 return_ACPI_STATUS (Status);
267 }
268 }
269 else
270 {
271 AcpiGbl_RSDP = RsdpAddress.Pointer.Logical;
272 }
273
274 /*
275 * The signature and checksum must both be correct
276 */
277 if (ACPI_STRNCMP ((char *) AcpiGbl_RSDP, RSDP_SIG, sizeof (RSDP_SIG)-1) != 0)
278 {
279 /* Nope, BAD Signature */
280
281 return_ACPI_STATUS (AE_BAD_SIGNATURE);
282 }
283
284 if (AcpiTbChecksum (AcpiGbl_RSDP, ACPI_RSDP_CHECKSUM_LENGTH) != 0)
285 {
286 /* Nope, BAD Checksum */
287
288 return_ACPI_STATUS (AE_BAD_CHECKSUM);
289 }
290 }
291
292 /* Get the RSDT and validate it */
293
294 AcpiTbGetRsdtAddress (&Address);
295
296 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
297 "RSDP located at %p, RSDT physical=%8.8X%8.8X \n",
298 AcpiGbl_RSDP,
299 ACPI_FORMAT_UINT64 (Address.Pointer.Value)));
300
301 /* Insert ProcessorMode flags */
302
303 Address.PointerType |= Flags;
304
305 Status = AcpiTbGetTable (&Address, &RsdtInfo);
306 if (ACPI_FAILURE (Status))
307 {
308 return_ACPI_STATUS (Status);
309 }
310
311 Status = AcpiTbValidateRsdt (RsdtInfo.Pointer);
312 if (ACPI_FAILURE (Status))
313 {
314 goto Cleanup;
315 }
316
317 /* Get the number of table pointers within the RSDT */
318
319 TableCount = AcpiTbGetTableCount (AcpiGbl_RSDP, RsdtInfo.Pointer);
320
321 Address.PointerType = AcpiGbl_TableFlags | Flags;
322
323 /*
324 * Search the RSDT/XSDT for the correct instance of the
325 * requested table
326 */
327 for (i = 0, j = 0; i < TableCount; i++)
328 {
329 /* Get the next table pointer, handle RSDT vs. XSDT */
330
331 if (AcpiGbl_RSDP->Revision < 2)
332 {
333 Address.Pointer.Value = (ACPI_CAST_PTR (RSDT_DESCRIPTOR, RsdtInfo.Pointer))->TableOffsetEntry[i];
334 }
335 else
336 {
337 Address.Pointer.Value = ACPI_GET_ADDRESS (
338 (ACPI_CAST_PTR (XSDT_DESCRIPTOR, RsdtInfo.Pointer))->TableOffsetEntry[i]);
339 }
340
341 /* Get the table header */
342
343 Status = AcpiTbGetTableHeader (&Address, &Header);
344 if (ACPI_FAILURE (Status))
345 {
346 goto Cleanup;
347 }
348
349 /* Compare table signatures and table instance */
350
351 if (!ACPI_STRNCMP (Header.Signature, Signature, ACPI_NAME_SIZE))
352 {
353 /* An instance of the table was found */
354
355 j++;
356 if (j >= Instance)
357 {
358 /* Found the correct instance, get the entire table */
359
360 Status = AcpiTbGetTableBody (&Address, &Header, &TableInfo);
361 if (ACPI_FAILURE (Status))
362 {
363 goto Cleanup;
364 }
365
366 *TablePointer = TableInfo.Pointer;
367 goto Cleanup;
368 }
369 }
370 }
371
372 /* Did not find the table */
373
374 Status = AE_NOT_EXIST;
375
376
377Cleanup:
378 AcpiOsUnmapMemory (RsdtInfo.Pointer, (ACPI_SIZE) RsdtInfo.Pointer->Length);
379 return_ACPI_STATUS (Status);
380}
381
382
383/* TBD: Move to a new file */
384
385#if ACPI_MACHINE_WIDTH != 16
386
387/*******************************************************************************
388 *
389 * FUNCTION: AcpiFindRootPointer
390 *
391 * PARAMETERS: **RsdpAddress - Where to place the RSDP address
392 * Flags - Logical/Physical addressing
393 *
394 * RETURN: Status, Physical address of the RSDP
395 *
396 * DESCRIPTION: Find the RSDP
397 *
398 ******************************************************************************/
399
400ACPI_STATUS
401AcpiFindRootPointer (
402 UINT32 Flags,
403 ACPI_POINTER *RsdpAddress)
404{
405 ACPI_TABLE_DESC TableInfo;
406 ACPI_STATUS Status;
407
408
409 ACPI_FUNCTION_TRACE ("AcpiFindRootPointer");
410
411
412 /* Get the RSDP */
413
414 Status = AcpiTbFindRsdp (&TableInfo, Flags);
415 if (ACPI_FAILURE (Status))
416 {
417 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "RSDP structure not found, %s Flags=%X\n",
418 AcpiFormatException (Status), Flags));
419 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
420 }
421
422 RsdpAddress->PointerType = ACPI_PHYSICAL_POINTER;
423 RsdpAddress->Pointer.Physical = TableInfo.PhysicalAddress;
424 return_ACPI_STATUS (AE_OK);
425}
426
427
428/*******************************************************************************
429 *
430 * FUNCTION: AcpiTbScanMemoryForRsdp
431 *
432 * PARAMETERS: StartAddress - Starting pointer for search
433 * Length - Maximum length to search
434 *
435 * RETURN: Pointer to the RSDP if found, otherwise NULL.
436 *
437 * DESCRIPTION: Search a block of memory for the RSDP signature
438 *
439 ******************************************************************************/
440
441UINT8 *
442AcpiTbScanMemoryForRsdp (
443 UINT8 *StartAddress,
444 UINT32 Length)
445{
446 UINT32 Offset;
447 UINT8 *MemRover;
448
449
450 ACPI_FUNCTION_TRACE ("TbScanMemoryForRsdp");
451
452
453 /* Search from given start addr for the requested length */
454
455 for (Offset = 0, MemRover = StartAddress;
456 Offset < Length;
457 Offset += ACPI_RSDP_SCAN_STEP, MemRover += ACPI_RSDP_SCAN_STEP)
458 {
459
460 /* The signature and checksum must both be correct */
461
462 if (ACPI_STRNCMP ((char *) MemRover,
463 RSDP_SIG, sizeof (RSDP_SIG)-1) == 0 &&
464 AcpiTbChecksum (MemRover, ACPI_RSDP_CHECKSUM_LENGTH) == 0)
465 {
466 /* If so, we have found the RSDP */
467
468 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
469 "RSDP located at physical address %p\n",MemRover));
470 return_PTR (MemRover);
471 }
472 }
473
474 /* Searched entire block, no RSDP was found */
475
476 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,"Searched entire block, no RSDP was found.\n"));
477 return_PTR (NULL);
478}
479
480
481/*******************************************************************************
482 *
483 * FUNCTION: AcpiTbFindRsdp
484 *
485 * PARAMETERS: *TableInfo - Where the table info is returned
486 * Flags - Current memory mode (logical vs.
487 * physical addressing)
488 *
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2004, 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 char *Signature,
145 char *OemId,
146 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) > ACPI_NAME_SIZE) ||
159 (ACPI_STRLEN (OemId) > sizeof (Table->OemId)) ||
160 (ACPI_STRLEN (OemTableId) > sizeof (Table->OemTableId)))
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 - 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_POINTER RsdpAddress;
217 ACPI_POINTER Address;
218 ACPI_STATUS Status;
219 ACPI_TABLE_HEADER Header;
220 ACPI_TABLE_DESC TableInfo;
221 ACPI_TABLE_DESC RsdtInfo;
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 RsdtInfo.Pointer = NULL;
246
247 if (!AcpiGbl_RSDP)
248 {
249 /* Get the RSDP */
250
251 Status = AcpiOsGetRootPointer (Flags, &RsdpAddress);
252 if (ACPI_FAILURE (Status))
253 {
254 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "RSDP not found\n"));
255 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
256 }
257
258 /* Map and validate the RSDP */
259
260 if ((Flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING)
261 {
262 Status = AcpiOsMapMemory (RsdpAddress.Pointer.Physical, sizeof (RSDP_DESCRIPTOR),
263 (void *) &AcpiGbl_RSDP);
264 if (ACPI_FAILURE (Status))
265 {
266 return_ACPI_STATUS (Status);
267 }
268 }
269 else
270 {
271 AcpiGbl_RSDP = RsdpAddress.Pointer.Logical;
272 }
273
274 /*
275 * The signature and checksum must both be correct
276 */
277 if (ACPI_STRNCMP ((char *) AcpiGbl_RSDP, RSDP_SIG, sizeof (RSDP_SIG)-1) != 0)
278 {
279 /* Nope, BAD Signature */
280
281 return_ACPI_STATUS (AE_BAD_SIGNATURE);
282 }
283
284 if (AcpiTbChecksum (AcpiGbl_RSDP, ACPI_RSDP_CHECKSUM_LENGTH) != 0)
285 {
286 /* Nope, BAD Checksum */
287
288 return_ACPI_STATUS (AE_BAD_CHECKSUM);
289 }
290 }
291
292 /* Get the RSDT and validate it */
293
294 AcpiTbGetRsdtAddress (&Address);
295
296 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
297 "RSDP located at %p, RSDT physical=%8.8X%8.8X \n",
298 AcpiGbl_RSDP,
299 ACPI_FORMAT_UINT64 (Address.Pointer.Value)));
300
301 /* Insert ProcessorMode flags */
302
303 Address.PointerType |= Flags;
304
305 Status = AcpiTbGetTable (&Address, &RsdtInfo);
306 if (ACPI_FAILURE (Status))
307 {
308 return_ACPI_STATUS (Status);
309 }
310
311 Status = AcpiTbValidateRsdt (RsdtInfo.Pointer);
312 if (ACPI_FAILURE (Status))
313 {
314 goto Cleanup;
315 }
316
317 /* Get the number of table pointers within the RSDT */
318
319 TableCount = AcpiTbGetTableCount (AcpiGbl_RSDP, RsdtInfo.Pointer);
320
321 Address.PointerType = AcpiGbl_TableFlags | Flags;
322
323 /*
324 * Search the RSDT/XSDT for the correct instance of the
325 * requested table
326 */
327 for (i = 0, j = 0; i < TableCount; i++)
328 {
329 /* Get the next table pointer, handle RSDT vs. XSDT */
330
331 if (AcpiGbl_RSDP->Revision < 2)
332 {
333 Address.Pointer.Value = (ACPI_CAST_PTR (RSDT_DESCRIPTOR, RsdtInfo.Pointer))->TableOffsetEntry[i];
334 }
335 else
336 {
337 Address.Pointer.Value = ACPI_GET_ADDRESS (
338 (ACPI_CAST_PTR (XSDT_DESCRIPTOR, RsdtInfo.Pointer))->TableOffsetEntry[i]);
339 }
340
341 /* Get the table header */
342
343 Status = AcpiTbGetTableHeader (&Address, &Header);
344 if (ACPI_FAILURE (Status))
345 {
346 goto Cleanup;
347 }
348
349 /* Compare table signatures and table instance */
350
351 if (!ACPI_STRNCMP (Header.Signature, Signature, ACPI_NAME_SIZE))
352 {
353 /* An instance of the table was found */
354
355 j++;
356 if (j >= Instance)
357 {
358 /* Found the correct instance, get the entire table */
359
360 Status = AcpiTbGetTableBody (&Address, &Header, &TableInfo);
361 if (ACPI_FAILURE (Status))
362 {
363 goto Cleanup;
364 }
365
366 *TablePointer = TableInfo.Pointer;
367 goto Cleanup;
368 }
369 }
370 }
371
372 /* Did not find the table */
373
374 Status = AE_NOT_EXIST;
375
376
377Cleanup:
378 AcpiOsUnmapMemory (RsdtInfo.Pointer, (ACPI_SIZE) RsdtInfo.Pointer->Length);
379 return_ACPI_STATUS (Status);
380}
381
382
383/* TBD: Move to a new file */
384
385#if ACPI_MACHINE_WIDTH != 16
386
387/*******************************************************************************
388 *
389 * FUNCTION: AcpiFindRootPointer
390 *
391 * PARAMETERS: **RsdpAddress - Where to place the RSDP address
392 * Flags - Logical/Physical addressing
393 *
394 * RETURN: Status, Physical address of the RSDP
395 *
396 * DESCRIPTION: Find the RSDP
397 *
398 ******************************************************************************/
399
400ACPI_STATUS
401AcpiFindRootPointer (
402 UINT32 Flags,
403 ACPI_POINTER *RsdpAddress)
404{
405 ACPI_TABLE_DESC TableInfo;
406 ACPI_STATUS Status;
407
408
409 ACPI_FUNCTION_TRACE ("AcpiFindRootPointer");
410
411
412 /* Get the RSDP */
413
414 Status = AcpiTbFindRsdp (&TableInfo, Flags);
415 if (ACPI_FAILURE (Status))
416 {
417 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "RSDP structure not found, %s Flags=%X\n",
418 AcpiFormatException (Status), Flags));
419 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
420 }
421
422 RsdpAddress->PointerType = ACPI_PHYSICAL_POINTER;
423 RsdpAddress->Pointer.Physical = TableInfo.PhysicalAddress;
424 return_ACPI_STATUS (AE_OK);
425}
426
427
428/*******************************************************************************
429 *
430 * FUNCTION: AcpiTbScanMemoryForRsdp
431 *
432 * PARAMETERS: StartAddress - Starting pointer for search
433 * Length - Maximum length to search
434 *
435 * RETURN: Pointer to the RSDP if found, otherwise NULL.
436 *
437 * DESCRIPTION: Search a block of memory for the RSDP signature
438 *
439 ******************************************************************************/
440
441UINT8 *
442AcpiTbScanMemoryForRsdp (
443 UINT8 *StartAddress,
444 UINT32 Length)
445{
446 UINT32 Offset;
447 UINT8 *MemRover;
448
449
450 ACPI_FUNCTION_TRACE ("TbScanMemoryForRsdp");
451
452
453 /* Search from given start addr for the requested length */
454
455 for (Offset = 0, MemRover = StartAddress;
456 Offset < Length;
457 Offset += ACPI_RSDP_SCAN_STEP, MemRover += ACPI_RSDP_SCAN_STEP)
458 {
459
460 /* The signature and checksum must both be correct */
461
462 if (ACPI_STRNCMP ((char *) MemRover,
463 RSDP_SIG, sizeof (RSDP_SIG)-1) == 0 &&
464 AcpiTbChecksum (MemRover, ACPI_RSDP_CHECKSUM_LENGTH) == 0)
465 {
466 /* If so, we have found the RSDP */
467
468 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
469 "RSDP located at physical address %p\n",MemRover));
470 return_PTR (MemRover);
471 }
472 }
473
474 /* Searched entire block, no RSDP was found */
475
476 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,"Searched entire block, no RSDP was found.\n"));
477 return_PTR (NULL);
478}
479
480
481/*******************************************************************************
482 *
483 * FUNCTION: AcpiTbFindRsdp
484 *
485 * PARAMETERS: *TableInfo - Where the table info is returned
486 * Flags - Current memory mode (logical vs.
487 * physical addressing)
488 *
489 * RETURN: Status
489 * RETURN: Status, RSDP physical address
490 *
491 * DESCRIPTION: Search lower 1Mbyte of memory for the root system descriptor
492 * pointer structure. If it is found, set *RSDP to point to it.
493 *
490 *
491 * DESCRIPTION: Search lower 1Mbyte of memory for the root system descriptor
492 * pointer structure. If it is found, set *RSDP to point to it.
493 *
494 * NOTE: The RSDP must be either in the first 1K of the Extended
495 * BIOS Data Area or between E0000 and FFFFF (ACPI 1.0 section
496 * 5.2.2; assertion #421).
494 * NOTE1: The RSDP must be either in the first 1K of the Extended
495 * BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
496 * Only a 32-bit physical address is necessary.
497 *
497 *
498 * NOTE2: This function is always available, regardless of the
499 * initialization state of the rest of ACPI.
500 *
498 ******************************************************************************/
499
500ACPI_STATUS
501AcpiTbFindRsdp (
502 ACPI_TABLE_DESC *TableInfo,
503 UINT32 Flags)
504{
505 UINT8 *TablePtr;
506 UINT8 *MemRover;
501 ******************************************************************************/
502
503ACPI_STATUS
504AcpiTbFindRsdp (
505 ACPI_TABLE_DESC *TableInfo,
506 UINT32 Flags)
507{
508 UINT8 *TablePtr;
509 UINT8 *MemRover;
507 UINT64 PhysAddr;
508 ACPI_STATUS Status = AE_OK;
510 UINT32 PhysicalAddress;
511 ACPI_STATUS Status;
509
510
511 ACPI_FUNCTION_TRACE ("TbFindRsdp");
512
513
514 /*
515 * Scan supports either 1) Logical addressing or 2) Physical addressing
516 */
517 if ((Flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING)
518 {
519 /*
512
513
514 ACPI_FUNCTION_TRACE ("TbFindRsdp");
515
516
517 /*
518 * Scan supports either 1) Logical addressing or 2) Physical addressing
519 */
520 if ((Flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING)
521 {
522 /*
520 * 1) Search EBDA (low memory) paragraphs
523 * 1a) Get the location of the EBDA
521 */
524 */
522 Status = AcpiOsMapMemory ((UINT64) ACPI_LO_RSDP_WINDOW_BASE, ACPI_LO_RSDP_WINDOW_SIZE,
525 Status = AcpiOsMapMemory ((ACPI_PHYSICAL_ADDRESS) ACPI_EBDA_PTR_LOCATION,
526 ACPI_EBDA_PTR_LENGTH,
523 (void *) &TablePtr);
524 if (ACPI_FAILURE (Status))
525 {
527 (void *) &TablePtr);
528 if (ACPI_FAILURE (Status))
529 {
526 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not map memory at %X for length %X\n",
527 ACPI_LO_RSDP_WINDOW_BASE, ACPI_LO_RSDP_WINDOW_SIZE));
530 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not map memory at %8.8X for length %X\n",
531 ACPI_EBDA_PTR_LOCATION, ACPI_EBDA_PTR_LENGTH));
528 return_ACPI_STATUS (Status);
529 }
530
532 return_ACPI_STATUS (Status);
533 }
534
531 MemRover = AcpiTbScanMemoryForRsdp (TablePtr, ACPI_LO_RSDP_WINDOW_SIZE);
532 AcpiOsUnmapMemory (TablePtr, ACPI_LO_RSDP_WINDOW_SIZE);
535 ACPI_MOVE_16_TO_32 (&PhysicalAddress, TablePtr);
536 PhysicalAddress <<= 4; /* Convert segment to physical address */
537 AcpiOsUnmapMemory (TablePtr, ACPI_EBDA_PTR_LENGTH);
533
538
534 if (MemRover)
539 /* EBDA present? */
540
541 if (PhysicalAddress > 0x400)
535 {
542 {
536 /* Found it, return the physical address */
543 /*
544 * 1b) Search EBDA paragraphs (EBDA is required to be a minimum of 1K length)
545 */
546 Status = AcpiOsMapMemory ((ACPI_PHYSICAL_ADDRESS) PhysicalAddress,
547 ACPI_EBDA_WINDOW_SIZE,
548 (void *) &TablePtr);
549 if (ACPI_FAILURE (Status))
550 {
551 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not map memory at %8.8X for length %X\n",
552 PhysicalAddress, ACPI_EBDA_WINDOW_SIZE));
553 return_ACPI_STATUS (Status);
554 }
537
555
538 PhysAddr = ACPI_LO_RSDP_WINDOW_BASE;
539 PhysAddr += ACPI_PTR_DIFF (MemRover,TablePtr);
556 MemRover = AcpiTbScanMemoryForRsdp (TablePtr, ACPI_EBDA_WINDOW_SIZE);
557 AcpiOsUnmapMemory (TablePtr, ACPI_EBDA_WINDOW_SIZE);
540
558
541 TableInfo->PhysicalAddress = PhysAddr;
542 return_ACPI_STATUS (AE_OK);
559 if (MemRover)
560 {
561 /* Found it, return the physical address */
562
563 PhysicalAddress += ACPI_PTR_DIFF (MemRover, TablePtr);
564
565 TableInfo->PhysicalAddress = (ACPI_PHYSICAL_ADDRESS) PhysicalAddress;
566 return_ACPI_STATUS (AE_OK);
567 }
543 }
544
545 /*
568 }
569
570 /*
546 * 2) Search upper memory: 16-byte boundaries in E0000h-F0000h
571 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
547 */
572 */
548 Status = AcpiOsMapMemory ((UINT64) ACPI_HI_RSDP_WINDOW_BASE, ACPI_HI_RSDP_WINDOW_SIZE,
573 Status = AcpiOsMapMemory ((ACPI_PHYSICAL_ADDRESS) ACPI_HI_RSDP_WINDOW_BASE,
574 ACPI_HI_RSDP_WINDOW_SIZE,
549 (void *) &TablePtr);
550 if (ACPI_FAILURE (Status))
551 {
575 (void *) &TablePtr);
576 if (ACPI_FAILURE (Status))
577 {
552 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not map memory at %X for length %X\n",
578 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not map memory at %8.8X for length %X\n",
553 ACPI_HI_RSDP_WINDOW_BASE, ACPI_HI_RSDP_WINDOW_SIZE));
554 return_ACPI_STATUS (Status);
555 }
556
557 MemRover = AcpiTbScanMemoryForRsdp (TablePtr, ACPI_HI_RSDP_WINDOW_SIZE);
558 AcpiOsUnmapMemory (TablePtr, ACPI_HI_RSDP_WINDOW_SIZE);
559
560 if (MemRover)
561 {
562 /* Found it, return the physical address */
563
579 ACPI_HI_RSDP_WINDOW_BASE, ACPI_HI_RSDP_WINDOW_SIZE));
580 return_ACPI_STATUS (Status);
581 }
582
583 MemRover = AcpiTbScanMemoryForRsdp (TablePtr, ACPI_HI_RSDP_WINDOW_SIZE);
584 AcpiOsUnmapMemory (TablePtr, ACPI_HI_RSDP_WINDOW_SIZE);
585
586 if (MemRover)
587 {
588 /* Found it, return the physical address */
589
564 PhysAddr = ACPI_HI_RSDP_WINDOW_BASE;
565 PhysAddr += ACPI_PTR_DIFF (MemRover, TablePtr);
590 PhysicalAddress = ACPI_HI_RSDP_WINDOW_BASE + ACPI_PTR_DIFF (MemRover, TablePtr);
566
591
567 TableInfo->PhysicalAddress = PhysAddr;
592 TableInfo->PhysicalAddress = (ACPI_PHYSICAL_ADDRESS) PhysicalAddress;
568 return_ACPI_STATUS (AE_OK);
569 }
570 }
571
572 /*
573 * Physical addressing
574 */
575 else
576 {
577 /*
593 return_ACPI_STATUS (AE_OK);
594 }
595 }
596
597 /*
598 * Physical addressing
599 */
600 else
601 {
602 /*
578 * 1) Search EBDA (low memory) paragraphs
603 * 1a) Get the location of the EBDA
579 */
604 */
580 MemRover = AcpiTbScanMemoryForRsdp (ACPI_PHYSADDR_TO_PTR (ACPI_LO_RSDP_WINDOW_BASE),
581 ACPI_LO_RSDP_WINDOW_SIZE);
582 if (MemRover)
605 ACPI_MOVE_16_TO_32 (&PhysicalAddress, ACPI_EBDA_PTR_LOCATION);
606 PhysicalAddress <<= 4; /* Convert segment to physical address */
607
608 /* EBDA present? */
609
610 if (PhysicalAddress > 0x400)
583 {
611 {
584 /* Found it, return the physical address */
612 /*
613 * 1b) Search EBDA paragraphs (EBDA is required to be a minimum of 1K length)
614 */
615 MemRover = AcpiTbScanMemoryForRsdp (ACPI_PHYSADDR_TO_PTR (PhysicalAddress),
616 ACPI_EBDA_WINDOW_SIZE);
617 if (MemRover)
618 {
619 /* Found it, return the physical address */
585
620
586 TableInfo->PhysicalAddress = ACPI_TO_INTEGER (MemRover);
587 return_ACPI_STATUS (AE_OK);
621 TableInfo->PhysicalAddress = ACPI_TO_INTEGER (MemRover);
622 return_ACPI_STATUS (AE_OK);
623 }
588 }
589
590 /*
624 }
625
626 /*
591 * 2) Search upper memory: 16-byte boundaries in E0000h-F0000h
627 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
592 */
593 MemRover = AcpiTbScanMemoryForRsdp (ACPI_PHYSADDR_TO_PTR (ACPI_HI_RSDP_WINDOW_BASE),
594 ACPI_HI_RSDP_WINDOW_SIZE);
595 if (MemRover)
596 {
597 /* Found it, return the physical address */
598
599 TableInfo->PhysicalAddress = ACPI_TO_INTEGER (MemRover);
600 return_ACPI_STATUS (AE_OK);
601 }
602 }
603
604 /* RSDP signature was not found */
605
606 return_ACPI_STATUS (AE_NOT_FOUND);
607}
608
609#endif
610
628 */
629 MemRover = AcpiTbScanMemoryForRsdp (ACPI_PHYSADDR_TO_PTR (ACPI_HI_RSDP_WINDOW_BASE),
630 ACPI_HI_RSDP_WINDOW_SIZE);
631 if (MemRover)
632 {
633 /* Found it, return the physical address */
634
635 TableInfo->PhysicalAddress = ACPI_TO_INTEGER (MemRover);
636 return_ACPI_STATUS (AE_OK);
637 }
638 }
639
640 /* RSDP signature was not found */
641
642 return_ACPI_STATUS (AE_NOT_FOUND);
643}
644
645#endif
646