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

Commit 5ba1aef5 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki
Browse files

Merge branch 'acpi-fixes'

* acpi-fixes:
  ACPI: Try harder to resolve _ADR collisions for bridges
  ACPI / processor: move try_offline_node() after acpi_unmap_lsapic()
  ACPI: Drop physical_node_id_bitmap from struct acpi_device
  ACPI / PM: Walk physical_node_list under physical_node_lock
  ACPI / video: improve quirk check in acpi_video_bqc_quirk()
parents c095ba72 60f75b8e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -451,7 +451,6 @@ static void acpi_processor_remove(struct acpi_device *device)
	/* Clean up. */
	per_cpu(processor_device_array, pr->id) = NULL;
	per_cpu(processors, pr->id) = NULL;
	try_offline_node(cpu_to_node(pr->id));

	/* Remove the CPU. */
	get_online_cpus();
@@ -459,6 +458,8 @@ static void acpi_processor_remove(struct acpi_device *device)
	acpi_unmap_lsapic(pr->id);
	put_online_cpus();

	try_offline_node(cpu_to_node(pr->id));

 out:
	free_cpumask_var(pr->throttling.shared_cpu_map);
	kfree(pr);
+101 −32
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ static LIST_HEAD(bus_type_list);
static DECLARE_RWSEM(bus_type_sem);

#define PHYSICAL_NODE_STRING "physical_node"
#define PHYSICAL_NODE_NAME_SIZE (sizeof(PHYSICAL_NODE_STRING) + 10)

int register_acpi_bus_type(struct acpi_bus_type *type)
{
@@ -78,41 +79,108 @@ static struct acpi_bus_type *acpi_get_bus_type(struct device *dev)
	return ret;
}

static acpi_status do_acpi_find_child(acpi_handle handle, u32 lvl_not_used,
				      void *addr_p, void **ret_p)
static acpi_status acpi_dev_present(acpi_handle handle, u32 lvl_not_used,
				  void *not_used, void **ret_p)
{
	unsigned long long addr, sta;
	acpi_status status;
	struct acpi_device *adev = NULL;

	status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &addr);
	if (ACPI_SUCCESS(status) && addr == *((u64 *)addr_p)) {
	acpi_bus_get_device(handle, &adev);
	if (adev) {
		*ret_p = handle;
		status = acpi_bus_get_status_handle(handle, &sta);
		if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_ENABLED))
		return AE_CTRL_TERMINATE;
	}
	return AE_OK;
}

acpi_handle acpi_get_child(acpi_handle parent, u64 address)
static bool acpi_extra_checks_passed(acpi_handle handle, bool is_bridge)
{
	void *ret = NULL;
	unsigned long long sta;
	acpi_status status;

	if (!parent)
		return NULL;
	status = acpi_bus_get_status_handle(handle, &sta);
	if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_ENABLED))
		return false;

	if (is_bridge) {
		void *test = NULL;

		/* Check if this object has at least one child device. */
		acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
				    acpi_dev_present, NULL, NULL, &test);
		return !!test;
	}
	return true;
}

struct find_child_context {
	u64 addr;
	bool is_bridge;
	acpi_handle ret;
	bool ret_checked;
};

static acpi_status do_find_child(acpi_handle handle, u32 lvl_not_used,
				 void *data, void **not_used)
{
	struct find_child_context *context = data;
	unsigned long long addr;
	acpi_status status;

	status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &addr);
	if (ACPI_FAILURE(status) || addr != context->addr)
		return AE_OK;

	if (!context->ret) {
		/* This is the first matching object.  Save its handle. */
		context->ret = handle;
		return AE_OK;
	}
	/*
	 * There is more than one matching object with the same _ADR value.
	 * That really is unexpected, so we are kind of beyond the scope of the
	 * spec here.  We have to choose which one to return, though.
	 *
	 * First, check if the previously found object is good enough and return
	 * its handle if so.  Second, check the same for the object that we've
	 * just found.
	 */
	if (!context->ret_checked) {
		if (acpi_extra_checks_passed(context->ret, context->is_bridge))
			return AE_CTRL_TERMINATE;
		else
			context->ret_checked = true;
	}
	if (acpi_extra_checks_passed(handle, context->is_bridge)) {
		context->ret = handle;
		return AE_CTRL_TERMINATE;
	}
	return AE_OK;
}

	acpi_walk_namespace(ACPI_TYPE_DEVICE, parent, 1, NULL,
			    do_acpi_find_child, &address, &ret);
	return (acpi_handle)ret;
acpi_handle acpi_find_child(acpi_handle parent, u64 addr, bool is_bridge)
{
	if (parent) {
		struct find_child_context context = {
			.addr = addr,
			.is_bridge = is_bridge,
		};

		acpi_walk_namespace(ACPI_TYPE_DEVICE, parent, 1, do_find_child,
				    NULL, &context, NULL);
		return context.ret;
	}
EXPORT_SYMBOL(acpi_get_child);
	return NULL;
}
EXPORT_SYMBOL_GPL(acpi_find_child);

