| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** | 
|  | 2 | * | 
|  | 3 | * Module Name: nsload - namespace loading/expanding/contracting procedures | 
|  | 4 | * | 
|  | 5 | *****************************************************************************/ | 
|  | 6 |  | 
|  | 7 | /* | 
| Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * All rights reserved. | 
|  | 10 | * | 
|  | 11 | * Redistribution and use in source and binary forms, with or without | 
|  | 12 | * modification, are permitted provided that the following conditions | 
|  | 13 | * are met: | 
|  | 14 | * 1. Redistributions of source code must retain the above copyright | 
|  | 15 | *    notice, this list of conditions, and the following disclaimer, | 
|  | 16 | *    without modification. | 
|  | 17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | 
|  | 18 | *    substantially similar to the "NO WARRANTY" disclaimer below | 
|  | 19 | *    ("Disclaimer") and any redistribution must be conditioned upon | 
|  | 20 | *    including a substantially similar Disclaimer requirement for further | 
|  | 21 | *    binary redistribution. | 
|  | 22 | * 3. Neither the names of the above-listed copyright holders nor the names | 
|  | 23 | *    of any contributors may be used to endorse or promote products derived | 
|  | 24 | *    from this software without specific prior written permission. | 
|  | 25 | * | 
|  | 26 | * Alternatively, this software may be distributed under the terms of the | 
|  | 27 | * GNU General Public License ("GPL") version 2 as published by the Free | 
|  | 28 | * Software Foundation. | 
|  | 29 | * | 
|  | 30 | * NO WARRANTY | 
|  | 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
|  | 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
|  | 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | 
|  | 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
|  | 35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
|  | 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 
|  | 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 
|  | 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 
|  | 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | 
|  | 40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 
|  | 41 | * POSSIBILITY OF SUCH DAMAGES. | 
|  | 42 | */ | 
|  | 43 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> | 
|  | 45 | #include <acpi/acnamesp.h> | 
|  | 46 | #include <acpi/acdispat.h> | 
|  | 47 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #define _COMPONENT          ACPI_NAMESPACE | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 49 | ACPI_MODULE_NAME("nsload") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 51 | /* Local prototypes */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | static acpi_status acpi_ns_load_table_by_type(acpi_table_type table_type); | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 53 |  | 
|  | 54 | #ifdef ACPI_FUTURE_IMPLEMENTATION | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 55 | acpi_status acpi_ns_unload_namespace(acpi_handle handle); | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 56 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 57 | static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle); | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 58 | #endif | 
|  | 59 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #ifndef ACPI_NO_METHOD_EXECUTION | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /******************************************************************************* | 
|  | 62 | * | 
|  | 63 | * FUNCTION:    acpi_ns_load_table | 
|  | 64 | * | 
|  | 65 | * PARAMETERS:  table_desc      - Descriptor for table to be loaded | 
|  | 66 | *              Node            - Owning NS node | 
|  | 67 | * | 
|  | 68 | * RETURN:      Status | 
|  | 69 | * | 
|  | 70 | * DESCRIPTION: Load one ACPI table into the namespace | 
|  | 71 | * | 
|  | 72 | ******************************************************************************/ | 
|  | 73 |  | 
|  | 74 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | acpi_ns_load_table(struct acpi_table_desc *table_desc, | 
|  | 76 | struct acpi_namespace_node *node) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 80 | ACPI_FUNCTION_TRACE("ns_load_table"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 |  | 
|  | 82 | /* Check if table contains valid AML (must be DSDT, PSDT, SSDT, etc.) */ | 
|  | 83 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 84 | if (! | 
|  | 85 | (acpi_gbl_table_data[table_desc->type]. | 
|  | 86 | flags & ACPI_TABLE_EXECUTABLE)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | /* Just ignore this table */ | 
|  | 88 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 89 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } | 
|  | 91 |  | 
|  | 92 | /* Check validity of the AML start and length */ | 
|  | 93 |  | 
|  | 94 | if (!table_desc->aml_start) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 95 | ACPI_ERROR((AE_INFO, "Null AML pointer")); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 96 | return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } | 
|  | 98 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 99 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "AML block at %p\n", | 
|  | 100 | table_desc->aml_start)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 |  | 
|  | 102 | /* Ignore table if there is no AML contained within */ | 
|  | 103 |  | 
|  | 104 | if (!table_desc->aml_length) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 105 | ACPI_WARNING((AE_INFO, "Zero-length AML block in table [%4.4s]", | 
|  | 106 | table_desc->pointer->signature)); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 107 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } | 
|  | 109 |  | 
|  | 110 | /* | 
|  | 111 | * Parse the table and load the namespace with all named | 
|  | 112 | * objects found within.  Control methods are NOT parsed | 
|  | 113 | * at this time.  In fact, the control methods cannot be | 
|  | 114 | * parsed until the entire namespace is loaded, because | 
|  | 115 | * if a control method makes a forward reference (call) | 
|  | 116 | * to another control method, we can't continue parsing | 
|  | 117 | * because we don't know how many arguments to parse next! | 
|  | 118 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 119 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
|  | 120 | "**** Loading table into namespace ****\n")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 122 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
|  | 123 | if (ACPI_FAILURE(status)) { | 
|  | 124 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } | 
|  | 126 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 127 | status = acpi_ns_parse_table(table_desc, node->child); | 
|  | 128 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 130 | if (ACPI_FAILURE(status)) { | 
|  | 131 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } | 
|  | 133 |  | 
|  | 134 | /* | 
|  | 135 | * Now we can parse the control methods.  We always parse | 
|  | 136 | * them here for a sanity check, and if configured for | 
|  | 137 | * just-in-time parsing, we delete the control method | 
|  | 138 | * parse trees. | 
|  | 139 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 140 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
|  | 141 | "**** Begin Table Method Parsing and Object Initialization ****\n")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 143 | status = acpi_ds_initialize_objects(table_desc, node); | 
| 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_DEBUG_PRINT((ACPI_DB_INFO, | 
|  | 146 | "**** Completed Table Method Parsing and Object Initialization ****\n")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 148 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | } | 
|  | 150 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | /******************************************************************************* | 
|  | 152 | * | 
|  | 153 | * FUNCTION:    acpi_ns_load_table_by_type | 
|  | 154 | * | 
|  | 155 | * PARAMETERS:  table_type          - Id of the table type to load | 
|  | 156 | * | 
|  | 157 | * RETURN:      Status | 
|  | 158 | * | 
|  | 159 | * DESCRIPTION: Load an ACPI table or tables into the namespace.  All tables | 
|  | 160 | *              of the given type are loaded.  The mechanism allows this | 
|  | 161 | *              routine to be called repeatedly. | 
|  | 162 | * | 
|  | 163 | ******************************************************************************/ | 
|  | 164 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 165 | static acpi_status acpi_ns_load_table_by_type(acpi_table_type table_type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 167 | u32 i; | 
|  | 168 | acpi_status status; | 
|  | 169 | struct acpi_table_desc *table_desc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 171 | ACPI_FUNCTION_TRACE("ns_load_table_by_type"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 173 | status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES); | 
|  | 174 | if (ACPI_FAILURE(status)) { | 
|  | 175 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } | 
|  | 177 |  | 
|  | 178 | /* | 
|  | 179 | * Table types supported are: | 
|  | 180 | * DSDT (one), SSDT/PSDT (multiple) | 
|  | 181 | */ | 
|  | 182 | switch (table_type) { | 
|  | 183 | case ACPI_TABLE_DSDT: | 
|  | 184 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 185 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Namespace load: DSDT\n")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 |  | 
|  | 187 | table_desc = acpi_gbl_table_lists[ACPI_TABLE_DSDT].next; | 
|  | 188 |  | 
|  | 189 | /* If table already loaded into namespace, just return */ | 
|  | 190 |  | 
|  | 191 | if (table_desc->loaded_into_namespace) { | 
|  | 192 | goto unlock_and_exit; | 
|  | 193 | } | 
|  | 194 |  | 
|  | 195 | /* Now load the single DSDT */ | 
|  | 196 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 197 | status = acpi_ns_load_table(table_desc, acpi_gbl_root_node); | 
|  | 198 | if (ACPI_SUCCESS(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | table_desc->loaded_into_namespace = TRUE; | 
|  | 200 | } | 
|  | 201 | break; | 
|  | 202 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | case ACPI_TABLE_SSDT: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | case ACPI_TABLE_PSDT: | 
|  | 205 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 206 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
|  | 207 | "Namespace load: %d SSDT or PSDTs\n", | 
|  | 208 | acpi_gbl_table_lists[table_type].count)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 |  | 
|  | 210 | /* | 
| Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 211 | * Traverse list of SSDT or PSDT tables | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | */ | 
| Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 213 | table_desc = acpi_gbl_table_lists[table_type].next; | 
|  | 214 | for (i = 0; i < acpi_gbl_table_lists[table_type].count; i++) { | 
|  | 215 | /* | 
|  | 216 | * Only attempt to load table into namespace if it is not | 
|  | 217 | * already loaded! | 
|  | 218 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | if (!table_desc->loaded_into_namespace) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 220 | status = | 
|  | 221 | acpi_ns_load_table(table_desc, | 
|  | 222 | acpi_gbl_root_node); | 
|  | 223 | if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | break; | 
|  | 225 | } | 
|  | 226 |  | 
|  | 227 | table_desc->loaded_into_namespace = TRUE; | 
|  | 228 | } | 
|  | 229 |  | 
|  | 230 | table_desc = table_desc->next; | 
|  | 231 | } | 
|  | 232 | break; | 
|  | 233 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | default: | 
|  | 235 | status = AE_SUPPORT; | 
|  | 236 | break; | 
|  | 237 | } | 
|  | 238 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 239 | unlock_and_exit: | 
|  | 240 | (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); | 
|  | 241 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } | 
|  | 243 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | /******************************************************************************* | 
|  | 245 | * | 
|  | 246 | * FUNCTION:    acpi_load_namespace | 
|  | 247 | * | 
|  | 248 | * PARAMETERS:  None | 
|  | 249 | * | 
|  | 250 | * RETURN:      Status | 
|  | 251 | * | 
|  | 252 | * DESCRIPTION: Load the name space from what ever is pointed to by DSDT. | 
|  | 253 | *              (DSDT points to either the BIOS or a buffer.) | 
|  | 254 | * | 
|  | 255 | ******************************************************************************/ | 
|  | 256 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 257 | acpi_status acpi_ns_load_namespace(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 259 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 261 | ACPI_FUNCTION_TRACE("acpi_load_name_space"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 |  | 
|  | 263 | /* There must be at least a DSDT installed */ | 
|  | 264 |  | 
|  | 265 | if (acpi_gbl_DSDT == NULL) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 266 | ACPI_ERROR((AE_INFO, "DSDT is not in memory")); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 267 | return_ACPI_STATUS(AE_NO_ACPI_TABLES); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } | 
|  | 269 |  | 
|  | 270 | /* | 
|  | 271 | * Load the namespace.  The DSDT is required, | 
|  | 272 | * but the SSDT and PSDT tables are optional. | 
|  | 273 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 274 | status = acpi_ns_load_table_by_type(ACPI_TABLE_DSDT); | 
|  | 275 | if (ACPI_FAILURE(status)) { | 
|  | 276 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | } | 
|  | 278 |  | 
|  | 279 | /* Ignore exceptions from these */ | 
|  | 280 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 281 | (void)acpi_ns_load_table_by_type(ACPI_TABLE_SSDT); | 
|  | 282 | (void)acpi_ns_load_table_by_type(ACPI_TABLE_PSDT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 284 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, | 
|  | 285 | "ACPI Namespace successfully loaded at root %p\n", | 
|  | 286 | acpi_gbl_root_node)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 288 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | } | 
|  | 290 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 291 | #ifdef ACPI_FUTURE_IMPLEMENTATION | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | /******************************************************************************* | 
|  | 293 | * | 
|  | 294 | * FUNCTION:    acpi_ns_delete_subtree | 
|  | 295 | * | 
|  | 296 | * PARAMETERS:  start_handle        - Handle in namespace where search begins | 
|  | 297 | * | 
|  | 298 | * RETURNS      Status | 
|  | 299 | * | 
|  | 300 | * DESCRIPTION: Walks the namespace starting at the given handle and deletes | 
|  | 301 | *              all objects, entries, and scopes in the entire subtree. | 
|  | 302 | * | 
|  | 303 | *              Namespace/Interpreter should be locked or the subsystem should | 
|  | 304 | *              be in shutdown before this routine is called. | 
|  | 305 | * | 
|  | 306 | ******************************************************************************/ | 
|  | 307 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 308 | static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 310 | acpi_status status; | 
|  | 311 | acpi_handle child_handle; | 
|  | 312 | acpi_handle parent_handle; | 
|  | 313 | acpi_handle next_child_handle; | 
|  | 314 | acpi_handle dummy; | 
|  | 315 | u32 level; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 317 | ACPI_FUNCTION_TRACE("ns_delete_subtree"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 |  | 
|  | 319 | parent_handle = start_handle; | 
|  | 320 | child_handle = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 321 | level = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 |  | 
|  | 323 | /* | 
|  | 324 | * Traverse the tree of objects until we bubble back up | 
|  | 325 | * to where we started. | 
|  | 326 | */ | 
|  | 327 | while (level > 0) { | 
|  | 328 | /* Attempt to get the next object in this scope */ | 
|  | 329 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 330 | status = acpi_get_next_object(ACPI_TYPE_ANY, parent_handle, | 
|  | 331 | child_handle, &next_child_handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 |  | 
|  | 333 | child_handle = next_child_handle; | 
|  | 334 |  | 
|  | 335 | /* Did we get a new object? */ | 
|  | 336 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 337 | if (ACPI_SUCCESS(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | /* Check if this object has any children */ | 
|  | 339 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 340 | if (ACPI_SUCCESS | 
|  | 341 | (acpi_get_next_object | 
|  | 342 | (ACPI_TYPE_ANY, child_handle, NULL, &dummy))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | /* | 
|  | 344 | * There is at least one child of this object, | 
|  | 345 | * visit the object | 
|  | 346 | */ | 
|  | 347 | level++; | 
|  | 348 | parent_handle = child_handle; | 
|  | 349 | child_handle = NULL; | 
|  | 350 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 351 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | /* | 
|  | 353 | * No more children in this object, go back up to | 
|  | 354 | * the object's parent | 
|  | 355 | */ | 
|  | 356 | level--; | 
|  | 357 |  | 
|  | 358 | /* Delete all children now */ | 
|  | 359 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 360 | acpi_ns_delete_children(child_handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 |  | 
|  | 362 | child_handle = parent_handle; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 363 | status = acpi_get_parent(parent_handle, &parent_handle); | 
|  | 364 | if (ACPI_FAILURE(status)) { | 
|  | 365 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | } | 
|  | 367 | } | 
|  | 368 | } | 
|  | 369 |  | 
|  | 370 | /* Now delete the starting object, and we are done */ | 
|  | 371 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 372 | acpi_ns_delete_node(child_handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 374 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } | 
|  | 376 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | /******************************************************************************* | 
|  | 378 | * | 
|  | 379 | *  FUNCTION:       acpi_ns_unload_name_space | 
|  | 380 | * | 
|  | 381 | *  PARAMETERS:     Handle          - Root of namespace subtree to be deleted | 
|  | 382 | * | 
|  | 383 | *  RETURN:         Status | 
|  | 384 | * | 
|  | 385 | *  DESCRIPTION:    Shrinks the namespace, typically in response to an undocking | 
|  | 386 | *                  event.  Deletes an entire subtree starting from (and | 
|  | 387 | *                  including) the given handle. | 
|  | 388 | * | 
|  | 389 | ******************************************************************************/ | 
|  | 390 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 391 | acpi_status acpi_ns_unload_namespace(acpi_handle handle) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 393 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 395 | ACPI_FUNCTION_TRACE("ns_unload_name_space"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 |  | 
|  | 397 | /* Parameter validation */ | 
|  | 398 |  | 
|  | 399 | if (!acpi_gbl_root_node) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 400 | return_ACPI_STATUS(AE_NO_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } | 
|  | 402 |  | 
|  | 403 | if (!handle) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 404 | return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } | 
|  | 406 |  | 
|  | 407 | /* This function does the real work */ | 
|  | 408 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 409 | status = acpi_ns_delete_subtree(handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 411 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 413 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | #endif |