ACPICA: Re-implement interpreters' "serialized mode"
[sfrench/cifs-2.6.git] / drivers / acpi / tables / tbutils.c
1 /******************************************************************************
2  *
3  * Module Name: tbutils   - table utilities
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2006, 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 <acpi/acpi.h>
45 #include <acpi/actables.h>
46
47 #define _COMPONENT          ACPI_TABLES
48 ACPI_MODULE_NAME("tbutils")
49
50 /* Local prototypes */
51 static void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags);
52
53 static void acpi_tb_convert_fadt(void);
54
55 static void
56 acpi_tb_install_table(acpi_physical_address address,
57                       u8 flags, char *signature, acpi_native_uint table_index);
58
59 static void inline
60 acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct,
61                              u8 bit_width, u64 address);
62
63 static acpi_physical_address
64 acpi_tb_get_root_table_entry(u8 * table_entry,
65                              acpi_native_uint table_entry_size);
66
67 /* Table used for conversion of FADT to common format */
68
69 typedef struct acpi_fadt_conversion {
70         u8 target;
71         u8 source;
72         u8 length;
73
74 } acpi_fadt_conversion;
75
76 static struct acpi_fadt_conversion fadt_conversion_table[] = {
77         {ACPI_FADT_OFFSET(xpm1a_event_block),
78          ACPI_FADT_OFFSET(pm1a_event_block),
79          ACPI_FADT_OFFSET(pm1_event_length)},
80         {ACPI_FADT_OFFSET(xpm1b_event_block),
81          ACPI_FADT_OFFSET(pm1b_event_block),
82          ACPI_FADT_OFFSET(pm1_event_length)},
83         {ACPI_FADT_OFFSET(xpm1a_control_block),
84          ACPI_FADT_OFFSET(pm1a_control_block),
85          ACPI_FADT_OFFSET(pm1_control_length)},
86         {ACPI_FADT_OFFSET(xpm1b_control_block),
87          ACPI_FADT_OFFSET(pm1b_control_block),
88          ACPI_FADT_OFFSET(pm1_control_length)},
89         {ACPI_FADT_OFFSET(xpm2_control_block),
90          ACPI_FADT_OFFSET(pm2_control_block),
91          ACPI_FADT_OFFSET(pm2_control_length)},
92         {ACPI_FADT_OFFSET(xpm_timer_block), ACPI_FADT_OFFSET(pm_timer_block),
93          ACPI_FADT_OFFSET(pm_timer_length)},
94         {ACPI_FADT_OFFSET(xgpe0_block), ACPI_FADT_OFFSET(gpe0_block),
95          ACPI_FADT_OFFSET(gpe0_block_length)},
96         {ACPI_FADT_OFFSET(xgpe1_block), ACPI_FADT_OFFSET(gpe1_block),
97          ACPI_FADT_OFFSET(gpe1_block_length)}
98 };
99
100 #define ACPI_FADT_CONVERSION_ENTRIES        (sizeof (fadt_conversion_table) / sizeof (struct acpi_fadt_conversion))
101
102 /*******************************************************************************
103  *
104  * FUNCTION:    acpi_tb_print_table_header
105  *
106  * PARAMETERS:  Address             - Table physical address
107  *              Header              - Table header
108  *
109  * RETURN:      None
110  *
111  * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
112  *
113  ******************************************************************************/
114
115 void
116 acpi_tb_print_table_header(acpi_physical_address address,
117                            struct acpi_table_header *header)
118 {
119
120         if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) {
121
122                 /* FACS only has signature and length fields of common table header */
123
124                 ACPI_INFO((AE_INFO, "%4.4s @ 0x%p/0x%04X",
125                            header->signature, ACPI_CAST_PTR(void, address),
126                            header->length));
127         } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) {
128
129                 /* RSDP has no common fields */
130
131                 ACPI_INFO((AE_INFO, "RSDP @ 0x%p/0x%04X (v%3.3d %6.6s)",
132                            ACPI_CAST_PTR(void, address),
133                            (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
134                             revision >
135                             0) ? ACPI_CAST_PTR(struct acpi_table_rsdp,
136                                                header)->length : 20,
137                            ACPI_CAST_PTR(struct acpi_table_rsdp,
138                                          header)->revision,
139                            ACPI_CAST_PTR(struct acpi_table_rsdp,
140                                          header)->oem_id));
141         } else {
142                 /* Standard ACPI table with full common header */
143
144                 ACPI_INFO((AE_INFO,
145                            "%4.4s @ 0x%p/0x%04X (v%3.3d %6.6s %8.8s 0x%08X %4.4s 0x%08X)",
146                            header->signature, ACPI_CAST_PTR(void, address),
147                            header->length, header->revision, header->oem_id,
148                            header->oem_table_id, header->oem_revision,
149                            header->asl_compiler_id,
150                            header->asl_compiler_revision));
151         }
152 }
153
154 /*******************************************************************************
155  *
156  * FUNCTION:    acpi_tb_init_generic_address
157  *
158  * PARAMETERS:  new_gas_struct      - GAS struct to be initialized
159  *              bit_width           - Width of this register
160  *              Address             - Address of the register
161  *
162  * RETURN:      None
163  *
164  * DESCRIPTION: Initialize a GAS structure.
165  *
166  ******************************************************************************/
167
168 static void inline
169 acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct,
170                              u8 bit_width, u64 address)
171 {
172
173         ACPI_MOVE_64_TO_64(&new_gas_struct->address, &address);
174         new_gas_struct->space_id = ACPI_ADR_SPACE_SYSTEM_IO;
175         new_gas_struct->bit_width = bit_width;
176         new_gas_struct->bit_offset = 0;
177         new_gas_struct->access_width = 0;
178 }
179
180 /*******************************************************************************
181  *
182  * FUNCTION:    acpi_tb_validate_checksum
183  *
184  * PARAMETERS:  Table               - ACPI table to verify
185  *              Length              - Length of entire table
186  *
187  * RETURN:      Status
188  *
189  * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
190  *              exception on bad checksum.
191  *
192  ******************************************************************************/
193
194 acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
195 {
196         u8 checksum;
197
198         /* Compute the checksum on the table */
199
200         checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length);
201
202         /* Checksum ok? (should be zero) */
203
204         if (checksum) {
205                 ACPI_WARNING((AE_INFO,
206                               "Incorrect checksum in table [%4.4s] -  %2.2X, should be %2.2X",
207                               table->signature, table->checksum,
208                               (u8) (table->checksum - checksum)));
209
210 #if (ACPI_CHECKSUM_ABORT)
211
212                 return (AE_BAD_CHECKSUM);
213 #endif
214         }
215
216         return (AE_OK);
217 }
218
219 /*******************************************************************************
220  *
221  * FUNCTION:    acpi_tb_checksum
222  *
223  * PARAMETERS:  Buffer          - Pointer to memory region to be checked
224  *              Length          - Length of this memory region
225  *
226  * RETURN:      Checksum (u8)
227  *
228  * DESCRIPTION: Calculates circular checksum of memory region.
229  *
230  ******************************************************************************/
231
232 u8 acpi_tb_checksum(u8 * buffer, acpi_native_uint length)
233 {
234         u8 sum = 0;
235         u8 *end = buffer + length;
236
237         while (buffer < end) {
238                 sum = (u8) (sum + *(buffer++));
239         }
240
241         return sum;
242 }
243
244 /*******************************************************************************
245  *
246  * FUNCTION:    acpi_tb_convert_fadt
247  *
248  * PARAMETERS:  None, uses acpi_gbl_FADT
249  *
250  * RETURN:      None
251  *
252  * DESCRIPTION: Converts all versions of the FADT to a common internal format.
253  *
254  * NOTE:        acpi_gbl_FADT must be of size (struct acpi_table_fadt), and must contain
255  *              a copy of the actual FADT.
256  *
257  * ACPICA will use the "X" fields of the FADT for all addresses.
258  *
259  * "X" fields are optional extensions to the original V1.0 fields. Even if
260  * they are present in the structure, they can be optionally not used by
261  * setting them to zero. Therefore, we must selectively expand V1.0 fields
262  * if the corresponding X field is zero.
263  *
264  * For ACPI 1.0 FADTs, all address fields are expanded to the corresponding
265  * "X" fields.
266  *
267  * For ACPI 2.0 FADTs, any "X" fields that are NULL are filled in by
268  * expanding the corresponding ACPI 1.0 field.
269  *
270  ******************************************************************************/
271
272 static void acpi_tb_convert_fadt(void)
273 {
274         u8 pm1_register_length;
275         struct acpi_generic_address *target;
276         acpi_native_uint i;
277
278         /* Expand the FACS and DSDT addresses as necessary */
279
280         if (!acpi_gbl_FADT.Xfacs) {
281                 acpi_gbl_FADT.Xfacs = (u64) acpi_gbl_FADT.facs;
282         }
283
284         if (!acpi_gbl_FADT.Xdsdt) {
285                 acpi_gbl_FADT.Xdsdt = (u64) acpi_gbl_FADT.dsdt;
286         }
287
288         /*
289          * Expand the 32-bit V1.0 addresses to the 64-bit "X" generic address
290          * structures as necessary.
291          */
292         for (i = 0; i < ACPI_FADT_CONVERSION_ENTRIES; i++) {
293                 target =
294                     ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT,
295                                  fadt_conversion_table[i].target);
296
297                 /* Expand only if the X target is null */
298
299                 if (!target->address) {
300                         acpi_tb_init_generic_address(target,
301                                                      *ACPI_ADD_PTR(u8,
302                                                                    &acpi_gbl_FADT,
303                                                                    fadt_conversion_table
304                                                                    [i].length),
305                                                      (u64) * ACPI_ADD_PTR(u32,
306                                                                           &acpi_gbl_FADT,
307                                                                           fadt_conversion_table
308                                                                           [i].
309                                                                           source));
310                 }
311         }
312
313         /*
314          * Calculate separate GAS structs for the PM1 Enable registers.
315          * These addresses do not appear (directly) in the FADT, so it is
316          * useful to calculate them once, here.
317          *
318          * The PM event blocks are split into two register blocks, first is the
319          * PM Status Register block, followed immediately by the PM Enable Register
320          * block. Each is of length (pm1_event_length/2)
321          */
322         pm1_register_length = (u8) ACPI_DIV_2(acpi_gbl_FADT.pm1_event_length);
323
324         /* PM1A is required */
325
326         acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
327                                      pm1_register_length,
328                                      (acpi_gbl_FADT.xpm1a_event_block.address +
329                                       pm1_register_length));
330
331         /* PM1B is optional; leave null if not present */
332
333         if (acpi_gbl_FADT.xpm1b_event_block.address) {
334                 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
335                                              pm1_register_length,
336                                              (acpi_gbl_FADT.xpm1b_event_block.
337                                               address + pm1_register_length));
338         }
339
340         /* Global FADT is the new common V2.0 FADT  */
341
342         acpi_gbl_FADT.header.length = sizeof(struct acpi_table_fadt);
343 }
344
345 /*******************************************************************************
346  *
347  * FUNCTION:    acpi_tb_install_table
348  *
349  * PARAMETERS:  Address                 - Physical address of DSDT or FACS
350  *              Flags                   - Flags
351  *              Signature               - Table signature, NULL if no need to
352  *                                        match
353  *              table_index             - Index into root table array
354  *
355  * RETURN:      None
356  *
357  * DESCRIPTION: Install an ACPI table into the global data structure.
358  *
359  ******************************************************************************/
360
361 static void
362 acpi_tb_install_table(acpi_physical_address address,
363                       u8 flags, char *signature, acpi_native_uint table_index)
364 {
365         struct acpi_table_header *table;
366
367         if (!address) {
368                 ACPI_ERROR((AE_INFO,
369                             "Null physical address for ACPI table [%s]",
370                             signature));
371                 return;
372         }
373
374         /* Map just the table header */
375
376         table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
377         if (!table) {
378                 return;
379         }
380
381         /* If a particular signature is expected, signature must match */
382
383         if (signature && !ACPI_COMPARE_NAME(table->signature, signature)) {
384                 ACPI_ERROR((AE_INFO,
385                             "Invalid signature 0x%X for ACPI table [%s]",
386                             *ACPI_CAST_PTR(u32, table->signature), signature));
387                 goto unmap_and_exit;
388         }
389
390         /* Initialize the table entry */
391
392         acpi_gbl_root_table_list.tables[table_index].address = address;
393         acpi_gbl_root_table_list.tables[table_index].length = table->length;
394         acpi_gbl_root_table_list.tables[table_index].flags = flags;
395
396         ACPI_MOVE_32_TO_32(&
397                            (acpi_gbl_root_table_list.tables[table_index].
398                             signature), table->signature);
399
400         acpi_tb_print_table_header(address, table);
401
402         if (table_index == ACPI_TABLE_INDEX_DSDT) {
403
404                 /* Global integer width is based upon revision of the DSDT */
405
406                 acpi_ut_set_integer_width(table->revision);
407         }
408
409       unmap_and_exit:
410         acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
411 }
412
413 /*******************************************************************************
414  *
415  * FUNCTION:    acpi_tb_parse_fadt
416  *
417  * PARAMETERS:  table_index         - Index for the FADT
418  *              Flags               - Flags
419  *
420  * RETURN:      None
421  *
422  * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
423  *              (FADT contains the addresses of the DSDT and FACS)
424  *
425  ******************************************************************************/
426
427 static void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags)
428 {
429         u32 length;
430         struct acpi_table_header *table;
431
432         /*
433          * Special case for the FADT because of multiple versions and the fact
434          * that it contains pointers to both the DSDT and FACS tables.
435          *
436          * Get a local copy of the FADT and convert it to a common format
437          * Map entire FADT, assumed to be smaller than one page.
438          */
439         length = acpi_gbl_root_table_list.tables[table_index].length;
440
441         table =
442             acpi_os_map_memory(acpi_gbl_root_table_list.tables[table_index].
443                                address, length);
444         if (!table) {
445                 return;
446         }
447
448         /*
449          * Validate the FADT checksum before we copy the table. Ignore
450          * checksum error as we want to try to get the DSDT and FACS.
451          */
452         (void)acpi_tb_verify_checksum(table, length);
453
454         /* Copy the entire FADT locally */
455
456         ACPI_MEMSET(&acpi_gbl_FADT, 0, sizeof(struct acpi_table_fadt));
457
458         ACPI_MEMCPY(&acpi_gbl_FADT, table,
459                     ACPI_MIN(length, sizeof(struct acpi_table_fadt)));
460         acpi_os_unmap_memory(table, length);
461
462         /* Convert local FADT to the common internal format */
463
464         acpi_tb_convert_fadt();
465
466         /* Extract the DSDT and FACS tables from the FADT */
467
468         acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xdsdt,
469                               flags, ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
470
471         acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xfacs,
472                               flags, ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS);
473 }
474
475 /*******************************************************************************
476  *
477  * FUNCTION:    acpi_tb_get_root_table_entry
478  *
479  * PARAMETERS:  table_entry         - Pointer to the RSDT/XSDT table entry
480  *              table_entry_size    - sizeof 32 or 64 (RSDT or XSDT)
481  *
482  * RETURN:      Physical address extracted from the root table
483  *
484  * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
485  *              both 32-bit and 64-bit platforms
486  *
487  * NOTE:        acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
488  *              64-bit platforms.
489  *
490  ******************************************************************************/
491
492 static acpi_physical_address
493 acpi_tb_get_root_table_entry(u8 * table_entry,
494                              acpi_native_uint table_entry_size)
495 {
496         u64 address64;
497
498         /*
499          * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
500          * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
501          */
502         if (table_entry_size == sizeof(u32)) {
503                 /*
504                  * 32-bit platform, RSDT: Return 32-bit table entry
505                  * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
506                  */
507                 return ((acpi_physical_address)
508                         (*ACPI_CAST_PTR(u32, table_entry)));
509         } else {
510                 /*
511                  * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
512                  * 64-bit platform, XSDT: Move (unaligned) 64-bit to local, return 64-bit
513                  */
514                 ACPI_MOVE_64_TO_64(&address64, table_entry);
515
516 #if ACPI_MACHINE_WIDTH == 32
517                 if (address64 > ACPI_UINT32_MAX) {
518
519                         /* Will truncate 64-bit address to 32 bits */
520
521                         ACPI_WARNING((AE_INFO,
522                                       "64-bit Physical Address in XSDT is too large (%8.8X%8.8X), truncating",
523                                       ACPI_FORMAT_UINT64(address64)));
524                 }
525 #endif
526                 return ((acpi_physical_address) (address64));
527         }
528 }
529
530 /*******************************************************************************
531  *
532  * FUNCTION:    acpi_tb_parse_root_table
533  *
534  * PARAMETERS:  Rsdp                    - Pointer to the RSDP
535  *              Flags                   - Flags
536  *
537  * RETURN:      Status
538  *
539  * DESCRIPTION: This function is called to parse the Root System Description
540  *              Table (RSDT or XSDT)
541  *
542  * NOTE:        Tables are mapped (not copied) for efficiency. The FACS must
543  *              be mapped and cannot be copied because it contains the actual
544  *              memory location of the ACPI Global Lock.
545  *
546  ******************************************************************************/
547
548 acpi_status __init
549 acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags)
550 {
551         struct acpi_table_rsdp *rsdp;
552         acpi_native_uint table_entry_size;
553         acpi_native_uint i;
554         u32 table_count;
555         struct acpi_table_header *table;
556         acpi_physical_address address;
557         u32 length;
558         u8 *table_entry;
559         acpi_status status;
560
561         ACPI_FUNCTION_TRACE(tb_parse_root_table);
562
563         /*
564          * Map the entire RSDP and extract the address of the RSDT or XSDT
565          */
566         rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp));
567         if (!rsdp) {
568                 return_ACPI_STATUS(AE_NO_MEMORY);
569         }
570
571         acpi_tb_print_table_header(rsdp_address,
572                                    ACPI_CAST_PTR(struct acpi_table_header,
573                                                  rsdp));
574
575         /* Differentiate between RSDT and XSDT root tables */
576
577         if (rsdp->revision > 1 && rsdp->xsdt_physical_address) {
578                 /*
579                  * Root table is an XSDT (64-bit physical addresses). We must use the
580                  * XSDT if the revision is > 1 and the XSDT pointer is present, as per
581                  * the ACPI specification.
582                  */
583                 address = (acpi_physical_address) rsdp->xsdt_physical_address;
584                 table_entry_size = sizeof(u64);
585         } else {
586                 /* Root table is an RSDT (32-bit physical addresses) */
587
588                 address = (acpi_physical_address) rsdp->rsdt_physical_address;
589                 table_entry_size = sizeof(u32);
590         }
591
592         /*
593          * It is not possible to map more than one entry in some environments,
594          * so unmap the RSDP here before mapping other tables
595          */
596         acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp));
597
598         /* Map the RSDT/XSDT table header to get the full table length */
599
600         table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
601         if (!table) {
602                 return_ACPI_STATUS(AE_NO_MEMORY);
603         }
604
605         acpi_tb_print_table_header(address, table);
606
607         /* Get the length of the full table, verify length and map entire table */
608
609         length = table->length;
610         acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
611
612         if (length < sizeof(struct acpi_table_header)) {
613                 ACPI_ERROR((AE_INFO, "Invalid length 0x%X in RSDT/XSDT",
614                             length));
615                 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
616         }
617
618         table = acpi_os_map_memory(address, length);
619         if (!table) {
620                 return_ACPI_STATUS(AE_NO_MEMORY);
621         }
622
623         /* Validate the root table checksum */
624
625         status = acpi_tb_verify_checksum(table, length);
626         if (ACPI_FAILURE(status)) {
627                 acpi_os_unmap_memory(table, length);
628                 return_ACPI_STATUS(status);
629         }
630
631         /* Calculate the number of tables described in the root table */
632
633         table_count =
634             (u32) ((table->length -
635                     sizeof(struct acpi_table_header)) / table_entry_size);
636
637         /*
638          * First two entries in the table array are reserved for the DSDT and FACS,
639          * which are not actually present in the RSDT/XSDT - they come from the FADT
640          */
641         table_entry =
642             ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header);
643         acpi_gbl_root_table_list.count = 2;
644
645         /*
646          * Initialize the root table array from the RSDT/XSDT
647          */
648         for (i = 0; i < table_count; i++) {
649                 if (acpi_gbl_root_table_list.count >=
650                     acpi_gbl_root_table_list.size) {
651
652                         /* There is no more room in the root table array, attempt resize */
653
654                         status = acpi_tb_resize_root_table_list();
655                         if (ACPI_FAILURE(status)) {
656                                 ACPI_WARNING((AE_INFO,
657                                               "Truncating %u table entries!",
658                                               (unsigned)
659                                               (acpi_gbl_root_table_list.size -
660                                                acpi_gbl_root_table_list.
661                                                count)));
662                                 break;
663                         }
664                 }
665
666                 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
667
668                 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
669                     address =
670                     acpi_tb_get_root_table_entry(table_entry, table_entry_size);
671
672                 table_entry += table_entry_size;
673                 acpi_gbl_root_table_list.count++;
674         }
675
676         /*
677          * It is not possible to map more than one entry in some environments,
678          * so unmap the root table here before mapping other tables
679          */
680         acpi_os_unmap_memory(table, length);
681
682         /*
683          * Complete the initialization of the root table array by examining
684          * the header of each table
685          */
686         for (i = 2; i < acpi_gbl_root_table_list.count; i++) {
687                 acpi_tb_install_table(acpi_gbl_root_table_list.tables[i].
688                                       address, flags, NULL, i);
689
690                 /* Special case for FADT - get the DSDT and FACS */
691
692                 if (ACPI_COMPARE_NAME
693                     (&acpi_gbl_root_table_list.tables[i].signature,
694                      ACPI_SIG_FADT)) {
695                         acpi_tb_parse_fadt(i, flags);
696                 }
697         }
698
699         return_ACPI_STATUS(AE_OK);
700 }
701
702 /******************************************************************************
703  *
704  * FUNCTION:    acpi_tb_map
705  *
706  * PARAMETERS:  Address             - Address to be mapped
707  *              Length              - Length to be mapped
708  *              Flags               - Logical or physical addressing mode
709  *
710  * RETURN:      Pointer to mapped region
711  *
712  * DESCRIPTION: Maps memory according to flag
713  *
714  *****************************************************************************/
715
716 void *acpi_tb_map(acpi_physical_address address, u32 length, u32 flags)
717 {
718
719         if (flags == ACPI_TABLE_ORIGIN_MAPPED) {
720                 return (acpi_os_map_memory(address, length));
721         } else {
722                 return (ACPI_CAST_PTR(void, address));
723         }
724 }
725
726 /******************************************************************************
727  *
728  * FUNCTION:    acpi_tb_unmap
729  *
730  * PARAMETERS:  Pointer             - To mapped region
731  *              Length              - Length to be unmapped
732  *              Flags               - Logical or physical addressing mode
733  *
734  * RETURN:      None
735  *
736  * DESCRIPTION: Unmaps memory according to flag
737  *
738  *****************************************************************************/
739
740 void acpi_tb_unmap(void *pointer, u32 length, u32 flags)
741 {
742
743         if (flags == ACPI_TABLE_ORIGIN_MAPPED) {
744                 acpi_os_unmap_memory(pointer, length);
745         }
746 }