| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** | 
 | 2 |  * | 
 | 3 |  * Module Name: evregion - ACPI address_space (op_region) handler dispatch | 
 | 4 |  * | 
 | 5 |  *****************************************************************************/ | 
 | 6 |  | 
 | 7 | /* | 
| Len Brown | 75a44ce | 2008-04-23 23:00:13 -0400 | [diff] [blame] | 8 |  * Copyright (C) 2000 - 2008, Intel Corp. | 
| 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> | 
| Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 45 | #include "accommon.h" | 
 | 46 | #include "acevents.h" | 
 | 47 | #include "acnamesp.h" | 
 | 48 | #include "acinterp.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 |  | 
 | 50 | #define _COMPONENT          ACPI_EVENTS | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | ACPI_MODULE_NAME("evregion") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 53 | /* Local prototypes */ | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 54 | static acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 55 | acpi_ev_reg_run(acpi_handle obj_handle, | 
 | 56 | 		u32 level, void *context, void **return_value); | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 57 |  | 
 | 58 | static acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 59 | acpi_ev_install_handler(acpi_handle obj_handle, | 
 | 60 | 			u32 level, void *context, void **return_value); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 |  | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 62 | /* These are the address spaces that will get default handlers */ | 
 | 63 |  | 
 | 64 | #define ACPI_NUM_DEFAULT_SPACES     4 | 
 | 65 |  | 
 | 66 | static u8 acpi_gbl_default_address_spaces[ACPI_NUM_DEFAULT_SPACES] = { | 
 | 67 | 	ACPI_ADR_SPACE_SYSTEM_MEMORY, | 
 | 68 | 	ACPI_ADR_SPACE_SYSTEM_IO, | 
 | 69 | 	ACPI_ADR_SPACE_PCI_CONFIG, | 
 | 70 | 	ACPI_ADR_SPACE_DATA_TABLE | 
 | 71 | }; | 
 | 72 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | /******************************************************************************* | 
 | 74 |  * | 
 | 75 |  * FUNCTION:    acpi_ev_install_region_handlers | 
 | 76 |  * | 
 | 77 |  * PARAMETERS:  None | 
 | 78 |  * | 
 | 79 |  * RETURN:      Status | 
 | 80 |  * | 
 | 81 |  * DESCRIPTION: Installs the core subsystem default address space handlers. | 
 | 82 |  * | 
 | 83 |  ******************************************************************************/ | 
 | 84 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 85 | acpi_status acpi_ev_install_region_handlers(void) | 
 | 86 | { | 
 | 87 | 	acpi_status status; | 
| Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 88 | 	u32 i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 90 | 	ACPI_FUNCTION_TRACE(ev_install_region_handlers); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 92 | 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
 | 93 | 	if (ACPI_FAILURE(status)) { | 
 | 94 | 		return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | 	} | 
 | 96 |  | 
 | 97 | 	/* | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 98 | 	 * All address spaces (PCI Config, EC, SMBus) are scope dependent and | 
 | 99 | 	 * registration must occur for a specific device. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | 	 * | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 101 | 	 * In the case of the system memory and IO address spaces there is | 
 | 102 | 	 * currently no device associated with the address space. For these we | 
 | 103 | 	 * use the root. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | 	 * | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 105 | 	 * We install the default PCI config space handler at the root so that | 
 | 106 | 	 * this space is immediately available even though the we have not | 
 | 107 | 	 * enumerated all the PCI Root Buses yet. This is to conform to the ACPI | 
 | 108 | 	 * specification which states that the PCI config space must be always | 
 | 109 | 	 * available -- even though we are nowhere near ready to find the PCI root | 
 | 110 | 	 * buses at this point. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | 	 * | 
 | 112 | 	 * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler | 
 | 113 | 	 * has already been installed (via acpi_install_address_space_handler). | 
 | 114 | 	 * Similar for AE_SAME_HANDLER. | 
 | 115 | 	 */ | 
 | 116 | 	for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 117 | 		status = acpi_ev_install_space_handler(acpi_gbl_root_node, | 
 | 118 | 						       acpi_gbl_default_address_spaces | 
 | 119 | 						       [i], | 
 | 120 | 						       ACPI_DEFAULT_HANDLER, | 
 | 121 | 						       NULL, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | 		switch (status) { | 
 | 123 | 		case AE_OK: | 
 | 124 | 		case AE_SAME_HANDLER: | 
 | 125 | 		case AE_ALREADY_EXISTS: | 
 | 126 |  | 
 | 127 | 			/* These exceptions are all OK */ | 
 | 128 |  | 
 | 129 | 			status = AE_OK; | 
 | 130 | 			break; | 
 | 131 |  | 
 | 132 | 		default: | 
 | 133 |  | 
 | 134 | 			goto unlock_and_exit; | 
 | 135 | 		} | 
 | 136 | 	} | 
 | 137 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 |       unlock_and_exit: | 
 | 139 | 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
 | 140 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } | 
 | 142 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | /******************************************************************************* | 
 | 144 |  * | 
 | 145 |  * FUNCTION:    acpi_ev_initialize_op_regions | 
 | 146 |  * | 
 | 147 |  * PARAMETERS:  None | 
 | 148 |  * | 
 | 149 |  * RETURN:      Status | 
 | 150 |  * | 
 | 151 |  * DESCRIPTION: Execute _REG methods for all Operation Regions that have | 
 | 152 |  *              an installed default region handler. | 
 | 153 |  * | 
 | 154 |  ******************************************************************************/ | 
 | 155 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | acpi_status acpi_ev_initialize_op_regions(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 158 | 	acpi_status status; | 
| Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 159 | 	u32 i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 161 | 	ACPI_FUNCTION_TRACE(ev_initialize_op_regions); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 163 | 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
 | 164 | 	if (ACPI_FAILURE(status)) { | 
 | 165 | 		return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | 	} | 
 | 167 |  | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 168 | 	/* Run the _REG methods for op_regions in each default address space */ | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 169 |  | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 170 | 	for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) { | 
 | 171 | 		/* | 
 | 172 | 		 * TBD: Make sure handler is the DEFAULT handler, otherwise | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | 		 * _REG will have already been run. | 
 | 174 | 		 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 175 | 		status = acpi_ev_execute_reg_methods(acpi_gbl_root_node, | 
 | 176 | 						     acpi_gbl_default_address_spaces | 
 | 177 | 						     [i]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | 	} | 
 | 179 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 180 | 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
 | 181 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } | 
 | 183 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | /******************************************************************************* | 
 | 185 |  * | 
 | 186 |  * FUNCTION:    acpi_ev_execute_reg_method | 
 | 187 |  * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 188 |  * PARAMETERS:  region_obj          - Region object | 
 | 189 |  *              Function            - Passed to _REG: On (1) or Off (0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 |  * | 
 | 191 |  * RETURN:      Status | 
 | 192 |  * | 
 | 193 |  * DESCRIPTION: Execute _REG method for a region | 
 | 194 |  * | 
 | 195 |  ******************************************************************************/ | 
 | 196 |  | 
 | 197 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 198 | acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 200 | 	struct acpi_evaluate_info *info; | 
 | 201 | 	union acpi_operand_object *args[3]; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 202 | 	union acpi_operand_object *region_obj2; | 
 | 203 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 205 | 	ACPI_FUNCTION_TRACE(ev_execute_reg_method); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 207 | 	region_obj2 = acpi_ns_get_secondary_object(region_obj); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | 	if (!region_obj2) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 209 | 		return_ACPI_STATUS(AE_NOT_EXIST); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | 	} | 
 | 211 |  | 
 | 212 | 	if (region_obj2->extra.method_REG == NULL) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 213 | 		return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | 	} | 
 | 215 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 216 | 	/* Allocate and initialize the evaluation information block */ | 
 | 217 |  | 
 | 218 | 	info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); | 
 | 219 | 	if (!info) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 220 | 		return_ACPI_STATUS(AE_NO_MEMORY); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | 	} | 
 | 222 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 223 | 	info->prefix_node = region_obj2->extra.method_REG; | 
 | 224 | 	info->pathname = NULL; | 
 | 225 | 	info->parameters = args; | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 226 | 	info->flags = ACPI_IGNORE_RETURN_VALUE; | 
 | 227 |  | 
 | 228 | 	/* | 
 | 229 | 	 * The _REG method has two arguments: | 
 | 230 | 	 * | 
 | 231 | 	 * Arg0 - Integer: | 
 | 232 | 	 *  Operation region space ID Same value as region_obj->Region.space_id | 
 | 233 | 	 * | 
 | 234 | 	 * Arg1 - Integer: | 
 | 235 | 	 *  connection status 1 for connecting the handler, 0 for disconnecting | 
 | 236 | 	 *  the handler (Passed as a parameter) | 
 | 237 | 	 */ | 
 | 238 | 	args[0] = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); | 
 | 239 | 	if (!args[0]) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | 		status = AE_NO_MEMORY; | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 241 | 		goto cleanup1; | 
 | 242 | 	} | 
 | 243 |  | 
 | 244 | 	args[1] = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); | 
 | 245 | 	if (!args[1]) { | 
 | 246 | 		status = AE_NO_MEMORY; | 
 | 247 | 		goto cleanup2; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | 	} | 
 | 249 |  | 
 | 250 | 	/* Setup the parameter objects */ | 
 | 251 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 252 | 	args[0]->integer.value = region_obj->region.space_id; | 
 | 253 | 	args[1]->integer.value = function; | 
 | 254 | 	args[2] = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 |  | 
 | 256 | 	/* Execute the method, no return value */ | 
 | 257 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 258 | 	ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 259 | 			(ACPI_TYPE_METHOD, info->prefix_node, NULL)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 261 | 	status = acpi_ns_evaluate(info); | 
 | 262 | 	acpi_ut_remove_reference(args[1]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 264 |       cleanup2: | 
 | 265 | 	acpi_ut_remove_reference(args[0]); | 
 | 266 |  | 
 | 267 |       cleanup1: | 
 | 268 | 	ACPI_FREE(info); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 269 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | } | 
 | 271 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | /******************************************************************************* | 
 | 273 |  * | 
 | 274 |  * FUNCTION:    acpi_ev_address_space_dispatch | 
 | 275 |  * | 
 | 276 |  * PARAMETERS:  region_obj          - Internal region object | 
 | 277 |  *              Function            - Read or Write operation | 
| Bob Moore | f5407af | 2009-05-21 10:56:52 +0800 | [diff] [blame] | 278 |  *              region_offset       - Where in the region to read or write | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 |  *              bit_width           - Field width in bits (8, 16, 32, or 64) | 
| Bob Moore | 958dd24 | 2006-05-12 17:12:00 -0400 | [diff] [blame] | 280 |  *              Value               - Pointer to in or out value, must be | 
 | 281 |  *                                    full 64-bit acpi_integer | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 |  * | 
 | 283 |  * RETURN:      Status | 
 | 284 |  * | 
 | 285 |  * DESCRIPTION: Dispatch an address space or operation region access to | 
 | 286 |  *              a previously installed handler. | 
 | 287 |  * | 
 | 288 |  ******************************************************************************/ | 
 | 289 |  | 
 | 290 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 291 | acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj, | 
 | 292 | 			       u32 function, | 
