1 /******************************************************************************
3 * Module Name: tbxface - Public interfaces to the ACPI subsystem
4 * ACPI table oriented interfaces
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2005, 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 <linux/module.h>
47 #include <acpi/acpi.h>
48 #include <acpi/acnamesp.h>
49 #include <acpi/actables.h>
52 #define _COMPONENT ACPI_TABLES
53 ACPI_MODULE_NAME ("tbxface")
56 /*******************************************************************************
58 * FUNCTION: acpi_load_tables
64 * DESCRIPTION: This function is called to load the ACPI tables from the
67 ******************************************************************************/
73 struct acpi_pointer rsdp_address;
77 ACPI_FUNCTION_TRACE ("acpi_load_tables");
82 status = acpi_os_get_root_pointer (ACPI_LOGICAL_ADDRESSING,
84 if (ACPI_FAILURE (status)) {
85 ACPI_REPORT_ERROR (("acpi_load_tables: Could not get RSDP, %s\n",
86 acpi_format_exception (status)));
90 /* Map and validate the RSDP */
92 acpi_gbl_table_flags = rsdp_address.pointer_type;
94 status = acpi_tb_verify_rsdp (&rsdp_address);
95 if (ACPI_FAILURE (status)) {
96 ACPI_REPORT_ERROR (("acpi_load_tables: RSDP Failed validation: %s\n",
97 acpi_format_exception (status)));
101 /* Get the RSDT via the RSDP */
103 status = acpi_tb_get_table_rsdt ();
104 if (ACPI_FAILURE (status)) {
105 ACPI_REPORT_ERROR (("acpi_load_tables: Could not load RSDT: %s\n",
106 acpi_format_exception (status)));
110 /* Now get the tables needed by this subsystem (FADT, DSDT, etc.) */
112 status = acpi_tb_get_required_tables ();
113 if (ACPI_FAILURE (status)) {
115 "acpi_load_tables: Error getting required tables (DSDT/FADT/FACS): %s\n",
116 acpi_format_exception (status)));
120 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
122 /* Load the namespace from the tables */
124 status = acpi_ns_load_namespace ();
125 if (ACPI_FAILURE (status)) {
126 ACPI_REPORT_ERROR (("acpi_load_tables: Could not load namespace: %s\n",
127 acpi_format_exception (status)));
131 return_ACPI_STATUS (AE_OK);
135 ACPI_REPORT_ERROR (("acpi_load_tables: Could not load tables: %s\n",
136 acpi_format_exception (status)));
138 return_ACPI_STATUS (status);
142 #ifdef ACPI_FUTURE_USAGE
143 /*******************************************************************************
145 * FUNCTION: acpi_load_table
147 * PARAMETERS: table_ptr - pointer to a buffer containing the entire
152 * DESCRIPTION: This function is called to load a table from the caller's
153 * buffer. The buffer must contain an entire ACPI Table including
154 * a valid header. The header fields will be verified, and if it
155 * is determined that the table is invalid, the call will fail.
157 ******************************************************************************/
161 struct acpi_table_header *table_ptr)
164 struct acpi_table_desc table_info;
165 struct acpi_pointer address;
168 ACPI_FUNCTION_TRACE ("acpi_load_table");
172 return_ACPI_STATUS (AE_BAD_PARAMETER);
175 /* Copy the table to a local buffer */
177 address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
178 address.pointer.logical = table_ptr;
180 status = acpi_tb_get_table_body (&address, table_ptr, &table_info);
181 if (ACPI_FAILURE (status)) {
182 return_ACPI_STATUS (status);
185 /* Install the new table into the local data structures */
187 status = acpi_tb_install_table (&table_info);
188 if (ACPI_FAILURE (status)) {
189 /* Free table allocated by acpi_tb_get_table_body */
191 acpi_tb_delete_single_table (&table_info);
192 return_ACPI_STATUS (status);
195 /* Convert the table to common format if necessary */
197 switch (table_info.type) {
198 case ACPI_TABLE_FADT:
200 status = acpi_tb_convert_table_fadt ();
203 case ACPI_TABLE_FACS:
205 status = acpi_tb_build_common_facs (&table_info);
209 /* Load table into namespace if it contains executable AML */
211 status = acpi_ns_load_table (table_info.installed_desc, acpi_gbl_root_node);
215 if (ACPI_FAILURE (status)) {
216 /* Uninstall table and free the buffer */
218 (void) acpi_tb_uninstall_table (table_info.installed_desc);
221 return_ACPI_STATUS (status);
225 /*******************************************************************************
227 * FUNCTION: acpi_unload_table
229 * PARAMETERS: table_type - Type of table to be unloaded
233 * DESCRIPTION: This routine is used to force the unload of a table
235 ******************************************************************************/
239 acpi_table_type table_type)
241 struct acpi_table_desc *table_desc;
244 ACPI_FUNCTION_TRACE ("acpi_unload_table");
247 /* Parameter validation */
249 if (table_type > ACPI_TABLE_MAX) {
250 return_ACPI_STATUS (AE_BAD_PARAMETER);
253 /* Find all tables of the requested type */
255 table_desc = acpi_gbl_table_lists[table_type].next;
258 * Delete all namespace entries owned by this table. Note that these
259 * entries can appear anywhere in the namespace by virtue of the AML
260 * "Scope" operator. Thus, we need to track ownership by an ID, not
261 * simply a position within the hierarchy
263 acpi_ns_delete_namespace_by_owner (table_desc->table_id);
265 table_desc = table_desc->next;
268 /* Delete (or unmap) all tables of this type */
270 acpi_tb_delete_tables_by_type (table_type);
271 return_ACPI_STATUS (AE_OK);
275 /*******************************************************************************
277 * FUNCTION: acpi_get_table_header
279 * PARAMETERS: table_type - one of the defined table types
280 * Instance - the non zero instance of the table, allows
281 * support for multiple tables of the same type
282 * see acpi_gbl_acpi_table_flag
283 * out_table_header - pointer to the struct acpi_table_header if successful
285 * DESCRIPTION: This function is called to get an ACPI table header. The caller
286 * supplies an pointer to a data area sufficient to contain an ACPI
287 * struct acpi_table_header structure.
289 * The header contains a length field that can be used to determine
290 * the size of the buffer needed to contain the entire table. This
291 * function is not valid for the RSD PTR table since it does not
292 * have a standard header and is fixed length.
294 ******************************************************************************/
297 acpi_get_table_header (
298 acpi_table_type table_type,
300 struct acpi_table_header *out_table_header)
302 struct acpi_table_header *tbl_ptr;
306 ACPI_FUNCTION_TRACE ("acpi_get_table_header");
309 if ((instance == 0) ||
310 (table_type == ACPI_TABLE_RSDP) ||
311 (!out_table_header)) {
312 return_ACPI_STATUS (AE_BAD_PARAMETER);
315 /* Check the table type and instance */
317 if ((table_type > ACPI_TABLE_MAX) ||
318 (ACPI_IS_SINGLE_TABLE (acpi_gbl_table_data[table_type].flags) &&
320 return_ACPI_STATUS (AE_BAD_PARAMETER);
323 /* Get a pointer to the entire table */
325 status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr);
326 if (ACPI_FAILURE (status)) {
327 return_ACPI_STATUS (status);
330 /* The function will return a NULL pointer if the table is not loaded */
332 if (tbl_ptr == NULL) {
333 return_ACPI_STATUS (AE_NOT_EXIST);
336 /* Copy the header to the caller's buffer */
338 ACPI_MEMCPY ((void *) out_table_header, (void *) tbl_ptr,
339 sizeof (struct acpi_table_header));
341 return_ACPI_STATUS (status);
344 #endif /* ACPI_FUTURE_USAGE */
346 /*******************************************************************************
348 * FUNCTION: acpi_get_table
350 * PARAMETERS: table_type - one of the defined table types
351 * Instance - the non zero instance of the table, allows
352 * support for multiple tables of the same type
353 * see acpi_gbl_acpi_table_flag
354 * ret_buffer - pointer to a structure containing a buffer to
359 * DESCRIPTION: This function is called to get an ACPI table. The caller
360 * supplies an out_buffer large enough to contain the entire ACPI
361 * table. The caller should call the acpi_get_table_header function
362 * first to determine the buffer size needed. Upon completion
363 * the out_buffer->Length field will indicate the number of bytes
364 * copied into the out_buffer->buf_ptr buffer. This table will be
365 * a complete table including the header.
367 ******************************************************************************/
371 acpi_table_type table_type,
373 struct acpi_buffer *ret_buffer)
375 struct acpi_table_header *tbl_ptr;
377 acpi_size table_length;
380 ACPI_FUNCTION_TRACE ("acpi_get_table");
383 /* Parameter validation */
386 return_ACPI_STATUS (AE_BAD_PARAMETER);
389 status = acpi_ut_validate_buffer (ret_buffer);
390 if (ACPI_FAILURE (status)) {
391 return_ACPI_STATUS (status);
394 /* Check the table type and instance */
396 if ((table_type > ACPI_TABLE_MAX) ||
397 (ACPI_IS_SINGLE_TABLE (acpi_gbl_table_data[table_type].flags) &&
399 return_ACPI_STATUS (AE_BAD_PARAMETER);
402 /* Get a pointer to the entire table */
404 status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr);
405 if (ACPI_FAILURE (status)) {
406 return_ACPI_STATUS (status);
410 * acpi_tb_get_table_ptr will return a NULL pointer if the
411 * table is not loaded.
413 if (tbl_ptr == NULL) {
414 return_ACPI_STATUS (AE_NOT_EXIST);
417 /* Get the table length */
419 if (table_type == ACPI_TABLE_RSDP) {
420 /* RSD PTR is the only "table" without a header */
422 table_length = sizeof (struct rsdp_descriptor);
425 table_length = (acpi_size) tbl_ptr->length;
428 /* Validate/Allocate/Clear caller buffer */
430 status = acpi_ut_initialize_buffer (ret_buffer, table_length);
431 if (ACPI_FAILURE (status)) {
432 return_ACPI_STATUS (status);
435 /* Copy the table to the buffer */
437 ACPI_MEMCPY ((void *) ret_buffer->pointer, (void *) tbl_ptr, table_length);
438 return_ACPI_STATUS (AE_OK);
440 EXPORT_SYMBOL(acpi_get_table);