ACPI_STATUS AcpiEvInitializeRegion ( ACPI_OPERAND_OBJECT *RegionObj, BOOLEAN AcpiNsLocked) { ACPI_OPERAND_OBJECT *HandlerObj; ACPI_OPERAND_OBJECT *ObjDesc; ACPI_ADR_SPACE_TYPE SpaceId; ACPI_NAMESPACE_NODE *Node; ACPI_STATUS Status; ACPI_FUNCTION_TRACE_U32 (EvInitializeRegion, AcpiNsLocked); if (!RegionObj) { return_ACPI_STATUS (AE_BAD_PARAMETER); } if (RegionObj->Common.Flags & AOPOBJ_OBJECT_INITIALIZED) { return_ACPI_STATUS (AE_OK); } RegionObj->Common.Flags |= AOPOBJ_OBJECT_INITIALIZED; Node = RegionObj->Region.Node->Parent; SpaceId = RegionObj->Region.SpaceId; /* * The following loop depends upon the root Node having no parent * ie: AcpiGbl_RootNode->Parent being set to NULL */ while (Node) { /* Check to see if a handler exists */ HandlerObj = NULL; ObjDesc = AcpiNsGetAttachedObject (Node); if (ObjDesc) { /* Can only be a handler if the object exists */ switch (Node->Type) { case ACPI_TYPE_DEVICE: case ACPI_TYPE_PROCESSOR: case ACPI_TYPE_THERMAL: HandlerObj = ObjDesc->CommonNotify.Handler; break; case ACPI_TYPE_METHOD: /* * If we are executing module level code, the original * Node's object was replaced by this Method object and we * saved the handler in the method object. * * See AcpiNsExecModuleCode */ if (ObjDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL) { HandlerObj = ObjDesc->Method.Dispatch.Handler; } break; default: /* Ignore other objects */ break; } HandlerObj = AcpiEvFindRegionHandler (SpaceId, HandlerObj); if (HandlerObj) { /* Found correct handler */ ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, "Found handler %p for region %p in obj %p\n", HandlerObj, RegionObj, ObjDesc)); Status = AcpiEvAttachRegion (HandlerObj, RegionObj, AcpiNsLocked); /* * Tell all users that this region is usable by * running the _REG method */ if (AcpiNsLocked) { Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } } Status = AcpiEvExecuteRegMethod (RegionObj, ACPI_REG_CONNECT); if (AcpiNsLocked) { Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } } return_ACPI_STATUS (AE_OK); } } /* This node does not have the handler we need; Pop up one level */ Node = Node->Parent; } /* If we get here, there is no handler for this region */ ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, "No handler for RegionType %s(%X) (RegionObj %p)\n", AcpiUtGetRegionName (SpaceId), SpaceId, RegionObj)); return_ACPI_STATUS (AE_NOT_EXIST); }
static ACPI_STATUS AcpiEvInstallHandler ( ACPI_HANDLE ObjHandle, UINT32 Level, void *Context, void **ReturnValue) { ACPI_OPERAND_OBJECT *HandlerObj; ACPI_OPERAND_OBJECT *NextHandlerObj; ACPI_OPERAND_OBJECT *ObjDesc; ACPI_NAMESPACE_NODE *Node; ACPI_STATUS Status; ACPI_FUNCTION_NAME (EvInstallHandler); HandlerObj = (ACPI_OPERAND_OBJECT *) Context; /* Parameter validation */ if (!HandlerObj) { return (AE_OK); } /* Convert and validate the device handle */ Node = AcpiNsValidateHandle (ObjHandle); if (!Node) { return (AE_BAD_PARAMETER); } /* * We only care about regions and objects that are allowed to have * address space handlers */ if ((Node->Type != ACPI_TYPE_DEVICE) && (Node->Type != ACPI_TYPE_REGION) && (Node != AcpiGbl_RootNode)) { return (AE_OK); } /* Check for an existing internal object */ ObjDesc = AcpiNsGetAttachedObject (Node); if (!ObjDesc) { /* No object, just exit */ return (AE_OK); } /* Devices are handled different than regions */ if (ObjDesc->Common.Type == ACPI_TYPE_DEVICE) { /* Check if this Device already has a handler for this address space */ NextHandlerObj = AcpiEvFindRegionHandler ( HandlerObj->AddressSpace.SpaceId, ObjDesc->CommonNotify.Handler); if (NextHandlerObj) { /* Found a handler, is it for the same address space? */ ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, "Found handler for region [%s] in device %p(%p) handler %p\n", AcpiUtGetRegionName (HandlerObj->AddressSpace.SpaceId), ObjDesc, NextHandlerObj, HandlerObj)); /* * Since the object we found it on was a device, then it means * that someone has already installed a handler for the branch * of the namespace from this device on. Just bail out telling * the walk routine to not traverse this branch. This preserves * the scoping rule for handlers. */ return (AE_CTRL_DEPTH); } /* * As long as the device didn't have a handler for this space we * don't care about it. We just ignore it and proceed. */ return (AE_OK); } /* Object is a Region */ if (ObjDesc->Region.SpaceId != HandlerObj->AddressSpace.SpaceId) { /* This region is for a different address space, just ignore it */ return (AE_OK); } /* * Now we have a region and it is for the handler's address space type. * * First disconnect region for any previous handler (if any) */ AcpiEvDetachRegion (ObjDesc, FALSE); /* Connect the region to the new handler */ Status = AcpiEvAttachRegion (HandlerObj, ObjDesc, FALSE); return (Status); }
ACPI_STATUS AcpiEvInstallSpaceHandler ( ACPI_NAMESPACE_NODE *Node, ACPI_ADR_SPACE_TYPE SpaceId, ACPI_ADR_SPACE_HANDLER Handler, ACPI_ADR_SPACE_SETUP Setup, void *Context) { ACPI_OPERAND_OBJECT *ObjDesc; ACPI_OPERAND_OBJECT *HandlerObj; ACPI_STATUS Status = AE_OK; ACPI_OBJECT_TYPE Type; UINT8 Flags = 0; ACPI_FUNCTION_TRACE (EvInstallSpaceHandler); /* * This registration is valid for only the types below and the root. * The root node is where the default handlers get installed. */ if ((Node->Type != ACPI_TYPE_DEVICE) && (Node->Type != ACPI_TYPE_PROCESSOR) && (Node->Type != ACPI_TYPE_THERMAL) && (Node != AcpiGbl_RootNode)) { Status = AE_BAD_PARAMETER; goto UnlockAndExit; } if (Handler == ACPI_DEFAULT_HANDLER) { Flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED; switch (SpaceId) { case ACPI_ADR_SPACE_SYSTEM_MEMORY: Handler = AcpiExSystemMemorySpaceHandler; Setup = AcpiEvSystemMemoryRegionSetup; break; case ACPI_ADR_SPACE_SYSTEM_IO: Handler = AcpiExSystemIoSpaceHandler; Setup = AcpiEvIoSpaceRegionSetup; break; case ACPI_ADR_SPACE_PCI_CONFIG: Handler = AcpiExPciConfigSpaceHandler; Setup = AcpiEvPciConfigRegionSetup; break; case ACPI_ADR_SPACE_CMOS: Handler = AcpiExCmosSpaceHandler; Setup = AcpiEvCmosRegionSetup; break; case ACPI_ADR_SPACE_PCI_BAR_TARGET: Handler = AcpiExPciBarSpaceHandler; Setup = AcpiEvPciBarRegionSetup; break; case ACPI_ADR_SPACE_DATA_TABLE: Handler = AcpiExDataTableSpaceHandler; Setup = NULL; break; default: Status = AE_BAD_PARAMETER; goto UnlockAndExit; } } /* If the caller hasn't specified a setup routine, use the default */ if (!Setup) { Setup = AcpiEvDefaultRegionSetup; } /* Check for an existing internal object */ ObjDesc = AcpiNsGetAttachedObject (Node); if (ObjDesc) { /* * The attached device object already exists. Now make sure * the handler is not already installed. */ HandlerObj = AcpiEvFindRegionHandler (SpaceId, ObjDesc->CommonNotify.Handler); if (HandlerObj) { if (HandlerObj->AddressSpace.Handler == Handler) { /* * It is (relatively) OK to attempt to install the SAME * handler twice. This can easily happen with the * PCI_Config space. */ Status = AE_SAME_HANDLER; goto UnlockAndExit; } else { /* A handler is already installed */ Status = AE_ALREADY_EXISTS; } goto UnlockAndExit; } } else { ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, "Creating object on Device %p while installing handler\n", Node)); /* ObjDesc does not exist, create one */ if (Node->Type == ACPI_TYPE_ANY) { Type = ACPI_TYPE_DEVICE; } else { Type = Node->Type; } ObjDesc = AcpiUtCreateInternalObject (Type); if (!ObjDesc) { Status = AE_NO_MEMORY; goto UnlockAndExit; } /* Init new descriptor */ ObjDesc->Common.Type = (UINT8) Type; /* Attach the new object to the Node */ Status = AcpiNsAttachObject (Node, ObjDesc, Type); /* Remove local reference to the object */ AcpiUtRemoveReference (ObjDesc); if (ACPI_FAILURE (Status)) { goto UnlockAndExit; } } ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, "Installing address handler for region %s(%X) " "on Device %4.4s %p(%p)\n", AcpiUtGetRegionName (SpaceId), SpaceId, AcpiUtGetNodeName (Node), Node, ObjDesc)); /* * Install the handler * * At this point there is no existing handler. Just allocate the object * for the handler and link it into the list. */ HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_ADDRESS_HANDLER); if (!HandlerObj) { Status = AE_NO_MEMORY; goto UnlockAndExit; } /* Init handler obj */ HandlerObj->AddressSpace.SpaceId = (UINT8) SpaceId; HandlerObj->AddressSpace.HandlerFlags = Flags; HandlerObj->AddressSpace.RegionList = NULL; HandlerObj->AddressSpace.Node = Node; HandlerObj->AddressSpace.Handler = Handler; HandlerObj->AddressSpace.Context = Context; HandlerObj->AddressSpace.Setup = Setup; /* Install at head of Device.AddressSpace list */ HandlerObj->AddressSpace.Next = ObjDesc->CommonNotify.Handler; /* * The Device object is the first reference on the HandlerObj. * Each region that uses the handler adds a reference. */ ObjDesc->CommonNotify.Handler = HandlerObj; /* * Walk the namespace finding all of the regions this handler will * manage. * * Start at the device and search the branch toward the leaf nodes * until either the leaf is encountered or a device is detected that * has an address handler of the same type. * * In either case, back up and search down the remainder of the branch */ Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, AcpiEvInstallHandler, NULL, HandlerObj, NULL); UnlockAndExit: return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiEvInitializeRegion ( ACPI_OPERAND_OBJECT *RegionObj) { ACPI_OPERAND_OBJECT *HandlerObj; ACPI_OPERAND_OBJECT *ObjDesc; ACPI_ADR_SPACE_TYPE SpaceId; ACPI_NAMESPACE_NODE *Node; ACPI_FUNCTION_TRACE (EvInitializeRegion); if (!RegionObj) { return_ACPI_STATUS (AE_BAD_PARAMETER); } if (RegionObj->Common.Flags & AOPOBJ_OBJECT_INITIALIZED) { return_ACPI_STATUS (AE_OK); } RegionObj->Common.Flags |= AOPOBJ_OBJECT_INITIALIZED; Node = RegionObj->Region.Node->Parent; SpaceId = RegionObj->Region.SpaceId; /* * The following loop depends upon the root Node having no parent * ie: AcpiGbl_RootNode->Parent being set to NULL */ while (Node) { /* Check to see if a handler exists */ HandlerObj = NULL; ObjDesc = AcpiNsGetAttachedObject (Node); if (ObjDesc) { /* Can only be a handler if the object exists */ switch (Node->Type) { case ACPI_TYPE_DEVICE: case ACPI_TYPE_PROCESSOR: case ACPI_TYPE_THERMAL: HandlerObj = ObjDesc->CommonNotify.Handler; break; case ACPI_TYPE_METHOD: /* * If we are executing module level code, the original * Node's object was replaced by this Method object and we * saved the handler in the method object. * * Note: Only used for the legacy MLC support. Will * be removed in the future. * * See AcpiNsExecModuleCode */ if (!AcpiGbl_ExecuteTablesAsMethods && ObjDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL) { HandlerObj = ObjDesc->Method.Dispatch.Handler; } break; default: /* Ignore other objects */ break; } HandlerObj = AcpiEvFindRegionHandler (SpaceId, HandlerObj); if (HandlerObj) { /* Found correct handler */ ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, "Found handler %p for region %p in obj %p\n", HandlerObj, RegionObj, ObjDesc)); (void) AcpiEvAttachRegion (HandlerObj, RegionObj, FALSE); /* * Tell all users that this region is usable by * running the _REG method */ AcpiExExitInterpreter (); (void) AcpiEvExecuteRegMethod (RegionObj, ACPI_REG_CONNECT); AcpiExEnterInterpreter (); return_ACPI_STATUS (AE_OK); } } /* This node does not have the handler we need; Pop up one level */ Node = Node->Parent; } /* * If we get here, there is no handler for this region. This is not * fatal because many regions get created before a handler is installed * for said region. */ ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, "No handler for RegionType %s(%X) (RegionObj %p)\n", AcpiUtGetRegionName (SpaceId), SpaceId, RegionObj)); return_ACPI_STATUS (AE_OK); }