Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Bob Moore | d59b8ec | 2012-07-16 10:15:36 +0800 | [diff] [blame^] | 3 | * Module Name: tbxface - ACPI table oriented external interfaces |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | 7784813 | 2012-01-12 13:27:23 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2012, 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 | |
Paul Gortmaker | 214f2c9 | 2011-10-26 16:22:14 -0400 | [diff] [blame] | 44 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 46 | #include "accommon.h" |
| 47 | #include "acnamesp.h" |
| 48 | #include "actables.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define _COMPONENT ACPI_TABLES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | ACPI_MODULE_NAME("tbxface") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | /******************************************************************************* |
| 54 | * |
Bob Moore | 77389e1 | 2007-02-02 19:48:20 +0300 | [diff] [blame] | 55 | * FUNCTION: acpi_allocate_root_table |
| 56 | * |
| 57 | * PARAMETERS: initial_table_count - Size of initial_table_array, in number of |
| 58 | * struct acpi_table_desc structures |
| 59 | * |
| 60 | * RETURN: Status |
| 61 | * |
| 62 | * DESCRIPTION: Allocate a root table array. Used by i_aSL compiler and |
| 63 | * acpi_initialize_tables. |
| 64 | * |
| 65 | ******************************************************************************/ |
Bob Moore | 77389e1 | 2007-02-02 19:48:20 +0300 | [diff] [blame] | 66 | acpi_status acpi_allocate_root_table(u32 initial_table_count) |
| 67 | { |
| 68 | |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 69 | acpi_gbl_root_table_list.max_table_count = initial_table_count; |
Bob Moore | 77389e1 | 2007-02-02 19:48:20 +0300 | [diff] [blame] | 70 | acpi_gbl_root_table_list.flags = ACPI_ROOT_ALLOW_RESIZE; |
| 71 | |
| 72 | return (acpi_tb_resize_root_table_list()); |
| 73 | } |
| 74 | |
| 75 | /******************************************************************************* |
| 76 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 77 | * FUNCTION: acpi_initialize_tables |
| 78 | * |
| 79 | * PARAMETERS: initial_table_array - Pointer to an array of pre-allocated |
| 80 | * struct acpi_table_desc structures. If NULL, the |
| 81 | * array is dynamically allocated. |
| 82 | * initial_table_count - Size of initial_table_array, in number of |
| 83 | * struct acpi_table_desc structures |
| 84 | * allow_realloc - Flag to tell Table Manager if resize of |
| 85 | * pre-allocated array is allowed. Ignored |
| 86 | * if initial_table_array is NULL. |
| 87 | * |
| 88 | * RETURN: Status |
| 89 | * |
| 90 | * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT. |
| 91 | * |
| 92 | * NOTE: Allows static allocation of the initial table array in order |
| 93 | * to avoid the use of dynamic memory in confined environments |
| 94 | * such as the kernel boot sequence where it may not be available. |
| 95 | * |
| 96 | * If the host OS memory managers are initialized, use NULL for |
| 97 | * initial_table_array, and the table will be dynamically allocated. |
| 98 | * |
| 99 | ******************************************************************************/ |
| 100 | |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 101 | acpi_status __init |
Bob Moore | 77389e1 | 2007-02-02 19:48:20 +0300 | [diff] [blame] | 102 | acpi_initialize_tables(struct acpi_table_desc * initial_table_array, |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 103 | u32 initial_table_count, u8 allow_resize) |
| 104 | { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 105 | acpi_physical_address rsdp_address; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 106 | acpi_status status; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 107 | |
| 108 | ACPI_FUNCTION_TRACE(acpi_initialize_tables); |
| 109 | |
| 110 | /* |
| 111 | * Set up the Root Table Array |
| 112 | * Allocate the table array if requested |
| 113 | */ |
| 114 | if (!initial_table_array) { |
Bob Moore | 77389e1 | 2007-02-02 19:48:20 +0300 | [diff] [blame] | 115 | status = acpi_allocate_root_table(initial_table_count); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 116 | if (ACPI_FAILURE(status)) { |
| 117 | return_ACPI_STATUS(status); |
| 118 | } |
| 119 | } else { |
| 120 | /* Root Table Array has been statically allocated by the host */ |
| 121 | |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 122 | ACPI_MEMSET(initial_table_array, 0, |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 123 | (acpi_size) initial_table_count * |
Bob Moore | a4bbb81 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 124 | sizeof(struct acpi_table_desc)); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 125 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 126 | acpi_gbl_root_table_list.tables = initial_table_array; |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 127 | acpi_gbl_root_table_list.max_table_count = initial_table_count; |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 128 | acpi_gbl_root_table_list.flags = ACPI_ROOT_ORIGIN_UNKNOWN; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 129 | if (allow_resize) { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 130 | acpi_gbl_root_table_list.flags |= |
| 131 | ACPI_ROOT_ALLOW_RESIZE; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 135 | /* Get the address of the RSDP */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 136 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 137 | rsdp_address = acpi_os_get_root_pointer(); |
| 138 | if (!rsdp_address) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 139 | return_ACPI_STATUS(AE_NOT_FOUND); |
| 140 | } |
| 141 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 142 | /* |
| 143 | * Get the root table (RSDT or XSDT) and extract all entries to the local |
| 144 | * Root Table Array. This array contains the information of the RSDT/XSDT |
| 145 | * in a common, more useable format. |
| 146 | */ |
Bob Moore | 97cbb7d | 2009-02-03 14:41:03 +0800 | [diff] [blame] | 147 | status = acpi_tb_parse_root_table(rsdp_address); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 148 | return_ACPI_STATUS(status); |
| 149 | } |
| 150 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 151 | /******************************************************************************* |
| 152 | * |
| 153 | * FUNCTION: acpi_reallocate_root_table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | * |
| 155 | * PARAMETERS: None |
| 156 | * |
| 157 | * RETURN: Status |
| 158 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 159 | * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the |
| 160 | * root list from the previously provided scratch area. Should |
| 161 | * be called once dynamic memory allocation is available in the |
| 162 | * kernel |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | * |
| 164 | ******************************************************************************/ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 165 | acpi_status acpi_reallocate_root_table(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 167 | struct acpi_table_desc *tables; |
| 168 | acpi_size new_size; |
Alexey Starikovskiy | 333b04a | 2010-04-01 11:06:34 +0800 | [diff] [blame] | 169 | acpi_size current_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 171 | ACPI_FUNCTION_TRACE(acpi_reallocate_root_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 173 | /* |
| 174 | * Only reallocate the root table if the host provided a static buffer |
| 175 | * for the table array in the call to acpi_initialize_tables. |
| 176 | */ |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 177 | if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 178 | return_ACPI_STATUS(AE_SUPPORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Alexey Starikovskiy | 333b04a | 2010-04-01 11:06:34 +0800 | [diff] [blame] | 181 | /* |
| 182 | * Get the current size of the root table and add the default |
| 183 | * increment to create the new table size. |
| 184 | */ |
| 185 | current_size = (acpi_size) |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 186 | acpi_gbl_root_table_list.current_table_count * |
| 187 | sizeof(struct acpi_table_desc); |
Alexey Starikovskiy | 333b04a | 2010-04-01 11:06:34 +0800 | [diff] [blame] | 188 | |
| 189 | new_size = current_size + |
| 190 | (ACPI_ROOT_TABLE_SIZE_INCREMENT * sizeof(struct acpi_table_desc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 192 | /* Create new array and copy the old array */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 194 | tables = ACPI_ALLOCATE_ZEROED(new_size); |
| 195 | if (!tables) { |
| 196 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Alexey Starikovskiy | 333b04a | 2010-04-01 11:06:34 +0800 | [diff] [blame] | 199 | ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables, current_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Alexey Starikovskiy | 333b04a | 2010-04-01 11:06:34 +0800 | [diff] [blame] | 201 | /* |
| 202 | * Update the root table descriptor. The new size will be the current |
| 203 | * number of tables plus the increment, independent of the reserved |
| 204 | * size of the original table list. |
| 205 | */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 206 | acpi_gbl_root_table_list.tables = tables; |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 207 | acpi_gbl_root_table_list.max_table_count = |
| 208 | acpi_gbl_root_table_list.current_table_count + |
| 209 | ACPI_ROOT_TABLE_SIZE_INCREMENT; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 210 | acpi_gbl_root_table_list.flags = |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 211 | ACPI_ROOT_ORIGIN_ALLOCATED | ACPI_ROOT_ALLOW_RESIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 213 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
Len Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | /******************************************************************************* |
| 217 | * |
| 218 | * FUNCTION: acpi_load_table |
| 219 | * |
| 220 | * PARAMETERS: table_ptr - pointer to a buffer containing the entire |
| 221 | * table to be loaded |
| 222 | * |
| 223 | * RETURN: Status |
| 224 | * |
| 225 | * DESCRIPTION: This function is called to load a table from the caller's |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 226 | * buffer. The buffer must contain an entire ACPI Table including |
| 227 | * a valid header. The header fields will be verified, and if it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | * is determined that the table is invalid, the call will fail. |
| 229 | * |
| 230 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 231 | acpi_status acpi_load_table(struct acpi_table_header *table_ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 233 | acpi_status status; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 234 | u32 table_index; |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 235 | struct acpi_table_desc table_desc; |
| 236 | |
| 237 | if (!table_ptr) |
| 238 | return AE_BAD_PARAMETER; |
| 239 | |
| 240 | ACPI_MEMSET(&table_desc, 0, sizeof(struct acpi_table_desc)); |
| 241 | table_desc.pointer = table_ptr; |
| 242 | table_desc.length = table_ptr->length; |
| 243 | table_desc.flags = ACPI_TABLE_ORIGIN_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 245 | /* |
| 246 | * Install the new table into the local data structures |
| 247 | */ |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 248 | status = acpi_tb_add_table(&table_desc, &table_index); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 249 | if (ACPI_FAILURE(status)) { |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 250 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | } |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 252 | status = acpi_ns_load_table(table_index, acpi_gbl_root_node); |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 253 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 256 | ACPI_EXPORT_SYMBOL(acpi_load_table) |
| 257 | |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 258 | /******************************************************************************* |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 259 | * |
| 260 | * FUNCTION: acpi_get_table_header |
| 261 | * |
| 262 | * PARAMETERS: Signature - ACPI signature of needed table |
| 263 | * Instance - Which instance (for SSDTs) |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 264 | * out_table_header - The pointer to the table header to fill |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 265 | * |
| 266 | * RETURN: Status and pointer to mapped table header |
| 267 | * |
| 268 | * DESCRIPTION: Finds an ACPI table header. |
| 269 | * |
| 270 | * NOTE: Caller is responsible in unmapping the header with |
| 271 | * acpi_os_unmap_memory |
| 272 | * |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 273 | ******************************************************************************/ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 274 | acpi_status |
| 275 | acpi_get_table_header(char *signature, |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 276 | u32 instance, struct acpi_table_header *out_table_header) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 277 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 278 | u32 i; |
| 279 | u32 j; |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 280 | struct acpi_table_header *header; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 281 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 282 | /* Parameter validation */ |
| 283 | |
| 284 | if (!signature || !out_table_header) { |
| 285 | return (AE_BAD_PARAMETER); |
| 286 | } |
| 287 | |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 288 | /* Walk the root table list */ |
| 289 | |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 290 | for (i = 0, j = 0; i < acpi_gbl_root_table_list.current_table_count; |
| 291 | i++) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 292 | if (!ACPI_COMPARE_NAME |
| 293 | (&(acpi_gbl_root_table_list.tables[i].signature), |
| 294 | signature)) { |
| 295 | continue; |
| 296 | } |
| 297 | |
| 298 | if (++j < instance) { |
| 299 | continue; |
| 300 | } |
| 301 | |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 302 | if (!acpi_gbl_root_table_list.tables[i].pointer) { |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 303 | if ((acpi_gbl_root_table_list.tables[i].flags & |
| 304 | ACPI_TABLE_ORIGIN_MASK) == |
Alexey Starikovskiy | 428f211 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 305 | ACPI_TABLE_ORIGIN_MAPPED) { |
| 306 | header = |
| 307 | acpi_os_map_memory(acpi_gbl_root_table_list. |
| 308 | tables[i].address, |
| 309 | sizeof(struct |
| 310 | acpi_table_header)); |
| 311 | if (!header) { |
| 312 | return AE_NO_MEMORY; |
| 313 | } |
| 314 | ACPI_MEMCPY(out_table_header, header, |
| 315 | sizeof(struct acpi_table_header)); |
| 316 | acpi_os_unmap_memory(header, |
| 317 | sizeof(struct |
| 318 | acpi_table_header)); |
| 319 | } else { |
| 320 | return AE_NOT_FOUND; |
| 321 | } |
| 322 | } else { |
| 323 | ACPI_MEMCPY(out_table_header, |
| 324 | acpi_gbl_root_table_list.tables[i].pointer, |
| 325 | sizeof(struct acpi_table_header)); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 326 | } |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 327 | return (AE_OK); |
| 328 | } |
| 329 | |
| 330 | return (AE_NOT_FOUND); |
| 331 | } |
| 332 | |
| 333 | ACPI_EXPORT_SYMBOL(acpi_get_table_header) |
| 334 | |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 335 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | * |
John Keller | 0f0fe1a | 2006-12-19 12:56:19 -0800 | [diff] [blame] | 337 | * FUNCTION: acpi_unload_table_id |
| 338 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 339 | * PARAMETERS: id - Owner ID of the table to be removed. |
John Keller | 0f0fe1a | 2006-12-19 12:56:19 -0800 | [diff] [blame] | 340 | * |
| 341 | * RETURN: Status |
| 342 | * |
| 343 | * DESCRIPTION: This routine is used to force the unload of a table (by id) |
| 344 | * |
| 345 | ******************************************************************************/ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 346 | acpi_status acpi_unload_table_id(acpi_owner_id id) |
John Keller | 0f0fe1a | 2006-12-19 12:56:19 -0800 | [diff] [blame] | 347 | { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 348 | int i; |
| 349 | acpi_status status = AE_NOT_EXIST; |
John Keller | 0f0fe1a | 2006-12-19 12:56:19 -0800 | [diff] [blame] | 350 | |
John Keller | ecb5f75 | 2007-02-15 14:08:30 -0600 | [diff] [blame] | 351 | ACPI_FUNCTION_TRACE(acpi_unload_table_id); |
John Keller | 0f0fe1a | 2006-12-19 12:56:19 -0800 | [diff] [blame] | 352 | |
John Keller | ecb5f75 | 2007-02-15 14:08:30 -0600 | [diff] [blame] | 353 | /* Find table in the global table list */ |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 354 | 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] | 355 | if (id != acpi_gbl_root_table_list.tables[i].owner_id) { |
| 356 | continue; |
| 357 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | /* |
Len Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 359 | * Delete all namespace objects owned by this table. Note that these |
| 360 | * objects can appear anywhere in the namespace by virtue of the AML |
| 361 | * "Scope" operator. Thus, we need to track ownership by an ID, not |
| 362 | * simply a position within the hierarchy |
| 363 | */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 364 | acpi_tb_delete_namespace_by_owner(i); |
John Keller | ecb5f75 | 2007-02-15 14:08:30 -0600 | [diff] [blame] | 365 | status = acpi_tb_release_owner_id(i); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 366 | acpi_tb_set_table_loaded_flag(i, FALSE); |
John Keller | ecb5f75 | 2007-02-15 14:08:30 -0600 | [diff] [blame] | 367 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 369 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 372 | ACPI_EXPORT_SYMBOL(acpi_unload_table_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
| 374 | /******************************************************************************* |
| 375 | * |
Yinghai Lu | 7d97277 | 2009-02-07 15:39:41 -0800 | [diff] [blame] | 376 | * FUNCTION: acpi_get_table_with_size |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 378 | * PARAMETERS: Signature - ACPI signature of needed table |
| 379 | * Instance - Which instance (for SSDTs) |
| 380 | * out_table - Where the pointer to the table is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 382 | * RETURN: Status and pointer to table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 384 | * DESCRIPTION: Finds and verifies an ACPI table. |
| 385 | * |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 386 | ******************************************************************************/ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 387 | acpi_status |
Yinghai Lu | 7d97277 | 2009-02-07 15:39:41 -0800 | [diff] [blame] | 388 | acpi_get_table_with_size(char *signature, |
| 389 | u32 instance, struct acpi_table_header **out_table, |
| 390 | acpi_size *tbl_size) |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 391 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 392 | u32 i; |
| 393 | u32 j; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 394 | acpi_status status; |
| 395 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 396 | /* Parameter validation */ |
| 397 | |
| 398 | if (!signature || !out_table) { |
| 399 | return (AE_BAD_PARAMETER); |
| 400 | } |
| 401 | |
Bob Moore | ec41f19 | 2009-02-18 15:03:30 +0800 | [diff] [blame] | 402 | /* Walk the root table list */ |
| 403 | |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 404 | for (i = 0, j = 0; i < acpi_gbl_root_table_list.current_table_count; |
| 405 | i++) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 406 | if (!ACPI_COMPARE_NAME |
| 407 | (&(acpi_gbl_root_table_list.tables[i].signature), |
| 408 | signature)) { |
| 409 | continue; |
| 410 | } |
| 411 | |
| 412 | if (++j < instance) { |
| 413 | continue; |
| 414 | } |
| 415 | |
| 416 | status = |
| 417 | acpi_tb_verify_table(&acpi_gbl_root_table_list.tables[i]); |
| 418 | if (ACPI_SUCCESS(status)) { |
| 419 | *out_table = acpi_gbl_root_table_list.tables[i].pointer; |
Yinghai Lu | 7d97277 | 2009-02-07 15:39:41 -0800 | [diff] [blame] | 420 | *tbl_size = acpi_gbl_root_table_list.tables[i].length; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 421 | } |
| 422 | |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 423 | if (!acpi_gbl_permanent_mmap) { |
Randy Dunlap | 70c0846 | 2007-02-13 16:11:36 -0800 | [diff] [blame] | 424 | acpi_gbl_root_table_list.tables[i].pointer = NULL; |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 425 | } |
| 426 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 427 | return (status); |
| 428 | } |
| 429 | |
| 430 | return (AE_NOT_FOUND); |
| 431 | } |
| 432 | |
Yinghai Lu | 7d97277 | 2009-02-07 15:39:41 -0800 | [diff] [blame] | 433 | acpi_status |
| 434 | acpi_get_table(char *signature, |
| 435 | u32 instance, struct acpi_table_header **out_table) |
| 436 | { |
| 437 | acpi_size tbl_size; |
| 438 | |
| 439 | return acpi_get_table_with_size(signature, |
| 440 | instance, out_table, &tbl_size); |
| 441 | } |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 442 | ACPI_EXPORT_SYMBOL(acpi_get_table) |
| 443 | |
| 444 | /******************************************************************************* |
| 445 | * |
| 446 | * FUNCTION: acpi_get_table_by_index |
| 447 | * |
| 448 | * PARAMETERS: table_index - Table index |
| 449 | * Table - Where the pointer to the table is returned |
| 450 | * |
| 451 | * RETURN: Status and pointer to the table |
| 452 | * |
| 453 | * DESCRIPTION: Obtain a table by an index into the global table list. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | * |
| 455 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | acpi_status |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 457 | acpi_get_table_by_index(u32 table_index, struct acpi_table_header **table) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 459 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 461 | ACPI_FUNCTION_TRACE(acpi_get_table_by_index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 463 | /* Parameter validation */ |
| 464 | |
| 465 | if (!table) { |
| 466 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 467 | } |
| 468 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 469 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 471 | /* Validate index */ |
| 472 | |
Bob Moore | b9ee204 | 2010-04-27 11:16:14 +0800 | [diff] [blame] | 473 | if (table_index >= acpi_gbl_root_table_list.current_table_count) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 474 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 475 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 478 | if (!acpi_gbl_root_table_list.tables[table_index].pointer) { |
| 479 | |
| 480 | /* Table is not mapped, map it */ |
| 481 | |
| 482 | status = |
| 483 | acpi_tb_verify_table(&acpi_gbl_root_table_list. |
| 484 | tables[table_index]); |
| 485 | if (ACPI_FAILURE(status)) { |
| 486 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 487 | return_ACPI_STATUS(status); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | *table = acpi_gbl_root_table_list.tables[table_index].pointer; |
| 492 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 493 | return_ACPI_STATUS(AE_OK); |
| 494 | } |
| 495 | |
| 496 | ACPI_EXPORT_SYMBOL(acpi_get_table_by_index) |
| 497 | |
Len Brown | 67effe8 | 2007-07-26 00:50:06 -0400 | [diff] [blame] | 498 | |
Lin Ming | 3e08e2d | 2008-04-10 19:06:38 +0400 | [diff] [blame] | 499 | /******************************************************************************* |
| 500 | * |
| 501 | * FUNCTION: acpi_install_table_handler |
| 502 | * |
| 503 | * PARAMETERS: Handler - Table event handler |
| 504 | * Context - Value passed to the handler on each event |
| 505 | * |
| 506 | * RETURN: Status |
| 507 | * |
| 508 | * DESCRIPTION: Install table event handler |
| 509 | * |
| 510 | ******************************************************************************/ |
| 511 | acpi_status |
| 512 | acpi_install_table_handler(acpi_tbl_handler handler, void *context) |
| 513 | { |
| 514 | acpi_status status; |
| 515 | |
| 516 | ACPI_FUNCTION_TRACE(acpi_install_table_handler); |
| 517 | |
| 518 | if (!handler) { |
| 519 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 520 | } |
| 521 | |
| 522 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 523 | if (ACPI_FAILURE(status)) { |
| 524 | return_ACPI_STATUS(status); |
| 525 | } |
| 526 | |
| 527 | /* Don't allow more than one handler */ |
| 528 | |
| 529 | if (acpi_gbl_table_handler) { |
| 530 | status = AE_ALREADY_EXISTS; |
| 531 | goto cleanup; |
| 532 | } |
| 533 | |
| 534 | /* Install the handler */ |
| 535 | |
| 536 | acpi_gbl_table_handler = handler; |
| 537 | acpi_gbl_table_handler_context = context; |
| 538 | |
| 539 | cleanup: |
| 540 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 541 | return_ACPI_STATUS(status); |
| 542 | } |
| 543 | |
| 544 | ACPI_EXPORT_SYMBOL(acpi_install_table_handler) |
| 545 | |
| 546 | /******************************************************************************* |
| 547 | * |
| 548 | * FUNCTION: acpi_remove_table_handler |
| 549 | * |
| 550 | * PARAMETERS: Handler - Table event handler that was installed |
| 551 | * previously. |
| 552 | * |
| 553 | * RETURN: Status |
| 554 | * |
| 555 | * DESCRIPTION: Remove table event handler |
| 556 | * |
| 557 | ******************************************************************************/ |
| 558 | acpi_status acpi_remove_table_handler(acpi_tbl_handler handler) |
| 559 | { |
| 560 | acpi_status status; |
| 561 | |
| 562 | ACPI_FUNCTION_TRACE(acpi_remove_table_handler); |
| 563 | |
| 564 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 565 | if (ACPI_FAILURE(status)) { |
| 566 | return_ACPI_STATUS(status); |
| 567 | } |
| 568 | |
| 569 | /* Make sure that the installed handler is the same */ |
| 570 | |
| 571 | if (!handler || handler != acpi_gbl_table_handler) { |
| 572 | status = AE_BAD_PARAMETER; |
| 573 | goto cleanup; |
| 574 | } |
| 575 | |
| 576 | /* Remove the handler */ |
| 577 | |
| 578 | acpi_gbl_table_handler = NULL; |
| 579 | |
| 580 | cleanup: |
| 581 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 582 | return_ACPI_STATUS(status); |
| 583 | } |
| 584 | |
| 585 | ACPI_EXPORT_SYMBOL(acpi_remove_table_handler) |