| Bob Moore | f5407af | 2009-05-21 10:56:52 +0800 | [diff] [blame] | 293 | 			       u32 region_offset, | 
| Bob Moore | 958dd24 | 2006-05-12 17:12:00 -0400 | [diff] [blame] | 294 | 			       u32 bit_width, acpi_integer * value) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 296 | 	acpi_status status; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 297 | 	acpi_adr_space_handler handler; | 
 | 298 | 	acpi_adr_space_setup region_setup; | 
 | 299 | 	union acpi_operand_object *handler_desc; | 
 | 300 | 	union acpi_operand_object *region_obj2; | 
 | 301 | 	void *region_context = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 303 | 	ACPI_FUNCTION_TRACE(ev_address_space_dispatch); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 305 | 	region_obj2 = acpi_ns_get_secondary_object(region_obj); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | 	if (!region_obj2) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 307 | 		return_ACPI_STATUS(AE_NOT_EXIST); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | 	} | 
 | 309 |  | 
 | 310 | 	/* Ensure that there is a handler associated with this region */ | 
 | 311 |  | 
 | 312 | 	handler_desc = region_obj->region.handler; | 
 | 313 | 	if (!handler_desc) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 314 | 		ACPI_ERROR((AE_INFO, | 
 | 315 | 			    "No handler for Region [%4.4s] (%p) [%s]", | 
 | 316 | 			    acpi_ut_get_node_name(region_obj->region.node), | 
 | 317 | 			    region_obj, | 
 | 318 | 			    acpi_ut_get_region_name(region_obj->region. | 
 | 319 | 						    space_id))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 321 | 		return_ACPI_STATUS(AE_NOT_EXIST); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | 	} | 
 | 323 |  | 
 | 324 | 	/* | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 325 | 	 * It may be the case that the region has never been initialized. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | 	 * Some types of regions require special init code | 
 | 327 | 	 */ | 
 | 328 | 	if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) { | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 329 |  | 
 | 330 | 		/* This region has not been initialized yet, do it */ | 
 | 331 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | 		region_setup = handler_desc->address_space.setup; | 
 | 333 | 		if (!region_setup) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 334 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | 			/* No initialization routine, exit with error */ | 
 | 336 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 337 | 			ACPI_ERROR((AE_INFO, | 
 | 338 | 				    "No init routine for region(%p) [%s]", | 
 | 339 | 				    region_obj, | 
 | 340 | 				    acpi_ut_get_region_name(region_obj->region. | 
 | 341 | 							    space_id))); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 342 | 			return_ACPI_STATUS(AE_NOT_EXIST); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | 		} | 
 | 344 |  | 
 | 345 | 		/* | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 346 | 		 * We must exit the interpreter because the region setup will | 
 | 347 | 		 * potentially execute control methods (for example, the _REG method | 
 | 348 | 		 * for this region) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | 		 */ | 
