evrgnini.c 16.7 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7
/******************************************************************************
 *
 * Module Name: evrgnini- ACPI address_space (op_region) init
 *
 *****************************************************************************/

/*
Bob Moore's avatar
Bob Moore committed
8
 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds's avatar
Linus Torvalds committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    substantially similar to the "NO WARRANTY" disclaimer below
 *    ("Disclaimer") and any redistribution must be conditioned upon
 *    including a substantially similar Disclaimer requirement for further
 *    binary redistribution.
 * 3. Neither the names of the above-listed copyright holders nor the names
 *    of any contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 */

#include <acpi/acpi.h>
#include <acpi/acevents.h>
#include <acpi/acnamesp.h>

#define _COMPONENT          ACPI_EVENTS
Len Brown's avatar
Len Brown committed
49
ACPI_MODULE_NAME("evrgnini")
Linus Torvalds's avatar
Linus Torvalds committed
50 51 52 53 54 55 56 57 58 59 60 61

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_system_memory_region_setup
 *
 * PARAMETERS:  Handle              - Region we are interested in
 *              Function            - Start or stop
 *              handler_context     - Address space handler context
 *              region_context      - Region specific context
 *
 * RETURN:      Status
 *
62
 * DESCRIPTION: Setup a system_memory operation region
Linus Torvalds's avatar
Linus Torvalds committed
63 64 65
 *
 ******************************************************************************/
acpi_status
Len Brown's avatar
Len Brown committed
66 67 68
acpi_ev_system_memory_region_setup(acpi_handle handle,
				   u32 function,
				   void *handler_context, void **region_context)
