Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | /****************************************************************************** * * Module Name: tbutils - Table manipulation utilities * $Revision: 40 $ * *****************************************************************************/ /* * Copyright (C) 2000, 2001 R. Byron Moore * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "acpi.h" #include "actables.h" #include "acinterp.h" #define _COMPONENT ACPI_TABLES MODULE_NAME ("tbutils") /******************************************************************************* * * FUNCTION: Acpi_tb_handle_to_object * * PARAMETERS: Table_id - Id for which the function is searching * Table_desc - Pointer to return the matching table * descriptor. * * RETURN: Search the tables to find one with a matching Table_id and * return a pointer to that table descriptor. * ******************************************************************************/ acpi_status acpi_tb_handle_to_object ( u16 table_id, acpi_table_desc **table_desc) { u32 i; acpi_table_desc *list_head; PROC_NAME ("Tb_handle_to_object"); for (i = 0; i < ACPI_TABLE_MAX; i++) { list_head = &acpi_gbl_acpi_tables[i]; do { if (list_head->table_id == table_id) { *table_desc = list_head; return (AE_OK); } list_head = list_head->next; } while (list_head != &acpi_gbl_acpi_tables[i]); } ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Table_id=%X does not exist\n", table_id)); return (AE_BAD_PARAMETER); } /******************************************************************************* * * FUNCTION: Acpi_tb_system_table_pointer * * PARAMETERS: *Where - Pointer to be examined * * RETURN: TRUE if Where is within the AML stream (in one of the ACPI * system tables such as the DSDT or an SSDT.) * FALSE otherwise * ******************************************************************************/ u8 acpi_tb_system_table_pointer ( void *where) { u32 i; acpi_table_desc *table_desc; acpi_table_header *table; /* No function trace, called too often! */ /* Ignore null pointer */ if (!where) { return (FALSE); } /* Check for a pointer within the DSDT */ if ((acpi_gbl_DSDT) && (IS_IN_ACPI_TABLE (where, acpi_gbl_DSDT))) { return (TRUE); } /* Check each of the loaded SSDTs (if any)*/ table_desc = &acpi_gbl_acpi_tables[ACPI_TABLE_SSDT]; for (i = 0; i < acpi_gbl_acpi_tables[ACPI_TABLE_SSDT].count; i++) { table = table_desc->pointer; if (IS_IN_ACPI_TABLE (where, table)) { return (TRUE); } table_desc = table_desc->next; } /* Check each of the loaded PSDTs (if any)*/ table_desc = &acpi_gbl_acpi_tables[ACPI_TABLE_PSDT]; for (i = 0; i < acpi_gbl_acpi_tables[ACPI_TABLE_PSDT].count; i++) { table = table_desc->pointer; if (IS_IN_ACPI_TABLE (where, table)) { return (TRUE); } table_desc = table_desc->next; } /* Pointer does not point into any system table */ return (FALSE); } /******************************************************************************* * * FUNCTION: Acpi_tb_validate_table_header * * PARAMETERS: Table_header - Logical pointer to the table * * RETURN: Status * * DESCRIPTION: Check an ACPI table header for validity * * NOTE: Table pointers are validated as follows: * 1) Table pointer must point to valid physical memory * 2) Signature must be 4 ASCII chars, even if we don't recognize the * name * 3) Table must be readable for length specified in the header * 4) Table checksum must be valid (with the exception of the FACS * which has no checksum for some odd reason) * ******************************************************************************/ acpi_status acpi_tb_validate_table_header ( acpi_table_header *table_header) { acpi_name signature; PROC_NAME ("Tb_validate_table_header"); /* Verify that this is a valid address */ if (!acpi_os_readable (table_header, sizeof (acpi_table_header))) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Cannot read table header at %p\n", table_header)); return (AE_BAD_ADDRESS); } /* Ensure that the signature is 4 ASCII characters */ MOVE_UNALIGNED32_TO_32 (&signature, &table_header->signature); if (!acpi_ut_valid_acpi_name (signature)) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Table signature at %p [%X] has invalid characters\n", table_header, &signature)); REPORT_WARNING (("Invalid table signature %4.4s found\n", &signature)); DUMP_BUFFER (table_header, sizeof (acpi_table_header)); return (AE_BAD_SIGNATURE); } /* Validate the table length */ if (table_header->length < sizeof (acpi_table_header)) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid length in table header %p name %4.4s\n", table_header, &signature)); REPORT_WARNING (("Invalid table header length found\n")); DUMP_BUFFER (table_header, sizeof (acpi_table_header)); return (AE_BAD_HEADER); } return (AE_OK); } /******************************************************************************* * * FUNCTION: Acpi_tb_map_acpi_table * * PARAMETERS: Physical_address - Physical address of table to map * *Size - Size of the table. If zero, the size * from the table header is used. * Actual size is returned here. * **Logical_address - Logical address of mapped table * * RETURN: Logical address of the mapped table. * * DESCRIPTION: Maps the physical address of table into a logical address * ******************************************************************************/ acpi_status acpi_tb_map_acpi_table ( ACPI_PHYSICAL_ADDRESS physical_address, u32 *size, acpi_table_header **logical_address) { acpi_table_header *table; u32 table_size = *size; acpi_status status = AE_OK; PROC_NAME ("Tb_map_acpi_table"); /* If size is zero, look at the table header to get the actual size */ if ((*size) == 0) { /* Get the table header so we can extract the table length */ status = acpi_os_map_memory (physical_address, sizeof (acpi_table_header), (void **) &table); if (ACPI_FAILURE (status)) { return (status); } /* Extract the full table length before we delete the mapping */ table_size = table->length; /* * Validate the header and delete the mapping. * We will create a mapping for the full table below. */ status = acpi_tb_validate_table_header (table); /* Always unmap the memory for the header */ acpi_os_unmap_memory (table, sizeof (acpi_table_header)); /* Exit if header invalid */ if (ACPI_FAILURE (status)) { return (status); } } /* Map the physical memory for the correct length */ status = acpi_os_map_memory (physical_address, table_size, (void **) &table); if (ACPI_FAILURE (status)) { return (status); } ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Mapped memory for ACPI table, length=%d(%X) at %p\n", table_size, table_size, table)); *size = table_size; *logical_address = table; return (status); } /******************************************************************************* * * FUNCTION: Acpi_tb_verify_table_checksum * * PARAMETERS: *Table_header - ACPI table to verify * * RETURN: 8 bit checksum of table * * DESCRIPTION: Does an 8 bit checksum of table and returns status. A correct * table should have a checksum of 0. * ******************************************************************************/ acpi_status acpi_tb_verify_table_checksum ( acpi_table_header *table_header) { u8 checksum; acpi_status status = AE_OK; FUNCTION_TRACE ("Tb_verify_table_checksum"); /* Compute the checksum on the table */ checksum = acpi_tb_checksum (table_header, table_header->length); /* Return the appropriate exception */ if (checksum) { REPORT_WARNING (("Invalid checksum (%X) in table %4.4s\n", checksum, &table_header->signature)); status = AE_BAD_CHECKSUM; } return_ACPI_STATUS (status); } /******************************************************************************* * * FUNCTION: Acpi_tb_checksum * * PARAMETERS: Buffer - Buffer to checksum * Length - Size of the buffer * * RETURNS 8 bit checksum of buffer * * DESCRIPTION: Computes an 8 bit checksum of the buffer(length) and returns it. * ******************************************************************************/ u8 acpi_tb_checksum ( void *buffer, u32 length) { u8 *limit; u8 *rover; u8 sum = 0; if (buffer && length) { /* Buffer and Length are valid */ limit = (u8 *) buffer + length; for (rover = buffer; rover < limit; rover++) { sum = (u8) (sum + *rover); } } return (sum); } |