blob: 7ec02b0f69e0fd30051adea4a6e9c4a344a6b274 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: tbinstal - ACPI table installation and removal
4 *
5 *****************************************************************************/
6
7/*
Bob Moorea8357b02010-01-22 19:07:36 +08008 * Copyright (C) 2000 - 2010, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acnamesp.h"
47#include "actables.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define _COMPONENT ACPI_TABLES
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("tbinstal")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Bob Mooref3d2e782007-02-02 19:48:18 +030052/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 *
Bob Mooref3d2e782007-02-02 19:48:18 +030054 * FUNCTION: acpi_tb_verify_table
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 *
Bob Mooref3d2e782007-02-02 19:48:18 +030056 * PARAMETERS: table_desc - table
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 *
58 * RETURN: Status
59 *
Bob Mooref3d2e782007-02-02 19:48:18 +030060 * DESCRIPTION: this function is called to verify and map table
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 *
Bob Mooref3d2e782007-02-02 19:48:18 +030062 *****************************************************************************/
63acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Alexey Starikovskiy428f2112007-02-02 19:48:22 +030065 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Bob Mooref3d2e782007-02-02 19:48:18 +030067 ACPI_FUNCTION_TRACE(tb_verify_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Bob Mooref3d2e782007-02-02 19:48:18 +030069 /* Map the table if necessary */
Robert Moore44f6c012005-04-18 22:49:35 -040070
Bob Mooref3d2e782007-02-02 19:48:18 +030071 if (!table_desc->pointer) {
Alexey Starikovskiy428f2112007-02-02 19:48:22 +030072 if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
73 ACPI_TABLE_ORIGIN_MAPPED) {
74 table_desc->pointer =
75 acpi_os_map_memory(table_desc->address,
76 table_desc->length);
77 }
Bob Mooref3d2e782007-02-02 19:48:18 +030078 if (!table_desc->pointer) {
79 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 }
81 }
82
Bob Mooref3d2e782007-02-02 19:48:18 +030083 /* FACS is the odd table, has no standard ACPI header and no checksum */
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Alexey Starikovskiy428f2112007-02-02 19:48:22 +030085 if (!ACPI_COMPARE_NAME(&table_desc->signature, ACPI_SIG_FACS)) {
86
87 /* Always calculate checksum, ignore bad checksum if requested */
88
89 status =
90 acpi_tb_verify_checksum(table_desc->pointer,
91 table_desc->length);
Bob Mooref3d2e782007-02-02 19:48:18 +030092 }
93
Bob Moorec5fc42a2007-02-02 19:48:19 +030094 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097/*******************************************************************************
98 *
Bob Mooref3d2e782007-02-02 19:48:18 +030099 * FUNCTION: acpi_tb_add_table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 *
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300101 * PARAMETERS: table_desc - Table descriptor
Bob Mooref3d2e782007-02-02 19:48:18 +0300102 * table_index - Where the table index is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 *
104 * RETURN: Status
105 *
Bob Moored3ccaff2009-02-03 14:43:04 +0800106 * DESCRIPTION: This function is called to add an ACPI table. It is used to
107 * dynamically load tables via the Load and load_table AML
108 * operators.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 *
110 ******************************************************************************/
111
Bob Mooref3d2e782007-02-02 19:48:18 +0300112acpi_status
Bob Moore67a119f2008-06-10 13:42:13 +0800113acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
Bob Moore67a119f2008-06-10 13:42:13 +0800115 u32 i;
Bob Mooref3d2e782007-02-02 19:48:18 +0300116 acpi_status status = AE_OK;
Bob Moored3ccaff2009-02-03 14:43:04 +0800117 struct acpi_table_header *override_table = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Bob Mooref3d2e782007-02-02 19:48:18 +0300119 ACPI_FUNCTION_TRACE(tb_add_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300121 if (!table_desc->pointer) {
122 status = acpi_tb_verify_table(table_desc);
123 if (ACPI_FAILURE(status) || !table_desc->pointer) {
124 return_ACPI_STATUS(status);
125 }
126 }
127
Bob Moorebc45b1d2008-06-10 14:12:50 +0800128 /*
129 * Originally, we checked the table signature for "SSDT" or "PSDT" here.
130 * Next, we added support for OEMx tables, signature "OEM".
131 * Valid tables were encountered with a null signature, so we've just
132 * given up on validating the signature, since it seems to be a waste
133 * of code. The original code was removed (05/2008).
134 */
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300135
Bob Mooref3d2e782007-02-02 19:48:18 +0300136 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Bob Mooref3d2e782007-02-02 19:48:18 +0300138 /* Check if table is already registered */
139
140 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
141 if (!acpi_gbl_root_table_list.tables[i].pointer) {
142 status =
143 acpi_tb_verify_table(&acpi_gbl_root_table_list.
144 tables[i]);
145 if (ACPI_FAILURE(status)
146 || !acpi_gbl_root_table_list.tables[i].pointer) {
147 continue;
148 }
149 }
150
Bob Moorea6f30532008-07-04 10:57:51 +0800151 /*
152 * Check for a table match on the entire table length,
153 * not just the header.
154 */
155 if (table_desc->length !=
156 acpi_gbl_root_table_list.tables[i].length) {
157 continue;
158 }
Bob Mooree56f5612008-07-04 10:48:43 +0800159
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300160 if (ACPI_MEMCMP(table_desc->pointer,
161 acpi_gbl_root_table_list.tables[i].pointer,
Bob Moorea6f30532008-07-04 10:57:51 +0800162 acpi_gbl_root_table_list.tables[i].length)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300163 continue;
164 }
165
Bob Mooree56f5612008-07-04 10:48:43 +0800166 /*
167 * Note: the current mechanism does not unregister a table if it is
168 * dynamically unloaded. The related namespace entries are deleted,
169 * but the table remains in the root table list.
170 *
171 * The assumption here is that the number of different tables that
172 * will be loaded is actually small, and there is minimal overhead
173 * in just keeping the table in case it is needed again.
174 *
175 * If this assumption changes in the future (perhaps on large
176 * machines with many table load/unload operations), tables will
177 * need to be unregistered when they are unloaded, and slots in the
178 * root table list should be reused when empty.
179 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300180
Bob Mooree56f5612008-07-04 10:48:43 +0800181 /*
182 * Table is already registered.
183 * We can delete the table that was passed as a parameter.
184 */
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300185 acpi_tb_delete_table(table_desc);
Bob Mooref3d2e782007-02-02 19:48:18 +0300186 *table_index = i;
Bob Mooree56f5612008-07-04 10:48:43 +0800187
188 if (acpi_gbl_root_table_list.tables[i].
189 flags & ACPI_TABLE_IS_LOADED) {
190
191 /* Table is still loaded, this is an error */
192
193 status = AE_ALREADY_EXISTS;
194 goto release;
195 } else {
196 /* Table was unloaded, allow it to be reloaded */
197
198 table_desc->pointer =
199 acpi_gbl_root_table_list.tables[i].pointer;
200 table_desc->address =
201 acpi_gbl_root_table_list.tables[i].address;
202 status = AE_OK;
203 goto print_header;
204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 }
206
Bob Moored3ccaff2009-02-03 14:43:04 +0800207 /*
208 * ACPI Table Override:
209 * Allow the host to override dynamically loaded tables.
210 */
211 status = acpi_os_table_override(table_desc->pointer, &override_table);
212 if (ACPI_SUCCESS(status) && override_table) {
213 ACPI_INFO((AE_INFO,
214 "%4.4s @ 0x%p Table override, replaced with:",
215 table_desc->pointer->signature,
216 ACPI_CAST_PTR(void, table_desc->address)));
217
218 /* We can delete the table that was passed as a parameter */
219
220 acpi_tb_delete_table(table_desc);
221
222 /* Setup descriptor for the new table */
223
224 table_desc->address = ACPI_PTR_TO_PHYSADDR(override_table);
225 table_desc->pointer = override_table;
226 table_desc->length = override_table->length;
227 table_desc->flags = ACPI_TABLE_ORIGIN_OVERRIDE;
228 }
229
Bob Mooree56f5612008-07-04 10:48:43 +0800230 /* Add the table to the global root table list */
231
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300232 status = acpi_tb_store_table(table_desc->address, table_desc->pointer,
233 table_desc->length, table_desc->flags,
234 table_index);
Len Brown4be44fc2005-08-05 00:44:28 -0400235 if (ACPI_FAILURE(status)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300236 goto release;
Robert Moore0c9938c2005-07-29 15:15:00 -0700237 }
238
Bob Mooree56f5612008-07-04 10:48:43 +0800239 print_header:
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300240 acpi_tb_print_table_header(table_desc->address, table_desc->pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
Bob Mooref3d2e782007-02-02 19:48:18 +0300242 release:
Len Brown4be44fc2005-08-05 00:44:28 -0400243 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
244 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245}
246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247/*******************************************************************************
248 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300249 * FUNCTION: acpi_tb_resize_root_table_list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300251 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 *
253 * RETURN: Status
254 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300255 * DESCRIPTION: Expand the size of global table array
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 *
257 ******************************************************************************/
258
Bob Mooref3d2e782007-02-02 19:48:18 +0300259acpi_status acpi_tb_resize_root_table_list(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
Bob Mooref3d2e782007-02-02 19:48:18 +0300261 struct acpi_table_desc *tables;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Bob Mooref3d2e782007-02-02 19:48:18 +0300263 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Bob Mooref3d2e782007-02-02 19:48:18 +0300265 /* allow_resize flag is a parameter to acpi_initialize_tables */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Bob Moorec5fc42a2007-02-02 19:48:19 +0300267 if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300268 ACPI_ERROR((AE_INFO,
269 "Resize of Root Table Array is not allowed"));
270 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 }
272
Bob Mooref3d2e782007-02-02 19:48:18 +0300273 /* Increase the Table Array size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Bob Moore67a119f2008-06-10 13:42:13 +0800275 tables = ACPI_ALLOCATE_ZEROED(((acpi_size) acpi_gbl_root_table_list.
Bob Mooreec41f192009-02-18 15:03:30 +0800276 size +
277 ACPI_ROOT_TABLE_SIZE_INCREMENT) *
278 sizeof(struct acpi_table_desc));
Bob Mooref3d2e782007-02-02 19:48:18 +0300279 if (!tables) {
280 ACPI_ERROR((AE_INFO,
281 "Could not allocate new root table array"));
Len Brown4be44fc2005-08-05 00:44:28 -0400282 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 }
284
Bob Mooref3d2e782007-02-02 19:48:18 +0300285 /* Copy and free the previous table array */
Robert Mooref9f46012005-07-08 00:00:00 -0400286
Bob Mooref3d2e782007-02-02 19:48:18 +0300287 if (acpi_gbl_root_table_list.tables) {
288 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
Bob Moore67a119f2008-06-10 13:42:13 +0800289 (acpi_size) acpi_gbl_root_table_list.size *
Bob Mooref3d2e782007-02-02 19:48:18 +0300290 sizeof(struct acpi_table_desc));
Robert Mooref9f46012005-07-08 00:00:00 -0400291
Bob Moorec5fc42a2007-02-02 19:48:19 +0300292 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300293 ACPI_FREE(acpi_gbl_root_table_list.tables);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 }
295 }
296
Bob Mooref3d2e782007-02-02 19:48:18 +0300297 acpi_gbl_root_table_list.tables = tables;
298 acpi_gbl_root_table_list.size += ACPI_ROOT_TABLE_SIZE_INCREMENT;
Bob Moorec5fc42a2007-02-02 19:48:19 +0300299 acpi_gbl_root_table_list.flags |= (u8) ACPI_ROOT_ORIGIN_ALLOCATED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Len Brown4be44fc2005-08-05 00:44:28 -0400301 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302}
303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304/*******************************************************************************
305 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300306 * FUNCTION: acpi_tb_store_table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300308 * PARAMETERS: Address - Table address
309 * Table - Table header
310 * Length - Table length
311 * Flags - flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300313 * RETURN: Status and table index.
314 *
315 * DESCRIPTION: Add an ACPI table to the global table list
316 *
317 ******************************************************************************/
318
319acpi_status
320acpi_tb_store_table(acpi_physical_address address,
321 struct acpi_table_header *table,
Bob Moore67a119f2008-06-10 13:42:13 +0800322 u32 length, u8 flags, u32 *table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +0300323{
324 acpi_status status = AE_OK;
325
326 /* Ensure that there is room for the table in the Root Table List */
327
328 if (acpi_gbl_root_table_list.count >= acpi_gbl_root_table_list.size) {
329 status = acpi_tb_resize_root_table_list();
330 if (ACPI_FAILURE(status)) {
331 return (status);
332 }
333 }
334
335 /* Initialize added table */
336
337 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
338 address = address;
339 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
340 pointer = table;
341 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].length =
342 length;
343 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
344 owner_id = 0;
345 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].flags =
346 flags;
347
348 ACPI_MOVE_32_TO_32(&
349 (acpi_gbl_root_table_list.
350 tables[acpi_gbl_root_table_list.count].signature),
351 table->signature);
352
353 *table_index = acpi_gbl_root_table_list.count;
354 acpi_gbl_root_table_list.count++;
355 return (status);
356}
357
358/*******************************************************************************
359 *
360 * FUNCTION: acpi_tb_delete_table
361 *
362 * PARAMETERS: table_index - Table index
363 *
364 * RETURN: None
365 *
366 * DESCRIPTION: Delete one internal ACPI table
367 *
368 ******************************************************************************/
369
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300370void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
Bob Mooref3d2e782007-02-02 19:48:18 +0300371{
Bob Mooref3d2e782007-02-02 19:48:18 +0300372 /* Table must be mapped or allocated */
Bob Mooref3d2e782007-02-02 19:48:18 +0300373 if (!table_desc->pointer) {
374 return;
375 }
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300376 switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
377 case ACPI_TABLE_ORIGIN_MAPPED:
378 acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
379 break;
380 case ACPI_TABLE_ORIGIN_ALLOCATED:
Bob Mooref3d2e782007-02-02 19:48:18 +0300381 ACPI_FREE(table_desc->pointer);
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300382 break;
383 default:;
Bob Mooref3d2e782007-02-02 19:48:18 +0300384 }
385
386 table_desc->pointer = NULL;
387}
388
389/*******************************************************************************
390 *
391 * FUNCTION: acpi_tb_terminate
392 *
393 * PARAMETERS: None
394 *
395 * RETURN: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 *
397 * DESCRIPTION: Delete all internal ACPI tables
398 *
399 ******************************************************************************/
400
Bob Mooref3d2e782007-02-02 19:48:18 +0300401void acpi_tb_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
Bob Moore67a119f2008-06-10 13:42:13 +0800403 u32 i;
Bob Mooref3d2e782007-02-02 19:48:18 +0300404
405 ACPI_FUNCTION_TRACE(tb_terminate);
406
407 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
408
409 /* Delete the individual tables */
410
411 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300412 acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]);
Bob Mooref3d2e782007-02-02 19:48:18 +0300413 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415 /*
Bob Mooref3d2e782007-02-02 19:48:18 +0300416 * Delete the root table array if allocated locally. Array cannot be
417 * mapped, so we don't need to check for that flag.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300419 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300420 ACPI_FREE(acpi_gbl_root_table_list.tables);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300422
423 acpi_gbl_root_table_list.tables = NULL;
424 acpi_gbl_root_table_list.flags = 0;
425 acpi_gbl_root_table_list.count = 0;
426
427 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
428 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429}
430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431/*******************************************************************************
432 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300433 * FUNCTION: acpi_tb_delete_namespace_by_owner
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300435 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 *
Bob Moore8a335a22009-03-09 16:31:04 +0800437 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300439 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 *
441 ******************************************************************************/
442
Bob Moore8a335a22009-03-09 16:31:04 +0800443acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Bob Mooref3d2e782007-02-02 19:48:18 +0300445 acpi_owner_id owner_id;
Bob Moore8a335a22009-03-09 16:31:04 +0800446 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Bob Moore8a335a22009-03-09 16:31:04 +0800448 ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner);
449
450 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
451 if (ACPI_FAILURE(status)) {
452 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 }
454
Bob Moore8a335a22009-03-09 16:31:04 +0800455 if (table_index >= acpi_gbl_root_table_list.count) {
456
457 /* The table index does not exist */
458
459 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
460 return_ACPI_STATUS(AE_NOT_EXIST);
461 }
462
463 /* Get the owner ID for this table, used to delete namespace nodes */
464
465 owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id;
Len Brown4be44fc2005-08-05 00:44:28 -0400466 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Bob Moore8a335a22009-03-09 16:31:04 +0800467
468 /*
469 * Need to acquire the namespace writer lock to prevent interference
470 * with any concurrent namespace walks. The interpreter must be
471 * released during the deletion since the acquisition of the deletion
472 * lock may block, and also since the execution of a namespace walk
473 * must be allowed to use the interpreter.
474 */
Bob Mooree4c1ebf2009-04-22 13:02:06 +0800475 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
Bob Moore8a335a22009-03-09 16:31:04 +0800476 status = acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock);
477
Bob Mooref3d2e782007-02-02 19:48:18 +0300478 acpi_ns_delete_namespace_by_owner(owner_id);
Bob Moore8a335a22009-03-09 16:31:04 +0800479 if (ACPI_FAILURE(status)) {
480 return_ACPI_STATUS(status);
481 }
482
483 acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock);
484
485 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
486 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487}
488
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489/*******************************************************************************
490 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300491 * FUNCTION: acpi_tb_allocate_owner_id
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300493 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300495 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300497 * DESCRIPTION: Allocates owner_id in table_desc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 *
499 ******************************************************************************/
500
Bob Moore67a119f2008-06-10 13:42:13 +0800501acpi_status acpi_tb_allocate_owner_id(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502{
Bob Mooref3d2e782007-02-02 19:48:18 +0300503 acpi_status status = AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Bob Mooref3d2e782007-02-02 19:48:18 +0300505 ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Bob Mooref3d2e782007-02-02 19:48:18 +0300507 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
508 if (table_index < acpi_gbl_root_table_list.count) {
509 status = acpi_ut_allocate_owner_id
510 (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 }
512
Bob Mooref3d2e782007-02-02 19:48:18 +0300513 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
514 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515}
516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517/*******************************************************************************
518 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300519 * FUNCTION: acpi_tb_release_owner_id
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300521 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300523 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300525 * DESCRIPTION: Releases owner_id in table_desc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 *
527 ******************************************************************************/
528
Bob Moore67a119f2008-06-10 13:42:13 +0800529acpi_status acpi_tb_release_owner_id(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530{
Bob Mooref3d2e782007-02-02 19:48:18 +0300531 acpi_status status = AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Bob Mooref3d2e782007-02-02 19:48:18 +0300533 ACPI_FUNCTION_TRACE(tb_release_owner_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Bob Mooref3d2e782007-02-02 19:48:18 +0300535 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
536 if (table_index < acpi_gbl_root_table_list.count) {
537 acpi_ut_release_owner_id(&
538 (acpi_gbl_root_table_list.
539 tables[table_index].owner_id));
540 status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 }
542
Bob Mooref3d2e782007-02-02 19:48:18 +0300543 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
544 return_ACPI_STATUS(status);
545}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Bob Mooref3d2e782007-02-02 19:48:18 +0300547/*******************************************************************************
548 *
549 * FUNCTION: acpi_tb_get_owner_id
550 *
551 * PARAMETERS: table_index - Table index
552 * owner_id - Where the table owner_id is returned
553 *
554 * RETURN: Status
555 *
556 * DESCRIPTION: returns owner_id for the ACPI table
557 *
558 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
Bob Moore67a119f2008-06-10 13:42:13 +0800560acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id)
Bob Mooref3d2e782007-02-02 19:48:18 +0300561{
562 acpi_status status = AE_BAD_PARAMETER;
563
564 ACPI_FUNCTION_TRACE(tb_get_owner_id);
565
566 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
567 if (table_index < acpi_gbl_root_table_list.count) {
568 *owner_id =
569 acpi_gbl_root_table_list.tables[table_index].owner_id;
570 status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 }
572
Bob Mooref3d2e782007-02-02 19:48:18 +0300573 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
574 return_ACPI_STATUS(status);
575}
576
577/*******************************************************************************
578 *
579 * FUNCTION: acpi_tb_is_table_loaded
580 *
581 * PARAMETERS: table_index - Table index
582 *
583 * RETURN: Table Loaded Flag
584 *
585 ******************************************************************************/
586
Bob Moore67a119f2008-06-10 13:42:13 +0800587u8 acpi_tb_is_table_loaded(u32 table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +0300588{
589 u8 is_loaded = FALSE;
590
591 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
592 if (table_index < acpi_gbl_root_table_list.count) {
593 is_loaded = (u8)
Bob Mooreec41f192009-02-18 15:03:30 +0800594 (acpi_gbl_root_table_list.tables[table_index].flags &
595 ACPI_TABLE_IS_LOADED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 }
597
Bob Mooref3d2e782007-02-02 19:48:18 +0300598 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
599 return (is_loaded);
600}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Bob Mooref3d2e782007-02-02 19:48:18 +0300602/*******************************************************************************
603 *
604 * FUNCTION: acpi_tb_set_table_loaded_flag
605 *
606 * PARAMETERS: table_index - Table index
607 * is_loaded - TRUE if table is loaded, FALSE otherwise
608 *
609 * RETURN: None
610 *
611 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
612 *
613 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Bob Moore67a119f2008-06-10 13:42:13 +0800615void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
Bob Mooref3d2e782007-02-02 19:48:18 +0300616{
Bob Mooref6dd9222006-07-07 20:44:38 -0400617
Bob Mooref3d2e782007-02-02 19:48:18 +0300618 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
619 if (table_index < acpi_gbl_root_table_list.count) {
620 if (is_loaded) {
621 acpi_gbl_root_table_list.tables[table_index].flags |=
Bob Moorec5fc42a2007-02-02 19:48:19 +0300622 ACPI_TABLE_IS_LOADED;
Bob Mooref3d2e782007-02-02 19:48:18 +0300623 } else {
624 acpi_gbl_root_table_list.tables[table_index].flags &=
Bob Moorec5fc42a2007-02-02 19:48:19 +0300625 ~ACPI_TABLE_IS_LOADED;
Bob Mooref3d2e782007-02-02 19:48:18 +0300626 }
627 }
Bob Mooref6dd9222006-07-07 20:44:38 -0400628
Bob Mooref3d2e782007-02-02 19:48:18 +0300629 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630}