From patchwork Fri Oct 1 05:01:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 514991 Delivered-To: patch@linaro.org Received: by 2002:a02:606e:0:0:0:0:0 with SMTP id d46csp452163jaf; Thu, 30 Sep 2021 22:05:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYLAqXriiiy7J9KYcaAH1j4hCl0OPSs9y6/cKrfoUmAKGTM3n7vrSGCE9L7tCLeeP1xhSn X-Received: by 2002:a17:906:51d3:: with SMTP id v19mr3216804ejk.148.1633064740844; Thu, 30 Sep 2021 22:05:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633064740; cv=none; d=google.com; s=arc-20160816; b=F+1yi9ilj24Tu2aX9IOfXwH0Cfd7gY9kVhmSpKhzqzEDxRwFVZOVM6M2xpFv6YDHRe IPAC8lzzTmFMbwutCCcDx7/G+U+Qq7grQsAc2ZTgI6latBFO3StduzIYk0v/lIgYEcES HL6ESN3TJ8xFj7JAUe8Maf1kcY9Y+1btw5+kQJGZWgkwivYeakvHQpiKDosJZhpNWq/7 Qwn9keL7hJ6IJwpT819VoqblTjvfiesjGNe2+F8MZwVcw1hSbA+U4QVZ99U8BQIGFbZ1 PKh+g88DsPmCECFkgjgF0vIaLlde9TVcIgHW5+P7qnuAZvuRbIQVm3ywcLBeUV0FoNR5 jWVQ== 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=IsvbNWBf3Cb1fB7NRQj3IvV0CWErt7caDSgfP0x/ZcWDmRk0n2hlZ0C8w5/65LYKnB Y+Cx1AzBDVsAI7ejvLmL9TUoMg9nnEQfET1x7y+vmwwMyb5DK3JSNNyD6B2Fmluz10gg SF0Vh+X6wGutWcNHlRiR6Js1170fshCQR0X3DkpBwPEfcUrpHCZ917dwVdgFWLhOtOTB fv3h5Fv0SvFUPRdkhThSs+HMJwH/4wcLEYBfKgXN7yVqs0GX1lgYyVeDtkS3QgrqAAfh FQbXrhvoK8f5fTBy53ZUubrGfDsldBQ09omjKw3jCGzOjwFhCYlMSI2e9lH7X6He5eBF OnrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BX1V9m6E; 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 f4si6086827ejl.218.2021.09.30.22.05.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 22:05:40 -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=BX1V9m6E; 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 5586F832C6; Fri, 1 Oct 2021 07:03:58 +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="BX1V9m6E"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D464483169; Fri, 1 Oct 2021 07:03:40 +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-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) (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 A4B7282127 for ; Fri, 1 Oct 2021 07:03:35 +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-pf1-x433.google.com with SMTP id 187so2478673pfc.10 for ; Thu, 30 Sep 2021 22:03:35 -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=BX1V9m6EThuRJxopTusQdc+ohdHqb2gbm3G3VxQ2ndq5HwSRlaTlBnH4RUcrRQZ8Kr Y/uQHEcaNUIBNHE/PfUOJsejg0y2eCkLUuxs+bBmLqR5pHo4NuwccVfEl7y3Mc2RAVq9 fzU8qANj1ZHzRsY/MS2DQclT07hkVlDkPnITzyXTKJB7Hn0VF+Geky+3lHvPZsJKq3jT trvJxSO+Bdjdb38rTkAG6y4hnFe2BLbtuxTUmB0ujS/oAO8plHPSkm3Py1dE6Bk7Db0z Y4UnPb8sEFMU09iGO0CO98oWFneECxsOtenkhPBWcW8pMOBp7yVazmyWpnKq07L79Yln Nz2w== 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=VknK5GPT9PQOv1alYtBByRHk2/sRx+pTusF9mm7suKFTo9xRjwxJ3naNT6VOmXL9GB nva0xLw64f2lHhNT5K3Cp1SBi4vvucAiiFJLrR3NagLV6BU6AYi4zrk+UIsdQf2NqTCA 7TJsgLeqXvNt2EjFZM6+uu8jrDEqkWytCJdirZzfP2IH9ZQZO4JbURrrrTqbALgF+d9D eV1+kqDlOb/S8+GptK42v2lxTdzblBP8LyhbaFP5YsNY2CmDOQQc0TenVrg+QdT0phbP iNLObfBVFMYU2R6qbrvWrst0GKVQig+4Cj+zyBzXsQ7CBr1hDfUUwxwc3/y3y2vIN6sF 8F5g== X-Gm-Message-State: AOAM530amS3gpTz9eXK78k8Ayx9hZ0rbFAo2tO2upVlI6QERNHujvCTO JPMTtRvB/Jv3ltTyE+rQ2xJ/9550mgfPLw== X-Received: by 2002:a63:8f06:: with SMTP id n6mr8219825pgd.315.1633064613833; Thu, 30 Sep 2021 22:03:33 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 22:03:33 -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 07/22] dm: blk: add UCLASS_PARTITION Date: Fri, 1 Oct 2021 14:01:58 +0900 Message-Id: <20211001050228.55183-15-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 */