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 | |
| 45 | #include <linux/module.h> |
| 46 | |
| 47 | #include <acpi/acpi.h> |
| 48 | #include <acpi/acnamesp.h> |
| 49 | #include <acpi/actables.h> |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define _COMPONENT ACPI_TABLES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | ACPI_MODULE_NAME("tbxface") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | /******************************************************************************* |
| 55 | * |
| 56 | * FUNCTION: acpi_load_tables |
| 57 | * |
| 58 | * PARAMETERS: None |
| 59 | * |
| 60 | * RETURN: Status |
| 61 | * |
| 62 | * DESCRIPTION: This function is called to load the ACPI tables from the |
| 63 | * provided RSDT |
| 64 | * |
| 65 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 66 | acpi_status acpi_load_tables(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 68 | struct acpi_pointer rsdp_address; |
| 69 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 71 | ACPI_FUNCTION_TRACE("acpi_load_tables"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | /* Get the RSDP */ |
| 74 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | status = acpi_os_get_root_pointer(ACPI_LOGICAL_ADDRESSING, |
| 76 | &rsdp_address); |
| 77 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame^] | 78 | ACPI_EXCEPTION((AE_INFO, status, "Could not get the RSDP")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | goto error_exit; |
| 80 | } |
| 81 | |
| 82 | /* Map and validate the RSDP */ |
| 83 | |
| 84 | acpi_gbl_table_flags = rsdp_address.pointer_type; |
| 85 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 86 | status = acpi_tb_verify_rsdp(&rsdp_address); |
| 87 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame^] | 88 | ACPI_EXCEPTION((AE_INFO, status, "During RSDP validation")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | goto error_exit; |
| 90 | } |
| 91 | |
| 92 | /* Get the RSDT via the RSDP */ |
| 93 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 94 | status = acpi_tb_get_table_rsdt(); |
| 95 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame^] | 96 | ACPI_EXCEPTION((AE_INFO, status, "Could not load RSDT")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | goto error_exit; |
| 98 | } |
| 99 | |
| 100 | /* Now get the tables needed by this subsystem (FADT, DSDT, etc.) */ |
| 101 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 102 | status = acpi_tb_get_required_tables(); |
| 103 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame^] | 104 | ACPI_EXCEPTION((AE_INFO, status, |
| 105 | "Could not get all required tables (DSDT/FADT/FACS)")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | goto error_exit; |
| 107 | } |
| 108 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 109 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI Tables successfully acquired\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | /* Load the namespace from the tables */ |
| 112 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 113 | status = acpi_ns_load_namespace(); |
| 114 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame^] | 115 | ACPI_EXCEPTION((AE_INFO, status, "Could not load namespace")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | goto error_exit; |
| 117 | } |
| 118 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 119 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 121 | error_exit: |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame^] | 122 | ACPI_EXCEPTION((AE_INFO, status, "Could not load tables")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 123 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | #ifdef ACPI_FUTURE_USAGE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | /******************************************************************************* |
| 128 | * |
| 129 | * FUNCTION: acpi_load_table |
| 130 | * |
| 131 | * PARAMETERS: table_ptr - pointer to a buffer containing the entire |
| 132 | * table to be loaded |
| 133 | * |
| 134 | * RETURN: Status |
| 135 | * |
| 136 | * DESCRIPTION: This function is called to load a table from the caller's |
| 137 | * buffer. The buffer must contain an entire ACPI Table including |
| 138 | * a valid header. The header fields will be verified, and if it |
| 139 | * is determined that the table is invalid, the call will fail. |
| 140 | * |
| 141 | ******************************************************************************/ |
| 142 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 143 | acpi_status acpi_load_table(struct acpi_table_header *table_ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | acpi_status status; |
| 146 | struct acpi_table_desc table_info; |
| 147 | struct acpi_pointer address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 149 | ACPI_FUNCTION_TRACE("acpi_load_table"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | if (!table_ptr) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 152 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | /* Copy the table to a local buffer */ |
| 156 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | address.pointer.logical = table_ptr; |
| 159 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 160 | status = acpi_tb_get_table_body(&address, table_ptr, &table_info); |
| 161 | if (ACPI_FAILURE(status)) { |
| 162 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 165 | /* Check signature for a valid table type */ |
| 166 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 167 | status = acpi_tb_recognize_table(&table_info, ACPI_TABLE_ALL); |
| 168 | if (ACPI_FAILURE(status)) { |
| 169 | return_ACPI_STATUS(status); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | /* Install the new table into the local data structures */ |
| 173 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | status = acpi_tb_install_table(&table_info); |
| 175 | if (ACPI_FAILURE(status)) { |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 176 | if (status == AE_ALREADY_EXISTS) { |
| 177 | /* Table already exists, no error */ |
| 178 | |
| 179 | status = AE_OK; |
| 180 | } |
| 181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | /* Free table allocated by acpi_tb_get_table_body */ |
| 183 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 184 | acpi_tb_delete_single_table(&table_info); |
| 185 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | /* Convert the table to common format if necessary */ |
| 189 | |
| 190 | switch (table_info.type) { |
| 191 | case ACPI_TABLE_FADT: |
| 192 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 193 | status = acpi_tb_convert_table_fadt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | break; |
| 195 | |
| 196 | case ACPI_TABLE_FACS: |
| 197 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 198 | status = acpi_tb_build_common_facs(&table_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | break; |
| 200 | |
| 201 | default: |
| 202 | /* Load table into namespace if it contains executable AML */ |
| 203 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | status = |
| 205 | acpi_ns_load_table(table_info.installed_desc, |
| 206 | acpi_gbl_root_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | break; |
| 208 | } |
| 209 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 210 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | /* Uninstall table and free the buffer */ |
| 212 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 213 | (void)acpi_tb_uninstall_table(table_info.installed_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | /******************************************************************************* |
| 220 | * |
| 221 | * FUNCTION: acpi_unload_table |
| 222 | * |
| 223 | * PARAMETERS: table_type - Type of table to be unloaded |
| 224 | * |
| 225 | * RETURN: Status |
| 226 | * |
| 227 | * DESCRIPTION: This routine is used to force the unload of a table |
| 228 | * |
| 229 | ******************************************************************************/ |
| 230 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 231 | acpi_status acpi_unload_table(acpi_table_type table_type) |
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 | struct acpi_table_desc *table_desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 235 | ACPI_FUNCTION_TRACE("acpi_unload_table"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | /* Parameter validation */ |
| 238 | |
| 239 | if (table_type > ACPI_TABLE_MAX) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 240 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | /* Find all tables of the requested type */ |
| 244 | |
| 245 | table_desc = acpi_gbl_table_lists[table_type].next; |
| 246 | while (table_desc) { |
| 247 | /* |
| 248 | * Delete all namespace entries owned by this table. Note that these |
| 249 | * entries can appear anywhere in the namespace by virtue of the AML |
| 250 | * "Scope" operator. Thus, we need to track ownership by an ID, not |
| 251 | * simply a position within the hierarchy |
| 252 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 253 | acpi_ns_delete_namespace_by_owner(table_desc->owner_id); |
| 254 | acpi_ut_release_owner_id(&table_desc->owner_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | table_desc = table_desc->next; |
| 256 | } |
| 257 | |
| 258 | /* Delete (or unmap) all tables of this type */ |
| 259 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 260 | acpi_tb_delete_tables_by_type(table_type); |
| 261 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | /******************************************************************************* |
| 265 | * |
| 266 | * FUNCTION: acpi_get_table_header |
| 267 | * |
| 268 | * PARAMETERS: table_type - one of the defined table types |
| 269 | * Instance - the non zero instance of the table, allows |
| 270 | * support for multiple tables of the same type |
| 271 | * see acpi_gbl_acpi_table_flag |
| 272 | * out_table_header - pointer to the struct acpi_table_header if successful |
| 273 | * |
| 274 | * DESCRIPTION: This function is called to get an ACPI table header. The caller |
| 275 | * supplies an pointer to a data area sufficient to contain an ACPI |
| 276 | * struct acpi_table_header structure. |
| 277 | * |
| 278 | * The header contains a length field that can be used to determine |
| 279 | * the size of the buffer needed to contain the entire table. This |
| 280 | * function is not valid for the RSD PTR table since it does not |
| 281 | * have a standard header and is fixed length. |
| 282 | * |
| 283 | ******************************************************************************/ |
| 284 | |
| 285 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 286 | acpi_get_table_header(acpi_table_type table_type, |
| 287 | u32 instance, struct acpi_table_header *out_table_header) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 289 | struct acpi_table_header *tbl_ptr; |
| 290 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 292 | ACPI_FUNCTION_TRACE("acpi_get_table_header"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 294 | if ((instance == 0) || |
| 295 | (table_type == ACPI_TABLE_RSDP) || (!out_table_header)) { |
| 296 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | /* Check the table type and instance */ |
| 300 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 301 | if ((table_type > ACPI_TABLE_MAX) || |
| 302 | (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) && |
| 303 | instance > 1)) { |
| 304 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | /* Get a pointer to the entire table */ |
| 308 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 309 | status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr); |
| 310 | if (ACPI_FAILURE(status)) { |
| 311 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 314 | /* The function will return a NULL pointer if the table is not loaded */ |
| 315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | if (tbl_ptr == NULL) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 317 | return_ACPI_STATUS(AE_NOT_EXIST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 320 | /* Copy the header to the caller's buffer */ |
| 321 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 322 | ACPI_MEMCPY((void *)out_table_header, (void *)tbl_ptr, |
| 323 | sizeof(struct acpi_table_header)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 325 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 328 | #endif /* ACPI_FUTURE_USAGE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | /******************************************************************************* |
| 331 | * |
| 332 | * FUNCTION: acpi_get_table |
| 333 | * |
| 334 | * PARAMETERS: table_type - one of the defined table types |
| 335 | * Instance - the non zero instance of the table, allows |
| 336 | * support for multiple tables of the same type |
| 337 | * see acpi_gbl_acpi_table_flag |
| 338 | * ret_buffer - pointer to a structure containing a buffer to |
| 339 | * receive the table |
| 340 | * |
| 341 | * RETURN: Status |
| 342 | * |
| 343 | * DESCRIPTION: This function is called to get an ACPI table. The caller |
| 344 | * supplies an out_buffer large enough to contain the entire ACPI |
| 345 | * table. The caller should call the acpi_get_table_header function |
| 346 | * first to determine the buffer size needed. Upon completion |
| 347 | * the out_buffer->Length field will indicate the number of bytes |
| 348 | * copied into the out_buffer->buf_ptr buffer. This table will be |
| 349 | * a complete table including the header. |
| 350 | * |
| 351 | ******************************************************************************/ |
| 352 | |
| 353 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 354 | acpi_get_table(acpi_table_type table_type, |
| 355 | u32 instance, struct acpi_buffer *ret_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 357 | struct acpi_table_header *tbl_ptr; |
| 358 | acpi_status status; |
| 359 | acpi_size table_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 361 | ACPI_FUNCTION_TRACE("acpi_get_table"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
| 363 | /* Parameter validation */ |
| 364 | |
| 365 | if (instance == 0) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 366 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 369 | status = acpi_ut_validate_buffer(ret_buffer); |
| 370 | if (ACPI_FAILURE(status)) { |
| 371 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | /* Check the table type and instance */ |
| 375 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 376 | if ((table_type > ACPI_TABLE_MAX) || |
| 377 | (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) && |
| 378 | instance > 1)) { |
| 379 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | /* Get a pointer to the entire table */ |
| 383 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 384 | status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr); |
| 385 | if (ACPI_FAILURE(status)) { |
| 386 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | /* |
| 390 | * acpi_tb_get_table_ptr will return a NULL pointer if the |
| 391 | * table is not loaded. |
| 392 | */ |
| 393 | if (tbl_ptr == NULL) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 394 | return_ACPI_STATUS(AE_NOT_EXIST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | /* Get the table length */ |
| 398 | |
| 399 | if (table_type == ACPI_TABLE_RSDP) { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 400 | /* RSD PTR is the only "table" without a header */ |
| 401 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 402 | table_length = sizeof(struct rsdp_descriptor); |
| 403 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | table_length = (acpi_size) tbl_ptr->length; |
| 405 | } |
| 406 | |
| 407 | /* Validate/Allocate/Clear caller buffer */ |
| 408 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 409 | status = acpi_ut_initialize_buffer(ret_buffer, table_length); |
| 410 | if (ACPI_FAILURE(status)) { |
| 411 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | /* Copy the table to the buffer */ |
| 415 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 416 | ACPI_MEMCPY((void *)ret_buffer->pointer, (void *)tbl_ptr, table_length); |
| 417 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 420 | EXPORT_SYMBOL(acpi_get_table); |