From patchwork Tue Mar 8 11:36:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 549282 Delivered-To: patch@linaro.org Received: by 2002:adf:80eb:0:0:0:0:0 with SMTP id 98csp1662752wrl; Tue, 8 Mar 2022 03:41:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJxBdjjJbRYn6kYkZuNkZQZiHL0t6rNSPoFNxwLEtzBjHxEbVQeopPtLNT7of2LZo8JQ/ABS X-Received: by 2002:a05:6402:1b90:b0:415:d7d0:d9bf with SMTP id cc16-20020a0564021b9000b00415d7d0d9bfmr15863772edb.17.1646739719740; Tue, 08 Mar 2022 03:41:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646739719; cv=none; d=google.com; s=arc-20160816; b=uyAy/Pa314vfYcTOfVUljzKe01h8bpLwPl7/br+QXt7Tq23AXSTUrFDr+2nwfyPlNE z+7L/7nU9eihgNYWomINpIb6W5K03E/2wBFymxpRrbek7Gz9OAqMraQ165HLBJm42hi4 Wt46Q0jm3I3HlUzsAQ5B5Auwzwh/KLyS+XP6l/28XVwSU3QA3G4gL/zd7OwUmrTA15Sw 3QI3g7wS5pJYoCt2uxHreJmRxXozFQIB6caAc8KYfVvWlRU495I3ahIiMLfAxpDsvb+Y cf9nvjXOK+2BW12EXGgXy8s2td2bJRdVheScitNJCEEZvN2DDnK0Uh+j0OGWiGxZUCs0 0F3g== 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=mJDmu9OSdJgzmswr53AWCpA0O3fozCSHU6IFziGHwJtovoKzmQULuBBWwEHJaFCu4T dVKQ2rnSVUVFEVJtxJ3d2z5Va+OgbNm1oDcMFqtzNmB5ZCBK45nwK0EOj+B6aPrEbBnh DFF8Bx5rwuWuzcwpKOoRddJUeV3hTnZEUKve9UZK+d7CZCW3hB3GySqKe/m829BeM2Gh Wf+Ga/LK+LFe042NYNrrhBWUZk+2ijtl4uX7PKZwgL0htLOlRV6hBifoAyGOKz4KytS7 UsBcfK2E3hVik6u6BUkBriSPWT8M15ucahK6DQRMdDNWt1iUZjXJlSsF2a35vKErBEQw Osfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BoMns9Uj; 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 qb35-20020a1709077ea300b006b51bc8230fsi11218181ejc.671.2022.03.08.03.41.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 03:41:59 -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=BoMns9Uj; 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 9D892839AC; Tue, 8 Mar 2022 12:41:30 +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="BoMns9Uj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7D8EE839BC; Tue, 8 Mar 2022 12:40:57 +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-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) (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 8AF19839A4 for ; Tue, 8 Mar 2022 12:38:40 +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-pl1-x630.google.com with SMTP id z3so8337126plg.8 for ; Tue, 08 Mar 2022 03:38:40 -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=BoMns9Uj6EbPJWVbkiD4uZFn3DOA625j+wuAHFaDDAs9NJhyFw8Kpd0JkhhBzmyM5G mOKHTUfwSn7/wFLgP8LJFHXsCtcfqk0DqX/fwWqeOhtjPMt25MEIeh0xi9SmkMpWDIvK 9X1Z+qk2RWEnF3A1naHXxZU9cu+v//zPVtD0hiFwQhI5zrWGxv82iMHL3rxDY/W47tB0 YCLFubxH4rgf37OmXDCKjgAt/Gb68E4Lj9z2bnUZGmEpZbe9uP5Nv+3DaSCZ31rzc0R6 jqBhnApQyUGKfs+zk8bQKB1NVjyH2qiQNWYJzBMuIXEcSf3ZCN6VF2I+Lh+gZT4CIT25 aYRg== 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=5/FG1sGzpK24Hg5uu1HkJDAHt1qjwfB28pmsfg1NMiSmudaLCx+C3C1o+D5zS9EVyz f7gAC4MAPWYFBK2DTaP8bbIZ2sfEKdWZR/4q94qyCZs5gBAQ1mAt/emDlutJqIRiQWyx EfNqjgZhIucQQkUqG8ktn8nXMBPNbdPtu1aflAlCSb2V0vWK6cl5PnOyGiYAsj8LkAHi MRYF5JwR8n3Og+1OFbvbO8UauJfQP6147Bai4fNk4CN8t3jRWJaUt1MPXaFODWGiKpjA 2GI4eBmVC3AVzPm/8xolhyToNblBtvBLCu+0CYUaM2Y3neQwv0YAVcjkyqOvC43wt3PI v0Sg== X-Gm-Message-State: AOAM532hkQ4Ua6GgtUvcaVL1CDNcti8Co36L+6liVvk0vMFP0El33va4 4DYiDng7grBzipy9nVoFAn2KAQ== X-Received: by 2002:a17:902:f612:b0:14c:e978:f99e with SMTP id n18-20020a170902f61200b0014ce978f99emr16708341plg.23.1646739518946; Tue, 08 Mar 2022 03:38:38 -0800 (PST) Received: from localhost.localdomain ([2400:4050:c3e1:100:b94a:f47a:3d51:185c]) by smtp.gmail.com with ESMTPSA id z2-20020a17090a170200b001bf2d530d64sm3434677pjd.2.2022.03.08.03.38.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 03:38:38 -0800 (PST) From: AKASHI Takahiro To: lukma@denx.de, peng.fan@nxp.com, jh80.chung@samsung.com, bmeng.cn@gmail.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 v3 16/19] dm: disk: add read/write interfaces with udevice Date: Tue, 8 Mar 2022 20:36:54 +0900 Message-Id: <20220308113657.221101-17-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220308113657.221101-1-takahiro.akashi@linaro.org> References: <20220308113657.221101-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; }