2019-06-01 11:08:42 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-03-19 02:45:35 +03:00
|
|
|
/*
|
|
|
|
* Link physical devices with ACPI devices support
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005 David Shaohua Li <shaohua.li@intel.com>
|
|
|
|
* Copyright (c) 2005 Intel Corp.
|
|
|
|
*/
|
2017-03-07 15:40:06 +03:00
|
|
|
|
2021-06-02 11:54:27 +03:00
|
|
|
#define pr_fmt(fmt) "ACPI: " fmt
|
|
|
|
|
2017-03-07 15:40:06 +03:00
|
|
|
#include <linux/acpi_iort.h>
|
2011-10-27 00:22:14 +04:00
|
|
|
#include <linux/export.h>
|
2005-03-19 02:45:35 +03:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/device.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2005-03-19 02:45:35 +03:00
|
|
|
#include <linux/rwsem.h>
|
|
|
|
#include <linux/acpi.h>
|
2015-06-10 19:08:52 +03:00
|
|
|
#include <linux/dma-mapping.h>
|
2021-09-18 15:53:44 +03:00
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/pci-acpi.h>
|
2017-03-07 15:40:06 +03:00
|
|
|
#include <linux/platform_device.h>
|
2005-03-19 02:45:35 +03:00
|
|
|
|
2009-07-29 00:45:54 +04:00
|
|
|
#include "internal.h"
|
|
|
|
|
2005-03-19 02:45:35 +03:00
|
|
|
static LIST_HEAD(bus_type_list);
|
|
|
|
static DECLARE_RWSEM(bus_type_sem);
|
|
|
|
|
2012-08-17 10:44:09 +04:00
|
|
|
#define PHYSICAL_NODE_STRING "physical_node"
|
2013-08-06 16:32:54 +04:00
|
|
|
#define PHYSICAL_NODE_NAME_SIZE (sizeof(PHYSICAL_NODE_STRING) + 10)
|
2012-08-17 10:44:09 +04:00
|
|
|
|
2005-03-19 02:45:35 +03:00
|
|
|
int register_acpi_bus_type(struct acpi_bus_type *type)
|
|
|
|
{
|
|
|
|
if (acpi_disabled)
|
|
|
|
return -ENODEV;
|
2013-11-29 19:27:34 +04:00
|
|
|
if (type && type->match && type->find_companion) {
|
2005-03-19 02:45:35 +03:00
|
|
|
down_write(&bus_type_sem);
|
|
|
|
list_add_tail(&type->list, &bus_type_list);
|
|
|
|
up_write(&bus_type_sem);
|
2021-06-02 11:54:27 +03:00
|
|
|
pr_info("bus type %s registered\n", type->name);
|
2005-03-19 02:45:35 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2012-07-25 22:24:13 +04:00
|
|
|
EXPORT_SYMBOL_GPL(register_acpi_bus_type);
|
2005-03-19 02:45:35 +03:00
|
|
|
|
|
|
|
int unregister_acpi_bus_type(struct acpi_bus_type *type)
|
|
|
|
{
|
|
|
|
if (acpi_disabled)
|
|
|
|
return 0;
|
|
|
|
if (type) {
|
|
|
|
down_write(&bus_type_sem);
|
|
|
|
list_del_init(&type->list);
|
|
|
|
up_write(&bus_type_sem);
|
2021-06-02 11:54:27 +03:00
|
|
|
pr_info("bus type %s unregistered\n", type->name);
|
2005-03-19 02:45:35 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2012-07-25 22:24:13 +04:00
|
|
|
EXPORT_SYMBOL_GPL(unregister_acpi_bus_type);
|
2005-03-19 02:45:35 +03:00
|
|
|
|
2013-03-04 01:35:20 +04:00
|
|
|
static struct acpi_bus_type *acpi_get_bus_type(struct device *dev)
|
2005-03-19 02:45:35 +03: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 01:35:20 +04:00
|
|
|
if (tmp->match(dev)) {
|
2005-03-19 02:45:35 +03:00
|
|
|
ret = tmp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
up_read(&bus_type_sem);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-09-10 01:07:47 +04:00
|
|
|
#define FIND_CHILD_MIN_SCORE 1
|
ACPI: Fix selecting wrong ACPI fwnode for the iGPU on some Dell laptops
The Dell Latitude E6430 both with and without the optional NVidia dGPU
has a bug in its ACPI tables which is causing Linux to assign the wrong
ACPI fwnode / companion to the pci_device for the i915 iGPU.
Specifically under the PCI root bridge there are these 2 ACPI Device()s :
Scope (_SB.PCI0)
{
Device (GFX0)
{
Name (_ADR, 0x00020000) // _ADR: Address
}
...
Device (VID)
{
Name (_ADR, 0x00020000) // _ADR: Address
...
Method (_DOS, 1, NotSerialized) // _DOS: Disable Output Switching
{
VDP8 = Arg0
VDP1 (One, VDP8)
}
Method (_DOD, 0, NotSerialized) // _DOD: Display Output Devices
{
...
}
...
}
}
The non-functional GFX0 ACPI device is a problem, because this gets
returned as ACPI companion-device by acpi_find_child_device() for the iGPU.
This is a long standing problem and the i915 driver does use the ACPI
companion for some things, but works fine without it.
However since commit 63f534b8bad9 ("ACPI: PCI: Rework acpi_get_pci_dev()")
acpi_get_pci_dev() relies on the physical-node pointer in the acpi_device
and that is set on the wrong acpi_device because of the wrong
acpi_find_child_device() return. This breaks the ACPI video code,
leading to non working backlight control in some cases.
Add a type.backlight flag, mark ACPI video bus devices with this and make
find_child_checks() return a higher score for children with this flag set,
so that it picks the right companion-device.
Fixes: 63f534b8bad9 ("ACPI: PCI: Rework acpi_get_pci_dev()")
Co-developed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Cc: 6.1+ <stable@vger.kernel.org> # 6.1+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-01-10 18:30:28 +03:00
|
|
|
#define FIND_CHILD_MID_SCORE 2
|
|
|
|
#define FIND_CHILD_MAX_SCORE 3
|
2013-09-10 01:07:47 +04:00
|
|
|
|
2022-06-13 21:06:18 +03:00
|
|
|
static int match_any(struct acpi_device *adev, void *not_used)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool acpi_dev_has_children(struct acpi_device *adev)
|
|
|
|
{
|
|
|
|
return acpi_dev_for_each_child(adev, match_any, NULL) > 0;
|
|
|
|
}
|
|
|
|
|
2013-11-29 02:57:58 +04: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 00:55:00 +04:00
|
|
|
{
|
|
|
|
unsigned long long sta;
|
|
|
|
acpi_status status;
|
|
|
|
|
2022-06-13 21:06:18 +03:00
|
|
|
if (check_children && !acpi_dev_has_children(adev))
|
2022-05-05 21:52:57 +03:00
|
|
|
return -ENODEV;
|
|
|
|
|
2013-11-29 02:57:58 +04:00
|
|
|
status = acpi_evaluate_integer(adev->handle, "_STA", NULL, &sta);
|
ACPI: Fix selecting wrong ACPI fwnode for the iGPU on some Dell laptops
The Dell Latitude E6430 both with and without the optional NVidia dGPU
has a bug in its ACPI tables which is causing Linux to assign the wrong
ACPI fwnode / companion to the pci_device for the i915 iGPU.
Specifically under the PCI root bridge there are these 2 ACPI Device()s :
Scope (_SB.PCI0)
{
Device (GFX0)
{
Name (_ADR, 0x00020000) // _ADR: Address
}
...
Device (VID)
{
Name (_ADR, 0x00020000) // _ADR: Address
...
Method (_DOS, 1, NotSerialized) // _DOS: Disable Output Switching
{
VDP8 = Arg0
VDP1 (One, VDP8)
}
Method (_DOD, 0, NotSerialized) // _DOD: Display Output Devices
{
...
}
...
}
}
The non-functional GFX0 ACPI device is a problem, because this gets
returned as ACPI companion-device by acpi_find_child_device() for the iGPU.
This is a long standing problem and the i915 driver does use the ACPI
companion for some things, but works fine without it.
However since commit 63f534b8bad9 ("ACPI: PCI: Rework acpi_get_pci_dev()")
acpi_get_pci_dev() relies on the physical-node pointer in the acpi_device
and that is set on the wrong acpi_device because of the wrong
acpi_find_child_device() return. This breaks the ACPI video code,
leading to non working backlight control in some cases.
Add a type.backlight flag, mark ACPI video bus devices with this and make
find_child_checks() return a higher score for children with this flag set,
so that it picks the right companion-device.
Fixes: 63f534b8bad9 ("ACPI: PCI: Rework acpi_get_pci_dev()")
Co-developed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Cc: 6.1+ <stable@vger.kernel.org> # 6.1+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-01-10 18:30:28 +03:00
|
|
|
if (status == AE_NOT_FOUND) {
|
|
|
|
/*
|
|
|
|
* Special case: backlight device objects without _STA are
|
|
|
|
* preferred to other objects with the same _ADR value, because
|
|
|
|
* it is more likely that they are actually useful.
|
|
|
|
*/
|
|
|
|
if (adev->pnp.type.backlight)
|
|
|
|
return FIND_CHILD_MID_SCORE;
|
|
|
|
|
2022-05-05 21:52:57 +03:00
|
|
|
return FIND_CHILD_MIN_SCORE;
|
ACPI: Fix selecting wrong ACPI fwnode for the iGPU on some Dell laptops
The Dell Latitude E6430 both with and without the optional NVidia dGPU
has a bug in its ACPI tables which is causing Linux to assign the wrong
ACPI fwnode / companion to the pci_device for the i915 iGPU.
Specifically under the PCI root bridge there are these 2 ACPI Device()s :
Scope (_SB.PCI0)
{
Device (GFX0)
{
Name (_ADR, 0x00020000) // _ADR: Address
}
...
Device (VID)
{
Name (_ADR, 0x00020000) // _ADR: Address
...
Method (_DOS, 1, NotSerialized) // _DOS: Disable Output Switching
{
VDP8 = Arg0
VDP1 (One, VDP8)
}
Method (_DOD, 0, NotSerialized) // _DOD: Display Output Devices
{
...
}
...
}
}
The non-functional GFX0 ACPI device is a problem, because this gets
returned as ACPI companion-device by acpi_find_child_device() for the iGPU.
This is a long standing problem and the i915 driver does use the ACPI
companion for some things, but works fine without it.
However since commit 63f534b8bad9 ("ACPI: PCI: Rework acpi_get_pci_dev()")
acpi_get_pci_dev() relies on the physical-node pointer in the acpi_device
and that is set on the wrong acpi_device because of the wrong
acpi_find_child_device() return. This breaks the ACPI video code,
leading to non working backlight control in some cases.
Add a type.backlight flag, mark ACPI video bus devices with this and make
find_child_checks() return a higher score for children with this flag set,
so that it picks the right companion-device.
Fixes: 63f534b8bad9 ("ACPI: PCI: Rework acpi_get_pci_dev()")
Co-developed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Cc: 6.1+ <stable@vger.kernel.org> # 6.1+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-01-10 18:30:28 +03: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-08 00:55:00 +04:00
|
|
|
|
2022-05-05 21:52:57 +03:00
|
|
|
if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_ENABLED))
|
2013-11-29 02:57:58 +04:00
|
|
|
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 00:55:00 +04:00
|
|
|
|
2016-12-30 04:27:31 +03:00
|
|
|
/*
|
2017-04-01 01:45:52 +03:00
|
|
|
* If the device has a _HID returning a valid ACPI/PNP device ID, it is
|
|
|
|
* better to make it look less attractive here, so that the other device
|
|
|
|
* with the same _ADR value (that may not have a valid device ID) can be
|
|
|
|
* matched going forward. [This means a second spec violation in a row,
|
|
|
|
* so whatever we do here is best effort anyway.]
|
2016-12-30 04:27:31 +03:00
|
|
|
*/
|
2022-05-05 21:52:57 +03:00
|
|
|
if (adev->pnp.type.platform_id)
|
|
|
|
return FIND_CHILD_MIN_SCORE;
|
|
|
|
|
|
|
|
return FIND_CHILD_MAX_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 00:55:00 +04:00
|
|
|
}
|
|
|
|
|
2022-06-13 21:05:17 +03:00
|
|
|
struct find_child_walk_data {
|
|
|
|
struct acpi_device *adev;
|
|
|
|
u64 address;
|
|
|
|
int score;
|
2022-06-13 21:10:03 +03:00
|
|
|
bool check_sta;
|
2022-06-13 21:05:17 +03:00
|
|
|
bool check_children;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int check_one_child(struct acpi_device *adev, void *data)
|
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 00:55:00 +04:00
|
|
|
{
|
2022-06-13 21:05:17 +03:00
|
|
|
struct find_child_walk_data *wd = data;
|
|
|
|
int score;
|
2013-11-29 02:57:58 +04:00
|
|
|
|
2022-06-13 21:05:17 +03:00
|
|
|
if (!adev->pnp.type.bus_address || acpi_device_adr(adev) != wd->address)
|
|
|
|
return 0;
|
2013-11-29 02:58:08 +04:00
|
|
|
|
2022-06-13 21:05:17 +03:00
|
|
|
if (!wd->adev) {
|
2022-06-13 21:10:03 +03:00
|
|
|
/*
|
|
|
|
* This is the first matching object, so save it. If it is not
|
|
|
|
* necessary to look for any other matching objects, stop the
|
|
|
|
* search.
|
|
|
|
*/
|
2022-06-13 21:05:17 +03:00
|
|
|
wd->adev = adev;
|
2022-06-13 21:10:03 +03:00
|
|
|
return !(wd->check_sta || wd->check_children);
|
2022-06-13 21:05:17 +03:00
|
|
|
}
|
2013-11-29 02:57:58 +04:00
|
|
|
|
2022-06-13 21:05:17 +03:00
|
|
|
/*
|
|
|
|
* 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, get the score for the previously found object and terminate
|
|
|
|
* the walk if it is maximum.
|
|
|
|
*/
|
|
|
|
if (!wd->score) {
|
|
|
|
score = find_child_checks(wd->adev, wd->check_children);
|
|
|
|
if (score == FIND_CHILD_MAX_SCORE)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
wd->score = score;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Second, if the object that has just been found has a better score,
|
|
|
|
* replace the previously found one with it and terminate the walk if
|
|
|
|
* the new score is maximum.
|
|
|
|
*/
|
|
|
|
score = find_child_checks(adev, wd->check_children);
|
|
|
|
if (score > wd->score) {
|
|
|
|
wd->adev = adev;
|
|
|
|
if (score == FIND_CHILD_MAX_SCORE)
|
|
|
|
return 1;
|
2013-11-29 02:57:58 +04:00
|
|
|
|
2022-06-13 21:05:17 +03:00
|
|
|
wd->score = score;
|
2005-03-19 02:45:35 +03:00
|
|
|
}
|
2022-06-13 21:05:17 +03:00
|
|
|
|
|
|
|
/* Continue, because there may be better matches. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-13 21:10:03 +03:00
|
|
|
static struct acpi_device *acpi_find_child(struct acpi_device *parent,
|
|
|
|
u64 address, bool check_children,
|
|
|
|
bool check_sta)
|
2022-06-13 21:05:17 +03:00
|
|
|
{
|
|
|
|
struct find_child_walk_data wd = {
|
|
|
|
.address = address,
|
|
|
|
.check_children = check_children,
|
2022-06-13 21:10:03 +03:00
|
|
|
.check_sta = check_sta,
|
2022-06-13 21:05:17 +03:00
|
|
|
.adev = NULL,
|
|
|
|
.score = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
acpi_dev_for_each_child(parent, check_one_child, &wd);
|
|
|
|
|
|
|
|
return wd.adev;
|
2005-03-19 02:45:35 +03:00
|
|
|
}
|
2022-06-13 21:10:03 +03:00
|
|
|
|
|
|
|
struct acpi_device *acpi_find_child_device(struct acpi_device *parent,
|
|
|
|
u64 address, bool check_children)
|
|
|
|
{
|
|
|
|
return acpi_find_child(parent, address, check_children, true);
|
|
|
|
}
|
2013-11-29 02:58:28 +04:00
|
|
|
EXPORT_SYMBOL_GPL(acpi_find_child_device);
|
2005-03-19 02:45:35 +03:00
|
|
|
|
2022-06-13 21:10:03 +03:00
|
|
|
struct acpi_device *acpi_find_child_by_adr(struct acpi_device *adev,
|
|
|
|
acpi_bus_address adr)
|
|
|
|
{
|
|
|
|
return acpi_find_child(adev, adr, false, false);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(acpi_find_child_by_adr);
|
|
|
|
|
2013-08-07 03:19:23 +04: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 19:27:43 +04:00
|
|
|
int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
|
2005-03-19 02:45:35 +03:00
|
|
|
{
|
2012-11-21 03:21:39 +04:00
|
|
|
struct acpi_device_physical_node *physical_node, *pn;
|
2013-08-06 16:32:54 +04:00
|
|
|
char physical_node_name[PHYSICAL_NODE_NAME_SIZE];
|
|
|
|
struct list_head *physnode_list;
|
|
|
|
unsigned int node_id;
|
2012-08-17 10:44:09 +04:00
|
|
|
int retval = -EINVAL;
|
2005-03-19 02:45:35 +03:00
|
|
|
|
2015-03-17 01:49:08 +03:00
|
|
|
if (has_acpi_companion(dev)) {
|
2013-11-29 19:27:43 +04: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 01:41:56 +04:00
|
|
|
dev_warn(dev, "ACPI companion already set\n");
|
2012-11-21 03:21:39 +04: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 01:41:56 +04:00
|
|
|
acpi_dev = ACPI_COMPANION(dev);
|
2012-11-21 03:21:39 +04:00
|
|
|
}
|
2005-03-19 02:45:35 +03: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 01:41:56 +04:00
|
|
|
if (!acpi_dev)
|
2012-11-21 03:21:39 +04:00
|
|
|
return -EINVAL;
|
2012-08-17 10:44:09 +04:00
|
|
|
|
2021-04-13 01:23:58 +03:00
|
|
|
acpi_dev_get(acpi_dev);
|
2005-03-19 02:45:35 +03:00
|
|
|
get_device(dev);
|
2012-11-21 03:21:39 +04:00
|
|
|
physical_node = kzalloc(sizeof(*physical_node), GFP_KERNEL);
|
2012-08-17 10:44:09 +04:00
|
|
|
if (!physical_node) {
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto err;
|
2005-03-19 02:45:35 +03:00
|
|
|
}
|
|
|
|
|
2012-08-17 10:44:09 +04:00
|
|
|
mutex_lock(&acpi_dev->physical_node_lock);
|
2012-11-21 03:21:39 +04:00
|
|
|
|
2013-08-06 16:32:54 +04: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 03:21:39 +04:00
|
|
|
if (pn->dev == dev) {
|
2013-08-08 18:19:10 +04:00
|
|
|
mutex_unlock(&acpi_dev->physical_node_lock);
|
|
|
|
|
2012-11-21 03:21:39 +04:00
|
|
|
dev_warn(dev, "Already associated with ACPI node\n");
|
2013-08-08 18:19:10 +04: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 01:41:56 +04:00
|
|
|
if (ACPI_COMPANION(dev) != acpi_dev)
|
2013-08-08 18:19:10 +04:00
|
|
|
goto err;
|
2013-08-07 03:15:25 +04:00
|
|
|
|
2013-08-08 18:19:10 +04:00
|
|
|
put_device(dev);
|
2021-04-13 01:23:58 +03:00
|
|
|
acpi_dev_put(acpi_dev);
|
2013-08-08 18:19:10 +04:00
|
|
|
return 0;
|
2012-11-21 03:21:39 +04:00
|
|
|
}
|
2013-08-06 16:32:54 +04:00
|
|
|
if (pn->node_id == node_id) {
|
|
|
|
physnode_list = &pn->node;
|
|
|
|
node_id++;
|
|
|
|
}
|
2008-02-23 08:54:24 +03:00
|
|
|
}
|
|
|
|
|
2013-08-06 16:32:54 +04:00
|
|
|
physical_node->node_id = node_id;
|
2012-08-17 10:44:09 +04:00
|
|
|
physical_node->dev = dev;
|
2013-08-06 16:32:54 +04:00
|
|
|
list_add(&physical_node->node, physnode_list);
|
2012-08-17 10:44:09 +04:00
|
|
|
acpi_dev->physical_node_count++;
|
2012-11-21 03:21:39 +04:00
|
|
|
|
2015-03-17 01:49:08 +03: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 01:41:56 +04:00
|
|
|
ACPI_COMPANION_SET(dev, acpi_dev);
|
2012-08-17 10:44:09 +04:00
|
|
|
|
2013-08-07 03:19:23 +04:00
|
|
|
acpi_physnode_link_name(physical_node_name, node_id);
|
2012-08-17 10:44:09 +04:00
|
|
|
retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
|
2013-08-07 03:19:52 +04:00
|
|
|
physical_node_name);
|
2013-08-08 18:19:19 +04:00
|
|
|
if (retval)
|
|
|
|
dev_err(&acpi_dev->dev, "Failed to create link %s (%d)\n",
|
|
|
|
physical_node_name, retval);
|
|
|
|
|
2012-08-17 10:44:09 +04:00
|
|
|
retval = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj,
|
2013-08-07 03:19:52 +04:00
|
|
|
"firmware_node");
|
2013-08-08 18:19:19 +04:00
|
|
|
if (retval)
|
|
|
|
dev_err(dev, "Failed to create link firmware_node (%d)\n",
|
|
|
|
retval);
|
2012-08-17 10:44:09 +04:00
|
|
|
|
2013-08-07 03:19:37 +04:00
|
|
|
mutex_unlock(&acpi_dev->physical_node_lock);
|
|
|
|
|
2012-08-17 10:44:09 +04:00
|
|
|
if (acpi_dev->wakeup.flags.valid)
|
|
|
|
device_set_wakeup_capable(dev, true);
|
|
|
|
|
2005-03-19 02:45:35 +03:00
|
|
|
return 0;
|
2012-08-17 10:44:09 +04:00
|
|
|
|
|
|
|
err:
|
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 01:41:56 +04:00
|
|
|
ACPI_COMPANION_SET(dev, NULL);
|
2012-08-17 10:44:09 +04:00
|
|
|
put_device(dev);
|
2021-04-13 01:23:58 +03:00
|
|
|
acpi_dev_put(acpi_dev);
|
2012-08-17 10:44:09 +04:00
|
|
|
return retval;
|
2005-03-19 02:45:35 +03: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 02:26:22 +04:00
|
|
|
EXPORT_SYMBOL_GPL(acpi_bind_one);
|
2005-03-19 02:45:35 +03: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 02:26:22 +04:00
|
|
|
int acpi_unbind_one(struct device *dev)
|
2005-03-19 02:45:35 +03: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 01:41:56 +04:00
|
|
|
struct acpi_device *acpi_dev = ACPI_COMPANION(dev);
|
2012-08-17 10:44:09 +04: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 01:41:56 +04:00
|
|
|
if (!acpi_dev)
|
2005-03-19 02:45:35 +03:00
|
|
|
return 0;
|
2008-02-23 08:54:24 +03:00
|
|
|
|
2012-08-17 10:44:09 +04:00
|
|
|
mutex_lock(&acpi_dev->physical_node_lock);
|
2013-08-07 03:22:08 +04: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 01:41:56 +04:00
|
|
|
ACPI_COMPANION_SET(dev, NULL);
|
2013-11-15 02:18:32 +04:00
|
|
|
/* Drop references taken by acpi_bind_one(). */
|
2013-08-07 03:22:08 +04:00
|
|
|
put_device(dev);
|
2021-04-13 01:23:58 +03:00
|
|
|
acpi_dev_put(acpi_dev);
|
2013-08-07 03:22:08 +04:00
|
|
|
kfree(entry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-17 10:44:09 +04:00
|
|
|
mutex_unlock(&acpi_dev->physical_node_lock);
|
2005-03-19 02:45:35 +03:00
|
|
|
return 0;
|
|
|
|
}
|
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 02:26:22 +04:00
|
|
|
EXPORT_SYMBOL_GPL(acpi_unbind_one);
|
2005-03-19 02:45:35 +03:00
|
|
|
|
2021-07-12 20:25:55 +03:00
|
|
|
void acpi_device_notify(struct device *dev)
|
2005-03-19 02:45:35 +03:00
|
|
|
{
|
2014-02-11 03:35:46 +04:00
|
|
|
struct acpi_device *adev;
|
2012-12-23 03:02:13 +04:00
|
|
|
int ret;
|
2005-03-19 02:45:35 +03:00
|
|
|
|
2012-11-21 03:21:39 +04:00
|
|
|
ret = acpi_bind_one(dev, NULL);
|
2021-07-12 20:23:32 +03:00
|
|
|
if (ret) {
|
2021-09-18 16:02:23 +03:00
|
|
|
struct acpi_bus_type *type = acpi_get_bus_type(dev);
|
|
|
|
|
2021-07-12 20:23:32 +03:00
|
|
|
if (!type)
|
|
|
|
goto err;
|
2013-11-29 19:27:34 +04:00
|
|
|
|
|
|
|
adev = type->find_companion(dev);
|
|
|
|
if (!adev) {
|
2021-07-12 20:23:32 +03:00
|
|
|
dev_dbg(dev, "ACPI companion not found\n");
|
|
|
|
goto err;
|
2012-12-23 03:02:13 +04:00
|
|
|
}
|
2013-11-29 19:27:43 +04:00
|
|
|
ret = acpi_bind_one(dev, adev);
|
2012-12-23 03:02:13 +04:00
|
|
|
if (ret)
|
2021-07-12 20:23:32 +03:00
|
|
|
goto err;
|
2012-12-23 03:02:13 +04:00
|
|
|
|
2021-09-18 16:02:23 +03:00
|
|
|
if (type->setup) {
|
|
|
|
type->setup(dev);
|
|
|
|
goto done;
|
|
|
|
}
|
2021-09-18 15:53:44 +03:00
|
|
|
} else {
|
2021-09-18 16:02:23 +03:00
|
|
|
adev = ACPI_COMPANION(dev);
|
2017-03-07 15:40:06 +03:00
|
|
|
|
2021-09-18 16:02:23 +03:00
|
|
|
if (dev_is_pci(dev)) {
|
|
|
|
pci_acpi_setup(dev, adev);
|
|
|
|
goto done;
|
|
|
|
} else if (dev_is_platform(dev)) {
|
|
|
|
acpi_configure_pmsi_domain(dev);
|
|
|
|
}
|
2021-09-18 15:53:44 +03:00
|
|
|
}
|
2017-03-07 15:40:06 +03:00
|
|
|
|
2021-09-18 16:02:23 +03:00
|
|
|
if (adev->handler && adev->handler->bind)
|
2014-02-11 03:35:46 +04:00
|
|
|
adev->handler->bind(dev);
|
2005-03-19 02:45:35 +03:00
|
|
|
|
2021-09-18 16:02:23 +03:00
|
|
|
done:
|
2021-07-12 20:23:32 +03:00
|
|
|
acpi_handle_debug(ACPI_HANDLE(dev), "Bound to device %s\n",
|
|
|
|
dev_name(dev));
|
2005-03-19 02:45:35 +03:00
|
|
|
|
2021-07-12 20:23:37 +03:00
|
|
|
return;
|
2021-07-12 20:23:32 +03:00
|
|
|
|
|
|
|
err:
|
|
|
|
dev_dbg(dev, "No ACPI support\n");
|
2005-03-19 02:45:35 +03:00
|
|
|
}
|
|
|
|
|
2021-07-12 20:25:55 +03:00
|
|
|
void acpi_device_notify_remove(struct device *dev)
|
2005-03-19 02:45:35 +03:00
|
|
|
{
|
2014-02-11 03:35:46 +04:00
|
|
|
struct acpi_device *adev = ACPI_COMPANION(dev);
|
2012-12-23 03:02:13 +04:00
|
|
|
|
2014-02-11 03:35:46 +04:00
|
|
|
if (!adev)
|
2021-07-12 20:23:37 +03:00
|
|
|
return;
|
2014-02-11 03:35:46 +04:00
|
|
|
|
2021-09-18 15:56:17 +03:00
|
|
|
if (dev_is_pci(dev))
|
2021-09-18 15:53:44 +03:00
|
|
|
pci_acpi_cleanup(dev, adev);
|
2014-02-11 03:35:46 +04:00
|
|
|
else if (adev->handler && adev->handler->unbind)
|
|
|
|
adev->handler->unbind(dev);
|
2012-12-23 03:02:13 +04:00
|
|
|
|
2005-03-19 02:45:35 +03:00
|
|
|
acpi_unbind_one(dev);
|
|
|
|
}
|