blob: 6fc1e36e6042675d112fb4c9d9d1284de52eba44 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
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
44
45#include <acpi/acpi.h>
46#include <acpi/actables.h>
47
48
49#define _COMPONENT ACPI_TABLES
50 ACPI_MODULE_NAME ("tbutils")
51
Robert Moore44f6c012005-04-18 22:49:35 -040052/* Local prototypes */
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Robert Moore44f6c012005-04-18 22:49:35 -040054#ifdef ACPI_OBSOLETE_FUNCTIONS
Linus Torvalds1da177e2005-04-16 15:20:36 -070055acpi_status
56acpi_tb_handle_to_object (
57 u16 table_id,
Robert Moore44f6c012005-04-18 22:49:35 -040058 struct acpi_table_desc **table_desc);
59#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61
62/*******************************************************************************
63 *
Robert Moore0c9938c2005-07-29 15:15:00 -070064 * FUNCTION: acpi_tb_is_table_installed
65 *
66 * PARAMETERS: new_table_desc - Descriptor for new table being installed
67 *
68 * RETURN: Status - AE_ALREADY_EXISTS if the table is already installed
69 *
70 * DESCRIPTION: Determine if an ACPI table is already installed
71 *
72 * MUTEX: Table data structures should be locked
73 *
74 ******************************************************************************/
75
76acpi_status
77acpi_tb_is_table_installed (
78 struct acpi_table_desc *new_table_desc)
79{
80 struct acpi_table_desc *table_desc;
81
82
83 ACPI_FUNCTION_TRACE ("tb_is_table_installed");
84
85
86 /* Get the list descriptor and first table descriptor */
87
88 table_desc = acpi_gbl_table_lists[new_table_desc->type].next;
89
90 /* Examine all installed tables of this type */
91
92 while (table_desc) {
93 /* Compare Revision and oem_table_id */
94
95 if ((table_desc->loaded_into_namespace) &&
96 (table_desc->pointer->revision ==
97 new_table_desc->pointer->revision) &&
98 (!ACPI_MEMCMP (table_desc->pointer->oem_table_id,
99 new_table_desc->pointer->oem_table_id, 8))) {
100 /* This table is already installed */
101
102 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES,
103 "Table [%4.4s] already installed: Rev %X oem_table_id [%8.8s]\n",
104 new_table_desc->pointer->signature,
105 new_table_desc->pointer->revision,
106 new_table_desc->pointer->oem_table_id));
107
108 new_table_desc->owner_id = table_desc->owner_id;
109 new_table_desc->installed_desc = table_desc;
110
111 return_ACPI_STATUS (AE_ALREADY_EXISTS);
112 }
113
114 /* Get next table on the list */
115
116 table_desc = table_desc->next;
117 }
118
119 return_ACPI_STATUS (AE_OK);
120}
121
122
123/*******************************************************************************
124 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 * FUNCTION: acpi_tb_validate_table_header
126 *
127 * PARAMETERS: table_header - Logical pointer to the table
128 *
129 * RETURN: Status
130 *
131 * DESCRIPTION: Check an ACPI table header for validity
132 *
133 * NOTE: Table pointers are validated as follows:
134 * 1) Table pointer must point to valid physical memory
135 * 2) Signature must be 4 ASCII chars, even if we don't recognize the
136 * name
137 * 3) Table must be readable for length specified in the header
138 * 4) Table checksum must be valid (with the exception of the FACS
139 * which has no checksum because it contains variable fields)
140 *
141 ******************************************************************************/
142
143acpi_status
144acpi_tb_validate_table_header (
145 struct acpi_table_header *table_header)
146{
147 acpi_name signature;
148
149
150 ACPI_FUNCTION_NAME ("tb_validate_table_header");
151
152
153 /* Verify that this is a valid address */
154
155 if (!acpi_os_readable (table_header, sizeof (struct acpi_table_header))) {
156 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
157 "Cannot read table header at %p\n", table_header));
Robert Moore44f6c012005-04-18 22:49:35 -0400158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 return (AE_BAD_ADDRESS);
160 }
161
162 /* Ensure that the signature is 4 ASCII characters */
163
164 ACPI_MOVE_32_TO_32 (&signature, table_header->signature);
165 if (!acpi_ut_valid_acpi_name (signature)) {
166 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
167 "Table signature at %p [%p] has invalid characters\n",
168 table_header, &signature));
169
170 ACPI_REPORT_WARNING (("Invalid table signature found: [%4.4s]\n",
171 (char *) &signature));
Robert Moore44f6c012005-04-18 22:49:35 -0400172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 ACPI_DUMP_BUFFER (table_header, sizeof (struct acpi_table_header));
174 return (AE_BAD_SIGNATURE);
175 }
176
177 /* Validate the table length */
178
179 if (table_header->length < sizeof (struct acpi_table_header)) {
180 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
181 "Invalid length in table header %p name %4.4s\n",
182 table_header, (char *) &signature));
183
184 ACPI_REPORT_WARNING (("Invalid table header length (0x%X) found\n",
185 (u32) table_header->length));
Robert Moore44f6c012005-04-18 22:49:35 -0400186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 ACPI_DUMP_BUFFER (table_header, sizeof (struct acpi_table_header));
188 return (AE_BAD_HEADER);
189 }
190
191 return (AE_OK);
192}
193
194
195/*******************************************************************************
196 *
197 * FUNCTION: acpi_tb_verify_table_checksum
198 *
199 * PARAMETERS: *table_header - ACPI table to verify
200 *
201 * RETURN: 8 bit checksum of table
202 *
203 * DESCRIPTION: Does an 8 bit checksum of table and returns status. A correct
204 * table should have a checksum of 0.
205 *
206 ******************************************************************************/
207
208acpi_status
209acpi_tb_verify_table_checksum (
210 struct acpi_table_header *table_header)
211{
212 u8 checksum;
213 acpi_status status = AE_OK;
214
215
216 ACPI_FUNCTION_TRACE ("tb_verify_table_checksum");
217
218
219 /* Compute the checksum on the table */
220
Robert Moore0c9938c2005-07-29 15:15:00 -0700221 checksum = acpi_tb_generate_checksum (table_header, table_header->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 /* Return the appropriate exception */
224
225 if (checksum) {
Robert Moore44f6c012005-04-18 22:49:35 -0400226 ACPI_REPORT_WARNING ((
227 "Invalid checksum in table [%4.4s] (%02X, sum %02X is not zero)\n",
228 table_header->signature, (u32) table_header->checksum,
229 (u32) checksum));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231 status = AE_BAD_CHECKSUM;
232 }
233 return_ACPI_STATUS (status);
234}
235
236
237/*******************************************************************************
238 *
Robert Moore0c9938c2005-07-29 15:15:00 -0700239 * FUNCTION: acpi_tb_generate_checksum
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 *
241 * PARAMETERS: Buffer - Buffer to checksum
242 * Length - Size of the buffer
243 *
Robert Moore44f6c012005-04-18 22:49:35 -0400244 * RETURN: 8 bit checksum of buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 *
246 * DESCRIPTION: Computes an 8 bit checksum of the buffer(length) and returns it.
247 *
248 ******************************************************************************/
249
250u8
Robert Moore0c9938c2005-07-29 15:15:00 -0700251acpi_tb_generate_checksum (
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 void *buffer,
253 u32 length)
254{
255 const u8 *limit;
256 const u8 *rover;
257 u8 sum = 0;
258
259
260 if (buffer && length) {
261 /* Buffer and Length are valid */
262
263 limit = (u8 *) buffer + length;
264
265 for (rover = buffer; rover < limit; rover++) {
266 sum = (u8) (sum + *rover);
267 }
268 }
269 return (sum);
270}
271
272
Robert Moore44f6c012005-04-18 22:49:35 -0400273#ifdef ACPI_OBSOLETE_FUNCTIONS
274/*******************************************************************************
275 *
276 * FUNCTION: acpi_tb_handle_to_object
277 *
278 * PARAMETERS: table_id - Id for which the function is searching
279 * table_desc - Pointer to return the matching table
280 * descriptor.
281 *
282 * RETURN: Search the tables to find one with a matching table_id and
283 * return a pointer to that table descriptor.
284 *
285 ******************************************************************************/
286
287acpi_status
288acpi_tb_handle_to_object (
289 u16 table_id,
290 struct acpi_table_desc **return_table_desc)
291{
292 u32 i;
293 struct acpi_table_desc *table_desc;
294
295
296 ACPI_FUNCTION_NAME ("tb_handle_to_object");
297
298
299 for (i = 0; i < ACPI_TABLE_MAX; i++) {
300 table_desc = acpi_gbl_table_lists[i].next;
301 while (table_desc) {
302 if (table_desc->table_id == table_id) {
303 *return_table_desc = table_desc;
304 return (AE_OK);
305 }
306
307 table_desc = table_desc->next;
308 }
309 }
310
311 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "table_id=%X does not exist\n", table_id));
312 return (AE_BAD_PARAMETER);
313}
314#endif
315
316