From patchwork Mon Jan 20 10:50:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 858762 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:cc8:b0:385:e875:8a9e with SMTP id dq8csp1859641wrb; Mon, 20 Jan 2025 02:51:54 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXDgrOrMNKebtsxLIzjMhoLiQaxUFuoeq9GpknXO0oRoDhTQwZiTw78EfnCQXw8aIaDh4aZtQ==@linaro.org X-Google-Smtp-Source: AGHT+IFSdypHgbIlBGavIz7mS3MBjE8RWKAQSR7QOGQ3Yi5XZSBCtPQrGvSKE9A75YoOmfCsek+K X-Received: by 2002:a05:600c:5119:b0:434:a529:3b87 with SMTP id 5b1f17b1804b1-438913cb50dmr142173505e9.10.1737370314151; Mon, 20 Jan 2025 02:51:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1737370314; cv=none; d=google.com; s=arc-20240605; b=YdnNVjUh90hXUjIXWSgWU+m564Vc7FpziS5pAALRkkFZeutClAIJ5yh+JOVtZLq+FG YkZPGvcL8P2ikp6vyx9tSkeMEIv/54D+fh35AKsOPcc4QppruvBuinH9O2pTXa+Pf3v4 YWC8Z8Pex6xpc2wjDQek625uv+mqTLS3o/5mfPImRkpDej6vdCr5vbqCI/N1QKK6cNh2 NZe1BeXfDqi55Tn+Qbpt66PwEINwdRSjVbZQd1kiQiZ1DyJFdG/pclnpD/E2TwO1qpcN Um5KPFoHyE3Pnk5ZSIJzcAzfG1Wt1zRq3woIw1pVgU4Ye4jBwX7CjLKrzt30SUUgSIPA Fbtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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; bh=8R7v7/bAZgnJrGJcnboW1GZCcbOfTWsVjBlmgNjIF08=; fh=YztAvNK/sr+8F45uFKQI49AUhmfh/leUUwFnn5QUXFw=; b=iVV6j8uzwntw5pWG0VhuXsXBuM0FtntUCmQ3WlRPz0Pp6un5OT279Pg8fxqRi+OQKI 2z92RGUjz0QRzg/nUsi4lk9PwqAcnXsI/For/HxSZqe3UAgd6Grxo8ERciUW9W2ZHi4t l2l6yRtpFUlG2j6r0pd3RbFq8lUPXWMLcPIoFJrPCYP6Y0moQEyUvetf6J/lOtfU51by R8pjB0iI6Dvlehjl1gz/KDrKkVV6T5hBrgycEJCfGs1e6ASyDQsue7/JeP9dzr4DPSs8 Zk5sxLHrJMbOEC5IuIGlFBYODUSUVFNtrmF6fiD0A/JoFpFGW5EeDh+KjsEQmQJ2AqjK y+Ug==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 5b1f17b1804b1-437c754b6bfsi88657545e9.146.2025.01.20.02.51.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2025 02:51:54 -0800 (PST) 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; 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=fail (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 94FFE801CF; Mon, 20 Jan 2025 11:51:27 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id BCCAC801CF; Mon, 20 Jan 2025 11:51:26 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 22349807C0 for ; Mon, 20 Jan 2025 11:51:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0D12D1063; Mon, 20 Jan 2025 02:51:52 -0800 (PST) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 640023F740; Mon, 20 Jan 2025 02:51:20 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Anton Antonov , Tobias Waldekranz , Bin Meng , Sughosh Ganu Subject: [PATCH v3 5/5] blkmap: add pmem nodes for blkmap mem mapping devices Date: Mon, 20 Jan 2025 16:20:45 +0530 Message-Id: <20250120105045.1281262-6-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250120105045.1281262-1-sughosh.ganu@linaro.org> References: <20250120105045.1281262-1-sughosh.ganu@linaro.org> MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean The EFI HTTP boot puts the ISO installer image at some location in memory which needs to be added to the devicetree as persistent memory (pmem) node. The OS installer then gets information about the presence of this ISO image through the pmem node and proceeds with the installation. In U-Boot, this ISO image gets mounted as a memory mapped blkmap device. Add a helper function which iterates through all such memory mapped blkmap devices, and calls the FDT fixup function to add the pmem node. Invoke this helper function as part of the DT fixup which happens before booting the OS. Signed-off-by: Sughosh Ganu --- Changes since V2: New patch boot/image-fdt.c | 9 ++++ drivers/block/blkmap.c | 80 ------------------------------ drivers/block/blkmap_helper.c | 45 +++++++++++++++++ include/blkmap.h | 91 +++++++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+), 80 deletions(-) diff --git a/boot/image-fdt.c b/boot/image-fdt.c index 9d1598b1a93..9af00f406bb 100644 --- a/boot/image-fdt.c +++ b/boot/image-fdt.c @@ -8,6 +8,7 @@ * Wolfgang Denk, DENX Software Engineering, wd@denx.de. */ +#include #include #include #include @@ -649,6 +650,14 @@ int image_setup_libfdt(struct bootm_headers *images, void *blob, bool lmb) if (!ft_verify_fdt(blob)) goto err; + if (CONFIG_IS_ENABLED(BLKMAP)) { + fdt_ret = blkmap_fdt_pmem_setup(blob); + if (fdt_ret) { + log_err("pmem node fixup failed\n"); + goto err; + } + } + /* after here we are using a livetree */ if (!of_live_active() && CONFIG_IS_ENABLED(EVENT)) { struct event_ft_fixup fixup; diff --git a/drivers/block/blkmap.c b/drivers/block/blkmap.c index a817345b6bc..f4a89277173 100644 --- a/drivers/block/blkmap.c +++ b/drivers/block/blkmap.c @@ -14,57 +14,6 @@ #include #include -struct blkmap; - -/** - * struct blkmap_slice - Region mapped to a blkmap - * - * Common data for a region mapped to a blkmap, specialized by each - * map type. - * - * @node: List node used to associate this slice with a blkmap - * @blknr: Start block number of the mapping - * @blkcnt: Number of blocks covered by this mapping - */ -struct blkmap_slice { - struct list_head node; - - lbaint_t blknr; - lbaint_t blkcnt; - - /** - * @read: - Read from slice - * - * @read.bm: Blkmap to which this slice belongs - * @read.bms: This slice - * @read.blknr: Start block number to read from - * @read.blkcnt: Number of blocks to read - * @read.buffer: Buffer to store read data to - */ - ulong (*read)(struct blkmap *bm, struct blkmap_slice *bms, - lbaint_t blknr, lbaint_t blkcnt, void *buffer); - - /** - * @write: - Write to slice - * - * @write.bm: Blkmap to which this slice belongs - * @write.bms: This slice - * @write.blknr: Start block number to write to - * @write.blkcnt: Number of blocks to write - * @write.buffer: Data to be written - */ - ulong (*write)(struct blkmap *bm, struct blkmap_slice *bms, - lbaint_t blknr, lbaint_t blkcnt, const void *buffer); - - /** - * @destroy: - Tear down slice - * - * @read.bm: Blkmap to which this slice belongs - * @read.bms: This slice - */ - void (*destroy)(struct blkmap *bm, struct blkmap_slice *bms); -}; - static bool blkmap_slice_contains(struct blkmap_slice *bms, lbaint_t blknr) { return (blknr >= bms->blknr) && (blknr < (bms->blknr + bms->blkcnt)); @@ -114,20 +63,6 @@ static int blkmap_slice_add(struct blkmap *bm, struct blkmap_slice *new) return 0; } -/** - * struct blkmap_linear - Linear mapping to other block device - * - * @slice: Common map data - * @blk: Target block device of this mapping - * @blknr: Start block number of the target device - */ -struct blkmap_linear { - struct blkmap_slice slice; - - struct udevice *blk; - lbaint_t blknr; -}; - static ulong blkmap_linear_read(struct blkmap *bm, struct blkmap_slice *bms, lbaint_t blknr, lbaint_t blkcnt, void *buffer) { @@ -188,21 +123,6 @@ int blkmap_map_linear(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, return err; } -/** - * struct blkmap_mem - Memory mapping - * - * @slice: Common map data - * @addr: Target memory region of this mapping - * @remapped: True if @addr is backed by a physical to virtual memory - * mapping that must be torn down at the end of this mapping's - * lifetime. - */ -struct blkmap_mem { - struct blkmap_slice slice; - void *addr; - bool remapped; -}; - static ulong blkmap_mem_read(struct blkmap *bm, struct blkmap_slice *bms, lbaint_t blknr, lbaint_t blkcnt, void *buffer) { diff --git a/drivers/block/blkmap_helper.c b/drivers/block/blkmap_helper.c index 56cbe57d4aa..c91a4410d9c 100644 --- a/drivers/block/blkmap_helper.c +++ b/drivers/block/blkmap_helper.c @@ -7,8 +7,11 @@ #include #include +#include #include #include +#include +#include int blkmap_create_ramdisk(const char *label, ulong image_addr, ulong image_size, struct udevice **devp) @@ -51,3 +54,45 @@ err: return ret; } + +static int blkmap_add_pmem_node(void *fdt, struct blkmap *bm) +{ + int ret; + u32 size; + ulong addr; + struct blkmap_mem *bmm; + struct blkmap_slice *bms; + struct blk_desc *bd = dev_get_uclass_plat(bm->blk); + + list_for_each_entry(bms, &bm->slices, node) { + bmm = container_of(bms, struct blkmap_mem, slice); + + addr = (ulong)(uintptr_t)bmm->addr; + size = (u32)bms->blkcnt << bd->log2blksz; + + ret = fdt_fixup_pmem_region(fdt, addr, size); + if (ret) + return ret; + } + + return 0; +} + +int blkmap_fdt_pmem_setup(void *fdt) +{ + int ret; + struct udevice *dev; + struct uclass *uc; + struct blkmap *bm; + + uclass_id_foreach_dev(UCLASS_BLKMAP, dev, uc) { + bm = dev_get_plat(dev); + if (bm->type == BLKMAP_MEM) { + ret = blkmap_add_pmem_node(fdt, bm); + if (ret) + return ret; + } + } + + return 0; +} diff --git a/include/blkmap.h b/include/blkmap.h index 21169c30af1..4fe8ec2767c 100644 --- a/include/blkmap.h +++ b/include/blkmap.h @@ -7,6 +7,7 @@ #ifndef _BLKMAP_H #define _BLKMAP_H +#include #include /* Type of blkmap device, Linear or Memory */ @@ -32,6 +33,84 @@ struct blkmap { struct list_head slices; }; +/** + * struct blkmap_slice - Region mapped to a blkmap + * + * Common data for a region mapped to a blkmap, specialized by each + * map type. + * + * @node: List node used to associate this slice with a blkmap + * @blknr: Start block number of the mapping + * @blkcnt: Number of blocks covered by this mapping + */ +struct blkmap_slice { + struct list_head node; + + lbaint_t blknr; + lbaint_t blkcnt; + + /** + * @read: - Read from slice + * + * @read.bm: Blkmap to which this slice belongs + * @read.bms: This slice + * @read.blknr: Start block number to read from + * @read.blkcnt: Number of blocks to read + * @read.buffer: Buffer to store read data to + */ + ulong (*read)(struct blkmap *bm, struct blkmap_slice *bms, + lbaint_t blknr, lbaint_t blkcnt, void *buffer); + + /** + * @write: - Write to slice + * + * @write.bm: Blkmap to which this slice belongs + * @write.bms: This slice + * @write.blknr: Start block number to write to + * @write.blkcnt: Number of blocks to write + * @write.buffer: Data to be written + */ + ulong (*write)(struct blkmap *bm, struct blkmap_slice *bms, + lbaint_t blknr, lbaint_t blkcnt, const void *buffer); + + /** + * @destroy: - Tear down slice + * + * @read.bm: Blkmap to which this slice belongs + * @read.bms: This slice + */ + void (*destroy)(struct blkmap *bm, struct blkmap_slice *bms); +}; + +/** + * struct blkmap_mem - Memory mapping + * + * @slice: Common map data + * @addr: Target memory region of this mapping + * @remapped: True if @addr is backed by a physical to virtual memory + * mapping that must be torn down at the end of this mapping's + * lifetime. + */ +struct blkmap_mem { + struct blkmap_slice slice; + void *addr; + bool remapped; +}; + +/** + * struct blkmap_linear - Linear mapping to other block device + * + * @slice: Common map data + * @blk: Target block device of this mapping + * @blknr: Start block number of the target device + */ +struct blkmap_linear { + struct blkmap_slice slice; + + struct udevice *blk; + lbaint_t blknr; +}; + /** * blkmap_map_linear() - Map region of other block device * @@ -112,4 +191,16 @@ int blkmap_destroy(struct udevice *dev); int blkmap_create_ramdisk(const char *label, ulong image_addr, ulong image_size, struct udevice **devp); +/** + * blkmap_fdt_pmem_setup() - Add pmem nodes to the devicetree + * @fdt: Devicetree to add the pmem nodes to + * + * Iterate through all the blkmap devices, look for BLKMAP_MEM devices, + * and add pmem nodes corresponding to the blkmap slice to the + * devicetree. + * + * Returns: 0 on success, negative error on failure + */ +int blkmap_fdt_pmem_setup(void *fdt); + #endif /* _BLKMAP_H */