From patchwork Wed Feb 2 01:08:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 539316 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp1192819imr; Tue, 1 Feb 2022 17:13:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4GtpdAr14izG7MlcdCSoc3/7BOE/zF70u4PRldOcfhjMiz20pb0TBGSXZwvy993tzmd6e X-Received: by 2002:a17:907:1b16:: with SMTP id mp22mr23852112ejc.537.1643764411526; Tue, 01 Feb 2022 17:13:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643764411; cv=none; d=google.com; s=arc-20160816; b=rahUvbeadb5JtkV3WypFMaRao2d3eTcg2YBb01RGdgqANh8Y0EzLd+cr+UqM8USDgZ dwGgKAfR1YOpSbwqiolyOaZaxnSN955dLBsLhAWj28K4LvE7/4nRvAr24+4Me6bZOPVB OeTXkXj6o3/FNVGfBdLR5LBSBPhWGT+rQjX0TXcwB1VsYW5QDXCX6ksduBAInKF9Yrwe QQ172WdkY0v0NXZfNaezxMiuwGVHQ2qAkNgUbzzFRDxRI20zxfto8ewnbuH9rrxEYjvm /aYEY3zY2NPTaKABqLUlfXulI8RyMz37rif+qNyBdjghdfYF6Zo7xx70twsm+tqT02Mm i73g== 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=qXlZ0KA8pwR3M8F40KCZMVBt6DC0n9yWRhLkeVNcfCDqRKuFI5Pmb3QpdFsOrg3dBk DD/B84sRLp+t8WJw7rkP6BFlJb8R1GcInwx4HeoRj8YWWmdZeO7cdsAsBNgbT69Zc7CW SXB+LYqfY86WYHzFGdlZwTnXiS4KXGRbHp+v5ReNIIyb+2yzJTCXhCMeZgjx3UnlgWZK P03MZTFIhLZFhgzEuXJBGw7WcTWLJ7klqYVqB70I07OMksJ6g2/+C+18JsYGUROvTrQW eQl81OwbOvw/abk3vIYeFuwCj95GKLShHECE2VtkEHiI0DSZMUoA+nX6tgRv3S5juXgC +//g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hhtsp59u; 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 h20si12559276ede.184.2022.02.01.17.13.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 17:13:31 -0800 (PST) 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=hhtsp59u; 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 3C56883917; Wed, 2 Feb 2022 02:10:37 +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="hhtsp59u"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4D36783003; Wed, 2 Feb 2022 02:10:33 +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=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (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 14A4F8341A for ; Wed, 2 Feb 2022 02:10:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pl1-x62f.google.com with SMTP id b15so16882115plg.3 for ; Tue, 01 Feb 2022 17:10:26 -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=hhtsp59uGy19ITQ7WGmgRm/3NSvN86L1gQqr1oZysNVeaawt114zlbk2/oGbP7gwNq pbakc8KGypq9Uij2SMbRvTh0rOJvA0CxgekoTzFhVThXAVUT1PC+oNmtE1dUNbmpignG NzoZzf9Kwurcdw2gPBY08YnSy6x3Cu7YkeRiRLPU2ZQClI+r0iwb5igrkIfV+uG/rTRu n8yQtj7vqwgbogX6EmHdwi429Q7vW+qdF+LS5mRHDGyae+fSh8xrmNCw93rMsY3lvQzK UlkmqCd/12Lh581qgr9h/oDc6qRETvcNNolx8qnKyOVqZXYzv2AAqg3iqsODja0RgBtl eTFQ== 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=h3WGlkeVOI604cxWGUxcYVcHo+7JrNt4/J6hv6j99GRKeL01ACIhOHBeI44P94VQaF HVlCJuLesu5lzAdzks9z9E4Cvd+DNv/qGD/ErUKZM/QtpaO5TvgdkrJJaXc2OxtVXzoq usxI37AptFGiAb/ceN/Sf+1u3fgthrVpBqSb/2LlOhy9IdohM93ui0MAomerfNcadRV1 EZn+uFkFjWYhpfEy2kBJFd51EX5rRFTH0qiK8ec8UOp5Ve9op/Jc8CmVEDhafqqqeW7Y RhISquOma/6v02/k4MwXj39BEkw/txq650tFPNcSUGpIkW1OwOzEtBqlL82PZRZ67c0H Rt3w== X-Gm-Message-State: AOAM533MgH4q80ywXGSp3ak/LhPtsYNJxZOH4qYgNvGcsc9ApqfujlAP 4cSmP77HRenuG2NxNmVXvGtdVg== X-Received: by 2002:a17:90b:2281:: with SMTP id kx1mr5418988pjb.37.1643764224453; Tue, 01 Feb 2022 17:10:24 -0800 (PST) Received: from localhost.localdomain ([2400:4050:c3e1:100:314e:b83b:fa90:7f2e]) by smtp.gmail.com with ESMTPSA id f5sm10761429pfc.0.2022.02.01.17.10.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 17:10:24 -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 16/19] dm: disk: add read/write interfaces with udevice Date: Wed, 2 Feb 2022 10:08:50 +0900 Message-Id: <20220202010853.40405-17-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220202010853.40405-1-takahiro.akashi@linaro.org> References: <20220202010853.40405-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; }