From patchwork Fri Apr 15 07:15:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 561947 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp115920map; Fri, 15 Apr 2022 00:18:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy55pIUU4JsYcocDAW5k/vCv7aU6YJw/iRsBftROolwKxU/z7w5b6Ra+8FvVUFhLV1shgVE X-Received: by 2002:a17:906:4408:b0:6da:bec1:2808 with SMTP id x8-20020a170906440800b006dabec12808mr5153569ejo.543.1650007101651; Fri, 15 Apr 2022 00:18:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650007101; cv=none; d=google.com; s=arc-20160816; b=ex+Af64mjvud7d/jYs40R05QuADAIEkaZ6WCDdi347HKP2X2bH66kkTfr8rxI7EW+Z KiUgslKzsxOgQ9VEPCJ4JeImVmhwIKiPduFkgRyKlTtCVe/OnsLzcQ+h+zdvYSDQ2a+f /At8x/qDvVM8M9wWMZOc4u6yP8ccM98bzan1WfWKYmqLT+GH+9/+mePaelS5EJ4yyxVJ VAXYH02BPZHZbx3gb8sV0e+ELolTyv/lk6dsh5C4dLHR+8n4Mua5D/xmwcH2y0sBGyq7 NtgGJLVRCegP1jaPaE/IOZvQqJGq3bmugwaLRjT/33QwsNTXJs1T4HcRmnYzzdMIqwrr 6Wsg== 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=061GZJVSIIurGZJRV3GvyZc3JG4zYyc5UBd90jHpFIw=; b=nQVC/N8FRNC4NLVr02h/pjBTquPVGpMOtPgthrJfmBnAxMeFJoXpBbcWsx17PWgdwF t1v8Fvyga73RX5YnEVwM8qa31MjCRkwwDOTuwnNDGdiff/WIUryzrDdqpJ8SaTDErirj EPPpDG3Y3JcwkHokt9nLbBOGgjp8YNFIJ6oWUzzZJwNvVVcld7JGaGZXe9odtA1gEnWo PupdYXT63kUrPxipWmNwOzw+e7/czFac5uTWKfjvw9XQA4qrbqfmJuHJwCkqPIHXBN6d yVqv4YqCVwiGM5+LhogOzSV2GQoheV4W4och+Y40fqHdkDFp/5MjX2fI5Z24zZ0bTFIs zKjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j6i4TrmD; 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 j7-20020a05640211c700b0041d71714dc1si723005edw.420.2022.04.15.00.18.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 00:18:21 -0700 (PDT) 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=j6i4TrmD; 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 DEBBF83E0E; Fri, 15 Apr 2022 09:16: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=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="j6i4TrmD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 509A1831CA; Fri, 15 Apr 2022 09:16:45 +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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) (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 16C72831CA for ; Fri, 15 Apr 2022 09:16:42 +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-pj1-x1030.google.com with SMTP id md20-20020a17090b23d400b001cb70ef790dso11184853pjb.5 for ; Fri, 15 Apr 2022 00:16:42 -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=061GZJVSIIurGZJRV3GvyZc3JG4zYyc5UBd90jHpFIw=; b=j6i4TrmDuygszmFgQDm5V9b236DKql/Gn3mgufqFndhGfh6TO5vIis5citEyLeCFDw 7HY4ju9JWRZm40wUjiDEJDT+XP6M5QhmkXrD+ynZlZZsyz4cqkQ0kRjAgZhMdlv5/WF4 BniEQnGvllq7zElFS6uASemzyp88uf0GQktubPoQob6YLNXkwIvUY75vvKlBqZZsJcYK O8pC+wwvLyAwIHphchc5DAVqVKxtA5xo+sPpKGegBsM4/ZetCE4sNFhBylPPgvd5I4Va wLIHxE3edA7ixA228iMCWSNzizWNhe563BHLH8yJiJXJUlrAumVJxPO3OsM1RMrK96jO RxuQ== 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=061GZJVSIIurGZJRV3GvyZc3JG4zYyc5UBd90jHpFIw=; b=wIAQxRzxuZXOYhMfqfxqDoQu7FZEL5T9O2m+VZooPZ+EVQ2dUU84ZVa1AqssUU8hrK ZOYKwiJs+cxSQu5ujZrRKAvvzItQvmNdxPRxSU4majEnr5alIumtiUfy/WoO+ZmOO6EE 3y51BMKiOZcPfLcF3iCNsC/btpMr0Loh3TkbqOAOWHcJEN85OlBHMNdZc1KIql6Iml9F TImKXu9tbeMqywFyx5MHukCUCluvRFuGfELlfcN33CH/jJWHeIr5A0gYCLFTmkoFOBd3 FjXPHHGB/yP2/JlnvuD16XFbbGYtI3EnkvKwxMMXQGY9s6XzQYXaoy1FxKqmjqzmfm4e klBQ== X-Gm-Message-State: AOAM531ZG+G7u+VodHFwkc+GEkrwzQ2cM0UGffKC8WkMp4KmtbOxh/+G liNSBuvdelZpyXY/SGOP0ZmWgA== X-Received: by 2002:a17:90a:4897:b0:1c7:5fce:cbcd with SMTP id b23-20020a17090a489700b001c75fcecbcdmr2699532pjh.45.1650007000523; Fri, 15 Apr 2022 00:16:40 -0700 (PDT) Received: from localhost.localdomain ([2400:4050:c3e1:100:18f3:1e4:6c4:6ea3]) by smtp.gmail.com with ESMTPSA id p1-20020a17090a0e4100b001ce188720e5sm3566921pja.53.2022.04.15.00.16.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 00:16:40 -0700 (PDT) From: AKASHI Takahiro To: 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 v4 11/12] dm: disk: add read/write interfaces with udevice Date: Fri, 15 Apr 2022 16:15:45 +0900 Message-Id: <20220415071546.122475-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220415071546.122475-1-takahiro.akashi@linaro.org> References: <20220415071546.122475-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 907c227aa20d..36b76f00563f 100644 --- a/include/part.h +++ b/include/part.h @@ -297,6 +297,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); + /* * We don't support printing partition information in SPL and only support * getting partition information in a few cases.