[RFC 3/7] dm: implement get_dp_node for block devices

Simon Glass sjg at chromium.org
Mon Mar 27 06:00:40 CEST 2023


Hi Heinrich,

On Mon, 27 Mar 2023 at 06:27, Heinrich Schuchardt
<heinrich.schuchardt at canonical.com> wrote:
>
> Generate a Ctrl() node for block devices.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
> ---
>  drivers/block/blk-uclass.c | 56 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 56 insertions(+)

Can this go in drivers/block/blk_efi.c ?

Can you create a function which returns the path given a device? Then
we are discuss the get_dp_node() member or moving to an event. I
favour the event for now.

>
> diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
> index c69fc4d518..08202aaaba 100644
> --- a/drivers/block/blk-uclass.c
> +++ b/drivers/block/blk-uclass.c
> @@ -9,6 +9,7 @@
>  #include <common.h>
>  #include <blk.h>
>  #include <dm.h>
> +#include <efi_loader.h>
>  #include <log.h>
>  #include <malloc.h>
>  #include <part.h>
> @@ -779,9 +780,64 @@ static int blk_post_probe(struct udevice *dev)
>         return 0;
>  }
>
> +#if CONFIG_IS_ENABLED(EFI_LOADER)
> +__maybe_unused
> +static struct efi_device_path *blk_scsi_get_dp_node(struct udevice *dev)
> +{
> +       struct efi_device_path_scsi *dp;
> +       struct blk_desc *desc = dev_get_uclass_plat(dev);
> +
> +       dp = efi_alloc(sizeof(struct efi_device_path_scsi));
> +       if (!dp)
> +               return NULL;
> +
> +       dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
> +       dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_SCSI;
> +       dp->dp.length = sizeof(*dp);
> +       dp->logical_unit_number = desc->lun;
> +       dp->target_id = desc->target;
> +
> +       return &dp->dp;
> +}
> +
> +static struct efi_device_path *blk_get_dp_node(struct udevice *dev)
> +{
> +       struct efi_device_path_controller *dp;
> +       struct blk_desc *desc = dev_get_uclass_plat(dev);
> +       u32 controller_number;
> +
> +       switch (device_get_uclass_id(dev->parent)) {
> +#if CONFIG_IS_ENABLED(SCSI)
> +       case UCLASS_SCSI:
> +               return blk_scsi_get_dp_node(dev);
> +#endif
> +       case UCLASS_MMC:
> +               dp->controller_number = desc->hwpart;
> +               break;
> +       default:

Since this is checking the parent class, it seems to me that this info
should be attacked there (the 'media' device) instead of the block
device.

> +               dp->controller_number = desc->lun;
> +               break;
> +       }
> +
> +       dp = efi_alloc(sizeof(struct efi_device_path_controller));
> +       if (!dp)
> +               return NULL;
> +
> +       dp->dp.type           = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
> +       dp->dp.sub_type       = DEVICE_PATH_SUB_TYPE_CONTROLLER;
> +       dp->dp.length         = sizeof(*dp);
> +       dp->controller_number = controller_number;
> +
> +       return &dp->dp;
> +}
> +#endif
> +
>  UCLASS_DRIVER(blk) = {
>         .id             = UCLASS_BLK,
>         .name           = "blk",
>         .post_probe     = blk_post_probe,
>         .per_device_plat_auto   = sizeof(struct blk_desc),
> +#if CONFIG_IS_ENABLED(EFI_LOADER)
> +       .get_dp_node    = blk_get_dp_node,
> +#endif
>  };
> --
> 2.39.2
>

Regards,
Simon


More information about the U-Boot mailing list