dm: core: Add late driver remove option
PATCH v3 1/1 dm: core: Add late driver remove option
Add another flag to the DM core which could be assigned to drivers and which makes those drivers call their remove callbacks last, just before booting OS and after all the other drivers finished with their remove callbacks. This is necessary for things like clock drivers, where the other drivers might depend on the clock driver in their remove callbacks. Prime example is the mmc subsystem, which can reconfigure a card from HS mode to slower modes in the remove callback and for that it needs to reconfigure the controller clock.
---
V2: Fix DM tests
V3: - Address feedback from V2, drop extra {}
- Add test
--- arch/arm/lib/bootm.c | 1 + board/Marvell/octeontx2/board.c | 4 +- drivers/core/device-remove.c | 13 +++-- drivers/core/root.c | 2 + drivers/core/uclass.c | 26 +++++++-- include/dm/device.h | 10 ++++ include/dm/uclass-internal.h | 3 +- test/dm/core.c | 99 ++++++++++++++++++++++++++++++--- test/dm/test-driver.c | 11 ++++ test/dm/test-main.c | 30 +++++----- 10 files changed, 165 insertions(+), 34 deletions(-)
arch/arm/lib/bootm.c +1 -0
@@ -120,6 +120,7 @@ static void announce_and_cleanup(int fake)* of DMA operation or releasing device internal buffers. */ dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL ); +dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL |DM_REMOVE_LATE );cleanup_before_linux (); }
board/Marvell/octeontx2/board.c +2 -2
@@ -65,7 +65,7 @@ void board_quiesce_devices(void)/* Removes all RVU PF devices */ ret =uclass_get (UCLASS_ETH , &uc_dev);if (uc_dev) - ret =uclass_destroy (uc_dev); + ret =uclass_destroy (uc_dev,DM_REMOVE_NORMAL );if (ret)printf ("couldn't remove rvu pf devices\n" );
@@ -77,7 +77,7 @@ void board_quiesce_devices(void)/* Removes all CGX and RVU AF devices */ ret =uclass_get (UCLASS_MISC , &uc_dev);if (uc_dev) - ret =uclass_destroy (uc_dev); + ret =uclass_destroy (uc_dev,DM_REMOVE_NORMAL );if (ret)printf ("couldn't remove misc (cgx/rvu_af) devices\n" );
drivers/core/device-remove.c +9 -4
@@ -152,7 +152,7 @@ void device_free(struct udevice *dev)static bool flags_remove (uint flags,uint drv_flags) {if ((flags &DM_REMOVE_NORMAL ) || - (flags & (drv_flags & (DM_FLAG_ACTIVE_DMA |DM_FLAG_OS_PREPARE )))) + (flags && (drv_flags & (DM_FLAG_ACTIVE_DMA |DM_FLAG_OS_PREPARE ))))return true;return false;
@@ -172,14 +172,19 @@ int device_remove(struct udevice *dev, uint flags) drv = dev->driver;assert (drv); - ret =uclass_pre_remove_device (dev); -if (ret) -return ret; +if (!(flags &DM_REMOVE_LATE )) { + ret =uclass_pre_remove_device (dev); +if (ret) +return ret; + } ret =device_chld_remove (dev,NULL , flags);if (ret) goto err; +if (!(flags &DM_REMOVE_LATE ) && (drv->flags &DM_FLAG_REMOVE_LATE )) +return 0 ; +/* * Remove the device if called with the "normal" remove flag set, * or if the remove flag matches any of the drivers remove flags
drivers/core/root.c +2 -0
@@ -163,6 +163,7 @@ int dm_init(bool of_live)int dm_uninit (void ) {device_remove (dm_root (),DM_REMOVE_NORMAL ); +device_remove (dm_root (),DM_REMOVE_LATE );device_unbind (dm_root ()); gd->dm_root =NULL ;
@@ -391,6 +392,7 @@ struct acpi_ops root_acpi_ops = {U_BOOT_DRIVER (root_driver) = { .name ="root_driver" , .id =UCLASS_ROOT , + .flags =DM_FLAG_REMOVE_LATE ,ACPI_OPS_PTR (&root_acpi_ops) };
drivers/core/uclass.c +21 -5
@@ -104,10 +104,28 @@ fail_mem:return ret; } -int uclass_destroy (struct uclass *uc) +int uclass_find_device_by_drv_flag (struct uclass *uc,const unsigned int flag, +const bool neg,struct udevice **devp) +{ +struct udevice *dev; + + *devp =NULL ; + uclass_foreach_dev(dev, uc) { +if ((neg && (dev->driver->flags & flag)) || + (!neg && !(dev->driver->flags & flag))) { + *devp = dev; +return 0 ; + } + } + +return -ENODEV ; +} + +int uclass_destroy (struct uclass *uc,unsigned int flag) {struct uclass_driver *uc_drv;struct udevice *dev; +bool late = flag &DM_REMOVE_LATE ;int ret;/*
@@ -116,10 +134,8 @@ int uclass_destroy(struct uclass *uc)* unbound (by the recursion in the call to device_unbind() below). * We can loop until the list is empty. */ -while (!list_empty (&uc->dev_head)) { - dev = list_first_entry(&uc->dev_head, struct udevice, - uclass_node); - ret =device_remove (dev,DM_REMOVE_NORMAL |DM_REMOVE_NO_PD ); +while (!uclass_find_device_by_drv_flag (uc,DM_FLAG_REMOVE_LATE , late, &dev)) { + ret =device_remove (dev, flag |DM_REMOVE_NO_PD );if (ret)return log_msg_ret ("remove" , ret); ret =device_unbind (dev);
include/dm/device.h +10 -0
@@ -73,6 +73,13 @@ struct driver_info;*/ #define DM_FLAG_REMOVE_WITH_PD_ON (1 << 13) +/* +* Device is removed late, after all regular devices were removed. This +* is useful e.g. for clock, which need to be active during the device +* remove phase. +*/ +#define DM_FLAG_REMOVE_LATE (1 << 14) +/* * One or multiple of these flags are passed to device_remove() so that * a selective device removal as specified by the remove-stage and the
@@ -95,6 +102,9 @@ enum {/* Don't power down any attached power domains */ DM_REMOVE_NO_PD =1 <<1 , + +/* Remove device after all regular devices are removed */ + DM_REMOVE_LATE = 1 << 2, };/**
include/dm/uclass-internal.h +2 -1
@@ -247,8 +247,9 @@ struct uclass *uclass_find(enum uclass_id key);* Destroy a uclass and all its devices * * @uc: uclass to destroy +* @flag: driver flags (DM_REMOVE_NORMAL or DM_REMOVE_LATE) * @return 0 on success, -ve on error */ -int uclass_destroy (struct uclass *uc); +int uclass_destroy (struct uclass *uc,unsigned int flag);#endif
test/dm/core.c +90 -9
125 lines not on this page · raw message
test/dm/test-driver.c +11 -0
@@ -169,3 +169,14 @@ U_BOOT_DRIVER(test_act_dma_drv) = { .unbind = test_manual_unbind, .flags = DM_FLAG_ACTIVE_DMA, }; + +U_BOOT_DRIVER (test_act_late_clk_drv) = { + .name ="test_act_late_clk_drv" , + .id =UCLASS_TEST , + .ops = &test_manual_ops, + .bind = test_manual_bind, + .probe = test_manual_probe, + .remove = test_manual_remove, + .unbind = test_manual_unbind, + .flags =DM_FLAG_OS_PREPARE |DM_FLAG_REMOVE_LATE , +};
test/dm/test-main.c +17 -13
@@ -59,19 +59,23 @@ static int do_autoprobe(struct unit_test_state *uts)static int dm_test_destroy (struct unit_test_state *uts) { -int id; - -for (id =0 ; id <UCLASS_COUNT ; id++) { -struct uclass *uc; - -/* -* If the uclass doesn't exist we don't want to create it. So -* check that here before we call uclass_find_device(). -*/ - uc =uclass_find (id); -if (!uc) -continue ; -ut_assertok (uclass_destroy (uc)); +int i, id; + +for (i =0 ; i <2 ; i++) { +for (id =0 ; id <UCLASS_COUNT ; id++) { +struct uclass *uc; + +/* +* If the uclass doesn't exist we don't want to +* create it. So check that here before we call +* uclass_find_device(). +*/ + uc =uclass_find (id); +if (!uc) +continue ; +ut_assertok (uclass_destroy (uc, + i ?DM_REMOVE_LATE :DM_REMOVE_NORMAL )); + } }return 0 ;
Signature · 1 line
2.28.0
PATCH v3 1/1 dm: core: Add late driver remove option
Hi Marek,
Quoted 36 lines · Marek Vasut
Add another flag to the DM core which could be assigned to drivers and which makes those drivers call their remove callbacks last, just before booting OS and after all the other drivers finished with their remove callbacks. This is necessary for things like clock drivers, where the other drivers might depend on the clock driver in their remove callbacks. Prime example is the mmc subsystem, which can reconfigure a card from HS mode to slower modes in the remove callback and for that it needs to reconfigure the controller clock.
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Stefan Roese <[email protected]>Cc Tom Rini <[email protected]>---
V2: Fix DM tests
V3: - Address feedback from V2, drop extra {}
- Add test--- arch/arm/lib/bootm.c | 1 + board/Marvell/octeontx2/board.c | 4 +- drivers/core/device-remove.c | 13 +++-- drivers/core/root.c | 2 + drivers/core/uclass.c | 26 +++++++-- include/dm/device.h | 10 ++++ include/dm/uclass-internal.h | 3 +- test/dm/core.c | 99 ++++++++++++++++++++++++++++++--- test/dm/test-driver.c | 11 ++++ test/dm/test-main.c | 30 +++++----- 10 files changed, 165 insertions(+), 34 deletions(-)arch/arm/lib/bootm.c +0
-0
arch/arm/lib/bootm.c static void announce_and_cleanup(int fake) · line 123
Quoted 4 lines
arch/arm/lib/bootm.c +1
-0@@ -120,6 +120,7 @@ static void announce_and_cleanup(int fake)* of DMA operation or releasing device internal buffers. */ dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL ); +dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL |DM_REMOVE_LATE );
Please see my previous comments about the naming and semantics. I'm repeating them here:
Firstly I think we should use a different name. 'Late' doesn't really tell me anything.
If I understand it correctly, this is supposed to be after OS_PREPARE but before booting the OS?
I think we need to separate the flag names as they are too similar.
I think DM_FLAG_BASIC and DM_REMOVE_NON_BASIC would be better (or some term that explains that this is a device used by many others)
If BASIC is too terrible, perhaps CORE, or VITAL, or PRIME or CRITICAL or something like that?
That way we are describing the property of the device rather than what we want to do with it.
Note also the semantics of what is going on here. The idea of the existing OS_PREPARE and ACTIVE_DMA flags is that the default for device_remove() is to remove everything, but if you provide a flag then it just removes those things. Your flag is the opposite to that, which is why you are changing so much code.
So I think we could change this to DM_REMOVE_NON_BASIC and make that a separate step before we do a final remove with flags of 0.
board/Marvell/octeontx2/board.c
Quoted 7 lines
arch/arm/lib/bootm.c +0
-0cleanup_before_linux (); }board/Marvell/octeontx2/board.c +0
-0
Should be in a separate patch
Quoted 23 lines
board/Marvell/octeontx2/board.c +2
-2@@ -65,7 +65,7 @@ void board_quiesce_devices(void)/* Removes all RVU PF devices */ ret =uclass_get (UCLASS_ETH , &uc_dev);if (uc_dev) - ret =uclass_destroy (uc_dev); + ret =uclass_destroy (uc_dev,DM_REMOVE_NORMAL );if (ret)printf ("couldn't remove rvu pf devices\n" );@@ -77,7 +77,7 @@ void board_quiesce_devices(void)/* Removes all CGX and RVU AF devices */ ret =uclass_get (UCLASS_MISC , &uc_dev);if (uc_dev) - ret =uclass_destroy (uc_dev); + ret =uclass_destroy (uc_dev,DM_REMOVE_NORMAL );if (ret)printf ("couldn't remove misc (cgx/rvu_af) devices\n" );drivers/core/device-remove.c +0
-0
drivers/core/device-remove.c void device_free(struct udevice *dev) · line 155
Quoted 5 lines
drivers/core/device-remove.c +1
-1@@ -152,7 +152,7 @@ void device_free(struct udevice *dev)static bool flags_remove (uint flags,uint drv_flags) {if ((flags &DM_REMOVE_NORMAL ) || - (flags & (drv_flags & (DM_FLAG_ACTIVE_DMA |DM_FLAG_OS_PREPARE )))) + (flags && (drv_flags & (DM_FLAG_ACTIVE_DMA |DM_FLAG_OS_PREPARE ))))
This looks like a bug fix. In any case it should be in its own patch.
Quoted 81 lines
drivers/core/device-remove.c +8
-3return true;return false;@@ -172,14 +172,19 @@ int device_remove(struct udevice *dev, uint flags) drv = dev->driver;assert (drv); - ret =uclass_pre_remove_device (dev); -if (ret) -return ret; +if (!(flags &DM_REMOVE_LATE )) { + ret =uclass_pre_remove_device (dev); +if (ret) +return ret; + } ret =device_chld_remove (dev,NULL , flags);if (ret) goto err; +if (!(flags &DM_REMOVE_LATE ) && (drv->flags &DM_FLAG_REMOVE_LATE )) +return 0 ; +/* * Remove the device if called with the "normal" remove flag set, * or if the remove flag matches any of the drivers remove flags drivers/core/root.c +2
-0@@ -163,6 +163,7 @@ int dm_init(bool of_live)int dm_uninit (void ) {device_remove (dm_root (),DM_REMOVE_NORMAL ); +device_remove (dm_root (),DM_REMOVE_LATE );device_unbind (dm_root ()); gd->dm_root =NULL ;@@ -391,6 +392,7 @@ struct acpi_ops root_acpi_ops = {U_BOOT_DRIVER (root_driver) = { .name ="root_driver" , .id =UCLASS_ROOT , + .flags =DM_FLAG_REMOVE_LATE ,ACPI_OPS_PTR (&root_acpi_ops) };drivers/core/uclass.c +19
-1@@ -104,10 +104,28 @@ fail_mem:return ret; } -int uclass_destroy (struct uclass *uc) +int uclass_find_device_by_drv_flag (struct uclass *uc,const unsigned int flag, +const bool neg,struct udevice **devp) +{ +struct udevice *dev; + + *devp =NULL ; + uclass_foreach_dev(dev, uc) { +if ((neg && (dev->driver->flags & flag)) || + (!neg && !(dev->driver->flags & flag))) { + *devp = dev; +return 0 ; + } + } + +return -ENODEV ; +} + +int uclass_destroy (struct uclass *uc,unsigned int flag) {struct uclass_driver *uc_drv;struct udevice *dev; +bool late = flag &DM_REMOVE_LATE ;int ret;/*
drivers/core/uclass.c int uclass_destroy(struct uclass *uc) · line 138
Quoted 9 lines
drivers/core/uclass.c +2
-4@@ -116,10 +134,8 @@ int uclass_destroy(struct uclass *uc)* unbound (by the recursion in the call to device_unbind() below). * We can loop until the list is empty. */ -while (!list_empty (&uc->dev_head)) { - dev = list_first_entry(&uc->dev_head, struct udevice, - uclass_node); - ret =device_remove (dev,DM_REMOVE_NORMAL |DM_REMOVE_NO_PD ); +while (!uclass_find_device_by_drv_flag (uc,DM_FLAG_REMOVE_LATE , late, &dev)) { + ret =device_remove (dev, flag |DM_REMOVE_NO_PD );
I think this logic will get a lot simpler when you change the semantics as above.
Quoted 76 lines
drivers/core/uclass.c +0
-0if (ret)return log_msg_ret ("remove" , ret); ret =device_unbind (dev);include/dm/device.h +10
-0@@ -73,6 +73,13 @@ struct driver_info;*/ #define DM_FLAG_REMOVE_WITH_PD_ON (1 << 13) +/* +* Device is removed late, after all regular devices were removed. This +* is useful e.g. for clock, which need to be active during the device +* remove phase. +*/ +#define DM_FLAG_REMOVE_LATE (1 << 14) +/* * One or multiple of these flags are passed to device_remove() so that * a selective device removal as specified by the remove-stage and the @@ -95,6 +102,9 @@ enum {/* Don't power down any attached power domains */ DM_REMOVE_NO_PD =1 <<1 , + +/* Remove device after all regular devices are removed */ + DM_REMOVE_LATE = 1 << 2, };/** include/dm/uclass-internal.h +2
-1@@ -247,8 +247,9 @@ struct uclass *uclass_find(enum uclass_id key);* Destroy a uclass and all its devices * * @uc: uclass to destroy +* @flag: driver flags (DM_REMOVE_NORMAL or DM_REMOVE_LATE) * @return 0 on success, -ve on error */ -int uclass_destroy (struct uclass *uc); +int uclass_destroy (struct uclass *uc,unsigned int flag);#endif test/dm/core.c +5
-8@@ -72,6 +72,10 @@ static struct driver_info driver_info_act_dma = { .name = "test_act_dma_drv", }; +static struct driver_info driver_info_act_late_clk = { + .name ="test_act_late_clk_drv" , +}; +void dm_leak_check_start (struct unit_test_state *uts) { uts->start =mallinfo ();@@ -82,16 +86,19 @@ void dm_leak_check_start(struct unit_test_state *uts)int dm_leak_check_end (struct unit_test_state *uts) {struct mallinfo end; -int id, diff; +int i, id, diff;/* Don't delete the root class, since we started with that */ -for (id =UCLASS_ROOT +1 ; id <UCLASS_COUNT ; id++) { -struct uclass *uc; - - uc =uclass_find (id); -if (!uc) -continue ; -ut_assertok (uclass_destroy (uc));
test/dm/core.c void dm_leak_check_start(struct unit_test_state *uts) · line 101
Quoted 10 lines
test/dm/core.c +10
-0+for (i =0 ; i <2 ; i++) { +for (id =UCLASS_ROOT +1 ; id <UCLASS_COUNT ; id++) { +struct uclass *uc; + + uc =uclass_find (id); +if (!uc) +continue ; +ut_assertok (uclass_destroy (uc, + i ?DM_REMOVE_LATE :DM_REMOVE_NORMAL )); + }
Why do we need to destroy the classes in two steps? I understand removing devices, but destroying the uclasses seems like it could stay as it is?
Quoted 80 lines
test/dm/core.c +65
-1} end =mallinfo ();@@ -514,7 +521,7 @@ static int dm_test_uclass(struct unit_test_state *uts)ut_asserteq (0 , dm_testdrv_op_count[DM_TEST_OP_DESTROY ]);ut_assert (uc->priv); -ut_assertok (uclass_destroy (uc)); +ut_assertok (uclass_destroy (uc,DM_REMOVE_LATE ));ut_asserteq (1 , dm_testdrv_op_count[DM_TEST_OP_INIT ]);ut_asserteq (1 , dm_testdrv_op_count[DM_TEST_OP_DESTROY ]);@@ -883,6 +890,80 @@ static int dm_test_remove_active_dma(struct unit_test_state *uts) }DM_TEST (dm_test_remove_active_dma,0 ); +/* +* Test that removal of devices, either via the "normal" device_remove() +* API or via the device driver selective flag works as expected +*/ +static int dm_test_remove_active_late (struct unit_test_state *uts) +{ +struct dm_test_state *dms = uts->priv; +struct udevice *devn, *devl; + +/* Skip the behaviour in test_post_probe() */ + dms->skip_post_probe =1 ; + +ut_assertok (device_bind_by_name (dms->root, false, + &driver_info_act_late_clk, + &devl)); +ut_assert (devl); + +ut_assertok (device_bind_by_name (dms->root, false, + &driver_info_manual, + &devn)); +ut_assert (devn); + +/* Part 1, DM_REMOVE_ACTIVE_ALL */ + +/* Probe the devices */ +ut_assertok (device_probe (devl)); +ut_assertok (device_probe (devn)); + +/* Test if devices are active right now */ +ut_asserteq (true,device_active (devl)); +ut_asserteq (true,device_active (devn)); + +/* Remove normal devices via selective remove flag */ +dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL |DM_REMOVE_NORMAL ); + +/* Test if normal devices are inactive right now */ +ut_asserteq (true,device_active (devl)); +ut_asserteq (false,device_active (devn)); + +/* Remove late devices via selective remove flag */ +dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL |DM_REMOVE_LATE ); + +/* Test if all devices are inactive right now */ +ut_asserteq (false,device_active (devl)); +ut_asserteq (false,device_active (devn)); + +/* Part 2, device_remove() */ + +/* Probe the devices again */ +ut_assertok (device_probe (devl)); +ut_assertok (device_probe (devn)); + +/* Test if devices are active right now */ +ut_asserteq (true,device_active (devl)); +ut_asserteq (true,device_active (devn)); + +/* Remove the devices via "normal" remove API */ +ut_assertok (device_remove (devn,DM_REMOVE_NORMAL )); +ut_assertok (device_remove (devl,DM_REMOVE_NORMAL )); + +/* Test if normal devices are inactive right now */ +ut_asserteq (true,device_active (devl)); +ut_asserteq (false,device_active (devn)); +
test/dm/core.c static int dm_test_remove_active_dma(struct unit_test_state *uts) · line 966
Quoted 10 lines
test/dm/core.c +10
-0+ut_assertok (device_remove (devl,DM_REMOVE_LATE )); + +/* Test if devices are inactive right now */ +ut_asserteq (false,device_active (devl)); +ut_asserteq (false,device_active (devn)); + +return 0 ; +} +DM_TEST (dm_test_remove_active_late,0 ); +
This test looks good to me.
Quoted 50 lines
test/dm/core.c +0
-0static int dm_test_uclass_before_ready (struct unit_test_state *uts) {struct uclass *uc;test/dm/test-driver.c +11
-0@@ -169,3 +169,14 @@ U_BOOT_DRIVER(test_act_dma_drv) = { .unbind = test_manual_unbind, .flags = DM_FLAG_ACTIVE_DMA, }; + +U_BOOT_DRIVER (test_act_late_clk_drv) = { + .name ="test_act_late_clk_drv" , + .id =UCLASS_TEST , + .ops = &test_manual_ops, + .bind = test_manual_bind, + .probe = test_manual_probe, + .remove = test_manual_remove, + .unbind = test_manual_unbind, + .flags =DM_FLAG_OS_PREPARE |DM_FLAG_REMOVE_LATE , +};test/dm/test-main.c +7
-13@@ -59,19 +59,23 @@ static int do_autoprobe(struct unit_test_state *uts)static int dm_test_destroy (struct unit_test_state *uts) { -int id; - -for (id =0 ; id <UCLASS_COUNT ; id++) { -struct uclass *uc; - -/* -* If the uclass doesn't exist we don't want to create it. So -* check that here before we call uclass_find_device(). -*/ - uc =uclass_find (id); -if (!uc) -continue ; -ut_assertok (uclass_destroy (uc)); +int i, id; + +for (i =0 ; i <2 ; i++) { +for (id =0 ; id <UCLASS_COUNT ; id++) { +struct uclass *uc; + +/*
test/dm/test-main.c static int do_autoprobe(struct unit_test_state *uts) · line 78
Quoted 10 lines
test/dm/test-main.c +10
-0+* If the uclass doesn't exist we don't want to +* create it. So check that here before we call +* uclass_find_device(). +*/ + uc =uclass_find (id); +if (!uc) +continue ; +ut_assertok (uclass_destroy (uc, + i ?DM_REMOVE_LATE :DM_REMOVE_NORMAL )); + }
See comments about uclass destroy above.
Quoted 6 lines
test/dm/test-main.c +0
-1}return 0 ; --2.28.0
Regadrs,
Simon
PATCH v3 1/1 dm: core: Add late driver remove option
Quoted 1 line · Simon Glass
Hi Marek,
[...]
Quoted 13 lines
arch/arm/lib/bootm.c static void announce_and_cleanup(int fake) · line 123
Quoted 9 lines
arch/arm/lib/bootm.c +1
-0@@ -120,6 +120,7 @@ static void announce_and_cleanup(int fake)* of DMA operation or releasing device internal buffers. */ dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL ); +dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL |DM_REMOVE_LATE );Please see my previous comments about the naming and semantics. I'm repeating them here:
Quoted 5 lines
Firstly I think we should use a different name. 'Late' doesn't really tell me anything.
If I understand it correctly, this is supposed to be after
OS_PREPAREbut before booting the OS?
No. The drivers which are marked as remove-late should be removed late, after all the normal drivers were removed. The example in the commit message explains where this is needed -- first remove mmc driver to set eMMC out of HS mode and change the bus clock and after that remove clock driver ; the clock driver is still required during the removal of the mmc driver.
Quoted 7 lines
I think we need to separate the flag names as they are too similar.
I think
DM_FLAG_BASICandDM_REMOVE_NON_BASICwould be better (or some term that explains that this is a device used by many others)If BASIC is too terrible, perhaps CORE, or VITAL, or PRIME or CRITICAL or something like that?
This makes no sense to me.
Quoted 2 lines
That way we are describing the property of the device rather than what we want to do with it.
The device is not critical or vital, it just needs to be torn down late.
Quoted 5 lines
Note also the semantics of what is going on here. The idea of the existing
OS_PREPAREandACTIVE_DMAflags is that the default fordevice_remove()is to remove everything, but if you provide a flag then it just removes those things. Your flag is the opposite to that, which is why you are changing so much code.
I obviously cannot remove everything, see the example above.
Quoted 2 lines
So I think we could change this to
DM_REMOVE_NON_BASICand make that a separate step before we do a final remove with flags of 0.
[...]
Quoted 21 lines
Quoted 21 lines
arch/arm/lib/bootm.c +7
-8@@ -82,16 +86,19 @@ void dm_leak_check_start(struct unit_test_state *uts)int dm_leak_check_end (struct unit_test_state *uts) {struct mallinfo end; -int id, diff; +int i, id, diff;/* Don't delete the root class, since we started with that */ -for (id =UCLASS_ROOT +1 ; id <UCLASS_COUNT ; id++) { -struct uclass *uc; - - uc =uclass_find (id); -if (!uc) -continue ; -ut_assertok (uclass_destroy (uc)); +for (i =0 ; i <2 ; i++) { +for (id =UCLASS_ROOT +1 ; id <UCLASS_COUNT ; id++) { +struct uclass *uc; + + uc =uclass_find (id); +if (!uc)
Quoted 8 lines
arch/arm/lib/bootm.c void dm_leak_check_start(struct unit_test_state *uts) · line 101
Quoted 4 lines
arch/arm/lib/bootm.c +4
-0+continue ; +ut_assertok (uclass_destroy (uc, + i ?DM_REMOVE_LATE :DM_REMOVE_NORMAL )); + }Why do we need to destroy the classes in two steps? I understand removing devices, but destroying the uclasses seems like it could stay as it is?
Because if you destroy clock uclass before mmc uclass, then you cannot remove the mmc drivers and reconfigure the bus clock anymore in the remove callback. So that needs to be done in two steps.
[...]
PATCH v3 1/1 dm: core: Add late driver remove option
Hi Marek,
Quoted 34 lines · Marek Vasut
Quoted 1 line · Simon Glass
Hi Marek,
[...]
Quoted 13 lines
arch/arm/lib/bootm.c static void announce_and_cleanup(int fake) · line 123
Quoted 9 lines
arch/arm/lib/bootm.c +1
-0@@ -120,6 +120,7 @@ static void announce_and_cleanup(int fake)* of DMA operation or releasing device internal buffers. */ dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL ); +dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL |DM_REMOVE_LATE );Please see my previous comments about the naming and semantics. I'm repeating them here:
Quoted 5 lines
Firstly I think we should use a different name. 'Late' doesn't really tell me anything.
If I understand it correctly, this is supposed to be after
OS_PREPAREbut before booting the OS?No. The drivers which are marked as remove-late should be removed late, after all the normal drivers were removed. The example in the commit message explains where this is needed -- first remove mmc driver to set eMMC out of HS mode and change the bus clock and after that remove clock driver ; the clock driver is still required during the removal of the mmc driver.
Quoted 2 lines
I think we need to separate the flag names as they are too similar.
Quoted 7 lines
Quoted 5 lines
I think
DM_FLAG_BASICandDM_REMOVE_NON_BASICwould be better (or some term that explains that this is a device used by many others)If BASIC is too terrible, perhaps CORE, or VITAL, or PRIME or CRITICAL or something like that?
This makes no sense to me.
I don't want the word 'late'. Then we'll end up with 'later' and 'fairly late', etc. and it will get out of hand. We need a word that describes what is special about the devices, not when to do stuff with them.
Quoted 5 lines
Quoted 3 lines
That way we are describing the property of the device rather than what we want to do with it.
The device is not critical or vital, it just needs to be torn down late.
What is it about the device that requires it to be torn down 'late'?
Quoted 8 lines
Quoted 6 lines
Note also the semantics of what is going on here. The idea of the existing
OS_PREPAREandACTIVE_DMAflags is that the default fordevice_remove()is to remove everything, but if you provide a flag then it just removes those things. Your flag is the opposite to that, which is why you are changing so much code.I obviously cannot remove everything, see the example above.
Do you understand what I am saying about inverting the flag?
Quoted 36 lines
Quoted 3 lines
So I think we could change this to
DM_REMOVE_NON_BASICand make that a separate step before we do a final remove with flags of 0.[...]
Quoted 21 lines
Quoted 21 lines
arch/arm/lib/bootm.c +7
-8@@ -82,16 +86,19 @@ void dm_leak_check_start(struct unit_test_state *uts)int dm_leak_check_end (struct unit_test_state *uts) {struct mallinfo end; -int id, diff; +int i, id, diff;/* Don't delete the root class, since we started with that */ -for (id =UCLASS_ROOT +1 ; id <UCLASS_COUNT ; id++) { -struct uclass *uc; - - uc =uclass_find (id); -if (!uc) -continue ; -ut_assertok (uclass_destroy (uc)); +for (i =0 ; i <2 ; i++) { +for (id =UCLASS_ROOT +1 ; id <UCLASS_COUNT ; id++) { +struct uclass *uc; + + uc =uclass_find (id); +if (!uc)Quoted 8 lines
arch/arm/lib/bootm.c void dm_leak_check_start(struct unit_test_state *uts) · line 101
Quoted 4 lines
arch/arm/lib/bootm.c +4
-0+continue ; +ut_assertok (uclass_destroy (uc, + i ?DM_REMOVE_LATE :DM_REMOVE_NORMAL )); + }Why do we need to destroy the classes in two steps? I understand removing devices, but destroying the uclasses seems like it could stay as it is?
Quoted 3 lines
Because if you destroy clock uclass before mmc uclass, then you cannot remove the mmc drivers and reconfigure the bus clock anymore in the remove callback. So that needs to be done in two steps.
Yes I understand that. All of my comments are about the implementation rather than the problem you are solving. See the existing DM_REMOVE_ flags for examples.
If you like, I could have a try at this. Perhaps it is not as straightforward as I imagine.
Regards,
Simon
PATCH v3 1/1 dm: core: Add late driver remove option
Quoted 51 lines · Simon Glass
Hi Marek,
Quoted 34 lines · Marek Vasut
Quoted 1 line · Simon Glass
Hi Marek,
[...]
Quoted 13 lines
arch/arm/lib/bootm.c static void announce_and_cleanup(int fake) · line 123
Quoted 9 lines
arch/arm/lib/bootm.c +1
-0@@ -120,6 +120,7 @@ static void announce_and_cleanup(int fake)* of DMA operation or releasing device internal buffers. */ dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL ); +dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL |DM_REMOVE_LATE );Please see my previous comments about the naming and semantics. I'm repeating them here:
Quoted 5 lines
Firstly I think we should use a different name. 'Late' doesn't really tell me anything.
If I understand it correctly, this is supposed to be after
OS_PREPAREbut before booting the OS?No. The drivers which are marked as remove-late should be removed late, after all the normal drivers were removed. The example in the commit message explains where this is needed -- first remove mmc driver to set eMMC out of HS mode and change the bus clock and after that remove clock driver ; the clock driver is still required during the removal of the mmc driver.
Quoted 2 lines
I think we need to separate the flag names as they are too similar.
Quoted 7 lines
Quoted 5 lines
I think
DM_FLAG_BASICandDM_REMOVE_NON_BASICwould be better (or some term that explains that this is a device used by many others)If BASIC is too terrible, perhaps CORE, or VITAL, or PRIME or CRITICAL or something like that?
This makes no sense to me.
I don't want the word 'late'. Then we'll end up with 'later' and 'fairly late', etc. and it will get out of hand. We need a word that describes what is special about the devices, not when to do stuff with them.
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
That way we are describing the property of the device rather than what we want to do with it.
The device is not critical or vital, it just needs to be torn down late.
What is it about the device that requires it to be torn down 'late'?
I think perhaps the problem isn't that it needs to be "late", it's that it has perhaps not obviously described children. Which gets back to what you just said as well about "later" and "fairly late". It's an ordering problem.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201118/422f84a7/attachment.sig>
PATCH v3 1/1 dm: core: Add late driver remove option
Hi Tom,
Quoted 56 lines · Tom Rini
Quoted 54 lines · Simon Glass
Hi Marek,
Quoted 34 lines · Marek Vasut
Quoted 1 line · Simon Glass
Hi Marek,
[...]
Quoted 13 lines
arch/arm/lib/bootm.c static void announce_and_cleanup(int fake) · line 123
Quoted 9 lines
arch/arm/lib/bootm.c +1
-0@@ -120,6 +120,7 @@ static void announce_and_cleanup(int fake)* of DMA operation or releasing device internal buffers. */ dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL ); +dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL |DM_REMOVE_LATE );Please see my previous comments about the naming and semantics. I'm repeating them here:
Quoted 5 lines
Firstly I think we should use a different name. 'Late' doesn't really tell me anything.
If I understand it correctly, this is supposed to be after
OS_PREPAREbut before booting the OS?No. The drivers which are marked as remove-late should be removed late, after all the normal drivers were removed. The example in the commit message explains where this is needed -- first remove mmc driver to set eMMC out of HS mode and change the bus clock and after that remove clock driver ; the clock driver is still required during the removal of the mmc driver.
Quoted 2 lines
I think we need to separate the flag names as they are too similar.
Quoted 7 lines
Quoted 5 lines
I think
DM_FLAG_BASICandDM_REMOVE_NON_BASICwould be better (or some term that explains that this is a device used by many others)If BASIC is too terrible, perhaps CORE, or VITAL, or PRIME or CRITICAL or something like that?
This makes no sense to me.
I don't want the word 'late'. Then we'll end up with 'later' and 'fairly late', etc. and it will get out of hand. We need a word that describes what is special about the devices, not when to do stuff with them.
Quoted 4 lines
Quoted 3 lines
That way we are describing the property of the device rather than what we want to do with it.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
The device is not critical or vital, it just needs to be torn down late.
What is it about the device that requires it to be torn down 'late'?
I think perhaps the problem isn't that it needs to be "late", it's that it has perhaps not obviously described children. Which gets back to what you just said as well about "later" and "fairly late". It's an ordering problem.
Yes it is.
We currently don't record devices that depend on others. It would be possible to add a refcount to DM to cope with this and implement it for clocks. I wonder if that might be better than what we have here?
Regards,
Simon
PATCH v3 1/1 dm: core: Add late driver remove option
On 11/22/20 12:07 AM, Simon Glass wrote:
[...]
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
That way we are describing the property of the device rather than what we want to do with it.
The device is not critical or vital, it just needs to be torn down late.
What is it about the device that requires it to be torn down 'late'?
I think perhaps the problem isn't that it needs to be "late", it's that it has perhaps not obviously described children. Which gets back to what you just said as well about "later" and "fairly late". It's an ordering problem.
Quoted 5 lines
Yes it is.
We currently don't record devices that depend on others. It would be possible to add a refcount to DM to cope with this and implement it for clocks. I wonder if that might be better than what we have here?
This is still a bootloader, not a general-purpose OS, so I would argue we should not complicate this more than is necessary. The DM already adds a lot of bloat to U-Boot, no need to make that worse unless there is a real good reason for that. Also, in V1 of this patch, Simon did suggest that a simple approach is OK if I recall correctly.
PATCH v3 1/1 dm: core: Add late driver remove option
Quoted 15 lines · Marek Vasut
On 11/22/20 12:07 AM, Simon Glass wrote:
[...]Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
That way we are describing the property of the device rather than what we want to do with it.
The device is not critical or vital, it just needs to be torn down late.
What is it about the device that requires it to be torn down 'late'?
I think perhaps the problem isn't that it needs to be "late", it's that it has perhaps not obviously described children. Which gets back to what you just said as well about "later" and "fairly late". It's an ordering problem.
Quoted 7 lines
Quoted 5 lines
Yes it is.
We currently don't record devices that depend on others. It would be possible to add a refcount to DM to cope with this and implement it for clocks. I wonder if that might be better than what we have here?
This is still a bootloader, not a general-purpose OS, so I would argue we should not complicate this more than is necessary. The DM already addsa lot of bloat to U-Boot, no need to make that worse unless there is a real good reason for that. Also, in V1 of this patch, Simon did suggest that a simple approach is OK if I recall correctly.
FWIW the clock subsystem already does refcounting of clocks (though it is for struct clk and not for the devices themselves). However, I think it would be difficult to use those counts to determine when the clock driver is no longer needed. For example, some devices (such as CPUs) may use clocks, but should never stop those clocks.
A quick-and-dirty method could be to create a linked list of all probed devices, and then remove devices in reverse order. So an example call sequence could be
...
1. mmc's probe()
2. clk_get_*()
3. clk's probe()
4. clk's finishes; clk added to probed list
5. mmc's probe finishes; mmc added to probed list
...
7. mmc's remove() called
8. clk's remove() called
Note that this would be a change to dm_uninit, not device_remove; we would still need the recursive removal logic for when devices are removed via other means. Unfortunately, this method would require yet another list_head in udevice, so perhaps it should just be an option?
--Sean
PATCH v3 1/1 dm: core: Add late driver remove option
In reply to Marek VasutQuoted 21 lines · Marek Vasut
On 11/22/20 12:07 AM, Simon Glass wrote:
[...]Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
That way we are describing the property of the device rather than what we want to do with it.
The device is not critical or vital, it just needs to be torn down late.
What is it about the device that requires it to be torn down 'late'?
I think perhaps the problem isn't that it needs to be "late", it's that it has perhaps not obviously described children. Which gets back to what you just said as well about "later" and "fairly late". It's an ordering problem.
Quoted 5 lines
Yes it is.
We currently don't record devices that depend on others. It would be possible to add a refcount to DM to cope with this and implement it for clocks. I wonder if that might be better than what we have here?
Quoted 5 lines
This is still a bootloader, not a general-purpose OS, so I would argue we should not complicate this more than is necessary. The DM already adds a lot of bloat to U-Boot, no need to make that worse unless there is a real good reason for that. Also, in V1 of this patch, Simon did suggest that a simple approach is OK if I recall correctly.
Perhaps now that it's clear to everyone what "late" means in this context, we can just solve it with a flag + documentation that ...whatever the name is... means that it's for ensuring that we have unwound the other parts of the system which require this to be enabled first.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201123/d9aeb5e3/attachment.sig>
PATCH v3 1/1 dm: core: Add late driver remove option
In reply to Simon GlassOn 11/18/20 3:37 PM, Simon Glass wrote:
Hi,
[...]
Quoted 34 lines
Quoted 34 lines
Quoted 13 lines
arch/arm/lib/bootm.c static void announce_and_cleanup(int fake) · line 123
Quoted 9 lines
arch/arm/lib/bootm.c +1
-0@@ -120,6 +120,7 @@ static void announce_and_cleanup(int fake)* of DMA operation or releasing device internal buffers. */ dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL ); +dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL |DM_REMOVE_LATE );Please see my previous comments about the naming and semantics. I'm repeating them here:
Quoted 5 lines
Firstly I think we should use a different name. 'Late' doesn't really tell me anything.
If I understand it correctly, this is supposed to be after
OS_PREPAREbut before booting the OS?No. The drivers which are marked as remove-late should be removed late, after all the normal drivers were removed. The example in the commit message explains where this is needed -- first remove mmc driver to set eMMC out of HS mode and change the bus clock and after that remove clock driver ; the clock driver is still required during the removal of the mmc driver.
Quoted 7 lines
I think we need to separate the flag names as they are too similar.
I think
DM_FLAG_BASICandDM_REMOVE_NON_BASICwould be better (or some term that explains that this is a device used by many others)If BASIC is too terrible, perhaps CORE, or VITAL, or PRIME or CRITICAL or something like that?
Quoted 6 lines
Quoted 1 line
This makes no sense to me.
I don't want the word 'late'. Then we'll end up with 'later' and 'fairly late', etc. and it will get out of hand. We need a word that describes what is special about the devices, not when to do stuff with them.
If there is a need for "later" , then we will need some more complex code. I suggest we cross that bridge when we come to it.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
That way we are describing the property of the device rather than what we want to do with it.
The device is not critical or vital, it just needs to be torn down late.
What is it about the device that requires it to be torn down 'late'?
For example clock driver needs to be turn down after mmc controller, since the mmc controller might need to reconfigure the card in .remove callback, for which it still needs to clock to be active. That's the usecase I have on real hardware.
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Note also the semantics of what is going on here. The idea of the existing
OS_PREPAREandACTIVE_DMAflags is that the default fordevice_remove()is to remove everything, but if you provide a flag then it just removes those things. Your flag is the opposite to that, which is why you are changing so much code.I obviously cannot remove everything, see the example above.
Do you understand what I am saying about inverting the flag?
No, please elaborate.
Quoted 39 lines
Quoted 35 lines
Quoted 2 lines
So I think we could change this to
DM_REMOVE_NON_BASICand make that a separate step before we do a final remove with flags of 0.[...]
Quoted 21 lines
Quoted 21 lines
arch/arm/lib/bootm.c +7
-8@@ -82,16 +86,19 @@ void dm_leak_check_start(struct unit_test_state *uts)int dm_leak_check_end (struct unit_test_state *uts) {struct mallinfo end; -int id, diff; +int i, id, diff;/* Don't delete the root class, since we started with that */ -for (id =UCLASS_ROOT +1 ; id <UCLASS_COUNT ; id++) { -struct uclass *uc; - - uc =uclass_find (id); -if (!uc) -continue ; -ut_assertok (uclass_destroy (uc)); +for (i =0 ; i <2 ; i++) { +for (id =UCLASS_ROOT +1 ; id <UCLASS_COUNT ; id++) { +struct uclass *uc; + + uc =uclass_find (id); +if (!uc)Quoted 8 lines
arch/arm/lib/bootm.c void dm_leak_check_start(struct unit_test_state *uts) · line 101
Quoted 4 lines
arch/arm/lib/bootm.c +4
-0+continue ; +ut_assertok (uclass_destroy (uc, + i ?DM_REMOVE_LATE :DM_REMOVE_NORMAL )); + }Why do we need to destroy the classes in two steps? I understand removing devices, but destroying the uclasses seems like it could stay as it is?
Quoted 3 lines
Because if you destroy clock uclass before mmc uclass, then you cannot remove the mmc drivers and reconfigure the bus clock anymore in the remove callback. So that needs to be done in two steps.
Quoted 6 lines
Yes I understand that. All of my comments are about the implementation rather than the problem you are solving. See the existing
DM_REMOVE_flags for examples.If you like, I could have a try at this. Perhaps it is not as straightforward as I imagine.
I think it would be a good idea if you looked at the use case for this first.
PATCH v3 1/1 dm: core: Add late driver remove option
Hi Marek,
Quoted 43 lines · Marek Vasut
On 11/18/20 3:37 PM, Simon Glass wrote:
Hi,
[...]
Quoted 36 lines
Quoted 35 lines
Quoted 13 lines
arch/arm/lib/bootm.c static void announce_and_cleanup(int fake) · line 123
Quoted 9 lines
arch/arm/lib/bootm.c +1
-0@@ -120,6 +120,7 @@ static void announce_and_cleanup(int fake)* of DMA operation or releasing device internal buffers. */ dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL ); +dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL |DM_REMOVE_LATE );Please see my previous comments about the naming and semantics. I'm repeating them here:
Quoted 5 lines
Firstly I think we should use a different name. 'Late' doesn't really tell me anything.
If I understand it correctly, this is supposed to be after
OS_PREPAREbut before booting the OS?No. The drivers which are marked as remove-late should be removed late, after all the normal drivers were removed. The example in the commit message explains where this is needed -- first remove mmc driver to set eMMC out of HS mode and change the bus clock and after that remove clock driver ; the clock driver is still required during the removal of the mmc driver.
Quoted 7 lines
I think we need to separate the flag names as they are too similar.
I think
DM_FLAG_BASICandDM_REMOVE_NON_BASICwould be better (or some term that explains that this is a device used by many others)If BASIC is too terrible, perhaps CORE, or VITAL, or PRIME or CRITICAL or something like that?
This makes no sense to me.
Quoted 8 lines
Quoted 4 lines
I don't want the word 'late'. Then we'll end up with 'later' and 'fairly late', etc. and it will get out of hand. We need a word that describes what is special about the devices, not when to do stuff with them.
If there is a need for "later" , then we will need some more complex code. I suggest we cross that bridge when we come to it.
I'm OK with that.
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
That way we are describing the property of the device rather than what we want to do with it.
The device is not critical or vital, it just needs to be torn down late.
What is it about the device that requires it to be torn down 'late'?
For example clock driver needs to be turn down after mmc controller, since the mmc controller might need to reconfigure the card in .remove callback, for which it still needs to clock to be active. That's the usecase I have on real hardware.
Yes I understand that.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Note also the semantics of what is going on here. The idea of the existing
OS_PREPAREandACTIVE_DMAflags is that the default fordevice_remove()is to remove everything, but if you provide a flag then it just removes those things. Your flag is the opposite to that, which is why you are changing so much code.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
I obviously cannot remove everything, see the example above.
Do you understand what I am saying about inverting the flag?
No, please elaborate.
The normal situation should be to remove everything. Removing only non-late things (which I want to call 'basic', or something like that) should be an option, like we have DM_REMOVE_OS_PREPARE.
Quoted 44 lines
Quoted 44 lines
Quoted 36 lines
Quoted 3 lines
So I think we could change this to
DM_REMOVE_NON_BASICand make that a separate step before we do a final remove with flags of 0.[...]
Quoted 21 lines
Quoted 21 lines
arch/arm/lib/bootm.c +7
-8@@ -82,16 +86,19 @@ void dm_leak_check_start(struct unit_test_state *uts)int dm_leak_check_end (struct unit_test_state *uts) {struct mallinfo end; -int id, diff; +int i, id, diff;/* Don't delete the root class, since we started with that */ -for (id =UCLASS_ROOT +1 ; id <UCLASS_COUNT ; id++) { -struct uclass *uc; - - uc =uclass_find (id); -if (!uc) -continue ; -ut_assertok (uclass_destroy (uc)); +for (i =0 ; i <2 ; i++) { +for (id =UCLASS_ROOT +1 ; id <UCLASS_COUNT ; id++) { +struct uclass *uc; + + uc =uclass_find (id); +if (!uc)Quoted 8 lines
arch/arm/lib/bootm.c void dm_leak_check_start(struct unit_test_state *uts) · line 101
Quoted 4 lines
arch/arm/lib/bootm.c +4
-0+continue ; +ut_assertok (uclass_destroy (uc, + i ?DM_REMOVE_LATE :DM_REMOVE_NORMAL )); + }Why do we need to destroy the classes in two steps? I understand removing devices, but destroying the uclasses seems like it could stay as it is?
Quoted 3 lines
Because if you destroy clock uclass before mmc uclass, then you cannot remove the mmc drivers and reconfigure the bus clock anymore in the remove callback. So that needs to be done in two steps.
Yes I understand that. All of my comments are about the implementation rather than the problem you are solving. See the existing
DM_REMOVE_flags for examples.
Quoted 5 lines
Quoted 2 lines
If you like, I could have a try at this. Perhaps it is not as straightforward as I imagine.
I think it would be a good idea if you looked at the use case for this first.
I'm not sure what it is about this use case that I don't understand. It seems fairly straightforward to me. We have decided to leave reference counting for another day and all I am really commenting on is the implementation.
Regards,
Simon
PATCH v3 1/1 dm: core: Add late driver remove option
On 12/10/20 6:44 PM, Simon Glass wrote:
[...]
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Note also the semantics of what is going on here. The idea of the existing
OS_PREPAREandACTIVE_DMAflags is that the default fordevice_remove()is to remove everything, but if you provide a flag then it just removes those things. Your flag is the opposite to that, which is why you are changing so much code.I obviously cannot remove everything, see the example above.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Do you understand what I am saying about inverting the flag?
No, please elaborate.
The normal situation should be to remove everything. Removing only non-late things (which I want to call 'basic', or something like that) should be an option, like we have
DM_REMOVE_OS_PREPARE.
We cannot remove everything at once, because then various real hardware cannot work properly. So there needs to be some way to remove e.g. the clock drivers later. Marking a couple of drivers as "remove-late" is much less intrusive than marking most drivers as "do-not-remove-early".
How do you propose this "inverted" remove flag would look like ?
[...]
PATCH v3 1/1 dm: core: Add late driver remove option
Hi Marek,
Quoted 17 lines · Marek Vasut
On 12/10/20 6:44 PM, Simon Glass wrote:
[...]
Quoted 12 lines
Quoted 11 lines
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Note also the semantics of what is going on here. The idea of the existing
OS_PREPAREandACTIVE_DMAflags is that the default fordevice_remove()is to remove everything, but if you provide a flag then it just removes those things. Your flag is the opposite to that, which is why you are changing so much code.I obviously cannot remove everything, see the example above.
Do you understand what I am saying about inverting the flag?
No, please elaborate.
Quoted 8 lines
Quoted 3 lines
The normal situation should be to remove everything. Removing only non-late things (which I want to call 'basic', or something like that) should be an option, like we have
DM_REMOVE_OS_PREPARE.We cannot remove everything at once, because then various real hardware cannot work properly. So there needs to be some way to remove e.g. the clock drivers later. Marking a couple of drivers as "remove-late" is much less intrusive than marking most drivers as "do-not-remove-early".
I'm not suggesting marking drivers as 'do not remove early'. I am referring to the parameter of the device_remove() function. Mostly what I am asking for is better naming, and (I hope) a simpler implementation.
Quoted 2 lines
How do you propose this "inverted" remove flag would look like ?
Similar to the existing flags. See for example DM_FLAG_ACTIVE_DMA.
I have this on my list to look at more closely and should do so in the next week.
Regards,
Simon