2005-03-18 23:45:35 +00: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-26 20:22:14 +00:00
|
|
|
#include <linux/export.h>
|
2005-03-18 23:45:35 +00: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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2005-03-18 23:45:35 +00:00
|
|
|
#include <linux/rwsem.h>
|
|
|
|
#include <linux/acpi.h>
|
|
|
|
|
2009-07-28 20:45:54 +00:00
|
|
|
#include "internal.h"
|
|
|
|
|
2005-03-18 23:45:35 +00:00
|
|
|
#define ACPI_GLUE_DEBUG 0
|
|
|
|
#if ACPI_GLUE_DEBUG
|
2012-12-18 06:31:30 +00:00
|
|
|
#define DBG(fmt, ...) \
|
|
|
|
printk(KERN_DEBUG PREFIX fmt, ##__VA_ARGS__)
|
2005-03-18 23:45:35 +00:00
|
|
|
#else
|
2012-12-18 06:31:30 +00:00
|
|
|
#define DBG(fmt, ...) \
|
|
|
|
do { \
|
|
|
|
if (0) \
|
|
|
|
printk(KERN_DEBUG PREFIX fmt, ##__VA_ARGS__); \
|
|
|
|
} while (0)
|
2005-03-18 23:45:35 +00:00
|
|
|
#endif
|
|
|
|
static LIST_HEAD(bus_type_list);
|
|
|
|
static DECLARE_RWSEM(bus_type_sem);
|
|
|
|
|
2012-08-17 06:44:09 +00:00
|
|
|
#define PHYSICAL_NODE_STRING "physical_node"
|
2013-08-06 12:32:54 +00:00
|
|
|
#define PHYSICAL_NODE_NAME_SIZE (sizeof(PHYSICAL_NODE_STRING) + 10)
|
2012-08-17 06:44:09 +00:00
|
|
|
|
2005-03-18 23:45:35 +00:00
|
|
|
int register_acpi_bus_type(struct acpi_bus_type *type)
|
|
|
|
{
|
|
|
|
if (acpi_disabled)
|
|
|
|
return -ENODEV;
|
2013-03-03 21:35:20 +00:00
|
|
|
if (type && type->match && type->find_device) {
|
2005-03-18 23:45:35 +00:00
|
|
|
down_write(&bus_type_sem);
|
|
|
|
list_add_tail(&type->list, &bus_type_list);
|
|
|
|
up_write(&bus_type_sem);
|
2013-03-03 21:35:20 +00:00
|
|
|
printk(KERN_INFO PREFIX "bus type %s registered\n", type->name);
|
2005-03-18 23:45:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2012-07-25 18:24:13 +00:00
|
|
|
EXPORT_SYMBOL_GPL(register_acpi_bus_type);
|
2005-03-18 23:45:35 +00: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);
|
2013-03-03 21:35:20 +00:00
|
|
|
printk(KERN_INFO PREFIX "bus type %s unregistered\n",
|
|
|
|
type->name);
|
2005-03-18 23:45:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2012-07-25 18:24:13 +00:00
|
|
|
EXPORT_SYMBOL_GPL(unregister_acpi_bus_type);
|
2005-03-18 23:45:35 +00:00
|
|
|
|
2013-03-03 21:35:20 +00:00
|
|
|
static struct acpi_bus_type *acpi_get_bus_type(struct device *dev)
|
2005-03-18 23:45:35 +00:00
|
|
|
{
|
|
|
|
struct acpi_bus_type *tmp, *ret = NULL;
|
|
|
|
|
|
|
|
down_read(&bus_type_sem);
|
|
|
|
list_for_each_entry(tmp, &bus_type_list, list) {
|
2013-03-03 21:35:20 +00:00
|
|
|
if (tmp->match(dev)) {
|
2005-03-18 23:45:35 +00:00
|
|
|
ret = tmp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
up_read(&bus_type_sem);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
ACPI: Try harder to resolve _ADR collisions for bridges
In theory, under a given ACPI namespace node there should be only
one child device object with _ADR whose value matches a given bus
address exactly. In practice, however, there are systems in which
multiple child device objects under a given parent have _ADR matching
exactly the same address. In those cases we use _STA to determine
which of the multiple matching devices is enabled, since some systems
are known to indicate which ACPI device object to associate with the
given physical (usually PCI) device this way.
Unfortunately, as it turns out, there are systems in which many
device objects under the same parent have _ADR matching exactly the
same bus address and none of them has _STA, in which case they all
should be regarded as enabled according to the spec. Still, if
those device objects are supposed to represent bridges (e.g. this
is the case for device objects corresponding to PCIe ports), we can
try harder and skip the ones that have no child device objects in the
ACPI namespace. With luck, we can avoid using device objects that we
are not expected to use this way.
Although this only works for bridges whose children also have ACPI
namespace representation, it is sufficient to address graphics
adapter detection issues on some systems, so rework the code finding
a matching device ACPI handle for a given bus address to implement
this idea.
Introduce a new function, acpi_find_child(), taking three arguments:
the ACPI handle of the device's parent, a bus address suitable for
the device's bus type and a bool indicating if the device is a
bridge and make it work as outlined above. Reimplement the function
currently used for this purpose, acpi_get_child(), as a call to
acpi_find_child() with the last argument set to 'false' and make
the PCI subsystem use acpi_find_child() with the bridge information
passed as the last argument to it. [Lan Tianyu notices that it is
not sufficient to use pci_is_bridge() for that, because the device's
subordinate pointer hasn't been set yet at this point, so use
hdr_type instead.]
This change fixes a regression introduced inadvertently by commit
33f767d (ACPI: Rework acpi_get_child() to be more efficient) which
overlooked the fact that for acpi_walk_namespace() "post-order" means
"after all children have been visited" rather than "on the way back",
so for device objects without children and for namespace walks of
depth 1, as in the acpi_get_child() case, the "post-order" callbacks
ordering is actually the same as the ordering of "pre-order" ones.
Since that commit changed the namespace walk in acpi_get_child() to
terminate after finding the first matching object instead of going
through all of them and returning the last one, it effectively
changed the result returned by that function in some rare cases and
that led to problems (the switch from a "pre-order" to a "post-order"
callback was supposed to prevent that from happening, but it was
ineffective).
As it turns out, the systems where the change made by commit
33f767d actually matters are those where there are multiple ACPI
device objects representing the same PCIe port (which effectively
is a bridge). Moreover, only one of them, and the one we are
expected to use, has child device objects in the ACPI namespace,
so the regression can be addressed as described above.
References: https://bugzilla.kernel.org/show_bug.cgi?id=60561
Reported-by: Peter Wu <lekensteyn@gmail.com>
Tested-by: Vladimir Lalov <mail@vlalov.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: 3.9+ <stable@vger.kernel.org> # 3.9+
2013-08-07 20:55:00 +00:00
|
|
|
static acpi_status acpi_dev_present(acpi_handle handle, u32 lvl_not_used,
|
|
|
|
void *not_used, void **ret_p)
|
2005-03-18 23:45:35 +00:00
|
|
|
{
|
ACPI: Try harder to resolve _ADR collisions for bridges
In theory, under a given ACPI namespace node there should be only
one child device object with _ADR whose value matches a given bus
address exactly. In practice, however, there are systems in which
multiple child device objects under a given parent have _ADR matching
exactly the same address. In those cases we use _STA to determine
which of the multiple matching devices is enabled, since some systems
are known to indicate which ACPI device object to associate with the
given physical (usually PCI) device this way.
Unfortunately, as it turns out, there are systems in which many
device objects under the same parent have _ADR matching exactly the
same bus address and none of them has _STA, in which case they all
should be regarded as enabled according to the spec. Still, if
those device objects are supposed to represent bridges (e.g. this
is the case for device objects corresponding to PCIe ports), we can
try harder and skip the ones that have no child device objects in the
ACPI namespace. With luck, we can avoid using device objects that we
are not expected to use this way.
Although this only works for bridges whose children also have ACPI
namespace representation, it is sufficient to address graphics
adapter detection issues on some systems, so rework the code finding
a matching device ACPI handle for a given bus address to implement
this idea.
Introduce a new function, acpi_find_child(), taking three arguments:
the ACPI handle of the device's parent, a bus address suitable for
the device's bus type and a bool indicating if the device is a
bridge and make it work as outlined above. Reimplement the function
currently used for this purpose, acpi_get_child(), as a call to
acpi_find_child() with the last argument set to 'false' and make
the PCI subsystem use acpi_find_child() with the bridge information
passed as the last argument to it. [Lan Tianyu notices that it is
not sufficient to use pci_is_bridge() for that, because the device's
subordinate pointer hasn't been set yet at this point, so use
hdr_type instead.]
This change fixes a regression introduced inadvertently by commit
33f767d (ACPI: Rework acpi_get_child() to be more efficient) which
overlooked the fact that for acpi_walk_namespace() "post-order" means
"after all children have been visited" rather than "on the way back",
so for device objects without children and for namespace walks of
depth 1, as in the acpi_get_child() case, the "post-order" callbacks
ordering is actually the same as the ordering of "pre-order" ones.
Since that commit changed the namespace walk in acpi_get_child() to
terminate after finding the first matching object instead of going
through all of them and returning the last one, it effectively
changed the result returned by that function in some rare cases and
that led to problems (the switch from a "pre-order" to a "post-order"
callback was supposed to prevent that from happening, but it was
ineffective).
As it turns out, the systems where the change made by commit
33f767d actually matters are those where there are multiple ACPI
device objects representing the same PCIe port (which effectively
is a bridge). Moreover, only one of them, and the one we are
expected to use, has child device objects in the ACPI namespace,
so the regression can be addressed as described above.
References: https://bugzilla.kernel.org/show_bug.cgi?id=60561
Reported-by: Peter Wu <lekensteyn@gmail.com>
Tested-by: Vladimir Lalov <mail@vlalov.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: 3.9+ <stable@vger.kernel.org> # 3.9+
2013-08-07 20:55:00 +00:00
|
|
|
struct acpi_device *adev = NULL;
|
|
|
|
|
|
|
|
acpi_bus_get_device(handle, &adev);
|
|
|
|
if (adev) {
|
|
|
|
*ret_p = handle;
|
|
|
|
return AE_CTRL_TERMINATE;
|
|
|
|
}
|
|
|
|
return AE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool acpi_extra_checks_passed(acpi_handle handle, bool is_bridge)
|
|
|
|
{
|
|
|
|
unsigned long long sta;
|
|
|
|
acpi_status status;
|
|
|
|
|
|
|
|
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;
|
2005-03-18 23:45:35 +00:00
|
|
|
acpi_status status;
|
2013-01-10 12:13:49 +00:00
|
|
|
|
|
|
|
status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &addr);
|
ACPI: Try harder to resolve _ADR collisions for bridges
In theory, under a given ACPI namespace node there should be only
one child device object with _ADR whose value matches a given bus
address exactly. In practice, however, there are systems in which
multiple child device objects under a given parent have _ADR matching
exactly the same address. In those cases we use _STA to determine
which of the multiple matching devices is enabled, since some systems
are known to indicate which ACPI device object to associate with the
given physical (usually PCI) device this way.
Unfortunately, as it turns out, there are systems in which many
device objects under the same parent have _ADR matching exactly the
same bus address and none of them has _STA, in which case they all
should be regarded as enabled according to the spec. Still, if
those device objects are supposed to represent bridges (e.g. this
is the case for device objects corresponding to PCIe ports), we can
try harder and skip the ones that have no child device objects in the
ACPI namespace. With luck, we can avoid using device objects that we
are not expected to use this way.
Although this only works for bridges whose children also have ACPI
namespace representation, it is sufficient to address graphics
adapter detection issues on some systems, so rework the code finding
a matching device ACPI handle for a given bus address to implement
this idea.
Introduce a new function, acpi_find_child(), taking three arguments:
the ACPI handle of the device's parent, a bus address suitable for
the device's bus type and a bool indicating if the device is a
bridge and make it work as outlined above. Reimplement the function
currently used for this purpose, acpi_get_child(), as a call to
acpi_find_child() with the last argument set to 'false' and make
the PCI subsystem use acpi_find_child() with the bridge information
passed as the last argument to it. [Lan Tianyu notices that it is
not sufficient to use pci_is_bridge() for that, because the device's
subordinate pointer hasn't been set yet at this point, so use
hdr_type instead.]
This change fixes a regression introduced inadvertently by commit
33f767d (ACPI: Rework acpi_get_child() to be more efficient) which
overlooked the fact that for acpi_walk_namespace() "post-order" means
"after all children have been visited" rather than "on the way back",
so for device objects without children and for namespace walks of
depth 1, as in the acpi_get_child() case, the "post-order" callbacks
ordering is actually the same as the ordering of "pre-order" ones.
Since that commit changed the namespace walk in acpi_get_child() to
terminate after finding the first matching object instead of going
through all of them and returning the last one, it effectively
changed the result returned by that function in some rare cases and
that led to problems (the switch from a "pre-order" to a "post-order"
callback was supposed to prevent that from happening, but it was
ineffective).
As it turns out, the systems where the change made by commit
33f767d actually matters are those where there are multiple ACPI
device objects representing the same PCIe port (which effectively
is a bridge). Moreover, only one of them, and the one we are
expected to use, has child device objects in the ACPI namespace,
so the regression can be addressed as described above.
References: https://bugzilla.kernel.org/show_bug.cgi?id=60561
Reported-by: Peter Wu <lekensteyn@gmail.com>
Tested-by: Vladimir Lalov <mail@vlalov.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: 3.9+ <stable@vger.kernel.org> # 3.9+
2013-08-07 20:55:00 +00:00
|
|
|
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))
|
ACPI: add _STA evaluation at do_acpi_find_child()
Once do_acpi_find_child() has found the first matching handle, it
makes the acpi_get_child() loop stop and return that handle. On some
platforms, though, there are multiple devices with the same value of
"_ADR" in the same namespace scope, and if one of them is enabled,
the others will be disabled. For example:
Address : 0x1FFFF ; path : SB_PCI0.SATA.DEV0
Address : 0x1FFFF ; path : SB_PCI0.SATA.DEV1
Address : 0x1FFFF ; path : SB_PCI0.SATA.DEV2
If DEV0 and DEV1 are disabled and DEV2 is enabled, the handle of DEV2
should be returned, but actually the function always returns the
handle of DEV0.
To address that issue, make do_acpi_find_child() evaluate _STA to
check the device status. If a matching device object exists, but is
disabled, acpi_get_child() will continue to walk the namespace in the
hope of finding an enabled one. If one is found, its handle will be
returned, but otherwise the function will return the handle of the
disabled object found before (in case it is enabled going forward).
[rjw: Changelog]
Signed-off-by: Jeff Wu <zlinuxkernel@gmail.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2013-05-29 06:31:30 +00:00
|
|
|
return AE_CTRL_TERMINATE;
|
ACPI: Try harder to resolve _ADR collisions for bridges
In theory, under a given ACPI namespace node there should be only
one child device object with _ADR whose value matches a given bus
address exactly. In practice, however, there are systems in which
multiple child device objects under a given parent have _ADR matching
exactly the same address. In those cases we use _STA to determine
which of the multiple matching devices is enabled, since some systems
are known to indicate which ACPI device object to associate with the
given physical (usually PCI) device this way.
Unfortunately, as it turns out, there are systems in which many
device objects under the same parent have _ADR matching exactly the
same bus address and none of them has _STA, in which case they all
should be regarded as enabled according to the spec. Still, if
those device objects are supposed to represent bridges (e.g. this
is the case for device objects corresponding to PCIe ports), we can
try harder and skip the ones that have no child device objects in the
ACPI namespace. With luck, we can avoid using device objects that we
are not expected to use this way.
Although this only works for bridges whose children also have ACPI
namespace representation, it is sufficient to address graphics
adapter detection issues on some systems, so rework the code finding
a matching device ACPI handle for a given bus address to implement
this idea.
Introduce a new function, acpi_find_child(), taking three arguments:
the ACPI handle of the device's parent, a bus address suitable for
the device's bus type and a bool indicating if the device is a
bridge and make it work as outlined above. Reimplement the function
currently used for this purpose, acpi_get_child(), as a call to
acpi_find_child() with the last argument set to 'false' and make
the PCI subsystem use acpi_find_child() with the bridge information
passed as the last argument to it. [Lan Tianyu notices that it is
not sufficient to use pci_is_bridge() for that, because the device's
subordinate pointer hasn't been set yet at this point, so use
hdr_type instead.]
This change fixes a regression introduced inadvertently by commit
33f767d (ACPI: Rework acpi_get_child() to be more efficient) which
overlooked the fact that for acpi_walk_namespace() "post-order" means
"after all children have been visited" rather than "on the way back",
so for device objects without children and for namespace walks of
depth 1, as in the acpi_get_child() case, the "post-order" callbacks
ordering is actually the same as the ordering of "pre-order" ones.
Since that commit changed the namespace walk in acpi_get_child() to
terminate after finding the first matching object instead of going
through all of them and returning the last one, it effectively
changed the result returned by that function in some rare cases and
that led to problems (the switch from a "pre-order" to a "post-order"
callback was supposed to prevent that from happening, but it was
ineffective).
As it turns out, the systems where the change made by commit
33f767d actually matters are those where there are multiple ACPI
device objects representing the same PCIe port (which effectively
is a bridge). Moreover, only one of them, and the one we are
expected to use, has child device objects in the ACPI namespace,
so the regression can be addressed as described above.
References: https://bugzilla.kernel.org/show_bug.cgi?id=60561
Reported-by: Peter Wu <lekensteyn@gmail.com>
Tested-by: Vladimir Lalov <mail@vlalov.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: 3.9+ <stable@vger.kernel.org> # 3.9+
2013-08-07 20:55:00 +00:00
|
|
|
else
|
|
|
|
context->ret_checked = true;
|
|
|
|
}
|
|
|
|
if (acpi_extra_checks_passed(handle, context->is_bridge)) {
|
|
|
|
context->ret = handle;
|
|
|
|
return AE_CTRL_TERMINATE;
|
2005-03-18 23:45:35 +00:00
|
|
|
}
|
|
|
|
return AE_OK;
|
|
|
|
}
|
|
|
|
|
ACPI: Try harder to resolve _ADR collisions for bridges
In theory, under a given ACPI namespace node there should be only
one child device object with _ADR whose value matches a given bus
address exactly. In practice, however, there are systems in which
multiple child device objects under a given parent have _ADR matching
exactly the same address. In those cases we use _STA to determine
which of the multiple matching devices is enabled, since some systems
are known to indicate which ACPI device object to associate with the
given physical (usually PCI) device this way.
Unfortunately, as it turns out, there are systems in which many
device objects under the same parent have _ADR matching exactly the
same bus address and none of them has _STA, in which case they all
should be regarded as enabled according to the spec. Still, if
those device objects are supposed to represent bridges (e.g. this
is the case for device objects corresponding to PCIe ports), we can
try harder and skip the ones that have no child device objects in the
ACPI namespace. With luck, we can avoid using device objects that we
are not expected to use this way.
Although this only works for bridges whose children also have ACPI
namespace representation, it is sufficient to address graphics
adapter detection issues on some systems, so rework the code finding
a matching device ACPI handle for a given bus address to implement
this idea.
Introduce a new function, acpi_find_child(), taking three arguments:
the ACPI handle of the device's parent, a bus address suitable for
the device's bus type and a bool indicating if the device is a
bridge and make it work as outlined above. Reimplement the function
currently used for this purpose, acpi_get_child(), as a call to
acpi_find_child() with the last argument set to 'false' and make
the PCI subsystem use acpi_find_child() with the bridge information
passed as the last argument to it. [Lan Tianyu notices that it is
not sufficient to use pci_is_bridge() for that, because the device's
subordinate pointer hasn't been set yet at this point, so use
hdr_type instead.]
This change fixes a regression introduced inadvertently by commit
33f767d (ACPI: Rework acpi_get_child() to be more efficient) which
overlooked the fact that for acpi_walk_namespace() "post-order" means
"after all children have been visited" rather than "on the way back",
so for device objects without children and for namespace walks of
depth 1, as in the acpi_get_child() case, the "post-order" callbacks
ordering is actually the same as the ordering of "pre-order" ones.
Since that commit changed the namespace walk in acpi_get_child() to
terminate after finding the first matching object instead of going
through all of them and returning the last one, it effectively
changed the result returned by that function in some rare cases and
that led to problems (the switch from a "pre-order" to a "post-order"
callback was supposed to prevent that from happening, but it was
ineffective).
As it turns out, the systems where the change made by commit
33f767d actually matters are those where there are multiple ACPI
device objects representing the same PCIe port (which effectively
is a bridge). Moreover, only one of them, and the one we are
expected to use, has child device objects in the ACPI namespace,
so the regression can be addressed as described above.
References: https://bugzilla.kernel.org/show_bug.cgi?id=60561
Reported-by: Peter Wu <lekensteyn@gmail.com>
Tested-by: Vladimir Lalov <mail@vlalov.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: 3.9+ <stable@vger.kernel.org> # 3.9+
2013-08-07 20:55:00 +00:00
|
|
|
acpi_handle acpi_find_child(acpi_handle parent, u64 addr, bool is_bridge)
|
2005-03-18 23:45:35 +00:00
|
|
|
{
|
ACPI: Try harder to resolve _ADR collisions for bridges
In theory, under a given ACPI namespace node there should be only
one child device object with _ADR whose value matches a given bus
address exactly. In practice, however, there are systems in which
multiple child device objects under a given parent have _ADR matching
exactly the same address. In those cases we use _STA to determine
which of the multiple matching devices is enabled, since some systems
are known to indicate which ACPI device object to associate with the
given physical (usually PCI) device this way.
Unfortunately, as it turns out, there are systems in which many
device objects under the same parent have _ADR matching exactly the
same bus address and none of them has _STA, in which case they all
should be regarded as enabled according to the spec. Still, if
those device objects are supposed to represent bridges (e.g. this
is the case for device objects corresponding to PCIe ports), we can
try harder and skip the ones that have no child device objects in the
ACPI namespace. With luck, we can avoid using device objects that we
are not expected to use this way.
Although this only works for bridges whose children also have ACPI
namespace representation, it is sufficient to address graphics
adapter detection issues on some systems, so rework the code finding
a matching device ACPI handle for a given bus address to implement
this idea.
Introduce a new function, acpi_find_child(), taking three arguments:
the ACPI handle of the device's parent, a bus address suitable for
the device's bus type and a bool indicating if the device is a
bridge and make it work as outlined above. Reimplement the function
currently used for this purpose, acpi_get_child(), as a call to
acpi_find_child() with the last argument set to 'false' and make
the PCI subsystem use acpi_find_child() with the bridge information
passed as the last argument to it. [Lan Tianyu notices that it is
not sufficient to use pci_is_bridge() for that, because the device's
subordinate pointer hasn't been set yet at this point, so use
hdr_type instead.]
This change fixes a regression introduced inadvertently by commit
33f767d (ACPI: Rework acpi_get_child() to be more efficient) which
overlooked the fact that for acpi_walk_namespace() "post-order" means
"after all children have been visited" rather than "on the way back",
so for device objects without children and for namespace walks of
depth 1, as in the acpi_get_child() case, the "post-order" callbacks
ordering is actually the same as the ordering of "pre-order" ones.
Since that commit changed the namespace walk in acpi_get_child() to
terminate after finding the first matching object instead of going
through all of them and returning the last one, it effectively
changed the result returned by that function in some rare cases and
that led to problems (the switch from a "pre-order" to a "post-order"
callback was supposed to prevent that from happening, but it was
ineffective).
As it turns out, the systems where the change made by commit
33f767d actually matters are those where there are multiple ACPI
device objects representing the same PCIe port (which effectively
is a bridge). Moreover, only one of them, and the one we are
expected to use, has child device objects in the ACPI namespace,
so the regression can be addressed as described above.
References: https://bugzilla.kernel.org/show_bug.cgi?id=60561
Reported-by: Peter Wu <lekensteyn@gmail.com>
Tested-by: Vladimir Lalov <mail@vlalov.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: 3.9+ <stable@vger.kernel.org> # 3.9+
2013-08-07 20:55:00 +00:00
|
|
|
if (parent) {
|
|
|
|
struct find_child_context context = {
|
|
|
|
.addr = addr,
|
|
|
|
.is_bridge = is_bridge,
|
|
|
|
};
|
2005-03-18 23:45:35 +00:00
|
|
|
|
ACPI: Try harder to resolve _ADR collisions for bridges
In theory, under a given ACPI namespace node there should be only
one child device object with _ADR whose value matches a given bus
address exactly. In practice, however, there are systems in which
multiple child device objects under a given parent have _ADR matching
exactly the same address. In those cases we use _STA to determine
which of the multiple matching devices is enabled, since some systems
are known to indicate which ACPI device object to associate with the
given physical (usually PCI) device this way.
Unfortunately, as it turns out, there are systems in which many
device objects under the same parent have _ADR matching exactly the
same bus address and none of them has _STA, in which case they all
should be regarded as enabled according to the spec. Still, if
those device objects are supposed to represent bridges (e.g. this
is the case for device objects corresponding to PCIe ports), we can
try harder and skip the ones that have no child device objects in the
ACPI namespace. With luck, we can avoid using device objects that we
are not expected to use this way.
Although this only works for bridges whose children also have ACPI
namespace representation, it is sufficient to address graphics
adapter detection issues on some systems, so rework the code finding
a matching device ACPI handle for a given bus address to implement
this idea.
Introduce a new function, acpi_find_child(), taking three arguments:
the ACPI handle of the device's parent, a bus address suitable for
the device's bus type and a bool indicating if the device is a
bridge and make it work as outlined above. Reimplement the function
currently used for this purpose, acpi_get_child(), as a call to
acpi_find_child() with the last argument set to 'false' and make
the PCI subsystem use acpi_find_child() with the bridge information
passed as the last argument to it. [Lan Tianyu notices that it is
not sufficient to use pci_is_bridge() for that, because the device's
subordinate pointer hasn't been set yet at this point, so use
hdr_type instead.]
This change fixes a regression introduced inadvertently by commit
33f767d (ACPI: Rework acpi_get_child() to be more efficient) which
overlooked the fact that for acpi_walk_namespace() "post-order" means
"after all children have been visited" rather than "on the way back",
so for device objects without children and for namespace walks of
depth 1, as in the acpi_get_child() case, the "post-order" callbacks
ordering is actually the same as the ordering of "pre-order" ones.
Since that commit changed the namespace walk in acpi_get_child() to
terminate after finding the first matching object instead of going
through all of them and returning the last one, it effectively
changed the result returned by that function in some rare cases and
that led to problems (the switch from a "pre-order" to a "post-order"
callback was supposed to prevent that from happening, but it was
ineffective).
As it turns out, the systems where the change made by commit
33f767d actually matters are those where there are multiple ACPI
device objects representing the same PCIe port (which effectively
is a bridge). Moreover, only one of them, and the one we are
expected to use, has child device objects in the ACPI namespace,
so the regression can be addressed as described above.
References: https://bugzilla.kernel.org/show_bug.cgi?id=60561
Reported-by: Peter Wu <lekensteyn@gmail.com>
Tested-by: Vladimir Lalov <mail@vlalov.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: 3.9+ <stable@vger.kernel.org> # 3.9+
2013-08-07 20:55:00 +00:00
|
|
|
acpi_walk_namespace(ACPI_TYPE_DEVICE, parent, 1, do_find_child,
|
|
|
|
NULL, &context, NULL);
|
|
|
|
return context.ret;
|
|
|
|
}
|
|
|
|
return NULL;
|
2013-01-10 12:13:49 +00:00
|
|
|
}
|
ACPI: Try harder to resolve _ADR collisions for bridges
In theory, under a given ACPI namespace node there should be only
one child device object with _ADR whose value matches a given bus
address exactly. In practice, however, there are systems in which
multiple child device objects under a given parent have _ADR matching
exactly the same address. In those cases we use _STA to determine
which of the multiple matching devices is enabled, since some systems
are known to indicate which ACPI device object to associate with the
given physical (usually PCI) device this way.
Unfortunately, as it turns out, there are systems in which many
device objects under the same parent have _ADR matching exactly the
same bus address and none of them has _STA, in which case they all
should be regarded as enabled according to the spec. Still, if
those device objects are supposed to represent bridges (e.g. this
is the case for device objects corresponding to PCIe ports), we can
try harder and skip the ones that have no child device objects in the
ACPI namespace. With luck, we can avoid using device objects that we
are not expected to use this way.
Although this only works for bridges whose children also have ACPI
namespace representation, it is sufficient to address graphics
adapter detection issues on some systems, so rework the code finding
a matching device ACPI handle for a given bus address to implement
this idea.
Introduce a new function, acpi_find_child(), taking three arguments:
the ACPI handle of the device's parent, a bus address suitable for
the device's bus type and a bool indicating if the device is a
bridge and make it work as outlined above. Reimplement the function
currently used for this purpose, acpi_get_child(), as a call to
acpi_find_child() with the last argument set to 'false' and make
the PCI subsystem use acpi_find_child() with the bridge information
passed as the last argument to it. [Lan Tianyu notices that it is
not sufficient to use pci_is_bridge() for that, because the device's
subordinate pointer hasn't been set yet at this point, so use
hdr_type instead.]
This change fixes a regression introduced inadvertently by commit
33f767d (ACPI: Rework acpi_get_child() to be more efficient) which
overlooked the fact that for acpi_walk_namespace() "post-order" means
"after all children have been visited" rather than "on the way back",
so for device objects without children and for namespace walks of
depth 1, as in the acpi_get_child() case, the "post-order" callbacks
ordering is actually the same as the ordering of "pre-order" ones.
Since that commit changed the namespace walk in acpi_get_child() to
terminate after finding the first matching object instead of going
through all of them and returning the last one, it effectively
changed the result returned by that function in some rare cases and
that led to problems (the switch from a "pre-order" to a "post-order"
callback was supposed to prevent that from happening, but it was
ineffective).
As it turns out, the systems where the change made by commit
33f767d actually matters are those where there are multiple ACPI
device objects representing the same PCIe port (which effectively
is a bridge). Moreover, only one of them, and the one we are
expected to use, has child device objects in the ACPI namespace,
so the regression can be addressed as described above.
References: https://bugzilla.kernel.org/show_bug.cgi?id=60561
Reported-by: Peter Wu <lekensteyn@gmail.com>
Tested-by: Vladimir Lalov <mail@vlalov.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: 3.9+ <stable@vger.kernel.org> # 3.9+
2013-08-07 20:55:00 +00:00
|
|
|
EXPORT_SYMBOL_GPL(acpi_find_child);
|
2005-03-18 23:45:35 +00:00
|
|
|
|
ACPI / processor: Use common hotplug infrastructure
Split the ACPI processor driver into two parts, one that is
non-modular, resides in the ACPI core and handles the enumeration
and hotplug of processors and one that implements the rest of the
existing processor driver functionality.
The non-modular part uses an ACPI scan handler object to enumerate
processors on the basis of information provided by the ACPI namespace
and to hook up with the common ACPI hotplug infrastructure. It also
populates the ACPI handle of each processor device having a
corresponding object in the ACPI namespace, which allows the driver
proper to bind to those devices, and makes the driver bind to them
if it is readily available (i.e. loaded) when the scan handler's
.attach() routine is running.
There are a few reasons to make this change.
First, switching the ACPI processor driver to using the common ACPI
hotplug infrastructure reduces code duplication and size considerably,
even though a new file is created along with a header comment etc.
Second, since the common hotplug code attempts to offline devices
before starting the (non-reversible) removal procedure, it will abort
(and possibly roll back) hot-remove operations involving processors
if cpu_down() returns an error code for one of them instead of
continuing them blindly (if /sys/firmware/acpi/hotplug/force_remove
is unset). That is a more desirable behavior than what the current
code does.
Finally, the separation of the scan/hotplug part from the driver
proper makes it possible to simplify the driver's .remove() routine,
because it doesn't need to worry about the possible cleanup related
to processor removal any more (the scan/hotplug part is responsible
for that now) and can handle device removal and driver removal
symmetricaly (i.e. as appropriate).
Some user-visible changes in sysfs are made (for example, the
'sysdev' link from the ACPI device node to the processor device's
directory is gone and a 'physical_node' link is present instead
and a corresponding 'firmware_node' is present in the processor
device's directory, the processor driver is now visible under
/sys/bus/cpu/drivers/ and bound to the processor device), but
that shouldn't affect the functionality that users care about
(frequency scaling, C-states and thermal management).
Tested on my venerable Toshiba Portege R500.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Toshi Kani <toshi.kani@hp.com>
2013-05-02 22:26:22 +00:00
|
|
|
int acpi_bind_one(struct device *dev, acpi_handle handle)
|
2005-03-18 23:45:35 +00:00
|
|
|
{
|
2008-02-23 05:54:24 +00:00
|
|
|
struct acpi_device *acpi_dev;
|
2005-03-18 23:45:35 +00:00
|
|
|
acpi_status status;
|
2012-11-20 23:21:39 +00:00
|
|
|
struct acpi_device_physical_node *physical_node, *pn;
|
2013-08-06 12:32:54 +00:00
|
|
|
char physical_node_name[PHYSICAL_NODE_NAME_SIZE];
|
|
|
|
struct list_head *physnode_list;
|
|
|
|
unsigned int node_id;
|
2012-08-17 06:44:09 +00:00
|
|
|
int retval = -EINVAL;
|
2005-03-18 23:45:35 +00:00
|
|
|
|
2012-11-20 23:21:50 +00:00
|
|
|
if (ACPI_HANDLE(dev)) {
|
2012-11-20 23:21:39 +00:00
|
|
|
if (handle) {
|
|
|
|
dev_warn(dev, "ACPI handle is already set\n");
|
|
|
|
return -EINVAL;
|
|
|
|
} else {
|
2012-11-20 23:21:50 +00:00
|
|
|
handle = ACPI_HANDLE(dev);
|
2012-11-20 23:21:39 +00:00
|
|
|
}
|
2005-03-18 23:45:35 +00:00
|
|
|
}
|
2012-11-20 23:21:39 +00:00
|
|
|
if (!handle)
|
|
|
|
return -EINVAL;
|
2012-08-17 06:44:09 +00:00
|
|
|
|
2005-03-18 23:45:35 +00:00
|
|
|
get_device(dev);
|
2012-08-17 06:44:09 +00:00
|
|
|
status = acpi_bus_get_device(handle, &acpi_dev);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
goto err;
|
|
|
|
|
2012-11-20 23:21:39 +00:00
|
|
|
physical_node = kzalloc(sizeof(*physical_node), GFP_KERNEL);
|
2012-08-17 06:44:09 +00:00
|
|
|
if (!physical_node) {
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto err;
|
2005-03-18 23:45:35 +00:00
|
|
|
}
|
|
|
|
|
2012-08-17 06:44:09 +00:00
|
|
|
mutex_lock(&acpi_dev->physical_node_lock);
|
2012-11-20 23:21:39 +00:00
|
|
|
|
2013-08-06 12:32:54 +00:00
|
|
|
/*
|
|
|
|
* 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. */
|
2012-11-20 23:21:39 +00:00
|
|
|
if (pn->dev == dev) {
|
|
|
|
dev_warn(dev, "Already associated with ACPI node\n");
|
2013-08-06 23:15:25 +00:00
|
|
|
if (ACPI_HANDLE(dev) == handle)
|
|
|
|
retval = 0;
|
|
|
|
|
|
|
|
goto out_free;
|
2012-11-20 23:21:39 +00:00
|
|
|
}
|
2013-08-06 12:32:54 +00:00
|
|
|
if (pn->node_id == node_id) {
|
|
|
|
physnode_list = &pn->node;
|
|
|
|
node_id++;
|
|
|
|
}
|
2008-02-23 05:54:24 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 12:32:54 +00:00
|
|
|
physical_node->node_id = node_id;
|
2012-08-17 06:44:09 +00:00
|
|
|
physical_node->dev = dev;
|
2013-08-06 12:32:54 +00:00
|
|
|
list_add(&physical_node->node, physnode_list);
|
2012-08-17 06:44:09 +00:00
|
|
|
acpi_dev->physical_node_count++;
|
2012-11-20 23:21:39 +00:00
|
|
|
|
2012-08-17 06:44:09 +00:00
|
|
|
mutex_unlock(&acpi_dev->physical_node_lock);
|
|
|
|
|
2012-11-20 23:21:50 +00:00
|
|
|
if (!ACPI_HANDLE(dev))
|
|
|
|
ACPI_HANDLE_SET(dev, acpi_dev->handle);
|
2012-08-17 06:44:09 +00: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-18 23:45:35 +00:00
|
|
|
return 0;
|
2012-08-17 06:44:09 +00:00
|
|
|
|
|
|
|
err:
|
2012-11-20 23:21:50 +00:00
|
|
|
ACPI_HANDLE_SET(dev, NULL);
|
2012-08-17 06:44:09 +00:00
|
|
|
put_device(dev);
|
|
|
|
return retval;
|
2012-11-20 23:21:39 +00:00
|
|
|
|
2013-08-06 23:15:25 +00:00
|
|
|
out_free:
|
2012-11-20 23:21:39 +00:00
|
|
|
mutex_unlock(&acpi_dev->physical_node_lock);
|
|
|
|
kfree(physical_node);
|
2013-08-06 23:15:25 +00:00
|
|
|
if (retval)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
put_device(dev);
|
|
|
|
return 0;
|
2005-03-18 23:45:35 +00:00
|
|
|
}
|
ACPI / processor: Use common hotplug infrastructure
Split the ACPI processor driver into two parts, one that is
non-modular, resides in the ACPI core and handles the enumeration
and hotplug of processors and one that implements the rest of the
existing processor driver functionality.
The non-modular part uses an ACPI scan handler object to enumerate
processors on the basis of information provided by the ACPI namespace
and to hook up with the common ACPI hotplug infrastructure. It also
populates the ACPI handle of each processor device having a
corresponding object in the ACPI namespace, which allows the driver
proper to bind to those devices, and makes the driver bind to them
if it is readily available (i.e. loaded) when the scan handler's
.attach() routine is running.
There are a few reasons to make this change.
First, switching the ACPI processor driver to using the common ACPI
hotplug infrastructure reduces code duplication and size considerably,
even though a new file is created along with a header comment etc.
Second, since the common hotplug code attempts to offline devices
before starting the (non-reversible) removal procedure, it will abort
(and possibly roll back) hot-remove operations involving processors
if cpu_down() returns an error code for one of them instead of
continuing them blindly (if /sys/firmware/acpi/hotplug/force_remove
is unset). That is a more desirable behavior than what the current
code does.
Finally, the separation of the scan/hotplug part from the driver
proper makes it possible to simplify the driver's .remove() routine,
because it doesn't need to worry about the possible cleanup related
to processor removal any more (the scan/hotplug part is responsible
for that now) and can handle device removal and driver removal
symmetricaly (i.e. as appropriate).
Some user-visible changes in sysfs are made (for example, the
'sysdev' link from the ACPI device node to the processor device's
directory is gone and a 'physical_node' link is present instead
and a corresponding 'firmware_node' is present in the processor
device's directory, the processor driver is now visible under
/sys/bus/cpu/drivers/ and bound to the processor device), but
that shouldn't affect the functionality that users care about
(frequency scaling, C-states and thermal management).
Tested on my venerable Toshiba Portege R500.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Toshi Kani <toshi.kani@hp.com>
2013-05-02 22:26:22 +00:00
|
|
|
EXPORT_SYMBOL_GPL(acpi_bind_one);
|
2005-03-18 23:45:35 +00:00
|
|
|
|
ACPI / processor: Use common hotplug infrastructure
Split the ACPI processor driver into two parts, one that is
non-modular, resides in the ACPI core and handles the enumeration
and hotplug of processors and one that implements the rest of the
existing processor driver functionality.
The non-modular part uses an ACPI scan handler object to enumerate
processors on the basis of information provided by the ACPI namespace
and to hook up with the common ACPI hotplug infrastructure. It also
populates the ACPI handle of each processor device having a
corresponding object in the ACPI namespace, which allows the driver
proper to bind to those devices, and makes the driver bind to them
if it is readily available (i.e. loaded) when the scan handler's
.attach() routine is running.
There are a few reasons to make this change.
First, switching the ACPI processor driver to using the common ACPI
hotplug infrastructure reduces code duplication and size considerably,
even though a new file is created along with a header comment etc.
Second, since the common hotplug code attempts to offline devices
before starting the (non-reversible) removal procedure, it will abort
(and possibly roll back) hot-remove operations involving processors
if cpu_down() returns an error code for one of them instead of
continuing them blindly (if /sys/firmware/acpi/hotplug/force_remove
is unset). That is a more desirable behavior than what the current
code does.
Finally, the separation of the scan/hotplug part from the driver
proper makes it possible to simplify the driver's .remove() routine,
because it doesn't need to worry about the possible cleanup related
to processor removal any more (the scan/hotplug part is responsible
for that now) and can handle device removal and driver removal
symmetricaly (i.e. as appropriate).
Some user-visible changes in sysfs are made (for example, the
'sysdev' link from the ACPI device node to the processor device's
directory is gone and a 'physical_node' link is present instead
and a corresponding 'firmware_node' is present in the processor
device's directory, the processor driver is now visible under
/sys/bus/cpu/drivers/ and bound to the processor device), but
that shouldn't affect the functionality that users care about
(frequency scaling, C-states and thermal management).
Tested on my venerable Toshiba Portege R500.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Toshi Kani <toshi.kani@hp.com>
2013-05-02 22:26:22 +00:00
|
|
|
int acpi_unbind_one(struct device *dev)
|
2005-03-18 23:45:35 +00:00
|
|
|
{
|
2012-08-17 06:44:09 +00:00
|
|
|
struct acpi_device_physical_node *entry;
|
|
|
|
struct acpi_device *acpi_dev;
|
|
|
|
acpi_status status;
|
|
|
|
struct list_head *node, *next;
|
|
|
|
|
2012-11-20 23:21:50 +00:00
|
|
|
if (!ACPI_HANDLE(dev))
|
2005-03-18 23:45:35 +00:00
|
|
|
return 0;
|
2008-02-23 05:54:24 +00:00
|
|
|
|
2012-11-20 23:21:50 +00:00
|
|
|
status = acpi_bus_get_device(ACPI_HANDLE(dev), &acpi_dev);
|
2012-08-17 06:44:09 +00:00
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
goto err;
|
2008-02-23 05:54:24 +00:00
|
|
|
|
2012-08-17 06:44:09 +00:00
|
|
|
mutex_lock(&acpi_dev->physical_node_lock);
|
|
|
|
list_for_each_safe(node, next, &acpi_dev->physical_node_list) {
|
2013-08-06 12:32:54 +00:00
|
|
|
char physical_node_name[PHYSICAL_NODE_NAME_SIZE];
|
2012-08-17 06:44:09 +00:00
|
|
|
|
|
|
|
entry = list_entry(node, struct acpi_device_physical_node,
|
|
|
|
node);
|
|
|
|
if (entry->dev != dev)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
list_del(node);
|
2008-02-23 05:54:24 +00:00
|
|
|
|
2012-08-17 06:44:09 +00: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-20 23:21:50 +00:00
|
|
|
ACPI_HANDLE_SET(dev, NULL);
|
2005-03-18 23:45:35 +00:00
|
|
|
/* acpi_bind_one increase refcnt by one */
|
|
|
|
put_device(dev);
|
2012-08-17 06:44:09 +00:00
|
|
|
kfree(entry);
|
2005-03-18 23:45:35 +00:00
|
|
|
}
|
2012-08-17 06:44:09 +00:00
|
|
|
mutex_unlock(&acpi_dev->physical_node_lock);
|
|
|
|
|
2005-03-18 23:45:35 +00:00
|
|
|
return 0;
|
2012-08-17 06:44:09 +00:00
|
|
|
|
|
|
|
err:
|
|
|
|
dev_err(dev, "Oops, 'acpi_handle' corrupt\n");
|
|
|
|
return -EINVAL;
|
2005-03-18 23:45:35 +00:00
|
|
|
}
|
ACPI / processor: Use common hotplug infrastructure
Split the ACPI processor driver into two parts, one that is
non-modular, resides in the ACPI core and handles the enumeration
and hotplug of processors and one that implements the rest of the
existing processor driver functionality.
The non-modular part uses an ACPI scan handler object to enumerate
processors on the basis of information provided by the ACPI namespace
and to hook up with the common ACPI hotplug infrastructure. It also
populates the ACPI handle of each processor device having a
corresponding object in the ACPI namespace, which allows the driver
proper to bind to those devices, and makes the driver bind to them
if it is readily available (i.e. loaded) when the scan handler's
.attach() routine is running.
There are a few reasons to make this change.
First, switching the ACPI processor driver to using the common ACPI
hotplug infrastructure reduces code duplication and size considerably,
even though a new file is created along with a header comment etc.
Second, since the common hotplug code attempts to offline devices
before starting the (non-reversible) removal procedure, it will abort
(and possibly roll back) hot-remove operations involving processors
if cpu_down() returns an error code for one of them instead of
continuing them blindly (if /sys/firmware/acpi/hotplug/force_remove
is unset). That is a more desirable behavior than what the current
code does.
Finally, the separation of the scan/hotplug part from the driver
proper makes it possible to simplify the driver's .remove() routine,
because it doesn't need to worry about the possible cleanup related
to processor removal any more (the scan/hotplug part is responsible
for that now) and can handle device removal and driver removal
symmetricaly (i.e. as appropriate).
Some user-visible changes in sysfs are made (for example, the
'sysdev' link from the ACPI device node to the processor device's
directory is gone and a 'physical_node' link is present instead
and a corresponding 'firmware_node' is present in the processor
device's directory, the processor driver is now visible under
/sys/bus/cpu/drivers/ and bound to the processor device), but
that shouldn't affect the functionality that users care about
(frequency scaling, C-states and thermal management).
Tested on my venerable Toshiba Portege R500.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Toshi Kani <toshi.kani@hp.com>
2013-05-02 22:26:22 +00:00
|
|
|
EXPORT_SYMBOL_GPL(acpi_unbind_one);
|
2005-03-18 23:45:35 +00:00
|
|
|
|
|
|
|
static int acpi_platform_notify(struct device *dev)
|
|
|
|
{
|
2013-03-03 21:35:20 +00:00
|
|
|
struct acpi_bus_type *type = acpi_get_bus_type(dev);
|
2005-03-18 23:45:35 +00:00
|
|
|
acpi_handle handle;
|
2012-12-22 23:02:13 +00:00
|
|
|
int ret;
|
2005-03-18 23:45:35 +00:00
|
|
|
|
2012-11-20 23:21:39 +00:00
|
|
|
ret = acpi_bind_one(dev, NULL);
|
2013-03-03 21:35:44 +00:00
|
|
|
if (ret && type) {
|
2012-12-22 23:02:13 +00:00
|
|
|
ret = type->find_device(dev, &handle);
|
|
|
|
if (ret) {
|
|
|
|
DBG("Unable to get handle for %s\n", dev_name(dev));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
ret = acpi_bind_one(dev, handle);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
2005-03-18 23:45:35 +00:00
|
|
|
}
|
2012-12-22 23:02:13 +00:00
|
|
|
|
|
|
|
if (type && type->setup)
|
|
|
|
type->setup(dev);
|
2005-03-18 23:45:35 +00:00
|
|
|
|
2012-11-20 23:21:39 +00:00
|
|
|
out:
|
2005-03-18 23:45:35 +00:00
|
|
|
#if ACPI_GLUE_DEBUG
|
|
|
|
if (!ret) {
|
|
|
|
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
|
|
|
|
|
2013-01-12 13:00:06 +00:00
|
|
|
acpi_get_name(ACPI_HANDLE(dev), ACPI_FULL_PATHNAME, &buffer);
|
2009-01-25 22:40:56 +00:00
|
|
|
DBG("Device %s -> %s\n", dev_name(dev), (char *)buffer.pointer);
|
2006-06-30 07:19:10 +00:00
|
|
|
kfree(buffer.pointer);
|
2005-03-18 23:45:35 +00:00
|
|
|
} else
|
2009-01-25 22:40:56 +00:00
|
|
|
DBG("Device %s -> No ACPI support\n", dev_name(dev));
|
2005-03-18 23:45:35 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int acpi_platform_notify_remove(struct device *dev)
|
|
|
|
{
|
2012-12-22 23:02:13 +00:00
|
|
|
struct acpi_bus_type *type;
|
|
|
|
|
2013-03-03 21:35:20 +00:00
|
|
|
type = acpi_get_bus_type(dev);
|
2012-12-22 23:02:13 +00:00
|
|
|
if (type && type->cleanup)
|
|
|
|
type->cleanup(dev);
|
|
|
|
|
2005-03-18 23:45:35 +00:00
|
|
|
acpi_unbind_one(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-24 22:50:09 +00:00
|
|
|
int __init init_acpi_device_notify(void)
|
2005-03-18 23:45:35 +00: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;
|
|
|
|
}
|