| Bob Moore | 014d433 | 2008-01-10 23:04:10 -0500 | [diff] [blame] | 350 | 		acpi_ex_exit_interpreter(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 352 | 		status = region_setup(region_obj, ACPI_REGION_ACTIVATE, | 
 | 353 | 				      handler_desc->address_space.context, | 
 | 354 | 				      ®ion_context); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 |  | 
 | 356 | 		/* Re-enter the interpreter */ | 
 | 357 |  | 
| Bob Moore | 014d433 | 2008-01-10 23:04:10 -0500 | [diff] [blame] | 358 | 		acpi_ex_enter_interpreter(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 |  | 
 | 360 | 		/* Check for failure of the Region Setup */ | 
 | 361 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 362 | 		if (ACPI_FAILURE(status)) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 363 | 			ACPI_EXCEPTION((AE_INFO, status, | 
 | 364 | 					"During region initialization: [%s]", | 
 | 365 | 					acpi_ut_get_region_name(region_obj-> | 
 | 366 | 								region. | 
 | 367 | 								space_id))); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 368 | 			return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | 		} | 
 | 370 |  | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 371 | 		/* Region initialization may have been completed by region_setup */ | 
 | 372 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | 		if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) { | 
 | 374 | 			region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE; | 
 | 375 |  | 
 | 376 | 			if (region_obj2->extra.region_context) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 377 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | 				/* The handler for this region was already installed */ | 
 | 379 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 380 | 				ACPI_FREE(region_context); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 381 | 			} else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | 				/* | 
 | 383 | 				 * Save the returned context for use in all accesses to | 
 | 384 | 				 * this particular region | 
 | 385 | 				 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 386 | 				region_obj2->extra.region_context = | 
 | 387 | 				    region_context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | 			} | 
 | 389 | 		} | 
 | 390 | 	} | 
 | 391 |  | 
 | 392 | 	/* We have everything we need, we can invoke the address space handler */ | 
 | 393 |  | 
 | 394 | 	handler = handler_desc->address_space.handler; | 
 | 395 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 396 | 	ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, | 
 | 397 | 			  "Handler %p (@%p) Address %8.8X%8.8X [%s]\n", | 
 | 398 | 			  ®ion_obj->region.handler->address_space, handler, | 
| Bob Moore | f5407af | 2009-05-21 10:56:52 +0800 | [diff] [blame] | 399 | 			  ACPI_FORMAT_NATIVE_UINT(region_obj->region.address + | 
 | 400 | 						  region_offset), | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 401 | 			  acpi_ut_get_region_name(region_obj->region. | 
 | 402 | 						  space_id))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 |  | 
| Bob Moore | 6168612 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 404 | 	if (!(handler_desc->address_space.handler_flags & | 
 | 405 | 	      ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | 		/* | 
 | 407 | 		 * For handlers other than the default (supplied) handlers, we must | 
 | 408 | 		 * exit the interpreter because the handler *might* block -- we don't | 
 | 409 | 		 * know what it will do, so we can't hold the lock on the intepreter. | 
 | 410 | 		 */ | 
| Bob Moore | 014d433 | 2008-01-10 23:04:10 -0500 | [diff] [blame] | 411 | 		acpi_ex_exit_interpreter(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | 	} | 
 | 413 |  | 
 | 414 | 	/* Call the handler */ | 
 | 415 |  | 
| Bob Moore | f5407af | 2009-05-21 10:56:52 +0800 | [diff] [blame] | 416 | 	status = handler(function, | 
 | 417 | 			 (region_obj->region.address + region_offset), | 
 | 418 | 			 bit_width, value, handler_desc->address_space.context, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | 			 region_obj2->extra.region_context); | 
 | 420 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 421 | 	if (ACPI_FAILURE(status)) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 422 | 		ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]", | 
 | 423 | 				acpi_ut_get_region_name(region_obj->region. | 
 | 424 | 							space_id))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | 	} | 
 | 426 |  | 
