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