Fixed compatibility of output.
[AROS.git] / arch / all-pc / acpica / source / components / tables / tbxface.c
blob16449269eebb53c9948089240ffb4a945b9258a1
1 /******************************************************************************
3 * Module Name: tbxface - ACPI table-oriented external interfaces
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #define __TBXFACE_C__
45 #define EXPORT_ACPI_INTERFACES
47 #include "acpi.h"
48 #include "accommon.h"
49 #include "actables.h"
51 #define _COMPONENT ACPI_TABLES
52 ACPI_MODULE_NAME ("tbxface")
55 /*******************************************************************************
57 * FUNCTION: AcpiAllocateRootTable
59 * PARAMETERS: InitialTableCount - Size of InitialTableArray, in number of
60 * ACPI_TABLE_DESC structures
62 * RETURN: Status
64 * DESCRIPTION: Allocate a root table array. Used by iASL compiler and
65 * AcpiInitializeTables.
67 ******************************************************************************/
69 ACPI_STATUS
70 AcpiAllocateRootTable (
71 UINT32 InitialTableCount)
74 AcpiGbl_RootTableList.MaxTableCount = InitialTableCount;
75 AcpiGbl_RootTableList.Flags = ACPI_ROOT_ALLOW_RESIZE;
77 return (AcpiTbResizeRootTableList ());
81 /*******************************************************************************
83 * FUNCTION: AcpiInitializeTables
85 * PARAMETERS: InitialTableArray - Pointer to an array of pre-allocated
86 * ACPI_TABLE_DESC structures. If NULL, the
87 * array is dynamically allocated.
88 * InitialTableCount - Size of InitialTableArray, in number of
89 * ACPI_TABLE_DESC structures
90 * AllowResize - Flag to tell Table Manager if resize of
91 * pre-allocated array is allowed. Ignored
92 * if InitialTableArray is NULL.
94 * RETURN: Status
96 * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
98 * NOTE: Allows static allocation of the initial table array in order
99 * to avoid the use of dynamic memory in confined environments
100 * such as the kernel boot sequence where it may not be available.
102 * If the host OS memory managers are initialized, use NULL for
103 * InitialTableArray, and the table will be dynamically allocated.
105 ******************************************************************************/
107 ACPI_STATUS
108 AcpiInitializeTables (
109 ACPI_TABLE_DESC *InitialTableArray,
110 UINT32 InitialTableCount,
111 BOOLEAN AllowResize)
113 ACPI_PHYSICAL_ADDRESS RsdpAddress;
114 ACPI_STATUS Status;
117 ACPI_FUNCTION_TRACE (AcpiInitializeTables);
121 * Setup the Root Table Array and allocate the table array
122 * if requested
124 if (!InitialTableArray)
126 Status = AcpiAllocateRootTable (InitialTableCount);
127 if (ACPI_FAILURE (Status))
129 return_ACPI_STATUS (Status);
132 else
134 /* Root Table Array has been statically allocated by the host */
136 ACPI_MEMSET (InitialTableArray, 0,
137 (ACPI_SIZE) InitialTableCount * sizeof (ACPI_TABLE_DESC));
139 AcpiGbl_RootTableList.Tables = InitialTableArray;
140 AcpiGbl_RootTableList.MaxTableCount = InitialTableCount;
141 AcpiGbl_RootTableList.Flags = ACPI_ROOT_ORIGIN_UNKNOWN;
142 if (AllowResize)
144 AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
148 /* Get the address of the RSDP */
150 RsdpAddress = AcpiOsGetRootPointer ();
151 if (!RsdpAddress)
153 return_ACPI_STATUS (AE_NOT_FOUND);
157 * Get the root table (RSDT or XSDT) and extract all entries to the local
158 * Root Table Array. This array contains the information of the RSDT/XSDT
159 * in a common, more useable format.
161 Status = AcpiTbParseRootTable (RsdpAddress);
162 return_ACPI_STATUS (Status);
165 ACPI_EXPORT_SYMBOL_INIT (AcpiInitializeTables)
168 /*******************************************************************************
170 * FUNCTION: AcpiReallocateRootTable
172 * PARAMETERS: None
174 * RETURN: Status
176 * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the
177 * root list from the previously provided scratch area. Should
178 * be called once dynamic memory allocation is available in the
179 * kernel.
181 ******************************************************************************/
183 ACPI_STATUS
184 AcpiReallocateRootTable (
185 void)
187 ACPI_STATUS Status;
190 ACPI_FUNCTION_TRACE (AcpiReallocateRootTable);
194 * Only reallocate the root table if the host provided a static buffer
195 * for the table array in the call to AcpiInitializeTables.
197 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
199 return_ACPI_STATUS (AE_SUPPORT);
202 AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
204 Status = AcpiTbResizeRootTableList ();
205 return_ACPI_STATUS (Status);
208 ACPI_EXPORT_SYMBOL_INIT (AcpiReallocateRootTable)
211 /*******************************************************************************
213 * FUNCTION: AcpiGetTableHeader
215 * PARAMETERS: Signature - ACPI signature of needed table
216 * Instance - Which instance (for SSDTs)
217 * OutTableHeader - The pointer to the table header to fill
219 * RETURN: Status and pointer to mapped table header
221 * DESCRIPTION: Finds an ACPI table header.
223 * NOTE: Caller is responsible in unmapping the header with
224 * AcpiOsUnmapMemory
226 ******************************************************************************/
228 ACPI_STATUS
229 AcpiGetTableHeader (
230 char *Signature,
231 UINT32 Instance,
232 ACPI_TABLE_HEADER *OutTableHeader)
234 UINT32 i;
235 UINT32 j;
236 ACPI_TABLE_HEADER *Header;
239 /* Parameter validation */
241 if (!Signature || !OutTableHeader)
243 return (AE_BAD_PARAMETER);
246 /* Walk the root table list */
248 for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
250 if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
251 Signature))
253 continue;
256 if (++j < Instance)
258 continue;
261 if (!AcpiGbl_RootTableList.Tables[i].Pointer)
263 if ((AcpiGbl_RootTableList.Tables[i].Flags &
264 ACPI_TABLE_ORIGIN_MASK) ==
265 ACPI_TABLE_ORIGIN_MAPPED)
267 Header = AcpiOsMapMemory (
268 AcpiGbl_RootTableList.Tables[i].Address,
269 sizeof (ACPI_TABLE_HEADER));
270 if (!Header)
272 return (AE_NO_MEMORY);
275 ACPI_MEMCPY (OutTableHeader, Header,
276 sizeof (ACPI_TABLE_HEADER));
277 AcpiOsUnmapMemory (Header, sizeof (ACPI_TABLE_HEADER));
279 else
281 return (AE_NOT_FOUND);
284 else
286 ACPI_MEMCPY (OutTableHeader,
287 AcpiGbl_RootTableList.Tables[i].Pointer,
288 sizeof (ACPI_TABLE_HEADER));
291 return (AE_OK);
294 return (AE_NOT_FOUND);
297 ACPI_EXPORT_SYMBOL (AcpiGetTableHeader)
300 /*******************************************************************************
302 * FUNCTION: AcpiGetTable
304 * PARAMETERS: Signature - ACPI signature of needed table
305 * Instance - Which instance (for SSDTs)
306 * OutTable - Where the pointer to the table is returned
308 * RETURN: Status and pointer to the requested table
310 * DESCRIPTION: Finds and verifies an ACPI table. Table must be in the
311 * RSDT/XSDT.
313 ******************************************************************************/
315 ACPI_STATUS
316 AcpiGetTable (
317 char *Signature,
318 UINT32 Instance,
319 ACPI_TABLE_HEADER **OutTable)
321 UINT32 i;
322 UINT32 j;
323 ACPI_STATUS Status;
326 /* Parameter validation */
328 if (!Signature || !OutTable)
330 return (AE_BAD_PARAMETER);
333 /* Walk the root table list */
335 for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
337 if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
338 Signature))
340 continue;
343 if (++j < Instance)
345 continue;
348 Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[i]);
349 if (ACPI_SUCCESS (Status))
351 *OutTable = AcpiGbl_RootTableList.Tables[i].Pointer;
354 return (Status);
357 return (AE_NOT_FOUND);
360 ACPI_EXPORT_SYMBOL (AcpiGetTable)
363 /*******************************************************************************
365 * FUNCTION: AcpiGetTableByIndex
367 * PARAMETERS: TableIndex - Table index
368 * Table - Where the pointer to the table is returned
370 * RETURN: Status and pointer to the requested table
372 * DESCRIPTION: Obtain a table by an index into the global table list. Used
373 * internally also.
375 ******************************************************************************/
377 ACPI_STATUS
378 AcpiGetTableByIndex (
379 UINT32 TableIndex,
380 ACPI_TABLE_HEADER **Table)
382 ACPI_STATUS Status;
385 ACPI_FUNCTION_TRACE (AcpiGetTableByIndex);
388 /* Parameter validation */
390 if (!Table)
392 return_ACPI_STATUS (AE_BAD_PARAMETER);
395 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
397 /* Validate index */
399 if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
401 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
402 return_ACPI_STATUS (AE_BAD_PARAMETER);
405 if (!AcpiGbl_RootTableList.Tables[TableIndex].Pointer)
407 /* Table is not mapped, map it */
409 Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[TableIndex]);
410 if (ACPI_FAILURE (Status))
412 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
413 return_ACPI_STATUS (Status);
417 *Table = AcpiGbl_RootTableList.Tables[TableIndex].Pointer;
418 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
419 return_ACPI_STATUS (AE_OK);
422 ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex)
425 /*******************************************************************************
427 * FUNCTION: AcpiInstallTableHandler
429 * PARAMETERS: Handler - Table event handler
430 * Context - Value passed to the handler on each event
432 * RETURN: Status
434 * DESCRIPTION: Install a global table event handler.
436 ******************************************************************************/
438 ACPI_STATUS
439 AcpiInstallTableHandler (
440 ACPI_TABLE_HANDLER Handler,
441 void *Context)
443 ACPI_STATUS Status;
446 ACPI_FUNCTION_TRACE (AcpiInstallTableHandler);
449 if (!Handler)
451 return_ACPI_STATUS (AE_BAD_PARAMETER);
454 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
455 if (ACPI_FAILURE (Status))
457 return_ACPI_STATUS (Status);
460 /* Don't allow more than one handler */
462 if (AcpiGbl_TableHandler)
464 Status = AE_ALREADY_EXISTS;
465 goto Cleanup;
468 /* Install the handler */
470 AcpiGbl_TableHandler = Handler;
471 AcpiGbl_TableHandlerContext = Context;
473 Cleanup:
474 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
475 return_ACPI_STATUS (Status);
478 ACPI_EXPORT_SYMBOL (AcpiInstallTableHandler)
481 /*******************************************************************************
483 * FUNCTION: AcpiRemoveTableHandler
485 * PARAMETERS: Handler - Table event handler that was installed
486 * previously.
488 * RETURN: Status
490 * DESCRIPTION: Remove a table event handler
492 ******************************************************************************/
494 ACPI_STATUS
495 AcpiRemoveTableHandler (
496 ACPI_TABLE_HANDLER Handler)
498 ACPI_STATUS Status;
501 ACPI_FUNCTION_TRACE (AcpiRemoveTableHandler);
504 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
505 if (ACPI_FAILURE (Status))
507 return_ACPI_STATUS (Status);
510 /* Make sure that the installed handler is the same */
512 if (!Handler ||
513 Handler != AcpiGbl_TableHandler)
515 Status = AE_BAD_PARAMETER;
516 goto Cleanup;
519 /* Remove the handler */
521 AcpiGbl_TableHandler = NULL;
523 Cleanup:
524 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
525 return_ACPI_STATUS (Status);
528 ACPI_EXPORT_SYMBOL (AcpiRemoveTableHandler)