2012-10-12 10:32:54

by Tang Chen

[permalink] [raw]
Subject: [PATCH 0/3] Find pci root bridges by comparing HID from acpi_device_info, not acpi_device.

Hi Yinghai,

I found a little problem in your following patches. :)
[PATCH 00/40] PCI, ACPI, x86: pci root bus hotplug support.

In acpi_is_root_bridge(), it gets device's HID from acpi_device struct.
If the device is not added when the system boots, there will be no
acpi_device for it. And as a result, acpi_is_root_bridge() will fail.
But it doesn't mean that the device is not a root bridge.

In this case, the not-added root bridges have no handle_hotplug_event_root()
callback registerred. And when we hot add it later, it will do nothing.

This patch set changes the acpi_is_root_bridge()'s behavior. When we fail
to get HID from acpi_device, we will get HID from acpi_device_info by
acpi_get_object_info(), which gets the HID from ACPI namespace directly.

So no matter the device is present or not, we will always find out if it
is a pci root bridge, and register a handle_hotplug_event_root() callback
for it.

These patches are based on Lu Yinghai's for-pci-root-bus-hotplug branch.

Tang Chen (3):
Introduce a new acpi to determine HID match.
Do not use acpi_device to find pci root bridge in _init code.
Check exit status of acpi_install_notify_handler() in
find_root_bridges().

drivers/acpi/pci_root.c | 27 ++++++++++++++++++++++-----
drivers/acpi/pci_root_hp.c | 12 +++++++++---
drivers/acpi/scan.c | 24 ++++++++++++++++++++++++
include/acpi/acpi_bus.h | 2 ++
4 files changed, 57 insertions(+), 8 deletions(-)


2012-10-12 10:32:59

by Tang Chen

[permalink] [raw]
Subject: [PATCH 3/3] Check exit status of acpi_install_notify_handler() in find_root_bridges().

acpi_install_notify_handler() could fail. So check the exit status
and give a better debug info.

Signed-off-by: Tang Chen <[email protected]>
---
drivers/acpi/pci_root_hp.c | 12 +++++++++---
1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/acpi/pci_root_hp.c b/drivers/acpi/pci_root_hp.c
index 05a88ae..1985749 100644
--- a/drivers/acpi/pci_root_hp.c
+++ b/drivers/acpi/pci_root_hp.c
@@ -246,6 +246,7 @@ static void handle_hotplug_event_root(acpi_handle handle, u32 type,
static acpi_status __init
find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
{
+ acpi_status status;
char objname[64];
struct acpi_buffer buffer = { .length = sizeof(objname),
.pointer = objname };
@@ -258,9 +259,14 @@ find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)

acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);

- acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
- handle_hotplug_event_root, NULL);
- printk(KERN_DEBUG "acpi root: %s notify handler installed\n", objname);
+ status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
+ handle_hotplug_event_root, NULL);
+ if (ACPI_FAILURE(status))
+ printk(KERN_DEBUG "acpi root: %s notify handler not installed\n"
+ "acpi root: exit status: %u\n",
+ objname, (unsigned int)status);
+ else
+ printk(KERN_DEBUG "acpi root: %s notify handler installed\n", objname);

add_acpi_root_bridge(handle);

--
1.7.1

2012-10-12 10:32:52

by Tang Chen

[permalink] [raw]
Subject: [PATCH 1/3] Introduce a new acpi to determine HID match.

This introduce a new api to determine if a HID matches a list of IDs.
Different from acpi_match_device_ids(), the new api gets HID from
acpi_device_info struct.

Signed-off-by: Tang Chen <[email protected]>
---
drivers/acpi/scan.c | 24 ++++++++++++++++++++++++
include/acpi/acpi_bus.h | 2 ++
2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 03c12e6..41fd4c9 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -312,6 +312,30 @@ int acpi_match_device_ids(struct acpi_device *device,
}
EXPORT_SYMBOL(acpi_match_device_ids);

