blob: 50a6f229633c1aaf6512994024889596839e5e13 [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
Lv Zheng86dfc6f32014-04-04 12:38:57 +080052/* Local prototypes */
53static acpi_status
Bob Mooreed6f1d42014-04-04 12:39:26 +080054acpi_tb_acquire_temp_table(struct acpi_table_desc *table_desc,
55 acpi_physical_address address, u8 flags);
Lv Zheng86dfc6f32014-04-04 12:38:57 +080056
Bob Mooreed6f1d42014-04-04 12:39:26 +080057static void acpi_tb_release_temp_table(struct acpi_table_desc *table_desc);
Lv Zheng86dfc6f32014-04-04 12:38:57 +080058
Bob Mooreed6f1d42014-04-04 12:39:26 +080059static acpi_status acpi_tb_get_root_table_entry(u32 *table_index);
Lv Zheng86dfc6f32014-04-04 12:38:57 +080060
61static u8
62acpi_tb_is_equivalent_table(struct acpi_table_desc *table_desc,
63 u32 table_index);
64
Lv Zheng7f9fc992014-04-04 12:38:42 +080065/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 *
Lv Zheng7f9fc992014-04-04 12:38:42 +080067 * FUNCTION: acpi_tb_acquire_table
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 *
Lv Zheng7f9fc992014-04-04 12:38:42 +080069 * PARAMETERS: table_desc - Table descriptor
70 * table_ptr - Where table is returned
71 * table_length - Where table length is returned
72 * table_flags - Where table allocation flags are returned
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 *
74 * RETURN: Status
75 *
Bob Mooreed6f1d42014-04-04 12:39:26 +080076 * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
77 * maintained in the acpi_gbl_root_table_list.
Lv Zheng7f9fc992014-04-04 12:38:42 +080078 *
79 ******************************************************************************/
Lv Zheng86dfc6f32014-04-04 12:38:57 +080080
Lv Zheng7f9fc992014-04-04 12:38:42 +080081acpi_status
82acpi_tb_acquire_table(struct acpi_table_desc *table_desc,
83 struct acpi_table_header **table_ptr,
84 u32 *table_length, u8 *table_flags)
85{
86 struct acpi_table_header *table = NULL;
87
88 switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
Bob Mooreed6f1d42014-04-04 12:39:26 +080089 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
Lv Zheng7f9fc992014-04-04 12:38:42 +080090
91 table =
92 acpi_os_map_memory(table_desc->address, table_desc->length);
93 break;
94
Bob Mooreed6f1d42014-04-04 12:39:26 +080095 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
96 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
Lv Zheng7f9fc992014-04-04 12:38:42 +080097
98 table =
99 ACPI_CAST_PTR(struct acpi_table_header,
100 table_desc->address);
101 break;
102
103 default:
104
105 break;
106 }
107
108 /* Table is not valid yet */
109
110 if (!table) {
111 return (AE_NO_MEMORY);
112 }
113
114 /* Fill the return values */
115
116 *table_ptr = table;
117 *table_length = table_desc->length;
118 *table_flags = table_desc->flags;
Lv Zheng7f9fc992014-04-04 12:38:42 +0800119 return (AE_OK);
120}
121
122/*******************************************************************************
123 *
124 * FUNCTION: acpi_tb_release_table
125 *
126 * PARAMETERS: table - Pointer for the table
127 * table_length - Length for the table
128 * table_flags - Allocation flags for the table
129 *
130 * RETURN: None
131 *
Bob Mooreed6f1d42014-04-04 12:39:26 +0800132 * DESCRIPTION: Release a table. The inverse of acpi_tb_acquire_table().
Lv Zheng7f9fc992014-04-04 12:38:42 +0800133 *
134 ******************************************************************************/
135
136void
137acpi_tb_release_table(struct acpi_table_header *table,
138 u32 table_length, u8 table_flags)
139{
Bob Mooreed6f1d42014-04-04 12:39:26 +0800140
Lv Zheng7f9fc992014-04-04 12:38:42 +0800141 switch (table_flags & ACPI_TABLE_ORIGIN_MASK) {
Bob Mooreed6f1d42014-04-04 12:39:26 +0800142 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
Lv Zheng7f9fc992014-04-04 12:38:42 +0800143
144 acpi_os_unmap_memory(table, table_length);
145 break;
146
Bob Mooreed6f1d42014-04-04 12:39:26 +0800147 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
148 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
Lv Zheng7f9fc992014-04-04 12:38:42 +0800149 default:
150
151 break;
152 }
153}
154
155/******************************************************************************
156 *
157 * FUNCTION: acpi_tb_validate_table
158 *
159 * PARAMETERS: table_desc - Table descriptor
160 *
161 * RETURN: Status
162 *
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800163 * DESCRIPTION: This function is called to validate the table, the returned
164 * table descriptor is in "VALIDATED" state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300166 *****************************************************************************/
Lv Zheng7f9fc992014-04-04 12:38:42 +0800167
168acpi_status acpi_tb_validate_table(struct acpi_table_desc *table_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169{
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300170 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Lv Zheng7f9fc992014-04-04 12:38:42 +0800172 ACPI_FUNCTION_TRACE(tb_validate_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Lv Zheng7f9fc992014-04-04 12:38:42 +0800174 /* Validate the table if necessary */
Robert Moore44f6c012005-04-18 22:49:35 -0400175
Bob Mooref3d2e782007-02-02 19:48:18 +0300176 if (!table_desc->pointer) {
Lv Zheng7f9fc992014-04-04 12:38:42 +0800177 status = acpi_tb_acquire_table(table_desc, &table_desc->pointer,
178 &table_desc->length,
179 &table_desc->flags);
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800180 if (!table_desc->pointer) {
181 status = AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 }
183 }
184
Bob Moorec5fc42a2007-02-02 19:48:19 +0300185 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186}
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188/*******************************************************************************
189 *
Lv Zheng7f9fc992014-04-04 12:38:42 +0800190 * FUNCTION: acpi_tb_invalidate_table
191 *
192 * PARAMETERS: table_desc - Table descriptor
193 *
194 * RETURN: None
195 *
Bob Mooreed6f1d42014-04-04 12:39:26 +0800196 * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
Lv Zheng7f9fc992014-04-04 12:38:42 +0800197 * acpi_tb_validate_table().
198 *
199 ******************************************************************************/
200
201void acpi_tb_invalidate_table(struct acpi_table_desc *table_desc)
202{
203
204 ACPI_FUNCTION_TRACE(tb_invalidate_table);
205
206 /* Table must be validated */
207
208 if (!table_desc->pointer) {
209 return_VOID;
210 }
211
212 acpi_tb_release_table(table_desc->pointer, table_desc->length,
213 table_desc->flags);
214 table_desc->pointer = NULL;
215
216 return_VOID;
217}
218
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800219/******************************************************************************
Lv Zheng7f9fc992014-04-04 12:38:42 +0800220 *
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800221 * FUNCTION: acpi_tb_verify_table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 *
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300223 * PARAMETERS: table_desc - Table descriptor
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800224 * signature - Table signature to verify
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 *
226 * RETURN: Status
227 *
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800228 * DESCRIPTION: This function is called to validate and verify the table, the
229 * returned table descriptor is in "VALIDATED" state.
230 *
231 *****************************************************************************/
232
233acpi_status
234acpi_tb_verify_table(struct acpi_table_desc *table_desc, char *signature)
235{
236 acpi_status status = AE_OK;
237
238 ACPI_FUNCTION_TRACE(tb_verify_table);
239
240 /* Validate the table */
241
242 status = acpi_tb_validate_table(table_desc);
243 if (ACPI_FAILURE(status)) {
244 return_ACPI_STATUS(AE_NO_MEMORY);
245 }
246
247 /* If a particular signature is expected (DSDT/FACS), it must match */
248
249 if (signature && !ACPI_COMPARE_NAME(&table_desc->signature, signature)) {
250 ACPI_BIOS_ERROR((AE_INFO,
251 "Invalid signature 0x%X for ACPI table, expected [%s]",
252 table_desc->signature.integer, signature));
253 status = AE_BAD_SIGNATURE;
254 goto invalidate_and_exit;
255 }
256
257 /* Verify the checksum */
258
259 status =
260 acpi_tb_verify_checksum(table_desc->pointer, table_desc->length);
261 if (ACPI_FAILURE(status)) {
262 ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY,
263 "%4.4s " ACPI_PRINTF_UINT
264 " Attempted table install failed",
265 acpi_ut_valid_acpi_name(table_desc->signature.
266 ascii) ? table_desc->
267 signature.ascii : "????",
268 ACPI_FORMAT_TO_UINT(table_desc->address)));
269 goto invalidate_and_exit;
270 }
271
272 return_ACPI_STATUS(AE_OK);
273
274invalidate_and_exit:
275 acpi_tb_invalidate_table(table_desc);
276 return_ACPI_STATUS(status);
277}
278
279/*******************************************************************************
280 *
Bob Mooreed6f1d42014-04-04 12:39:26 +0800281 * FUNCTION: acpi_tb_init_table_descriptor
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800282 *
283 * PARAMETERS: table_desc - Table descriptor
284 * address - Physical address of the table
285 * flags - Allocation flags of the table
286 * table - Pointer to the table
287 *
288 * RETURN: None
289 *
Bob Mooreed6f1d42014-04-04 12:39:26 +0800290 * DESCRIPTION: Initialize a new table descriptor
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 *
292 ******************************************************************************/
293
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800294void
Bob Mooreed6f1d42014-04-04 12:39:26 +0800295acpi_tb_init_table_descriptor(struct acpi_table_desc *table_desc,
296 acpi_physical_address address,
297 u8 flags, struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
Bob Mooreed6f1d42014-04-04 12:39:26 +0800299
Bob Moorebc45b1d2008-06-10 14:12:50 +0800300 /*
Bob Mooreed6f1d42014-04-04 12:39:26 +0800301 * Initialize the table descriptor. Set the pointer to NULL, since the
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800302 * table is not fully mapped at this time.
Bob Moorebc45b1d2008-06-10 14:12:50 +0800303 */
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800304 ACPI_MEMSET(table_desc, 0, sizeof(struct acpi_table_desc));
305 table_desc->address = address;
306 table_desc->length = table->length;
307 table_desc->flags = flags;
308 ACPI_MOVE_32_TO_32(table_desc->signature.ascii, table->signature);
309}
Bob Moorec8cefe32011-06-14 10:42:53 +0800310
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800311/*******************************************************************************
312 *
Bob Mooreed6f1d42014-04-04 12:39:26 +0800313 * FUNCTION: acpi_tb_acquire_temp_table
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800314 *
315 * PARAMETERS: table_desc - Table descriptor to be acquired
316 * address - Address of the table
317 * flags - Allocation flags of the table
318 *
319 * RETURN: Status
320 *
321 * DESCRIPTION: This function validates the table header to obtain the length
322 * of a table and fills the table descriptor to make its state as
Bob Mooreed6f1d42014-04-04 12:39:26 +0800323 * "INSTALLED". Such a table descriptor is only used for verified
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800324 * installation.
325 *
326 ******************************************************************************/
327
328static acpi_status
Bob Mooreed6f1d42014-04-04 12:39:26 +0800329acpi_tb_acquire_temp_table(struct acpi_table_desc *table_desc,
330 acpi_physical_address address, u8 flags)
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800331{
332 struct acpi_table_header *table_header;
333
334 switch (flags & ACPI_TABLE_ORIGIN_MASK) {
Bob Mooreed6f1d42014-04-04 12:39:26 +0800335 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800336
Bob Mooreed6f1d42014-04-04 12:39:26 +0800337 /* Get the length of the full table from the header */
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800338
339 table_header =
340 acpi_os_map_memory(address,
341 sizeof(struct acpi_table_header));
342 if (!table_header) {
343 return (AE_NO_MEMORY);
344 }
Bob Mooreed6f1d42014-04-04 12:39:26 +0800345
346 acpi_tb_init_table_descriptor(table_desc, address, flags,
347 table_header);
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800348 acpi_os_unmap_memory(table_header,
349 sizeof(struct acpi_table_header));
350 return (AE_OK);
351
Bob Mooreed6f1d42014-04-04 12:39:26 +0800352 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
353 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800354
355 table_header = ACPI_CAST_PTR(struct acpi_table_header, address);
356 if (!table_header) {
357 return (AE_NO_MEMORY);
358 }
Bob Mooreed6f1d42014-04-04 12:39:26 +0800359
360 acpi_tb_init_table_descriptor(table_desc, address, flags,
361 table_header);
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800362 return (AE_OK);
363
364 default:
365
366 break;
Bob Moorec8cefe32011-06-14 10:42:53 +0800367 }
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300368
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800369 /* Table is not valid yet */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800371 return (AE_NO_MEMORY);
372}
Bob Mooref3d2e782007-02-02 19:48:18 +0300373
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800374/*******************************************************************************
375 *
Bob Mooreed6f1d42014-04-04 12:39:26 +0800376 * FUNCTION: acpi_tb_release_temp_table
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800377 *
378 * PARAMETERS: table_desc - Table descriptor to be released
379 *
380 * RETURN: Status
381 *
Bob Mooreed6f1d42014-04-04 12:39:26 +0800382 * DESCRIPTION: The inverse of acpi_tb_acquire_temp_table().
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800383 *
384 ******************************************************************************/
Bob Mooref3d2e782007-02-02 19:48:18 +0300385
Bob Mooreed6f1d42014-04-04 12:39:26 +0800386static void acpi_tb_release_temp_table(struct acpi_table_desc *table_desc)
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800387{
Bob Mooreed6f1d42014-04-04 12:39:26 +0800388
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800389 /*
390 * Note that the .Address is maintained by the callers of
Bob Mooreed6f1d42014-04-04 12:39:26 +0800391 * acpi_tb_acquire_temp_table(), thus do not invoke acpi_tb_uninstall_table()
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800392 * where .Address will be freed.
393 */
394 acpi_tb_invalidate_table(table_desc);
395}
Bob Mooree56f5612008-07-04 10:48:43 +0800396
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800397/*******************************************************************************
398 *
Bob Mooreed6f1d42014-04-04 12:39:26 +0800399 * FUNCTION: acpi_tb_install_table_with_override
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800400 *
401 * PARAMETERS: table_index - Index into root table array
402 * new_table_desc - New table descriptor to install
Lv Zhengcaf4a152014-04-04 12:39:18 +0800403 * override - Whether override should be performed
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800404 *
405 * RETURN: None
406 *
407 * DESCRIPTION: Install an ACPI table into the global data structure. The
408 * table override mechanism is called to allow the host
409 * OS to replace any table before it is installed in the root
410 * table array.
411 *
412 ******************************************************************************/
Bob Mooref3d2e782007-02-02 19:48:18 +0300413
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800414void
Bob Mooreed6f1d42014-04-04 12:39:26 +0800415acpi_tb_install_table_with_override(u32 table_index,
416 struct acpi_table_desc *new_table_desc,
417 u8 override)
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800418{
Bob Mooreed6f1d42014-04-04 12:39:26 +0800419
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800420 if (table_index >= acpi_gbl_root_table_list.current_table_count) {
421 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 }
423
Bob Moored3ccaff2009-02-03 14:43:04 +0800424 /*
425 * ACPI Table Override:
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800426 *
427 * Before we install the table, let the host OS override it with a new
428 * one if desired. Any table within the RSDT/XSDT can be replaced,
429 * including the DSDT which is pointed to by the FADT.
Bob Moored3ccaff2009-02-03 14:43:04 +0800430 */
Lv Zhengcaf4a152014-04-04 12:39:18 +0800431 if (override) {
432 acpi_tb_override_table(new_table_desc);
433 }
Lv Zheng7f9fc992014-04-04 12:38:42 +0800434
Bob Mooreed6f1d42014-04-04 12:39:26 +0800435 acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.
436 tables[table_index],
437 new_table_desc->address,
438 new_table_desc->flags,
439 new_table_desc->pointer);
Lv Zheng7f9fc992014-04-04 12:38:42 +0800440
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800441 acpi_tb_print_table_header(new_table_desc->address,
442 new_table_desc->pointer);
443
444 /* Set the global integer width (based upon revision of the DSDT) */
445
446 if (table_index == ACPI_TABLE_INDEX_DSDT) {
447 acpi_ut_set_integer_width(new_table_desc->pointer->revision);
448 }
449}
450
451/*******************************************************************************
452 *
453 * FUNCTION: acpi_tb_install_fixed_table
454 *
455 * PARAMETERS: address - Physical address of DSDT or FACS
456 * signature - Table signature, NULL if no need to
457 * match
458 * table_index - Index into root table array
459 *
460 * RETURN: Status
461 *
462 * DESCRIPTION: Install a fixed ACPI table (DSDT/FACS) into the global data
463 * structure.
464 *
465 ******************************************************************************/
466
467acpi_status
468acpi_tb_install_fixed_table(acpi_physical_address address,
469 char *signature, u32 table_index)
470{
471 struct acpi_table_desc new_table_desc;
472 acpi_status status;
473
474 ACPI_FUNCTION_TRACE(tb_install_fixed_table);
475
476 if (!address) {
477 ACPI_ERROR((AE_INFO,
478 "Null physical address for ACPI table [%s]",
479 signature));
480 return (AE_NO_MEMORY);
481 }
482
483 /* Fill a table descriptor for validation */
484
Bob Mooreed6f1d42014-04-04 12:39:26 +0800485 status = acpi_tb_acquire_temp_table(&new_table_desc, address,
486 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800487 if (ACPI_FAILURE(status)) {
488 ACPI_ERROR((AE_INFO, "Could not acquire table length at %p",
489 ACPI_CAST_PTR(void, address)));
490 return_ACPI_STATUS(status);
491 }
492
493 /* Validate and verify a table before installation */
494
495 status = acpi_tb_verify_table(&new_table_desc, signature);
496 if (ACPI_FAILURE(status)) {
497 goto release_and_exit;
498 }
499
Bob Mooreed6f1d42014-04-04 12:39:26 +0800500 acpi_tb_install_table_with_override(table_index, &new_table_desc, TRUE);
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800501
502release_and_exit:
503
Bob Mooreed6f1d42014-04-04 12:39:26 +0800504 /* Release the temporary table descriptor */
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800505
Bob Mooreed6f1d42014-04-04 12:39:26 +0800506 acpi_tb_release_temp_table(&new_table_desc);
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800507 return_ACPI_STATUS(status);
508}
509
510/*******************************************************************************
511 *
512 * FUNCTION: acpi_tb_is_equivalent_table
513 *
514 * PARAMETERS: table_desc - Table 1 descriptor to be compared
515 * table_index - Index of table 2 to be compared
516 *
517 * RETURN: TRUE if 2 tables are equivalent
518 *
519 * DESCRIPTION: This function is called to compare a table with what have
520 * already been installed in the root table list.
521 *
522 ******************************************************************************/
523
524static u8
525acpi_tb_is_equivalent_table(struct acpi_table_desc *table_desc, u32 table_index)
526{
527 acpi_status status = AE_OK;
528 u8 is_equivalent;
529 struct acpi_table_header *table;
530 u32 table_length;
531 u8 table_flags;
532
533 status =
534 acpi_tb_acquire_table(&acpi_gbl_root_table_list.tables[table_index],
535 &table, &table_length, &table_flags);
536 if (ACPI_FAILURE(status)) {
537 return (FALSE);
538 }
539
540 /*
541 * Check for a table match on the entire table length,
542 * not just the header.
543 */
544 is_equivalent = (u8)((table_desc->length != table_length ||
545 ACPI_MEMCMP(table_desc->pointer, table,
546 table_length)) ? FALSE : TRUE);
547
548 /* Release the acquired table */
549
550 acpi_tb_release_table(table, table_length, table_flags);
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800551 return (is_equivalent);
552}
553
554/*******************************************************************************
555 *
Bob Mooreed6f1d42014-04-04 12:39:26 +0800556 * FUNCTION: acpi_tb_install_standard_table
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800557 *
Lv Zheng8a216d72014-04-04 12:39:04 +0800558 * PARAMETERS: address - Address of the table (might be a virtual
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800559 * address depending on the table_flags)
560 * flags - Flags for the table
561 * reload - Whether reload should be performed
Lv Zhengcaf4a152014-04-04 12:39:18 +0800562 * override - Whether override should be performed
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800563 * table_index - Where the table index is returned
564 *
565 * RETURN: Status
566 *
567 * DESCRIPTION: This function is called to install an ACPI table that is
Bob Mooreed6f1d42014-04-04 12:39:26 +0800568 * neither DSDT nor FACS (a "standard" table.)
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800569 * When this function is called by "Load" or "LoadTable" opcodes,
570 * or by acpi_load_table() API, the "Reload" parameter is set.
571 * After sucessfully returning from this function, table is
572 * "INSTALLED" but not "VALIDATED".
573 *
574 ******************************************************************************/
575
576acpi_status
Bob Mooreed6f1d42014-04-04 12:39:26 +0800577acpi_tb_install_standard_table(acpi_physical_address address,
578 u8 flags,
579 u8 reload, u8 override, u32 *table_index)
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800580{
581 u32 i;
582 acpi_status status = AE_OK;
583 struct acpi_table_desc new_table_desc;
584
Bob Mooreed6f1d42014-04-04 12:39:26 +0800585 ACPI_FUNCTION_TRACE(tb_install_standard_table);
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800586
Bob Mooreed6f1d42014-04-04 12:39:26 +0800587 /* Acquire a temporary table descriptor for validation */
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800588
Bob Mooreed6f1d42014-04-04 12:39:26 +0800589 status = acpi_tb_acquire_temp_table(&new_table_desc, address, flags);
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800590 if (ACPI_FAILURE(status)) {
591 ACPI_ERROR((AE_INFO, "Could not acquire table length at %p",
592 ACPI_CAST_PTR(void, address)));
593 return_ACPI_STATUS(status);
594 }
595
Lv Zhenga94e88c2014-04-04 12:39:11 +0800596 /*
597 * Optionally do not load any SSDTs from the RSDT/XSDT. This can
598 * be useful for debugging ACPI problems on some machines.
599 */
Bob Mooreed6f1d42014-04-04 12:39:26 +0800600 if (!reload &&
601 acpi_gbl_disable_ssdt_table_install &&
Lv Zhenga94e88c2014-04-04 12:39:11 +0800602 ACPI_COMPARE_NAME(&new_table_desc.signature, ACPI_SIG_SSDT)) {
603 ACPI_INFO((AE_INFO, "Ignoring installation of %4.4s at %p",
604 new_table_desc.signature.ascii, ACPI_CAST_PTR(void,
605 address)));
606 goto release_and_exit;
607 }
608
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800609 /* Validate and verify a table before installation */
610
611 status = acpi_tb_verify_table(&new_table_desc, NULL);
612 if (ACPI_FAILURE(status)) {
613 goto release_and_exit;
614 }
615
616 if (reload) {
617 /*
618 * Validate the incoming table signature.
619 *
620 * 1) Originally, we checked the table signature for "SSDT" or "PSDT".
621 * 2) We added support for OEMx tables, signature "OEM".
622 * 3) Valid tables were encountered with a null signature, so we just
623 * gave up on validating the signature, (05/2008).
624 * 4) We encountered non-AML tables such as the MADT, which caused
625 * interpreter errors and kernel faults. So now, we once again allow
626 * only "SSDT", "OEMx", and now, also a null signature. (05/2011).
627 */
628 if ((new_table_desc.signature.ascii[0] != 0x00) &&
629 (!ACPI_COMPARE_NAME
630 (&new_table_desc.signature, ACPI_SIG_SSDT))
631 && (ACPI_STRNCMP(new_table_desc.signature.ascii, "OEM", 3)))
632 {
633 ACPI_BIOS_ERROR((AE_INFO,
634 "Table has invalid signature [%4.4s] (0x%8.8X), "
635 "must be SSDT or OEMx",
636 acpi_ut_valid_acpi_name(new_table_desc.
637 signature.
638 ascii) ?
639 new_table_desc.signature.
640 ascii : "????",
641 new_table_desc.signature.integer));
642
643 status = AE_BAD_SIGNATURE;
644 goto release_and_exit;
645 }
646
647 /* Check if table is already registered */
648
649 for (i = 0; i < acpi_gbl_root_table_list.current_table_count;
650 ++i) {
651 /*
652 * Check for a table match on the entire table length,
653 * not just the header.
654 */
655 if (!acpi_tb_is_equivalent_table(&new_table_desc, i)) {
656 continue;
657 }
658
659 /*
660 * Note: the current mechanism does not unregister a table if it is
661 * dynamically unloaded. The related namespace entries are deleted,
662 * but the table remains in the root table list.
663 *
664 * The assumption here is that the number of different tables that
665 * will be loaded is actually small, and there is minimal overhead
666 * in just keeping the table in case it is needed again.
667 *
668 * If this assumption changes in the future (perhaps on large
669 * machines with many table load/unload operations), tables will
670 * need to be unregistered when they are unloaded, and slots in the
671 * root table list should be reused when empty.
672 */
673 if (acpi_gbl_root_table_list.tables[i].
674 flags & ACPI_TABLE_IS_LOADED) {
675
676 /* Table is still loaded, this is an error */
677
678 status = AE_ALREADY_EXISTS;
679 goto release_and_exit;
680 } else {
681 /*
682 * Table was unloaded, allow it to be reloaded.
683 * As we are going to return AE_OK to the caller, we should
684 * take the responsibility of freeing the input descriptor.
685 * Refill the input descriptor to ensure
Bob Mooreed6f1d42014-04-04 12:39:26 +0800686 * acpi_tb_install_table_with_override() can be called again to
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800687 * indicate the re-installation.
688 */
689 acpi_tb_uninstall_table(&new_table_desc);
690 *table_index = i;
691 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
692 return_ACPI_STATUS(AE_OK);
693 }
694 }
Lv Zheng7f9fc992014-04-04 12:38:42 +0800695 }
Bob Moored3ccaff2009-02-03 14:43:04 +0800696
Bob Mooree56f5612008-07-04 10:48:43 +0800697 /* Add the table to the global root table list */
698
Bob Mooreed6f1d42014-04-04 12:39:26 +0800699 status = acpi_tb_get_root_table_entry(&i);
Len Brown4be44fc2005-08-05 00:44:28 -0400700 if (ACPI_FAILURE(status)) {
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800701 goto release_and_exit;
Robert Moore0c9938c2005-07-29 15:15:00 -0700702 }
Bob Mooreed6f1d42014-04-04 12:39:26 +0800703
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800704 *table_index = i;
Bob Mooreed6f1d42014-04-04 12:39:26 +0800705 acpi_tb_install_table_with_override(i, &new_table_desc, override);
Robert Moore0c9938c2005-07-29 15:15:00 -0700706
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800707release_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Bob Mooreed6f1d42014-04-04 12:39:26 +0800709 /* Release the temporary table descriptor */
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800710
Bob Mooreed6f1d42014-04-04 12:39:26 +0800711 acpi_tb_release_temp_table(&new_table_desc);
Len Brown4be44fc2005-08-05 00:44:28 -0400712 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713}
714
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715/*******************************************************************************
716 *
Lv Zheng7f9fc992014-04-04 12:38:42 +0800717 * FUNCTION: acpi_tb_override_table
Bob Mooref7b004a2012-02-14 18:31:56 +0800718 *
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800719 * PARAMETERS: old_table_desc - Validated table descriptor to be
720 * overridden
Bob Mooref7b004a2012-02-14 18:31:56 +0800721 *
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800722 * RETURN: None
Bob Mooref7b004a2012-02-14 18:31:56 +0800723 *
724 * DESCRIPTION: Attempt table override by calling the OSL override functions.
725 * Note: If the table is overridden, then the entire new table
Lv Zheng7f9fc992014-04-04 12:38:42 +0800726 * is acquired and returned by this function.
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800727 * Before/after invocation, the table descriptor is in a state
728 * that is "VALIDATED".
Bob Mooref7b004a2012-02-14 18:31:56 +0800729 *
730 ******************************************************************************/
731
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800732void acpi_tb_override_table(struct acpi_table_desc *old_table_desc)
Bob Mooref7b004a2012-02-14 18:31:56 +0800733{
734 acpi_status status;
Bob Mooref7b004a2012-02-14 18:31:56 +0800735 char *override_type;
Lv Zheng7f9fc992014-04-04 12:38:42 +0800736 struct acpi_table_desc new_table_desc;
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800737 struct acpi_table_header *table;
738 acpi_physical_address address;
739 u32 length;
Bob Mooref7b004a2012-02-14 18:31:56 +0800740
741 /* (1) Attempt logical override (returns a logical address) */
742
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800743 status = acpi_os_table_override(old_table_desc->pointer, &table);
744 if (ACPI_SUCCESS(status) && table) {
Bob Mooreed6f1d42014-04-04 12:39:26 +0800745 acpi_tb_acquire_temp_table(&new_table_desc,
746 ACPI_PTR_TO_PHYSADDR(table),
747 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL);
Bob Mooref7b004a2012-02-14 18:31:56 +0800748 override_type = "Logical";
749 goto finish_override;
750 }
751
752 /* (2) Attempt physical override (returns a physical address) */
753
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800754 status = acpi_os_physical_table_override(old_table_desc->pointer,
755 &address, &length);
756 if (ACPI_SUCCESS(status) && address && length) {
Bob Mooreed6f1d42014-04-04 12:39:26 +0800757 acpi_tb_acquire_temp_table(&new_table_desc, address,
758 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
Bob Mooref7b004a2012-02-14 18:31:56 +0800759 override_type = "Physical";
Bob Mooref7b004a2012-02-14 18:31:56 +0800760 goto finish_override;
761 }
762
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800763 return; /* There was no override */
Bob Mooref7b004a2012-02-14 18:31:56 +0800764
Lv Zheng10622bf2013-10-29 09:30:02 +0800765finish_override:
Bob Mooref7b004a2012-02-14 18:31:56 +0800766
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800767 /* Validate and verify a table before overriding */
768
769 status = acpi_tb_verify_table(&new_table_desc, NULL);
Lv Zheng7f9fc992014-04-04 12:38:42 +0800770 if (ACPI_FAILURE(status)) {
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800771 return;
Lv Zheng7f9fc992014-04-04 12:38:42 +0800772 }
773
Bob Moore2e19f8d2014-02-08 09:42:07 +0800774 ACPI_INFO((AE_INFO, "%4.4s " ACPI_PRINTF_UINT
775 " %s table override, new table: " ACPI_PRINTF_UINT,
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800776 old_table_desc->signature.ascii,
777 ACPI_FORMAT_TO_UINT(old_table_desc->address),
Lv Zheng7f9fc992014-04-04 12:38:42 +0800778 override_type, ACPI_FORMAT_TO_UINT(new_table_desc.address)));
Bob Mooref7b004a2012-02-14 18:31:56 +0800779
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800780 /* We can now uninstall the original table */
Bob Mooref7b004a2012-02-14 18:31:56 +0800781
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800782 acpi_tb_uninstall_table(old_table_desc);
Bob Mooref7b004a2012-02-14 18:31:56 +0800783
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800784 /*
785 * Replace the original table descriptor and keep its state as
786 * "VALIDATED".
787 */
Bob Mooreed6f1d42014-04-04 12:39:26 +0800788 acpi_tb_init_table_descriptor(old_table_desc, new_table_desc.address,
789 new_table_desc.flags,
790 new_table_desc.pointer);
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800791 acpi_tb_validate_table(old_table_desc);
Bob Mooref7b004a2012-02-14 18:31:56 +0800792
Bob Mooreed6f1d42014-04-04 12:39:26 +0800793 /* Release the temporary table descriptor */
Bob Mooref7b004a2012-02-14 18:31:56 +0800794
Bob Mooreed6f1d42014-04-04 12:39:26 +0800795 acpi_tb_release_temp_table(&new_table_desc);
Bob Mooref7b004a2012-02-14 18:31:56 +0800796}
797
798/*******************************************************************************
799 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300800 * FUNCTION: acpi_tb_resize_root_table_list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300802 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 *
804 * RETURN: Status
805 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300806 * DESCRIPTION: Expand the size of global table array
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 *
808 ******************************************************************************/
809
Bob Mooref3d2e782007-02-02 19:48:18 +0300810acpi_status acpi_tb_resize_root_table_list(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811{
Bob Mooref3d2e782007-02-02 19:48:18 +0300812 struct acpi_table_desc *tables;
Lv Zheng2bc198c2012-09-13 09:29:06 -0700813 u32 table_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Bob Mooref3d2e782007-02-02 19:48:18 +0300815 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Bob Mooref3d2e782007-02-02 19:48:18 +0300817 /* allow_resize flag is a parameter to acpi_initialize_tables */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
Bob Moorec5fc42a2007-02-02 19:48:19 +0300819 if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300820 ACPI_ERROR((AE_INFO,
821 "Resize of Root Table Array is not allowed"));
822 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 }
824
Bob Mooref3d2e782007-02-02 19:48:18 +0300825 /* Increase the Table Array size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
Lv Zheng2bc198c2012-09-13 09:29:06 -0700827 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
828 table_count = acpi_gbl_root_table_list.max_table_count;
829 } else {
830 table_count = acpi_gbl_root_table_list.current_table_count;
831 }
832
833 tables = ACPI_ALLOCATE_ZEROED(((acpi_size) table_count +
Bob Mooreec41f192009-02-18 15:03:30 +0800834 ACPI_ROOT_TABLE_SIZE_INCREMENT) *
835 sizeof(struct acpi_table_desc));
Bob Mooref3d2e782007-02-02 19:48:18 +0300836 if (!tables) {
837 ACPI_ERROR((AE_INFO,
838 "Could not allocate new root table array"));
Len Brown4be44fc2005-08-05 00:44:28 -0400839 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 }
841
Bob Mooref3d2e782007-02-02 19:48:18 +0300842 /* Copy and free the previous table array */
Robert Mooref9f46012005-07-08 00:00:00 -0400843
Bob Mooref3d2e782007-02-02 19:48:18 +0300844 if (acpi_gbl_root_table_list.tables) {
845 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
Lv Zheng2bc198c2012-09-13 09:29:06 -0700846 (acpi_size) table_count *
847 sizeof(struct acpi_table_desc));
Robert Mooref9f46012005-07-08 00:00:00 -0400848
Bob Moorec5fc42a2007-02-02 19:48:19 +0300849 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300850 ACPI_FREE(acpi_gbl_root_table_list.tables);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 }
852 }
853
Bob Mooref3d2e782007-02-02 19:48:18 +0300854 acpi_gbl_root_table_list.tables = tables;
Lv Zheng2bc198c2012-09-13 09:29:06 -0700855 acpi_gbl_root_table_list.max_table_count =
856 table_count + ACPI_ROOT_TABLE_SIZE_INCREMENT;
857 acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Len Brown4be44fc2005-08-05 00:44:28 -0400859 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860}
861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862/*******************************************************************************
863 *
Bob Mooreed6f1d42014-04-04 12:39:26 +0800864 * FUNCTION: acpi_tb_get_root_table_entry
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800865 *
866 * PARAMETERS: table_index - Where table index is returned
867 *
868 * RETURN: Status and table index.
869 *
870 * DESCRIPTION: Allocate a new ACPI table entry to the global table list
871 *
872 ******************************************************************************/
873
Bob Mooreed6f1d42014-04-04 12:39:26 +0800874static acpi_status acpi_tb_get_root_table_entry(u32 *table_index)
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800875{
876 acpi_status status;
877
878 /* Ensure that there is room for the table in the Root Table List */
879
880 if (acpi_gbl_root_table_list.current_table_count >=
881 acpi_gbl_root_table_list.max_table_count) {
882 status = acpi_tb_resize_root_table_list();
883 if (ACPI_FAILURE(status)) {
884 return (status);
885 }
886 }
887
888 *table_index = acpi_gbl_root_table_list.current_table_count;
889 acpi_gbl_root_table_list.current_table_count++;
890 return (AE_OK);
891}
892
893/*******************************************************************************
894 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300895 * FUNCTION: acpi_tb_store_table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 *
Bob Mooreba494be2012-07-12 09:40:10 +0800897 * PARAMETERS: address - Table address
898 * table - Table header
899 * length - Table length
Bob Mooreed6f1d42014-04-04 12:39:26 +0800900 * flags - Install flags
901 * table_index - Where the table index is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300903 * RETURN: Status and table index.
904 *
905 * DESCRIPTION: Add an ACPI table to the global table list
906 *
907 ******************************************************************************/
908
909acpi_status
910acpi_tb_store_table(acpi_physical_address address,
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800911 struct acpi_table_header * table,
Bob Moore67a119f2008-06-10 13:42:13 +0800912 u32 length, u8 flags, u32 *table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +0300913{
Bob Mooreb9ee2042010-04-27 11:16:14 +0800914 acpi_status status;
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800915 struct acpi_table_desc *table_desc;
Bob Mooref3d2e782007-02-02 19:48:18 +0300916
Bob Mooreed6f1d42014-04-04 12:39:26 +0800917 status = acpi_tb_get_root_table_entry(table_index);
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800918 if (ACPI_FAILURE(status)) {
919 return (status);
Bob Mooref3d2e782007-02-02 19:48:18 +0300920 }
921
922 /* Initialize added table */
923
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800924 table_desc = &acpi_gbl_root_table_list.tables[*table_index];
Bob Mooreed6f1d42014-04-04 12:39:26 +0800925 acpi_tb_init_table_descriptor(table_desc, address, flags, table);
Lv Zheng86dfc6f32014-04-04 12:38:57 +0800926 table_desc->pointer = table;
Bob Mooreb9ee2042010-04-27 11:16:14 +0800927 return (AE_OK);
Bob Mooref3d2e782007-02-02 19:48:18 +0300928}
929
930/*******************************************************************************
931 *
Lv Zheng7f9fc992014-04-04 12:38:42 +0800932 * FUNCTION: acpi_tb_uninstall_table
Bob Mooref3d2e782007-02-02 19:48:18 +0300933 *
Lv Zheng7f9fc992014-04-04 12:38:42 +0800934 * PARAMETERS: table_desc - Table descriptor
Bob Mooref3d2e782007-02-02 19:48:18 +0300935 *
936 * RETURN: None
937 *
938 * DESCRIPTION: Delete one internal ACPI table
939 *
940 ******************************************************************************/
941
Lv Zheng7f9fc992014-04-04 12:38:42 +0800942void acpi_tb_uninstall_table(struct acpi_table_desc *table_desc)
Bob Mooref3d2e782007-02-02 19:48:18 +0300943{
Lv Zheng55829822014-04-04 12:38:18 +0800944
Lv Zheng7f9fc992014-04-04 12:38:42 +0800945 ACPI_FUNCTION_TRACE(tb_uninstall_table);
Lv Zheng55829822014-04-04 12:38:18 +0800946
Lv Zheng7f9fc992014-04-04 12:38:42 +0800947 /* Table must be installed */
948
949 if (!table_desc->address) {
950 return_VOID;
Bob Mooref3d2e782007-02-02 19:48:18 +0300951 }
Lv Zheng55829822014-04-04 12:38:18 +0800952
Lv Zheng7f9fc992014-04-04 12:38:42 +0800953 acpi_tb_invalidate_table(table_desc);
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000954
Lv Zheng7f9fc992014-04-04 12:38:42 +0800955 if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
Bob Mooreed6f1d42014-04-04 12:39:26 +0800956 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL) {
Lv Zheng7f9fc992014-04-04 12:38:42 +0800957 ACPI_FREE(ACPI_CAST_PTR(void, table_desc->address));
Bob Mooref3d2e782007-02-02 19:48:18 +0300958 }
959
Lv Zheng7f9fc992014-04-04 12:38:42 +0800960 table_desc->address = ACPI_PTR_TO_PHYSADDR(NULL);
Lv Zheng7f9fc992014-04-04 12:38:42 +0800961 return_VOID;
Bob Mooref3d2e782007-02-02 19:48:18 +0300962}
963
964/*******************************************************************************
965 *
966 * FUNCTION: acpi_tb_terminate
967 *
968 * PARAMETERS: None
969 *
970 * RETURN: None
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 *
972 * DESCRIPTION: Delete all internal ACPI tables
973 *
974 ******************************************************************************/
975
Bob Mooref3d2e782007-02-02 19:48:18 +0300976void acpi_tb_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977{
Bob Moore67a119f2008-06-10 13:42:13 +0800978 u32 i;
Bob Mooref3d2e782007-02-02 19:48:18 +0300979
980 ACPI_FUNCTION_TRACE(tb_terminate);
981
982 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
983
984 /* Delete the individual tables */
985
Bob Mooreb9ee2042010-04-27 11:16:14 +0800986 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
Lv Zheng7f9fc992014-04-04 12:38:42 +0800987 acpi_tb_uninstall_table(&acpi_gbl_root_table_list.tables[i]);
Bob Mooref3d2e782007-02-02 19:48:18 +0300988 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
990 /*
Bob Mooref3d2e782007-02-02 19:48:18 +0300991 * Delete the root table array if allocated locally. Array cannot be
992 * mapped, so we don't need to check for that flag.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300994 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300995 ACPI_FREE(acpi_gbl_root_table_list.tables);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300997
998 acpi_gbl_root_table_list.tables = NULL;
999 acpi_gbl_root_table_list.flags = 0;
Bob Mooreb9ee2042010-04-27 11:16:14 +08001000 acpi_gbl_root_table_list.current_table_count = 0;
Bob Mooref3d2e782007-02-02 19:48:18 +03001001
1002 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
Bob Moore68aafc32012-10-31 02:26:01 +00001003
Bob Mooreed6f1d42014-04-04 12:39:26 +08001004 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Bob Moore68aafc32012-10-31 02:26:01 +00001005 return_VOID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006}
1007
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008/*******************************************************************************
1009 *
Bob Mooref3d2e782007-02-02 19:48:18 +03001010 * FUNCTION: acpi_tb_delete_namespace_by_owner
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 *
Bob Mooref3d2e782007-02-02 19:48:18 +03001012 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 *
Bob Moore8a335a232009-03-09 16:31:04 +08001014 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 *
Bob Mooref3d2e782007-02-02 19:48:18 +03001016 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 *
1018 ******************************************************************************/
1019
Bob Moore8a335a232009-03-09 16:31:04 +08001020acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021{
Bob Mooref3d2e782007-02-02 19:48:18 +03001022 acpi_owner_id owner_id;
Bob Moore8a335a232009-03-09 16:31:04 +08001023 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
Bob Moore8a335a232009-03-09 16:31:04 +08001025 ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner);
1026
1027 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
1028 if (ACPI_FAILURE(status)) {
1029 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 }
1031
Bob Mooreb9ee2042010-04-27 11:16:14 +08001032 if (table_index >= acpi_gbl_root_table_list.current_table_count) {
Bob Moore8a335a232009-03-09 16:31:04 +08001033
1034 /* The table index does not exist */
1035
1036 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
1037 return_ACPI_STATUS(AE_NOT_EXIST);
1038 }
1039
1040 /* Get the owner ID for this table, used to delete namespace nodes */
1041
1042 owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id;
Len Brown4be44fc2005-08-05 00:44:28 -04001043 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Bob Moore8a335a232009-03-09 16:31:04 +08001044
1045 /*
1046 * Need to acquire the namespace writer lock to prevent interference
1047 * with any concurrent namespace walks. The interpreter must be
1048 * released during the deletion since the acquisition of the deletion
1049 * lock may block, and also since the execution of a namespace walk
1050 * must be allowed to use the interpreter.
1051 */
Bob Mooree4c1ebf2009-04-22 13:02:06 +08001052 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
Bob Moore8a335a232009-03-09 16:31:04 +08001053 status = acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock);
1054
Bob Mooref3d2e782007-02-02 19:48:18 +03001055 acpi_ns_delete_namespace_by_owner(owner_id);
Bob Moore8a335a232009-03-09 16:31:04 +08001056 if (ACPI_FAILURE(status)) {
1057 return_ACPI_STATUS(status);
1058 }
1059
1060 acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock);
1061
1062 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
1063 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064}
1065
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066/*******************************************************************************
1067 *
Bob Mooref3d2e782007-02-02 19:48:18 +03001068 * FUNCTION: acpi_tb_allocate_owner_id
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 *
Bob Mooref3d2e782007-02-02 19:48:18 +03001070 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 *
Bob Mooref3d2e782007-02-02 19:48:18 +03001072 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 *
Bob Mooref3d2e782007-02-02 19:48:18 +03001074 * DESCRIPTION: Allocates owner_id in table_desc
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 *
1076 ******************************************************************************/
1077
Bob Moore67a119f2008-06-10 13:42:13 +08001078acpi_status acpi_tb_allocate_owner_id(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079{
Bob Mooref3d2e782007-02-02 19:48:18 +03001080 acpi_status status = AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
Bob Mooref3d2e782007-02-02 19:48:18 +03001082 ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
Bob Mooref3d2e782007-02-02 19:48:18 +03001084 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +08001085 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooreed6f1d42014-04-04 12:39:26 +08001086 status =
1087 acpi_ut_allocate_owner_id(&
1088 (acpi_gbl_root_table_list.
1089 tables[table_index].owner_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 }
1091
Bob Mooref3d2e782007-02-02 19:48:18 +03001092 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
1093 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094}
1095
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096/*******************************************************************************
1097 *
Bob Mooref3d2e782007-02-02 19:48:18 +03001098 * FUNCTION: acpi_tb_release_owner_id
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 *
Bob Mooref3d2e782007-02-02 19:48:18 +03001100 * PARAMETERS: table_index - Table index
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 *
Bob Mooref3d2e782007-02-02 19:48:18 +03001102 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 *
Bob Mooref3d2e782007-02-02 19:48:18 +03001104 * DESCRIPTION: Releases owner_id in table_desc
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 *
1106 ******************************************************************************/
1107
Bob Moore67a119f2008-06-10 13:42:13 +08001108acpi_status acpi_tb_release_owner_id(u32 table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109{
Bob Mooref3d2e782007-02-02 19:48:18 +03001110 acpi_status status = AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
Bob Mooref3d2e782007-02-02 19:48:18 +03001112 ACPI_FUNCTION_TRACE(tb_release_owner_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
Bob Mooref3d2e782007-02-02 19:48:18 +03001114 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +08001115 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +03001116 acpi_ut_release_owner_id(&
1117 (acpi_gbl_root_table_list.
1118 tables[table_index].owner_id));
1119 status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 }
1121
Bob Mooref3d2e782007-02-02 19:48:18 +03001122 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
1123 return_ACPI_STATUS(status);
1124}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Bob Mooref3d2e782007-02-02 19:48:18 +03001126/*******************************************************************************
1127 *
1128 * FUNCTION: acpi_tb_get_owner_id
1129 *
1130 * PARAMETERS: table_index - Table index
1131 * owner_id - Where the table owner_id is returned
1132 *
1133 * RETURN: Status
1134 *
1135 * DESCRIPTION: returns owner_id for the ACPI table
1136 *
1137 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
Lv Zheng55829822014-04-04 12:38:18 +08001139acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id * owner_id)
Bob Mooref3d2e782007-02-02 19:48:18 +03001140{
1141 acpi_status status = AE_BAD_PARAMETER;
1142
1143 ACPI_FUNCTION_TRACE(tb_get_owner_id);
1144
1145 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +08001146 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +03001147 *owner_id =
1148 acpi_gbl_root_table_list.tables[table_index].owner_id;
1149 status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 }
1151
Bob Mooref3d2e782007-02-02 19:48:18 +03001152 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
1153 return_ACPI_STATUS(status);
1154}
1155
1156/*******************************************************************************
1157 *
1158 * FUNCTION: acpi_tb_is_table_loaded
1159 *
Bob Mooreed6f1d42014-04-04 12:39:26 +08001160 * PARAMETERS: table_index - Index into the root table
Bob Mooref3d2e782007-02-02 19:48:18 +03001161 *
1162 * RETURN: Table Loaded Flag
1163 *
1164 ******************************************************************************/
1165
Bob Moore67a119f2008-06-10 13:42:13 +08001166u8 acpi_tb_is_table_loaded(u32 table_index)
Bob Mooref3d2e782007-02-02 19:48:18 +03001167{
1168 u8 is_loaded = FALSE;
1169
1170 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +08001171 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +03001172 is_loaded = (u8)
Bob Mooreec41f192009-02-18 15:03:30 +08001173 (acpi_gbl_root_table_list.tables[table_index].flags &
1174 ACPI_TABLE_IS_LOADED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 }
1176
Bob Mooref3d2e782007-02-02 19:48:18 +03001177 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
1178 return (is_loaded);
1179}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
Bob Mooref3d2e782007-02-02 19:48:18 +03001181/*******************************************************************************
1182 *
1183 * FUNCTION: acpi_tb_set_table_loaded_flag
1184 *
1185 * PARAMETERS: table_index - Table index
1186 * is_loaded - TRUE if table is loaded, FALSE otherwise
1187 *
1188 * RETURN: None
1189 *
1190 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
1191 *
1192 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
Bob Moore67a119f2008-06-10 13:42:13 +08001194void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
Bob Mooref3d2e782007-02-02 19:48:18 +03001195{
Bob Mooref6dd9222006-07-07 20:44:38 -04001196
Bob Mooref3d2e782007-02-02 19:48:18 +03001197 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Bob Mooreb9ee2042010-04-27 11:16:14 +08001198 if (table_index < acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +03001199 if (is_loaded) {
1200 acpi_gbl_root_table_list.tables[table_index].flags |=
Bob Moorec5fc42a2007-02-02 19:48:19 +03001201 ACPI_TABLE_IS_LOADED;
Bob Mooref3d2e782007-02-02 19:48:18 +03001202 } else {
1203 acpi_gbl_root_table_list.tables[table_index].flags &=
Bob Moorec5fc42a2007-02-02 19:48:19 +03001204 ~ACPI_TABLE_IS_LOADED;
Bob Mooref3d2e782007-02-02 19:48:18 +03001205 }
1206 }
Bob Mooref6dd9222006-07-07 20:44:38 -04001207
Bob Mooref3d2e782007-02-02 19:48:18 +03001208 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209}