blob: 73fffb0f3dd3798e8e16096e7665e73d06f31d25 [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 Moorefbb7a2d2014-02-08 09:42:25 +08008 * Copyright (C) 2000 - 2014, 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 }
Lv Zheng55829822014-04-04 12:38:18 +080078
Bob Mooref3d2e782007-02-02 19:48:18 +030079 if (!table_desc->pointer) {
80 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 }
82 }
83
Lv Zheng94d4be62013-09-23 09:52:29 +080084 /* Always calculate checksum, ignore bad checksum if requested */
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Lv Zheng94d4be62013-09-23 09:52:29 +080086 status =
87 acpi_tb_verify_checksum(table_desc->pointer, table_desc->length);
Bob Mooref3d2e782007-02-02 19:48:18 +030088
Bob Moorec5fc42a2007-02-02 19:48:19 +030089 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092/*******************************************************************************
93 *
Bob Mooref3d2e782007-02-02 19:48:18 +030094 * FUNCTION: acpi_tb_add_table
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 *
Alexey Starikovskiy428f2112007-02-02 19:48:22 +030096 * PARAMETERS: table_desc - Table descriptor
Bob Mooref3d2e782007-02-02 19:48:18 +030097 * table_index - Where the table index is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 *
99 * RETURN: Status
100 *
Bob Moored3ccaff2009-02-03 14:43:04 +0800101 * DESCRIPTION: This function is called to add an ACPI table. It is used to
102 * dynamically load tables via the Load and load_table AML
103 * operators.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 *
105 ******************************************************************************/
106
Bob Mooref3d2e782007-02-02 19:48:18 +0300107acpi_status
Bob Moore67a119f2008-06-10 13:42:13 +0800108acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
Bob Moore67a119f2008-06-10 13:42:13 +0800110 u32 i;
Bob Mooref3d2e782007-02-02 19:48:18 +0300111 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Bob Mooref3d2e782007-02-02 19:48:18 +0300113 ACPI_FUNCTION_TRACE(tb_add_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300115 if (!table_desc->pointer) {
116 status = acpi_tb_verify_table(table_desc);
117 if (ACPI_FAILURE(status) || !table_desc->pointer) {
118 return_ACPI_STATUS(status);
119 }
120 }
121
Bob Moorebc45b1d2008-06-10 14:12:50 +0800122 /*
Bob Moorec8cefe32011-06-14 10:42:53 +0800123 * Validate the incoming table signature.
124 *
125 * 1) Originally, we checked the table signature for "SSDT" or "PSDT".
126 * 2) We added support for OEMx tables, signature "OEM".
127 * 3) Valid tables were encountered with a null signature, so we just
128 * gave up on validating the signature, (05/2008).
129 * 4) We encountered non-AML tables such as the MADT, which caused
130 * interpreter errors and kernel faults. So now, we once again allow
131 * only "SSDT", "OEMx", and now, also a null signature. (05/2011).
Bob Moorebc45b1d2008-06-10 14:12:50 +0800132 */
Bob Moorec8cefe32011-06-14 10:42:53 +0800133 if ((table_desc->pointer->signature[0] != 0x00) &&
134 (!ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_SSDT))
135 && (ACPI_STRNCMP(table_desc->pointer->signature, "OEM", 3))) {
Bob Moore3b3ea772012-07-16 09:39:54 +0800136 ACPI_BIOS_ERROR((AE_INFO,
137 "Table has invalid signature [%4.4s] (0x%8.8X), "
138 "must be SSDT or OEMx",
Bob Moorede8e7db2013-06-08 00:59:44 +0000139 acpi_ut_valid_acpi_name(table_desc->pointer->
Bob Moore3b3ea772012-07-16 09:39:54 +0800140 signature) ?
141 table_desc->pointer->signature : "????",
142 *(u32 *)table_desc->pointer->signature));
Bob Moorec8cefe32011-06-14 10:42:53 +0800143
144 return_ACPI_STATUS(AE_BAD_SIGNATURE);
145 }
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300146
Bob Mooref3d2e782007-02-02 19:48:18 +0300147 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Bob Mooref3d2e782007-02-02 19:48:18 +0300149 /* Check if table is already registered */
150
Bob Mooreb9ee2042010-04-27 11:16:14 +0800151 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300152 if (!acpi_gbl_root_table_list.tables[i].pointer) {
153 status =
154 acpi_tb_verify_table(&acpi_gbl_root_table_list.
155 tables[i]);
156 if (ACPI_FAILURE(status)
157 || !acpi_gbl_root_table_list.tables[i].pointer) {
158 continue;
159 }
160 }
161
Bob Moorea6f30532008-07-04 10:57:51 +0800162 /*
163 * Check for a table match on the entire table length,
164 * not just the header.
165 */
166 if (table_desc->length !=
167 acpi_gbl_root_table_list.tables[i].length) {
168 continue;
169 }
Bob Mooree56f5612008-07-04 10:48:43 +0800170
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300171 if (ACPI_MEMCMP(table_desc->pointer,
172 acpi_gbl_root_table_list.tables[i].pointer,
Bob Moorea6f30532008-07-04 10:57:51 +0800173 acpi_gbl_root_table_list.tables[i].length)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300174 continue;
175 }
176
Bob Mooree56f5612008-07-04 10:48:43 +0800177 /*
178 * Note: the current mechanism does not unregister a table if it is
179 * dynamically unloaded. The related namespace entries are deleted,
180 * but the table remains in the root table list.
181 *
182 * The assumption here is that the number of different tables that
183 * will be loaded is actually small, and there is minimal overhead
184 * in just keeping the table in case it is needed again.
185 *
186 * If this assumption changes in the future (perhaps on large
187 * machines with many table load/unload operations), tables will
188 * need to be unregistered when they are unloaded, and slots in the
189 * root table list should be reused when empty.
190 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300191
Bob Mooree56f5612008-07-04 10:48:43 +0800192 /*
193 * Table is already registered.
194 * We can delete the table that was passed as a parameter.
195 */
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300196 acpi_tb_delete_table(table_desc);
Bob Mooref3d2e782007-02-02 19:48:18 +0300197 *table_index = i;
Bob Mooree56f5612008-07-04 10:48:43 +0800198
199 if (acpi_gbl_root_table_list.tables[i].
200 flags & ACPI_TABLE_IS_LOADED) {
201
202 /* Table is still loaded, this is an error */
203
204 status = AE_ALREADY_EXISTS;
205 goto release;
206 } else {
207 /* Table was unloaded, allow it to be reloaded */
208
209 table_desc->pointer =
210 acpi_gbl_root_table_list.tables[i].pointer;
211 table_desc->address =
212 acpi_gbl_root_table_list.tables[i].address;
213 status = AE_OK;
214 goto print_header;
215 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 }
217
Bob Moored3ccaff2009-02-03 14:43:04 +0800218 /*
219 * ACPI Table Override:
220 * Allow the host to override dynamically loaded tables.
Bob Mooref7b004a2012-02-14 18:31:56 +0800221 * NOTE: the table is fully mapped at this point, and the mapping will
222 * be deleted by tb_table_override if the table is actually overridden.
Bob Moored3ccaff2009-02-03 14:43:04 +0800223 */
Bob Mooref7b004a2012-02-14 18:31:56 +0800224 (void)acpi_tb_table_override(table_desc->pointer, table_desc);
Bob Moored3ccaff2009-02-03 14:43:04 +0800225
Bob Mooree56f5612008-07-04 10:48:43 +0800226 /* Add the table to the global root table list */
227
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300228 status = acpi_tb_store_table(table_desc->address, table_desc->pointer,
229 table_desc->length, table_desc->flags,
230 table_index);
Len Brown4be44fc2005-08-05 00:44:28 -0400231 if (ACPI_FAILURE(status)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300232 goto release;
Robert Moore0c9938c2005-07-29 15:15:00 -0700233 }
234
Lv Zheng10622bf2013-10-29 09:30:02 +0800235print_header:
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300236 acpi_tb_print_table_header(table_desc->address, table_desc->pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Lv Zheng10622bf2013-10-29 09:30:02 +0800238release:
Len Brown4be44fc2005-08-05 00:44:28 -0400239 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
240 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241}
242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243/*******************************************************************************
244 *
Bob Mooref7b004a2012-02-14 18:31:56 +0800245 * FUNCTION: acpi_tb_table_override
246 *
247 * PARAMETERS: table_header - Header for the original table
248 * table_desc - Table descriptor initialized for the
249 * original table. May or may not be mapped.
250 *
251 * RETURN: Pointer to the entire new table. NULL if table not overridden.
252 * If overridden, installs the new table within the input table
253 * descriptor.
254 *
255 * DESCRIPTION: Attempt table override by calling the OSL override functions.
256 * Note: If the table is overridden, then the entire new table
257 * is mapped and returned by this function.
258 *
259 ******************************************************************************/
260
261struct acpi_table_header *acpi_tb_table_override(struct acpi_table_header
262 *table_header,
263 struct acpi_table_desc
264 *table_desc)
265{
266 acpi_status status;
267 struct acpi_table_header *new_table = NULL;
268 acpi_physical_address new_address = 0;
269 u32 new_table_length = 0;
270 u8 new_flags;
271 char *override_type;
272
273 /* (1) Attempt logical override (returns a logical address) */
274
275 status = acpi_os_table_override(table_header, &new_table);
276 if (ACPI_SUCCESS(status) && new_table) {
277 new_address = ACPI_PTR_TO_PHYSADDR(new_table);
278 new_table_length = new_table->length;
279 new_flags = ACPI_TABLE_ORIGIN_OVERRIDE;
280 override_type = "Logical";
281 goto finish_override;
282 }
283
284 /* (2) Attempt physical override (returns a physical address) */
285
286 status = acpi_os_physical_table_override(table_header,
287 &new_address,
288 &new_table_length);
289 if (ACPI_SUCCESS(status) && new_address && new_table_length) {
290
291 /* Map the entire new table */
292
293 new_table = acpi_os_map_memory(new_address, new_table_length);
294 if (!new_table) {
295 ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY,
Bob Moore2e19f8d2014-02-08 09:42:07 +0800296 "%4.4s " ACPI_PRINTF_UINT
297 " Attempted physical table override failed",
Bob Mooref7b004a2012-02-14 18:31:56 +0800298 table_header->signature,
Bob Moore2e19f8d2014-02-08 09:42:07 +0800299 ACPI_FORMAT_TO_UINT(table_desc->
300 address)));
Bob Mooref7b004a2012-02-14 18:31:56 +0800301 return (NULL);
302 }
303
304 override_type = "Physical";
305 new_flags = ACPI_TABLE_ORIGIN_MAPPED;
306 goto finish_override;
307 }
308
309 return (NULL); /* There was no override */
310
Lv Zheng10622bf2013-10-29 09:30:02 +0800311finish_override:
Bob Mooref7b004a2012-02-14 18:31:56 +0800312
Bob Moore2e19f8d2014-02-08 09:42:07 +0800313 ACPI_INFO((AE_INFO, "%4.4s " ACPI_PRINTF_UINT
314 " %s table override, new table: " ACPI_PRINTF_UINT,
Bob Mooref7b004a2012-02-14 18:31:56 +0800315 table_header->signature,
Bob Moore2e19f8d2014-02-08 09:42:07 +0800316 ACPI_FORMAT_TO_UINT(table_desc->address),
317 override_type, ACPI_FORMAT_TO_UINT(new_table)));
Bob Mooref7b004a2012-02-14 18:31:56 +0800318
319 /* We can now unmap/delete the original table (if fully mapped) */
320
321 acpi_tb_delete_table(table_desc);
322
323 /* Setup descriptor for the new table */
324
325 table_desc->address = new_address;
326 table_desc->pointer = new_table;
327 table_desc->length = new_table_length;
328 table_desc->flags = new_flags;
329
330 return (new_table);
331}
332
333/*******************************************************************************
334 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300335 * FUNCTION: acpi_tb_resize_root_table_list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300337 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 *
339 * RETURN: Status
340 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300341 * DESCRIPTION: Expand the size of global table array
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 *
343 ******************************************************************************/
344
Bob Mooref3d2e782007-02-02 19:48:18 +0300345acpi_status acpi_tb_resize_root_table_list(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
Bob Mooref3d2e782007-02-02 19:48:18 +0300347 struct acpi_table_desc *tables;
Lv Zheng2bc198c2012-09-13 09:29:06 -0700348 u32 table_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Bob Mooref3d2e782007-02-02 19:48:18 +0300350 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Bob Mooref3d2e782007-02-02 19:48:18 +0300352 /* allow_resize flag is a parameter to acpi_initialize_tables */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Bob Moorec5fc42a2007-02-02 19:48:19 +0300354 if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300355 ACPI_ERROR((AE_INFO,
356 "Resize of Root Table Array is not allowed"));
357 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 }
359
Bob Mooref3d2e782007-02-02 19:48:18 +0300360 /* Increase the Table Array size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Lv Zheng2bc198c2012-09-13 09:29:06 -0700362 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
363 table_count = acpi_gbl_root_table_list.max_table_count;
364 } else {
365 table_count = acpi_gbl_root_table_list.current_table_count;
366 }
367
368 tables = ACPI_ALLOCATE_ZEROED(((acpi_size) table_count +
Bob Mooreec41f192009-02-18 15:03:30 +0800369 ACPI_ROOT_TABLE_SIZE_INCREMENT) *
370 sizeof(struct acpi_table_desc));
Bob Mooref3d2e782007-02-02 19:48:18 +0300371 if (!tables) {
372 ACPI_ERROR((AE_INFO,
373 "Could not allocate new root table array"));
Len Brown4be44fc2005-08-05 00:44:28 -0400374 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 }
376
Bob Mooref3d2e782007-02-02 19:48:18 +0300377 /* Copy and free the previous table array */
Robert Mooref9f46012005-07-08 00:00:00 -0400378
Bob Mooref3d2e782007-02-02 19:48:18 +0300379 if (acpi_gbl_root_table_list.tables) {
380 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
Lv Zheng2bc198c2012-09-13 09:29:06 -0700381 (acpi_size) table_count *
382 sizeof(struct acpi_table_desc));
Robert Mooref9f46012005-07-08 00:00:00 -0400383
Bob Moorec5fc42a2007-02-02 19:48:19 +0300384 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300385 ACPI_FREE(acpi_gbl_root_table_list.tables);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 }
387 }
388
Bob Mooref3d2e782007-02-02 19:48:18 +0300389 acpi_gbl_root_table_list.tables = tables;
Lv Zheng2bc198c2012-09-13 09:29:06 -0700390 acpi_gbl_root_table_list.max_table_count =
391 table_count + ACPI_ROOT_TABLE_SIZE_INCREMENT;
392 acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Len Brown4be44fc2005-08-05 00:44:28 -0400394 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395}
396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397/*******************************************************************************
398 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300399 * FUNCTION: acpi_tb_store_table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 *
Bob Mooreba494be2012-07-12 09:40:10 +0800401 * PARAMETERS: address - Table address
402 * table - Table header
403 * length - Table length
404 * flags - flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300406 * RETURN: Status and table index.
407 *
408 * DESCRIPTION: Add an ACPI table to the global table list
409 *
410 ******************************************************************************/
411
412acpi_status
413acpi_tb_store_table(acpi_physical_address address,
414 struct acpi_table_header *table,
Bob Moore67a119f2008-06-10 13:42:13 +0800415 u32 length, u8 flags, u32 *table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +0300416{
Bob Mooreb9ee2042010-04-27 11:16:14 +0800417 acpi_status status;
418 struct acpi_table_desc *new_table;
Bob Mooref3d2e782007-02-02 19:48:18 +0300419
420 /* Ensure that there is room for the table in the Root Table List */
421
Bob Mooreb9ee2042010-04-27 11:16:14 +0800422 if (acpi_gbl_root_table_list.current_table_count >=
423 acpi_gbl_root_table_list.max_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300424 status = acpi_tb_resize_root_table_list();
425 if (ACPI_FAILURE(status)) {
426 return (status);
427 }
428 }
429
Bob Mooreb9ee2042010-04-27 11:16:14 +0800430 new_table =
431 &acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.
432 current_table_count];
433
Bob Mooref3d2e782007-02-02 19:48:18 +0300434 /* Initialize added table */
435
Bob Mooreb9ee2042010-04-27 11:16:14 +0800436 new_table->address = address;
437 new_table->pointer = table;
438 new_table->length = length;
439 new_table->owner_id = 0;
440 new_table->flags = flags;
Bob Mooref3d2e782007-02-02 19:48:18 +0300441
Bob Mooreb9ee2042010-04-27 11:16:14 +0800442 ACPI_MOVE_32_TO_32(&new_table->signature, table->signature);
Bob Mooref3d2e782007-02-02 19:48:18 +0300443
Bob Mooreb9ee2042010-04-27 11:16:14 +0800444 *table_index = acpi_gbl_root_table_list.current_table_count;
445 acpi_gbl_root_table_list.current_table_count++;
446 return (AE_OK);
Bob Mooref3d2e782007-02-02 19:48:18 +0300447}
448
449/*******************************************************************************
450 *
451 * FUNCTION: acpi_tb_delete_table
452 *
453 * PARAMETERS: table_index - Table index
454 *
455 * RETURN: None
456 *
457 * DESCRIPTION: Delete one internal ACPI table
458 *
459 ******************************************************************************/
460
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300461void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
Bob Mooref3d2e782007-02-02 19:48:18 +0300462{
Lv Zheng55829822014-04-04 12:38:18 +0800463
Bob Mooref3d2e782007-02-02 19:48:18 +0300464 /* Table must be mapped or allocated */
Lv Zheng55829822014-04-04 12:38:18 +0800465
Bob Mooref3d2e782007-02-02 19:48:18 +0300466 if (!table_desc->pointer) {
467 return;
468 }
Lv Zheng55829822014-04-04 12:38:18 +0800469
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300470 switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
471 case ACPI_TABLE_ORIGIN_MAPPED:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000472
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300473 acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
474 break;
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000475
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300476 case ACPI_TABLE_ORIGIN_ALLOCATED:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000477
Bob Mooref3d2e782007-02-02 19:48:18 +0300478 ACPI_FREE(table_desc->pointer);
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300479 break;
Bob Mooref7b004a2012-02-14 18:31:56 +0800480
481 /* Not mapped or allocated, there is nothing we can do */
482
483 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000484
Bob Mooref7b004a2012-02-14 18:31:56 +0800485 return;
Bob Mooref3d2e782007-02-02 19:48:18 +0300486 }
487
488 table_desc->pointer = NULL;
489}
490
491/*******************************************************************************
492 *
493 * FUNCTION: acpi_tb_terminate
494 *
495 * PARAMETERS: None
496 *
497 * RETURN: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 *
499 * DESCRIPTION: Delete all internal ACPI tables
500 *
501 ******************************************************************************/
502
Bob Mooref3d2e782007-02-02 19:48:18 +0300503void acpi_tb_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
Bob Moore67a119f2008-06-10 13:42:13 +0800505 u32 i;
Bob Mooref3d2e782007-02-02 19:48:18 +0300506
507 ACPI_FUNCTION_TRACE(tb_terminate);
508
509 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
510
511 /* Delete the individual tables */
512
Bob Mooreb9ee2042010-04-27 11:16:14 +0800513 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300514 acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]);
Bob Mooref3d2e782007-02-02 19:48:18 +0300515 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 /*
Bob Mooref3d2e782007-02-02 19:48:18 +0300518 * Delete the root table array if allocated locally. Array cannot be
519 * mapped, so we don't need to check for that flag.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300521 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300522 ACPI_FREE(acpi_gbl_root_table_list.tables);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300524
525 acpi_gbl_root_table_list.tables = NULL;
526 acpi_gbl_root_table_list.flags = 0;
Bob Mooreb9ee2042010-04-27 11:16:14 +0800527 acpi_gbl_root_table_list.current_table_count = 0;
Bob Mooref3d2e782007-02-02 19:48:18 +0300528
529 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
530 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Bob Moore68aafc32012-10-31 02:26:01 +0000531
532 return_VOID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533}
534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535/*******************************************************************************
536 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300537 * FUNCTION: acpi_tb_delete_namespace_by_owner
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300539 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 *
Bob Moore8a335a232009-03-09 16:31:04 +0800541 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300543 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 *
545 ******************************************************************************/
546
Bob Moore8a335a232009-03-09 16:31:04 +0800547acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
Bob Mooref3d2e782007-02-02 19:48:18 +0300549 acpi_owner_id owner_id;
Bob Moore8a335a232009-03-09 16:31:04 +0800550 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Bob Moore8a335a232009-03-09 16:31:04 +0800552 ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner);
553
554 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
555 if (ACPI_FAILURE(status)) {
556 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 }
558
Bob Mooreb9ee2042010-04-27 11:16:14 +0800559 if (table_index >= acpi_gbl_root_table_list.current_table_count) {
Bob Moore8a335a232009-03-09 16:31:04 +0800560
561 /* The table index does not exist */
562
563 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
564 return_ACPI_STATUS(AE_NOT_EXIST);
565 }
566
567 /* Get the owner ID for this table, used to delete namespace nodes */
568
569 owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id;
Len Brown4be44fc2005-08-05 00:44:28 -0400570 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Bob Moore8a335a232009-03-09 16:31:04 +0800571
572 /*
573 * Need to acquire the namespace writer lock to prevent interference
574 * with any concurrent namespace walks. The interpreter must be
575 * released during the deletion since the acquisition of the deletion
576 * lock may block, and also since the execution of a namespace walk
577 * must be allowed to use the interpreter.
578 */
Bob Mooree4c1ebf2009-04-22 13:02:06 +0800579 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
Bob Moore8a335a232009-03-09 16:31:04 +0800580 status = acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock);
581
Bob Mooref3d2e782007-02-02 19:48:18 +0300582 acpi_ns_delete_namespace_by_owner(owner_id);
Bob Moore8a335a232009-03-09 16:31:04 +0800583 if (ACPI_FAILURE(status)) {
584 return_ACPI_STATUS(status);
585 }
586
587 acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock);
588
589 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
590 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591}
592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593/*******************************************************************************
594 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300595 * FUNCTION: acpi_tb_allocate_owner_id
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300597 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300599 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300601 * DESCRIPTION: Allocates owner_id in table_desc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 *
603 ******************************************************************************/
604
Bob Moore67a119f2008-06-10 13:42:13 +0800605acpi_status acpi_tb_allocate_owner_id(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606{
Bob Mooref3d2e782007-02-02 19:48:18 +0300607 acpi_status status = AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Bob Mooref3d2e782007-02-02 19:48:18 +0300609 ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Bob Mooref3d2e782007-02-02 19:48:18 +0300611 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +0800612 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300613 status = acpi_ut_allocate_owner_id
614 (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 }
616
Bob Mooref3d2e782007-02-02 19:48:18 +0300617 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
618 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619}
620
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621/*******************************************************************************
622 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300623 * FUNCTION: acpi_tb_release_owner_id
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300625 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300627 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300629 * DESCRIPTION: Releases owner_id in table_desc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 *
631 ******************************************************************************/
632
Bob Moore67a119f2008-06-10 13:42:13 +0800633acpi_status acpi_tb_release_owner_id(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634{
Bob Mooref3d2e782007-02-02 19:48:18 +0300635 acpi_status status = AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Bob Mooref3d2e782007-02-02 19:48:18 +0300637 ACPI_FUNCTION_TRACE(tb_release_owner_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Bob Mooref3d2e782007-02-02 19:48:18 +0300639 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +0800640 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300641 acpi_ut_release_owner_id(&
642 (acpi_gbl_root_table_list.
643 tables[table_index].owner_id));
644 status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 }
646
Bob Mooref3d2e782007-02-02 19:48:18 +0300647 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
648 return_ACPI_STATUS(status);
649}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Bob Mooref3d2e782007-02-02 19:48:18 +0300651/*******************************************************************************
652 *
653 * FUNCTION: acpi_tb_get_owner_id
654 *
655 * PARAMETERS: table_index - Table index
656 * owner_id - Where the table owner_id is returned
657 *
658 * RETURN: Status
659 *
660 * DESCRIPTION: returns owner_id for the ACPI table
661 *
662 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Lv Zheng55829822014-04-04 12:38:18 +0800664acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id * owner_id)
Bob Mooref3d2e782007-02-02 19:48:18 +0300665{
666 acpi_status status = AE_BAD_PARAMETER;
667
668 ACPI_FUNCTION_TRACE(tb_get_owner_id);
669
670 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +0800671 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300672 *owner_id =
673 acpi_gbl_root_table_list.tables[table_index].owner_id;
674 status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 }
676
Bob Mooref3d2e782007-02-02 19:48:18 +0300677 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
678 return_ACPI_STATUS(status);
679}
680
681/*******************************************************************************
682 *
683 * FUNCTION: acpi_tb_is_table_loaded
684 *
685 * PARAMETERS: table_index - Table index
686 *
687 * RETURN: Table Loaded Flag
688 *
689 ******************************************************************************/
690
Bob Moore67a119f2008-06-10 13:42:13 +0800691u8 acpi_tb_is_table_loaded(u32 table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +0300692{
693 u8 is_loaded = FALSE;
694
695 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +0800696 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300697 is_loaded = (u8)
Bob Mooreec41f192009-02-18 15:03:30 +0800698 (acpi_gbl_root_table_list.tables[table_index].flags &
699 ACPI_TABLE_IS_LOADED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
701
Bob Mooref3d2e782007-02-02 19:48:18 +0300702 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
703 return (is_loaded);
704}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Bob Mooref3d2e782007-02-02 19:48:18 +0300706/*******************************************************************************
707 *
708 * FUNCTION: acpi_tb_set_table_loaded_flag
709 *
710 * PARAMETERS: table_index - Table index
711 * is_loaded - TRUE if table is loaded, FALSE otherwise
712 *
713 * RETURN: None
714 *
715 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
716 *
717 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Bob Moore67a119f2008-06-10 13:42:13 +0800719void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
Bob Mooref3d2e782007-02-02 19:48:18 +0300720{
Bob Mooref6dd9222006-07-07 20:44:38 -0400721
Bob Mooref3d2e782007-02-02 19:48:18 +0300722 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +0800723 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300724 if (is_loaded) {
725 acpi_gbl_root_table_list.tables[table_index].flags |=
Bob Moorec5fc42a2007-02-02 19:48:19 +0300726 ACPI_TABLE_IS_LOADED;
Bob Mooref3d2e782007-02-02 19:48:18 +0300727 } else {
728 acpi_gbl_root_table_list.tables[table_index].flags &=
Bob Moorec5fc42a2007-02-02 19:48:19 +0300729 ~ACPI_TABLE_IS_LOADED;
Bob Mooref3d2e782007-02-02 19:48:18 +0300730 }
731 }
Bob Mooref6dd9222006-07-07 20:44:38 -0400732
Bob Mooref3d2e782007-02-02 19:48:18 +0300733 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734}