Linus Torvalds's avatar
Linus Torvalds committed
69
{
Len Brown's avatar
Len Brown committed
70 71 72
	union acpi_operand_object *region_desc =
	    (union acpi_operand_object *)handle;
	struct acpi_mem_space_context *local_region_context;
Linus Torvalds's avatar
Linus Torvalds committed
73

Len Brown's avatar
Len Brown committed
74
	ACPI_FUNCTION_TRACE("ev_system_memory_region_setup");
Linus Torvalds's avatar
Linus Torvalds committed
75 76 77

	if (function == ACPI_REGION_DEACTIVATE) {
		if (*region_context) {
Len Brown's avatar
Len Brown committed
78
			ACPI_MEM_FREE(*region_context);
Linus Torvalds's avatar
Linus Torvalds committed
79 80
			*region_context = NULL;
		}
Len Brown's avatar
Len Brown committed
81
		return_ACPI_STATUS(AE_OK);
Linus Torvalds's avatar
Linus Torvalds committed
82 83 84 85
	}

	/* Create a new context */

Len Brown's avatar
Len Brown committed
86 87
	local_region_context =
	    ACPI_MEM_CALLOCATE(sizeof(struct acpi_mem_space_context));
Linus Torvalds's avatar
Linus Torvalds committed
88
	if (!(local_region_context)) {
Len Brown's avatar
Len Brown committed
89
		return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds's avatar
Linus Torvalds committed
90 91 92 93 94 95 96 97
	}

	/* Save the region length and address for use in the handler */

	local_region_context->length = region_desc->region.length;
	local_region_context->address = region_desc->region.address;

	*region_context = local_region_context;
Len Brown's avatar
Len Brown committed
98
	return_ACPI_STATUS(AE_OK);
Linus Torvalds's avatar
Linus Torvalds committed
99 100 101 102 103 104 105 106 107 108 109 110 111
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_io_space_region_setup
 *
 * PARAMETERS:  Handle              - Region we are interested in
 *              Function            - Start or stop
 *              handler_context     - Address space handler context
 *              region_context      - Region specific context
 *
 * RETURN:      Status
 *
112
 * DESCRIPTION: Setup a IO operation region
Linus Torvalds's avatar
Linus Torvalds committed
113 114 115 116
 *
 ******************************************************************************/

acpi_status
Len Brown's avatar
Len Brown committed
117 118 119
acpi_ev_io_space_region_setup(acpi_handle handle,
			      u32 function,
			      void *handler_context, void **region_context)
Linus Torvalds's avatar
Linus Torvalds committed
120
{
Len Brown's avatar
Len Brown committed
121
	ACPI_FUNCTION_TRACE("ev_io_space_region_setup");
Linus Torvalds's avatar
Linus Torvalds committed
122 123 124

	if (function == ACPI_REGION_DEACTIVATE) {
		*region_context = NULL;
Len Brown's avatar
Len Brown committed
125
	} else {
Linus Torvalds's avatar
Linus Torvalds committed
126 127 128
		*region_context = handler_context;
	}

Len Brown's avatar
Len Brown committed
129
	return_ACPI_STATUS(AE_OK);
Linus Torvalds's avatar
Linus Torvalds committed
130 131 132 133 134 135
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_pci_config_region_setup
 *
136
 * PARAMETERS:  Handle              - Region we are interested in
Linus Torvalds's avatar
Linus Torvalds committed
137 138 139 140 141 142
 *              Function            - Start or stop
 *              handler_context     - Address space handler context
 *              region_context      - Region specific context
 *
 * RETURN:      Status
 *
143
 * DESCRIPTION: Setup a PCI_Config operation region
Linus Torvalds's avatar
Linus Torvalds committed
144 145 146 147 148 149
 *
 * MUTEX:       Assumes namespace is not locked
 *
 ******************************************************************************/

acpi_status
Len Brown's avatar
Len Brown committed
150 151 152
acpi_ev_pci_config_region_setup(acpi_handle handle,
				u32 function,
				void *handler_context, void **region_context)
Linus Torvalds's avatar
Linus Torvalds committed
153
{
Len Brown's avatar
Len Brown committed
154 155 156 157 158 159 160 161 162 163 164
	acpi_status status = AE_OK;
	acpi_integer pci_value;
	struct acpi_pci_id *pci_id = *region_context;
	union acpi_operand_object *handler_obj;
	struct acpi_namespace_node *parent_node;
	struct acpi_namespace_node *pci_root_node;
	union acpi_operand_object *region_obj =
	    (union acpi_operand_object *)handle;
	struct acpi_device_id object_hID;

	ACPI_FUNCTION_TRACE("ev_pci_config_region_setup");
Linus Torvalds's avatar
Linus Torvalds committed
165 166 167 168 169 170 171

	handler_obj = region_obj->region.handler;
	if (!handler_obj) {
		/*
		 * No installed handler. This shouldn't happen because the dispatch
		 * routine checks before we get here, but we check again just in case.
		 */
Len Brown's avatar
Len Brown committed
172 173 174 175
		ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
				  "Attempting to init a region %p, with no handler\n",
				  region_obj));
		return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds's avatar
Linus Torvalds committed
176 177 178 179 180
	}

	*region_context = NULL;
	if (function == ACPI_REGION_DEACTIVATE) {
		if (pci_id) {
Len Brown's avatar
Len Brown committed
181
			ACPI_MEM_FREE(pci_id);
Linus Torvalds's avatar
Linus Torvalds committed
182
		}
Len Brown's avatar
Len Brown committed
183
		return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
184 185
	}

Len Brown's avatar
Len Brown committed
186
	parent_node = acpi_ns_get_parent_node(region_obj->region.node);
Linus Torvalds's avatar
Linus Torvalds committed
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201

	/*
	 * Get the _SEG and _BBN values from the device upon which the handler
	 * is installed.
	 *
	 * We need to get the _SEG and _BBN objects relative to the PCI BUS device.
	 * This is the device the handler has been registered to handle.
	 */

	/*
	 * If the address_space.Node is still pointing to the root, we need
	 * to scan upward for a PCI Root bridge and re-associate the op_region
	 * handlers with that device.
	 */
	if (handler_obj->address_space.node == acpi_gbl_root_node) {
Bob Moore's avatar
Bob Moore committed
202

Linus Torvalds's avatar
Linus Torvalds committed
203 204 205 206
		/* Start search from the parent object */

		pci_root_node = parent_node;
		while (pci_root_node != acpi_gbl_root_node) {
Len Brown's avatar
Len Brown committed
207 208 209
			status =
			    acpi_ut_execute_HID(pci_root_node, &object_hID);
			if (ACPI_SUCCESS(status)) {
210 211 212 213
				/*
				 * Got a valid _HID string, check if this is a PCI root.
				 * New for ACPI 3.0: check for a PCI Express root also.
				 */
Len Brown's avatar
Len Brown committed
214 215 216 217 218 219 220 221 222 223
				if (!
				    (ACPI_STRNCMP
				     (object_hID.value, PCI_ROOT_HID_STRING,
				      sizeof(PCI_ROOT_HID_STRING))
				     ||
				     !(ACPI_STRNCMP
				       (object_hID.value,
					PCI_EXPRESS_ROOT_HID_STRING,
					sizeof(PCI_EXPRESS_ROOT_HID_STRING)))))
				{
Bob Moore's avatar
Bob Moore committed
224

Linus Torvalds's avatar
Linus Torvalds committed
225 226
					/* Install a handler for this PCI root bridge */

Len Brown's avatar
Len Brown committed
227 228 229
					status =
					    acpi_install_address_space_handler((acpi_handle) pci_root_node, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
					if (ACPI_FAILURE(status)) {
Linus Torvalds's avatar
Linus Torvalds committed
230 231 232 233 234 235 236
						if (status == AE_SAME_HANDLER) {
							/*
							 * It is OK if the handler is already installed on the root
							 * bridge.  Still need to return a context object for the
							 * new PCI_Config operation region, however.
							 */
							status = AE_OK;
Len Brown's avatar
Len Brown committed
237
						} else {
Bob Moore's avatar
Bob Moore committed
238 239 240 241 242
							ACPI_EXCEPTION((AE_INFO,
									status,
									"Could not install pci_config handler for Root Bridge %4.4s",
									acpi_ut_get_node_name
									(pci_root_node)));
Linus Torvalds's avatar
Linus Torvalds committed
243 244 245 246 247 248
						}
					}
					break;
				}
			}

Len Brown's avatar
Len Brown committed
249
			pci_root_node = acpi_ns_get_parent_node(pci_root_node);
Linus Torvalds's avatar
Linus Torvalds committed
250 251 252
		}

		/* PCI root bridge not found, use namespace root node */
Len Brown's avatar
Len Brown committed
253
	} else {
Linus Torvalds's avatar
Linus Torvalds committed
254 255 256 257 258 259 260 261
		pci_root_node = handler_obj->address_space.node;
	}

	/*
	 * If this region is now initialized, we are done.
	 * (install_address_space_handler could have initialized it)
	 */
	if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
Len Brown's avatar
Len Brown committed
262
		return_ACPI_STATUS(AE_OK);
Linus Torvalds's avatar
Linus Torvalds committed
263 264 265 266
	}

	/* Region is still not initialized. Create a new context */

Len Brown's avatar
Len Brown committed
267
	pci_id = ACPI_MEM_CALLOCATE(sizeof(struct acpi_pci_id));
Linus Torvalds's avatar
Linus Torvalds committed
268
	if (!pci_id) {
Len Brown's avatar
Len Brown committed
269
		return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds's avatar
Linus Torvalds committed
270 271 272 273 274 275 276 277 278 279 280
	}

	/*
	 * For PCI_Config space access, we need the segment, bus,
	 * device and function numbers.  Acquire them here.
	 */

	/*
	 * Get the PCI device and function numbers from the _ADR object
	 * contained in the parent's scope.
	 */
Len Brown's avatar
Len Brown committed
281 282 283
	status =
	    acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, parent_node,
					    &pci_value);
Linus Torvalds's avatar
Linus Torvalds committed
284 285 286 287 288

	/*
	 * The default is zero, and since the allocation above zeroed
	 * the data, just do nothing on failure.
	 */
Len Brown's avatar
Len Brown committed
289 290 291
	if (ACPI_SUCCESS(status)) {
		pci_id->device = ACPI_HIWORD(ACPI_LODWORD(pci_value));
		pci_id->function = ACPI_LOWORD(ACPI_LODWORD(pci_value));
Linus Torvalds's avatar
Linus Torvalds committed
292 293 294 295
	}

	/* The PCI segment number comes from the _SEG method */

Len Brown's avatar
Len Brown committed
296 297 298 299 300
	status =
	    acpi_ut_evaluate_numeric_object(METHOD_NAME__SEG, pci_root_node,
					    &pci_value);
	if (ACPI_SUCCESS(status)) {
		pci_id->segment = ACPI_LOWORD(pci_value);
Linus Torvalds's avatar
Linus Torvalds committed
301 302 303 304
	}

	/* The PCI bus number comes from the _BBN method */

Len Brown's avatar
Len Brown committed
305 306 307 308 309
	status =
	    acpi_ut_evaluate_numeric_object(METHOD_NAME__BBN, pci_root_node,
					    &pci_value);
	if (ACPI_SUCCESS(status)) {
		pci_id->bus = ACPI_LOWORD(pci_value);
Linus Torvalds's avatar
Linus Torvalds committed
310 311 312 313
	}

	/* Complete this device's pci_id */

Len Brown's avatar
Len Brown committed
314
	acpi_os_derive_pci_id(pci_root_node, region_obj->region.node, &pci_id);
Linus Torvalds's avatar
Linus Torvalds committed
315 316

	*region_context = pci_id;
Len Brown's avatar
Len Brown committed
317
	return_ACPI_STATUS(AE_OK);
Linus Torvalds's avatar
Linus Torvalds committed
318 319 320 321 322 323 324 325 326 327 328 329 330
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_pci_bar_region_setup
 *
 * PARAMETERS:  Handle              - Region we are interested in
 *              Function            - Start or stop
 *              handler_context     - Address space handler context
 *              region_context      - Region specific context
 *
 * RETURN:      Status
 *
331
 * DESCRIPTION: Setup a pci_bAR operation region
Linus Torvalds's avatar
Linus Torvalds committed
332 333 334 335 336 337
 *
 * MUTEX:       Assumes namespace is not locked
 *
 ******************************************************************************/

acpi_status
Len Brown's avatar
Len Brown committed
338 339 340
acpi_ev_pci_bar_region_setup(acpi_handle handle,
			     u32 function,
			     void *handler_context, void **region_context)
Linus Torvalds's avatar
Linus Torvalds committed
341
{
Len Brown's avatar
Len Brown committed
342
	ACPI_FUNCTION_TRACE("ev_pci_bar_region_setup");
Linus Torvalds's avatar
Linus Torvalds committed
343

Len Brown's avatar
Len Brown committed
344
	return_ACPI_STATUS(AE_OK);
Linus Torvalds's avatar
Linus Torvalds committed
345 346 347 348 349 350 351 352 353 354 355 356 357
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_cmos_region_setup
 *
 * PARAMETERS:  Handle              - Region we are interested in
 *              Function            - Start or stop
 *              handler_context     - Address space handler context
 *              region_context      - Region specific context
 *
 * RETURN:      Status
 *
358
 * DESCRIPTION: Setup a CMOS operation region
Linus Torvalds's avatar
Linus Torvalds committed
359 360 361 362 363 364
 *
 * MUTEX:       Assumes namespace is not locked
 *
 ******************************************************************************/

acpi_status
Len Brown's avatar
Len Brown committed
365 366 367
acpi_ev_cmos_region_setup(acpi_handle handle,
			  u32 function,
			  void *handler_context, void **region_context)
Linus Torvalds's avatar
Linus Torvalds committed
368
{
Len Brown's avatar
Len Brown committed
369
	ACPI_FUNCTION_TRACE("ev_cmos_region_setup");
Linus Torvalds's avatar
Linus Torvalds committed
370

Len Brown's avatar
Len Brown committed
371
	return_ACPI_STATUS(AE_OK);
Linus Torvalds's avatar
Linus Torvalds committed
372 373 374 375 376 377 378 379 380 381 382 383 384
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_default_region_setup
 *
 * PARAMETERS:  Handle              - Region we are interested in
 *              Function            - Start or stop
 *              handler_context     - Address space handler context
 *              region_context      - Region specific context
 *
 * RETURN:      Status
 *
385
 * DESCRIPTION: Default region initialization
Linus Torvalds's avatar
Linus Torvalds committed
386 387 388 389
 *
 ******************************************************************************/

acpi_status
Len Brown's avatar
Len Brown committed
390 391 392
acpi_ev_default_region_setup(acpi_handle handle,
			     u32 function,
			     void *handler_context, void **region_context)
Linus Torvalds's avatar
Linus Torvalds committed
393
{
Len Brown's avatar
Len Brown committed
394
	ACPI_FUNCTION_TRACE("ev_default_region_setup");
Linus Torvalds's avatar
Linus Torvalds committed
395 396 397

	if (function == ACPI_REGION_DEACTIVATE) {
		*region_context = NULL;
Len Brown's avatar
Len Brown committed
398
	} else {
Linus Torvalds's avatar
Linus Torvalds committed
399 400 401
		*region_context = handler_context;
	}

Len Brown's avatar
Len Brown committed
402
	return_ACPI_STATUS(AE_OK);
Linus Torvalds's avatar
Linus Torvalds committed
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_initialize_region
 *
 * PARAMETERS:  region_obj      - Region we are initializing
 *              acpi_ns_locked  - Is namespace locked?
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Initializes the region, finds any _REG methods and saves them
 *              for execution at a later time
 *
 *              Get the appropriate address space handler for a newly
 *              created region.
 *
 *              This also performs address space specific initialization.  For
 *              example, PCI regions must have an _ADR object that contains
 *              a PCI address in the scope of the definition.  This address is
 *              required to perform an access to PCI config space.
 *
 ******************************************************************************/

acpi_status
Len Brown's avatar
Len Brown committed
428 429
acpi_ev_initialize_region(union acpi_operand_object *region_obj,
			  u8 acpi_ns_locked)
Linus Torvalds's avatar
Linus Torvalds committed
430
{
Len Brown's avatar
Len Brown committed
431 432 433 434 435 436 437 438
	union acpi_operand_object *handler_obj;
	union acpi_operand_object *obj_desc;
	acpi_adr_space_type space_id;
	struct acpi_namespace_node *node;
	acpi_status status;
	struct acpi_namespace_node *method_node;
	acpi_name *reg_name_ptr = (acpi_name *) METHOD_NAME__REG;
	union acpi_operand_object *region_obj2;
Linus Torvalds's avatar
Linus Torvalds committed
439

Len Brown's avatar
Len Brown committed
440
	ACPI_FUNCTION_TRACE_U32("ev_initialize_region", acpi_ns_locked);
Linus Torvalds's avatar
Linus Torvalds committed
441 442

	if (!region_obj) {
Len Brown's avatar
Len Brown committed
443
		return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds's avatar
Linus Torvalds committed
444 445 446
	}

	if (region_obj->common.flags & AOPOBJ_OBJECT_INITIALIZED) {
Len Brown's avatar
Len Brown committed
447
		return_ACPI_STATUS(AE_OK);
Linus Torvalds's avatar
Linus Torvalds committed
448 449
	}

Len Brown's avatar
Len Brown committed
450
	region_obj2 = acpi_ns_get_secondary_object(region_obj);
Linus Torvalds's avatar
Linus Torvalds committed
451
	if (!region_obj2) {
Len Brown's avatar
Len Brown committed
452
		return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds's avatar
Linus Torvalds committed
453 454
	}

Len Brown's avatar
Len Brown committed
455
	node = acpi_ns_get_parent_node(region_obj->region.node);
Linus Torvalds's avatar
Linus Torvalds committed
456 457 458 459 460 461 462 463 464 465 466
	space_id = region_obj->region.space_id;

	/* Setup defaults */

	region_obj->region.handler = NULL;
	region_obj2->extra.method_REG = NULL;
	region_obj->common.flags &= ~(AOPOBJ_SETUP_COMPLETE);
	region_obj->common.flags |= AOPOBJ_OBJECT_INITIALIZED;

	/* Find any "_REG" method associated with this region definition */

Len Brown's avatar
Len Brown committed
467 468 469
	status = acpi_ns_search_node(*reg_name_ptr, node,
				     ACPI_TYPE_METHOD, &method_node);
	if (ACPI_SUCCESS(status)) {
Linus Torvalds's avatar
Linus Torvalds committed
470 471 472 473 474 475 476 477 478 479 480 481 482
		/*
		 * The _REG method is optional and there can be only one per region
		 * definition.  This will be executed when the handler is attached
		 * or removed
		 */
		region_obj2->extra.method_REG = method_node;
	}

	/*
	 * The following loop depends upon the root Node having no parent
	 * ie: acpi_gbl_root_node->parent_entry being set to NULL
	 */
	while (node) {
Bob Moore's avatar
Bob Moore committed
483

Linus Torvalds's avatar
Linus Torvalds committed
484 485 486
		/* Check to see if a handler exists */

		handler_obj = NULL;
Len Brown's avatar
Len Brown committed
487
		obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds's avatar
Linus Torvalds committed
488
		if (obj_desc) {
Bob Moore's avatar
Bob Moore committed
489

Linus Torvalds's avatar
Linus Torvalds committed
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
			/* Can only be a handler if the object exists */

			switch (node->type) {
			case ACPI_TYPE_DEVICE:

				handler_obj = obj_desc->device.handler;
				break;

			case ACPI_TYPE_PROCESSOR:

				handler_obj = obj_desc->processor.handler;
				break;

			case ACPI_TYPE_THERMAL:

				handler_obj = obj_desc->thermal_zone.handler;
				break;

			default:
				/* Ignore other objects */
				break;
			}

			while (handler_obj) {
Bob Moore's avatar
Bob Moore committed
514

Linus Torvalds's avatar
Linus Torvalds committed
515 516
				/* Is this handler of the correct type? */

Len Brown's avatar
Len Brown committed
517 518
				if (handler_obj->address_space.space_id ==
				    space_id) {
Bob Moore's avatar
Bob Moore committed
519

Linus Torvalds's avatar
Linus Torvalds committed
520 521
					/* Found correct handler */

Len Brown's avatar
Len Brown committed
522 523 524 525 526
					ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
							  "Found handler %p for region %p in obj %p\n",
							  handler_obj,
							  region_obj,
							  obj_desc));
Linus Torvalds's avatar
Linus Torvalds committed
527

Len Brown's avatar
Len Brown committed
528 529 530 531
					status =
					    acpi_ev_attach_region(handler_obj,
								  region_obj,
								  acpi_ns_locked);
Linus Torvalds's avatar
Linus Torvalds committed
532 533 534 535 536 537

					/*
					 * Tell all users that this region is usable by running the _REG
					 * method
					 */
					if (acpi_ns_locked) {
Len Brown's avatar
Len Brown committed
538 539 540 541 542 543
						status =
						    acpi_ut_release_mutex
						    (ACPI_MTX_NAMESPACE);
						if (ACPI_FAILURE(status)) {
							return_ACPI_STATUS
							    (status);
Linus Torvalds's avatar
Linus Torvalds committed
544 545 546
						}
					}

Len Brown's avatar
Len Brown committed
547 548 549
					status =
					    acpi_ev_execute_reg_method
					    (region_obj, 1);
Linus Torvalds's avatar
Linus Torvalds committed
550 551

					if (acpi_ns_locked) {
Len Brown's avatar
Len Brown committed
552 553 554 555 556 557
						status =
						    acpi_ut_acquire_mutex
						    (ACPI_MTX_NAMESPACE);
						if (ACPI_FAILURE(status)) {
							return_ACPI_STATUS
							    (status);
Linus Torvalds's avatar
Linus Torvalds committed
558 559 560
						}
					}

Len Brown's avatar
Len Brown committed
561
					return_ACPI_STATUS(AE_OK);
Linus Torvalds's avatar
Linus Torvalds committed
562 563 564 565 566 567 568 569 570 571 572 573
				}

				/* Try next handler in the list */

				handler_obj = handler_obj->address_space.next;
			}
		}

		/*
		 * This node does not have the handler we need;
		 * Pop up one level
		 */
Len Brown's avatar
Len Brown committed
574
		node = acpi_ns_get_parent_node(node);
Linus Torvalds's avatar
Linus Torvalds committed
575 576 577 578
	}

	/* If we get here, there is no handler for this region */

Len Brown's avatar
Len Brown committed
579 580 581 582
	ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
			  "No handler for region_type %s(%X) (region_obj %p)\n",
			  acpi_ut_get_region_name(space_id), space_id,
			  region_obj));
Linus Torvalds's avatar
Linus Torvalds committed
583

Len Brown's avatar
Len Brown committed
584
	return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds's avatar
Linus Torvalds committed
585
}