blob: 7856db759af0be7579abcd1733e74d1782455dbe [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: tbget - ACPI Table get* routines
4 *
5 *****************************************************************************/
6
7/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/actables.h>
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define _COMPONENT ACPI_TABLES
Len Brown4be44fc2005-08-05 00:44:28 -040048ACPI_MODULE_NAME("tbget")
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Robert Moore44f6c012005-04-18 22:49:35 -040050/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040051static acpi_status
52acpi_tb_get_this_table(struct acpi_pointer *address,
53 struct acpi_table_header *header,
54 struct acpi_table_desc *table_info);
Robert Moore44f6c012005-04-18 22:49:35 -040055
56static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040057acpi_tb_table_override(struct acpi_table_header *header,
58 struct acpi_table_desc *table_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60/*******************************************************************************
61 *
62 * FUNCTION: acpi_tb_get_table
63 *
64 * PARAMETERS: Address - Address of table to retrieve. Can be
65 * Logical or Physical
66 * table_info - Where table info is returned
67 *
68 * RETURN: None
69 *
70 * DESCRIPTION: Get entire table of unknown size.
71 *
72 ******************************************************************************/
73
74acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040075acpi_tb_get_table(struct acpi_pointer *address,
76 struct acpi_table_desc *table_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
Len Brown4be44fc2005-08-05 00:44:28 -040078 acpi_status status;
79 struct acpi_table_header header;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Bob Mooreb229cf92006-04-21 17:15:00 -040081 ACPI_FUNCTION_TRACE(tb_get_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Robert Moore44f6c012005-04-18 22:49:35 -040083 /* Get the header in order to get signature and table size */
84
Len Brown4be44fc2005-08-05 00:44:28 -040085 status = acpi_tb_get_table_header(address, &header);
86 if (ACPI_FAILURE(status)) {
87 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 }
89
90 /* Get the entire table */
91
Len Brown4be44fc2005-08-05 00:44:28 -040092 status = acpi_tb_get_table_body(address, &header, table_info);
93 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050094 ACPI_EXCEPTION((AE_INFO, status,
95 "Could not get ACPI table (size %X)",
96 header.length));
Len Brown4be44fc2005-08-05 00:44:28 -040097 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 }
99
Len Brown4be44fc2005-08-05 00:44:28 -0400100 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103/*******************************************************************************
104 *
105 * FUNCTION: acpi_tb_get_table_header
106 *
107 * PARAMETERS: Address - Address of table to retrieve. Can be
108 * Logical or Physical
109 * return_header - Where the table header is returned
110 *
111 * RETURN: Status
112 *
113 * DESCRIPTION: Get an ACPI table header. Works in both physical or virtual
114 * addressing mode. Works with both physical or logical pointers.
115 * Table is either copied or mapped, depending on the pointer
116 * type and mode of the processor.
117 *
118 ******************************************************************************/
119
120acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400121acpi_tb_get_table_header(struct acpi_pointer *address,
122 struct acpi_table_header *return_header)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
Len Brown4be44fc2005-08-05 00:44:28 -0400124 acpi_status status = AE_OK;
125 struct acpi_table_header *header = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Bob Mooreb229cf92006-04-21 17:15:00 -0400127 ACPI_FUNCTION_TRACE(tb_get_table_header);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400130 * Flags contains the current processor mode (Virtual or Physical
131 * addressing) The pointer_type is either Logical or Physical
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 */
133 switch (address->pointer_type) {
134 case ACPI_PHYSMODE_PHYSPTR:
135 case ACPI_LOGMODE_LOGPTR:
136
137 /* Pointer matches processor mode, copy the header */
138
Len Brown4be44fc2005-08-05 00:44:28 -0400139 ACPI_MEMCPY(return_header, address->pointer.logical,
140 sizeof(struct acpi_table_header));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 break;
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 case ACPI_LOGMODE_PHYSPTR:
144
Len Brown4be44fc2005-08-05 00:44:28 -0400145 /* Create a logical address for the physical pointer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Len Brown4be44fc2005-08-05 00:44:28 -0400147 status = acpi_os_map_memory(address->pointer.physical,
148 sizeof(struct acpi_table_header),
149 (void *)&header);
150 if (ACPI_FAILURE(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400151 ACPI_ERROR((AE_INFO,
152 "Could not map memory at %8.8X%8.8X for table header",
153 ACPI_FORMAT_UINT64(address->pointer.
154 physical)));
Len Brown4be44fc2005-08-05 00:44:28 -0400155 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157
158 /* Copy header and delete mapping */
159
Len Brown4be44fc2005-08-05 00:44:28 -0400160 ACPI_MEMCPY(return_header, header,
161 sizeof(struct acpi_table_header));
162 acpi_os_unmap_memory(header, sizeof(struct acpi_table_header));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 break;
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 default:
166
Bob Mooreb8e4d892006-01-27 16:43:00 -0500167 ACPI_ERROR((AE_INFO, "Invalid address flags %X",
168 address->pointer_type));
Len Brown4be44fc2005-08-05 00:44:28 -0400169 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 }
171
Len Brown4be44fc2005-08-05 00:44:28 -0400172 ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "Table Signature: [%4.4s]\n",
173 return_header->signature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Len Brown4be44fc2005-08-05 00:44:28 -0400175 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178/*******************************************************************************
179 *
180 * FUNCTION: acpi_tb_get_table_body
181 *
182 * PARAMETERS: Address - Address of table to retrieve. Can be
183 * Logical or Physical
184 * Header - Header of the table to retrieve
185 * table_info - Where the table info is returned
186 *
187 * RETURN: Status
188 *
189 * DESCRIPTION: Get an entire ACPI table with support to allow the host OS to
190 * replace the table with a newer version (table override.)
191 * Works in both physical or virtual
192 * addressing mode. Works with both physical or logical pointers.
193 * Table is either copied or mapped, depending on the pointer
194 * type and mode of the processor.
195 *
196 ******************************************************************************/
197
198acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400199acpi_tb_get_table_body(struct acpi_pointer *address,
200 struct acpi_table_header *header,
201 struct acpi_table_desc *table_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202{
Len Brown4be44fc2005-08-05 00:44:28 -0400203 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Bob Mooreb229cf92006-04-21 17:15:00 -0400205 ACPI_FUNCTION_TRACE(tb_get_table_body);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
207 if (!table_info || !address) {
Len Brown4be44fc2005-08-05 00:44:28 -0400208 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 }
210
Robert Moore44f6c012005-04-18 22:49:35 -0400211 /* Attempt table override. */
212
Len Brown4be44fc2005-08-05 00:44:28 -0400213 status = acpi_tb_table_override(header, table_info);
214 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 /* Table was overridden by the host OS */
217
Len Brown4be44fc2005-08-05 00:44:28 -0400218 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 }
220
221 /* No override, get the original table */
222
Len Brown4be44fc2005-08-05 00:44:28 -0400223 status = acpi_tb_get_this_table(address, header, table_info);
224 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225}
226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227/*******************************************************************************
228 *
229 * FUNCTION: acpi_tb_table_override
230 *
231 * PARAMETERS: Header - Pointer to table header
232 * table_info - Return info if table is overridden
233 *
234 * RETURN: None
235 *
236 * DESCRIPTION: Attempts override of current table with a new one if provided
237 * by the host OS.
238 *
239 ******************************************************************************/
240
Robert Moore44f6c012005-04-18 22:49:35 -0400241static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400242acpi_tb_table_override(struct acpi_table_header *header,
243 struct acpi_table_desc *table_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
Len Brown4be44fc2005-08-05 00:44:28 -0400245 struct acpi_table_header *new_table;
246 acpi_status status;
247 struct acpi_pointer address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Bob Mooreb229cf92006-04-21 17:15:00 -0400249 ACPI_FUNCTION_TRACE(tb_table_override);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
251 /*
252 * The OSL will examine the header and decide whether to override this
253 * table. If it decides to override, a table will be returned in new_table,
254 * which we will then copy.
255 */
Len Brown4be44fc2005-08-05 00:44:28 -0400256 status = acpi_os_table_override(header, &new_table);
257 if (ACPI_FAILURE(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 /* Some severe error from the OSL, but we basically ignore it */
260
Bob Mooreb8e4d892006-01-27 16:43:00 -0500261 ACPI_EXCEPTION((AE_INFO, status,
262 "Could not override ACPI table"));
Len Brown4be44fc2005-08-05 00:44:28 -0400263 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 }
265
266 if (!new_table) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 /* No table override */
269
Len Brown4be44fc2005-08-05 00:44:28 -0400270 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 }
272
273 /*
274 * We have a new table to override the old one. Get a copy of
275 * the new one. We know that the new table has a logical pointer.
276 */
Len Brown4be44fc2005-08-05 00:44:28 -0400277 address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 address.pointer.logical = new_table;
279
Len Brown4be44fc2005-08-05 00:44:28 -0400280 status = acpi_tb_get_this_table(&address, new_table, table_info);
281 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500282 ACPI_EXCEPTION((AE_INFO, status, "Could not copy ACPI table"));
Len Brown4be44fc2005-08-05 00:44:28 -0400283 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 }
285
286 /* Copy the table info */
287
Bob Mooreb8e4d892006-01-27 16:43:00 -0500288 ACPI_INFO((AE_INFO, "Table [%4.4s] replaced by host OS",
289 table_info->pointer->signature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Len Brown4be44fc2005-08-05 00:44:28 -0400291 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292}
293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294/*******************************************************************************
295 *
296 * FUNCTION: acpi_tb_get_this_table
297 *
298 * PARAMETERS: Address - Address of table to retrieve. Can be
299 * Logical or Physical
300 * Header - Header of the table to retrieve
301 * table_info - Where the table info is returned
302 *
303 * RETURN: Status
304 *
305 * DESCRIPTION: Get an entire ACPI table. Works in both physical or virtual
306 * addressing mode. Works with both physical or logical pointers.
307 * Table is either copied or mapped, depending on the pointer
308 * type and mode of the processor.
309 *
310 ******************************************************************************/
311
Robert Moore44f6c012005-04-18 22:49:35 -0400312static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400313acpi_tb_get_this_table(struct acpi_pointer *address,
314 struct acpi_table_header *header,
315 struct acpi_table_desc *table_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
Len Brown4be44fc2005-08-05 00:44:28 -0400317 struct acpi_table_header *full_table = NULL;
318 u8 allocation;
319 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Bob Mooreb229cf92006-04-21 17:15:00 -0400321 ACPI_FUNCTION_TRACE(tb_get_this_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Bob Mooref6dd9222006-07-07 20:44:38 -0400323 /* Validate minimum length */
324
325 if (header->length < sizeof(struct acpi_table_header)) {
326 ACPI_ERROR((AE_INFO,
327 "Table length (%X) is smaller than minimum (%X)",
328 header->length, sizeof(struct acpi_table_header)));
329
330 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
331 }
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400334 * Flags contains the current processor mode (Virtual or Physical
335 * addressing) The pointer_type is either Logical or Physical
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 */
337 switch (address->pointer_type) {
338 case ACPI_PHYSMODE_PHYSPTR:
339 case ACPI_LOGMODE_LOGPTR:
340
341 /* Pointer matches processor mode, copy the table to a new buffer */
342
Bob Moore83135242006-10-03 00:00:00 -0400343 full_table = ACPI_ALLOCATE(header->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 if (!full_table) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500345 ACPI_ERROR((AE_INFO,
346 "Could not allocate table memory for [%4.4s] length %X",
347 header->signature, header->length));
Len Brown4be44fc2005-08-05 00:44:28 -0400348 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
350
351 /* Copy the entire table (including header) to the local buffer */
352
Len Brown4be44fc2005-08-05 00:44:28 -0400353 ACPI_MEMCPY(full_table, address->pointer.logical,
354 header->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356 /* Save allocation type */
357
358 allocation = ACPI_MEM_ALLOCATED;
359 break;
360
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 case ACPI_LOGMODE_PHYSPTR:
362
363 /*
364 * Just map the table's physical memory
365 * into our address space.
366 */
Len Brown4be44fc2005-08-05 00:44:28 -0400367 status = acpi_os_map_memory(address->pointer.physical,
368 (acpi_size) header->length,
Bob Mooref6dd9222006-07-07 20:44:38 -0400369 ACPI_CAST_PTR(void, &full_table));
Len Brown4be44fc2005-08-05 00:44:28 -0400370 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500371 ACPI_ERROR((AE_INFO,
372 "Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X",
373 header->signature,
374 ACPI_FORMAT_UINT64(address->pointer.
375 physical),
376 header->length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 return (status);
378 }
379
380 /* Save allocation type */
381
382 allocation = ACPI_MEM_MAPPED;
383 break;
384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 default:
386
Bob Mooreb8e4d892006-01-27 16:43:00 -0500387 ACPI_ERROR((AE_INFO, "Invalid address flags %X",
388 address->pointer_type));
Len Brown4be44fc2005-08-05 00:44:28 -0400389 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 }
391
392 /*
393 * Validate checksum for _most_ tables,
394 * even the ones whose signature we don't recognize
395 */
Bob Mooreb229cf92006-04-21 17:15:00 -0400396 if (table_info->type != ACPI_TABLE_ID_FACS) {
Len Brown4be44fc2005-08-05 00:44:28 -0400397 status = acpi_tb_verify_table_checksum(full_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399#if (!ACPI_CHECKSUM_ABORT)
Len Brown4be44fc2005-08-05 00:44:28 -0400400 if (ACPI_FAILURE(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400401
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 /* Ignore the error if configuration says so */
403
404 status = AE_OK;
405 }
406#endif
407 }
408
409 /* Return values */
410
Len Brown4be44fc2005-08-05 00:44:28 -0400411 table_info->pointer = full_table;
412 table_info->length = (acpi_size) header->length;
413 table_info->allocation = allocation;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Len Brown4be44fc2005-08-05 00:44:28 -0400415 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
416 "Found table [%4.4s] at %8.8X%8.8X, mapped/copied to %p\n",
417 full_table->signature,
418 ACPI_FORMAT_UINT64(address->pointer.physical),
419 full_table));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Len Brown4be44fc2005-08-05 00:44:28 -0400421 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422}
423
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424/*******************************************************************************
425 *
426 * FUNCTION: acpi_tb_get_table_ptr
427 *
428 * PARAMETERS: table_type - one of the defined table types
429 * Instance - Which table of this type
Bob Moore41195322006-05-26 16:36:00 -0400430 * return_table - pointer to location to place the pointer for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 * return
432 *
433 * RETURN: Status
434 *
435 * DESCRIPTION: This function is called to get the pointer to an ACPI table.
436 *
437 ******************************************************************************/
438
439acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400440acpi_tb_get_table_ptr(acpi_table_type table_type,
Bob Moore41195322006-05-26 16:36:00 -0400441 u32 instance, struct acpi_table_header **return_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442{
Len Brown4be44fc2005-08-05 00:44:28 -0400443 struct acpi_table_desc *table_desc;
444 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Bob Mooreb229cf92006-04-21 17:15:00 -0400446 ACPI_FUNCTION_TRACE(tb_get_table_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Bob Mooreb229cf92006-04-21 17:15:00 -0400448 if (table_type > ACPI_TABLE_ID_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400449 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 }
451
Bob Moore41195322006-05-26 16:36:00 -0400452 /* Check for instance out of range of the current table count */
Robert Moore44f6c012005-04-18 22:49:35 -0400453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 if (instance > acpi_gbl_table_lists[table_type].count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400455 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 }
457
Bob Moore41195322006-05-26 16:36:00 -0400458 /*
459 * Walk the list to get the desired table
460 * Note: Instance is one-based
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 */
462 table_desc = acpi_gbl_table_lists[table_type].next;
Bob Moore41195322006-05-26 16:36:00 -0400463 for (i = 1; i < instance; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 table_desc = table_desc->next;
465 }
466
467 /* We are now pointing to the requested table's descriptor */
468
Bob Moore41195322006-05-26 16:36:00 -0400469 *return_table = table_desc->pointer;
Len Brown4be44fc2005-08-05 00:44:28 -0400470 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471}