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