tbxface.c revision 1.14 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.5 christos * Module Name: tbxface - ACPI table-oriented external interfaces
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.3 jruoho /*
8 1.14 christos * Copyright (C) 2000 - 2019, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.3 jruoho * Redistribution and use in source and binary forms, with or without
12 1.3 jruoho * modification, are permitted provided that the following conditions
13 1.3 jruoho * are met:
14 1.3 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.3 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.3 jruoho * without modification.
17 1.3 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.3 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.3 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.3 jruoho * including a substantially similar Disclaimer requirement for further
21 1.3 jruoho * binary redistribution.
22 1.3 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.3 jruoho * of any contributors may be used to endorse or promote products derived
24 1.3 jruoho * from this software without specific prior written permission.
25 1.3 jruoho *
26 1.3 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.3 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.3 jruoho * Software Foundation.
29 1.3 jruoho *
30 1.3 jruoho * NO WARRANTY
31 1.3 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.3 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.3 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.3 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.3 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.3 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.3 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.3 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.3 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.3 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.3 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.3 jruoho */
43 1.1 jruoho
44 1.5 christos #define EXPORT_ACPI_INTERFACES
45 1.1 jruoho
46 1.1 jruoho #include "acpi.h"
47 1.1 jruoho #include "accommon.h"
48 1.1 jruoho #include "actables.h"
49 1.1 jruoho
50 1.1 jruoho #define _COMPONENT ACPI_TABLES
51 1.1 jruoho ACPI_MODULE_NAME ("tbxface")
52 1.1 jruoho
53 1.1 jruoho
54 1.1 jruoho /*******************************************************************************
55 1.1 jruoho *
56 1.1 jruoho * FUNCTION: AcpiAllocateRootTable
57 1.1 jruoho *
58 1.1 jruoho * PARAMETERS: InitialTableCount - Size of InitialTableArray, in number of
59 1.1 jruoho * ACPI_TABLE_DESC structures
60 1.1 jruoho *
61 1.1 jruoho * RETURN: Status
62 1.1 jruoho *
63 1.1 jruoho * DESCRIPTION: Allocate a root table array. Used by iASL compiler and
64 1.1 jruoho * AcpiInitializeTables.
65 1.1 jruoho *
66 1.1 jruoho ******************************************************************************/
67 1.1 jruoho
68 1.1 jruoho ACPI_STATUS
69 1.1 jruoho AcpiAllocateRootTable (
70 1.1 jruoho UINT32 InitialTableCount)
71 1.1 jruoho {
72 1.1 jruoho
73 1.1 jruoho AcpiGbl_RootTableList.MaxTableCount = InitialTableCount;
74 1.1 jruoho AcpiGbl_RootTableList.Flags = ACPI_ROOT_ALLOW_RESIZE;
75 1.1 jruoho
76 1.1 jruoho return (AcpiTbResizeRootTableList ());
77 1.1 jruoho }
78 1.1 jruoho
79 1.1 jruoho
80 1.1 jruoho /*******************************************************************************
81 1.1 jruoho *
82 1.1 jruoho * FUNCTION: AcpiInitializeTables
83 1.1 jruoho *
84 1.1 jruoho * PARAMETERS: InitialTableArray - Pointer to an array of pre-allocated
85 1.1 jruoho * ACPI_TABLE_DESC structures. If NULL, the
86 1.1 jruoho * array is dynamically allocated.
87 1.1 jruoho * InitialTableCount - Size of InitialTableArray, in number of
88 1.1 jruoho * ACPI_TABLE_DESC structures
89 1.5 christos * AllowResize - Flag to tell Table Manager if resize of
90 1.1 jruoho * pre-allocated array is allowed. Ignored
91 1.1 jruoho * if InitialTableArray is NULL.
92 1.1 jruoho *
93 1.1 jruoho * RETURN: Status
94 1.1 jruoho *
95 1.1 jruoho * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
96 1.1 jruoho *
97 1.1 jruoho * NOTE: Allows static allocation of the initial table array in order
98 1.1 jruoho * to avoid the use of dynamic memory in confined environments
99 1.1 jruoho * such as the kernel boot sequence where it may not be available.
100 1.1 jruoho *
101 1.1 jruoho * If the host OS memory managers are initialized, use NULL for
102 1.1 jruoho * InitialTableArray, and the table will be dynamically allocated.
103 1.1 jruoho *
104 1.1 jruoho ******************************************************************************/
105 1.1 jruoho
106 1.10 christos ACPI_STATUS ACPI_INIT_FUNCTION
107 1.1 jruoho AcpiInitializeTables (
108 1.1 jruoho ACPI_TABLE_DESC *InitialTableArray,
109 1.1 jruoho UINT32 InitialTableCount,
110 1.1 jruoho BOOLEAN AllowResize)
111 1.1 jruoho {
112 1.1 jruoho ACPI_PHYSICAL_ADDRESS RsdpAddress;
113 1.1 jruoho ACPI_STATUS Status;
114 1.1 jruoho
115 1.1 jruoho
116 1.1 jruoho ACPI_FUNCTION_TRACE (AcpiInitializeTables);
117 1.1 jruoho
118 1.1 jruoho
119 1.1 jruoho /*
120 1.5 christos * Setup the Root Table Array and allocate the table array
121 1.5 christos * if requested
122 1.1 jruoho */
123 1.1 jruoho if (!InitialTableArray)
124 1.1 jruoho {
125 1.1 jruoho Status = AcpiAllocateRootTable (InitialTableCount);
126 1.1 jruoho if (ACPI_FAILURE (Status))
127 1.1 jruoho {
128 1.1 jruoho return_ACPI_STATUS (Status);
129 1.1 jruoho }
130 1.1 jruoho }
131 1.1 jruoho else
132 1.1 jruoho {
133 1.1 jruoho /* Root Table Array has been statically allocated by the host */
134 1.1 jruoho
135 1.8 christos memset (InitialTableArray, 0,
136 1.1 jruoho (ACPI_SIZE) InitialTableCount * sizeof (ACPI_TABLE_DESC));
137 1.1 jruoho
138 1.1 jruoho AcpiGbl_RootTableList.Tables = InitialTableArray;
139 1.1 jruoho AcpiGbl_RootTableList.MaxTableCount = InitialTableCount;
140 1.1 jruoho AcpiGbl_RootTableList.Flags = ACPI_ROOT_ORIGIN_UNKNOWN;
141 1.1 jruoho if (AllowResize)
142 1.1 jruoho {
143 1.1 jruoho AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
144 1.1 jruoho }
145 1.1 jruoho }
146 1.1 jruoho
147 1.1 jruoho /* Get the address of the RSDP */
148 1.1 jruoho
149 1.1 jruoho RsdpAddress = AcpiOsGetRootPointer ();
150 1.1 jruoho if (!RsdpAddress)
151 1.1 jruoho {
152 1.1 jruoho return_ACPI_STATUS (AE_NOT_FOUND);
153 1.1 jruoho }
154 1.1 jruoho
155 1.1 jruoho /*
156 1.1 jruoho * Get the root table (RSDT or XSDT) and extract all entries to the local
157 1.1 jruoho * Root Table Array. This array contains the information of the RSDT/XSDT
158 1.14 christos * in a common, more usable format.
159 1.1 jruoho */
160 1.1 jruoho Status = AcpiTbParseRootTable (RsdpAddress);
161 1.1 jruoho return_ACPI_STATUS (Status);
162 1.1 jruoho }
163 1.1 jruoho
164 1.5 christos ACPI_EXPORT_SYMBOL_INIT (AcpiInitializeTables)
165 1.1 jruoho
166 1.1 jruoho
167 1.1 jruoho /*******************************************************************************
168 1.1 jruoho *
169 1.1 jruoho * FUNCTION: AcpiReallocateRootTable
170 1.1 jruoho *
171 1.1 jruoho * PARAMETERS: None
172 1.1 jruoho *
173 1.1 jruoho * RETURN: Status
174 1.1 jruoho *
175 1.1 jruoho * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the
176 1.1 jruoho * root list from the previously provided scratch area. Should
177 1.1 jruoho * be called once dynamic memory allocation is available in the
178 1.5 christos * kernel.
179 1.1 jruoho *
180 1.1 jruoho ******************************************************************************/
181 1.1 jruoho
182 1.10 christos ACPI_STATUS ACPI_INIT_FUNCTION
183 1.1 jruoho AcpiReallocateRootTable (
184 1.1 jruoho void)
185 1.1 jruoho {
186 1.5 christos ACPI_STATUS Status;
187 1.12 christos ACPI_TABLE_DESC *TableDesc;
188 1.12 christos UINT32 i, j;
189 1.1 jruoho
190 1.1 jruoho
191 1.1 jruoho ACPI_FUNCTION_TRACE (AcpiReallocateRootTable);
192 1.1 jruoho
193 1.1 jruoho
194 1.1 jruoho /*
195 1.12 christos * If there are tables unverified, it is required to reallocate the
196 1.12 christos * root table list to clean up invalid table entries. Otherwise only
197 1.12 christos * reallocate the root table list if the host provided a static buffer
198 1.12 christos * for the table array in the call to AcpiInitializeTables().
199 1.1 jruoho */
200 1.12 christos if ((AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED) &&
201 1.12 christos AcpiGbl_EnableTableValidation)
202 1.1 jruoho {
203 1.1 jruoho return_ACPI_STATUS (AE_SUPPORT);
204 1.1 jruoho }
205 1.1 jruoho
206 1.12 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
207 1.12 christos
208 1.11 christos /*
209 1.11 christos * Ensure OS early boot logic, which is required by some hosts. If the
210 1.11 christos * table state is reported to be wrong, developers should fix the
211 1.11 christos * issue by invoking AcpiPutTable() for the reported table during the
212 1.11 christos * early stage.
213 1.11 christos */
214 1.11 christos for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
215 1.11 christos {
216 1.12 christos TableDesc = &AcpiGbl_RootTableList.Tables[i];
217 1.12 christos if (TableDesc->Pointer)
218 1.11 christos {
219 1.11 christos ACPI_ERROR ((AE_INFO,
220 1.11 christos "Table [%4.4s] is not invalidated during early boot stage",
221 1.12 christos TableDesc->Signature.Ascii));
222 1.12 christos }
223 1.12 christos }
224 1.12 christos
225 1.12 christos if (!AcpiGbl_EnableTableValidation)
226 1.12 christos {
227 1.12 christos /*
228 1.12 christos * Now it's safe to do full table validation. We can do deferred
229 1.14 christos * table initialization here once the flag is set.
230 1.12 christos */
231 1.12 christos AcpiGbl_EnableTableValidation = TRUE;
232 1.12 christos for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
233 1.12 christos {
234 1.12 christos TableDesc = &AcpiGbl_RootTableList.Tables[i];
235 1.12 christos if (!(TableDesc->Flags & ACPI_TABLE_IS_VERIFIED))
236 1.12 christos {
237 1.12 christos Status = AcpiTbVerifyTempTable (TableDesc, NULL, &j);
238 1.12 christos if (ACPI_FAILURE (Status))
239 1.12 christos {
240 1.12 christos AcpiTbUninstallTable (TableDesc);
241 1.12 christos }
242 1.12 christos }
243 1.11 christos }
244 1.11 christos }
245 1.11 christos
246 1.5 christos AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
247 1.12 christos Status = AcpiTbResizeRootTableList ();
248 1.12 christos AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
249 1.1 jruoho
250 1.12 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
251 1.5 christos return_ACPI_STATUS (Status);
252 1.1 jruoho }
253 1.1 jruoho
254 1.5 christos ACPI_EXPORT_SYMBOL_INIT (AcpiReallocateRootTable)
255 1.1 jruoho
256 1.1 jruoho
257 1.1 jruoho /*******************************************************************************
258 1.1 jruoho *
259 1.1 jruoho * FUNCTION: AcpiGetTableHeader
260 1.1 jruoho *
261 1.1 jruoho * PARAMETERS: Signature - ACPI signature of needed table
262 1.1 jruoho * Instance - Which instance (for SSDTs)
263 1.1 jruoho * OutTableHeader - The pointer to the table header to fill
264 1.1 jruoho *
265 1.1 jruoho * RETURN: Status and pointer to mapped table header
266 1.1 jruoho *
267 1.1 jruoho * DESCRIPTION: Finds an ACPI table header.
268 1.1 jruoho *
269 1.1 jruoho ******************************************************************************/
270 1.1 jruoho
271 1.1 jruoho ACPI_STATUS
272 1.1 jruoho AcpiGetTableHeader (
273 1.2 jruoho ACPI_CONST_STRING Signature,
274 1.1 jruoho UINT32 Instance,
275 1.1 jruoho ACPI_TABLE_HEADER *OutTableHeader)
276 1.1 jruoho {
277 1.1 jruoho UINT32 i;
278 1.1 jruoho UINT32 j;
279 1.1 jruoho ACPI_TABLE_HEADER *Header;
280 1.1 jruoho
281 1.1 jruoho /* Parameter validation */
282 1.1 jruoho
283 1.1 jruoho if (!Signature || !OutTableHeader)
284 1.1 jruoho {
285 1.1 jruoho return (AE_BAD_PARAMETER);
286 1.1 jruoho }
287 1.1 jruoho
288 1.1 jruoho /* Walk the root table list */
289 1.1 jruoho
290 1.1 jruoho for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
291 1.1 jruoho {
292 1.14 christos if (!ACPI_COMPARE_NAMESEG (
293 1.9 christos &(AcpiGbl_RootTableList.Tables[i].Signature), Signature))
294 1.1 jruoho {
295 1.1 jruoho continue;
296 1.1 jruoho }
297 1.1 jruoho
298 1.1 jruoho if (++j < Instance)
299 1.1 jruoho {
300 1.1 jruoho continue;
301 1.1 jruoho }
302 1.1 jruoho
303 1.1 jruoho if (!AcpiGbl_RootTableList.Tables[i].Pointer)
304 1.1 jruoho {
305 1.1 jruoho if ((AcpiGbl_RootTableList.Tables[i].Flags &
306 1.1 jruoho ACPI_TABLE_ORIGIN_MASK) ==
307 1.6 christos ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL)
308 1.1 jruoho {
309 1.1 jruoho Header = AcpiOsMapMemory (
310 1.9 christos AcpiGbl_RootTableList.Tables[i].Address,
311 1.9 christos sizeof (ACPI_TABLE_HEADER));
312 1.1 jruoho if (!Header)
313 1.1 jruoho {
314 1.5 christos return (AE_NO_MEMORY);
315 1.1 jruoho }
316 1.1 jruoho
317 1.9 christos memcpy (OutTableHeader, Header, sizeof (ACPI_TABLE_HEADER));
318 1.5 christos AcpiOsUnmapMemory (Header, sizeof (ACPI_TABLE_HEADER));
319 1.1 jruoho }
320 1.1 jruoho else
321 1.1 jruoho {
322 1.5 christos return (AE_NOT_FOUND);
323 1.1 jruoho }
324 1.1 jruoho }
325 1.1 jruoho else
326 1.1 jruoho {
327 1.8 christos memcpy (OutTableHeader,
328 1.1 jruoho AcpiGbl_RootTableList.Tables[i].Pointer,
329 1.5 christos sizeof (ACPI_TABLE_HEADER));
330 1.1 jruoho }
331 1.1 jruoho
332 1.1 jruoho return (AE_OK);
333 1.1 jruoho }
334 1.1 jruoho
335 1.1 jruoho return (AE_NOT_FOUND);
336 1.1 jruoho }
337 1.1 jruoho
338 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiGetTableHeader)
339 1.1 jruoho
340 1.1 jruoho
341 1.1 jruoho /*******************************************************************************
342 1.1 jruoho *
343 1.1 jruoho * FUNCTION: AcpiGetTable
344 1.1 jruoho *
345 1.1 jruoho * PARAMETERS: Signature - ACPI signature of needed table
346 1.1 jruoho * Instance - Which instance (for SSDTs)
347 1.1 jruoho * OutTable - Where the pointer to the table is returned
348 1.1 jruoho *
349 1.5 christos * RETURN: Status and pointer to the requested table
350 1.1 jruoho *
351 1.5 christos * DESCRIPTION: Finds and verifies an ACPI table. Table must be in the
352 1.5 christos * RSDT/XSDT.
353 1.11 christos * Note that an early stage AcpiGetTable() call must be paired
354 1.11 christos * with an early stage AcpiPutTable() call. otherwise the table
355 1.11 christos * pointer mapped by the early stage mapping implementation may be
356 1.11 christos * erroneously unmapped by the late stage unmapping implementation
357 1.11 christos * in an AcpiPutTable() invoked during the late stage.
358 1.1 jruoho *
359 1.1 jruoho ******************************************************************************/
360 1.1 jruoho
361 1.1 jruoho ACPI_STATUS
362 1.1 jruoho AcpiGetTable (
363 1.2 jruoho ACPI_CONST_STRING Signature,
364 1.1 jruoho UINT32 Instance,
365 1.1 jruoho ACPI_TABLE_HEADER **OutTable)
366 1.1 jruoho {
367 1.1 jruoho UINT32 i;
368 1.1 jruoho UINT32 j;
369 1.11 christos ACPI_STATUS Status = AE_NOT_FOUND;
370 1.11 christos ACPI_TABLE_DESC *TableDesc;
371 1.1 jruoho
372 1.1 jruoho /* Parameter validation */
373 1.1 jruoho
374 1.1 jruoho if (!Signature || !OutTable)
375 1.1 jruoho {
376 1.1 jruoho return (AE_BAD_PARAMETER);
377 1.1 jruoho }
378 1.1 jruoho
379 1.11 christos /*
380 1.11 christos * Note that the following line is required by some OSPMs, they only
381 1.11 christos * check if the returned table is NULL instead of the returned status
382 1.11 christos * to determined if this function is succeeded.
383 1.11 christos */
384 1.11 christos *OutTable = NULL;
385 1.11 christos
386 1.11 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
387 1.11 christos
388 1.1 jruoho /* Walk the root table list */
389 1.1 jruoho
390 1.1 jruoho for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
391 1.1 jruoho {
392 1.11 christos TableDesc = &AcpiGbl_RootTableList.Tables[i];
393 1.11 christos
394 1.14 christos if (!ACPI_COMPARE_NAMESEG (&TableDesc->Signature, Signature))
395 1.1 jruoho {
396 1.1 jruoho continue;
397 1.1 jruoho }
398 1.1 jruoho
399 1.1 jruoho if (++j < Instance)
400 1.1 jruoho {
401 1.1 jruoho continue;
402 1.1 jruoho }
403 1.1 jruoho
404 1.11 christos Status = AcpiTbGetTable (TableDesc, OutTable);
405 1.11 christos break;
406 1.11 christos }
407 1.11 christos
408 1.11 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
409 1.11 christos return (Status);
410 1.11 christos }
411 1.11 christos
412 1.11 christos ACPI_EXPORT_SYMBOL (AcpiGetTable)
413 1.11 christos
414 1.11 christos
415 1.11 christos /*******************************************************************************
416 1.11 christos *
417 1.11 christos * FUNCTION: AcpiPutTable
418 1.11 christos *
419 1.11 christos * PARAMETERS: Table - The pointer to the table
420 1.11 christos *
421 1.11 christos * RETURN: None
422 1.11 christos *
423 1.11 christos * DESCRIPTION: Release a table returned by AcpiGetTable() and its clones.
424 1.11 christos * Note that it is not safe if this function was invoked after an
425 1.11 christos * uninstallation happened to the original table descriptor.
426 1.11 christos * Currently there is no OSPMs' requirement to handle such
427 1.11 christos * situations.
428 1.11 christos *
429 1.11 christos ******************************************************************************/
430 1.11 christos
431 1.11 christos void
432 1.11 christos AcpiPutTable (
433 1.11 christos ACPI_TABLE_HEADER *Table)
434 1.11 christos {
435 1.11 christos UINT32 i;
436 1.11 christos ACPI_TABLE_DESC *TableDesc;
437 1.11 christos
438 1.11 christos
439 1.11 christos ACPI_FUNCTION_TRACE (AcpiPutTable);
440 1.11 christos
441 1.11 christos
442 1.12 christos if (!Table)
443 1.12 christos {
444 1.12 christos return_VOID;
445 1.12 christos }
446 1.12 christos
447 1.11 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
448 1.11 christos
449 1.11 christos /* Walk the root table list */
450 1.11 christos
451 1.11 christos for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
452 1.11 christos {
453 1.11 christos TableDesc = &AcpiGbl_RootTableList.Tables[i];
454 1.11 christos
455 1.11 christos if (TableDesc->Pointer != Table)
456 1.1 jruoho {
457 1.11 christos continue;
458 1.1 jruoho }
459 1.1 jruoho
460 1.11 christos AcpiTbPutTable (TableDesc);
461 1.11 christos break;
462 1.1 jruoho }
463 1.1 jruoho
464 1.11 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
465 1.11 christos return_VOID;
466 1.1 jruoho }
467 1.1 jruoho
468 1.11 christos ACPI_EXPORT_SYMBOL (AcpiPutTable)
469 1.1 jruoho
470 1.1 jruoho
471 1.1 jruoho /*******************************************************************************
472 1.1 jruoho *
473 1.1 jruoho * FUNCTION: AcpiGetTableByIndex
474 1.1 jruoho *
475 1.1 jruoho * PARAMETERS: TableIndex - Table index
476 1.11 christos * OutTable - Where the pointer to the table is returned
477 1.1 jruoho *
478 1.5 christos * RETURN: Status and pointer to the requested table
479 1.1 jruoho *
480 1.5 christos * DESCRIPTION: Obtain a table by an index into the global table list. Used
481 1.5 christos * internally also.
482 1.1 jruoho *
483 1.1 jruoho ******************************************************************************/
484 1.1 jruoho
485 1.1 jruoho ACPI_STATUS
486 1.1 jruoho AcpiGetTableByIndex (
487 1.1 jruoho UINT32 TableIndex,
488 1.11 christos ACPI_TABLE_HEADER **OutTable)
489 1.1 jruoho {
490 1.1 jruoho ACPI_STATUS Status;
491 1.1 jruoho
492 1.1 jruoho
493 1.1 jruoho ACPI_FUNCTION_TRACE (AcpiGetTableByIndex);
494 1.1 jruoho
495 1.1 jruoho
496 1.1 jruoho /* Parameter validation */
497 1.1 jruoho
498 1.11 christos if (!OutTable)
499 1.1 jruoho {
500 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
501 1.1 jruoho }
502 1.1 jruoho
503 1.11 christos /*
504 1.11 christos * Note that the following line is required by some OSPMs, they only
505 1.11 christos * check if the returned table is NULL instead of the returned status
506 1.11 christos * to determined if this function is succeeded.
507 1.11 christos */
508 1.11 christos *OutTable = NULL;
509 1.11 christos
510 1.1 jruoho (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
511 1.1 jruoho
512 1.1 jruoho /* Validate index */
513 1.1 jruoho
514 1.1 jruoho if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
515 1.1 jruoho {
516 1.11 christos Status = AE_BAD_PARAMETER;
517 1.11 christos goto UnlockAndExit;
518 1.1 jruoho }
519 1.1 jruoho
520 1.11 christos Status = AcpiTbGetTable (
521 1.11 christos &AcpiGbl_RootTableList.Tables[TableIndex], OutTable);
522 1.1 jruoho
523 1.11 christos UnlockAndExit:
524 1.1 jruoho (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
525 1.11 christos return_ACPI_STATUS (Status);
526 1.1 jruoho }
527 1.1 jruoho
528 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex)
529 1.1 jruoho
530 1.1 jruoho
531 1.1 jruoho /*******************************************************************************
532 1.1 jruoho *
533 1.1 jruoho * FUNCTION: AcpiInstallTableHandler
534 1.1 jruoho *
535 1.1 jruoho * PARAMETERS: Handler - Table event handler
536 1.1 jruoho * Context - Value passed to the handler on each event
537 1.1 jruoho *
538 1.1 jruoho * RETURN: Status
539 1.1 jruoho *
540 1.5 christos * DESCRIPTION: Install a global table event handler.
541 1.1 jruoho *
542 1.1 jruoho ******************************************************************************/
543 1.1 jruoho
544 1.1 jruoho ACPI_STATUS
545 1.1 jruoho AcpiInstallTableHandler (
546 1.1 jruoho ACPI_TABLE_HANDLER Handler,
547 1.1 jruoho void *Context)
548 1.1 jruoho {
549 1.1 jruoho ACPI_STATUS Status;
550 1.1 jruoho
551 1.1 jruoho
552 1.1 jruoho ACPI_FUNCTION_TRACE (AcpiInstallTableHandler);
553 1.1 jruoho
554 1.1 jruoho
555 1.1 jruoho if (!Handler)
556 1.1 jruoho {
557 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
558 1.1 jruoho }
559 1.1 jruoho
560 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
561 1.1 jruoho if (ACPI_FAILURE (Status))
562 1.1 jruoho {
563 1.1 jruoho return_ACPI_STATUS (Status);
564 1.1 jruoho }
565 1.1 jruoho
566 1.1 jruoho /* Don't allow more than one handler */
567 1.1 jruoho
568 1.1 jruoho if (AcpiGbl_TableHandler)
569 1.1 jruoho {
570 1.1 jruoho Status = AE_ALREADY_EXISTS;
571 1.1 jruoho goto Cleanup;
572 1.1 jruoho }
573 1.1 jruoho
574 1.1 jruoho /* Install the handler */
575 1.1 jruoho
576 1.1 jruoho AcpiGbl_TableHandler = Handler;
577 1.1 jruoho AcpiGbl_TableHandlerContext = Context;
578 1.1 jruoho
579 1.1 jruoho Cleanup:
580 1.1 jruoho (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
581 1.1 jruoho return_ACPI_STATUS (Status);
582 1.1 jruoho }
583 1.1 jruoho
584 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiInstallTableHandler)
585 1.1 jruoho
586 1.1 jruoho
587 1.1 jruoho /*******************************************************************************
588 1.1 jruoho *
589 1.1 jruoho * FUNCTION: AcpiRemoveTableHandler
590 1.1 jruoho *
591 1.1 jruoho * PARAMETERS: Handler - Table event handler that was installed
592 1.1 jruoho * previously.
593 1.1 jruoho *
594 1.1 jruoho * RETURN: Status
595 1.1 jruoho *
596 1.5 christos * DESCRIPTION: Remove a table event handler
597 1.1 jruoho *
598 1.1 jruoho ******************************************************************************/
599 1.1 jruoho
600 1.1 jruoho ACPI_STATUS
601 1.1 jruoho AcpiRemoveTableHandler (
602 1.1 jruoho ACPI_TABLE_HANDLER Handler)
603 1.1 jruoho {
604 1.1 jruoho ACPI_STATUS Status;
605 1.1 jruoho
606 1.1 jruoho
607 1.1 jruoho ACPI_FUNCTION_TRACE (AcpiRemoveTableHandler);
608 1.1 jruoho
609 1.1 jruoho
610 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
611 1.1 jruoho if (ACPI_FAILURE (Status))
612 1.1 jruoho {
613 1.1 jruoho return_ACPI_STATUS (Status);
614 1.1 jruoho }
615 1.1 jruoho
616 1.1 jruoho /* Make sure that the installed handler is the same */
617 1.1 jruoho
618 1.1 jruoho if (!Handler ||
619 1.1 jruoho Handler != AcpiGbl_TableHandler)
620 1.1 jruoho {
621 1.1 jruoho Status = AE_BAD_PARAMETER;
622 1.1 jruoho goto Cleanup;
623 1.1 jruoho }
624 1.1 jruoho
625 1.1 jruoho /* Remove the handler */
626 1.1 jruoho
627 1.1 jruoho AcpiGbl_TableHandler = NULL;
628 1.1 jruoho
629 1.1 jruoho Cleanup:
630 1.1 jruoho (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
631 1.1 jruoho return_ACPI_STATUS (Status);
632 1.1 jruoho }
633 1.1 jruoho
634 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiRemoveTableHandler)
635