Sync usage with man page.
[netbsd-mini2440.git] / sys / external / intel-public / acpica / dist / tables / tbxface.c
blob7dcf1cbbf01bd833a7058f6f74b033ccacae72f7
1 /******************************************************************************
3 * Module Name: tbxface - Public interfaces to the ACPI subsystem
4 * ACPI table oriented interfaces
6 *****************************************************************************/
8 /******************************************************************************
10 * 1. Copyright Notice
12 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
13 * All rights reserved.
15 * 2. License
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.
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
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;
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
41 * 3. Conditions
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.
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.
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.
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
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.
81 * 4. Disclaimer and Export Compliance
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.
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.
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.
115 *****************************************************************************/
117 #define __TBXFACE_C__
119 #include "acpi.h"
120 #include "accommon.h"
121 #include "acnamesp.h"
122 #include "actables.h"
124 #define _COMPONENT ACPI_TABLES
125 ACPI_MODULE_NAME ("tbxface")
127 /* Local prototypes */
129 static ACPI_STATUS
130 AcpiTbLoadNamespace (
131 void);
134 /*******************************************************************************
136 * FUNCTION: AcpiAllocateRootTable
138 * PARAMETERS: InitialTableCount - Size of InitialTableArray, in number of
139 * ACPI_TABLE_DESC structures
141 * RETURN: Status
143 * DESCRIPTION: Allocate a root table array. Used by iASL compiler and
144 * AcpiInitializeTables.
146 ******************************************************************************/
148 ACPI_STATUS
149 AcpiAllocateRootTable (
150 UINT32 InitialTableCount)
153 AcpiGbl_RootTableList.Size = InitialTableCount;
154 AcpiGbl_RootTableList.Flags = ACPI_ROOT_ALLOW_RESIZE;
156 return (AcpiTbResizeRootTableList ());
160 /*******************************************************************************
162 * FUNCTION: AcpiInitializeTables
164 * PARAMETERS: InitialTableArray - Pointer to an array of pre-allocated
165 * ACPI_TABLE_DESC structures. If NULL, the
166 * array is dynamically allocated.
167 * InitialTableCount - Size of InitialTableArray, in number of
168 * ACPI_TABLE_DESC structures
169 * AllowRealloc - Flag to tell Table Manager if resize of
170 * pre-allocated array is allowed. Ignored
171 * if InitialTableArray is NULL.
173 * RETURN: Status
175 * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
177 * NOTE: Allows static allocation of the initial table array in order
178 * to avoid the use of dynamic memory in confined environments
179 * such as the kernel boot sequence where it may not be available.
181 * If the host OS memory managers are initialized, use NULL for
182 * InitialTableArray, and the table will be dynamically allocated.
184 ******************************************************************************/
186 ACPI_STATUS
187 AcpiInitializeTables (
188 ACPI_TABLE_DESC *InitialTableArray,
189 UINT32 InitialTableCount,
190 BOOLEAN AllowResize)
192 ACPI_PHYSICAL_ADDRESS RsdpAddress;
193 ACPI_STATUS Status;
196 ACPI_FUNCTION_TRACE (AcpiInitializeTables);
200 * Set up the Root Table Array
201 * Allocate the table array if requested
203 if (!InitialTableArray)
205 Status = AcpiAllocateRootTable (InitialTableCount);
206 if (ACPI_FAILURE (Status))
208 return_ACPI_STATUS (Status);
211 else
213 /* Root Table Array has been statically allocated by the host */
215 ACPI_MEMSET (InitialTableArray, 0,
216 (ACPI_SIZE) InitialTableCount * sizeof (ACPI_TABLE_DESC));
218 AcpiGbl_RootTableList.Tables = InitialTableArray;
219 AcpiGbl_RootTableList.Size = InitialTableCount;
220 AcpiGbl_RootTableList.Flags = ACPI_ROOT_ORIGIN_UNKNOWN;
221 if (AllowResize)
223 AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
227 /* Get the address of the RSDP */
229 RsdpAddress = AcpiOsGetRootPointer ();
230 if (!RsdpAddress)
232 return_ACPI_STATUS (AE_NOT_FOUND);
236 * Get the root table (RSDT or XSDT) and extract all entries to the local
237 * Root Table Array. This array contains the information of the RSDT/XSDT
238 * in a common, more useable format.
240 Status = AcpiTbParseRootTable (RsdpAddress);
241 return_ACPI_STATUS (Status);
244 ACPI_EXPORT_SYMBOL (AcpiInitializeTables)
247 /*******************************************************************************
249 * FUNCTION: AcpiReallocateRootTable
251 * PARAMETERS: None
253 * RETURN: Status
255 * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the
256 * root list from the previously provided scratch area. Should
257 * be called once dynamic memory allocation is available in the
258 * kernel
260 ******************************************************************************/
262 ACPI_STATUS
263 AcpiReallocateRootTable (
264 void)
266 ACPI_TABLE_DESC *Tables;
267 ACPI_SIZE NewSize;
270 ACPI_FUNCTION_TRACE (AcpiReallocateRootTable);
274 * Only reallocate the root table if the host provided a static buffer
275 * for the table array in the call to AcpiInitializeTables.
277 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
279 return_ACPI_STATUS (AE_SUPPORT);
282 NewSize = ((ACPI_SIZE) AcpiGbl_RootTableList.Count +
283 ACPI_ROOT_TABLE_SIZE_INCREMENT) *
284 sizeof (ACPI_TABLE_DESC);
286 /* Create new array and copy the old array */
288 Tables = ACPI_ALLOCATE_ZEROED (NewSize);
289 if (!Tables)
291 return_ACPI_STATUS (AE_NO_MEMORY);
294 ACPI_MEMCPY (Tables, AcpiGbl_RootTableList.Tables, NewSize);
296 AcpiGbl_RootTableList.Size = AcpiGbl_RootTableList.Count;
297 AcpiGbl_RootTableList.Tables = Tables;
298 AcpiGbl_RootTableList.Flags =
299 ACPI_ROOT_ORIGIN_ALLOCATED | ACPI_ROOT_ALLOW_RESIZE;
301 return_ACPI_STATUS (AE_OK);
304 ACPI_EXPORT_SYMBOL (AcpiReallocateRootTable)
307 /*******************************************************************************
309 * FUNCTION: AcpiGetTableHeader
311 * PARAMETERS: Signature - ACPI signature of needed table
312 * Instance - Which instance (for SSDTs)
313 * OutTableHeader - The pointer to the table header to fill
315 * RETURN: Status and pointer to mapped table header
317 * DESCRIPTION: Finds an ACPI table header.
319 * NOTE: Caller is responsible in unmapping the header with
320 * AcpiOsUnmapMemory
322 ******************************************************************************/
324 ACPI_STATUS
325 AcpiGetTableHeader (
326 ACPI_CONST_STRING Signature,
327 UINT32 Instance,
328 ACPI_TABLE_HEADER *OutTableHeader)
330 UINT32 i;
331 UINT32 j;
332 ACPI_TABLE_HEADER *Header;
333 ACPI_STRING USignature = __UNCONST(Signature);
335 /* Parameter validation */
337 if (!Signature || !OutTableHeader)
339 return (AE_BAD_PARAMETER);
342 /* Walk the root table list */
344 for (i = 0, j = 0; i < AcpiGbl_RootTableList.Count; i++)
346 if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
347 USignature))
349 continue;
352 if (++j < Instance)
354 continue;
357 if (!AcpiGbl_RootTableList.Tables[i].Pointer)
359 if ((AcpiGbl_RootTableList.Tables[i].Flags &
360 ACPI_TABLE_ORIGIN_MASK) ==
361 ACPI_TABLE_ORIGIN_MAPPED)
363 Header = AcpiOsMapMemory (
364 AcpiGbl_RootTableList.Tables[i].Address,
365 sizeof (ACPI_TABLE_HEADER));
366 if (!Header)
368 return AE_NO_MEMORY;
371 ACPI_MEMCPY (OutTableHeader, Header, sizeof(ACPI_TABLE_HEADER));
372 AcpiOsUnmapMemory (Header, sizeof(ACPI_TABLE_HEADER));
374 else
376 return AE_NOT_FOUND;
379 else
381 ACPI_MEMCPY (OutTableHeader,
382 AcpiGbl_RootTableList.Tables[i].Pointer,
383 sizeof(ACPI_TABLE_HEADER));
386 return (AE_OK);
389 return (AE_NOT_FOUND);
392 ACPI_EXPORT_SYMBOL (AcpiGetTableHeader)
395 /*******************************************************************************
397 * FUNCTION: AcpiGetTable
399 * PARAMETERS: Signature - ACPI signature of needed table
400 * Instance - Which instance (for SSDTs)
401 * OutTable - Where the pointer to the table is returned
403 * RETURN: Status and pointer to table
405 * DESCRIPTION: Finds and verifies an ACPI table.
407 ******************************************************************************/
409 ACPI_STATUS
410 AcpiGetTable (
411 ACPI_CONST_STRING Signature,
412 UINT32 Instance,
413 ACPI_TABLE_HEADER **OutTable)
415 UINT32 i;
416 UINT32 j;
417 ACPI_STATUS Status;
418 ACPI_STRING USignature = __UNCONST(Signature);
420 /* Parameter validation */
422 if (!Signature || !OutTable)
424 return (AE_BAD_PARAMETER);
427 /* Walk the root table list */
429 for (i = 0, j = 0; i < AcpiGbl_RootTableList.Count; i++)
431 if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
432 USignature))
434 continue;
437 if (++j < Instance)
439 continue;
442 Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[i]);
443 if (ACPI_SUCCESS (Status))
445 *OutTable = AcpiGbl_RootTableList.Tables[i].Pointer;
448 return (Status);
451 return (AE_NOT_FOUND);
454 ACPI_EXPORT_SYMBOL (AcpiGetTable)
457 /*******************************************************************************
459 * FUNCTION: AcpiGetTableByIndex
461 * PARAMETERS: TableIndex - Table index
462 * Table - Where the pointer to the table is returned
464 * RETURN: Status and pointer to the table
466 * DESCRIPTION: Obtain a table by an index into the global table list.
468 ******************************************************************************/
470 ACPI_STATUS
471 AcpiGetTableByIndex (
472 UINT32 TableIndex,
473 ACPI_TABLE_HEADER **Table)
475 ACPI_STATUS Status;
478 ACPI_FUNCTION_TRACE (AcpiGetTableByIndex);
481 /* Parameter validation */
483 if (!Table)
485 return_ACPI_STATUS (AE_BAD_PARAMETER);
488 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
490 /* Validate index */
492 if (TableIndex >= AcpiGbl_RootTableList.Count)
494 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
495 return_ACPI_STATUS (AE_BAD_PARAMETER);
498 if (!AcpiGbl_RootTableList.Tables[TableIndex].Pointer)
500 /* Table is not mapped, map it */
502 Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[TableIndex]);
503 if (ACPI_FAILURE (Status))
505 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
506 return_ACPI_STATUS (Status);
510 *Table = AcpiGbl_RootTableList.Tables[TableIndex].Pointer;
511 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
512 return_ACPI_STATUS (AE_OK);
515 ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex)
518 /*******************************************************************************
520 * FUNCTION: AcpiTbLoadNamespace
522 * PARAMETERS: None
524 * RETURN: Status
526 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
527 * the RSDT/XSDT.
529 ******************************************************************************/
531 static ACPI_STATUS
532 AcpiTbLoadNamespace (
533 void)
535 ACPI_STATUS Status;
536 UINT32 i;
539 ACPI_FUNCTION_TRACE (TbLoadNamespace);
542 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
545 * Load the namespace. The DSDT is required, but any SSDT and PSDT tables
546 * are optional.
548 if (!AcpiGbl_RootTableList.Count ||
549 !ACPI_COMPARE_NAME (
550 &(AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Signature),
551 ACPI_SIG_DSDT) ||
552 ACPI_FAILURE (AcpiTbVerifyTable (
553 &AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT])))
555 Status = AE_NO_ACPI_TABLES;
556 goto UnlockAndExit;
559 /* A valid DSDT is required */
561 Status = AcpiTbVerifyTable (
562 &AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT]);
563 if (ACPI_FAILURE (Status))
565 Status = AE_NO_ACPI_TABLES;
566 goto UnlockAndExit;
569 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
571 /* Load and parse tables */
573 Status = AcpiNsLoadTable (ACPI_TABLE_INDEX_DSDT, AcpiGbl_RootNode);
574 if (ACPI_FAILURE (Status))
576 return_ACPI_STATUS (Status);
579 /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
581 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
582 for (i = 0; i < AcpiGbl_RootTableList.Count; ++i)
584 if ((!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
585 ACPI_SIG_SSDT) &&
586 !ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
587 ACPI_SIG_PSDT)) ||
588 ACPI_FAILURE (AcpiTbVerifyTable (
589 &AcpiGbl_RootTableList.Tables[i])))
591 continue;
594 /* Ignore errors while loading tables, get as many as possible */
596 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
597 (void) AcpiNsLoadTable (i, AcpiGbl_RootNode);
598 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
601 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
603 UnlockAndExit:
604 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
605 return_ACPI_STATUS (Status);
609 /*******************************************************************************
611 * FUNCTION: AcpiLoadTables
613 * PARAMETERS: None
615 * RETURN: Status
617 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
619 ******************************************************************************/
621 ACPI_STATUS
622 AcpiLoadTables (
623 void)
625 ACPI_STATUS Status;
628 ACPI_FUNCTION_TRACE (AcpiLoadTables);
631 /* Load the namespace from the tables */
633 Status = AcpiTbLoadNamespace ();
634 if (ACPI_FAILURE (Status))
636 ACPI_EXCEPTION ((AE_INFO, Status,
637 "While loading namespace from ACPI tables"));
640 return_ACPI_STATUS (Status);
643 ACPI_EXPORT_SYMBOL (AcpiLoadTables)
646 /*******************************************************************************
648 * FUNCTION: AcpiInstallTableHandler
650 * PARAMETERS: Handler - Table event handler
651 * Context - Value passed to the handler on each event
653 * RETURN: Status
655 * DESCRIPTION: Install table event handler
657 ******************************************************************************/
659 ACPI_STATUS
660 AcpiInstallTableHandler (
661 ACPI_TABLE_HANDLER Handler,
662 void *Context)
664 ACPI_STATUS Status;
667 ACPI_FUNCTION_TRACE (AcpiInstallTableHandler);
670 if (!Handler)
672 return_ACPI_STATUS (AE_BAD_PARAMETER);
675 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
676 if (ACPI_FAILURE (Status))
678 return_ACPI_STATUS (Status);
681 /* Don't allow more than one handler */
683 if (AcpiGbl_TableHandler)
685 Status = AE_ALREADY_EXISTS;
686 goto Cleanup;
689 /* Install the handler */
691 AcpiGbl_TableHandler = Handler;
692 AcpiGbl_TableHandlerContext = Context;
694 Cleanup:
695 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
696 return_ACPI_STATUS (Status);
699 ACPI_EXPORT_SYMBOL (AcpiInstallTableHandler)
702 /*******************************************************************************
704 * FUNCTION: AcpiRemoveTableHandler
706 * PARAMETERS: Handler - Table event handler that was installed
707 * previously.
709 * RETURN: Status
711 * DESCRIPTION: Remove table event handler
713 ******************************************************************************/
715 ACPI_STATUS
716 AcpiRemoveTableHandler (
717 ACPI_TABLE_HANDLER Handler)
719 ACPI_STATUS Status;
722 ACPI_FUNCTION_TRACE (AcpiRemoveTableHandler);
725 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
726 if (ACPI_FAILURE (Status))
728 return_ACPI_STATUS (Status);
731 /* Make sure that the installed handler is the same */
733 if (!Handler ||
734 Handler != AcpiGbl_TableHandler)
736 Status = AE_BAD_PARAMETER;
737 goto Cleanup;
740 /* Remove the handler */
742 AcpiGbl_TableHandler = NULL;
744 Cleanup:
745 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
746 return_ACPI_STATUS (Status);
749 ACPI_EXPORT_SYMBOL (AcpiRemoveTableHandler)