ACPICA 20050526 from Bob Moore <robert.moore@intel.com>
[deliverable/linux.git] / drivers / acpi / tables / tbxfroot.c
1 /******************************************************************************
2 *
3 * Module Name: tbxfroot - Find the root ACPI table (RSDT)
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * 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
44 #include <linux/module.h>
45
46 #include <acpi/acpi.h>
47 #include <acpi/actables.h>
48
49
50 #define _COMPONENT ACPI_TABLES
51 ACPI_MODULE_NAME ("tbxfroot")
52
53 /* Local prototypes */
54
55 static acpi_status
56 acpi_tb_find_rsdp (
57 struct acpi_table_desc *table_info,
58 u32 flags);
59
60 static u8 *
61 acpi_tb_scan_memory_for_rsdp (
62 u8 *start_address,
63 u32 length);
64
65
66 /*******************************************************************************
67 *
68 * FUNCTION: acpi_tb_find_table
69 *
70 * PARAMETERS: Signature - String with ACPI table signature
71 * oem_id - String with the table OEM ID
72 * oem_table_id - String with the OEM Table ID
73 * table_ptr - Where the table pointer is returned
74 *
75 * RETURN: Status
76 *
77 * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
78 * Signature, OEM ID and OEM Table ID.
79 *
80 ******************************************************************************/
81
82 acpi_status
83 acpi_tb_find_table (
84 char *signature,
85 char *oem_id,
86 char *oem_table_id,
87 struct acpi_table_header **table_ptr)
88 {
89 acpi_status status;
90 struct acpi_table_header *table;
91
92
93 ACPI_FUNCTION_TRACE ("tb_find_table");
94
95
96 /* Validate string lengths */
97
98 if ((ACPI_STRLEN (signature) > ACPI_NAME_SIZE) ||
99 (ACPI_STRLEN (oem_id) > sizeof (table->oem_id)) ||
100 (ACPI_STRLEN (oem_table_id) > sizeof (table->oem_table_id))) {
101 return_ACPI_STATUS (AE_AML_STRING_LIMIT);
102 }
103
104 if (!ACPI_STRNCMP (signature, DSDT_SIG, ACPI_NAME_SIZE)) {
105 /*
106 * The DSDT pointer is contained in the FADT, not the RSDT.
107 * This code should suffice, because the only code that would perform
108 * a "find" on the DSDT is the data_table_region() AML opcode -- in
109 * which case, the DSDT is guaranteed to be already loaded.
110 * If this becomes insufficient, the FADT will have to be found first.
111 */
112 if (!acpi_gbl_DSDT) {
113 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
114 }
115 table = acpi_gbl_DSDT;
116 }
117 else {
118 /* Find the table */
119
120 status = acpi_get_firmware_table (signature, 1,
121 ACPI_LOGICAL_ADDRESSING, &table);
122 if (ACPI_FAILURE (status)) {
123 return_ACPI_STATUS (status);
124 }
125 }
126
127 /* Check oem_id and oem_table_id */
128
129 if ((oem_id[0] && ACPI_STRNCMP (
130 oem_id, table->oem_id,
131 sizeof (table->oem_id))) ||
132
133 (oem_table_id[0] && ACPI_STRNCMP (
134 oem_table_id, table->oem_table_id,
135 sizeof (table->oem_table_id)))) {
136 return_ACPI_STATUS (AE_AML_NAME_NOT_FOUND);
137 }
138
139 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "Found table [%4.4s]\n",
140 table->signature));
141
142 *table_ptr = table;
143 return_ACPI_STATUS (AE_OK);
144 }
145
146
147 /*******************************************************************************
148 *
149 * FUNCTION: acpi_get_firmware_table
150 *
151 * PARAMETERS: Signature - Any ACPI table signature
152 * Instance - the non zero instance of the table, allows
153 * support for multiple tables of the same type
154 * Flags - Physical/Virtual support
155 * table_pointer - Where a buffer containing the table is
156 * returned
157 *
158 * RETURN: Status
159 *
160 * DESCRIPTION: This function is called to get an ACPI table. A buffer is
161 * allocated for the table and returned in table_pointer.
162 * This table will be a complete table including the header.
163 *
164 ******************************************************************************/
165
166 acpi_status
167 acpi_get_firmware_table (
168 acpi_string signature,
169 u32 instance,
170 u32 flags,
171 struct acpi_table_header **table_pointer)
172 {
173 acpi_status status;
174 struct acpi_pointer address;
175 struct acpi_table_header *header = NULL;
176 struct acpi_table_desc *table_info = NULL;
177 struct acpi_table_desc *rsdt_info;
178 u32 table_count;
179 u32 i;
180 u32 j;
181
182
183 ACPI_FUNCTION_TRACE ("acpi_get_firmware_table");
184
185
186 /*
187 * Ensure that at least the table manager is initialized. We don't
188 * require that the entire ACPI subsystem is up for this interface.
189 * If we have a buffer, we must have a length too
190 */
191 if ((instance == 0) ||
192 (!signature) ||
193 (!table_pointer)) {
194 return_ACPI_STATUS (AE_BAD_PARAMETER);
195 }
196
197 /* Ensure that we have a RSDP */
198
199 if (!acpi_gbl_RSDP) {
200 /* Get the RSDP */
201
202 status = acpi_os_get_root_pointer (flags, &address);
203 if (ACPI_FAILURE (status)) {
204 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "RSDP not found\n"));
205 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
206 }
207
208 /* Map and validate the RSDP */
209
210 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
211 status = acpi_os_map_memory (address.pointer.physical,
212 sizeof (struct rsdp_descriptor), (void *) &acpi_gbl_RSDP);
213 if (ACPI_FAILURE (status)) {
214 return_ACPI_STATUS (status);
215 }
216 }
217 else {
218 acpi_gbl_RSDP = address.pointer.logical;
219 }
220
221 /* The signature and checksum must both be correct */
222
223 if (ACPI_STRNCMP ((char *) acpi_gbl_RSDP, RSDP_SIG,
224 sizeof (RSDP_SIG)-1) != 0) {
225 /* Nope, BAD Signature */
226
227 return_ACPI_STATUS (AE_BAD_SIGNATURE);
228 }
229
230 if (acpi_tb_checksum (acpi_gbl_RSDP, ACPI_RSDP_CHECKSUM_LENGTH) != 0) {
231 /* Nope, BAD Checksum */
232
233 return_ACPI_STATUS (AE_BAD_CHECKSUM);
234 }
235 }
236
237 /* Get the RSDT address via the RSDP */
238
239 acpi_tb_get_rsdt_address (&address);
240 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
241 "RSDP located at %p, RSDT physical=%8.8X%8.8X \n",
242 acpi_gbl_RSDP,
243 ACPI_FORMAT_UINT64 (address.pointer.value)));
244
245 /* Insert processor_mode flags */
246
247 address.pointer_type |= flags;
248
249 /* Get and validate the RSDT */
250
251 rsdt_info = ACPI_MEM_CALLOCATE (sizeof (struct acpi_table_desc));
252 if (!rsdt_info) {
253 return_ACPI_STATUS (AE_NO_MEMORY);
254 }
255
256 status = acpi_tb_get_table (&address, rsdt_info);
257 if (ACPI_FAILURE (status)) {
258 goto cleanup;
259 }
260
261 status = acpi_tb_validate_rsdt (rsdt_info->pointer);
262 if (ACPI_FAILURE (status)) {
263 goto cleanup;
264 }
265
266 /* Allocate a scratch table header and table descriptor */
267
268 header = ACPI_MEM_ALLOCATE (sizeof (struct acpi_table_header));
269 if (!header) {
270 status = AE_NO_MEMORY;
271 goto cleanup;
272 }
273
274 table_info = ACPI_MEM_ALLOCATE (sizeof (struct acpi_table_desc));
275 if (!table_info) {
276 status = AE_NO_MEMORY;
277 goto cleanup;
278 }
279
280 /* Get the number of table pointers within the RSDT */
281
282 table_count = acpi_tb_get_table_count (acpi_gbl_RSDP, rsdt_info->pointer);
283 address.pointer_type = acpi_gbl_table_flags | flags;
284
285 /*
286 * Search the RSDT/XSDT for the correct instance of the
287 * requested table
288 */
289 for (i = 0, j = 0; i < table_count; i++) {
290 /* Get the next table pointer, handle RSDT vs. XSDT */
291
292 if (acpi_gbl_RSDP->revision < 2) {
293 address.pointer.value = (ACPI_CAST_PTR (
294 RSDT_DESCRIPTOR, rsdt_info->pointer))->table_offset_entry[i];
295 }
296 else {
297 address.pointer.value = (ACPI_CAST_PTR (
298 XSDT_DESCRIPTOR, rsdt_info->pointer))->table_offset_entry[i];
299 }
300
301 /* Get the table header */
302
303 status = acpi_tb_get_table_header (&address, header);
304 if (ACPI_FAILURE (status)) {
305 goto cleanup;
306 }
307
308 /* Compare table signatures and table instance */
309
310 if (!ACPI_STRNCMP (header->signature, signature, ACPI_NAME_SIZE)) {
311 /* An instance of the table was found */
312
313 j++;
314 if (j >= instance) {
315 /* Found the correct instance, get the entire table */
316
317 status = acpi_tb_get_table_body (&address, header, table_info);
318 if (ACPI_FAILURE (status)) {
319 goto cleanup;
320 }
321
322 *table_pointer = table_info->pointer;
323 goto cleanup;
324 }
325 }
326 }
327
328 /* Did not find the table */
329
330 status = AE_NOT_EXIST;
331
332
333 cleanup:
334 if (rsdt_info->pointer) {
335 acpi_os_unmap_memory (rsdt_info->pointer,
336 (acpi_size) rsdt_info->pointer->length);
337 }
338 ACPI_MEM_FREE (rsdt_info);
339
340 if (header) {
341 ACPI_MEM_FREE (header);
342 }
343 if (table_info) {
344 ACPI_MEM_FREE (table_info);
345 }
346 return_ACPI_STATUS (status);
347 }
348 EXPORT_SYMBOL(acpi_get_firmware_table);
349
350
351 /* TBD: Move to a new file */
352
353 #if ACPI_MACHINE_WIDTH != 16
354
355 /*******************************************************************************
356 *
357 * FUNCTION: acpi_find_root_pointer
358 *
359 * PARAMETERS: Flags - Logical/Physical addressing
360 * rsdp_address - Where to place the RSDP address
361 *
362 * RETURN: Status, Physical address of the RSDP
363 *
364 * DESCRIPTION: Find the RSDP
365 *
366 ******************************************************************************/
367
368 acpi_status
369 acpi_find_root_pointer (
370 u32 flags,
371 struct acpi_pointer *rsdp_address)
372 {
373 struct acpi_table_desc table_info;
374 acpi_status status;
375
376
377 ACPI_FUNCTION_TRACE ("acpi_find_root_pointer");
378
379
380 /* Get the RSDP */
381
382 status = acpi_tb_find_rsdp (&table_info, flags);
383 if (ACPI_FAILURE (status)) {
384 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
385 "RSDP structure not found, %s Flags=%X\n",
386 acpi_format_exception (status), flags));
387
388 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
389 }
390
391 rsdp_address->pointer_type = ACPI_PHYSICAL_POINTER;
392 rsdp_address->pointer.physical = table_info.physical_address;
393 return_ACPI_STATUS (AE_OK);
394 }
395
396
397 /*******************************************************************************
398 *
399 * FUNCTION: acpi_tb_scan_memory_for_rsdp
400 *
401 * PARAMETERS: start_address - Starting pointer for search
402 * Length - Maximum length to search
403 *
404 * RETURN: Pointer to the RSDP if found, otherwise NULL.
405 *
406 * DESCRIPTION: Search a block of memory for the RSDP signature
407 *
408 ******************************************************************************/
409
410 static u8 *
411 acpi_tb_scan_memory_for_rsdp (
412 u8 *start_address,
413 u32 length)
414 {
415 u8 *mem_rover;
416 u8 *end_address;
417 u8 checksum;
418
419
420 ACPI_FUNCTION_TRACE ("tb_scan_memory_for_rsdp");
421
422
423 end_address = start_address + length;
424
425 /* Search from given start address for the requested length */
426
427 for (mem_rover = start_address; mem_rover < end_address;
428 mem_rover += ACPI_RSDP_SCAN_STEP) {
429 /* The signature and checksum must both be correct */
430
431 if (ACPI_STRNCMP ((char *) mem_rover,
432 RSDP_SIG, sizeof (RSDP_SIG) - 1) != 0) {
433 /* No signature match, keep looking */
434
435 continue;
436 }
437
438 /* Signature matches, check the appropriate checksum */
439
440 if ((ACPI_CAST_PTR (struct rsdp_descriptor, mem_rover))->revision < 2) {
441 /* ACPI version 1.0 */
442
443 checksum = acpi_tb_checksum (mem_rover, ACPI_RSDP_CHECKSUM_LENGTH);
444 }
445 else {
446 /* Post ACPI 1.0, use extended_checksum */
447
448 checksum = acpi_tb_checksum (mem_rover, ACPI_RSDP_XCHECKSUM_LENGTH);
449 }
450
451 if (checksum == 0) {
452 /* Checksum valid, we have found a valid RSDP */
453
454 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
455 "RSDP located at physical address %p\n", mem_rover));
456 return_PTR (mem_rover);
457 }
458
459 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
460 "Found an RSDP at physical address %p, but it has a bad checksum\n",
461 mem_rover));
462 }
463
464 /* Searched entire block, no RSDP was found */
465
466 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
467 "Searched entire block, no valid RSDP was found.\n"));
468 return_PTR (NULL);
469 }
470
471
472 /*******************************************************************************
473 *
474 * FUNCTION: acpi_tb_find_rsdp
475 *
476 * PARAMETERS: table_info - Where the table info is returned
477 * Flags - Current memory mode (logical vs.
478 * physical addressing)
479 *
480 * RETURN: Status, RSDP physical address
481 *
482 * DESCRIPTION: search lower 1_mbyte of memory for the root system descriptor
483 * pointer structure. If it is found, set *RSDP to point to it.
484 *
485 * NOTE1: The RSDp must be either in the first 1_k of the Extended
486 * BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
487 * Only a 32-bit physical address is necessary.
488 *
489 * NOTE2: This function is always available, regardless of the
490 * initialization state of the rest of ACPI.
491 *
492 ******************************************************************************/
493
494 static acpi_status
495 acpi_tb_find_rsdp (
496 struct acpi_table_desc *table_info,
497 u32 flags)
498 {
499 u8 *table_ptr;
500 u8 *mem_rover;
501 u32 physical_address;
502 acpi_status status;
503
504
505 ACPI_FUNCTION_TRACE ("tb_find_rsdp");
506
507
508 /*
509 * Scan supports either logical addressing or physical addressing
510 */
511 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
512 /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
513
514 status = acpi_os_map_memory (
515 (acpi_physical_address) ACPI_EBDA_PTR_LOCATION,
516 ACPI_EBDA_PTR_LENGTH, (void *) &table_ptr);
517 if (ACPI_FAILURE (status)) {
518 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
519 "Could not map memory at %8.8X for length %X\n",
520 ACPI_EBDA_PTR_LOCATION, ACPI_EBDA_PTR_LENGTH));
521
522 return_ACPI_STATUS (status);
523 }
524
525 ACPI_MOVE_16_TO_32 (&physical_address, table_ptr);
526
527 /* Convert segment part to physical address */
528
529 physical_address <<= 4;
530 acpi_os_unmap_memory (table_ptr, ACPI_EBDA_PTR_LENGTH);
531
532 /* EBDA present? */
533
534 if (physical_address > 0x400) {
535 /*
536 * 1b) Search EBDA paragraphs (EBDa is required to be a
537 * minimum of 1_k length)
538 */
539 status = acpi_os_map_memory (
540 (acpi_physical_address) physical_address,
541 ACPI_EBDA_WINDOW_SIZE, (void *) &table_ptr);
542 if (ACPI_FAILURE (status)) {
543 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
544 "Could not map memory at %8.8X for length %X\n",
545 physical_address, ACPI_EBDA_WINDOW_SIZE));
546
547 return_ACPI_STATUS (status);
548 }
549
550 mem_rover = acpi_tb_scan_memory_for_rsdp (table_ptr,
551 ACPI_EBDA_WINDOW_SIZE);
552 acpi_os_unmap_memory (table_ptr, ACPI_EBDA_WINDOW_SIZE);
553
554 if (mem_rover) {
555 /* Found it, return the physical address */
556
557 physical_address += ACPI_PTR_DIFF (mem_rover, table_ptr);
558
559 table_info->physical_address =
560 (acpi_physical_address) physical_address;
561 return_ACPI_STATUS (AE_OK);
562 }
563 }
564
565 /*
566 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
567 */
568 status = acpi_os_map_memory (
569 (acpi_physical_address) ACPI_HI_RSDP_WINDOW_BASE,
570 ACPI_HI_RSDP_WINDOW_SIZE, (void *) &table_ptr);
571
572 if (ACPI_FAILURE (status)) {
573 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
574 "Could not map memory at %8.8X for length %X\n",
575 ACPI_HI_RSDP_WINDOW_BASE, ACPI_HI_RSDP_WINDOW_SIZE));
576
577 return_ACPI_STATUS (status);
578 }
579
580 mem_rover = acpi_tb_scan_memory_for_rsdp (table_ptr, ACPI_HI_RSDP_WINDOW_SIZE);
581 acpi_os_unmap_memory (table_ptr, ACPI_HI_RSDP_WINDOW_SIZE);
582
583 if (mem_rover) {
584 /* Found it, return the physical address */
585
586 physical_address =
587 ACPI_HI_RSDP_WINDOW_BASE + ACPI_PTR_DIFF (mem_rover, table_ptr);
588
589 table_info->physical_address =
590 (acpi_physical_address) physical_address;
591 return_ACPI_STATUS (AE_OK);
592 }
593 }
594
595 /*
596 * Physical addressing
597 */
598 else {
599 /* 1a) Get the location of the EBDA */
600
601 ACPI_MOVE_16_TO_32 (&physical_address, ACPI_EBDA_PTR_LOCATION);
602 physical_address <<= 4; /* Convert segment to physical address */
603
604 /* EBDA present? */
605
606 if (physical_address > 0x400) {
607 /*
608 * 1b) Search EBDA paragraphs (EBDa is required to be a minimum of
609 * 1_k length)
610 */
611 mem_rover = acpi_tb_scan_memory_for_rsdp (
612 ACPI_PHYSADDR_TO_PTR (physical_address),
613 ACPI_EBDA_WINDOW_SIZE);
614 if (mem_rover) {
615 /* Found it, return the physical address */
616
617 table_info->physical_address = ACPI_TO_INTEGER (mem_rover);
618 return_ACPI_STATUS (AE_OK);
619 }
620 }
621
622 /* 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh */
623
624 mem_rover = acpi_tb_scan_memory_for_rsdp (
625 ACPI_PHYSADDR_TO_PTR (ACPI_HI_RSDP_WINDOW_BASE),
626 ACPI_HI_RSDP_WINDOW_SIZE);
627 if (mem_rover) {
628 /* Found it, return the physical address */
629
630 table_info->physical_address = ACPI_TO_INTEGER (mem_rover);
631 return_ACPI_STATUS (AE_OK);
632 }
633 }
634
635 /* RSDP signature was not found */
636
637 return_ACPI_STATUS (AE_NOT_FOUND);
638 }
639
640 #endif
641
This page took 0.051594 seconds and 6 git commands to generate.