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 | /* |
Bob Moore | fbb7a2d | 2014-02-08 09:42:25 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2014, 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 | |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 52 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | * |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 54 | * FUNCTION: acpi_tb_acquire_table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | * |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 56 | * PARAMETERS: table_desc - Table descriptor |
| 57 | * table_ptr - Where table is returned |
| 58 | * table_length - Where table length is returned |
| 59 | * table_flags - Where table allocation flags are returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | * |
| 61 | * RETURN: Status |
| 62 | * |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 63 | * DESCRIPTION: Acquire a table. It can be used for tables not maintained in |
| 64 | * acpi_gbl_root_table_list. |
| 65 | * |
| 66 | ******************************************************************************/ |
| 67 | acpi_status |
| 68 | acpi_tb_acquire_table(struct acpi_table_desc *table_desc, |
| 69 | struct acpi_table_header **table_ptr, |
| 70 | u32 *table_length, u8 *table_flags) |
| 71 | { |
| 72 | struct acpi_table_header *table = NULL; |
| 73 | |
| 74 | switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) { |
| 75 | case ACPI_TABLE_ORIGIN_MAPPED: |
| 76 | |
| 77 | table = |
| 78 | acpi_os_map_memory(table_desc->address, table_desc->length); |
| 79 | break; |
| 80 | |
| 81 | case ACPI_TABLE_ORIGIN_ALLOCATED: |
| 82 | case ACPI_TABLE_ORIGIN_UNKNOWN: |
| 83 | case ACPI_TABLE_ORIGIN_OVERRIDE: |
| 84 | |
| 85 | table = |
| 86 | ACPI_CAST_PTR(struct acpi_table_header, |
| 87 | table_desc->address); |
| 88 | break; |
| 89 | |
| 90 | default: |
| 91 | |
| 92 | break; |
| 93 | } |
| 94 | |
| 95 | /* Table is not valid yet */ |
| 96 | |
| 97 | if (!table) { |
| 98 | return (AE_NO_MEMORY); |
| 99 | } |
| 100 | |
| 101 | /* Fill the return values */ |
| 102 | |
| 103 | *table_ptr = table; |
| 104 | *table_length = table_desc->length; |
| 105 | *table_flags = table_desc->flags; |
| 106 | |
| 107 | return (AE_OK); |
| 108 | } |
| 109 | |
| 110 | /******************************************************************************* |
| 111 | * |
| 112 | * FUNCTION: acpi_tb_release_table |
| 113 | * |
| 114 | * PARAMETERS: table - Pointer for the table |
| 115 | * table_length - Length for the table |
| 116 | * table_flags - Allocation flags for the table |
| 117 | * |
| 118 | * RETURN: None |
| 119 | * |
| 120 | * DESCRIPTION: Release a table. The reversal of acpi_tb_acquire_table(). |
| 121 | * |
| 122 | ******************************************************************************/ |
| 123 | |
| 124 | void |
| 125 | acpi_tb_release_table(struct acpi_table_header *table, |
| 126 | u32 table_length, u8 table_flags) |
| 127 | { |
| 128 | switch (table_flags & ACPI_TABLE_ORIGIN_MASK) { |
| 129 | case ACPI_TABLE_ORIGIN_MAPPED: |
| 130 | |
| 131 | acpi_os_unmap_memory(table, table_length); |
| 132 | break; |
| 133 | |
| 134 | case ACPI_TABLE_ORIGIN_ALLOCATED: |
| 135 | case ACPI_TABLE_ORIGIN_UNKNOWN: |
| 136 | case ACPI_TABLE_ORIGIN_OVERRIDE: |
| 137 | default: |
| 138 | |
| 139 | break; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | /****************************************************************************** |
| 144 | * |
| 145 | * FUNCTION: acpi_tb_validate_table |
| 146 | * |
| 147 | * PARAMETERS: table_desc - Table descriptor |
| 148 | * |
| 149 | * RETURN: Status |
| 150 | * |
| 151 | * DESCRIPTION: This function is called to validate (ensure Pointer is valid) |
| 152 | * and verify the table. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 154 | *****************************************************************************/ |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 155 | |
| 156 | acpi_status acpi_tb_validate_table(struct acpi_table_desc *table_desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 158 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 160 | ACPI_FUNCTION_TRACE(tb_validate_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 162 | /* Validate the table if necessary */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 163 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 164 | if (!table_desc->pointer) { |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 165 | status = acpi_tb_acquire_table(table_desc, &table_desc->pointer, |
| 166 | &table_desc->length, |
| 167 | &table_desc->flags); |
| 168 | if (ACPI_FAILURE(status) || !table_desc->pointer) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 169 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | |
Lv Zheng | 94d4be6 | 2013-09-23 09:52:29 +0800 | [diff] [blame] | 173 | /* Always calculate checksum, ignore bad checksum if requested */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Lv Zheng | 94d4be6 | 2013-09-23 09:52:29 +0800 | [diff] [blame] | 175 | status = |
| 176 | acpi_tb_verify_checksum(table_desc->pointer, table_desc->length); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 177 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 178 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | /******************************************************************************* |
| 182 | * |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 183 | * FUNCTION: acpi_tb_invalidate_table |
| 184 | * |
| 185 | * PARAMETERS: table_desc - Table descriptor |
| 186 | * |
| 187 | * RETURN: None |
| 188 | * |
| 189 | * DESCRIPTION: Invalidate one internal ACPI table, this is reversal of |
| 190 | * acpi_tb_validate_table(). |
| 191 | * |
| 192 | ******************************************************************************/ |
| 193 | |
| 194 | void acpi_tb_invalidate_table(struct acpi_table_desc *table_desc) |
| 195 | { |
| 196 | |
| 197 | ACPI_FUNCTION_TRACE(tb_invalidate_table); |
| 198 | |
| 199 | /* Table must be validated */ |
| 200 | |
| 201 | if (!table_desc->pointer) { |
| 202 | return_VOID; |
| 203 | } |
| 204 | |
| 205 | acpi_tb_release_table(table_desc->pointer, table_desc->length, |
| 206 | table_desc->flags); |
| 207 | table_desc->pointer = NULL; |
| 208 | |
| 209 | return_VOID; |
| 210 | } |
| 211 | |
| 212 | /******************************************************************************* |
| 213 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 214 | * FUNCTION: acpi_tb_add_table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | * |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 216 | * PARAMETERS: table_desc - Table descriptor |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 217 | * table_index - Where the table index is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | * |
| 219 | * RETURN: Status |
| 220 | * |
Bob Moore | d3ccaff | 2009-02-03 14:43:04 +0800 | [diff] [blame] | 221 | * DESCRIPTION: This function is called to add an ACPI table. It is used to |
| 222 | * dynamically load tables via the Load and load_table AML |
| 223 | * operators. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | * |
| 225 | ******************************************************************************/ |
| 226 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 227 | acpi_status |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 228 | 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] | 229 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 230 | u32 i; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 231 | acpi_status status = AE_OK; |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 232 | struct acpi_table_header *final_table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 234 | ACPI_FUNCTION_TRACE(tb_add_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 236 | if (!table_desc->pointer) { |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 237 | status = acpi_tb_validate_table(table_desc); |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 238 | if (ACPI_FAILURE(status) || !table_desc->pointer) { |
| 239 | return_ACPI_STATUS(status); |
| 240 | } |
| 241 | } |
| 242 | |
Bob Moore | bc45b1d | 2008-06-10 14:12:50 +0800 | [diff] [blame] | 243 | /* |
Bob Moore | c8cefe3 | 2011-06-14 10:42:53 +0800 | [diff] [blame] | 244 | * Validate the incoming table signature. |
| 245 | * |
| 246 | * 1) Originally, we checked the table signature for "SSDT" or "PSDT". |
| 247 | * 2) We added support for OEMx tables, signature "OEM". |
| 248 | * 3) Valid tables were encountered with a null signature, so we just |
| 249 | * gave up on validating the signature, (05/2008). |
| 250 | * 4) We encountered non-AML tables such as the MADT, which caused |
| 251 | * interpreter errors and kernel faults. So now, we once again allow |
| 252 | * only "SSDT", "OEMx", and now, also a null signature. (05/2011). |
Bob Moore | bc45b1d | 2008-06-10 14:12:50 +0800 | [diff] [blame] | 253 | */ |
Bob Moore | c8cefe3 | 2011-06-14 10:42:53 +0800 | [diff] [blame] | 254 | if ((table_desc->pointer->signature[0] != 0x00) && |
| 255 | (!ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_SSDT)) |
| 256 | && (ACPI_STRNCMP(table_desc->pointer->signature, "OEM", 3))) { |
Bob Moore | 3b3ea77 | 2012-07-16 09:39:54 +0800 | [diff] [blame] | 257 | ACPI_BIOS_ERROR((AE_INFO, |
| 258 | "Table has invalid signature [%4.4s] (0x%8.8X), " |
| 259 | "must be SSDT or OEMx", |
Bob Moore | de8e7db | 2013-06-08 00:59:44 +0000 | [diff] [blame] | 260 | acpi_ut_valid_acpi_name(table_desc->pointer-> |
Bob Moore | 3b3ea77 | 2012-07-16 09:39:54 +0800 | [diff] [blame] | 261 | signature) ? |
| 262 | table_desc->pointer->signature : "????", |
| 263 | *(u32 *)table_desc->pointer->signature)); |
Bob Moore | c8cefe3 | 2011-06-14 10:42:53 +0800 | [diff] [blame] | 264 | |
| 265 | return_ACPI_STATUS(AE_BAD_SIGNATURE); |
| 266 | } |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 267 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 268 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 270 | /* Check if table is already registered */ |
| 271 | |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 272 | for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 273 | if (!acpi_gbl_root_table_list.tables[i].pointer) { |
| 274 | status = |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 275 | acpi_tb_validate_table(&acpi_gbl_root_table_list. |
| 276 | tables[i]); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 277 | if (ACPI_FAILURE(status) |
| 278 | || !acpi_gbl_root_table_list.tables[i].pointer) { |
| 279 | continue; |
| 280 | } |
| 281 | } |
| 282 | |
Bob Moore | a6f3053 | 2008-07-04 10:57:51 +0800 | [diff] [blame] | 283 | /* |
| 284 | * Check for a table match on the entire table length, |
| 285 | * not just the header. |
| 286 | */ |
| 287 | if (table_desc->length != |
| 288 | acpi_gbl_root_table_list.tables[i].length) { |
| 289 | continue; |
| 290 | } |
Bob Moore | e56f561 | 2008-07-04 10:48:43 +0800 | [diff] [blame] | 291 | |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 292 | if (ACPI_MEMCMP(table_desc->pointer, |
| 293 | acpi_gbl_root_table_list.tables[i].pointer, |
Bob Moore | a6f3053 | 2008-07-04 10:57:51 +0800 | [diff] [blame] | 294 | acpi_gbl_root_table_list.tables[i].length)) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 295 | continue; |
| 296 | } |
| 297 | |
Bob Moore | e56f561 | 2008-07-04 10:48:43 +0800 | [diff] [blame] | 298 | /* |
| 299 | * Note: the current mechanism does not unregister a table if it is |
| 300 | * dynamically unloaded. The related namespace entries are deleted, |
| 301 | * but the table remains in the root table list. |
| 302 | * |
| 303 | * The assumption here is that the number of different tables that |
| 304 | * will be loaded is actually small, and there is minimal overhead |
| 305 | * in just keeping the table in case it is needed again. |
| 306 | * |
| 307 | * If this assumption changes in the future (perhaps on large |
| 308 | * machines with many table load/unload operations), tables will |
| 309 | * need to be unregistered when they are unloaded, and slots in the |
| 310 | * root table list should be reused when empty. |
| 311 | */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 312 | *table_index = i; |
Bob Moore | e56f561 | 2008-07-04 10:48:43 +0800 | [diff] [blame] | 313 | |
| 314 | if (acpi_gbl_root_table_list.tables[i]. |
| 315 | flags & ACPI_TABLE_IS_LOADED) { |
| 316 | |
| 317 | /* Table is still loaded, this is an error */ |
| 318 | |
| 319 | status = AE_ALREADY_EXISTS; |
| 320 | goto release; |
| 321 | } else { |
| 322 | /* Table was unloaded, allow it to be reloaded */ |
| 323 | |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 324 | acpi_tb_uninstall_table(table_desc); |
Bob Moore | e56f561 | 2008-07-04 10:48:43 +0800 | [diff] [blame] | 325 | table_desc->pointer = |
| 326 | acpi_gbl_root_table_list.tables[i].pointer; |
| 327 | table_desc->address = |
| 328 | acpi_gbl_root_table_list.tables[i].address; |
| 329 | status = AE_OK; |
| 330 | goto print_header; |
| 331 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Bob Moore | d3ccaff | 2009-02-03 14:43:04 +0800 | [diff] [blame] | 334 | /* |
| 335 | * ACPI Table Override: |
| 336 | * Allow the host to override dynamically loaded tables. |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 337 | * NOTE: the table is fully mapped at this point, and the mapping will |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 338 | * be deleted by acpi_tb_override_table if the table is actually overridden. |
Bob Moore | d3ccaff | 2009-02-03 14:43:04 +0800 | [diff] [blame] | 339 | */ |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 340 | final_table = acpi_tb_override_table(table_desc->pointer, table_desc); |
| 341 | if (final_table) { |
| 342 | |
| 343 | /* Ensure table descriptor is in "VALIDATED" state */ |
| 344 | |
| 345 | table_desc->pointer = final_table; |
| 346 | } |
Bob Moore | d3ccaff | 2009-02-03 14:43:04 +0800 | [diff] [blame] | 347 | |
Bob Moore | e56f561 | 2008-07-04 10:48:43 +0800 | [diff] [blame] | 348 | /* Add the table to the global root table list */ |
| 349 | |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 350 | status = acpi_tb_store_table(table_desc->address, table_desc->pointer, |
| 351 | table_desc->length, table_desc->flags, |
| 352 | table_index); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 353 | if (ACPI_FAILURE(status)) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 354 | goto release; |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 357 | print_header: |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 358 | acpi_tb_print_table_header(table_desc->address, table_desc->pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 360 | release: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 361 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 362 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | /******************************************************************************* |
| 366 | * |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 367 | * FUNCTION: acpi_tb_override_table |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 368 | * |
| 369 | * PARAMETERS: table_header - Header for the original table |
| 370 | * table_desc - Table descriptor initialized for the |
| 371 | * original table. May or may not be mapped. |
| 372 | * |
| 373 | * RETURN: Pointer to the entire new table. NULL if table not overridden. |
| 374 | * If overridden, installs the new table within the input table |
| 375 | * descriptor. |
| 376 | * |
| 377 | * DESCRIPTION: Attempt table override by calling the OSL override functions. |
| 378 | * Note: If the table is overridden, then the entire new table |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 379 | * is acquired and returned by this function. |
| 380 | * After invocation, the table descriptor is in a state that is |
| 381 | * "INSTALLED" but not "VALIDATED", thus the "Pointer" member is |
| 382 | * kept NULL. |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 383 | * |
| 384 | ******************************************************************************/ |
| 385 | |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 386 | struct acpi_table_header *acpi_tb_override_table(struct acpi_table_header |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 387 | *table_header, |
| 388 | struct acpi_table_desc |
| 389 | *table_desc) |
| 390 | { |
| 391 | acpi_status status; |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 392 | struct acpi_table_header *new_table; |
| 393 | u32 new_table_length; |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 394 | u8 new_flags; |
| 395 | char *override_type; |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 396 | struct acpi_table_desc new_table_desc; |
| 397 | |
| 398 | ACPI_MEMSET(&new_table_desc, 0, sizeof(struct acpi_table_desc)); |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 399 | |
| 400 | /* (1) Attempt logical override (returns a logical address) */ |
| 401 | |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 402 | status = acpi_os_table_override(table_header, &new_table_desc.pointer); |
| 403 | if (ACPI_SUCCESS(status) && new_table_desc.pointer) { |
| 404 | new_table_desc.address = |
| 405 | ACPI_PTR_TO_PHYSADDR(new_table_desc.pointer); |
| 406 | new_table_desc.length = new_table_desc.pointer->length; |
| 407 | new_table_desc.flags = ACPI_TABLE_ORIGIN_OVERRIDE; |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 408 | override_type = "Logical"; |
| 409 | goto finish_override; |
| 410 | } |
| 411 | |
| 412 | /* (2) Attempt physical override (returns a physical address) */ |
| 413 | |
| 414 | status = acpi_os_physical_table_override(table_header, |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 415 | &new_table_desc.address, |
| 416 | &new_table_desc.length); |
| 417 | if (ACPI_SUCCESS(status) && new_table_desc.address |
| 418 | && new_table_desc.length) { |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 419 | override_type = "Physical"; |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 420 | new_table_desc.flags = ACPI_TABLE_ORIGIN_MAPPED; |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 421 | goto finish_override; |
| 422 | } |
| 423 | |
| 424 | return (NULL); /* There was no override */ |
| 425 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 426 | finish_override: |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 427 | |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 428 | /* |
| 429 | * Acquire the entire new table to indicate overridden. |
| 430 | * Note that this is required by the callers of this function. |
| 431 | */ |
| 432 | status = acpi_tb_acquire_table(&new_table_desc, &new_table, |
| 433 | &new_table_length, &new_flags); |
| 434 | if (ACPI_FAILURE(status)) { |
| 435 | ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY, |
| 436 | "%4.4s " ACPI_PRINTF_UINT |
| 437 | " Attempted table override failed", |
| 438 | table_header->signature, |
| 439 | ACPI_FORMAT_TO_UINT(table_desc->address))); |
| 440 | return (NULL); |
| 441 | } |
| 442 | |
Bob Moore | 2e19f8d | 2014-02-08 09:42:07 +0800 | [diff] [blame] | 443 | ACPI_INFO((AE_INFO, "%4.4s " ACPI_PRINTF_UINT |
| 444 | " %s table override, new table: " ACPI_PRINTF_UINT, |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 445 | table_header->signature, |
Bob Moore | 2e19f8d | 2014-02-08 09:42:07 +0800 | [diff] [blame] | 446 | ACPI_FORMAT_TO_UINT(table_desc->address), |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 447 | override_type, ACPI_FORMAT_TO_UINT(new_table_desc.address))); |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 448 | |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 449 | /* We can now uninstall the original table (if fully mapped) */ |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 450 | |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 451 | acpi_tb_uninstall_table(table_desc); |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 452 | |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 453 | /* Install the new table */ |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 454 | |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 455 | table_desc->address = new_table_desc.address; |
| 456 | table_desc->length = new_table_desc.length; |
| 457 | table_desc->flags = new_table_desc.flags; |
Bob Moore | f7b004a | 2012-02-14 18:31:56 +0800 | [diff] [blame] | 458 | |
| 459 | return (new_table); |
| 460 | } |
| 461 | |
| 462 | /******************************************************************************* |
| 463 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 464 | * FUNCTION: acpi_tb_resize_root_table_list |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 466 | * PARAMETERS: None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | * |
| 468 | * RETURN: Status |
| 469 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 470 | * DESCRIPTION: Expand the size of global table array |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | * |
| 472 | ******************************************************************************/ |
| 473 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 474 | acpi_status acpi_tb_resize_root_table_list(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 476 | struct acpi_table_desc *tables; |
Lv Zheng | 2bc198c | 2012-09-13 09:29:06 -0700 | [diff] [blame] | 477 | u32 table_count; |
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 | ACPI_FUNCTION_TRACE(tb_resize_root_table_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 481 | /* allow_resize flag is a parameter to acpi_initialize_tables */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 483 | if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 484 | ACPI_ERROR((AE_INFO, |
| 485 | "Resize of Root Table Array is not allowed")); |
| 486 | return_ACPI_STATUS(AE_SUPPORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } |
| 488 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 489 | /* Increase the Table Array size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
Lv Zheng | 2bc198c | 2012-09-13 09:29:06 -0700 | [diff] [blame] | 491 | if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { |
| 492 | table_count = acpi_gbl_root_table_list.max_table_count; |
| 493 | } else { |
| 494 | table_count = acpi_gbl_root_table_list.current_table_count; |
| 495 | } |
| 496 | |
| 497 | tables = ACPI_ALLOCATE_ZEROED(((acpi_size) table_count + |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 498 | ACPI_ROOT_TABLE_SIZE_INCREMENT) * |
| 499 | sizeof(struct acpi_table_desc)); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 500 | if (!tables) { |
| 501 | ACPI_ERROR((AE_INFO, |
| 502 | "Could not allocate new root table array")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 503 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | } |
| 505 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 506 | /* Copy and free the previous table array */ |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 507 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 508 | if (acpi_gbl_root_table_list.tables) { |
| 509 | ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables, |
Lv Zheng | 2bc198c | 2012-09-13 09:29:06 -0700 | [diff] [blame] | 510 | (acpi_size) table_count * |
| 511 | sizeof(struct acpi_table_desc)); |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 512 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 513 | if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 514 | ACPI_FREE(acpi_gbl_root_table_list.tables); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | } |
| 516 | } |
| 517 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 518 | acpi_gbl_root_table_list.tables = tables; |
Lv Zheng | 2bc198c | 2012-09-13 09:29:06 -0700 | [diff] [blame] | 519 | acpi_gbl_root_table_list.max_table_count = |
| 520 | table_count + ACPI_ROOT_TABLE_SIZE_INCREMENT; |
| 521 | acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 523 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | /******************************************************************************* |
| 527 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 528 | * FUNCTION: acpi_tb_store_table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 530 | * PARAMETERS: address - Table address |
| 531 | * table - Table header |
| 532 | * length - Table length |
| 533 | * flags - flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 535 | * RETURN: Status and table index. |
| 536 | * |
| 537 | * DESCRIPTION: Add an ACPI table to the global table list |
| 538 | * |
| 539 | ******************************************************************************/ |
| 540 | |
| 541 | acpi_status |
| 542 | acpi_tb_store_table(acpi_physical_address address, |
| 543 | struct acpi_table_header *table, |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 544 | u32 length, u8 flags, u32 *table_index) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 545 | { |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 546 | acpi_status status; |
| 547 | struct acpi_table_desc *new_table; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 548 | |
| 549 | /* Ensure that there is room for the table in the Root Table List */ |
| 550 | |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 551 | if (acpi_gbl_root_table_list.current_table_count >= |
| 552 | acpi_gbl_root_table_list.max_table_count) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 553 | status = acpi_tb_resize_root_table_list(); |
| 554 | if (ACPI_FAILURE(status)) { |
| 555 | return (status); |
| 556 | } |
| 557 | } |
| 558 | |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 559 | new_table = |
| 560 | &acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list. |
| 561 | current_table_count]; |
| 562 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 563 | /* Initialize added table */ |
| 564 | |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 565 | new_table->address = address; |
| 566 | new_table->pointer = table; |
| 567 | new_table->length = length; |
| 568 | new_table->owner_id = 0; |
| 569 | new_table->flags = flags; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 570 | |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 571 | ACPI_MOVE_32_TO_32(&new_table->signature, table->signature); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 572 | |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 573 | *table_index = acpi_gbl_root_table_list.current_table_count; |
| 574 | acpi_gbl_root_table_list.current_table_count++; |
| 575 | return (AE_OK); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | /******************************************************************************* |
| 579 | * |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 580 | * FUNCTION: acpi_tb_uninstall_table |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 581 | * |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 582 | * PARAMETERS: table_desc - Table descriptor |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 583 | * |
| 584 | * RETURN: None |
| 585 | * |
| 586 | * DESCRIPTION: Delete one internal ACPI table |
| 587 | * |
| 588 | ******************************************************************************/ |
| 589 | |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 590 | void acpi_tb_uninstall_table(struct acpi_table_desc *table_desc) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 591 | { |
Lv Zheng | 5582982 | 2014-04-04 12:38:18 +0800 | [diff] [blame] | 592 | |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 593 | ACPI_FUNCTION_TRACE(tb_uninstall_table); |
Lv Zheng | 5582982 | 2014-04-04 12:38:18 +0800 | [diff] [blame] | 594 | |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 595 | /* Table must be installed */ |
| 596 | |
| 597 | if (!table_desc->address) { |
| 598 | return_VOID; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 599 | } |
Lv Zheng | 5582982 | 2014-04-04 12:38:18 +0800 | [diff] [blame] | 600 | |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 601 | acpi_tb_invalidate_table(table_desc); |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 602 | |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 603 | if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) == |
| 604 | ACPI_TABLE_ORIGIN_ALLOCATED) { |
| 605 | ACPI_FREE(ACPI_CAST_PTR(void, table_desc->address)); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 606 | } |
| 607 | |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 608 | table_desc->address = ACPI_PTR_TO_PHYSADDR(NULL); |
| 609 | |
| 610 | return_VOID; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /******************************************************************************* |
| 614 | * |
| 615 | * FUNCTION: acpi_tb_terminate |
| 616 | * |
| 617 | * PARAMETERS: None |
| 618 | * |
| 619 | * RETURN: None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | * |
| 621 | * DESCRIPTION: Delete all internal ACPI tables |
| 622 | * |
| 623 | ******************************************************************************/ |
| 624 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 625 | void acpi_tb_terminate(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 627 | u32 i; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 628 | |
| 629 | ACPI_FUNCTION_TRACE(tb_terminate); |
| 630 | |
| 631 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
| 632 | |
| 633 | /* Delete the individual tables */ |
| 634 | |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 635 | for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) { |
Lv Zheng | 7f9fc99 | 2014-04-04 12:38:42 +0800 | [diff] [blame^] | 636 | acpi_tb_uninstall_table(&acpi_gbl_root_table_list.tables[i]); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 637 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | |
| 639 | /* |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 640 | * Delete the root table array if allocated locally. Array cannot be |
| 641 | * mapped, so we don't need to check for that flag. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | */ |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 643 | if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 644 | ACPI_FREE(acpi_gbl_root_table_list.tables); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | } |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 646 | |
| 647 | acpi_gbl_root_table_list.tables = NULL; |
| 648 | acpi_gbl_root_table_list.flags = 0; |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 649 | acpi_gbl_root_table_list.current_table_count = 0; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 650 | |
| 651 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n")); |
| 652 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
Bob Moore | 68aafc3 | 2012-10-31 02:26:01 +0000 | [diff] [blame] | 653 | |
| 654 | return_VOID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | /******************************************************************************* |
| 658 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 659 | * FUNCTION: acpi_tb_delete_namespace_by_owner |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 661 | * PARAMETERS: table_index - Table index |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | * |
Bob Moore | 8a335a23 | 2009-03-09 16:31:04 +0800 | [diff] [blame] | 663 | * RETURN: Status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 665 | * DESCRIPTION: Delete all namespace objects created when this table was loaded. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | * |
| 667 | ******************************************************************************/ |
| 668 | |
Bob Moore | 8a335a23 | 2009-03-09 16:31:04 +0800 | [diff] [blame] | 669 | acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 671 | acpi_owner_id owner_id; |
Bob Moore | 8a335a23 | 2009-03-09 16:31:04 +0800 | [diff] [blame] | 672 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
Bob Moore | 8a335a23 | 2009-03-09 16:31:04 +0800 | [diff] [blame] | 674 | ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner); |
| 675 | |
| 676 | status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
| 677 | if (ACPI_FAILURE(status)) { |
| 678 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 681 | if (table_index >= acpi_gbl_root_table_list.current_table_count) { |
Bob Moore | 8a335a23 | 2009-03-09 16:31:04 +0800 | [diff] [blame] | 682 | |
| 683 | /* The table index does not exist */ |
| 684 | |
| 685 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 686 | return_ACPI_STATUS(AE_NOT_EXIST); |
| 687 | } |
| 688 | |
| 689 | /* Get the owner ID for this table, used to delete namespace nodes */ |
| 690 | |
| 691 | owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 692 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
Bob Moore | 8a335a23 | 2009-03-09 16:31:04 +0800 | [diff] [blame] | 693 | |
| 694 | /* |
| 695 | * Need to acquire the namespace writer lock to prevent interference |
| 696 | * with any concurrent namespace walks. The interpreter must be |
| 697 | * released during the deletion since the acquisition of the deletion |
| 698 | * lock may block, and also since the execution of a namespace walk |
| 699 | * must be allowed to use the interpreter. |
| 700 | */ |
Bob Moore | e4c1ebf | 2009-04-22 13:02:06 +0800 | [diff] [blame] | 701 | (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER); |
Bob Moore | 8a335a23 | 2009-03-09 16:31:04 +0800 | [diff] [blame] | 702 | status = acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock); |
| 703 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 704 | acpi_ns_delete_namespace_by_owner(owner_id); |
Bob Moore | 8a335a23 | 2009-03-09 16:31:04 +0800 | [diff] [blame] | 705 | if (ACPI_FAILURE(status)) { |
| 706 | return_ACPI_STATUS(status); |
| 707 | } |
| 708 | |
| 709 | acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock); |
| 710 | |
| 711 | status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER); |
| 712 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | } |
| 714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | /******************************************************************************* |
| 716 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 717 | * FUNCTION: acpi_tb_allocate_owner_id |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 719 | * PARAMETERS: table_index - Table index |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 721 | * RETURN: Status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 723 | * DESCRIPTION: Allocates owner_id in table_desc |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | * |
| 725 | ******************************************************************************/ |
| 726 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 727 | acpi_status acpi_tb_allocate_owner_id(u32 table_index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 729 | acpi_status status = AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 731 | ACPI_FUNCTION_TRACE(tb_allocate_owner_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 733 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 734 | if (table_index < acpi_gbl_root_table_list.current_table_count) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 735 | status = acpi_ut_allocate_owner_id |
| 736 | (&(acpi_gbl_root_table_list.tables[table_index].owner_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | } |
| 738 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 739 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 740 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | } |
| 742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | /******************************************************************************* |
| 744 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 745 | * FUNCTION: acpi_tb_release_owner_id |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 747 | * PARAMETERS: table_index - Table index |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 749 | * RETURN: Status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 751 | * DESCRIPTION: Releases owner_id in table_desc |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | * |
| 753 | ******************************************************************************/ |
| 754 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 755 | acpi_status acpi_tb_release_owner_id(u32 table_index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 757 | acpi_status status = AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 759 | ACPI_FUNCTION_TRACE(tb_release_owner_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 761 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 762 | if (table_index < acpi_gbl_root_table_list.current_table_count) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 763 | acpi_ut_release_owner_id(& |
| 764 | (acpi_gbl_root_table_list. |
| 765 | tables[table_index].owner_id)); |
| 766 | status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | } |
| 768 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 769 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 770 | return_ACPI_STATUS(status); |
| 771 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 773 | /******************************************************************************* |
| 774 | * |
| 775 | * FUNCTION: acpi_tb_get_owner_id |
| 776 | * |
| 777 | * PARAMETERS: table_index - Table index |
| 778 | * owner_id - Where the table owner_id is returned |
| 779 | * |
| 780 | * RETURN: Status |
| 781 | * |
| 782 | * DESCRIPTION: returns owner_id for the ACPI table |
| 783 | * |
| 784 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
Lv Zheng | 5582982 | 2014-04-04 12:38:18 +0800 | [diff] [blame] | 786 | 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] | 787 | { |
| 788 | acpi_status status = AE_BAD_PARAMETER; |
| 789 | |
| 790 | ACPI_FUNCTION_TRACE(tb_get_owner_id); |
| 791 | |
| 792 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 793 | if (table_index < acpi_gbl_root_table_list.current_table_count) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 794 | *owner_id = |
| 795 | acpi_gbl_root_table_list.tables[table_index].owner_id; |
| 796 | status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 799 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 800 | return_ACPI_STATUS(status); |
| 801 | } |
| 802 | |
| 803 | /******************************************************************************* |
| 804 | * |
| 805 | * FUNCTION: acpi_tb_is_table_loaded |
| 806 | * |
| 807 | * PARAMETERS: table_index - Table index |
| 808 | * |
| 809 | * RETURN: Table Loaded Flag |
| 810 | * |
| 811 | ******************************************************************************/ |
| 812 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 813 | u8 acpi_tb_is_table_loaded(u32 table_index) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 814 | { |
| 815 | u8 is_loaded = FALSE; |
| 816 | |
| 817 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 818 | if (table_index < acpi_gbl_root_table_list.current_table_count) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 819 | is_loaded = (u8) |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 820 | (acpi_gbl_root_table_list.tables[table_index].flags & |
| 821 | ACPI_TABLE_IS_LOADED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 824 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 825 | return (is_loaded); |
| 826 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 828 | /******************************************************************************* |
| 829 | * |
| 830 | * FUNCTION: acpi_tb_set_table_loaded_flag |
| 831 | * |
| 832 | * PARAMETERS: table_index - Table index |
| 833 | * is_loaded - TRUE if table is loaded, FALSE otherwise |
| 834 | * |
| 835 | * RETURN: None |
| 836 | * |
| 837 | * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE. |
| 838 | * |
| 839 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 841 | 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] | 842 | { |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 843 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 844 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 845 | if (table_index < acpi_gbl_root_table_list.current_table_count) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 846 | if (is_loaded) { |
| 847 | acpi_gbl_root_table_list.tables[table_index].flags |= |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 848 | ACPI_TABLE_IS_LOADED; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 849 | } else { |
| 850 | acpi_gbl_root_table_list.tables[table_index].flags &= |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 851 | ~ACPI_TABLE_IS_LOADED; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 852 | } |
| 853 | } |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 854 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 855 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | } |