Re: [PATCH v3 5/7] drivers: nvme: Export nvme_shutdown()

[email protected] Mon, 20 Jul 2026 11:42:31 +0200
Newsgroups de.denx.lists.u-boot
Organization Linaro
Message-ID <[email protected]>
On 7/17/26 00:33, [email protected] wrote:
> From: Denis Mukhin <[email protected]>
> 
> Make nvme_shutdown() public so that it can be re-used in
> board-specific board_quiesce_devices() before OS hand-off.
> 
> Signed-off-by: Denis Mukhin <[email protected]>
> ---
> Changes since v2:
> - fixup for apple device
> 
> Changes since v1:
> - n/a
> ---
>   drivers/nvme/nvme.h       |  7 -------
>   drivers/nvme/nvme_apple.c |  1 +
>   include/nvme.h            | 11 +++++++++++
>   3 files changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/nvme/nvme.h b/drivers/nvme/nvme.h
> index a938da728506..cc1477717391 100644
> --- a/drivers/nvme/nvme.h
> +++ b/drivers/nvme/nvme.h
> @@ -703,11 +703,4 @@ struct nvme_ops {
>    */
>   int nvme_init(struct udevice *udev);
>   
> -/**
> - * nvme_shutdown() - Shutdown NVM Express device
> - * @udev:	The NVM Express device
> - * Return: 0 if OK, -ve on error
> - */
> -int nvme_shutdown(struct udevice *udev);
> -
>   #endif /* __DRIVER_NVME_H__ */
> diff --git a/drivers/nvme/nvme_apple.c b/drivers/nvme/nvme_apple.c
> index 7e7538553e3f..a36f15a3ff4e 100644
> --- a/drivers/nvme/nvme_apple.c
> +++ b/drivers/nvme/nvme_apple.c
> @@ -6,6 +6,7 @@
>   #include <dm.h>
>   #include <mailbox.h>
>   #include <mapmem.h>
> +#include <nvme.h>
>   #include "nvme.h"
>   #include <reset.h>
>   
> diff --git a/include/nvme.h b/include/nvme.h
> index 2cdf8ce320c1..c7b301300097 100644
> --- a/include/nvme.h
> +++ b/include/nvme.h
> @@ -90,4 +90,15 @@ int nvme_print_info(struct udevice *udev);
>    */
>   int nvme_get_namespace_id(struct udevice *udev, u32 *ns_id, u8 *eui64);
>   
> +/**
> + * nvme_shutdown() - Shutdown NVM Express device
> + *
> + * Must be called before booting an OS to ensure cache is flushed
> + * and the controller is in a clean state for OS to re-initialize.
> + *
> + * @udev:	The NVM Express device
> + * Return: 0 if OK, -ve on error
> + */
> +int nvme_shutdown(struct udevice *udev);
> +
>   #endif /* __NVME_H__ */

Could you instead add the DM_FLAG_ACTIVE_DMA flag to the PCI NVMe driver and
then call nvme_shutdown() from a new nvem_remove in nvem_pci.c

This will automatically shutdown the NVMe devices when booting an OS and you could
trigger this manually by calling:

dm_remove_devices_flags(DM_REMOVE_ACTIVE_DMA)

Neil