From patchwork Fri Oct 1 05:02:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 515002 Delivered-To: patch@linaro.org Received: by 2002:a02:606e:0:0:0:0:0 with SMTP id d46csp453373jaf; Thu, 30 Sep 2021 22:07:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPM/LK22Tz9GWAj8YgIh3Br6vHkMkOc0epU72A15foFEqXZC8DWVqkAXJFEg6fch1QrsFE X-Received: by 2002:aa7:c686:: with SMTP id n6mr12132065edq.101.1633064868552; Thu, 30 Sep 2021 22:07:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633064868; cv=none; d=google.com; s=arc-20160816; b=t7vfHwNbB23Zcl3bRmdbD5e2KdzdqVUjjwyL3bN4h2gwdXDP3OmbrIwAmy5acbUDBR DbpJ4HbFDhER/+W+OxAcHIv8KynHCaBF1rIFOb1vl/geCdJCbA1/2Lc1ASo2daUH9zB6 NegtaFi+iRj7wU1+8hTV35WaMYXJvHNntIRcvm6DaIj1JID5WX12LIgQ5W3/tvJLon2g JkamEDpwR1V8vtR8LuI9Q2BBxzeroRBoDe2UGbrW6vgXjvV348mynjVHmuYO759LGpYJ P/ZR32UtxwEcIyfMBr7EPcVr/wZfqA9QCt1g1mMKqqMaa7AbASF1QNBAvLcaNd5Ps++8 txwg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ljBbc9yy6BIAE/d1lliVlMaJO1EJHQ1AhZFnjPHH/kI=; b=BvRrFipl/EvYgNWpP+69NhKVET2p4M1XRrSA9jXFyEyuyhNx3E3z7p288nbmANXzgI N/qEu3zE2eDecdKkJ6QdAGAnLLZnnPeYafwVXdVE9+Dq4aDHi8ueR69XzZUIdLsuf+Bq Vswi4DckWCF/XCBvMRmQcIFbZdB+YLJOZDPIOoSD8c3gahg7zkuy8MyhCvwxjwMaN7vZ +2EcczuxAP2ujV8KFh84HrgZU6DuQaQPbCY9NDDHw4fkjTPYWvlPH+S8lkzEZhcwoowY xaFTJNZ33SFWmEW/1Y2GRZpL6cv9a3xIwYpKIgn7KPwo/B0TG9h/pF5Vd+T63FXzU9Jb tW/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Ah/HQK35"; 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 i10si6497020ejd.99.2021.09.30.22.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 22:07:48 -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="Ah/HQK35"; 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 A7F9083465; Fri, 1 Oct 2021 07:04:47 +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="Ah/HQK35"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7AFE983404; Fri, 1 Oct 2021 07:04:24 +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-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) (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 18B838341B for ; Fri, 1 Oct 2021 07:04:15 +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=takahiro.akashi@linaro.org Received: by mail-pl1-x629.google.com with SMTP id y1so5519729plk.10 for ; Thu, 30 Sep 2021 22:04:15 -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 :mime-version:content-transfer-encoding; bh=ljBbc9yy6BIAE/d1lliVlMaJO1EJHQ1AhZFnjPHH/kI=; b=Ah/HQK35REkodihkPeXka5DzU0sy9gTFtKA+qdvW6+E1PrA/ISx9pWIHe0kbxAt5df g5bj85m3xHpd5o+8p0lXfjTf6Ddnrj6eQWr0C15fFrbJDVs3JhuJJ5fgy4WtEknzTxpZ +1QmL+nydHj2mAsBoD1PVQnzvu/UdCU3a5f65OjB2uYdF7UPpPGfcDv3F2zv432goR3u im1xxevUEYjwL8uWZElV39sOqO9LQ7Yjk5fmLL5DwTqd5uaelFOHlvU5EvoGpCX5sZe1 my7uggw/p0PUGIplxNzuOmBYF6lSSb6FIKMXtkbOts5+o5WmFUbQKaAeKwURGl5/aoHR zrhQ== 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:mime-version:content-transfer-encoding; bh=ljBbc9yy6BIAE/d1lliVlMaJO1EJHQ1AhZFnjPHH/kI=; b=LWw0DaFl8qWvRPKUTGYtM3Wd3qRev2tR6StrSt3txJ4WatApyTZfSS7xCngbNj2MPo yfgOA63GpkwcPJ+eMXagiI4g57PlV243R8zFezbcB+8yyL5eeKnjFD0XB4WO658OhUxy T4x6RR1oiaJMsC32LjEXkyl5AefegvVCuvO3QHHQH8t2QmsgfgqKYI4c+Qg0YYdueQn2 0EGswn8Adomufc3dfsn3w3e5iQpdWnzDOkqgItQXFfH11MbOsNp38mv9Jgur785MsQyG 43Prm0kaQcrK5BCpx8tnWexcWFsRBu8M2Y7Bp9OQ+kWz7DPY+W2VqdRQpjMhDxaeAuLG CyOw== X-Gm-Message-State: AOAM533vgFyKQi90r8eur8caahwF3ZHsRFHqLa23fyasOMZw4walaBP9 uR6QFKtkQTe0xp+P2hHvLIyRYWPEoxkKqg== X-Received: by 2002:a17:90a:3fca:: with SMTP id u10mr17393243pjm.95.1633064653336; Thu, 30 Sep 2021 22:04:13 -0700 (PDT) Received: from localhost.localdomain (122-100-26-52m5.mineo.jp. [122.100.26.52]) by smtp.gmail.com with ESMTPSA id z8sm4615113pgc.53.2021.09.30.22.04.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 22:04:12 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de, sjg@chromium.org, ilias.apalodimas@linaro.org Cc: u-boot@lists.denx.de, AKASHI Takahiro Subject: [RFC 13/22] efi_loader: disk: a helper function to create efi_disk objects from udevice Date: Fri, 1 Oct 2021 14:02:09 +0900 Message-Id: <20211001050228.55183-26-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211001050228.55183-1-takahiro.akashi@linaro.org> References: <20211001050228.55183-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 Add efi_disk_create() function. Any UEFI handle created by efi_disk_create() can be treated as a efi_disk object, the udevice is either a UCLASS_BLK (a whole raw disk) or UCLASS_PARTITION (a disk partition). So this function is expected to be called every time such an udevice is detected and activated through a device model's "probe" interface. Signed-off-by: AKASHI Takahiro --- include/efi_loader.h | 2 + lib/efi_loader/efi_disk.c | 92 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) -- 2.33.0 diff --git a/include/efi_loader.h b/include/efi_loader.h index c440962fe522..751fde7fb153 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -517,6 +517,8 @@ efi_status_t EFIAPI efi_convert_pointer(efi_uintn_t debug_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 */ +int efi_disk_create(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_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index cd5528046251..3fae40e034fb 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 @@ -484,6 +485,7 @@ error: return ret; } +#ifndef CONFIG_BLK /** * efi_disk_create_partitions() - create handles and protocols for partitions * @@ -531,6 +533,96 @@ int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc, return disks; } +#endif /* CONFIG_BLK */ + +/* + * Create a handle for a whole raw disk + * + * @dev uclass device + * @return 0 on success, -1 otherwise + */ +static int efi_disk_create_raw(struct udevice *dev) +{ + struct efi_disk_obj *disk; + struct blk_desc *desc; + const char *if_typename; + int diskid; + efi_status_t ret; + + desc = dev_get_uclass_plat(dev); + if_typename = blk_get_if_type_name(desc->if_type); + diskid = desc->devnum; + + ret = efi_disk_add_dev(NULL, NULL, if_typename, desc, + diskid, NULL, 0, &disk); + if (ret != EFI_SUCCESS) { + log_err("Adding disk %s%d failed\n", if_typename, diskid); + return -1; + } + disk->dev = dev; + dev->efi_obj = &disk->header; + + return 0; +} + +/* + * Create a handle for a disk partition + * + * @dev uclass device + * @return 0 on success, -1 otherwise + */ +static int efi_disk_create_part(struct udevice *dev) +{ + efi_handle_t parent; + struct blk_desc *desc; + const char *if_typename; + struct disk_part *part_data; + struct disk_partition *info; + unsigned int part; + int diskid; + struct efi_device_path *dp = NULL; + struct efi_disk_obj *disk; + efi_status_t ret; + + parent = dev->parent->efi_obj; + desc = dev_get_uclass_plat(dev->parent); + if_typename = blk_get_if_type_name(desc->if_type); + diskid = desc->devnum; + + part_data = dev_get_uclass_plat(dev); + part = part_data->partnum; + info = &part_data->gpt_part_info; + + /* TODO: should not use desc? */ + dp = efi_dp_from_part(desc, 0); + + ret = efi_disk_add_dev(parent, dp, if_typename, desc, diskid, + info, part, &disk); + if (ret != EFI_SUCCESS) { + log_err("Adding partition %s%d:%x failed\n", + if_typename, diskid, part); + return -1; + } + disk->dev = dev; + dev->efi_obj = &disk->header; + + return 0; +} + +int efi_disk_create(struct udevice *dev) +{ + enum uclass_id id; + + id = device_get_uclass_id(dev); + + if (id == UCLASS_BLK) + return efi_disk_create_raw(dev); + + if (id == UCLASS_PARTITION) + return efi_disk_create_part(dev); + + return -1; +} /** * efi_disk_register() - register block devices