From patchwork Fri Jul 15 14:47:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 590845 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp569666max; Fri, 15 Jul 2022 07:45:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sWhYnfHKOVoCtYpGnwSxQn88qHjyarCC9MOXpts9/U4wEKQ/S+F/9i54cR3dEIfuRSmgms X-Received: by 2002:a05:6638:3290:b0:33f:6ead:a517 with SMTP id f16-20020a056638329000b0033f6eada517mr7670286jav.73.1657896332476; Fri, 15 Jul 2022 07:45:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657896332; cv=none; d=google.com; s=arc-20160816; b=SKdM2nGxKewZdZXwwz6Fx46fSrbQcTn7O1SCtZcqpCWhGujlejWdpJvdsXUJlwlbHB IhDL7D7xMx+0q25HLteW78WnL9fxBrEWDfsuLcaOcUrlke//N4dPAqkMJ8kg/BHMnIWs GFve/ynmLRV/K+Ddbbd1bFSf42aJqZUIIwFWd5cgQ6hP02oSBvTQvCr9HqmoHRRPcUpM WuVcsZKG9RLJfvDsEgcfDPxHimjAKx/Q3MyDCumSqIUc+VfKEP4j5aJuiMLBF7eUrxvz Jrhliv1YocxmtCIVcr5779Ol96Rto+GdQtiq5rxeMG5RJKziWoOJR37wfrbwWijvcnJB 1UEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=XDIyGQEMuuWcA12ZFBDN6dJBAyexu/pWj0+yvfXHVJI=; b=SBibFwg6TMv5S/jwYHYhSOPg35ZgIBKl3Wj7cNa96gO2FFQuNcZSPQsfm63vcGJrle GFlM4RBbfJfE8dK/pyeK0i2GpQYP12b/4Bf54nCibciscKLpdSENfHKS2R4t4OWMrGZ2 ijUAZSi7pnEFGKezGi3ZIR49Jfz7vOOo6lQ4rInWYotIyb6PqYmXshFAxi/esx3wRkLK sYgGzxEXtjVze5c+U7KEhI2P76/MU/8qvVjQ5ihZ2NIsA/gVW2v9keegdz4BmrYgvBYV NHVV5MPAqN9VIlQPKBPlLZXLwIAEIFsSCtPbcrdfhR8y0C7wnwGa9/LyNC3vvVzK15/L 3s2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="OfLU/Cws"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id q13-20020a056e0220ed00b002d9290e5a4dsi6007430ilv.21.2022.07.15.07.45.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 07:45:32 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="OfLU/Cws"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B9C81810F2; Fri, 15 Jul 2022 16:45:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="OfLU/Cws"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C89BA810E8; Fri, 15 Jul 2022 16:45:15 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) (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 B65C680C75 for ; Fri, 15 Jul 2022 16:45:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pg1-x52b.google.com with SMTP id o18so4576921pgu.9 for ; Fri, 15 Jul 2022 07:45:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XDIyGQEMuuWcA12ZFBDN6dJBAyexu/pWj0+yvfXHVJI=; b=OfLU/Cwsld0396Xuk39W+MeFKRckKNHHPK63MQKxohBI3Xv/xsIxh+1XzhaSMNcfRl W2vaWTV0lmCqSDWBNY0Fc6hQZDEFnT019irikh8MGOqjweG/ibJLTqvsngSBcp+CD8/s ETQlBvB2xHFQmp1kIuYyoylIzROu4M+TXFycXRuPKI6LKSEtuj58kj9WDY4RoHa41hZ8 ONhT83jvpVeGvy8/OYFNaCyJ0xLLtzCV8ux691GOAtt6tpeL3bedTs35nsjlzKFNtxYr zttIQAG84PkOg2oF8YGKUwj+19oTPM4deNBglc+6YbbLMtYajlrre0KwUVAPlwe6/DC8 LX0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XDIyGQEMuuWcA12ZFBDN6dJBAyexu/pWj0+yvfXHVJI=; b=zTA5RK4R9tfhOQXXnIBbEF6ju9onCrc/jyvm6Hc3kBRqEhQHbFrotyhqfCqFlEaHWM 5q49KzMlyKYdGa0qHMldpfSeVRvNEmmaG7U0cETmJBNweLnXP9+0v2kQkxzmxX6FqC+n l5VjIjbokbri3m0gEciQCvo3KNDRG8RMmkSkLdO91iMLCUHOUo3Uf18hHCPJfu4o8wFw /e0OBH2JMaOq/kRiWGinBB2J9S1ehMeP0K7mvMhi1/kHD7IsRIQT5F7YJxRcJXlYE8rj g0lUgKTDwzK3u/Lcmj8+/s17YYhfL+AeeqRxUB141RkIHpOhH9ur0UmA8Z+TryloBz3t dikg== X-Gm-Message-State: AJIora+byioSPr9FSx/b+HLxbI7lURS7auXg6ZMFi9pjKuTFzWgChhbH krq6ze97Wnc669KcAmECKjLi0XeQi/1BZQ== X-Received: by 2002:aa7:9d8a:0:b0:52a:bb32:528f with SMTP id f10-20020aa79d8a000000b0052abb32528fmr14611876pfq.0.1657896310904; Fri, 15 Jul 2022 07:45:10 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id u16-20020a170903125000b001690d398401sm3719923plh.88.2022.07.15.07.45.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 07:45:10 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Mark Kettenis , Masahisa Kojima Subject: [RESEND v9 1/9] efi_loader: move udevice pointer into struct efi_object Date: Fri, 15 Jul 2022 23:47:41 +0900 Message-Id: <20220715144749.30564-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220715144749.30564-1-masahisa.kojima@linaro.org> References: <20220715144749.30564-1-masahisa.kojima@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean This is a preparation patch to provide the unified method to access udevice pointer associated with the block io device. The EFI handles of both EFI block io driver implemented in lib/efi_loader/efi_disk.c and EFI block io driver implemented as EFI payload can posess the udevice pointer in the struct efi_object. We can use this udevice pointer to get the U-Boot friendly block device name(e.g. mmc 0:1, nvme 0:1) through efi_handle_t. Signed-off-by: Masahisa Kojima --- Newly created in v9 include/efi_loader.h | 8 ++++++++ lib/efi_loader/efi_disk.c | 20 +++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index 3a63a1f75f..bba5ffd482 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -226,6 +226,12 @@ const char *__efi_nesting_dec(void); #define EFI_CACHELINE_SIZE 128 #endif +/** + * efi_handle_to_udev - accessor to the DM device associated to the EFI handle + * @handle: pointer to the EFI handle + */ +#define efi_handle_to_udev(handle) (((struct efi_object *)handle)->dev) + /* Key identifying current memory map */ extern efi_uintn_t efi_memory_map_key; @@ -375,6 +381,7 @@ enum efi_object_type { * @protocols: linked list with the protocol interfaces installed on this * handle * @type: image type if the handle relates to an image + * @dev: pointer to the DM device which is associated with this EFI handle * * UEFI offers a flexible and expandable object model. The objects in the UEFI * API are devices, drivers, and loaded images. struct efi_object is our storage @@ -392,6 +399,7 @@ struct efi_object { /* The list of protocols */ struct list_head protocols; enum efi_object_type type; + struct udevice *dev; }; enum efi_image_auth_status { diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 1d700b2a6b..a8e8521e3e 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -46,7 +46,6 @@ struct efi_disk_obj { struct efi_device_path *dp; unsigned int part; struct efi_simple_file_system_protocol *volume; - struct udevice *dev; /* TODO: move it to efi_object */ }; /** @@ -124,16 +123,16 @@ static efi_status_t efi_disk_rw_blocks(struct efi_block_io *this, return EFI_BAD_BUFFER_SIZE; if (CONFIG_IS_ENABLED(PARTITIONS) && - device_get_uclass_id(diskobj->dev) == UCLASS_PARTITION) { + device_get_uclass_id(efi_handle_to_udev(diskobj)) == UCLASS_PARTITION) { if (direction == EFI_DISK_READ) - n = dev_read(diskobj->dev, lba, blocks, buffer); + n = dev_read(efi_handle_to_udev(diskobj), lba, blocks, buffer); else - n = dev_write(diskobj->dev, lba, blocks, buffer); + n = dev_write(efi_handle_to_udev(diskobj), lba, blocks, buffer); } else { /* dev is a block device (UCLASS_BLK) */ struct blk_desc *desc; - desc = dev_get_uclass_plat(diskobj->dev); + desc = dev_get_uclass_plat(efi_handle_to_udev(diskobj)); if (direction == EFI_DISK_READ) n = blk_dread(desc, lba, blocks, buffer); else @@ -552,7 +551,7 @@ static int efi_disk_create_raw(struct udevice *dev) return -1; } - disk->dev = dev; + efi_handle_to_udev(disk) = dev; if (dev_tag_set_ptr(dev, DM_TAG_EFI, &disk->header)) { efi_free_pool(disk->dp); efi_delete_handle(&disk->header); @@ -609,7 +608,7 @@ static int efi_disk_create_part(struct udevice *dev) log_err("Adding partition for %s failed\n", dev->name); return -1; } - disk->dev = dev; + efi_handle_to_udev(disk) = dev; if (dev_tag_set_ptr(dev, DM_TAG_EFI, &disk->header)) { efi_free_pool(disk->dp); efi_delete_handle(&disk->header); @@ -656,6 +655,13 @@ static int efi_disk_probe(void *ctx, struct event *event) ret = efi_disk_create_raw(dev); if (ret) return -1; + } else { + efi_handle_t handle; + + if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)&handle)) + return -1; + + efi_handle_to_udev(handle) = dev; } device_foreach_child(child, dev) {