From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7689DC49361 for ; Fri, 18 Jun 2021 07:25:24 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ABF73610A2 for ; Fri, 18 Jun 2021 07:25:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ABF73610A2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3F88F80488; Fri, 18 Jun 2021 09:25:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="XvIG0Qyl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 341C882AF4; Fri, 18 Jun 2021 09:25:19 +0200 (CEST) Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6363F80488 for ; Fri, 18 Jun 2021 09:25:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=matwey.kornilov@gmail.com Received: by mail-qv1-xf29.google.com with SMTP id g19so214923qvx.12 for ; Fri, 18 Jun 2021 00:25:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=YV/LfsUdTbnsPo6+YvuqBrjQXM9LwU1FbFv/37Nx3Rc=; b=XvIG0QylyEk8tQBVz9GGtQdVgQq4aIT2GxTyeoikJt+jYJwnkO1Orxf4r7kzz+H41E e21jZuhhHsNBN65T8fRH+m0/XiXeqiS651bbHjBplA1TSdpQwC8nYExbJ5b/R3izM4HI rsnqWsDoZlusHUyzcazHO9FlL2E5WVZ/393WLskKEKNVS0+5wI/hPAHl29tnFR5P8g9c 0+HZK8SVaq07iD8bQ33/jThxwAcv/WtwmlNqhmdoVKJIsNQxViM4zqvhwrTmXryIU52I CksrLMdY41V0FLGdp9nH5Itric6dyETd4DDYYCIuFdUCaPCkPKf7uo49a43sRWMz8Gnd WVIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=YV/LfsUdTbnsPo6+YvuqBrjQXM9LwU1FbFv/37Nx3Rc=; b=GC7FWGlNRhOp09ZBapVnrTABzJYH+nAFsNO/UeUNYNvX8hKnV6mjeaOvx5sHwInoxU 6GWcPRzgJT+WCnvPlx1XXy4+DoHepYRJ3XzZwTAKLOCrc6CHr7XPyTC9VNcfqe+QOI+n RQgn+aH4t2Dg8ivar5l3eKg+UIxGEL7hxAX9y6uXNoaGN8Yo8XJCSIUYA8CzbYkaPCBj hqLlBdMexpzO1dWyctlow/msyT4XjHXl2VbernTf35Ly8xX99A3SFpXiDTLcAIIEoukM yphB6y2HnhhEaE1BhOYuYhwGtWGPXUjZAoPojWwkePpm688pfSxe1FLmXvcOcdQgIcPS h43A== X-Gm-Message-State: AOAM53120nsCJ9lbvZv/Z0pazc/JCOhxIqQ9N/somgs/e0fedt14nRvS b19aMboQEDiYnjmGDBNwjvoLehXaI3yfDyxacAY= X-Google-Smtp-Source: ABdhPJwlLkrNWPM7IlyfLOQSjF0hw9BhyVfpTOmObZZp/o1PBxZMZ50c89KP4lpNYx4SUIfg7Z47PepGkqdhCKN9ojA= X-Received: by 2002:a05:6214:b0d:: with SMTP id u13mr2102331qvj.55.1624001110834; Fri, 18 Jun 2021 00:25:10 -0700 (PDT) MIME-Version: 1.0 References: <20210617151532.10350-1-xypron.glpk@gmx.de> In-Reply-To: <20210617151532.10350-1-xypron.glpk@gmx.de> From: "Matwey V. Kornilov" Date: Fri, 18 Jun 2021 10:24:59 +0300 Message-ID: Subject: Re: [PATCH 1/1] efi_loader: improve block device integration with DM To: Heinrich Schuchardt Cc: U-Boot Mailing List , Simon Glass , Alexander Graf , AKASHI Takahiro , michael@walle.cc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Hi Heinrich, This patch fixes my issue with am335x: EFI Grub works as expected now. =D1=87=D1=82, 17 =D0=B8=D1=8E=D0=BD. 2021 =D0=B3. =D0=B2 18:15, Heinrich Sc= huchardt : > > Up to now when devices became available after executing the UEFI > sub-system initialization where not available for EFI applications. > > With the patch block devices are added to the UEFI object list whenever > they are probed. > > Signed-off-by: Heinrich Schuchardt Tested-by: Matwey V. Kornilov > --- > drivers/core/device.c | 7 +++ > include/efi_loader.h | 6 +++ > lib/efi_driver/Makefile | 1 + > lib/efi_driver/efi_dm_integration.c | 36 +++++++++++++++ > lib/efi_loader/efi_disk.c | 72 +++++++++++++++++------------ > 5 files changed, 93 insertions(+), 29 deletions(-) > create mode 100644 lib/efi_driver/efi_dm_integration.c > > diff --git a/drivers/core/device.c b/drivers/core/device.c > index cb960f8ec4..7355a5c2a9 100644 > --- a/drivers/core/device.c > +++ b/drivers/core/device.c > @@ -14,6 +14,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -579,6 +580,12 @@ int device_probe(struct udevice *dev) > if (dev->parent && device_get_uclass_id(dev) =3D=3D UCLASS_PINCTR= L) > pinctrl_select_state(dev, "default"); > > + if (CONFIG_IS_ENABLED(EFI_LOADER)) { > + ret =3D efi_post_probe_device(dev); > + if (ret) > + goto fail_uclass; > + } > + > return 0; > fail_uclass: > if (device_remove(dev, DM_REMOVE_NORMAL)) { > diff --git a/include/efi_loader.h b/include/efi_loader.h > index 0a9c82a257..78dd687913 100644 > --- a/include/efi_loader.h > +++ b/include/efi_loader.h > @@ -17,6 +17,7 @@ > #include > > struct blk_desc; > +struct udevice; > > static inline int guidcmp(const void *g1, const void *g2) > { > @@ -28,6 +29,9 @@ static inline void *guidcpy(void *dst, const void *src) > return memcpy(dst, src, sizeof(efi_guid_t)); > } > > +/* Called by device_probe() */ > +int efi_post_probe_device(struct udevice *dev); > + > /* No need for efi loader support in SPL */ > #if CONFIG_IS_ENABLED(EFI_LOADER) > > @@ -420,6 +424,8 @@ efi_status_t EFIAPI efi_convert_pointer(efi_uintn_t d= ebug_disposition, > void efi_carve_out_dt_rsv(void *fdt); > /* Called by bootefi to make console interface available */ > efi_status_t efi_console_register(void); > +/* Called when a block devices has been probed */ > +efi_status_t efi_block_device_register(struct udevice *dev); > /* Called by bootefi to make all disk storage accessible as EFI objects = */ > efi_status_t efi_disk_register(void); > /* Called by efi_init_obj_list() to install EFI_RNG_PROTOCOL */ > diff --git a/lib/efi_driver/Makefile b/lib/efi_driver/Makefile > index 83baa1c9a4..f0d5fa5074 100644 > --- a/lib/efi_driver/Makefile > +++ b/lib/efi_driver/Makefile > @@ -5,6 +5,7 @@ > # This file only gets included with CONFIG_EFI_LOADER set, so all > # object inclusion implicitly depends on it > > +obj-y +=3D efi_dm_integration.o > obj-y +=3D efi_uclass.o > ifeq ($(CONFIG_BLK)$(CONFIG_PARTITIONS),yy) > obj-y +=3D efi_block_device.o > diff --git a/lib/efi_driver/efi_dm_integration.c b/lib/efi_driver/efi_dm_= integration.c > new file mode 100644 > index 0000000000..9c6c339473 > --- /dev/null > +++ b/lib/efi_driver/efi_dm_integration.c > @@ -0,0 +1,36 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Copyright 2021, Heinrich Schuchardt > + */ > + > +#define LOG_CATEGORY LOGC_EFI > + > +#include > +#include > +#include > +#include > + > +/** > + * efi_post_probe_device() - set up handle for probed device > + * > + * This function is called by device_probe(). After the UEFI sub-system = is > + * initialized this function adds handles for new devices. > + * > + * @dev: probed device > + * Return: 0 on success > + */ > +int efi_post_probe_device(struct udevice *dev) > +{ > + if (!dev || !dev->uclass) > + return -EINVAL; > + > + switch (dev->uclass->uc_drv->id) { > + case UCLASS_BLK: > + if (efi_block_device_register(dev) !=3D EFI_SUCCESS) > + log_err("Failed to register %s\n", dev->name); > + default: > + break; > + } > + > + return 0; > +} > diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c > index 988907ecb9..b798cab345 100644 > --- a/lib/efi_loader/efi_disk.c > +++ b/lib/efi_loader/efi_disk.c > @@ -10,6 +10,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -535,6 +536,41 @@ int efi_disk_create_partitions(efi_handle_t parent, = struct blk_desc *desc, > return disks; > } > > +/** > + * efi_block_device_register() - register a block device in the UEFI sub= -system > + * > + * @dev: block device > + * Return: status code > + */ > +efi_status_t efi_block_device_register(struct udevice *dev) > +{ > + struct blk_desc *desc =3D dev_get_uclass_plat(dev); > + const char *if_typename =3D blk_get_if_type_name(desc->if_type); > + struct efi_disk_obj *disk; > + efi_status_t ret; > + > + /* Add block device for the full device */ > + ret =3D device_probe(dev); > + if (ret) > + return EFI_NOT_FOUND; > + log_info("Scanning disk %s...\n", dev->name); > + ret =3D efi_disk_add_dev(NULL, NULL, if_typename, > + desc, desc->devnum, NULL, 0, &disk); > + if (ret =3D=3D EFI_NOT_READY) { > + log_notice("Disk %s not ready\n", dev->name); > + return ret; > + } else if (ret !=3D EFI_SUCCESS) { > + log_err("ERROR: failure to add disk device %s, r =3D %lu\= n", > + dev->name, ret & ~EFI_ERROR_MASK); > + return ret; > + } > + > + /* Partitions show up as block devices in EFI */ > + efi_disk_create_partitions(&disk->header, desc, if_typename, > + desc->devnum, dev->name); > + return ret; > +} > + > /** > * efi_disk_register() - register block devices > * > @@ -552,38 +588,16 @@ int efi_disk_create_partitions(efi_handle_t parent,= struct blk_desc *desc, > */ > efi_status_t efi_disk_register(void) > { > - struct efi_disk_obj *disk; > - int disks =3D 0; > - efi_status_t ret; > #ifdef CONFIG_BLK > struct udevice *dev; > - > + /* Probe all block devices */ > for (uclass_first_device_check(UCLASS_BLK, &dev); dev; > - uclass_next_device_check(&dev)) { > - struct blk_desc *desc =3D dev_get_uclass_plat(dev); > - const char *if_typename =3D blk_get_if_type_name(desc->if= _type); > - > - /* Add block device for the full device */ > - log_info("Scanning disk %s...\n", dev->name); > - ret =3D efi_disk_add_dev(NULL, NULL, if_typename, > - desc, desc->devnum, NULL, 0, &dis= k); > - if (ret =3D=3D EFI_NOT_READY) { > - log_notice("Disk %s not ready\n", dev->name); > - continue; > - } > - if (ret) { > - log_err("ERROR: failure to add disk device %s, r = =3D %lu\n", > - dev->name, ret & ~EFI_ERROR_MASK); > - return ret; > - } > - disks++; > - > - /* Partitions show up as block devices in EFI */ > - disks +=3D efi_disk_create_partitions( > - &disk->header, desc, if_typename, > - desc->devnum, dev->name); > - } > + uclass_next_device_check(&dev)) > + ; > #else > + struct efi_disk_obj *disk; > + int disks =3D 0; > + efi_status_t ret; > int i, if_type; > > /* Search for all available disk devices */ > @@ -630,8 +644,8 @@ efi_status_t efi_disk_register(void) > if_typename, i, devname)= ; > } > } > -#endif > log_info("Found %d disks\n", disks); > +#endif > > return EFI_SUCCESS; > } > -- > 2.30.2 > -- With best regards, Matwey V. Kornilov