blob: 37374b21969d4574c298945a869e3a714795529f [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/*
Len Brown75a44ce2008-04-23 23:00:13 -04008 * Copyright (C) 2000 - 2008, 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 Mooref3d2e782007-02-02 19:48:18 +0300106 * DESCRIPTION: This function is called to add the ACPI table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 *
108 ******************************************************************************/
109
Bob Mooref3d2e782007-02-02 19:48:18 +0300110acpi_status
Bob Moore67a119f2008-06-10 13:42:13 +0800111acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
Bob Moore67a119f2008-06-10 13:42:13 +0800113 u32 i;
Bob Mooref3d2e782007-02-02 19:48:18 +0300114 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Bob Mooref3d2e782007-02-02 19:48:18 +0300116 ACPI_FUNCTION_TRACE(tb_add_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300118 if (!table_desc->pointer) {
119 status = acpi_tb_verify_table(table_desc);
120 if (ACPI_FAILURE(status) || !table_desc->pointer) {
121 return_ACPI_STATUS(status);
122 }
123 }
124
Bob Moorebc45b1d2008-06-10 14:12:50 +0800125 /*
126 * Originally, we checked the table signature for "SSDT" or "PSDT" here.
127 * Next, we added support for OEMx tables, signature "OEM".
128 * Valid tables were encountered with a null signature, so we've just
129 * given up on validating the signature, since it seems to be a waste
130 * of code. The original code was removed (05/2008).
131 */
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300132
Bob Mooref3d2e782007-02-02 19:48:18 +0300133 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Bob Mooref3d2e782007-02-02 19:48:18 +0300135 /* Check if table is already registered */
136
137 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
138 if (!acpi_gbl_root_table_list.tables[i].pointer) {
139 status =
140 acpi_tb_verify_table(&acpi_gbl_root_table_list.
141 tables[i]);
142 if (ACPI_FAILURE(status)
143 || !acpi_gbl_root_table_list.tables[i].pointer) {
144 continue;
145 }
146 }
147
Bob Moorea6f30532008-07-04 10:57:51 +0800148 /*
149 * Check for a table match on the entire table length,
150 * not just the header.
151 */
152 if (table_desc->length !=
153 acpi_gbl_root_table_list.tables[i].length) {
154 continue;
155 }
Bob Mooree56f5612008-07-04 10:48:43 +0800156
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300157 if (ACPI_MEMCMP(table_desc->pointer,
158 acpi_gbl_root_table_list.tables[i].pointer,
Bob Moorea6f30532008-07-04 10:57:51 +0800159 acpi_gbl_root_table_list.tables[i].length)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300160 continue;
161 }
162
Bob Mooree56f5612008-07-04 10:48:43 +0800163 /*
164 * Note: the current mechanism does not unregister a table if it is
165 * dynamically unloaded. The related namespace entries are deleted,
166 * but the table remains in the root table list.
167 *
168 * The assumption here is that the number of different tables that
169 * will be loaded is actually small, and there is minimal overhead
170 * in just keeping the table in case it is needed again.
171 *
172 * If this assumption changes in the future (perhaps on large
173 * machines with many table load/unload operations), tables will
174 * need to be unregistered when they are unloaded, and slots in the
175 * root table list should be reused when empty.
176 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300177
Bob Mooree56f5612008-07-04 10:48:43 +0800178 /*
179 * Table is already registered.
180 * We can delete the table that was passed as a parameter.
181 */
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300182 acpi_tb_delete_table(table_desc);
Bob Mooref3d2e782007-02-02 19:48:18 +0300183 *table_index = i;
Bob Mooree56f5612008-07-04 10:48:43 +0800184
185 if (acpi_gbl_root_table_list.tables[i].
186 flags & ACPI_TABLE_IS_LOADED) {
187
188 /* Table is still loaded, this is an error */
189
190 status = AE_ALREADY_EXISTS;
191 goto release;
192 } else {
193 /* Table was unloaded, allow it to be reloaded */
194
195 table_desc->pointer =
196 acpi_gbl_root_table_list.tables[i].pointer;
197 table_desc->address =
198 acpi_gbl_root_table_list.tables[i].address;
199 status = AE_OK;
200 goto print_header;
201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 }
203
Bob Mooree56f5612008-07-04 10:48:43 +0800204 /* Add the table to the global root table list */
205
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300206 status = acpi_tb_store_table(table_desc->address, table_desc->pointer,
207 table_desc->length, table_desc->flags,
208 table_index);
Len Brown4be44fc2005-08-05 00:44:28 -0400209 if (ACPI_FAILURE(status)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300210 goto release;
Robert Moore0c9938c2005-07-29 15:15:00 -0700211 }
212
Bob Mooree56f5612008-07-04 10:48:43 +0800213 print_header:
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300214 acpi_tb_print_table_header(table_desc->address, table_desc->pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Bob Mooref3d2e782007-02-02 19:48:18 +0300216 release:
Len Brown4be44fc2005-08-05 00:44:28 -0400217 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
218 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221/*******************************************************************************
222 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300223 * FUNCTION: acpi_tb_resize_root_table_list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300225 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 *
227 * RETURN: Status
228 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300229 * DESCRIPTION: Expand the size of global table array
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 *
231 ******************************************************************************/
232
Bob Mooref3d2e782007-02-02 19:48:18 +0300233acpi_status acpi_tb_resize_root_table_list(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
Bob Mooref3d2e782007-02-02 19:48:18 +0300235 struct acpi_table_desc *tables;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Bob Mooref3d2e782007-02-02 19:48:18 +0300237 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Bob Mooref3d2e782007-02-02 19:48:18 +0300239 /* allow_resize flag is a parameter to acpi_initialize_tables */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Bob Moorec5fc42a2007-02-02 19:48:19 +0300241 if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300242 ACPI_ERROR((AE_INFO,
243 "Resize of Root Table Array is not allowed"));
244 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 }
246
Bob Mooref3d2e782007-02-02 19:48:18 +0300247 /* Increase the Table Array size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Bob Moore67a119f2008-06-10 13:42:13 +0800249 tables = ACPI_ALLOCATE_ZEROED(((acpi_size) acpi_gbl_root_table_list.
250 size + ACPI_ROOT_TABLE_SIZE_INCREMENT)
Bob Mooref3d2e782007-02-02 19:48:18 +0300251 * sizeof(struct acpi_table_desc));
252 if (!tables) {
253 ACPI_ERROR((AE_INFO,
254 "Could not allocate new root table array"));
Len Brown4be44fc2005-08-05 00:44:28 -0400255 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 }
257
Bob Mooref3d2e782007-02-02 19:48:18 +0300258 /* Copy and free the previous table array */
Robert Mooref9f46012005-07-08 00:00:00 -0400259
Bob Mooref3d2e782007-02-02 19:48:18 +0300260 if (acpi_gbl_root_table_list.tables) {
261 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
Bob Moore67a119f2008-06-10 13:42:13 +0800262 (acpi_size) acpi_gbl_root_table_list.size *
Bob Mooref3d2e782007-02-02 19:48:18 +0300263 sizeof(struct acpi_table_desc));
Robert Mooref9f46012005-07-08 00:00:00 -0400264
Bob Moorec5fc42a2007-02-02 19:48:19 +0300265 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300266 ACPI_FREE(acpi_gbl_root_table_list.tables);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 }
268 }
269
Bob Mooref3d2e782007-02-02 19:48:18 +0300270 acpi_gbl_root_table_list.tables = tables;
271 acpi_gbl_root_table_list.size += ACPI_ROOT_TABLE_SIZE_INCREMENT;
Bob Moorec5fc42a2007-02-02 19:48:19 +0300272 acpi_gbl_root_table_list.flags |= (u8) ACPI_ROOT_ORIGIN_ALLOCATED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Len Brown4be44fc2005-08-05 00:44:28 -0400274 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275}
276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277/*******************************************************************************
278 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300279 * FUNCTION: acpi_tb_store_table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300281 * PARAMETERS: Address - Table address
282 * Table - Table header
283 * Length - Table length
284 * Flags - flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300286 * RETURN: Status and table index.
287 *
288 * DESCRIPTION: Add an ACPI table to the global table list
289 *
290 ******************************************************************************/
291
292acpi_status
293acpi_tb_store_table(acpi_physical_address address,
294 struct acpi_table_header *table,
Bob Moore67a119f2008-06-10 13:42:13 +0800295 u32 length, u8 flags, u32 *table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +0300296{
297 acpi_status status = AE_OK;
298
299 /* Ensure that there is room for the table in the Root Table List */
300
301 if (acpi_gbl_root_table_list.count >= acpi_gbl_root_table_list.size) {
302 status = acpi_tb_resize_root_table_list();
303 if (ACPI_FAILURE(status)) {
304 return (status);
305 }
306 }
307
308 /* Initialize added table */
309
310 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
311 address = address;
312 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
313 pointer = table;
314 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].length =
315 length;
316 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
317 owner_id = 0;
318 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].flags =
319 flags;
320
321 ACPI_MOVE_32_TO_32(&
322 (acpi_gbl_root_table_list.
323 tables[acpi_gbl_root_table_list.count].signature),
324 table->signature);
325
326 *table_index = acpi_gbl_root_table_list.count;
327 acpi_gbl_root_table_list.count++;
328 return (status);
329}
330
331/*******************************************************************************
332 *
333 * FUNCTION: acpi_tb_delete_table
334 *
335 * PARAMETERS: table_index - Table index
336 *
337 * RETURN: None
338 *
339 * DESCRIPTION: Delete one internal ACPI table
340 *
341 ******************************************************************************/
342
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300343void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
Bob Mooref3d2e782007-02-02 19:48:18 +0300344{
Bob Mooref3d2e782007-02-02 19:48:18 +0300345 /* Table must be mapped or allocated */
Bob Mooref3d2e782007-02-02 19:48:18 +0300346 if (!table_desc->pointer) {
347 return;
348 }
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300349 switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
350 case ACPI_TABLE_ORIGIN_MAPPED:
351 acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
352 break;
353 case ACPI_TABLE_ORIGIN_ALLOCATED:
Bob Mooref3d2e782007-02-02 19:48:18 +0300354 ACPI_FREE(table_desc->pointer);
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300355 break;
356 default:;
Bob Mooref3d2e782007-02-02 19:48:18 +0300357 }
358
359 table_desc->pointer = NULL;
360}
361
362/*******************************************************************************
363 *
364 * FUNCTION: acpi_tb_terminate
365 *
366 * PARAMETERS: None
367 *
368 * RETURN: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 *
370 * DESCRIPTION: Delete all internal ACPI tables
371 *
372 ******************************************************************************/
373
Bob Mooref3d2e782007-02-02 19:48:18 +0300374void acpi_tb_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375{
Bob Moore67a119f2008-06-10 13:42:13 +0800376 u32 i;
Bob Mooref3d2e782007-02-02 19:48:18 +0300377
378 ACPI_FUNCTION_TRACE(tb_terminate);
379
380 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
381
382 /* Delete the individual tables */
383
384 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300385 acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]);
Bob Mooref3d2e782007-02-02 19:48:18 +0300386 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 /*
Bob Mooref3d2e782007-02-02 19:48:18 +0300389 * Delete the root table array if allocated locally. Array cannot be
390 * mapped, so we don't need to check for that flag.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300392 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300393 ACPI_FREE(acpi_gbl_root_table_list.tables);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300395
396 acpi_gbl_root_table_list.tables = NULL;
397 acpi_gbl_root_table_list.flags = 0;
398 acpi_gbl_root_table_list.count = 0;
399
400 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
401 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402}
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404/*******************************************************************************
405 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300406 * FUNCTION: acpi_tb_delete_namespace_by_owner
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300408 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300410 * RETURN: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300412 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 *
414 ******************************************************************************/
415
Bob Moore67a119f2008-06-10 13:42:13 +0800416void acpi_tb_delete_namespace_by_owner(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417{
Bob Mooref3d2e782007-02-02 19:48:18 +0300418 acpi_owner_id owner_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Bob Mooref3d2e782007-02-02 19:48:18 +0300420 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
421 if (table_index < acpi_gbl_root_table_list.count) {
422 owner_id =
423 acpi_gbl_root_table_list.tables[table_index].owner_id;
424 } else {
425 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 return;
427 }
428
Len Brown4be44fc2005-08-05 00:44:28 -0400429 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Bob Mooref3d2e782007-02-02 19:48:18 +0300430 acpi_ns_delete_namespace_by_owner(owner_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
432
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433/*******************************************************************************
434 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300435 * FUNCTION: acpi_tb_allocate_owner_id
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300437 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300439 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300441 * DESCRIPTION: Allocates owner_id in table_desc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 *
443 ******************************************************************************/
444
Bob Moore67a119f2008-06-10 13:42:13 +0800445acpi_status acpi_tb_allocate_owner_id(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446{
Bob Mooref3d2e782007-02-02 19:48:18 +0300447 acpi_status status = AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Bob Mooref3d2e782007-02-02 19:48:18 +0300449 ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Bob Mooref3d2e782007-02-02 19:48:18 +0300451 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
452 if (table_index < acpi_gbl_root_table_list.count) {
453 status = acpi_ut_allocate_owner_id
454 (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 }
456
Bob Mooref3d2e782007-02-02 19:48:18 +0300457 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
458 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459}
460
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461/*******************************************************************************
462 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300463 * FUNCTION: acpi_tb_release_owner_id
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300465 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300467 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300469 * DESCRIPTION: Releases owner_id in table_desc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 *
471 ******************************************************************************/
472
Bob Moore67a119f2008-06-10 13:42:13 +0800473acpi_status acpi_tb_release_owner_id(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
Bob Mooref3d2e782007-02-02 19:48:18 +0300475 acpi_status status = AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Bob Mooref3d2e782007-02-02 19:48:18 +0300477 ACPI_FUNCTION_TRACE(tb_release_owner_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Bob Mooref3d2e782007-02-02 19:48:18 +0300479 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
480 if (table_index < acpi_gbl_root_table_list.count) {
481 acpi_ut_release_owner_id(&
482 (acpi_gbl_root_table_list.
483 tables[table_index].owner_id));
484 status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 }
486
Bob Mooref3d2e782007-02-02 19:48:18 +0300487 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
488 return_ACPI_STATUS(status);
489}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Bob Mooref3d2e782007-02-02 19:48:18 +0300491/*******************************************************************************
492 *
493 * FUNCTION: acpi_tb_get_owner_id
494 *
495 * PARAMETERS: table_index - Table index
496 * owner_id - Where the table owner_id is returned
497 *
498 * RETURN: Status
499 *
500 * DESCRIPTION: returns owner_id for the ACPI table
501 *
502 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Bob Moore67a119f2008-06-10 13:42:13 +0800504acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id)
Bob Mooref3d2e782007-02-02 19:48:18 +0300505{
506 acpi_status status = AE_BAD_PARAMETER;
507
508 ACPI_FUNCTION_TRACE(tb_get_owner_id);
509
510 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
511 if (table_index < acpi_gbl_root_table_list.count) {
512 *owner_id =
513 acpi_gbl_root_table_list.tables[table_index].owner_id;
514 status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 }
516
Bob Mooref3d2e782007-02-02 19:48:18 +0300517 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
518 return_ACPI_STATUS(status);
519}
520
521/*******************************************************************************
522 *
523 * FUNCTION: acpi_tb_is_table_loaded
524 *
525 * PARAMETERS: table_index - Table index
526 *
527 * RETURN: Table Loaded Flag
528 *
529 ******************************************************************************/
530
Bob Moore67a119f2008-06-10 13:42:13 +0800531u8 acpi_tb_is_table_loaded(u32 table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +0300532{
533 u8 is_loaded = FALSE;
534
535 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
536 if (table_index < acpi_gbl_root_table_list.count) {
537 is_loaded = (u8)
538 (acpi_gbl_root_table_list.tables[table_index].
Bob Moorec5fc42a2007-02-02 19:48:19 +0300539 flags & ACPI_TABLE_IS_LOADED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 }
541
Bob Mooref3d2e782007-02-02 19:48:18 +0300542 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
543 return (is_loaded);
544}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Bob Mooref3d2e782007-02-02 19:48:18 +0300546/*******************************************************************************
547 *
548 * FUNCTION: acpi_tb_set_table_loaded_flag
549 *
550 * PARAMETERS: table_index - Table index
551 * is_loaded - TRUE if table is loaded, FALSE otherwise
552 *
553 * RETURN: None
554 *
555 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
556 *
557 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Bob Moore67a119f2008-06-10 13:42:13 +0800559void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
Bob Mooref3d2e782007-02-02 19:48:18 +0300560{
Bob Mooref6dd9222006-07-07 20:44:38 -0400561
Bob Mooref3d2e782007-02-02 19:48:18 +0300562 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
563 if (table_index < acpi_gbl_root_table_list.count) {
564 if (is_loaded) {
565 acpi_gbl_root_table_list.tables[table_index].flags |=
Bob Moorec5fc42a2007-02-02 19:48:19 +0300566 ACPI_TABLE_IS_LOADED;
Bob Mooref3d2e782007-02-02 19:48:18 +0300567 } else {
568 acpi_gbl_root_table_list.tables[table_index].flags &=
Bob Moorec5fc42a2007-02-02 19:48:19 +0300569 ~ACPI_TABLE_IS_LOADED;
Bob Mooref3d2e782007-02-02 19:48:18 +0300570 }
571 }
Bob Mooref6dd9222006-07-07 20:44:38 -0400572
Bob Mooref3d2e782007-02-02 19:48:18 +0300573 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574}