From patchwork Thu Feb 10 08:11:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 541412 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp2040192imo; Thu, 10 Feb 2022 00:15:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJyEvoA3tIcrENJZMfvNk1bPZqCOrCZdufcaafzXMSYwpAu4KLnbT0LjELECz1zyRsT3h5sY X-Received: by 2002:a17:907:9720:: with SMTP id jg32mr2210344ejc.175.1644480941736; Thu, 10 Feb 2022 00:15:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644480941; cv=none; d=google.com; s=arc-20160816; b=cgwaHRdsHNELUC4Ok/9Wu8N2f8SmGwIjz4Gt/4TyB1U17ufWSpk5JKfq7+UVO77Q+H zQy/z+JgVvMziD+YsAtWCfae6o94nng7OdhcxXEuSe01+Va2ECgKHjSSXsm6juiKOCq8 COsjI/ZVHbimD8bkGGGcclNaSvVuAJLZEU5/+BCr8cAmD6TcXerNp96JEwSTxThgDJSN vQqTcliFFQBHZBcDsLpN0EPNsROAbbYRBkqzh/BTqAZyodPswM+ZTI4u0q+ipNUT/yCX h6/ZrwgJhILbkopWdPZ6voxKNFn/gzvBG5ib+4lC5oU7XdwnYR7DBvtEH4FaYdQXbp2+ kSiA== 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=OsQfVSYdhgShxJakhkjh4CKoWsiUp44hecLFF1owVw0=; b=sDTuKkqok2ZBSJbtkeB6uEUmmpp1Aa/YXf6vlpHa5QKOSDUJA1H+8n6svzv39N0Jcx T7e6Pl/5Uj9/G25QaL6AI0gQqQm15qoxU83ySD3aCit5gyTLRcCIBPlLWLM71wuzFJ9G pHd/kla71t5nyHDNbWPg+W71oYw1Jty6M8abBKpZ690obds6vWKAvjeDiLLJFK6fsX6p Y8BPFvDyon4rXpfQFdXZ8xi6q+1VyKnrncecu86eX1JqoIEB+uh93x6LYN6ZADXVqDQS /5QeeeVfGRVRipT0mS/hphLDCqCVjlVVZR07aXy3Q4YSau+yt1tA+YgNzSK8vzgaJ6nN 3hFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G+0Uwvbj; 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 dt7si14896305ejc.559.2022.02.10.00.15.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 00:15:41 -0800 (PST) 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=G+0Uwvbj; 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 86D4C83A46; Thu, 10 Feb 2022 09:14:09 +0100 (CET) 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="G+0Uwvbj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CCE2881F4D; Thu, 10 Feb 2022 09:14:00 +0100 (CET) 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, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) (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 47A8983885 for ; Thu, 10 Feb 2022 09:13:15 +0100 (CET) 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-x102d.google.com with SMTP id h7-20020a17090a648700b001b927560c2bso3633808pjj.1 for ; Thu, 10 Feb 2022 00:13:15 -0800 (PST) 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=OsQfVSYdhgShxJakhkjh4CKoWsiUp44hecLFF1owVw0=; b=G+0UwvbjLNpdHevXagLUgtgKN5V0uyrhWIxVBSpgA6fFgTcpNjyLinAqrQxGuFgQPT Lk8iO0NkfkFgEV46FySB0ZgyFvXz78kIflOfwVdERiUR26bK6ybohv09GJ3wYLhMsM5j v3pHGZnZRblLkU9aebzzpbeVj15OHlMEw6hFgAmtc1wmJvb4MnfeYdpEyMsDXF53OOjc G0lcZmk9euj7vUfDsaZd+zoCKU8fh5YLUMqHC6OSyaRBoHGJNedNoF67GxDda2or9h8G Ye41iJBzaIg71ZEGoMUT7NxlK37DKRaI6n6yqdhD5Y8XaCBCPkwHW6gtVQM8MqVBMZ83 zrDw== 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=OsQfVSYdhgShxJakhkjh4CKoWsiUp44hecLFF1owVw0=; b=jXS7NwMvyYCB1+5/XxYscRFR83M3Ey+E7aoIz1AwAl/sDxvU8rGQzDv/0O/v9jRtWw LMZomj+gpt6w9pe8VTUsJmDlqZiDwU28zoZK7eK0eGtlJfi9ViWHh5jMGUr4kad+4erH cSE+nKqHL6jQkX73gD5KNzpE1w2NbjswIEG44L7xDJpuzWTSeypOT48ZEUTHkATeiSui cYFByx661mmoMTk3H8KB1GSEVSCGmPBDR9hTyEX3Q9XHJVPrOy7n1QqP4gi2N6yiFNP0 EqtpRL1/Vw6p1J7A0wNJERHtjxg9Z5edOz4t+71QVXtT4SpaSkXCZ5Ngqe7lfSATqZGR vi4Q== X-Gm-Message-State: AOAM533o1Z2u0im+pZrosw7dGLGmGh42UuZxJ0PePG2yFjibXw6cJKq8 DcGNuaM58jx33slSbGrE4pwirA== X-Received: by 2002:a17:902:e74c:: with SMTP id p12mr6702441plf.115.1644480793610; Thu, 10 Feb 2022 00:13:13 -0800 (PST) Received: from localhost.localdomain ([2400:4050:c3e1:100:412e:384:fab9:f24]) by smtp.gmail.com with ESMTPSA id lk8sm1529208pjb.40.2022.02.10.00.13.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 00:13:13 -0800 (PST) From: AKASHI Takahiro To: lukma@denx.de, peng.fan@nxp.com, jh80.chung@samsung.com, bmeng.cn@gmail.com, peng.ma@nxp.com, sr@denx.de, xypron.glpk@gmx.de, sjg@chromium.org, ilias.apalodimas@linaro.org Cc: masami.hiramatsu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v2 17/20] dm: disk: add read/write interfaces with udevice Date: Thu, 10 Feb 2022 17:11:21 +0900 Message-Id: <20220210081124.86612-18-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220210081124.86612-1-takahiro.akashi@linaro.org> References: <20220210081124.86612-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.5 at phobos.denx.de X-Virus-Status: Clean In include/blk.h, Simon suggested: ===> /* * 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 --- disk/disk-uclass.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++ include/part.h | 7 ++++ 2 files changed, 101 insertions(+) diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c index 4918a2f72d1e..72ff62ebf581 100644 --- a/disk/disk-uclass.c +++ b/disk/disk-uclass.c @@ -146,6 +146,100 @@ U_BOOT_DRIVER(blk_partition) = { .ops = &blk_part_ops, }; +/* + * BLOCK IO APIs + */ +static struct blk_desc *dev_get_blk(struct udevice *dev) +{ + struct blk_desc *block_dev; + + switch (device_get_uclass_id(dev)) { + /* + * We won't support UCLASS_BLK with dev_* interfaces. + */ + case UCLASS_PARTITION: + block_dev = dev_get_uclass_plat(dev_get_parent(dev)); + break; + default: + block_dev = NULL; + break; + } + + return block_dev; +} + +unsigned long dev_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 dev_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 dev_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); +} + UCLASS_DRIVER(partition) = { .id = UCLASS_PARTITION, .per_device_plat_auto = sizeof(struct disk_part), diff --git a/include/part.h b/include/part.h index 95e30e60af10..d4e5cd921db1 100644 --- a/include/part.h +++ b/include/part.h @@ -264,6 +264,13 @@ struct udevice; */ int part_create_block_devices(struct udevice *blk_dev); +unsigned long dev_read(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt, void *buffer); +unsigned long dev_write(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt, const void *buffer); +unsigned long dev_erase(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt); + #else static inline struct blk_desc *blk_get_dev(const char *ifname, int dev) { return NULL; }