blob: 472a91ccde954e04b0a67bd59eb056ce461f22a4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
Bob Moored59b8ec2012-07-16 10:15:36 +08003 * Module Name: tbxface - ACPI table oriented external interfaces
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 *****************************************************************************/
6
7/*
Bob Moore77848132012-01-12 13:27:23 +08008 * Copyright (C) 2000 - 2012, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Paul Gortmaker214f2c92011-10-26 16:22:14 -040044#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050046#include "accommon.h"
47#include "acnamesp.h"
48#include "actables.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define _COMPONENT ACPI_TABLES
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("tbxface")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/*******************************************************************************
54 *
Bob Moore77389e12007-02-02 19:48:20 +030055 * FUNCTION: acpi_allocate_root_table
56 *
57 * PARAMETERS: initial_table_count - Size of initial_table_array, in number of
58 * struct acpi_table_desc structures
59 *
60 * RETURN: Status
61 *
62 * DESCRIPTION: Allocate a root table array. Used by i_aSL compiler and
63 * acpi_initialize_tables.
64 *
65 ******************************************************************************/
Bob Moore77389e12007-02-02 19:48:20 +030066acpi_status acpi_allocate_root_table(u32 initial_table_count)
67{
68
Bob Mooreb9ee2042010-04-27 11:16:14 +080069 acpi_gbl_root_table_list.max_table_count = initial_table_count;
Bob Moore77389e12007-02-02 19:48:20 +030070 acpi_gbl_root_table_list.flags = ACPI_ROOT_ALLOW_RESIZE;
71
72 return (acpi_tb_resize_root_table_list());
73}
74
75/*******************************************************************************
76 *
Bob Mooref3d2e782007-02-02 19:48:18 +030077 * FUNCTION: acpi_initialize_tables
78 *
79 * PARAMETERS: initial_table_array - Pointer to an array of pre-allocated
80 * struct acpi_table_desc structures. If NULL, the
81 * array is dynamically allocated.
82 * initial_table_count - Size of initial_table_array, in number of
83 * struct acpi_table_desc structures
84 * allow_realloc - Flag to tell Table Manager if resize of
85 * pre-allocated array is allowed. Ignored
86 * if initial_table_array is NULL.
87 *
88 * RETURN: Status
89 *
90 * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
91 *
92 * NOTE: Allows static allocation of the initial table array in order
93 * to avoid the use of dynamic memory in confined environments
94 * such as the kernel boot sequence where it may not be available.
95 *
96 * If the host OS memory managers are initialized, use NULL for
97 * initial_table_array, and the table will be dynamically allocated.
98 *
99 ******************************************************************************/
100
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300101acpi_status __init
Bob Moore77389e12007-02-02 19:48:20 +0300102acpi_initialize_tables(struct acpi_table_desc * initial_table_array,
Bob Mooref3d2e782007-02-02 19:48:18 +0300103 u32 initial_table_count, u8 allow_resize)
104{
Bob Moorec5fc42a2007-02-02 19:48:19 +0300105 acpi_physical_address rsdp_address;
Bob Mooref3d2e782007-02-02 19:48:18 +0300106 acpi_status status;
Bob Mooref3d2e782007-02-02 19:48:18 +0300107
108 ACPI_FUNCTION_TRACE(acpi_initialize_tables);
109
110 /*
111 * Set up the Root Table Array
112 * Allocate the table array if requested
113 */
114 if (!initial_table_array) {
Bob Moore77389e12007-02-02 19:48:20 +0300115 status = acpi_allocate_root_table(initial_table_count);
Bob Mooref3d2e782007-02-02 19:48:18 +0300116 if (ACPI_FAILURE(status)) {
117 return_ACPI_STATUS(status);
118 }
119 } else {
120 /* Root Table Array has been statically allocated by the host */
121
Bob Moorea4bbb812007-02-02 19:48:19 +0300122 ACPI_MEMSET(initial_table_array, 0,
Bob Moore67a119f2008-06-10 13:42:13 +0800123 (acpi_size) initial_table_count *
Bob Moorea4bbb812007-02-02 19:48:19 +0300124 sizeof(struct acpi_table_desc));
Bob Moorec5fc42a2007-02-02 19:48:19 +0300125
Bob Mooref3d2e782007-02-02 19:48:18 +0300126 acpi_gbl_root_table_list.tables = initial_table_array;
Bob Mooreb9ee2042010-04-27 11:16:14 +0800127 acpi_gbl_root_table_list.max_table_count = initial_table_count;
Bob Moorec5fc42a2007-02-02 19:48:19 +0300128 acpi_gbl_root_table_list.flags = ACPI_ROOT_ORIGIN_UNKNOWN;
Bob Mooref3d2e782007-02-02 19:48:18 +0300129 if (allow_resize) {
Bob Moorec5fc42a2007-02-02 19:48:19 +0300130 acpi_gbl_root_table_list.flags |=
131 ACPI_ROOT_ALLOW_RESIZE;
Bob Mooref3d2e782007-02-02 19:48:18 +0300132 }
133 }
134
Bob Moorec5fc42a2007-02-02 19:48:19 +0300135 /* Get the address of the RSDP */
Bob Mooref3d2e782007-02-02 19:48:18 +0300136
Bob Moorec5fc42a2007-02-02 19:48:19 +0300137 rsdp_address = acpi_os_get_root_pointer();
138 if (!rsdp_address) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300139 return_ACPI_STATUS(AE_NOT_FOUND);
140 }
141
Bob Mooref3d2e782007-02-02 19:48:18 +0300142 /*
143 * Get the root table (RSDT or XSDT) and extract all entries to the local
144 * Root Table Array. This array contains the information of the RSDT/XSDT
145 * in a common, more useable format.
146 */
Bob Moore97cbb7d2009-02-03 14:41:03 +0800147 status = acpi_tb_parse_root_table(rsdp_address);
Bob Mooref3d2e782007-02-02 19:48:18 +0300148 return_ACPI_STATUS(status);
149}
150
Bob Mooref3d2e782007-02-02 19:48:18 +0300151/*******************************************************************************
152 *
153 * FUNCTION: acpi_reallocate_root_table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 *
155 * PARAMETERS: None
156 *
157 * RETURN: Status
158 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300159 * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the
160 * root list from the previously provided scratch area. Should
161 * be called once dynamic memory allocation is available in the
162 * kernel
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 *
164 ******************************************************************************/
Bob Mooref3d2e782007-02-02 19:48:18 +0300165acpi_status acpi_reallocate_root_table(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
Bob Mooref3d2e782007-02-02 19:48:18 +0300167 struct acpi_table_desc *tables;
168 acpi_size new_size;
Alexey Starikovskiy333b04a2010-04-01 11:06:34 +0800169 acpi_size current_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Bob Mooref3d2e782007-02-02 19:48:18 +0300171 ACPI_FUNCTION_TRACE(acpi_reallocate_root_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Bob Mooref3d2e782007-02-02 19:48:18 +0300173 /*
174 * Only reallocate the root table if the host provided a static buffer
175 * for the table array in the call to acpi_initialize_tables.
176 */
Bob Moorec5fc42a2007-02-02 19:48:19 +0300177 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300178 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 }
180
Alexey Starikovskiy333b04a2010-04-01 11:06:34 +0800181 /*
182 * Get the current size of the root table and add the default
183 * increment to create the new table size.
184 */
185 current_size = (acpi_size)
Bob Mooreb9ee2042010-04-27 11:16:14 +0800186 acpi_gbl_root_table_list.current_table_count *
187 sizeof(struct acpi_table_desc);
Alexey Starikovskiy333b04a2010-04-01 11:06:34 +0800188
189 new_size = current_size +
190 (ACPI_ROOT_TABLE_SIZE_INCREMENT * sizeof(struct acpi_table_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Bob Mooref3d2e782007-02-02 19:48:18 +0300192 /* Create new array and copy the old array */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Bob Mooref3d2e782007-02-02 19:48:18 +0300194 tables = ACPI_ALLOCATE_ZEROED(new_size);
195 if (!tables) {
196 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 }
198
Alexey Starikovskiy333b04a2010-04-01 11:06:34 +0800199 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables, current_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Alexey Starikovskiy333b04a2010-04-01 11:06:34 +0800201 /*
202 * Update the root table descriptor. The new size will be the current
203 * number of tables plus the increment, independent of the reserved
204 * size of the original table list.
205 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300206 acpi_gbl_root_table_list.tables = tables;
Bob Mooreb9ee2042010-04-27 11:16:14 +0800207 acpi_gbl_root_table_list.max_table_count =
208 acpi_gbl_root_table_list.current_table_count +
209 ACPI_ROOT_TABLE_SIZE_INCREMENT;
Bob Mooref3d2e782007-02-02 19:48:18 +0300210 acpi_gbl_root_table_list.flags =
Bob Moorec5fc42a2007-02-02 19:48:19 +0300211 ACPI_ROOT_ORIGIN_ALLOCATED | ACPI_ROOT_ALLOW_RESIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Len Brown4be44fc2005-08-05 00:44:28 -0400213 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}
Len Brownfd350942007-05-09 23:34:35 -0400215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216/*******************************************************************************
217 *
218 * FUNCTION: acpi_load_table
219 *
220 * PARAMETERS: table_ptr - pointer to a buffer containing the entire
221 * table to be loaded
222 *
223 * RETURN: Status
224 *
225 * DESCRIPTION: This function is called to load a table from the caller's
Bob Mooref6dd9222006-07-07 20:44:38 -0400226 * buffer. The buffer must contain an entire ACPI Table including
227 * a valid header. The header fields will be verified, and if it
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 * is determined that the table is invalid, the call will fail.
229 *
230 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400231acpi_status acpi_load_table(struct acpi_table_header *table_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
Len Brown4be44fc2005-08-05 00:44:28 -0400233 acpi_status status;
Bob Moore67a119f2008-06-10 13:42:13 +0800234 u32 table_index;
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300235 struct acpi_table_desc table_desc;
236
237 if (!table_ptr)
238 return AE_BAD_PARAMETER;
239
240 ACPI_MEMSET(&table_desc, 0, sizeof(struct acpi_table_desc));
241 table_desc.pointer = table_ptr;
242 table_desc.length = table_ptr->length;
243 table_desc.flags = ACPI_TABLE_ORIGIN_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Bob Mooref3d2e782007-02-02 19:48:18 +0300245 /*
246 * Install the new table into the local data structures
247 */
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300248 status = acpi_tb_add_table(&table_desc, &table_index);
Len Brown4be44fc2005-08-05 00:44:28 -0400249 if (ACPI_FAILURE(status)) {
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300250 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300252 status = acpi_ns_load_table(table_index, acpi_gbl_root_node);
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300253 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254}
255
Bob Moore83135242006-10-03 00:00:00 -0400256ACPI_EXPORT_SYMBOL(acpi_load_table)
257
Bob Mooreec41f192009-02-18 15:03:30 +0800258/*******************************************************************************
Bob Mooref3d2e782007-02-02 19:48:18 +0300259 *
260 * FUNCTION: acpi_get_table_header
261 *
262 * PARAMETERS: Signature - ACPI signature of needed table
263 * Instance - Which instance (for SSDTs)
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300264 * out_table_header - The pointer to the table header to fill
Bob Mooref3d2e782007-02-02 19:48:18 +0300265 *
266 * RETURN: Status and pointer to mapped table header
267 *
268 * DESCRIPTION: Finds an ACPI table header.
269 *
270 * NOTE: Caller is responsible in unmapping the header with
271 * acpi_os_unmap_memory
272 *
Bob Mooreec41f192009-02-18 15:03:30 +0800273 ******************************************************************************/
Bob Mooref3d2e782007-02-02 19:48:18 +0300274acpi_status
275acpi_get_table_header(char *signature,
Bob Moore67a119f2008-06-10 13:42:13 +0800276 u32 instance, struct acpi_table_header *out_table_header)
Bob Mooref3d2e782007-02-02 19:48:18 +0300277{
Bob Moore67a119f2008-06-10 13:42:13 +0800278 u32 i;
279 u32 j;
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300280 struct acpi_table_header *header;
Bob Mooref3d2e782007-02-02 19:48:18 +0300281
Bob Moorec5fc42a2007-02-02 19:48:19 +0300282 /* Parameter validation */
283
284 if (!signature || !out_table_header) {
285 return (AE_BAD_PARAMETER);
286 }
287
Bob Mooreec41f192009-02-18 15:03:30 +0800288 /* Walk the root table list */
289
Bob Mooreb9ee2042010-04-27 11:16:14 +0800290 for (i = 0, j = 0; i < acpi_gbl_root_table_list.current_table_count;
291 i++) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300292 if (!ACPI_COMPARE_NAME
293 (&(acpi_gbl_root_table_list.tables[i].signature),
294 signature)) {
295 continue;
296 }
297
298 if (++j < instance) {
299 continue;
300 }
301
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300302 if (!acpi_gbl_root_table_list.tables[i].pointer) {
Bob Mooreec41f192009-02-18 15:03:30 +0800303 if ((acpi_gbl_root_table_list.tables[i].flags &
304 ACPI_TABLE_ORIGIN_MASK) ==
Alexey Starikovskiy428f2112007-02-02 19:48:22 +0300305 ACPI_TABLE_ORIGIN_MAPPED) {
306 header =
307 acpi_os_map_memory(acpi_gbl_root_table_list.
308 tables[i].address,
309 sizeof(struct
310 acpi_table_header));
311 if (!header) {
312 return AE_NO_MEMORY;
313 }
314 ACPI_MEMCPY(out_table_header, header,
315 sizeof(struct acpi_table_header));
316 acpi_os_unmap_memory(header,
317 sizeof(struct
318 acpi_table_header));
319 } else {
320 return AE_NOT_FOUND;
321 }
322 } else {
323 ACPI_MEMCPY(out_table_header,
324 acpi_gbl_root_table_list.tables[i].pointer,
325 sizeof(struct acpi_table_header));
Bob Mooref3d2e782007-02-02 19:48:18 +0300326 }
Bob Mooref3d2e782007-02-02 19:48:18 +0300327 return (AE_OK);
328 }
329
330 return (AE_NOT_FOUND);
331}
332
333ACPI_EXPORT_SYMBOL(acpi_get_table_header)
334
Bob Mooreec41f192009-02-18 15:03:30 +0800335/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 *
John Keller0f0fe1a2006-12-19 12:56:19 -0800337 * FUNCTION: acpi_unload_table_id
338 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300339 * PARAMETERS: id - Owner ID of the table to be removed.
John Keller0f0fe1a2006-12-19 12:56:19 -0800340 *
341 * RETURN: Status
342 *
343 * DESCRIPTION: This routine is used to force the unload of a table (by id)
344 *
345 ******************************************************************************/
Bob Mooref3d2e782007-02-02 19:48:18 +0300346acpi_status acpi_unload_table_id(acpi_owner_id id)
John Keller0f0fe1a2006-12-19 12:56:19 -0800347{
Bob Mooref3d2e782007-02-02 19:48:18 +0300348 int i;
349 acpi_status status = AE_NOT_EXIST;
John Keller0f0fe1a2006-12-19 12:56:19 -0800350
John Kellerecb5f752007-02-15 14:08:30 -0600351 ACPI_FUNCTION_TRACE(acpi_unload_table_id);
John Keller0f0fe1a2006-12-19 12:56:19 -0800352
John Kellerecb5f752007-02-15 14:08:30 -0600353 /* Find table in the global table list */
Bob Mooreb9ee2042010-04-27 11:16:14 +0800354 for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300355 if (id != acpi_gbl_root_table_list.tables[i].owner_id) {
356 continue;
357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 /*
Len Brownfd350942007-05-09 23:34:35 -0400359 * Delete all namespace objects owned by this table. Note that these
360 * objects can appear anywhere in the namespace by virtue of the AML
361 * "Scope" operator. Thus, we need to track ownership by an ID, not
362 * simply a position within the hierarchy
363 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300364 acpi_tb_delete_namespace_by_owner(i);
John Kellerecb5f752007-02-15 14:08:30 -0600365 status = acpi_tb_release_owner_id(i);
Bob Mooref3d2e782007-02-02 19:48:18 +0300366 acpi_tb_set_table_loaded_flag(i, FALSE);
John Kellerecb5f752007-02-15 14:08:30 -0600367 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 }
Len Brown4be44fc2005-08-05 00:44:28 -0400369 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370}
371
Bob Mooref3d2e782007-02-02 19:48:18 +0300372ACPI_EXPORT_SYMBOL(acpi_unload_table_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374/*******************************************************************************
375 *
Yinghai Lu7d972772009-02-07 15:39:41 -0800376 * FUNCTION: acpi_get_table_with_size
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300378 * PARAMETERS: Signature - ACPI signature of needed table
379 * Instance - Which instance (for SSDTs)
380 * out_table - Where the pointer to the table is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300382 * RETURN: Status and pointer to table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 *
Bob Mooref3d2e782007-02-02 19:48:18 +0300384 * DESCRIPTION: Finds and verifies an ACPI table.
385 *
Bob Mooreec41f192009-02-18 15:03:30 +0800386 ******************************************************************************/
Bob Mooref3d2e782007-02-02 19:48:18 +0300387acpi_status
Yinghai Lu7d972772009-02-07 15:39:41 -0800388acpi_get_table_with_size(char *signature,
389 u32 instance, struct acpi_table_header **out_table,
390 acpi_size *tbl_size)
Bob Mooref3d2e782007-02-02 19:48:18 +0300391{
Bob Moore67a119f2008-06-10 13:42:13 +0800392 u32 i;
393 u32 j;
Bob Mooref3d2e782007-02-02 19:48:18 +0300394 acpi_status status;
395
Bob Moorec5fc42a2007-02-02 19:48:19 +0300396 /* Parameter validation */
397
398 if (!signature || !out_table) {
399 return (AE_BAD_PARAMETER);
400 }
401
Bob Mooreec41f192009-02-18 15:03:30 +0800402 /* Walk the root table list */
403
Bob Mooreb9ee2042010-04-27 11:16:14 +0800404 for (i = 0, j = 0; i < acpi_gbl_root_table_list.current_table_count;
405 i++) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300406 if (!ACPI_COMPARE_NAME
407 (&(acpi_gbl_root_table_list.tables[i].signature),
408 signature)) {
409 continue;
410 }
411
412 if (++j < instance) {
413 continue;
414 }
415
416 status =
417 acpi_tb_verify_table(&acpi_gbl_root_table_list.tables[i]);
418 if (ACPI_SUCCESS(status)) {
419 *out_table = acpi_gbl_root_table_list.tables[i].pointer;
Yinghai Lu7d972772009-02-07 15:39:41 -0800420 *tbl_size = acpi_gbl_root_table_list.tables[i].length;
Bob Mooref3d2e782007-02-02 19:48:18 +0300421 }
422
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300423 if (!acpi_gbl_permanent_mmap) {
Randy Dunlap70c08462007-02-13 16:11:36 -0800424 acpi_gbl_root_table_list.tables[i].pointer = NULL;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300425 }
426
Bob Mooref3d2e782007-02-02 19:48:18 +0300427 return (status);
428 }
429
430 return (AE_NOT_FOUND);
431}
432
Yinghai Lu7d972772009-02-07 15:39:41 -0800433acpi_status
434acpi_get_table(char *signature,
435 u32 instance, struct acpi_table_header **out_table)
436{
437 acpi_size tbl_size;
438
439 return acpi_get_table_with_size(signature,
440 instance, out_table, &tbl_size);
441}
Bob Mooref3d2e782007-02-02 19:48:18 +0300442ACPI_EXPORT_SYMBOL(acpi_get_table)
443
444/*******************************************************************************
445 *
446 * FUNCTION: acpi_get_table_by_index
447 *
448 * PARAMETERS: table_index - Table index
449 * Table - Where the pointer to the table is returned
450 *
451 * RETURN: Status and pointer to the table
452 *
453 * DESCRIPTION: Obtain a table by an index into the global table list.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 *
455 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456acpi_status
Bob Moore67a119f2008-06-10 13:42:13 +0800457acpi_get_table_by_index(u32 table_index, struct acpi_table_header **table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458{
Len Brown4be44fc2005-08-05 00:44:28 -0400459 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Bob Mooref3d2e782007-02-02 19:48:18 +0300461 ACPI_FUNCTION_TRACE(acpi_get_table_by_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
Bob Moorec5fc42a2007-02-02 19:48:19 +0300463 /* Parameter validation */
464
465 if (!table) {
466 return_ACPI_STATUS(AE_BAD_PARAMETER);
467 }
468
Bob Mooref3d2e782007-02-02 19:48:18 +0300469 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Bob Mooref3d2e782007-02-02 19:48:18 +0300471 /* Validate index */
472
Bob Mooreb9ee2042010-04-27 11:16:14 +0800473 if (table_index >= acpi_gbl_root_table_list.current_table_count) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300474 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Len Brown4be44fc2005-08-05 00:44:28 -0400475 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 }
477
Bob Mooref3d2e782007-02-02 19:48:18 +0300478 if (!acpi_gbl_root_table_list.tables[table_index].pointer) {
479
480 /* Table is not mapped, map it */
481
482 status =
483 acpi_tb_verify_table(&acpi_gbl_root_table_list.
484 tables[table_index]);
485 if (ACPI_FAILURE(status)) {
486 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
487 return_ACPI_STATUS(status);
488 }
489 }
490
491 *table = acpi_gbl_root_table_list.tables[table_index].pointer;
492 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
493 return_ACPI_STATUS(AE_OK);
494}
495
496ACPI_EXPORT_SYMBOL(acpi_get_table_by_index)
497
Len Brown67effe82007-07-26 00:50:06 -0400498
Lin Ming3e08e2d2008-04-10 19:06:38 +0400499/*******************************************************************************
500 *
501 * FUNCTION: acpi_install_table_handler
502 *
503 * PARAMETERS: Handler - Table event handler
504 * Context - Value passed to the handler on each event
505 *
506 * RETURN: Status
507 *
508 * DESCRIPTION: Install table event handler
509 *
510 ******************************************************************************/
511acpi_status
512acpi_install_table_handler(acpi_tbl_handler handler, void *context)
513{
514 acpi_status status;
515
516 ACPI_FUNCTION_TRACE(acpi_install_table_handler);
517
518 if (!handler) {
519 return_ACPI_STATUS(AE_BAD_PARAMETER);
520 }
521
522 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
523 if (ACPI_FAILURE(status)) {
524 return_ACPI_STATUS(status);
525 }
526
527 /* Don't allow more than one handler */
528
529 if (acpi_gbl_table_handler) {
530 status = AE_ALREADY_EXISTS;
531 goto cleanup;
532 }
533
534 /* Install the handler */
535
536 acpi_gbl_table_handler = handler;
537 acpi_gbl_table_handler_context = context;
538
539 cleanup:
540 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
541 return_ACPI_STATUS(status);
542}
543
544ACPI_EXPORT_SYMBOL(acpi_install_table_handler)
545
546/*******************************************************************************
547 *
548 * FUNCTION: acpi_remove_table_handler
549 *
550 * PARAMETERS: Handler - Table event handler that was installed
551 * previously.
552 *
553 * RETURN: Status
554 *
555 * DESCRIPTION: Remove table event handler
556 *
557 ******************************************************************************/
558acpi_status acpi_remove_table_handler(acpi_tbl_handler handler)
559{
560 acpi_status status;
561
562 ACPI_FUNCTION_TRACE(acpi_remove_table_handler);
563
564 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
565 if (ACPI_FAILURE(status)) {
566 return_ACPI_STATUS(status);
567 }
568
569 /* Make sure that the installed handler is the same */
570
571 if (!handler || handler != acpi_gbl_table_handler) {
572 status = AE_BAD_PARAMETER;
573 goto cleanup;
574 }
575
576 /* Remove the handler */
577
578 acpi_gbl_table_handler = NULL;
579
580 cleanup:
581 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
582 return_ACPI_STATUS(status);
583}
584
585ACPI_EXPORT_SYMBOL(acpi_remove_table_handler)