Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 952c63e9 authored by Jiang Liu's avatar Jiang Liu Committed by Rafael J. Wysocki
Browse files

ACPI: introduce helper function acpi_has_method()



Introduce helper function acpi_has_method() and use it in a number
of places to simplify code.

[rjw: Changelog]
Signed-off-by: default avatarJiang Liu <jiang.liu@huawei.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 472d963b
Loading
Loading
Loading
Loading
+3 −8
Original line number Original line Diff line number Diff line
@@ -548,12 +548,8 @@ static int acpi_battery_set_alarm(struct acpi_battery *battery)


static int acpi_battery_init_alarm(struct acpi_battery *battery)
static int acpi_battery_init_alarm(struct acpi_battery *battery)
{
{
	acpi_status status = AE_OK;
	acpi_handle handle = NULL;

	/* See if alarms are supported, and if so, set default */
	/* See if alarms are supported, and if so, set default */
	status = acpi_get_handle(battery->device->handle, "_BTP", &handle);
	if (!acpi_has_method(battery->device->handle, "_BTP")) {
	if (ACPI_FAILURE(status)) {
		clear_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags);
		clear_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags);
		return 0;
		return 0;
	}
	}
@@ -1066,7 +1062,7 @@ static int acpi_battery_add(struct acpi_device *device)
{
{
	int result = 0;
	int result = 0;
	struct acpi_battery *battery = NULL;
	struct acpi_battery *battery = NULL;
	acpi_handle handle;

	if (!device)
	if (!device)
		return -EINVAL;
		return -EINVAL;
	battery = kzalloc(sizeof(struct acpi_battery), GFP_KERNEL);
	battery = kzalloc(sizeof(struct acpi_battery), GFP_KERNEL);
@@ -1078,8 +1074,7 @@ static int acpi_battery_add(struct acpi_device *device)
	device->driver_data = battery;
	device->driver_data = battery;
	mutex_init(&battery->lock);
	mutex_init(&battery->lock);
	mutex_init(&battery->sysfs_lock);
	mutex_init(&battery->sysfs_lock);
	if (ACPI_SUCCESS(acpi_get_handle(battery->device->handle,
	if (acpi_has_method(battery->device->handle, "_BIX"))
			"_BIX", &handle)))
		set_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags);
		set_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags);
	result = acpi_battery_update(battery);
	result = acpi_battery_update(battery);
	if (result)
	if (result)
+1 −3
Original line number Original line Diff line number Diff line
@@ -1049,10 +1049,8 @@ int __init acpi_ec_ecdt_probe(void)
		* which needs it, has fake EC._INI method, so use it as flag.
		* which needs it, has fake EC._INI method, so use it as flag.
		* Keep boot_ec struct as it will be needed soon.
		* Keep boot_ec struct as it will be needed soon.
		*/
		*/
		acpi_handle dummy;
		if (!dmi_name_in_vendors("ASUS") ||
		if (!dmi_name_in_vendors("ASUS") ||
		    ACPI_FAILURE(acpi_get_handle(boot_ec->handle, "_INI",
		    !acpi_has_method(boot_ec->handle, "_INI"))
							&dummy)))
			return -ENODEV;
			return -ENODEV;
	}
	}
install:
install:
+7 −15
Original line number Original line Diff line number Diff line
@@ -164,17 +164,12 @@ static void acpi_processor_ppc_ost(acpi_handle handle, int status)
		{.type = ACPI_TYPE_INTEGER,},
		{.type = ACPI_TYPE_INTEGER,},
	};
	};
	struct acpi_object_list arg_list = {2, params};
	struct acpi_object_list arg_list = {2, params};
	acpi_handle temp;


	if (acpi_has_method(handle, "_OST")) {
		params[0].integer.value = ACPI_PROCESSOR_NOTIFY_PERFORMANCE;
		params[0].integer.value = ACPI_PROCESSOR_NOTIFY_PERFORMANCE;
		params[1].integer.value =  status;
		params[1].integer.value =  status;

	/* when there is no _OST , skip it */
	if (ACPI_FAILURE(acpi_get_handle(handle, "_OST", &temp)))
		return;

		acpi_evaluate_object(handle, "_OST", &arg_list, NULL);
		acpi_evaluate_object(handle, "_OST", &arg_list, NULL);
	return;
	}
}
}


