static acpi_status processor_walk_namespace_cb(acpi_handle handle, u32 lvl, void *context, void **rv) { acpi_status status; int *action = context; acpi_object_type type = 0; status = acpi_get_type(handle, &type); if (ACPI_FAILURE(status)) return (AE_OK); if (type != ACPI_TYPE_PROCESSOR) return (AE_OK); switch (*action) { case INSTALL_NOTIFY_HANDLER: acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, acpi_processor_hotplug_notify, NULL); break; case UNINSTALL_NOTIFY_HANDLER: acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY, acpi_processor_hotplug_notify); break; default: break; } return (AE_OK); }
/** * acpi_add_pm_notifier - Register PM notify handler for given ACPI device. * @adev: ACPI device to add the notify handler for. * @dev: Device to generate a wakeup event for while handling the notification. * @work_func: Work function to execute when handling the notification. * * NOTE: @adev need not be a run-wake or wakeup device to be a valid source of * PM wakeup events. For example, wakeup events may be generated for bridges * if one of the devices below the bridge is signaling wakeup, even if the * bridge itself doesn't have a wakeup GPE associated with it. */ acpi_status acpi_add_pm_notifier(struct acpi_device *adev, struct device *dev, void (*work_func)(struct work_struct *work)) { acpi_status status = AE_ALREADY_EXISTS; if (!dev && !work_func) return AE_BAD_PARAMETER; mutex_lock(&acpi_pm_notifier_lock); if (adev->wakeup.flags.notifier_present) goto out; adev->wakeup.ws = wakeup_source_register(dev_name(&adev->dev)); adev->wakeup.context.dev = dev; if (work_func) INIT_WORK(&adev->wakeup.context.work, work_func); status = acpi_install_notify_handler(adev->handle, ACPI_SYSTEM_NOTIFY, acpi_pm_notify_handler, NULL); if (ACPI_FAILURE(status)) goto out; adev->wakeup.flags.notifier_present = true; out: mutex_unlock(&acpi_pm_notifier_lock); return status; }
static acpi_status processor_walk_namespace_cb(acpi_handle handle, u32 lvl, void *context, void **rv) { acpi_status status; int *action = context; status = is_processor_device(handle); if (ACPI_FAILURE(status)) return AE_OK; /* not a processor; continue to walk */ switch (*action) { case INSTALL_NOTIFY_HANDLER: acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, acpi_processor_hotplug_notify, NULL); break; case UNINSTALL_NOTIFY_HANDLER: acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY, acpi_processor_hotplug_notify); break; default: break; } /* found a processor; skip walking underneath */ return AE_CTRL_DEPTH; }
static int __acpi_processor_start(struct acpi_device *device) { struct acpi_processor *pr = acpi_driver_data(device); acpi_status status; int result = 0; if (!pr) return -ENODEV; if (pr->flags.need_hotplug_init) return 0; result = acpi_cppc_processor_probe(pr); if (result) return -ENODEV; if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver) acpi_processor_power_init(pr); result = acpi_pss_perf_init(pr, device); if (result) goto err_power_exit; status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, acpi_processor_notify, device); if (ACPI_SUCCESS(status)) return 0; err_power_exit: acpi_processor_power_exit(pr); return result; }
static int intel_hid_probe(struct platform_device *device) { acpi_handle handle = ACPI_HANDLE(&device->dev); struct intel_hid_priv *priv; unsigned long long mode; acpi_status status; int err; status = acpi_evaluate_integer(handle, "HDMM", NULL, &mode); if (!ACPI_SUCCESS(status)) { dev_warn(&device->dev, "failed to read mode\n"); return -ENODEV; } if (mode != 0) { /* * This driver only implements "simple" mode. There appear * to be no other modes, but we should be paranoid and check * for compatibility. */ dev_info(&device->dev, "platform is not in simple mode\n"); return -ENODEV; } priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; dev_set_drvdata(&device->dev, priv); err = intel_hid_input_setup(device); if (err) { pr_err("Failed to setup Intel HID hotkeys\n"); return err; } status = acpi_install_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler, device); if (ACPI_FAILURE(status)) { err = -EBUSY; goto err_remove_input; } err = intel_hid_set_enable(&device->dev, 1); if (err) goto err_remove_notify; return 0; err_remove_notify: acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler); err_remove_input: intel_hid_input_destroy(device); return err; }
static int acpi_thermal_add ( struct acpi_device *device) { int result = 0; acpi_status status = AE_OK; struct acpi_thermal *tz = NULL; ACPI_FUNCTION_TRACE("acpi_thermal_add"); if (!device) return_VALUE(-EINVAL); tz = kmalloc(sizeof(struct acpi_thermal), GFP_KERNEL); if (!tz) return_VALUE(-ENOMEM); memset(tz, 0, sizeof(struct acpi_thermal)); tz->handle = device->handle; sprintf(tz->name, "%s", device->pnp.bus_id); sprintf(acpi_device_name(device), "%s", ACPI_THERMAL_DEVICE_NAME); sprintf(acpi_device_class(device), "%s", ACPI_THERMAL_CLASS); acpi_driver_data(device) = tz; result = acpi_thermal_get_info(tz); if (result) goto end; result = acpi_thermal_add_fs(device); if (result) return_VALUE(result); init_timer(&tz->timer); acpi_thermal_check(tz); status = acpi_install_notify_handler(tz->handle, ACPI_DEVICE_NOTIFY, acpi_thermal_notify, tz); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error installing notify handler\n")); result = -ENODEV; goto end; } printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n", acpi_device_name(device), acpi_device_bid(device), KELVIN_TO_CELSIUS(tz->temperature)); end: if (result) { acpi_thermal_remove_fs(device); kfree(tz); } return_VALUE(result); }
static int acpi_processor_start(struct acpi_device *device) { int result = 0; acpi_status status = AE_OK; struct acpi_processor *pr; ACPI_FUNCTION_TRACE("acpi_processor_start"); pr = acpi_driver_data(device); result = acpi_processor_get_info(pr); if (result) { /* Processor is physically not present */ return_VALUE(0); } BUG_ON((pr->id >= NR_CPUS) || (pr->id < 0)); /* * Buggy BIOS check * ACPI id of processors can be reported wrongly by the BIOS. * Don't trust it blindly */ if (processor_device_array[pr->id] != NULL && processor_device_array[pr->id] != (void *)device) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "BIOS reporting wrong ACPI id" "for the processor\n")); return_VALUE(-ENODEV); } processor_device_array[pr->id] = (void *)device; processors[pr->id] = pr; result = acpi_processor_add_fs(device); if (result) goto end; status = acpi_install_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY, acpi_processor_notify, pr); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error installing device notify handler\n")); } acpi_processor_power_init(pr, device); if (pr->flags.throttling) { printk(KERN_INFO PREFIX "%s [%s] (supports", acpi_device_name(device), acpi_device_bid(device)); printk(" %d throttling states", pr->throttling.state_count); printk(")\n"); } end: return_VALUE(result); }
static void acpi_pad_handle_notify(acpi_handle handle) { int num_cpus; uint32_t idle_cpus; struct acpi_buffer param = { .length = 4, .pointer = (void *)&idle_cpus, }; mutex_lock(&isolated_cpus_lock); num_cpus = acpi_pad_pur(handle); if (num_cpus < 0) { mutex_unlock(&isolated_cpus_lock); return; } acpi_pad_idle_cpus(num_cpus); idle_cpus = acpi_pad_idle_cpus_num(); acpi_evaluate_ost(handle, ACPI_PROCESSOR_AGGREGATOR_NOTIFY, 0, ¶m); mutex_unlock(&isolated_cpus_lock); } static void acpi_pad_notify(acpi_handle handle, u32 event, void *data) { struct acpi_device *device = data; switch (event) { case ACPI_PROCESSOR_AGGREGATOR_NOTIFY: acpi_pad_handle_notify(handle); acpi_bus_generate_netlink_event(device->pnp.device_class, dev_name(&device->dev), event, 0); break; default: pr_warn("Unsupported event [0x%x]\n", event); break; } } static int acpi_pad_add(struct acpi_device *device) { acpi_status status; strcpy(acpi_device_name(device), ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME); strcpy(acpi_device_class(device), ACPI_PROCESSOR_AGGREGATOR_CLASS); if (acpi_pad_add_sysfs(device)) return -ENODEV; status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, acpi_pad_notify, device); if (ACPI_FAILURE(status)) { acpi_pad_remove_sysfs(device); return -ENODEV; } return 0; }
static int __cpuinit acpi_processor_start(struct acpi_device *device) { int result = 0; acpi_status status = AE_OK; struct acpi_processor *pr; pr = acpi_driver_data(device); result = acpi_processor_get_info(pr); if (result) { /* Processor is physically not present */ return 0; } BUG_ON((pr->id >= NR_CPUS) || (pr->id < 0)); /* * Buggy BIOS check * ACPI id of processors can be reported wrongly by the BIOS. * Don't trust it blindly */ if (processor_device_array[pr->id] != NULL && processor_device_array[pr->id] != device) { printk(KERN_WARNING "BIOS reported wrong ACPI id" "for the processor\n"); return -ENODEV; } processor_device_array[pr->id] = device; processors[pr->id] = pr; result = acpi_processor_add_fs(device); if (result) goto end; status = acpi_install_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY, acpi_processor_notify, pr); /* _PDC call should be done before doing anything else (if reqd.). */ arch_acpi_processor_init_pdc(pr); acpi_processor_set_pdc(pr); acpi_processor_power_init(pr, device); if (pr->flags.throttling) { printk(KERN_INFO PREFIX "%s [%s] (supports", acpi_device_name(device), acpi_device_bid(device)); printk(" %d throttling states", pr->throttling.state_count); printk(")\n"); } end: return result; }
static acpi_status container_walk_namespace_cb(acpi_handle handle, u32 lvl, void *context, void **rv) { char *hid = NULL; struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; struct acpi_device_info *info; acpi_status status; int *action = context; ACPI_FUNCTION_TRACE("container_walk_namespace_cb"); status = acpi_get_object_info(handle, &buffer); if (ACPI_FAILURE(status) || !buffer.pointer) { return_ACPI_STATUS(AE_OK); } info = buffer.pointer; if (info->valid & ACPI_VALID_HID) hid = info->hardware_id.value; if (hid == NULL) { goto end; } if (strcmp(hid, "ACPI0004") && strcmp(hid, "PNP0A05") && strcmp(hid, "PNP0A06")) { goto end; } switch(*action) { case INSTALL_NOTIFY_HANDLER: acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, container_notify_cb, NULL); break; case UNINSTALL_NOTIFY_HANDLER: acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY, container_notify_cb); break; default: break; } end: acpi_os_free(buffer.pointer); return_ACPI_STATUS(AE_OK); }
static int acpi_ac_probe(struct platform_device *pdev) { int result = 0; struct acpi_ac *ac = NULL; struct acpi_device *adev; if (!pdev) return -EINVAL; adev = ACPI_COMPANION(&pdev->dev); if (!adev) return -ENODEV; ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL); if (!ac) return -ENOMEM; strcpy(acpi_device_name(adev), ACPI_AC_DEVICE_NAME); strcpy(acpi_device_class(adev), ACPI_AC_CLASS); ac->pdev = pdev; platform_set_drvdata(pdev, ac); result = acpi_ac_get_state(ac); if (result) goto end; ac->charger.name = acpi_device_bid(adev); ac->charger.type = POWER_SUPPLY_TYPE_MAINS; ac->charger.properties = ac_props; ac->charger.num_properties = ARRAY_SIZE(ac_props); ac->charger.get_property = get_ac_property; result = power_supply_register(&pdev->dev, &ac->charger); if (result) goto end; result = acpi_install_notify_handler(ACPI_HANDLE(&pdev->dev), ACPI_ALL_NOTIFY, acpi_ac_notify_handler, ac); if (result) { power_supply_unregister(&ac->charger); goto end; } printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(adev), acpi_device_bid(adev), ac->state ? "on-line" : "off-line"); end: if (result) kfree(ac); dmi_check_system(ac_dmi_table); return result; }
static int acpi_battery_add ( struct acpi_device *device) { int result = 0; acpi_status status = 0; struct acpi_battery *battery = NULL; ACPI_FUNCTION_TRACE("acpi_battery_add"); if (!device) return_VALUE(-EINVAL); battery = kmalloc(sizeof(struct acpi_battery), GFP_KERNEL); if (!battery) return_VALUE(-ENOMEM); memset(battery, 0, sizeof(struct acpi_battery)); battery->handle = device->handle; strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS); acpi_driver_data(device) = battery; result = acpi_battery_check(battery); if (result) goto end; result = acpi_battery_add_fs(device); if (result) goto end; status = acpi_install_notify_handler(battery->handle, ACPI_DEVICE_NOTIFY, acpi_battery_notify, battery); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error installing notify handler\n")); result = -ENODEV; goto end; } printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n", ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device), device->status.battery_present?"present":"absent"); end: if (result) { acpi_battery_remove_fs(device); kfree(battery); } return_VALUE(result); }
int acpi_ac_add ( struct acpi_device *device) { int result = 0; acpi_status status = AE_OK; struct acpi_ac *ac = NULL; ACPI_FUNCTION_TRACE("acpi_ac_add"); if (!device) return_VALUE(-EINVAL); ac = kmalloc(sizeof(struct acpi_ac), GFP_KERNEL); if (!ac) return_VALUE(-ENOMEM); memset(ac, 0, sizeof(struct acpi_ac)); ac->handle = device->handle; sprintf(acpi_device_name(device), "%s", ACPI_AC_DEVICE_NAME); sprintf(acpi_device_class(device), "%s", ACPI_AC_CLASS); acpi_driver_data(device) = ac; result = acpi_ac_get_state(ac); if (result) goto end; result = acpi_ac_add_fs(device); if (result) goto end; status = acpi_install_notify_handler(ac->handle, ACPI_DEVICE_NOTIFY, acpi_ac_notify, ac); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error installing notify handler\n")); result = -ENODEV; goto end; } printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device), acpi_device_bid(device), ac->state?"on-line":"off-line"); end: if (result) { acpi_ac_remove_fs(device); kfree(ac); } return_VALUE(result); }
static int acpi_battery_add(struct acpi_device *device) { int result = 0; acpi_status status = 0; struct acpi_battery *battery = NULL; if (!device) return -EINVAL; battery = kzalloc(sizeof(struct acpi_battery), GFP_KERNEL); if (!battery) return -ENOMEM; battery->device = device; strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS); acpi_driver_data(device) = battery; result = acpi_battery_check(battery); if (result) goto end; result = acpi_battery_add_fs(device); if (result) goto end; status = acpi_install_notify_handler(device->handle, ACPI_ALL_NOTIFY, acpi_battery_notify, battery); if (ACPI_FAILURE(status)) { result = -ENODEV; goto end; } printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n", ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device), device->status.battery_present ? "present" : "absent"); end: if (result) { acpi_battery_remove_fs(device); kfree(battery); } return result; }
static acpi_status container_walk_namespace_cb(acpi_handle handle, u32 lvl, void *context, void **rv) { char *hid = NULL; struct acpi_device_info *info; acpi_status status; int *action = context; status = acpi_get_object_info(handle, &info); if (ACPI_FAILURE(status)) { return AE_OK; } if (info->valid & ACPI_VALID_HID) hid = info->hardware_id.string; if (hid == NULL) { goto end; } if (strcmp(hid, "ACPI0004") && strcmp(hid, "PNP0A05") && strcmp(hid, "PNP0A06")) { goto end; } switch (*action) { case INSTALL_NOTIFY_HANDLER: acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, container_notify_cb, NULL); break; case UNINSTALL_NOTIFY_HANDLER: acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY, container_notify_cb); break; default: break; } end: kfree(info); return AE_OK; }
static int ucsi_acpi_probe(struct platform_device *pdev) { struct resource *res; acpi_status status; struct ucsi *ucsi; int ret; ucsi = devm_kzalloc(&pdev->dev, sizeof(*ucsi), GFP_KERNEL); if (!ucsi) return -ENOMEM; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(&pdev->dev, "missing memory resource\n"); return -ENODEV; } /* * NOTE: ACPI has claimed the memory region as it's also an Operation * Region. It's not possible to request it in the driver. */ ucsi->data = devm_ioremap(&pdev->dev, res->start, resource_size(res)); if (!ucsi->data) return -ENOMEM; ucsi->dev = &pdev->dev; status = acpi_install_notify_handler(ACPI_HANDLE(&pdev->dev), ACPI_ALL_NOTIFY, ucsi_acpi_notify, ucsi); if (ACPI_FAILURE(status)) return -ENODEV; ret = ucsi_init(ucsi); if (ret) { acpi_remove_notify_handler(ACPI_HANDLE(&pdev->dev), ACPI_ALL_NOTIFY, ucsi_acpi_notify); return ret; } platform_set_drvdata(pdev, ucsi); return 0; }
/** \brief install notify handler for acpi device * \param device acpi device * \param handler_type type of handler * \param handler pointer of notify handler * \param context context for the handler * \return status */ unsigned int ATI_API_CALL KCL_ACPI_InstallHandler(KCL_ACPI_DevHandle device, unsigned int handler_type, KCL_ACPI_CallbackHandle handler, KCL_ACPI_ContextHandle context, KCL_NOTIFIER_BLOCKER *nb) { #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) return acpi_install_notify_handler(device, handler_type, (acpi_notify_handler)handler, context); #else KCL_ACPI_DevHandle dummy_handle; //register notifier chain for video switching events if ((KCL_ACPI_GetDevHandle(device, "_DOD", &dummy_handle) == KCL_ACPI_OK) || (KCL_ACPI_GetDevHandle(device, "_DOS", &dummy_handle) == KCL_ACPI_OK)) { *nb = kmalloc(sizeof(struct notifier_block), GFP_KERNEL); if (!*nb) { KCL_DEBUG_ERROR ("Could not allocate enough memory for video notifier_block\n"); return -ENOMEM; } ((struct notifier_block*)(*nb))->notifier_call = firegl_acpi_video_event; return register_acpi_notifier((struct notifier_block*)(*nb)); } //register notifier chain for ac adapter events if (KCL_ACPI_GetDevHandle(device, "_PSR", &dummy_handle) == KCL_ACPI_OK) { *nb = kmalloc(sizeof(struct notifier_block), GFP_KERNEL); if (!*nb) { KCL_DEBUG_ERROR ("Could not allocate enough memory for ac notifier_block\n"); return -ENOMEM; } ((struct notifier_block*)(*nb))->notifier_call = firegl_acpi_ac_event; return register_acpi_notifier((struct notifier_block*)(*nb)); } return 0; #endif }
/** * acpi_add_pm_notifier - Register PM notifier for given ACPI device. * @adev: ACPI device to add the notifier for. * @context: Context information to pass to the notifier routine. * * NOTE: @adev need not be a run-wake or wakeup device to be a valid source of * PM wakeup events. For example, wakeup events may be generated for bridges * if one of the devices below the bridge is signaling wakeup, even if the * bridge itself doesn't have a wakeup GPE associated with it. */ acpi_status acpi_add_pm_notifier(struct acpi_device *adev, acpi_notify_handler handler, void *context) { acpi_status status = AE_ALREADY_EXISTS; mutex_lock(&acpi_pm_notifier_lock); if (adev->wakeup.flags.notifier_present) goto out; status = acpi_install_notify_handler(adev->handle, ACPI_SYSTEM_NOTIFY, handler, context); if (ACPI_FAILURE(status)) goto out; adev->wakeup.flags.notifier_present = true; out: mutex_unlock(&acpi_pm_notifier_lock); return status; }
static acpi_status acpi_memory_register_notify_handler(acpi_handle handle, u32 level, void *ctxt, void **retv) { acpi_status status; ACPI_FUNCTION_TRACE("acpi_memory_register_notify_handler"); status = is_memory_device(handle); if (ACPI_FAILURE(status)) return_ACPI_STATUS(AE_OK); /* continue */ status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, acpi_memory_device_notify, NULL); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error installing notify handler\n")); return_ACPI_STATUS(AE_OK); /* continue */ } return_ACPI_STATUS(status); }
static int acpi_device_install_notify_handler(struct acpi_device *device) { acpi_status status; if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON) status = acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, acpi_device_fixed_event, device); else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON) status = acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, acpi_device_fixed_event, device); else status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, acpi_device_notify, device); if (ACPI_FAILURE(status)) return -EINVAL; return 0; }
static int intel_vbtn_probe(struct platform_device *device) { acpi_handle handle = ACPI_HANDLE(&device->dev); struct intel_vbtn_priv *priv; acpi_status status; int err; status = acpi_evaluate_object(handle, "VBDL", NULL, NULL); if (ACPI_FAILURE(status)) { dev_warn(&device->dev, "failed to read Intel Virtual Button driver\n"); return -ENODEV; } priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; dev_set_drvdata(&device->dev, priv); err = intel_vbtn_input_setup(device); if (err) { pr_err("Failed to setup Intel Virtual Button\n"); return err; } detect_tablet_mode(device); status = acpi_install_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler, device); if (ACPI_FAILURE(status)) return -EBUSY; device_init_wakeup(&device->dev, true); return 0; }
static int __cpuinit acpi_processor_start(struct acpi_device *device) { int result = 0; acpi_status status = AE_OK; struct acpi_processor *pr; struct sys_device *sysdev; pr = acpi_driver_data(device); result = acpi_processor_get_info(pr, device->flags.unique_id); if (result) { /* Processor is physically not present */ return 0; } BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0)); /* * Buggy BIOS check * ACPI id of processors can be reported wrongly by the BIOS. * Don't trust it blindly */ if (per_cpu(processor_device_array, pr->id) != NULL && per_cpu(processor_device_array, pr->id) != device) { printk(KERN_WARNING "BIOS reported wrong ACPI id " "for the processor\n"); return -ENODEV; } per_cpu(processor_device_array, pr->id) = device; per_cpu(processors, pr->id) = pr; result = acpi_processor_add_fs(device); if (result) goto end; sysdev = get_cpu_sysdev(pr->id); if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev")) return -EFAULT; status = acpi_install_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY, acpi_processor_notify, pr); /* _PDC call should be done before doing anything else (if reqd.). */ arch_acpi_processor_init_pdc(pr); acpi_processor_set_pdc(pr); #ifdef CONFIG_CPU_FREQ acpi_processor_ppc_has_changed(pr); #endif acpi_processor_get_throttling_info(pr); acpi_processor_get_limit_info(pr); acpi_processor_power_init(pr, device); pr->cdev = thermal_cooling_device_register("Processor", device, &processor_cooling_ops); if (IS_ERR(pr->cdev)) { result = PTR_ERR(pr->cdev); goto end; } dev_info(&device->dev, "registered as cooling_device%d\n", pr->cdev->id); result = sysfs_create_link(&device->dev.kobj, &pr->cdev->device.kobj, "thermal_cooling"); if (result) printk(KERN_ERR PREFIX "Create sysfs link\n"); result = sysfs_create_link(&pr->cdev->device.kobj, &device->dev.kobj, "device"); if (result) printk(KERN_ERR PREFIX "Create sysfs link\n"); if (pr->flags.throttling) { printk(KERN_INFO PREFIX "%s [%s] (supports", acpi_device_name(device), acpi_device_bid(device)); printk(" %d throttling states", pr->throttling.state_count); printk(")\n"); } end: return result; }
static int cros_ec_lpc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct acpi_device *adev; acpi_status status; struct cros_ec_device *ec_dev; u8 buf[2]; int ret; if (!devm_request_region(dev, EC_LPC_ADDR_MEMMAP, EC_MEMMAP_SIZE, dev_name(dev))) { dev_err(dev, "couldn't reserve memmap region\n"); return -EBUSY; } cros_ec_lpc_read_bytes(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID, 2, buf); if (buf[0] != 'E' || buf[1] != 'C') { dev_err(dev, "EC ID not detected\n"); return -ENODEV; } if (!devm_request_region(dev, EC_HOST_CMD_REGION0, EC_HOST_CMD_REGION_SIZE, dev_name(dev))) { dev_err(dev, "couldn't reserve region0\n"); return -EBUSY; } if (!devm_request_region(dev, EC_HOST_CMD_REGION1, EC_HOST_CMD_REGION_SIZE, dev_name(dev))) { dev_err(dev, "couldn't reserve region1\n"); return -EBUSY; } ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL); if (!ec_dev) return -ENOMEM; platform_set_drvdata(pdev, ec_dev); ec_dev->dev = dev; ec_dev->phys_name = dev_name(dev); ec_dev->cmd_xfer = cros_ec_cmd_xfer_lpc; ec_dev->pkt_xfer = cros_ec_pkt_xfer_lpc; ec_dev->cmd_readmem = cros_ec_lpc_readmem; ec_dev->din_size = sizeof(struct ec_host_response) + sizeof(struct ec_response_get_protocol_info); ec_dev->dout_size = sizeof(struct ec_host_request); ret = cros_ec_register(ec_dev); if (ret) { dev_err(dev, "couldn't register ec_dev (%d)\n", ret); return ret; } /* * Connect a notify handler to process MKBP messages if we have a * companion ACPI device. */ adev = ACPI_COMPANION(dev); if (adev) { status = acpi_install_notify_handler(adev->handle, ACPI_ALL_NOTIFY, cros_ec_lpc_acpi_notify, ec_dev); if (ACPI_FAILURE(status)) dev_warn(dev, "Failed to register notifier %08x\n", status); } return 0; }
static int __init acpi_bus_init (void) { int result = 0; acpi_status status = AE_OK; extern acpi_status acpi_os_initialize1(void); ACPI_FUNCTION_TRACE("acpi_bus_init"); status = acpi_os_initialize1(); status = acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE); if (ACPI_FAILURE(status)) { printk(KERN_ERR PREFIX "Unable to start the ACPI Interpreter\n"); goto error1; } if (ACPI_FAILURE(status)) { printk(KERN_ERR PREFIX "Unable to initialize ACPI OS objects\n"); goto error1; } #ifdef CONFIG_ACPI_EC /* * ACPI 2.0 requires the EC driver to be loaded and work before * the EC device is found in the namespace (i.e. before acpi_initialize_objects() * is called). * * This is accomplished by looking for the ECDT table, and getting * the EC parameters out of that. */ status = acpi_ec_ecdt_probe(); /* Ignore result. Not having an ECDT is not fatal. */ #endif status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION); if (ACPI_FAILURE(status)) { printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n"); goto error1; } printk(KERN_INFO PREFIX "Interpreter enabled\n"); /* * Get the system interrupt model and evaluate \_PIC. */ result = acpi_bus_init_irq(); if (result) goto error1; /* * Register the for all standard device notifications. */ status = acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY, &acpi_bus_notify, NULL); if (ACPI_FAILURE(status)) { printk(KERN_ERR PREFIX "Unable to register for device notifications\n"); goto error1; } /* * Create the top ACPI proc directory */ acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL); return_VALUE(0); /* Mimic structured exception handling */ error1: acpi_terminate(); return_VALUE(-ENODEV); }
static int intel_hid_probe(struct platform_device *device) { acpi_handle handle = ACPI_HANDLE(&device->dev); unsigned long long event_cap, mode; struct intel_hid_priv *priv; acpi_status status; int err; status = acpi_evaluate_integer(handle, "HDMM", NULL, &mode); if (ACPI_FAILURE(status)) { dev_warn(&device->dev, "failed to read mode\n"); return -ENODEV; } if (mode != 0) { /* * This driver only implements "simple" mode. There appear * to be no other modes, but we should be paranoid and check * for compatibility. */ dev_info(&device->dev, "platform is not in simple mode\n"); return -ENODEV; } priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; dev_set_drvdata(&device->dev, priv); err = intel_hid_input_setup(device); if (err) { pr_err("Failed to setup Intel HID hotkeys\n"); return err; } /* Setup 5 button array */ status = acpi_evaluate_integer(handle, "HEBC", NULL, &event_cap); if (ACPI_SUCCESS(status) && (event_cap & 0x20000)) { dev_info(&device->dev, "platform supports 5 button array\n"); err = intel_button_array_input_setup(device); if (err) pr_err("Failed to setup Intel 5 button array hotkeys\n"); } status = acpi_install_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler, device); if (ACPI_FAILURE(status)) return -EBUSY; err = intel_hid_set_enable(&device->dev, true); if (err) goto err_remove_notify; if (priv->array) { intel_button_array_enable(&device->dev, true); /* Call button load method to enable HID power button */ status = acpi_evaluate_object(handle, "BTNL", NULL, NULL); if (ACPI_FAILURE(status)) dev_warn(&device->dev, "failed to enable HID power button\n"); } return 0; err_remove_notify: acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler); return err; }
static int __acpi_processor_start(struct acpi_device *device) { struct acpi_processor *pr = acpi_driver_data(device); acpi_status status; int result = 0; if (!pr) return -ENODEV; if (pr->flags.need_hotplug_init) return 0; #ifdef CONFIG_CPU_FREQ acpi_processor_ppc_has_changed(pr, 0); acpi_processor_load_module(pr); #endif acpi_processor_get_throttling_info(pr); acpi_processor_get_limit_info(pr); if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver) acpi_processor_power_init(pr); pr->cdev = thermal_cooling_device_register("Processor", device, &processor_cooling_ops); if (IS_ERR(pr->cdev)) { result = PTR_ERR(pr->cdev); goto err_power_exit; } dev_dbg(&device->dev, "registered as cooling_device%d\n", pr->cdev->id); result = sysfs_create_link(&device->dev.kobj, &pr->cdev->device.kobj, "thermal_cooling"); if (result) { dev_err(&device->dev, "Failed to create sysfs link 'thermal_cooling'\n"); goto err_thermal_unregister; } result = sysfs_create_link(&pr->cdev->device.kobj, &device->dev.kobj, "device"); if (result) { dev_err(&pr->cdev->device, "Failed to create sysfs link 'device'\n"); goto err_remove_sysfs_thermal; } status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, acpi_processor_notify, device); if (ACPI_SUCCESS(status)) return 0; sysfs_remove_link(&pr->cdev->device.kobj, "device"); err_remove_sysfs_thermal: sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); err_thermal_unregister: thermal_cooling_device_unregister(pr->cdev); err_power_exit: acpi_processor_power_exit(pr); return result; }
static void ata_acpi_add_pm_notifier(struct ata_device *dev) { acpi_handle handle = ata_dev_acpi_handle(dev); acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, zpodd_wake_dev, dev); }
static int acpi_button_add ( struct acpi_device *device) { int result = 0; acpi_status status = AE_OK; struct acpi_button *button = NULL; static struct acpi_device *power_button; static struct acpi_device *sleep_button; static struct acpi_device *lid_button; ACPI_FUNCTION_TRACE("acpi_button_add"); if (!device) return_VALUE(-EINVAL); button = kmalloc(sizeof(struct acpi_button), GFP_KERNEL); if (!button) return_VALUE(-ENOMEM); memset(button, 0, sizeof(struct acpi_button)); button->device = device; button->handle = device->handle; acpi_driver_data(device) = button; /* * Determine the button type (via hid), as fixed-feature buttons * need to be handled a bit differently than generic-space. */ if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_POWER)) { button->type = ACPI_BUTTON_TYPE_POWER; sprintf(acpi_device_name(device), "%s", ACPI_BUTTON_DEVICE_NAME_POWER); sprintf(acpi_device_class(device), "%s/%s", ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER); } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_POWERF)) { button->type = ACPI_BUTTON_TYPE_POWERF; sprintf(acpi_device_name(device), "%s", ACPI_BUTTON_DEVICE_NAME_POWERF); sprintf(acpi_device_class(device), "%s/%s", ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER); } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_SLEEP)) { button->type = ACPI_BUTTON_TYPE_SLEEP; sprintf(acpi_device_name(device), "%s", ACPI_BUTTON_DEVICE_NAME_SLEEP); sprintf(acpi_device_class(device), "%s/%s", ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP); } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_SLEEPF)) { button->type = ACPI_BUTTON_TYPE_SLEEPF; sprintf(acpi_device_name(device), "%s", ACPI_BUTTON_DEVICE_NAME_SLEEPF); sprintf(acpi_device_class(device), "%s/%s", ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP); } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_LID)) { button->type = ACPI_BUTTON_TYPE_LID; sprintf(acpi_device_name(device), "%s", ACPI_BUTTON_DEVICE_NAME_LID); sprintf(acpi_device_class(device), "%s/%s", ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID); } else { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unsupported hid [%s]\n", acpi_device_hid(device))); result = -ENODEV; goto end; } /* * Ensure only one button of each type is used. */ switch (button->type) { case ACPI_BUTTON_TYPE_POWER: case ACPI_BUTTON_TYPE_POWERF: if (!power_button) power_button = device; else { kfree(button); return_VALUE(-ENODEV); } break; case ACPI_BUTTON_TYPE_SLEEP: case ACPI_BUTTON_TYPE_SLEEPF: if (!sleep_button) sleep_button = device; else { kfree(button); return_VALUE(-ENODEV); } break; case ACPI_BUTTON_TYPE_LID: if (!lid_button) lid_button = device; else { kfree(button); return_VALUE(-ENODEV); } break; } result = acpi_button_add_fs(device); if (result) goto end; switch (button->type) { case ACPI_BUTTON_TYPE_POWERF: status = acpi_install_fixed_event_handler ( ACPI_EVENT_POWER_BUTTON, acpi_button_notify_fixed, button); break; case ACPI_BUTTON_TYPE_SLEEPF: status = acpi_install_fixed_event_handler ( ACPI_EVENT_SLEEP_BUTTON, acpi_button_notify_fixed, button); break; default: status = acpi_install_notify_handler ( button->handle, ACPI_DEVICE_NOTIFY, acpi_button_notify, button); break; } if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error installing notify handler\n")); result = -ENODEV; goto end; } printk(KERN_INFO PREFIX "%s [%s]\n", acpi_device_name(device), acpi_device_bid(device)); end: if (result) { acpi_button_remove_fs(device); kfree(button); } return_VALUE(result); }
acpi_status bm_initialize (void) { acpi_status status = AE_OK; u32 start = 0; u32 stop = 0; u32 elapsed = 0; FUNCTION_TRACE("bm_initialize"); MEMSET(&node_list, 0, sizeof(BM_NODE_LIST)); status = acpi_get_timer(&start); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Building device hierarchy.\n")); /* * Enumerate ACPI fixed-feature devices. */ status = bm_enumerate_fixed_features(); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Enumerate the ACPI namespace. */ status = bm_enumerate_namespace(); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } acpi_get_timer(&stop); acpi_get_timer_duration(start, stop, &elapsed); ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Building device hierarchy took [%d] microseconds.\n", elapsed)); /* * Display hierarchy. */ bm_print_hierarchy(); /* * Register for all standard and device-specific notifications. */ ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Registering for all device notifications.\n")); status = acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY, &bm_notify, NULL); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unable to register for standard notifications.\n")); return_ACPI_STATUS(status); } status = acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_DEVICE_NOTIFY, &bm_notify, NULL); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unable to register for device-specific notifications.\n")); return_ACPI_STATUS(status); } ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Bus Manager enabled.\n")); /* * Initialize built-in power resource driver. */ bm_pr_initialize(); return_ACPI_STATUS(status); }
static int intel_hid_probe(struct platform_device *device) { acpi_handle handle = ACPI_HANDLE(&device->dev); unsigned long long mode; struct intel_hid_priv *priv; acpi_status status; int err; intel_hid_init_dsm(handle); if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_HDMM_FN, &mode)) { dev_warn(&device->dev, "failed to read mode\n"); return -ENODEV; } if (mode != 0) { /* * This driver only implements "simple" mode. There appear * to be no other modes, but we should be paranoid and check * for compatibility. */ dev_info(&device->dev, "platform is not in simple mode\n"); return -ENODEV; } priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; dev_set_drvdata(&device->dev, priv); err = intel_hid_input_setup(device); if (err) { pr_err("Failed to setup Intel HID hotkeys\n"); return err; } /* Setup 5 button array */ if (button_array_present(device)) { dev_info(&device->dev, "platform supports 5 button array\n"); err = intel_button_array_input_setup(device); if (err) pr_err("Failed to setup Intel 5 button array hotkeys\n"); } status = acpi_install_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler, device); if (ACPI_FAILURE(status)) return -EBUSY; err = intel_hid_set_enable(&device->dev, true); if (err) goto err_remove_notify; if (priv->array) { unsigned long long dummy; intel_button_array_enable(&device->dev, true); /* Call button load method to enable HID power button */ if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_BTNL_FN, &dummy)) { dev_warn(&device->dev, "failed to enable HID power button\n"); } } device_init_wakeup(&device->dev, true); return 0; err_remove_notify: acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler); return err; }