Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: tbxface - Public interfaces to the ACPI subsystem |
| 4 | * ACPI table oriented interfaces |
| 5 | * |
| 6 | *****************************************************************************/ |
| 7 | |
| 8 | /* |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 9 | * Copyright (C) 2000 - 2006, R. Byron Moore |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * All rights reserved. |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * 1. Redistributions of source code must retain the above copyright |
| 16 | * notice, this list of conditions, and the following disclaimer, |
| 17 | * without modification. |
| 18 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 19 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 20 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 21 | * including a substantially similar Disclaimer requirement for further |
| 22 | * binary redistribution. |
| 23 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 24 | * of any contributors may be used to endorse or promote products derived |
| 25 | * from this software without specific prior written permission. |
| 26 | * |
| 27 | * Alternatively, this software may be distributed under the terms of the |
| 28 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 29 | * Software Foundation. |
| 30 | * |
| 31 | * NO WARRANTY |
| 32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 33 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 35 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 36 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 40 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 41 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 42 | * POSSIBILITY OF SUCH DAMAGES. |
| 43 | */ |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <acpi/acpi.h> |
| 46 | #include <acpi/acnamesp.h> |
| 47 | #include <acpi/actables.h> |
| 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("tbxface") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 52 | /* Local prototypes */ |
| 53 | static acpi_status acpi_tb_load_namespace(void); |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | /******************************************************************************* |
| 56 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 57 | * FUNCTION: acpi_initialize_tables |
| 58 | * |
| 59 | * PARAMETERS: initial_table_array - Pointer to an array of pre-allocated |
| 60 | * struct acpi_table_desc structures. If NULL, the |
| 61 | * array is dynamically allocated. |
| 62 | * initial_table_count - Size of initial_table_array, in number of |
| 63 | * struct acpi_table_desc structures |
| 64 | * allow_realloc - Flag to tell Table Manager if resize of |
| 65 | * pre-allocated array is allowed. Ignored |
| 66 | * if initial_table_array is NULL. |
| 67 | * |
| 68 | * RETURN: Status |
| 69 | * |
| 70 | * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT. |
| 71 | * |
| 72 | * NOTE: Allows static allocation of the initial table array in order |
| 73 | * to avoid the use of dynamic memory in confined environments |
| 74 | * such as the kernel boot sequence where it may not be available. |
| 75 | * |
| 76 | * If the host OS memory managers are initialized, use NULL for |
| 77 | * initial_table_array, and the table will be dynamically allocated. |
| 78 | * |
| 79 | ******************************************************************************/ |
| 80 | |
| 81 | acpi_status |
| 82 | acpi_initialize_tables(struct acpi_table_desc *initial_table_array, |
| 83 | u32 initial_table_count, u8 allow_resize) |
| 84 | { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame^] | 85 | acpi_physical_address rsdp_address; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 86 | acpi_status status; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 87 | |
| 88 | ACPI_FUNCTION_TRACE(acpi_initialize_tables); |
| 89 | |
| 90 | /* |
| 91 | * Set up the Root Table Array |
| 92 | * Allocate the table array if requested |
| 93 | */ |
| 94 | if (!initial_table_array) { |
| 95 | acpi_gbl_root_table_list.size = initial_table_count; |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame^] | 96 | acpi_gbl_root_table_list.flags = ACPI_ROOT_ALLOW_RESIZE; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 97 | |
| 98 | status = acpi_tb_resize_root_table_list(); |
| 99 | if (ACPI_FAILURE(status)) { |
| 100 | return_ACPI_STATUS(status); |
| 101 | } |
| 102 | } else { |
| 103 | /* Root Table Array has been statically allocated by the host */ |
| 104 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame^] | 105 | ACPI_MEMSET(initial_table_array, |
| 106 | initial_table_count * |
| 107 | sizeof(struct acpi_table_desc), 0); |
| 108 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 109 | acpi_gbl_root_table_list.tables = initial_table_array; |
| 110 | acpi_gbl_root_table_list.size = initial_table_count; |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame^] | 111 | acpi_gbl_root_table_list.flags = ACPI_ROOT_ORIGIN_UNKNOWN; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 112 | if (allow_resize) { |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame^] | 113 | acpi_gbl_root_table_list.flags |= |
| 114 | ACPI_ROOT_ALLOW_RESIZE; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame^] | 118 | /* Get the address of the RSDP */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 119 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame^] | 120 | rsdp_address = acpi_os_get_root_pointer(); |
| 121 | if (!rsdp_address) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 122 | return_ACPI_STATUS(AE_NOT_FOUND); |
| 123 | } |
| 124 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 125 | /* |
| 126 | * Get the root table (RSDT or XSDT) and extract all entries to the local |
| 127 | * Root Table Array. This array contains the information of the RSDT/XSDT |
| 128 | * in a common, more useable format. |
| 129 | */ |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame^] | 130 | status = |
| 131 | acpi_tb_parse_root_table(rsdp_address, ACPI_TABLE_ORIGIN_MAPPED); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 132 | return_ACPI_STATUS(status); |
| 133 | } |
| 134 | |
| 135 | ACPI_EXPORT_SYMBOL(acpi_initialize_tables) |
| 136 | |
| 137 | /******************************************************************************* |
| 138 | * |
| 139 | * FUNCTION: acpi_reallocate_root_table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | * |
| 141 | * PARAMETERS: None |
| 142 | * |
| 143 | * RETURN: Status |
| 144 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 145 | * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the |
| 146 | * root list from the previously provided scratch area. Should |
| 147 | * be called once dynamic memory allocation is available in the |
| 148 | * kernel |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | * |
| 150 | ******************************************************************************/ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 151 | acpi_status acpi_reallocate_root_table(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 153 | struct acpi_table_desc *tables; |
| 154 | acpi_size new_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 156 | ACPI_FUNCTION_TRACE(acpi_reallocate_root_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 158 | /* |
| 159 | * Only reallocate the root table if the host provided a static buffer |
| 160 | * for the table array in the call to acpi_initialize_tables. |
| 161 | */ |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame^] | 162 | if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 163 | return_ACPI_STATUS(AE_SUPPORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 166 | new_size = |
| 167 | (acpi_gbl_root_table_list.count + |
| 168 | ACPI_ROOT_TABLE_SIZE_INCREMENT) * sizeof(struct acpi_table_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 170 | /* Create new array and copy the old array */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 172 | tables = ACPI_ALLOCATE_ZEROED(new_size); |
| 173 | if (!tables) { |
| 174 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 177 | ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables, new_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 179 | acpi_gbl_root_table_list.size = acpi_gbl_root_table_list.count; |
| 180 | acpi_gbl_root_table_list.tables = tables; |
| 181 | acpi_gbl_root_table_list.flags = |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame^] | 182 | ACPI_ROOT_ORIGIN_ALLOCATED | ACPI_ROOT_ALLOW_RESIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 184 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | /******************************************************************************* |
| 187 | * |
| 188 | * FUNCTION: acpi_load_table |
| 189 | * |
| 190 | * PARAMETERS: table_ptr - pointer to a buffer containing the entire |
| 191 | * table to be loaded |
| 192 | * |
| 193 | * RETURN: Status |
| 194 | * |
| 195 | * 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] | 196 | * buffer. The buffer must contain an entire ACPI Table including |
| 197 | * a valid header. The header fields will be verified, and if it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | * is determined that the table is invalid, the call will fail. |
| 199 | * |
| 200 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | acpi_status acpi_load_table(struct acpi_table_header *table_ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 203 | acpi_status status; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 204 | acpi_native_uint table_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 206 | /* |
| 207 | * Install the new table into the local data structures |
| 208 | */ |
| 209 | status = acpi_tb_add_table(table_ptr, &table_index); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 210 | if (ACPI_FAILURE(status)) { |
| 211 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 213 | status = acpi_ns_load_table(table_index, acpi_gbl_root_node); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 214 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 217 | ACPI_EXPORT_SYMBOL(acpi_load_table) |
| 218 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 219 | /****************************************************************************** |
| 220 | * |
| 221 | * FUNCTION: acpi_get_table_header |
| 222 | * |
| 223 | * PARAMETERS: Signature - ACPI signature of needed table |
| 224 | * Instance - Which instance (for SSDTs) |
| 225 | * out_table_header - Where the pointer to the table header |
| 226 | * is returned |
| 227 | * |
| 228 | * RETURN: Status and pointer to mapped table header |
| 229 | * |
| 230 | * DESCRIPTION: Finds an ACPI table header. |
| 231 | * |
| 232 | * NOTE: Caller is responsible in unmapping the header with |
| 233 | * acpi_os_unmap_memory |
| 234 | * |
| 235 | *****************************************************************************/ |
| 236 | acpi_status |
| 237 | acpi_get_table_header(char *signature, |
| 238 | acpi_native_uint instance, |
| 239 | struct acpi_table_header **out_table_header) |
| 240 | { |
| 241 | acpi_native_uint i; |
| 242 | acpi_native_uint j; |
| 243 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame^] | 244 | /* Parameter validation */ |
| 245 | |
| 246 | if (!signature || !out_table_header) { |
| 247 | return (AE_BAD_PARAMETER); |
| 248 | } |
| 249 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 250 | /* |
| 251 | * Walk the root table list |
| 252 | */ |
| 253 | for (i = 0, j = 0; i < acpi_gbl_root_table_list.count; i++) { |
| 254 | if (!ACPI_COMPARE_NAME |
| 255 | (&(acpi_gbl_root_table_list.tables[i].signature), |
| 256 | signature)) { |
| 257 | continue; |
| 258 | } |
| 259 | |
| 260 | if (++j < instance) { |
| 261 | continue; |
| 262 | } |
| 263 | |
| 264 | *out_table_header = |
| 265 | acpi_tb_map(acpi_gbl_root_table_list.tables[i].address, |
| 266 | (u32) sizeof(struct acpi_table_header), |
| 267 | acpi_gbl_root_table_list.tables[i]. |
| 268 | flags & ACPI_TABLE_ORIGIN_MASK); |
| 269 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame^] | 270 | if (!(*out_table_header)) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 271 | return (AE_NO_MEMORY); |
| 272 | } |
| 273 | |
| 274 | return (AE_OK); |
| 275 | } |
| 276 | |
| 277 | return (AE_NOT_FOUND); |
| 278 | } |
| 279 | |
| 280 | ACPI_EXPORT_SYMBOL(acpi_get_table_header) |
| 281 | |
| 282 | |
| 283 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | * |
John Keller | 0f0fe1a | 2006-12-19 12:56:19 -0800 | [diff] [blame] | 285 | * FUNCTION: acpi_unload_table_id |
| 286 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 287 | * PARAMETERS: id - Owner ID of the table to be removed. |
John Keller | 0f0fe1a | 2006-12-19 12:56:19 -0800 | [diff] [blame] | 288 | * |
| 289 | * RETURN: Status |
| 290 | * |
| 291 | * DESCRIPTION: This routine is used to force the unload of a table (by id) |
| 292 | * |
| 293 | ******************************************************************************/ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 294 | acpi_status acpi_unload_table_id(acpi_owner_id id) |
John Keller | 0f0fe1a | 2006-12-19 12:56:19 -0800 | [diff] [blame] | 295 | { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 296 | int i; |
| 297 | acpi_status status = AE_NOT_EXIST; |
John Keller | 0f0fe1a | 2006-12-19 12:56:19 -0800 | [diff] [blame] | 298 | |
| 299 | ACPI_FUNCTION_TRACE(acpi_unload_table); |
| 300 | |
John Keller | 0f0fe1a | 2006-12-19 12:56:19 -0800 | [diff] [blame] | 301 | /* Find table from the requested type list */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 302 | for (i = 0; i < acpi_gbl_root_table_list.count; ++i) { |
| 303 | if (id != acpi_gbl_root_table_list.tables[i].owner_id) { |
| 304 | continue; |
| 305 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | /* |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 307 | * Delete all namespace objects owned by this table. Note that these |
| 308 | * objects can appear anywhere in the namespace by virtue of the AML |
| 309 | * "Scope" operator. Thus, we need to track ownership by an ID, not |
| 310 | * simply a position within the hierarchy |
| 311 | */ |
| 312 | acpi_tb_delete_namespace_by_owner(i); |
| 313 | acpi_tb_release_owner_id(i); |
| 314 | acpi_tb_set_table_loaded_flag(i, FALSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 316 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 319 | ACPI_EXPORT_SYMBOL(acpi_unload_table_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
| 321 | /******************************************************************************* |
| 322 | * |
| 323 | * FUNCTION: acpi_get_table |
| 324 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 325 | * PARAMETERS: Signature - ACPI signature of needed table |
| 326 | * Instance - Which instance (for SSDTs) |
| 327 | * out_table - Where the pointer to the table is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 329 | * RETURN: Status and pointer to table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | * |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 331 | * DESCRIPTION: Finds and verifies an ACPI table. |
| 332 | * |
| 333 | *****************************************************************************/ |
| 334 | acpi_status |
| 335 | acpi_get_table(char *signature, |
| 336 | acpi_native_uint instance, struct acpi_table_header ** out_table) |
| 337 | { |
| 338 | acpi_native_uint i; |
| 339 | acpi_native_uint j; |
| 340 | acpi_status status; |
| 341 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame^] | 342 | /* Parameter validation */ |
| 343 | |
| 344 | if (!signature || !out_table) { |
| 345 | return (AE_BAD_PARAMETER); |
| 346 | } |
| 347 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 348 | /* |
| 349 | * Walk the root table list |
| 350 | */ |
| 351 | for (i = 0, j = 0; i < acpi_gbl_root_table_list.count; i++) { |
| 352 | if (!ACPI_COMPARE_NAME |
| 353 | (&(acpi_gbl_root_table_list.tables[i].signature), |
| 354 | signature)) { |
| 355 | continue; |
| 356 | } |
| 357 | |
| 358 | if (++j < instance) { |
| 359 | continue; |
| 360 | } |
| 361 | |
| 362 | status = |
| 363 | acpi_tb_verify_table(&acpi_gbl_root_table_list.tables[i]); |
| 364 | if (ACPI_SUCCESS(status)) { |
| 365 | *out_table = acpi_gbl_root_table_list.tables[i].pointer; |
| 366 | } |
| 367 | |
| 368 | return (status); |
| 369 | } |
| 370 | |
| 371 | return (AE_NOT_FOUND); |
| 372 | } |
| 373 | |
| 374 | ACPI_EXPORT_SYMBOL(acpi_get_table) |
| 375 | |
| 376 | /******************************************************************************* |
| 377 | * |
| 378 | * FUNCTION: acpi_get_table_by_index |
| 379 | * |
| 380 | * PARAMETERS: table_index - Table index |
| 381 | * Table - Where the pointer to the table is returned |
| 382 | * |
| 383 | * RETURN: Status and pointer to the table |
| 384 | * |
| 385 | * DESCRIPTION: Obtain a table by an index into the global table list. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | * |
| 387 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | acpi_status |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 389 | acpi_get_table_by_index(acpi_native_uint table_index, |
| 390 | struct acpi_table_header ** table) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 392 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 394 | ACPI_FUNCTION_TRACE(acpi_get_table_by_index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame^] | 396 | /* Parameter validation */ |
| 397 | |
| 398 | if (!table) { |
| 399 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 400 | } |
| 401 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 402 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 404 | /* Validate index */ |
| 405 | |
| 406 | if (table_index >= acpi_gbl_root_table_list.count) { |
| 407 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 408 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 411 | if (!acpi_gbl_root_table_list.tables[table_index].pointer) { |
| 412 | |
| 413 | /* Table is not mapped, map it */ |
| 414 | |
| 415 | status = |
| 416 | acpi_tb_verify_table(&acpi_gbl_root_table_list. |
| 417 | tables[table_index]); |
| 418 | if (ACPI_FAILURE(status)) { |
| 419 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 420 | return_ACPI_STATUS(status); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | *table = acpi_gbl_root_table_list.tables[table_index].pointer; |
| 425 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 426 | return_ACPI_STATUS(AE_OK); |
| 427 | } |
| 428 | |
| 429 | ACPI_EXPORT_SYMBOL(acpi_get_table_by_index) |
| 430 | |
| 431 | /******************************************************************************* |
| 432 | * |
| 433 | * FUNCTION: acpi_tb_load_namespace |
| 434 | * |
| 435 | * PARAMETERS: None |
| 436 | * |
| 437 | * RETURN: Status |
| 438 | * |
| 439 | * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in |
| 440 | * the RSDT/XSDT. |
| 441 | * |
| 442 | ******************************************************************************/ |
| 443 | static acpi_status acpi_tb_load_namespace(void) |
| 444 | { |
| 445 | acpi_status status; |
| 446 | struct acpi_table_header *table; |
| 447 | acpi_native_uint i; |
| 448 | |
| 449 | ACPI_FUNCTION_TRACE(tb_load_namespace); |
| 450 | |
| 451 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
| 452 | |
| 453 | /* |
| 454 | * Load the namespace. The DSDT is required, but any SSDT and PSDT tables |
| 455 | * are optional. |
| 456 | */ |
| 457 | if (!acpi_gbl_root_table_list.count || |
| 458 | !ACPI_COMPARE_NAME(& |
| 459 | (acpi_gbl_root_table_list. |
| 460 | tables[ACPI_TABLE_INDEX_DSDT].signature), |
| 461 | ACPI_SIG_DSDT) |
| 462 | || |
| 463 | ACPI_FAILURE(acpi_tb_verify_table |
| 464 | (&acpi_gbl_root_table_list. |
| 465 | tables[ACPI_TABLE_INDEX_DSDT]))) { |
| 466 | status = AE_NO_ACPI_TABLES; |
| 467 | goto unlock_and_exit; |
| 468 | } |
| 469 | |
| 470 | /* |
| 471 | * Find DSDT table |
| 472 | */ |
| 473 | status = |
| 474 | acpi_os_table_override(acpi_gbl_root_table_list. |
| 475 | tables[ACPI_TABLE_INDEX_DSDT].pointer, |
| 476 | &table); |
| 477 | if (ACPI_SUCCESS(status) && table) { |
| 478 | /* |
| 479 | * DSDT table has been found |
| 480 | */ |
| 481 | acpi_tb_delete_table(ACPI_TABLE_INDEX_DSDT); |
| 482 | acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].pointer = |
| 483 | table; |
| 484 | acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].length = |
| 485 | table->length; |
| 486 | acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].flags = |
| 487 | ACPI_TABLE_ORIGIN_UNKNOWN; |
| 488 | |
| 489 | ACPI_INFO((AE_INFO, "Table DSDT replaced by host OS")); |
| 490 | acpi_tb_print_table_header(0, table); |
| 491 | } |
| 492 | |
| 493 | status = |
| 494 | acpi_tb_verify_table(&acpi_gbl_root_table_list. |
| 495 | tables[ACPI_TABLE_INDEX_DSDT]); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 496 | if (ACPI_FAILURE(status)) { |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 497 | |
| 498 | /* A valid DSDT is required */ |
| 499 | |
| 500 | status = AE_NO_ACPI_TABLES; |
| 501 | goto unlock_and_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 504 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 506 | /* |
| 507 | * Load and parse tables. |
| 508 | */ |
| 509 | status = acpi_ns_load_table(ACPI_TABLE_INDEX_DSDT, acpi_gbl_root_node); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 510 | if (ACPI_FAILURE(status)) { |
| 511 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | /* |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 515 | * Load any SSDT or PSDT tables. Note: Loop leaves tables locked |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 517 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
| 518 | for (i = 0; i < acpi_gbl_root_table_list.count; ++i) { |
| 519 | if ((!ACPI_COMPARE_NAME |
| 520 | (&(acpi_gbl_root_table_list.tables[i].signature), |
| 521 | ACPI_SIG_SSDT) |
| 522 | && |
| 523 | !ACPI_COMPARE_NAME(& |
| 524 | (acpi_gbl_root_table_list.tables[i]. |
| 525 | signature), ACPI_SIG_PSDT)) |
| 526 | || |
| 527 | ACPI_FAILURE(acpi_tb_verify_table |
| 528 | (&acpi_gbl_root_table_list.tables[i]))) { |
| 529 | continue; |
| 530 | } |
| 531 | |
| 532 | /* Ignore errors while loading tables, get as many as possible */ |
| 533 | |
| 534 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 535 | (void)acpi_ns_load_table(i, acpi_gbl_root_node); |
| 536 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 539 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI Tables successfully acquired\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 541 | unlock_and_exit: |
| 542 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); |
| 543 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 546 | /******************************************************************************* |
| 547 | * |
| 548 | * FUNCTION: acpi_load_tables |
| 549 | * |
| 550 | * PARAMETERS: None |
| 551 | * |
| 552 | * RETURN: Status |
| 553 | * |
| 554 | * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT |
| 555 | * |
| 556 | ******************************************************************************/ |
| 557 | |
| 558 | acpi_status acpi_load_tables(void) |
| 559 | { |
| 560 | acpi_status status; |
| 561 | |
| 562 | ACPI_FUNCTION_TRACE(acpi_load_tables); |
| 563 | |
| 564 | /* |
| 565 | * Load the namespace from the tables |
| 566 | */ |
| 567 | status = acpi_tb_load_namespace(); |
| 568 | if (ACPI_FAILURE(status)) { |
| 569 | ACPI_EXCEPTION((AE_INFO, status, |
| 570 | "While loading namespace from ACPI tables")); |
| 571 | } |
| 572 | |
| 573 | return_ACPI_STATUS(status); |
| 574 | } |
| 575 | |
| 576 | ACPI_EXPORT_SYMBOL(acpi_load_tables) |