pandora: defconfig: update
[pandora-kernel.git] / drivers / acpi / acpica / tbutils.c
1 /******************************************************************************
2  *
3  * Module Name: tbutils   - table utilities
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2011, Intel Corp.
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 "accommon.h"
46 #include "actables.h"
47
48 #define _COMPONENT          ACPI_TABLES
49 ACPI_MODULE_NAME("tbutils")
50
51 /* Local prototypes */
52 static void acpi_tb_fix_string(char *string, acpi_size length);
53
54 static void
55 acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
56                              struct acpi_table_header *header);
57
58 static acpi_physical_address
59 acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size);
60
61 /*******************************************************************************
62  *
63  * FUNCTION:    acpi_tb_check_xsdt
64  *
65  * PARAMETERS:  address                    - Pointer to the XSDT
66  *
67  * RETURN:      status
68  *              AE_OK - XSDT is okay
69  *              AE_NO_MEMORY - can't map XSDT
70  *              AE_INVALID_TABLE_LENGTH - invalid table length
71  *              AE_NULL_ENTRY - XSDT has NULL entry
72  *
73  * DESCRIPTION: validate XSDT
74 ******************************************************************************/
75
76 static acpi_status
77 acpi_tb_check_xsdt(acpi_physical_address address)
78 {
79         struct acpi_table_header *table;
80         u32 length;
81         u64 xsdt_entry_address;
82         u8 *table_entry;
83         u32 table_count;
84         int i;
85
86         table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
87         if (!table)
88                 return AE_NO_MEMORY;
89
90         length = table->length;
91         acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
92         if (length < sizeof(struct acpi_table_header))
93                 return AE_INVALID_TABLE_LENGTH;
94
95         table = acpi_os_map_memory(address, length);
96         if (!table)
97                 return AE_NO_MEMORY;
98
99         /* Calculate the number of tables described in XSDT */
100         table_count =
101                 (u32) ((table->length -
102                 sizeof(struct acpi_table_header)) / sizeof(u64));
103         table_entry =
104                 ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header);
105         for (i = 0; i < table_count; i++) {
106                 ACPI_MOVE_64_TO_64(&xsdt_entry_address, table_entry);
107                 if (!xsdt_entry_address) {
108                         /* XSDT has NULL entry */
109                         break;
110                 }
111                 table_entry += sizeof(u64);
112         }
113         acpi_os_unmap_memory(table, length);
114
115         if (i < table_count)
116                 return AE_NULL_ENTRY;
117         else
118                 return AE_OK;
119 }
120
121 /*******************************************************************************
122  *
123  * FUNCTION:    acpi_tb_initialize_facs
124  *
125  * PARAMETERS:  None
126  *
127  * RETURN:      Status
128  *
129  * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global
130  *              for accessing the Global Lock and Firmware Waking Vector
131  *
132  ******************************************************************************/
133
134 acpi_status acpi_tb_initialize_facs(void)
135 {
136         acpi_status status;
137
138         status = acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
139                                          ACPI_CAST_INDIRECT_PTR(struct
140                                                                 acpi_table_header,
141                                                                 &acpi_gbl_FACS));
142         return status;
143 }
144
145 /*******************************************************************************
146  *
147  * FUNCTION:    acpi_tb_tables_loaded
148  *
149  * PARAMETERS:  None
150  *
151  * RETURN:      TRUE if required ACPI tables are loaded
152  *
153  * DESCRIPTION: Determine if the minimum required ACPI tables are present
154  *              (FADT, FACS, DSDT)
155  *
156  ******************************************************************************/
157
158 u8 acpi_tb_tables_loaded(void)
159 {
160
161         if (acpi_gbl_root_table_list.current_table_count >= 3) {
162                 return (TRUE);
163         }
164
165         return (FALSE);
166 }
167
168 /*******************************************************************************
169  *
170  * FUNCTION:    acpi_tb_fix_string
171  *
172  * PARAMETERS:  String              - String to be repaired
173  *              Length              - Maximum length
174  *
175  * RETURN:      None
176  *
177  * DESCRIPTION: Replace every non-printable or non-ascii byte in the string
178  *              with a question mark '?'.
179  *
180  ******************************************************************************/
181
182 static void acpi_tb_fix_string(char *string, acpi_size length)
183 {
184
185         while (length && *string) {
186                 if (!ACPI_IS_PRINT(*string)) {
187                         *string = '?';
188                 }
189                 string++;
190                 length--;
191         }
192 }
193
194 /*******************************************************************************
195  *
196  * FUNCTION:    acpi_tb_cleanup_table_header
197  *
198  * PARAMETERS:  out_header          - Where the cleaned header is returned
199  *              Header              - Input ACPI table header
200  *
201  * RETURN:      Returns the cleaned header in out_header
202  *
203  * DESCRIPTION: Copy the table header and ensure that all "string" fields in
204  *              the header consist of printable characters.
205  *
206  ******************************************************************************/
207
208 static void
209 acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
210                              struct acpi_table_header *header)
211 {
212
213         ACPI_MEMCPY(out_header, header, sizeof(struct acpi_table_header));
214
215         acpi_tb_fix_string(out_header->signature, ACPI_NAME_SIZE);
216         acpi_tb_fix_string(out_header->oem_id, ACPI_OEM_ID_SIZE);
217         acpi_tb_fix_string(out_header->oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
218         acpi_tb_fix_string(out_header->asl_compiler_id, ACPI_NAME_SIZE);
219 }
220
221 /*******************************************************************************
222  *
223  * FUNCTION:    acpi_tb_print_table_header
224  *
225  * PARAMETERS:  Address             - Table physical address
226  *              Header              - Table header
227  *
228  * RETURN:      None
229  *
230  * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
231  *
232  ******************************************************************************/
233
234 void
235 acpi_tb_print_table_header(acpi_physical_address address,
236                            struct acpi_table_header *header)
237 {
238         struct acpi_table_header local_header;
239
240         if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) {
241
242                 /* FACS only has signature and length fields */
243
244                 ACPI_INFO((AE_INFO, "%4.4s 0x%8.8X%8.8X %05X",
245                            header->signature, ACPI_FORMAT_UINT64(address),
246                            header->length));
247         } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) {
248
249                 /* RSDP has no common fields */
250
251                 ACPI_MEMCPY(local_header.oem_id,
252                             ACPI_CAST_PTR(struct acpi_table_rsdp,
253                                           header)->oem_id, ACPI_OEM_ID_SIZE);
254                 acpi_tb_fix_string(local_header.oem_id, ACPI_OEM_ID_SIZE);
255
256                 ACPI_INFO((AE_INFO, "RSDP 0x%8.8X%8.8X %05X (v%.2d %6.6s)",
257                            ACPI_FORMAT_UINT64(address),
258                            (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
259                             revision >
260                             0) ? ACPI_CAST_PTR(struct acpi_table_rsdp,
261                                                header)->length : 20,
262                            ACPI_CAST_PTR(struct acpi_table_rsdp,
263                                          header)->revision,
264                            local_header.oem_id));
265         } else {
266                 /* Standard ACPI table with full common header */
267
268                 acpi_tb_cleanup_table_header(&local_header, header);
269
270                 ACPI_INFO((AE_INFO,
271                            "%-4.4s 0x%8.8X%8.8X %05X (v%.2d %-6.6s %-8.8s %08X %-4.4s %08X)",
272                            local_header.signature, ACPI_FORMAT_UINT64(address),
273                            local_header.length, local_header.revision,
274                            local_header.oem_id, local_header.oem_table_id,
275                            local_header.oem_revision,
276                            local_header.asl_compiler_id,
277                            local_header.asl_compiler_revision));
278
279         }
280 }
281
282 /*******************************************************************************
283  *
284  * FUNCTION:    acpi_tb_validate_checksum
285  *
286  * PARAMETERS:  Table               - ACPI table to verify
287  *              Length              - Length of entire table
288  *
289  * RETURN:      Status
290  *
291  * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
292  *              exception on bad checksum.
293  *
294  ******************************************************************************/
295
296 acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
297 {
298         u8 checksum;
299
300         /* Compute the checksum on the table */
301
302         checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length);
303
304         /* Checksum ok? (should be zero) */
305
306         if (checksum) {
307                 ACPI_WARNING((AE_INFO,
308                               "Incorrect checksum in table [%4.4s] - 0x%2.2X, should be 0x%2.2X",
309                               table->signature, table->checksum,
310                               (u8) (table->checksum - checksum)));
311
312 #if (ACPI_CHECKSUM_ABORT)
313
314                 return (AE_BAD_CHECKSUM);
315 #endif
316         }
317
318         return (AE_OK);
319 }
320
321 /*******************************************************************************
322  *
323  * FUNCTION:    acpi_tb_checksum
324  *
325  * PARAMETERS:  Buffer          - Pointer to memory region to be checked
326  *              Length          - Length of this memory region
327  *
328  * RETURN:      Checksum (u8)
329  *
330  * DESCRIPTION: Calculates circular checksum of memory region.
331  *
332  ******************************************************************************/
333
334 u8 acpi_tb_checksum(u8 *buffer, u32 length)
335 {
336         u8 sum = 0;
337         u8 *end = buffer + length;
338
339         while (buffer < end) {
340                 sum = (u8) (sum + *(buffer++));
341         }
342
343         return sum;
344 }
345
346 /*******************************************************************************
347  *
348  * FUNCTION:    acpi_tb_check_dsdt_header
349  *
350  * PARAMETERS:  None
351  *
352  * RETURN:      None
353  *
354  * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect
355  *              if the DSDT has been replaced from outside the OS and/or if
356  *              the DSDT header has been corrupted.
357  *
358  ******************************************************************************/
359
360 void acpi_tb_check_dsdt_header(void)
361 {
362
363         /* Compare original length and checksum to current values */
364
365         if (acpi_gbl_original_dsdt_header.length != acpi_gbl_DSDT->length ||
366             acpi_gbl_original_dsdt_header.checksum != acpi_gbl_DSDT->checksum) {
367                 ACPI_ERROR((AE_INFO,
368                             "The DSDT has been corrupted or replaced - old, new headers below"));
369                 acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header);
370                 acpi_tb_print_table_header(0, acpi_gbl_DSDT);
371
372                 ACPI_ERROR((AE_INFO,
373                             "Please send DMI info to linux-acpi@vger.kernel.org\n"
374                             "If system does not work as expected, please boot with acpi=copy_dsdt"));
375
376                 /* Disable further error messages */
377
378                 acpi_gbl_original_dsdt_header.length = acpi_gbl_DSDT->length;
379                 acpi_gbl_original_dsdt_header.checksum =
380                     acpi_gbl_DSDT->checksum;
381         }
382 }
383
384 /*******************************************************************************
385  *
386  * FUNCTION:    acpi_tb_copy_dsdt
387  *
388  * PARAMETERS:  table_desc          - Installed table to copy
389  *
390  * RETURN:      None
391  *
392  * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory.
393  *              Some very bad BIOSs are known to either corrupt the DSDT or
394  *              install a new, bad DSDT. This copy works around the problem.
395  *
396  ******************************************************************************/
397
398 struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index)
399 {
400         struct acpi_table_header *new_table;
401         struct acpi_table_desc *table_desc;
402
403         table_desc = &acpi_gbl_root_table_list.tables[table_index];
404
405         new_table = ACPI_ALLOCATE(table_desc->length);
406         if (!new_table) {
407                 ACPI_ERROR((AE_INFO, "Could not copy DSDT of length 0x%X",
408                             table_desc->length));
409                 return (NULL);
410         }
411
412         ACPI_MEMCPY(new_table, table_desc->pointer, table_desc->length);
413         acpi_tb_delete_table(table_desc);
414         table_desc->pointer = new_table;
415         table_desc->flags = ACPI_TABLE_ORIGIN_ALLOCATED;
416
417         ACPI_INFO((AE_INFO,
418                    "Forced DSDT copy: length 0x%05X copied locally, original unmapped",
419                    new_table->length));
420
421         return (new_table);
422 }
423
424 /*******************************************************************************
425  *
426  * FUNCTION:    acpi_tb_install_table
427  *
428  * PARAMETERS:  Address                 - Physical address of DSDT or FACS
429  *              Signature               - Table signature, NULL if no need to
430  *                                        match
431  *              table_index             - Index into root table array
432  *
433  * RETURN:      None
434  *
435  * DESCRIPTION: Install an ACPI table into the global data structure. The
436  *              table override mechanism is implemented here to allow the host
437  *              OS to replace any table before it is installed in the root
438  *              table array.
439  *
440  ******************************************************************************/
441
442 void
443 acpi_tb_install_table(acpi_physical_address address,
444                       char *signature, u32 table_index)
445 {
446         u8 flags;
447         acpi_status status;
448         struct acpi_table_header *table_to_install;
449         struct acpi_table_header *mapped_table;
450         struct acpi_table_header *override_table = NULL;
451
452         if (!address) {
453                 ACPI_ERROR((AE_INFO,
454                             "Null physical address for ACPI table [%s]",
455                             signature));
456                 return;
457         }
458
459         /* Map just the table header */
460
461         mapped_table =
462             acpi_os_map_memory(address, sizeof(struct acpi_table_header));
463         if (!mapped_table) {
464                 return;
465         }
466
467         /* If a particular signature is expected (DSDT/FACS), it must match */
468
469         if (signature && !ACPI_COMPARE_NAME(mapped_table->signature, signature)) {
470                 ACPI_ERROR((AE_INFO,
471                             "Invalid signature 0x%X for ACPI table, expected [%s]",
472                             *ACPI_CAST_PTR(u32, mapped_table->signature),
473                             signature));
474                 goto unmap_and_exit;
475         }
476
477         /*
478          * ACPI Table Override:
479          *
480          * Before we install the table, let the host OS override it with a new
481          * one if desired. Any table within the RSDT/XSDT can be replaced,
482          * including the DSDT which is pointed to by the FADT.
483          */
484         status = acpi_os_table_override(mapped_table, &override_table);
485         if (ACPI_SUCCESS(status) && override_table) {
486                 ACPI_INFO((AE_INFO,
487                            "%4.4s @ 0x%8.8X%8.8X Table override, replaced with:",
488                            mapped_table->signature, ACPI_FORMAT_UINT64(address)));
489
490                 acpi_gbl_root_table_list.tables[table_index].pointer =
491                     override_table;
492                 address = ACPI_PTR_TO_PHYSADDR(override_table);
493
494                 table_to_install = override_table;
495                 flags = ACPI_TABLE_ORIGIN_OVERRIDE;
496         } else {
497                 table_to_install = mapped_table;
498                 flags = ACPI_TABLE_ORIGIN_MAPPED;
499         }
500
501         /* Initialize the table entry */
502
503         acpi_gbl_root_table_list.tables[table_index].address = address;
504         acpi_gbl_root_table_list.tables[table_index].length =
505             table_to_install->length;
506         acpi_gbl_root_table_list.tables[table_index].flags = flags;
507
508         ACPI_MOVE_32_TO_32(&
509                            (acpi_gbl_root_table_list.tables[table_index].
510                             signature), table_to_install->signature);
511
512         acpi_tb_print_table_header(address, table_to_install);
513
514         if (table_index == ACPI_TABLE_INDEX_DSDT) {
515
516                 /* Global integer width is based upon revision of the DSDT */
517
518                 acpi_ut_set_integer_width(table_to_install->revision);
519         }
520
521       unmap_and_exit:
522         acpi_os_unmap_memory(mapped_table, sizeof(struct acpi_table_header));
523 }
524
525 /*******************************************************************************
526  *
527  * FUNCTION:    acpi_tb_get_root_table_entry
528  *
529  * PARAMETERS:  table_entry         - Pointer to the RSDT/XSDT table entry
530  *              table_entry_size    - sizeof 32 or 64 (RSDT or XSDT)
531  *
532  * RETURN:      Physical address extracted from the root table
533  *
534  * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
535  *              both 32-bit and 64-bit platforms
536  *
537  * NOTE:        acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
538  *              64-bit platforms.
539  *
540  ******************************************************************************/
541
542 static acpi_physical_address
543 acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
544 {
545         u64 address64;
546
547         /*
548          * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
549          * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
550          */
551         if (table_entry_size == sizeof(u32)) {
552                 /*
553                  * 32-bit platform, RSDT: Return 32-bit table entry
554                  * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
555                  */
556                 return ((acpi_physical_address)
557                         (*ACPI_CAST_PTR(u32, table_entry)));
558         } else {
559                 /*
560                  * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
561                  * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
562                  *  return 64-bit
563                  */
564                 ACPI_MOVE_64_TO_64(&address64, table_entry);
565
566 #if ACPI_MACHINE_WIDTH == 32
567                 if (address64 > ACPI_UINT32_MAX) {
568
569                         /* Will truncate 64-bit address to 32 bits, issue warning */
570
571                         ACPI_WARNING((AE_INFO,
572                                       "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
573                                       " truncating",
574                                       ACPI_FORMAT_UINT64(address64)));
575                 }
576 #endif
577                 return ((acpi_physical_address) (address64));
578         }
579 }
580
581 /*******************************************************************************
582  *
583  * FUNCTION:    acpi_tb_parse_root_table
584  *
585  * PARAMETERS:  Rsdp                    - Pointer to the RSDP
586  *
587  * RETURN:      Status
588  *
589  * DESCRIPTION: This function is called to parse the Root System Description
590  *              Table (RSDT or XSDT)
591  *
592  * NOTE:        Tables are mapped (not copied) for efficiency. The FACS must
593  *              be mapped and cannot be copied because it contains the actual
594  *              memory location of the ACPI Global Lock.
595  *
596  ******************************************************************************/
597
598 acpi_status __init
599 acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
600 {
601         struct acpi_table_rsdp *rsdp;
602         u32 table_entry_size;
603         u32 i;
604         u32 table_count;
605         struct acpi_table_header *table;
606         acpi_physical_address address;
607         acpi_physical_address uninitialized_var(rsdt_address);
608         u32 length;
609         u8 *table_entry;
610         acpi_status status;
611
612         ACPI_FUNCTION_TRACE(tb_parse_root_table);
613
614         /*
615          * Map the entire RSDP and extract the address of the RSDT or XSDT
616          */
617         rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp));
618         if (!rsdp) {
619                 return_ACPI_STATUS(AE_NO_MEMORY);
620         }
621
622         acpi_tb_print_table_header(rsdp_address,
623                                    ACPI_CAST_PTR(struct acpi_table_header,
624                                                  rsdp));
625
626         /* Differentiate between RSDT and XSDT root tables */
627
628         if (rsdp->revision > 1 && rsdp->xsdt_physical_address
629                         && !acpi_rsdt_forced) {
630                 /*
631                  * Root table is an XSDT (64-bit physical addresses). We must use the
632                  * XSDT if the revision is > 1 and the XSDT pointer is present, as per
633                  * the ACPI specification.
634                  */
635                 address = (acpi_physical_address) rsdp->xsdt_physical_address;
636                 table_entry_size = sizeof(u64);
637                 rsdt_address = (acpi_physical_address)
638                                         rsdp->rsdt_physical_address;
639         } else {
640                 /* Root table is an RSDT (32-bit physical addresses) */
641
642                 address = (acpi_physical_address) rsdp->rsdt_physical_address;
643                 table_entry_size = sizeof(u32);
644         }
645
646         /*
647          * It is not possible to map more than one entry in some environments,
648          * so unmap the RSDP here before mapping other tables
649          */
650         acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp));
651
652         if (table_entry_size == sizeof(u64)) {
653                 if (acpi_tb_check_xsdt(address) == AE_NULL_ENTRY) {
654                         /* XSDT has NULL entry, RSDT is used */
655                         address = rsdt_address;
656                         table_entry_size = sizeof(u32);
657                         ACPI_WARNING((AE_INFO, "BIOS XSDT has NULL entry, "
658                                         "using RSDT"));
659                 }
660         }
661         /* Map the RSDT/XSDT table header to get the full table length */
662
663         table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
664         if (!table) {
665                 return_ACPI_STATUS(AE_NO_MEMORY);
666         }
667
668         acpi_tb_print_table_header(address, table);
669
670         /* Get the length of the full table, verify length and map entire table */
671
672         length = table->length;
673         acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
674
675         if (length < sizeof(struct acpi_table_header)) {
676                 ACPI_ERROR((AE_INFO, "Invalid length 0x%X in RSDT/XSDT",
677                             length));
678                 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
679         }
680
681         table = acpi_os_map_memory(address, length);
682         if (!table) {
683                 return_ACPI_STATUS(AE_NO_MEMORY);
684         }
685
686         /* Validate the root table checksum */
687
688         status = acpi_tb_verify_checksum(table, length);
689         if (ACPI_FAILURE(status)) {
690                 acpi_os_unmap_memory(table, length);
691                 return_ACPI_STATUS(status);
692         }
693
694         /* Calculate the number of tables described in the root table */
695
696         table_count = (u32)((table->length - sizeof(struct acpi_table_header)) /
697                             table_entry_size);
698         /*
699          * First two entries in the table array are reserved for the DSDT
700          * and FACS, which are not actually present in the RSDT/XSDT - they
701          * come from the FADT
702          */
703         table_entry =
704             ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header);
705         acpi_gbl_root_table_list.current_table_count = 2;
706
707         /*
708          * Initialize the root table array from the RSDT/XSDT
709          */
710         for (i = 0; i < table_count; i++) {
711                 if (acpi_gbl_root_table_list.current_table_count >=
712                     acpi_gbl_root_table_list.max_table_count) {
713
714                         /* There is no more room in the root table array, attempt resize */
715
716                         status = acpi_tb_resize_root_table_list();
717                         if (ACPI_FAILURE(status)) {
718                                 ACPI_WARNING((AE_INFO,
719                                               "Truncating %u table entries!",
720                                               (unsigned) (table_count -
721                                                (acpi_gbl_root_table_list.
722                                                           current_table_count -
723                                                           2))));
724                                 break;
725                         }
726                 }
727
728                 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
729
730                 acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.
731                                                 current_table_count].address =
732                     acpi_tb_get_root_table_entry(table_entry, table_entry_size);
733
734                 table_entry += table_entry_size;
735                 acpi_gbl_root_table_list.current_table_count++;
736         }
737
738         /*
739          * It is not possible to map more than one entry in some environments,
740          * so unmap the root table here before mapping other tables
741          */
742         acpi_os_unmap_memory(table, length);
743
744         /*
745          * Complete the initialization of the root table array by examining
746          * the header of each table
747          */
748         for (i = 2; i < acpi_gbl_root_table_list.current_table_count; i++) {
749                 acpi_tb_install_table(acpi_gbl_root_table_list.tables[i].
750                                       address, NULL, i);
751
752                 /* Special case for FADT - get the DSDT and FACS */
753
754                 if (ACPI_COMPARE_NAME
755                     (&acpi_gbl_root_table_list.tables[i].signature,
756                      ACPI_SIG_FADT)) {
757                         acpi_tb_parse_fadt(i);
758                 }
759         }
760
761         return_ACPI_STATUS(AE_OK);
762 }