| Bob Moore | 6168612 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 427 | 	if (!(handler_desc->address_space.handler_flags & | 
 | 428 | 	      ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | 		/* | 
 | 430 | 		 * We just returned from a non-default handler, we must re-enter the | 
 | 431 | 		 * interpreter | 
 | 432 | 		 */ | 
| Bob Moore | 014d433 | 2008-01-10 23:04:10 -0500 | [diff] [blame] | 433 | 		acpi_ex_enter_interpreter(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | 	} | 
 | 435 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 436 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } | 
 | 438 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | /******************************************************************************* | 
 | 440 |  * | 
 | 441 |  * FUNCTION:    acpi_ev_detach_region | 
 | 442 |  * | 
 | 443 |  * PARAMETERS:  region_obj          - Region Object | 
 | 444 |  *              acpi_ns_is_locked   - Namespace Region Already Locked? | 
 | 445 |  * | 
 | 446 |  * RETURN:      None | 
 | 447 |  * | 
 | 448 |  * DESCRIPTION: Break the association between the handler and the region | 
 | 449 |  *              this is a two way association. | 
 | 450 |  * | 
 | 451 |  ******************************************************************************/ | 
 | 452 |  | 
 | 453 | void | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 454 | acpi_ev_detach_region(union acpi_operand_object *region_obj, | 
 | 455 | 		      u8 acpi_ns_is_locked) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 457 | 	union acpi_operand_object *handler_obj; | 
 | 458 | 	union acpi_operand_object *obj_desc; | 
 | 459 | 	union acpi_operand_object **last_obj_ptr; | 
 | 460 | 	acpi_adr_space_setup region_setup; | 
 | 461 | 	void **region_context; | 
 | 462 | 	union acpi_operand_object *region_obj2; | 
 | 463 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 465 | 	ACPI_FUNCTION_TRACE(ev_detach_region); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 467 | 	region_obj2 = acpi_ns_get_secondary_object(region_obj); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | 	if (!region_obj2) { | 
 | 469 | 		return_VOID; | 
 | 470 | 	} | 
 | 471 | 	region_context = ®ion_obj2->extra.region_context; | 
 | 472 |  | 
 | 473 | 	/* Get the address handler from the region object */ | 
 | 474 |  | 
 | 475 | 	handler_obj = region_obj->region.handler; | 
 | 476 | 	if (!handler_obj) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 477 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | 		/* This region has no handler, all done */ | 
 | 479 |  | 
 | 480 | 		return_VOID; | 
 | 481 | 	} | 
 | 482 |  | 
 | 483 | 	/* Find this region in the handler's list */ | 
 | 484 |  | 
 | 485 | 	obj_desc = handler_obj->address_space.region_list; | 
 | 486 | 	last_obj_ptr = &handler_obj->address_space.region_list; | 
 | 487 |  | 
 | 488 | 	while (obj_desc) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 489 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | 		/* Is this the correct Region? */ | 
 | 491 |  | 
 | 492 | 		if (obj_desc == region_obj) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 493 | 			ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, | 
 | 494 | 					  "Removing Region %p from address handler %p\n", | 
 | 495 | 					  region_obj, handler_obj)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 |  | 
 | 497 | 			/* This is it, remove it from the handler's list */ | 
 | 498 |  | 
 | 499 | 			*last_obj_ptr = obj_desc->region.next; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 500 | 			obj_desc->region.next = NULL;	/* Must clear field */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 |  | 
 | 502 | 			if (acpi_ns_is_locked) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 503 | 				status = | 
 | 504 | 				    acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
 | 505 | 				if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | 					return_VOID; | 
 | 507 | 				} | 
 | 508 | 			} | 
 | 509 |  | 
 | 510 | 			/* Now stop region accesses by executing the _REG method */ | 
 | 511 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 512 | 			status = acpi_ev_execute_reg_method(region_obj, 0); | 
 | 513 | 			if (ACPI_FAILURE(status)) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 514 | 				ACPI_EXCEPTION((AE_INFO, status, | 
 | 515 | 						"from region _REG, [%s]", | 
 | 516 | 						acpi_ut_get_region_name | 
 | 517 | 						(region_obj->region.space_id))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | 			} | 
 | 519 |  | 
 | 520 | 			if (acpi_ns_is_locked) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 521 | 				status = | 
 | 522 | 				    acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
 | 523 | 				if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | 					return_VOID; | 
 | 525 | 				} | 
 | 526 | 			} | 
 | 527 |  | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 528 | 			/* | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 529 | 			 * If the region has been activated, call the setup handler with | 
 | 530 | 			 * the deactivate notification | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 531 | 			 */ | 
 | 532 | 			if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) { | 
 | 533 | 				region_setup = handler_obj->address_space.setup; | 
 | 534 | 				status = | 
 | 535 | 				    region_setup(region_obj, | 
 | 536 | 						 ACPI_REGION_DEACTIVATE, | 
 | 537 | 						 handler_obj->address_space. | 
 | 538 | 						 context, region_context); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 |  | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 540 | 				/* Init routine may fail, Just ignore errors */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 |  | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 542 | 				if (ACPI_FAILURE(status)) { | 
 | 543 | 					ACPI_EXCEPTION((AE_INFO, status, | 
 | 544 | 							"from region handler - deactivate, [%s]", | 
 | 545 | 							acpi_ut_get_region_name | 
 | 546 | 							(region_obj->region. | 
 | 547 | 							 space_id))); | 
 | 548 | 				} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 |  | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 550 | 				region_obj->region.flags &= | 
 | 551 | 				    ~(AOPOBJ_SETUP_COMPLETE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | 			} | 
 | 553 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | 			/* | 
 | 555 | 			 * Remove handler reference in the region | 
 | 556 | 			 * | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 557 | 			 * NOTE: this doesn't mean that the region goes away, the region | 
 | 558 | 			 * is just inaccessible as indicated to the _REG method | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | 			 * | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 560 | 			 * If the region is on the handler's list, this must be the | 
 | 561 | 			 * region's handler | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | 			 */ | 
 | 563 | 			region_obj->region.handler = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 564 | 			acpi_ut_remove_reference(handler_obj); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 |  | 
 | 566 | 			return_VOID; | 
 | 567 | 		} | 
 | 568 |  | 
 | 569 | 		/* Walk the linked list of handlers */ | 
 | 570 |  | 
 | 571 | 		last_obj_ptr = &obj_desc->region.next; | 
 | 572 | 		obj_desc = obj_desc->region.next; | 
 | 573 | 	} | 
 | 574 |  | 
 | 575 | 	/* If we get here, the region was not in the handler's region list */ | 
 | 576 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 577 | 	ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, | 
 | 578 | 			  "Cannot remove region %p from address handler %p\n", | 
 | 579 | 			  region_obj, handler_obj)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 |  | 
 | 581 | 	return_VOID; | 
 | 582 | } | 
 | 583 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | /******************************************************************************* | 
 | 585 |  * | 
 | 586 |  * FUNCTION:    acpi_ev_attach_region | 
 | 587 |  * | 
 | 588 |  * PARAMETERS:  handler_obj         - Handler Object | 
 | 589 |  *              region_obj          - Region Object | 
 | 590 |  *              acpi_ns_is_locked   - Namespace Region Already Locked? | 
 | 591 |  * | 
 | 592 |  * RETURN:      None | 
 | 593 |  * | 
 | 594 |  * DESCRIPTION: Create the association between the handler and the region | 
 | 595 |  *              this is a two way association. | 
 | 596 |  * | 
 | 597 |  ******************************************************************************/ | 
 | 598 |  | 
 | 599 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 600 | acpi_ev_attach_region(union acpi_operand_object *handler_obj, | 
 | 601 | 		      union acpi_operand_object *region_obj, | 
 | 602 | 		      u8 acpi_ns_is_locked) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | { | 
 | 604 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 605 | 	ACPI_FUNCTION_TRACE(ev_attach_region); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 607 | 	ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, | 
 | 608 | 			  "Adding Region [%4.4s] %p to address handler %p [%s]\n", | 
 | 609 | 			  acpi_ut_get_node_name(region_obj->region.node), | 
 | 610 | 			  region_obj, handler_obj, | 
 | 611 | 			  acpi_ut_get_region_name(region_obj->region. | 
 | 612 | 						  space_id))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 |  | 
 | 614 | 	/* Link this region to the front of the handler's list */ | 
 | 615 |  | 
 | 616 | 	region_obj->region.next = handler_obj->address_space.region_list; | 
 | 617 | 	handler_obj->address_space.region_list = region_obj; | 
 | 618 |  | 
 | 619 | 	/* Install the region's handler */ | 
 | 620 |  | 
 | 621 | 	if (region_obj->region.handler) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 622 | 		return_ACPI_STATUS(AE_ALREADY_EXISTS); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | 	} | 
 | 624 |  | 
 | 625 | 	region_obj->region.handler = handler_obj; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 626 | 	acpi_ut_add_reference(handler_obj); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 628 | 	return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | } | 
 | 630 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | /******************************************************************************* | 
 | 632 |  * | 
 | 633 |  * FUNCTION:    acpi_ev_install_handler | 
 | 634 |  * | 
 | 635 |  * PARAMETERS:  walk_namespace callback | 
 | 636 |  * | 
 | 637 |  * DESCRIPTION: This routine installs an address handler into objects that are | 
 | 638 |  *              of type Region or Device. | 
 | 639 |  * | 
 | 640 |  *              If the Object is a Device, and the device has a handler of | 
 | 641 |  *              the same type then the search is terminated in that branch. | 
 | 642 |  * | 
 | 643 |  *              This is because the existing handler is closer in proximity | 
 | 644 |  *              to any more regions than the one we are trying to install. | 
 | 645 |  * | 
 | 646 |  ******************************************************************************/ | 
 | 647 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 648 | static acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 649 | acpi_ev_install_handler(acpi_handle obj_handle, | 
 | 650 | 			u32 level, void *context, void **return_value) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 652 | 	union acpi_operand_object *handler_obj; | 
 | 653 | 	union acpi_operand_object *next_handler_obj; | 
 | 654 | 	union acpi_operand_object *obj_desc; | 
 | 655 | 	struct acpi_namespace_node *node; | 
 | 656 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 658 | 	ACPI_FUNCTION_NAME(ev_install_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 660 | 	handler_obj = (union acpi_operand_object *)context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 |  | 
 | 662 | 	/* Parameter validation */ | 
 | 663 |  | 
 | 664 | 	if (!handler_obj) { | 
 | 665 | 		return (AE_OK); | 
 | 666 | 	} | 
 | 667 |  | 
 | 668 | 	/* Convert and validate the device handle */ | 
 | 669 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 670 | 	node = acpi_ns_map_handle_to_node(obj_handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | 	if (!node) { | 
 | 672 | 		return (AE_BAD_PARAMETER); | 
 | 673 | 	} | 
 | 674 |  | 
 | 675 | 	/* | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 676 | 	 * We only care about regions and objects that are allowed to have | 
 | 677 | 	 * address space handlers | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | 	 */ | 
 | 679 | 	if ((node->type != ACPI_TYPE_DEVICE) && | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 680 | 	    (node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | 		return (AE_OK); | 
 | 682 | 	} | 
 | 683 |  | 
 | 684 | 	/* Check for an existing internal object */ | 
 | 685 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 686 | 	obj_desc = acpi_ns_get_attached_object(node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | 	if (!obj_desc) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 688 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | 		/* No object, just exit */ | 
 | 690 |  | 
 | 691 | 		return (AE_OK); | 
 | 692 | 	} | 
 | 693 |  | 
 | 694 | 	/* Devices are handled different than regions */ | 
 | 695 |  | 
| Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 696 | 	if (obj_desc->common.type == ACPI_TYPE_DEVICE) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 697 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | 		/* Check if this Device already has a handler for this address space */ | 
 | 699 |  | 
 | 700 | 		next_handler_obj = obj_desc->device.handler; | 
 | 701 | 		while (next_handler_obj) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 702 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | 			/* Found a handler, is it for the same address space? */ | 
 | 704 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 705 | 			if (next_handler_obj->address_space.space_id == | 
 | 706 | 			    handler_obj->address_space.space_id) { | 
 | 707 | 				ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, | 
| Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 708 | 						  "Found handler for region [%s] in device %p(%p) " | 
 | 709 | 						  "handler %p\n", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 710 | 						  acpi_ut_get_region_name | 
 | 711 | 						  (handler_obj->address_space. | 
 | 712 | 						   space_id), obj_desc, | 
 | 713 | 						  next_handler_obj, | 
 | 714 | 						  handler_obj)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 |  | 
 | 716 | 				/* | 
 | 717 | 				 * Since the object we found it on was a device, then it | 
 | 718 | 				 * means that someone has already installed a handler for | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 719 | 				 * the branch of the namespace from this device on. Just | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | 				 * bail out telling the walk routine to not traverse this | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 721 | 				 * branch. This preserves the scoping rule for handlers. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | 				 */ | 
 | 723 | 				return (AE_CTRL_DEPTH); | 
 | 724 | 			} | 
 | 725 |  | 
 | 726 | 			/* Walk the linked list of handlers attached to this device */ | 
 | 727 |  | 
 | 728 | 			next_handler_obj = next_handler_obj->address_space.next; | 
 | 729 | 		} | 
 | 730 |  | 
 | 731 | 		/* | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 732 | 		 * As long as the device didn't have a handler for this space we | 
 | 733 | 		 * don't care about it. We just ignore it and proceed. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | 		 */ | 
 | 735 | 		return (AE_OK); | 
 | 736 | 	} | 
 | 737 |  | 
 | 738 | 	/* Object is a Region */ | 
 | 739 |  | 
 | 740 | 	if (obj_desc->region.space_id != handler_obj->address_space.space_id) { | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 741 |  | 
 | 742 | 		/* This region is for a different address space, just ignore it */ | 
 | 743 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | 		return (AE_OK); | 
 | 745 | 	} | 
 | 746 |  | 
 | 747 | 	/* | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 748 | 	 * Now we have a region and it is for the handler's address space type. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | 	 * | 
 | 750 | 	 * First disconnect region for any previous handler (if any) | 
 | 751 | 	 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 752 | 	acpi_ev_detach_region(obj_desc, FALSE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 |  | 
 | 754 | 	/* Connect the region to the new handler */ | 
 | 755 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 756 | 	status = acpi_ev_attach_region(handler_obj, obj_desc, FALSE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | 	return (status); | 
 | 758 | } | 
 | 759 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | /******************************************************************************* | 
 | 761 |  * | 
 | 762 |  * FUNCTION:    acpi_ev_install_space_handler | 
 | 763 |  * | 
 | 764 |  * PARAMETERS:  Node            - Namespace node for the device | 
 | 765 |  *              space_id        - The address space ID | 
 | 766 |  *              Handler         - Address of the handler | 
 | 767 |  *              Setup           - Address of the setup function | 
 | 768 |  *              Context         - Value passed to the handler on each access | 
 | 769 |  * | 
 | 770 |  * RETURN:      Status | 
 | 771 |  * | 
 | 772 |  * DESCRIPTION: Install a handler for all op_regions of a given space_id. | 
 | 773 |  *              Assumes namespace is locked | 
 | 774 |  * | 
 | 775 |  ******************************************************************************/ | 
 | 776 |  | 
 | 777 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 778 | acpi_ev_install_space_handler(struct acpi_namespace_node * node, | 
 | 779 | 			      acpi_adr_space_type space_id, | 
 | 780 | 			      acpi_adr_space_handler handler, | 
 | 781 | 			      acpi_adr_space_setup setup, void *context) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 783 | 	union acpi_operand_object *obj_desc; | 
 | 784 | 	union acpi_operand_object *handler_obj; | 
 | 785 | 	acpi_status status; | 
 | 786 | 	acpi_object_type type; | 
