[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / acpi / tables / tbinstal.c
blob85d5bb01022c1be435e86cf959fe89a8075b479b
1 /******************************************************************************
3 * Module Name: tbinstal - ACPI table installation and removal
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.
45 #include <acpi/acpi.h>
46 #include <acpi/actables.h>
49 #define _COMPONENT ACPI_TABLES
50 ACPI_MODULE_NAME ("tbinstal")
53 /*******************************************************************************
55 * FUNCTION: acpi_tb_match_signature
57 * PARAMETERS: Signature - Table signature to match
58 * table_info - Return data
60 * RETURN: Status
62 * DESCRIPTION: Compare signature against the list of "ACPI-subsystem-owned"
63 * tables (DSDT/FADT/SSDT, etc.) Returns the table_type_iD on match.
65 ******************************************************************************/
67 acpi_status
68 acpi_tb_match_signature (
69 char *signature,
70 struct acpi_table_desc *table_info,
71 u8 search_type)
73 acpi_native_uint i;
76 ACPI_FUNCTION_TRACE ("tb_match_signature");
80 * Search for a signature match among the known table types
82 for (i = 0; i < NUM_ACPI_TABLE_TYPES; i++) {
83 if (!(acpi_gbl_table_data[i].flags & search_type)) {
84 continue;
87 if (!ACPI_STRNCMP (signature, acpi_gbl_table_data[i].signature,
88 acpi_gbl_table_data[i].sig_length)) {
89 /* Found a signature match, return index if requested */
91 if (table_info) {
92 table_info->type = (u8) i;
95 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
96 "Table [%4.4s] is an ACPI table consumed by the core subsystem\n",
97 (char *) acpi_gbl_table_data[i].signature));
99 return_ACPI_STATUS (AE_OK);
103 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
104 "Table [%4.4s] is not an ACPI table consumed by the core subsystem - ignored\n",
105 (char *) signature));
107 return_ACPI_STATUS (AE_TABLE_NOT_SUPPORTED);
111 /*******************************************************************************
113 * FUNCTION: acpi_tb_install_table
115 * PARAMETERS: table_info - Return value from acpi_tb_get_table_body
117 * RETURN: Status
119 * DESCRIPTION: Load and validate all tables other than the RSDT. The RSDT must
120 * already be loaded and validated.
121 * Install the table into the global data structs.
123 ******************************************************************************/
125 acpi_status
126 acpi_tb_install_table (
127 struct acpi_table_desc *table_info)
129 acpi_status status;
131 ACPI_FUNCTION_TRACE ("tb_install_table");
134 /* Lock tables while installing */
136 status = acpi_ut_acquire_mutex (ACPI_MTX_TABLES);
137 if (ACPI_FAILURE (status)) {
138 ACPI_REPORT_ERROR (("Could not acquire table mutex for [%4.4s], %s\n",
139 table_info->pointer->signature, acpi_format_exception (status)));
140 return_ACPI_STATUS (status);
143 /* Install the table into the global data structure */
145 status = acpi_tb_init_table_descriptor (table_info->type, table_info);
146 if (ACPI_FAILURE (status)) {
147 ACPI_REPORT_ERROR (("Could not install ACPI table [%4.4s], %s\n",
148 table_info->pointer->signature, acpi_format_exception (status)));
151 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "%s located at %p\n",
152 acpi_gbl_table_data[table_info->type].name, table_info->pointer));
154 (void) acpi_ut_release_mutex (ACPI_MTX_TABLES);
155 return_ACPI_STATUS (status);
159 /*******************************************************************************
161 * FUNCTION: acpi_tb_recognize_table
163 * PARAMETERS: table_info - Return value from acpi_tb_get_table_body
165 * RETURN: Status
167 * DESCRIPTION: Check a table signature for a match against known table types
169 * NOTE: All table pointers are validated as follows:
170 * 1) Table pointer must point to valid physical memory
171 * 2) Signature must be 4 ASCII chars, even if we don't recognize the
172 * name
173 * 3) Table must be readable for length specified in the header
174 * 4) Table checksum must be valid (with the exception of the FACS
175 * which has no checksum for some odd reason)
177 ******************************************************************************/
179 acpi_status
180 acpi_tb_recognize_table (
181 struct acpi_table_desc *table_info,
182 u8 search_type)
184 struct acpi_table_header *table_header;
185 acpi_status status;
188 ACPI_FUNCTION_TRACE ("tb_recognize_table");
191 /* Ensure that we have a valid table pointer */
193 table_header = (struct acpi_table_header *) table_info->pointer;
194 if (!table_header) {
195 return_ACPI_STATUS (AE_BAD_PARAMETER);
199 * We only "recognize" a limited number of ACPI tables -- namely, the
200 * ones that are used by the subsystem (DSDT, FADT, etc.)
202 * An AE_TABLE_NOT_SUPPORTED means that the table was not recognized.
203 * This can be any one of many valid ACPI tables, it just isn't one of
204 * the tables that is consumed by the core subsystem
206 status = acpi_tb_match_signature (table_header->signature, table_info, search_type);
207 if (ACPI_FAILURE (status)) {
208 return_ACPI_STATUS (status);
211 status = acpi_tb_validate_table_header (table_header);
212 if (ACPI_FAILURE (status)) {
213 return_ACPI_STATUS (status);
216 /* Return the table type and length via the info struct */
218 table_info->length = (acpi_size) table_header->length;
220 return_ACPI_STATUS (status);
224 /*******************************************************************************
226 * FUNCTION: acpi_tb_init_table_descriptor
228 * PARAMETERS: table_type - The type of the table
229 * table_info - A table info struct
231 * RETURN: None.
233 * DESCRIPTION: Install a table into the global data structs.
235 ******************************************************************************/
237 acpi_status
238 acpi_tb_init_table_descriptor (
239 acpi_table_type table_type,
240 struct acpi_table_desc *table_info)
242 struct acpi_table_list *list_head;
243 struct acpi_table_desc *table_desc;
246 ACPI_FUNCTION_TRACE_U32 ("tb_init_table_descriptor", table_type);
249 /* Allocate a descriptor for this table */
251 table_desc = ACPI_MEM_CALLOCATE (sizeof (struct acpi_table_desc));
252 if (!table_desc) {
253 return_ACPI_STATUS (AE_NO_MEMORY);
257 * Install the table into the global data structure
259 list_head = &acpi_gbl_table_lists[table_type];
262 * Two major types of tables: 1) Only one instance is allowed. This
263 * includes most ACPI tables such as the DSDT. 2) Multiple instances of
264 * the table are allowed. This includes SSDT and PSDTs.
266 if (ACPI_IS_SINGLE_TABLE (acpi_gbl_table_data[table_type].flags)) {
268 * Only one table allowed, and a table has alread been installed
269 * at this location, so return an error.
271 if (list_head->next) {
272 ACPI_MEM_FREE (table_desc);
273 return_ACPI_STATUS (AE_ALREADY_EXISTS);
276 table_desc->next = list_head->next;
277 list_head->next = table_desc;
279 if (table_desc->next) {
280 table_desc->next->prev = table_desc;
283 list_head->count++;
285 else {
287 * Link the new table in to the list of tables of this type.
288 * Insert at the end of the list, order IS IMPORTANT.
290 * table_desc->Prev & Next are already NULL from calloc()
292 list_head->count++;
294 if (!list_head->next) {
295 list_head->next = table_desc;
297 else {
298 table_desc->next = list_head->next;
300 while (table_desc->next->next) {
301 table_desc->next = table_desc->next->next;
304 table_desc->next->next = table_desc;
305 table_desc->prev = table_desc->next;
306 table_desc->next = NULL;
310 /* Finish initialization of the table descriptor */
312 table_desc->type = (u8) table_type;
313 table_desc->pointer = table_info->pointer;
314 table_desc->length = table_info->length;
315 table_desc->allocation = table_info->allocation;
316 table_desc->aml_start = (u8 *) (table_desc->pointer + 1),
317 table_desc->aml_length = (u32) (table_desc->length -
318 (u32) sizeof (struct acpi_table_header));
319 table_desc->table_id = acpi_ut_allocate_owner_id (ACPI_OWNER_TYPE_TABLE);
320 table_desc->loaded_into_namespace = FALSE;
323 * Set the appropriate global pointer (if there is one) to point to the
324 * newly installed table
326 if (acpi_gbl_table_data[table_type].global_ptr) {
327 *(acpi_gbl_table_data[table_type].global_ptr) = table_info->pointer;
330 /* Return Data */
332 table_info->table_id = table_desc->table_id;
333 table_info->installed_desc = table_desc;
335 return_ACPI_STATUS (AE_OK);
339 /*******************************************************************************
341 * FUNCTION: acpi_tb_delete_all_tables
343 * PARAMETERS: None.
345 * RETURN: None.
347 * DESCRIPTION: Delete all internal ACPI tables
349 ******************************************************************************/
351 void
352 acpi_tb_delete_all_tables (void)
354 acpi_table_type type;
358 * Free memory allocated for ACPI tables
359 * Memory can either be mapped or allocated
361 for (type = 0; type < NUM_ACPI_TABLE_TYPES; type++) {
362 acpi_tb_delete_tables_by_type (type);
367 /*******************************************************************************
369 * FUNCTION: acpi_tb_delete_tables_by_type
371 * PARAMETERS: Type - The table type to be deleted
373 * RETURN: None.
375 * DESCRIPTION: Delete an internal ACPI table
376 * Locks the ACPI table mutex
378 ******************************************************************************/
380 void
381 acpi_tb_delete_tables_by_type (
382 acpi_table_type type)
384 struct acpi_table_desc *table_desc;
385 u32 count;
386 u32 i;
389 ACPI_FUNCTION_TRACE_U32 ("tb_delete_tables_by_type", type);
392 if (type > ACPI_TABLE_MAX) {
393 return_VOID;
396 if (ACPI_FAILURE (acpi_ut_acquire_mutex (ACPI_MTX_TABLES))) {
397 return;
400 /* Clear the appropriate "typed" global table pointer */
402 switch (type) {
403 case ACPI_TABLE_RSDP:
404 acpi_gbl_RSDP = NULL;
405 break;
407 case ACPI_TABLE_DSDT:
408 acpi_gbl_DSDT = NULL;
409 break;
411 case ACPI_TABLE_FADT:
412 acpi_gbl_FADT = NULL;
413 break;
415 case ACPI_TABLE_FACS:
416 acpi_gbl_FACS = NULL;
417 break;
419 case ACPI_TABLE_XSDT:
420 acpi_gbl_XSDT = NULL;
421 break;
423 case ACPI_TABLE_SSDT:
424 case ACPI_TABLE_PSDT:
425 default:
426 break;
430 * Free the table
431 * 1) Get the head of the list
433 table_desc = acpi_gbl_table_lists[type].next;
434 count = acpi_gbl_table_lists[type].count;
437 * 2) Walk the entire list, deleting both the allocated tables
438 * and the table descriptors
440 for (i = 0; i < count; i++) {
441 table_desc = acpi_tb_uninstall_table (table_desc);
444 (void) acpi_ut_release_mutex (ACPI_MTX_TABLES);
445 return_VOID;
449 /*******************************************************************************
451 * FUNCTION: acpi_tb_delete_single_table
453 * PARAMETERS: table_info - A table info struct
455 * RETURN: None.
457 * DESCRIPTION: Low-level free for a single ACPI table. Handles cases where
458 * the table was allocated a buffer or was mapped.
460 ******************************************************************************/
462 void
463 acpi_tb_delete_single_table (
464 struct acpi_table_desc *table_desc)
467 /* Must have a valid table descriptor and pointer */
469 if ((!table_desc) ||
470 (!table_desc->pointer)) {
471 return;
474 /* Valid table, determine type of memory allocation */
476 switch (table_desc->allocation) {
477 case ACPI_MEM_NOT_ALLOCATED:
478 break;
480 case ACPI_MEM_ALLOCATED:
482 ACPI_MEM_FREE (table_desc->pointer);
483 break;
485 case ACPI_MEM_MAPPED:
487 acpi_os_unmap_memory (table_desc->pointer, table_desc->length);
488 break;
490 default:
491 break;
496 /*******************************************************************************
498 * FUNCTION: acpi_tb_uninstall_table
500 * PARAMETERS: table_info - A table info struct
502 * RETURN: Pointer to the next table in the list (of same type)
504 * DESCRIPTION: Free the memory associated with an internal ACPI table that
505 * is either installed or has never been installed.
506 * Table mutex should be locked.
508 ******************************************************************************/
510 struct acpi_table_desc *
511 acpi_tb_uninstall_table (
512 struct acpi_table_desc *table_desc)
514 struct acpi_table_desc *next_desc;
517 ACPI_FUNCTION_TRACE_PTR ("tb_uninstall_table", table_desc);
520 if (!table_desc) {
521 return_PTR (NULL);
524 /* Unlink the descriptor from the doubly linked list */
526 if (table_desc->prev) {
527 table_desc->prev->next = table_desc->next;
529 else {
530 /* Is first on list, update list head */
532 acpi_gbl_table_lists[table_desc->type].next = table_desc->next;
535 if (table_desc->next) {
536 table_desc->next->prev = table_desc->prev;
539 /* Free the memory allocated for the table itself */
541 acpi_tb_delete_single_table (table_desc);
543 /* Free the table descriptor */
545 next_desc = table_desc->next;
546 ACPI_MEM_FREE (table_desc);
548 /* Return pointer to the next descriptor */
550 return_PTR (next_desc);