blob: c03500b4cc7ac999bc757205fd765708745220a9 [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))) {
141 ACPI_ERROR((AE_INFO,
142 "Table has invalid signature [%4.4s] (0x%8.8X), must be SSDT or OEMx",
143 acpi_ut_valid_acpi_name(*(u32 *)table_desc->
144 pointer->
145 signature) ? table_desc->
146 pointer->signature : "????",
147 *(u32 *)table_desc->pointer->signature));
148
149 return_ACPI_STATUS(AE_BAD_SIGNATURE);
150 }
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300151
Bob Mooref3d2e782007-02-02 19:48:18 +0300152 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Bob Mooref3d2e782007-02-02 19:48:18 +0300154 /* Check if table is already registered */
155
Bob Mooreb9ee2042010-04-27 11:16:14 +0800156 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300157 if (!acpi_gbl_root_table_list.tables[i].pointer) {
158 status =
159 acpi_tb_verify_table(&acpi_gbl_root_table_list.
160 tables[i]);
161 if (ACPI_FAILURE(status)
162 || !acpi_gbl_root_table_list.tables[i].pointer) {
163 continue;
164 }
165 }
166
Bob Moorea6f30532008-07-04 10:57:51 +0800167 /*
168 * Check for a table match on the entire table length,
169 * not just the header.
170 */
171 if (table_desc->length !=
172 acpi_gbl_root_table_list.tables[i].length) {
173 continue;
174 }
Bob Mooree56f5612008-07-04 10:48:43 +0800175
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300176 if (ACPI_MEMCMP(table_desc->pointer,
177 acpi_gbl_root_table_list.tables[i].pointer,
Bob Moorea6f30532008-07-04 10:57:51 +0800178 acpi_gbl_root_table_list.tables[i].length)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300179 continue;
180 }
181
Bob Mooree56f5612008-07-04 10:48:43 +0800182 /*
183 * Note: the current mechanism does not unregister a table if it is
184 * dynamically unloaded. The related namespace entries are deleted,
185 * but the table remains in the root table list.
186 *
187 * The assumption here is that the number of different tables that
188 * will be loaded is actually small, and there is minimal overhead
189 * in just keeping the table in case it is needed again.
190 *
191 * If this assumption changes in the future (perhaps on large
192 * machines with many table load/unload operations), tables will
193 * need to be unregistered when they are unloaded, and slots in the
194 * root table list should be reused when empty.
195 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300196
Bob Mooree56f5612008-07-04 10:48:43 +0800197 /*
198 * Table is already registered.
199 * We can delete the table that was passed as a parameter.
200 */
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300201 acpi_tb_delete_table(table_desc);
Bob Mooref3d2e782007-02-02 19:48:18 +0300202 *table_index = i;
Bob Mooree56f5612008-07-04 10:48:43 +0800203
204 if (acpi_gbl_root_table_list.tables[i].
205 flags & ACPI_TABLE_IS_LOADED) {
206
207 /* Table is still loaded, this is an error */
208
209 status = AE_ALREADY_EXISTS;
210 goto release;
211 } else {
212 /* Table was unloaded, allow it to be reloaded */
213
214 table_desc->pointer =
215 acpi_gbl_root_table_list.tables[i].pointer;
216 table_desc->address =
217 acpi_gbl_root_table_list.tables[i].address;
218 status = AE_OK;
219 goto print_header;
220 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 }
222
Bob Moored3ccaff2009-02-03 14:43:04 +0800223 /*
224 * ACPI Table Override:
225 * Allow the host to override dynamically loaded tables.
Bob Mooref7b004a2012-02-14 18:31:56 +0800226 * NOTE: the table is fully mapped at this point, and the mapping will
227 * be deleted by tb_table_override if the table is actually overridden.
Bob Moored3ccaff2009-02-03 14:43:04 +0800228 */
Bob Mooref7b004a2012-02-14 18:31:56 +0800229 (void)acpi_tb_table_override(table_desc->pointer, table_desc);
Bob Moored3ccaff2009-02-03 14:43:04 +0800230
Bob Mooree56f5612008-07-04 10:48:43 +0800231 /* Add the table to the global root table list */
232
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300233 status = acpi_tb_store_table(table_desc->address, table_desc->pointer,
234 table_desc->length, table_desc->flags,
235 table_index);
Len Brown4be44fc2005-08-05 00:44:28 -0400236 if (ACPI_FAILURE(status)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300237 goto release;
Robert Moore0c9938c2005-07-29 15:15:00 -0700238 }
239
Bob Mooree56f5612008-07-04 10:48:43 +0800240 print_header:
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300241 acpi_tb_print_table_header(table_desc->address, table_desc->pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Bob Mooref3d2e782007-02-02 19:48:18 +0300243 release:
Len Brown4be44fc2005-08-05 00:44:28 -0400244 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
245 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246}
247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248/*******************************************************************************
249 *
Bob Mooref7b004a2012-02-14 18:31:56 +0800250 * FUNCTION: acpi_tb_table_override
251 *
252 * PARAMETERS: table_header - Header for the original table
253 * table_desc - Table descriptor initialized for the
254 * original table. May or may not be mapped.
255 *
256 * RETURN: Pointer to the entire new table. NULL if table not overridden.
257 * If overridden, installs the new table within the input table
258 * descriptor.
259 *
260 * DESCRIPTION: Attempt table override by calling the OSL override functions.
261 * Note: If the table is overridden, then the entire new table
262 * is mapped and returned by this function.
263 *
264 ******************************************************************************/
265
266struct acpi_table_header *acpi_tb_table_override(struct acpi_table_header
267 *table_header,
268 struct acpi_table_desc
269 *table_desc)
270{
271 acpi_status status;
272 struct acpi_table_header *new_table = NULL;
273 acpi_physical_address new_address = 0;
274 u32 new_table_length = 0;
275 u8 new_flags;
276 char *override_type;
277
278 /* (1) Attempt logical override (returns a logical address) */
279
280 status = acpi_os_table_override(table_header, &new_table);
281 if (ACPI_SUCCESS(status) && new_table) {
282 new_address = ACPI_PTR_TO_PHYSADDR(new_table);
283 new_table_length = new_table->length;
284 new_flags = ACPI_TABLE_ORIGIN_OVERRIDE;
285 override_type = "Logical";
286 goto finish_override;
287 }
288
289 /* (2) Attempt physical override (returns a physical address) */
290
291 status = acpi_os_physical_table_override(table_header,
292 &new_address,
293 &new_table_length);
294 if (ACPI_SUCCESS(status) && new_address && new_table_length) {
295
296 /* Map the entire new table */
297
298 new_table = acpi_os_map_memory(new_address, new_table_length);
299 if (!new_table) {
300 ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY,
301 "%4.4s %p Attempted physical table override failed",
302 table_header->signature,
303 ACPI_CAST_PTR(void,
304 table_desc->address)));
305 return (NULL);
306 }
307
308 override_type = "Physical";
309 new_flags = ACPI_TABLE_ORIGIN_MAPPED;
310 goto finish_override;
311 }
312
313 return (NULL); /* There was no override */
314
315 finish_override:
316
317 ACPI_INFO((AE_INFO,
318 "%4.4s %p %s table override, new table: %p",
319 table_header->signature,
320 ACPI_CAST_PTR(void, table_desc->address),
321 override_type, new_table));
322
323 /* We can now unmap/delete the original table (if fully mapped) */
324
325 acpi_tb_delete_table(table_desc);
326
327 /* Setup descriptor for the new table */
328
329 table_desc->address = new_address;
330 table_desc->pointer = new_table;
331 table_desc->length = new_table_length;
332 table_desc->flags = new_flags;
333
334 return (new_table);
335}
336
337/*******************************************************************************
338 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300339 * FUNCTION: acpi_tb_resize_root_table_list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300341 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 *
343 * RETURN: Status
344 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300345 * DESCRIPTION: Expand the size of global table array
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 *
347 ******************************************************************************/
348
Bob Mooref3d2e782007-02-02 19:48:18 +0300349acpi_status acpi_tb_resize_root_table_list(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350{
Bob Mooref3d2e782007-02-02 19:48:18 +0300351 struct acpi_table_desc *tables;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Bob Mooref3d2e782007-02-02 19:48:18 +0300353 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Bob Mooref3d2e782007-02-02 19:48:18 +0300355 /* allow_resize flag is a parameter to acpi_initialize_tables */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Bob Moorec5fc42a2007-02-02 19:48:19 +0300357 if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300358 ACPI_ERROR((AE_INFO,
359 "Resize of Root Table Array is not allowed"));
360 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
362
Bob Mooref3d2e782007-02-02 19:48:18 +0300363 /* Increase the Table Array size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Bob Moore67a119f2008-06-10 13:42:13 +0800365 tables = ACPI_ALLOCATE_ZEROED(((acpi_size) acpi_gbl_root_table_list.
Bob Mooreb9ee2042010-04-27 11:16:14 +0800366 max_table_count +
Bob Mooreec41f192009-02-18 15:03:30 +0800367 ACPI_ROOT_TABLE_SIZE_INCREMENT) *
368 sizeof(struct acpi_table_desc));
Bob Mooref3d2e782007-02-02 19:48:18 +0300369 if (!tables) {
370 ACPI_ERROR((AE_INFO,
371 "Could not allocate new root table array"));
Len Brown4be44fc2005-08-05 00:44:28 -0400372 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 }
374
Bob Mooref3d2e782007-02-02 19:48:18 +0300375 /* Copy and free the previous table array */
Robert Mooref9f46012005-07-08 00:00:00 -0400376
Bob Mooref3d2e782007-02-02 19:48:18 +0300377 if (acpi_gbl_root_table_list.tables) {
378 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
Bob Mooreb9ee2042010-04-27 11:16:14 +0800379 (acpi_size) acpi_gbl_root_table_list.
380 max_table_count * sizeof(struct acpi_table_desc));
Robert Mooref9f46012005-07-08 00:00:00 -0400381
Bob Moorec5fc42a2007-02-02 19:48:19 +0300382 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300383 ACPI_FREE(acpi_gbl_root_table_list.tables);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 }
385 }
386
Bob Mooref3d2e782007-02-02 19:48:18 +0300387 acpi_gbl_root_table_list.tables = tables;
Bob Mooreb9ee2042010-04-27 11:16:14 +0800388 acpi_gbl_root_table_list.max_table_count +=
389 ACPI_ROOT_TABLE_SIZE_INCREMENT;
390 acpi_gbl_root_table_list.flags |= (u8)ACPI_ROOT_ORIGIN_ALLOCATED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Len Brown4be44fc2005-08-05 00:44:28 -0400392 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393}
394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395/*******************************************************************************
396 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300397 * FUNCTION: acpi_tb_store_table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300399 * PARAMETERS: Address - Table address
400 * Table - Table header
401 * Length - Table length
402 * Flags - flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300404 * RETURN: Status and table index.
405 *
406 * DESCRIPTION: Add an ACPI table to the global table list
407 *
408 ******************************************************************************/
409
410acpi_status
411acpi_tb_store_table(acpi_physical_address address,
412 struct acpi_table_header *table,
Bob Moore67a119f2008-06-10 13:42:13 +0800413 u32 length, u8 flags, u32 *table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +0300414{
Bob Mooreb9ee2042010-04-27 11:16:14 +0800415 acpi_status status;
416 struct acpi_table_desc *new_table;
Bob Mooref3d2e782007-02-02 19:48:18 +0300417
418 /* Ensure that there is room for the table in the Root Table List */
419
Bob Mooreb9ee2042010-04-27 11:16:14 +0800420 if (acpi_gbl_root_table_list.current_table_count >=
421 acpi_gbl_root_table_list.max_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300422 status = acpi_tb_resize_root_table_list();
423 if (ACPI_FAILURE(status)) {
424 return (status);
425 }
426 }
427
Bob Mooreb9ee2042010-04-27 11:16:14 +0800428 new_table =
429 &acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.
430 current_table_count];
431
Bob Mooref3d2e782007-02-02 19:48:18 +0300432 /* Initialize added table */
433
Bob Mooreb9ee2042010-04-27 11:16:14 +0800434 new_table->address = address;
435 new_table->pointer = table;
436 new_table->length = length;
437 new_table->owner_id = 0;
438 new_table->flags = flags;
Bob Mooref3d2e782007-02-02 19:48:18 +0300439
Bob Mooreb9ee2042010-04-27 11:16:14 +0800440 ACPI_MOVE_32_TO_32(&new_table->signature, table->signature);
Bob Mooref3d2e782007-02-02 19:48:18 +0300441
Bob Mooreb9ee2042010-04-27 11:16:14 +0800442 *table_index = acpi_gbl_root_table_list.current_table_count;
443 acpi_gbl_root_table_list.current_table_count++;
444 return (AE_OK);
Bob Mooref3d2e782007-02-02 19:48:18 +0300445}
446
447/*******************************************************************************
448 *
449 * FUNCTION: acpi_tb_delete_table
450 *
451 * PARAMETERS: table_index - Table index
452 *
453 * RETURN: None
454 *
455 * DESCRIPTION: Delete one internal ACPI table
456 *
457 ******************************************************************************/
458
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300459void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
Bob Mooref3d2e782007-02-02 19:48:18 +0300460{
Bob Mooref3d2e782007-02-02 19:48:18 +0300461 /* Table must be mapped or allocated */
Bob Mooref3d2e782007-02-02 19:48:18 +0300462 if (!table_desc->pointer) {
463 return;
464 }
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300465 switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
466 case ACPI_TABLE_ORIGIN_MAPPED:
467 acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
468 break;
469 case ACPI_TABLE_ORIGIN_ALLOCATED:
Bob Mooref3d2e782007-02-02 19:48:18 +0300470 ACPI_FREE(table_desc->pointer);
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300471 break;
Bob Mooref7b004a2012-02-14 18:31:56 +0800472
473 /* Not mapped or allocated, there is nothing we can do */
474
475 default:
476 return;
Bob Mooref3d2e782007-02-02 19:48:18 +0300477 }
478
479 table_desc->pointer = NULL;
480}
481
482/*******************************************************************************
483 *
484 * FUNCTION: acpi_tb_terminate
485 *
486 * PARAMETERS: None
487 *
488 * RETURN: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 *
490 * DESCRIPTION: Delete all internal ACPI tables
491 *
492 ******************************************************************************/
493
Bob Mooref3d2e782007-02-02 19:48:18 +0300494void acpi_tb_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495{
Bob Moore67a119f2008-06-10 13:42:13 +0800496 u32 i;
Bob Mooref3d2e782007-02-02 19:48:18 +0300497
498 ACPI_FUNCTION_TRACE(tb_terminate);
499
500 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
501
502 /* Delete the individual tables */
503
Bob Mooreb9ee2042010-04-27 11:16:14 +0800504 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300505 acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]);
Bob Mooref3d2e782007-02-02 19:48:18 +0300506 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
508 /*
Bob Mooref3d2e782007-02-02 19:48:18 +0300509 * Delete the root table array if allocated locally. Array cannot be
510 * mapped, so we don't need to check for that flag.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300512 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300513 ACPI_FREE(acpi_gbl_root_table_list.tables);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300515
516 acpi_gbl_root_table_list.tables = NULL;
517 acpi_gbl_root_table_list.flags = 0;
Bob Mooreb9ee2042010-04-27 11:16:14 +0800518 acpi_gbl_root_table_list.current_table_count = 0;
Bob Mooref3d2e782007-02-02 19:48:18 +0300519
520 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
521 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522}
523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524/*******************************************************************************
525 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300526 * FUNCTION: acpi_tb_delete_namespace_by_owner
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300528 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 *
Bob Moore8a335a232009-03-09 16:31:04 +0800530 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300532 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 *
534 ******************************************************************************/
535
Bob Moore8a335a232009-03-09 16:31:04 +0800536acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537{
Bob Mooref3d2e782007-02-02 19:48:18 +0300538 acpi_owner_id owner_id;
Bob Moore8a335a232009-03-09 16:31:04 +0800539 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Bob Moore8a335a232009-03-09 16:31:04 +0800541 ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner);
542
543 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
544 if (ACPI_FAILURE(status)) {
545 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 }
547
Bob Mooreb9ee2042010-04-27 11:16:14 +0800548 if (table_index >= acpi_gbl_root_table_list.current_table_count) {
Bob Moore8a335a232009-03-09 16:31:04 +0800549
550 /* The table index does not exist */
551
552 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
553 return_ACPI_STATUS(AE_NOT_EXIST);
554 }
555
556 /* Get the owner ID for this table, used to delete namespace nodes */
557
558 owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id;
Len Brown4be44fc2005-08-05 00:44:28 -0400559 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Bob Moore8a335a232009-03-09 16:31:04 +0800560
561 /*
562 * Need to acquire the namespace writer lock to prevent interference
563 * with any concurrent namespace walks. The interpreter must be
564 * released during the deletion since the acquisition of the deletion
565 * lock may block, and also since the execution of a namespace walk
566 * must be allowed to use the interpreter.
567 */
Bob Mooree4c1ebf2009-04-22 13:02:06 +0800568 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
Bob Moore8a335a232009-03-09 16:31:04 +0800569 status = acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock);
570
Bob Mooref3d2e782007-02-02 19:48:18 +0300571 acpi_ns_delete_namespace_by_owner(owner_id);
Bob Moore8a335a232009-03-09 16:31:04 +0800572 if (ACPI_FAILURE(status)) {
573 return_ACPI_STATUS(status);
574 }
575
576 acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock);
577
578 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
579 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580}
581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582/*******************************************************************************
583 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300584 * FUNCTION: acpi_tb_allocate_owner_id
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300586 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300588 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300590 * DESCRIPTION: Allocates owner_id in table_desc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 *
592 ******************************************************************************/
593
Bob Moore67a119f2008-06-10 13:42:13 +0800594acpi_status acpi_tb_allocate_owner_id(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595{
Bob Mooref3d2e782007-02-02 19:48:18 +0300596 acpi_status status = AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Bob Mooref3d2e782007-02-02 19:48:18 +0300598 ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Bob Mooref3d2e782007-02-02 19:48:18 +0300600 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +0800601 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300602 status = acpi_ut_allocate_owner_id
603 (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 }
605
Bob Mooref3d2e782007-02-02 19:48:18 +0300606 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
607 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608}
609
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610/*******************************************************************************
611 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300612 * FUNCTION: acpi_tb_release_owner_id
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300614 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300616 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300618 * DESCRIPTION: Releases owner_id in table_desc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 *
620 ******************************************************************************/
621
Bob Moore67a119f2008-06-10 13:42:13 +0800622acpi_status acpi_tb_release_owner_id(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623{
Bob Mooref3d2e782007-02-02 19:48:18 +0300624 acpi_status status = AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Bob Mooref3d2e782007-02-02 19:48:18 +0300626 ACPI_FUNCTION_TRACE(tb_release_owner_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Bob Mooref3d2e782007-02-02 19:48:18 +0300628 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +0800629 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300630 acpi_ut_release_owner_id(&
631 (acpi_gbl_root_table_list.
632 tables[table_index].owner_id));
633 status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 }
635
Bob Mooref3d2e782007-02-02 19:48:18 +0300636 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
637 return_ACPI_STATUS(status);
638}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
Bob Mooref3d2e782007-02-02 19:48:18 +0300640/*******************************************************************************
641 *
642 * FUNCTION: acpi_tb_get_owner_id
643 *
644 * PARAMETERS: table_index - Table index
645 * owner_id - Where the table owner_id is returned
646 *
647 * RETURN: Status
648 *
649 * DESCRIPTION: returns owner_id for the ACPI table
650 *
651 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Bob Moore67a119f2008-06-10 13:42:13 +0800653acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id)
Bob Mooref3d2e782007-02-02 19:48:18 +0300654{
655 acpi_status status = AE_BAD_PARAMETER;
656
657 ACPI_FUNCTION_TRACE(tb_get_owner_id);
658
659 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +0800660 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300661 *owner_id =
662 acpi_gbl_root_table_list.tables[table_index].owner_id;
663 status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 }
665
Bob Mooref3d2e782007-02-02 19:48:18 +0300666 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
667 return_ACPI_STATUS(status);
668}
669
670/*******************************************************************************
671 *
672 * FUNCTION: acpi_tb_is_table_loaded
673 *
674 * PARAMETERS: table_index - Table index
675 *
676 * RETURN: Table Loaded Flag
677 *
678 ******************************************************************************/
679
Bob Moore67a119f2008-06-10 13:42:13 +0800680u8 acpi_tb_is_table_loaded(u32 table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +0300681{
682 u8 is_loaded = FALSE;
683
684 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +0800685 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300686 is_loaded = (u8)
Bob Mooreec41f192009-02-18 15:03:30 +0800687 (acpi_gbl_root_table_list.tables[table_index].flags &
688 ACPI_TABLE_IS_LOADED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 }
690
Bob Mooref3d2e782007-02-02 19:48:18 +0300691 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
692 return (is_loaded);
693}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
Bob Mooref3d2e782007-02-02 19:48:18 +0300695/*******************************************************************************
696 *
697 * FUNCTION: acpi_tb_set_table_loaded_flag
698 *
699 * PARAMETERS: table_index - Table index
700 * is_loaded - TRUE if table is loaded, FALSE otherwise
701 *
702 * RETURN: None
703 *
704 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
705 *
706 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
Bob Moore67a119f2008-06-10 13:42:13 +0800708void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
Bob Mooref3d2e782007-02-02 19:48:18 +0300709{
Bob Mooref6dd9222006-07-07 20:44:38 -0400710
Bob Mooref3d2e782007-02-02 19:48:18 +0300711 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +0800712 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300713 if (is_loaded) {
714 acpi_gbl_root_table_list.tables[table_index].flags |=
Bob Moorec5fc42a2007-02-02 19:48:19 +0300715 ACPI_TABLE_IS_LOADED;
Bob Mooref3d2e782007-02-02 19:48:18 +0300716 } else {
717 acpi_gbl_root_table_list.tables[table_index].flags &=
Bob Moorec5fc42a2007-02-02 19:48:19 +0300718 ~ACPI_TABLE_IS_LOADED;
Bob Mooref3d2e782007-02-02 19:48:18 +0300719 }
720 }
Bob Mooref6dd9222006-07-07 20:44:38 -0400721
Bob Mooref3d2e782007-02-02 19:48:18 +0300722 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723}