tbdata.c revision 1.5 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.5 christos * Copyright (C) 2000 - 2016, 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.1 christos
49 1.1 christos #define _COMPONENT ACPI_TABLES
50 1.1 christos ACPI_MODULE_NAME ("tbdata")
51 1.1 christos
52 1.1 christos
53 1.1 christos /*******************************************************************************
54 1.1 christos *
55 1.1 christos * FUNCTION: AcpiTbInitTableDescriptor
56 1.1 christos *
57 1.1 christos * PARAMETERS: TableDesc - Table descriptor
58 1.1 christos * Address - Physical address of the table
59 1.1 christos * Flags - Allocation flags of the table
60 1.1 christos * Table - Pointer to the table
61 1.1 christos *
62 1.1 christos * RETURN: None
63 1.1 christos *
64 1.1 christos * DESCRIPTION: Initialize a new table descriptor
65 1.1 christos *
66 1.1 christos ******************************************************************************/
67 1.1 christos
68 1.1 christos void
69 1.1 christos AcpiTbInitTableDescriptor (
70 1.1 christos ACPI_TABLE_DESC *TableDesc,
71 1.1 christos ACPI_PHYSICAL_ADDRESS Address,
72 1.1 christos UINT8 Flags,
73 1.1 christos ACPI_TABLE_HEADER *Table)
74 1.1 christos {
75 1.1 christos
76 1.1 christos /*
77 1.1 christos * Initialize the table descriptor. Set the pointer to NULL, since the
78 1.1 christos * table is not fully mapped at this time.
79 1.1 christos */
80 1.4 christos memset (TableDesc, 0, sizeof (ACPI_TABLE_DESC));
81 1.1 christos TableDesc->Address = Address;
82 1.1 christos TableDesc->Length = Table->Length;
83 1.1 christos TableDesc->Flags = Flags;
84 1.1 christos ACPI_MOVE_32_TO_32 (TableDesc->Signature.Ascii, Table->Signature);
85 1.1 christos }
86 1.1 christos
87 1.1 christos
88 1.1 christos /*******************************************************************************
89 1.1 christos *
90 1.1 christos * FUNCTION: AcpiTbAcquireTable
91 1.1 christos *
92 1.1 christos * PARAMETERS: TableDesc - Table descriptor
93 1.1 christos * TablePtr - Where table is returned
94 1.1 christos * TableLength - Where table length is returned
95 1.1 christos * TableFlags - Where table allocation flags are returned
96 1.1 christos *
97 1.1 christos * RETURN: Status
98 1.1 christos *
99 1.1 christos * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
100 1.1 christos * maintained in the AcpiGbl_RootTableList.
101 1.1 christos *
102 1.1 christos ******************************************************************************/
103 1.1 christos
104 1.1 christos ACPI_STATUS
105 1.1 christos AcpiTbAcquireTable (
106 1.1 christos ACPI_TABLE_DESC *TableDesc,
107 1.1 christos ACPI_TABLE_HEADER **TablePtr,
108 1.1 christos UINT32 *TableLength,
109 1.1 christos UINT8 *TableFlags)
110 1.1 christos {
111 1.1 christos ACPI_TABLE_HEADER *Table = NULL;
112 1.1 christos
113 1.1 christos
114 1.1 christos switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)
115 1.1 christos {
116 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
117 1.1 christos
118 1.1 christos Table = AcpiOsMapMemory (TableDesc->Address, TableDesc->Length);
119 1.1 christos break;
120 1.1 christos
121 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
122 1.1 christos case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
123 1.1 christos
124 1.3 christos Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
125 1.5 christos ACPI_PHYSADDR_TO_PTR (TableDesc->Address));
126 1.1 christos break;
127 1.1 christos
128 1.1 christos default:
129 1.1 christos
130 1.1 christos break;
131 1.1 christos }
132 1.1 christos
133 1.1 christos /* Table is not valid yet */
134 1.1 christos
135 1.1 christos if (!Table)
136 1.1 christos {
137 1.1 christos return (AE_NO_MEMORY);
138 1.1 christos }
139 1.1 christos
140 1.1 christos /* Fill the return values */
141 1.1 christos
142 1.1 christos *TablePtr = Table;
143 1.1 christos *TableLength = TableDesc->Length;
144 1.1 christos *TableFlags = TableDesc->Flags;
145 1.1 christos return (AE_OK);
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: AcpiTbReleaseTable
152 1.1 christos *
153 1.1 christos * PARAMETERS: Table - Pointer for the table
154 1.1 christos * TableLength - Length for the table
155 1.1 christos * TableFlags - Allocation flags for the table
156 1.1 christos *
157 1.1 christos * RETURN: None
158 1.1 christos *
159 1.1 christos * DESCRIPTION: Release a table. The inverse of AcpiTbAcquireTable().
160 1.1 christos *
161 1.1 christos ******************************************************************************/
162 1.1 christos
163 1.1 christos void
164 1.1 christos AcpiTbReleaseTable (
165 1.1 christos ACPI_TABLE_HEADER *Table,
166 1.1 christos UINT32 TableLength,
167 1.1 christos UINT8 TableFlags)
168 1.1 christos {
169 1.1 christos
170 1.1 christos switch (TableFlags & ACPI_TABLE_ORIGIN_MASK)
171 1.1 christos {
172 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
173 1.1 christos
174 1.1 christos AcpiOsUnmapMemory (Table, TableLength);
175 1.1 christos break;
176 1.1 christos
177 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
178 1.1 christos case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
179 1.1 christos default:
180 1.1 christos
181 1.1 christos break;
182 1.1 christos }
183 1.1 christos }
184 1.1 christos
185 1.1 christos
186 1.1 christos /*******************************************************************************
187 1.1 christos *
188 1.1 christos * FUNCTION: AcpiTbAcquireTempTable
189 1.1 christos *
190 1.1 christos * PARAMETERS: TableDesc - Table descriptor to be acquired
191 1.1 christos * Address - Address of the table
192 1.1 christos * Flags - Allocation flags of the table
193 1.1 christos *
194 1.1 christos * RETURN: Status
195 1.1 christos *
196 1.1 christos * DESCRIPTION: This function validates the table header to obtain the length
197 1.1 christos * of a table and fills the table descriptor to make its state as
198 1.1 christos * "INSTALLED". Such a table descriptor is only used for verified
199 1.1 christos * installation.
200 1.1 christos *
201 1.1 christos ******************************************************************************/
202 1.1 christos
203 1.1 christos ACPI_STATUS
204 1.1 christos AcpiTbAcquireTempTable (
205 1.1 christos ACPI_TABLE_DESC *TableDesc,
206 1.1 christos ACPI_PHYSICAL_ADDRESS Address,
207 1.1 christos UINT8 Flags)
208 1.1 christos {
209 1.1 christos ACPI_TABLE_HEADER *TableHeader;
210 1.1 christos
211 1.1 christos
212 1.1 christos switch (Flags & ACPI_TABLE_ORIGIN_MASK)
213 1.1 christos {
214 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
215 1.1 christos
216 1.1 christos /* Get the length of the full table from the header */
217 1.1 christos
218 1.1 christos TableHeader = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
219 1.1 christos if (!TableHeader)
220 1.1 christos {
221 1.1 christos return (AE_NO_MEMORY);
222 1.1 christos }
223 1.1 christos
224 1.1 christos AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
225 1.1 christos AcpiOsUnmapMemory (TableHeader, sizeof (ACPI_TABLE_HEADER));
226 1.1 christos return (AE_OK);
227 1.1 christos
228 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
229 1.1 christos case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
230 1.1 christos
231 1.3 christos TableHeader = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
232 1.5 christos ACPI_PHYSADDR_TO_PTR (Address));
233 1.1 christos if (!TableHeader)
234 1.1 christos {
235 1.1 christos return (AE_NO_MEMORY);
236 1.1 christos }
237 1.1 christos
238 1.1 christos AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
239 1.1 christos return (AE_OK);
240 1.1 christos
241 1.1 christos default:
242 1.1 christos
243 1.1 christos break;
244 1.1 christos }
245 1.1 christos
246 1.1 christos /* Table is not valid yet */
247 1.1 christos
248 1.1 christos return (AE_NO_MEMORY);
249 1.1 christos }
250 1.1 christos
251 1.1 christos
252 1.1 christos /*******************************************************************************
253 1.1 christos *
254 1.1 christos * FUNCTION: AcpiTbReleaseTempTable
255 1.1 christos *
256 1.1 christos * PARAMETERS: TableDesc - Table descriptor to be released
257 1.1 christos *
258 1.1 christos * RETURN: Status
259 1.1 christos *
260 1.1 christos * DESCRIPTION: The inverse of AcpiTbAcquireTempTable().
261 1.1 christos *
262 1.1 christos *****************************************************************************/
263 1.1 christos
264 1.1 christos void
265 1.1 christos AcpiTbReleaseTempTable (
266 1.1 christos ACPI_TABLE_DESC *TableDesc)
267 1.1 christos {
268 1.1 christos
269 1.1 christos /*
270 1.1 christos * Note that the .Address is maintained by the callers of
271 1.1 christos * AcpiTbAcquireTempTable(), thus do not invoke AcpiTbUninstallTable()
272 1.1 christos * where .Address will be freed.
273 1.1 christos */
274 1.1 christos AcpiTbInvalidateTable (TableDesc);
275 1.1 christos }
276 1.1 christos
277 1.1 christos
278 1.1 christos /******************************************************************************
279 1.1 christos *
280 1.1 christos * FUNCTION: AcpiTbValidateTable
281 1.1 christos *
282 1.1 christos * PARAMETERS: TableDesc - Table descriptor
283 1.1 christos *
284 1.1 christos * RETURN: Status
285 1.1 christos *
286 1.1 christos * DESCRIPTION: This function is called to validate the table, the returned
287 1.1 christos * table descriptor is in "VALIDATED" state.
288 1.1 christos *
289 1.1 christos *****************************************************************************/
290 1.1 christos
291 1.1 christos ACPI_STATUS
292 1.1 christos AcpiTbValidateTable (
293 1.1 christos ACPI_TABLE_DESC *TableDesc)
294 1.1 christos {
295 1.1 christos ACPI_STATUS Status = AE_OK;
296 1.1 christos
297 1.1 christos
298 1.1 christos ACPI_FUNCTION_TRACE (TbValidateTable);
299 1.1 christos
300 1.1 christos
301 1.1 christos /* Validate the table if necessary */
302 1.1 christos
303 1.1 christos if (!TableDesc->Pointer)
304 1.1 christos {
305 1.1 christos Status = AcpiTbAcquireTable (TableDesc, &TableDesc->Pointer,
306 1.5 christos &TableDesc->Length, &TableDesc->Flags);
307 1.1 christos if (!TableDesc->Pointer)
308 1.1 christos {
309 1.1 christos Status = AE_NO_MEMORY;
310 1.1 christos }
311 1.1 christos }
312 1.1 christos
313 1.1 christos return_ACPI_STATUS (Status);
314 1.1 christos }
315 1.1 christos
316 1.1 christos
317 1.1 christos /*******************************************************************************
318 1.1 christos *
319 1.1 christos * FUNCTION: AcpiTbInvalidateTable
320 1.1 christos *
321 1.1 christos * PARAMETERS: TableDesc - Table descriptor
322 1.1 christos *
323 1.1 christos * RETURN: None
324 1.1 christos *
325 1.1 christos * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
326 1.1 christos * AcpiTbValidateTable().
327 1.1 christos *
328 1.1 christos ******************************************************************************/
329 1.1 christos
330 1.1 christos void
331 1.1 christos AcpiTbInvalidateTable (
332 1.1 christos ACPI_TABLE_DESC *TableDesc)
333 1.1 christos {
334 1.1 christos
335 1.1 christos ACPI_FUNCTION_TRACE (TbInvalidateTable);
336 1.1 christos
337 1.1 christos
338 1.1 christos /* Table must be validated */
339 1.1 christos
340 1.1 christos if (!TableDesc->Pointer)
341 1.1 christos {
342 1.1 christos return_VOID;
343 1.1 christos }
344 1.1 christos
345 1.1 christos AcpiTbReleaseTable (TableDesc->Pointer, TableDesc->Length,
346 1.1 christos TableDesc->Flags);
347 1.1 christos TableDesc->Pointer = NULL;
348 1.1 christos
349 1.1 christos return_VOID;
350 1.1 christos }
351 1.1 christos
352 1.1 christos
353 1.1 christos /******************************************************************************
354 1.1 christos *
355 1.1 christos * FUNCTION: AcpiTbValidateTempTable
356 1.1 christos *
357 1.1 christos * PARAMETERS: TableDesc - Table descriptor
358 1.1 christos *
359 1.1 christos * RETURN: Status
360 1.1 christos *
361 1.1 christos * DESCRIPTION: This function is called to validate the table, the returned
362 1.1 christos * table descriptor is in "VALIDATED" state.
363 1.1 christos *
364 1.1 christos *****************************************************************************/
365 1.1 christos
366 1.1 christos ACPI_STATUS
367 1.1 christos AcpiTbValidateTempTable (
368 1.1 christos ACPI_TABLE_DESC *TableDesc)
369 1.1 christos {
370 1.1 christos
371 1.1 christos if (!TableDesc->Pointer && !AcpiGbl_VerifyTableChecksum)
372 1.1 christos {
373 1.1 christos /*
374 1.1 christos * Only validates the header of the table.
375 1.1 christos * Note that Length contains the size of the mapping after invoking
376 1.1 christos * this work around, this value is required by
377 1.1 christos * AcpiTbReleaseTempTable().
378 1.1 christos * We can do this because in AcpiInitTableDescriptor(), the Length
379 1.1 christos * field of the installed descriptor is filled with the actual
380 1.1 christos * table length obtaining from the table header.
381 1.1 christos */
382 1.1 christos TableDesc->Length = sizeof (ACPI_TABLE_HEADER);
383 1.1 christos }
384 1.1 christos
385 1.1 christos return (AcpiTbValidateTable (TableDesc));
386 1.1 christos }
387 1.1 christos
388 1.1 christos
389 1.1 christos /******************************************************************************
390 1.1 christos *
391 1.1 christos * FUNCTION: AcpiTbVerifyTempTable
392 1.1 christos *
393 1.1 christos * PARAMETERS: TableDesc - Table descriptor
394 1.1 christos * Signature - Table signature to verify
395 1.1 christos *
396 1.1 christos * RETURN: Status
397 1.1 christos *
398 1.1 christos * DESCRIPTION: This function is called to validate and verify the table, the
399 1.1 christos * returned table descriptor is in "VALIDATED" state.
400 1.1 christos *
401 1.1 christos *****************************************************************************/
402 1.1 christos
403 1.1 christos ACPI_STATUS
404 1.1 christos AcpiTbVerifyTempTable (
405 1.1 christos ACPI_TABLE_DESC *TableDesc,
406 1.2 christos const char *Signature)
407 1.1 christos {
408 1.1 christos ACPI_STATUS Status = AE_OK;
409 1.1 christos
410 1.1 christos
411 1.1 christos ACPI_FUNCTION_TRACE (TbVerifyTempTable);
412 1.1 christos
413 1.1 christos
414 1.1 christos /* Validate the table */
415 1.1 christos
416 1.1 christos Status = AcpiTbValidateTempTable (TableDesc);
417 1.1 christos if (ACPI_FAILURE (Status))
418 1.1 christos {
419 1.1 christos return_ACPI_STATUS (AE_NO_MEMORY);
420 1.1 christos }
421 1.1 christos
422 1.1 christos /* If a particular signature is expected (DSDT/FACS), it must match */
423 1.1 christos
424 1.1 christos if (Signature &&
425 1.1 christos !ACPI_COMPARE_NAME (&TableDesc->Signature, Signature))
426 1.1 christos {
427 1.1 christos ACPI_BIOS_ERROR ((AE_INFO,
428 1.1 christos "Invalid signature 0x%X for ACPI table, expected [%s]",
429 1.1 christos TableDesc->Signature.Integer, Signature));
430 1.1 christos Status = AE_BAD_SIGNATURE;
431 1.1 christos goto InvalidateAndExit;
432 1.1 christos }
433 1.1 christos
434 1.1 christos /* Verify the checksum */
435 1.1 christos
436 1.1 christos if (AcpiGbl_VerifyTableChecksum)
437 1.1 christos {
438 1.1 christos Status = AcpiTbVerifyChecksum (TableDesc->Pointer, TableDesc->Length);
439 1.1 christos if (ACPI_FAILURE (Status))
440 1.1 christos {
441 1.1 christos ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY,
442 1.3 christos "%4.4s 0x%8.8X%8.8X"
443 1.1 christos " Attempted table install failed",
444 1.1 christos AcpiUtValidAcpiName (TableDesc->Signature.Ascii) ?
445 1.1 christos TableDesc->Signature.Ascii : "????",
446 1.3 christos ACPI_FORMAT_UINT64 (TableDesc->Address)));
447 1.5 christos
448 1.1 christos goto InvalidateAndExit;
449 1.1 christos }
450 1.1 christos }
451 1.1 christos
452 1.1 christos return_ACPI_STATUS (AE_OK);
453 1.1 christos
454 1.1 christos InvalidateAndExit:
455 1.1 christos AcpiTbInvalidateTable (TableDesc);
456 1.1 christos return_ACPI_STATUS (Status);
457 1.1 christos }
458 1.1 christos
459 1.1 christos
460 1.1 christos /*******************************************************************************
461 1.1 christos *
462 1.1 christos * FUNCTION: AcpiTbResizeRootTableList
463 1.1 christos *
464 1.1 christos * PARAMETERS: None
465 1.1 christos *
466 1.1 christos * RETURN: Status
467 1.1 christos *
468 1.1 christos * DESCRIPTION: Expand the size of global table array
469 1.1 christos *
470 1.1 christos ******************************************************************************/
471 1.1 christos
472 1.1 christos ACPI_STATUS
473 1.1 christos AcpiTbResizeRootTableList (
474 1.1 christos void)
475 1.1 christos {
476 1.1 christos ACPI_TABLE_DESC *Tables;
477 1.1 christos UINT32 TableCount;
478 1.1 christos
479 1.1 christos
480 1.1 christos ACPI_FUNCTION_TRACE (TbResizeRootTableList);
481 1.1 christos
482 1.1 christos
483 1.1 christos /* AllowResize flag is a parameter to AcpiInitializeTables */
484 1.1 christos
485 1.1 christos if (!(AcpiGbl_RootTableList.Flags & ACPI_ROOT_ALLOW_RESIZE))
486 1.1 christos {
487 1.1 christos ACPI_ERROR ((AE_INFO, "Resize of Root Table Array is not allowed"));
488 1.1 christos return_ACPI_STATUS (AE_SUPPORT);
489 1.1 christos }
490 1.1 christos
491 1.1 christos /* Increase the Table Array size */
492 1.1 christos
493 1.1 christos if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
494 1.1 christos {
495 1.1 christos TableCount = AcpiGbl_RootTableList.MaxTableCount;
496 1.1 christos }
497 1.1 christos else
498 1.1 christos {
499 1.1 christos TableCount = AcpiGbl_RootTableList.CurrentTableCount;
500 1.1 christos }
501 1.1 christos
502 1.1 christos Tables = ACPI_ALLOCATE_ZEROED (
503 1.1 christos ((ACPI_SIZE) TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT) *
504 1.1 christos sizeof (ACPI_TABLE_DESC));
505 1.1 christos if (!Tables)
506 1.1 christos {
507 1.1 christos ACPI_ERROR ((AE_INFO, "Could not allocate new root table array"));
508 1.1 christos return_ACPI_STATUS (AE_NO_MEMORY);
509 1.1 christos }
510 1.1 christos
511 1.1 christos /* Copy and free the previous table array */
512 1.1 christos
513 1.1 christos if (AcpiGbl_RootTableList.Tables)
514 1.1 christos {
515 1.4 christos memcpy (Tables, AcpiGbl_RootTableList.Tables,
516 1.1 christos (ACPI_SIZE) TableCount * sizeof (ACPI_TABLE_DESC));
517 1.1 christos
518 1.1 christos if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
519 1.1 christos {
520 1.1 christos ACPI_FREE (AcpiGbl_RootTableList.Tables);
521 1.1 christos }
522 1.1 christos }
523 1.1 christos
524 1.1 christos AcpiGbl_RootTableList.Tables = Tables;
525 1.1 christos AcpiGbl_RootTableList.MaxTableCount =
526 1.1 christos TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT;
527 1.1 christos AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
528 1.1 christos
529 1.1 christos return_ACPI_STATUS (AE_OK);
530 1.1 christos }
531 1.1 christos
532 1.1 christos
533 1.1 christos /*******************************************************************************
534 1.1 christos *
535 1.3 christos * FUNCTION: AcpiTbGetNextTableDescriptor
536 1.1 christos *
537 1.1 christos * PARAMETERS: TableIndex - Where table index is returned
538 1.3 christos * TableDesc - Where table descriptor is returned
539 1.1 christos *
540 1.3 christos * RETURN: Status and table index/descriptor.
541 1.1 christos *
542 1.1 christos * DESCRIPTION: Allocate a new ACPI table entry to the global table list
543 1.1 christos *
544 1.1 christos ******************************************************************************/
545 1.1 christos
546 1.1 christos ACPI_STATUS
547 1.3 christos AcpiTbGetNextTableDescriptor (
548 1.3 christos UINT32 *TableIndex,
549 1.3 christos ACPI_TABLE_DESC **TableDesc)
550 1.1 christos {
551 1.1 christos ACPI_STATUS Status;
552 1.3 christos UINT32 i;
553 1.1 christos
554 1.1 christos
555 1.1 christos /* Ensure that there is room for the table in the Root Table List */
556 1.1 christos
557 1.1 christos if (AcpiGbl_RootTableList.CurrentTableCount >=
558 1.1 christos AcpiGbl_RootTableList.MaxTableCount)
559 1.1 christos {
560 1.1 christos Status = AcpiTbResizeRootTableList();
561 1.1 christos if (ACPI_FAILURE (Status))
562 1.1 christos {
563 1.1 christos return (Status);
564 1.1 christos }
565 1.1 christos }
566 1.1 christos
567 1.3 christos i = AcpiGbl_RootTableList.CurrentTableCount;
568 1.1 christos AcpiGbl_RootTableList.CurrentTableCount++;
569 1.3 christos
570 1.3 christos if (TableIndex)
571 1.3 christos {
572 1.3 christos *TableIndex = i;
573 1.3 christos }
574 1.3 christos if (TableDesc)
575 1.3 christos {
576 1.3 christos *TableDesc = &AcpiGbl_RootTableList.Tables[i];
577 1.3 christos }
578 1.3 christos
579 1.1 christos return (AE_OK);
580 1.1 christos }
581 1.1 christos
582 1.1 christos
583 1.1 christos /*******************************************************************************
584 1.1 christos *
585 1.1 christos * FUNCTION: AcpiTbTerminate
586 1.1 christos *
587 1.1 christos * PARAMETERS: None
588 1.1 christos *
589 1.1 christos * RETURN: None
590 1.1 christos *
591 1.1 christos * DESCRIPTION: Delete all internal ACPI tables
592 1.1 christos *
593 1.1 christos ******************************************************************************/
594 1.1 christos
595 1.1 christos void
596 1.1 christos AcpiTbTerminate (
597 1.1 christos void)
598 1.1 christos {
599 1.1 christos UINT32 i;
600 1.1 christos
601 1.1 christos
602 1.1 christos ACPI_FUNCTION_TRACE (TbTerminate);
603 1.1 christos
604 1.1 christos
605 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
606 1.1 christos
607 1.1 christos /* Delete the individual tables */
608 1.1 christos
609 1.1 christos for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
610 1.1 christos {
611 1.1 christos AcpiTbUninstallTable (&AcpiGbl_RootTableList.Tables[i]);
612 1.1 christos }
613 1.1 christos
614 1.1 christos /*
615 1.1 christos * Delete the root table array if allocated locally. Array cannot be
616 1.1 christos * mapped, so we don't need to check for that flag.
617 1.1 christos */
618 1.1 christos if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
619 1.1 christos {
620 1.1 christos ACPI_FREE (AcpiGbl_RootTableList.Tables);
621 1.1 christos }
622 1.1 christos
623 1.1 christos AcpiGbl_RootTableList.Tables = NULL;
624 1.1 christos AcpiGbl_RootTableList.Flags = 0;
625 1.1 christos AcpiGbl_RootTableList.CurrentTableCount = 0;
626 1.1 christos
627 1.1 christos ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
628 1.1 christos
629 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
630 1.1 christos return_VOID;
631 1.1 christos }
632 1.1 christos
633 1.1 christos
634 1.1 christos /*******************************************************************************
635 1.1 christos *
636 1.1 christos * FUNCTION: AcpiTbDeleteNamespaceByOwner
637 1.1 christos *
638 1.1 christos * PARAMETERS: TableIndex - Table index
639 1.1 christos *
640 1.1 christos * RETURN: Status
641 1.1 christos *
642 1.1 christos * DESCRIPTION: Delete all namespace objects created when this table was loaded.
643 1.1 christos *
644 1.1 christos ******************************************************************************/
645 1.1 christos
646 1.1 christos ACPI_STATUS
647 1.1 christos AcpiTbDeleteNamespaceByOwner (
648 1.1 christos UINT32 TableIndex)
649 1.1 christos {
650 1.1 christos ACPI_OWNER_ID OwnerId;
651 1.1 christos ACPI_STATUS Status;
652 1.1 christos
653 1.1 christos
654 1.1 christos ACPI_FUNCTION_TRACE (TbDeleteNamespaceByOwner);
655 1.1 christos
656 1.1 christos
657 1.1 christos Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES);
658 1.1 christos if (ACPI_FAILURE (Status))
659 1.1 christos {
660 1.1 christos return_ACPI_STATUS (Status);
661 1.1 christos }
662 1.1 christos
663 1.1 christos if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
664 1.1 christos {
665 1.1 christos /* The table index does not exist */
666 1.1 christos
667 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
668 1.1 christos return_ACPI_STATUS (AE_NOT_EXIST);
669 1.1 christos }
670 1.1 christos
671 1.1 christos /* Get the owner ID for this table, used to delete namespace nodes */
672 1.1 christos
673 1.1 christos OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
674 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
675 1.1 christos
676 1.1 christos /*
677 1.1 christos * Need to acquire the namespace writer lock to prevent interference
678 1.1 christos * with any concurrent namespace walks. The interpreter must be
679 1.1 christos * released during the deletion since the acquisition of the deletion
680 1.1 christos * lock may block, and also since the execution of a namespace walk
681 1.1 christos * must be allowed to use the interpreter.
682 1.1 christos */
683 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
684 1.1 christos Status = AcpiUtAcquireWriteLock (&AcpiGbl_NamespaceRwLock);
685 1.1 christos
686 1.1 christos AcpiNsDeleteNamespaceByOwner (OwnerId);
687 1.1 christos if (ACPI_FAILURE (Status))
688 1.1 christos {
689 1.1 christos return_ACPI_STATUS (Status);
690 1.1 christos }
691 1.1 christos
692 1.1 christos AcpiUtReleaseWriteLock (&AcpiGbl_NamespaceRwLock);
693 1.1 christos
694 1.1 christos Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
695 1.1 christos return_ACPI_STATUS (Status);
696 1.1 christos }
697 1.1 christos
698 1.1 christos
699 1.1 christos /*******************************************************************************
700 1.1 christos *
701 1.1 christos * FUNCTION: AcpiTbAllocateOwnerId
702 1.1 christos *
703 1.1 christos * PARAMETERS: TableIndex - Table index
704 1.1 christos *
705 1.1 christos * RETURN: Status
706 1.1 christos *
707 1.1 christos * DESCRIPTION: Allocates OwnerId in TableDesc
708 1.1 christos *
709 1.1 christos ******************************************************************************/
710 1.1 christos
711 1.1 christos ACPI_STATUS
712 1.1 christos AcpiTbAllocateOwnerId (
713 1.1 christos UINT32 TableIndex)
714 1.1 christos {
715 1.1 christos ACPI_STATUS Status = AE_BAD_PARAMETER;
716 1.1 christos
717 1.1 christos
718 1.1 christos ACPI_FUNCTION_TRACE (TbAllocateOwnerId);
719 1.1 christos
720 1.1 christos
721 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
722 1.1 christos if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
723 1.1 christos {
724 1.1 christos Status = AcpiUtAllocateOwnerId (
725 1.5 christos &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
726 1.1 christos }
727 1.1 christos
728 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
729 1.1 christos return_ACPI_STATUS (Status);
730 1.1 christos }
731 1.1 christos
732 1.1 christos
733 1.1 christos /*******************************************************************************
734 1.1 christos *
735 1.1 christos * FUNCTION: AcpiTbReleaseOwnerId
736 1.1 christos *
737 1.1 christos * PARAMETERS: TableIndex - Table index
738 1.1 christos *
739 1.1 christos * RETURN: Status
740 1.1 christos *
741 1.1 christos * DESCRIPTION: Releases OwnerId in TableDesc
742 1.1 christos *
743 1.1 christos ******************************************************************************/
744 1.1 christos
745 1.1 christos ACPI_STATUS
746 1.1 christos AcpiTbReleaseOwnerId (
747 1.1 christos UINT32 TableIndex)
748 1.1 christos {
749 1.1 christos ACPI_STATUS Status = AE_BAD_PARAMETER;
750 1.1 christos
751 1.1 christos
752 1.1 christos ACPI_FUNCTION_TRACE (TbReleaseOwnerId);
753 1.1 christos
754 1.1 christos
755 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
756 1.1 christos if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
757 1.1 christos {
758 1.1 christos AcpiUtReleaseOwnerId (
759 1.1 christos &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
760 1.1 christos Status = AE_OK;
761 1.1 christos }
762 1.1 christos
763 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
764 1.1 christos return_ACPI_STATUS (Status);
765 1.1 christos }
766 1.1 christos
767 1.1 christos
768 1.1 christos /*******************************************************************************
769 1.1 christos *
770 1.1 christos * FUNCTION: AcpiTbGetOwnerId
771 1.1 christos *
772 1.1 christos * PARAMETERS: TableIndex - Table index
773 1.1 christos * OwnerId - Where the table OwnerId is returned
774 1.1 christos *
775 1.1 christos * RETURN: Status
776 1.1 christos *
777 1.1 christos * DESCRIPTION: returns OwnerId for the ACPI table
778 1.1 christos *
779 1.1 christos ******************************************************************************/
780 1.1 christos
781 1.1 christos ACPI_STATUS
782 1.1 christos AcpiTbGetOwnerId (
783 1.1 christos UINT32 TableIndex,
784 1.1 christos ACPI_OWNER_ID *OwnerId)
785 1.1 christos {
786 1.1 christos ACPI_STATUS Status = AE_BAD_PARAMETER;
787 1.1 christos
788 1.1 christos
789 1.1 christos ACPI_FUNCTION_TRACE (TbGetOwnerId);
790 1.1 christos
791 1.1 christos
792 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
793 1.1 christos if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
794 1.1 christos {
795 1.1 christos *OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
796 1.1 christos Status = AE_OK;
797 1.1 christos }
798 1.1 christos
799 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
800 1.1 christos return_ACPI_STATUS (Status);
801 1.1 christos }
802 1.1 christos
803 1.1 christos
804 1.1 christos /*******************************************************************************
805 1.1 christos *
806 1.1 christos * FUNCTION: AcpiTbIsTableLoaded
807 1.1 christos *
808 1.1 christos * PARAMETERS: TableIndex - Index into the root table
809 1.1 christos *
810 1.1 christos * RETURN: Table Loaded Flag
811 1.1 christos *
812 1.1 christos ******************************************************************************/
813 1.1 christos
814 1.1 christos BOOLEAN
815 1.1 christos AcpiTbIsTableLoaded (
816 1.1 christos UINT32 TableIndex)
817 1.1 christos {
818 1.1 christos BOOLEAN IsLoaded = FALSE;
819 1.1 christos
820 1.1 christos
821 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
822 1.1 christos if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
823 1.1 christos {
824 1.1 christos IsLoaded = (BOOLEAN)
825 1.1 christos (AcpiGbl_RootTableList.Tables[TableIndex].Flags &
826 1.1 christos ACPI_TABLE_IS_LOADED);
827 1.1 christos }
828 1.1 christos
829 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
830 1.1 christos return (IsLoaded);
831 1.1 christos }
832 1.1 christos
833 1.1 christos
834 1.1 christos /*******************************************************************************
835 1.1 christos *
836 1.1 christos * FUNCTION: AcpiTbSetTableLoadedFlag
837 1.1 christos *
838 1.1 christos * PARAMETERS: TableIndex - Table index
839 1.1 christos * IsLoaded - TRUE if table is loaded, FALSE otherwise
840 1.1 christos *
841 1.1 christos * RETURN: None
842 1.1 christos *
843 1.1 christos * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
844 1.1 christos *
845 1.1 christos ******************************************************************************/
846 1.1 christos
847 1.1 christos void
848 1.1 christos AcpiTbSetTableLoadedFlag (
849 1.1 christos UINT32 TableIndex,
850 1.1 christos BOOLEAN IsLoaded)
851 1.1 christos {
852 1.1 christos
853 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
854 1.1 christos if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
855 1.1 christos {
856 1.1 christos if (IsLoaded)
857 1.1 christos {
858 1.1 christos AcpiGbl_RootTableList.Tables[TableIndex].Flags |=
859 1.1 christos ACPI_TABLE_IS_LOADED;
860 1.1 christos }
861 1.1 christos else
862 1.1 christos {
863 1.1 christos AcpiGbl_RootTableList.Tables[TableIndex].Flags &=
864 1.1 christos ~ACPI_TABLE_IS_LOADED;
865 1.1 christos }
866 1.1 christos }
867 1.1 christos
868 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
869 1.1 christos }
870