1 /******************************************************************************
3 * Module Name: tbxface - Public interfaces to the ACPI subsystem
4 * ACPI table oriented interfaces
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2006, R. Byron Moore
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
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.
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.
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.
45 #include <acpi/acpi.h>
46 #include <acpi/acnamesp.h>
47 #include <acpi/actables.h>
49 #define _COMPONENT ACPI_TABLES
50 ACPI_MODULE_NAME("tbxface")
52 /*******************************************************************************
54 * FUNCTION: acpi_load_tables
60 * DESCRIPTION: This function is called to load the ACPI tables from the
63 ******************************************************************************/
64 acpi_status
acpi_load_tables(void)
66 struct acpi_pointer rsdp_address
;
69 ACPI_FUNCTION_TRACE(acpi_load_tables
);
73 status
= acpi_os_get_root_pointer(ACPI_LOGICAL_ADDRESSING
,
75 if (ACPI_FAILURE(status
)) {
76 ACPI_EXCEPTION((AE_INFO
, status
, "Could not get the RSDP"));
80 /* Map and validate the RSDP */
82 acpi_gbl_table_flags
= rsdp_address
.pointer_type
;
84 status
= acpi_tb_verify_rsdp(&rsdp_address
);
85 if (ACPI_FAILURE(status
)) {
86 ACPI_EXCEPTION((AE_INFO
, status
, "During RSDP validation"));
90 /* Get the RSDT via the RSDP */
92 status
= acpi_tb_get_table_rsdt();
93 if (ACPI_FAILURE(status
)) {
94 ACPI_EXCEPTION((AE_INFO
, status
, "Could not load RSDT"));
98 /* Now get the tables needed by this subsystem (FADT, DSDT, etc.) */
100 status
= acpi_tb_get_required_tables();
101 if (ACPI_FAILURE(status
)) {
102 ACPI_EXCEPTION((AE_INFO
, status
,
103 "Could not get all required tables (DSDT/FADT/FACS)"));
107 ACPI_DEBUG_PRINT((ACPI_DB_INIT
, "ACPI Tables successfully acquired\n"));
109 /* Load the namespace from the tables */
111 status
= acpi_ns_load_namespace();
112 if (ACPI_FAILURE(status
)) {
113 ACPI_EXCEPTION((AE_INFO
, status
, "Could not load namespace"));
117 return_ACPI_STATUS(AE_OK
);
120 ACPI_EXCEPTION((AE_INFO
, status
, "Could not load tables"));
121 return_ACPI_STATUS(status
);
124 ACPI_EXPORT_SYMBOL(acpi_load_tables
)
126 /*******************************************************************************
128 * FUNCTION: acpi_load_table
130 * PARAMETERS: table_ptr - pointer to a buffer containing the entire
135 * DESCRIPTION: This function is called to load a table from the caller's
136 * buffer. The buffer must contain an entire ACPI Table including
137 * a valid header. The header fields will be verified, and if it
138 * is determined that the table is invalid, the call will fail.
140 ******************************************************************************/
141 acpi_status
acpi_load_table(struct acpi_table_header
*table_ptr
)
144 struct acpi_table_desc table_info
;
145 struct acpi_pointer address
;
147 ACPI_FUNCTION_TRACE(acpi_load_table
);
150 return_ACPI_STATUS(AE_BAD_PARAMETER
);
153 /* Copy the table to a local buffer */
155 address
.pointer_type
= ACPI_LOGICAL_POINTER
| ACPI_LOGICAL_ADDRESSING
;
156 address
.pointer
.logical
= table_ptr
;
158 status
= acpi_tb_get_table_body(&address
, table_ptr
, &table_info
);
159 if (ACPI_FAILURE(status
)) {
160 return_ACPI_STATUS(status
);
163 /* Check signature for a valid table type */
165 status
= acpi_tb_recognize_table(&table_info
, ACPI_TABLE_ALL
);
166 if (ACPI_FAILURE(status
)) {
167 return_ACPI_STATUS(status
);
170 /* Install the new table into the local data structures */
172 status
= acpi_tb_install_table(&table_info
);
173 if (ACPI_FAILURE(status
)) {
174 if (status
== AE_ALREADY_EXISTS
) {
176 /* Table already exists, no error */
181 /* Free table allocated by acpi_tb_get_table_body */
183 acpi_tb_delete_single_table(&table_info
);
184 return_ACPI_STATUS(status
);
187 /* Convert the table to common format if necessary */
189 switch (table_info
.type
) {
190 case ACPI_TABLE_ID_FADT
:
192 status
= acpi_tb_convert_table_fadt();
195 case ACPI_TABLE_ID_FACS
:
197 status
= acpi_tb_build_common_facs(&table_info
);
201 /* Load table into namespace if it contains executable AML */
204 acpi_ns_load_table(table_info
.installed_desc
,
209 if (ACPI_FAILURE(status
)) {
211 /* Uninstall table and free the buffer */
213 (void)acpi_tb_uninstall_table(table_info
.installed_desc
);
216 return_ACPI_STATUS(status
);
219 ACPI_EXPORT_SYMBOL(acpi_load_table
)
221 /*******************************************************************************
223 * FUNCTION: acpi_unload_table_id
225 * PARAMETERS: table_type - Type of table to be unloaded
226 * id - Owner ID of the table to be removed.
230 * DESCRIPTION: This routine is used to force the unload of a table (by id)
232 ******************************************************************************/
233 acpi_status
acpi_unload_table_id(acpi_table_type table_type
, acpi_owner_id id
)
235 struct acpi_table_desc
*table_desc
;
238 ACPI_FUNCTION_TRACE(acpi_unload_table
);
240 /* Parameter validation */
241 if (table_type
> ACPI_TABLE_ID_MAX
)
242 return_ACPI_STATUS(AE_BAD_PARAMETER
);
244 /* Find table from the requested type list */
245 table_desc
= acpi_gbl_table_lists
[table_type
].next
;
246 while (table_desc
&& table_desc
->owner_id
!= id
)
247 table_desc
= table_desc
->next
;
250 return_ACPI_STATUS(AE_NOT_EXIST
);
253 * Delete all namespace objects owned by this table. Note that these
254 * objects can appear anywhere in the namespace by virtue of the AML
255 * "Scope" operator. Thus, we need to track ownership by an ID, not
256 * simply a position within the hierarchy
258 acpi_ns_delete_namespace_by_owner(table_desc
->owner_id
);
260 status
= acpi_ut_acquire_mutex(ACPI_MTX_TABLES
);
261 if (ACPI_FAILURE(status
))
262 return_ACPI_STATUS(status
);
264 (void)acpi_tb_uninstall_table(table_desc
);
266 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES
);
268 return_ACPI_STATUS(AE_OK
);
271 ACPI_EXPORT_SYMBOL(acpi_unload_table_id
)
273 #ifdef ACPI_FUTURE_USAGE
274 /*******************************************************************************
276 * FUNCTION: acpi_unload_table
278 * PARAMETERS: table_type - Type of table to be unloaded
282 * DESCRIPTION: This routine is used to force the unload of a table
284 ******************************************************************************/
285 acpi_status
acpi_unload_table(acpi_table_type table_type
)
287 struct acpi_table_desc
*table_desc
;
289 ACPI_FUNCTION_TRACE(acpi_unload_table
);
291 /* Parameter validation */
293 if (table_type
> ACPI_TABLE_ID_MAX
) {
294 return_ACPI_STATUS(AE_BAD_PARAMETER
);
297 /* Find all tables of the requested type */
299 table_desc
= acpi_gbl_table_lists
[table_type
].next
;
301 return_ACPI_STATUS(AE_NOT_EXIST
);
306 * Delete all namespace objects owned by this table. Note that these
307 * objects can appear anywhere in the namespace by virtue of the AML
308 * "Scope" operator. Thus, we need to track ownership by an ID, not
309 * simply a position within the hierarchy
311 acpi_ns_delete_namespace_by_owner(table_desc
->owner_id
);
312 table_desc
= table_desc
->next
;
315 /* Delete (or unmap) all tables of this type */
317 acpi_tb_delete_tables_by_type(table_type
);
318 return_ACPI_STATUS(AE_OK
);
321 ACPI_EXPORT_SYMBOL(acpi_unload_table
)
323 /*******************************************************************************
325 * FUNCTION: acpi_get_table_header
327 * PARAMETERS: table_type - one of the defined table types
328 * Instance - the non zero instance of the table, allows
329 * support for multiple tables of the same type
330 * see acpi_gbl_acpi_table_flag
331 * out_table_header - pointer to the struct acpi_table_header if successful
333 * DESCRIPTION: This function is called to get an ACPI table header. The caller
334 * supplies an pointer to a data area sufficient to contain an ACPI
335 * struct acpi_table_header structure.
337 * The header contains a length field that can be used to determine
338 * the size of the buffer needed to contain the entire table. This
339 * function is not valid for the RSD PTR table since it does not
340 * have a standard header and is fixed length.
342 ******************************************************************************/
344 acpi_get_table_header(acpi_table_type table_type
,
345 u32 instance
, struct acpi_table_header
*out_table_header
)
347 struct acpi_table_header
*tbl_ptr
;
350 ACPI_FUNCTION_TRACE(acpi_get_table_header
);
352 if ((instance
== 0) ||
353 (table_type
== ACPI_TABLE_ID_RSDP
) || (!out_table_header
)) {
354 return_ACPI_STATUS(AE_BAD_PARAMETER
);
357 /* Check the table type and instance */
359 if ((table_type
> ACPI_TABLE_ID_MAX
) ||
360 (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data
[table_type
].flags
) &&
362 return_ACPI_STATUS(AE_BAD_PARAMETER
);
365 /* Get a pointer to the entire table */
367 status
= acpi_tb_get_table_ptr(table_type
, instance
, &tbl_ptr
);
368 if (ACPI_FAILURE(status
)) {
369 return_ACPI_STATUS(status
);
372 /* The function will return a NULL pointer if the table is not loaded */
374 if (tbl_ptr
== NULL
) {
375 return_ACPI_STATUS(AE_NOT_EXIST
);
378 /* Copy the header to the caller's buffer */
380 ACPI_MEMCPY(ACPI_CAST_PTR(void, out_table_header
),
381 ACPI_CAST_PTR(void, tbl_ptr
),
382 sizeof(struct acpi_table_header
));
384 return_ACPI_STATUS(status
);
387 ACPI_EXPORT_SYMBOL(acpi_get_table_header
)
388 #endif /* ACPI_FUTURE_USAGE */
390 /*******************************************************************************
392 * FUNCTION: acpi_get_table
394 * PARAMETERS: table_type - one of the defined table types
395 * Instance - the non zero instance of the table, allows
396 * support for multiple tables of the same type
397 * see acpi_gbl_acpi_table_flag
398 * ret_buffer - pointer to a structure containing a buffer to
403 * DESCRIPTION: This function is called to get an ACPI table. The caller
404 * supplies an out_buffer large enough to contain the entire ACPI
405 * table. The caller should call the acpi_get_table_header function
406 * first to determine the buffer size needed. Upon completion
407 * the out_buffer->Length field will indicate the number of bytes
408 * copied into the out_buffer->buf_ptr buffer. This table will be
409 * a complete table including the header.
411 ******************************************************************************/
413 acpi_get_table(acpi_table_type table_type
,
414 u32 instance
, struct acpi_buffer
*ret_buffer
)
416 struct acpi_table_header
*tbl_ptr
;
418 acpi_size table_length
;
420 ACPI_FUNCTION_TRACE(acpi_get_table
);
422 /* Parameter validation */
425 return_ACPI_STATUS(AE_BAD_PARAMETER
);
428 status
= acpi_ut_validate_buffer(ret_buffer
);
429 if (ACPI_FAILURE(status
)) {
430 return_ACPI_STATUS(status
);
433 /* Check the table type and instance */
435 if ((table_type
> ACPI_TABLE_ID_MAX
) ||
436 (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data
[table_type
].flags
) &&
438 return_ACPI_STATUS(AE_BAD_PARAMETER
);
441 /* Get a pointer to the entire table */
443 status
= acpi_tb_get_table_ptr(table_type
, instance
, &tbl_ptr
);
444 if (ACPI_FAILURE(status
)) {
445 return_ACPI_STATUS(status
);
449 * acpi_tb_get_table_ptr will return a NULL pointer if the
450 * table is not loaded.
452 if (tbl_ptr
== NULL
) {
453 return_ACPI_STATUS(AE_NOT_EXIST
);
456 /* Get the table length */
458 if (table_type
== ACPI_TABLE_ID_RSDP
) {
460 /* RSD PTR is the only "table" without a header */
462 table_length
= sizeof(struct rsdp_descriptor
);
464 table_length
= (acpi_size
) tbl_ptr
->length
;
467 /* Validate/Allocate/Clear caller buffer */
469 status
= acpi_ut_initialize_buffer(ret_buffer
, table_length
);
470 if (ACPI_FAILURE(status
)) {
471 return_ACPI_STATUS(status
);
474 /* Copy the table to the buffer */
476 ACPI_MEMCPY(ACPI_CAST_PTR(void, ret_buffer
->pointer
),
477 ACPI_CAST_PTR(void, tbl_ptr
), table_length
);
479 return_ACPI_STATUS(AE_OK
);
482 ACPI_EXPORT_SYMBOL(acpi_get_table
)