int acpi_bind_one(struct device *dev, acpi_handle handle)
{
	struct acpi_device *acpi_dev;
	acpi_status status;
	struct acpi_device_physical_node *physical_node, *pn;
	char physical_node_name[sizeof(PHYSICAL_NODE_STRING) + 2];
	char physical_node_name[PHYSICAL_NODE_NAME_SIZE];
	struct list_head *physnode_list;
	unsigned int node_id;
	int retval = -EINVAL;

	if (ACPI_HANDLE(dev)) {
@@ -139,25 +207,27 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)

	mutex_lock(&acpi_dev->physical_node_lock);

	/*
	 * Keep the list sorted by node_id so that the IDs of removed nodes can
	 * be recycled easily.
	 */
	physnode_list = &acpi_dev->physical_node_list;
	node_id = 0;
	list_for_each_entry(pn, &acpi_dev->physical_node_list, node) {
		/* Sanity check. */
	list_for_each_entry(pn, &acpi_dev->physical_node_list, node)
		if (pn->dev == dev) {
			dev_warn(dev, "Already associated with ACPI node\n");
			goto err_free;
		}

	/* allocate physical node id according to physical_node_id_bitmap */
	physical_node->node_id =
		find_first_zero_bit(acpi_dev->physical_node_id_bitmap,
		ACPI_MAX_PHYSICAL_NODE);
	if (physical_node->node_id >= ACPI_MAX_PHYSICAL_NODE) {
		retval = -ENOSPC;
		goto err_free;
		if (pn->node_id == node_id) {
			physnode_list = &pn->node;
			node_id++;
		}
	}

	set_bit(physical_node->node_id, acpi_dev->physical_node_id_bitmap);
	physical_node->node_id = node_id;
	physical_node->dev = dev;
	list_add_tail(&physical_node->node, &acpi_dev->physical_node_list);
	list_add(&physical_node->node, physnode_list);
	acpi_dev->physical_node_count++;

	mutex_unlock(&acpi_dev->physical_node_lock);
@@ -208,7 +278,7 @@ int acpi_unbind_one(struct device *dev)

	mutex_lock(&acpi_dev->physical_node_lock);
	list_for_each_safe(node, next, &acpi_dev->physical_node_list) {
		char physical_node_name[sizeof(PHYSICAL_NODE_STRING) + 2];
		char physical_node_name[PHYSICAL_NODE_NAME_SIZE];

		entry = list_entry(node, struct acpi_device_physical_node,
			node);
@@ -216,7 +286,6 @@ int acpi_unbind_one(struct device *dev)
			continue;

		list_del(node);
		clear_bit(entry->node_id, acpi_dev->physical_node_id_bitmap);

		acpi_dev->physical_node_count--;

+8 −0
Original line number Diff line number Diff line
@@ -311,6 +311,8 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
			   dev->pnp.bus_id,
			   (u32) dev->wakeup.sleep_state);

		mutex_lock(&dev->physical_node_lock);

		if (!dev->physical_node_count) {
			seq_printf(seq, "%c%-8s\n",
				dev->wakeup.flags.run_wake ? '*' : ' ',
@@ -338,6 +340,8 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
				put_device(ldev);
			}
		}

		mutex_unlock(&dev->physical_node_lock);
	}
	mutex_unlock(&acpi_device_lock);
	return 0;
@@ -347,12 +351,16 @@ static void physical_device_enable_wakeup(struct acpi_device *adev)
{
	struct acpi_device_physical_node *entry;

	mutex_lock(&adev->physical_node_lock);

	list_for_each_entry(entry,
		&adev->physical_node_list, node)
		if (entry->dev && device_can_wakeup(entry->dev)) {
			bool enable = !device_may_wakeup(entry->dev);
			device_set_wakeup_enable(entry->dev, enable);
		}

	mutex_unlock(&adev->physical_node_lock);
}

static ssize_t
+1 −1
Original line number Diff line number Diff line
@@ -689,7 +689,7 @@ static int acpi_video_bqc_quirk(struct acpi_video_device *device,
	 * Some systems always report current brightness level as maximum
	 * through _BQC, we need to test another value for them.
	 */
	test_level = current_level == max_level ? br->levels[2] : max_level;
	test_level = current_level == max_level ? br->levels[3] : max_level;

	result = acpi_video_device_lcd_set_level(device, test_level);
	if (result)
+11 −4
Original line number Diff line number Diff line
@@ -317,13 +317,20 @@ void acpi_pci_remove_bus(struct pci_bus *bus)
/* ACPI bus type */
static int acpi_pci_find_device(struct device *dev, acpi_handle *handle)
{
	struct pci_dev * pci_dev;
	struct pci_dev *pci_dev = to_pci_dev(dev);
	bool is_bridge;
	u64 addr;

	pci_dev = to_pci_dev(dev);
	/*
	 * pci_is_bridge() is not suitable here, because pci_dev->subordinate
	 * is set only after acpi_pci_find_device() has been called for the
	 * given device.
	 */
	is_bridge = pci_dev->hdr_type == PCI_HEADER_TYPE_BRIDGE
			|| pci_dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
	/* Please ref to ACPI spec for the syntax of _ADR */
	addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
	*handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr);
	*handle = acpi_find_child(ACPI_HANDLE(dev->parent), addr, is_bridge);
	if (!*handle)
		return -ENODEV;
	return 0;
Loading