From patchwork Fri Oct 1 05:01:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 514992 Delivered-To: patch@linaro.org Received: by 2002:a02:606e:0:0:0:0:0 with SMTP id d46csp452274jaf; Thu, 30 Sep 2021 22:05:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+pc8M6u17uGpQhwZUs7/Nds62m6r78zWQKsH64kw/ryxBseX4O9HMNxaa0tl6QG0xk5GS X-Received: by 2002:a05:6402:5186:: with SMTP id q6mr12416231edd.64.1633064752771; Thu, 30 Sep 2021 22:05:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633064752; cv=none; d=google.com; s=arc-20160816; b=KdVbAiKVeBcv3KF3ZHfiaec80cICOGgUCf4YQEbybWMb4CgbXtsLWtEeR23Dt+sBJU jAeFqT1mrb4Bi2Xf5I2T+u4aqOR77brYLmDFbmKHMyI3CqifFd0lXGFqizhzaDOcfesb 8LA7DQPvi26s1bgGK/AGIuoh9NwE2JJIJyeGd+h/F7A+sKYPpz49uEij/dHBpybdPD5y gCUl16c1+Co0litBzp9/WkpCW58giPWOaC1jCqCX5y5nBpXIl//oVSd33pB/BfXPX+h0 xt0yThlnz/Gc0LK1h6WWjCBNA+yw3x288DIiij5G2lsBgfVFfmlJ1jBxsFZBbTUFIFW1 xKtQ== 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=M1QmaGPB1jY3ktE9zUcnB3ZhDSExNMLt8nEg2Elk+W5nKJ6F2YKONWUngwt3TBNmsk 32ShO5/P8AjCbIv0z7v5K80MIy8YhrG9NqdnPcDhcH4Hu1HO5hQ/LHrZkLKE87Ed1g4M trFLuR0+qPuvyqMFEjqDmZJusm2gtPGy7HJQh9LG0dQ2fpUonzUBuJWj3RjRxJYV446x LubgjBPzy+KxXdb9wLlv4trVeY9T+u8zxCWJ4cZOQANp79fSxRQRggH8NYfk+bSg3UYT o//YlW6eiiRozqWUP7VuRboHlKVgidFuAP9bD7aaruaMGSIgbJ5c1ZdLASqEYL0aWFr2 PZyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hKpb2ZfT; 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 18si5454903ejj.476.2021.09.30.22.05.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 22:05:52 -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=hKpb2ZfT; 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 1124F831B0; Fri, 1 Oct 2021 07:04:03 +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="hKpb2ZfT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C79E482EBD; Fri, 1 Oct 2021 07:03:45 +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-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) (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 63B9D8314C for ; Fri, 1 Oct 2021 07:03:39 +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-pg1-x52e.google.com with SMTP id k24so8357030pgh.8 for ; Thu, 30 Sep 2021 22:03:39 -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=hKpb2ZfTGylTNCfzW29vonqKEdvHjQ1nhfyGvWI0SFt1LJwu97Y6W4kQbjLmOjGxxD DMdydq87nBZ7MX+zJm0twMRaqdJ9I4ZzVQZYhICc7bi0FN/Bxv9fvVUKaM0UaIHi32J5 vg8GpFn7uuwtZ9nHN3TdnuDihD8Z89drFRHfXeFe1qrQtQtMjnj6PNCsKkXtZFnXWeov q4b7sLjzsUd8wixwRUP/aOzUm2wHmEkzEJlE6Q849vCRSEv6n+Y/ILXcNEYLn3PZRh72 mPZ8l4jbzUIHMMBxrgePhmJBXcYUDeslfR9MDWGSx4PfesibKNHjGKuLllzTJiWccXKt AXrg== 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=VdFXjGHhBe3zy8ftXSfwzEwVPfyx8sduPKfDAGG6MfHsvPvhkICcO3iPvog9WhuQbm db1RqG1PAmjnBzA5AslqzZLxopXBr3dCcpbjpPB6YYj9OKqtmQOBLEgI/A2xiWxaTRdN bJThfGKglXO8w6LRgHqg0MOzeGa8yi5qfy5HdYaWahc0qAA0sMWaByRya5T87MlQK9tq wYGY6vWboQHOWccyLjqW2o2wGLQWgfgiE1e/gybXt5YjUn+I1/7p5VbI8d3hRmA432dX 6lbGLU7CKv8SDvbJeYPUChho2yb1qEiXZzi27FfjDRyIrnTaIyPdPl2kb2v2Di8q5EYs xOrg== X-Gm-Message-State: AOAM530zRbzXwYeBdo/x46hJ6Ken89PxwqsGvDOywX8qjWPrNs3RBM5Q Y7EeYTjAMxR6CDfjiLABtUQACQ== X-Received: by 2002:a65:564e:: with SMTP id m14mr8237408pgs.113.1633064617616; Thu, 30 Sep 2021 22:03:37 -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.03.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 22:03:37 -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 08/22] dm: blk: add UCLASS_PARTITION Date: Fri, 1 Oct 2021 14:01:59 +0900 Message-Id: <20211001050228.55183-16-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 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 */