Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: tbutils - Table manipulation utilities | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
4a90c7e8 | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
1da177e4 LT |
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 | ||
1da177e4 LT |
44 | #include <acpi/acpi.h> |
45 | #include <acpi/actables.h> | |
46 | ||
1da177e4 | 47 | #define _COMPONENT ACPI_TABLES |
4be44fcd | 48 | ACPI_MODULE_NAME("tbutils") |
1da177e4 | 49 | |
44f6c012 | 50 | /* Local prototypes */ |
44f6c012 | 51 | #ifdef ACPI_OBSOLETE_FUNCTIONS |
1da177e4 | 52 | acpi_status |
4be44fcd | 53 | acpi_tb_handle_to_object(u16 table_id, struct acpi_table_desc **table_desc); |
44f6c012 | 54 | #endif |
1da177e4 | 55 | |
0c9938cc RM |
56 | /******************************************************************************* |
57 | * | |
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 | ||
4be44fcd | 70 | acpi_status acpi_tb_is_table_installed(struct acpi_table_desc *new_table_desc) |
0c9938cc | 71 | { |
4be44fcd | 72 | struct acpi_table_desc *table_desc; |
0c9938cc | 73 | |
4be44fcd | 74 | ACPI_FUNCTION_TRACE("tb_is_table_installed"); |
0c9938cc RM |
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) { | |
a18ecf41 BM |
83 | /* |
84 | * If the table lengths match, perform a full bytewise compare. This | |
85 | * means that we will allow tables with duplicate oem_table_id(s), as | |
86 | * long as the tables are different in some way. | |
87 | * | |
88 | * Checking if the table has been loaded into the namespace means that | |
89 | * we don't check for duplicate tables during the initial installation | |
90 | * of tables within the RSDT/XSDT. | |
91 | */ | |
0c9938cc | 92 | if ((table_desc->loaded_into_namespace) && |
a18ecf41 BM |
93 | (table_desc->pointer->length == |
94 | new_table_desc->pointer->length) | |
95 | && | |
96 | (!ACPI_MEMCMP | |
0897831b BM |
97 | (table_desc->pointer, new_table_desc->pointer, |
98 | new_table_desc->pointer->length))) { | |
a18ecf41 | 99 | /* Match: this table is already installed */ |
0c9938cc | 100 | |
4be44fcd LB |
101 | ACPI_DEBUG_PRINT((ACPI_DB_TABLES, |
102 | "Table [%4.4s] already installed: Rev %X oem_table_id [%8.8s]\n", | |
103 | new_table_desc->pointer->signature, | |
104 | new_table_desc->pointer->revision, | |
105 | new_table_desc->pointer-> | |
106 | oem_table_id)); | |
0c9938cc | 107 | |
4be44fcd | 108 | new_table_desc->owner_id = table_desc->owner_id; |
0c9938cc RM |
109 | new_table_desc->installed_desc = table_desc; |
110 | ||
4be44fcd | 111 | return_ACPI_STATUS(AE_ALREADY_EXISTS); |
0c9938cc RM |
112 | } |
113 | ||
114 | /* Get next table on the list */ | |
115 | ||
116 | table_desc = table_desc->next; | |
117 | } | |
118 | ||
4be44fcd | 119 | return_ACPI_STATUS(AE_OK); |
0c9938cc RM |
120 | } |
121 | ||
1da177e4 LT |
122 | /******************************************************************************* |
123 | * | |
124 | * FUNCTION: acpi_tb_validate_table_header | |
125 | * | |
126 | * PARAMETERS: table_header - Logical pointer to the table | |
127 | * | |
128 | * RETURN: Status | |
129 | * | |
130 | * DESCRIPTION: Check an ACPI table header for validity | |
131 | * | |
132 | * NOTE: Table pointers are validated as follows: | |
133 | * 1) Table pointer must point to valid physical memory | |
134 | * 2) Signature must be 4 ASCII chars, even if we don't recognize the | |
135 | * name | |
136 | * 3) Table must be readable for length specified in the header | |
137 | * 4) Table checksum must be valid (with the exception of the FACS | |
138 | * which has no checksum because it contains variable fields) | |
139 | * | |
140 | ******************************************************************************/ | |
141 | ||
142 | acpi_status | |
4be44fcd | 143 | acpi_tb_validate_table_header(struct acpi_table_header *table_header) |
1da177e4 | 144 | { |
4be44fcd | 145 | acpi_name signature; |
1da177e4 | 146 | |
4a90c7e8 | 147 | ACPI_FUNCTION_ENTRY(); |
1da177e4 LT |
148 | |
149 | /* Verify that this is a valid address */ | |
150 | ||
4be44fcd | 151 | if (!acpi_os_readable(table_header, sizeof(struct acpi_table_header))) { |
b8e4d893 BM |
152 | ACPI_ERROR((AE_INFO, |
153 | "Cannot read table header at %p", table_header)); | |
44f6c012 | 154 | |
1da177e4 LT |
155 | return (AE_BAD_ADDRESS); |
156 | } | |
157 | ||
158 | /* Ensure that the signature is 4 ASCII characters */ | |
159 | ||
4be44fcd LB |
160 | ACPI_MOVE_32_TO_32(&signature, table_header->signature); |
161 | if (!acpi_ut_valid_acpi_name(signature)) { | |
b8e4d893 BM |
162 | ACPI_ERROR((AE_INFO, |
163 | "Table signature at %p [%p] has invalid characters", | |
164 | table_header, &signature)); | |
1da177e4 | 165 | |
b8e4d893 BM |
166 | ACPI_WARNING((AE_INFO, "Invalid table signature found: [%4.4s]", |
167 | ACPI_CAST_PTR(char, &signature))); | |
44f6c012 | 168 | |
4be44fcd LB |
169 | ACPI_DUMP_BUFFER(table_header, |
170 | sizeof(struct acpi_table_header)); | |
1da177e4 LT |
171 | return (AE_BAD_SIGNATURE); |
172 | } | |
173 | ||
174 | /* Validate the table length */ | |
175 | ||
4be44fcd | 176 | if (table_header->length < sizeof(struct acpi_table_header)) { |
b8e4d893 BM |
177 | ACPI_ERROR((AE_INFO, |
178 | "Invalid length in table header %p name %4.4s", | |
179 | table_header, (char *)&signature)); | |
1da177e4 | 180 | |
b8e4d893 BM |
181 | ACPI_WARNING((AE_INFO, |
182 | "Invalid table header length (0x%X) found", | |
183 | (u32) table_header->length)); | |
44f6c012 | 184 | |
4be44fcd LB |
185 | ACPI_DUMP_BUFFER(table_header, |
186 | sizeof(struct acpi_table_header)); | |
1da177e4 LT |
187 | return (AE_BAD_HEADER); |
188 | } | |
189 | ||
190 | return (AE_OK); | |
191 | } | |
192 | ||
1da177e4 LT |
193 | /******************************************************************************* |
194 | * | |
195 | * FUNCTION: acpi_tb_verify_table_checksum | |
196 | * | |
197 | * PARAMETERS: *table_header - ACPI table to verify | |
198 | * | |
199 | * RETURN: 8 bit checksum of table | |
200 | * | |
201 | * DESCRIPTION: Does an 8 bit checksum of table and returns status. A correct | |
202 | * table should have a checksum of 0. | |
203 | * | |
204 | ******************************************************************************/ | |
205 | ||
206 | acpi_status | |
4be44fcd | 207 | acpi_tb_verify_table_checksum(struct acpi_table_header * table_header) |
1da177e4 | 208 | { |
4be44fcd LB |
209 | u8 checksum; |
210 | acpi_status status = AE_OK; | |
1da177e4 | 211 | |
4be44fcd | 212 | ACPI_FUNCTION_TRACE("tb_verify_table_checksum"); |
1da177e4 LT |
213 | |
214 | /* Compute the checksum on the table */ | |
215 | ||
4be44fcd LB |
216 | checksum = |
217 | acpi_tb_generate_checksum(table_header, table_header->length); | |
1da177e4 LT |
218 | |
219 | /* Return the appropriate exception */ | |
220 | ||
221 | if (checksum) { | |
b8e4d893 BM |
222 | ACPI_WARNING((AE_INFO, |
223 | "Invalid checksum in table [%4.4s] (%02X, sum %02X is not zero)", | |
224 | table_header->signature, | |
225 | (u32) table_header->checksum, (u32) checksum)); | |
1da177e4 LT |
226 | |
227 | status = AE_BAD_CHECKSUM; | |
228 | } | |
4be44fcd | 229 | return_ACPI_STATUS(status); |
1da177e4 LT |
230 | } |
231 | ||
1da177e4 LT |
232 | /******************************************************************************* |
233 | * | |
0c9938cc | 234 | * FUNCTION: acpi_tb_generate_checksum |
1da177e4 LT |
235 | * |
236 | * PARAMETERS: Buffer - Buffer to checksum | |
237 | * Length - Size of the buffer | |
238 | * | |
44f6c012 | 239 | * RETURN: 8 bit checksum of buffer |
1da177e4 LT |
240 | * |
241 | * DESCRIPTION: Computes an 8 bit checksum of the buffer(length) and returns it. | |
242 | * | |
243 | ******************************************************************************/ | |
244 | ||
4be44fcd | 245 | u8 acpi_tb_generate_checksum(void *buffer, u32 length) |
1da177e4 | 246 | { |
c51a4de8 BM |
247 | u8 *end_buffer; |
248 | u8 *rover; | |
4be44fcd | 249 | u8 sum = 0; |
1da177e4 LT |
250 | |
251 | if (buffer && length) { | |
252 | /* Buffer and Length are valid */ | |
253 | ||
c51a4de8 | 254 | end_buffer = ACPI_ADD_PTR(u8, buffer, length); |
1da177e4 | 255 | |
c51a4de8 | 256 | for (rover = buffer; rover < end_buffer; rover++) { |
1da177e4 LT |
257 | sum = (u8) (sum + *rover); |
258 | } | |
259 | } | |
260 | return (sum); | |
261 | } | |
262 | ||
44f6c012 RM |
263 | #ifdef ACPI_OBSOLETE_FUNCTIONS |
264 | /******************************************************************************* | |
265 | * | |
266 | * FUNCTION: acpi_tb_handle_to_object | |
267 | * | |
268 | * PARAMETERS: table_id - Id for which the function is searching | |
269 | * table_desc - Pointer to return the matching table | |
270 | * descriptor. | |
271 | * | |
272 | * RETURN: Search the tables to find one with a matching table_id and | |
273 | * return a pointer to that table descriptor. | |
274 | * | |
275 | ******************************************************************************/ | |
276 | ||
277 | acpi_status | |
4be44fcd LB |
278 | acpi_tb_handle_to_object(u16 table_id, |
279 | struct acpi_table_desc ** return_table_desc) | |
44f6c012 | 280 | { |
4be44fcd LB |
281 | u32 i; |
282 | struct acpi_table_desc *table_desc; | |
44f6c012 | 283 | |
4be44fcd | 284 | ACPI_FUNCTION_NAME("tb_handle_to_object"); |
44f6c012 RM |
285 | |
286 | for (i = 0; i < ACPI_TABLE_MAX; i++) { | |
287 | table_desc = acpi_gbl_table_lists[i].next; | |
288 | while (table_desc) { | |
289 | if (table_desc->table_id == table_id) { | |
290 | *return_table_desc = table_desc; | |
291 | return (AE_OK); | |
292 | } | |
293 | ||
294 | table_desc = table_desc->next; | |
295 | } | |
296 | } | |
297 | ||
b8e4d893 | 298 | ACPI_ERROR((AE_INFO, "table_id=%X does not exist", table_id)); |
44f6c012 RM |
299 | return (AE_BAD_PARAMETER); |
300 | } | |
301 | #endif |