tbxface.c revision 1.3.2.2 1 1.3.2.2 bouyer /******************************************************************************
2 1.3.2.2 bouyer *
3 1.3.2.2 bouyer * Module Name: tbxface - Public interfaces to the ACPI subsystem
4 1.3.2.2 bouyer * ACPI table oriented interfaces
5 1.3.2.2 bouyer *
6 1.3.2.2 bouyer *****************************************************************************/
7 1.3.2.2 bouyer
8 1.3.2.2 bouyer /*
9 1.3.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
10 1.3.2.2 bouyer * All rights reserved.
11 1.3.2.2 bouyer *
12 1.3.2.2 bouyer * Redistribution and use in source and binary forms, with or without
13 1.3.2.2 bouyer * modification, are permitted provided that the following conditions
14 1.3.2.2 bouyer * are met:
15 1.3.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
16 1.3.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
17 1.3.2.2 bouyer * without modification.
18 1.3.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.3.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
20 1.3.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
21 1.3.2.2 bouyer * including a substantially similar Disclaimer requirement for further
22 1.3.2.2 bouyer * binary redistribution.
23 1.3.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
24 1.3.2.2 bouyer * of any contributors may be used to endorse or promote products derived
25 1.3.2.2 bouyer * from this software without specific prior written permission.
26 1.3.2.2 bouyer *
27 1.3.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
28 1.3.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
29 1.3.2.2 bouyer * Software Foundation.
30 1.3.2.2 bouyer *
31 1.3.2.2 bouyer * NO WARRANTY
32 1.3.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.3.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.3.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.3.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.3.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.3.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.3.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.3.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.3.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.3.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.3.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
43 1.3.2.2 bouyer */
44 1.3.2.2 bouyer
45 1.3.2.2 bouyer #define __TBXFACE_C__
46 1.3.2.2 bouyer
47 1.3.2.2 bouyer #include "acpi.h"
48 1.3.2.2 bouyer #include "accommon.h"
49 1.3.2.2 bouyer #include "acnamesp.h"
50 1.3.2.2 bouyer #include "actables.h"
51 1.3.2.2 bouyer
52 1.3.2.2 bouyer #define _COMPONENT ACPI_TABLES
53 1.3.2.2 bouyer ACPI_MODULE_NAME ("tbxface")
54 1.3.2.2 bouyer
55 1.3.2.2 bouyer /* Local prototypes */
56 1.3.2.2 bouyer
57 1.3.2.2 bouyer static ACPI_STATUS
58 1.3.2.2 bouyer AcpiTbLoadNamespace (
59 1.3.2.2 bouyer void);
60 1.3.2.2 bouyer
61 1.3.2.2 bouyer
62 1.3.2.2 bouyer /*******************************************************************************
63 1.3.2.2 bouyer *
64 1.3.2.2 bouyer * FUNCTION: AcpiAllocateRootTable
65 1.3.2.2 bouyer *
66 1.3.2.2 bouyer * PARAMETERS: InitialTableCount - Size of InitialTableArray, in number of
67 1.3.2.2 bouyer * ACPI_TABLE_DESC structures
68 1.3.2.2 bouyer *
69 1.3.2.2 bouyer * RETURN: Status
70 1.3.2.2 bouyer *
71 1.3.2.2 bouyer * DESCRIPTION: Allocate a root table array. Used by iASL compiler and
72 1.3.2.2 bouyer * AcpiInitializeTables.
73 1.3.2.2 bouyer *
74 1.3.2.2 bouyer ******************************************************************************/
75 1.3.2.2 bouyer
76 1.3.2.2 bouyer ACPI_STATUS
77 1.3.2.2 bouyer AcpiAllocateRootTable (
78 1.3.2.2 bouyer UINT32 InitialTableCount)
79 1.3.2.2 bouyer {
80 1.3.2.2 bouyer
81 1.3.2.2 bouyer AcpiGbl_RootTableList.MaxTableCount = InitialTableCount;
82 1.3.2.2 bouyer AcpiGbl_RootTableList.Flags = ACPI_ROOT_ALLOW_RESIZE;
83 1.3.2.2 bouyer
84 1.3.2.2 bouyer return (AcpiTbResizeRootTableList ());
85 1.3.2.2 bouyer }
86 1.3.2.2 bouyer
87 1.3.2.2 bouyer
88 1.3.2.2 bouyer /*******************************************************************************
89 1.3.2.2 bouyer *
90 1.3.2.2 bouyer * FUNCTION: AcpiInitializeTables
91 1.3.2.2 bouyer *
92 1.3.2.2 bouyer * PARAMETERS: InitialTableArray - Pointer to an array of pre-allocated
93 1.3.2.2 bouyer * ACPI_TABLE_DESC structures. If NULL, the
94 1.3.2.2 bouyer * array is dynamically allocated.
95 1.3.2.2 bouyer * InitialTableCount - Size of InitialTableArray, in number of
96 1.3.2.2 bouyer * ACPI_TABLE_DESC structures
97 1.3.2.2 bouyer * AllowRealloc - Flag to tell Table Manager if resize of
98 1.3.2.2 bouyer * pre-allocated array is allowed. Ignored
99 1.3.2.2 bouyer * if InitialTableArray is NULL.
100 1.3.2.2 bouyer *
101 1.3.2.2 bouyer * RETURN: Status
102 1.3.2.2 bouyer *
103 1.3.2.2 bouyer * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
104 1.3.2.2 bouyer *
105 1.3.2.2 bouyer * NOTE: Allows static allocation of the initial table array in order
106 1.3.2.2 bouyer * to avoid the use of dynamic memory in confined environments
107 1.3.2.2 bouyer * such as the kernel boot sequence where it may not be available.
108 1.3.2.2 bouyer *
109 1.3.2.2 bouyer * If the host OS memory managers are initialized, use NULL for
110 1.3.2.2 bouyer * InitialTableArray, and the table will be dynamically allocated.
111 1.3.2.2 bouyer *
112 1.3.2.2 bouyer ******************************************************************************/
113 1.3.2.2 bouyer
114 1.3.2.2 bouyer ACPI_STATUS
115 1.3.2.2 bouyer AcpiInitializeTables (
116 1.3.2.2 bouyer ACPI_TABLE_DESC *InitialTableArray,
117 1.3.2.2 bouyer UINT32 InitialTableCount,
118 1.3.2.2 bouyer BOOLEAN AllowResize)
119 1.3.2.2 bouyer {
120 1.3.2.2 bouyer ACPI_PHYSICAL_ADDRESS RsdpAddress;
121 1.3.2.2 bouyer ACPI_STATUS Status;
122 1.3.2.2 bouyer
123 1.3.2.2 bouyer
124 1.3.2.2 bouyer ACPI_FUNCTION_TRACE (AcpiInitializeTables);
125 1.3.2.2 bouyer
126 1.3.2.2 bouyer
127 1.3.2.2 bouyer /*
128 1.3.2.2 bouyer * Set up the Root Table Array
129 1.3.2.2 bouyer * Allocate the table array if requested
130 1.3.2.2 bouyer */
131 1.3.2.2 bouyer if (!InitialTableArray)
132 1.3.2.2 bouyer {
133 1.3.2.2 bouyer Status = AcpiAllocateRootTable (InitialTableCount);
134 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
135 1.3.2.2 bouyer {
136 1.3.2.2 bouyer return_ACPI_STATUS (Status);
137 1.3.2.2 bouyer }
138 1.3.2.2 bouyer }
139 1.3.2.2 bouyer else
140 1.3.2.2 bouyer {
141 1.3.2.2 bouyer /* Root Table Array has been statically allocated by the host */
142 1.3.2.2 bouyer
143 1.3.2.2 bouyer ACPI_MEMSET (InitialTableArray, 0,
144 1.3.2.2 bouyer (ACPI_SIZE) InitialTableCount * sizeof (ACPI_TABLE_DESC));
145 1.3.2.2 bouyer
146 1.3.2.2 bouyer AcpiGbl_RootTableList.Tables = InitialTableArray;
147 1.3.2.2 bouyer AcpiGbl_RootTableList.MaxTableCount = InitialTableCount;
148 1.3.2.2 bouyer AcpiGbl_RootTableList.Flags = ACPI_ROOT_ORIGIN_UNKNOWN;
149 1.3.2.2 bouyer if (AllowResize)
150 1.3.2.2 bouyer {
151 1.3.2.2 bouyer AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE;
152 1.3.2.2 bouyer }
153 1.3.2.2 bouyer }
154 1.3.2.2 bouyer
155 1.3.2.2 bouyer /* Get the address of the RSDP */
156 1.3.2.2 bouyer
157 1.3.2.2 bouyer RsdpAddress = AcpiOsGetRootPointer ();
158 1.3.2.2 bouyer if (!RsdpAddress)
159 1.3.2.2 bouyer {
160 1.3.2.2 bouyer return_ACPI_STATUS (AE_NOT_FOUND);
161 1.3.2.2 bouyer }
162 1.3.2.2 bouyer
163 1.3.2.2 bouyer /*
164 1.3.2.2 bouyer * Get the root table (RSDT or XSDT) and extract all entries to the local
165 1.3.2.2 bouyer * Root Table Array. This array contains the information of the RSDT/XSDT
166 1.3.2.2 bouyer * in a common, more useable format.
167 1.3.2.2 bouyer */
168 1.3.2.2 bouyer Status = AcpiTbParseRootTable (RsdpAddress);
169 1.3.2.2 bouyer return_ACPI_STATUS (Status);
170 1.3.2.2 bouyer }
171 1.3.2.2 bouyer
172 1.3.2.2 bouyer ACPI_EXPORT_SYMBOL (AcpiInitializeTables)
173 1.3.2.2 bouyer
174 1.3.2.2 bouyer
175 1.3.2.2 bouyer /*******************************************************************************
176 1.3.2.2 bouyer *
177 1.3.2.2 bouyer * FUNCTION: AcpiReallocateRootTable
178 1.3.2.2 bouyer *
179 1.3.2.2 bouyer * PARAMETERS: None
180 1.3.2.2 bouyer *
181 1.3.2.2 bouyer * RETURN: Status
182 1.3.2.2 bouyer *
183 1.3.2.2 bouyer * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the
184 1.3.2.2 bouyer * root list from the previously provided scratch area. Should
185 1.3.2.2 bouyer * be called once dynamic memory allocation is available in the
186 1.3.2.2 bouyer * kernel
187 1.3.2.2 bouyer *
188 1.3.2.2 bouyer ******************************************************************************/
189 1.3.2.2 bouyer
190 1.3.2.2 bouyer ACPI_STATUS
191 1.3.2.2 bouyer AcpiReallocateRootTable (
192 1.3.2.2 bouyer void)
193 1.3.2.2 bouyer {
194 1.3.2.2 bouyer ACPI_TABLE_DESC *Tables;
195 1.3.2.2 bouyer ACPI_SIZE NewSize;
196 1.3.2.2 bouyer ACPI_SIZE CurrentSize;
197 1.3.2.2 bouyer
198 1.3.2.2 bouyer
199 1.3.2.2 bouyer ACPI_FUNCTION_TRACE (AcpiReallocateRootTable);
200 1.3.2.2 bouyer
201 1.3.2.2 bouyer
202 1.3.2.2 bouyer /*
203 1.3.2.2 bouyer * Only reallocate the root table if the host provided a static buffer
204 1.3.2.2 bouyer * for the table array in the call to AcpiInitializeTables.
205 1.3.2.2 bouyer */
206 1.3.2.2 bouyer if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
207 1.3.2.2 bouyer {
208 1.3.2.2 bouyer return_ACPI_STATUS (AE_SUPPORT);
209 1.3.2.2 bouyer }
210 1.3.2.2 bouyer
211 1.3.2.2 bouyer /*
212 1.3.2.2 bouyer * Get the current size of the root table and add the default
213 1.3.2.2 bouyer * increment to create the new table size.
214 1.3.2.2 bouyer */
215 1.3.2.2 bouyer CurrentSize = (ACPI_SIZE)
216 1.3.2.2 bouyer AcpiGbl_RootTableList.CurrentTableCount * sizeof (ACPI_TABLE_DESC);
217 1.3.2.2 bouyer
218 1.3.2.2 bouyer NewSize = CurrentSize +
219 1.3.2.2 bouyer (ACPI_ROOT_TABLE_SIZE_INCREMENT * sizeof (ACPI_TABLE_DESC));
220 1.3.2.2 bouyer
221 1.3.2.2 bouyer /* Create new array and copy the old array */
222 1.3.2.2 bouyer
223 1.3.2.2 bouyer Tables = ACPI_ALLOCATE_ZEROED (NewSize);
224 1.3.2.2 bouyer if (!Tables)
225 1.3.2.2 bouyer {
226 1.3.2.2 bouyer return_ACPI_STATUS (AE_NO_MEMORY);
227 1.3.2.2 bouyer }
228 1.3.2.2 bouyer
229 1.3.2.2 bouyer ACPI_MEMCPY (Tables, AcpiGbl_RootTableList.Tables, CurrentSize);
230 1.3.2.2 bouyer
231 1.3.2.2 bouyer /*
232 1.3.2.2 bouyer * Update the root table descriptor. The new size will be the current
233 1.3.2.2 bouyer * number of tables plus the increment, independent of the reserved
234 1.3.2.2 bouyer * size of the original table list.
235 1.3.2.2 bouyer */
236 1.3.2.2 bouyer AcpiGbl_RootTableList.Tables = Tables;
237 1.3.2.2 bouyer AcpiGbl_RootTableList.MaxTableCount =
238 1.3.2.2 bouyer AcpiGbl_RootTableList.CurrentTableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT;
239 1.3.2.2 bouyer AcpiGbl_RootTableList.Flags =
240 1.3.2.2 bouyer ACPI_ROOT_ORIGIN_ALLOCATED | ACPI_ROOT_ALLOW_RESIZE;
241 1.3.2.2 bouyer
242 1.3.2.2 bouyer return_ACPI_STATUS (AE_OK);
243 1.3.2.2 bouyer }
244 1.3.2.2 bouyer
245 1.3.2.2 bouyer ACPI_EXPORT_SYMBOL (AcpiReallocateRootTable)
246 1.3.2.2 bouyer
247 1.3.2.2 bouyer
248 1.3.2.2 bouyer /*******************************************************************************
249 1.3.2.2 bouyer *
250 1.3.2.2 bouyer * FUNCTION: AcpiGetTableHeader
251 1.3.2.2 bouyer *
252 1.3.2.2 bouyer * PARAMETERS: Signature - ACPI signature of needed table
253 1.3.2.2 bouyer * Instance - Which instance (for SSDTs)
254 1.3.2.2 bouyer * OutTableHeader - The pointer to the table header to fill
255 1.3.2.2 bouyer *
256 1.3.2.2 bouyer * RETURN: Status and pointer to mapped table header
257 1.3.2.2 bouyer *
258 1.3.2.2 bouyer * DESCRIPTION: Finds an ACPI table header.
259 1.3.2.2 bouyer *
260 1.3.2.2 bouyer * NOTE: Caller is responsible in unmapping the header with
261 1.3.2.2 bouyer * AcpiOsUnmapMemory
262 1.3.2.2 bouyer *
263 1.3.2.2 bouyer ******************************************************************************/
264 1.3.2.2 bouyer
265 1.3.2.2 bouyer ACPI_STATUS
266 1.3.2.2 bouyer AcpiGetTableHeader (
267 1.3.2.2 bouyer ACPI_CONST_STRING Signature,
268 1.3.2.2 bouyer UINT32 Instance,
269 1.3.2.2 bouyer ACPI_TABLE_HEADER *OutTableHeader)
270 1.3.2.2 bouyer {
271 1.3.2.2 bouyer UINT32 i;
272 1.3.2.2 bouyer UINT32 j;
273 1.3.2.2 bouyer ACPI_TABLE_HEADER *Header;
274 1.3.2.2 bouyer ACPI_STRING USignature = __UNCONST(Signature);
275 1.3.2.2 bouyer
276 1.3.2.2 bouyer /* Parameter validation */
277 1.3.2.2 bouyer
278 1.3.2.2 bouyer if (!Signature || !OutTableHeader)
279 1.3.2.2 bouyer {
280 1.3.2.2 bouyer return (AE_BAD_PARAMETER);
281 1.3.2.2 bouyer }
282 1.3.2.2 bouyer
283 1.3.2.2 bouyer /* Walk the root table list */
284 1.3.2.2 bouyer
285 1.3.2.2 bouyer for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
286 1.3.2.2 bouyer {
287 1.3.2.2 bouyer if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
288 1.3.2.2 bouyer USignature))
289 1.3.2.2 bouyer {
290 1.3.2.2 bouyer continue;
291 1.3.2.2 bouyer }
292 1.3.2.2 bouyer
293 1.3.2.2 bouyer if (++j < Instance)
294 1.3.2.2 bouyer {
295 1.3.2.2 bouyer continue;
296 1.3.2.2 bouyer }
297 1.3.2.2 bouyer
298 1.3.2.2 bouyer if (!AcpiGbl_RootTableList.Tables[i].Pointer)
299 1.3.2.2 bouyer {
300 1.3.2.2 bouyer if ((AcpiGbl_RootTableList.Tables[i].Flags &
301 1.3.2.2 bouyer ACPI_TABLE_ORIGIN_MASK) ==
302 1.3.2.2 bouyer ACPI_TABLE_ORIGIN_MAPPED)
303 1.3.2.2 bouyer {
304 1.3.2.2 bouyer Header = AcpiOsMapMemory (
305 1.3.2.2 bouyer AcpiGbl_RootTableList.Tables[i].Address,
306 1.3.2.2 bouyer sizeof (ACPI_TABLE_HEADER));
307 1.3.2.2 bouyer if (!Header)
308 1.3.2.2 bouyer {
309 1.3.2.2 bouyer return AE_NO_MEMORY;
310 1.3.2.2 bouyer }
311 1.3.2.2 bouyer
312 1.3.2.2 bouyer ACPI_MEMCPY (OutTableHeader, Header, sizeof(ACPI_TABLE_HEADER));
313 1.3.2.2 bouyer AcpiOsUnmapMemory (Header, sizeof(ACPI_TABLE_HEADER));
314 1.3.2.2 bouyer }
315 1.3.2.2 bouyer else
316 1.3.2.2 bouyer {
317 1.3.2.2 bouyer return AE_NOT_FOUND;
318 1.3.2.2 bouyer }
319 1.3.2.2 bouyer }
320 1.3.2.2 bouyer else
321 1.3.2.2 bouyer {
322 1.3.2.2 bouyer ACPI_MEMCPY (OutTableHeader,
323 1.3.2.2 bouyer AcpiGbl_RootTableList.Tables[i].Pointer,
324 1.3.2.2 bouyer sizeof(ACPI_TABLE_HEADER));
325 1.3.2.2 bouyer }
326 1.3.2.2 bouyer
327 1.3.2.2 bouyer return (AE_OK);
328 1.3.2.2 bouyer }
329 1.3.2.2 bouyer
330 1.3.2.2 bouyer return (AE_NOT_FOUND);
331 1.3.2.2 bouyer }
332 1.3.2.2 bouyer
333 1.3.2.2 bouyer ACPI_EXPORT_SYMBOL (AcpiGetTableHeader)
334 1.3.2.2 bouyer
335 1.3.2.2 bouyer
336 1.3.2.2 bouyer /*******************************************************************************
337 1.3.2.2 bouyer *
338 1.3.2.2 bouyer * FUNCTION: AcpiGetTable
339 1.3.2.2 bouyer *
340 1.3.2.2 bouyer * PARAMETERS: Signature - ACPI signature of needed table
341 1.3.2.2 bouyer * Instance - Which instance (for SSDTs)
342 1.3.2.2 bouyer * OutTable - Where the pointer to the table is returned
343 1.3.2.2 bouyer *
344 1.3.2.2 bouyer * RETURN: Status and pointer to table
345 1.3.2.2 bouyer *
346 1.3.2.2 bouyer * DESCRIPTION: Finds and verifies an ACPI table.
347 1.3.2.2 bouyer *
348 1.3.2.2 bouyer ******************************************************************************/
349 1.3.2.2 bouyer
350 1.3.2.2 bouyer ACPI_STATUS
351 1.3.2.2 bouyer AcpiGetTable (
352 1.3.2.2 bouyer ACPI_CONST_STRING Signature,
353 1.3.2.2 bouyer UINT32 Instance,
354 1.3.2.2 bouyer ACPI_TABLE_HEADER **OutTable)
355 1.3.2.2 bouyer {
356 1.3.2.2 bouyer UINT32 i;
357 1.3.2.2 bouyer UINT32 j;
358 1.3.2.2 bouyer ACPI_STATUS Status;
359 1.3.2.2 bouyer ACPI_STRING USignature = __UNCONST(Signature);
360 1.3.2.2 bouyer
361 1.3.2.2 bouyer /* Parameter validation */
362 1.3.2.2 bouyer
363 1.3.2.2 bouyer if (!Signature || !OutTable)
364 1.3.2.2 bouyer {
365 1.3.2.2 bouyer return (AE_BAD_PARAMETER);
366 1.3.2.2 bouyer }
367 1.3.2.2 bouyer
368 1.3.2.2 bouyer /* Walk the root table list */
369 1.3.2.2 bouyer
370 1.3.2.2 bouyer for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
371 1.3.2.2 bouyer {
372 1.3.2.2 bouyer if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
373 1.3.2.2 bouyer USignature))
374 1.3.2.2 bouyer {
375 1.3.2.2 bouyer continue;
376 1.3.2.2 bouyer }
377 1.3.2.2 bouyer
378 1.3.2.2 bouyer if (++j < Instance)
379 1.3.2.2 bouyer {
380 1.3.2.2 bouyer continue;
381 1.3.2.2 bouyer }
382 1.3.2.2 bouyer
383 1.3.2.2 bouyer Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[i]);
384 1.3.2.2 bouyer if (ACPI_SUCCESS (Status))
385 1.3.2.2 bouyer {
386 1.3.2.2 bouyer *OutTable = AcpiGbl_RootTableList.Tables[i].Pointer;
387 1.3.2.2 bouyer }
388 1.3.2.2 bouyer
389 1.3.2.2 bouyer return (Status);
390 1.3.2.2 bouyer }
391 1.3.2.2 bouyer
392 1.3.2.2 bouyer return (AE_NOT_FOUND);
393 1.3.2.2 bouyer }
394 1.3.2.2 bouyer
395 1.3.2.2 bouyer ACPI_EXPORT_SYMBOL (AcpiGetTable)
396 1.3.2.2 bouyer
397 1.3.2.2 bouyer
398 1.3.2.2 bouyer /*******************************************************************************
399 1.3.2.2 bouyer *
400 1.3.2.2 bouyer * FUNCTION: AcpiGetTableByIndex
401 1.3.2.2 bouyer *
402 1.3.2.2 bouyer * PARAMETERS: TableIndex - Table index
403 1.3.2.2 bouyer * Table - Where the pointer to the table is returned
404 1.3.2.2 bouyer *
405 1.3.2.2 bouyer * RETURN: Status and pointer to the table
406 1.3.2.2 bouyer *
407 1.3.2.2 bouyer * DESCRIPTION: Obtain a table by an index into the global table list.
408 1.3.2.2 bouyer *
409 1.3.2.2 bouyer ******************************************************************************/
410 1.3.2.2 bouyer
411 1.3.2.2 bouyer ACPI_STATUS
412 1.3.2.2 bouyer AcpiGetTableByIndex (
413 1.3.2.2 bouyer UINT32 TableIndex,
414 1.3.2.2 bouyer ACPI_TABLE_HEADER **Table)
415 1.3.2.2 bouyer {
416 1.3.2.2 bouyer ACPI_STATUS Status;
417 1.3.2.2 bouyer
418 1.3.2.2 bouyer
419 1.3.2.2 bouyer ACPI_FUNCTION_TRACE (AcpiGetTableByIndex);
420 1.3.2.2 bouyer
421 1.3.2.2 bouyer
422 1.3.2.2 bouyer /* Parameter validation */
423 1.3.2.2 bouyer
424 1.3.2.2 bouyer if (!Table)
425 1.3.2.2 bouyer {
426 1.3.2.2 bouyer return_ACPI_STATUS (AE_BAD_PARAMETER);
427 1.3.2.2 bouyer }
428 1.3.2.2 bouyer
429 1.3.2.2 bouyer (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
430 1.3.2.2 bouyer
431 1.3.2.2 bouyer /* Validate index */
432 1.3.2.2 bouyer
433 1.3.2.2 bouyer if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
434 1.3.2.2 bouyer {
435 1.3.2.2 bouyer (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
436 1.3.2.2 bouyer return_ACPI_STATUS (AE_BAD_PARAMETER);
437 1.3.2.2 bouyer }
438 1.3.2.2 bouyer
439 1.3.2.2 bouyer if (!AcpiGbl_RootTableList.Tables[TableIndex].Pointer)
440 1.3.2.2 bouyer {
441 1.3.2.2 bouyer /* Table is not mapped, map it */
442 1.3.2.2 bouyer
443 1.3.2.2 bouyer Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[TableIndex]);
444 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
445 1.3.2.2 bouyer {
446 1.3.2.2 bouyer (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
447 1.3.2.2 bouyer return_ACPI_STATUS (Status);
448 1.3.2.2 bouyer }
449 1.3.2.2 bouyer }
450 1.3.2.2 bouyer
451 1.3.2.2 bouyer *Table = AcpiGbl_RootTableList.Tables[TableIndex].Pointer;
452 1.3.2.2 bouyer (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
453 1.3.2.2 bouyer return_ACPI_STATUS (AE_OK);
454 1.3.2.2 bouyer }
455 1.3.2.2 bouyer
456 1.3.2.2 bouyer ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex)
457 1.3.2.2 bouyer
458 1.3.2.2 bouyer
459 1.3.2.2 bouyer /*******************************************************************************
460 1.3.2.2 bouyer *
461 1.3.2.2 bouyer * FUNCTION: AcpiTbLoadNamespace
462 1.3.2.2 bouyer *
463 1.3.2.2 bouyer * PARAMETERS: None
464 1.3.2.2 bouyer *
465 1.3.2.2 bouyer * RETURN: Status
466 1.3.2.2 bouyer *
467 1.3.2.2 bouyer * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
468 1.3.2.2 bouyer * the RSDT/XSDT.
469 1.3.2.2 bouyer *
470 1.3.2.2 bouyer ******************************************************************************/
471 1.3.2.2 bouyer
472 1.3.2.2 bouyer static ACPI_STATUS
473 1.3.2.2 bouyer AcpiTbLoadNamespace (
474 1.3.2.2 bouyer void)
475 1.3.2.2 bouyer {
476 1.3.2.2 bouyer ACPI_STATUS Status;
477 1.3.2.2 bouyer UINT32 i;
478 1.3.2.2 bouyer ACPI_TABLE_HEADER *NewDsdt;
479 1.3.2.2 bouyer
480 1.3.2.2 bouyer
481 1.3.2.2 bouyer ACPI_FUNCTION_TRACE (TbLoadNamespace);
482 1.3.2.2 bouyer
483 1.3.2.2 bouyer
484 1.3.2.2 bouyer (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
485 1.3.2.2 bouyer
486 1.3.2.2 bouyer /*
487 1.3.2.2 bouyer * Load the namespace. The DSDT is required, but any SSDT and
488 1.3.2.2 bouyer * PSDT tables are optional. Verify the DSDT.
489 1.3.2.2 bouyer */
490 1.3.2.2 bouyer if (!AcpiGbl_RootTableList.CurrentTableCount ||
491 1.3.2.2 bouyer !ACPI_COMPARE_NAME (
492 1.3.2.2 bouyer &(AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Signature),
493 1.3.2.2 bouyer ACPI_SIG_DSDT) ||
494 1.3.2.2 bouyer ACPI_FAILURE (AcpiTbVerifyTable (
495 1.3.2.2 bouyer &AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT])))
496 1.3.2.2 bouyer {
497 1.3.2.2 bouyer Status = AE_NO_ACPI_TABLES;
498 1.3.2.2 bouyer goto UnlockAndExit;
499 1.3.2.2 bouyer }
500 1.3.2.2 bouyer
501 1.3.2.2 bouyer /*
502 1.3.2.2 bouyer * Save the DSDT pointer for simple access. This is the mapped memory
503 1.3.2.2 bouyer * address. We must take care here because the address of the .Tables
504 1.3.2.2 bouyer * array can change dynamically as tables are loaded at run-time. Note:
505 1.3.2.2 bouyer * .Pointer field is not validated until after call to AcpiTbVerifyTable.
506 1.3.2.2 bouyer */
507 1.3.2.2 bouyer AcpiGbl_DSDT = AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Pointer;
508 1.3.2.2 bouyer
509 1.3.2.2 bouyer /*
510 1.3.2.2 bouyer * Optionally copy the entire DSDT to local memory (instead of simply
511 1.3.2.2 bouyer * mapping it.) There are some BIOSs that corrupt or replace the original
512 1.3.2.2 bouyer * DSDT, creating the need for this option. Default is FALSE, do not copy
513 1.3.2.2 bouyer * the DSDT.
514 1.3.2.2 bouyer */
515 1.3.2.2 bouyer if (AcpiGbl_CopyDsdtLocally)
516 1.3.2.2 bouyer {
517 1.3.2.2 bouyer NewDsdt = AcpiTbCopyDsdt (ACPI_TABLE_INDEX_DSDT);
518 1.3.2.2 bouyer if (NewDsdt)
519 1.3.2.2 bouyer {
520 1.3.2.2 bouyer AcpiGbl_DSDT = NewDsdt;
521 1.3.2.2 bouyer }
522 1.3.2.2 bouyer }
523 1.3.2.2 bouyer
524 1.3.2.2 bouyer /*
525 1.3.2.2 bouyer * Save the original DSDT header for detection of table corruption
526 1.3.2.2 bouyer * and/or replacement of the DSDT from outside the OS.
527 1.3.2.2 bouyer */
528 1.3.2.2 bouyer ACPI_MEMCPY (&AcpiGbl_OriginalDsdtHeader, AcpiGbl_DSDT,
529 1.3.2.2 bouyer sizeof (ACPI_TABLE_HEADER));
530 1.3.2.2 bouyer
531 1.3.2.2 bouyer (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
532 1.3.2.2 bouyer
533 1.3.2.2 bouyer /* Load and parse tables */
534 1.3.2.2 bouyer
535 1.3.2.2 bouyer Status = AcpiNsLoadTable (ACPI_TABLE_INDEX_DSDT, AcpiGbl_RootNode);
536 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
537 1.3.2.2 bouyer {
538 1.3.2.2 bouyer return_ACPI_STATUS (Status);
539 1.3.2.2 bouyer }
540 1.3.2.2 bouyer
541 1.3.2.2 bouyer /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
542 1.3.2.2 bouyer
543 1.3.2.2 bouyer (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
544 1.3.2.2 bouyer for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
545 1.3.2.2 bouyer {
546 1.3.2.2 bouyer if ((!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
547 1.3.2.2 bouyer ACPI_SIG_SSDT) &&
548 1.3.2.2 bouyer !ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
549 1.3.2.2 bouyer ACPI_SIG_PSDT)) ||
550 1.3.2.2 bouyer ACPI_FAILURE (AcpiTbVerifyTable (
551 1.3.2.2 bouyer &AcpiGbl_RootTableList.Tables[i])))
552 1.3.2.2 bouyer {
553 1.3.2.2 bouyer continue;
554 1.3.2.2 bouyer }
555 1.3.2.2 bouyer
556 1.3.2.2 bouyer /* Ignore errors while loading tables, get as many as possible */
557 1.3.2.2 bouyer
558 1.3.2.2 bouyer (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
559 1.3.2.2 bouyer (void) AcpiNsLoadTable (i, AcpiGbl_RootNode);
560 1.3.2.2 bouyer (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
561 1.3.2.2 bouyer }
562 1.3.2.2 bouyer
563 1.3.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
564 1.3.2.2 bouyer
565 1.3.2.2 bouyer UnlockAndExit:
566 1.3.2.2 bouyer (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
567 1.3.2.2 bouyer return_ACPI_STATUS (Status);
568 1.3.2.2 bouyer }
569 1.3.2.2 bouyer
570 1.3.2.2 bouyer
571 1.3.2.2 bouyer /*******************************************************************************
572 1.3.2.2 bouyer *
573 1.3.2.2 bouyer * FUNCTION: AcpiLoadTables
574 1.3.2.2 bouyer *
575 1.3.2.2 bouyer * PARAMETERS: None
576 1.3.2.2 bouyer *
577 1.3.2.2 bouyer * RETURN: Status
578 1.3.2.2 bouyer *
579 1.3.2.2 bouyer * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
580 1.3.2.2 bouyer *
581 1.3.2.2 bouyer ******************************************************************************/
582 1.3.2.2 bouyer
583 1.3.2.2 bouyer ACPI_STATUS
584 1.3.2.2 bouyer AcpiLoadTables (
585 1.3.2.2 bouyer void)
586 1.3.2.2 bouyer {
587 1.3.2.2 bouyer ACPI_STATUS Status;
588 1.3.2.2 bouyer
589 1.3.2.2 bouyer
590 1.3.2.2 bouyer ACPI_FUNCTION_TRACE (AcpiLoadTables);
591 1.3.2.2 bouyer
592 1.3.2.2 bouyer
593 1.3.2.2 bouyer /* Load the namespace from the tables */
594 1.3.2.2 bouyer
595 1.3.2.2 bouyer Status = AcpiTbLoadNamespace ();
596 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
597 1.3.2.2 bouyer {
598 1.3.2.2 bouyer ACPI_EXCEPTION ((AE_INFO, Status,
599 1.3.2.2 bouyer "While loading namespace from ACPI tables"));
600 1.3.2.2 bouyer }
601 1.3.2.2 bouyer
602 1.3.2.2 bouyer return_ACPI_STATUS (Status);
603 1.3.2.2 bouyer }
604 1.3.2.2 bouyer
605 1.3.2.2 bouyer ACPI_EXPORT_SYMBOL (AcpiLoadTables)
606 1.3.2.2 bouyer
607 1.3.2.2 bouyer
608 1.3.2.2 bouyer /*******************************************************************************
609 1.3.2.2 bouyer *
610 1.3.2.2 bouyer * FUNCTION: AcpiInstallTableHandler
611 1.3.2.2 bouyer *
612 1.3.2.2 bouyer * PARAMETERS: Handler - Table event handler
613 1.3.2.2 bouyer * Context - Value passed to the handler on each event
614 1.3.2.2 bouyer *
615 1.3.2.2 bouyer * RETURN: Status
616 1.3.2.2 bouyer *
617 1.3.2.2 bouyer * DESCRIPTION: Install table event handler
618 1.3.2.2 bouyer *
619 1.3.2.2 bouyer ******************************************************************************/
620 1.3.2.2 bouyer
621 1.3.2.2 bouyer ACPI_STATUS
622 1.3.2.2 bouyer AcpiInstallTableHandler (
623 1.3.2.2 bouyer ACPI_TABLE_HANDLER Handler,
624 1.3.2.2 bouyer void *Context)
625 1.3.2.2 bouyer {
626 1.3.2.2 bouyer ACPI_STATUS Status;
627 1.3.2.2 bouyer
628 1.3.2.2 bouyer
629 1.3.2.2 bouyer ACPI_FUNCTION_TRACE (AcpiInstallTableHandler);
630 1.3.2.2 bouyer
631 1.3.2.2 bouyer
632 1.3.2.2 bouyer if (!Handler)
633 1.3.2.2 bouyer {
634 1.3.2.2 bouyer return_ACPI_STATUS (AE_BAD_PARAMETER);
635 1.3.2.2 bouyer }
636 1.3.2.2 bouyer
637 1.3.2.2 bouyer Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
638 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
639 1.3.2.2 bouyer {
640 1.3.2.2 bouyer return_ACPI_STATUS (Status);
641 1.3.2.2 bouyer }
642 1.3.2.2 bouyer
643 1.3.2.2 bouyer /* Don't allow more than one handler */
644 1.3.2.2 bouyer
645 1.3.2.2 bouyer if (AcpiGbl_TableHandler)
646 1.3.2.2 bouyer {
647 1.3.2.2 bouyer Status = AE_ALREADY_EXISTS;
648 1.3.2.2 bouyer goto Cleanup;
649 1.3.2.2 bouyer }
650 1.3.2.2 bouyer
651 1.3.2.2 bouyer /* Install the handler */
652 1.3.2.2 bouyer
653 1.3.2.2 bouyer AcpiGbl_TableHandler = Handler;
654 1.3.2.2 bouyer AcpiGbl_TableHandlerContext = Context;
655 1.3.2.2 bouyer
656 1.3.2.2 bouyer Cleanup:
657 1.3.2.2 bouyer (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
658 1.3.2.2 bouyer return_ACPI_STATUS (Status);
659 1.3.2.2 bouyer }
660 1.3.2.2 bouyer
661 1.3.2.2 bouyer ACPI_EXPORT_SYMBOL (AcpiInstallTableHandler)
662 1.3.2.2 bouyer
663 1.3.2.2 bouyer
664 1.3.2.2 bouyer /*******************************************************************************
665 1.3.2.2 bouyer *
666 1.3.2.2 bouyer * FUNCTION: AcpiRemoveTableHandler
667 1.3.2.2 bouyer *
668 1.3.2.2 bouyer * PARAMETERS: Handler - Table event handler that was installed
669 1.3.2.2 bouyer * previously.
670 1.3.2.2 bouyer *
671 1.3.2.2 bouyer * RETURN: Status
672 1.3.2.2 bouyer *
673 1.3.2.2 bouyer * DESCRIPTION: Remove table event handler
674 1.3.2.2 bouyer *
675 1.3.2.2 bouyer ******************************************************************************/
676 1.3.2.2 bouyer
677 1.3.2.2 bouyer ACPI_STATUS
678 1.3.2.2 bouyer AcpiRemoveTableHandler (
679 1.3.2.2 bouyer ACPI_TABLE_HANDLER Handler)
680 1.3.2.2 bouyer {
681 1.3.2.2 bouyer ACPI_STATUS Status;
682 1.3.2.2 bouyer
683 1.3.2.2 bouyer
684 1.3.2.2 bouyer ACPI_FUNCTION_TRACE (AcpiRemoveTableHandler);
685 1.3.2.2 bouyer
686 1.3.2.2 bouyer
687 1.3.2.2 bouyer Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
688 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
689 1.3.2.2 bouyer {
690 1.3.2.2 bouyer return_ACPI_STATUS (Status);
691 1.3.2.2 bouyer }
692 1.3.2.2 bouyer
693 1.3.2.2 bouyer /* Make sure that the installed handler is the same */
694 1.3.2.2 bouyer
695 1.3.2.2 bouyer if (!Handler ||
696 1.3.2.2 bouyer Handler != AcpiGbl_TableHandler)
697 1.3.2.2 bouyer {
698 1.3.2.2 bouyer Status = AE_BAD_PARAMETER;
699 1.3.2.2 bouyer goto Cleanup;
700 1.3.2.2 bouyer }
701 1.3.2.2 bouyer
702 1.3.2.2 bouyer /* Remove the handler */
703 1.3.2.2 bouyer
704 1.3.2.2 bouyer AcpiGbl_TableHandler = NULL;
705 1.3.2.2 bouyer
706 1.3.2.2 bouyer Cleanup:
707 1.3.2.2 bouyer (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
708 1.3.2.2 bouyer return_ACPI_STATUS (Status);
709 1.3.2.2 bouyer }
710 1.3.2.2 bouyer
711 1.3.2.2 bouyer ACPI_EXPORT_SYMBOL (AcpiRemoveTableHandler)
712 1.3.2.2 bouyer
713