| Bob Moore | 6168612 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 787 | 	u8 flags = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 789 | 	ACPI_FUNCTION_TRACE(ev_install_space_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 |  | 
 | 791 | 	/* | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 792 | 	 * This registration is valid for only the types below and the root. This | 
 | 793 | 	 * is where the default handlers get placed. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | 	 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 795 | 	if ((node->type != ACPI_TYPE_DEVICE) && | 
 | 796 | 	    (node->type != ACPI_TYPE_PROCESSOR) && | 
 | 797 | 	    (node->type != ACPI_TYPE_THERMAL) && (node != acpi_gbl_root_node)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | 		status = AE_BAD_PARAMETER; | 
 | 799 | 		goto unlock_and_exit; | 
 | 800 | 	} | 
 | 801 |  | 
 | 802 | 	if (handler == ACPI_DEFAULT_HANDLER) { | 
 | 803 | 		flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED; | 
 | 804 |  | 
 | 805 | 		switch (space_id) { | 
 | 806 | 		case ACPI_ADR_SPACE_SYSTEM_MEMORY: | 
 | 807 | 			handler = acpi_ex_system_memory_space_handler; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 808 | 			setup = acpi_ev_system_memory_region_setup; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | 			break; | 
 | 810 |  | 
 | 811 | 		case ACPI_ADR_SPACE_SYSTEM_IO: | 
 | 812 | 			handler = acpi_ex_system_io_space_handler; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 813 | 			setup = acpi_ev_io_space_region_setup; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | 			break; | 
 | 815 |  | 
 | 816 | 		case ACPI_ADR_SPACE_PCI_CONFIG: | 
 | 817 | 			handler = acpi_ex_pci_config_space_handler; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 818 | 			setup = acpi_ev_pci_config_region_setup; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | 			break; | 
 | 820 |  | 
 | 821 | 		case ACPI_ADR_SPACE_CMOS: | 
 | 822 | 			handler = acpi_ex_cmos_space_handler; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 823 | 			setup = acpi_ev_cmos_region_setup; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | 			break; | 
 | 825 |  | 
 | 826 | 		case ACPI_ADR_SPACE_PCI_BAR_TARGET: | 
 | 827 | 			handler = acpi_ex_pci_bar_space_handler; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 828 | 			setup = acpi_ev_pci_bar_region_setup; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | 			break; | 
 | 830 |  | 
 | 831 | 		case ACPI_ADR_SPACE_DATA_TABLE: | 
 | 832 | 			handler = acpi_ex_data_table_space_handler; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 833 | 			setup = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | 			break; | 
 | 835 |  | 
 | 836 | 		default: | 
 | 837 | 			status = AE_BAD_PARAMETER; | 
 | 838 | 			goto unlock_and_exit; | 
 | 839 | 		} | 
 | 840 | 	} | 
 | 841 |  | 
 | 842 | 	/* If the caller hasn't specified a setup routine, use the default */ | 
 | 843 |  | 
 | 844 | 	if (!setup) { | 
 | 845 | 		setup = acpi_ev_default_region_setup; | 
 | 846 | 	} | 
 | 847 |  | 
 | 848 | 	/* Check for an existing internal object */ | 
 | 849 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 850 | 	obj_desc = acpi_ns_get_attached_object(node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | 	if (obj_desc) { | 
 | 852 | 		/* | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 853 | 		 * The attached device object already exists. Make sure the handler | 
 | 854 | 		 * is not already installed. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | 		 */ | 
 | 856 | 		handler_obj = obj_desc->device.handler; | 
 | 857 |  | 
 | 858 | 		/* Walk the handler list for this device */ | 
 | 859 |  | 
 | 860 | 		while (handler_obj) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 861 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | 			/* Same space_id indicates a handler already installed */ | 
 | 863 |  | 
 | 864 | 			if (handler_obj->address_space.space_id == space_id) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 865 | 				if (handler_obj->address_space.handler == | 
 | 866 | 				    handler) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | 					/* | 
 | 868 | 					 * It is (relatively) OK to attempt to install the SAME | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 869 | 					 * handler twice. This can easily happen with the | 
 | 870 | 					 * PCI_Config space. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | 					 */ | 
 | 872 | 					status = AE_SAME_HANDLER; | 
 | 873 | 					goto unlock_and_exit; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 874 | 				} else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | 					/* A handler is already installed */ | 
 | 876 |  | 
 | 877 | 					status = AE_ALREADY_EXISTS; | 
 | 878 | 				} | 
 | 879 | 				goto unlock_and_exit; | 
 | 880 | 			} | 
 | 881 |  | 
 | 882 | 			/* Walk the linked list of handlers */ | 
 | 883 |  | 
 | 884 | 			handler_obj = handler_obj->address_space.next; | 
 | 885 | 		} | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 886 | 	} else { | 
 | 887 | 		ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, | 
 | 888 | 				  "Creating object on Device %p while installing handler\n", | 
 | 889 | 				  node)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 |  | 
 | 891 | 		/* obj_desc does not exist, create one */ | 
 | 892 |  | 
 | 893 | 		if (node->type == ACPI_TYPE_ANY) { | 
 | 894 | 			type = ACPI_TYPE_DEVICE; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 895 | 		} else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | 			type = node->type; | 
 | 897 | 		} | 
 | 898 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 899 | 		obj_desc = acpi_ut_create_internal_object(type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | 		if (!obj_desc) { | 
 | 901 | 			status = AE_NO_MEMORY; | 
 | 902 | 			goto unlock_and_exit; | 
 | 903 | 		} | 
 | 904 |  | 
 | 905 | 		/* Init new descriptor */ | 
 | 906 |  | 
 | 907 | 		obj_desc->common.type = (u8) type; | 
 | 908 |  | 
 | 909 | 		/* Attach the new object to the Node */ | 
 | 910 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 911 | 		status = acpi_ns_attach_object(node, obj_desc, type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 |  | 
 | 913 | 		/* Remove local reference to the object */ | 
 | 914 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 915 | 		acpi_ut_remove_reference(obj_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 917 | 		if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | 			goto unlock_and_exit; | 
 | 919 | 		} | 
 | 920 | 	} | 
 | 921 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 922 | 	ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, | 
 | 923 | 			  "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n", | 
 | 924 | 			  acpi_ut_get_region_name(space_id), space_id, | 
 | 925 | 			  acpi_ut_get_node_name(node), node, obj_desc)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 |  | 
 | 927 | 	/* | 
 | 928 | 	 * Install the handler | 
 | 929 | 	 * | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 930 | 	 * At this point there is no existing handler. Just allocate the object | 
 | 931 | 	 * for the handler and link it into the list. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | 	 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 933 | 	handler_obj = | 
 | 934 | 	    acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_ADDRESS_HANDLER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | 	if (!handler_obj) { | 
 | 936 | 		status = AE_NO_MEMORY; | 
 | 937 | 		goto unlock_and_exit; | 
 | 938 | 	} | 
 | 939 |  | 
 | 940 | 	/* Init handler obj */ | 
 | 941 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 942 | 	handler_obj->address_space.space_id = (u8) space_id; | 
