From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB8B6C433EF for ; Sun, 10 Oct 2021 14:17:55 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6BA276058D for ; Sun, 10 Oct 2021 14:17:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6BA276058D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4C260836FE; Sun, 10 Oct 2021 16:16:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="egv8/fOI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6D0ED836C0; Sun, 10 Oct 2021 16:15:10 +0200 (CEST) Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) (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 1E755836B1 for ; Sun, 10 Oct 2021 16:14:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@google.com Received: by mail-ot1-x331.google.com with SMTP id r43-20020a05683044ab00b0054716b40005so18181679otv.4 for ; Sun, 10 Oct 2021 07:14:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ScA7fTiJvaZUhrJayC32AZoV5/7LHBXHVKbSfRaXjAk=; b=egv8/fOIk9QcKNAPRTx5O3LhX7yNt2s456qIo6v8f5a02jp2O8cFkw28AZnm8fPQEn CV50kbTRVlOaTFhVpR6AcD4hUjNtUVBfO3/WF6RlRhcgshuMHcMg0lunMWVgWcLhpIdq PPWt8iLetXfjJVDzOYXeWgGP6UZniEJfdb/UE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ScA7fTiJvaZUhrJayC32AZoV5/7LHBXHVKbSfRaXjAk=; b=wL6F1qhWVrD8ie7grgQVyLWB/IcC4g1Iuo8De7peLny9ghVADUTapyFdj0AdHDQA/F Vg+nHN8XlBCLlP0goywBYFMofgT5X8OO0t2Rd5euRWFfuCB/Ml7MNuz1HEIernb0I3NU nr3kNUhgevkzgiDMvkcIpVbK0gaQpWcEwqiETTHTItGHTefcEa43yMr6UZK4nLd4HkNP f15Jf11y9bCqBc74JcCqQJuD7YOdKEgAK/wcjlTcKIcQxNNKRJaqq7L1kVZ3/vXHjxjL 8NsmLPTxxMku6l7LZjg8CJb4G5IRyKrrkr9EuqYcVGo2pxXJw0WLxIY31ZDc8bukUPcJ Vlmw== X-Gm-Message-State: AOAM531jzF0qzrLrhrlnH2tAYJvgYTQLiyyVXBPwKhe5bI5nUfakz5Fo U9bO/7klMRD40vEHRpakUqCILZZZDzrMuEDKtaPskA== X-Google-Smtp-Source: ABdhPJyRSDX5WMys6+3/9uOlKqXDeyKVnGk3qQcjLR1gHv/0oe8ACI3DzHsYBbscf5ttoxzfxPsQR+bq1tXQ+pwWPeY= X-Received: by 2002:a05:6830:3093:: with SMTP id f19mr3862798ots.97.1633875286486; Sun, 10 Oct 2021 07:14:46 -0700 (PDT) MIME-Version: 1.0 References: <20211001050228.55183-1-takahiro.akashi@linaro.org> <20211001050228.55183-15-takahiro.akashi@linaro.org> In-Reply-To: <20211001050228.55183-15-takahiro.akashi@linaro.org> From: Simon Glass Date: Sun, 10 Oct 2021 08:14:34 -0600 Message-ID: Subject: Re: [RFC 07/22] dm: blk: add UCLASS_PARTITION To: AKASHI Takahiro Cc: Heinrich Schuchardt , Alex Graf , Ilias Apalodimas , U-Boot Mailing List Content-Type: text/plain; charset="UTF-8" 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 Hi Takahiro, On Thu, 30 Sept 2021 at 23:03, AKASHI Takahiro wrote: > > 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(+) > > 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); log_debug() and drop __func__ > + > + 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) > +{ part_blk_read() so that it is clear that this takes a UCLASS_PARTITION device, not a UCLASS_BLK > + 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, > +}; Can you put this all in a separate part-uclass.c file? This too: > + > +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 UCLASS_BLK? It is good to document the device types to avoid people getting confused later. > + */ > +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 */ > -- > 2.33.0 > This is a new uclass so needs a sandbox test. Regards, Simon