blob: 09b4ee6dfd60a6e96e7aa2f1a50ba6c4cbabe47a [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
Len Brown4be44fc2005-08-05 00:44:28 -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
Len Brown4be44fc2005-08-05 00:44:28 -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)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400151 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 }
153
154 /* Copy header and delete mapping */
155
Len Brown4be44fc2005-08-05 00:44:28 -0400156 ACPI_MEMCPY(return_header, header,
157 sizeof(struct acpi_table_header));
158 acpi_os_unmap_memory(header, sizeof(struct acpi_table_header));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 break;
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 default:
162
Bob Mooreb8e4d892006-01-27 16:43:00 -0500163 ACPI_ERROR((AE_INFO, "Invalid address flags %X",
164 address->pointer_type));
Len Brown4be44fc2005-08-05 00:44:28 -0400165 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 }
167
Len Brown4be44fc2005-08-05 00:44:28 -0400168 ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "Table Signature: [%4.4s]\n",
169 return_header->signature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Len Brown4be44fc2005-08-05 00:44:28 -0400171 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172}
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174/*******************************************************************************
175 *
176 * FUNCTION: acpi_tb_get_table_body
177 *
178 * PARAMETERS: Address - Address of table to retrieve. Can be
179 * Logical or Physical
180 * Header - Header of the table to retrieve
181 * table_info - Where the table info is returned
182 *
183 * RETURN: Status
184 *
185 * DESCRIPTION: Get an entire ACPI table with support to allow the host OS to
186 * replace the table with a newer version (table override.)
187 * Works in both physical or virtual
188 * addressing mode. Works with both physical or logical pointers.
189 * Table is either copied or mapped, depending on the pointer
190 * type and mode of the processor.
191 *
192 ******************************************************************************/
193
194acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400195acpi_tb_get_table_body(struct acpi_pointer *address,
196 struct acpi_table_header *header,
197 struct acpi_table_desc *table_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
Len Brown4be44fc2005-08-05 00:44:28 -0400199 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Len Brown4be44fc2005-08-05 00:44:28 -0400201 ACPI_FUNCTION_TRACE("tb_get_table_body");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203 if (!table_info || !address) {
Len Brown4be44fc2005-08-05 00:44:28 -0400204 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 }
206
Robert Moore44f6c012005-04-18 22:49:35 -0400207 /* Attempt table override. */
208
Len Brown4be44fc2005-08-05 00:44:28 -0400209 status = acpi_tb_table_override(header, table_info);
210 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 /* Table was overridden by the host OS */
212
Len Brown4be44fc2005-08-05 00:44:28 -0400213 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 }
215
216 /* No override, get the original table */
217
Len Brown4be44fc2005-08-05 00:44:28 -0400218 status = acpi_tb_get_this_table(address, header, table_info);
219 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220}
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222/*******************************************************************************
223 *
224 * FUNCTION: acpi_tb_table_override
225 *
226 * PARAMETERS: Header - Pointer to table header
227 * table_info - Return info if table is overridden
228 *
229 * RETURN: None
230 *
231 * DESCRIPTION: Attempts override of current table with a new one if provided
232 * by the host OS.
233 *
234 ******************************************************************************/
235
Robert Moore44f6c012005-04-18 22:49:35 -0400236static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400237acpi_tb_table_override(struct acpi_table_header *header,
238 struct acpi_table_desc *table_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239{
Len Brown4be44fc2005-08-05 00:44:28 -0400240 struct acpi_table_header *new_table;
241 acpi_status status;
242 struct acpi_pointer address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Len Brown4be44fc2005-08-05 00:44:28 -0400244 ACPI_FUNCTION_TRACE("tb_table_override");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246 /*
247 * The OSL will examine the header and decide whether to override this
248 * table. If it decides to override, a table will be returned in new_table,
249 * which we will then copy.
250 */
Len Brown4be44fc2005-08-05 00:44:28 -0400251 status = acpi_os_table_override(header, &new_table);
252 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 /* Some severe error from the OSL, but we basically ignore it */
254
Bob Mooreb8e4d892006-01-27 16:43:00 -0500255 ACPI_EXCEPTION((AE_INFO, status,
256 "Could not override ACPI table"));
Len Brown4be44fc2005-08-05 00:44:28 -0400257 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 }
259
260 if (!new_table) {
261 /* No table override */
262
Len Brown4be44fc2005-08-05 00:44:28 -0400263 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 }
265
266 /*
267 * We have a new table to override the old one. Get a copy of
268 * the new one. We know that the new table has a logical pointer.
269 */
Len Brown4be44fc2005-08-05 00:44:28 -0400270 address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 address.pointer.logical = new_table;
272
Len Brown4be44fc2005-08-05 00:44:28 -0400273 status = acpi_tb_get_this_table(&address, new_table, table_info);
274 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500275 ACPI_EXCEPTION((AE_INFO, status, "Could not copy ACPI table"));
Len Brown4be44fc2005-08-05 00:44:28 -0400276 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 }
278
279 /* Copy the table info */
280
Bob Mooreb8e4d892006-01-27 16:43:00 -0500281 ACPI_INFO((AE_INFO, "Table [%4.4s] replaced by host OS",
282 table_info->pointer->signature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
Len Brown4be44fc2005-08-05 00:44:28 -0400284 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287/*******************************************************************************
288 *
289 * FUNCTION: acpi_tb_get_this_table
290 *
291 * PARAMETERS: Address - Address of table to retrieve. Can be
292 * Logical or Physical
293 * Header - Header of the table to retrieve
294 * table_info - Where the table info is returned
295 *
296 * RETURN: Status
297 *
298 * DESCRIPTION: Get an entire ACPI table. Works in both physical or virtual
299 * addressing mode. Works with both physical or logical pointers.
300 * Table is either copied or mapped, depending on the pointer
301 * type and mode of the processor.
302 *
303 ******************************************************************************/
304
Robert Moore44f6c012005-04-18 22:49:35 -0400305static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400306acpi_tb_get_this_table(struct acpi_pointer *address,
307 struct acpi_table_header *header,
308 struct acpi_table_desc *table_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
Len Brown4be44fc2005-08-05 00:44:28 -0400310 struct acpi_table_header *full_table = NULL;
311 u8 allocation;
312 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Len Brown4be44fc2005-08-05 00:44:28 -0400314 ACPI_FUNCTION_TRACE("tb_get_this_table");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400317 * Flags contains the current processor mode (Virtual or Physical
318 * addressing) The pointer_type is either Logical or Physical
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 */
320 switch (address->pointer_type) {
321 case ACPI_PHYSMODE_PHYSPTR:
322 case ACPI_LOGMODE_LOGPTR:
323
324 /* Pointer matches processor mode, copy the table to a new buffer */
325
Len Brown4be44fc2005-08-05 00:44:28 -0400326 full_table = ACPI_MEM_ALLOCATE(header->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 if (!full_table) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500328 ACPI_ERROR((AE_INFO,
329 "Could not allocate table memory for [%4.4s] length %X",
330 header->signature, header->length));
Len Brown4be44fc2005-08-05 00:44:28 -0400331 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 }
333
334 /* Copy the entire table (including header) to the local buffer */
335
Len Brown4be44fc2005-08-05 00:44:28 -0400336 ACPI_MEMCPY(full_table, address->pointer.logical,
337 header->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 /* Save allocation type */
340
341 allocation = ACPI_MEM_ALLOCATED;
342 break;
343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 case ACPI_LOGMODE_PHYSPTR:
345
346 /*
347 * Just map the table's physical memory
348 * into our address space.
349 */
Len Brown4be44fc2005-08-05 00:44:28 -0400350 status = acpi_os_map_memory(address->pointer.physical,
351 (acpi_size) header->length,
352 (void *)&full_table);
353 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500354 ACPI_ERROR((AE_INFO,
355 "Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X",
356 header->signature,
357 ACPI_FORMAT_UINT64(address->pointer.
358 physical),
359 header->length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 return (status);
361 }
362
363 /* Save allocation type */
364
365 allocation = ACPI_MEM_MAPPED;
366 break;
367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 default:
369
Bob Mooreb8e4d892006-01-27 16:43:00 -0500370 ACPI_ERROR((AE_INFO, "Invalid address flags %X",
371 address->pointer_type));
Len Brown4be44fc2005-08-05 00:44:28 -0400372 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 }
374
375 /*
376 * Validate checksum for _most_ tables,
377 * even the ones whose signature we don't recognize
378 */
379 if (table_info->type != ACPI_TABLE_FACS) {
Len Brown4be44fc2005-08-05 00:44:28 -0400380 status = acpi_tb_verify_table_checksum(full_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
382#if (!ACPI_CHECKSUM_ABORT)
Len Brown4be44fc2005-08-05 00:44:28 -0400383 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 /* Ignore the error if configuration says so */
385
386 status = AE_OK;
387 }
388#endif
389 }
390
391 /* Return values */
392
Len Brown4be44fc2005-08-05 00:44:28 -0400393 table_info->pointer = full_table;
394 table_info->length = (acpi_size) header->length;
395 table_info->allocation = allocation;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Len Brown4be44fc2005-08-05 00:44:28 -0400397 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
398 "Found table [%4.4s] at %8.8X%8.8X, mapped/copied to %p\n",
399 full_table->signature,
400 ACPI_FORMAT_UINT64(address->pointer.physical),
401 full_table));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Len Brown4be44fc2005-08-05 00:44:28 -0400403 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404}
405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406/*******************************************************************************
407 *
408 * FUNCTION: acpi_tb_get_table_ptr
409 *
410 * PARAMETERS: table_type - one of the defined table types
411 * Instance - Which table of this type
412 * table_ptr_loc - pointer to location to place the pointer for
413 * return
414 *
415 * RETURN: Status
416 *
417 * DESCRIPTION: This function is called to get the pointer to an ACPI table.
418 *
419 ******************************************************************************/
420
421acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400422acpi_tb_get_table_ptr(acpi_table_type table_type,
423 u32 instance, struct acpi_table_header **table_ptr_loc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
Len Brown4be44fc2005-08-05 00:44:28 -0400425 struct acpi_table_desc *table_desc;
426 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Len Brown4be44fc2005-08-05 00:44:28 -0400428 ACPI_FUNCTION_TRACE("tb_get_table_ptr");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430 if (!acpi_gbl_DSDT) {
Len Brown4be44fc2005-08-05 00:44:28 -0400431 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 }
433
434 if (table_type > ACPI_TABLE_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400435 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 }
437
438 /*
439 * For all table types (Single/Multiple), the first
440 * instance is always in the list head.
441 */
442 if (instance == 1) {
443 /* Get the first */
444
445 *table_ptr_loc = NULL;
446 if (acpi_gbl_table_lists[table_type].next) {
Len Brown4be44fc2005-08-05 00:44:28 -0400447 *table_ptr_loc =
448 acpi_gbl_table_lists[table_type].next->pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 }
Len Brown4be44fc2005-08-05 00:44:28 -0400450 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 }
452
Robert Moore44f6c012005-04-18 22:49:35 -0400453 /* Check for instance out of range */
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 if (instance > acpi_gbl_table_lists[table_type].count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400456 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 }
458
459 /* Walk the list to get the desired table
460 * Since the if (Instance == 1) check above checked for the
461 * first table, setting table_desc equal to the .Next member
462 * is actually pointing to the second table. Therefore, we
463 * need to walk from the 2nd table until we reach the Instance
464 * that the user is looking for and return its table pointer.
465 */
466 table_desc = acpi_gbl_table_lists[table_type].next;
467 for (i = 2; i < instance; i++) {
468 table_desc = table_desc->next;
469 }
470
471 /* We are now pointing to the requested table's descriptor */
472
473 *table_ptr_loc = table_desc->pointer;
474
Len Brown4be44fc2005-08-05 00:44:28 -0400475 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476}