static void pciehpc_acpi_uninstall_event_handler(pcie_hp_ctrl_t *ctrl_p) { pciehpc_acpi_t *acpi_p = ctrl_p->hc_misc_data; pcie_hp_slot_t *slot_p = ctrl_p->hc_slots[0]; PCIE_DBG("Uninstall event handler for slot #%d\n", slot_p->hs_phy_slot_num); (void) AcpiRemoveNotifyHandler(acpi_p->slot_dev_obj, ACPI_SYSTEM_NOTIFY, pciehpc_acpi_notify_handler); (void) AcpiRemoveNotifyHandler(acpi_p->bus_obj, ACPI_SYSTEM_NOTIFY, pciehpc_acpi_notify_handler); }
status_t remove_notify_handler(acpi_handle device, uint32 handlerType, acpi_notify_handler handler) { return AcpiRemoveNotifyHandler(device, handlerType, (ACPI_NOTIFY_HANDLER)handler) == AE_OK ? B_OK : B_ERROR; }
/* * Uninstall event handler for ACPI system events. * Return DDI_SUCCESS on success, and DDI_FAILURE on failure. */ static int acpinex_event_uninstall_handler(ACPI_HANDLE hdl, ACPI_DEVICE_INFO *infop, acpidev_data_handle_t dhdl) { ASSERT(hdl != NULL); ASSERT(dhdl != NULL); ASSERT(infop != NULL); if (!acpidev_data_get_flag(dhdl, ACPIDEV_DATA_HANDLER_READY)) { return (DDI_SUCCESS); } if (ACPI_SUCCESS(AcpiRemoveNotifyHandler(hdl, ACPI_SYSTEM_NOTIFY, acpinex_event_system_handler))) { acpidev_data_clear_flag(dhdl, ACPIDEV_DATA_HANDLER_READY); } else { char *objname; objname = acpidev_get_object_name(hdl); cmn_err(CE_WARN, "!acpinex: failed to uninstall system event " "handler for %s.", objname); acpidev_free_object_name(objname); return (DDI_FAILURE); } return (DDI_SUCCESS); }
static int acpi_cmbat_detach(device_t dev) { ACPI_HANDLE handle; handle = acpi_get_handle(dev); AcpiRemoveNotifyHandler(handle, ACPI_ALL_NOTIFY, acpi_cmbat_notify_handler); acpi_battery_remove(dev); return (0); }
static int acpi_fujitsu_detach(device_t dev) { struct acpi_fujitsu_softc *sc; sc = device_get_softc(dev); AcpiRemoveNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY, acpi_fujitsu_notify_handler); sysctl_ctx_free(&sc->sysctl_ctx); return (0); }
static int acpi_panasonic_detach(device_t dev) { struct acpi_panasonic_softc *sc; sc = device_get_softc(dev); /* Remove power profile event handler */ EVENTHANDLER_DEREGISTER(power_profile_change, sc->power_evh); /* Remove notify handler */ AcpiRemoveNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY, acpi_panasonic_notify); /* Free sysctl tree */ sysctl_ctx_free(&sc->sysctl_ctx); return (0); }
/* * Install event handler for the hot plug events on the bus node as well * as device function (dev=0,func=0). */ static ACPI_STATUS pciehpc_acpi_install_event_handler(pcie_hp_ctrl_t *ctrl_p) { pcie_hp_slot_t *slot_p = ctrl_p->hc_slots[0]; int status = AE_OK; pciehpc_acpi_t *acpi_p; PCIE_DBG("install event handler for slot %d\n", slot_p->hs_phy_slot_num); acpi_p = ctrl_p->hc_misc_data; if (acpi_p->slot_dev_obj == NULL) return (AE_NOT_FOUND); /* * Install event hanlder for events on the bus object. * (Note: Insert event (hot-insert) is delivered on this object) */ status = AcpiInstallNotifyHandler(acpi_p->slot_dev_obj, ACPI_SYSTEM_NOTIFY, pciehpc_acpi_notify_handler, (void *)ctrl_p); if (status != AE_OK) goto cleanup; /* * Install event hanlder for events on the device function object. * (Note: Eject device event (hot-remove) is delivered on this object) * * NOTE: Here the assumption is that Notify events are delivered * on all of the 8 possible device functions so, subscribing to * one of them is sufficient. */ status = AcpiInstallNotifyHandler(acpi_p->bus_obj, ACPI_SYSTEM_NOTIFY, pciehpc_acpi_notify_handler, (void *)ctrl_p); return (status); cleanup: (void) AcpiRemoveNotifyHandler(acpi_p->slot_dev_obj, ACPI_SYSTEM_NOTIFY, pciehpc_acpi_notify_handler); return (status); }
ACPI_STATUS AeInstallEarlyHandlers ( void) { ACPI_STATUS Status; UINT32 i; ACPI_HANDLE Handle; ACPI_FUNCTION_ENTRY (); Status = AcpiInstallInterfaceHandler (AeInterfaceHandler); if (ACPI_FAILURE (Status)) { printf ("Could not install interface handler, %s\n", AcpiFormatException (Status)); } Status = AcpiInstallTableHandler (AeTableHandler, NULL); if (ACPI_FAILURE (Status)) { printf ("Could not install table handler, %s\n", AcpiFormatException (Status)); } Status = AcpiInstallExceptionHandler (AeExceptionHandler); if (ACPI_FAILURE (Status)) { printf ("Could not install exception handler, %s\n", AcpiFormatException (Status)); } /* Install global notify handlers */ Status = AcpiInstallNotifyHandler (ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY, AeSystemNotifyHandler, NULL); if (ACPI_FAILURE (Status)) { printf ("Could not install a global system notify handler, %s\n", AcpiFormatException (Status)); } Status = AcpiInstallNotifyHandler (ACPI_ROOT_OBJECT, ACPI_DEVICE_NOTIFY, AeDeviceNotifyHandler, NULL); if (ACPI_FAILURE (Status)) { printf ("Could not install a global notify handler, %s\n", AcpiFormatException (Status)); } Status = AcpiGetHandle (NULL, "\\_SB", &Handle); if (ACPI_SUCCESS (Status)) { Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY, AeNotifyHandler1, NULL); if (ACPI_FAILURE (Status)) { printf ("Could not install a notify handler, %s\n", AcpiFormatException (Status)); } Status = AcpiRemoveNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY, AeNotifyHandler1); if (ACPI_FAILURE (Status)) { printf ("Could not remove a notify handler, %s\n", AcpiFormatException (Status)); } Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY, AeNotifyHandler1, NULL); AE_CHECK_OK (AcpiInstallNotifyHandler, Status); Status = AcpiRemoveNotifyHandler (Handle, ACPI_ALL_NOTIFY, AeNotifyHandler1); AE_CHECK_OK (AcpiRemoveNotifyHandler, Status); #if 0 Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY, AeNotifyHandler1, NULL); if (ACPI_FAILURE (Status)) { printf ("Could not install a notify handler, %s\n", AcpiFormatException (Status)); } #endif /* Install two handlers for _SB_ */ Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY, AeNotifyHandler1, ACPI_CAST_PTR (void, 0x01234567)); Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY, AeNotifyHandler2, ACPI_CAST_PTR (void, 0x89ABCDEF)); /* Attempt duplicate handler installation, should fail */ Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY, AeNotifyHandler1, ACPI_CAST_PTR (void, 0x77777777)); Status = AcpiAttachData (Handle, AeAttachedDataHandler, Handle); AE_CHECK_OK (AcpiAttachData, Status); Status = AcpiDetachData (Handle, AeAttachedDataHandler); AE_CHECK_OK (AcpiDetachData, Status); /* Test attach data at the root object */ Status = AcpiAttachData (ACPI_ROOT_OBJECT, AeAttachedDataHandler, AcpiGbl_RootNode); AE_CHECK_OK (AcpiAttachData, Status); Status = AcpiAttachData (ACPI_ROOT_OBJECT, AeAttachedDataHandler2, AcpiGbl_RootNode); AE_CHECK_OK (AcpiAttachData, Status); /* Test support for multiple attaches */ Status = AcpiAttachData (Handle, AeAttachedDataHandler, Handle); AE_CHECK_OK (AcpiAttachData, Status); Status = AcpiAttachData (Handle, AeAttachedDataHandler2, Handle); AE_CHECK_OK (AcpiAttachData, Status); } else {
ACPI_STATUS AeInstallLateHandlers ( void) { ACPI_STATUS Status; ACPI_HANDLE Handle; Status = AcpiGetHandle (NULL, "\\_TZ.TZ1", &Handle); if (ACPI_SUCCESS (Status)) { Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY, AeNotifyHandler1, ACPI_CAST_PTR (void, 0x01234567)); Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY, AeNotifyHandler2, ACPI_CAST_PTR (void, 0x89ABCDEF)); Status = AcpiRemoveNotifyHandler (Handle, ACPI_ALL_NOTIFY, AeNotifyHandler1); Status = AcpiRemoveNotifyHandler (Handle, ACPI_ALL_NOTIFY, AeNotifyHandler2); Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY, AeNotifyHandler2, ACPI_CAST_PTR (void, 0x89ABCDEF)); Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY, AeNotifyHandler1, ACPI_CAST_PTR (void, 0x01234567)); } Status = AcpiGetHandle (NULL, "\\_PR.CPU0", &Handle); if (ACPI_SUCCESS (Status)) { Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY, AeNotifyHandler1, ACPI_CAST_PTR (void, 0x01234567)); Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY, AeNotifyHandler2, ACPI_CAST_PTR (void, 0x89ABCDEF)); } #if (!ACPI_REDUCED_HARDWARE) if (!AcpiGbl_ReducedHardware) { /* Install a user SCI handler */ Status = AeInstallSciHandler (); ACPI_CHECK_OK (AeInstallSciHandler, Status); /* Install some fixed event handlers */ Status = AcpiInstallFixedEventHandler ( ACPI_EVENT_GLOBAL, AeEventHandler, NULL); ACPI_CHECK_OK (AcpiInstallFixedEventHandler, Status); Status = AcpiInstallFixedEventHandler ( ACPI_EVENT_RTC, AeEventHandler, NULL); ACPI_CHECK_OK (AcpiInstallFixedEventHandler, Status); } #endif /* !ACPI_REDUCED_HARDWARE */ AeMyContext.Connection = NULL; AeMyContext.AccessLength = 0xA5; /* * We will install a handler for each EC device, directly under the EC * device definition. This is unlike the other handlers which we install * at the root node. Also install memory and I/O handlers at any PCI * devices. */ AeInstallDeviceHandlers (); /* * Install handlers for some of the "device driver" address spaces * such as SMBus, etc. */ AeInstallRegionHandlers (); return (AE_OK); }
static int acpi_tz_attach(device_t dev) { struct acpi_tz_softc *sc; struct acpi_softc *acpi_sc; int error; char oidname[8]; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); sc = device_get_softc(dev); sc->tz_dev = dev; sc->tz_handle = acpi_get_handle(dev); sc->tz_requested = TZ_ACTIVE_NONE; sc->tz_active = TZ_ACTIVE_UNKNOWN; sc->tz_thflags = TZ_THFLAG_NONE; sc->tz_cooling_proc = NULL; sc->tz_cooling_proc_running = FALSE; sc->tz_cooling_active = FALSE; sc->tz_cooling_updated = FALSE; sc->tz_cooling_enabled = FALSE; /* * Parse the current state of the thermal zone and build control * structures. We don't need to worry about interference with the * control thread since we haven't fully attached this device yet. */ if ((error = acpi_tz_establish(sc)) != 0) return (error); /* * Register for any Notify events sent to this zone. */ AcpiInstallNotifyHandler(sc->tz_handle, ACPI_DEVICE_NOTIFY, acpi_tz_notify_handler, sc); /* * Create our sysctl nodes. * * XXX we need a mechanism for adding nodes under ACPI. */ if (device_get_unit(dev) == 0) { acpi_sc = acpi_device_get_parent_softc(dev); sysctl_ctx_init(&acpi_tz_sysctl_ctx); acpi_tz_sysctl_tree = SYSCTL_ADD_NODE(&acpi_tz_sysctl_ctx, SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree), OID_AUTO, "thermal", CTLFLAG_RD, 0, ""); SYSCTL_ADD_INT(&acpi_tz_sysctl_ctx, SYSCTL_CHILDREN(acpi_tz_sysctl_tree), OID_AUTO, "min_runtime", CTLFLAG_RW, &acpi_tz_min_runtime, 0, "minimum cooling run time in sec"); SYSCTL_ADD_INT(&acpi_tz_sysctl_ctx, SYSCTL_CHILDREN(acpi_tz_sysctl_tree), OID_AUTO, "polling_rate", CTLFLAG_RW, &acpi_tz_polling_rate, 0, "monitor polling interval in seconds"); SYSCTL_ADD_INT(&acpi_tz_sysctl_ctx, SYSCTL_CHILDREN(acpi_tz_sysctl_tree), OID_AUTO, "user_override", CTLFLAG_RW, &acpi_tz_override, 0, "allow override of thermal settings"); } sysctl_ctx_init(&sc->tz_sysctl_ctx); sprintf(oidname, "tz%d", device_get_unit(dev)); sc->tz_sysctl_tree = SYSCTL_ADD_NODE(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(acpi_tz_sysctl_tree), OID_AUTO, oidname, CTLFLAG_RD, 0, ""); SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree), OID_AUTO, "temperature", CTLTYPE_INT | CTLFLAG_RD, &sc->tz_temperature, 0, sysctl_handle_int, "IK", "current thermal zone temperature"); SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree), OID_AUTO, "active", CTLTYPE_INT | CTLFLAG_RW, sc, 0, acpi_tz_active_sysctl, "I", "cooling is active"); SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree), OID_AUTO, "passive_cooling", CTLTYPE_INT | CTLFLAG_RW, sc, 0, acpi_tz_cooling_sysctl, "I", "enable passive (speed reduction) cooling"); SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree), OID_AUTO, "thermal_flags", CTLFLAG_RD, &sc->tz_thflags, 0, "thermal zone flags"); SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree), OID_AUTO, "_PSV", CTLTYPE_INT | CTLFLAG_RW, sc, offsetof(struct acpi_tz_softc, tz_zone.psv), acpi_tz_temp_sysctl, "IK", "passive cooling temp setpoint"); SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree), OID_AUTO, "_HOT", CTLTYPE_INT | CTLFLAG_RW, sc, offsetof(struct acpi_tz_softc, tz_zone.hot), acpi_tz_temp_sysctl, "IK", "too hot temp setpoint (suspend now)"); SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree), OID_AUTO, "_CRT", CTLTYPE_INT | CTLFLAG_RW, sc, offsetof(struct acpi_tz_softc, tz_zone.crt), acpi_tz_temp_sysctl, "IK", "critical temp setpoint (shutdown now)"); SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree), OID_AUTO, "_ACx", CTLTYPE_INT | CTLFLAG_RD, &sc->tz_zone.ac, sizeof(sc->tz_zone.ac), sysctl_handle_opaque, "IK", ""); SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree), OID_AUTO, "_TC1", CTLTYPE_INT | CTLFLAG_RW, sc, offsetof(struct acpi_tz_softc, tz_zone.tc1), acpi_tz_passive_sysctl, "I", "thermal constant 1 for passive cooling"); SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree), OID_AUTO, "_TC2", CTLTYPE_INT | CTLFLAG_RW, sc, offsetof(struct acpi_tz_softc, tz_zone.tc2), acpi_tz_passive_sysctl, "I", "thermal constant 2 for passive cooling"); SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree), OID_AUTO, "_TSP", CTLTYPE_INT | CTLFLAG_RW, sc, offsetof(struct acpi_tz_softc, tz_zone.tsp), acpi_tz_passive_sysctl, "I", "thermal sampling period for passive cooling"); /* * Create thread to service all of the thermal zones. Register * our power profile event handler. */ sc->tz_event = EVENTHANDLER_REGISTER(power_profile_change, acpi_tz_power_profile, sc, 0); if (acpi_tz_proc == NULL) { error = kproc_create(acpi_tz_thread, NULL, &acpi_tz_proc, RFHIGHPID, 0, "acpi_thermal"); if (error != 0) { device_printf(sc->tz_dev, "could not create thread - %d", error); goto out; } } /* * Create a thread to handle passive cooling for 1st zone which * has _PSV, _TSP, _TC1 and _TC2. Users can enable it for other * zones manually for now. * * XXX We enable only one zone to avoid multiple zones conflict * with each other since cpufreq currently sets all CPUs to the * given frequency whereas it's possible for different thermal * zones to specify independent settings for multiple CPUs. */ if (acpi_tz_cooling_unit < 0 && acpi_tz_cooling_is_available(sc)) sc->tz_cooling_enabled = TRUE; if (sc->tz_cooling_enabled) { error = acpi_tz_cooling_thread_start(sc); if (error != 0) { sc->tz_cooling_enabled = FALSE; goto out; } acpi_tz_cooling_unit = device_get_unit(dev); } /* * Flag the event handler for a manual invocation by our timeout. * We defer it like this so that the rest of the subsystem has time * to come up. Don't bother evaluating/printing the temperature at * this point; on many systems it'll be bogus until the EC is running. */ sc->tz_flags |= TZ_FLAG_GETPROFILE; out: if (error != 0) { EVENTHANDLER_DEREGISTER(power_profile_change, sc->tz_event); AcpiRemoveNotifyHandler(sc->tz_handle, ACPI_DEVICE_NOTIFY, acpi_tz_notify_handler); sysctl_ctx_free(&sc->tz_sysctl_ctx); } return_VALUE (error); }
ACPI_STATUS AeInstallHandlers (void) { ACPI_STATUS Status; UINT32 i; ACPI_HANDLE Handle; ACPI_FUNCTION_ENTRY (); Status = AcpiInstallTableHandler (AeTableHandler, NULL); if (ACPI_FAILURE (Status)) { printf ("Could not install table handler, %s\n", AcpiFormatException (Status)); } Status = AcpiInstallExceptionHandler (AeExceptionHandler); if (ACPI_FAILURE (Status)) { printf ("Could not install exception handler, %s\n", AcpiFormatException (Status)); } /* Install global notify handler */ Status = AcpiInstallNotifyHandler (ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY, AeNotifyHandler, NULL); if (ACPI_FAILURE (Status)) { printf ("Could not install a global notify handler, %s\n", AcpiFormatException (Status)); } Status = AcpiInstallNotifyHandler (ACPI_ROOT_OBJECT, ACPI_DEVICE_NOTIFY, AeDeviceNotifyHandler, NULL); if (ACPI_FAILURE (Status)) { printf ("Could not install a global notify handler, %s\n", AcpiFormatException (Status)); } Status = AcpiGetHandle (NULL, "\\_SB", &Handle); if (ACPI_SUCCESS (Status)) { Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY, AeNotifyHandler, NULL); if (ACPI_FAILURE (Status)) { printf ("Could not install a notify handler, %s\n", AcpiFormatException (Status)); } Status = AcpiRemoveNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY, AeNotifyHandler); if (ACPI_FAILURE (Status)) { printf ("Could not remove a notify handler, %s\n", AcpiFormatException (Status)); } Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY, AeNotifyHandler, NULL); Status = AcpiRemoveNotifyHandler (Handle, ACPI_ALL_NOTIFY, AeNotifyHandler); Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY, AeNotifyHandler, NULL); if (ACPI_FAILURE (Status)) { printf ("Could not install a notify handler, %s\n", AcpiFormatException (Status)); } Status = AcpiAttachData (Handle, AeAttachedDataHandler, Handle); Status = AcpiDetachData (Handle, AeAttachedDataHandler); Status = AcpiAttachData (Handle, AeAttachedDataHandler, Handle); } else { printf ("No _SB_ found, %s\n", AcpiFormatException (Status)); } /* Set a handler for all supported operation regions */ for (i = 0; i < AEXEC_NUM_REGIONS; i++) { Status = AcpiRemoveAddressSpaceHandler (AcpiGbl_RootNode, SpaceId[i], AeRegionHandler); /* Install handler at the root object. * TBD: all default handlers should be installed here! */ Status = AcpiInstallAddressSpaceHandler (AcpiGbl_RootNode, SpaceId[i], AeRegionHandler, AeRegionInit, NULL); if (ACPI_FAILURE (Status)) { ACPI_EXCEPTION ((AE_INFO, Status, "Could not install an OpRegion handler for %s space(%u)", AcpiUtGetRegionName((UINT8) SpaceId[i]), SpaceId[i])); return (Status); } } /* * Initialize the global Region Handler space * MCW 3/23/00 */ AeRegions.NumberOfRegions = 0; AeRegions.RegionList = NULL; return Status; }