1ae115bc7Smrj /******************************************************************************
2ae115bc7Smrj *
3*de5d74c2SJerry Jelinek * Module Name: tbxface - ACPI table-oriented external interfaces
4ae115bc7Smrj *
5ae115bc7Smrj *****************************************************************************/
6ae115bc7Smrj
726f3cdf0SGordon Ross /*
8*de5d74c2SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp.
9ae115bc7Smrj * All rights reserved.
10ae115bc7Smrj *
1126f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without
1226f3cdf0SGordon Ross * modification, are permitted provided that the following conditions
1326f3cdf0SGordon Ross * are met:
1426f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright
1526f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer,
1626f3cdf0SGordon Ross * without modification.
1726f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1826f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below
1926f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon
2026f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further
2126f3cdf0SGordon Ross * binary redistribution.
2226f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names
2326f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived
2426f3cdf0SGordon Ross * from this software without specific prior written permission.
25ae115bc7Smrj *
2626f3cdf0SGordon Ross * Alternatively, this software may be distributed under the terms of the
2726f3cdf0SGordon Ross * GNU General Public License ("GPL") version 2 as published by the Free
2826f3cdf0SGordon Ross * Software Foundation.
29ae115bc7Smrj *
3026f3cdf0SGordon Ross * NO WARRANTY
3126f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3226f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3326f3cdf0SGordon Ross * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3426f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3526f3cdf0SGordon Ross * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3626f3cdf0SGordon Ross * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3726f3cdf0SGordon Ross * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3826f3cdf0SGordon Ross * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3926f3cdf0SGordon Ross * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4026f3cdf0SGordon Ross * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4126f3cdf0SGordon Ross * POSSIBILITY OF SUCH DAMAGES.
4226f3cdf0SGordon Ross */
43ae115bc7Smrj
44*de5d74c2SJerry Jelinek #define EXPORT_ACPI_INTERFACES
45ae115bc7Smrj
46ae115bc7Smrj #include "acpi.h"
47aa2aa9a6SDana Myers #include "accommon.h"
48ae115bc7Smrj #include "actables.h"
49ae115bc7Smrj
50ae115bc7Smrj #define _COMPONENT ACPI_TABLES
51ae115bc7Smrj ACPI_MODULE_NAME ("tbxface")
52ae115bc7Smrj
53db2bae30SDana Myers
54db2bae30SDana Myers /*******************************************************************************
55db2bae30SDana Myers *
56db2bae30SDana Myers * FUNCTION: AcpiAllocateRootTable
57db2bae30SDana Myers *
58db2bae30SDana Myers * PARAMETERS: InitialTableCount - Size of InitialTableArray, in number of
59db2bae30SDana Myers * ACPI_TABLE_DESC structures
60db2bae30SDana Myers *
61db2bae30SDana Myers * RETURN: Status
62db2bae30SDana Myers *
63db2bae30SDana Myers * DESCRIPTION: Allocate a root table array. Used by iASL compiler and
64db2bae30SDana Myers * AcpiInitializeTables.
65db2bae30SDana Myers *
66db2bae30SDana Myers ******************************************************************************/
67db2bae30SDana Myers
68db2bae30SDana Myers ACPI_STATUS
AcpiAllocateRootTable(UINT32 InitialTableCount)69db2bae30SDana Myers AcpiAllocateRootTable (
70db2bae30SDana Myers UINT32 InitialTableCount)
71db2bae30SDana Myers {
72db2bae30SDana Myers
7326f3cdf0SGordon Ross AcpiGbl_RootTableList.MaxTableCount = InitialTableCount;
74db2bae30SDana Myers AcpiGbl_RootTableList.Flags = ACPI_ROOT_ALLOW_RESIZE;
75db2bae30SDana Myers
76db2bae30SDana Myers return (AcpiTbResizeRootTableList ());
77db2bae30SDana Myers }
78db2bae30SDana Myers
79db2bae30SDana Myers
80db2bae30SDana Myers /*******************************************************************************
81db2bae30SDana Myers *
82db2bae30SDana Myers * FUNCTION: AcpiInitializeTables
83db2bae30SDana Myers *
84db2bae30SDana Myers * PARAMETERS: InitialTableArray - Pointer to an array of pre-allocated
85db2bae30SDana Myers * ACPI_TABLE_DESC structures. If NULL, the
86db2bae30SDana Myers * array is dynamically allocated.
87db2bae30SDana Myers * InitialTableCount - Size of InitialTableArray, in number of
88db2bae30SDana Myers * ACPI_TABLE_DESC structures
89*de5d74c2SJerry Jelinek * AllowResize - Flag to tell Table Manager if resize of
90db2bae30SDana Myers * pre-allocated array is allowed. Ignored
91db2bae30SDana Myers * if InitialTableArray is NULL.
92db2bae30SDana Myers *
93db2bae30SDana Myers * RETURN: Status
94db2bae30SDana Myers *
95db2bae30SDana Myers * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
96db2bae30SDana Myers *
97db2bae30SDana Myers * NOTE: Allows static allocation of the initial table array in order
98db2bae30SDana Myers * to avoid the use of dynamic memory in confined environments
99db2bae30SDana Myers * such as the kernel boot sequence where it may not be available.
100db2bae30SDana Myers *
101db2bae30SDana Myers * If the host OS memory managers are initialized, use NULL for
102db2bae30SDana Myers * InitialTableArray, and the table will be dynamically allocated.
103db2bae30SDana Myers *
104db2bae30SDana Myers ******************************************************************************/
105db2bae30SDana Myers
106db2bae30SDana Myers ACPI_STATUS
AcpiInitializeTables(ACPI_TABLE_DESC * InitialTableArray,UINT32 InitialTableCount,BOOLEAN AllowResize)107db2bae30SDana Myers AcpiInitializeTables (
108db2bae30SDana Myers ACPI_TABLE_DESC *InitialTableArray,
109db2bae30SDana Myers UINT32 InitialTableCount,
110db2bae30SDana Myers BOOLEAN AllowResize)
111db2bae30SDana Myers {
112db2bae30SDana Myers ACPI_PHYSICAL_ADDRESS RsdpAddress;
113db2bae30SDana Myers ACPI_STATUS Status;
114db2bae30SDana Myers
115db2bae30SDana Myers
116db2bae30SDana Myers ACPI_FUNCTION_TRACE (AcpiInitializeTables);
117db2bae30SDana Myers
118db2bae30SDana Myers
119db2bae30SDana Myers /*
120*de5d74c2SJerry Jelinek * Setup the Root Table Array and allocate the table array
121*de5d74c2SJerry Jelinek * if requested
122db2bae30SDana Myers */
123db2bae30SDana Myers if (!InitialTableArray)
124db2bae30SDana Myers {
125db2bae30SDana Myers Status = AcpiAllocateRootTable (InitialTableCount);
126db2bae30SDana Myers if (ACPI_FAILURE (Status))
127db2bae30SDana Myers {
128db2bae30SDana Myers return_ACPI_STATUS (Status);
129db2bae30SDana Myers }
130db2bae30SDana Myers }
131db2bae30SDana Myers else
132db2bae30SDana Myers {
133db2bae30SDana Myers /* Root Table Array has been statically allocated by the host */
134db2bae30SDana Myers
135*de5d74c2SJerry Jelinek memset (InitialTableArray, 0,
136db2bae30SDana Myers (ACPI_SIZE) InitialTableCount * sizeof (ACPI_TABLE_DESC));
137db2bae30SDana Myers
138db2bae30SDana Myers AcpiGbl_RootTableList.Tables = InitialTableArray;
13926f3cdf0SGordon Ross AcpiGbl_RootTableList.MaxTableCount = InitialTableCount;
140db2bae30SDana Myers AcpiGbl_RootTableList.Flags = ACPI_ROOT_ORIGIN_UNKNOWN;
141db2bae30SDana Myers if (AllowResize)
142db2bae30SDana Myers {
143db2bae30SDana Myers AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
144db2bae30SDana Myers }
145db2bae30SDana Myers }
146db2bae30SDana Myers
147db2bae30SDana Myers /* Get the address of the RSDP */
148db2bae30SDana Myers
149db2bae30SDana Myers RsdpAddress = AcpiOsGetRootPointer ();
150db2bae30SDana Myers if (!RsdpAddress)
151db2bae30SDana Myers {
152db2bae30SDana Myers return_ACPI_STATUS (AE_NOT_FOUND);
153db2bae30SDana Myers }
154db2bae30SDana Myers
155db2bae30SDana Myers /*
156db2bae30SDana Myers * Get the root table (RSDT or XSDT) and extract all entries to the local
157db2bae30SDana Myers * Root Table Array. This array contains the information of the RSDT/XSDT
158db2bae30SDana Myers * in a common, more useable format.
159db2bae30SDana Myers */
160aa2aa9a6SDana Myers Status = AcpiTbParseRootTable (RsdpAddress);
161db2bae30SDana Myers return_ACPI_STATUS (Status);
162db2bae30SDana Myers }
163db2bae30SDana Myers
ACPI_EXPORT_SYMBOL_INIT(AcpiInitializeTables)164*de5d74c2SJerry Jelinek ACPI_EXPORT_SYMBOL_INIT (AcpiInitializeTables)
165db2bae30SDana Myers
166db2bae30SDana Myers
167db2bae30SDana Myers /*******************************************************************************
168db2bae30SDana Myers *
169db2bae30SDana Myers * FUNCTION: AcpiReallocateRootTable
170db2bae30SDana Myers *
171db2bae30SDana Myers * PARAMETERS: None
172db2bae30SDana Myers *
173db2bae30SDana Myers * RETURN: Status
174db2bae30SDana Myers *
175db2bae30SDana Myers * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the
176db2bae30SDana Myers * root list from the previously provided scratch area. Should
177db2bae30SDana Myers * be called once dynamic memory allocation is available in the
178*de5d74c2SJerry Jelinek * kernel.
179db2bae30SDana Myers *
180db2bae30SDana Myers ******************************************************************************/
181db2bae30SDana Myers
182db2bae30SDana Myers ACPI_STATUS
183db2bae30SDana Myers AcpiReallocateRootTable (
184db2bae30SDana Myers void)
185db2bae30SDana Myers {
186*de5d74c2SJerry Jelinek ACPI_STATUS Status;
187db2bae30SDana Myers
188db2bae30SDana Myers
189db2bae30SDana Myers ACPI_FUNCTION_TRACE (AcpiReallocateRootTable);
190db2bae30SDana Myers
191db2bae30SDana Myers
192db2bae30SDana Myers /*
193db2bae30SDana Myers * Only reallocate the root table if the host provided a static buffer
194db2bae30SDana Myers * for the table array in the call to AcpiInitializeTables.
195db2bae30SDana Myers */
196db2bae30SDana Myers if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
197db2bae30SDana Myers {
198db2bae30SDana Myers return_ACPI_STATUS (AE_SUPPORT);
199db2bae30SDana Myers }
200db2bae30SDana Myers
201*de5d74c2SJerry Jelinek AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
20226f3cdf0SGordon Ross
203*de5d74c2SJerry Jelinek Status = AcpiTbResizeRootTableList ();
204*de5d74c2SJerry Jelinek return_ACPI_STATUS (Status);
205db2bae30SDana Myers }
206db2bae30SDana Myers
ACPI_EXPORT_SYMBOL_INIT(AcpiReallocateRootTable)207*de5d74c2SJerry Jelinek ACPI_EXPORT_SYMBOL_INIT (AcpiReallocateRootTable)
208db2bae30SDana Myers
209db2bae30SDana Myers
210aa2aa9a6SDana Myers /*******************************************************************************
211db2bae30SDana Myers *
212db2bae30SDana Myers * FUNCTION: AcpiGetTableHeader
213db2bae30SDana Myers *
214db2bae30SDana Myers * PARAMETERS: Signature - ACPI signature of needed table
215db2bae30SDana Myers * Instance - Which instance (for SSDTs)
216db2bae30SDana Myers * OutTableHeader - The pointer to the table header to fill
217db2bae30SDana Myers *
218db2bae30SDana Myers * RETURN: Status and pointer to mapped table header
219db2bae30SDana Myers *
220db2bae30SDana Myers * DESCRIPTION: Finds an ACPI table header.
221db2bae30SDana Myers *
222db2bae30SDana Myers * NOTE: Caller is responsible in unmapping the header with
223db2bae30SDana Myers * AcpiOsUnmapMemory
224db2bae30SDana Myers *
225aa2aa9a6SDana Myers ******************************************************************************/
226db2bae30SDana Myers
227db2bae30SDana Myers ACPI_STATUS
228db2bae30SDana Myers AcpiGetTableHeader (
229db2bae30SDana Myers char *Signature,
230db2bae30SDana Myers UINT32 Instance,
231db2bae30SDana Myers ACPI_TABLE_HEADER *OutTableHeader)
232db2bae30SDana Myers {
233db2bae30SDana Myers UINT32 i;
234db2bae30SDana Myers UINT32 j;
235db2bae30SDana Myers ACPI_TABLE_HEADER *Header;
236db2bae30SDana Myers
237db2bae30SDana Myers
238db2bae30SDana Myers /* Parameter validation */
239db2bae30SDana Myers
240db2bae30SDana Myers if (!Signature || !OutTableHeader)
241db2bae30SDana Myers {
242db2bae30SDana Myers return (AE_BAD_PARAMETER);
243db2bae30SDana Myers }
244db2bae30SDana Myers
245aa2aa9a6SDana Myers /* Walk the root table list */
246aa2aa9a6SDana Myers
24726f3cdf0SGordon Ross for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
248db2bae30SDana Myers {
249*de5d74c2SJerry Jelinek if (!ACPI_COMPARE_NAME (
250*de5d74c2SJerry Jelinek &(AcpiGbl_RootTableList.Tables[i].Signature), Signature))
251db2bae30SDana Myers {
252db2bae30SDana Myers continue;
253db2bae30SDana Myers }
254db2bae30SDana Myers
255db2bae30SDana Myers if (++j < Instance)
256db2bae30SDana Myers {
257db2bae30SDana Myers continue;
258db2bae30SDana Myers }
259db2bae30SDana Myers
260db2bae30SDana Myers if (!AcpiGbl_RootTableList.Tables[i].Pointer)
261db2bae30SDana Myers {
262aa2aa9a6SDana Myers if ((AcpiGbl_RootTableList.Tables[i].Flags &
263aa2aa9a6SDana Myers ACPI_TABLE_ORIGIN_MASK) ==
264*de5d74c2SJerry Jelinek ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL)
265db2bae30SDana Myers {
266aa2aa9a6SDana Myers Header = AcpiOsMapMemory (
267aa2aa9a6SDana Myers AcpiGbl_RootTableList.Tables[i].Address,
268db2bae30SDana Myers sizeof (ACPI_TABLE_HEADER));
269db2bae30SDana Myers if (!Header)
270db2bae30SDana Myers {
271*de5d74c2SJerry Jelinek return (AE_NO_MEMORY);
272db2bae30SDana Myers }
273db2bae30SDana Myers
274*de5d74c2SJerry Jelinek memcpy (OutTableHeader, Header, sizeof (ACPI_TABLE_HEADER));
275db2bae30SDana Myers AcpiOsUnmapMemory (Header, sizeof (ACPI_TABLE_HEADER));
276db2bae30SDana Myers }
277db2bae30SDana Myers else
278db2bae30SDana Myers {
279*de5d74c2SJerry Jelinek return (AE_NOT_FOUND);
280db2bae30SDana Myers }
281db2bae30SDana Myers }
282db2bae30SDana Myers else
283db2bae30SDana Myers {
284*de5d74c2SJerry Jelinek memcpy (OutTableHeader,
285aa2aa9a6SDana Myers AcpiGbl_RootTableList.Tables[i].Pointer,
286db2bae30SDana Myers sizeof (ACPI_TABLE_HEADER));
287db2bae30SDana Myers }
288db2bae30SDana Myers
289db2bae30SDana Myers return (AE_OK);
290db2bae30SDana Myers }
291db2bae30SDana Myers
292db2bae30SDana Myers return (AE_NOT_FOUND);
293db2bae30SDana Myers }
294db2bae30SDana Myers
ACPI_EXPORT_SYMBOL(AcpiGetTableHeader)295db2bae30SDana Myers ACPI_EXPORT_SYMBOL (AcpiGetTableHeader)
296db2bae30SDana Myers
297db2bae30SDana Myers
298aa2aa9a6SDana Myers /*******************************************************************************
299db2bae30SDana Myers *
300db2bae30SDana Myers * FUNCTION: AcpiGetTable
301db2bae30SDana Myers *
302db2bae30SDana Myers * PARAMETERS: Signature - ACPI signature of needed table
303db2bae30SDana Myers * Instance - Which instance (for SSDTs)
304db2bae30SDana Myers * OutTable - Where the pointer to the table is returned
305db2bae30SDana Myers *
306*de5d74c2SJerry Jelinek * RETURN: Status and pointer to the requested table
307db2bae30SDana Myers *
308*de5d74c2SJerry Jelinek * DESCRIPTION: Finds and verifies an ACPI table. Table must be in the
309*de5d74c2SJerry Jelinek * RSDT/XSDT.
310db2bae30SDana Myers *
311aa2aa9a6SDana Myers ******************************************************************************/
312db2bae30SDana Myers
313db2bae30SDana Myers ACPI_STATUS
314db2bae30SDana Myers AcpiGetTable (
315db2bae30SDana Myers char *Signature,
316db2bae30SDana Myers UINT32 Instance,
317db2bae30SDana Myers ACPI_TABLE_HEADER **OutTable)
318db2bae30SDana Myers {
319db2bae30SDana Myers UINT32 i;
320db2bae30SDana Myers UINT32 j;
321db2bae30SDana Myers ACPI_STATUS Status;
322db2bae30SDana Myers
323db2bae30SDana Myers
324db2bae30SDana Myers /* Parameter validation */
325db2bae30SDana Myers
326db2bae30SDana Myers if (!Signature || !OutTable)
327db2bae30SDana Myers {
328db2bae30SDana Myers return (AE_BAD_PARAMETER);
329db2bae30SDana Myers }
330db2bae30SDana Myers
331aa2aa9a6SDana Myers /* Walk the root table list */
332aa2aa9a6SDana Myers
33326f3cdf0SGordon Ross for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
334db2bae30SDana Myers {
335*de5d74c2SJerry Jelinek if (!ACPI_COMPARE_NAME (
336*de5d74c2SJerry Jelinek &(AcpiGbl_RootTableList.Tables[i].Signature), Signature))
337db2bae30SDana Myers {
338db2bae30SDana Myers continue;
339db2bae30SDana Myers }
340db2bae30SDana Myers
341db2bae30SDana Myers if (++j < Instance)
342db2bae30SDana Myers {
343db2bae30SDana Myers continue;
344db2bae30SDana Myers }
345db2bae30SDana Myers
346*de5d74c2SJerry Jelinek Status = AcpiTbValidateTable (&AcpiGbl_RootTableList.Tables[i]);
347db2bae30SDana Myers if (ACPI_SUCCESS (Status))
348db2bae30SDana Myers {
349db2bae30SDana Myers *OutTable = AcpiGbl_RootTableList.Tables[i].Pointer;
350db2bae30SDana Myers }
351db2bae30SDana Myers
352db2bae30SDana Myers return (Status);
353db2bae30SDana Myers }
354db2bae30SDana Myers
355db2bae30SDana Myers return (AE_NOT_FOUND);
356db2bae30SDana Myers }
357db2bae30SDana Myers
ACPI_EXPORT_SYMBOL(AcpiGetTable)358db2bae30SDana Myers ACPI_EXPORT_SYMBOL (AcpiGetTable)
359db2bae30SDana Myers
360db2bae30SDana Myers
361db2bae30SDana Myers /*******************************************************************************
362db2bae30SDana Myers *
363db2bae30SDana Myers * FUNCTION: AcpiGetTableByIndex
364db2bae30SDana Myers *
365db2bae30SDana Myers * PARAMETERS: TableIndex - Table index
366db2bae30SDana Myers * Table - Where the pointer to the table is returned
367db2bae30SDana Myers *
368*de5d74c2SJerry Jelinek * RETURN: Status and pointer to the requested table
369db2bae30SDana Myers *
370*de5d74c2SJerry Jelinek * DESCRIPTION: Obtain a table by an index into the global table list. Used
371*de5d74c2SJerry Jelinek * internally also.
372db2bae30SDana Myers *
373db2bae30SDana Myers ******************************************************************************/
374db2bae30SDana Myers
375db2bae30SDana Myers ACPI_STATUS
376db2bae30SDana Myers AcpiGetTableByIndex (
377db2bae30SDana Myers UINT32 TableIndex,
378db2bae30SDana Myers ACPI_TABLE_HEADER **Table)
379db2bae30SDana Myers {
380db2bae30SDana Myers ACPI_STATUS Status;
381db2bae30SDana Myers
382db2bae30SDana Myers
383db2bae30SDana Myers ACPI_FUNCTION_TRACE (AcpiGetTableByIndex);
384db2bae30SDana Myers
385db2bae30SDana Myers
386db2bae30SDana Myers /* Parameter validation */
387db2bae30SDana Myers
388db2bae30SDana Myers if (!Table)
389db2bae30SDana Myers {
390db2bae30SDana Myers return_ACPI_STATUS (AE_BAD_PARAMETER);
391db2bae30SDana Myers }
392db2bae30SDana Myers
393db2bae30SDana Myers (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
394db2bae30SDana Myers
395db2bae30SDana Myers /* Validate index */
396db2bae30SDana Myers
39726f3cdf0SGordon Ross if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
398db2bae30SDana Myers {
399db2bae30SDana Myers (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
400db2bae30SDana Myers return_ACPI_STATUS (AE_BAD_PARAMETER);
401db2bae30SDana Myers }
402db2bae30SDana Myers
403db2bae30SDana Myers if (!AcpiGbl_RootTableList.Tables[TableIndex].Pointer)
404db2bae30SDana Myers {
405db2bae30SDana Myers /* Table is not mapped, map it */
406db2bae30SDana Myers
407*de5d74c2SJerry Jelinek Status = AcpiTbValidateTable (
408*de5d74c2SJerry Jelinek &AcpiGbl_RootTableList.Tables[TableIndex]);
409db2bae30SDana Myers if (ACPI_FAILURE (Status))
410db2bae30SDana Myers {
411db2bae30SDana Myers (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
412db2bae30SDana Myers return_ACPI_STATUS (Status);
413db2bae30SDana Myers }
414db2bae30SDana Myers }
415db2bae30SDana Myers
416db2bae30SDana Myers *Table = AcpiGbl_RootTableList.Tables[TableIndex].Pointer;
417db2bae30SDana Myers (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
418db2bae30SDana Myers return_ACPI_STATUS (AE_OK);
419db2bae30SDana Myers }
420db2bae30SDana Myers
ACPI_EXPORT_SYMBOL(AcpiGetTableByIndex)421db2bae30SDana Myers ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex)
422db2bae30SDana Myers
423db2bae30SDana Myers
424db2bae30SDana Myers /*******************************************************************************
425db2bae30SDana Myers *
426db2bae30SDana Myers * FUNCTION: AcpiInstallTableHandler
427ae115bc7Smrj *
428db2bae30SDana Myers * PARAMETERS: Handler - Table event handler
429db2bae30SDana Myers * Context - Value passed to the handler on each event
430ae115bc7Smrj *
431ae115bc7Smrj * RETURN: Status
432ae115bc7Smrj *
433*de5d74c2SJerry Jelinek * DESCRIPTION: Install a global table event handler.
434ae115bc7Smrj *
435ae115bc7Smrj ******************************************************************************/
436ae115bc7Smrj
437ae115bc7Smrj ACPI_STATUS
438db2bae30SDana Myers AcpiInstallTableHandler (
439db2bae30SDana Myers ACPI_TABLE_HANDLER Handler,
440db2bae30SDana Myers void *Context)
441ae115bc7Smrj {
442ae115bc7Smrj ACPI_STATUS Status;
443ae115bc7Smrj
444ae115bc7Smrj
445db2bae30SDana Myers ACPI_FUNCTION_TRACE (AcpiInstallTableHandler);
446ae115bc7Smrj
447ae115bc7Smrj
448db2bae30SDana Myers if (!Handler)
449ae115bc7Smrj {
450ae115bc7Smrj return_ACPI_STATUS (AE_BAD_PARAMETER);
451ae115bc7Smrj }
452ae115bc7Smrj
453db2bae30SDana Myers Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
454ae115bc7Smrj if (ACPI_FAILURE (Status))
455ae115bc7Smrj {
456ae115bc7Smrj return_ACPI_STATUS (Status);
457ae115bc7Smrj }
458ae115bc7Smrj
459db2bae30SDana Myers /* Don't allow more than one handler */
460ae115bc7Smrj
461db2bae30SDana Myers if (AcpiGbl_TableHandler)
462ae115bc7Smrj {
463db2bae30SDana Myers Status = AE_ALREADY_EXISTS;
464db2bae30SDana Myers goto Cleanup;
465db2bae30SDana Myers }
466db2bae30SDana Myers
467db2bae30SDana Myers /* Install the handler */
468db2bae30SDana Myers
469db2bae30SDana Myers AcpiGbl_TableHandler = Handler;
470db2bae30SDana Myers AcpiGbl_TableHandlerContext = Context;
471db2bae30SDana Myers
472db2bae30SDana Myers Cleanup:
473db2bae30SDana Myers (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
474ae115bc7Smrj return_ACPI_STATUS (Status);
475ae115bc7Smrj }
476ae115bc7Smrj
ACPI_EXPORT_SYMBOL(AcpiInstallTableHandler)477db2bae30SDana Myers ACPI_EXPORT_SYMBOL (AcpiInstallTableHandler)
478ae115bc7Smrj
479ae115bc7Smrj
480ae115bc7Smrj /*******************************************************************************
481ae115bc7Smrj *
482db2bae30SDana Myers * FUNCTION: AcpiRemoveTableHandler
483ae115bc7Smrj *
484db2bae30SDana Myers * PARAMETERS: Handler - Table event handler that was installed
485db2bae30SDana Myers * previously.
486ae115bc7Smrj *
487ae115bc7Smrj * RETURN: Status
488ae115bc7Smrj *
489*de5d74c2SJerry Jelinek * DESCRIPTION: Remove a table event handler
490ae115bc7Smrj *
491ae115bc7Smrj ******************************************************************************/
492ae115bc7Smrj
493ae115bc7Smrj ACPI_STATUS
494db2bae30SDana Myers AcpiRemoveTableHandler (
495db2bae30SDana Myers ACPI_TABLE_HANDLER Handler)
496ae115bc7Smrj {
497ae115bc7Smrj ACPI_STATUS Status;
498ae115bc7Smrj
499ae115bc7Smrj
500db2bae30SDana Myers ACPI_FUNCTION_TRACE (AcpiRemoveTableHandler);
501ae115bc7Smrj
502ae115bc7Smrj
503db2bae30SDana Myers Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
504ae115bc7Smrj if (ACPI_FAILURE (Status))
505ae115bc7Smrj {
506ae115bc7Smrj return_ACPI_STATUS (Status);
507ae115bc7Smrj }
508ae115bc7Smrj
509db2bae30SDana Myers /* Make sure that the installed handler is the same */
510ae115bc7Smrj
511db2bae30SDana Myers if (!Handler ||
512db2bae30SDana Myers Handler != AcpiGbl_TableHandler)
513ae115bc7Smrj {
514db2bae30SDana Myers Status = AE_BAD_PARAMETER;
515db2bae30SDana Myers goto Cleanup;
516ae115bc7Smrj }
517ae115bc7Smrj
518db2bae30SDana Myers /* Remove the handler */
519ae115bc7Smrj
520db2bae30SDana Myers AcpiGbl_TableHandler = NULL;
521ae115bc7Smrj
522db2bae30SDana Myers Cleanup:
523db2bae30SDana Myers (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
524ae115bc7Smrj return_ACPI_STATUS (Status);
525ae115bc7Smrj }
526ae115bc7Smrj
527db2bae30SDana Myers ACPI_EXPORT_SYMBOL (AcpiRemoveTableHandler)
528