blob: 70f9d787c82cd9e8af9ae6fbd19d4d5a7cee2ac0 [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 Moore77848132012-01-12 13:27:23 +08008 * Copyright (C) 2000 - 2012, 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Bob Mooref3d2e782007-02-02 19:48:18 +0300118 ACPI_FUNCTION_TRACE(tb_add_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300120 if (!table_desc->pointer) {
121 status = acpi_tb_verify_table(table_desc);
122 if (ACPI_FAILURE(status) || !table_desc->pointer) {
123 return_ACPI_STATUS(status);
124 }
125 }
126
Bob Moorebc45b1d2008-06-10 14:12:50 +0800127 /*
Bob Moorec8cefe32011-06-14 10:42:53 +0800128 * Validate the incoming table signature.
129 *
130 * 1) Originally, we checked the table signature for "SSDT" or "PSDT".
131 * 2) We added support for OEMx tables, signature "OEM".
132 * 3) Valid tables were encountered with a null signature, so we just
133 * gave up on validating the signature, (05/2008).
134 * 4) We encountered non-AML tables such as the MADT, which caused
135 * interpreter errors and kernel faults. So now, we once again allow
136 * only "SSDT", "OEMx", and now, also a null signature. (05/2011).
Bob Moorebc45b1d2008-06-10 14:12:50 +0800137 */
Bob Moorec8cefe32011-06-14 10:42:53 +0800138 if ((table_desc->pointer->signature[0] != 0x00) &&
139 (!ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_SSDT))
140 && (ACPI_STRNCMP(table_desc->pointer->signature, "OEM", 3))) {
Bob Moore3b3ea772012-07-16 09:39:54 +0800141 ACPI_BIOS_ERROR((AE_INFO,
142 "Table has invalid signature [%4.4s] (0x%8.8X), "
143 "must be SSDT or OEMx",
144 acpi_ut_valid_acpi_name(*(u32 *)table_desc->
145 pointer->
146 signature) ?
147 table_desc->pointer->signature : "????",
148 *(u32 *)table_desc->pointer->signature));
Bob Moorec8cefe32011-06-14 10:42:53 +0800149
150 return_ACPI_STATUS(AE_BAD_SIGNATURE);
151 }
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300152
Bob Mooref3d2e782007-02-02 19:48:18 +0300153 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Bob Mooref3d2e782007-02-02 19:48:18 +0300155 /* Check if table is already registered */
156
Bob Mooreb9ee2042010-04-27 11:16:14 +0800157 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300158 if (!acpi_gbl_root_table_list.tables[i].pointer) {
159 status =
160 acpi_tb_verify_table(&acpi_gbl_root_table_list.
161 tables[i]);
162 if (ACPI_FAILURE(status)
163 || !acpi_gbl_root_table_list.tables[i].pointer) {
164 continue;
165 }
166 }
167
Bob Moorea6f30532008-07-04 10:57:51 +0800168 /*
169 * Check for a table match on the entire table length,
170 * not just the header.
171 */
172 if (table_desc->length !=
173 acpi_gbl_root_table_list.tables[i].length) {
174 continue;
175 }
Bob Mooree56f5612008-07-04 10:48:43 +0800176
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300177 if (ACPI_MEMCMP(table_desc->pointer,
178 acpi_gbl_root_table_list.tables[i].pointer,
Bob Moorea6f30532008-07-04 10:57:51 +0800179 acpi_gbl_root_table_list.tables[i].length)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300180 continue;
181 }
182
Bob Mooree56f5612008-07-04 10:48:43 +0800183 /*
184 * Note: the current mechanism does not unregister a table if it is
185 * dynamically unloaded. The related namespace entries are deleted,
186 * but the table remains in the root table list.
187 *
188 * The assumption here is that the number of different tables that
189 * will be loaded is actually small, and there is minimal overhead
190 * in just keeping the table in case it is needed again.
191 *
192 * If this assumption changes in the future (perhaps on large
193 * machines with many table load/unload operations), tables will
194 * need to be unregistered when they are unloaded, and slots in the
195 * root table list should be reused when empty.
196 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300197
Bob Mooree56f5612008-07-04 10:48:43 +0800198 /*
199 * Table is already registered.
200 * We can delete the table that was passed as a parameter.
201 */
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300202 acpi_tb_delete_table(table_desc);
Bob Mooref3d2e782007-02-02 19:48:18 +0300203 *table_index = i;
Bob Mooree56f5612008-07-04 10:48:43 +0800204
205 if (acpi_gbl_root_table_list.tables[i].
206 flags & ACPI_TABLE_IS_LOADED) {
207
208 /* Table is still loaded, this is an error */
209
210 status = AE_ALREADY_EXISTS;
211 goto release;
212 } else {
213 /* Table was unloaded, allow it to be reloaded */
214
215 table_desc->pointer =
216 acpi_gbl_root_table_list.tables[i].pointer;
217 table_desc->address =
218 acpi_gbl_root_table_list.tables[i].address;
219 status = AE_OK;
220 goto print_header;
221 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 }
223
Bob Moored3ccaff2009-02-03 14:43:04 +0800224 /*
225 * ACPI Table Override:
226 * Allow the host to override dynamically loaded tables.
Bob Mooref7b004a2012-02-14 18:31:56 +0800227 * NOTE: the table is fully mapped at this point, and the mapping will
228 * be deleted by tb_table_override if the table is actually overridden.
Bob Moored3ccaff2009-02-03 14:43:04 +0800229 */
Bob Mooref7b004a2012-02-14 18:31:56 +0800230 (void)acpi_tb_table_override(table_desc->pointer, table_desc);
Bob Moored3ccaff2009-02-03 14:43:04 +0800231
Bob Mooree56f5612008-07-04 10:48:43 +0800232 /* Add the table to the global root table list */
233
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300234 status = acpi_tb_store_table(table_desc->address, table_desc->pointer,
235 table_desc->length, table_desc->flags,
236 table_index);
Len Brown4be44fc2005-08-05 00:44:28 -0400237 if (ACPI_FAILURE(status)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300238 goto release;
Robert Moore0c9938c2005-07-29 15:15:00 -0700239 }
240
Bob Mooree56f5612008-07-04 10:48:43 +0800241 print_header:
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300242 acpi_tb_print_table_header(table_desc->address, table_desc->pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Bob Mooref3d2e782007-02-02 19:48:18 +0300244 release:
Len Brown4be44fc2005-08-05 00:44:28 -0400245 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
246 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247}
248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249/*******************************************************************************
250 *
Bob Mooref7b004a2012-02-14 18:31:56 +0800251 * FUNCTION: acpi_tb_table_override
252 *
253 * PARAMETERS: table_header - Header for the original table
254 * table_desc - Table descriptor initialized for the
255 * original table. May or may not be mapped.
256 *
257 * RETURN: Pointer to the entire new table. NULL if table not overridden.
258 * If overridden, installs the new table within the input table
259 * descriptor.
260 *
261 * DESCRIPTION: Attempt table override by calling the OSL override functions.
262 * Note: If the table is overridden, then the entire new table
263 * is mapped and returned by this function.
264 *
265 ******************************************************************************/
266
267struct acpi_table_header *acpi_tb_table_override(struct acpi_table_header
268 *table_header,
269 struct acpi_table_desc
270 *table_desc)
271{
272 acpi_status status;
273 struct acpi_table_header *new_table = NULL;
274 acpi_physical_address new_address = 0;
275 u32 new_table_length = 0;
276 u8 new_flags;
277 char *override_type;
278
279 /* (1) Attempt logical override (returns a logical address) */
280
281 status = acpi_os_table_override(table_header, &new_table);
282 if (ACPI_SUCCESS(status) && new_table) {
283 new_address = ACPI_PTR_TO_PHYSADDR(new_table);
284 new_table_length = new_table->length;
285 new_flags = ACPI_TABLE_ORIGIN_OVERRIDE;
286 override_type = "Logical";
287 goto finish_override;
288 }
289
290 /* (2) Attempt physical override (returns a physical address) */
291
292 status = acpi_os_physical_table_override(table_header,
293 &new_address,
294 &new_table_length);
295 if (ACPI_SUCCESS(status) && new_address && new_table_length) {
296
297 /* Map the entire new table */
298
299 new_table = acpi_os_map_memory(new_address, new_table_length);
300 if (!new_table) {
301 ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY,
302 "%4.4s %p Attempted physical table override failed",
303 table_header->signature,
304 ACPI_CAST_PTR(void,
305 table_desc->address)));
306 return (NULL);
307 }
308
309 override_type = "Physical";
310 new_flags = ACPI_TABLE_ORIGIN_MAPPED;
311 goto finish_override;
312 }
313
314 return (NULL); /* There was no override */
315
316 finish_override:
317
318 ACPI_INFO((AE_INFO,
319 "%4.4s %p %s table override, new table: %p",
320 table_header->signature,
321 ACPI_CAST_PTR(void, table_desc->address),
322 override_type, new_table));
323
324 /* We can now unmap/delete the original table (if fully mapped) */
325
326 acpi_tb_delete_table(table_desc);
327
328 /* Setup descriptor for the new table */
329
330 table_desc->address = new_address;
331 table_desc->pointer = new_table;
332 table_desc->length = new_table_length;
333 table_desc->flags = new_flags;
334
335 return (new_table);
336}
337
338/*******************************************************************************
339 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300340 * FUNCTION: acpi_tb_resize_root_table_list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300342 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 *
344 * RETURN: Status
345 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300346 * DESCRIPTION: Expand the size of global table array
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 *
348 ******************************************************************************/
349
Bob Mooref3d2e782007-02-02 19:48:18 +0300350acpi_status acpi_tb_resize_root_table_list(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
Bob Mooref3d2e782007-02-02 19:48:18 +0300352 struct acpi_table_desc *tables;
Lv Zheng2bc198c2012-09-13 09:29:06 -0700353 u32 table_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Bob Mooref3d2e782007-02-02 19:48:18 +0300355 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Bob Mooref3d2e782007-02-02 19:48:18 +0300357 /* allow_resize flag is a parameter to acpi_initialize_tables */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Bob Moorec5fc42a2007-02-02 19:48:19 +0300359 if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300360 ACPI_ERROR((AE_INFO,
361 "Resize of Root Table Array is not allowed"));
362 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 }
364
Bob Mooref3d2e782007-02-02 19:48:18 +0300365 /* Increase the Table Array size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Lv Zheng2bc198c2012-09-13 09:29:06 -0700367 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
368 table_count = acpi_gbl_root_table_list.max_table_count;
369 } else {
370 table_count = acpi_gbl_root_table_list.current_table_count;
371 }
372
373 tables = ACPI_ALLOCATE_ZEROED(((acpi_size) table_count +
Bob Mooreec41f192009-02-18 15:03:30 +0800374 ACPI_ROOT_TABLE_SIZE_INCREMENT) *
375 sizeof(struct acpi_table_desc));
Bob Mooref3d2e782007-02-02 19:48:18 +0300376 if (!tables) {
377 ACPI_ERROR((AE_INFO,
378 "Could not allocate new root table array"));
Len Brown4be44fc2005-08-05 00:44:28 -0400379 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 }
381
Bob Mooref3d2e782007-02-02 19:48:18 +0300382 /* Copy and free the previous table array */
Robert Mooref9f46012005-07-08 00:00:00 -0400383
Bob Mooref3d2e782007-02-02 19:48:18 +0300384 if (acpi_gbl_root_table_list.tables) {
385 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
Lv Zheng2bc198c2012-09-13 09:29:06 -0700386 (acpi_size) table_count *
387 sizeof(struct acpi_table_desc));
Robert Mooref9f46012005-07-08 00:00:00 -0400388
Bob Moorec5fc42a2007-02-02 19:48:19 +0300389 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300390 ACPI_FREE(acpi_gbl_root_table_list.tables);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 }
392 }
393
Bob Mooref3d2e782007-02-02 19:48:18 +0300394 acpi_gbl_root_table_list.tables = tables;
Lv Zheng2bc198c2012-09-13 09:29:06 -0700395 acpi_gbl_root_table_list.max_table_count =
396 table_count + ACPI_ROOT_TABLE_SIZE_INCREMENT;
397 acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Len Brown4be44fc2005-08-05 00:44:28 -0400399 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400}
401
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402/*******************************************************************************
403 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300404 * FUNCTION: acpi_tb_store_table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 *
Bob Mooreba494be2012-07-12 09:40:10 +0800406 * PARAMETERS: address - Table address
407 * table - Table header
408 * length - Table length
409 * flags - flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300411 * RETURN: Status and table index.
412 *
413 * DESCRIPTION: Add an ACPI table to the global table list
414 *
415 ******************************************************************************/
416
417acpi_status
418acpi_tb_store_table(acpi_physical_address address,
419 struct acpi_table_header *table,
Bob Moore67a119f2008-06-10 13:42:13 +0800420 u32 length, u8 flags, u32 *table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +0300421{
Bob Mooreb9ee2042010-04-27 11:16:14 +0800422 acpi_status status;
423 struct acpi_table_desc *new_table;
Bob Mooref3d2e782007-02-02 19:48:18 +0300424
425 /* Ensure that there is room for the table in the Root Table List */
426
Bob Mooreb9ee2042010-04-27 11:16:14 +0800427 if (acpi_gbl_root_table_list.current_table_count >=
428 acpi_gbl_root_table_list.max_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300429 status = acpi_tb_resize_root_table_list();
430 if (ACPI_FAILURE(status)) {
431 return (status);
432 }
433 }
434
Bob Mooreb9ee2042010-04-27 11:16:14 +0800435 new_table =
436 &acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.
437 current_table_count];
438
Bob Mooref3d2e782007-02-02 19:48:18 +0300439 /* Initialize added table */
440
Bob Mooreb9ee2042010-04-27 11:16:14 +0800441 new_table->address = address;
442 new_table->pointer = table;
443 new_table->length = length;
444 new_table->owner_id = 0;
445 new_table->flags = flags;
Bob Mooref3d2e782007-02-02 19:48:18 +0300446
Bob Mooreb9ee2042010-04-27 11:16:14 +0800447 ACPI_MOVE_32_TO_32(&new_table->signature, table->signature);
Bob Mooref3d2e782007-02-02 19:48:18 +0300448
Bob Mooreb9ee2042010-04-27 11:16:14 +0800449 *table_index = acpi_gbl_root_table_list.current_table_count;
450 acpi_gbl_root_table_list.current_table_count++;
451 return (AE_OK);
Bob Mooref3d2e782007-02-02 19:48:18 +0300452}
453
454/*******************************************************************************
455 *
456 * FUNCTION: acpi_tb_delete_table
457 *
458 * PARAMETERS: table_index - Table index
459 *
460 * RETURN: None
461 *
462 * DESCRIPTION: Delete one internal ACPI table
463 *
464 ******************************************************************************/
465
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300466void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
Bob Mooref3d2e782007-02-02 19:48:18 +0300467{
Bob Mooref3d2e782007-02-02 19:48:18 +0300468 /* Table must be mapped or allocated */
Bob Mooref3d2e782007-02-02 19:48:18 +0300469 if (!table_desc->pointer) {
470 return;
471 }
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300472 switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
473 case ACPI_TABLE_ORIGIN_MAPPED:
474 acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
475 break;
476 case ACPI_TABLE_ORIGIN_ALLOCATED:
Bob Mooref3d2e782007-02-02 19:48:18 +0300477 ACPI_FREE(table_desc->pointer);
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300478 break;
Bob Mooref7b004a2012-02-14 18:31:56 +0800479
480 /* Not mapped or allocated, there is nothing we can do */
481
482 default:
483 return;
Bob Mooref3d2e782007-02-02 19:48:18 +0300484 }
485
486 table_desc->pointer = NULL;
487}
488
489/*******************************************************************************
490 *
491 * FUNCTION: acpi_tb_terminate
492 *
493 * PARAMETERS: None
494 *
495 * RETURN: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 *
497 * DESCRIPTION: Delete all internal ACPI tables
498 *
499 ******************************************************************************/
500
Bob Mooref3d2e782007-02-02 19:48:18 +0300501void acpi_tb_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502{
Bob Moore67a119f2008-06-10 13:42:13 +0800503 u32 i;
Bob Mooref3d2e782007-02-02 19:48:18 +0300504
505 ACPI_FUNCTION_TRACE(tb_terminate);
506
507 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
508
509 /* Delete the individual tables */
510
Bob Mooreb9ee2042010-04-27 11:16:14 +0800511 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300512 acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]);
Bob Mooref3d2e782007-02-02 19:48:18 +0300513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
515 /*
Bob Mooref3d2e782007-02-02 19:48:18 +0300516 * Delete the root table array if allocated locally. Array cannot be
517 * mapped, so we don't need to check for that flag.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300519 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300520 ACPI_FREE(acpi_gbl_root_table_list.tables);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300522
523 acpi_gbl_root_table_list.tables = NULL;
524 acpi_gbl_root_table_list.flags = 0;
Bob Mooreb9ee2042010-04-27 11:16:14 +0800525 acpi_gbl_root_table_list.current_table_count = 0;
Bob Mooref3d2e782007-02-02 19:48:18 +0300526
527 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
528 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529}
530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531/*******************************************************************************
532 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300533 * FUNCTION: acpi_tb_delete_namespace_by_owner
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300535 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 *
Bob Moore8a335a232009-03-09 16:31:04 +0800537 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300539 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 *
541 ******************************************************************************/
542
Bob Moore8a335a232009-03-09 16:31:04 +0800543acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
Bob Mooref3d2e782007-02-02 19:48:18 +0300545 acpi_owner_id owner_id;
Bob Moore8a335a232009-03-09 16:31:04 +0800546 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Bob Moore8a335a232009-03-09 16:31:04 +0800548 ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner);
549
550 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
551 if (ACPI_FAILURE(status)) {
552 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 }
554
Bob Mooreb9ee2042010-04-27 11:16:14 +0800555 if (table_index >= acpi_gbl_root_table_list.current_table_count) {
Bob Moore8a335a232009-03-09 16:31:04 +0800556
557 /* The table index does not exist */
558
559 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
560 return_ACPI_STATUS(AE_NOT_EXIST);
561 }
562
563 /* Get the owner ID for this table, used to delete namespace nodes */
564
565 owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id;
Len Brown4be44fc2005-08-05 00:44:28 -0400566 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Bob Moore8a335a232009-03-09 16:31:04 +0800567
568 /*
569 * Need to acquire the namespace writer lock to prevent interference
570 * with any concurrent namespace walks. The interpreter must be
571 * released during the deletion since the acquisition of the deletion
572 * lock may block, and also since the execution of a namespace walk
573 * must be allowed to use the interpreter.
574 */
Bob Mooree4c1ebf2009-04-22 13:02:06 +0800575 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
Bob Moore8a335a232009-03-09 16:31:04 +0800576 status = acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock);
577
Bob Mooref3d2e782007-02-02 19:48:18 +0300578 acpi_ns_delete_namespace_by_owner(owner_id);
Bob Moore8a335a232009-03-09 16:31:04 +0800579 if (ACPI_FAILURE(status)) {
580 return_ACPI_STATUS(status);
581 }
582
583 acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock);
584
585 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
586 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587}
588
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589/*******************************************************************************
590 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300591 * FUNCTION: acpi_tb_allocate_owner_id
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300593 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300595 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300597 * DESCRIPTION: Allocates owner_id in table_desc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 *
599 ******************************************************************************/
600
Bob Moore67a119f2008-06-10 13:42:13 +0800601acpi_status acpi_tb_allocate_owner_id(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
Bob Mooref3d2e782007-02-02 19:48:18 +0300603 acpi_status status = AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Bob Mooref3d2e782007-02-02 19:48:18 +0300605 ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Bob Mooref3d2e782007-02-02 19:48:18 +0300607 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +0800608 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300609 status = acpi_ut_allocate_owner_id
610 (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 }
612
Bob Mooref3d2e782007-02-02 19:48:18 +0300613 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
614 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615}
616
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617/*******************************************************************************
618 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300619 * FUNCTION: acpi_tb_release_owner_id
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300621 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300623 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300625 * DESCRIPTION: Releases owner_id in table_desc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 *
627 ******************************************************************************/
628
Bob Moore67a119f2008-06-10 13:42:13 +0800629acpi_status acpi_tb_release_owner_id(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630{
Bob Mooref3d2e782007-02-02 19:48:18 +0300631 acpi_status status = AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Bob Mooref3d2e782007-02-02 19:48:18 +0300633 ACPI_FUNCTION_TRACE(tb_release_owner_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Bob Mooref3d2e782007-02-02 19:48:18 +0300635 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +0800636 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300637 acpi_ut_release_owner_id(&
638 (acpi_gbl_root_table_list.
639 tables[table_index].owner_id));
640 status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 }
642
Bob Mooref3d2e782007-02-02 19:48:18 +0300643 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
644 return_ACPI_STATUS(status);
645}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Bob Mooref3d2e782007-02-02 19:48:18 +0300647/*******************************************************************************
648 *
649 * FUNCTION: acpi_tb_get_owner_id
650 *
651 * PARAMETERS: table_index - Table index
652 * owner_id - Where the table owner_id is returned
653 *
654 * RETURN: Status
655 *
656 * DESCRIPTION: returns owner_id for the ACPI table
657 *
658 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Bob Moore67a119f2008-06-10 13:42:13 +0800660acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id)
Bob Mooref3d2e782007-02-02 19:48:18 +0300661{
662 acpi_status status = AE_BAD_PARAMETER;
663
664 ACPI_FUNCTION_TRACE(tb_get_owner_id);
665
666 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +0800667 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300668 *owner_id =
669 acpi_gbl_root_table_list.tables[table_index].owner_id;
670 status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 }
672
Bob Mooref3d2e782007-02-02 19:48:18 +0300673 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
674 return_ACPI_STATUS(status);
675}
676
677/*******************************************************************************
678 *
679 * FUNCTION: acpi_tb_is_table_loaded
680 *
681 * PARAMETERS: table_index - Table index
682 *
683 * RETURN: Table Loaded Flag
684 *
685 ******************************************************************************/
686
Bob Moore67a119f2008-06-10 13:42:13 +0800687u8 acpi_tb_is_table_loaded(u32 table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +0300688{
689 u8 is_loaded = FALSE;
690
691 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +0800692 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300693 is_loaded = (u8)
Bob Mooreec41f192009-02-18 15:03:30 +0800694 (acpi_gbl_root_table_list.tables[table_index].flags &
695 ACPI_TABLE_IS_LOADED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 }
697
Bob Mooref3d2e782007-02-02 19:48:18 +0300698 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
699 return (is_loaded);
700}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Bob Mooref3d2e782007-02-02 19:48:18 +0300702/*******************************************************************************
703 *
704 * FUNCTION: acpi_tb_set_table_loaded_flag
705 *
706 * PARAMETERS: table_index - Table index
707 * is_loaded - TRUE if table is loaded, FALSE otherwise
708 *
709 * RETURN: None
710 *
711 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
712 *
713 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
Bob Moore67a119f2008-06-10 13:42:13 +0800715void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
Bob Mooref3d2e782007-02-02 19:48:18 +0300716{
Bob Mooref6dd9222006-07-07 20:44:38 -0400717
Bob Mooref3d2e782007-02-02 19:48:18 +0300718 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +0800719 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300720 if (is_loaded) {
721 acpi_gbl_root_table_list.tables[table_index].flags |=
Bob Moorec5fc42a2007-02-02 19:48:19 +0300722 ACPI_TABLE_IS_LOADED;
Bob Mooref3d2e782007-02-02 19:48:18 +0300723 } else {
724 acpi_gbl_root_table_list.tables[table_index].flags &=
Bob Moorec5fc42a2007-02-02 19:48:19 +0300725 ~ACPI_TABLE_IS_LOADED;
Bob Mooref3d2e782007-02-02 19:48:18 +0300726 }
727 }
Bob Mooref6dd9222006-07-07 20:44:38 -0400728
Bob Mooref3d2e782007-02-02 19:48:18 +0300729 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730}