From patchwork Tue Mar 8 11:36:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 549277 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp2540249mag; Tue, 8 Mar 2022 03:40:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxE48GGu1AYHCQTijvM5c8y8mH6L6QbDqqQTfY4b4vstlHkJO1CWmCoiR/RhnKRUCtoRp2Z X-Received: by 2002:a17:906:3adb:b0:6b7:876c:d11b with SMTP id z27-20020a1709063adb00b006b7876cd11bmr12881272ejd.250.1646739633209; Tue, 08 Mar 2022 03:40:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646739633; cv=none; d=google.com; s=arc-20160816; b=QzF3qUtNcIumAZHwzi80ntKxYCk0bgWvNDBOpANqrW5ky7zGI2tdz8ijFy8EXi1FrT p6ziI12bV9tjmRVpZpmtsgFqJzgfN7rRtKHAs5kUmWvlltGJRBuj3736EU2GUKlPfkUD mU0i1E31MT92yRzrz6iJn6OsB3B9mz73Wjwp5m2gmWPjwQp0DYj+nYtsg9Xh6tPaU20l 1d6DbzjvijGlf1zJClY7Cm6Gnyp6/k16QCPQWERXTi7qsHAYtOvZ5WacUoXFlIr8wDb+ I32UTMMEv18MUOd4lHAtEfPoY/e4d27lpOQtefE6bPHGi8ZACYV4p6j9+5cPD/VonAy/ WI1w== 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=jOd231FtqlYhW0H9SCH9Peko72xgDMiZL/3jps6yxaU=; b=ih89DWyhpAYwfS9enk6P0NYSn99j3ntFrm2Jny8ZjEE/JheCAZg5NkAylgZQG2NojE 4JZkcuJN1urIFrHjR6y+rmJS0LtoWTQMDSJSQHlgV6LxCEFfpWF071ZCBuhHoRu3lVWz ZB9y3joiEBkU3ucWIIi7CMEvtIR9UlzHy6MySt04zm8mYtr3UW95GiQamZCrUx8nqFWH Ohh8vyDXL/9EasndwCYbrlMuhbdP9cx1s4IeciQSClrFrasX5IHprd8vKrhsXLC2YXXM JSAD/ID+hQG+WK5B59DzHWRMH8kLAqRv0xwQxBg+ap4+kCayT0vdKpfZCaqZsAgXIU68 d2zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YQXTX6Df; 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 ji3-20020a170907980300b006d8121d0fc6si10371750ejc.457.2022.03.08.03.40.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 03:40:33 -0800 (PST) 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=YQXTX6Df; 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 E1766839B1; Tue, 8 Mar 2022 12:40:26 +0100 (CET) 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="YQXTX6Df"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 63D0C8312A; Tue, 8 Mar 2022 12:39:54 +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=-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=unavailable autolearn_force=no version=3.4.2 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) (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 6FB4A83933 for ; Tue, 8 Mar 2022 12:38:22 +0100 (CET) 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-pg1-x529.google.com with SMTP id bc27so16217188pgb.4 for ; Tue, 08 Mar 2022 03:38:22 -0800 (PST) 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=jOd231FtqlYhW0H9SCH9Peko72xgDMiZL/3jps6yxaU=; b=YQXTX6Df7DIyg8AEhSHK8e8gFai5aNLY+rvIME6qtUwpMIYFjYaCsN1wqOBFPhkL9R 1W2rofqNhLbhiWnPqLlIYfEY/uEphYhDrvvmDSE6grGVK+FjsTLfTLf3+gcF5sPzwHAJ 92N/H4Q2Uyk7rpIMVK4QxBNY6CZ9pDYkiGSLIAIHvfGs3XfTc2kUgXxAQZXeieWBaL0X BEYYMlewjUphnaWKgDJv7BHUX6WnfV8BQDg2MoKjP34JMokB8AeaKDX5NOyuRkX89YiA tGRngB1xEXz/+sCOMzVDjnsKT6v/rt0XRJh2JmWYPHhnAR3YRtgwdF2ASAEZac9GzoIk DhnA== 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=jOd231FtqlYhW0H9SCH9Peko72xgDMiZL/3jps6yxaU=; b=6h3d/FagglLINlpvFSUjKObwyofnrlTRAnKHiBAc58seVeyochPu0GdnydZMbSRDWv /YecOZWjO4dJ9XX6PyZY2WfMn0ZlN9IC5VfaCidc+q3dUMhowSnAfNItlQJqnrMWAPMS UpdxM5/sRhK1opVDPgMwgZe41k5W20iuhRg/8BJgGPl6oiR/AZ9KMHe1c6lyTTzsyYWk 4sOSgJk8bYPJhuEJXa2FZpqJgbGhOQTHC71H5VZ+j1uNgCEAMtLcd45n7HNRmawzeZsj Z1H/nziLEX4hz21arYKFgVuEAwZHf5v5N7cPeicEycO0Rcmag3/vgiDoD74xeawqGQyP dDHg== X-Gm-Message-State: AOAM531COy6nFGkMvPDdOIocD05B2nQ9pqgm+0g6lk/HpsJh8KYUh/W9 +DxGew0PpjhAtQVHOYI9jZwc0A== X-Received: by 2002:a63:6c44:0:b0:37c:8874:c335 with SMTP id h65-20020a636c44000000b0037c8874c335mr13579179pgc.420.1646739500824; Tue, 08 Mar 2022 03:38:20 -0800 (PST) Received: from localhost.localdomain ([2400:4050:c3e1:100:b94a:f47a:3d51:185c]) by smtp.gmail.com with ESMTPSA id z2-20020a17090a170200b001bf2d530d64sm3434677pjd.2.2022.03.08.03.38.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 03:38:20 -0800 (PST) From: AKASHI Takahiro To: lukma@denx.de, peng.fan@nxp.com, jh80.chung@samsung.com, bmeng.cn@gmail.com, sr@denx.de, xypron.glpk@gmx.de, sjg@chromium.org, ilias.apalodimas@linaro.org Cc: masami.hiramatsu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v3 11/19] dm: disk: add UCLASS_PARTITION Date: Tue, 8 Mar 2022 20:36:49 +0900 Message-Id: <20220308113657.221101-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220308113657.221101-1-takahiro.akashi@linaro.org> References: <20220308113657.221101-1-takahiro.akashi@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.5 at phobos.denx.de X-Virus-Status: Clean With this new function, UCLASS_PARTITION devices will be created as child nodes of UCLASS_BLK device. Signed-off-by: AKASHI Takahiro --- disk/Makefile | 3 + disk/disk-uclass.c | 153 +++++++++++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/part.h | 11 +++ 4 files changed, 168 insertions(+) create mode 100644 disk/disk-uclass.c diff --git a/disk/Makefile b/disk/Makefile index 6ce5a687b36c..ec37b74f5f40 100644 --- a/disk/Makefile +++ b/disk/Makefile @@ -6,6 +6,9 @@ #ccflags-y += -DET_DEBUG -DDEBUG obj-$(CONFIG_PARTITIONS) += part.o +ifdef CONFIG_$(SPL_)BLK +obj-$(CONFIG_PARTITIONS) += disk-uclass.o +endif obj-$(CONFIG_$(SPL_)MAC_PARTITION) += part_mac.o obj-$(CONFIG_$(SPL_)DOS_PARTITION) += part_dos.o obj-$(CONFIG_$(SPL_)ISO_PARTITION) += part_iso.o diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c new file mode 100644 index 000000000000..4918a2f72d1e --- /dev/null +++ b/disk/disk-uclass.c @@ -0,0 +1,153 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Software partition device (UCLASS_PARTITION) + * + * Copyright (c) 2021 Linaro Limited + * Author: AKASHI Takahiro + */ + +#define LOG_CATEGORY UCLASS_PARTITION + +#include +#include +#include +#include +#include +#include +#include + +int part_create_block_devices(struct udevice *blk_dev) +{ + int part, count; + struct blk_desc *desc = dev_get_uclass_plat(blk_dev); + struct disk_partition info; + struct disk_part *part_data; + char devname[32]; + struct udevice *dev; + int ret; + + if (!CONFIG_IS_ENABLED(PARTITIONS) || + !CONFIG_IS_ENABLED(HAVE_BLOCK_DEVICE)) + return 0; + + if (device_get_uclass_id(blk_dev) != UCLASS_BLK) + return 0; + + /* Add devices for each partition */ + for (count = 0, part = 1; part <= MAX_SEARCH_PARTITIONS; part++) { + if (part_get_info(desc, part, &info)) + continue; + snprintf(devname, sizeof(devname), "%s:%d", blk_dev->name, + part); + + ret = device_bind_driver(blk_dev, "blk_partition", + strdup(devname), &dev); + if (ret) + return ret; + + part_data = dev_get_uclass_plat(dev); + part_data->partnum = part; + part_data->gpt_part_info = info; + count++; + + ret = device_probe(dev); + if (ret) { + debug("Can't probe\n"); + count--; + device_unbind(dev); + + continue; + } + } + debug("%s: %d partitions found in %s\n", __func__, count, + blk_dev->name); + + return 0; +} + +static ulong blk_part_read(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt, void *buffer) +{ + struct udevice *parent; + struct disk_part *part; + const struct blk_ops *ops; + + parent = dev_get_parent(dev); + ops = blk_get_ops(parent); + if (!ops->read) + return -ENOSYS; + + part = dev_get_uclass_plat(dev); + if (start >= part->gpt_part_info.size) + return 0; + + if ((start + blkcnt) > part->gpt_part_info.size) + blkcnt = part->gpt_part_info.size - start; + start += part->gpt_part_info.start; + + return ops->read(parent, start, blkcnt, buffer); +} + +static ulong blk_part_write(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt, const void *buffer) +{ + struct udevice *parent; + struct disk_part *part; + const struct blk_ops *ops; + + parent = dev_get_parent(dev); + ops = blk_get_ops(parent); + if (!ops->write) + return -ENOSYS; + + part = dev_get_uclass_plat(dev); + if (start >= part->gpt_part_info.size) + return 0; + + if ((start + blkcnt) > part->gpt_part_info.size) + blkcnt = part->gpt_part_info.size - start; + start += part->gpt_part_info.start; + + return ops->write(parent, start, blkcnt, buffer); +} + +static ulong blk_part_erase(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt) +{ + struct udevice *parent; + struct disk_part *part; + const struct blk_ops *ops; + + parent = dev_get_parent(dev); + ops = blk_get_ops(parent); + if (!ops->erase) + return -ENOSYS; + + part = dev_get_uclass_plat(dev); + if (start >= part->gpt_part_info.size) + return 0; + + if ((start + blkcnt) > part->gpt_part_info.size) + blkcnt = part->gpt_part_info.size - start; + start += part->gpt_part_info.start; + + return ops->erase(parent, start, blkcnt); +} + +static const struct blk_ops blk_part_ops = { + .read = blk_part_read, + .write = blk_part_write, + .erase = blk_part_erase, +}; + +U_BOOT_DRIVER(blk_partition) = { + .name = "blk_partition", + .id = UCLASS_PARTITION, + .ops = &blk_part_ops, +}; + +UCLASS_DRIVER(partition) = { + .id = UCLASS_PARTITION, + .per_device_plat_auto = sizeof(struct disk_part), + .name = "partition", +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 0e26e1d13824..230b1ea528cf 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -83,6 +83,7 @@ enum uclass_id { UCLASS_P2SB, /* (x86) Primary-to-Sideband Bus */ UCLASS_PANEL, /* Display panel, such as an LCD */ UCLASS_PANEL_BACKLIGHT, /* Backlight controller for panel */ + UCLASS_PARTITION, /* Logical disk partition device */ UCLASS_PCH, /* x86 platform controller hub */ UCLASS_PCI, /* PCI bus */ UCLASS_PCI_EP, /* PCI endpoint device */ diff --git a/include/part.h b/include/part.h index 53cfbdd87671..95e30e60af10 100644 --- a/include/part.h +++ b/include/part.h @@ -253,6 +253,17 @@ void part_set_generic_name(const struct blk_desc *dev_desc, int part_num, char *name); extern const struct block_drvr block_drvr[]; + +struct udevice; +/** + * part_create_block_devices - Create block devices for disk partitions + * + * Create UCLASS_PARTITION udevices for each of disk partitions in @parent + * + * @blk_dev: Whole disk device + */ +int part_create_block_devices(struct udevice *blk_dev); + #else static inline struct blk_desc *blk_get_dev(const char *ifname, int dev) { return NULL; }