dm: net: Assorted patches related to networking and DMA
Subsystems (6)
v2 cover dm: net: Assorted patches related to networking and DMA
This series collects together a few patches related to U-Boot leaving DMA running when booting.
Changes in v2:
- Use the designware_eth_remove() method directly
- Add gmac_rockchip too
- Reword the commit message to mention the uclass' actions
- Add a new patch to mark drivers as having active DMA
Simon Glass (4):
designware: Use the remove() method with related drivers
net: designware: Mark drivers as having active DMA
efi_loader: Move device-removal later in exit-boot-services
dm: core: Rename dm_remove_devices_active()
arch/arm/lib/bootm.c | 4 ++-- arch/riscv/lib/bootm.c | 2 +- arch/x86/lib/bootm.c | 2 +- drivers/core/root.c | 2 +- drivers/net/designware.c | 4 ++-- drivers/net/designware.h | 12 ++++++++++++ drivers/net/dwmac_meson8b.c | 3 ++- drivers/net/dwmac_s700.c | 3 ++- drivers/net/dwmac_socfpga.c | 3 ++- drivers/net/gmac_rockchip.c | 3 ++- include/dm/root.h | 6 +++--- lib/efi_loader/efi_boottime.c | 21 +++++++++++++-------- test/dm/core.c | 2 +- 13 files changed, 44 insertions(+), 23 deletions(-)
Signature · 4 lines
2.43.0 base-commit: d47b5693e21f78d8cd8caa8fcd9e64fd6ae85759 branch: eth2
PATCH v2 1/4 designware: Use the remove() method with related drivers
Several drivers make use of the designware Ethernet driver but do not implement the remove() method. Add this to keep things tidy.
Note that the Ethernet uclass calls each driver's stop() method on removal, so there is no need to do that here.
---
Changes in v2:
- Use the designware_eth_remove() method directly
- Add gmac_rockchip too
- Reword the commit message to mention the uclass' actions
drivers/net/designware.c | 2 +- drivers/net/designware.h | 12 ++++++++++++ drivers/net/dwmac_meson8b.c | 1 + drivers/net/dwmac_s700.c | 1 + drivers/net/dwmac_socfpga.c | 1 + drivers/net/gmac_rockchip.c | 1 + 6 files changed, 17 insertions(+), 1 deletion(-)
drivers/net/designware.c +1 -1
@@ -805,7 +805,7 @@ clk_err:return err; } -static int designware_eth_remove (struct udevice *dev) +int designware_eth_remove (struct udevice *dev) {struct dw_eth_dev *priv =dev_get_priv (dev);
drivers/net/designware.h +12 -0
@@ -247,6 +247,18 @@ struct dw_eth_dev {int designware_eth_of_to_plat (struct udevice *dev);int designware_eth_probe (struct udevice *dev); + +/** +* designware_eth_remove() - Remove the device +* +* Disables DMA and marks the device as remove. This must be called before +* booting an OS, to ensure that DMA is inactive. +* +* @dev: Device to remove +* Return 0 if OK, -ve on error +*/ +int designware_eth_remove (struct udevice *dev); +extern const struct eth_ops designware_eth_ops;struct dw_eth_pdata {
drivers/net/dwmac_meson8b.c +1 -0
@@ -158,6 +158,7 @@ U_BOOT_DRIVER(dwmac_meson8b) = { .of_match = dwmac_meson8b_ids, .of_to_plat = dwmac_meson8b_of_to_plat, .probe = dwmac_meson8b_probe, + .remove = designware_eth_remove, .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dwmac_meson8b_plat),
drivers/net/dwmac_s700.c +1 -0
@@ -60,6 +60,7 @@ U_BOOT_DRIVER(dwmac_s700) = { .of_match = dwmac_s700_ids, .of_to_plat = dwmac_s700_of_to_plat, .probe = dwmac_s700_probe, + .remove = designware_eth_remove, .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct eth_pdata),
drivers/net/dwmac_socfpga.c +1 -0
@@ -141,6 +141,7 @@ U_BOOT_DRIVER(dwmac_socfpga) = { .of_match = dwmac_socfpga_ids, .of_to_plat = dwmac_socfpga_of_to_plat, .probe = dwmac_socfpga_probe, + .remove = designware_eth_remove, .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dwmac_socfpga_plat),
drivers/net/gmac_rockchip.c +1 -0
@@ -756,6 +756,7 @@ U_BOOT_DRIVER(eth_gmac_rockchip) = { .of_match = rockchip_gmac_ids, .of_to_plat = gmac_rockchip_of_to_plat, .probe = gmac_rockchip_probe, + .remove = designware_eth_remove, .ops = &gmac_rockchip_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct gmac_rockchip_plat),
Signature · 1 line
2.43.0
Re: [PATCH v2 1/4] designware: Use the remove() method with related drivers
Quoted 100 lines · Simon Glass
Several drivers make use of the designware Ethernet driver but do not implement the
remove()method. Add this to keep things tidy.Note that the Ethernet uclass calls each driver's
stop()method on removal, so there is no need to do that here.Signed-off-by Simon Glass <[email protected]>Reported-by Christian Kohlschütter <[email protected]>---
Changes in v2:
- Use thedesignware_eth_remove()method directly
- Addgmac_rockchiptoo
- Reword the commit message to mention the uclass' actionsdrivers/net/designware.c | 2 +- drivers/net/designware.h | 12 ++++++++++++ drivers/net/dwmac_meson8b.c | 1 + drivers/net/dwmac_s700.c | 1 + drivers/net/dwmac_socfpga.c | 1 + drivers/net/gmac_rockchip.c | 1 + 6 files changed, 17 insertions(+), 1 deletion(-)drivers/net/designware.c +1
-1@@ -805,7 +805,7 @@ clk_err:return err; } -static int designware_eth_remove (struct udevice *dev) +int designware_eth_remove (struct udevice *dev) {struct dw_eth_dev *priv =dev_get_priv (dev);drivers/net/designware.h +12
-0@@ -247,6 +247,18 @@ struct dw_eth_dev {int designware_eth_of_to_plat (struct udevice *dev);int designware_eth_probe (struct udevice *dev); + +/** +* designware_eth_remove() - Remove the device +* +* Disables DMA and marks the device as remove. This must be called before +* booting an OS, to ensure that DMA is inactive. +* +* @dev: Device to remove +* Return 0 if OK, -ve on error +*/ +int designware_eth_remove (struct udevice *dev); +extern const struct eth_ops designware_eth_ops;struct dw_eth_pdata {drivers/net/dwmac_meson8b.c +1
-0@@ -158,6 +158,7 @@ U_BOOT_DRIVER(dwmac_meson8b) = { .of_match = dwmac_meson8b_ids, .of_to_plat = dwmac_meson8b_of_to_plat, .probe = dwmac_meson8b_probe, + .remove = designware_eth_remove, .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dwmac_meson8b_plat),drivers/net/dwmac_s700.c +1
-0@@ -60,6 +60,7 @@ U_BOOT_DRIVER(dwmac_s700) = { .of_match = dwmac_s700_ids, .of_to_plat = dwmac_s700_of_to_plat, .probe = dwmac_s700_probe, + .remove = designware_eth_remove, .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct eth_pdata),drivers/net/dwmac_socfpga.c +1
-0@@ -141,6 +141,7 @@ U_BOOT_DRIVER(dwmac_socfpga) = { .of_match = dwmac_socfpga_ids, .of_to_plat = dwmac_socfpga_of_to_plat, .probe = dwmac_socfpga_probe, + .remove = designware_eth_remove, .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dwmac_socfpga_plat),drivers/net/gmac_rockchip.c +0
-0
drivers/net/gmac_rockchip.c U_BOOT_DRIVER(eth_gmac_rockchip) = { · line 762
Quoted 7 lines
drivers/net/gmac_rockchip.c +1
-0@@ -756,6 +756,7 @@ U_BOOT_DRIVER(eth_gmac_rockchip) = { .of_match = rockchip_gmac_ids, .of_to_plat = gmac_rockchip_of_to_plat, .probe = gmac_rockchip_probe, + .remove = designware_eth_remove, .ops = &gmac_rockchip_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct gmac_rockchip_plat),
PATCH v2 2/4 net: designware: Mark drivers as having active DMA
In reply to Simon GlassNetwork devices which use this driver have DMA running while receiving packages. Add the required flag to driver model so that they will be removed before starting the OS.
---
Changes in v2:
- Add a new patch to mark drivers as having active DMA
drivers/net/designware.c | 2 +- drivers/net/dwmac_meson8b.c | 2 +- drivers/net/dwmac_s700.c | 2 +- drivers/net/dwmac_socfpga.c | 2 +- drivers/net/gmac_rockchip.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/designware.c +1 -1
@@ -885,7 +885,7 @@ U_BOOT_DRIVER(eth_designware) = { .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dw_eth_pdata), - .flags = DM_FLAG_ALLOC_PRIV_DMA, + .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA, };static struct pci_device_id supported[] = {
drivers/net/dwmac_meson8b.c +1 -1
@@ -162,5 +162,5 @@ U_BOOT_DRIVER(dwmac_meson8b) = { .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dwmac_meson8b_plat), - .flags = DM_FLAG_ALLOC_PRIV_DMA, + .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA, };
drivers/net/dwmac_s700.c +1 -1
@@ -64,5 +64,5 @@ U_BOOT_DRIVER(dwmac_s700) = { .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct eth_pdata), - .flags = DM_FLAG_ALLOC_PRIV_DMA, + .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA, };
drivers/net/dwmac_socfpga.c +1 -1
@@ -145,5 +145,5 @@ U_BOOT_DRIVER(dwmac_socfpga) = { .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dwmac_socfpga_plat), - .flags = DM_FLAG_ALLOC_PRIV_DMA, + .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA, };
drivers/net/gmac_rockchip.c +1 -1
@@ -760,5 +760,5 @@ U_BOOT_DRIVER(eth_gmac_rockchip) = { .ops = &gmac_rockchip_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct gmac_rockchip_plat), - .flags = DM_FLAG_ALLOC_PRIV_DMA, + .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA, };
Signature · 1 line
2.43.0
Re: [PATCH v2 2/4] net: designware: Mark drivers as having active DMA
Quoted 68 lines · Simon Glass
Network devices which use this driver have DMA running while receiving packages. Add the required flag to driver model so that they will be removed before starting the OS.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Add a new patch to mark drivers as having active DMAdrivers/net/designware.c | 2 +- drivers/net/dwmac_meson8b.c | 2 +- drivers/net/dwmac_s700.c | 2 +- drivers/net/dwmac_socfpga.c | 2 +- drivers/net/gmac_rockchip.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)drivers/net/designware.c +1
-1@@ -885,7 +885,7 @@ U_BOOT_DRIVER(eth_designware) = { .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dw_eth_pdata), - .flags = DM_FLAG_ALLOC_PRIV_DMA, + .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA, };static struct pci_device_id supported[] = {drivers/net/dwmac_meson8b.c +1
-1@@ -162,5 +162,5 @@ U_BOOT_DRIVER(dwmac_meson8b) = { .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dwmac_meson8b_plat), - .flags = DM_FLAG_ALLOC_PRIV_DMA, + .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA, };drivers/net/dwmac_s700.c +1
-1@@ -64,5 +64,5 @@ U_BOOT_DRIVER(dwmac_s700) = { .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct eth_pdata), - .flags = DM_FLAG_ALLOC_PRIV_DMA, + .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA, };drivers/net/dwmac_socfpga.c +1
-1@@ -145,5 +145,5 @@ U_BOOT_DRIVER(dwmac_socfpga) = { .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dwmac_socfpga_plat), - .flags = DM_FLAG_ALLOC_PRIV_DMA, + .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA, };drivers/net/gmac_rockchip.c +0
-0
drivers/net/gmac_rockchip.c U_BOOT_DRIVER(eth_gmac_rockchip) = { · line 764
Quoted 6 lines
drivers/net/gmac_rockchip.c +1
-1@@ -760,5 +760,5 @@ U_BOOT_DRIVER(eth_gmac_rockchip) = { .ops = &gmac_rockchip_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct gmac_rockchip_plat), - .flags = DM_FLAG_ALLOC_PRIV_DMA, + .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA, };
PATCH v2 3/4 efi_loader: Move device-removal later in exit-boot-services
In reply to Simon GlassThis removal should be the last thing done, so that U-Boot does no more memory allocations afterwards, thus avoiding potentially allocating memory which has been freed by a device that fails to de-activate its DMA.
Of course, devices should be marked with DM_FLAG_ACTIVE_DMA or DM_FLAG_OS_PREPARE but this change is good practice, in any case.
It also matches the code in announce_and_cleanup(), which we should at some point unify with EFI_LOADER
So move the code and add a comment.
Note that the TCG2 log is updated after this call, but I cannot see any allocations there.
---
(no changes since v1)
lib/efi_loader/efi_boottime.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
lib/efi_loader/efi_boottime.c +13 -8
@@ -2250,14 +2250,6 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,list_del (&evt->link); } -if (!efi_st_keep_devices) { -bootm_disable_interrupts (); -if (IS_ENABLED (CONFIG_USB_DEVICE )) -udc_disconnect (); -board_quiesce_devices (); -dm_remove_devices_active (); - } -/* Patch out unsupported runtime function */ efi_runtime_detach ();
@@ -2279,6 +2271,19 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,/* Give the payload some time to boot */ efi_set_watchdog (0 );schedule (); + +/* +* this should be the last thing done, to avoid memory allocations +* between removing devices and the OS taking over +*/ +if (!efi_st_keep_devices) { +bootm_disable_interrupts (); +if (IS_ENABLED (CONFIG_USB_DEVICE )) +udc_disconnect (); +board_quiesce_devices (); +dm_remove_devices_active (); + } + out:if (IS_ENABLED (CONFIG_EFI_TCG2_PROTOCOL )) {if (ret !=EFI_SUCCESS )
Signature · 1 line
2.43.0
Re: [PATCH v2 3/4] efi_loader: Move device-removal later in exit-boot-services
Quoted 4 lines · Simon Glass
This removal should be the last thing done, so that U-Boot does no more memory allocations afterwards, thus avoiding potentially allocating memory which has been freed by a device that fails to de-activate its DMA.
The EFI application that is calling ExitBootServices() has been reading the EFI memory map with GetMemoryMap() before. This is checked by comparing the MapKey parameter.
Whatever allocations are done or not in ExitBootServices() is not visible to the EFI application.
DMA has to be stopped in all cases.
I don't understand the virtue of the proposed change.
Best regards
Heinrich
Quoted 62 lines
Of course, devices should be marked with
DM_FLAG_ACTIVE_DMAorDM_FLAG_OS_PREPAREbut this change is good practice, in any case.It also matches the code in
announce_and_cleanup(), which we should at some point unify withEFI_LOADERSo move the code and add a comment.
Note that the TCG2 log is updated after this call, but I cannot see any allocations there.
Reported-by Christian Kohlschütter <[email protected]>Signed-off-by Simon Glass <[email protected]>---
(no changes since v1)
lib/efi_loader/efi_boottime.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)lib/efi_loader/efi_boottime.c +13
-8@@ -2250,14 +2250,6 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,list_del (&evt->link); } -if (!efi_st_keep_devices) { -bootm_disable_interrupts (); -if (IS_ENABLED (CONFIG_USB_DEVICE )) -udc_disconnect (); -board_quiesce_devices (); -dm_remove_devices_active (); - } -/* Patch out unsupported runtime function */ efi_runtime_detach ();@@ -2279,6 +2271,19 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,/* Give the payload some time to boot */ efi_set_watchdog (0 );schedule (); + +/* +* this should be the last thing done, to avoid memory allocations +* between removing devices and the OS taking over +*/ +if (!efi_st_keep_devices) { +bootm_disable_interrupts (); +if (IS_ENABLED (CONFIG_USB_DEVICE )) +udc_disconnect (); +board_quiesce_devices (); +dm_remove_devices_active (); + } + out:if (IS_ENABLED (CONFIG_EFI_TCG2_PROTOCOL )) {if (ret !=EFI_SUCCESS )
Re: [PATCH v2 3/4] efi_loader: Move device-removal later in exit-boot-services
Hi Heinrich,
Quoted 7 lines · Heinrich Schuchardt
Quoted 4 lines · Simon Glass
This removal should be the last thing done, so that U-Boot does no more memory allocations afterwards, thus avoiding potentially allocating memory which has been freed by a device that fails to de-activate its DMA.
Quoted 8 lines
The EFI application that is calling
ExitBootServices()has been reading the EFI memory map withGetMemoryMap()before. This is checked by comparing the MapKey parameter.Whatever allocations are done or not in
ExitBootServices()is not visible to the EFI application.DMA has to be stopped in all cases.
Yes, DMA must be stopped.
Quoted 2 lines
I don't understand the virtue of the proposed change.
It is described in the next two paragraphs:
Quoted 11 lines
Best regards
Heinrich
Quoted 6 lines
Of course, devices should be marked with
DM_FLAG_ACTIVE_DMAorDM_FLAG_OS_PREPAREbut this change is good practice, in any case.It also matches the code in
announce_and_cleanup(), which we should at some point unify withEFI_LOADER
See above. Also, what do you think about unifying with announce_and_cleanup() ?
Regards,
Simon
Quoted 57 lines
Quoted 56 lines
So move the code and add a comment.
Note that the TCG2 log is updated after this call, but I cannot see any allocations there.
Reported-by Christian Kohlschütter <[email protected]>Signed-off-by Simon Glass <[email protected]>---
(no changes since v1)
lib/efi_loader/efi_boottime.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)lib/efi_loader/efi_boottime.c +13
-8@@ -2250,14 +2250,6 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,list_del (&evt->link); } -if (!efi_st_keep_devices) { -bootm_disable_interrupts (); -if (IS_ENABLED (CONFIG_USB_DEVICE )) -udc_disconnect (); -board_quiesce_devices (); -dm_remove_devices_active (); - } -/* Patch out unsupported runtime function */ efi_runtime_detach ();@@ -2279,6 +2271,19 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,/* Give the payload some time to boot */ efi_set_watchdog (0 );schedule (); + +/* +* this should be the last thing done, to avoid memory allocations +* between removing devices and the OS taking over +*/ +if (!efi_st_keep_devices) { +bootm_disable_interrupts (); +if (IS_ENABLED (CONFIG_USB_DEVICE )) +udc_disconnect (); +board_quiesce_devices (); +dm_remove_devices_active (); + } + out:if (IS_ENABLED (CONFIG_EFI_TCG2_PROTOCOL )) {if (ret !=EFI_SUCCESS )
Re: [PATCH v2 3/4] efi_loader: Move device-removal later in exit-boot-services
Quoted 2 lines
From: Simon Glass <[email protected]>
Date: Mon, 7 Apr 2025 22:49:05 +1200
Hi Simon,
Since I brought up the same objection as Heinrich...
Quoted 17 lines
Hi Heinrich,
Quoted 14 lines · Heinrich Schuchardt
Quoted 4 lines · Simon Glass
This removal should be the last thing done, so that U-Boot does no more memory allocations afterwards, thus avoiding potentially allocating memory which has been freed by a device that fails to de-activate its DMA.
The EFI application that is calling
ExitBootServices()has been reading the EFI memory map withGetMemoryMap()before. This is checked by comparing the MapKey parameter.Whatever allocations are done or not in
ExitBootServices()is not visible to the EFI application.
Quoted 17 lines
Quoted 1 line
DMA has to be stopped in all cases.
Yes, DMA must be stopped.
Quoted 2 lines
I don't understand the virtue of the proposed change.
It is described in the next two paragraphs:
Quoted 8 lines
Best regards
Heinrich
Quoted 3 lines
Of course, devices should be marked with
DM_FLAG_ACTIVE_DMAorDM_FLAG_OS_PREPAREbut this change is good practice, in any case.
I disagree. Stopping DMA is early as possible is good practice.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
It also matches the code in
announce_and_cleanup(), which we should at some point unify withEFI_LOADER
As far as I can see there is nothing that happens in between the old location and your new location in efi_exit_boot_services() that matches anything that is done in announce_and_cleanup().
Quoted 65 lines
See above. Also, what do you think about unifying with
announce_and_cleanup()?Regards,
SimonQuoted 57 lines
Quoted 56 lines
So move the code and add a comment.
Note that the TCG2 log is updated after this call, but I cannot see any allocations there.
Reported-by Christian Kohlschütter <[email protected]>Signed-off-by Simon Glass <[email protected]>---
(no changes since v1)
lib/efi_loader/efi_boottime.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)lib/efi_loader/efi_boottime.c +13
-8@@ -2250,14 +2250,6 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,list_del (&evt->link); } -if (!efi_st_keep_devices) { -bootm_disable_interrupts (); -if (IS_ENABLED (CONFIG_USB_DEVICE )) -udc_disconnect (); -board_quiesce_devices (); -dm_remove_devices_active (); - } -/* Patch out unsupported runtime function */ efi_runtime_detach ();@@ -2279,6 +2271,19 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,/* Give the payload some time to boot */ efi_set_watchdog (0 );schedule (); + +/* +* this should be the last thing done, to avoid memory allocations +* between removing devices and the OS taking over +*/ +if (!efi_st_keep_devices) { +bootm_disable_interrupts (); +if (IS_ENABLED (CONFIG_USB_DEVICE )) +udc_disconnect (); +board_quiesce_devices (); +dm_remove_devices_active (); + } + out:if (IS_ENABLED (CONFIG_EFI_TCG2_PROTOCOL )) {if (ret !=EFI_SUCCESS )
PATCH v2 4/4 dm: core: Rename dm_remove_devices_active()
In reply to Simon GlassThis function doesn't have a great name, since we talk of devices being active once they are probed.
Rename it to dm_remove_dma_devices().
---
(no changes since v1)
arch/arm/lib/bootm.c | 4 ++-- arch/riscv/lib/bootm.c | 2 +- arch/x86/lib/bootm.c | 2 +- drivers/core/root.c | 2 +- include/dm/root.h | 6 +++--- lib/efi_loader/efi_boottime.c | 2 +- test/dm/core.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-)
arch/arm/lib/bootm.c +2 -2
@@ -74,10 +74,10 @@ static void announce_and_cleanup(int fake)* Call remove function of all devices with a removal flag set. * This may be useful for last-stage operations, like cancelling * of DMA operation or releasing device internal buffers. -* dm_remove_devices_active() ensures that vital devices are removed in +* dm_remove_dma_devices() ensures that vital devices are removed in * a second round. */ -dm_remove_devices_active (); +dm_remove_dma_devices ();cleanup_before_linux (); }
arch/riscv/lib/bootm.c +1 -1
@@ -57,7 +57,7 @@ static void announce_and_cleanup(int fake)* This may be useful for last-stage operations, like cancelling * of DMA operation or releasing device internal buffers. */ -dm_remove_devices_active (); +dm_remove_dma_devices ();cleanup_before_linux (); }
arch/x86/lib/bootm.c +1 -1
@@ -50,7 +50,7 @@ void bootm_announce_and_cleanup(void)* This may be useful for last-stage operations, like cancelling * of DMA operation or releasing device internal buffers. */ -dm_remove_devices_active (); +dm_remove_dma_devices (); }#if defined(CONFIG_OF_LIBFDT ) && !defined(CONFIG_OF_NO_KERNEL )
drivers/core/root.c +1 -1
@@ -148,7 +148,7 @@ int dm_remove_devices_flags(uint flags)return 0 ; } -void dm_remove_devices_active (void ) +void dm_remove_dma_devices (void ) {/* Remove non-vital devices first */ device_remove (dm_root (),DM_REMOVE_ACTIVE_ALL |DM_REMOVE_NON_VITAL );
include/dm/root.h +3 -3
@@ -169,16 +169,16 @@ int dm_uninit(void);int dm_remove_devices_flags (uint flags);/** -* dm_remove_devices_active - Call remove function of all active drivers heeding +* dm_remove_dma_devices - Call remove function of all active drivers heeding * device dependencies as far as know, i.e. removing * devices marked with DM_FLAG_VITAL last. * * All active devices will be removed */ -void dm_remove_devices_active (void ); +void dm_remove_dma_devices (void );#else static inline int dm_remove_devices_flags (uint flags) {return 0 ; } -static inline void dm_remove_devices_active (void ) { } +static inline void dm_remove_dma_devices (void ) { }#endif /**
lib/efi_loader/efi_boottime.c +1 -1
@@ -2281,7 +2281,7 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,if (IS_ENABLED (CONFIG_USB_DEVICE ))udc_disconnect ();board_quiesce_devices (); -dm_remove_devices_active (); +dm_remove_dma_devices (); } out:
test/dm/core.c +1 -1
@@ -1057,7 +1057,7 @@ static int dm_test_remove_active(struct unit_test_state *uts)ut_asserteq (true,device_active (dma_vital));/* Remove active devices in an ordered way */ -dm_remove_devices_active (); +dm_remove_dma_devices ();/* Check that all devices are inactive right now */ ut_asserteq (true,device_active (normal));
Signature · 1 line
2.43.0
Re: [PATCH v2 4/4] dm: core: Rename dm_remove_devices_active()
Quoted 83 lines · Simon Glass
This function doesn't have a great name, since we talk of devices being active once they are probed.
Rename it to
dm_remove_dma_devices().Signed-off-by Simon Glass <[email protected]>Suggested-by Jonas Karlman <[email protected]>---
(no changes since v1)
arch/arm/lib/bootm.c | 4 ++-- arch/riscv/lib/bootm.c | 2 +- arch/x86/lib/bootm.c | 2 +- drivers/core/root.c | 2 +- include/dm/root.h | 6 +++--- lib/efi_loader/efi_boottime.c | 2 +- test/dm/core.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-)arch/arm/lib/bootm.c +2
-2@@ -74,10 +74,10 @@ static void announce_and_cleanup(int fake)* Call remove function of all devices with a removal flag set. * This may be useful for last-stage operations, like cancelling * of DMA operation or releasing device internal buffers. -* dm_remove_devices_active() ensures that vital devices are removed in +* dm_remove_dma_devices() ensures that vital devices are removed in * a second round. */ -dm_remove_devices_active (); +dm_remove_dma_devices ();cleanup_before_linux (); }arch/riscv/lib/bootm.c +1
-1@@ -57,7 +57,7 @@ static void announce_and_cleanup(int fake)* This may be useful for last-stage operations, like cancelling * of DMA operation or releasing device internal buffers. */ -dm_remove_devices_active (); +dm_remove_dma_devices ();cleanup_before_linux (); }arch/x86/lib/bootm.c +1
-1@@ -50,7 +50,7 @@ void bootm_announce_and_cleanup(void)* This may be useful for last-stage operations, like cancelling * of DMA operation or releasing device internal buffers. */ -dm_remove_devices_active (); +dm_remove_dma_devices (); }#if defined(CONFIG_OF_LIBFDT ) && !defined(CONFIG_OF_NO_KERNEL )drivers/core/root.c +1
-1@@ -148,7 +148,7 @@ int dm_remove_devices_flags(uint flags)return 0 ; } -void dm_remove_devices_active (void ) +void dm_remove_dma_devices (void ) {/* Remove non-vital devices first */ device_remove (dm_root (),DM_REMOVE_ACTIVE_ALL |DM_REMOVE_NON_VITAL );include/dm/root.h +0
-0@@ -169,16 +169,16 @@ int dm_uninit(void);int dm_remove_devices_flags (uint flags);
include/dm/root.h int dm_uninit(void); · line 178
Quoted 10 lines
include/dm/root.h +2
-2/** -* dm_remove_devices_active - Call remove function of all active drivers heeding +* dm_remove_dma_devices - Call remove function of all active drivers heeding * device dependencies as far as know, i.e. removing * devices marked with DM_FLAG_VITAL last. * * All active devices will be removed */ -void dm_remove_devices_active (void ); +void dm_remove_dma_devices (void );
We have to remove all active devices. Not only DMA devices but also any device that creates interrupts.
The renaming is misleading.
Best regards
Heinrich
Quoted 33 lines
include/dm/root.h +1
-1#else static inline int dm_remove_devices_flags (uint flags) {return 0 ; } -static inline void dm_remove_devices_active (void ) { } +static inline void dm_remove_dma_devices (void ) { }#endif /** lib/efi_loader/efi_boottime.c +1
-1@@ -2281,7 +2281,7 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,if (IS_ENABLED (CONFIG_USB_DEVICE ))udc_disconnect ();board_quiesce_devices (); -dm_remove_devices_active (); +dm_remove_dma_devices (); } out:test/dm/core.c +1
-1@@ -1057,7 +1057,7 @@ static int dm_test_remove_active(struct unit_test_state *uts)ut_asserteq (true,device_active (dma_vital));/* Remove active devices in an ordered way */ -dm_remove_devices_active (); +dm_remove_dma_devices ();/* Check that all devices are inactive right now */ ut_asserteq (true,device_active (normal));
Re: [PATCH v2 4/4] dm: core: Rename dm_remove_devices_active()
Hi Heinrich,
Quoted 99 lines · Heinrich Schuchardt
Quoted 83 lines · Simon Glass
This function doesn't have a great name, since we talk of devices being active once they are probed.
Rename it to
dm_remove_dma_devices().Signed-off-by Simon Glass <[email protected]>Suggested-by Jonas Karlman <[email protected]>---
(no changes since v1)
arch/arm/lib/bootm.c | 4 ++-- arch/riscv/lib/bootm.c | 2 +- arch/x86/lib/bootm.c | 2 +- drivers/core/root.c | 2 +- include/dm/root.h | 6 +++--- lib/efi_loader/efi_boottime.c | 2 +- test/dm/core.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-)arch/arm/lib/bootm.c +2
-2@@ -74,10 +74,10 @@ static void announce_and_cleanup(int fake)* Call remove function of all devices with a removal flag set. * This may be useful for last-stage operations, like cancelling * of DMA operation or releasing device internal buffers. -* dm_remove_devices_active() ensures that vital devices are removed in +* dm_remove_dma_devices() ensures that vital devices are removed in * a second round. */ -dm_remove_devices_active (); +dm_remove_dma_devices ();cleanup_before_linux (); }arch/riscv/lib/bootm.c +1
-1@@ -57,7 +57,7 @@ static void announce_and_cleanup(int fake)* This may be useful for last-stage operations, like cancelling * of DMA operation or releasing device internal buffers. */ -dm_remove_devices_active (); +dm_remove_dma_devices ();cleanup_before_linux (); }arch/x86/lib/bootm.c +1
-1@@ -50,7 +50,7 @@ void bootm_announce_and_cleanup(void)* This may be useful for last-stage operations, like cancelling * of DMA operation or releasing device internal buffers. */ -dm_remove_devices_active (); +dm_remove_dma_devices (); }#if defined(CONFIG_OF_LIBFDT ) && !defined(CONFIG_OF_NO_KERNEL )drivers/core/root.c +1
-1@@ -148,7 +148,7 @@ int dm_remove_devices_flags(uint flags)return 0 ; } -void dm_remove_devices_active (void ) +void dm_remove_dma_devices (void ) {/* Remove non-vital devices first */ device_remove (dm_root (),DM_REMOVE_ACTIVE_ALL |DM_REMOVE_NON_VITAL );include/dm/root.h +0
-0@@ -169,16 +169,16 @@ int dm_uninit(void);int dm_remove_devices_flags (uint flags);include/dm/root.h int dm_uninit(void); · line 178
Quoted 10 lines
include/dm/root.h +2
-2/** -* dm_remove_devices_active - Call remove function of all active drivers heeding +* dm_remove_dma_devices - Call remove function of all active drivers heeding * device dependencies as far as know, i.e. removing * devices marked with DM_FLAG_VITAL last. * * All active devices will be removed */ -void dm_remove_devices_active (void ); +void dm_remove_dma_devices (void );We have to remove all active devices. Not only DMA devices but also any device that creates interrupts.
Quoted 1 line
The renaming is misleading.
Yes, but so is the existing name, as mentioned.
How about dm_remove_for_boot() ?
Regards,
Simon
Re: [PATCH v2 4/4] dm: core: Rename dm_remove_devices_active()
Quoted 102 lines · Simon Glass
Hi Heinrich,
Quoted 99 lines · Heinrich Schuchardt
Quoted 83 lines · Simon Glass
This function doesn't have a great name, since we talk of devices being active once they are probed.
Rename it to
dm_remove_dma_devices().Signed-off-by Simon Glass <[email protected]>Suggested-by Jonas Karlman <[email protected]>---
(no changes since v1)
arch/arm/lib/bootm.c | 4 ++-- arch/riscv/lib/bootm.c | 2 +- arch/x86/lib/bootm.c | 2 +- drivers/core/root.c | 2 +- include/dm/root.h | 6 +++--- lib/efi_loader/efi_boottime.c | 2 +- test/dm/core.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-)arch/arm/lib/bootm.c +2
-2@@ -74,10 +74,10 @@ static void announce_and_cleanup(int fake)* Call remove function of all devices with a removal flag set. * This may be useful for last-stage operations, like cancelling * of DMA operation or releasing device internal buffers. -* dm_remove_devices_active() ensures that vital devices are removed in +* dm_remove_dma_devices() ensures that vital devices are removed in * a second round. */ -dm_remove_devices_active (); +dm_remove_dma_devices ();cleanup_before_linux (); }arch/riscv/lib/bootm.c +1
-1@@ -57,7 +57,7 @@ static void announce_and_cleanup(int fake)* This may be useful for last-stage operations, like cancelling * of DMA operation or releasing device internal buffers. */ -dm_remove_devices_active (); +dm_remove_dma_devices ();cleanup_before_linux (); }arch/x86/lib/bootm.c +1
-1@@ -50,7 +50,7 @@ void bootm_announce_and_cleanup(void)* This may be useful for last-stage operations, like cancelling * of DMA operation or releasing device internal buffers. */ -dm_remove_devices_active (); +dm_remove_dma_devices (); }#if defined(CONFIG_OF_LIBFDT ) && !defined(CONFIG_OF_NO_KERNEL )drivers/core/root.c +1
-1@@ -148,7 +148,7 @@ int dm_remove_devices_flags(uint flags)return 0 ; } -void dm_remove_devices_active (void ) +void dm_remove_dma_devices (void ) {/* Remove non-vital devices first */ device_remove (dm_root (),DM_REMOVE_ACTIVE_ALL |DM_REMOVE_NON_VITAL );include/dm/root.h +0
-0@@ -169,16 +169,16 @@ int dm_uninit(void);int dm_remove_devices_flags (uint flags);include/dm/root.h int dm_uninit(void); · line 178
Quoted 10 lines
include/dm/root.h +2
-2/** -* dm_remove_devices_active - Call remove function of all active drivers heeding +* dm_remove_dma_devices - Call remove function of all active drivers heeding * device dependencies as far as know, i.e. removing * devices marked with DM_FLAG_VITAL last. * * All active devices will be removed */ -void dm_remove_devices_active (void ); +void dm_remove_dma_devices (void );We have to remove all active devices. Not only DMA devices but also any device that creates interrupts.
Quoted 5 lines
Quoted 1 line
The renaming is misleading.
Yes, but so is the existing name, as mentioned.
How about
dm_remove_for_boot()?
I think the name itself is fine and maybe just a bit more documentation? It's dealing with the DM_REMOVE_ACTIVE_ALL flag after all.
Signature · 1 line
Tom
Re: [PATCH v2 4/4] dm: core: Rename dm_remove_devices_active()
Hi Tom,
Quoted 106 lines · Tom Rini
Quoted 104 lines · Simon Glass
Hi Heinrich,
Quoted 100 lines · Heinrich Schuchardt
Quoted 83 lines · Simon Glass
This function doesn't have a great name, since we talk of devices being active once they are probed.
Rename it to
dm_remove_dma_devices().Signed-off-by Simon Glass <[email protected]>Suggested-by Jonas Karlman <[email protected]>---
(no changes since v1)
arch/arm/lib/bootm.c | 4 ++-- arch/riscv/lib/bootm.c | 2 +- arch/x86/lib/bootm.c | 2 +- drivers/core/root.c | 2 +- include/dm/root.h | 6 +++--- lib/efi_loader/efi_boottime.c | 2 +- test/dm/core.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-)arch/arm/lib/bootm.c +2
-2@@ -74,10 +74,10 @@ static void announce_and_cleanup(int fake)* Call remove function of all devices with a removal flag set. * This may be useful for last-stage operations, like cancelling * of DMA operation or releasing device internal buffers. -* dm_remove_devices_active() ensures that vital devices are removed in +* dm_remove_dma_devices() ensures that vital devices are removed in * a second round. */ -dm_remove_devices_active (); +dm_remove_dma_devices ();cleanup_before_linux (); }arch/riscv/lib/bootm.c +1
-1@@ -57,7 +57,7 @@ static void announce_and_cleanup(int fake)* This may be useful for last-stage operations, like cancelling * of DMA operation or releasing device internal buffers. */ -dm_remove_devices_active (); +dm_remove_dma_devices ();cleanup_before_linux (); }arch/x86/lib/bootm.c +1
-1@@ -50,7 +50,7 @@ void bootm_announce_and_cleanup(void)* This may be useful for last-stage operations, like cancelling * of DMA operation or releasing device internal buffers. */ -dm_remove_devices_active (); +dm_remove_dma_devices (); }#if defined(CONFIG_OF_LIBFDT ) && !defined(CONFIG_OF_NO_KERNEL )drivers/core/root.c +1
-1@@ -148,7 +148,7 @@ int dm_remove_devices_flags(uint flags)return 0 ; } -void dm_remove_devices_active (void ) +void dm_remove_dma_devices (void ) {/* Remove non-vital devices first */ device_remove (dm_root (),DM_REMOVE_ACTIVE_ALL |DM_REMOVE_NON_VITAL );include/dm/root.h +0
-0@@ -169,16 +169,16 @@ int dm_uninit(void);int dm_remove_devices_flags (uint flags);include/dm/root.h int dm_uninit(void); · line 178
Quoted 10 lines
include/dm/root.h +2
-2/** -* dm_remove_devices_active - Call remove function of all active drivers heeding +* dm_remove_dma_devices - Call remove function of all active drivers heeding * device dependencies as far as know, i.e. removing * devices marked with DM_FLAG_VITAL last. * * All active devices will be removed */ -void dm_remove_devices_active (void ); +void dm_remove_dma_devices (void );We have to remove all active devices. Not only DMA devices but also any device that creates interrupts.
The renaming is misleading.
Quoted 7 lines
Quoted 3 lines
Yes, but so is the existing name, as mentioned.
How about
dm_remove_for_boot()?I think the name itself is fine and maybe just a bit more documentation? It's dealing with the
DM_REMOVE_ACTIVE_ALLflag after all.
Yes, it is. I would like to more clearly separate the naming, but I haven't come up with a great option. So let's drop this patch.
Regards,
SImon