blob: 5ba9303293ad968c4366ca49c4044291cd4bf10c [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
52/*******************************************************************************
53 *
54 * FUNCTION: acpi_load_tables
55 *
56 * PARAMETERS: None
57 *
58 * RETURN: Status
59 *
60 * DESCRIPTION: This function is called to load the ACPI tables from the
61 * provided RSDT
62 *
63 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040064acpi_status acpi_load_tables(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Len Brown4be44fc2005-08-05 00:44:28 -040066 struct acpi_pointer rsdp_address;
67 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Bob Mooreb229cf92006-04-21 17:15:00 -040069 ACPI_FUNCTION_TRACE(acpi_load_tables);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71 /* Get the RSDP */
72
Len Brown4be44fc2005-08-05 00:44:28 -040073 status = acpi_os_get_root_pointer(ACPI_LOGICAL_ADDRESSING,
74 &rsdp_address);
75 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050076 ACPI_EXCEPTION((AE_INFO, status, "Could not get the RSDP"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 goto error_exit;
78 }
79
80 /* Map and validate the RSDP */
81
82 acpi_gbl_table_flags = rsdp_address.pointer_type;
83
Len Brown4be44fc2005-08-05 00:44:28 -040084 status = acpi_tb_verify_rsdp(&rsdp_address);
85 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050086 ACPI_EXCEPTION((AE_INFO, status, "During RSDP validation"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 goto error_exit;
88 }
89
90 /* Get the RSDT via the RSDP */
91
Len Brown4be44fc2005-08-05 00:44:28 -040092 status = acpi_tb_get_table_rsdt();
93 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050094 ACPI_EXCEPTION((AE_INFO, status, "Could not load RSDT"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 goto error_exit;
96 }
97
98 /* Now get the tables needed by this subsystem (FADT, DSDT, etc.) */
99
Len Brown4be44fc2005-08-05 00:44:28 -0400100 status = acpi_tb_get_required_tables();
101 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500102 ACPI_EXCEPTION((AE_INFO, status,
103 "Could not get all required tables (DSDT/FADT/FACS)"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 goto error_exit;
105 }
106
Len Brown4be44fc2005-08-05 00:44:28 -0400107 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 /* Load the namespace from the tables */
110
Len Brown4be44fc2005-08-05 00:44:28 -0400111 status = acpi_ns_load_namespace();
112 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500113 ACPI_EXCEPTION((AE_INFO, status, "Could not load namespace"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 goto error_exit;
115 }
116
Len Brown4be44fc2005-08-05 00:44:28 -0400117 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Len Brown4be44fc2005-08-05 00:44:28 -0400119 error_exit:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500120 ACPI_EXCEPTION((AE_INFO, status, "Could not load tables"));
Len Brown4be44fc2005-08-05 00:44:28 -0400121 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
123
Bob Moore83135242006-10-03 00:00:00 -0400124ACPI_EXPORT_SYMBOL(acpi_load_tables)
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126/*******************************************************************************
127 *
128 * FUNCTION: acpi_load_table
129 *
130 * PARAMETERS: table_ptr - pointer to a buffer containing the entire
131 * table to be loaded
132 *
133 * RETURN: Status
134 *
135 * DESCRIPTION: This function is called to load a table from the caller's
Bob Mooref6dd9222006-07-07 20:44:38 -0400136 * buffer. The buffer must contain an entire ACPI Table including
137 * a valid header. The header fields will be verified, and if it
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 * is determined that the table is invalid, the call will fail.
139 *
140 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400141acpi_status acpi_load_table(struct acpi_table_header *table_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142{
Len Brown4be44fc2005-08-05 00:44:28 -0400143 acpi_status status;
144 struct acpi_table_desc table_info;
145 struct acpi_pointer address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Bob Mooreb229cf92006-04-21 17:15:00 -0400147 ACPI_FUNCTION_TRACE(acpi_load_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 if (!table_ptr) {
Len Brown4be44fc2005-08-05 00:44:28 -0400150 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 }
152
153 /* Copy the table to a local buffer */
154
Len Brown4be44fc2005-08-05 00:44:28 -0400155 address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 address.pointer.logical = table_ptr;
157
Len Brown4be44fc2005-08-05 00:44:28 -0400158 status = acpi_tb_get_table_body(&address, table_ptr, &table_info);
159 if (ACPI_FAILURE(status)) {
160 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
162
Robert Moore0c9938c2005-07-29 15:15:00 -0700163 /* Check signature for a valid table type */
164
Len Brown4be44fc2005-08-05 00:44:28 -0400165 status = acpi_tb_recognize_table(&table_info, ACPI_TABLE_ALL);
166 if (ACPI_FAILURE(status)) {
167 return_ACPI_STATUS(status);
Robert Moore0c9938c2005-07-29 15:15:00 -0700168 }
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 /* Install the new table into the local data structures */
171
Len Brown4be44fc2005-08-05 00:44:28 -0400172 status = acpi_tb_install_table(&table_info);
173 if (ACPI_FAILURE(status)) {
Robert Moore0c9938c2005-07-29 15:15:00 -0700174 if (status == AE_ALREADY_EXISTS) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400175
Robert Moore0c9938c2005-07-29 15:15:00 -0700176 /* Table already exists, no error */
177
178 status = AE_OK;
179 }
180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 /* Free table allocated by acpi_tb_get_table_body */
182
Len Brown4be44fc2005-08-05 00:44:28 -0400183 acpi_tb_delete_single_table(&table_info);
184 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 }
186
187 /* Convert the table to common format if necessary */
188
189 switch (table_info.type) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400190 case ACPI_TABLE_ID_FADT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Len Brown4be44fc2005-08-05 00:44:28 -0400192 status = acpi_tb_convert_table_fadt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 break;
194
Bob Mooreb229cf92006-04-21 17:15:00 -0400195 case ACPI_TABLE_ID_FACS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Len Brown4be44fc2005-08-05 00:44:28 -0400197 status = acpi_tb_build_common_facs(&table_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 break;
199
200 default:
201 /* Load table into namespace if it contains executable AML */
202
Len Brown4be44fc2005-08-05 00:44:28 -0400203 status =
204 acpi_ns_load_table(table_info.installed_desc,
205 acpi_gbl_root_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 break;
207 }
208
Len Brown4be44fc2005-08-05 00:44:28 -0400209 if (ACPI_FAILURE(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 /* Uninstall table and free the buffer */
212
Len Brown4be44fc2005-08-05 00:44:28 -0400213 (void)acpi_tb_uninstall_table(table_info.installed_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 }
215
Len Brown4be44fc2005-08-05 00:44:28 -0400216 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217}
218
Bob Moore83135242006-10-03 00:00:00 -0400219ACPI_EXPORT_SYMBOL(acpi_load_table)
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221/*******************************************************************************
222 *
John Keller0f0fe1a2006-12-19 12:56:19 -0800223 * FUNCTION: acpi_unload_table_id
224 *
225 * PARAMETERS: table_type - Type of table to be unloaded
226 * id - Owner ID of the table to be removed.
227 *
228 * RETURN: Status
229 *
230 * DESCRIPTION: This routine is used to force the unload of a table (by id)
231 *
232 ******************************************************************************/
233acpi_status acpi_unload_table_id(acpi_table_type table_type, acpi_owner_id id)
234{
235 struct acpi_table_desc *table_desc;
236 acpi_status status;
237
238 ACPI_FUNCTION_TRACE(acpi_unload_table);
239
240 /* Parameter validation */
241 if (table_type > ACPI_TABLE_ID_MAX)
242 return_ACPI_STATUS(AE_BAD_PARAMETER);
243
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;
248
249 if (!table_desc)
250 return_ACPI_STATUS(AE_NOT_EXIST);
251
252 /*
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
257 */
258 acpi_ns_delete_namespace_by_owner(table_desc->owner_id);
259
260 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
261 if (ACPI_FAILURE(status))
262 return_ACPI_STATUS(status);
263
264 (void)acpi_tb_uninstall_table(table_desc);
265
266 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
267
268 return_ACPI_STATUS(AE_OK);
269}
270
271ACPI_EXPORT_SYMBOL(acpi_unload_table_id)
272
273#ifdef ACPI_FUTURE_USAGE
274/*******************************************************************************
275 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 * FUNCTION: acpi_unload_table
277 *
278 * PARAMETERS: table_type - Type of table to be unloaded
279 *
280 * RETURN: Status
281 *
282 * DESCRIPTION: This routine is used to force the unload of a table
283 *
284 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400285acpi_status acpi_unload_table(acpi_table_type table_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
Len Brown4be44fc2005-08-05 00:44:28 -0400287 struct acpi_table_desc *table_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Bob Mooreb229cf92006-04-21 17:15:00 -0400289 ACPI_FUNCTION_TRACE(acpi_unload_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291 /* Parameter validation */
292
Bob Mooreb229cf92006-04-21 17:15:00 -0400293 if (table_type > ACPI_TABLE_ID_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400294 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 }
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 /* Find all tables of the requested type */
298
299 table_desc = acpi_gbl_table_lists[table_type].next;
Bob Mooref6dd9222006-07-07 20:44:38 -0400300 if (!table_desc) {
301 return_ACPI_STATUS(AE_NOT_EXIST);
302 }
303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 while (table_desc) {
305 /*
Bob Mooref6dd9222006-07-07 20:44:38 -0400306 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 * simply a position within the hierarchy
310 */
Len Brown4be44fc2005-08-05 00:44:28 -0400311 acpi_ns_delete_namespace_by_owner(table_desc->owner_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 table_desc = table_desc->next;
313 }
314
315 /* Delete (or unmap) all tables of this type */
316
Len Brown4be44fc2005-08-05 00:44:28 -0400317 acpi_tb_delete_tables_by_type(table_type);
318 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319}
320
Bob Moore83135242006-10-03 00:00:00 -0400321ACPI_EXPORT_SYMBOL(acpi_unload_table)
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323/*******************************************************************************
324 *
325 * FUNCTION: acpi_get_table_header
326 *
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
332 *
Bob Mooref6dd9222006-07-07 20:44:38 -0400333 * DESCRIPTION: This function is called to get an ACPI table header. The caller
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 * supplies an pointer to a data area sufficient to contain an ACPI
335 * struct acpi_table_header structure.
336 *
337 * The header contains a length field that can be used to determine
Bob Mooref6dd9222006-07-07 20:44:38 -0400338 * the size of the buffer needed to contain the entire table. This
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 * function is not valid for the RSD PTR table since it does not
340 * have a standard header and is fixed length.
341 *
342 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400344acpi_get_table_header(acpi_table_type table_type,
345 u32 instance, struct acpi_table_header *out_table_header)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
Len Brown4be44fc2005-08-05 00:44:28 -0400347 struct acpi_table_header *tbl_ptr;
348 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Bob Mooreb229cf92006-04-21 17:15:00 -0400350 ACPI_FUNCTION_TRACE(acpi_get_table_header);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Len Brown4be44fc2005-08-05 00:44:28 -0400352 if ((instance == 0) ||
Bob Mooreb229cf92006-04-21 17:15:00 -0400353 (table_type == ACPI_TABLE_ID_RSDP) || (!out_table_header)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400354 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 }
356
357 /* Check the table type and instance */
358
Bob Mooreb229cf92006-04-21 17:15:00 -0400359 if ((table_type > ACPI_TABLE_ID_MAX) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400360 (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) &&
361 instance > 1)) {
362 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 }
364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 /* Get a pointer to the entire table */
366
Len Brown4be44fc2005-08-05 00:44:28 -0400367 status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr);
368 if (ACPI_FAILURE(status)) {
369 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 }
371
Robert Moore44f6c012005-04-18 22:49:35 -0400372 /* The function will return a NULL pointer if the table is not loaded */
373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 if (tbl_ptr == NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -0400375 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 }
377
Robert Moore44f6c012005-04-18 22:49:35 -0400378 /* Copy the header to the caller's buffer */
379
Bob Mooref6dd9222006-07-07 20:44:38 -0400380 ACPI_MEMCPY(ACPI_CAST_PTR(void, out_table_header),
381 ACPI_CAST_PTR(void, tbl_ptr),
Len Brown4be44fc2005-08-05 00:44:28 -0400382 sizeof(struct acpi_table_header));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Len Brown4be44fc2005-08-05 00:44:28 -0400384 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385}
386
Bob Moore83135242006-10-03 00:00:00 -0400387ACPI_EXPORT_SYMBOL(acpi_get_table_header)
Len Brown4be44fc2005-08-05 00:44:28 -0400388#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
390/*******************************************************************************
391 *
392 * FUNCTION: acpi_get_table
393 *
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
399 * receive the table
400 *
401 * RETURN: Status
402 *
Bob Mooref6dd9222006-07-07 20:44:38 -0400403 * DESCRIPTION: This function is called to get an ACPI table. The caller
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 * supplies an out_buffer large enough to contain the entire ACPI
Bob Mooref6dd9222006-07-07 20:44:38 -0400405 * table. The caller should call the acpi_get_table_header function
406 * first to determine the buffer size needed. Upon completion
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 * 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.
410 *
411 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400413acpi_get_table(acpi_table_type table_type,
414 u32 instance, struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
Len Brown4be44fc2005-08-05 00:44:28 -0400416 struct acpi_table_header *tbl_ptr;
417 acpi_status status;
418 acpi_size table_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Bob Mooreb229cf92006-04-21 17:15:00 -0400420 ACPI_FUNCTION_TRACE(acpi_get_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
422 /* Parameter validation */
423
424 if (instance == 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400425 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 }
427
Len Brown4be44fc2005-08-05 00:44:28 -0400428 status = acpi_ut_validate_buffer(ret_buffer);
429 if (ACPI_FAILURE(status)) {
430 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 }
432
433 /* Check the table type and instance */
434
Bob Mooreb229cf92006-04-21 17:15:00 -0400435 if ((table_type > ACPI_TABLE_ID_MAX) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400436 (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) &&
437 instance > 1)) {
438 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 }
440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 /* Get a pointer to the entire table */
442
Len Brown4be44fc2005-08-05 00:44:28 -0400443 status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr);
444 if (ACPI_FAILURE(status)) {
445 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 }
447
448 /*
449 * acpi_tb_get_table_ptr will return a NULL pointer if the
450 * table is not loaded.
451 */
452 if (tbl_ptr == NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -0400453 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 }
455
456 /* Get the table length */
457
Bob Mooreb229cf92006-04-21 17:15:00 -0400458 if (table_type == ACPI_TABLE_ID_RSDP) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400459
Robert Moore44f6c012005-04-18 22:49:35 -0400460 /* RSD PTR is the only "table" without a header */
461
Len Brown4be44fc2005-08-05 00:44:28 -0400462 table_length = sizeof(struct rsdp_descriptor);
463 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 table_length = (acpi_size) tbl_ptr->length;
465 }
466
467 /* Validate/Allocate/Clear caller buffer */
468
Len Brown4be44fc2005-08-05 00:44:28 -0400469 status = acpi_ut_initialize_buffer(ret_buffer, table_length);
470 if (ACPI_FAILURE(status)) {
471 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 }
473
474 /* Copy the table to the buffer */
475
Bob Mooref6dd9222006-07-07 20:44:38 -0400476 ACPI_MEMCPY(ACPI_CAST_PTR(void, ret_buffer->pointer),
477 ACPI_CAST_PTR(void, tbl_ptr), table_length);
478
Len Brown4be44fc2005-08-05 00:44:28 -0400479 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Bob Moore83135242006-10-03 00:00:00 -0400482ACPI_EXPORT_SYMBOL(acpi_get_table)