From patchwork Mon Oct 4 03:44:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 515136 Delivered-To: patch@linaro.org Received: by 2002:ac0:890a:0:0:0:0:0 with SMTP id 10csp1062194imy; Sun, 3 Oct 2021 20:46:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQzRpzfeYfdDUQqil7KR7vpMj4tHm4YAw5l0MG95CKrYiSrHrqml6J/HzJzg3U0zThu7hN X-Received: by 2002:a17:906:713:: with SMTP id y19mr14702619ejb.506.1633319197317; Sun, 03 Oct 2021 20:46:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633319197; cv=none; d=google.com; s=arc-20160816; b=PpgUDufCUUWPTPzLijS/EjDKHDfMyeV8t0oiH8R6KBkHQOiYMBfxKcHOP71d7rOvat aiga4WuQnQDiapQ4g2TszRdyFaecy+seT8wt0M/GHkDklVH6cggAD3HCaGPxh6XbaM3l 1eQli5BeP+z8JYDXXnLNU6OciHRYS5w1c2/Bcsc3LuLoTFGPjtoaTtsSIVOaLHi652Pz drGf22ZYoHq3hEfZSYYP7PD6BNv1Db3nDLOhmNUFj7Q+Z4hfRGYA5e7kBAiNYGhcRyoI Jw9Q+M7naoMokKJ0q6pleTEqvB4N6r5+35FHILPHsS4AdmwbS5wo7WP2g7QZ6GH15qL0 ZXiw== 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=xNd/2bFfKjwaY5xV+8Y8nucr8xmVq9A0zVABHGaXLyA=; b=NSHdhC2NKOvM7AHD9jnT2pcn7/7ZrD/X9O+MOK2kw/NNBvdAZJp8M1Z7+15XLThDSv EpNMWgfzxFNDfsPcSw5CczfhAXYxZiXUo8slX6IZOM/n0y/Rbjbs3D7eWKkU2WsW6Hy/ 2FsBB2qg7KP+JQz44sjmW7oSzGerGApHjgC9K6ro3W/0O3UoxLtFmxuL3Ui6t6sELWkv hhvbr4mPn25XvQ4+6YG9YvaqdFxdWH40Jah9eroVo+YXyJk+nxNhmOSahmRfY+PlmihI Wcb3h5K34ag8U1I9UvQ8S6k5X7NvGDGuWfBgGVXKpBrsA10MjCo8u5L10jI8XIH4j9CF gCzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PkFO9oip; 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=pass (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 d10si17101331edn.269.2021.10.03.20.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 20:46:37 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.s=google header.b=PkFO9oip; 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=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 C021383586; Mon, 4 Oct 2021 05:46: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="PkFO9oip"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F33B483577; Mon, 4 Oct 2021 05:45:51 +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-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) (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 C23C58356D for ; Mon, 4 Oct 2021 05:45:40 +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-pj1-x102a.google.com with SMTP id np13so574571pjb.4 for ; Sun, 03 Oct 2021 20:45:40 -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=xNd/2bFfKjwaY5xV+8Y8nucr8xmVq9A0zVABHGaXLyA=; b=PkFO9oip2AwhRyMTl5KsAZL2BvIPVGvDZnKd5V7JyFwcX74WgNqOFUYpw3Xy7oZhRW Wy/WTdQNmi7P3+JbKXoNr0+vipEhXk8JdalsNvRsWrZtDLMd34rh9CyHHCCaWCU6u7DD HZOHKys3+xP5NQbvg5NS9qAOrtetnpeBZuJbRUPBxMJYsb9J4UkUmlV+seFHwC6mD9dK tZD95PmmPjURQCE0WbM60pRQvEXndU98C9TOv1AREUjFDKNjqaf+jjuzgIwqxwhMS1Ly 8/gsSOpqBf1zkbO9GISNQPgrpwnVd4Kn0TXXsO7Be1GeABCu3xAP45uLgckUr4MozwIB dhsg== 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=xNd/2bFfKjwaY5xV+8Y8nucr8xmVq9A0zVABHGaXLyA=; b=TdfrKv82eKCL9sQV/tjJNoGigqMKU5+Iv1grYK2Q2h5Gm9+gsC5LoRlYfMuyemIhqE aiEKRY5T0SV9mbAJk4Ucq23kueMorE1xLg5S8fKa3rU7K81W3i1Q2FFbCUQde52XBLoa OuxBcqqu20o0d1w4uUyCGGJhP9tg6f/mkmnb/l/lcLyrcZpjo9zsxHNjpda3kOqMlFnO 0HJ1TXLwvXmnpc5qGzasCi0B7lZYI+qdQyvfH/BfwQY6nW1Hatk7EaludsJqhdilOERb qoI1gJa3/2aOg0B1xnE2QcV+4U4kJZT3kU7EenvpmdCcPIp5zMyeqJFAOkkEV/kyiKa0 j1sg== X-Gm-Message-State: AOAM531uKTCak7LoZ3kd6jOVc0EmrupX8OxIPP5nwELGGTOWklhpWQD3 0gJAgjgIDZs5f+XHDosHalc9zw== X-Received: by 2002:a17:90b:14cd:: with SMTP id jz13mr15759605pjb.192.1633319139073; Sun, 03 Oct 2021 20:45:39 -0700 (PDT) Received: from localhost.localdomain (61-205-96-147m5.grp4.mineo.jp. [61.205.96.147]) by smtp.gmail.com with ESMTPSA id a11sm11863515pgj.75.2021.10.03.20.45.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 20:45:38 -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: [resent RFC 08/22] dm: blk: add UCLASS_PARTITION Date: Mon, 4 Oct 2021 12:44:16 +0900 Message-Id: <20211004034430.41355-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004034430.41355-1-takahiro.akashi@linaro.org> References: <20211004034430.41355-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 UCLASS_PARTITION device will be created as a child node of UCLASS_BLK device. Signed-off-by: AKASHI Takahiro --- drivers/block/blk-uclass.c | 111 +++++++++++++++++++++++++++++++++++++ include/blk.h | 9 +++ include/dm/uclass-id.h | 1 + 3 files changed, 121 insertions(+) -- 2.33.0 diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c index 83682dcc181a..dd7f3c0fe31e 100644 --- a/drivers/block/blk-uclass.c +++ b/drivers/block/blk-uclass.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -695,6 +696,44 @@ int blk_unbind_all(int if_type) return 0; } +int blk_create_partitions(struct udevice *parent) +{ + int part, count; + struct blk_desc *desc = dev_get_uclass_plat(parent); + 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; + + /* 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", parent->name, + part); + + ret = device_bind_driver(parent, "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++; + + device_probe(dev); + } + debug("%s: %d partitions found in %s\n", __func__, count, parent->name); + + return 0; +} + static int blk_post_probe(struct udevice *dev) { if (IS_ENABLED(CONFIG_PARTITIONS) && @@ -713,3 +752,75 @@ UCLASS_DRIVER(blk) = { .post_probe = blk_post_probe, .per_device_plat_auto = sizeof(struct blk_desc), }; + +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); + 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); + 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); + 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/blk.h b/include/blk.h index 19bab081c2cd..3d883eb1db64 100644 --- a/include/blk.h +++ b/include/blk.h @@ -366,6 +366,15 @@ int blk_create_devicef(struct udevice *parent, const char *drv_name, const char *name, int if_type, int devnum, int blksz, lbaint_t lba, struct udevice **devp); +/** + * blk_create_partitions - Create block devices for disk partitions + * + * Create UCLASS_PARTITION udevices for each of disk partitions in @parent + * + * @parent: Whole disk device + */ +int blk_create_partitions(struct udevice *parent); + /** * blk_unbind_all() - Unbind all device of the given interface type * diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index e7edd409f307..30892d01ce13 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -80,6 +80,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 */