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

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
...@@ -451,7 +451,6 @@ static void acpi_processor_remove(struct acpi_device *device) ...@@ -451,7 +451,6 @@ static void acpi_processor_remove(struct acpi_device *device)
/* Clean up. */ /* Clean up. */
per_cpu(processor_device_array, pr->id) = NULL; per_cpu(processor_device_array, pr->id) = NULL;
per_cpu(processors, pr->id) = NULL; per_cpu(processors, pr->id) = NULL;
try_offline_node(cpu_to_node(pr->id));
/* Remove the CPU. */ /* Remove the CPU. */
get_online_cpus(); get_online_cpus();
...@@ -459,6 +458,8 @@ static void acpi_processor_remove(struct acpi_device *device) ...@@ -459,6 +458,8 @@ static void acpi_processor_remove(struct acpi_device *device)
acpi_unmap_lsapic(pr->id); acpi_unmap_lsapic(pr->id);
put_online_cpus(); put_online_cpus();
try_offline_node(cpu_to_node(pr->id));
out: out:
free_cpumask_var(pr->throttling.shared_cpu_map); free_cpumask_var(pr->throttling.shared_cpu_map);
kfree(pr); kfree(pr);
......
...@@ -31,6 +31,7 @@ static LIST_HEAD(bus_type_list); ...@@ -31,6 +31,7 @@ static LIST_HEAD(bus_type_list);
static DECLARE_RWSEM(bus_type_sem); static DECLARE_RWSEM(bus_type_sem);
#define PHYSICAL_NODE_STRING "physical_node" #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) 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) ...@@ -78,41 +79,108 @@ static struct acpi_bus_type *acpi_get_bus_type(struct device *dev)
return ret; return ret;
} }
static acpi_status do_acpi_find_child(acpi_handle handle, u32 lvl_not_used, static acpi_status acpi_dev_present(acpi_handle handle, u32 lvl_not_used,
void *addr_p, void **ret_p) void *not_used, void **ret_p)
{ {
unsigned long long addr, sta; struct acpi_device *adev = NULL;
acpi_status status;
status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &addr); acpi_bus_get_device(handle, &adev);
if (ACPI_SUCCESS(status) && addr == *((u64 *)addr_p)) { if (adev) {
*ret_p = handle; *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_CTRL_TERMINATE;
} }
return AE_OK; 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) status = acpi_bus_get_status_handle(handle, &sta);
return NULL; 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, acpi_handle acpi_find_child(acpi_handle parent, u64 addr, bool is_bridge)
do_acpi_find_child, &address, &ret); {
return (acpi_handle)ret; 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;
}
return NULL;
} }
EXPORT_SYMBOL(acpi_get_child); EXPORT_SYMBOL_GPL(acpi_find_child);
int acpi_bind_one(struct device *dev, acpi_handle handle) int acpi_bind_one(struct device *dev, acpi_handle handle)
{ {
struct acpi_device *acpi_dev; struct acpi_device *acpi_dev;
acpi_status status; acpi_status status;
struct acpi_device_physical_node *physical_node, *pn; 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; int retval = -EINVAL;
if (ACPI_HANDLE(dev)) { if (ACPI_HANDLE(dev)) {
...@@ -139,25 +207,27 @@ int acpi_bind_one(struct device *dev, acpi_handle handle) ...@@ -139,25 +207,27 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)
mutex_lock(&acpi_dev->physical_node_lock); 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. */ /* Sanity check. */
list_for_each_entry(pn, &acpi_dev->physical_node_list, node)
if (pn->dev == dev) { if (pn->dev == dev) {
dev_warn(dev, "Already associated with ACPI node\n"); dev_warn(dev, "Already associated with ACPI node\n");
goto err_free; goto err_free;
} }
if (pn->node_id == node_id) {
/* allocate physical node id according to physical_node_id_bitmap */ physnode_list = &pn->node;
physical_node->node_id = 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;
} }
set_bit(physical_node->node_id, acpi_dev->physical_node_id_bitmap); physical_node->node_id = node_id;
physical_node->dev = dev; 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++; acpi_dev->physical_node_count++;
mutex_unlock(&acpi_dev->physical_node_lock); mutex_unlock(&acpi_dev->physical_node_lock);
...@@ -208,7 +278,7 @@ int acpi_unbind_one(struct device *dev) ...@@ -208,7 +278,7 @@ int acpi_unbind_one(struct device *dev)
mutex_lock(&acpi_dev->physical_node_lock); mutex_lock(&acpi_dev->physical_node_lock);
list_for_each_safe(node, next, &acpi_dev->physical_node_list) { 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, entry = list_entry(node, struct acpi_device_physical_node,
node); node);
...@@ -216,7 +286,6 @@ int acpi_unbind_one(struct device *dev) ...@@ -216,7 +286,6 @@ int acpi_unbind_one(struct device *dev)
continue; continue;
list_del(node); list_del(node);
clear_bit(entry->node_id, acpi_dev->physical_node_id_bitmap);
acpi_dev->physical_node_count--; acpi_dev->physical_node_count--;
......
...@@ -311,6 +311,8 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset) ...@@ -311,6 +311,8 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
dev->pnp.bus_id, dev->pnp.bus_id,
(u32) dev->wakeup.sleep_state); (u32) dev->wakeup.sleep_state);
mutex_lock(&dev->physical_node_lock);
if (!dev->physical_node_count) { if (!dev->physical_node_count) {
seq_printf(seq, "%c%-8s\n", seq_printf(seq, "%c%-8s\n",
dev->wakeup.flags.run_wake ? '*' : ' ', dev->wakeup.flags.run_wake ? '*' : ' ',
...@@ -338,6 +340,8 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset) ...@@ -338,6 +340,8 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
put_device(ldev); put_device(ldev);
} }
} }
mutex_unlock(&dev->physical_node_lock);
} }
mutex_unlock(&acpi_device_lock); mutex_unlock(&acpi_device_lock);
return 0; return 0;
...@@ -347,12 +351,16 @@ static void physical_device_enable_wakeup(struct acpi_device *adev) ...@@ -347,12 +351,16 @@ static void physical_device_enable_wakeup(struct acpi_device *adev)
{ {
struct acpi_device_physical_node *entry; struct acpi_device_physical_node *entry;
mutex_lock(&adev->physical_node_lock);
list_for_each_entry(entry, list_for_each_entry(entry,
&adev->physical_node_list, node) &adev->physical_node_list, node)
if (entry->dev && device_can_wakeup(entry->dev)) { if (entry->dev && device_can_wakeup(entry->dev)) {
bool enable = !device_may_wakeup(entry->dev); bool enable = !device_may_wakeup(entry->dev);
device_set_wakeup_enable(entry->dev, enable); device_set_wakeup_enable(entry->dev, enable);
} }
mutex_unlock(&adev->physical_node_lock);
} }
static ssize_t static ssize_t
......
...@@ -689,7 +689,7 @@ static int acpi_video_bqc_quirk(struct acpi_video_device *device, ...@@ -689,7 +689,7 @@ static int acpi_video_bqc_quirk(struct acpi_video_device *device,
* Some systems always report current brightness level as maximum * Some systems always report current brightness level as maximum
* through _BQC, we need to test another value for them. * 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); result = acpi_video_device_lcd_set_level(device, test_level);
if (result) if (result)
......
...@@ -317,13 +317,20 @@ void acpi_pci_remove_bus(struct pci_bus *bus) ...@@ -317,13 +317,20 @@ void acpi_pci_remove_bus(struct pci_bus *bus)
/* ACPI bus type */ /* ACPI bus type */
static int acpi_pci_find_device(struct device *dev, acpi_handle *handle) 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; 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 */ /* Please ref to ACPI spec for the syntax of _ADR */
addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn); 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) if (!*handle)
return -ENODEV; return -ENODEV;
return 0; return 0;
......
...@@ -274,15 +274,12 @@ struct acpi_device_wakeup { ...@@ -274,15 +274,12 @@ struct acpi_device_wakeup {
}; };
struct acpi_device_physical_node { struct acpi_device_physical_node {
u8 node_id; unsigned int node_id;
struct list_head node; struct list_head node;
struct device *dev; struct device *dev;
bool put_online:1; bool put_online:1;
}; };
/* set maximum of physical nodes to 32 for expansibility */
#define ACPI_MAX_PHYSICAL_NODE 32
/* Device */ /* Device */
struct acpi_device { struct acpi_device {
int device_type; int device_type;
...@@ -302,10 +299,9 @@ struct acpi_device { ...@@ -302,10 +299,9 @@ struct acpi_device {
struct acpi_driver *driver; struct acpi_driver *driver;
void *driver_data; void *driver_data;
struct device dev; struct device dev;
u8 physical_node_count; unsigned int physical_node_count;
struct list_head physical_node_list; struct list_head physical_node_list;
struct mutex physical_node_lock; struct mutex physical_node_lock;
DECLARE_BITMAP(physical_node_id_bitmap, ACPI_MAX_PHYSICAL_NODE);
struct list_head power_dependent; struct list_head power_dependent;
void (*remove)(struct acpi_device *); void (*remove)(struct acpi_device *);
}; };
...@@ -445,7 +441,11 @@ struct acpi_pci_root { ...@@ -445,7 +441,11 @@ struct acpi_pci_root {
}; };
/* helper */ /* helper */
acpi_handle acpi_get_child(acpi_handle, u64); acpi_handle acpi_find_child(acpi_handle, u64, bool);
static inline acpi_handle acpi_get_child(acpi_handle handle, u64 addr)
{
return acpi_find_child(handle, addr, false);
}
int acpi_is_root_bridge(acpi_handle); int acpi_is_root_bridge(acpi_handle);
struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle); struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle);
#define DEVICE_ACPI_HANDLE(dev) ((acpi_handle)ACPI_HANDLE(dev)) #define DEVICE_ACPI_HANDLE(dev) ((acpi_handle)ACPI_HANDLE(dev))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment