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 75D03C433EF for ; Tue, 12 Oct 2021 03:53:40 +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 34B2460F38 for ; Tue, 12 Oct 2021 03:53:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 34B2460F38 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.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 115C18329E; Tue, 12 Oct 2021 05:53:37 +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="I20dib5e"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8CE2A8321C; Tue, 12 Oct 2021 05:53:34 +0200 (CEST) Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (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 553138329E for ; Tue, 12 Oct 2021 05:53:30 +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-pl1-x632.google.com with SMTP id x8so12608028plv.8 for ; Mon, 11 Oct 2021 20:53:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=bXJAgHOZJfYKD5smeOJh96tUEAWMnTg2vnyxwTYpS6E=; b=I20dib5epjmKgsFaEB+Q/qZKxdFCqAI9jK1uttx1rXDNL1yUacf0y0rgrmAVzMwx5S Da7ll/EMnju6O2l0Iix2B5ylccl75bhjYbnFOGumeiYONmGJnQ6an7GeCOerbvYi2OeT xdb2XjHZEOq83IIQYbD3OptC3ZGhhtmDQ7f34ahxcLxNsefO+hRcYMIQrEY89AEtoo38 da75mYmnI4jUof1tEZi4OW7lbKmeNGCyPqvljV2XeVQWI1/Indofk+WoQiMg5ucCFfBv nGz1lvyEobYzrYf84xbROwOE89AzZqhALery0lzGRI3gRaFfNNSvq4xnsgTHHzHIyFmB tw2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=bXJAgHOZJfYKD5smeOJh96tUEAWMnTg2vnyxwTYpS6E=; b=ng+UsJEI+YSG05t5Q6H5iX6N6gMCNSfBhMv1B0I4NIg+ILThJmDS0zLvyeGHFQbXXn HHN/0kLMGmQWf8Am2hWtJTWxxGvfLKpanwUKPh6O+MLE6R0U46/k0VmSqweLa1ychMrH bYZBTLcuukHbJf7PxWIWkkPZzjg9jpNGinWbFxE1ZLRf+gtNHZEzkwa6I250jf/YnKPm jOYXcTTDSRVGUNF6R51LDxkefsqSs/G6TVywrl9KjqsPrJi6EKUDG+Q4YsP5Gih3MLF6 imDi7oVerlQ/VtjUs6fjlvCgkzZGDn7oN41pb7JSV6fXQ/M9zhVmd27LJDyqQ9qdUIcX iaYw== X-Gm-Message-State: AOAM533YmepTMZU6gCf49d4N4sYnT8ixg64ANYlDojCnqwsp8KkrpcJi 3Um3XsP/Hz7cHisI0XFbimJfxg== X-Google-Smtp-Source: ABdhPJxh6FKMWK99dKiyLXD8LP+y4aa0+rNugmG9v4R5LLQT+H8A6gM3CeXbWvKrVKJwUfW1rf7MAg== X-Received: by 2002:a17:90b:4c86:: with SMTP id my6mr3306822pjb.77.1634010808424; Mon, 11 Oct 2021 20:53:28 -0700 (PDT) Received: from laputa ([2400:4050:c3e1:100:dbc:a6fe:8374:7fdb]) by smtp.gmail.com with ESMTPSA id z68sm5817611pgz.90.2021.10.11.20.53.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Oct 2021 20:53:28 -0700 (PDT) Date: Tue, 12 Oct 2021 12:53:23 +0900 From: AKASHI Takahiro To: Simon Glass Cc: Heinrich Schuchardt , Alex Graf , Ilias Apalodimas , U-Boot Mailing List Subject: Re: [RFC 07/22] dm: blk: add UCLASS_PARTITION Message-ID: <20211012035323.GF38222@laputa> Mail-Followup-To: AKASHI Takahiro , Simon Glass , Heinrich Schuchardt , Alex Graf , Ilias Apalodimas , U-Boot Mailing List References: <20211001050228.55183-1-takahiro.akashi@linaro.org> <20211001050228.55183-15-takahiro.akashi@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Simon, On Sun, Oct 10, 2021 at 08:14:34AM -0600, Simon Glass wrote: > 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__ OK. > > + > > + 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 OK. > > + 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: OK. Then put the file under disk/, driver/block or driver/partition? > > + > > +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. OK. > > + */ > > +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. Yes, I intend to do so with pytest once we have some consensus on interfaces. -Takahiro Akashi > Regards, > Simon