From patchwork Fri Jul 15 14:27:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 590835 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp551353max; Fri, 15 Jul 2022 07:25:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vyXFNBTB70F+Ht2ubdhHF5Dz2+lo7tK7T7vq39BxP+gvuHKb2++l8ZuuriAHSQmRqTHPQb X-Received: by 2002:a05:6638:12c8:b0:33f:c6f4:4680 with SMTP id v8-20020a05663812c800b0033fc6f44680mr5588173jas.267.1657895119805; Fri, 15 Jul 2022 07:25:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657895119; cv=none; d=google.com; s=arc-20160816; b=T4n+qs918pkHQHZj27gOmjY1RV6RZ/2Ox9ytchZAJ6HuY1+4Lvn7wSitL7EtpmdzJh eYx3YSv2pdooJsstMDm2y9e3O3aiyMRRuZXSRuKXW35s7K1acEzo73c8BCKb++Zu0yrG PBgXIwAskDfKSmPXMEhy324CwONEmL9+3lgTImAMFdgLP/25TTqYr7h5F2VYpBBYWqLV zCTfwIY4qwdUyN/DRXYo9fMFJTJz1Z0tF55z6qJBJNsEL/vojFBrSldqWMH6weoOr/Mj nH1yzF8to29axDXN+GmuJ0Q4a8X1DXDVvxXz1y+bzQK9Q5ZwkNg9sDjZfHBJ3QXZDIIE +BRA== 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=bADVhoMyeg7g3e6y9XKn45gdUJP16VkHXi+d4V8CDetf6N1N1mhCijzz5Lqpm5WVKn Rcik8FiaJv1kxUd9KUNcvZ/yUWXBMP+7rn4sSleNwlcMbfHOtSM3udS61Ay946e0qxwD f5nG7RLvJDLQnOVkdO3czR2Fm52/xapMAjoas03N9Gkry4eANCoFPk/vPhc+uQqXkDfb UCpTn6K93yw3zHUqFxZCuiIC8DTIL+7LPH7bCmKagfxscMlwtAyep+odqIVtVZ+pxmBw E6qxnB9uaciTQKhyuNfGiFzbiqmMJA1fnFHIl8mkvQO5aHip1/uQEYZ1hgvzw52aGcdV g3nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Nif7paM1; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id x11-20020a056602160b00b0067ba8c5c434si5409913iow.50.2022.07.15.07.25.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 07:25:19 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Nif7paM1; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 5C47981100; Fri, 15 Jul 2022 16:25:05 +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="Nif7paM1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 670DB80909; Fri, 15 Jul 2022 16:25:02 +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-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) (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 0903E80C75 for ; Fri, 15 Jul 2022 16:24:58 +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-pf1-x433.google.com with SMTP id d10so4782213pfd.9 for ; Fri, 15 Jul 2022 07:24:57 -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=Nif7paM1bEczt4ctYamDgueoG3+vEtnMBqoJd7iq0blyNY2Mpjt7/bx9rqGgmZNbFc X3XQjtc6fnYF+2TreKFtgPlYLk4f1jk6s2vopv3PlASXSURvpNkCCzeoEjNLktfMowKs ilkeKkv4oSc03Lziq6JSwcZjCikGUUjKaGw5AcFbQ5lT+pKsPBVdmwYe4CipQXo9fBFm BVLGWobUUvARCKgNriKEkSpk9Ps6+KhKYZDAPoqFNKjzORuJhoRKTl7vJDbwM/LOsFTO LixHLrjBW7k1RDI8GjgiCgZ7TTRhYg61GwcYfSZgpeUpJt99JCtIz5lx3KmQguv5XPu3 6kHw== 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=PGPjwRn5itv+5A2nizQD1Laccm9UayUAzRfapEUW9sZFpe7IVXCs9r5/KJaQq2Mz+y FhTpJ13LAMAF//Ny9yoXhc6P3TyRuY1g9lmez18dHLiZlDo8870VZg0NXx5DZlL33MST OPJTlXEHTAmybcVWcn4wRrLgmI8JSK4UcT17KiZt7bKDRiRis4rWE51qNhJRbRW+wH6W xe1bc3AGU/Co3Bn4T0PLZKe32VMxKKAW36zEK9P8NuZRy062xqBT/tTYEdDvlAJ8bepC Fcgfits2X35vlGXK0p6DDehPwt4oTu3pL3w2iNAhB1CPqBwGoCELlm4BhdSH3CdtvQzZ bewg== X-Gm-Message-State: AJIora+XvhJG1smUiGxMx4Zj3OWcK8D+xcnqmVEiE7sp8L69rHpE6ieR FsDQH2aUFGYbQNPSgazwCIaLi8kIaPum2g== X-Received: by 2002:a62:6506:0:b0:52b:15cb:8ea9 with SMTP id z6-20020a626506000000b0052b15cb8ea9mr11826538pfb.57.1657895096124; Fri, 15 Jul 2022 07:24:56 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id d22-20020aa797b6000000b0051c49fb62b7sm3891174pfq.165.2022.07.15.07.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 07:24:55 -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 1/9] efi_loader: move udevice pointer into struct efi_object Date: Fri, 15 Jul 2022 23:27:35 +0900 Message-Id: <20220715142743.30137-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220715142743.30137-1-masahisa.kojima@linaro.org> References: <20220715142743.30137-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) {