tbdata.c revision 1.13 1 1.1 christos /******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: tbdata - Table manager data structure functions
4 1.1 christos *
5 1.1 christos *****************************************************************************/
6 1.1 christos
7 1.1 christos /*
8 1.12 christos * Copyright (C) 2000 - 2019, Intel Corp.
9 1.1 christos * All rights reserved.
10 1.1 christos *
11 1.1 christos * Redistribution and use in source and binary forms, with or without
12 1.1 christos * modification, are permitted provided that the following conditions
13 1.1 christos * are met:
14 1.1 christos * 1. Redistributions of source code must retain the above copyright
15 1.1 christos * notice, this list of conditions, and the following disclaimer,
16 1.1 christos * without modification.
17 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1 christos * including a substantially similar Disclaimer requirement for further
21 1.1 christos * binary redistribution.
22 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1 christos * of any contributors may be used to endorse or promote products derived
24 1.1 christos * from this software without specific prior written permission.
25 1.1 christos *
26 1.1 christos * Alternatively, this software may be distributed under the terms of the
27 1.1 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1 christos * Software Foundation.
29 1.1 christos *
30 1.1 christos * NO WARRANTY
31 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.1 christos */
43 1.1 christos
44 1.1 christos #include "acpi.h"
45 1.1 christos #include "accommon.h"
46 1.1 christos #include "acnamesp.h"
47 1.1 christos #include "actables.h"
48 1.7 christos #include "acevents.h"
49 1.1 christos
50 1.1 christos #define _COMPONENT ACPI_TABLES
51 1.1 christos ACPI_MODULE_NAME ("tbdata")
52 1.1 christos
53 1.9 christos /* Local prototypes */
54 1.9 christos
55 1.9 christos static ACPI_STATUS
56 1.9 christos AcpiTbCheckDuplication (
57 1.9 christos ACPI_TABLE_DESC *TableDesc,
58 1.9 christos UINT32 *TableIndex);
59 1.9 christos
60 1.9 christos static BOOLEAN
61 1.9 christos AcpiTbCompareTables (
62 1.9 christos ACPI_TABLE_DESC *TableDesc,
63 1.9 christos UINT32 TableIndex);
64 1.9 christos
65 1.9 christos
66 1.9 christos /*******************************************************************************
67 1.9 christos *
68 1.9 christos * FUNCTION: AcpiTbCompareTables
69 1.9 christos *
70 1.9 christos * PARAMETERS: TableDesc - Table 1 descriptor to be compared
71 1.9 christos * TableIndex - Index of table 2 to be compared
72 1.9 christos *
73 1.9 christos * RETURN: TRUE if both tables are identical.
74 1.9 christos *
75 1.9 christos * DESCRIPTION: This function compares a table with another table that has
76 1.9 christos * already been installed in the root table list.
77 1.9 christos *
78 1.9 christos ******************************************************************************/
79 1.9 christos
80 1.9 christos static BOOLEAN
81 1.9 christos AcpiTbCompareTables (
82 1.9 christos ACPI_TABLE_DESC *TableDesc,
83 1.9 christos UINT32 TableIndex)
84 1.9 christos {
85 1.9 christos ACPI_STATUS Status = AE_OK;
86 1.9 christos BOOLEAN IsIdentical;
87 1.9 christos ACPI_TABLE_HEADER *Table;
88 1.9 christos UINT32 TableLength;
89 1.9 christos UINT8 TableFlags;
90 1.9 christos
91 1.9 christos
92 1.9 christos Status = AcpiTbAcquireTable (&AcpiGbl_RootTableList.Tables[TableIndex],
93 1.9 christos &Table, &TableLength, &TableFlags);
94 1.9 christos if (ACPI_FAILURE (Status))
95 1.9 christos {
96 1.9 christos return (FALSE);
97 1.9 christos }
98 1.9 christos
99 1.9 christos /*
100 1.9 christos * Check for a table match on the entire table length,
101 1.9 christos * not just the header.
102 1.9 christos */
103 1.9 christos IsIdentical = (BOOLEAN)((TableDesc->Length != TableLength ||
104 1.9 christos memcmp (TableDesc->Pointer, Table, TableLength)) ?
105 1.9 christos FALSE : TRUE);
106 1.9 christos
107 1.9 christos /* Release the acquired table */
108 1.9 christos
109 1.9 christos AcpiTbReleaseTable (Table, TableLength, TableFlags);
110 1.9 christos return (IsIdentical);
111 1.9 christos }
112 1.9 christos
113 1.1 christos
114 1.1 christos /*******************************************************************************
115 1.1 christos *
116 1.1 christos * FUNCTION: AcpiTbInitTableDescriptor
117 1.1 christos *
118 1.1 christos * PARAMETERS: TableDesc - Table descriptor
119 1.1 christos * Address - Physical address of the table
120 1.1 christos * Flags - Allocation flags of the table
121 1.1 christos * Table - Pointer to the table
122 1.1 christos *
123 1.1 christos * RETURN: None
124 1.1 christos *
125 1.1 christos * DESCRIPTION: Initialize a new table descriptor
126 1.1 christos *
127 1.1 christos ******************************************************************************/
128 1.1 christos
129 1.1 christos void
130 1.1 christos AcpiTbInitTableDescriptor (
131 1.1 christos ACPI_TABLE_DESC *TableDesc,
132 1.1 christos ACPI_PHYSICAL_ADDRESS Address,
133 1.1 christos UINT8 Flags,
134 1.1 christos ACPI_TABLE_HEADER *Table)
135 1.1 christos {
136 1.1 christos
137 1.1 christos /*
138 1.1 christos * Initialize the table descriptor. Set the pointer to NULL, since the
139 1.1 christos * table is not fully mapped at this time.
140 1.1 christos */
141 1.4 christos memset (TableDesc, 0, sizeof (ACPI_TABLE_DESC));
142 1.1 christos TableDesc->Address = Address;
143 1.1 christos TableDesc->Length = Table->Length;
144 1.1 christos TableDesc->Flags = Flags;
145 1.1 christos ACPI_MOVE_32_TO_32 (TableDesc->Signature.Ascii, Table->Signature);
146 1.1 christos }
147 1.1 christos
148 1.1 christos
149 1.1 christos /*******************************************************************************
150 1.1 christos *
151 1.1 christos * FUNCTION: AcpiTbAcquireTable
152 1.1 christos *
153 1.1 christos * PARAMETERS: TableDesc - Table descriptor
154 1.1 christos * TablePtr - Where table is returned
155 1.1 christos * TableLength - Where table length is returned
156 1.1 christos * TableFlags - Where table allocation flags are returned
157 1.1 christos *
158 1.1 christos * RETURN: Status
159 1.1 christos *
160 1.1 christos * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
161 1.1 christos * maintained in the AcpiGbl_RootTableList.
162 1.1 christos *
163 1.1 christos ******************************************************************************/
164 1.1 christos
165 1.1 christos ACPI_STATUS
166 1.1 christos AcpiTbAcquireTable (
167 1.1 christos ACPI_TABLE_DESC *TableDesc,
168 1.1 christos ACPI_TABLE_HEADER **TablePtr,
169 1.1 christos UINT32 *TableLength,
170 1.1 christos UINT8 *TableFlags)
171 1.1 christos {
172 1.1 christos ACPI_TABLE_HEADER *Table = NULL;
173 1.1 christos
174 1.1 christos
175 1.1 christos switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)
176 1.1 christos {
177 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
178 1.1 christos
179 1.1 christos Table = AcpiOsMapMemory (TableDesc->Address, TableDesc->Length);
180 1.1 christos break;
181 1.1 christos
182 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
183 1.1 christos case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
184 1.1 christos
185 1.3 christos Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
186 1.5 christos ACPI_PHYSADDR_TO_PTR (TableDesc->Address));
187 1.1 christos break;
188 1.1 christos
189 1.1 christos default:
190 1.1 christos
191 1.1 christos break;
192 1.1 christos }
193 1.1 christos
194 1.1 christos /* Table is not valid yet */
195 1.1 christos
196 1.1 christos if (!Table)
197 1.1 christos {
198 1.1 christos return (AE_NO_MEMORY);
199 1.1 christos }
200 1.1 christos
201 1.1 christos /* Fill the return values */
202 1.1 christos
203 1.1 christos *TablePtr = Table;
204 1.1 christos *TableLength = TableDesc->Length;
205 1.1 christos *TableFlags = TableDesc->Flags;
206 1.1 christos return (AE_OK);
207 1.1 christos }
208 1.1 christos
209 1.1 christos
210 1.1 christos /*******************************************************************************
211 1.1 christos *
212 1.1 christos * FUNCTION: AcpiTbReleaseTable
213 1.1 christos *
214 1.1 christos * PARAMETERS: Table - Pointer for the table
215 1.1 christos * TableLength - Length for the table
216 1.1 christos * TableFlags - Allocation flags for the table
217 1.1 christos *
218 1.1 christos * RETURN: None
219 1.1 christos *
220 1.1 christos * DESCRIPTION: Release a table. The inverse of AcpiTbAcquireTable().
221 1.1 christos *
222 1.1 christos ******************************************************************************/
223 1.1 christos
224 1.1 christos void
225 1.1 christos AcpiTbReleaseTable (
226 1.1 christos ACPI_TABLE_HEADER *Table,
227 1.1 christos UINT32 TableLength,
228 1.1 christos UINT8 TableFlags)
229 1.1 christos {
230 1.1 christos
231 1.1 christos switch (TableFlags & ACPI_TABLE_ORIGIN_MASK)
232 1.1 christos {
233 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
234 1.1 christos
235 1.1 christos AcpiOsUnmapMemory (Table, TableLength);
236 1.1 christos break;
237 1.1 christos
238 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
239 1.1 christos case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
240 1.1 christos default:
241 1.1 christos
242 1.1 christos break;
243 1.1 christos }
244 1.1 christos }
245 1.1 christos
246 1.1 christos
247 1.1 christos /*******************************************************************************
248 1.1 christos *
249 1.1 christos * FUNCTION: AcpiTbAcquireTempTable
250 1.1 christos *
251 1.1 christos * PARAMETERS: TableDesc - Table descriptor to be acquired
252 1.1 christos * Address - Address of the table
253 1.1 christos * Flags - Allocation flags of the table
254 1.1 christos *
255 1.1 christos * RETURN: Status
256 1.1 christos *
257 1.1 christos * DESCRIPTION: This function validates the table header to obtain the length
258 1.1 christos * of a table and fills the table descriptor to make its state as
259 1.1 christos * "INSTALLED". Such a table descriptor is only used for verified
260 1.1 christos * installation.
261 1.1 christos *
262 1.1 christos ******************************************************************************/
263 1.1 christos
264 1.1 christos ACPI_STATUS
265 1.1 christos AcpiTbAcquireTempTable (
266 1.1 christos ACPI_TABLE_DESC *TableDesc,
267 1.1 christos ACPI_PHYSICAL_ADDRESS Address,
268 1.1 christos UINT8 Flags)
269 1.1 christos {
270 1.1 christos ACPI_TABLE_HEADER *TableHeader;
271 1.1 christos
272 1.1 christos
273 1.1 christos switch (Flags & ACPI_TABLE_ORIGIN_MASK)
274 1.1 christos {
275 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
276 1.1 christos
277 1.1 christos /* Get the length of the full table from the header */
278 1.1 christos
279 1.1 christos TableHeader = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
280 1.1 christos if (!TableHeader)
281 1.1 christos {
282 1.1 christos return (AE_NO_MEMORY);
283 1.1 christos }
284 1.1 christos
285 1.1 christos AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
286 1.1 christos AcpiOsUnmapMemory (TableHeader, sizeof (ACPI_TABLE_HEADER));
287 1.1 christos return (AE_OK);
288 1.1 christos
289 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
290 1.1 christos case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
291 1.1 christos
292 1.3 christos TableHeader = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
293 1.5 christos ACPI_PHYSADDR_TO_PTR (Address));
294 1.1 christos if (!TableHeader)
295 1.1 christos {
296 1.1 christos return (AE_NO_MEMORY);
297 1.1 christos }
298 1.1 christos
299 1.1 christos AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
300 1.1 christos return (AE_OK);
301 1.1 christos
302 1.1 christos default:
303 1.1 christos
304 1.1 christos break;
305 1.1 christos }
306 1.1 christos
307 1.1 christos /* Table is not valid yet */
308 1.1 christos
309 1.1 christos return (AE_NO_MEMORY);
310 1.1 christos }
311 1.1 christos
312 1.1 christos
313 1.1 christos /*******************************************************************************
314 1.1 christos *
315 1.1 christos * FUNCTION: AcpiTbReleaseTempTable
316 1.1 christos *
317 1.1 christos * PARAMETERS: TableDesc - Table descriptor to be released
318 1.1 christos *
319 1.1 christos * RETURN: Status
320 1.1 christos *
321 1.1 christos * DESCRIPTION: The inverse of AcpiTbAcquireTempTable().
322 1.1 christos *
323 1.1 christos *****************************************************************************/
324 1.1 christos
325 1.1 christos void
326 1.1 christos AcpiTbReleaseTempTable (
327 1.1 christos ACPI_TABLE_DESC *TableDesc)
328 1.1 christos {
329 1.1 christos
330 1.1 christos /*
331 1.1 christos * Note that the .Address is maintained by the callers of
332 1.1 christos * AcpiTbAcquireTempTable(), thus do not invoke AcpiTbUninstallTable()
333 1.1 christos * where .Address will be freed.
334 1.1 christos */
335 1.1 christos AcpiTbInvalidateTable (TableDesc);
336 1.1 christos }
337 1.1 christos
338 1.1 christos
339 1.1 christos /******************************************************************************
340 1.1 christos *
341 1.1 christos * FUNCTION: AcpiTbValidateTable
342 1.1 christos *
343 1.1 christos * PARAMETERS: TableDesc - Table descriptor
344 1.1 christos *
345 1.1 christos * RETURN: Status
346 1.1 christos *
347 1.1 christos * DESCRIPTION: This function is called to validate the table, the returned
348 1.1 christos * table descriptor is in "VALIDATED" state.
349 1.1 christos *
350 1.1 christos *****************************************************************************/
351 1.1 christos
352 1.1 christos ACPI_STATUS
353 1.1 christos AcpiTbValidateTable (
354 1.1 christos ACPI_TABLE_DESC *TableDesc)
355 1.1 christos {
356 1.1 christos ACPI_STATUS Status = AE_OK;
357 1.1 christos
358 1.1 christos
359 1.1 christos ACPI_FUNCTION_TRACE (TbValidateTable);
360 1.1 christos
361 1.1 christos
362 1.1 christos /* Validate the table if necessary */
363 1.1 christos
364 1.1 christos if (!TableDesc->Pointer)
365 1.1 christos {
366 1.1 christos Status = AcpiTbAcquireTable (TableDesc, &TableDesc->Pointer,
367 1.5 christos &TableDesc->Length, &TableDesc->Flags);
368 1.1 christos if (!TableDesc->Pointer)
369 1.1 christos {
370 1.1 christos Status = AE_NO_MEMORY;
371 1.1 christos }
372 1.1 christos }
373 1.1 christos
374 1.1 christos return_ACPI_STATUS (Status);
375 1.1 christos }
376 1.1 christos
377 1.1 christos
378 1.1 christos /*******************************************************************************
379 1.1 christos *
380 1.1 christos * FUNCTION: AcpiTbInvalidateTable
381 1.1 christos *
382 1.1 christos * PARAMETERS: TableDesc - Table descriptor
383 1.1 christos *
384 1.1 christos * RETURN: None
385 1.1 christos *
386 1.1 christos * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
387 1.1 christos * AcpiTbValidateTable().
388 1.1 christos *
389 1.1 christos ******************************************************************************/
390 1.1 christos
391 1.1 christos void
392 1.1 christos AcpiTbInvalidateTable (
393 1.1 christos ACPI_TABLE_DESC *TableDesc)
394 1.1 christos {
395 1.1 christos
396 1.1 christos ACPI_FUNCTION_TRACE (TbInvalidateTable);
397 1.1 christos
398 1.1 christos
399 1.1 christos /* Table must be validated */
400 1.1 christos
401 1.1 christos if (!TableDesc->Pointer)
402 1.1 christos {
403 1.1 christos return_VOID;
404 1.1 christos }
405 1.1 christos
406 1.1 christos AcpiTbReleaseTable (TableDesc->Pointer, TableDesc->Length,
407 1.1 christos TableDesc->Flags);
408 1.1 christos TableDesc->Pointer = NULL;
409 1.1 christos
410 1.1 christos return_VOID;
411 1.1 christos }
412 1.1 christos
413 1.1 christos
414 1.1 christos /******************************************************************************
415 1.1 christos *
416 1.1 christos * FUNCTION: AcpiTbValidateTempTable
417 1.1 christos *
418 1.1 christos * PARAMETERS: TableDesc - Table descriptor
419 1.1 christos *
420 1.1 christos * RETURN: Status
421 1.1 christos *
422 1.1 christos * DESCRIPTION: This function is called to validate the table, the returned
423 1.1 christos * table descriptor is in "VALIDATED" state.
424 1.1 christos *
425 1.1 christos *****************************************************************************/
426 1.1 christos
427 1.1 christos ACPI_STATUS
428 1.1 christos AcpiTbValidateTempTable (
429 1.1 christos ACPI_TABLE_DESC *TableDesc)
430 1.1 christos {
431 1.1 christos
432 1.9 christos if (!TableDesc->Pointer && !AcpiGbl_EnableTableValidation)
433 1.1 christos {
434 1.1 christos /*
435 1.1 christos * Only validates the header of the table.
436 1.1 christos * Note that Length contains the size of the mapping after invoking
437 1.1 christos * this work around, this value is required by
438 1.1 christos * AcpiTbReleaseTempTable().
439 1.1 christos * We can do this because in AcpiInitTableDescriptor(), the Length
440 1.1 christos * field of the installed descriptor is filled with the actual
441 1.1 christos * table length obtaining from the table header.
442 1.1 christos */
443 1.1 christos TableDesc->Length = sizeof (ACPI_TABLE_HEADER);
444 1.1 christos }
445 1.1 christos
446 1.1 christos return (AcpiTbValidateTable (TableDesc));
447 1.1 christos }
448 1.1 christos
449 1.1 christos
450 1.9 christos /*******************************************************************************
451 1.9 christos *
452 1.9 christos * FUNCTION: AcpiTbCheckDuplication
453 1.9 christos *
454 1.9 christos * PARAMETERS: TableDesc - Table descriptor
455 1.9 christos * TableIndex - Where the table index is returned
456 1.9 christos *
457 1.9 christos * RETURN: Status
458 1.9 christos *
459 1.9 christos * DESCRIPTION: Avoid installing duplicated tables. However table override and
460 1.9 christos * user aided dynamic table load is allowed, thus comparing the
461 1.9 christos * address of the table is not sufficient, and checking the entire
462 1.9 christos * table content is required.
463 1.9 christos *
464 1.9 christos ******************************************************************************/
465 1.9 christos
466 1.9 christos static ACPI_STATUS
467 1.9 christos AcpiTbCheckDuplication (
468 1.9 christos ACPI_TABLE_DESC *TableDesc,
469 1.9 christos UINT32 *TableIndex)
470 1.9 christos {
471 1.9 christos UINT32 i;
472 1.9 christos
473 1.9 christos
474 1.9 christos ACPI_FUNCTION_TRACE (TbCheckDuplication);
475 1.9 christos
476 1.9 christos
477 1.9 christos /* Check if table is already registered */
478 1.9 christos
479 1.9 christos for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
480 1.9 christos {
481 1.9 christos /* Do not compare with unverified tables */
482 1.9 christos
483 1.9 christos if (!(AcpiGbl_RootTableList.Tables[i].Flags & ACPI_TABLE_IS_VERIFIED))
484 1.9 christos {
485 1.9 christos continue;
486 1.9 christos }
487 1.9 christos
488 1.9 christos /*
489 1.9 christos * Check for a table match on the entire table length,
490 1.9 christos * not just the header.
491 1.9 christos */
492 1.9 christos if (!AcpiTbCompareTables (TableDesc, i))
493 1.9 christos {
494 1.9 christos continue;
495 1.9 christos }
496 1.9 christos
497 1.9 christos /*
498 1.9 christos * Note: the current mechanism does not unregister a table if it is
499 1.9 christos * dynamically unloaded. The related namespace entries are deleted,
500 1.9 christos * but the table remains in the root table list.
501 1.9 christos *
502 1.9 christos * The assumption here is that the number of different tables that
503 1.9 christos * will be loaded is actually small, and there is minimal overhead
504 1.9 christos * in just keeping the table in case it is needed again.
505 1.9 christos *
506 1.9 christos * If this assumption changes in the future (perhaps on large
507 1.9 christos * machines with many table load/unload operations), tables will
508 1.9 christos * need to be unregistered when they are unloaded, and slots in the
509 1.9 christos * root table list should be reused when empty.
510 1.9 christos */
511 1.9 christos if (AcpiGbl_RootTableList.Tables[i].Flags &
512 1.9 christos ACPI_TABLE_IS_LOADED)
513 1.9 christos {
514 1.9 christos /* Table is still loaded, this is an error */
515 1.9 christos
516 1.9 christos return_ACPI_STATUS (AE_ALREADY_EXISTS);
517 1.9 christos }
518 1.9 christos else
519 1.9 christos {
520 1.9 christos *TableIndex = i;
521 1.9 christos return_ACPI_STATUS (AE_CTRL_TERMINATE);
522 1.9 christos }
523 1.9 christos }
524 1.9 christos
525 1.9 christos /* Indicate no duplication to the caller */
526 1.9 christos
527 1.9 christos return_ACPI_STATUS (AE_OK);
528 1.9 christos }
529 1.9 christos
530 1.9 christos
531 1.1 christos /******************************************************************************
532 1.1 christos *
533 1.1 christos * FUNCTION: AcpiTbVerifyTempTable
534 1.1 christos *
535 1.1 christos * PARAMETERS: TableDesc - Table descriptor
536 1.1 christos * Signature - Table signature to verify
537 1.9 christos * TableIndex - Where the table index is returned
538 1.1 christos *
539 1.1 christos * RETURN: Status
540 1.1 christos *
541 1.1 christos * DESCRIPTION: This function is called to validate and verify the table, the
542 1.1 christos * returned table descriptor is in "VALIDATED" state.
543 1.9 christos * Note that 'TableIndex' is required to be set to !NULL to
544 1.9 christos * enable duplication check.
545 1.1 christos *
546 1.1 christos *****************************************************************************/
547 1.1 christos
548 1.1 christos ACPI_STATUS
549 1.1 christos AcpiTbVerifyTempTable (
550 1.1 christos ACPI_TABLE_DESC *TableDesc,
551 1.9 christos const char *Signature,
552 1.9 christos UINT32 *TableIndex)
553 1.1 christos {
554 1.1 christos ACPI_STATUS Status = AE_OK;
555 1.1 christos
556 1.1 christos
557 1.1 christos ACPI_FUNCTION_TRACE (TbVerifyTempTable);
558 1.1 christos
559 1.1 christos
560 1.1 christos /* Validate the table */
561 1.1 christos
562 1.1 christos Status = AcpiTbValidateTempTable (TableDesc);
563 1.1 christos if (ACPI_FAILURE (Status))
564 1.1 christos {
565 1.1 christos return_ACPI_STATUS (AE_NO_MEMORY);
566 1.1 christos }
567 1.1 christos
568 1.1 christos /* If a particular signature is expected (DSDT/FACS), it must match */
569 1.1 christos
570 1.1 christos if (Signature &&
571 1.12 christos !ACPI_COMPARE_NAMESEG (&TableDesc->Signature, Signature))
572 1.1 christos {
573 1.1 christos ACPI_BIOS_ERROR ((AE_INFO,
574 1.1 christos "Invalid signature 0x%X for ACPI table, expected [%s]",
575 1.1 christos TableDesc->Signature.Integer, Signature));
576 1.1 christos Status = AE_BAD_SIGNATURE;
577 1.1 christos goto InvalidateAndExit;
578 1.1 christos }
579 1.1 christos
580 1.9 christos if (AcpiGbl_EnableTableValidation)
581 1.9 christos {
582 1.9 christos /* Verify the checksum */
583 1.1 christos
584 1.1 christos Status = AcpiTbVerifyChecksum (TableDesc->Pointer, TableDesc->Length);
585 1.1 christos if (ACPI_FAILURE (Status))
586 1.1 christos {
587 1.1 christos ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY,
588 1.3 christos "%4.4s 0x%8.8X%8.8X"
589 1.1 christos " Attempted table install failed",
590 1.6 christos AcpiUtValidNameseg (TableDesc->Signature.Ascii) ?
591 1.1 christos TableDesc->Signature.Ascii : "????",
592 1.3 christos ACPI_FORMAT_UINT64 (TableDesc->Address)));
593 1.5 christos
594 1.1 christos goto InvalidateAndExit;
595 1.1 christos }
596 1.9 christos
597 1.9 christos /* Avoid duplications */
598 1.9 christos
599 1.9 christos if (TableIndex)
600 1.9 christos {
601 1.9 christos Status = AcpiTbCheckDuplication (TableDesc, TableIndex);
602 1.9 christos if (ACPI_FAILURE (Status))
603 1.9 christos {
604 1.9 christos if (Status != AE_CTRL_TERMINATE)
605 1.9 christos {
606 1.11 christos ACPI_EXCEPTION ((AE_INFO, Status,
607 1.9 christos "%4.4s 0x%8.8X%8.8X"
608 1.11 christos " Table is already loaded",
609 1.9 christos AcpiUtValidNameseg (TableDesc->Signature.Ascii) ?
610 1.9 christos TableDesc->Signature.Ascii : "????",
611 1.9 christos ACPI_FORMAT_UINT64 (TableDesc->Address)));
612 1.9 christos }
613 1.9 christos
614 1.9 christos goto InvalidateAndExit;
615 1.9 christos }
616 1.9 christos }
617 1.9 christos
618 1.9 christos TableDesc->Flags |= ACPI_TABLE_IS_VERIFIED;
619 1.1 christos }
620 1.1 christos
621 1.9 christos return_ACPI_STATUS (Status);
622 1.1 christos
623 1.1 christos InvalidateAndExit:
624 1.1 christos AcpiTbInvalidateTable (TableDesc);
625 1.1 christos return_ACPI_STATUS (Status);
626 1.1 christos }
627 1.1 christos
628 1.1 christos
629 1.1 christos /*******************************************************************************
630 1.1 christos *
631 1.1 christos * FUNCTION: AcpiTbResizeRootTableList
632 1.1 christos *
633 1.1 christos * PARAMETERS: None
634 1.1 christos *
635 1.1 christos * RETURN: Status
636 1.1 christos *
637 1.1 christos * DESCRIPTION: Expand the size of global table array
638 1.1 christos *
639 1.1 christos ******************************************************************************/
640 1.1 christos
641 1.1 christos ACPI_STATUS
642 1.1 christos AcpiTbResizeRootTableList (
643 1.1 christos void)
644 1.1 christos {
645 1.1 christos ACPI_TABLE_DESC *Tables;
646 1.1 christos UINT32 TableCount;
647 1.9 christos UINT32 CurrentTableCount, MaxTableCount;
648 1.9 christos UINT32 i;
649 1.1 christos
650 1.1 christos
651 1.1 christos ACPI_FUNCTION_TRACE (TbResizeRootTableList);
652 1.1 christos
653 1.1 christos
654 1.1 christos /* AllowResize flag is a parameter to AcpiInitializeTables */
655 1.1 christos
656 1.1 christos if (!(AcpiGbl_RootTableList.Flags & ACPI_ROOT_ALLOW_RESIZE))
657 1.1 christos {
658 1.1 christos ACPI_ERROR ((AE_INFO, "Resize of Root Table Array is not allowed"));
659 1.1 christos return_ACPI_STATUS (AE_SUPPORT);
660 1.1 christos }
661 1.1 christos
662 1.1 christos /* Increase the Table Array size */
663 1.1 christos
664 1.1 christos if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
665 1.1 christos {
666 1.1 christos TableCount = AcpiGbl_RootTableList.MaxTableCount;
667 1.1 christos }
668 1.1 christos else
669 1.1 christos {
670 1.1 christos TableCount = AcpiGbl_RootTableList.CurrentTableCount;
671 1.1 christos }
672 1.1 christos
673 1.9 christos MaxTableCount = TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT;
674 1.1 christos Tables = ACPI_ALLOCATE_ZEROED (
675 1.9 christos ((ACPI_SIZE) MaxTableCount) * sizeof (ACPI_TABLE_DESC));
676 1.1 christos if (!Tables)
677 1.1 christos {
678 1.1 christos ACPI_ERROR ((AE_INFO, "Could not allocate new root table array"));
679 1.1 christos return_ACPI_STATUS (AE_NO_MEMORY);
680 1.1 christos }
681 1.1 christos
682 1.1 christos /* Copy and free the previous table array */
683 1.1 christos
684 1.9 christos CurrentTableCount = 0;
685 1.1 christos if (AcpiGbl_RootTableList.Tables)
686 1.1 christos {
687 1.9 christos for (i = 0; i < TableCount; i++)
688 1.9 christos {
689 1.9 christos if (AcpiGbl_RootTableList.Tables[i].Address)
690 1.9 christos {
691 1.9 christos memcpy (Tables + CurrentTableCount,
692 1.9 christos AcpiGbl_RootTableList.Tables + i,
693 1.9 christos sizeof (ACPI_TABLE_DESC));
694 1.9 christos CurrentTableCount++;
695 1.9 christos }
696 1.9 christos }
697 1.1 christos
698 1.1 christos if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
699 1.1 christos {
700 1.1 christos ACPI_FREE (AcpiGbl_RootTableList.Tables);
701 1.1 christos }
702 1.1 christos }
703 1.1 christos
704 1.1 christos AcpiGbl_RootTableList.Tables = Tables;
705 1.9 christos AcpiGbl_RootTableList.MaxTableCount = MaxTableCount;
706 1.9 christos AcpiGbl_RootTableList.CurrentTableCount = CurrentTableCount;
707 1.1 christos AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
708 1.1 christos
709 1.1 christos return_ACPI_STATUS (AE_OK);
710 1.1 christos }
711 1.1 christos
712 1.1 christos
713 1.1 christos /*******************************************************************************
714 1.1 christos *
715 1.3 christos * FUNCTION: AcpiTbGetNextTableDescriptor
716 1.1 christos *
717 1.1 christos * PARAMETERS: TableIndex - Where table index is returned
718 1.3 christos * TableDesc - Where table descriptor is returned
719 1.1 christos *
720 1.3 christos * RETURN: Status and table index/descriptor.
721 1.1 christos *
722 1.1 christos * DESCRIPTION: Allocate a new ACPI table entry to the global table list
723 1.1 christos *
724 1.1 christos ******************************************************************************/
725 1.1 christos
726 1.1 christos ACPI_STATUS
727 1.3 christos AcpiTbGetNextTableDescriptor (
728 1.3 christos UINT32 *TableIndex,
729 1.3 christos ACPI_TABLE_DESC **TableDesc)
730 1.1 christos {
731 1.1 christos ACPI_STATUS Status;
732 1.3 christos UINT32 i;
733 1.1 christos
734 1.1 christos
735 1.1 christos /* Ensure that there is room for the table in the Root Table List */
736 1.1 christos
737 1.1 christos if (AcpiGbl_RootTableList.CurrentTableCount >=
738 1.1 christos AcpiGbl_RootTableList.MaxTableCount)
739 1.1 christos {
740 1.1 christos Status = AcpiTbResizeRootTableList();
741 1.1 christos if (ACPI_FAILURE (Status))
742 1.1 christos {
743 1.1 christos return (Status);
744 1.1 christos }
745 1.1 christos }
746 1.1 christos
747 1.3 christos i = AcpiGbl_RootTableList.CurrentTableCount;
748 1.1 christos AcpiGbl_RootTableList.CurrentTableCount++;
749 1.3 christos
750 1.3 christos if (TableIndex)
751 1.3 christos {
752 1.3 christos *TableIndex = i;
753 1.3 christos }
754 1.3 christos if (TableDesc)
755 1.3 christos {
756 1.3 christos *TableDesc = &AcpiGbl_RootTableList.Tables[i];
757 1.3 christos }
758 1.3 christos
759 1.1 christos return (AE_OK);
760 1.1 christos }
761 1.1 christos
762 1.1 christos
763 1.1 christos /*******************************************************************************
764 1.1 christos *
765 1.1 christos * FUNCTION: AcpiTbTerminate
766 1.1 christos *
767 1.1 christos * PARAMETERS: None
768 1.1 christos *
769 1.1 christos * RETURN: None
770 1.1 christos *
771 1.1 christos * DESCRIPTION: Delete all internal ACPI tables
772 1.1 christos *
773 1.1 christos ******************************************************************************/
774 1.1 christos
775 1.1 christos void
776 1.1 christos AcpiTbTerminate (
777 1.1 christos void)
778 1.1 christos {
779 1.1 christos UINT32 i;
780 1.1 christos
781 1.1 christos
782 1.1 christos ACPI_FUNCTION_TRACE (TbTerminate);
783 1.1 christos
784 1.1 christos
785 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
786 1.1 christos
787 1.1 christos /* Delete the individual tables */
788 1.1 christos
789 1.1 christos for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
790 1.1 christos {
791 1.1 christos AcpiTbUninstallTable (&AcpiGbl_RootTableList.Tables[i]);
792 1.1 christos }
793 1.1 christos
794 1.1 christos /*
795 1.1 christos * Delete the root table array if allocated locally. Array cannot be
796 1.1 christos * mapped, so we don't need to check for that flag.
797 1.1 christos */
798 1.1 christos if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
799 1.1 christos {
800 1.1 christos ACPI_FREE (AcpiGbl_RootTableList.Tables);
801 1.1 christos }
802 1.1 christos
803 1.1 christos AcpiGbl_RootTableList.Tables = NULL;
804 1.1 christos AcpiGbl_RootTableList.Flags = 0;
805 1.1 christos AcpiGbl_RootTableList.CurrentTableCount = 0;
806 1.1 christos
807 1.1 christos ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
808 1.1 christos
809 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
810 1.1 christos return_VOID;
811 1.1 christos }
812 1.1 christos
813 1.1 christos
814 1.1 christos /*******************************************************************************
815 1.1 christos *
816 1.1 christos * FUNCTION: AcpiTbDeleteNamespaceByOwner
817 1.1 christos *
818 1.1 christos * PARAMETERS: TableIndex - Table index
819 1.1 christos *
820 1.1 christos * RETURN: Status
821 1.1 christos *
822 1.1 christos * DESCRIPTION: Delete all namespace objects created when this table was loaded.
823 1.1 christos *
824 1.1 christos ******************************************************************************/
825 1.1 christos
826 1.1 christos ACPI_STATUS
827 1.1 christos AcpiTbDeleteNamespaceByOwner (
828 1.1 christos UINT32 TableIndex)
829 1.1 christos {
830 1.1 christos ACPI_OWNER_ID OwnerId;
831 1.1 christos ACPI_STATUS Status;
832 1.1 christos
833 1.1 christos
834 1.1 christos ACPI_FUNCTION_TRACE (TbDeleteNamespaceByOwner);
835 1.1 christos
836 1.1 christos
837 1.1 christos Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES);
838 1.1 christos if (ACPI_FAILURE (Status))
839 1.1 christos {
840 1.1 christos return_ACPI_STATUS (Status);
841 1.1 christos }
842 1.1 christos
843 1.1 christos if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
844 1.1 christos {
845 1.1 christos /* The table index does not exist */
846 1.1 christos
847 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
848 1.1 christos return_ACPI_STATUS (AE_NOT_EXIST);
849 1.1 christos }
850 1.1 christos
851 1.1 christos /* Get the owner ID for this table, used to delete namespace nodes */
852 1.1 christos
853 1.1 christos OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
854 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
855 1.1 christos
856 1.1 christos /*
857 1.1 christos * Need to acquire the namespace writer lock to prevent interference
858 1.1 christos * with any concurrent namespace walks. The interpreter must be
859 1.1 christos * released during the deletion since the acquisition of the deletion
860 1.1 christos * lock may block, and also since the execution of a namespace walk
861 1.1 christos * must be allowed to use the interpreter.
862 1.1 christos */
863 1.1 christos Status = AcpiUtAcquireWriteLock (&AcpiGbl_NamespaceRwLock);
864 1.1 christos if (ACPI_FAILURE (Status))
865 1.1 christos {
866 1.1 christos return_ACPI_STATUS (Status);
867 1.1 christos }
868 1.13 christos
869 1.7 christos AcpiNsDeleteNamespaceByOwner (OwnerId);
870 1.1 christos AcpiUtReleaseWriteLock (&AcpiGbl_NamespaceRwLock);
871 1.1 christos return_ACPI_STATUS (Status);
872 1.1 christos }
873 1.1 christos
874 1.1 christos
875 1.1 christos /*******************************************************************************
876 1.1 christos *
877 1.1 christos * FUNCTION: AcpiTbAllocateOwnerId
878 1.1 christos *
879 1.1 christos * PARAMETERS: TableIndex - Table index
880 1.1 christos *
881 1.1 christos * RETURN: Status
882 1.1 christos *
883 1.1 christos * DESCRIPTION: Allocates OwnerId in TableDesc
884 1.1 christos *
885 1.1 christos ******************************************************************************/
886 1.1 christos
887 1.1 christos ACPI_STATUS
888 1.1 christos AcpiTbAllocateOwnerId (
889 1.1 christos UINT32 TableIndex)
890 1.1 christos {
891 1.1 christos ACPI_STATUS Status = AE_BAD_PARAMETER;
892 1.1 christos
893 1.1 christos
894 1.1 christos ACPI_FUNCTION_TRACE (TbAllocateOwnerId);
895 1.1 christos
896 1.1 christos
897 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
898 1.1 christos if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
899 1.1 christos {
900 1.1 christos Status = AcpiUtAllocateOwnerId (
901 1.5 christos &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
902 1.1 christos }
903 1.1 christos
904 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
905 1.1 christos return_ACPI_STATUS (Status);
906 1.1 christos }
907 1.1 christos
908 1.1 christos
909 1.1 christos /*******************************************************************************
910 1.1 christos *
911 1.1 christos * FUNCTION: AcpiTbReleaseOwnerId
912 1.1 christos *
913 1.1 christos * PARAMETERS: TableIndex - Table index
914 1.1 christos *
915 1.1 christos * RETURN: Status
916 1.1 christos *
917 1.1 christos * DESCRIPTION: Releases OwnerId in TableDesc
918 1.1 christos *
919 1.1 christos ******************************************************************************/
920 1.1 christos
921 1.1 christos ACPI_STATUS
922 1.1 christos AcpiTbReleaseOwnerId (
923 1.1 christos UINT32 TableIndex)
924 1.1 christos {
925 1.1 christos ACPI_STATUS Status = AE_BAD_PARAMETER;
926 1.1 christos
927 1.1 christos
928 1.1 christos ACPI_FUNCTION_TRACE (TbReleaseOwnerId);
929 1.1 christos
930 1.1 christos
931 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
932 1.1 christos if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
933 1.1 christos {
934 1.1 christos AcpiUtReleaseOwnerId (
935 1.1 christos &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
936 1.1 christos Status = AE_OK;
937 1.1 christos }
938 1.1 christos
939 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
940 1.1 christos return_ACPI_STATUS (Status);
941 1.1 christos }
942 1.1 christos
943 1.1 christos
944 1.1 christos /*******************************************************************************
945 1.1 christos *
946 1.1 christos * FUNCTION: AcpiTbGetOwnerId
947 1.1 christos *
948 1.1 christos * PARAMETERS: TableIndex - Table index
949 1.1 christos * OwnerId - Where the table OwnerId is returned
950 1.1 christos *
951 1.1 christos * RETURN: Status
952 1.1 christos *
953 1.1 christos * DESCRIPTION: returns OwnerId for the ACPI table
954 1.1 christos *
955 1.1 christos ******************************************************************************/
956 1.1 christos
957 1.1 christos ACPI_STATUS
958 1.1 christos AcpiTbGetOwnerId (
959 1.1 christos UINT32 TableIndex,
960 1.1 christos ACPI_OWNER_ID *OwnerId)
961 1.1 christos {
962 1.1 christos ACPI_STATUS Status = AE_BAD_PARAMETER;
963 1.1 christos
964 1.1 christos
965 1.1 christos ACPI_FUNCTION_TRACE (TbGetOwnerId);
966 1.1 christos
967 1.1 christos
968 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
969 1.1 christos if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
970 1.1 christos {
971 1.1 christos *OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
972 1.1 christos Status = AE_OK;
973 1.1 christos }
974 1.1 christos
975 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
976 1.1 christos return_ACPI_STATUS (Status);
977 1.1 christos }
978 1.1 christos
979 1.1 christos
980 1.1 christos /*******************************************************************************
981 1.1 christos *
982 1.1 christos * FUNCTION: AcpiTbIsTableLoaded
983 1.1 christos *
984 1.1 christos * PARAMETERS: TableIndex - Index into the root table
985 1.1 christos *
986 1.1 christos * RETURN: Table Loaded Flag
987 1.1 christos *
988 1.1 christos ******************************************************************************/
989 1.1 christos
990 1.1 christos BOOLEAN
991 1.1 christos AcpiTbIsTableLoaded (
992 1.1 christos UINT32 TableIndex)
993 1.1 christos {
994 1.1 christos BOOLEAN IsLoaded = FALSE;
995 1.1 christos
996 1.1 christos
997 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
998 1.1 christos if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
999 1.1 christos {
1000 1.1 christos IsLoaded = (BOOLEAN)
1001 1.1 christos (AcpiGbl_RootTableList.Tables[TableIndex].Flags &
1002 1.1 christos ACPI_TABLE_IS_LOADED);
1003 1.1 christos }
1004 1.1 christos
1005 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1006 1.1 christos return (IsLoaded);
1007 1.1 christos }
1008 1.1 christos
1009 1.1 christos
1010 1.1 christos /*******************************************************************************
1011 1.1 christos *
1012 1.1 christos * FUNCTION: AcpiTbSetTableLoadedFlag
1013 1.1 christos *
1014 1.1 christos * PARAMETERS: TableIndex - Table index
1015 1.1 christos * IsLoaded - TRUE if table is loaded, FALSE otherwise
1016 1.1 christos *
1017 1.1 christos * RETURN: None
1018 1.1 christos *
1019 1.1 christos * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
1020 1.1 christos *
1021 1.1 christos ******************************************************************************/
1022 1.1 christos
1023 1.1 christos void
1024 1.1 christos AcpiTbSetTableLoadedFlag (
1025 1.1 christos UINT32 TableIndex,
1026 1.1 christos BOOLEAN IsLoaded)
1027 1.1 christos {
1028 1.1 christos
1029 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
1030 1.1 christos if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
1031 1.1 christos {
1032 1.1 christos if (IsLoaded)
1033 1.1 christos {
1034 1.1 christos AcpiGbl_RootTableList.Tables[TableIndex].Flags |=
1035 1.1 christos ACPI_TABLE_IS_LOADED;
1036 1.1 christos }
1037 1.1 christos else
1038 1.1 christos {
1039 1.1 christos AcpiGbl_RootTableList.Tables[TableIndex].Flags &=
1040 1.1 christos ~ACPI_TABLE_IS_LOADED;
1041 1.1 christos }
1042 1.1 christos }
1043 1.1 christos
1044 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
1045 1.1 christos }
1046 1.7 christos
1047 1.7 christos
1048 1.7 christos /*******************************************************************************
1049 1.7 christos *
1050 1.7 christos * FUNCTION: AcpiTbLoadTable
1051 1.7 christos *
1052 1.7 christos * PARAMETERS: TableIndex - Table index
1053 1.7 christos * ParentNode - Where table index is returned
1054 1.7 christos *
1055 1.7 christos * RETURN: Status
1056 1.7 christos *
1057 1.7 christos * DESCRIPTION: Load an ACPI table
1058 1.7 christos *
1059 1.7 christos ******************************************************************************/
1060 1.7 christos
1061 1.7 christos ACPI_STATUS
1062 1.7 christos AcpiTbLoadTable (
1063 1.7 christos UINT32 TableIndex,
1064 1.7 christos ACPI_NAMESPACE_NODE *ParentNode)
1065 1.7 christos {
1066 1.7 christos ACPI_TABLE_HEADER *Table;
1067 1.7 christos ACPI_STATUS Status;
1068 1.7 christos ACPI_OWNER_ID OwnerId;
1069 1.7 christos
1070 1.7 christos
1071 1.7 christos ACPI_FUNCTION_TRACE (TbLoadTable);
1072 1.7 christos
1073 1.7 christos
1074 1.7 christos /*
1075 1.7 christos * Note: Now table is "INSTALLED", it must be validated before
1076 1.7 christos * using.
1077 1.7 christos */
1078 1.7 christos Status = AcpiGetTableByIndex (TableIndex, &Table);
1079 1.7 christos if (ACPI_FAILURE (Status))
1080 1.7 christos {
1081 1.7 christos return_ACPI_STATUS (Status);
1082 1.7 christos }
1083 1.7 christos
1084 1.7 christos Status = AcpiNsLoadTable (TableIndex, ParentNode);
1085 1.7 christos
1086 1.10 christos /*
1087 1.7 christos * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
1088 1.7 christos * responsible for discovering any new wake GPEs by running _PRW methods
1089 1.7 christos * that may have been loaded by this table.
1090 1.7 christos */
1091 1.7 christos Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
1092 1.7 christos if (ACPI_SUCCESS (Status))
1093 1.7 christos {
1094 1.7 christos AcpiEvUpdateGpes (OwnerId);
1095 1.7 christos }
1096 1.7 christos
1097 1.9 christos /* Invoke table handler */
1098 1.7 christos
1099 1.9 christos AcpiTbNotifyTable (ACPI_TABLE_EVENT_LOAD, Table);
1100 1.7 christos return_ACPI_STATUS (Status);
1101 1.7 christos }
1102 1.7 christos
1103 1.7 christos
1104 1.7 christos /*******************************************************************************
1105 1.7 christos *
1106 1.7 christos * FUNCTION: AcpiTbInstallAndLoadTable
1107 1.7 christos *
1108 1.8 christos * PARAMETERS: Address - Physical address of the table
1109 1.7 christos * Flags - Allocation flags of the table
1110 1.8 christos * Override - Whether override should be performed
1111 1.7 christos * TableIndex - Where table index is returned
1112 1.7 christos *
1113 1.7 christos * RETURN: Status
1114 1.7 christos *
1115 1.7 christos * DESCRIPTION: Install and load an ACPI table
1116 1.7 christos *
1117 1.7 christos ******************************************************************************/
1118 1.7 christos
1119 1.7 christos ACPI_STATUS
1120 1.7 christos AcpiTbInstallAndLoadTable (
1121 1.7 christos ACPI_PHYSICAL_ADDRESS Address,
1122 1.7 christos UINT8 Flags,
1123 1.7 christos BOOLEAN Override,
1124 1.7 christos UINT32 *TableIndex)
1125 1.7 christos {
1126 1.7 christos ACPI_STATUS Status;
1127 1.7 christos UINT32 i;
1128 1.7 christos
1129 1.7 christos
1130 1.8 christos ACPI_FUNCTION_TRACE (TbInstallAndLoadTable);
1131 1.7 christos
1132 1.7 christos
1133 1.7 christos /* Install the table and load it into the namespace */
1134 1.7 christos
1135 1.7 christos Status = AcpiTbInstallStandardTable (Address, Flags, TRUE,
1136 1.7 christos Override, &i);
1137 1.7 christos if (ACPI_FAILURE (Status))
1138 1.7 christos {
1139 1.9 christos goto Exit;
1140 1.7 christos }
1141 1.7 christos
1142 1.8 christos Status = AcpiTbLoadTable (i, AcpiGbl_RootNode);
1143 1.7 christos
1144 1.9 christos Exit:
1145 1.8 christos *TableIndex = i;
1146 1.8 christos return_ACPI_STATUS (Status);
1147 1.8 christos }
1148 1.8 christos
1149 1.8 christos
1150 1.8 christos /*******************************************************************************
1151 1.8 christos *
1152 1.8 christos * FUNCTION: AcpiTbUnloadTable
1153 1.8 christos *
1154 1.8 christos * PARAMETERS: TableIndex - Table index
1155 1.8 christos *
1156 1.8 christos * RETURN: Status
1157 1.8 christos *
1158 1.8 christos * DESCRIPTION: Unload an ACPI table
1159 1.8 christos *
1160 1.8 christos ******************************************************************************/
1161 1.7 christos
1162 1.8 christos ACPI_STATUS
1163 1.8 christos AcpiTbUnloadTable (
1164 1.8 christos UINT32 TableIndex)
1165 1.8 christos {
1166 1.8 christos ACPI_STATUS Status = AE_OK;
1167 1.8 christos ACPI_TABLE_HEADER *Table;
1168 1.8 christos
1169 1.8 christos
1170 1.8 christos ACPI_FUNCTION_TRACE (TbUnloadTable);
1171 1.8 christos
1172 1.8 christos
1173 1.8 christos /* Ensure the table is still loaded */
1174 1.7 christos
1175 1.8 christos if (!AcpiTbIsTableLoaded (TableIndex))
1176 1.7 christos {
1177 1.8 christos return_ACPI_STATUS (AE_NOT_EXIST);
1178 1.7 christos }
1179 1.7 christos
1180 1.9 christos /* Invoke table handler */
1181 1.8 christos
1182 1.9 christos Status = AcpiGetTableByIndex (TableIndex, &Table);
1183 1.9 christos if (ACPI_SUCCESS (Status))
1184 1.7 christos {
1185 1.9 christos AcpiTbNotifyTable (ACPI_TABLE_EVENT_UNLOAD, Table);
1186 1.7 christos }
1187 1.7 christos
1188 1.8 christos /* Delete the portion of the namespace owned by this table */
1189 1.7 christos
1190 1.8 christos Status = AcpiTbDeleteNamespaceByOwner (TableIndex);
1191 1.8 christos if (ACPI_FAILURE (Status))
1192 1.7 christos {
1193 1.8 christos return_ACPI_STATUS (Status);
1194 1.7 christos }
1195 1.7 christos
1196 1.8 christos (void) AcpiTbReleaseOwnerId (TableIndex);
1197 1.8 christos AcpiTbSetTableLoadedFlag (TableIndex, FALSE);
1198 1.7 christos return_ACPI_STATUS (Status);
1199 1.7 christos }
1200 1.9 christos
1201 1.9 christos
1202 1.9 christos /*******************************************************************************
1203 1.9 christos *
1204 1.9 christos * FUNCTION: AcpiTbNotifyTable
1205 1.9 christos *
1206 1.9 christos * PARAMETERS: Event - Table event
1207 1.9 christos * Table - Validated table pointer
1208 1.9 christos *
1209 1.9 christos * RETURN: None
1210 1.9 christos *
1211 1.9 christos * DESCRIPTION: Notify a table event to the users.
1212 1.9 christos *
1213 1.9 christos ******************************************************************************/
1214 1.9 christos
1215 1.9 christos void
1216 1.9 christos AcpiTbNotifyTable (
1217 1.9 christos UINT32 Event,
1218 1.9 christos void *Table)
1219 1.9 christos {
1220 1.9 christos /* Invoke table handler if present */
1221 1.9 christos
1222 1.9 christos if (AcpiGbl_TableHandler)
1223 1.9 christos {
1224 1.9 christos (void) AcpiGbl_TableHandler (Event, Table,
1225 1.9 christos AcpiGbl_TableHandlerContext);
1226 1.9 christos }
1227 1.9 christos }
1228