blob: 9d451e8a4e46eb30674edec1b9d7a65c739fc17d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: tbxface - Public interfaces to the ACPI subsystem
4 * ACPI table oriented interfaces
5 *
6 *****************************************************************************/
7
8/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05009 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <acpi/acpi.h>
46#include <acpi/acnamesp.h>
47#include <acpi/actables.h>
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define _COMPONENT ACPI_TABLES
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("tbxface")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Bob Mooref3d2e782007-02-02 19:48:18 +030052/* Local prototypes */
53static acpi_status acpi_tb_load_namespace(void);
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055/*******************************************************************************
56 *
Bob Moore77389e12007-02-02 19:48:20 +030057 * FUNCTION: acpi_allocate_root_table
58 *
59 * PARAMETERS: initial_table_count - Size of initial_table_array, in number of
60 * struct acpi_table_desc structures
61 *
62 * RETURN: Status
63 *
64 * DESCRIPTION: Allocate a root table array. Used by i_aSL compiler and
65 * acpi_initialize_tables.
66 *
67 ******************************************************************************/
68
69acpi_status acpi_allocate_root_table(u32 initial_table_count)
70{
71
72 acpi_gbl_root_table_list.size = initial_table_count;
73 acpi_gbl_root_table_list.flags = ACPI_ROOT_ALLOW_RESIZE;
74
75 return (acpi_tb_resize_root_table_list());
76}
77
78/*******************************************************************************
79 *
Bob Mooref3d2e782007-02-02 19:48:18 +030080 * FUNCTION: acpi_initialize_tables
81 *
82 * PARAMETERS: initial_table_array - Pointer to an array of pre-allocated
83 * struct acpi_table_desc structures. If NULL, the
84 * array is dynamically allocated.
85 * initial_table_count - Size of initial_table_array, in number of
86 * struct acpi_table_desc structures
87 * allow_realloc - Flag to tell Table Manager if resize of
88 * pre-allocated array is allowed. Ignored
89 * if initial_table_array is NULL.
90 *
91 * RETURN: Status
92 *
93 * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
94 *
95 * NOTE: Allows static allocation of the initial table array in order
96 * to avoid the use of dynamic memory in confined environments
97 * such as the kernel boot sequence where it may not be available.
98 *
99 * If the host OS memory managers are initialized, use NULL for
100 * initial_table_array, and the table will be dynamically allocated.
101 *
102 ******************************************************************************/
103
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300104acpi_status __init
Bob Moore77389e12007-02-02 19:48:20 +0300105acpi_initialize_tables(struct acpi_table_desc * initial_table_array,
Bob Mooref3d2e782007-02-02 19:48:18 +0300106 u32 initial_table_count, u8 allow_resize)
107{
Bob Moorec5fc42a2007-02-02 19:48:19 +0300108 acpi_physical_address rsdp_address;
Bob Mooref3d2e782007-02-02 19:48:18 +0300109 acpi_status status;
Bob Mooref3d2e782007-02-02 19:48:18 +0300110
111 ACPI_FUNCTION_TRACE(acpi_initialize_tables);
112
113 /*
114 * Set up the Root Table Array
115 * Allocate the table array if requested
116 */
117 if (!initial_table_array) {
Bob Moore77389e12007-02-02 19:48:20 +0300118 status = acpi_allocate_root_table(initial_table_count);
Bob Mooref3d2e782007-02-02 19:48:18 +0300119 if (ACPI_FAILURE(status)) {
120 return_ACPI_STATUS(status);
121 }
122 } else {
123 /* Root Table Array has been statically allocated by the host */
124
Bob Moorea4bbb8102007-02-02 19:48:19 +0300125 ACPI_MEMSET(initial_table_array, 0,
Bob Moorec5fc42a2007-02-02 19:48:19 +0300126 initial_table_count *
Bob Moorea4bbb8102007-02-02 19:48:19 +0300127 sizeof(struct acpi_table_desc));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300128
Bob Mooref3d2e782007-02-02 19:48:18 +0300129 acpi_gbl_root_table_list.tables = initial_table_array;
130 acpi_gbl_root_table_list.size = initial_table_count;
Bob Moorec5fc42a2007-02-02 19:48:19 +0300131 acpi_gbl_root_table_list.flags = ACPI_ROOT_ORIGIN_UNKNOWN;
Bob Mooref3d2e782007-02-02 19:48:18 +0300132 if (allow_resize) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300133 acpi_gbl_root_table_list.flags |=
134 ACPI_ROOT_ALLOW_RESIZE;
Bob Mooref3d2e782007-02-02 19:48:18 +0300135 }
136 }
137
Bob Moorec5fc42a2007-02-02 19:48:19 +0300138 /* Get the address of the RSDP */
Bob Mooref3d2e782007-02-02 19:48:18 +0300139
Bob Moorec5fc42a2007-02-02 19:48:19 +0300140 rsdp_address = acpi_os_get_root_pointer();
141 if (!rsdp_address) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300142 return_ACPI_STATUS(AE_NOT_FOUND);
143 }
144
Bob Mooref3d2e782007-02-02 19:48:18 +0300145 /*
146 * Get the root table (RSDT or XSDT) and extract all entries to the local
147 * Root Table Array. This array contains the information of the RSDT/XSDT
148 * in a common, more useable format.
149 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300150 status =
151 acpi_tb_parse_root_table(rsdp_address, ACPI_TABLE_ORIGIN_MAPPED);
Bob Mooref3d2e782007-02-02 19:48:18 +0300152 return_ACPI_STATUS(status);
153}
154
Bob Mooref3d2e782007-02-02 19:48:18 +0300155/*******************************************************************************
156 *
157 * FUNCTION: acpi_reallocate_root_table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 *
159 * PARAMETERS: None
160 *
161 * RETURN: Status
162 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300163 * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the
164 * root list from the previously provided scratch area. Should
165 * be called once dynamic memory allocation is available in the
166 * kernel
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 *
168 ******************************************************************************/
Bob Mooref3d2e782007-02-02 19:48:18 +0300169acpi_status acpi_reallocate_root_table(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170{
Bob Mooref3d2e782007-02-02 19:48:18 +0300171 struct acpi_table_desc *tables;
172 acpi_size new_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Bob Mooref3d2e782007-02-02 19:48:18 +0300174 ACPI_FUNCTION_TRACE(acpi_reallocate_root_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Bob Mooref3d2e782007-02-02 19:48:18 +0300176 /*
177 * Only reallocate the root table if the host provided a static buffer
178 * for the table array in the call to acpi_initialize_tables.
179 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300180 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300181 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 }
183
Bob Mooref3d2e782007-02-02 19:48:18 +0300184 new_size =
185 (acpi_gbl_root_table_list.count +
186 ACPI_ROOT_TABLE_SIZE_INCREMENT) * sizeof(struct acpi_table_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Bob Mooref3d2e782007-02-02 19:48:18 +0300188 /* Create new array and copy the old array */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Bob Mooref3d2e782007-02-02 19:48:18 +0300190 tables = ACPI_ALLOCATE_ZEROED(new_size);
191 if (!tables) {
192 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 }
194
Bob Mooref3d2e782007-02-02 19:48:18 +0300195 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables, new_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Bob Mooref3d2e782007-02-02 19:48:18 +0300197 acpi_gbl_root_table_list.size = acpi_gbl_root_table_list.count;
198 acpi_gbl_root_table_list.tables = tables;
199 acpi_gbl_root_table_list.flags =
Bob Moorec5fc42a2007-02-02 19:48:19 +0300200 ACPI_ROOT_ORIGIN_ALLOCATED | ACPI_ROOT_ALLOW_RESIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Len Brown4be44fc2005-08-05 00:44:28 -0400202 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204/*******************************************************************************
205 *
206 * FUNCTION: acpi_load_table
207 *
208 * PARAMETERS: table_ptr - pointer to a buffer containing the entire
209 * table to be loaded
210 *
211 * RETURN: Status
212 *
213 * DESCRIPTION: This function is called to load a table from the caller's
Bob Mooref6dd9222006-07-07 20:44:38 -0400214 * buffer. The buffer must contain an entire ACPI Table including
215 * a valid header. The header fields will be verified, and if it
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 * is determined that the table is invalid, the call will fail.
217 *
218 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400219acpi_status acpi_load_table(struct acpi_table_header *table_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Len Brown4be44fc2005-08-05 00:44:28 -0400221 acpi_status status;
Bob Mooref3d2e782007-02-02 19:48:18 +0300222 acpi_native_uint table_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Bob Mooref3d2e782007-02-02 19:48:18 +0300224 /*
225 * Install the new table into the local data structures
226 */
227 status = acpi_tb_add_table(table_ptr, &table_index);
Len Brown4be44fc2005-08-05 00:44:28 -0400228 if (ACPI_FAILURE(status)) {
229 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300231 status = acpi_ns_load_table(table_index, acpi_gbl_root_node);
Len Brown4be44fc2005-08-05 00:44:28 -0400232 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233}
234
Bob Moore83135242006-10-03 00:00:00 -0400235ACPI_EXPORT_SYMBOL(acpi_load_table)
236
Bob Mooref3d2e782007-02-02 19:48:18 +0300237/******************************************************************************
238 *
239 * FUNCTION: acpi_get_table_header
240 *
241 * PARAMETERS: Signature - ACPI signature of needed table
242 * Instance - Which instance (for SSDTs)
243 * out_table_header - Where the pointer to the table header
244 * is returned
245 *
246 * RETURN: Status and pointer to mapped table header
247 *
248 * DESCRIPTION: Finds an ACPI table header.
249 *
250 * NOTE: Caller is responsible in unmapping the header with
251 * acpi_os_unmap_memory
252 *
253 *****************************************************************************/
254acpi_status
255acpi_get_table_header(char *signature,
256 acpi_native_uint instance,
257 struct acpi_table_header **out_table_header)
258{
259 acpi_native_uint i;
260 acpi_native_uint j;
261
Bob Moorec5fc42a2007-02-02 19:48:19 +0300262 /* Parameter validation */
263
264 if (!signature || !out_table_header) {
265 return (AE_BAD_PARAMETER);
266 }
267
Bob Mooref3d2e782007-02-02 19:48:18 +0300268 /*
269 * Walk the root table list
270 */
271 for (i = 0, j = 0; i < acpi_gbl_root_table_list.count; i++) {
272 if (!ACPI_COMPARE_NAME
273 (&(acpi_gbl_root_table_list.tables[i].signature),
274 signature)) {
275 continue;
276 }
277
278 if (++j < instance) {
279 continue;
280 }
281
282 *out_table_header =
283 acpi_tb_map(acpi_gbl_root_table_list.tables[i].address,
284 (u32) sizeof(struct acpi_table_header),
285 acpi_gbl_root_table_list.tables[i].
286 flags & ACPI_TABLE_ORIGIN_MASK);
287
Bob Moorec5fc42a2007-02-02 19:48:19 +0300288 if (!(*out_table_header)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300289 return (AE_NO_MEMORY);
290 }
291
292 return (AE_OK);
293 }
294
295 return (AE_NOT_FOUND);
296}
297
298ACPI_EXPORT_SYMBOL(acpi_get_table_header)
299
300
301/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 *
John Keller0f0fe1a2006-12-19 12:56:19 -0800303 * FUNCTION: acpi_unload_table_id
304 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300305 * PARAMETERS: id - Owner ID of the table to be removed.
John Keller0f0fe1a2006-12-19 12:56:19 -0800306 *
307 * RETURN: Status
308 *
309 * DESCRIPTION: This routine is used to force the unload of a table (by id)
310 *
311 ******************************************************************************/
Bob Mooref3d2e782007-02-02 19:48:18 +0300312acpi_status acpi_unload_table_id(acpi_owner_id id)
John Keller0f0fe1a2006-12-19 12:56:19 -0800313{
Bob Mooref3d2e782007-02-02 19:48:18 +0300314 int i;
315 acpi_status status = AE_NOT_EXIST;
John Keller0f0fe1a2006-12-19 12:56:19 -0800316
317 ACPI_FUNCTION_TRACE(acpi_unload_table);
318
John Keller0f0fe1a2006-12-19 12:56:19 -0800319 /* Find table from the requested type list */
Bob Mooref3d2e782007-02-02 19:48:18 +0300320 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
321 if (id != acpi_gbl_root_table_list.tables[i].owner_id) {
322 continue;
323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 /*
Bob Mooref3d2e782007-02-02 19:48:18 +0300325 * Delete all namespace objects owned by this table. Note that these
326 * objects can appear anywhere in the namespace by virtue of the AML
327 * "Scope" operator. Thus, we need to track ownership by an ID, not
328 * simply a position within the hierarchy
329 */
330 acpi_tb_delete_namespace_by_owner(i);
331 acpi_tb_release_owner_id(i);
332 acpi_tb_set_table_loaded_flag(i, FALSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 }
Len Brown4be44fc2005-08-05 00:44:28 -0400334 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335}
336
Bob Mooref3d2e782007-02-02 19:48:18 +0300337ACPI_EXPORT_SYMBOL(acpi_unload_table_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339/*******************************************************************************
340 *
341 * FUNCTION: acpi_get_table
342 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300343 * PARAMETERS: Signature - ACPI signature of needed table
344 * Instance - Which instance (for SSDTs)
345 * out_table - Where the pointer to the table is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300347 * RETURN: Status and pointer to table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300349 * DESCRIPTION: Finds and verifies an ACPI table.
350 *
351 *****************************************************************************/
352acpi_status
353acpi_get_table(char *signature,
354 acpi_native_uint instance, struct acpi_table_header ** out_table)
355{
356 acpi_native_uint i;
357 acpi_native_uint j;
358 acpi_status status;
359
Bob Moorec5fc42a2007-02-02 19:48:19 +0300360 /* Parameter validation */
361
362 if (!signature || !out_table) {
363 return (AE_BAD_PARAMETER);
364 }
365
Bob Mooref3d2e782007-02-02 19:48:18 +0300366 /*
367 * Walk the root table list
368 */
369 for (i = 0, j = 0; i < acpi_gbl_root_table_list.count; i++) {
370 if (!ACPI_COMPARE_NAME
371 (&(acpi_gbl_root_table_list.tables[i].signature),
372 signature)) {
373 continue;
374 }
375
376 if (++j < instance) {
377 continue;
378 }
379
380 status =
381 acpi_tb_verify_table(&acpi_gbl_root_table_list.tables[i]);
382 if (ACPI_SUCCESS(status)) {
383 *out_table = acpi_gbl_root_table_list.tables[i].pointer;
384 }
385
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300386 if (!acpi_gbl_permanent_mmap) {
387 acpi_gbl_root_table_list.tables[i].pointer = 0;
388 }
389
Bob Mooref3d2e782007-02-02 19:48:18 +0300390 return (status);
391 }
392
393 return (AE_NOT_FOUND);
394}
395
396ACPI_EXPORT_SYMBOL(acpi_get_table)
397
398/*******************************************************************************
399 *
400 * FUNCTION: acpi_get_table_by_index
401 *
402 * PARAMETERS: table_index - Table index
403 * Table - Where the pointer to the table is returned
404 *
405 * RETURN: Status and pointer to the table
406 *
407 * DESCRIPTION: Obtain a table by an index into the global table list.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 *
409 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410acpi_status
Bob Mooref3d2e782007-02-02 19:48:18 +0300411acpi_get_table_by_index(acpi_native_uint table_index,
412 struct acpi_table_header ** table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
Len Brown4be44fc2005-08-05 00:44:28 -0400414 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Bob Mooref3d2e782007-02-02 19:48:18 +0300416 ACPI_FUNCTION_TRACE(acpi_get_table_by_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Bob Moorec5fc42a2007-02-02 19:48:19 +0300418 /* Parameter validation */
419
420 if (!table) {
421 return_ACPI_STATUS(AE_BAD_PARAMETER);
422 }
423
Bob Mooref3d2e782007-02-02 19:48:18 +0300424 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Bob Mooref3d2e782007-02-02 19:48:18 +0300426 /* Validate index */
427
428 if (table_index >= acpi_gbl_root_table_list.count) {
429 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Len Brown4be44fc2005-08-05 00:44:28 -0400430 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 }
432
Bob Mooref3d2e782007-02-02 19:48:18 +0300433 if (!acpi_gbl_root_table_list.tables[table_index].pointer) {
434
435 /* Table is not mapped, map it */
436
437 status =
438 acpi_tb_verify_table(&acpi_gbl_root_table_list.
439 tables[table_index]);
440 if (ACPI_FAILURE(status)) {
441 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
442 return_ACPI_STATUS(status);
443 }
444 }
445
446 *table = acpi_gbl_root_table_list.tables[table_index].pointer;
447 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
448 return_ACPI_STATUS(AE_OK);
449}
450
451ACPI_EXPORT_SYMBOL(acpi_get_table_by_index)
452
453/*******************************************************************************
454 *
455 * FUNCTION: acpi_tb_load_namespace
456 *
457 * PARAMETERS: None
458 *
459 * RETURN: Status
460 *
461 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
462 * the RSDT/XSDT.
463 *
464 ******************************************************************************/
465static acpi_status acpi_tb_load_namespace(void)
466{
467 acpi_status status;
468 struct acpi_table_header *table;
469 acpi_native_uint i;
470
471 ACPI_FUNCTION_TRACE(tb_load_namespace);
472
473 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
474
475 /*
476 * Load the namespace. The DSDT is required, but any SSDT and PSDT tables
477 * are optional.
478 */
479 if (!acpi_gbl_root_table_list.count ||
480 !ACPI_COMPARE_NAME(&
481 (acpi_gbl_root_table_list.
482 tables[ACPI_TABLE_INDEX_DSDT].signature),
483 ACPI_SIG_DSDT)
484 ||
485 ACPI_FAILURE(acpi_tb_verify_table
486 (&acpi_gbl_root_table_list.
487 tables[ACPI_TABLE_INDEX_DSDT]))) {
488 status = AE_NO_ACPI_TABLES;
489 goto unlock_and_exit;
490 }
491
492 /*
493 * Find DSDT table
494 */
495 status =
496 acpi_os_table_override(acpi_gbl_root_table_list.
497 tables[ACPI_TABLE_INDEX_DSDT].pointer,
498 &table);
499 if (ACPI_SUCCESS(status) && table) {
500 /*
501 * DSDT table has been found
502 */
503 acpi_tb_delete_table(ACPI_TABLE_INDEX_DSDT);
504 acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].pointer =
505 table;
506 acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].length =
507 table->length;
508 acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].flags =
509 ACPI_TABLE_ORIGIN_UNKNOWN;
510
511 ACPI_INFO((AE_INFO, "Table DSDT replaced by host OS"));
512 acpi_tb_print_table_header(0, table);
513 }
514
515 status =
516 acpi_tb_verify_table(&acpi_gbl_root_table_list.
517 tables[ACPI_TABLE_INDEX_DSDT]);
Len Brown4be44fc2005-08-05 00:44:28 -0400518 if (ACPI_FAILURE(status)) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300519
520 /* A valid DSDT is required */
521
522 status = AE_NO_ACPI_TABLES;
523 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 }
525
Bob Mooref3d2e782007-02-02 19:48:18 +0300526 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Bob Mooref3d2e782007-02-02 19:48:18 +0300528 /*
529 * Load and parse tables.
530 */
531 status = acpi_ns_load_table(ACPI_TABLE_INDEX_DSDT, acpi_gbl_root_node);
Len Brown4be44fc2005-08-05 00:44:28 -0400532 if (ACPI_FAILURE(status)) {
533 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 }
535
536 /*
Bob Mooref3d2e782007-02-02 19:48:18 +0300537 * Load any SSDT or PSDT tables. Note: Loop leaves tables locked
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300539 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
540 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
541 if ((!ACPI_COMPARE_NAME
542 (&(acpi_gbl_root_table_list.tables[i].signature),
543 ACPI_SIG_SSDT)
544 &&
545 !ACPI_COMPARE_NAME(&
546 (acpi_gbl_root_table_list.tables[i].
547 signature), ACPI_SIG_PSDT))
548 ||
549 ACPI_FAILURE(acpi_tb_verify_table
550 (&acpi_gbl_root_table_list.tables[i]))) {
551 continue;
552 }
553
554 /* Ignore errors while loading tables, get as many as possible */
555
556 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
557 (void)acpi_ns_load_table(i, acpi_gbl_root_node);
558 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 }
560
Bob Mooref3d2e782007-02-02 19:48:18 +0300561 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Bob Mooref3d2e782007-02-02 19:48:18 +0300563 unlock_and_exit:
564 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
565 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Bob Mooref3d2e782007-02-02 19:48:18 +0300568/*******************************************************************************
569 *
570 * FUNCTION: acpi_load_tables
571 *
572 * PARAMETERS: None
573 *
574 * RETURN: Status
575 *
576 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
577 *
578 ******************************************************************************/
579
580acpi_status acpi_load_tables(void)
581{
582 acpi_status status;
583
584 ACPI_FUNCTION_TRACE(acpi_load_tables);
585
586 /*
587 * Load the namespace from the tables
588 */
589 status = acpi_tb_load_namespace();
590 if (ACPI_FAILURE(status)) {
591 ACPI_EXCEPTION((AE_INFO, status,
592 "While loading namespace from ACPI tables"));
593 }
594
595 return_ACPI_STATUS(status);
596}
597
598ACPI_EXPORT_SYMBOL(acpi_load_tables)