From patchwork Fri Jul 22 02:39:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 592448 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp99545mab; Thu, 21 Jul 2022 19:36:33 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vohFIZirV+oF/dcOP+IqL1cD+oMW2JIfhjuXvDZskpx/1z63cH+o9m8QyeKBQS3fgnYVew X-Received: by 2002:a05:6e02:784:b0:2dd:49c:18b5 with SMTP id q4-20020a056e02078400b002dd049c18b5mr573814ils.224.1658457392961; Thu, 21 Jul 2022 19:36:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658457392; cv=none; d=google.com; s=arc-20160816; b=Gtq+D2jHCxkImyDUSzSc1/Wbo9lYBpVG39eWsqrNUn1SKM7GY/Bor6szR8Nfr2yP4J 6bCxNZKDB4VkbKPzpfZ/w5K2EzA5Dt4Jyz46Ml7it7xhKqY0x4FeUTbBLIz+mQpw2nKy j+6XdVhflULiwNMPQSoKV1sdcNV0BQD9eYLbkoSfdG8a9/2/Yai58+D/ytd56PcXKt1A uAVz6RYHYWV1bQS00jQ9YKmzomgIbfpcp0On/wX263Vz2Nu0mWplS81tDIvHdc68p6Xq sqP/l4UWjMO+9qXOjZFIhGVjlytHl2WW7jNTL1Ux89jLAoYhHhu1OLC6B5DSleLtGODY AI/Q== 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=erXTtqJEEjGM7PI9gLMumJ4rUmdVEgQRxw1A241WahE=; b=irx1L0vATPNmOo/bsacWQ9IQZa0MCb15ZoPv6Hxp1PMM4DW3wOT5iFKIM+CqC0sbXG QVNcA+4jIBnlh/3Fh8UbF45qibKpFSjRGq4HBJZqXjzTqA1BMhM5lsn0P2io15YLiKJ3 KzJ9lslgc7aqjbL/hJ6jXdREuJExdvaUaWzLvbJ5Rf1wHrNim5pzooSDp3rjd3M/ZPOF sQSd7K2sazgArZHJV0IBrtYp4Dza9Sn7VfcCkZcEEtk0YsT71gs5kUA78/LbMREABn3B Z659Wov/xO52j/McSppnr5oFvhQ8SxNSAPZWtplA3WAm1CUF3sRjXiGYYo/5YorJKsEP 0dRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dQDRc20V; 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 bo22-20020a056638439600b0033f60a8909esi2581092jab.93.2022.07.21.19.36.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 19:36: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=dQDRc20V; 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 5A55E84084; Fri, 22 Jul 2022 04:36:20 +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="dQDRc20V"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E2F7D840B3; Fri, 22 Jul 2022 04:36:17 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (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 84BDC83F4B for ; Fri, 22 Jul 2022 04:36:14 +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-pl1-x632.google.com with SMTP id v21so3522081plo.0 for ; Thu, 21 Jul 2022 19:36:14 -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=erXTtqJEEjGM7PI9gLMumJ4rUmdVEgQRxw1A241WahE=; b=dQDRc20VRcjark5eIIGS/raMyB0NQhoZbOUi2cjgnXj9suHoHjCHyMdAHLNmRxCd0X u6G2LjX+I88E2Qp/OuHFEEpt4C0ExIkpd2f6kddx25PdXq77bCgztiPMfYBETZucig/v 6ZgayeFG843eoyx10hVOmvuNS5XH/gE/zVALkYIT3PgEdlgDlOgXJw6DFbkiMrVfflha WaPPRrBHgRMSNyEynmSKxkA++sMHH9WJrItSRLcDms8sDTfPPF+x9m7xGnRdxgXmDGT4 adWW4xe7xVZBB16pbSyx0tV3YDtTa1SunyhwIENUpEMWPPIzIGmgapbzn/IeZ1YAoMUg KtZA== 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=erXTtqJEEjGM7PI9gLMumJ4rUmdVEgQRxw1A241WahE=; b=Pjdcw+5oElCr5vcgXePf/1YnYFqz+iXnv3M+vMOnQqX+AmjgcJTnq5qhKNMr2VEQS4 elwm9fMGpBFSTXJPBrhERanHcDxT5Ri4vf7B0otSwlub6YsNMnvULykFk6BFG5/w7rD6 HKlZwQ1NtDT4TAAh1L2dlRtbJJ/NtV9HyddOVB2nZqegIW6n1VfxWjmWznyD+rMxgBlh JRyn17eyaUq7GTzEq4WEBQ2Stg47N3DazhxypC37Cehl/iCHmgpIFlSWLN+n9pgFt/ID txRoaqqKzrmuuciMQytb3MCPhR4shPl6LcW7Gi4vNjRsccJPMIZlQVkZwZowiB/J09DN b6TA== X-Gm-Message-State: AJIora/fI5Nod8BlSAmsLYsQoocvNX+pPCLa49R17zVxwEEOi68Khfh9 +qs+PBnCDh1t3EkAD/AqJlD+zZkxaLcJaA== X-Received: by 2002:a17:90a:9a91:b0:1f2:34eb:6f8c with SMTP id e17-20020a17090a9a9100b001f234eb6f8cmr5605897pjp.91.1658457372387; Thu, 21 Jul 2022 19:36:12 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id k21-20020aa79735000000b0051c758a3957sm2509896pfg.149.2022.07.21.19.36.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 19:36:11 -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: [PATCH v10 01/10] efi_loader: move udevice pointer into struct efi_object Date: Fri, 22 Jul 2022 11:39:10 +0900 Message-Id: <20220722023919.19676-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220722023919.19676-1-masahisa.kojima@linaro.org> References: <20220722023919.19676-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 EFI handle by adding udevice pointer into struct efi_object. The patch also introduces a helper function efi_link_dev() to link the udevice and EFI handle. 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 access 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. Signed-off-by: Masahisa Kojima Reviewed-by: Heinrich Schuchardt --- Changes in v10: - introduce efi_link_dev() and remove accessor macro - set udevice in efi_bl_bind() Newly created in v9 include/efi_loader.h | 4 ++++ lib/efi_driver/efi_block_device.c | 3 +-- lib/efi_loader/efi_disk.c | 15 ++++++--------- lib/efi_loader/efi_helper.c | 13 +++++++++++++ 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index 3a63a1f75f..b0d6fff67c 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -375,6 +375,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 +393,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 { @@ -690,6 +692,8 @@ struct efi_device_path *efi_get_dp_from_boot(const efi_guid_t guid); const char *guid_to_sha_str(const efi_guid_t *guid); int algo_to_len(const char *algo); +int efi_link_dev(efi_handle_t handle, struct udevice *dev); + /** * efi_size_in_pages() - convert size in bytes to size in pages * diff --git a/lib/efi_driver/efi_block_device.c b/lib/efi_driver/efi_block_device.c index 5baa6f87a3..d57d281f85 100644 --- a/lib/efi_driver/efi_block_device.c +++ b/lib/efi_driver/efi_block_device.c @@ -158,8 +158,7 @@ static int efi_bl_bind(efi_handle_t handle, void *interface) * FIXME: necessary because we won't do almost nothing in * efi_disk_create() when called from device_probe(). */ - ret = dev_tag_set_ptr(bdev, DM_TAG_EFI, handle); - if (ret) + if (efi_link_dev(handle, bdev)) /* FIXME: cleanup for bdev */ return ret; diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 1d700b2a6b..16d14b0429 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(diskobj->header.dev) == UCLASS_PARTITION) { if (direction == EFI_DISK_READ) - n = dev_read(diskobj->dev, lba, blocks, buffer); + n = dev_read(diskobj->header.dev, lba, blocks, buffer); else - n = dev_write(diskobj->dev, lba, blocks, buffer); + n = dev_write(diskobj->header.dev, 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(diskobj->header.dev); if (direction == EFI_DISK_READ) n = blk_dread(desc, lba, blocks, buffer); else @@ -552,8 +551,7 @@ static int efi_disk_create_raw(struct udevice *dev) return -1; } - disk->dev = dev; - if (dev_tag_set_ptr(dev, DM_TAG_EFI, &disk->header)) { + if (efi_link_dev(&disk->header, dev)) { efi_free_pool(disk->dp); efi_delete_handle(&disk->header); @@ -609,8 +607,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; - if (dev_tag_set_ptr(dev, DM_TAG_EFI, &disk->header)) { + if (efi_link_dev(&disk->header, dev)) { efi_free_pool(disk->dp); efi_delete_handle(&disk->header); diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index c4499f65ee..8ed564e261 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -158,3 +158,16 @@ int algo_to_len(const char *algo) return 0; } + +/** efi_link_dev - link the efi_handle_t and udevice + * + * @handle: efi handle to associate with udevice + * @dev: udevice to associate with efi handle + * + * Return: 0 on success, negative on failure + */ +int efi_link_dev(efi_handle_t handle, struct udevice *dev) +{ + handle->dev = dev; + return dev_tag_set_ptr(dev, DM_TAG_EFI, handle); +}