From patchwork Mon Oct 4 03:44:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 515138 Delivered-To: patch@linaro.org Received: by 2002:ac0:890a:0:0:0:0:0 with SMTP id 10csp1062317imy; Sun, 3 Oct 2021 20:46:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlXxcgqNvwwfY5VSF+2Nkvp11BHFo2XI2bW2+MpeiW+ZIW7tpBtHS4EQnRO900fNGi8J7k X-Received: by 2002:a17:906:51d3:: with SMTP id v19mr14563088ejk.148.1633319219590; Sun, 03 Oct 2021 20:46:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633319219; cv=none; d=google.com; s=arc-20160816; b=FSF0zXKULmHYGV48BHWCLd7uy7MciXMrMoHWYGu8+1XoYVifwQKPEJrmj8wsV0G+VS +rYXAe8jgKhLyAoM0+LFeYl/EKnirvfw9XLpk/XGLajkw1ZrdNyOeGGtb4+ge0l+hUrW 7wMmSptuBuZRSRSy15Rl5WTAJsTI7cq3vLReYwYJ12GEswAbdX7EpR+P9ZNu4tXMoWR3 Pq/01HwOmk9GHMVhCYG87ZwiGw7/10lY3BJBL+erQgrXGUxXTg5y+VIol8TEdgK8nZV1 6VfrPBV87IRYdSbGYzZXhgX3dPU130WizJ97R/ecE6h0mQk39QfzOJcIQ8KBkDuvi4Nu 1CMQ== 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=UhrBaUxpdF9KOEH0VMrJEPB6fFwCE5yYYSjjBkt4tmM=; b=aVhfryM9K8J95YbRsqZoSJ44igitEyGpgTnwLdGI9ZHbpk6lZSqMjpBkE6ixKN9fui ryzgXuJd9fUCT7AENiWrRu5H4TfKGfNg4gITCMtzj37mA7azNYCGjMGCDPZ5LSPk+vMa H5mOjOwfXhtOADDmGCEc6hnYmJPgFIdb9L3JTVwo+h9TW4J+Mjl1NxcWcZbRWdSZQ++A 0ITZtSlWy/o1XYB+maN3eDoywUPH43SPOKhgio0ccPzy0fKyEGK86w35VX9Coc5/QS1n cR1BkeZyEJNXxepRp1xXg4b3P/EdSyNc8w+mDFQ2AZC7R+Y+1yAIFIGV9GVGppKmongA BbwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=INJ7wfXw; 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 y15si17447906edj.517.2021.10.03.20.46.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 20:46:59 -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=INJ7wfXw; 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 8CA768357D; Mon, 4 Oct 2021 05:46:15 +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="INJ7wfXw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B0C1F83568; Mon, 4 Oct 2021 05:46:00 +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-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) (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 BB4DC83569 for ; Mon, 4 Oct 2021 05:45:50 +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-x52c.google.com with SMTP id h3so4612618pgb.7 for ; Sun, 03 Oct 2021 20:45:50 -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=UhrBaUxpdF9KOEH0VMrJEPB6fFwCE5yYYSjjBkt4tmM=; b=INJ7wfXwTnSPPfay7CV4vJhh4MksEtvnXZPjTqF50NbrvZGp3ELaLyNCosfXmBkGQu QWg12HlRiYY/JVBM34tdShFUS9MGhLiDy++30Jaf3f8ucfKxKOHKtz45TOCjxNwLaWiv oDEd5RUcNYOs2+WN5bynxUoWjKyXN4ZR38w8RqDZ6aXevu3xQ271eqVFgU+sgZUPiSeP ui/y235XaBlGN2n3XrNbmiEAC0UNlFfpo7z2t4tUdaEGsRYdy4JPAv2utAzfCHc1j82J lfcKlzGir9hUUtQG8hgt5J2aB7ETJIkXFHOFd128JRlv9Z62afTzUQRc48ULbE31N+NE Hfbw== 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=UhrBaUxpdF9KOEH0VMrJEPB6fFwCE5yYYSjjBkt4tmM=; b=ZnfK0/0gtCt7CWwbT5gngNGifpYXZ2hbveOZ3mJW0dKH3ad3SEOEQmVmzASZxVkDKW qJ8PMqJw8BJuR6YMqG+/wLMCYN8iStd4e7FzD7O4fXyWV2p2U7Ng67EyW7yxObINjQX5 1FPjsWStg7DRix/MontYh16efU54vA8/0TEHvQs57Opyhj/1+MN/KjRUrD0DRr9RB70l /gB4pK2aSUHfrYPUP+3dCy7qnWpL7vZPpBZoRFiO+ZMVI1FtnF0R86+Qb5K3pQijEqtj C8YE/eR5f3xel9Q5d7owAFoONkSZV/cgUvixXvladKIJkWOpINJCfsLZ0EKKxs7VoIEZ OlOQ== X-Gm-Message-State: AOAM532LBR89x6K5cPwKDQnpqQHF5Xm6gdSX/Pf1xEqq94QdYgle3GLz NDUM4kpH6NfMts5QxLW1Pvt9iw== X-Received: by 2002:aa7:9985:0:b0:44b:de92:f72f with SMTP id k5-20020aa79985000000b0044bde92f72fmr22848484pfh.51.1633319149037; Sun, 03 Oct 2021 20:45:49 -0700 (PDT) Received: from localhost.localdomain (61-205-96-147m5.grp4.mineo.jp. [61.205.96.147]) by smtp.gmail.com with ESMTPSA id a11sm11863515pgj.75.2021.10.03.20.45.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 20:45:48 -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: [resent RFC 10/22] dm: blk: add read/write interfaces with udevice Date: Mon, 4 Oct 2021 12:44:18 +0900 Message-Id: <20211004034430.41355-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004034430.41355-1-takahiro.akashi@linaro.org> References: <20211004034430.41355-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 In include/blk.h, Simon suggested: -- 2.33.0 ===> /* * These functions should take struct udevice instead of struct blk_desc, * but this is convenient for migration to driver model. Add a 'd' prefix * to the function operations, so that blk_read(), etc. can be reserved for * functions with the correct arguments. */ unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, void *buffer); unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, const void *buffer); unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt); <=== So new interfaces are provided with this patch. They are expected to be used everywhere in U-Boot at the end. The exceptions are block device drivers, partition drivers and efi_disk which should know details of blk_desc structure. Signed-off-by: AKASHI Takahiro --- drivers/block/blk-uclass.c | 91 ++++++++++++++++++++++++++++++++++++++ include/blk.h | 6 +++ 2 files changed, 97 insertions(+) diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c index 6ba11a8fa7f7..8fbec8779e1e 100644 --- a/drivers/block/blk-uclass.c +++ b/drivers/block/blk-uclass.c @@ -482,6 +482,97 @@ unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start, return ops->erase(dev, start, blkcnt); } +static struct blk_desc *dev_get_blk(struct udevice *dev) +{ + struct blk_desc *block_dev; + + switch (device_get_uclass_id(dev)) { + case UCLASS_BLK: + block_dev = dev_get_uclass_plat(dev); + break; + case UCLASS_PARTITION: + block_dev = dev_get_uclass_plat(dev_get_parent(dev)); + break; + default: + block_dev = NULL; + break; + } + + return block_dev; +} + +unsigned long blk_read(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt, void *buffer) +{ + struct blk_desc *block_dev; + const struct blk_ops *ops; + struct disk_part *part; + lbaint_t start_in_disk; + ulong blks_read; + + block_dev = dev_get_blk(dev); + if (!block_dev) + return -ENOSYS; + + ops = blk_get_ops(dev); + if (!ops->read) + return -ENOSYS; + + start_in_disk = start; + if (device_get_uclass_id(dev) == UCLASS_PARTITION) { + part = dev_get_uclass_plat(dev); + start_in_disk += part->gpt_part_info.start; + } + + if (blkcache_read(block_dev->if_type, block_dev->devnum, + start_in_disk, blkcnt, block_dev->blksz, buffer)) + return blkcnt; + blks_read = ops->read(dev, start, blkcnt, buffer); + if (blks_read == blkcnt) + blkcache_fill(block_dev->if_type, block_dev->devnum, + start_in_disk, blkcnt, block_dev->blksz, buffer); + + return blks_read; +} + +unsigned long blk_write(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt, const void *buffer) +{ + struct blk_desc *block_dev; + const struct blk_ops *ops; + + block_dev = dev_get_blk(dev); + if (!block_dev) + return -ENOSYS; + + ops = blk_get_ops(dev); + if (!ops->write) + return -ENOSYS; + + blkcache_invalidate(block_dev->if_type, block_dev->devnum); + + return ops->write(dev, start, blkcnt, buffer); +} + +unsigned long blk_erase(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt) +{ + struct blk_desc *block_dev; + const struct blk_ops *ops; + + block_dev = dev_get_blk(dev); + if (!block_dev) + return -ENOSYS; + + ops = blk_get_ops(dev); + if (!ops->erase) + return -ENOSYS; + + blkcache_invalidate(block_dev->if_type, block_dev->devnum); + + return ops->erase(dev, start, blkcnt); +} + int blk_get_from_parent(struct udevice *parent, struct udevice **devp) { struct udevice *dev; diff --git a/include/blk.h b/include/blk.h index 3d883eb1db64..f5fdd6633a09 100644 --- a/include/blk.h +++ b/include/blk.h @@ -284,6 +284,12 @@ unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start, unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt); +unsigned long blk_read(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt, void *buffer); +unsigned long blk_write(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt, const void *buffer); +unsigned long blk_erase(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt); /** * blk_find_device() - Find a block device *