int acpi_processor_ppc_has_changed(struct acpi_processor *pr, int event_flag)
int acpi_processor_ppc_has_changed(struct acpi_processor *pr, int event_flag)
@@ -468,14 +463,11 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)
int acpi_processor_get_performance_info(struct acpi_processor *pr)
int acpi_processor_get_performance_info(struct acpi_processor *pr)
{
{
	int result = 0;
	int result = 0;
	acpi_status status = AE_OK;
	acpi_handle handle = NULL;


	if (!pr || !pr->performance || !pr->handle)
	if (!pr || !pr->performance || !pr->handle)
		return -EINVAL;
		return -EINVAL;


	status = acpi_get_handle(pr->handle, "_PCT", &handle);
	if (!acpi_has_method(pr->handle, "_PCT")) {
	if (ACPI_FAILURE(status)) {
		ACPI_DEBUG_PRINT((ACPI_DB_INFO,
		ACPI_DEBUG_PRINT((ACPI_DB_INFO,
				  "ACPI-based processor performance control unavailable\n"));
				  "ACPI-based processor performance control unavailable\n"));
		return -ENODEV;
		return -ENODEV;
@@ -501,7 +493,7 @@ int acpi_processor_get_performance_info(struct acpi_processor *pr)
	 */
	 */
 update_bios:
 update_bios:
#ifdef CONFIG_X86
#ifdef CONFIG_X86
	if (ACPI_SUCCESS(acpi_get_handle(pr->handle, "_PPC", &handle))){
	if (acpi_has_method(pr->handle, "_PPC")) {
		if(boot_cpu_has(X86_FEATURE_EST))
		if(boot_cpu_has(X86_FEATURE_EST))
			printk(KERN_WARNING FW_BUG "BIOS needs update for CPU "
			printk(KERN_WARNING FW_BUG "BIOS needs update for CPU "
			       "frequency support\n");
			       "frequency support\n");
+1 −3
Original line number Original line Diff line number Diff line
@@ -505,14 +505,12 @@ int acpi_dev_get_resources(struct acpi_device *adev, struct list_head *list,
			   void *preproc_data)
			   void *preproc_data)
{
{
	struct res_proc_context c;
	struct res_proc_context c;
	acpi_handle not_used;
	acpi_status status;
	acpi_status status;


	if (!adev || !adev->handle || !list_empty(list))
	if (!adev || !adev->handle || !list_empty(list))
		return -EINVAL;
		return -EINVAL;


	status = acpi_get_handle(adev->handle, METHOD_NAME__CRS, &not_used);
	if (!acpi_has_method(adev->handle, METHOD_NAME__CRS))
	if (ACPI_FAILURE(status))
		return 0;
		return 0;


	c.list = list;
	c.list = list;
+30 −69
Original line number Original line Diff line number Diff line
@@ -193,7 +193,6 @@ static acpi_status acpi_bus_online_companions(acpi_handle handle, u32 lvl,
static int acpi_scan_hot_remove(struct acpi_device *device)
static int acpi_scan_hot_remove(struct acpi_device *device)
{
{
	acpi_handle handle = device->handle;
	acpi_handle handle = device->handle;
	acpi_handle not_used;
	struct acpi_object_list arg_list;
	struct acpi_object_list arg_list;
	union acpi_object arg;
	union acpi_object arg;
	struct device *errdev;
	struct device *errdev;
@@ -258,7 +257,7 @@ static int acpi_scan_hot_remove(struct acpi_device *device)
	put_device(&device->dev);
	put_device(&device->dev);
	device = NULL;
	device = NULL;


	if (ACPI_SUCCESS(acpi_get_handle(handle, "_LCK", &not_used))) {
	if (acpi_has_method(handle, "_LCK")) {
		arg_list.count = 1;
		arg_list.count = 1;
		arg_list.pointer = &arg;
		arg_list.pointer = &arg;
		arg.type = ACPI_TYPE_INTEGER;
		arg.type = ACPI_TYPE_INTEGER;
@@ -652,7 +651,6 @@ static int acpi_device_setup_files(struct acpi_device *dev)
{
{
	struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
	struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
	acpi_status status;
	acpi_status status;
	acpi_handle temp;
	unsigned long long sun;
	unsigned long long sun;
	int result = 0;
	int result = 0;


@@ -678,8 +676,7 @@ static int acpi_device_setup_files(struct acpi_device *dev)
	/*
	/*
	 * If device has _STR, 'description' file is created
	 * If device has _STR, 'description' file is created
	 */
	 */
	status = acpi_get_handle(dev->handle, "_STR", &temp);
	if (acpi_has_method(dev->handle, "_STR")) {
	if (ACPI_SUCCESS(status)) {
		status = acpi_evaluate_object(dev->handle, "_STR",
		status = acpi_evaluate_object(dev->handle, "_STR",
					NULL, &buffer);
					NULL, &buffer);
		if (ACPI_FAILURE(status))
		if (ACPI_FAILURE(status))
@@ -709,8 +706,7 @@ static int acpi_device_setup_files(struct acpi_device *dev)
         * If device has _EJ0, 'eject' file is created that is used to trigger
         * If device has _EJ0, 'eject' file is created that is used to trigger
         * hot-removal function from userland.
         * hot-removal function from userland.
         */
         */
	status = acpi_get_handle(dev->handle, "_EJ0", &temp);
	if (acpi_has_method(dev->handle, "_EJ0")) {
	if (ACPI_SUCCESS(status)) {
		result = device_create_file(&dev->dev, &dev_attr_eject);
		result = device_create_file(&dev->dev, &dev_attr_eject);
		if (result)
		if (result)
			return result;
			return result;
@@ -732,9 +728,6 @@ static int acpi_device_setup_files(struct acpi_device *dev)


static void acpi_device_remove_files(struct acpi_device *dev)
static void acpi_device_remove_files(struct acpi_device *dev)
{
{
	acpi_status status;
	acpi_handle temp;

	if (dev->flags.power_manageable) {
	if (dev->flags.power_manageable) {
		device_remove_file(&dev->dev, &dev_attr_power_state);
		device_remove_file(&dev->dev, &dev_attr_power_state);
		if (dev->power.flags.power_resources)
		if (dev->power.flags.power_resources)
@@ -745,20 +738,17 @@ static void acpi_device_remove_files(struct acpi_device *dev)
	/*
	/*
	 * If device has _STR, remove 'description' file
	 * If device has _STR, remove 'description' file
	 */
	 */
	status = acpi_get_handle(dev->handle, "_STR", &temp);
	if (acpi_has_method(dev->handle, "_STR")) {
	if (ACPI_SUCCESS(status)) {
		kfree(dev->pnp.str_obj);
		kfree(dev->pnp.str_obj);
		device_remove_file(&dev->dev, &dev_attr_description);
		device_remove_file(&dev->dev, &dev_attr_description);
	}
	}
	/*
	/*
	 * If device has _EJ0, remove 'eject' file.
	 * If device has _EJ0, remove 'eject' file.
	 */
	 */
	status = acpi_get_handle(dev->handle, "_EJ0", &temp);
	if (acpi_has_method(dev->handle, "_EJ0"))
	if (ACPI_SUCCESS(status))
		device_remove_file(&dev->dev, &dev_attr_eject);
		device_remove_file(&dev->dev, &dev_attr_eject);


	status = acpi_get_handle(dev->handle, "_SUN", &temp);
	if (acpi_has_method(dev->handle, "_SUN"))
	if (ACPI_SUCCESS(status))
		device_remove_file(&dev->dev, &dev_attr_sun);
		device_remove_file(&dev->dev, &dev_attr_sun);


	if (dev->pnp.unique_id)
	if (dev->pnp.unique_id)
@@ -1334,13 +1324,10 @@ static void acpi_bus_set_run_wake_flags(struct acpi_device *device)


static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
{
{
	acpi_handle temp;
	acpi_status status = 0;
	int err;
	int err;


	/* Presence of _PRW indicates wake capable */
	/* Presence of _PRW indicates wake capable */
	status = acpi_get_handle(device->handle, "_PRW", &temp);
	if (!acpi_has_method(device->handle, "_PRW"))
	if (ACPI_FAILURE(status))
		return;
		return;


	err = acpi_bus_extract_wakeup_device_power_package(device->handle,
	err = acpi_bus_extract_wakeup_device_power_package(device->handle,
@@ -1370,7 +1357,6 @@ static void acpi_bus_init_power_state(struct acpi_device *device, int state)
	struct acpi_device_power_state *ps = &device->power.states[state];
	struct acpi_device_power_state *ps = &device->power.states[state];
	char pathname[5] = { '_', 'P', 'R', '0' + state, '\0' };
	char pathname[5] = { '_', 'P', 'R', '0' + state, '\0' };
	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
	acpi_handle handle;
	acpi_status status;
	acpi_status status;


	INIT_LIST_HEAD(&ps->resources);
	INIT_LIST_HEAD(&ps->resources);
@@ -1393,8 +1379,7 @@ static void acpi_bus_init_power_state(struct acpi_device *device, int state)


	/* Evaluate "_PSx" to see if we can do explicit sets */
	/* Evaluate "_PSx" to see if we can do explicit sets */
	pathname[2] = 'S';
	pathname[2] = 'S';
	status = acpi_get_handle(device->handle, pathname, &handle);
	if (acpi_has_method(device->handle, pathname))
	if (ACPI_SUCCESS(status))
		ps->flags.explicit_set = 1;
		ps->flags.explicit_set = 1;


	/*
	/*
@@ -1413,28 +1398,21 @@ static void acpi_bus_init_power_state(struct acpi_device *device, int state)


static void acpi_bus_get_power_flags(struct acpi_device *device)
static void acpi_bus_get_power_flags(struct acpi_device *device)
{
{
	acpi_status status;
	acpi_handle handle;
	u32 i;
	u32 i;


	/* Presence of _PS0|_PR0 indicates 'power manageable' */
	/* Presence of _PS0|_PR0 indicates 'power manageable' */
	status = acpi_get_handle(device->handle, "_PS0", &handle);
	if (!acpi_has_method(device->handle, "_PS0") &&
	if (ACPI_FAILURE(status)) {
	    !acpi_has_method(device->handle, "_PR0"))
		status = acpi_get_handle(device->handle, "_PR0", &handle);
		if (ACPI_FAILURE(status))
		return;
		return;
	}


	device->flags.power_manageable = 1;
	device->flags.power_manageable = 1;


	/*
	/*
	 * Power Management Flags
	 * Power Management Flags
	 */
	 */
	status = acpi_get_handle(device->handle, "_PSC", &handle);
	if (acpi_has_method(device->handle, "_PSC"))
	if (ACPI_SUCCESS(status))
		device->power.flags.explicit_get = 1;
		device->power.flags.explicit_get = 1;
	status = acpi_get_handle(device->handle, "_IRC", &handle);
	if (acpi_has_method(device->handle, "_IRC"))
	if (ACPI_SUCCESS(status))
		device->power.flags.inrush_current = 1;
		device->power.flags.inrush_current = 1;


	/*
	/*
@@ -1468,29 +1446,19 @@ static void acpi_bus_get_power_flags(struct acpi_device *device)


static void acpi_bus_get_flags(struct acpi_device *device)
static void acpi_bus_get_flags(struct acpi_device *device)
{
{
	acpi_status status = AE_OK;
	acpi_handle temp = NULL;

	/* Presence of _STA indicates 'dynamic_status' */
	/* Presence of _STA indicates 'dynamic_status' */
	status = acpi_get_handle(device->handle, "_STA", &temp);
	if (acpi_has_method(device->handle, "_STA"))
	if (ACPI_SUCCESS(status))
		device->flags.dynamic_status = 1;
		device->flags.dynamic_status = 1;


	/* Presence of _RMV indicates 'removable' */
	/* Presence of _RMV indicates 'removable' */
	status = acpi_get_handle(device->handle, "_RMV", &temp);
	if (acpi_has_method(device->handle, "_RMV"))
	if (ACPI_SUCCESS(status))
		device->flags.removable = 1;
		device->flags.removable = 1;


	/* Presence of _EJD|_EJ0 indicates 'ejectable' */
	/* Presence of _EJD|_EJ0 indicates 'ejectable' */
	status = acpi_get_handle(device->handle, "_EJD", &temp);
	if (acpi_has_method(device->handle, "_EJD") ||
	if (ACPI_SUCCESS(status))
	    acpi_has_method(device->handle, "_EJ0"))
		device->flags.ejectable = 1;
	else {
		status = acpi_get_handle(device->handle, "_EJ0", &temp);
		if (ACPI_SUCCESS(status))
		device->flags.ejectable = 1;
		device->flags.ejectable = 1;
}
}
}


static void acpi_device_get_busid(struct acpi_device *device)
static void acpi_device_get_busid(struct acpi_device *device)
{
{
@@ -1538,27 +1506,24 @@ static void acpi_device_get_busid(struct acpi_device *device)
 */
 */
static int acpi_bay_match(acpi_handle handle)
static int acpi_bay_match(acpi_handle handle)
{
{
	acpi_status status;
	acpi_handle tmp;
	acpi_handle phandle;
	acpi_handle phandle;


	status = acpi_get_handle(handle, "_EJ0", &tmp);
	if (!acpi_has_method(handle, "_EJ0"))
	if (ACPI_FAILURE(status))
		return -ENODEV;
		return -ENODEV;


	if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) ||
	if (acpi_has_method(handle, "_GTF") ||
		(ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) ||
	    acpi_has_method(handle, "_GTM") ||
		(ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) ||
	    acpi_has_method(handle, "_STM") ||
		(ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp))))
	    acpi_has_method(handle, "_SDD"))
		return 0;
		return 0;


	if (acpi_get_parent(handle, &phandle))
	if (acpi_get_parent(handle, &phandle))
		return -ENODEV;
		return -ENODEV;


        if ((ACPI_SUCCESS(acpi_get_handle(phandle, "_GTF", &tmp))) ||
	if (acpi_has_method(phandle, "_GTF") ||
                (ACPI_SUCCESS(acpi_get_handle(phandle, "_GTM", &tmp))) ||
	    acpi_has_method(phandle, "_GTM") ||
                (ACPI_SUCCESS(acpi_get_handle(phandle, "_STM", &tmp))) ||
	    acpi_has_method(phandle, "_STM") ||
                (ACPI_SUCCESS(acpi_get_handle(phandle, "_SDD", &tmp))))
	    acpi_has_method(phandle, "_SDD"))
                return 0;
                return 0;


	return -ENODEV;
	return -ENODEV;
@@ -1610,7 +1575,6 @@ static void acpi_add_id(struct acpi_device_pnp *pnp, const char *dev_id)
 */
 */
static int acpi_ibm_smbus_match(acpi_handle handle)
static int acpi_ibm_smbus_match(acpi_handle handle)
{
{
	acpi_handle h_dummy;
	struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL};
	struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL};
	int result;
	int result;


@@ -1629,9 +1593,9 @@ static int acpi_ibm_smbus_match(acpi_handle handle)


	/* Does it have the necessary (but misnamed) methods? */
	/* Does it have the necessary (but misnamed) methods? */
	result = -ENODEV;
	result = -ENODEV;
	if (ACPI_SUCCESS(acpi_get_handle(handle, "SBI", &h_dummy)) &&
	if (acpi_has_method(handle, "SBI") &&
	    ACPI_SUCCESS(acpi_get_handle(handle, "SBR", &h_dummy)) &&
	    acpi_has_method(handle, "SBR") &&
	    ACPI_SUCCESS(acpi_get_handle(handle, "SBW", &h_dummy)))
	    acpi_has_method(handle, "SBW"))
		result = 0;
		result = 0;
out:
out:
	kfree(path.pointer);
	kfree(path.pointer);
@@ -1898,7 +1862,6 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used,
	struct acpi_device *device = NULL;
	struct acpi_device *device = NULL;
	int type;
	int type;
	unsigned long long sta;
	unsigned long long sta;
	acpi_status status;
	int result;
	int result;


	acpi_bus_get_device(handle, &device);
	acpi_bus_get_device(handle, &device);
@@ -1919,10 +1882,8 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used,
	if (!(sta & ACPI_STA_DEVICE_PRESENT) &&
	if (!(sta & ACPI_STA_DEVICE_PRESENT) &&
	    !(sta & ACPI_STA_DEVICE_FUNCTIONING)) {
	    !(sta & ACPI_STA_DEVICE_FUNCTIONING)) {
		struct acpi_device_wakeup wakeup;
		struct acpi_device_wakeup wakeup;
		acpi_handle temp;


		status = acpi_get_handle(handle, "_PRW", &temp);
		if (acpi_has_method(handle, "_PRW")) {
		if (ACPI_SUCCESS(status)) {
			acpi_bus_extract_wakeup_device_power_package(handle,
			acpi_bus_extract_wakeup_device_power_package(handle,
								     &wakeup);
								     &wakeup);
			acpi_power_resources_list_free(&wakeup.resources);
			acpi_power_resources_list_free(&wakeup.resources);
Loading