2005-03-19 02:45:35 +03:00
|
|
|
/*
|
|
|
|
* Link physical devices with ACPI devices support
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005 David Shaohua Li <shaohua.li@intel.com>
|
|
|
|
* Copyright (c) 2005 Intel Corp.
|
|
|
|
*
|
|
|
|
* This file is released under the GPLv2.
|
|
|
|
*/
|
2011-10-27 00:22:14 +04:00
|
|
|
#include <linux/export.h>
|
2005-03-19 02:45:35 +03:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/device.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2005-03-19 02:45:35 +03:00
|
|
|
#include <linux/rwsem.h>
|
|
|
|
#include <linux/acpi.h>
|
|
|
|
|
2009-07-29 00:45:54 +04:00
|
|
|
#include "internal.h"
|
|
|
|
|
2005-03-19 02:45:35 +03:00
|
|
|
#define ACPI_GLUE_DEBUG 0
|
|
|
|
#if ACPI_GLUE_DEBUG
|
|
|
|
#define DBG(x...) printk(PREFIX x)
|
|
|
|
#else
|
2007-07-09 22:33:14 +04:00
|
|
|
#define DBG(x...) do { } while(0)
|
2005-03-19 02:45:35 +03:00
|
|
|
#endif
|
|
|
|
static LIST_HEAD(bus_type_list);
|
|
|
|
static DECLARE_RWSEM(bus_type_sem);
|
|
|
|
|
2012-08-17 10:44:09 +04:00
|
|
|
#define PHYSICAL_NODE_STRING "physical_node"
|
|
|
|
|
2005-03-19 02:45:35 +03:00
|
|
|
int register_acpi_bus_type(struct acpi_bus_type *type)
|
|
|
|
{
|
|
|
|
if (acpi_disabled)
|
|
|
|
return -ENODEV;
|
|
|
|
if (type && type->bus && type->find_device) {
|
|
|
|
down_write(&bus_type_sem);
|
|
|
|
list_add_tail(&type->list, &bus_type_list);
|
|
|
|
up_write(&bus_type_sem);
|
2005-08-05 08:44:28 +04:00
|
|
|
printk(KERN_INFO PREFIX "bus type %s registered\n",
|
|
|
|
type->bus->name);
|
2005-03-19 02:45:35 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2012-07-25 22:24:13 +04:00
|
|
|
EXPORT_SYMBOL_GPL(register_acpi_bus_type);
|
2005-03-19 02:45:35 +03:00
|
|
|
|
|
|
|
int unregister_acpi_bus_type(struct acpi_bus_type *type)
|
|
|
|
{
|
|
|
|
if (acpi_disabled)
|
|
|
|
return 0;
|
|
|
|
if (type) {
|
|
|
|
down_write(&bus_type_sem);
|
|
|
|
list_del_init(&type->list);
|
|
|
|
up_write(&bus_type_sem);
|
2005-08-05 08:44:28 +04:00
|
|
|
printk(KERN_INFO PREFIX "ACPI bus type %s unregistered\n",
|
|
|
|
type->bus->name);
|
2005-03-19 02:45:35 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2012-07-25 22:24:13 +04:00
|
|
|
EXPORT_SYMBOL_GPL(unregister_acpi_bus_type);
|
2005-03-19 02:45:35 +03:00
|
|
|
|
|
|
|
static struct acpi_bus_type *acpi_get_bus_type(struct bus_type *type)
|
|
|
|
{
|
|
|
|
struct acpi_bus_type *tmp, *ret = NULL;
|
|
|
|
|
|
|
|
down_read(&bus_type_sem);
|
|
|
|
list_for_each_entry(tmp, &bus_type_list, list) {
|
|
|
|
if (tmp->bus == type) {
|
|
|
|
ret = tmp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
up_read(&bus_type_sem);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int acpi_find_bridge_device(struct device *dev, acpi_handle * handle)
|
|
|
|
{
|
|
|
|
struct acpi_bus_type *tmp;
|
|
|
|
int ret = -ENODEV;
|
|
|
|
|
|
|
|
down_read(&bus_type_sem);
|
|
|
|
list_for_each_entry(tmp, &bus_type_list, list) {
|
|
|
|
if (tmp->find_bridge && !tmp->find_bridge(dev, handle)) {
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
up_read(&bus_type_sem);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get device's handler per its address under its parent */
|
|
|
|
struct acpi_find_child {
|
|
|
|
acpi_handle handle;
|
2010-01-28 05:53:19 +03:00
|
|
|
u64 address;
|
2005-03-19 02:45:35 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static acpi_status
|
|
|
|
do_acpi_find_child(acpi_handle handle, u32 lvl, void *context, void **rv)
|
|
|
|
{
|
|
|
|
acpi_status status;
|
|
|
|
struct acpi_device_info *info;
|
2006-10-01 02:28:50 +04:00
|
|
|
struct acpi_find_child *find = context;
|
2005-03-19 02:45:35 +03:00
|
|
|
|
2009-06-29 09:39:29 +04:00
|
|
|
status = acpi_get_object_info(handle, &info);
|
2005-03-19 02:45:35 +03:00
|
|
|
if (ACPI_SUCCESS(status)) {
|
2010-07-13 07:36:08 +04:00
|
|
|
if ((info->address == find->address)
|
|
|
|
&& (info->valid & ACPI_VALID_ADR))
|
2005-03-19 02:45:35 +03:00
|
|
|
find->handle = handle;
|
2009-06-29 09:39:29 +04:00
|
|
|
kfree(info);
|
2005-03-19 02:45:35 +03:00
|
|
|
}
|
|
|
|
return AE_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-28 05:53:19 +03:00
|
|
|
acpi_handle acpi_get_child(acpi_handle parent, u64 address)
|
2005-03-19 02:45:35 +03:00
|
|
|
{
|
|
|
|
struct acpi_find_child find = { NULL, address };
|
|
|
|
|
|
|
|
if (!parent)
|
|
|
|
return NULL;
|
|
|
|
acpi_walk_namespace(ACPI_TYPE_DEVICE, parent,
|
2009-11-13 05:06:08 +03:00
|
|
|
1, do_acpi_find_child, NULL, &find, NULL);
|
2005-03-19 02:45:35 +03:00
|
|
|
return find.handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(acpi_get_child);
|
|
|
|
|
|
|
|
static int acpi_bind_one(struct device *dev, acpi_handle handle)
|
|
|
|
{
|
2008-02-23 08:54:24 +03:00
|
|
|
struct acpi_device *acpi_dev;
|
2005-03-19 02:45:35 +03:00
|
|
|
acpi_status status;
|
2012-11-21 03:21:39 +04:00
|
|
|
struct acpi_device_physical_node *physical_node, *pn;
|
2012-08-17 10:44:09 +04:00
|
|
|
char physical_node_name[sizeof(PHYSICAL_NODE_STRING) + 2];
|
|
|
|
int retval = -EINVAL;
|
2005-03-19 02:45:35 +03:00
|
|
|
|
2012-11-21 03:21:50 +04:00
|
|
|
if (ACPI_HANDLE(dev)) {
|
2012-11-21 03:21:39 +04:00
|
|
|
if (handle) {
|
|
|
|
dev_warn(dev, "ACPI handle is already set\n");
|
|
|
|
return -EINVAL;
|
|
|
|
} else {
|
2012-11-21 03:21:50 +04:00
|
|
|
handle = ACPI_HANDLE(dev);
|
2012-11-21 03:21:39 +04:00
|
|
|
}
|
2005-03-19 02:45:35 +03:00
|
|
|
}
|
2012-11-21 03:21:39 +04:00
|
|
|
if (!handle)
|
|
|
|
return -EINVAL;
|
2012-08-17 10:44:09 +04:00
|
|
|
|
2005-03-19 02:45:35 +03:00
|
|
|
get_device(dev);
|
2012-08-17 10:44:09 +04:00
|
|
|
status = acpi_bus_get_device(handle, &acpi_dev);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
goto err;
|
|
|
|
|
2012-11-21 03:21:39 +04:00
|
|
|
physical_node = kzalloc(sizeof(*physical_node), GFP_KERNEL);
|
2012-08-17 10:44:09 +04:00
|
|
|
if (!physical_node) {
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto err;
|
2005-03-19 02:45:35 +03:00
|
|
|
}
|
|
|
|
|
2012-08-17 10:44:09 +04:00
|
|
|
mutex_lock(&acpi_dev->physical_node_lock);
|
2012-11-21 03:21:39 +04:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2012-08-17 10:44:09 +04:00
|
|
|
/* 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;
|
2012-11-21 03:21:39 +04:00
|
|
|
goto err_free;
|
2008-02-23 08:54:24 +03:00
|
|
|
}
|
|
|
|
|
2012-08-17 10:44:09 +04:00
|
|
|
set_bit(physical_node->node_id, acpi_dev->physical_node_id_bitmap);
|
|
|
|
physical_node->dev = dev;
|
|
|
|
list_add_tail(&physical_node->node, &acpi_dev->physical_node_list);
|
|
|
|
acpi_dev->physical_node_count++;
|
2012-11-21 03:21:39 +04:00
|
|
|
|
2012-08-17 10:44:09 +04:00
|
|
|
mutex_unlock(&acpi_dev->physical_node_lock);
|
|
|
|
|
2012-11-21 03:21:50 +04:00
|
|
|
if (!ACPI_HANDLE(dev))
|
|
|
|
ACPI_HANDLE_SET(dev, acpi_dev->handle);
|
2012-08-17 10:44:09 +04:00
|
|
|
|
|
|
|
if (!physical_node->node_id)
|
|
|
|
strcpy(physical_node_name, PHYSICAL_NODE_STRING);
|
|
|
|
else
|
|
|
|
sprintf(physical_node_name,
|
|
|
|
"physical_node%d", physical_node->node_id);
|
|
|
|
retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
|
|
|
|
physical_node_name);
|
|
|
|
retval = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj,
|
|
|
|
"firmware_node");
|
|
|
|
|
|
|
|
if (acpi_dev->wakeup.flags.valid)
|
|
|
|
device_set_wakeup_capable(dev, true);
|
|
|
|
|
2005-03-19 02:45:35 +03:00
|
|
|
return 0;
|
2012-08-17 10:44:09 +04:00
|
|
|
|
|
|
|
err:
|
2012-11-21 03:21:50 +04:00
|
|
|
ACPI_HANDLE_SET(dev, NULL);
|
2012-08-17 10:44:09 +04:00
|
|
|
put_device(dev);
|
|
|
|
return retval;
|
2012-11-21 03:21:39 +04:00
|
|
|
|
|
|
|
err_free:
|
|
|
|
mutex_unlock(&acpi_dev->physical_node_lock);
|
|
|
|
kfree(physical_node);
|
|
|
|
goto err;
|
2005-03-19 02:45:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int acpi_unbind_one(struct device *dev)
|
|
|
|
{
|
2012-08-17 10:44:09 +04:00
|
|
|
struct acpi_device_physical_node *entry;
|
|
|
|
struct acpi_device *acpi_dev;
|
|
|
|
acpi_status status;
|
|
|
|
struct list_head *node, *next;
|
|
|
|
|
2012-11-21 03:21:50 +04:00
|
|
|
if (!ACPI_HANDLE(dev))
|
2005-03-19 02:45:35 +03:00
|
|
|
return 0;
|
2008-02-23 08:54:24 +03:00
|
|
|
|
2012-11-21 03:21:50 +04:00
|
|
|
status = acpi_bus_get_device(ACPI_HANDLE(dev), &acpi_dev);
|
2012-08-17 10:44:09 +04:00
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
goto err;
|
2008-02-23 08:54:24 +03:00
|
|
|
|
2012-08-17 10:44:09 +04:00
|
|
|
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];
|
|
|
|
|
|
|
|
entry = list_entry(node, struct acpi_device_physical_node,
|
|
|
|
node);
|
|
|
|
if (entry->dev != dev)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
list_del(node);
|
|
|
|
clear_bit(entry->node_id, acpi_dev->physical_node_id_bitmap);
|
2008-02-23 08:54:24 +03:00
|
|
|
|
2012-08-17 10:44:09 +04:00
|
|
|
acpi_dev->physical_node_count--;
|
|
|
|
|
|
|
|
if (!entry->node_id)
|
|
|
|
strcpy(physical_node_name, PHYSICAL_NODE_STRING);
|
|
|
|
else
|
|
|
|
sprintf(physical_node_name,
|
|
|
|
"physical_node%d", entry->node_id);
|
|
|
|
|
|
|
|
sysfs_remove_link(&acpi_dev->dev.kobj, physical_node_name);
|
|
|
|
sysfs_remove_link(&dev->kobj, "firmware_node");
|
2012-11-21 03:21:50 +04:00
|
|
|
ACPI_HANDLE_SET(dev, NULL);
|
2005-03-19 02:45:35 +03:00
|
|
|
/* acpi_bind_one increase refcnt by one */
|
|
|
|
put_device(dev);
|
2012-08-17 10:44:09 +04:00
|
|
|
kfree(entry);
|
2005-03-19 02:45:35 +03:00
|
|
|
}
|
2012-08-17 10:44:09 +04:00
|
|
|
mutex_unlock(&acpi_dev->physical_node_lock);
|
|
|
|
|
2005-03-19 02:45:35 +03:00
|
|
|
return 0;
|
2012-08-17 10:44:09 +04:00
|
|
|
|
|
|
|
err:
|
|
|
|
dev_err(dev, "Oops, 'acpi_handle' corrupt\n");
|
|
|
|
return -EINVAL;
|
2005-03-19 02:45:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int acpi_platform_notify(struct device *dev)
|
|
|
|
{
|
|
|
|
struct acpi_bus_type *type;
|
|
|
|
acpi_handle handle;
|
|
|
|
int ret = -EINVAL;
|
|
|
|
|
2012-11-21 03:21:39 +04:00
|
|
|
ret = acpi_bind_one(dev, NULL);
|
|
|
|
if (!ret)
|
|
|
|
goto out;
|
|
|
|
|
2005-03-19 02:45:35 +03:00
|
|
|
if (!dev->bus || !dev->parent) {
|
|
|
|
/* bridge devices genernally haven't bus or parent */
|
|
|
|
ret = acpi_find_bridge_device(dev, &handle);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
type = acpi_get_bus_type(dev->bus);
|
|
|
|
if (!type) {
|
2009-01-26 01:40:56 +03:00
|
|
|
DBG("No ACPI bus support for %s\n", dev_name(dev));
|
2005-03-19 02:45:35 +03:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if ((ret = type->find_device(dev, &handle)) != 0)
|
2009-01-26 01:40:56 +03:00
|
|
|
DBG("Can't get handler for %s\n", dev_name(dev));
|
2012-11-21 03:21:39 +04:00
|
|
|
end:
|
2005-03-19 02:45:35 +03:00
|
|
|
if (!ret)
|
|
|
|
acpi_bind_one(dev, handle);
|
|
|
|
|
2012-11-21 03:21:39 +04:00
|
|
|
out:
|
2005-03-19 02:45:35 +03:00
|
|
|
#if ACPI_GLUE_DEBUG
|
|
|
|
if (!ret) {
|
|
|
|
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
|
|
|
|
|
driver core / ACPI: Move ACPI support to core device and driver types
With ACPI 5 we are starting to see devices that don't natively support
discovery but can be enumerated with the help of the ACPI namespace.
Typically, these devices can be represented in the Linux device driver
model as platform devices or some serial bus devices, like SPI or I2C
devices.
Since we want to re-use existing drivers for those devices, we need a
way for drivers to specify the ACPI IDs of supported devices, so that
they can be matched against device nodes in the ACPI namespace. To
this end, it is sufficient to add a pointer to an array of supported
ACPI device IDs, that can be provided by the driver, to struct device.
Moreover, things like ACPI power management need to have access to
the ACPI handle of each supported device, because that handle is used
to invoke AML methods associated with the corresponding ACPI device
node. The ACPI handles of devices are now stored in the archdata
member structure of struct device whose definition depends on the
architecture and includes the ACPI handle only on x86 and ia64. Since
the pointer to an array of supported ACPI IDs is added to struct
device_driver in an architecture-independent way, it is logical to
move the ACPI handle from archdata to struct device itself at the same
time. This also makes code more straightforward in some places and
follows the example of Device Trees that have a poiter to struct
device_node in there too.
This changeset is based on Mika Westerberg's work.
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: H. Peter Anvin <hpa@zytor.com>
Acked-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2012-11-01 01:44:33 +04:00
|
|
|
acpi_get_name(dev->acpi_handle, ACPI_FULL_PATHNAME, &buffer);
|
2009-01-26 01:40:56 +03:00
|
|
|
DBG("Device %s -> %s\n", dev_name(dev), (char *)buffer.pointer);
|
2006-06-30 11:19:10 +04:00
|
|
|
kfree(buffer.pointer);
|
2005-03-19 02:45:35 +03:00
|
|
|
} else
|
2009-01-26 01:40:56 +03:00
|
|
|
DBG("Device %s -> No ACPI support\n", dev_name(dev));
|
2005-03-19 02:45:35 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int acpi_platform_notify_remove(struct device *dev)
|
|
|
|
{
|
|
|
|
acpi_unbind_one(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-25 01:50:09 +03:00
|
|
|
int __init init_acpi_device_notify(void)
|
2005-03-19 02:45:35 +03:00
|
|
|
{
|
|
|
|
if (platform_notify || platform_notify_remove) {
|
|
|
|
printk(KERN_ERR PREFIX "Can't use platform_notify\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
platform_notify = acpi_platform_notify;
|
|
|
|
platform_notify_remove = acpi_platform_notify_remove;
|
|
|
|
return 0;
|
|
|
|
}
|