Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: tbutils - Table manipulation utilities |
| 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("tbutils") |
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 */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 51 | #ifdef ACPI_OBSOLETE_FUNCTIONS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 53 | acpi_tb_handle_to_object(u16 table_id, struct acpi_table_desc **table_desc); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 54 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /******************************************************************************* |
| 57 | * |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 58 | * FUNCTION: acpi_tb_is_table_installed |
| 59 | * |
| 60 | * PARAMETERS: new_table_desc - Descriptor for new table being installed |
| 61 | * |
| 62 | * RETURN: Status - AE_ALREADY_EXISTS if the table is already installed |
| 63 | * |
| 64 | * DESCRIPTION: Determine if an ACPI table is already installed |
| 65 | * |
| 66 | * MUTEX: Table data structures should be locked |
| 67 | * |
| 68 | ******************************************************************************/ |
| 69 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 70 | acpi_status acpi_tb_is_table_installed(struct acpi_table_desc *new_table_desc) |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 71 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 72 | struct acpi_table_desc *table_desc; |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 73 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 74 | ACPI_FUNCTION_TRACE("tb_is_table_installed"); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 75 | |
| 76 | /* Get the list descriptor and first table descriptor */ |
| 77 | |
| 78 | table_desc = acpi_gbl_table_lists[new_table_desc->type].next; |
| 79 | |
| 80 | /* Examine all installed tables of this type */ |
| 81 | |
| 82 | while (table_desc) { |
| 83 | /* Compare Revision and oem_table_id */ |
| 84 | |
| 85 | if ((table_desc->loaded_into_namespace) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 86 | (table_desc->pointer->revision == |
| 87 | new_table_desc->pointer->revision) && |
| 88 | (!ACPI_MEMCMP(table_desc->pointer->oem_table_id, |
| 89 | new_table_desc->pointer->oem_table_id, 8))) { |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 90 | /* This table is already installed */ |
| 91 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 92 | ACPI_DEBUG_PRINT((ACPI_DB_TABLES, |
| 93 | "Table [%4.4s] already installed: Rev %X oem_table_id [%8.8s]\n", |
| 94 | new_table_desc->pointer->signature, |
| 95 | new_table_desc->pointer->revision, |
| 96 | new_table_desc->pointer-> |
| 97 | oem_table_id)); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 98 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 99 | new_table_desc->owner_id = table_desc->owner_id; |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 100 | new_table_desc->installed_desc = table_desc; |
| 101 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 102 | return_ACPI_STATUS(AE_ALREADY_EXISTS); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /* Get next table on the list */ |
| 106 | |
| 107 | table_desc = table_desc->next; |
| 108 | } |
| 109 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 110 | return_ACPI_STATUS(AE_OK); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 113 | /******************************************************************************* |
| 114 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | * FUNCTION: acpi_tb_validate_table_header |
| 116 | * |
| 117 | * PARAMETERS: table_header - Logical pointer to the table |
| 118 | * |
| 119 | * RETURN: Status |
| 120 | * |
| 121 | * DESCRIPTION: Check an ACPI table header for validity |
| 122 | * |
| 123 | * NOTE: Table pointers are validated as follows: |
| 124 | * 1) Table pointer must point to valid physical memory |
| 125 | * 2) Signature must be 4 ASCII chars, even if we don't recognize the |
| 126 | * name |
| 127 | * 3) Table must be readable for length specified in the header |
| 128 | * 4) Table checksum must be valid (with the exception of the FACS |
| 129 | * which has no checksum because it contains variable fields) |
| 130 | * |
| 131 | ******************************************************************************/ |
| 132 | |
| 133 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 134 | acpi_tb_validate_table_header(struct acpi_table_header *table_header) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 136 | acpi_name signature; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 138 | ACPI_FUNCTION_NAME("tb_validate_table_header"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | /* Verify that this is a valid address */ |
| 141 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 142 | if (!acpi_os_readable(table_header, sizeof(struct acpi_table_header))) { |
| 143 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 144 | "Cannot read table header at %p\n", |
| 145 | table_header)); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | return (AE_BAD_ADDRESS); |
| 148 | } |
| 149 | |
| 150 | /* Ensure that the signature is 4 ASCII characters */ |
| 151 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 152 | ACPI_MOVE_32_TO_32(&signature, table_header->signature); |
| 153 | if (!acpi_ut_valid_acpi_name(signature)) { |
| 154 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 155 | "Table signature at %p [%p] has invalid characters\n", |
| 156 | table_header, &signature)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 158 | ACPI_REPORT_WARNING(("Invalid table signature found: [%4.4s]\n", |
| 159 | (char *)&signature)); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 160 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 161 | ACPI_DUMP_BUFFER(table_header, |
| 162 | sizeof(struct acpi_table_header)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | return (AE_BAD_SIGNATURE); |
| 164 | } |
| 165 | |
| 166 | /* Validate the table length */ |
| 167 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 168 | if (table_header->length < sizeof(struct acpi_table_header)) { |
| 169 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 170 | "Invalid length in table header %p name %4.4s\n", |
| 171 | table_header, (char *)&signature)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 173 | ACPI_REPORT_WARNING(("Invalid table header length (0x%X) found\n", (u32) table_header->length)); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 174 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 175 | ACPI_DUMP_BUFFER(table_header, |
| 176 | sizeof(struct acpi_table_header)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | return (AE_BAD_HEADER); |
| 178 | } |
| 179 | |
| 180 | return (AE_OK); |
| 181 | } |
| 182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | /******************************************************************************* |
| 184 | * |
| 185 | * FUNCTION: acpi_tb_verify_table_checksum |
| 186 | * |
| 187 | * PARAMETERS: *table_header - ACPI table to verify |
| 188 | * |
| 189 | * RETURN: 8 bit checksum of table |
| 190 | * |
| 191 | * DESCRIPTION: Does an 8 bit checksum of table and returns status. A correct |
| 192 | * table should have a checksum of 0. |
| 193 | * |
| 194 | ******************************************************************************/ |
| 195 | |
| 196 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 197 | acpi_tb_verify_table_checksum(struct acpi_table_header * table_header) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 199 | u8 checksum; |
| 200 | acpi_status status = AE_OK; |
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_verify_table_checksum"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | /* Compute the checksum on the table */ |
| 205 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 206 | checksum = |
| 207 | acpi_tb_generate_checksum(table_header, table_header->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | /* Return the appropriate exception */ |
| 210 | |
| 211 | if (checksum) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 212 | ACPI_REPORT_WARNING(("Invalid checksum in table [%4.4s] (%02X, sum %02X is not zero)\n", table_header->signature, (u32) table_header->checksum, (u32) checksum)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
| 214 | status = AE_BAD_CHECKSUM; |
| 215 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 216 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | /******************************************************************************* |
| 220 | * |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 221 | * FUNCTION: acpi_tb_generate_checksum |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | * |
| 223 | * PARAMETERS: Buffer - Buffer to checksum |
| 224 | * Length - Size of the buffer |
| 225 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 226 | * RETURN: 8 bit checksum of buffer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | * |
| 228 | * DESCRIPTION: Computes an 8 bit checksum of the buffer(length) and returns it. |
| 229 | * |
| 230 | ******************************************************************************/ |
| 231 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 232 | u8 acpi_tb_generate_checksum(void *buffer, u32 length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 234 | const u8 *limit; |
| 235 | const u8 *rover; |
| 236 | u8 sum = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
| 238 | if (buffer && length) { |
| 239 | /* Buffer and Length are valid */ |
| 240 | |
| 241 | limit = (u8 *) buffer + length; |
| 242 | |
| 243 | for (rover = buffer; rover < limit; rover++) { |
| 244 | sum = (u8) (sum + *rover); |
| 245 | } |
| 246 | } |
| 247 | return (sum); |
| 248 | } |
| 249 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 250 | #ifdef ACPI_OBSOLETE_FUNCTIONS |
| 251 | /******************************************************************************* |
| 252 | * |
| 253 | * FUNCTION: acpi_tb_handle_to_object |
| 254 | * |
| 255 | * PARAMETERS: table_id - Id for which the function is searching |
| 256 | * table_desc - Pointer to return the matching table |
| 257 | * descriptor. |
| 258 | * |
| 259 | * RETURN: Search the tables to find one with a matching table_id and |
| 260 | * return a pointer to that table descriptor. |
| 261 | * |
| 262 | ******************************************************************************/ |
| 263 | |
| 264 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 265 | acpi_tb_handle_to_object(u16 table_id, |
| 266 | struct acpi_table_desc ** return_table_desc) |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 267 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 268 | u32 i; |
| 269 | struct acpi_table_desc *table_desc; |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 270 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 271 | ACPI_FUNCTION_NAME("tb_handle_to_object"); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 272 | |
| 273 | for (i = 0; i < ACPI_TABLE_MAX; i++) { |
| 274 | table_desc = acpi_gbl_table_lists[i].next; |
| 275 | while (table_desc) { |
| 276 | if (table_desc->table_id == table_id) { |
| 277 | *return_table_desc = table_desc; |
| 278 | return (AE_OK); |
| 279 | } |
| 280 | |
| 281 | table_desc = table_desc->next; |
| 282 | } |
| 283 | } |
| 284 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 285 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "table_id=%X does not exist\n", |
| 286 | table_id)); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 287 | return (AE_BAD_PARAMETER); |
| 288 | } |
| 289 | #endif |