+int acpi_match_object_info_ids(struct acpi_device_info *info,
+ const struct acpi_device_id *ids)
+{
+ char *hardware_id;
+ int i, j;
+
+ for (i = 0; ids[i].id[0]; i++) {
+ hardware_id = info->hardware_id.string;
+ if (hardware_id &&
+ !strcmp((char *)ids[i].id, hardware_id))
+ return 0;
+
+ for (j = 0; j < info->compatible_id_list.count; j++) {
+ hardware_id = info->compatible_id_list.ids[j].string;
+ if (hardware_id &&
+ !strcmp((char *)ids[i].id, hardware_id))
+ return 0;
+ }
+ }
+
+ return 1;
+}
+EXPORT_SYMBOL(acpi_match_object_info_ids);
+
static void acpi_free_ids(struct acpi_device *device)
{
struct acpi_hardware_id *id, *tmp;
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index f0b9681..f83d581 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -379,6 +379,8 @@ int acpi_bus_start(struct acpi_device *device);
acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd);
int acpi_match_device_ids(struct acpi_device *device,
const struct acpi_device_id *ids);
+int acpi_match_object_info_ids(struct acpi_device_info *info,
+ const struct acpi_device_id *ids);
int acpi_create_dir(struct acpi_device *);
void acpi_remove_dir(struct acpi_device *);

--
1.7.1

2012-10-12 10:32:58

by Tang Chen

[permalink] [raw]
Subject: [PATCH 2/3] Do not use acpi_device to find pci root bridge in _init code.

When the kernel is being initialized, and some hardwares are not added
to system, there won't be acpi_device structs for these devices. But
acpi_is_root_bridge() depends on acpi_device struct. As a result, all
the not-added root bridge will not be judged as a root bridge in
find_root_bridges(). And further more, no handle_hotplug_event_root()
notifier will be installed for them.

This patch introduces a new api to find all root bridges in system by
getting HID directly from ACPI namespace, not depending on acpi_device
struct.

