ACPI: Rework acpi_bus_trim()
Subsystems (3)
PATCH 5/5 ACPI / scan: Add second pass to acpi_bus_trim()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Make acpi_bus_trim() work in analogy with acpi_bus_scan() and carry out two passes such that ACPI drivers will be detached from device nodes being removed in the first pass and the device nodes themselves will be removed in the second pass.
For this purpose split the driver unregistration out of acpi_bus_remove() into a new routine, acpi_bus_device_detach(), that will be executed by acpi_bus_trim() in the additional first pass as a post-order callback.
This is necessary, because some ACPI drivers' .remove() routines unregister struct device objects associated with the ACPI device nodes being removed and that needs to happen while the ACPI device nodes are still around (for example, in case they need to be used for power management or similar things at that time).
--- drivers/acpi/scan.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-)
drivers/acpi/scan.c +28 -16
@@ -1425,22 +1425,6 @@ static void acpi_device_set_id(struct ac } } -static acpi_status acpi_bus_remove (acpi_handle handle,u32 lvl_not_used, -void *not_used,void **ret_not_used) -{ -struct acpi_device *dev =NULL ; - -if (acpi_bus_get_device (handle, &dev)) -return AE_OK ; - - dev->removal_type =ACPI_BUS_REMOVAL_EJECT ; -device_release_driver (&dev->dev); - -acpi_device_unregister (dev); - -return AE_OK ; -} -void acpi_init_device_object (struct acpi_device *device,acpi_handle handle,int type,unsigned long long sta) {
@@ -1647,8 +1631,36 @@ int acpi_bus_add(acpi_handle handle) }EXPORT_SYMBOL (acpi_bus_add); +static acpi_status acpi_bus_device_detach (acpi_handle handle,u32 lvl_not_used, +void *not_used,void **ret_not_used) +{ +struct acpi_device *device =NULL ; + +if (!acpi_bus_get_device (handle, &device)) { + device->removal_type =ACPI_BUS_REMOVAL_EJECT ; +device_release_driver (&device->dev); + } +return AE_OK ; +} + +static acpi_status acpi_bus_remove (acpi_handle handle,u32 lvl_not_used, +void *not_used,void **ret_not_used) +{ +struct acpi_device *device =NULL ; + +if (!acpi_bus_get_device (handle, &device)) +acpi_device_unregister (device); + +return AE_OK ; +} +int acpi_bus_trim (struct acpi_device *start) { +/* Detach all ACPI drivers from the device nodes being removed. */ +acpi_walk_namespace (ACPI_TYPE_ANY , start->handle,ACPI_UINT32_MAX ,NULL , + acpi_bus_device_detach,NULL ,NULL ); +acpi_bus_device_detach (start->handle,0 ,NULL ,NULL ); +/* Remove the device nodes. */ acpi_walk_namespace (ACPI_TYPE_ANY , start->handle,ACPI_UINT32_MAX ,NULL , acpi_bus_remove,NULL ,NULL );acpi_bus_remove (start->handle,0 ,NULL ,NULL );
PATCH 2/5 ACPI / scan: Drop the second argument of acpi_device_unregister()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Drop the second argument of acpi_device_unregister(), type, which is not used by that function.
--- drivers/acpi/scan.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/acpi/scan.c +3 -3
@@ -776,7 +776,7 @@ int acpi_device_register(struct acpi_devreturn result; } -static void acpi_device_unregister (struct acpi_device *device,int type) +static void acpi_device_unregister (struct acpi_device *device) {mutex_lock (&acpi_device_lock);if (device->parent)
@@ -1436,7 +1436,7 @@ static int acpi_bus_remove(struct acpi_dif (!rmdevice)return 0 ; -acpi_device_unregister (dev,ACPI_BUS_REMOVAL_EJECT ); +acpi_device_unregister (dev);return 0 ; }
@@ -1750,7 +1750,7 @@ int __init acpi_scan_init(void) result =acpi_bus_scan_fixed ();if (result) -acpi_device_unregister (acpi_root,ACPI_BUS_REMOVAL_NORMAL ); +acpi_device_unregister (acpi_root);else acpi_update_all_gpes ();
cover ACPI: Rework acpi_bus_trim()
Hi All,
This series of patches changes the way acpi_bus_trim() works so that, eventually, it walks the namespace twice detaching (ACPI) drivers from device nodes being removed in the first pass and removing the device nodes in the second pass.
The first two patches are just cleanups removing unused stuff:
[1/5] Remove the ops field from struct acpi_device (unrelated to the rest). [2/5] Drop the second argument of acpi_device_unregister().
The next three patches actually rework acpi_bus_trim() in three steps:
[3/5] Drop the second argument of acpi_bus_trim() (all callers pass 1 in there
anyway.
[4/5] Reimplement acpi_bus_trim() using acpi_walk_namespace(). [3/5] Make acpi_bus_trim() carry out two passes as described above.
I'm aware of the fact that this will conflict with the patches that Yinghai posted a few days ago, but in my opinion the changes here are prerequisite for the Yinghai's patchset.
Thanks,
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
PATCH 4/5 ACPI / scan: Change the implementation of acpi_bus_trim()
From: Rafael J. Wysocki <[email protected]>
The current acpi_bus_trim() implementation is not really straightforward and may be simplified significantly by using acpi_walk_namespace() with acpi_bus_remove() as a post-order callback.
Observe that acpi_bus_remove(), as called by acpi_bus_trim(), cannot actually fail, because its first argument is guaranteed not to be NULL thanks to the acpi_bus_get_device() check in acpi_bus_trim(), so simply move the acpi_bus_get_device() check to acpi_bus_remove() and use acpi_walk_namespace() to execute it for every device under start->handle as a post-order callback. The, run it directly for start->handle itself.
--- drivers/acpi/scan.c | 60 +++++++++------------------------------------------- 1 file changed, 11 insertions(+), 49 deletions(-)
drivers/acpi/scan.c +11 -49
@@ -1425,17 +1425,20 @@ static void acpi_device_set_id(struct ac } } -static int acpi_bus_remove (struct acpi_device *dev) +static acpi_status acpi_bus_remove (acpi_handle handle,u32 lvl_not_used, +void *not_used,void **ret_not_used) { -if (!dev) -return -EINVAL ; +struct acpi_device *dev =NULL ; + +if (acpi_bus_get_device (handle, &dev)) +return AE_OK ; dev->removal_type =ACPI_BUS_REMOVAL_EJECT ;device_release_driver (&dev->dev);acpi_device_unregister (dev); -return 0 ; +return AE_OK ; } void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
@@ -1646,51 +1649,10 @@ EXPORT_SYMBOL(acpi_bus_add);int acpi_bus_trim (struct acpi_device *start) { -acpi_status status; -struct acpi_device *parent, *child; -acpi_handle phandle, chandle; -acpi_object_type type; -u32 level =1 ; -int err =0 ; - - parent = start; - phandle = start->handle; - child = chandle =NULL ; - -while ((level >0 ) && parent && (!err)) { - status =acpi_get_next_object (ACPI_TYPE_ANY , phandle, - chandle, &chandle); - -/* -* If this scope is exhausted then move our way back up. -*/ -if (ACPI_FAILURE (status)) { - level--; - chandle = phandle; -acpi_get_parent (phandle, &phandle); - child = parent; - parent = parent->parent; - err =acpi_bus_remove (child); -continue ; - } - - status =acpi_get_type (chandle, &type); -if (ACPI_FAILURE (status)) { -continue ; - } -/* -* If there is a device corresponding to chandle then -* parse it (depth-first). -*/ -if (acpi_bus_get_device (chandle, &child) ==0 ) { - level++; - phandle = chandle; - chandle =NULL ; - parent = child; - } -continue ; - } -return err; +acpi_walk_namespace (ACPI_TYPE_ANY , start->handle,ACPI_UINT32_MAX ,NULL , + acpi_bus_remove,NULL ,NULL ); +acpi_bus_remove (start->handle,0 ,NULL ,NULL ); +return 0 ; }EXPORT_SYMBOL_GPL (acpi_bus_trim);
PATCH 1/5 ACPI: Remove the ops field from struct acpi_device
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The ops field in struct acpi_device is not used anywhere, so remove it.
--- include/acpi/acpi_bus.h | 1 - 1 file changed, 1 deletion(-)
include/acpi/acpi_bus.h +0 -1
@@ -271,7 +271,6 @@ struct acpi_device {struct acpi_device_wakeup wakeup;struct acpi_device_perf performance;struct acpi_device_dir dir; -struct acpi_device_ops ops;struct acpi_driver *driver;void *driver_data;struct device dev;
PATCH 3/5 ACPI / scan: Drop the second argument of acpi_bus_trim()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
All callers of acpi_bus_trim() pass 1 (true) as the second argument of it, so remove that argument entirely and change acpi_bus_trim() to always behave as though it were 1.
--- drivers/acpi/dock.c | 2 +- drivers/acpi/scan.c | 16 ++++------------ drivers/pci/hotplug/acpiphp_glue.c | 4 ++-- drivers/pci/hotplug/sgi_hotplug.c | 2 +- include/acpi/acpi_bus.h | 2 +- 5 files changed, 9 insertions(+), 17 deletions(-)
drivers/acpi/scan.c +4 -12
@@ -133,7 +133,7 @@ void acpi_bus_hot_remove_device(void *coACPI_DEBUG_PRINT ((ACPI_DB_INFO ,"Hot-removing device %s...\n" ,dev_name (&device->dev))); -if (acpi_bus_trim (device,1 )) { +if (acpi_bus_trim (device)) { printk(KERN_ERR PREFIX "Removing device failed\n"); goto err_out;
@@ -1425,7 +1425,7 @@ static void acpi_device_set_id(struct ac } } -static int acpi_bus_remove (struct acpi_device *dev,int rmdevice) +static int acpi_bus_remove (struct acpi_device *dev) {if (!dev)return -EINVAL ;
@@ -1433,9 +1433,6 @@ static int acpi_bus_remove(struct acpi_d dev->removal_type =ACPI_BUS_REMOVAL_EJECT ;device_release_driver (&dev->dev); -if (!rmdevice) -return 0 ; -acpi_device_unregister (dev);return 0 ;
@@ -1647,7 +1644,7 @@ int acpi_bus_add(acpi_handle handle) }EXPORT_SYMBOL (acpi_bus_add); -int acpi_bus_trim (struct acpi_device *start,int rmdevice) +int acpi_bus_trim (struct acpi_device *start) {acpi_status status;struct acpi_device *parent, *child;
@@ -1673,12 +1670,7 @@ int acpi_bus_trim(struct acpi_device *stacpi_get_parent (phandle, &phandle); child = parent; parent = parent->parent; - -if (level ==0 ) - err =acpi_bus_remove (child, rmdevice); -else - err =acpi_bus_remove (child,1 ); - + err =acpi_bus_remove (child);continue ; }
include/acpi/acpi_bus.h +1 -1
@@ -387,7 +387,7 @@ int acpi_bus_register_driver(struct acpivoid acpi_bus_unregister_driver (struct acpi_driver *driver);int acpi_bus_add (acpi_handle handle);void acpi_bus_hot_remove_device (void *context); -int acpi_bus_trim (struct acpi_device *start,int rmdevice); +int acpi_bus_trim (struct acpi_device *start);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);
drivers/acpi/dock.c +1 -1
@@ -339,7 +339,7 @@ static void dock_remove_acpi_device(acpiint ret;if (!acpi_bus_get_device (handle, &device)) { - ret =acpi_bus_trim (device,1 ); + ret =acpi_bus_trim (device);if (ret)pr_debug ("error removing bus, %x\n" , -ret); }
drivers/pci/hotplug/acpiphp_glue.c +2 -2
@@ -742,7 +742,7 @@ static int acpiphp_bus_add(struct acpiph/* this shouldn't be in here, so remove * the bus then re-add it... */ - ret_val =acpi_bus_trim (device,1 ); + ret_val =acpi_bus_trim (device);dbg ("acpi_bus_trim return %x\n" , ret_val); }
@@ -772,7 +772,7 @@ static int acpiphp_bus_trim(acpi_handlereturn retval; } - retval =acpi_bus_trim (device,1 ); + retval =acpi_bus_trim (device);if (retval)err ("cannot remove from acpi list\n" );
drivers/pci/hotplug/sgi_hotplug.c +1 -1
@@ -535,7 +535,7 @@ static int disable_slot(struct hotplug_s ret =acpi_bus_get_device (chandle, &device);if (ACPI_SUCCESS (ret)) -acpi_bus_trim (device,1 ); +acpi_bus_trim (device); } }
Quoted 10 lines · Rafael J. Wysocki
The next three patches actually rework
acpi_bus_trim()in three steps:[3/5] Drop the second argument of
acpi_bus_trim()(all callers pass 1 in there
anyway.
[4/5] Reimplementacpi_bus_trim()usingacpi_walk_namespace(). [3/5] Makeacpi_bus_trim()carry out two passes as described above.I'm aware of the fact that this will conflict with the patches that Yinghai posted a few days ago, but in my opinion the changes here are prerequisite for the Yinghai's patchset.
Sure, I will drop my change to acpi_bus_trim() and update one reference accordingly.
So you will put those patches in acpi-scan, and Bjorn will pull that again to pci tree?
Thanks
Yinghai
Re: [PATCH 5/5] ACPI / scan: Add second pass to acpi_bus_trim()
In reply to Rafael J. WysockiQuoted 12 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Make
acpi_bus_trim()work in analogy withacpi_bus_scan()and carry out two passes such that ACPI drivers will be detached from device nodes being removed in the first pass and the device nodes themselves will be removed in the second pass.For this purpose split the driver unregistration out of
acpi_bus_remove()into a new routine,acpi_bus_device_detach(), that will be executed byacpi_bus_trim()in the additional first pass as a post-order callback.
Quoted 7 lines
This is necessary, because some ACPI drivers' .remove() routines unregister struct device objects associated with the ACPI device nodes being removed and that needs to happen while the ACPI device nodes are still around (for example, in case they need to be used for power management or similar things at that time).
Signed-off-by Rafael J. Wysocki <[email protected]>
I'd suggest to add some comment stating that acpi_bus_device_detach() acpi_bus_remove() are post-order callbacks. I do not think many people recognize it by just looking the calls to acpi_walk_namespace().
Otherwise, the patchset looks good. For the patch series:
Thanks,
-Toshi
Quoted 69 lines
--- drivers/acpi/scan.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-)Index:
linux-pm/drivers/acpi/scan.c
===================================================================drivers/acpi/scan.c +28
-16@@ -1425,22 +1425,6 @@ static void acpi_device_set_id(struct ac } } -static acpi_status acpi_bus_remove (acpi_handle handle,u32 lvl_not_used, -void *not_used,void **ret_not_used) -{ -struct acpi_device *dev =NULL ; - -if (acpi_bus_get_device (handle, &dev)) -return AE_OK ; - - dev->removal_type =ACPI_BUS_REMOVAL_EJECT ; -device_release_driver (&dev->dev); - -acpi_device_unregister (dev); - -return AE_OK ; -} -void acpi_init_device_object (struct acpi_device *device,acpi_handle handle,int type,unsigned long long sta) {@@ -1647,8 +1631,36 @@ int acpi_bus_add(acpi_handle handle) }EXPORT_SYMBOL (acpi_bus_add); +static acpi_status acpi_bus_device_detach (acpi_handle handle,u32 lvl_not_used, +void *not_used,void **ret_not_used) +{ +struct acpi_device *device =NULL ; + +if (!acpi_bus_get_device (handle, &device)) { + device->removal_type =ACPI_BUS_REMOVAL_EJECT ; +device_release_driver (&device->dev); + } +return AE_OK ; +} + +static acpi_status acpi_bus_remove (acpi_handle handle,u32 lvl_not_used, +void *not_used,void **ret_not_used) +{ +struct acpi_device *device =NULL ; + +if (!acpi_bus_get_device (handle, &device)) +acpi_device_unregister (device); + +return AE_OK ; +} +int acpi_bus_trim (struct acpi_device *start) { +/* Detach all ACPI drivers from the device nodes being removed. */ +acpi_walk_namespace (ACPI_TYPE_ANY , start->handle,ACPI_UINT32_MAX ,NULL , + acpi_bus_device_detach,NULL ,NULL ); +acpi_bus_device_detach (start->handle,0 ,NULL ,NULL ); +/* Remove the device nodes. */ acpi_walk_namespace (ACPI_TYPE_ANY , start->handle,ACPI_UINT32_MAX ,NULL , acpi_bus_remove,NULL ,NULL );acpi_bus_remove (start->handle,0 ,NULL ,NULL );
Re: [PATCH 5/5] ACPI / scan: Add second pass to acpi_bus_trim()
Quoted 19 lines · Toshi Kani
Quoted 18 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Make
acpi_bus_trim()work in analogy withacpi_bus_scan()and carry out two passes such that ACPI drivers will be detached from device nodes being removed in the first pass and the device nodes themselves will be removed in the second pass.For this purpose split the driver unregistration out of
acpi_bus_remove()into a new routine,acpi_bus_device_detach(), that will be executed byacpi_bus_trim()in the additional first pass as a post-order callback.This is necessary, because some ACPI drivers' .remove() routines unregister struct device objects associated with the ACPI device nodes being removed and that needs to happen while the ACPI device nodes are still around (for example, in case they need to be used for power management or similar things at that time).
Quoted 5 lines
Quoted 1 line
Signed-off-by Rafael J. Wysocki <[email protected]>I'd suggest to add some comment stating that
acpi_bus_device_detach()acpi_bus_remove()are post-order callbacks. I do not think many people recognize it by just looking the calls toacpi_walk_namespace().
Yeah, good idea.
Quoted 2 lines
Otherwise, the patchset looks good. For the patch series:
Acked-by Toshi Kani <[email protected]>
Thanks!
Rafael
Quoted 71 lines
Quoted 69 lines
--- drivers/acpi/scan.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-)Index:
linux-pm/drivers/acpi/scan.c
===================================================================drivers/acpi/scan.c +28
-16@@ -1425,22 +1425,6 @@ static void acpi_device_set_id(struct ac } } -static acpi_status acpi_bus_remove (acpi_handle handle,u32 lvl_not_used, -void *not_used,void **ret_not_used) -{ -struct acpi_device *dev =NULL ; - -if (acpi_bus_get_device (handle, &dev)) -return AE_OK ; - - dev->removal_type =ACPI_BUS_REMOVAL_EJECT ; -device_release_driver (&dev->dev); - -acpi_device_unregister (dev); - -return AE_OK ; -} -void acpi_init_device_object (struct acpi_device *device,acpi_handle handle,int type,unsigned long long sta) {@@ -1647,8 +1631,36 @@ int acpi_bus_add(acpi_handle handle) }EXPORT_SYMBOL (acpi_bus_add); +static acpi_status acpi_bus_device_detach (acpi_handle handle,u32 lvl_not_used, +void *not_used,void **ret_not_used) +{ +struct acpi_device *device =NULL ; + +if (!acpi_bus_get_device (handle, &device)) { + device->removal_type =ACPI_BUS_REMOVAL_EJECT ; +device_release_driver (&device->dev); + } +return AE_OK ; +} + +static acpi_status acpi_bus_remove (acpi_handle handle,u32 lvl_not_used, +void *not_used,void **ret_not_used) +{ +struct acpi_device *device =NULL ; + +if (!acpi_bus_get_device (handle, &device)) +acpi_device_unregister (device); + +return AE_OK ; +} +int acpi_bus_trim (struct acpi_device *start) { +/* Detach all ACPI drivers from the device nodes being removed. */ +acpi_walk_namespace (ACPI_TYPE_ANY , start->handle,ACPI_UINT32_MAX ,NULL , + acpi_bus_device_detach,NULL ,NULL ); +acpi_bus_device_detach (start->handle,0 ,NULL ,NULL ); +/* Remove the device nodes. */ acpi_walk_namespace (ACPI_TYPE_ANY , start->handle,ACPI_UINT32_MAX ,NULL , acpi_bus_remove,NULL ,NULL );acpi_bus_remove (start->handle,0 ,NULL ,NULL );
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Quoted 8 lines · Yinghai Lu
Quoted 7 lines · Rafael J. Wysocki
The next three patches actually rework
acpi_bus_trim()in three steps:[3/5] Drop the second argument of
acpi_bus_trim()(all callers pass 1 in there
anyway.
[4/5] Reimplementacpi_bus_trim()usingacpi_walk_namespace(). [3/5] Makeacpi_bus_trim()carry out two passes as described above.
Quoted 8 lines
Quoted 3 lines
I'm aware of the fact that this will conflict with the patches that Yinghai posted a few days ago, but in my opinion the changes here are prerequisite for the Yinghai's patchset.
Sure, I will drop my change to
acpi_bus_trim()and update one reference accordingly.Acked-by for those 5 patches.
Thanks!
Quoted 2 lines
So you will put those patches in acpi-scan, and Bjorn will pull that again to pci tree?
I'm going to put them into acpi-scan some time later this week, but I'd like them to go through linux-next first to catch teething problems, if any.
I can't speak for Bjorn, though. I suppose he will pull them if you ask him to.
Thanks,
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Quoted 13 lines · Rafael J. Wysocki
Hi All,
This series of patches changes the way
acpi_bus_trim()works so that, eventually, it walks the namespace twice detaching (ACPI) drivers from device nodes being removed in the first pass and removing the device nodes in the second pass.The first two patches are just cleanups removing unused stuff:
[1/5] Remove the ops field from struct
acpi_device(unrelated to the rest). [2/5] Drop the second argument ofacpi_device_unregister().
Quoted 6 lines
The next three patches actually rework
acpi_bus_trim()in three steps:[3/5] Drop the second argument of
acpi_bus_trim()(all callers pass 1 in there
anyway.
[4/5] Reimplementacpi_bus_trim()usingacpi_walk_namespace(). [3/5] Makeacpi_bus_trim()carry out two passes as described above.
Quoted 9 lines
I'm aware of the fact that this will conflict with the patches that Yinghai posted a few days ago, but in my opinion the changes here are prerequisite for the Yinghai's patchset.
Thanks,
Rafael