blob: 1668a232fb6754fb3a0d571cf32cb443863cefa0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: tbinstal - ACPI table installation and removal
4 *
5 *****************************************************************************/
6
7/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/actables.h>
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define _COMPONENT ACPI_TABLES
Len Brown4be44fc2005-08-05 00:44:28 -040048ACPI_MODULE_NAME("tbinstal")
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Robert Moore44f6c012005-04-18 22:49:35 -040050/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040051static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040052acpi_tb_match_signature(char *signature,
53 struct acpi_table_desc *table_info, u8 search_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55/*******************************************************************************
56 *
57 * FUNCTION: acpi_tb_match_signature
58 *
59 * PARAMETERS: Signature - Table signature to match
60 * table_info - Return data
Robert Moore44f6c012005-04-18 22:49:35 -040061 * search_type - Table type to match (primary/secondary)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 *
63 * RETURN: Status
64 *
65 * DESCRIPTION: Compare signature against the list of "ACPI-subsystem-owned"
66 * tables (DSDT/FADT/SSDT, etc.) Returns the table_type_iD on match.
67 *
68 ******************************************************************************/
69
Robert Moore44f6c012005-04-18 22:49:35 -040070static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040071acpi_tb_match_signature(char *signature,
72 struct acpi_table_desc *table_info, u8 search_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
Len Brown4be44fc2005-08-05 00:44:28 -040074 acpi_native_uint i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Bob Mooreb229cf92006-04-21 17:15:00 -040076 ACPI_FUNCTION_TRACE(tb_match_signature);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Robert Moore44f6c012005-04-18 22:49:35 -040078 /* Search for a signature match among the known table types */
79
Bob Mooreb229cf92006-04-21 17:15:00 -040080 for (i = 0; i < (ACPI_TABLE_ID_MAX + 1); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 if (!(acpi_gbl_table_data[i].flags & search_type)) {
82 continue;
83 }
84
Len Brown4be44fc2005-08-05 00:44:28 -040085 if (!ACPI_STRNCMP(signature, acpi_gbl_table_data[i].signature,
86 acpi_gbl_table_data[i].sig_length)) {
Bob Moore52fc0b02006-10-02 00:00:00 -040087
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 /* Found a signature match, return index if requested */
89
90 if (table_info) {
91 table_info->type = (u8) i;
92 }
93
Len Brown4be44fc2005-08-05 00:44:28 -040094 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
95 "Table [%4.4s] is an ACPI table consumed by the core subsystem\n",
96 (char *)acpi_gbl_table_data[i].
97 signature));
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Len Brown4be44fc2005-08-05 00:44:28 -040099 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 }
101 }
102
Len Brown4be44fc2005-08-05 00:44:28 -0400103 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));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Len Brown4be44fc2005-08-05 00:44:28 -0400107 return_ACPI_STATUS(AE_TABLE_NOT_SUPPORTED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108}
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110/*******************************************************************************
111 *
112 * FUNCTION: acpi_tb_install_table
113 *
114 * PARAMETERS: table_info - Return value from acpi_tb_get_table_body
115 *
116 * RETURN: Status
117 *
Robert Moore0c9938c2005-07-29 15:15:00 -0700118 * DESCRIPTION: Install the table into the global data structures.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 *
120 ******************************************************************************/
121
Len Brown4be44fc2005-08-05 00:44:28 -0400122acpi_status acpi_tb_install_table(struct acpi_table_desc *table_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
Len Brown4be44fc2005-08-05 00:44:28 -0400124 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Bob Mooreb229cf92006-04-21 17:15:00 -0400126 ACPI_FUNCTION_TRACE(tb_install_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 /* Lock tables while installing */
129
Len Brown4be44fc2005-08-05 00:44:28 -0400130 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
131 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500132 ACPI_EXCEPTION((AE_INFO, status,
133 "Could not acquire table mutex"));
Len Brown4be44fc2005-08-05 00:44:28 -0400134 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
136
Robert Moore0c9938c2005-07-29 15:15:00 -0700137 /*
138 * Ignore a table that is already installed. For example, some BIOS
139 * ASL code will repeatedly attempt to load the same SSDT.
140 */
Len Brown4be44fc2005-08-05 00:44:28 -0400141 status = acpi_tb_is_table_installed(table_info);
142 if (ACPI_FAILURE(status)) {
Robert Moore0c9938c2005-07-29 15:15:00 -0700143 goto unlock_and_exit;
144 }
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 /* Install the table into the global data structure */
147
Len Brown4be44fc2005-08-05 00:44:28 -0400148 status = acpi_tb_init_table_descriptor(table_info->type, table_info);
149 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500150 ACPI_EXCEPTION((AE_INFO, status,
151 "Could not install table [%4.4s]",
152 table_info->pointer->signature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 }
154
Len Brown4be44fc2005-08-05 00:44:28 -0400155 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s located at %p\n",
156 acpi_gbl_table_data[table_info->type].name,
157 table_info->pointer));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Len Brown4be44fc2005-08-05 00:44:28 -0400159 unlock_and_exit:
160 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
161 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162}
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164/*******************************************************************************
165 *
166 * FUNCTION: acpi_tb_recognize_table
167 *
168 * PARAMETERS: table_info - Return value from acpi_tb_get_table_body
Robert Moore44f6c012005-04-18 22:49:35 -0400169 * search_type - Table type to match (primary/secondary)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 *
171 * RETURN: Status
172 *
173 * DESCRIPTION: Check a table signature for a match against known table types
174 *
175 * NOTE: All table pointers are validated as follows:
176 * 1) Table pointer must point to valid physical memory
177 * 2) Signature must be 4 ASCII chars, even if we don't recognize the
178 * name
179 * 3) Table must be readable for length specified in the header
180 * 4) Table checksum must be valid (with the exception of the FACS
181 * which has no checksum for some odd reason)
182 *
183 ******************************************************************************/
184
185acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400186acpi_tb_recognize_table(struct acpi_table_desc *table_info, u8 search_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
Len Brown4be44fc2005-08-05 00:44:28 -0400188 struct acpi_table_header *table_header;
189 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Bob Mooreb229cf92006-04-21 17:15:00 -0400191 ACPI_FUNCTION_TRACE(tb_recognize_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 /* Ensure that we have a valid table pointer */
194
Len Brown4be44fc2005-08-05 00:44:28 -0400195 table_header = (struct acpi_table_header *)table_info->pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 if (!table_header) {
Len Brown4be44fc2005-08-05 00:44:28 -0400197 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 }
199
200 /*
201 * We only "recognize" a limited number of ACPI tables -- namely, the
202 * ones that are used by the subsystem (DSDT, FADT, etc.)
203 *
204 * An AE_TABLE_NOT_SUPPORTED means that the table was not recognized.
205 * This can be any one of many valid ACPI tables, it just isn't one of
206 * the tables that is consumed by the core subsystem
207 */
Len Brown4be44fc2005-08-05 00:44:28 -0400208 status = acpi_tb_match_signature(table_header->signature,
209 table_info, search_type);
210 if (ACPI_FAILURE(status)) {
211 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 }
213
Len Brown4be44fc2005-08-05 00:44:28 -0400214 status = acpi_tb_validate_table_header(table_header);
215 if (ACPI_FAILURE(status)) {
216 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 }
218
219 /* Return the table type and length via the info struct */
220
221 table_info->length = (acpi_size) table_header->length;
Len Brown4be44fc2005-08-05 00:44:28 -0400222 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225/*******************************************************************************
226 *
227 * FUNCTION: acpi_tb_init_table_descriptor
228 *
229 * PARAMETERS: table_type - The type of the table
230 * table_info - A table info struct
231 *
232 * RETURN: None.
233 *
234 * DESCRIPTION: Install a table into the global data structs.
235 *
236 ******************************************************************************/
237
238acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400239acpi_tb_init_table_descriptor(acpi_table_type table_type,
240 struct acpi_table_desc *table_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
Len Brown4be44fc2005-08-05 00:44:28 -0400242 struct acpi_table_list *list_head;
243 struct acpi_table_desc *table_desc;
244 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Bob Mooreb229cf92006-04-21 17:15:00 -0400246 ACPI_FUNCTION_TRACE_U32(tb_init_table_descriptor, table_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
248 /* Allocate a descriptor for this table */
249
Bob Moore83135242006-10-03 00:00:00 -0400250 table_desc = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_table_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 if (!table_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400252 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 }
254
Robert Mooref9f46012005-07-08 00:00:00 -0400255 /* Get a new owner ID for the table */
256
Len Brown4be44fc2005-08-05 00:44:28 -0400257 status = acpi_ut_allocate_owner_id(&table_desc->owner_id);
258 if (ACPI_FAILURE(status)) {
Bob Mooref6dd9222006-07-07 20:44:38 -0400259 goto error_exit1;
Robert Mooref9f46012005-07-08 00:00:00 -0400260 }
261
Robert Moore44f6c012005-04-18 22:49:35 -0400262 /* Install the table into the global data structure */
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 list_head = &acpi_gbl_table_lists[table_type];
265
266 /*
267 * Two major types of tables: 1) Only one instance is allowed. This
268 * includes most ACPI tables such as the DSDT. 2) Multiple instances of
269 * the table are allowed. This includes SSDT and PSDTs.
270 */
Len Brown4be44fc2005-08-05 00:44:28 -0400271 if (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 /*
273 * Only one table allowed, and a table has alread been installed
274 * at this location, so return an error.
275 */
276 if (list_head->next) {
Bob Mooref6dd9222006-07-07 20:44:38 -0400277 status = AE_ALREADY_EXISTS;
278 goto error_exit2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 }
280
281 table_desc->next = list_head->next;
282 list_head->next = table_desc;
283
284 if (table_desc->next) {
285 table_desc->next->prev = table_desc;
286 }
287
288 list_head->count++;
Len Brown4be44fc2005-08-05 00:44:28 -0400289 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 /*
291 * Link the new table in to the list of tables of this type.
292 * Insert at the end of the list, order IS IMPORTANT.
293 *
294 * table_desc->Prev & Next are already NULL from calloc()
295 */
296 list_head->count++;
297
298 if (!list_head->next) {
299 list_head->next = table_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400300 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 table_desc->next = list_head->next;
302
303 while (table_desc->next->next) {
304 table_desc->next = table_desc->next->next;
305 }
306
307 table_desc->next->next = table_desc;
308 table_desc->prev = table_desc->next;
309 table_desc->next = NULL;
310 }
311 }
312
313 /* Finish initialization of the table descriptor */
314
Bob Mooreb229cf92006-04-21 17:15:00 -0400315 table_desc->loaded_into_namespace = FALSE;
Len Brown4be44fc2005-08-05 00:44:28 -0400316 table_desc->type = (u8) table_type;
317 table_desc->pointer = table_info->pointer;
318 table_desc->length = table_info->length;
319 table_desc->allocation = table_info->allocation;
320 table_desc->aml_start = (u8 *) (table_desc->pointer + 1),
Bob Mooreb229cf92006-04-21 17:15:00 -0400321 table_desc->aml_length = (u32)
322 (table_desc->length - (u32) sizeof(struct acpi_table_header));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 /*
325 * Set the appropriate global pointer (if there is one) to point to the
326 * newly installed table
327 */
328 if (acpi_gbl_table_data[table_type].global_ptr) {
Len Brown4be44fc2005-08-05 00:44:28 -0400329 *(acpi_gbl_table_data[table_type].global_ptr) =
330 table_info->pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 }
332
333 /* Return Data */
334
Len Brown4be44fc2005-08-05 00:44:28 -0400335 table_info->owner_id = table_desc->owner_id;
336 table_info->installed_desc = table_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400337 return_ACPI_STATUS(AE_OK);
Bob Mooref6dd9222006-07-07 20:44:38 -0400338
339 /* Error exit with cleanup */
340
341 error_exit2:
342
343 acpi_ut_release_owner_id(&table_desc->owner_id);
344
345 error_exit1:
346
347 ACPI_FREE(table_desc);
348 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349}
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351/*******************************************************************************
352 *
353 * FUNCTION: acpi_tb_delete_all_tables
354 *
355 * PARAMETERS: None.
356 *
357 * RETURN: None.
358 *
359 * DESCRIPTION: Delete all internal ACPI tables
360 *
361 ******************************************************************************/
362
Len Brown4be44fc2005-08-05 00:44:28 -0400363void acpi_tb_delete_all_tables(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
Len Brown4be44fc2005-08-05 00:44:28 -0400365 acpi_table_type type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 /*
368 * Free memory allocated for ACPI tables
369 * Memory can either be mapped or allocated
370 */
Bob Mooreb229cf92006-04-21 17:15:00 -0400371 for (type = 0; type < (ACPI_TABLE_ID_MAX + 1); type++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400372 acpi_tb_delete_tables_by_type(type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 }
374}
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376/*******************************************************************************
377 *
378 * FUNCTION: acpi_tb_delete_tables_by_type
379 *
380 * PARAMETERS: Type - The table type to be deleted
381 *
382 * RETURN: None.
383 *
384 * DESCRIPTION: Delete an internal ACPI table
385 * Locks the ACPI table mutex
386 *
387 ******************************************************************************/
388
Len Brown4be44fc2005-08-05 00:44:28 -0400389void acpi_tb_delete_tables_by_type(acpi_table_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
Len Brown4be44fc2005-08-05 00:44:28 -0400391 struct acpi_table_desc *table_desc;
392 u32 count;
393 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Bob Mooreb229cf92006-04-21 17:15:00 -0400395 ACPI_FUNCTION_TRACE_U32(tb_delete_tables_by_type, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Bob Mooreb229cf92006-04-21 17:15:00 -0400397 if (type > ACPI_TABLE_ID_MAX) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 return_VOID;
399 }
400
Len Brown4be44fc2005-08-05 00:44:28 -0400401 if (ACPI_FAILURE(acpi_ut_acquire_mutex(ACPI_MTX_TABLES))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 return;
403 }
404
405 /* Clear the appropriate "typed" global table pointer */
406
407 switch (type) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400408 case ACPI_TABLE_ID_RSDP:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 acpi_gbl_RSDP = NULL;
410 break;
411
Bob Mooreb229cf92006-04-21 17:15:00 -0400412 case ACPI_TABLE_ID_DSDT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 acpi_gbl_DSDT = NULL;
414 break;
415
Bob Mooreb229cf92006-04-21 17:15:00 -0400416 case ACPI_TABLE_ID_FADT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 acpi_gbl_FADT = NULL;
418 break;
419
Bob Mooreb229cf92006-04-21 17:15:00 -0400420 case ACPI_TABLE_ID_FACS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 acpi_gbl_FACS = NULL;
422 break;
423
Bob Mooreb229cf92006-04-21 17:15:00 -0400424 case ACPI_TABLE_ID_XSDT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 acpi_gbl_XSDT = NULL;
426 break;
427
Bob Mooreb229cf92006-04-21 17:15:00 -0400428 case ACPI_TABLE_ID_SSDT:
429 case ACPI_TABLE_ID_PSDT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 default:
431 break;
432 }
433
434 /*
435 * Free the table
436 * 1) Get the head of the list
437 */
438 table_desc = acpi_gbl_table_lists[type].next;
Len Brown4be44fc2005-08-05 00:44:28 -0400439 count = acpi_gbl_table_lists[type].count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441 /*
442 * 2) Walk the entire list, deleting both the allocated tables
443 * and the table descriptors
444 */
445 for (i = 0; i < count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400446 table_desc = acpi_tb_uninstall_table(table_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 }
448
Len Brown4be44fc2005-08-05 00:44:28 -0400449 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 return_VOID;
451}
452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453/*******************************************************************************
454 *
455 * FUNCTION: acpi_tb_delete_single_table
456 *
457 * PARAMETERS: table_info - A table info struct
458 *
459 * RETURN: None.
460 *
461 * DESCRIPTION: Low-level free for a single ACPI table. Handles cases where
462 * the table was allocated a buffer or was mapped.
463 *
464 ******************************************************************************/
465
Len Brown4be44fc2005-08-05 00:44:28 -0400466void acpi_tb_delete_single_table(struct acpi_table_desc *table_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467{
468
469 /* Must have a valid table descriptor and pointer */
470
Len Brown4be44fc2005-08-05 00:44:28 -0400471 if ((!table_desc) || (!table_desc->pointer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 return;
473 }
474
475 /* Valid table, determine type of memory allocation */
476
477 switch (table_desc->allocation) {
478 case ACPI_MEM_NOT_ALLOCATED:
479 break;
480
481 case ACPI_MEM_ALLOCATED:
482
Bob Moore83135242006-10-03 00:00:00 -0400483 ACPI_FREE(table_desc->pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 break;
485
486 case ACPI_MEM_MAPPED:
487
Len Brown4be44fc2005-08-05 00:44:28 -0400488 acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 break;
490
491 default:
492 break;
493 }
494}
495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496/*******************************************************************************
497 *
498 * FUNCTION: acpi_tb_uninstall_table
499 *
500 * PARAMETERS: table_info - A table info struct
501 *
502 * RETURN: Pointer to the next table in the list (of same type)
503 *
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.
507 *
508 ******************************************************************************/
509
Len Brown4be44fc2005-08-05 00:44:28 -0400510struct acpi_table_desc *acpi_tb_uninstall_table(struct acpi_table_desc
511 *table_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512{
Len Brown4be44fc2005-08-05 00:44:28 -0400513 struct acpi_table_desc *next_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Bob Mooreb229cf92006-04-21 17:15:00 -0400515 ACPI_FUNCTION_TRACE_PTR(tb_uninstall_table, table_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 if (!table_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400518 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 }
520
521 /* Unlink the descriptor from the doubly linked list */
522
523 if (table_desc->prev) {
524 table_desc->prev->next = table_desc->next;
Len Brown4be44fc2005-08-05 00:44:28 -0400525 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 /* Is first on list, update list head */
527
528 acpi_gbl_table_lists[table_desc->type].next = table_desc->next;
529 }
530
531 if (table_desc->next) {
532 table_desc->next->prev = table_desc->prev;
533 }
534
535 /* Free the memory allocated for the table itself */
536
Len Brown4be44fc2005-08-05 00:44:28 -0400537 acpi_tb_delete_single_table(table_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Bob Mooref6dd9222006-07-07 20:44:38 -0400539 /* Free the owner ID associated with this table */
540
541 acpi_ut_release_owner_id(&table_desc->owner_id);
542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 /* Free the table descriptor */
544
545 next_desc = table_desc->next;
Bob Moore83135242006-10-03 00:00:00 -0400546 ACPI_FREE(table_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 /* Return pointer to the next descriptor */
549
Len Brown4be44fc2005-08-05 00:44:28 -0400550 return_PTR(next_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551}