Signed-off-by: Tang Chen <[email protected]>
---
drivers/acpi/pci_root.c | 27 ++++++++++++++++++++++-----
1 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 7d0fb03..3819bee 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -128,9 +128,6 @@ EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle);
/**
* acpi_is_root_bridge - determine whether an ACPI CA node is a PCI root bridge
* @handle - the ACPI CA node in question.
- *
- * Note: we could make this API take a struct acpi_device * instead, but
- * for now, it's more convenient to operate on an acpi_handle.
*/
int acpi_is_root_bridge(acpi_handle handle)
{
@@ -138,8 +135,28 @@ int acpi_is_root_bridge(acpi_handle handle)
struct acpi_device *device;

ret = acpi_bus_get_device(handle, &device);
- if (ret)
- return 0;
+ if (ret) {
+ /**
+ * If a device is not added to the system yet, there won't be
+ * an acpi_device struct for it. But it doesn't mean it is not
+ * a PCI root bridge. In this case we need to get HID and CID
+ * from ACPI namespace directly.
+ */
+ struct acpi_device_info *info;
+ acpi_status status;
+ status = acpi_get_object_info(handle, &info);
+ if (ACPI_FAILURE(status)) {
+ printk(KERN_ERR PREFIX "%s: Error reading"
+ "device info\n", __func__);
+ return 0;
+ }
+
+ ret = acpi_match_object_info_ids(info, root_device_ids);
+ if (ret)
+ return 0;
+ else
+ return 1;
+ }

ret = acpi_match_device_ids(device, root_device_ids);
if (ret)
--
1.7.1

2012-10-12 10:38:01

by Jiang Liu (Gerry)

[permalink] [raw]
Subject: Re: [PATCH 2/3] Do not use acpi_device to find pci root bridge in _init code.

On 2012-10-12 18:31, Tang Chen wrote:
> When the kernel is being initialized, and some hardwares are not added
> to system, there won't be acpi_device structs for these devices. But
> acpi_is_root_bridge() depends on acpi_device struct. As a result, all
> the not-added root bridge will not be judged as a root bridge in
> find_root_bridges(). And further more, no handle_hotplug_event_root()
> notifier will be installed for them.
>
> This patch introduces a new api to find all root bridges in system by
> getting HID directly from ACPI namespace, not depending on acpi_device
> struct.
>
> Signed-off-by: Tang Chen <[email protected]>
> ---
> drivers/acpi/pci_root.c | 27 ++++++++++++++++++++++-----
> 1 files changed, 22 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
> index 7d0fb03..3819bee 100644
> --- a/drivers/acpi/pci_root.c
> +++ b/drivers/acpi/pci_root.c
> @@ -128,9 +128,6 @@ EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle);
> /**
> * acpi_is_root_bridge - determine whether an ACPI CA node is a PCI root bridge
> * @handle - the ACPI CA node in question.
> - *
> - * Note: we could make this API take a struct acpi_device * instead, but
> - * for now, it's more convenient to operate on an acpi_handle.
> */
> int acpi_is_root_bridge(acpi_handle handle)
> {
> @@ -138,8 +135,28 @@ int acpi_is_root_bridge(acpi_handle handle)
> struct acpi_device *device;
>
> ret = acpi_bus_get_device(handle, &device);
> - if (ret)
> - return 0;
> + if (ret) {
> + /**
> + * If a device is not added to the system yet, there won't be
> + * an acpi_device struct for it. But it doesn't mean it is not
> + * a PCI root bridge. In this case we need to get HID and CID
> + * from ACPI namespace directly.
> + */
> + struct acpi_device_info *info;
> + acpi_status status;
> + status = acpi_get_object_info(handle, &info);
> + if (ACPI_FAILURE(status)) {
> + printk(KERN_ERR PREFIX "%s: Error reading"
> + "device info\n", __func__);
> + return 0;
> + }
> +
> + ret = acpi_match_object_info_ids(info, root_device_ids);
> + if (ret)
> + return 0;
> + else
> + return 1;
> + }
I have sent a similar patch to Yinghai before. For simplicity, we could
use acpi_match_object_info_ids() instead of acpi_match_device_ids()
directly.
Thanks!
Gerry

>
> ret = acpi_match_device_ids(device, root_device_ids);
> if (ret)

2012-10-12 10:43:27

by Tang Chen

[permalink] [raw]
Subject: Re: [PATCH 2/3] Do not use acpi_device to find pci root bridge in _init code.

On 10/12/2012 06:36 PM, Jiang Liu wrote:
> On 2012-10-12 18:31, Tang Chen wrote:
>> When the kernel is being initialized, and some hardwares are not added
>> to system, there won't be acpi_device structs for these devices. But
>> acpi_is_root_bridge() depends on acpi_device struct. As a result, all
>> the not-added root bridge will not be judged as a root bridge in
>> find_root_bridges(). And further more, no handle_hotplug_event_root()
>> notifier will be installed for them.
>>
>> This patch introduces a new api to find all root bridges in system by
>> getting HID directly from ACPI namespace, not depending on acpi_device
>> struct.
>>
>> Signed-off-by: Tang Chen<[email protected]>
>> ---
>> drivers/acpi/pci_root.c | 27 ++++++++++++++++++++++-----
>> 1 files changed, 22 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
>> index 7d0fb03..3819bee 100644
>> --- a/drivers/acpi/pci_root.c
>> +++ b/drivers/acpi/pci_root.c
>> @@ -128,9 +128,6 @@ EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle);
>> /**
>> * acpi_is_root_bridge - determine whether an ACPI CA node is a PCI root bridge
>> * @handle - the ACPI CA node in question.
>> - *
>> - * Note: we could make this API take a struct acpi_device * instead, but
>> - * for now, it's more convenient to operate on an acpi_handle.
>> */
>> int acpi_is_root_bridge(acpi_handle handle)
>> {
>> @@ -138,8 +135,28 @@ int acpi_is_root_bridge(acpi_handle handle)
>> struct acpi_device *device;
>>
>> ret = acpi_bus_get_device(handle,&device);
>> - if (ret)
>> - return 0;
>> + if (ret) {
>> + /**
>> + * If a device is not added to the system yet, there won't be
>> + * an acpi_device struct for it. But it doesn't mean it is not
>> + * a PCI root bridge. In this case we need to get HID and CID
>> + * from ACPI namespace directly.
>> + */
>> + struct acpi_device_info *info;
>> + acpi_status status;
>> + status = acpi_get_object_info(handle,&info);
>> + if (ACPI_FAILURE(status)) {
>> + printk(KERN_ERR PREFIX "%s: Error reading"
>> + "device info\n", __func__);
>> + return 0;
>> + }
>> +
>> + ret = acpi_match_object_info_ids(info, root_device_ids);
>> + if (ret)
>> + return 0;
>> + else
>> + return 1;
>> + }
> I have sent a similar patch to Yinghai before. For simplicity, we could
> use acpi_match_object_info_ids() instead of acpi_match_device_ids()
> directly.

Hum, I must have missed it. :)
Using acpi_match_object_info_ids() directly seems good. I'm just worry
about if it could cause any other problem. :)

