[PATCH] W1: w1_netlink: New init/fini netlink callbacks.
[linux-2.6/verdex.git] / drivers / acpi / tables / tbutils.c
blob4b2fbb592f4933cf8b8138efe64f558c194a96fe
1 /******************************************************************************
3 * Module Name: tbutils - Table manipulation utilities
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
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.
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.
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.
44 #include <acpi/acpi.h>
45 #include <acpi/actables.h>
47 #define _COMPONENT ACPI_TABLES
48 ACPI_MODULE_NAME("tbutils")
50 /* Local prototypes */
51 #ifdef ACPI_OBSOLETE_FUNCTIONS
52 acpi_status
53 acpi_tb_handle_to_object(u16 table_id, struct acpi_table_desc **table_desc);
54 #endif
56 /*******************************************************************************
58 * FUNCTION: acpi_tb_is_table_installed
60 * PARAMETERS: new_table_desc - Descriptor for new table being installed
62 * RETURN: Status - AE_ALREADY_EXISTS if the table is already installed
64 * DESCRIPTION: Determine if an ACPI table is already installed
66 * MUTEX: Table data structures should be locked
68 ******************************************************************************/
70 acpi_status acpi_tb_is_table_installed(struct acpi_table_desc *new_table_desc)
72 struct acpi_table_desc *table_desc;
74 ACPI_FUNCTION_TRACE("tb_is_table_installed");
76 /* Get the list descriptor and first table descriptor */
78 table_desc = acpi_gbl_table_lists[new_table_desc->type].next;
80 /* Examine all installed tables of this type */
82 while (table_desc) {
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.
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.
92 if ((table_desc->loaded_into_namespace) &&
93 (table_desc->pointer->length ==
94 new_table_desc->pointer->length)
96 (!ACPI_MEMCMP
97 ((const char *)table_desc->pointer,
98 (const char *)new_table_desc->pointer,
99 (acpi_size) new_table_desc->pointer->length))) {
100 /* Match: this table is already installed */
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->
107 oem_table_id));
109 new_table_desc->owner_id = table_desc->owner_id;
110 new_table_desc->installed_desc = table_desc;
112 return_ACPI_STATUS(AE_ALREADY_EXISTS);
115 /* Get next table on the list */
117 table_desc = table_desc->next;
120 return_ACPI_STATUS(AE_OK);
123 /*******************************************************************************
125 * FUNCTION: acpi_tb_validate_table_header
127 * PARAMETERS: table_header - Logical pointer to the table
129 * RETURN: Status
131 * DESCRIPTION: Check an ACPI table header for validity
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)
141 ******************************************************************************/
143 acpi_status
144 acpi_tb_validate_table_header(struct acpi_table_header *table_header)
146 acpi_name signature;
148 ACPI_FUNCTION_NAME("tb_validate_table_header");
150 /* Verify that this is a valid address */
152 if (!acpi_os_readable(table_header, sizeof(struct acpi_table_header))) {
153 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
154 "Cannot read table header at %p\n",
155 table_header));
157 return (AE_BAD_ADDRESS);
160 /* Ensure that the signature is 4 ASCII characters */
162 ACPI_MOVE_32_TO_32(&signature, table_header->signature);
163 if (!acpi_ut_valid_acpi_name(signature)) {
164 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
165 "Table signature at %p [%p] has invalid characters\n",
166 table_header, &signature));
168 ACPI_REPORT_WARNING(("Invalid table signature found: [%4.4s]\n",
169 (char *)&signature));
171 ACPI_DUMP_BUFFER(table_header,
172 sizeof(struct acpi_table_header));
173 return (AE_BAD_SIGNATURE);
176 /* Validate the table length */
178 if (table_header->length < sizeof(struct acpi_table_header)) {
179 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
180 "Invalid length in table header %p name %4.4s\n",
181 table_header, (char *)&signature));
183 ACPI_REPORT_WARNING(("Invalid table header length (0x%X) found\n", (u32) table_header->length));
185 ACPI_DUMP_BUFFER(table_header,
186 sizeof(struct acpi_table_header));
187 return (AE_BAD_HEADER);
190 return (AE_OK);
193 /*******************************************************************************
195 * FUNCTION: acpi_tb_verify_table_checksum
197 * PARAMETERS: *table_header - ACPI table to verify
199 * RETURN: 8 bit checksum of table
201 * DESCRIPTION: Does an 8 bit checksum of table and returns status. A correct
202 * table should have a checksum of 0.
204 ******************************************************************************/
206 acpi_status
207 acpi_tb_verify_table_checksum(struct acpi_table_header * table_header)
209 u8 checksum;
210 acpi_status status = AE_OK;
212 ACPI_FUNCTION_TRACE("tb_verify_table_checksum");
214 /* Compute the checksum on the table */
216 checksum =
217 acpi_tb_generate_checksum(table_header, table_header->length);
219 /* Return the appropriate exception */
221 if (checksum) {
222 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));
224 status = AE_BAD_CHECKSUM;
226 return_ACPI_STATUS(status);
229 /*******************************************************************************
231 * FUNCTION: acpi_tb_generate_checksum
233 * PARAMETERS: Buffer - Buffer to checksum
234 * Length - Size of the buffer
236 * RETURN: 8 bit checksum of buffer
238 * DESCRIPTION: Computes an 8 bit checksum of the buffer(length) and returns it.
240 ******************************************************************************/
242 u8 acpi_tb_generate_checksum(void *buffer, u32 length)
244 const u8 *limit;
245 const u8 *rover;
246 u8 sum = 0;
248 if (buffer && length) {
249 /* Buffer and Length are valid */
251 limit = (u8 *) buffer + length;
253 for (rover = buffer; rover < limit; rover++) {
254 sum = (u8) (sum + *rover);
257 return (sum);
260 #ifdef ACPI_OBSOLETE_FUNCTIONS
261 /*******************************************************************************
263 * FUNCTION: acpi_tb_handle_to_object
265 * PARAMETERS: table_id - Id for which the function is searching
266 * table_desc - Pointer to return the matching table
267 * descriptor.
269 * RETURN: Search the tables to find one with a matching table_id and
270 * return a pointer to that table descriptor.
272 ******************************************************************************/
274 acpi_status
275 acpi_tb_handle_to_object(u16 table_id,
276 struct acpi_table_desc ** return_table_desc)
278 u32 i;
279 struct acpi_table_desc *table_desc;
281 ACPI_FUNCTION_NAME("tb_handle_to_object");
283 for (i = 0; i < ACPI_TABLE_MAX; i++) {
284 table_desc = acpi_gbl_table_lists[i].next;
285 while (table_desc) {
286 if (table_desc->table_id == table_id) {
287 *return_table_desc = table_desc;
288 return (AE_OK);
291 table_desc = table_desc->next;
295 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "table_id=%X does not exist\n",
296 table_id));
297 return (AE_BAD_PARAMETER);
299 #endif