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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 3A37CC433EF for ; Fri, 22 Jul 2022 02:36:31 +0000 (UTC) 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) 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-Google-Smtp-Source: AGRyM1umD+d3GThjq6+lI9DhWjf2BjYy/y992Imtla53wwksvZHaHj5ANXyX8J9WZfIouXvUIt2XCQ== 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 --- 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); +} -- 2.17.1