From patchwork Fri Oct 1 05:02:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 514996 Delivered-To: patch@linaro.org Received: by 2002:a02:606e:0:0:0:0:0 with SMTP id d46csp452705jaf; Thu, 30 Sep 2021 22:06:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTzoqMYjt8joxy9zdQoQBJl+NV0/13YOHfe5uGAoaf1jwnXif6PY2RLBNrpyIasFbYEVUv X-Received: by 2002:a17:906:374b:: with SMTP id e11mr544236ejc.492.1633064796406; Thu, 30 Sep 2021 22:06:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633064796; cv=none; d=google.com; s=arc-20160816; b=upCKBr4IJUnSqgCl0IslJybO+GoV4Zm3Sj/0SxWtTh6tGWcudgvbyEIyXtSuNYDJ/1 N5p6aelYmYfmE0bhDOysTcj5DEJgNy2BQ0PqvYyBWMGsHGIhoxTXN9VmdNbtHYnJLXkD XR0l3SN6hHfBKQhg7R0z4L19GgnNQm/BzRUJbpj7YSLd64g5DpGIp+9+NP0AW+9Re+OY 1snnb/cpGknidj+4wk+rit9yWGBx+eLj5UwiBAsLRcRtQD++1VEScQSfdO1fKGrnMsfV WxmBN+hcbKeZsOxUBBh+HFDDL85FjBN/SZ74wHhHMHb6INAZAfoVmLEZi71M1TMdiM/N 0jjg== 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=xksqh8QTsrIvS3PNb1xv01TEbRYulHoECyvz6tj8vYm/aKTR99fg/+NUZVKiQsjqMR nkkgszBSd4I5uFbINvyLuvcRS7vvbNEKZLwLFnC8oCKccsuT8aYR2Uv4FSQ6rgWClhmO 6zFpyLCilXn0BKirWP9Gl45KVhPsqnj4L2fEY69/6+kKbwY+HmOfzntJl3AezcF39lA4 GbAcJu6QCujOK9LDwDIerEjtYRMMJ9ETj7uYOiwIuKH0ZHkFRJLZZZQDvYDWdgcRRt34 wPH/ltkediCX3rJnXRfX6LX3MRtJm9KglpHQhNlQE6QxJ/WuKrexY6mpJDER1/tISOle hk/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PVZPi25+; 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 c11si6758980edy.498.2021.09.30.22.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 22:06:36 -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=PVZPi25+; 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 4213383424; Fri, 1 Oct 2021 07:04:16 +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="PVZPi25+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DD304832AF; Fri, 1 Oct 2021 07:04: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-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) (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 401508328D for ; Fri, 1 Oct 2021 07:03:54 +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-x531.google.com with SMTP id 66so7945933pgc.9 for ; Thu, 30 Sep 2021 22:03:54 -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=PVZPi25+76+yZ3FqyQ09LXR2Bif4y5oDdh8aR9BRUP+IHJSl0daYsyEDAsepdAXSSX Fcj2W37qe61bEuXc4REZpD2IH80U9vHw2LrKW7briB3Wi7OQQCGp9SW1uh2k8YdXNAXs KA1s8A+BR/Bv9JSRjX+rHX4hfOyiAuOao8W/zIXmU/qH3p0tYbBY3QeEFOxzxbYF6xhd DY5yUd0aIdlHEXHB/EMunv8iWB+gI2wIn5CFfgZFSwmTJnYvWZJ9VHbSy1VmJKWnXGkE dQ0mI1qT1g+arCWVAtSccRwH7rK7M4HbC9xJsyTLpjjhCyviv4k0zXUYBce9CdK6kfzB B3WQ== 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=zi1W3quc4j5CVosxEJxOkXbxIkLDEgleY0lwwNkjVrPEDLGHK7FNp9TPvut3n5Jm0M SkGl7vk4M5kgAhLid761Vp1Q6yRVDiUHzX3ImF0+W+7Q38DlGaE8D8pJTshKN9Fs/IBi DJiR8I5Gpfg+dL9PfkD/0gpBYA0lHOcZZ0MduoS/YPXBMN/Ndd9zZBAmuxWQ+SoUCnDQ Os5oGVmRA1MRliRInHgqx2onJro05JjExytaR9+ClSAwTCYdNvG5SA0HZqJLRrdpPDkK nvcGs+1j0PXBJDTk08+IUARKc74LpdIo8oOSAG3M0Yl5DveZVP9BKHANpqt4ElFCSg4q ffmw== X-Gm-Message-State: AOAM532RkenrAIciCeRvXVBFK4GSaqjDXM0rDc6VxfIi3Dgzclz1ZXA2 lKD6BWYSewWZswnWI1sGvw6VQw== X-Received: by 2002:a63:ea48:: with SMTP id l8mr2218498pgk.99.1633064632427; Thu, 30 Sep 2021 22:03:52 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 22:03:51 -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 10/22] dm: blk: add read/write interfaces with udevice Date: Fri, 1 Oct 2021 14:02:03 +0900 Message-Id: <20211001050228.55183-20-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 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 *