diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/acpi/tables/tbutils.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/acpi/tables/tbutils.c')
-rw-r--r-- | drivers/acpi/tables/tbutils.c | 240 |
1 files changed, 240 insertions, 0 deletions
diff --git a/drivers/acpi/tables/tbutils.c b/drivers/acpi/tables/tbutils.c new file mode 100644 index 000000000000..fede5804c783 --- /dev/null +++ b/drivers/acpi/tables/tbutils.c | |||
@@ -0,0 +1,240 @@ | |||
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 | |||
53 | /******************************************************************************* | ||
54 | * | ||
55 | * FUNCTION: acpi_tb_handle_to_object | ||
56 | * | ||
57 | * PARAMETERS: table_id - Id for which the function is searching | ||
58 | * table_desc - Pointer to return the matching table | ||
59 | * descriptor. | ||
60 | * | ||
61 | * RETURN: Search the tables to find one with a matching table_id and | ||
62 | * return a pointer to that table descriptor. | ||
63 | * | ||
64 | ******************************************************************************/ | ||
65 | #ifdef ACPI_FUTURE_USAGE | ||
66 | acpi_status | ||
67 | acpi_tb_handle_to_object ( | ||
68 | u16 table_id, | ||
69 | struct acpi_table_desc **return_table_desc) | ||
70 | { | ||
71 | u32 i; | ||
72 | struct acpi_table_desc *table_desc; | ||
73 | |||
74 | |||
75 | ACPI_FUNCTION_NAME ("tb_handle_to_object"); | ||
76 | |||
77 | |||
78 | for (i = 0; i < ACPI_TABLE_MAX; i++) { | ||
79 | table_desc = acpi_gbl_table_lists[i].next; | ||
80 | while (table_desc) { | ||
81 | if (table_desc->table_id == table_id) { | ||
82 | *return_table_desc = table_desc; | ||
83 | return (AE_OK); | ||
84 | } | ||
85 | |||
86 | table_desc = table_desc->next; | ||
87 | } | ||
88 | } | ||
89 | |||
90 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "table_id=%X does not exist\n", table_id)); | ||
91 | return (AE_BAD_PARAMETER); | ||
92 | } | ||
93 | #endif /* ACPI_FUTURE_USAGE */ | ||
94 | |||
95 | |||
96 | /******************************************************************************* | ||
97 | * | ||
98 | * FUNCTION: acpi_tb_validate_table_header | ||
99 | * | ||
100 | * PARAMETERS: table_header - Logical pointer to the table | ||
101 | * | ||
102 | * RETURN: Status | ||
103 | * | ||
104 | * DESCRIPTION: Check an ACPI table header for validity | ||
105 | * | ||
106 | * NOTE: Table pointers are validated as follows: | ||
107 | * 1) Table pointer must point to valid physical memory | ||
108 | * 2) Signature must be 4 ASCII chars, even if we don't recognize the | ||
109 | * name | ||
110 | * 3) Table must be readable for length specified in the header | ||
111 | * 4) Table checksum must be valid (with the exception of the FACS | ||
112 | * which has no checksum because it contains variable fields) | ||
113 | * | ||
114 | ******************************************************************************/ | ||
115 | |||
116 | acpi_status | ||
117 | acpi_tb_validate_table_header ( | ||
118 | struct acpi_table_header *table_header) | ||
119 | { | ||
120 | acpi_name signature; | ||
121 | |||
122 | |||
123 | ACPI_FUNCTION_NAME ("tb_validate_table_header"); | ||
124 | |||
125 | |||
126 | /* Verify that this is a valid address */ | ||
127 | |||
128 | if (!acpi_os_readable (table_header, sizeof (struct acpi_table_header))) { | ||
129 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, | ||
130 | "Cannot read table header at %p\n", table_header)); | ||
131 | return (AE_BAD_ADDRESS); | ||
132 | } | ||
133 | |||
134 | /* Ensure that the signature is 4 ASCII characters */ | ||
135 | |||
136 | ACPI_MOVE_32_TO_32 (&signature, table_header->signature); | ||
137 | if (!acpi_ut_valid_acpi_name (signature)) { | ||
138 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, | ||
139 | "Table signature at %p [%p] has invalid characters\n", | ||
140 | table_header, &signature)); | ||
141 | |||
142 | ACPI_REPORT_WARNING (("Invalid table signature found: [%4.4s]\n", | ||
143 | (char *) &signature)); | ||
144 | ACPI_DUMP_BUFFER (table_header, sizeof (struct acpi_table_header)); | ||
145 | return (AE_BAD_SIGNATURE); | ||
146 | } | ||
147 | |||
148 | /* Validate the table length */ | ||
149 | |||
150 | if (table_header->length < sizeof (struct acpi_table_header)) { | ||
151 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, | ||
152 | "Invalid length in table header %p name %4.4s\n", | ||
153 | table_header, (char *) &signature)); | ||
154 | |||
155 | ACPI_REPORT_WARNING (("Invalid table header length (0x%X) found\n", | ||
156 | (u32) table_header->length)); | ||
157 | ACPI_DUMP_BUFFER (table_header, sizeof (struct acpi_table_header)); | ||
158 | return (AE_BAD_HEADER); | ||
159 | } | ||
160 | |||
161 | return (AE_OK); | ||
162 | } | ||
163 | |||
164 | |||
165 | /******************************************************************************* | ||
166 | * | ||
167 | * FUNCTION: acpi_tb_verify_table_checksum | ||
168 | * | ||
169 | * PARAMETERS: *table_header - ACPI table to verify | ||
170 | * | ||
171 | * RETURN: 8 bit checksum of table | ||
172 | * | ||
173 | * DESCRIPTION: Does an 8 bit checksum of table and returns status. A correct | ||
174 | * table should have a checksum of 0. | ||
175 | * | ||
176 | ******************************************************************************/ | ||
177 | |||
178 | acpi_status | ||
179 | acpi_tb_verify_table_checksum ( | ||
180 | struct acpi_table_header *table_header) | ||
181 | { | ||
182 | u8 checksum; | ||
183 | acpi_status status = AE_OK; | ||
184 | |||
185 | |||
186 | ACPI_FUNCTION_TRACE ("tb_verify_table_checksum"); | ||
187 | |||
188 | |||
189 | /* Compute the checksum on the table */ | ||
190 | |||
191 | checksum = acpi_tb_checksum (table_header, table_header->length); | ||
192 | |||
193 | /* Return the appropriate exception */ | ||
194 | |||
195 | if (checksum) { | ||
196 | ACPI_REPORT_WARNING (("Invalid checksum in table [%4.4s] (%02X, sum %02X is not zero)\n", | ||
197 | table_header->signature, (u32) table_header->checksum, (u32) checksum)); | ||
198 | |||
199 | status = AE_BAD_CHECKSUM; | ||
200 | } | ||
201 | return_ACPI_STATUS (status); | ||
202 | } | ||
203 | |||
204 | |||
205 | /******************************************************************************* | ||
206 | * | ||
207 | * FUNCTION: acpi_tb_checksum | ||
208 | * | ||
209 | * PARAMETERS: Buffer - Buffer to checksum | ||
210 | * Length - Size of the buffer | ||
211 | * | ||
212 | * RETURNS 8 bit checksum of buffer | ||
213 | * | ||
214 | * DESCRIPTION: Computes an 8 bit checksum of the buffer(length) and returns it. | ||
215 | * | ||
216 | ******************************************************************************/ | ||
217 | |||
218 | u8 | ||
219 | acpi_tb_checksum ( | ||
220 | void *buffer, | ||
221 | u32 length) | ||
222 | { | ||
223 | const u8 *limit; | ||
224 | const u8 *rover; | ||
225 | u8 sum = 0; | ||
226 | |||
227 | |||
228 | if (buffer && length) { | ||
229 | /* Buffer and Length are valid */ | ||
230 | |||
231 | limit = (u8 *) buffer + length; | ||
232 | |||
233 | for (rover = buffer; rover < limit; rover++) { | ||
234 | sum = (u8) (sum + *rover); | ||
235 | } | ||
236 | } | ||
237 | return (sum); | ||
238 | } | ||
239 | |||
240 | |||