From patchwork Thu Dec 10 09:42:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Saenz Julienne X-Patchwork-Id: 1414018 X-Patchwork-Delegate: matthias.bgg@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CsBrl1nV2z9vd1 for ; Thu, 10 Dec 2020 22:43:51 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 715B882615; Thu, 10 Dec 2020 12:43:47 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id EA4D0825E8; Thu, 10 Dec 2020 12:43:45 +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=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id EDFE3825E8 for ; Thu, 10 Dec 2020 12:43:39 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=nsaenzjulienne@suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id AE063ADD8; Thu, 10 Dec 2020 11:43:38 +0000 (UTC) From: Nicolas Saenz Julienne To: mbrugger@suse.com, u-boot@lists.denx.de, bmeng.cn@gmail.com, sjg@chromium.org, marex@denx.de Cc: m.szyprowski@samsung.com, s.nawrocki@samsung.com, swarren@wwwdotorg.org, peng.fan@nxp.com, sr@denx.de, Nicolas Saenz Julienne Subject: [PATCH v2 5/8] dm: Introduce DMA constraints into the core device model Date: Thu, 10 Dec 2020 10:42:22 +0100 Message-Id: <20201210094224.15794-6-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210094224.15794-1-nsaenzjulienne@suse.de> References: <20201210094224.15794-1-nsaenzjulienne@suse.de> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Calculating the DMA offset between a bus address space and CPU's every time we call phys_to_bus() and bus_to_phys() isn't ideal performance wise, as it implies traversing the device tree from the device's node up to the root. Since this information is static and available before the device's initialization, parse it before the probe call an provide the DMA offset in 'struct udevice' for the address translation code to use it. Signed-off-by: Nicolas Saenz Julienne --- Changes since v1: - Update commit message so as to explain better the reasoning behind this drivers/core/device.c | 24 ++++++++++++++++++++++++ include/dm/device.h | 1 + 2 files changed, 25 insertions(+) diff --git a/drivers/core/device.c b/drivers/core/device.c index 4b3dcb3b37..4255bea24d 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -421,6 +421,28 @@ fail: return ret; } +void device_get_dma_constraints(struct udevice *dev) +{ + phys_addr_t cpu; + dma_addr_t bus; + u64 size; + int ret; + + if (!dev_of_valid(dev)) + return; + + ret = dev_get_dma_range(dev, &cpu, &bus, &size); + if (ret) { + /* Don't complain if no 'dma-ranges' were found */ + if (ret != -ENODEV) + dm_warn("%s: failed to get DMA range, %d\n", + dev->name, ret); + return; + } + + dev->dma_offset = cpu - bus; +} + int device_probe(struct udevice *dev) { const struct driver *drv; @@ -482,6 +504,8 @@ int device_probe(struct udevice *dev) goto fail; } + device_get_dma_constraints(dev); + ret = uclass_pre_probe_device(dev); if (ret) goto fail; diff --git a/include/dm/device.h b/include/dm/device.h index 5bef484247..59f711e3dd 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -161,6 +161,7 @@ struct udevice { #ifdef CONFIG_DEVRES struct list_head devres_head; #endif + u64 dma_offset; }; /* Maximum sequence number supported */