So now, is this bug fixed ? And we don't need these patches, right ?

Thanks. :)

> Thanks!
> Gerry
>
>>
>> ret = acpi_match_device_ids(device, root_device_ids);
>> if (ret)
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2012-10-12 10:55:09

by Jiang Liu (Gerry)

[permalink] [raw]
Subject: Re: [PATCH 2/3] Do not use acpi_device to find pci root bridge in _init code.

On 2012-10-12 18:42, Tang Chen wrote:
> On 10/12/2012 06:36 PM, Jiang Liu wrote:
>> On 2012-10-12 18:31, Tang Chen wrote:
>>> When the kernel is being initialized, and some hardwares are not added
>>> to system, there won't be acpi_device structs for these devices. But
>>> acpi_is_root_bridge() depends on acpi_device struct. As a result, all
>>> the not-added root bridge will not be judged as a root bridge in
>>> find_root_bridges(). And further more, no handle_hotplug_event_root()
>>> notifier will be installed for them.
>>>
>>> This patch introduces a new api to find all root bridges in system by
>>> getting HID directly from ACPI namespace, not depending on acpi_device
>>> struct.
>>>
>>> Signed-off-by: Tang Chen<[email protected]>
>>> ---
>>> drivers/acpi/pci_root.c | 27 ++++++++++++++++++++++-----
>>> 1 files changed, 22 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
>>> index 7d0fb03..3819bee 100644
>>> --- a/drivers/acpi/pci_root.c
>>> +++ b/drivers/acpi/pci_root.c
>>> @@ -128,9 +128,6 @@ EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle);
>>> /**
>>> * acpi_is_root_bridge - determine whether an ACPI CA node is a PCI root bridge
>>> * @handle - the ACPI CA node in question.
>>> - *
>>> - * Note: we could make this API take a struct acpi_device * instead, but
>>> - * for now, it's more convenient to operate on an acpi_handle.
>>> */
>>> int acpi_is_root_bridge(acpi_handle handle)
>>> {
>>> @@ -138,8 +135,28 @@ int acpi_is_root_bridge(acpi_handle handle)
>>> struct acpi_device *device;
>>>
>>> ret = acpi_bus_get_device(handle,&device);
>>> - if (ret)
>>> - return 0;
>>> + if (ret) {
>>> + /**
>>> + * If a device is not added to the system yet, there won't be
>>> + * an acpi_device struct for it. But it doesn't mean it is not
>>> + * a PCI root bridge. In this case we need to get HID and CID
>>> + * from ACPI namespace directly.
>>> + */
>>> + struct acpi_device_info *info;
>>> + acpi_status status;
>>> + status = acpi_get_object_info(handle,&info);
>>> + if (ACPI_FAILURE(status)) {
>>> + printk(KERN_ERR PREFIX "%s: Error reading"
>>> + "device info\n", __func__);
>>> + return 0;
>>> + }
>>> +
>>> + ret = acpi_match_object_info_ids(info, root_device_ids);
>>> + if (ret)
>>> + return 0;
>>> + else
>>> + return 1;
>>> + }
>> I have sent a similar patch to Yinghai before. For simplicity, we could
>> use acpi_match_object_info_ids() instead of acpi_match_device_ids()
>> directly.
>
> Hum, I must have missed it. :)
> Using acpi_match_object_info_ids() directly seems good. I'm just worry
> about if it could cause any other problem. :)
>
> So now, is this bug fixed ? And we don't need these patches, right ?
>
> Thanks. :)
I think Yinghai has missed my patch too, so just suggest to use
acpi_match_object_info_ids() directly.

--Gerry

>
>> Thanks!
>> Gerry
>>
>>>
>>> ret = acpi_match_device_ids(device, root_device_ids);
>>> if (ret)
>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>
>
> .
>

2012-10-12 10:59:16

