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