initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / acpi / tables / tbxface.c
blobc92e7150865172fd1e42d851902c5a0dd94abe26
1 /******************************************************************************
3 * Module Name: tbxface - Public interfaces to the ACPI subsystem
4 * ACPI table oriented interfaces
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2004, 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
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.
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.
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.
46 #include <acpi/acpi.h>
47 #include <acpi/acnamesp.h>
48 #include <acpi/actables.h>
51 #define _COMPONENT ACPI_TABLES
52 ACPI_MODULE_NAME ("tbxface")
55 /*******************************************************************************
57 * FUNCTION: acpi_load_tables
59 * PARAMETERS: None
61 * RETURN: Status
63 * DESCRIPTION: This function is called to load the ACPI tables from the
64 * provided RSDT
66 ******************************************************************************/
68 acpi_status
69 acpi_load_tables (void)
71 struct acpi_pointer rsdp_address;
72 acpi_status status;
75 ACPI_FUNCTION_TRACE ("acpi_load_tables");
78 /* Get the RSDP */
80 status = acpi_os_get_root_pointer (ACPI_LOGICAL_ADDRESSING,
81 &rsdp_address);
82 if (ACPI_FAILURE (status)) {
83 ACPI_REPORT_ERROR (("acpi_load_tables: Could not get RSDP, %s\n",
84 acpi_format_exception (status)));
85 goto error_exit;
88 /* Map and validate the RSDP */
90 acpi_gbl_table_flags = rsdp_address.pointer_type;
92 status = acpi_tb_verify_rsdp (&rsdp_address);
93 if (ACPI_FAILURE (status)) {
94 ACPI_REPORT_ERROR (("acpi_load_tables: RSDP Failed validation: %s\n",
95 acpi_format_exception (status)));
96 goto error_exit;
99 /* Get the RSDT via the RSDP */
101 status = acpi_tb_get_table_rsdt ();
102 if (ACPI_FAILURE (status)) {
103 ACPI_REPORT_ERROR (("acpi_load_tables: Could not load RSDT: %s\n",
104 acpi_format_exception (status)));
105 goto error_exit;
108 /* Now get the tables needed by this subsystem (FADT, DSDT, etc.) */
110 status = acpi_tb_get_required_tables ();
111 if (ACPI_FAILURE (status)) {
112 ACPI_REPORT_ERROR (("acpi_load_tables: Error getting required tables (DSDT/FADT/FACS): %s\n",
113 acpi_format_exception (status)));
114 goto error_exit;
117 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
120 /* Load the namespace from the tables */
122 status = acpi_ns_load_namespace ();
123 if (ACPI_FAILURE (status)) {
124 ACPI_REPORT_ERROR (("acpi_load_tables: Could not load namespace: %s\n",
125 acpi_format_exception (status)));
126 goto error_exit;
129 return_ACPI_STATUS (AE_OK);
132 error_exit:
133 ACPI_REPORT_ERROR (("acpi_load_tables: Could not load tables: %s\n",
134 acpi_format_exception (status)));
136 return_ACPI_STATUS (status);
140 /*******************************************************************************
142 * FUNCTION: acpi_load_table
144 * PARAMETERS: table_ptr - pointer to a buffer containing the entire
145 * table to be loaded
147 * RETURN: Status
149 * DESCRIPTION: This function is called to load a table from the caller's
150 * buffer. The buffer must contain an entire ACPI Table including
151 * a valid header. The header fields will be verified, and if it
152 * is determined that the table is invalid, the call will fail.
154 ******************************************************************************/
156 acpi_status
157 acpi_load_table (
158 struct acpi_table_header *table_ptr)
160 acpi_status status;
161 struct acpi_table_desc table_info;
162 struct acpi_pointer address;
165 ACPI_FUNCTION_TRACE ("acpi_load_table");
168 if (!table_ptr) {
169 return_ACPI_STATUS (AE_BAD_PARAMETER);
172 /* Copy the table to a local buffer */
174 address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
175 address.pointer.logical = table_ptr;
177 status = acpi_tb_get_table_body (&address, table_ptr, &table_info);
178 if (ACPI_FAILURE (status)) {
179 return_ACPI_STATUS (status);
182 /* Install the new table into the local data structures */
184 status = acpi_tb_install_table (&table_info);
185 if (ACPI_FAILURE (status)) {
186 /* Free table allocated by acpi_tb_get_table_body */
188 acpi_tb_delete_single_table (&table_info);
189 return_ACPI_STATUS (status);
192 /* Convert the table to common format if necessary */
194 switch (table_info.type) {
195 case ACPI_TABLE_FADT:
197 status = acpi_tb_convert_table_fadt ();
198 break;
200 case ACPI_TABLE_FACS:
202 status = acpi_tb_build_common_facs (&table_info);
203 break;
205 default:
206 /* Load table into namespace if it contains executable AML */
208 status = acpi_ns_load_table (table_info.installed_desc, acpi_gbl_root_node);
209 break;
212 if (ACPI_FAILURE (status)) {
213 /* Uninstall table and free the buffer */
215 (void) acpi_tb_uninstall_table (table_info.installed_desc);
218 return_ACPI_STATUS (status);
222 /*******************************************************************************
224 * FUNCTION: acpi_unload_table
226 * PARAMETERS: table_type - Type of table to be unloaded
228 * RETURN: Status
230 * DESCRIPTION: This routine is used to force the unload of a table
232 ******************************************************************************/
234 acpi_status
235 acpi_unload_table (
236 acpi_table_type table_type)
238 struct acpi_table_desc *table_desc;
241 ACPI_FUNCTION_TRACE ("acpi_unload_table");
244 /* Parameter validation */
246 if (table_type > ACPI_TABLE_MAX) {
247 return_ACPI_STATUS (AE_BAD_PARAMETER);
251 /* Find all tables of the requested type */
253 table_desc = acpi_gbl_table_lists[table_type].next;
254 while (table_desc) {
256 * Delete all namespace entries owned by this table. Note that these
257 * entries can appear anywhere in the namespace by virtue of the AML
258 * "Scope" operator. Thus, we need to track ownership by an ID, not
259 * simply a position within the hierarchy
261 acpi_ns_delete_namespace_by_owner (table_desc->table_id);
263 table_desc = table_desc->next;
266 /* Delete (or unmap) all tables of this type */
268 acpi_tb_delete_tables_by_type (table_type);
269 return_ACPI_STATUS (AE_OK);
273 /*******************************************************************************
275 * FUNCTION: acpi_get_table_header
277 * PARAMETERS: table_type - one of the defined table types
278 * Instance - the non zero instance of the table, allows
279 * support for multiple tables of the same type
280 * see acpi_gbl_acpi_table_flag
281 * out_table_header - pointer to the struct acpi_table_header if successful
283 * DESCRIPTION: This function is called to get an ACPI table header. The caller
284 * supplies an pointer to a data area sufficient to contain an ACPI
285 * struct acpi_table_header structure.
287 * The header contains a length field that can be used to determine
288 * the size of the buffer needed to contain the entire table. This
289 * function is not valid for the RSD PTR table since it does not
290 * have a standard header and is fixed length.
292 ******************************************************************************/
294 acpi_status
295 acpi_get_table_header (
296 acpi_table_type table_type,
297 u32 instance,
298 struct acpi_table_header *out_table_header)
300 struct acpi_table_header *tbl_ptr;
301 acpi_status status;
304 ACPI_FUNCTION_TRACE ("acpi_get_table_header");
307 if ((instance == 0) ||
308 (table_type == ACPI_TABLE_RSDP) ||
309 (!out_table_header)) {
310 return_ACPI_STATUS (AE_BAD_PARAMETER);
313 /* Check the table type and instance */
315 if ((table_type > ACPI_TABLE_MAX) ||
316 (ACPI_IS_SINGLE_TABLE (acpi_gbl_table_data[table_type].flags) &&
317 instance > 1)) {
318 return_ACPI_STATUS (AE_BAD_PARAMETER);
322 /* Get a pointer to the entire table */
324 status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr);
325 if (ACPI_FAILURE (status)) {
326 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);
337 * Copy the header to the caller's buffer
339 ACPI_MEMCPY ((void *) out_table_header, (void *) tbl_ptr,
340 sizeof (struct acpi_table_header));
342 return_ACPI_STATUS (status);
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
355 * receive the table
357 * RETURN: Status
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 ******************************************************************************/
369 acpi_status
370 acpi_get_table (
371 acpi_table_type table_type,
372 u32 instance,
373 struct acpi_buffer *ret_buffer)
375 struct acpi_table_header *tbl_ptr;
376 acpi_status status;
377 acpi_size table_length;
380 ACPI_FUNCTION_TRACE ("acpi_get_table");
383 /* Parameter validation */
385 if (instance == 0) {
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) &&
398 instance > 1)) {
399 return_ACPI_STATUS (AE_BAD_PARAMETER);
403 /* Get a pointer to the entire table */
405 status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr);
406 if (ACPI_FAILURE (status)) {
407 return_ACPI_STATUS (status);
411 * acpi_tb_get_table_ptr will return a NULL pointer if the
412 * table is not loaded.
414 if (tbl_ptr == NULL) {
415 return_ACPI_STATUS (AE_NOT_EXIST);
418 /* Get the table length */
420 if (table_type == ACPI_TABLE_RSDP) {
422 * RSD PTR is the only "table" without a header
424 table_length = sizeof (struct rsdp_descriptor);
426 else {
427 table_length = (acpi_size) tbl_ptr->length;
430 /* Validate/Allocate/Clear caller buffer */
432 status = acpi_ut_initialize_buffer (ret_buffer, table_length);
433 if (ACPI_FAILURE (status)) {
434 return_ACPI_STATUS (status);
437 /* Copy the table to the buffer */
439 ACPI_MEMCPY ((void *) ret_buffer->pointer, (void *) tbl_ptr, table_length);
440 return_ACPI_STATUS (AE_OK);