From patchwork Fri Dec 10 06:49:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 522741 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp2170944imb; Thu, 9 Dec 2021 22:53:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvnIgjvaVnYBfieDTWSZYhn4k8VzTUuJPEjfAGTWl/lMnxjr0G18Qwx2sv9yWAT4d8szD+ X-Received: by 2002:a50:ee19:: with SMTP id g25mr37105210eds.162.1639119212913; Thu, 09 Dec 2021 22:53:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639119212; cv=none; d=google.com; s=arc-20160816; b=KLlhFHY+OQDxUpPr5WMPxLCRFl7s6NpmX6nnzv5KyOubXWfZ77xEzouC1avmzG9Ul8 L+c64abknCZSaRuR8hFbM8eMFuAF7XulxbuXmDA4wSti9KiDVCChKC6tcGuMuOOyToir T5fMnavHPUVoG8VdrTEvheeKbr15PUj8tbA8a7Rkzuxu75S9VGUEuJeuE5l27/iIyOOm 3Eds7IxdV4gz7P7PgW/30EIE1cbwsqKjBieozkdFnpuf011iWYe1f7NpM36vG0jS7Pmh mW/MUVQiiBiF7bwJys688b8zZwyXG2M9vUu+Zlc217/bLLyTUUcU+HckTUvQ9eQP1SF8 UeFQ== 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=sYUc3BMcyz8ePK8CD3CP67NTGto6abBt+cXyNi4SEbI=; b=DEeCkqAEQzPm3dPmIoUUMJJ7+7eJSXBc1Aw+VnFuZsEBPmg1FkNX6T+hw0KM8Tbhta eJrIqLwbXbsa7OE0OluztxwLKNuUmiHUOsBKz/++6XC2weZUAxRuJK2EMBloYw2ep4Or KBO095e1BOlMsg4JYtJW3xomnqqGp6HqN462gS0WjvLjh6kY7ppTSYizYQw4sCVw0RTU 0K1GjmlKu43AXsH80SinOslI4mrX5EDikW30pXp59vwE5BB/5BacacNk1ySbiX+MEXrY je7ZYQuwEtGSBht2aZvQaojW1yHMd7gWN6nJctT33oZ4075gZmUrQlhnT2Flxe4R4yXU lVdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KCtnqvsu; 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 du13si4776922ejc.417.2021.12.09.22.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Dec 2021 22:53:32 -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=KCtnqvsu; 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 916918361E; Fri, 10 Dec 2021 07:51:46 +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="KCtnqvsu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D6F2F834DE; Fri, 10 Dec 2021 07:51:23 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (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 4789C834E8 for ; Fri, 10 Dec 2021 07:51:13 +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-pf1-x42f.google.com with SMTP id u80so7627806pfc.9 for ; Thu, 09 Dec 2021 22:51:13 -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=sYUc3BMcyz8ePK8CD3CP67NTGto6abBt+cXyNi4SEbI=; b=KCtnqvsu2urr+zJJstWb5oanj2Xhi5zKAkEoSUo2zAoJD/2uNYv6z4OhomP0M9mp9V uzrCOCkyWgAMVoln1VfQ3/lxLNHqL8ojK7iBLa2/c1HrY2/qeQRSlhV2gSQfGWeKIO4V xKJTkiP2o9fKpzhWJL6rlnJkvKWGarWV8qQZB9D9xmgDbjzllaR2TogtV6ZiVZOjGCEW WZmGCU7+LRFsZBAxXRd/Jjq6KKOo/xOb2DWEdATN2Qygov5TCDLVUw7xo+oIbN4iaKdq tJJlyLBjgRTv0+f1UCrypVPVf9XhNFp0ZFJa6AW/vOzNAts/NBlE+n2t5KiZ9fOV1N6w zNpg== 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=sYUc3BMcyz8ePK8CD3CP67NTGto6abBt+cXyNi4SEbI=; b=uXTfRZEQQ40vKudM+MnNaYr6bEnr3q7pmb6eH3r2XbsVWeNQjxBszMUxTnWw22gLyk 23pKXFD8o9nSMgpur69yWHvg5GwnJyWwiEteqeLtAfLI8YI9rvfzPrKP2t2HQF9m/nhb C6BaCeyiJMx7GvVzy+xgSiEki6bHxWDbZiWl8baELxq485gGm3iOwkJK+hXvX33bWJXv 1FBbF4kZNmZ9aqm1pCHaXBQF08/ldcYBa/SRswnncfOe7hyKLA9+tmGnF3cnAS+diJHU CwDoire9RhTsVe5Zful+fLvR7fqWIbQ0zENs2O541uUTE5m3aTVaB68pUo/KHqwezgGK eT+g== X-Gm-Message-State: AOAM5325pUQ5r5zv0G17YhNmpMqXMY1tYoNXulaCf/kwrkfxgazxSMZX fFfWL2eaFbjWHnQ0vzR3zz0hiQ== X-Received: by 2002:a63:b5e:: with SMTP id a30mr18811270pgl.432.1639119071627; Thu, 09 Dec 2021 22:51:11 -0800 (PST) Received: from localhost.localdomain ([2400:4050:c3e1:100:75dd:4e0e:4542:936e]) by smtp.gmail.com with ESMTPSA id nn4sm1639035pjb.38.2021.12.09.22.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Dec 2021 22:51:11 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de, sjg@chromium.org, ilias.apalodimas@linaro.org Cc: masami.hiramatsu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RFC v2 17/20] dm: disk: add read/write interfaces with udevice Date: Fri, 10 Dec 2021 15:49:44 +0900 Message-Id: <20211210064947.73361-18-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211210064947.73361-1-takahiro.akashi@linaro.org> References: <20211210064947.73361-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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: ===> /* * 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 | 96 ++++++++++++++++++++++++++++++++++++++++++++++ include/part.h | 7 ++++ 2 files changed, 103 insertions(+) diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c index 4918a2f72d1e..9cadba37ab2d 100644 --- a/disk/disk-uclass.c +++ b/disk/disk-uclass.c @@ -146,6 +146,102 @@ 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)) { +#if 0 /* FIXME */ + case UCLASS_BLK: + block_dev = dev_get_uclass_plat(dev); + break; +#endif + 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 e492c2249019..1c564c6d6a3e 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; }