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 | /* |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -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)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 94 | ACPI_EXCEPTION((AE_INFO, status, |
| 95 | "Could not get ACPI table (size %X)", |
| 96 | header.length)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -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)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 151 | ACPI_ERROR((AE_INFO, |
| 152 | "Could not map memory at %8.8X%8.8X for table header", |
| 153 | ACPI_FORMAT_UINT64(address->pointer. |
| 154 | physical))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 155 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /* Copy header and delete mapping */ |
| 159 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 160 | ACPI_MEMCPY(return_header, header, |
| 161 | sizeof(struct acpi_table_header)); |
| 162 | acpi_os_unmap_memory(header, sizeof(struct acpi_table_header)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | break; |
| 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | default: |
| 166 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 167 | ACPI_ERROR((AE_INFO, "Invalid address flags %X", |
| 168 | address->pointer_type)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 169 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 172 | ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "Table Signature: [%4.4s]\n", |
| 173 | return_header->signature)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 175 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | /******************************************************************************* |
| 179 | * |
| 180 | * FUNCTION: acpi_tb_get_table_body |
| 181 | * |
| 182 | * PARAMETERS: Address - Address of table to retrieve. Can be |
| 183 | * Logical or Physical |
| 184 | * Header - Header of the table to retrieve |
| 185 | * table_info - Where the table info is returned |
| 186 | * |
| 187 | * RETURN: Status |
| 188 | * |
| 189 | * DESCRIPTION: Get an entire ACPI table with support to allow the host OS to |
| 190 | * replace the table with a newer version (table override.) |
| 191 | * Works in both physical or virtual |
| 192 | * addressing mode. Works with both physical or logical pointers. |
| 193 | * Table is either copied or mapped, depending on the pointer |
| 194 | * type and mode of the processor. |
| 195 | * |
| 196 | ******************************************************************************/ |
| 197 | |
| 198 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 199 | acpi_tb_get_table_body(struct acpi_pointer *address, |
| 200 | struct acpi_table_header *header, |
| 201 | struct acpi_table_desc *table_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 203 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 205 | ACPI_FUNCTION_TRACE(tb_get_table_body); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
| 207 | if (!table_info || !address) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 208 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 211 | /* Attempt table override. */ |
| 212 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 213 | status = acpi_tb_table_override(header, table_info); |
| 214 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | /* Table was overridden by the host OS */ |
| 217 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 218 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /* No override, get the original table */ |
| 222 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 223 | status = acpi_tb_get_this_table(address, header, table_info); |
| 224 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /******************************************************************************* |
| 228 | * |
| 229 | * FUNCTION: acpi_tb_table_override |
| 230 | * |
| 231 | * PARAMETERS: Header - Pointer to table header |
| 232 | * table_info - Return info if table is overridden |
| 233 | * |
| 234 | * RETURN: None |
| 235 | * |
| 236 | * DESCRIPTION: Attempts override of current table with a new one if provided |
| 237 | * by the host OS. |
| 238 | * |
| 239 | ******************************************************************************/ |
| 240 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 241 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 242 | acpi_tb_table_override(struct acpi_table_header *header, |
| 243 | struct acpi_table_desc *table_info) |
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 | struct acpi_table_header *new_table; |
| 246 | acpi_status status; |
| 247 | struct acpi_pointer address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 249 | ACPI_FUNCTION_TRACE(tb_table_override); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | /* |
| 252 | * The OSL will examine the header and decide whether to override this |
| 253 | * table. If it decides to override, a table will be returned in new_table, |
| 254 | * which we will then copy. |
| 255 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 256 | status = acpi_os_table_override(header, &new_table); |
| 257 | if (ACPI_FAILURE(status)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | /* Some severe error from the OSL, but we basically ignore it */ |
| 260 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 261 | ACPI_EXCEPTION((AE_INFO, status, |
| 262 | "Could not override ACPI table")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 263 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | if (!new_table) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | /* No table override */ |
| 269 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 270 | return_ACPI_STATUS(AE_NO_ACPI_TABLES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /* |
| 274 | * We have a new table to override the old one. Get a copy of |
| 275 | * the new one. We know that the new table has a logical pointer. |
| 276 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 277 | address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | address.pointer.logical = new_table; |
| 279 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 280 | status = acpi_tb_get_this_table(&address, new_table, table_info); |
| 281 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 282 | ACPI_EXCEPTION((AE_INFO, status, "Could not copy ACPI table")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 283 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | /* Copy the table info */ |
| 287 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 288 | ACPI_INFO((AE_INFO, "Table [%4.4s] replaced by host OS", |
| 289 | table_info->pointer->signature)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 291 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | /******************************************************************************* |
| 295 | * |
| 296 | * FUNCTION: acpi_tb_get_this_table |
| 297 | * |
| 298 | * PARAMETERS: Address - Address of table to retrieve. Can be |
| 299 | * Logical or Physical |
| 300 | * Header - Header of the table to retrieve |
| 301 | * table_info - Where the table info is returned |
| 302 | * |
| 303 | * RETURN: Status |
| 304 | * |
| 305 | * DESCRIPTION: Get an entire ACPI table. Works in both physical or virtual |
| 306 | * addressing mode. Works with both physical or logical pointers. |
| 307 | * Table is either copied or mapped, depending on the pointer |
| 308 | * type and mode of the processor. |
| 309 | * |
| 310 | ******************************************************************************/ |
| 311 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 312 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 313 | acpi_tb_get_this_table(struct acpi_pointer *address, |
| 314 | struct acpi_table_header *header, |
| 315 | struct acpi_table_desc *table_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 317 | struct acpi_table_header *full_table = NULL; |
| 318 | u8 allocation; |
| 319 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 321 | ACPI_FUNCTION_TRACE(tb_get_this_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
| 323 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 324 | * Flags contains the current processor mode (Virtual or Physical |
| 325 | * addressing) The pointer_type is either Logical or Physical |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | */ |
| 327 | switch (address->pointer_type) { |
| 328 | case ACPI_PHYSMODE_PHYSPTR: |
| 329 | case ACPI_LOGMODE_LOGPTR: |
| 330 | |
| 331 | /* Pointer matches processor mode, copy the table to a new buffer */ |
| 332 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 333 | full_table = ACPI_ALLOCATE(header->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | if (!full_table) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 335 | ACPI_ERROR((AE_INFO, |
| 336 | "Could not allocate table memory for [%4.4s] length %X", |
| 337 | header->signature, header->length)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 338 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | /* Copy the entire table (including header) to the local buffer */ |
| 342 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 343 | ACPI_MEMCPY(full_table, address->pointer.logical, |
| 344 | header->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
| 346 | /* Save allocation type */ |
| 347 | |
| 348 | allocation = ACPI_MEM_ALLOCATED; |
| 349 | break; |
| 350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | case ACPI_LOGMODE_PHYSPTR: |
| 352 | |
| 353 | /* |
| 354 | * Just map the table's physical memory |
| 355 | * into our address space. |
| 356 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 357 | status = acpi_os_map_memory(address->pointer.physical, |
| 358 | (acpi_size) header->length, |
| 359 | (void *)&full_table); |
| 360 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 361 | ACPI_ERROR((AE_INFO, |
| 362 | "Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X", |
| 363 | header->signature, |
| 364 | ACPI_FORMAT_UINT64(address->pointer. |
| 365 | physical), |
| 366 | header->length)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | return (status); |
| 368 | } |
| 369 | |
| 370 | /* Save allocation type */ |
| 371 | |
| 372 | allocation = ACPI_MEM_MAPPED; |
| 373 | break; |
| 374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | default: |
| 376 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 377 | ACPI_ERROR((AE_INFO, "Invalid address flags %X", |
| 378 | address->pointer_type)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 379 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | /* |
| 383 | * Validate checksum for _most_ tables, |
| 384 | * even the ones whose signature we don't recognize |
| 385 | */ |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 386 | if (table_info->type != ACPI_TABLE_ID_FACS) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 387 | status = acpi_tb_verify_table_checksum(full_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
| 389 | #if (!ACPI_CHECKSUM_ABORT) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 390 | if (ACPI_FAILURE(status)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | /* Ignore the error if configuration says so */ |
| 393 | |
| 394 | status = AE_OK; |
| 395 | } |
| 396 | #endif |
| 397 | } |
| 398 | |
| 399 | /* Return values */ |
| 400 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 401 | table_info->pointer = full_table; |
| 402 | table_info->length = (acpi_size) header->length; |
| 403 | table_info->allocation = allocation; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 405 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 406 | "Found table [%4.4s] at %8.8X%8.8X, mapped/copied to %p\n", |
| 407 | full_table->signature, |
| 408 | ACPI_FORMAT_UINT64(address->pointer.physical), |
| 409 | full_table)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 411 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | /******************************************************************************* |
| 415 | * |
| 416 | * FUNCTION: acpi_tb_get_table_ptr |
| 417 | * |
| 418 | * PARAMETERS: table_type - one of the defined table types |
| 419 | * Instance - Which table of this type |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 420 | * return_table - pointer to location to place the pointer for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | * return |
| 422 | * |
| 423 | * RETURN: Status |
| 424 | * |
| 425 | * DESCRIPTION: This function is called to get the pointer to an ACPI table. |
| 426 | * |
| 427 | ******************************************************************************/ |
| 428 | |
| 429 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 430 | acpi_tb_get_table_ptr(acpi_table_type table_type, |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 431 | u32 instance, struct acpi_table_header **return_table) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 433 | struct acpi_table_desc *table_desc; |
| 434 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 436 | ACPI_FUNCTION_TRACE(tb_get_table_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 438 | if (table_type > ACPI_TABLE_ID_MAX) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 439 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 442 | /* Check for instance out of range of the current table count */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 443 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | if (instance > acpi_gbl_table_lists[table_type].count) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 445 | return_ACPI_STATUS(AE_NOT_EXIST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 448 | /* |
| 449 | * Walk the list to get the desired table |
| 450 | * Note: Instance is one-based |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | */ |
| 452 | table_desc = acpi_gbl_table_lists[table_type].next; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 453 | for (i = 1; i < instance; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | table_desc = table_desc->next; |
| 455 | } |
| 456 | |
| 457 | /* We are now pointing to the requested table's descriptor */ |
| 458 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 459 | *return_table = table_desc->pointer; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 460 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |