1 /******************************************************************************
3 * Module Name: evhandler - Support for Address Space handlers
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #define __EVHANDLER_C__
52 #define _COMPONENT ACPI_EVENTS
53 ACPI_MODULE_NAME ("evhandler")
56 /* Local prototypes */
59 AcpiEvInstallHandler (
60 ACPI_HANDLE ObjHandle,
65 /* These are the address spaces that will get default handlers */
67 UINT8 AcpiGbl_DefaultAddressSpaces[ACPI_NUM_DEFAULT_SPACES] =
69 ACPI_ADR_SPACE_SYSTEM_MEMORY,
70 ACPI_ADR_SPACE_SYSTEM_IO,
71 ACPI_ADR_SPACE_PCI_CONFIG,
72 ACPI_ADR_SPACE_DATA_TABLE
76 /*******************************************************************************
78 * FUNCTION: AcpiEvInstallRegionHandlers
84 * DESCRIPTION: Installs the core subsystem default address space handlers.
86 ******************************************************************************/
89 AcpiEvInstallRegionHandlers (
96 ACPI_FUNCTION_TRACE (EvInstallRegionHandlers);
99 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
100 if (ACPI_FAILURE (Status))
102 return_ACPI_STATUS (Status);
106 * All address spaces (PCI Config, EC, SMBus) are scope dependent and
107 * registration must occur for a specific device.
109 * In the case of the system memory and IO address spaces there is
110 * currently no device associated with the address space. For these we
113 * We install the default PCI config space handler at the root so that
114 * this space is immediately available even though the we have not
115 * enumerated all the PCI Root Buses yet. This is to conform to the ACPI
116 * specification which states that the PCI config space must be always
117 * available -- even though we are nowhere near ready to find the PCI root
118 * buses at this point.
120 * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
121 * has already been installed (via AcpiInstallAddressSpaceHandler).
122 * Similar for AE_SAME_HANDLER.
124 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
126 Status = AcpiEvInstallSpaceHandler (AcpiGbl_RootNode,
127 AcpiGbl_DefaultAddressSpaces[i],
128 ACPI_DEFAULT_HANDLER, NULL, NULL);
132 case AE_SAME_HANDLER:
133 case AE_ALREADY_EXISTS:
135 /* These exceptions are all OK */
147 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
148 return_ACPI_STATUS (Status);
152 /*******************************************************************************
154 * FUNCTION: AcpiEvHasDefaultHandler
156 * PARAMETERS: Node - Namespace node for the device
157 * SpaceId - The address space ID
159 * RETURN: TRUE if default handler is installed, FALSE otherwise
161 * DESCRIPTION: Check if the default handler is installed for the requested
164 ******************************************************************************/
167 AcpiEvHasDefaultHandler (
168 ACPI_NAMESPACE_NODE *Node,
169 ACPI_ADR_SPACE_TYPE SpaceId)
171 ACPI_OPERAND_OBJECT *ObjDesc;
172 ACPI_OPERAND_OBJECT *HandlerObj;
175 /* Must have an existing internal object */
177 ObjDesc = AcpiNsGetAttachedObject (Node);
180 HandlerObj = ObjDesc->Device.Handler;
182 /* Walk the linked list of handlers for this object */
186 if (HandlerObj->AddressSpace.SpaceId == SpaceId)
188 if (HandlerObj->AddressSpace.HandlerFlags &
189 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)
195 HandlerObj = HandlerObj->AddressSpace.Next;
203 /*******************************************************************************
205 * FUNCTION: AcpiEvInstallHandler
207 * PARAMETERS: WalkNamespace callback
209 * DESCRIPTION: This routine installs an address handler into objects that are
210 * of type Region or Device.
212 * If the Object is a Device, and the device has a handler of
213 * the same type then the search is terminated in that branch.
215 * This is because the existing handler is closer in proximity
216 * to any more regions than the one we are trying to install.
218 ******************************************************************************/
221 AcpiEvInstallHandler (
222 ACPI_HANDLE ObjHandle,
227 ACPI_OPERAND_OBJECT *HandlerObj;
228 ACPI_OPERAND_OBJECT *NextHandlerObj;
229 ACPI_OPERAND_OBJECT *ObjDesc;
230 ACPI_NAMESPACE_NODE *Node;
234 ACPI_FUNCTION_NAME (EvInstallHandler);
237 HandlerObj = (ACPI_OPERAND_OBJECT *) Context;
239 /* Parameter validation */
246 /* Convert and validate the device handle */
248 Node = AcpiNsValidateHandle (ObjHandle);
251 return (AE_BAD_PARAMETER);
255 * We only care about regions and objects that are allowed to have
256 * address space handlers
258 if ((Node->Type != ACPI_TYPE_DEVICE) &&
259 (Node->Type != ACPI_TYPE_REGION) &&
260 (Node != AcpiGbl_RootNode))
265 /* Check for an existing internal object */
267 ObjDesc = AcpiNsGetAttachedObject (Node);
270 /* No object, just exit */
275 /* Devices are handled different than regions */
277 if (ObjDesc->Common.Type == ACPI_TYPE_DEVICE)
279 /* Check if this Device already has a handler for this address space */
281 NextHandlerObj = ObjDesc->Device.Handler;
282 while (NextHandlerObj)
284 /* Found a handler, is it for the same address space? */
286 if (NextHandlerObj->AddressSpace.SpaceId ==
287 HandlerObj->AddressSpace.SpaceId)
289 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
290 "Found handler for region [%s] in device %p(%p) "
292 AcpiUtGetRegionName (HandlerObj->AddressSpace.SpaceId),
293 ObjDesc, NextHandlerObj, HandlerObj));
296 * Since the object we found it on was a device, then it
297 * means that someone has already installed a handler for
298 * the branch of the namespace from this device on. Just
299 * bail out telling the walk routine to not traverse this
300 * branch. This preserves the scoping rule for handlers.
302 return (AE_CTRL_DEPTH);
305 /* Walk the linked list of handlers attached to this device */
307 NextHandlerObj = NextHandlerObj->AddressSpace.Next;
311 * As long as the device didn't have a handler for this space we
312 * don't care about it. We just ignore it and proceed.
317 /* Object is a Region */
319 if (ObjDesc->Region.SpaceId != HandlerObj->AddressSpace.SpaceId)
321 /* This region is for a different address space, just ignore it */
327 * Now we have a region and it is for the handler's address space type.
329 * First disconnect region for any previous handler (if any)
331 AcpiEvDetachRegion (ObjDesc, FALSE);
333 /* Connect the region to the new handler */
335 Status = AcpiEvAttachRegion (HandlerObj, ObjDesc, FALSE);
340 /*******************************************************************************
342 * FUNCTION: AcpiEvInstallSpaceHandler
344 * PARAMETERS: Node - Namespace node for the device
345 * SpaceId - The address space ID
346 * Handler - Address of the handler
347 * Setup - Address of the setup function
348 * Context - Value passed to the handler on each access
352 * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
353 * Assumes namespace is locked
355 ******************************************************************************/
358 AcpiEvInstallSpaceHandler (
359 ACPI_NAMESPACE_NODE *Node,
360 ACPI_ADR_SPACE_TYPE SpaceId,
361 ACPI_ADR_SPACE_HANDLER Handler,
362 ACPI_ADR_SPACE_SETUP Setup,
365 ACPI_OPERAND_OBJECT *ObjDesc;
366 ACPI_OPERAND_OBJECT *HandlerObj;
368 ACPI_OBJECT_TYPE Type;
372 ACPI_FUNCTION_TRACE (EvInstallSpaceHandler);
376 * This registration is valid for only the types below and the root. This
377 * is where the default handlers get placed.
379 if ((Node->Type != ACPI_TYPE_DEVICE) &&
380 (Node->Type != ACPI_TYPE_PROCESSOR) &&
381 (Node->Type != ACPI_TYPE_THERMAL) &&
382 (Node != AcpiGbl_RootNode))
384 Status = AE_BAD_PARAMETER;
388 if (Handler == ACPI_DEFAULT_HANDLER)
390 Flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
394 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
396 Handler = AcpiExSystemMemorySpaceHandler;
397 Setup = AcpiEvSystemMemoryRegionSetup;
400 case ACPI_ADR_SPACE_SYSTEM_IO:
402 Handler = AcpiExSystemIoSpaceHandler;
403 Setup = AcpiEvIoSpaceRegionSetup;
406 case ACPI_ADR_SPACE_PCI_CONFIG:
408 Handler = AcpiExPciConfigSpaceHandler;
409 Setup = AcpiEvPciConfigRegionSetup;
412 case ACPI_ADR_SPACE_CMOS:
414 Handler = AcpiExCmosSpaceHandler;
415 Setup = AcpiEvCmosRegionSetup;
418 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
420 Handler = AcpiExPciBarSpaceHandler;
421 Setup = AcpiEvPciBarRegionSetup;
424 case ACPI_ADR_SPACE_DATA_TABLE:
426 Handler = AcpiExDataTableSpaceHandler;
432 Status = AE_BAD_PARAMETER;
437 /* If the caller hasn't specified a setup routine, use the default */
441 Setup = AcpiEvDefaultRegionSetup;
444 /* Check for an existing internal object */
446 ObjDesc = AcpiNsGetAttachedObject (Node);
450 * The attached device object already exists. Make sure the handler
451 * is not already installed.
453 HandlerObj = ObjDesc->Device.Handler;
455 /* Walk the handler list for this device */
459 /* Same SpaceId indicates a handler already installed */
461 if (HandlerObj->AddressSpace.SpaceId == SpaceId)
463 if (HandlerObj->AddressSpace.Handler == Handler)
466 * It is (relatively) OK to attempt to install the SAME
467 * handler twice. This can easily happen with the
470 Status = AE_SAME_HANDLER;
475 /* A handler is already installed */
477 Status = AE_ALREADY_EXISTS;
482 /* Walk the linked list of handlers */
484 HandlerObj = HandlerObj->AddressSpace.Next;
489 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
490 "Creating object on Device %p while installing handler\n", Node));
492 /* ObjDesc does not exist, create one */
494 if (Node->Type == ACPI_TYPE_ANY)
496 Type = ACPI_TYPE_DEVICE;
503 ObjDesc = AcpiUtCreateInternalObject (Type);
506 Status = AE_NO_MEMORY;
510 /* Init new descriptor */
512 ObjDesc->Common.Type = (UINT8) Type;
514 /* Attach the new object to the Node */
516 Status = AcpiNsAttachObject (Node, ObjDesc, Type);
518 /* Remove local reference to the object */
520 AcpiUtRemoveReference (ObjDesc);
522 if (ACPI_FAILURE (Status))
528 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
529 "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
530 AcpiUtGetRegionName (SpaceId), SpaceId,
531 AcpiUtGetNodeName (Node), Node, ObjDesc));
534 * Install the handler
536 * At this point there is no existing handler. Just allocate the object
537 * for the handler and link it into the list.
539 HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
542 Status = AE_NO_MEMORY;
546 /* Init handler obj */
548 HandlerObj->AddressSpace.SpaceId = (UINT8) SpaceId;
549 HandlerObj->AddressSpace.HandlerFlags = Flags;
550 HandlerObj->AddressSpace.RegionList = NULL;
551 HandlerObj->AddressSpace.Node = Node;
552 HandlerObj->AddressSpace.Handler = Handler;
553 HandlerObj->AddressSpace.Context = Context;
554 HandlerObj->AddressSpace.Setup = Setup;
556 /* Install at head of Device.AddressSpace list */
558 HandlerObj->AddressSpace.Next = ObjDesc->Device.Handler;
561 * The Device object is the first reference on the HandlerObj.
562 * Each region that uses the handler adds a reference.
564 ObjDesc->Device.Handler = HandlerObj;
567 * Walk the namespace finding all of the regions this
568 * handler will manage.
570 * Start at the device and search the branch toward
571 * the leaf nodes until either the leaf is encountered or
572 * a device is detected that has an address handler of the
575 * In either case, back up and search down the remainder
578 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
579 ACPI_NS_WALK_UNLOCK, AcpiEvInstallHandler, NULL,
583 return_ACPI_STATUS (Status);