Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: tbinstal - ACPI table installation and removal |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Len Brown | 75a44ce | 2008-04-23 23:00:13 -0400 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2008, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 45 | #include "accommon.h" |
| 46 | #include "acnamesp.h" |
| 47 | #include "actables.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #define _COMPONENT ACPI_TABLES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("tbinstal") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 52 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 54 | * FUNCTION: acpi_tb_verify_table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 56 | * PARAMETERS: table_desc - table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | * |
| 58 | * RETURN: Status |
| 59 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 60 | * DESCRIPTION: this function is called to verify and map table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 62 | *****************************************************************************/ |
| 63 | acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 65 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 67 | ACPI_FUNCTION_TRACE(tb_verify_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 69 | /* Map the table if necessary */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 70 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 71 | if (!table_desc->pointer) { |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 72 | if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) == |
| 73 | ACPI_TABLE_ORIGIN_MAPPED) { |
| 74 | table_desc->pointer = |
| 75 | acpi_os_map_memory(table_desc->address, |
| 76 | table_desc->length); |
| 77 | } |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 78 | if (!table_desc->pointer) { |
| 79 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 83 | /* FACS is the odd table, has no standard ACPI header and no checksum */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 85 | if (!ACPI_COMPARE_NAME(&table_desc->signature, ACPI_SIG_FACS)) { |
| 86 | |
| 87 | /* Always calculate checksum, ignore bad checksum if requested */ |
| 88 | |
| 89 | status = |
| 90 | acpi_tb_verify_checksum(table_desc->pointer, |
| 91 | table_desc->length); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 92 | } |
| 93 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 94 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | /******************************************************************************* |
| 98 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 99 | * FUNCTION: acpi_tb_add_table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | * |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 101 | * PARAMETERS: table_desc - Table descriptor |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 102 | * table_index - Where the table index is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | * |
| 104 | * RETURN: Status |
| 105 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 106 | * DESCRIPTION: This function is called to add the ACPI table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | * |
| 108 | ******************************************************************************/ |
| 109 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 110 | acpi_status |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 111 | acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 113 | u32 i; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 114 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 116 | ACPI_FUNCTION_TRACE(tb_add_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 118 | if (!table_desc->pointer) { |
| 119 | status = acpi_tb_verify_table(table_desc); |
| 120 | if (ACPI_FAILURE(status) || !table_desc->pointer) { |
| 121 | return_ACPI_STATUS(status); |
| 122 | } |
| 123 | } |
| 124 | |
Bob Moore | bc45b1d | 2008-06-10 14:12:50 +0800 | [diff] [blame] | 125 | /* |
| 126 | * Originally, we checked the table signature for "SSDT" or "PSDT" here. |
| 127 | * Next, we added support for OEMx tables, signature "OEM". |
| 128 | * Valid tables were encountered with a null signature, so we've just |
| 129 | * given up on validating the signature, since it seems to be a waste |
| 130 | * of code. The original code was removed (05/2008). |
| 131 | */ |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 132 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 133 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 135 | /* Check if table is already registered */ |
| 136 | |
| 137 | for (i = 0; i < acpi_gbl_root_table_list.count; ++i) { |
| 138 | if (!acpi_gbl_root_table_list.tables[i].pointer) { |
| 139 | status = |
| 140 | acpi_tb_verify_table(&acpi_gbl_root_table_list. |
| 141 | tables[i]); |
| 142 | if (ACPI_FAILURE(status) |
| 143 | || !acpi_gbl_root_table_list.tables[i].pointer) { |
| 144 | continue; |
| 145 | } |
| 146 | } |
| 147 | |
Bob Moore | a6f3053 | 2008-07-04 10:57:51 +0800 | [diff] [blame] | 148 | /* |
| 149 | * Check for a table match on the entire table length, |
| 150 | * not just the header. |
| 151 | */ |
| 152 | if (table_desc->length != |
| 153 | acpi_gbl_root_table_list.tables[i].length) { |
| 154 | continue; |
| 155 | } |
Bob Moore | e56f561 | 2008-07-04 10:48:43 +0800 | [diff] [blame] | 156 | |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 157 | if (ACPI_MEMCMP(table_desc->pointer, |
| 158 | acpi_gbl_root_table_list.tables[i].pointer, |
Bob Moore | a6f3053 | 2008-07-04 10:57:51 +0800 | [diff] [blame] | 159 | acpi_gbl_root_table_list.tables[i].length)) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 160 | continue; |
| 161 | } |
| 162 | |
Bob Moore | e56f561 | 2008-07-04 10:48:43 +0800 | [diff] [blame] | 163 | /* |
| 164 | * Note: the current mechanism does not unregister a table if it is |
| 165 | * dynamically unloaded. The related namespace entries are deleted, |
| 166 | * but the table remains in the root table list. |
| 167 | * |
| 168 | * The assumption here is that the number of different tables that |
| 169 | * will be loaded is actually small, and there is minimal overhead |
| 170 | * in just keeping the table in case it is needed again. |
| 171 | * |
| 172 | * If this assumption changes in the future (perhaps on large |
| 173 | * machines with many table load/unload operations), tables will |
| 174 | * need to be unregistered when they are unloaded, and slots in the |
| 175 | * root table list should be reused when empty. |
| 176 | */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 177 | |
Bob Moore | e56f561 | 2008-07-04 10:48:43 +0800 | [diff] [blame] | 178 | /* |
| 179 | * Table is already registered. |
| 180 | * We can delete the table that was passed as a parameter. |
| 181 | */ |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 182 | acpi_tb_delete_table(table_desc); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 183 | *table_index = i; |
Bob Moore | e56f561 | 2008-07-04 10:48:43 +0800 | [diff] [blame] | 184 | |
| 185 | if (acpi_gbl_root_table_list.tables[i]. |
| 186 | flags & ACPI_TABLE_IS_LOADED) { |
| 187 | |
| 188 | /* Table is still loaded, this is an error */ |
| 189 | |
| 190 | status = AE_ALREADY_EXISTS; |
| 191 | goto release; |
| 192 | } else { |
| 193 | /* Table was unloaded, allow it to be reloaded */ |
| 194 | |
| 195 | table_desc->pointer = |
| 196 | acpi_gbl_root_table_list.tables[i].pointer; |
| 197 | table_desc->address = |
| 198 | acpi_gbl_root_table_list.tables[i].address; |
| 199 | status = AE_OK; |
| 200 | goto print_header; |
| 201 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Bob Moore | e56f561 | 2008-07-04 10:48:43 +0800 | [diff] [blame] | 204 | /* Add the table to the global root table list */ |
| 205 | |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 206 | status = acpi_tb_store_table(table_desc->address, table_desc->pointer, |
| 207 | table_desc->length, table_desc->flags, |
| 208 | table_index); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 209 | if (ACPI_FAILURE(status)) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 210 | goto release; |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Bob Moore | e56f561 | 2008-07-04 10:48:43 +0800 | [diff] [blame] | 213 | print_header: |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 214 | acpi_tb_print_table_header(table_desc->address, table_desc->pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 216 | release: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 217 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 218 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | /******************************************************************************* |
| 222 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 223 | * FUNCTION: acpi_tb_resize_root_table_list |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 225 | * PARAMETERS: None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | * |
| 227 | * RETURN: Status |
| 228 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 229 | * DESCRIPTION: Expand the size of global table array |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | * |
| 231 | ******************************************************************************/ |
| 232 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 233 | acpi_status acpi_tb_resize_root_table_list(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 235 | struct acpi_table_desc *tables; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 237 | ACPI_FUNCTION_TRACE(tb_resize_root_table_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 239 | /* allow_resize flag is a parameter to acpi_initialize_tables */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 241 | if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 242 | ACPI_ERROR((AE_INFO, |
| 243 | "Resize of Root Table Array is not allowed")); |
| 244 | return_ACPI_STATUS(AE_SUPPORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 247 | /* Increase the Table Array size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 249 | tables = ACPI_ALLOCATE_ZEROED(((acpi_size) acpi_gbl_root_table_list. |
| 250 | size + ACPI_ROOT_TABLE_SIZE_INCREMENT) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 251 | * sizeof(struct acpi_table_desc)); |
| 252 | if (!tables) { |
| 253 | ACPI_ERROR((AE_INFO, |
| 254 | "Could not allocate new root table array")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 255 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 258 | /* Copy and free the previous table array */ |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 259 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 260 | if (acpi_gbl_root_table_list.tables) { |
| 261 | ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables, |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 262 | (acpi_size) acpi_gbl_root_table_list.size * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 263 | sizeof(struct acpi_table_desc)); |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 264 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 265 | if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 266 | ACPI_FREE(acpi_gbl_root_table_list.tables); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 270 | acpi_gbl_root_table_list.tables = tables; |
| 271 | acpi_gbl_root_table_list.size += ACPI_ROOT_TABLE_SIZE_INCREMENT; |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 272 | acpi_gbl_root_table_list.flags |= (u8) ACPI_ROOT_ORIGIN_ALLOCATED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 274 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | /******************************************************************************* |
| 278 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 279 | * FUNCTION: acpi_tb_store_table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 281 | * PARAMETERS: Address - Table address |
| 282 | * Table - Table header |
| 283 | * Length - Table length |
| 284 | * Flags - flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 286 | * RETURN: Status and table index. |
| 287 | * |
| 288 | * DESCRIPTION: Add an ACPI table to the global table list |
| 289 | * |
| 290 | ******************************************************************************/ |
| 291 | |
| 292 | acpi_status |
| 293 | acpi_tb_store_table(acpi_physical_address address, |
| 294 | struct acpi_table_header *table, |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 295 | u32 length, u8 flags, u32 *table_index) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 296 | { |
| 297 | acpi_status status = AE_OK; |
| 298 | |
| 299 | /* Ensure that there is room for the table in the Root Table List */ |
| 300 | |
| 301 | if (acpi_gbl_root_table_list.count >= acpi_gbl_root_table_list.size) { |
| 302 | status = acpi_tb_resize_root_table_list(); |
| 303 | if (ACPI_FAILURE(status)) { |
| 304 | return (status); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /* Initialize added table */ |
| 309 | |
| 310 | acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count]. |
| 311 | address = address; |
| 312 | acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count]. |
| 313 | pointer = table; |
| 314 | acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].length = |
| 315 | length; |
| 316 | acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count]. |
| 317 | owner_id = 0; |
| 318 | acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].flags = |
| 319 | flags; |
| 320 | |
| 321 | ACPI_MOVE_32_TO_32(& |
| 322 | (acpi_gbl_root_table_list. |
| 323 | tables[acpi_gbl_root_table_list.count].signature), |
| 324 | table->signature); |
| 325 | |
| 326 | *table_index = acpi_gbl_root_table_list.count; |
| 327 | acpi_gbl_root_table_list.count++; |
| 328 | return (status); |
| 329 | } |
| 330 | |
| 331 | /******************************************************************************* |
| 332 | * |
| 333 | * FUNCTION: acpi_tb_delete_table |
| 334 | * |
| 335 | * PARAMETERS: table_index - Table index |
| 336 | * |
| 337 | * RETURN: None |
| 338 | * |
| 339 | * DESCRIPTION: Delete one internal ACPI table |
| 340 | * |
| 341 | ******************************************************************************/ |
| 342 | |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 343 | void acpi_tb_delete_table(struct acpi_table_desc *table_desc) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 344 | { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 345 | /* Table must be mapped or allocated */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 346 | if (!table_desc->pointer) { |
| 347 | return; |
| 348 | } |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 349 | switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) { |
| 350 | case ACPI_TABLE_ORIGIN_MAPPED: |
| 351 | acpi_os_unmap_memory(table_desc->pointer, table_desc->length); |
| 352 | break; |
| 353 | case ACPI_TABLE_ORIGIN_ALLOCATED: |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 354 | ACPI_FREE(table_desc->pointer); |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 355 | break; |
| 356 | default:; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | table_desc->pointer = NULL; |
| 360 | } |
| 361 | |
| 362 | /******************************************************************************* |
| 363 | * |
| 364 | * FUNCTION: acpi_tb_terminate |
| 365 | * |
| 366 | * PARAMETERS: None |
| 367 | * |
| 368 | * RETURN: None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | * |
| 370 | * DESCRIPTION: Delete all internal ACPI tables |
| 371 | * |
| 372 | ******************************************************************************/ |
| 373 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 374 | void acpi_tb_terminate(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 376 | u32 i; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 377 | |
| 378 | ACPI_FUNCTION_TRACE(tb_terminate); |
| 379 | |
| 380 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
| 381 | |
| 382 | /* Delete the individual tables */ |
| 383 | |
| 384 | for (i = 0; i < acpi_gbl_root_table_list.count; ++i) { |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 385 | acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 386 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
| 388 | /* |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 389 | * Delete the root table array if allocated locally. Array cannot be |
| 390 | * mapped, so we don't need to check for that flag. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | */ |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 392 | if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 393 | ACPI_FREE(acpi_gbl_root_table_list.tables); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 395 | |
| 396 | acpi_gbl_root_table_list.tables = NULL; |
| 397 | acpi_gbl_root_table_list.flags = 0; |
| 398 | acpi_gbl_root_table_list.count = 0; |
| 399 | |
| 400 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n")); |
| 401 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | /******************************************************************************* |
| 405 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 406 | * FUNCTION: acpi_tb_delete_namespace_by_owner |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 408 | * PARAMETERS: table_index - Table index |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 410 | * RETURN: None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 412 | * DESCRIPTION: Delete all namespace objects created when this table was loaded. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | * |
| 414 | ******************************************************************************/ |
| 415 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 416 | void acpi_tb_delete_namespace_by_owner(u32 table_index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 418 | acpi_owner_id owner_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 420 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
| 421 | if (table_index < acpi_gbl_root_table_list.count) { |
| 422 | owner_id = |
| 423 | acpi_gbl_root_table_list.tables[table_index].owner_id; |
| 424 | } else { |
| 425 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | return; |
| 427 | } |
| 428 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 429 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 430 | acpi_ns_delete_namespace_by_owner(owner_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | /******************************************************************************* |
| 434 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 435 | * FUNCTION: acpi_tb_allocate_owner_id |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 437 | * PARAMETERS: table_index - Table index |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 439 | * RETURN: Status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 441 | * DESCRIPTION: Allocates owner_id in table_desc |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | * |
| 443 | ******************************************************************************/ |
| 444 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 445 | acpi_status acpi_tb_allocate_owner_id(u32 table_index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 447 | acpi_status status = AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 449 | ACPI_FUNCTION_TRACE(tb_allocate_owner_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 451 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
| 452 | if (table_index < acpi_gbl_root_table_list.count) { |
| 453 | status = acpi_ut_allocate_owner_id |
| 454 | (&(acpi_gbl_root_table_list.tables[table_index].owner_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 457 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 458 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | /******************************************************************************* |
| 462 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 463 | * FUNCTION: acpi_tb_release_owner_id |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 465 | * PARAMETERS: table_index - Table index |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 467 | * RETURN: Status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 469 | * DESCRIPTION: Releases owner_id in table_desc |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | * |
| 471 | ******************************************************************************/ |
| 472 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 473 | acpi_status acpi_tb_release_owner_id(u32 table_index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 475 | acpi_status status = AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 477 | ACPI_FUNCTION_TRACE(tb_release_owner_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 479 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
| 480 | if (table_index < acpi_gbl_root_table_list.count) { |
| 481 | acpi_ut_release_owner_id(& |
| 482 | (acpi_gbl_root_table_list. |
| 483 | tables[table_index].owner_id)); |
| 484 | status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 487 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 488 | return_ACPI_STATUS(status); |
| 489 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 491 | /******************************************************************************* |
| 492 | * |
| 493 | * FUNCTION: acpi_tb_get_owner_id |
| 494 | * |
| 495 | * PARAMETERS: table_index - Table index |
| 496 | * owner_id - Where the table owner_id is returned |
| 497 | * |
| 498 | * RETURN: Status |
| 499 | * |
| 500 | * DESCRIPTION: returns owner_id for the ACPI table |
| 501 | * |
| 502 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 504 | acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 505 | { |
| 506 | acpi_status status = AE_BAD_PARAMETER; |
| 507 | |
| 508 | ACPI_FUNCTION_TRACE(tb_get_owner_id); |
| 509 | |
| 510 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
| 511 | if (table_index < acpi_gbl_root_table_list.count) { |
| 512 | *owner_id = |
| 513 | acpi_gbl_root_table_list.tables[table_index].owner_id; |
| 514 | status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 517 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 518 | return_ACPI_STATUS(status); |
| 519 | } |
| 520 | |
| 521 | /******************************************************************************* |
| 522 | * |
| 523 | * FUNCTION: acpi_tb_is_table_loaded |
| 524 | * |
| 525 | * PARAMETERS: table_index - Table index |
| 526 | * |
| 527 | * RETURN: Table Loaded Flag |
| 528 | * |
| 529 | ******************************************************************************/ |
| 530 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 531 | u8 acpi_tb_is_table_loaded(u32 table_index) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 532 | { |
| 533 | u8 is_loaded = FALSE; |
| 534 | |
| 535 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
| 536 | if (table_index < acpi_gbl_root_table_list.count) { |
| 537 | is_loaded = (u8) |
| 538 | (acpi_gbl_root_table_list.tables[table_index]. |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 539 | flags & ACPI_TABLE_IS_LOADED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 542 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 543 | return (is_loaded); |
| 544 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 546 | /******************************************************************************* |
| 547 | * |
| 548 | * FUNCTION: acpi_tb_set_table_loaded_flag |
| 549 | * |
| 550 | * PARAMETERS: table_index - Table index |
| 551 | * is_loaded - TRUE if table is loaded, FALSE otherwise |
| 552 | * |
| 553 | * RETURN: None |
| 554 | * |
| 555 | * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE. |
| 556 | * |
| 557 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 559 | void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 560 | { |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 561 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 562 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
| 563 | if (table_index < acpi_gbl_root_table_list.count) { |
| 564 | if (is_loaded) { |
| 565 | acpi_gbl_root_table_list.tables[table_index].flags |= |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 566 | ACPI_TABLE_IS_LOADED; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 567 | } else { |
| 568 | acpi_gbl_root_table_list.tables[table_index].flags &= |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 569 | ~ACPI_TABLE_IS_LOADED; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 570 | } |
| 571 | } |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 572 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 573 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | } |