2005-03-19 07:45:35 +08: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 04:22:14 +08:00
|
|
|
#include <linux/export.h>
|
2005-03-19 07:45:35 +08: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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-03-19 07:45:35 +08:00
|
|
|
#include <linux/rwsem.h>
|
|
|
|
#include <linux/acpi.h>
|
2015-06-11 00:08:52 +08:00
|
|
|
#include <linux/dma-mapping.h>
|
2005-03-19 07:45:35 +08:00
|
|
|
|
2009-07-29 04:45:54 +08:00
|
|
|
#include "internal.h"
|
|
|
|
|
2005-03-19 07:45:35 +08:00
|
|
|
#define ACPI_GLUE_DEBUG 0
|
|
|
|
#if ACPI_GLUE_DEBUG
|
2012-12-18 14:31:30 +08:00
|
|
|
#define DBG(fmt, ...) \
|
|
|
|
printk(KERN_DEBUG PREFIX fmt, ##__VA_ARGS__)
|
2005-03-19 07:45:35 +08:00
|
|
|
#else
|
2012-12-18 14:31:30 +08:00
|
|
|
#define DBG(fmt, ...) \
|
|
|
|
do { \
|
|
|
|
if (0) \
|
|
|
|
printk(KERN_DEBUG PREFIX fmt, ##__VA_ARGS__); \
|
|
|
|
} while (0)
|
2005-03-19 07:45:35 +08:00
|
|
|
#endif
|
|
|
|
static LIST_HEAD(bus_type_list);
|
|
|
|
static DECLARE_RWSEM(bus_type_sem);
|
|
|
|
|
2012-08-17 14:44:09 +08:00
|
|
|
#define PHYSICAL_NODE_STRING "physical_node"
|
2013-08-06 20:32:54 +08:00
|
|
|
#define PHYSICAL_NODE_NAME_SIZE (sizeof(PHYSICAL_NODE_STRING) + 10)
|
2012-08-17 14:44:09 +08:00
|
|
|
|
2005-03-19 07:45:35 +08:00
|
|
|
int register_acpi_bus_type(struct acpi_bus_type *type)
|
|
|
|
{
|
|
|
|
if (acpi_disabled)
|
|
|
|
return -ENODEV;
|
2013-11-29 23:27:34 +08:00
|
|
|
if (type && type->match && type->find_companion) {
|
2005-03-19 07:45:35 +08:00
|
|
|
down_write(&bus_type_sem);
|
|
|
|
list_add_tail(&type->list, &bus_type_list);
|
|
|
|
up_write(&bus_type_sem);
|
2013-03-04 05:35:20 +08:00
|
|
|
printk(KERN_INFO PREFIX "bus type %s registered\n", type->name);
|
2005-03-19 07:45:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2012-07-26 02:24:13 +08:00
|
|
|
EXPORT_SYMBOL_GPL(register_acpi_bus_type);
|
2005-03-19 07:45:35 +08: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-04 05:35:20 +08:00
|
|
|
printk(KERN_INFO PREFIX "bus type %s unregistered\n",
|
|
|
|
type->name);
|
2005-03-19 07:45:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2012-07-26 02:24:13 +08:00
|
|
|
EXPORT_SYMBOL_GPL(unregister_acpi_bus_type);
|
2005-03-19 07:45:35 +08:00
|
|
|
|
2013-03-04 05:35:20 +08:00
|
|
|
static struct acpi_bus_type *acpi_get_bus_type(struct device *dev)
|
2005-03-19 07:45:35 +08:00
|
|
|
{
|
|
|
|
struct acpi_bus_type *tmp, *ret = NULL;
|
|
|
|
|
|
|
|
down_read(&bus_type_sem);
|
|
|
|
list_for_each_entry(tmp, &bus_type_list, list) {
|
2013-03-04 05:35:20 +08:00
|
|
|
if (tmp->match(dev)) {
|
2005-03-19 07:45:35 +08:00
|
|
|
ret = tmp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
up_read(&bus_type_sem);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-09-10 05:07:47 +08:00
|
|
|
#define FIND_CHILD_MIN_SCORE 1
|
|
|
|
#define FIND_CHILD_MAX_SCORE 2
|
|
|
|
|
2013-11-29 06:57:58 +08:00
|
|
|
static int find_child_checks(struct acpi_device *adev, bool check_children)
|
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-08 04:55:00 +08:00
|
|
|
{
|
2013-09-10 05:07:47 +08:00
|
|
|
bool sta_present = true;
|
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-08 04:55:00 +08:00
|
|
|
unsigned long long sta;
|
|
|
|
acpi_status status;
|
|
|
|
|
2013-11-29 06:57:58 +08:00
|
|
|
status = acpi_evaluate_integer(adev->handle, "_STA", NULL, &sta);
|
2013-09-10 05:07:47 +08:00
|
|
|
if (status == AE_NOT_FOUND)
|
|
|
|
sta_present = false;
|
|
|
|
else if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_ENABLED))
|
|
|
|
return -ENODEV;
|
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-08 04:55:00 +08:00
|
|
|
|
2013-11-29 06:57:58 +08:00
|
|
|
if (check_children && list_empty(&adev->children))
|
|
|
|
return -ENODEV;
|
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-08 04:55:00 +08:00
|
|
|
|
2013-09-10 05:07:47 +08:00
|
|
|
return sta_present ? FIND_CHILD_MAX_SCORE : FIND_CHILD_MIN_SCORE;
|
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-08 04:55:00 +08:00
|
|
|
}
|
|
|
|
|
2013-11-29 06:57:58 +08:00
|
|
|
struct acpi_device *acpi_find_child_device(struct acpi_device *parent,
|
|
|
|
u64 address, bool check_children)
|
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-08 04:55:00 +08:00
|
|
|
{
|
2013-11-29 06:57:58 +08:00
|
|
|
struct acpi_device *adev, *ret = NULL;
|
|
|
|
int ret_score = 0;
|
|
|
|
|
2013-11-29 06:58:08 +08:00
|
|
|
if (!parent)
|
|
|
|
return NULL;
|
|
|
|
|
2013-11-29 06:57:58 +08:00
|
|
|
list_for_each_entry(adev, &parent->children, node) {
|
|
|
|
unsigned long long addr;
|
|
|
|
acpi_status status;
|
|
|
|
int score;
|
|
|
|
|
|
|
|
status = acpi_evaluate_integer(adev->handle, METHOD_NAME__ADR,
|
|
|
|
NULL, &addr);
|
|
|
|
if (ACPI_FAILURE(status) || addr != address)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
/* This is the first matching object. Save it. */
|
|
|
|
ret = adev;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* There is more than one matching device 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 it if so. Second, do the same for the object that
|
|
|
|
* we've just found.
|
|
|
|
*/
|
|
|
|
if (!ret_score) {
|
|
|
|
ret_score = find_child_checks(ret, check_children);
|
|
|
|
if (ret_score == FIND_CHILD_MAX_SCORE)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
score = find_child_checks(adev, check_children);
|
|
|
|
if (score == FIND_CHILD_MAX_SCORE) {
|
|
|
|
return adev;
|
|
|
|
} else if (score > ret_score) {
|
|
|
|
ret = adev;
|
|
|
|
ret_score = score;
|
|
|
|
}
|
2005-03-19 07:45:35 +08:00
|
|
|
}
|
2013-11-29 06:57:58 +08:00
|
|
|
return ret;
|
2005-03-19 07:45:35 +08:00
|
|
|
}
|
2013-11-29 06:58:28 +08:00
|
|
|
EXPORT_SYMBOL_GPL(acpi_find_child_device);
|
2005-03-19 07:45:35 +08:00
|
|
|
|
2013-08-07 07:19:23 +08:00
|
|
|
static void acpi_physnode_link_name(char *buf, unsigned int node_id)
|
|
|
|
{
|
|
|
|
if (node_id > 0)
|
|
|
|
snprintf(buf, PHYSICAL_NODE_NAME_SIZE,
|
|
|
|
PHYSICAL_NODE_STRING "%u", node_id);
|
|
|
|
else
|
|
|
|
strcpy(buf, PHYSICAL_NODE_STRING);
|
|
|
|
}
|
|
|
|
|
2013-11-29 23:27:43 +08:00
|
|
|
int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
|
2005-03-19 07:45:35 +08:00
|
|
|
{
|
2012-11-21 07:21:39 +08:00
|
|
|
struct acpi_device_physical_node *physical_node, *pn;
|
2013-08-06 20:32:54 +08:00
|
|
|
char physical_node_name[PHYSICAL_NODE_NAME_SIZE];
|
|
|
|
struct list_head *physnode_list;
|
|
|
|
unsigned int node_id;
|
2012-08-17 14:44:09 +08:00
|
|
|
int retval = -EINVAL;
|
2015-06-11 00:08:52 +08:00
|
|
|
bool coherent;
|
2005-03-19 07:45:35 +08:00
|
|
|
|
2015-03-17 06:49:08 +08:00
|
|
|
if (has_acpi_companion(dev)) {
|
2013-11-29 23:27:43 +08:00
|
|
|
if (acpi_dev) {
|
ACPI / driver core: Store an ACPI device pointer in struct acpi_dev_node
Modify struct acpi_dev_node to contain a pointer to struct acpi_device
associated with the given device object (that is, its ACPI companion
device) instead of an ACPI handle corresponding to it. Introduce two
new macros for manipulating that pointer in a CONFIG_ACPI-safe way,
ACPI_COMPANION() and ACPI_COMPANION_SET(), and rework the
ACPI_HANDLE() macro to take the above changes into account.
Drop the ACPI_HANDLE_SET() macro entirely and rework its users to
use ACPI_COMPANION_SET() instead. For some of them who used to
pass the result of acpi_get_child() directly to ACPI_HANDLE_SET()
introduce a helper routine acpi_preset_companion() doing an
equivalent thing.
The main motivation for doing this is that there are things
represented by struct acpi_device objects that don't have valid
ACPI handles (so called fixed ACPI hardware features, such as
power and sleep buttons) and we would like to create platform
device objects for them and "glue" them to their ACPI companions
in the usual way (which currently is impossible due to the
lack of valid ACPI handles). However, there are more reasons
why it may be useful.
First, struct acpi_device pointers allow of much better type checking
than void pointers which are ACPI handles, so it should be more
difficult to write buggy code using modified struct acpi_dev_node
and the new macros. Second, the change should help to reduce (over
time) the number of places in which the result of ACPI_HANDLE() is
passed to acpi_bus_get_device() in order to obtain a pointer to the
struct acpi_device associated with the given "physical" device,
because now that pointer is returned by ACPI_COMPANION() directly.
Finally, the change should make it easier to write generic code that
will build both for CONFIG_ACPI set and unset without adding explicit
compiler directives to it.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com> # on Haswell
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Aaron Lu <aaron.lu@intel.com> # for ATA and SDIO part
2013-11-12 05:41:56 +08:00
|
|
|
dev_warn(dev, "ACPI companion already set\n");
|
2012-11-21 07:21:39 +08:00
|
|
|
return -EINVAL;
|
|
|
|
} else {
|
ACPI / driver core: Store an ACPI device pointer in struct acpi_dev_node
Modify struct acpi_dev_node to contain a pointer to struct acpi_device
associated with the given device object (that is, its ACPI companion
device) instead of an ACPI handle corresponding to it. Introduce two
new macros for manipulating that pointer in a CONFIG_ACPI-safe way,
ACPI_COMPANION() and ACPI_COMPANION_SET(), and rework the
ACPI_HANDLE() macro to take the above changes into account.
Drop the ACPI_HANDLE_SET() macro entirely and rework its users to
use ACPI_COMPANION_SET() instead. For some of them who used to
pass the result of acpi_get_child() directly to ACPI_HANDLE_SET()
introduce a helper routine acpi_preset_companion() doing an
equivalent thing.
The main motivation for doing this is that there are things
represented by struct acpi_device objects that don't have valid
ACPI handles (so called fixed ACPI hardware features, such as
power and sleep buttons) and we would like to create platform
device objects for them and "glue" them to their ACPI companions
in the usual way (which currently is impossible due to the
lack of valid ACPI handles). However, there are more reasons
why it may be useful.
First, struct acpi_device pointers allow of much better type checking
than void pointers which are ACPI handles, so it should be more
difficult to write buggy code using modified struct acpi_dev_node
and the new macros. Second, the change should help to reduce (over
time) the number of places in which the result of ACPI_HANDLE() is
passed to acpi_bus_get_device() in order to obtain a pointer to the
struct acpi_device associated with the given "physical" device,
because now that pointer is returned by ACPI_COMPANION() directly.
Finally, the change should make it easier to write generic code that
will build both for CONFIG_ACPI set and unset without adding explicit
compiler directives to it.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com> # on Haswell
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Aaron Lu <aaron.lu@intel.com> # for ATA and SDIO part
2013-11-12 05:41:56 +08:00
|
|
|
acpi_dev = ACPI_COMPANION(dev);
|
2012-11-21 07:21:39 +08:00
|
|
|
}
|
2005-03-19 07:45:35 +08:00
|
|
|
}
|
ACPI / driver core: Store an ACPI device pointer in struct acpi_dev_node
Modify struct acpi_dev_node to contain a pointer to struct acpi_device
associated with the given device object (that is, its ACPI companion
device) instead of an ACPI handle corresponding to it. Introduce two
new macros for manipulating that pointer in a CONFIG_ACPI-safe way,
ACPI_COMPANION() and ACPI_COMPANION_SET(), and rework the
ACPI_HANDLE() macro to take the above changes into account.
Drop the ACPI_HANDLE_SET() macro entirely and rework its users to
use ACPI_COMPANION_SET() instead. For some of them who used to
pass the result of acpi_get_child() directly to ACPI_HANDLE_SET()
introduce a helper routine acpi_preset_companion() doing an
equivalent thing.
The main motivation for doing this is that there are things
represented by struct acpi_device objects that don't have valid
ACPI handles (so called fixed ACPI hardware features, such as
power and sleep buttons) and we would like to create platform
device objects for them and "glue" them to their ACPI companions
in the usual way (which currently is impossible due to the
lack of valid ACPI handles). However, there are more reasons
why it may be useful.
First, struct acpi_device pointers allow of much better type checking
than void pointers which are ACPI handles, so it should be more
difficult to write buggy code using modified struct acpi_dev_node
and the new macros. Second, the change should help to reduce (over
time) the number of places in which the result of ACPI_HANDLE() is
passed to acpi_bus_get_device() in order to obtain a pointer to the
struct acpi_device associated with the given "physical" device,
because now that pointer is returned by ACPI_COMPANION() directly.
Finally, the change should make it easier to write generic code that
will build both for CONFIG_ACPI set and unset without adding explicit
compiler directives to it.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com> # on Haswell
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Aaron Lu <aaron.lu@intel.com> # for ATA and SDIO part
2013-11-12 05:41:56 +08:00
|
|
|
if (!acpi_dev)
|
2012-11-21 07:21:39 +08:00
|
|
|
return -EINVAL;
|
2012-08-17 14:44:09 +08:00
|
|
|
|
2013-11-15 06:18:32 +08:00
|
|
|
get_device(&acpi_dev->dev);
|
2005-03-19 07:45:35 +08:00
|
|
|
get_device(dev);
|
2012-11-21 07:21:39 +08:00
|
|
|
physical_node = kzalloc(sizeof(*physical_node), GFP_KERNEL);
|
2012-08-17 14:44:09 +08:00
|
|
|
if (!physical_node) {
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto err;
|
2005-03-19 07:45:35 +08:00
|
|
|
}
|
|
|
|
|
2012-08-17 14:44:09 +08:00
|
|
|
mutex_lock(&acpi_dev->physical_node_lock);
|
2012-11-21 07:21:39 +08:00
|
|
|
|
2013-08-06 20:32:54 +08: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-21 07:21:39 +08:00
|
|
|
if (pn->dev == dev) {
|
2013-08-08 22:19:10 +08:00
|
|
|
mutex_unlock(&acpi_dev->physical_node_lock);
|
|
|
|
|
2012-11-21 07:21:39 +08:00
|
|
|
dev_warn(dev, "Already associated with ACPI node\n");
|
2013-08-08 22:19:10 +08:00
|
|
|
kfree(physical_node);
|
ACPI / driver core: Store an ACPI device pointer in struct acpi_dev_node
Modify struct acpi_dev_node to contain a pointer to struct acpi_device
associated with the given device object (that is, its ACPI companion
device) instead of an ACPI handle corresponding to it. Introduce two
new macros for manipulating that pointer in a CONFIG_ACPI-safe way,
ACPI_COMPANION() and ACPI_COMPANION_SET(), and rework the
ACPI_HANDLE() macro to take the above changes into account.
Drop the ACPI_HANDLE_SET() macro entirely and rework its users to
use ACPI_COMPANION_SET() instead. For some of them who used to
pass the result of acpi_get_child() directly to ACPI_HANDLE_SET()
introduce a helper routine acpi_preset_companion() doing an
equivalent thing.
The main motivation for doing this is that there are things
represented by struct acpi_device objects that don't have valid
ACPI handles (so called fixed ACPI hardware features, such as
power and sleep buttons) and we would like to create platform
device objects for them and "glue" them to their ACPI companions
in the usual way (which currently is impossible due to the
lack of valid ACPI handles). However, there are more reasons
why it may be useful.
First, struct acpi_device pointers allow of much better type checking
than void pointers which are ACPI handles, so it should be more
difficult to write buggy code using modified struct acpi_dev_node
and the new macros. Second, the change should help to reduce (over
time) the number of places in which the result of ACPI_HANDLE() is
passed to acpi_bus_get_device() in order to obtain a pointer to the
struct acpi_device associated with the given "physical" device,
because now that pointer is returned by ACPI_COMPANION() directly.
Finally, the change should make it easier to write generic code that
will build both for CONFIG_ACPI set and unset without adding explicit
compiler directives to it.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com> # on Haswell
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Aaron Lu <aaron.lu@intel.com> # for ATA and SDIO part
2013-11-12 05:41:56 +08:00
|
|
|
if (ACPI_COMPANION(dev) != acpi_dev)
|
2013-08-08 22:19:10 +08:00
|
|
|
goto err;
|
2013-08-07 07:15:25 +08:00
|
|
|
|
2013-08-08 22:19:10 +08:00
|
|
|
put_device(dev);
|
2013-11-15 06:18:32 +08:00
|
|
|
put_device(&acpi_dev->dev);
|
2013-08-08 22:19:10 +08:00
|
|
|
return 0;
|
2012-11-21 07:21:39 +08:00
|
|
|
}
|
2013-08-06 20:32:54 +08:00
|
|
|
if (pn->node_id == node_id) {
|
|
|
|
physnode_list = &pn->node;
|
|
|
|
node_id++;
|
|
|
|
}
|
2008-02-23 13:54:24 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 20:32:54 +08:00
|
|
|
physical_node->node_id = node_id;
|
2012-08-17 14:44:09 +08:00
|
|
|
physical_node->dev = dev;
|
2013-08-06 20:32:54 +08:00
|
|
|
list_add(&physical_node->node, physnode_list);
|
2012-08-17 14:44:09 +08:00
|
|
|
acpi_dev->physical_node_count++;
|
2012-11-21 07:21:39 +08:00
|
|
|
|
2015-03-17 06:49:08 +08:00
|
|
|
if (!has_acpi_companion(dev))
|
ACPI / driver core: Store an ACPI device pointer in struct acpi_dev_node
Modify struct acpi_dev_node to contain a pointer to struct acpi_device
associated with the given device object (that is, its ACPI companion
device) instead of an ACPI handle corresponding to it. Introduce two
new macros for manipulating that pointer in a CONFIG_ACPI-safe way,
ACPI_COMPANION() and ACPI_COMPANION_SET(), and rework the
ACPI_HANDLE() macro to take the above changes into account.
Drop the ACPI_HANDLE_SET() macro entirely and rework its users to
use ACPI_COMPANION_SET() instead. For some of them who used to
pass the result of acpi_get_child() directly to ACPI_HANDLE_SET()
introduce a helper routine acpi_preset_companion() doing an
equivalent thing.
The main motivation for doing this is that there are things
represented by struct acpi_device objects that don't have valid
ACPI handles (so called fixed ACPI hardware features, such as
power and sleep buttons) and we would like to create platform
device objects for them and "glue" them to their ACPI companions
in the usual way (which currently is impossible due to the
lack of valid ACPI handles). However, there are more reasons
why it may be useful.
First, struct acpi_device pointers allow of much better type checking
than void pointers which are ACPI handles, so it should be more
difficult to write buggy code using modified struct acpi_dev_node
and the new macros. Second, the change should help to reduce (over
time) the number of places in which the result of ACPI_HANDLE() is
passed to acpi_bus_get_device() in order to obtain a pointer to the
struct acpi_device associated with the given "physical" device,
because now that pointer is returned by ACPI_COMPANION() directly.
Finally, the change should make it easier to write generic code that
will build both for CONFIG_ACPI set and unset without adding explicit
compiler directives to it.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com> # on Haswell
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Aaron Lu <aaron.lu@intel.com> # for ATA and SDIO part
2013-11-12 05:41:56 +08:00
|
|
|
ACPI_COMPANION_SET(dev, acpi_dev);
|
2012-08-17 14:44:09 +08:00
|
|
|
|
2015-06-11 00:08:52 +08:00
|
|
|
if (acpi_check_dma(acpi_dev, &coherent))
|
|
|
|
arch_setup_dma_ops(dev, 0, 0, NULL, coherent);
|
|
|
|
|
2013-08-07 07:19:23 +08:00
|
|
|
acpi_physnode_link_name(physical_node_name, node_id);
|
2012-08-17 14:44:09 +08:00
|
|
|
retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
|
2013-08-07 07:19:52 +08:00
|
|
|
physical_node_name);
|
2013-08-08 22:19:19 +08:00
|
|
|
if (retval)
|
|
|
|
dev_err(&acpi_dev->dev, "Failed to create link %s (%d)\n",
|
|
|
|
physical_node_name, retval);
|
|
|
|
|
2012-08-17 14:44:09 +08:00
|
|
|
retval = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj,
|
2013-08-07 07:19:52 +08:00
|
|
|
"firmware_node");
|
2013-08-08 22:19:19 +08:00
|
|
|
if (retval)
|
|
|
|
dev_err(dev, "Failed to create link firmware_node (%d)\n",
|
|
|
|
retval);
|
2012-08-17 14:44:09 +08:00
|
|
|
|
2013-08-07 07:19:37 +08:00
|
|
|
mutex_unlock(&acpi_dev->physical_node_lock);
|
|
|
|
|
2012-08-17 14:44:09 +08:00
|
|
|
if (acpi_dev->wakeup.flags.valid)
|
|
|
|
device_set_wakeup_capable(dev, true);
|
|
|
|
|
2005-03-19 07:45:35 +08:00
|
|
|
return 0;
|
2012-08-17 14:44:09 +08:00
|
|
|
|
|
|
|
err:
|
ACPI / driver core: Store an ACPI device pointer in struct acpi_dev_node
Modify struct acpi_dev_node to contain a pointer to struct acpi_device
associated with the given device object (that is, its ACPI companion
device) instead of an ACPI handle corresponding to it. Introduce two
new macros for manipulating that pointer in a CONFIG_ACPI-safe way,
ACPI_COMPANION() and ACPI_COMPANION_SET(), and rework the
ACPI_HANDLE() macro to take the above changes into account.
Drop the ACPI_HANDLE_SET() macro entirely and rework its users to
use ACPI_COMPANION_SET() instead. For some of them who used to
pass the result of acpi_get_child() directly to ACPI_HANDLE_SET()
introduce a helper routine acpi_preset_companion() doing an
equivalent thing.
The main motivation for doing this is that there are things
represented by struct acpi_device objects that don't have valid
ACPI handles (so called fixed ACPI hardware features, such as
power and sleep buttons) and we would like to create platform
device objects for them and "glue" them to their ACPI companions
in the usual way (which currently is impossible due to the
lack of valid ACPI handles). However, there are more reasons
why it may be useful.
First, struct acpi_device pointers allow of much better type checking
than void pointers which are ACPI handles, so it should be more
difficult to write buggy code using modified struct acpi_dev_node
and the new macros. Second, the change should help to reduce (over
time) the number of places in which the result of ACPI_HANDLE() is
passed to acpi_bus_get_device() in order to obtain a pointer to the
struct acpi_device associated with the given "physical" device,
because now that pointer is returned by ACPI_COMPANION() directly.
Finally, the change should make it easier to write generic code that
will build both for CONFIG_ACPI set and unset without adding explicit
compiler directives to it.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com> # on Haswell
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Aaron Lu <aaron.lu@intel.com> # for ATA and SDIO part
2013-11-12 05:41:56 +08:00
|
|
|
ACPI_COMPANION_SET(dev, NULL);
|
2012-08-17 14:44:09 +08:00
|
|
|
put_device(dev);
|
2013-11-15 06:18:32 +08:00
|
|
|
put_device(&acpi_dev->dev);
|
2012-08-17 14:44:09 +08:00
|
|
|
return retval;
|
2005-03-19 07:45:35 +08: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-03 06:26:22 +08:00
|
|
|
EXPORT_SYMBOL_GPL(acpi_bind_one);
|
2005-03-19 07:45:35 +08: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-03 06:26:22 +08:00
|
|
|
int acpi_unbind_one(struct device *dev)
|
2005-03-19 07:45:35 +08:00
|
|
|
{
|
ACPI / driver core: Store an ACPI device pointer in struct acpi_dev_node
Modify struct acpi_dev_node to contain a pointer to struct acpi_device
associated with the given device object (that is, its ACPI companion
device) instead of an ACPI handle corresponding to it. Introduce two
new macros for manipulating that pointer in a CONFIG_ACPI-safe way,
ACPI_COMPANION() and ACPI_COMPANION_SET(), and rework the
ACPI_HANDLE() macro to take the above changes into account.
Drop the ACPI_HANDLE_SET() macro entirely and rework its users to
use ACPI_COMPANION_SET() instead. For some of them who used to
pass the result of acpi_get_child() directly to ACPI_HANDLE_SET()
introduce a helper routine acpi_preset_companion() doing an
equivalent thing.
The main motivation for doing this is that there are things
represented by struct acpi_device objects that don't have valid
ACPI handles (so called fixed ACPI hardware features, such as
power and sleep buttons) and we would like to create platform
device objects for them and "glue" them to their ACPI companions
in the usual way (which currently is impossible due to the
lack of valid ACPI handles). However, there are more reasons
why it may be useful.
First, struct acpi_device pointers allow of much better type checking
than void pointers which are ACPI handles, so it should be more
difficult to write buggy code using modified struct acpi_dev_node
and the new macros. Second, the change should help to reduce (over
time) the number of places in which the result of ACPI_HANDLE() is
passed to acpi_bus_get_device() in order to obtain a pointer to the
struct acpi_device associated with the given "physical" device,
because now that pointer is returned by ACPI_COMPANION() directly.
Finally, the change should make it easier to write generic code that
will build both for CONFIG_ACPI set and unset without adding explicit
compiler directives to it.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com> # on Haswell
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Aaron Lu <aaron.lu@intel.com> # for ATA and SDIO part
2013-11-12 05:41:56 +08:00
|
|
|
struct acpi_device *acpi_dev = ACPI_COMPANION(dev);
|
2012-08-17 14:44:09 +08:00
|
|
|
struct acpi_device_physical_node *entry;
|
|
|
|
|
ACPI / driver core: Store an ACPI device pointer in struct acpi_dev_node
Modify struct acpi_dev_node to contain a pointer to struct acpi_device
associated with the given device object (that is, its ACPI companion
device) instead of an ACPI handle corresponding to it. Introduce two
new macros for manipulating that pointer in a CONFIG_ACPI-safe way,
ACPI_COMPANION() and ACPI_COMPANION_SET(), and rework the
ACPI_HANDLE() macro to take the above changes into account.
Drop the ACPI_HANDLE_SET() macro entirely and rework its users to
use ACPI_COMPANION_SET() instead. For some of them who used to
pass the result of acpi_get_child() directly to ACPI_HANDLE_SET()
introduce a helper routine acpi_preset_companion() doing an
equivalent thing.
The main motivation for doing this is that there are things
represented by struct acpi_device objects that don't have valid
ACPI handles (so called fixed ACPI hardware features, such as
power and sleep buttons) and we would like to create platform
device objects for them and "glue" them to their ACPI companions
in the usual way (which currently is impossible due to the
lack of valid ACPI handles). However, there are more reasons
why it may be useful.
First, struct acpi_device pointers allow of much better type checking
than void pointers which are ACPI handles, so it should be more
difficult to write buggy code using modified struct acpi_dev_node
and the new macros. Second, the change should help to reduce (over
time) the number of places in which the result of ACPI_HANDLE() is
passed to acpi_bus_get_device() in order to obtain a pointer to the
struct acpi_device associated with the given "physical" device,
because now that pointer is returned by ACPI_COMPANION() directly.
Finally, the change should make it easier to write generic code that
will build both for CONFIG_ACPI set and unset without adding explicit
compiler directives to it.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com> # on Haswell
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Aaron Lu <aaron.lu@intel.com> # for ATA and SDIO part
2013-11-12 05:41:56 +08:00
|
|
|
if (!acpi_dev)
|
2005-03-19 07:45:35 +08:00
|
|
|
return 0;
|
2008-02-23 13:54:24 +08:00
|
|
|
|
2012-08-17 14:44:09 +08:00
|
|
|
mutex_lock(&acpi_dev->physical_node_lock);
|
2013-08-07 07:22:08 +08:00
|
|
|
|
|
|
|
list_for_each_entry(entry, &acpi_dev->physical_node_list, node)
|
|
|
|
if (entry->dev == dev) {
|
|
|
|
char physnode_name[PHYSICAL_NODE_NAME_SIZE];
|
|
|
|
|
|
|
|
list_del(&entry->node);
|
|
|
|
acpi_dev->physical_node_count--;
|
|
|
|
|
|
|
|
acpi_physnode_link_name(physnode_name, entry->node_id);
|
|
|
|
sysfs_remove_link(&acpi_dev->dev.kobj, physnode_name);
|
|
|
|
sysfs_remove_link(&dev->kobj, "firmware_node");
|
ACPI / driver core: Store an ACPI device pointer in struct acpi_dev_node
Modify struct acpi_dev_node to contain a pointer to struct acpi_device
associated with the given device object (that is, its ACPI companion
device) instead of an ACPI handle corresponding to it. Introduce two
new macros for manipulating that pointer in a CONFIG_ACPI-safe way,
ACPI_COMPANION() and ACPI_COMPANION_SET(), and rework the
ACPI_HANDLE() macro to take the above changes into account.
Drop the ACPI_HANDLE_SET() macro entirely and rework its users to
use ACPI_COMPANION_SET() instead. For some of them who used to
pass the result of acpi_get_child() directly to ACPI_HANDLE_SET()
introduce a helper routine acpi_preset_companion() doing an
equivalent thing.
The main motivation for doing this is that there are things
represented by struct acpi_device objects that don't have valid
ACPI handles (so called fixed ACPI hardware features, such as
power and sleep buttons) and we would like to create platform
device objects for them and "glue" them to their ACPI companions
in the usual way (which currently is impossible due to the
lack of valid ACPI handles). However, there are more reasons
why it may be useful.
First, struct acpi_device pointers allow of much better type checking
than void pointers which are ACPI handles, so it should be more
difficult to write buggy code using modified struct acpi_dev_node
and the new macros. Second, the change should help to reduce (over
time) the number of places in which the result of ACPI_HANDLE() is
passed to acpi_bus_get_device() in order to obtain a pointer to the
struct acpi_device associated with the given "physical" device,
because now that pointer is returned by ACPI_COMPANION() directly.
Finally, the change should make it easier to write generic code that
will build both for CONFIG_ACPI set and unset without adding explicit
compiler directives to it.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com> # on Haswell
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Aaron Lu <aaron.lu@intel.com> # for ATA and SDIO part
2013-11-12 05:41:56 +08:00
|
|
|
ACPI_COMPANION_SET(dev, NULL);
|
2013-11-15 06:18:32 +08:00
|
|
|
/* Drop references taken by acpi_bind_one(). */
|
2013-08-07 07:22:08 +08:00
|
|
|
put_device(dev);
|
2013-11-15 06:18:32 +08:00
|
|
|
put_device(&acpi_dev->dev);
|
2013-08-07 07:22:08 +08:00
|
|
|
kfree(entry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-17 14:44:09 +08:00
|
|
|
mutex_unlock(&acpi_dev->physical_node_lock);
|
2005-03-19 07:45:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
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-03 06:26:22 +08:00
|
|
|
EXPORT_SYMBOL_GPL(acpi_unbind_one);
|
2005-03-19 07:45:35 +08:00
|
|
|
|
|
|
|
static int acpi_platform_notify(struct device *dev)
|
|
|
|
{
|
2013-03-04 05:35:20 +08:00
|
|
|
struct acpi_bus_type *type = acpi_get_bus_type(dev);
|
2014-02-11 07:35:46 +08:00
|
|
|
struct acpi_device *adev;
|
2012-12-23 07:02:13 +08:00
|
|
|
int ret;
|
2005-03-19 07:45:35 +08:00
|
|
|
|
2012-11-21 07:21:39 +08:00
|
|
|
ret = acpi_bind_one(dev, NULL);
|
2013-03-04 05:35:44 +08:00
|
|
|
if (ret && type) {
|
2013-11-29 23:27:34 +08:00
|
|
|
struct acpi_device *adev;
|
|
|
|
|
|
|
|
adev = type->find_companion(dev);
|
|
|
|
if (!adev) {
|
2012-12-23 07:02:13 +08:00
|
|
|
DBG("Unable to get handle for %s\n", dev_name(dev));
|
2013-11-29 23:27:34 +08:00
|
|
|
ret = -ENODEV;
|
2012-12-23 07:02:13 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2013-11-29 23:27:43 +08:00
|
|
|
ret = acpi_bind_one(dev, adev);
|
2012-12-23 07:02:13 +08:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
2005-03-19 07:45:35 +08:00
|
|
|
}
|
2014-02-11 07:35:46 +08:00
|
|
|
adev = ACPI_COMPANION(dev);
|
|
|
|
if (!adev)
|
|
|
|
goto out;
|
2012-12-23 07:02:13 +08:00
|
|
|
|
|
|
|
if (type && type->setup)
|
|
|
|
type->setup(dev);
|
2014-02-11 07:35:46 +08:00
|
|
|
else if (adev->handler && adev->handler->bind)
|
|
|
|
adev->handler->bind(dev);
|
2005-03-19 07:45:35 +08:00
|
|
|
|
2012-11-21 07:21:39 +08:00
|
|
|
out:
|
2005-03-19 07:45:35 +08:00
|
|
|
#if ACPI_GLUE_DEBUG
|
|
|
|
if (!ret) {
|
|
|
|
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
|
|
|
|
|
2013-01-12 21:00:06 +08:00
|
|
|
acpi_get_name(ACPI_HANDLE(dev), ACPI_FULL_PATHNAME, &buffer);
|
2009-01-26 06:40:56 +08:00
|
|
|
DBG("Device %s -> %s\n", dev_name(dev), (char *)buffer.pointer);
|
2006-06-30 15:19:10 +08:00
|
|
|
kfree(buffer.pointer);
|
2005-03-19 07:45:35 +08:00
|
|
|
} else
|
2009-01-26 06:40:56 +08:00
|
|
|
DBG("Device %s -> No ACPI support\n", dev_name(dev));
|
2005-03-19 07:45:35 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int acpi_platform_notify_remove(struct device *dev)
|
|
|
|
{
|
2014-02-11 07:35:46 +08:00
|
|
|
struct acpi_device *adev = ACPI_COMPANION(dev);
|
2012-12-23 07:02:13 +08:00
|
|
|
struct acpi_bus_type *type;
|
|
|
|
|
2014-02-11 07:35:46 +08:00
|
|
|
if (!adev)
|
|
|
|
return 0;
|
|
|
|
|
2013-03-04 05:35:20 +08:00
|
|
|
type = acpi_get_bus_type(dev);
|
2012-12-23 07:02:13 +08:00
|
|
|
if (type && type->cleanup)
|
|
|
|
type->cleanup(dev);
|
2014-02-11 07:35:46 +08:00
|
|
|
else if (adev->handler && adev->handler->unbind)
|
|
|
|
adev->handler->unbind(dev);
|
2012-12-23 07:02:13 +08:00
|
|
|
|
2005-03-19 07:45:35 +08:00
|
|
|
acpi_unbind_one(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-25 06:50:09 +08:00
|
|
|
int __init init_acpi_device_notify(void)
|
2005-03-19 07:45:35 +08: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;
|
|
|
|
}
|