by Tang Chen

[permalink] [raw]
Subject: Re: [PATCH 2/3] Do not use acpi_device to find pci root bridge in _init code.

On 10/12/2012 06:54 PM, Jiang Liu wrote:
>>> I have sent a similar patch to Yinghai before. For simplicity, we could
>>> use acpi_match_object_info_ids() instead of acpi_match_device_ids()
>>> directly.
>>
>> Hum, I must have missed it. :)
>> Using acpi_match_object_info_ids() directly seems good. I'm just worry
>> about if it could cause any other problem. :)
>>
>> So now, is this bug fixed ? And we don't need these patches, right ?
>>
>> Thanks. :)
> I think Yinghai has missed my patch too, so just suggest to use
> acpi_match_object_info_ids() directly.

OK. :)

I will resend a new patch set soon. Thanks for your advice. :)

>
> --Gerry
>
>>
>>> Thanks!
>>> Gerry
>>>
>>>>
>>>> ret = acpi_match_device_ids(device, root_device_ids);
>>>> if (ret)
>>>
>>>
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
>>> the body of a message to [email protected]
>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>
>>
>>
>> .
>>
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>

2012-10-12 18:34:13

by Yinghai Lu

[permalink] [raw]
Subject: Re: [PATCH 2/3] Do not use acpi_device to find pci root bridge in _init code.

On Fri, Oct 12, 2012 at 3:54 AM, Jiang Liu <[email protected]> wrote:
> On 2012-10-12 18:42, Tang Chen wrote:
>> On 10/12/2012 06:36 PM, Jiang Liu wrote:
>>> I have sent a similar patch to Yinghai before. For simplicity, we could
>>> use acpi_match_object_info_ids() instead of acpi_match_device_ids()
>>> directly.
>>
>> Hum, I must have missed it. :)
>> Using acpi_match_object_info_ids() directly seems good. I'm just worry
>> about if it could cause any other problem. :)
>>
>> So now, is this bug fixed ? And we don't need these patches, right ?
>>
>> Thanks. :)
> I think Yinghai has missed my patch too, so just suggest to use
> acpi_match_object_info_ids() directly.

i put that patch from Jiang in my branch for while, and later found it
cause pci_root_bus notifying
do not work anymore, so i dropped that.

Yinghai

2012-10-12 22:00:56

by Yinghai Lu

[permalink] [raw]
Subject: Re: [PATCH 2/3] Do not use acpi_device to find pci root bridge in _init code.

On Fri, Oct 12, 2012 at 11:34 AM, Yinghai Lu <[email protected]> wrote:
> On Fri, Oct 12, 2012 at 3:54 AM, Jiang Liu <[email protected]> wrote:
>> On 2012-10-12 18:42, Tang Chen wrote:
>>> On 10/12/2012 06:36 PM, Jiang Liu wrote:
>>>> I have sent a similar patch to Yinghai before. For simplicity, we could
>>>> use acpi_match_object_info_ids() instead of acpi_match_device_ids()
>>>> directly.
>>>
>>> Hum, I must have missed it. :)
>>> Using acpi_match_object_info_ids() directly seems good. I'm just worry
>>> about if it could cause any other problem. :)
>>>
>>> So now, is this bug fixed ? And we don't need these patches, right ?
>>>
>>> Thanks. :)
>> I think Yinghai has missed my patch too, so just suggest to use
>> acpi_match_object_info_ids() directly.
>
> i put that patch from Jiang in my branch for while, and later found it
> cause pci_root_bus notifying
> do not work anymore, so i dropped that.

I updated three patches and put them into my for-pci-split-pci-root-hp-2 branch.

http://git.kernel.org/?p=linux/kernel/git/yinghai/linux-yinghai.git;a=shortlog;h=refs/heads/for-pci-split-pci-root-hp-2

git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git
for-pci-split-pci-root-hp-2

Thanks

Yinghai


Attachments:
0001-ACPI-Introduce-a-new-acpi-handle-to-determine-HID-ma.patch (2.69 kB)
0002-PCI-correctly-detect-ACPI-PCI-host-bridge-objects.patch (2.47 kB)
0003-PCI-ACPI-debug-print-for-installation-of-acpi-root-b.patch (1.71 kB)
Download all attachments