Merge master.kernel.org:/pub/scm/linux/kernel/git/dtor/input
[deliverable/linux.git] / drivers / acpi / tables / tbutils.c
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
44
45 #include <acpi/acpi.h>
46 #include <acpi/actables.h>
47
48
49 #define _COMPONENT ACPI_TABLES
50 ACPI_MODULE_NAME ("tbutils")
51
52 /* Local prototypes */
53
54 #ifdef ACPI_OBSOLETE_FUNCTIONS
55 acpi_status
56 acpi_tb_handle_to_object (
57 u16 table_id,
58 struct acpi_table_desc **table_desc);
59 #endif
60
61
62 /*******************************************************************************
63 *
64 * FUNCTION: acpi_tb_validate_table_header
65 *
66 * PARAMETERS: table_header - Logical pointer to the table
67 *
68 * RETURN: Status
69 *
70 * DESCRIPTION: Check an ACPI table header for validity
71 *
72 * NOTE: Table pointers are validated as follows:
73 * 1) Table pointer must point to valid physical memory
74 * 2) Signature must be 4 ASCII chars, even if we don't recognize the
75 * name
76 * 3) Table must be readable for length specified in the header
77 * 4) Table checksum must be valid (with the exception of the FACS
78 * which has no checksum because it contains variable fields)
79 *
80 ******************************************************************************/
81
82 acpi_status
83 acpi_tb_validate_table_header (
84 struct acpi_table_header *table_header)
85 {
86 acpi_name signature;
87
88
89 ACPI_FUNCTION_NAME ("tb_validate_table_header");
90
91
92 /* Verify that this is a valid address */
93
94 if (!acpi_os_readable (table_header, sizeof (struct acpi_table_header))) {
95 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
96 "Cannot read table header at %p\n", table_header));
97
98 return (AE_BAD_ADDRESS);
99 }
100
101 /* Ensure that the signature is 4 ASCII characters */
102
103 ACPI_MOVE_32_TO_32 (&signature, table_header->signature);
104 if (!acpi_ut_valid_acpi_name (signature)) {
105 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
106 "Table signature at %p [%p] has invalid characters\n",
107 table_header, &signature));
108
109 ACPI_REPORT_WARNING (("Invalid table signature found: [%4.4s]\n",
110 (char *) &signature));
111
112 ACPI_DUMP_BUFFER (table_header, sizeof (struct acpi_table_header));
113 return (AE_BAD_SIGNATURE);
114 }
115
116 /* Validate the table length */
117
118 if (table_header->length < sizeof (struct acpi_table_header)) {
119 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
120 "Invalid length in table header %p name %4.4s\n",
121 table_header, (char *) &signature));
122
123 ACPI_REPORT_WARNING (("Invalid table header length (0x%X) found\n",
124 (u32) table_header->length));
125
126 ACPI_DUMP_BUFFER (table_header, sizeof (struct acpi_table_header));
127 return (AE_BAD_HEADER);
128 }
129
130 return (AE_OK);
131 }
132
133
134 /*******************************************************************************
135 *
136 * FUNCTION: acpi_tb_verify_table_checksum
137 *
138 * PARAMETERS: *table_header - ACPI table to verify
139 *
140 * RETURN: 8 bit checksum of table
141 *
142 * DESCRIPTION: Does an 8 bit checksum of table and returns status. A correct
143 * table should have a checksum of 0.
144 *
145 ******************************************************************************/
146
147 acpi_status
148 acpi_tb_verify_table_checksum (
149 struct acpi_table_header *table_header)
150 {
151 u8 checksum;
152 acpi_status status = AE_OK;
153
154
155 ACPI_FUNCTION_TRACE ("tb_verify_table_checksum");
156
157
158 /* Compute the checksum on the table */
159
160 checksum = acpi_tb_checksum (table_header, table_header->length);
161
162 /* Return the appropriate exception */
163
164 if (checksum) {
165 ACPI_REPORT_WARNING ((
166 "Invalid checksum in table [%4.4s] (%02X, sum %02X is not zero)\n",
167 table_header->signature, (u32) table_header->checksum,
168 (u32) checksum));
169
170 status = AE_BAD_CHECKSUM;
171 }
172 return_ACPI_STATUS (status);
173 }
174
175
176 /*******************************************************************************
177 *
178 * FUNCTION: acpi_tb_checksum
179 *
180 * PARAMETERS: Buffer - Buffer to checksum
181 * Length - Size of the buffer
182 *
183 * RETURN: 8 bit checksum of buffer
184 *
185 * DESCRIPTION: Computes an 8 bit checksum of the buffer(length) and returns it.
186 *
187 ******************************************************************************/
188
189 u8
190 acpi_tb_checksum (
191 void *buffer,
192 u32 length)
193 {
194 const u8 *limit;
195 const u8 *rover;
196 u8 sum = 0;
197
198
199 if (buffer && length) {
200 /* Buffer and Length are valid */
201
202 limit = (u8 *) buffer + length;
203
204 for (rover = buffer; rover < limit; rover++) {
205 sum = (u8) (sum + *rover);
206 }
207 }
208 return (sum);
209 }
210
211
212 #ifdef ACPI_OBSOLETE_FUNCTIONS
213 /*******************************************************************************
214 *
215 * FUNCTION: acpi_tb_handle_to_object
216 *
217 * PARAMETERS: table_id - Id for which the function is searching
218 * table_desc - Pointer to return the matching table
219 * descriptor.
220 *
221 * RETURN: Search the tables to find one with a matching table_id and
222 * return a pointer to that table descriptor.
223 *
224 ******************************************************************************/
225
226 acpi_status
227 acpi_tb_handle_to_object (
228 u16 table_id,
229 struct acpi_table_desc **return_table_desc)
230 {
231 u32 i;
232 struct acpi_table_desc *table_desc;
233
234
235 ACPI_FUNCTION_NAME ("tb_handle_to_object");
236
237
238 for (i = 0; i < ACPI_TABLE_MAX; i++) {
239 table_desc = acpi_gbl_table_lists[i].next;
240 while (table_desc) {
241 if (table_desc->table_id == table_id) {
242 *return_table_desc = table_desc;
243 return (AE_OK);
244 }
245
246 table_desc = table_desc->next;
247 }
248 }
249
250 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "table_id=%X does not exist\n", table_id));
251 return (AE_BAD_PARAMETER);
252 }
253 #endif
254
255
This page took 0.078793 seconds and 6 git commands to generate.