1 /******************************************************************************
3 * Module Name: evhandler - Support for Address Space handlers
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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.
45 #define __EVHANDLER_C__
53 #define _COMPONENT ACPI_EVENTS
54 ACPI_MODULE_NAME ("evhandler")
57 /* Local prototypes */
60 AcpiEvInstallHandler (
61 ACPI_HANDLE ObjHandle
,
66 /* These are the address spaces that will get default handlers */
68 UINT8 AcpiGbl_DefaultAddressSpaces
[ACPI_NUM_DEFAULT_SPACES
] =
70 ACPI_ADR_SPACE_SYSTEM_MEMORY
,
71 ACPI_ADR_SPACE_SYSTEM_IO
,
72 ACPI_ADR_SPACE_PCI_CONFIG
,
73 ACPI_ADR_SPACE_DATA_TABLE
77 /*******************************************************************************
79 * FUNCTION: AcpiEvInstallRegionHandlers
85 * DESCRIPTION: Installs the core subsystem default address space handlers.
87 ******************************************************************************/
90 AcpiEvInstallRegionHandlers (
97 ACPI_FUNCTION_TRACE (EvInstallRegionHandlers
);
100 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
101 if (ACPI_FAILURE (Status
))
103 return_ACPI_STATUS (Status
);
107 * All address spaces (PCI Config, EC, SMBus) are scope dependent and
108 * registration must occur for a specific device.
110 * In the case of the system memory and IO address spaces there is
111 * currently no device associated with the address space. For these we
114 * We install the default PCI config space handler at the root so that
115 * this space is immediately available even though the we have not
116 * enumerated all the PCI Root Buses yet. This is to conform to the ACPI
117 * specification which states that the PCI config space must be always
118 * available -- even though we are nowhere near ready to find the PCI root
119 * buses at this point.
121 * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
122 * has already been installed (via AcpiInstallAddressSpaceHandler).
123 * Similar for AE_SAME_HANDLER.
125 for (i
= 0; i
< ACPI_NUM_DEFAULT_SPACES
; i
++)
127 Status
= AcpiEvInstallSpaceHandler (AcpiGbl_RootNode
,
128 AcpiGbl_DefaultAddressSpaces
[i
],
129 ACPI_DEFAULT_HANDLER
, NULL
, NULL
);
133 case AE_SAME_HANDLER
:
134 case AE_ALREADY_EXISTS
:
136 /* These exceptions are all OK */
148 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
149 return_ACPI_STATUS (Status
);
153 /*******************************************************************************
155 * FUNCTION: AcpiEvHasDefaultHandler
157 * PARAMETERS: Node - Namespace node for the device
158 * SpaceId - The address space ID
160 * RETURN: TRUE if default handler is installed, FALSE otherwise
162 * DESCRIPTION: Check if the default handler is installed for the requested
165 ******************************************************************************/
168 AcpiEvHasDefaultHandler (
169 ACPI_NAMESPACE_NODE
*Node
,
170 ACPI_ADR_SPACE_TYPE SpaceId
)
172 ACPI_OPERAND_OBJECT
*ObjDesc
;
173 ACPI_OPERAND_OBJECT
*HandlerObj
;
176 /* Must have an existing internal object */
178 ObjDesc
= AcpiNsGetAttachedObject (Node
);
181 HandlerObj
= ObjDesc
->Device
.Handler
;
183 /* Walk the linked list of handlers for this object */
187 if (HandlerObj
->AddressSpace
.SpaceId
== SpaceId
)
189 if (HandlerObj
->AddressSpace
.HandlerFlags
&
190 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED
)
196 HandlerObj
= HandlerObj
->AddressSpace
.Next
;
204 /*******************************************************************************
206 * FUNCTION: AcpiEvInstallHandler
208 * PARAMETERS: WalkNamespace callback
210 * DESCRIPTION: This routine installs an address handler into objects that are
211 * of type Region or Device.
213 * If the Object is a Device, and the device has a handler of
214 * the same type then the search is terminated in that branch.
216 * This is because the existing handler is closer in proximity
217 * to any more regions than the one we are trying to install.
219 ******************************************************************************/
222 AcpiEvInstallHandler (
223 ACPI_HANDLE ObjHandle
,
228 ACPI_OPERAND_OBJECT
*HandlerObj
;
229 ACPI_OPERAND_OBJECT
*NextHandlerObj
;
230 ACPI_OPERAND_OBJECT
*ObjDesc
;
231 ACPI_NAMESPACE_NODE
*Node
;
235 ACPI_FUNCTION_NAME (EvInstallHandler
);
238 HandlerObj
= (ACPI_OPERAND_OBJECT
*) Context
;
240 /* Parameter validation */
247 /* Convert and validate the device handle */
249 Node
= AcpiNsValidateHandle (ObjHandle
);
252 return (AE_BAD_PARAMETER
);
256 * We only care about regions and objects that are allowed to have
257 * address space handlers
259 if ((Node
->Type
!= ACPI_TYPE_DEVICE
) &&
260 (Node
->Type
!= ACPI_TYPE_REGION
) &&
261 (Node
!= AcpiGbl_RootNode
))
266 /* Check for an existing internal object */
268 ObjDesc
= AcpiNsGetAttachedObject (Node
);
271 /* No object, just exit */
276 /* Devices are handled different than regions */
278 if (ObjDesc
->Common
.Type
== ACPI_TYPE_DEVICE
)
280 /* Check if this Device already has a handler for this address space */
282 NextHandlerObj
= ObjDesc
->Device
.Handler
;
283 while (NextHandlerObj
)
285 /* Found a handler, is it for the same address space? */
287 if (NextHandlerObj
->AddressSpace
.SpaceId
==
288 HandlerObj
->AddressSpace
.SpaceId
)
290 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
291 "Found handler for region [%s] in device %p(%p) "
293 AcpiUtGetRegionName (HandlerObj
->AddressSpace
.SpaceId
),
294 ObjDesc
, NextHandlerObj
, HandlerObj
));
297 * Since the object we found it on was a device, then it
298 * means that someone has already installed a handler for
299 * the branch of the namespace from this device on. Just
300 * bail out telling the walk routine to not traverse this
301 * branch. This preserves the scoping rule for handlers.
303 return (AE_CTRL_DEPTH
);
306 /* Walk the linked list of handlers attached to this device */
308 NextHandlerObj
= NextHandlerObj
->AddressSpace
.Next
;
312 * As long as the device didn't have a handler for this space we
313 * don't care about it. We just ignore it and proceed.
318 /* Object is a Region */
320 if (ObjDesc
->Region
.SpaceId
!= HandlerObj
->AddressSpace
.SpaceId
)
322 /* This region is for a different address space, just ignore it */
328 * Now we have a region and it is for the handler's address space type.
330 * First disconnect region for any previous handler (if any)
332 AcpiEvDetachRegion (ObjDesc
, FALSE
);
334 /* Connect the region to the new handler */
336 Status
= AcpiEvAttachRegion (HandlerObj
, ObjDesc
, FALSE
);
341 /*******************************************************************************
343 * FUNCTION: AcpiEvInstallSpaceHandler
345 * PARAMETERS: Node - Namespace node for the device
346 * SpaceId - The address space ID
347 * Handler - Address of the handler
348 * Setup - Address of the setup function
349 * Context - Value passed to the handler on each access
353 * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
354 * Assumes namespace is locked
356 ******************************************************************************/
359 AcpiEvInstallSpaceHandler (
360 ACPI_NAMESPACE_NODE
*Node
,
361 ACPI_ADR_SPACE_TYPE SpaceId
,
362 ACPI_ADR_SPACE_HANDLER Handler
,
363 ACPI_ADR_SPACE_SETUP Setup
,
366 ACPI_OPERAND_OBJECT
*ObjDesc
;
367 ACPI_OPERAND_OBJECT
*HandlerObj
;
369 ACPI_OBJECT_TYPE Type
;
373 ACPI_FUNCTION_TRACE (EvInstallSpaceHandler
);
377 * This registration is valid for only the types below and the root. This
378 * is where the default handlers get placed.
380 if ((Node
->Type
!= ACPI_TYPE_DEVICE
) &&
381 (Node
->Type
!= ACPI_TYPE_PROCESSOR
) &&
382 (Node
->Type
!= ACPI_TYPE_THERMAL
) &&
383 (Node
!= AcpiGbl_RootNode
))
385 Status
= AE_BAD_PARAMETER
;
389 if (Handler
== ACPI_DEFAULT_HANDLER
)
391 Flags
= ACPI_ADDR_HANDLER_DEFAULT_INSTALLED
;
395 case ACPI_ADR_SPACE_SYSTEM_MEMORY
:
397 Handler
= AcpiExSystemMemorySpaceHandler
;
398 Setup
= AcpiEvSystemMemoryRegionSetup
;
401 case ACPI_ADR_SPACE_SYSTEM_IO
:
403 Handler
= AcpiExSystemIoSpaceHandler
;
404 Setup
= AcpiEvIoSpaceRegionSetup
;
407 case ACPI_ADR_SPACE_PCI_CONFIG
:
409 Handler
= AcpiExPciConfigSpaceHandler
;
410 Setup
= AcpiEvPciConfigRegionSetup
;
413 case ACPI_ADR_SPACE_CMOS
:
415 Handler
= AcpiExCmosSpaceHandler
;
416 Setup
= AcpiEvCmosRegionSetup
;
419 case ACPI_ADR_SPACE_PCI_BAR_TARGET
:
421 Handler
= AcpiExPciBarSpaceHandler
;
422 Setup
= AcpiEvPciBarRegionSetup
;
425 case ACPI_ADR_SPACE_DATA_TABLE
:
427 Handler
= AcpiExDataTableSpaceHandler
;
433 Status
= AE_BAD_PARAMETER
;
438 /* If the caller hasn't specified a setup routine, use the default */
442 Setup
= AcpiEvDefaultRegionSetup
;
445 /* Check for an existing internal object */
447 ObjDesc
= AcpiNsGetAttachedObject (Node
);
451 * The attached device object already exists. Make sure the handler
452 * is not already installed.
454 HandlerObj
= ObjDesc
->Device
.Handler
;
456 /* Walk the handler list for this device */
460 /* Same SpaceId indicates a handler already installed */
462 if (HandlerObj
->AddressSpace
.SpaceId
== SpaceId
)
464 if (HandlerObj
->AddressSpace
.Handler
== Handler
)
467 * It is (relatively) OK to attempt to install the SAME
468 * handler twice. This can easily happen with the
471 Status
= AE_SAME_HANDLER
;
476 /* A handler is already installed */
478 Status
= AE_ALREADY_EXISTS
;
483 /* Walk the linked list of handlers */
485 HandlerObj
= HandlerObj
->AddressSpace
.Next
;
490 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
491 "Creating object on Device %p while installing handler\n", Node
));
493 /* ObjDesc does not exist, create one */
495 if (Node
->Type
== ACPI_TYPE_ANY
)
497 Type
= ACPI_TYPE_DEVICE
;
504 ObjDesc
= AcpiUtCreateInternalObject (Type
);
507 Status
= AE_NO_MEMORY
;
511 /* Init new descriptor */
513 ObjDesc
->Common
.Type
= (UINT8
) Type
;
515 /* Attach the new object to the Node */
517 Status
= AcpiNsAttachObject (Node
, ObjDesc
, Type
);
519 /* Remove local reference to the object */
521 AcpiUtRemoveReference (ObjDesc
);
523 if (ACPI_FAILURE (Status
))
529 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
530 "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
531 AcpiUtGetRegionName (SpaceId
), SpaceId
,
532 AcpiUtGetNodeName (Node
), Node
, ObjDesc
));
535 * Install the handler
537 * At this point there is no existing handler. Just allocate the object
538 * for the handler and link it into the list.
540 HandlerObj
= AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_ADDRESS_HANDLER
);
543 Status
= AE_NO_MEMORY
;
547 /* Init handler obj */
549 HandlerObj
->AddressSpace
.SpaceId
= (UINT8
) SpaceId
;
550 HandlerObj
->AddressSpace
.HandlerFlags
= Flags
;
551 HandlerObj
->AddressSpace
.RegionList
= NULL
;
552 HandlerObj
->AddressSpace
.Node
= Node
;
553 HandlerObj
->AddressSpace
.Handler
= Handler
;
554 HandlerObj
->AddressSpace
.Context
= Context
;
555 HandlerObj
->AddressSpace
.Setup
= Setup
;
557 /* Install at head of Device.AddressSpace list */
559 HandlerObj
->AddressSpace
.Next
= ObjDesc
->Device
.Handler
;
562 * The Device object is the first reference on the HandlerObj.
563 * Each region that uses the handler adds a reference.
565 ObjDesc
->Device
.Handler
= HandlerObj
;
568 * Walk the namespace finding all of the regions this
569 * handler will manage.
571 * Start at the device and search the branch toward
572 * the leaf nodes until either the leaf is encountered or
573 * a device is detected that has an address handler of the
576 * In either case, back up and search down the remainder
579 Status
= AcpiNsWalkNamespace (ACPI_TYPE_ANY
, Node
, ACPI_UINT32_MAX
,
580 ACPI_NS_WALK_UNLOCK
, AcpiEvInstallHandler
, NULL
,
584 return_ACPI_STATUS (Status
);