| Bob Moore | 6168612 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 943 | 	handler_obj->address_space.handler_flags = flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | 	handler_obj->address_space.region_list = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 945 | 	handler_obj->address_space.node = node; | 
 | 946 | 	handler_obj->address_space.handler = handler; | 
 | 947 | 	handler_obj->address_space.context = context; | 
 | 948 | 	handler_obj->address_space.setup = setup; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 |  | 
 | 950 | 	/* Install at head of Device.address_space list */ | 
 | 951 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 952 | 	handler_obj->address_space.next = obj_desc->device.handler; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 |  | 
 | 954 | 	/* | 
 | 955 | 	 * The Device object is the first reference on the handler_obj. | 
 | 956 | 	 * Each region that uses the handler adds a reference. | 
 | 957 | 	 */ | 
 | 958 | 	obj_desc->device.handler = handler_obj; | 
 | 959 |  | 
 | 960 | 	/* | 
 | 961 | 	 * Walk the namespace finding all of the regions this | 
 | 962 | 	 * handler will manage. | 
 | 963 | 	 * | 
 | 964 | 	 * Start at the device and search the branch toward | 
 | 965 | 	 * the leaf nodes until either the leaf is encountered or | 
 | 966 | 	 * a device is detected that has an address handler of the | 
 | 967 | 	 * same type. | 
 | 968 | 	 * | 
 | 969 | 	 * In either case, back up and search down the remainder | 
 | 970 | 	 * of the branch | 
 | 971 | 	 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 972 | 	status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX, | 
 | 973 | 					ACPI_NS_WALK_UNLOCK, | 
 | 974 | 					acpi_ev_install_handler, handler_obj, | 
 | 975 | 					NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 977 |       unlock_and_exit: | 
 | 978 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | } | 
 | 980 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | /******************************************************************************* | 
 | 982 |  * | 
 | 983 |  * FUNCTION:    acpi_ev_execute_reg_methods | 
 | 984 |  * | 
 | 985 |  * PARAMETERS:  Node            - Namespace node for the device | 
 | 986 |  *              space_id        - The address space ID | 
 | 987 |  * | 
 | 988 |  * RETURN:      Status | 
 | 989 |  * | 
 | 990 |  * DESCRIPTION: Run all _REG methods for the input Space ID; | 
 | 991 |  *              Note: assumes namespace is locked, or system init time. | 
 | 992 |  * | 
 | 993 |  ******************************************************************************/ | 
 | 994 |  | 
 | 995 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 996 | acpi_ev_execute_reg_methods(struct acpi_namespace_node *node, | 
 | 997 | 			    acpi_adr_space_type space_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 999 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1001 | 	ACPI_FUNCTION_TRACE(ev_execute_reg_methods); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 |  | 
 | 1003 | 	/* | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 1004 | 	 * Run all _REG methods for all Operation Regions for this space ID. This | 
 | 1005 | 	 * is a separate walk in order to handle any interdependencies between | 
 | 1006 | 	 * regions and _REG methods. (i.e. handlers must be installed for all | 
 | 1007 | 	 * regions of this Space ID before we can run any _REG methods) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | 	 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1009 | 	status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX, | 
 | 1010 | 					ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run, | 
 | 1011 | 					&space_id, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1013 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | } | 
 | 1015 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | /******************************************************************************* | 
 | 1017 |  * | 
 | 1018 |  * FUNCTION:    acpi_ev_reg_run | 
 | 1019 |  * | 
 | 1020 |  * PARAMETERS:  walk_namespace callback | 
 | 1021 |  * | 
| Bob Moore | 958dd24 | 2006-05-12 17:12:00 -0400 | [diff] [blame] | 1022 |  * DESCRIPTION: Run _REG method for region objects of the requested space_iD | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 |  * | 
 | 1024 |  ******************************************************************************/ | 
 | 1025 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 1026 | static acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1027 | acpi_ev_reg_run(acpi_handle obj_handle, | 
 | 1028 | 		u32 level, void *context, void **return_value) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1030 | 	union acpi_operand_object *obj_desc; | 
 | 1031 | 	struct acpi_namespace_node *node; | 
 | 1032 | 	acpi_adr_space_type space_id; | 
 | 1033 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1035 | 	space_id = *ACPI_CAST_PTR(acpi_adr_space_type, context); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 |  | 
 | 1037 | 	/* Convert and validate the device handle */ | 
 | 1038 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1039 | 	node = acpi_ns_map_handle_to_node(obj_handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | 	if (!node) { | 
 | 1041 | 		return (AE_BAD_PARAMETER); | 
 | 1042 | 	} | 
 | 1043 |  | 
 | 1044 | 	/* | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 1045 | 	 * We only care about regions.and objects that are allowed to have address | 
 | 1046 | 	 * space handlers | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | 	 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1048 | 	if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | 		return (AE_OK); | 
 | 1050 | 	} | 
 | 1051 |  | 
 | 1052 | 	/* Check for an existing internal object */ | 
 | 1053 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1054 | 	obj_desc = acpi_ns_get_attached_object(node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | 	if (!obj_desc) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 1056 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | 		/* No object, just exit */ | 
 | 1058 |  | 
 | 1059 | 		return (AE_OK); | 
 | 1060 | 	} | 
 | 1061 |  | 
 | 1062 | 	/* Object is a Region */ | 
 | 1063 |  | 
 | 1064 | 	if (obj_desc->region.space_id != space_id) { | 
| Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 1065 |  | 
 | 1066 | 		/* This region is for a different address space, just ignore it */ | 
 | 1067 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | 		return (AE_OK); | 
 | 1069 | 	} | 
 | 1070 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1071 | 	status = acpi_ev_execute_reg_method(obj_desc, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | 	return (status); | 
 | 1073 | } |