| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** | 
|  | 2 | * | 
|  | 3 | * Module Name: tbget - ACPI Table get* routines | 
|  | 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 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> | 
|  | 45 | #include <acpi/actables.h> | 
|  | 46 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #define _COMPONENT          ACPI_TABLES | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 48 | ACPI_MODULE_NAME("tbget") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 50 | /* Local prototypes */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | static acpi_status | 
|  | 52 | acpi_tb_get_this_table(struct acpi_pointer *address, | 
|  | 53 | struct acpi_table_header *header, | 
|  | 54 | struct acpi_table_desc *table_info); | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 55 |  | 
|  | 56 | static acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 57 | acpi_tb_table_override(struct acpi_table_header *header, | 
|  | 58 | struct acpi_table_desc *table_info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 |  | 
|  | 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 |  | 
|  | 74 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | acpi_tb_get_table(struct acpi_pointer *address, | 
|  | 76 | struct acpi_table_desc *table_info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | acpi_status status; | 
|  | 79 | struct acpi_table_header header; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 81 | ACPI_FUNCTION_TRACE("tb_get_table"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 83 | /* Get the header in order to get signature and table size */ | 
|  | 84 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 85 | status = acpi_tb_get_table_header(address, &header); | 
|  | 86 | if (ACPI_FAILURE(status)) { | 
|  | 87 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } | 
|  | 89 |  | 
|  | 90 | /* Get the entire table */ | 
|  | 91 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 92 | status = acpi_tb_get_table_body(address, &header, table_info); | 
|  | 93 | if (ACPI_FAILURE(status)) { | 
|  | 94 | ACPI_REPORT_ERROR(("Could not get ACPI table (size %X), %s\n", | 
|  | 95 | header.length, | 
|  | 96 | acpi_format_exception(status))); | 
|  | 97 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } | 
|  | 99 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 100 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } | 
|  | 102 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | /******************************************************************************* | 
|  | 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 |  | 
|  | 120 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 121 | acpi_tb_get_table_header(struct acpi_pointer *address, | 
|  | 122 | struct acpi_table_header *return_header) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 124 | acpi_status status = AE_OK; | 
|  | 125 | struct acpi_table_header *header = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 127 | ACPI_FUNCTION_TRACE("tb_get_table_header"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 |  | 
|  | 129 | /* | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 130 | * Flags contains the current processor mode (Virtual or Physical | 
|  | 131 | * addressing) The pointer_type is either Logical or Physical | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | */ | 
|  | 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 139 | ACPI_MEMCPY(return_header, address->pointer.logical, | 
|  | 140 | sizeof(struct acpi_table_header)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | break; | 
|  | 142 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | case ACPI_LOGMODE_PHYSPTR: | 
|  | 144 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | /* Create a logical address for the physical pointer */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | status = acpi_os_map_memory(address->pointer.physical, | 
|  | 148 | sizeof(struct acpi_table_header), | 
|  | 149 | (void *)&header); | 
|  | 150 | if (ACPI_FAILURE(status)) { | 
|  | 151 | ACPI_REPORT_ERROR(("Could not map memory at %8.8X%8.8X for length %X\n", ACPI_FORMAT_UINT64(address->pointer.physical), sizeof(struct acpi_table_header))); | 
|  | 152 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } | 
|  | 154 |  | 
|  | 155 | /* Copy header and delete mapping */ | 
|  | 156 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | ACPI_MEMCPY(return_header, header, | 
|  | 158 | sizeof(struct acpi_table_header)); | 
|  | 159 | acpi_os_unmap_memory(header, sizeof(struct acpi_table_header)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | break; | 
|  | 161 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | default: | 
|  | 163 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | ACPI_REPORT_ERROR(("Invalid address flags %X\n", | 
|  | 165 | address->pointer_type)); | 
|  | 166 | return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } | 
|  | 168 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 169 | ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "Table Signature: [%4.4s]\n", | 
|  | 170 | return_header->signature)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 172 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } | 
|  | 174 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | /******************************************************************************* | 
|  | 176 | * | 
|  | 177 | * FUNCTION:    acpi_tb_get_table_body | 
|  | 178 | * | 
|  | 179 | * PARAMETERS:  Address             - Address of table to retrieve.  Can be | 
|  | 180 | *                                    Logical or Physical | 
|  | 181 | *              Header              - Header of the table to retrieve | 
|  | 182 | *              table_info          - Where the table info is returned | 
|  | 183 | * | 
|  | 184 | * RETURN:      Status | 
|  | 185 | * | 
|  | 186 | * DESCRIPTION: Get an entire ACPI table with support to allow the host OS to | 
|  | 187 | *              replace the table with a newer version (table override.) | 
|  | 188 | *              Works in both physical or virtual | 
|  | 189 | *              addressing mode.  Works with both physical or logical pointers. | 
|  | 190 | *              Table is either copied or mapped, depending on the pointer | 
|  | 191 | *              type and mode of the processor. | 
|  | 192 | * | 
|  | 193 | ******************************************************************************/ | 
|  | 194 |  | 
|  | 195 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | acpi_tb_get_table_body(struct acpi_pointer *address, | 
|  | 197 | struct acpi_table_header *header, | 
|  | 198 | struct acpi_table_desc *table_info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 200 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 202 | ACPI_FUNCTION_TRACE("tb_get_table_body"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 |  | 
|  | 204 | if (!table_info || !address) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 205 | return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } | 
|  | 207 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 208 | /* Attempt table override. */ | 
|  | 209 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 210 | status = acpi_tb_table_override(header, table_info); | 
|  | 211 | if (ACPI_SUCCESS(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | /* Table was overridden by the host OS */ | 
|  | 213 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 214 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } | 
|  | 216 |  | 
|  | 217 | /* No override, get the original table */ | 
|  | 218 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | status = acpi_tb_get_this_table(address, header, table_info); | 
|  | 220 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } | 
|  | 222 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | /******************************************************************************* | 
|  | 224 | * | 
|  | 225 | * FUNCTION:    acpi_tb_table_override | 
|  | 226 | * | 
|  | 227 | * PARAMETERS:  Header              - Pointer to table header | 
|  | 228 | *              table_info          - Return info if table is overridden | 
|  | 229 | * | 
|  | 230 | * RETURN:      None | 
|  | 231 | * | 
|  | 232 | * DESCRIPTION: Attempts override of current table with a new one if provided | 
|  | 233 | *              by the host OS. | 
|  | 234 | * | 
|  | 235 | ******************************************************************************/ | 
|  | 236 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 237 | static acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 238 | acpi_tb_table_override(struct acpi_table_header *header, | 
|  | 239 | struct acpi_table_desc *table_info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 241 | struct acpi_table_header *new_table; | 
|  | 242 | acpi_status status; | 
|  | 243 | struct acpi_pointer address; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 245 | ACPI_FUNCTION_TRACE("tb_table_override"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 |  | 
|  | 247 | /* | 
|  | 248 | * The OSL will examine the header and decide whether to override this | 
|  | 249 | * table.  If it decides to override, a table will be returned in new_table, | 
|  | 250 | * which we will then copy. | 
|  | 251 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 252 | status = acpi_os_table_override(header, &new_table); | 
|  | 253 | if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | /* Some severe error from the OSL, but we basically ignore it */ | 
|  | 255 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 256 | ACPI_REPORT_ERROR(("Could not override ACPI table, %s\n", | 
|  | 257 | acpi_format_exception(status))); | 
|  | 258 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } | 
|  | 260 |  | 
|  | 261 | if (!new_table) { | 
|  | 262 | /* No table override */ | 
|  | 263 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 264 | return_ACPI_STATUS(AE_NO_ACPI_TABLES); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } | 
|  | 266 |  | 
|  | 267 | /* | 
|  | 268 | * We have a new table to override the old one.  Get a copy of | 
|  | 269 | * the new one.  We know that the new table has a logical pointer. | 
|  | 270 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 271 | address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | address.pointer.logical = new_table; | 
|  | 273 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 274 | status = acpi_tb_get_this_table(&address, new_table, table_info); | 
|  | 275 | if (ACPI_FAILURE(status)) { | 
|  | 276 | ACPI_REPORT_ERROR(("Could not copy override ACPI table, %s\n", | 
|  | 277 | acpi_format_exception(status))); | 
|  | 278 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | } | 
|  | 280 |  | 
|  | 281 | /* Copy the table info */ | 
|  | 282 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 283 | ACPI_REPORT_INFO(("Table [%4.4s] replaced by host OS\n", | 
|  | 284 | table_info->pointer->signature)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 286 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } | 
|  | 288 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | /******************************************************************************* | 
|  | 290 | * | 
|  | 291 | * FUNCTION:    acpi_tb_get_this_table | 
|  | 292 | * | 
|  | 293 | * PARAMETERS:  Address             - Address of table to retrieve.  Can be | 
|  | 294 | *                                    Logical or Physical | 
|  | 295 | *              Header              - Header of the table to retrieve | 
|  | 296 | *              table_info          - Where the table info is returned | 
|  | 297 | * | 
|  | 298 | * RETURN:      Status | 
|  | 299 | * | 
|  | 300 | * DESCRIPTION: Get an entire ACPI table.  Works in both physical or virtual | 
|  | 301 | *              addressing mode.  Works with both physical or logical pointers. | 
|  | 302 | *              Table is either copied or mapped, depending on the pointer | 
|  | 303 | *              type and mode of the processor. | 
|  | 304 | * | 
|  | 305 | ******************************************************************************/ | 
|  | 306 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 307 | static acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 308 | acpi_tb_get_this_table(struct acpi_pointer *address, | 
|  | 309 | struct acpi_table_header *header, | 
|  | 310 | struct acpi_table_desc *table_info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 312 | struct acpi_table_header *full_table = NULL; | 
|  | 313 | u8 allocation; | 
|  | 314 | acpi_status status = AE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 316 | ACPI_FUNCTION_TRACE("tb_get_this_table"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 |  | 
|  | 318 | /* | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 319 | * Flags contains the current processor mode (Virtual or Physical | 
|  | 320 | * addressing) The pointer_type is either Logical or Physical | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | */ | 
|  | 322 | switch (address->pointer_type) { | 
|  | 323 | case ACPI_PHYSMODE_PHYSPTR: | 
|  | 324 | case ACPI_LOGMODE_LOGPTR: | 
|  | 325 |  | 
|  | 326 | /* Pointer matches processor mode, copy the table to a new buffer */ | 
|  | 327 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 328 | full_table = ACPI_MEM_ALLOCATE(header->length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | if (!full_table) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 330 | ACPI_REPORT_ERROR(("Could not allocate table memory for [%4.4s] length %X\n", header->signature, header->length)); | 
|  | 331 | return_ACPI_STATUS(AE_NO_MEMORY); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } | 
|  | 333 |  | 
|  | 334 | /* Copy the entire table (including header) to the local buffer */ | 
|  | 335 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 336 | ACPI_MEMCPY(full_table, address->pointer.logical, | 
|  | 337 | header->length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 |  | 
|  | 339 | /* Save allocation type */ | 
|  | 340 |  | 
|  | 341 | allocation = ACPI_MEM_ALLOCATED; | 
|  | 342 | break; | 
|  | 343 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | case ACPI_LOGMODE_PHYSPTR: | 
|  | 345 |  | 
|  | 346 | /* | 
|  | 347 | * Just map the table's physical memory | 
|  | 348 | * into our address space. | 
|  | 349 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 350 | status = acpi_os_map_memory(address->pointer.physical, | 
|  | 351 | (acpi_size) header->length, | 
|  | 352 | (void *)&full_table); | 
|  | 353 | if (ACPI_FAILURE(status)) { | 
|  | 354 | ACPI_REPORT_ERROR(("Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X\n", header->signature, ACPI_FORMAT_UINT64(address->pointer.physical), header->length)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | return (status); | 
|  | 356 | } | 
|  | 357 |  | 
|  | 358 | /* Save allocation type */ | 
|  | 359 |  | 
|  | 360 | allocation = ACPI_MEM_MAPPED; | 
|  | 361 | break; | 
|  | 362 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | default: | 
|  | 364 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 365 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid address flags %X\n", | 
|  | 366 | address->pointer_type)); | 
|  | 367 | return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | } | 
|  | 369 |  | 
|  | 370 | /* | 
|  | 371 | * Validate checksum for _most_ tables, | 
|  | 372 | * even the ones whose signature we don't recognize | 
|  | 373 | */ | 
|  | 374 | if (table_info->type != ACPI_TABLE_FACS) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 375 | status = acpi_tb_verify_table_checksum(full_table); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 |  | 
|  | 377 | #if (!ACPI_CHECKSUM_ABORT) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 378 | if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | /* Ignore the error if configuration says so */ | 
|  | 380 |  | 
|  | 381 | status = AE_OK; | 
|  | 382 | } | 
|  | 383 | #endif | 
|  | 384 | } | 
|  | 385 |  | 
|  | 386 | /* Return values */ | 
|  | 387 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 388 | table_info->pointer = full_table; | 
|  | 389 | table_info->length = (acpi_size) header->length; | 
|  | 390 | table_info->allocation = allocation; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 392 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
|  | 393 | "Found table [%4.4s] at %8.8X%8.8X, mapped/copied to %p\n", | 
|  | 394 | full_table->signature, | 
|  | 395 | ACPI_FORMAT_UINT64(address->pointer.physical), | 
|  | 396 | full_table)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 398 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } | 
|  | 400 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | /******************************************************************************* | 
|  | 402 | * | 
|  | 403 | * FUNCTION:    acpi_tb_get_table_ptr | 
|  | 404 | * | 
|  | 405 | * PARAMETERS:  table_type      - one of the defined table types | 
|  | 406 | *              Instance        - Which table of this type | 
|  | 407 | *              table_ptr_loc   - pointer to location to place the pointer for | 
|  | 408 | *                                return | 
|  | 409 | * | 
|  | 410 | * RETURN:      Status | 
|  | 411 | * | 
|  | 412 | * DESCRIPTION: This function is called to get the pointer to an ACPI table. | 
|  | 413 | * | 
|  | 414 | ******************************************************************************/ | 
|  | 415 |  | 
|  | 416 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 417 | acpi_tb_get_table_ptr(acpi_table_type table_type, | 
|  | 418 | u32 instance, struct acpi_table_header **table_ptr_loc) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 420 | struct acpi_table_desc *table_desc; | 
|  | 421 | u32 i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 423 | ACPI_FUNCTION_TRACE("tb_get_table_ptr"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 |  | 
|  | 425 | if (!acpi_gbl_DSDT) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 426 | return_ACPI_STATUS(AE_NO_ACPI_TABLES); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } | 
|  | 428 |  | 
|  | 429 | if (table_type > ACPI_TABLE_MAX) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 430 | return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | } | 
|  | 432 |  | 
|  | 433 | /* | 
|  | 434 | * For all table types (Single/Multiple), the first | 
|  | 435 | * instance is always in the list head. | 
|  | 436 | */ | 
|  | 437 | if (instance == 1) { | 
|  | 438 | /* Get the first */ | 
|  | 439 |  | 
|  | 440 | *table_ptr_loc = NULL; | 
|  | 441 | if (acpi_gbl_table_lists[table_type].next) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 442 | *table_ptr_loc = | 
|  | 443 | acpi_gbl_table_lists[table_type].next->pointer; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 445 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } | 
|  | 447 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 448 | /* Check for instance out of range */ | 
|  | 449 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | if (instance > acpi_gbl_table_lists[table_type].count) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 451 | return_ACPI_STATUS(AE_NOT_EXIST); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | } | 
|  | 453 |  | 
|  | 454 | /* Walk the list to get the desired table | 
|  | 455 | * Since the if (Instance == 1) check above checked for the | 
|  | 456 | * first table, setting table_desc equal to the .Next member | 
|  | 457 | * is actually pointing to the second table.  Therefore, we | 
|  | 458 | * need to walk from the 2nd table until we reach the Instance | 
|  | 459 | * that the user is looking for and return its table pointer. | 
|  | 460 | */ | 
|  | 461 | table_desc = acpi_gbl_table_lists[table_type].next; | 
|  | 462 | for (i = 2; i < instance; i++) { | 
|  | 463 | table_desc = table_desc->next; | 
|  | 464 | } | 
|  | 465 |  | 
|  | 466 | /* We are now pointing to the requested table's descriptor */ | 
|  | 467 |  | 
|  | 468 | *table_ptr_loc = table_desc->pointer; | 
|  | 469 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 470 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | } |