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