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 8CE40C433F5 for ; Mon, 4 Oct 2021 03:28:16 +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 C0EAC61351 for ; Mon, 4 Oct 2021 03:28:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C0EAC61351 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 20CFF834D8; Mon, 4 Oct 2021 05:28:14 +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="E23sGpOm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7B4DE834FD; Mon, 4 Oct 2021 05:28:12 +0200 (CEST) Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) (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 69C5A834C5 for ; Mon, 4 Oct 2021 05:28:08 +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-x1031.google.com with SMTP id g13-20020a17090a3c8d00b00196286963b9so1725908pjc.3 for ; Sun, 03 Oct 2021 20:28:08 -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=qZS8gmmxtO3xS1pRKZooanZRfO/HdsCiwOln5YP6l3Q=; b=E23sGpOmjGOrdAbWNQhwEonDEX+e2NKpedUWYsRCMXJqZ5BTOn+TT9T9Ij4HRjGNB8 l7X1N1z2tEgt2K9GWNSSuE9G1ZnllE1lEBhmBv58bPEuTEdl+pGFQbGXzB/j0CRGB29i 43u6AZ/AATYCkYWSNtrqpKSzVePl9ZPe6iaDHJDxA1PIbcNzOHt2JoO4ueHIkOlQ+nUB 1nAPFGRL6YKzvd1SVW43MCEnKHCqDnxBIs8bwld/dHo/x2j/fQg5RE7xWwHnUtniciZM LCzG0AN4W6ZEY8fe5oBmiMqaYawJG6huCz+vRrNvbNI63sq31k1gzHOIPPzuX2/KHGxL 2stQ== 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=qZS8gmmxtO3xS1pRKZooanZRfO/HdsCiwOln5YP6l3Q=; b=W4UWd0MuyOHPbrKqJvIbGjbUykFDmhm5Cy69q/7EVpCErERiN5RV8IKyKqDy0zGoQh AzAcivxaHAv5ZWizp4/k3Je28Qxgi5W0CjIPphc2+4Bwpf+cInlxFrul2DQhHHPP3hQ1 1rOK0gQvAzL0Gx8BOgY7hV6tsEPNPCcUY6JE3JPBJvC/CaZBdiywAfq6h3ihXH5OtWtp E7XLuub7agOA2i0hwS8Z38OjDOMgBFQjF0fUHSW/ycU00w3IGCJ7FghXn9H0LAuWeQUk UU/Yr2+zpac9YYSyYZ3nhjPtLtPj1T80K3l93C2aLgpuj1CAzK9irYfS3HljN8X1mg+I qiKQ== X-Gm-Message-State: AOAM532cr4OAHopivMLCd2qvY8cLpBXWcZ9TpaJHuAAVIwU5q7NJTr+M Xa7Io0IHmfdvghYN3Yxmw/Uddw== X-Google-Smtp-Source: ABdhPJyW7aJEtPCY2ZWDGHhDe65sdOmhr8/NkmU7K7nn+oHOT692k8OGB9ikmOTixyA3crh6WVyBoA== X-Received: by 2002:a17:90a:1a06:: with SMTP id 6mr35002098pjk.150.1633318086531; Sun, 03 Oct 2021 20:28:06 -0700 (PDT) Received: from laputa (61-205-96-147m5.grp4.mineo.jp. [61.205.96.147]) by smtp.gmail.com with ESMTPSA id q16sm13487150pfk.214.2021.10.03.20.28.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 20:28:06 -0700 (PDT) Date: Mon, 4 Oct 2021 12:27:59 +0900 From: AKASHI Takahiro To: Heinrich Schuchardt Cc: u-boot@lists.denx.de, agraf@csgraf.de, sjg@chromium.org, ilias.apalodimas@linaro.org Subject: Re: [RFC 07/22] dm: blk: add UCLASS_PARTITION Message-ID: <20211004032759.GC39720@laputa> Mail-Followup-To: AKASHI Takahiro , Heinrich Schuchardt , u-boot@lists.denx.de, agraf@csgraf.de, sjg@chromium.org, ilias.apalodimas@linaro.org 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 On Fri, Oct 01, 2021 at 11:30:37AM +0200, Heinrich Schuchardt wrote: > > > On 10/1/21 07:01, 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); > > + > > + 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); > > What device type will the parent have if it is a eMMC hardware partition? > > > + ops = blk_get_ops(parent); > > + if (!ops->read) > > + return -ENOSYS; > > + > > + part = dev_get_uclass_plat(dev); > > You should check that we do not access the block device past the > partition end: Yes, I will fix all of checks. -Takahiro Akashi > struct blk_desc *desc = dev_get_uclass_plat(parent); > if ((start + blkcnt) * desc->blksz < part->gpt_part_info.blksz) > return -EFAULT. > > > + 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; > > here too > > > + > > + 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; > > here too > > Best regards > > Heinrich > > > + > > + 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 */ > >