From patchwork Fri Feb 14 22:43:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 204776 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB51BC35242 for ; Fri, 14 Feb 2020 22:43:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AA8E724686 for ; Fri, 14 Feb 2020 22:43:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581720229; bh=1dUFe/60+iBjueX3vXqk/UGfbi1n4EmSdN70HmJn4Mk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=tL2V/nV5OO02D4Pi5BUx/Y5TEze+RW0u3y1rDiNF0sKpuBhpwU+DcBGSD+CJdyoeF EvwAWf53CbUYqNbjsmsKyVSLwS65XNVe/JcB+zY+jvXc8WGWHxhZqhAy4UiJmsIU++ 17sh3iC2Crb6zOySCon3wZYa8fMGjzYa2GaQ8HB8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727905AbgBNWn3 (ORCPT ); Fri, 14 Feb 2020 17:43:29 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:39717 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727566AbgBNWn2 (ORCPT ); Fri, 14 Feb 2020 17:43:28 -0500 Received: by mail-ot1-f65.google.com with SMTP id 77so10685956oty.6; Fri, 14 Feb 2020 14:43:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iJLT9fE31WzVusqA3+ydaNjT/O63JNBeN6ZDzqnRwwg=; b=E+wHK0nEB+/YR8RdqqZXD/02AwmJut0mAdBizFI71J00NS2LrLTHjR+R4bRsUOo+8z xaDOJy6nmN5xtbgnTMrBfzMFewoYjU3Orx9L0n4rxl6TCrN0KGWm6jTEN81qasIOkUmj mxO9qAvsm8jGkehPesF6mnY4tKr7KBWZ1hHy/IkFOpoRwAkTWSIhHoLJCM4UEDrwWUDI QeasLNkrf+b9Tqo0KIHxJejrtxIMRXKbz2uW3dFOiGSsq4mLBrlpn/ucBJpcolyyUEpL QSw+67YztzBf309I0ZnzFNA0hy7wojbIdsb64OjNzXT8leHPKp5DwUDsNyU06jNMLbPd qiNg== X-Gm-Message-State: APjAAAWZCIRyPfb/tC0hrXIfcKpwbtWugmI9UszYVU565oofuR1hExIb mLjswQK5ydv3edrHqnF0yvQ7zvA= X-Google-Smtp-Source: APXvYqx0xFv4NMz1FqL6vpJxFMFKpg/WkEi3ohp0ZGVbhLQlrLVUpFTQ58w87DSciAPwtsQOj7dTEg== X-Received: by 2002:a9d:4e93:: with SMTP id v19mr2073700otk.200.1581720207829; Fri, 14 Feb 2020 14:43:27 -0800 (PST) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id m69sm2453167otc.78.2020.02.14.14.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2020 14:43:27 -0800 (PST) From: Rob Herring To: devicetree@vger.kernel.org, Frank Rowand Cc: linux-kernel@vger.kernel.org, Linus Walleij , Robin Murphy , Christoph Hellwig , Arnd Bergmann , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Michal Simek , Paul Mackerras Subject: [PATCH 3/7] powerpc: Drop using struct of_pci_range.pci_space field Date: Fri, 14 Feb 2020 16:43:18 -0600 Message-Id: <20200214224322.20030-4-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214224322.20030-1-robh@kernel.org> References: <20200214224322.20030-1-robh@kernel.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Let's use the struct of_pci_range.flags field instead so we can remove the pci_space field. Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Michael Ellerman Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Rob Herring --- arch/powerpc/kernel/pci-common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c index c6c03416a151..d0074ad73aa3 100644 --- a/arch/powerpc/kernel/pci-common.c +++ b/arch/powerpc/kernel/pci-common.c @@ -728,7 +728,7 @@ void pci_process_bridge_OF_ranges(struct pci_controller *hose, " MEM 0x%016llx..0x%016llx -> 0x%016llx %s\n", range.cpu_addr, range.cpu_addr + range.size - 1, range.pci_addr, - (range.pci_space & 0x40000000) ? + (range.flags & IORESOURCE_PREFETCH) ? "Prefetch" : ""); /* We support only 3 memory ranges */ From patchwork Fri Feb 14 22:43:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 204777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D47B9C3B1BF for ; Fri, 14 Feb 2020 22:43:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A6C8724649 for ; Fri, 14 Feb 2020 22:43:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581720228; bh=Rj8PSB+UwBprmaQ2JyKnvemogSiYDpPi3Vm6V0cZl4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=GuF2TSoNVyly9JHTluAHD0JBUP3b7TCxNt68ZZFVwsyO168da6QqPW626OqnvrRvx m/opBeyUOK0j+1r8zN4Bv3sewDNVcqCOiSumoGQ4xbcvcLdPskZmONcRu175OQ2lls tiFzBF3d2ky3v2cfL7xT/FOrWxA/78V9Fr20EDSU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727951AbgBNWno (ORCPT ); Fri, 14 Feb 2020 17:43:44 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:42955 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727953AbgBNWnd (ORCPT ); Fri, 14 Feb 2020 17:43:33 -0500 Received: by mail-ot1-f65.google.com with SMTP id 66so10674736otd.9; Fri, 14 Feb 2020 14:43:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pxqrTmSWehNrZNpQ90LT3R+yI3An6tFPJHq9Cs6TvSY=; b=O2oIHRQOgC/RyyoVqyUHnBlXqNO8XeUKzLO5VBx7Lqo0Bjb4bTdWhu7yRLxHglZ2k7 uDcAiVpHAD5+TXcZn+FVX4C2k4Ef2JGqso9GKoWmIyFqYl0yxJcU50cQt5fwXMGatFxf rD70SVy6fwgggMXWW1ro3WaT1KbRQpsPdIApn66Yj+dPR/LJ8RDeJMdYXKQZjTANtuaa /i3i1aW234SVTWXsJA4kbn8SzOGR8NNIKEkLStvlkU+AQupzWhDSj1lmEditDz02BgXY KjyXcjm+am6cZsdcF2o0FV1X6disavHLyr/tUVxT+KfOnrNaETN1v6TuG+5XMG/EO8dm Qszg== X-Gm-Message-State: APjAAAW8m46zMAYpL6I079eKaQY5MPDldy9Xjs5HRH/Nw0b++WaFEEoi y7l6EavD3zQV+okX8+uWqOsARAQ= X-Google-Smtp-Source: APXvYqzRyruX6jzkcJBQ4Ol9aSCzNcGPj4+4pT7mi4zsBVbfgiMtU6G60aL26K2rvdNgbEenPv9cKg== X-Received: by 2002:a05:6830:1049:: with SMTP id b9mr4276236otp.100.1581720211206; Fri, 14 Feb 2020 14:43:31 -0800 (PST) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id m69sm2453167otc.78.2020.02.14.14.43.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2020 14:43:30 -0800 (PST) From: Rob Herring To: devicetree@vger.kernel.org, Frank Rowand Cc: linux-kernel@vger.kernel.org, Linus Walleij , Robin Murphy , Christoph Hellwig , Arnd Bergmann , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Michal Simek , Paul Mackerras Subject: [PATCH 6/7] of/address: use range parser for of_dma_get_range Date: Fri, 14 Feb 2020 16:43:21 -0600 Message-Id: <20200214224322.20030-7-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214224322.20030-1-robh@kernel.org> References: <20200214224322.20030-1-robh@kernel.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org of_dma_get_range() does the same ranges parsing as of_pci_range_parser_one(), so let's refactor of_dma_get_range() to use it instead. This commit is no functional change. Subsequent commits will parse more than the 1st dma-ranges entry. Signed-off-by: Rob Herring --- drivers/of/address.c | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 6d33f849f114..a2c45812a50e 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -939,10 +939,11 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz { struct device_node *node = of_node_get(np); const __be32 *ranges = NULL; - int len, naddr, nsize, pna; + int len; int ret = 0; bool found_dma_ranges = false; - u64 dmaaddr; + struct of_range_parser parser; + struct of_range range; while (node) { ranges = of_get_property(node, "dma-ranges", &len); @@ -967,33 +968,20 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz goto out; } - naddr = of_bus_n_addr_cells(node); - nsize = of_bus_n_size_cells(node); - pna = of_n_addr_cells(node); - if ((len / sizeof(__be32)) % (pna + naddr + nsize)) { - ret = -EINVAL; - goto out; - } + of_dma_range_parser_init(&parser, node); + + for_each_of_range(&parser, &range) { + pr_debug("dma_addr(%llx) cpu_addr(%llx) size(%llx)\n", + range.bus_addr, range.cpu_addr, range.size); + + *dma_addr = range.bus_addr; + *paddr = range.cpu_addr; + *size = range.size; - /* dma-ranges format: - * DMA addr : naddr cells - * CPU addr : pna cells - * size : nsize cells - */ - dmaaddr = of_read_number(ranges, naddr); - *paddr = of_translate_dma_address(node, ranges + naddr); - if (*paddr == OF_BAD_ADDR) { - pr_err("translation of DMA address(%llx) to CPU address failed node(%pOF)\n", - dmaaddr, np); - ret = -EINVAL; goto out; } - *dma_addr = dmaaddr; - - *size = of_read_number(ranges + naddr + pna, nsize); - pr_debug("dma_addr(%llx) cpu_addr(%llx) size(%llx)\n", - *dma_addr, *paddr, *size); + pr_err("translation of DMA ranges failed on node(%pOF)\n", np); out: of_node_put(node); From patchwork Fri Feb 14 22:43:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 204778 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E89DC35242 for ; Fri, 14 Feb 2020 22:43:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E3C572081E for ; Fri, 14 Feb 2020 22:43:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581720224; bh=H/TPqHRNSmD4IwUAivQ4lInBziR9Asin4p/pl6/mCO0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ft7MovJuibCPz5frB+U24qugh0w36O/h+6B1aI5NM1dQvBKxC4i+5SM9oIrCQUNTn H/dmTopar/f5PI2IoSV4eTMP+PS+Dh9yyg/OyxRsvEpINsEQd8cMvxDMYqEoXkByj6 BqDbTrKzfafpBuFBhS3XJy6nJ1yHE3BHKFZNuGMM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727964AbgBNWnf (ORCPT ); Fri, 14 Feb 2020 17:43:35 -0500 Received: from mail-oi1-f195.google.com ([209.85.167.195]:43094 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727951AbgBNWnd (ORCPT ); Fri, 14 Feb 2020 17:43:33 -0500 Received: by mail-oi1-f195.google.com with SMTP id p125so10951895oif.10; Fri, 14 Feb 2020 14:43:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RRK+etse5GdhzRRMSbN0AsTFv8NtL6Mf75PwYVcJU44=; b=ufV4By3kONxEZnyPWsfuV2Gp6foK6U9A7tSQdfSdzAel/6TDFgZw+/8/HBKXxffZd1 VSXS6wlcC5Vy3zpTHZVjrJN9R0R5VcUuErrWkvkORdP1gFCIltpDwTt0FeBF4NKSIm5e jCwbS+hrkea14hx1vctyT1k32qmWR65sRNuP9/oxQwxNDWSaHpD7HVJt71ZH/uZndGfn 7YIpH+TAofUj3kKsjTNErV1o6ZVG8pq4RuHml7rDUybEroKiC1fskapyJvlmWXbj697e oaPjFj6ykMoFCux0u9FDbtjN+0b7skh0K0gx2npo/sHvIqTEfKfGGwLDEPflr32EdaM1 1m9A== X-Gm-Message-State: APjAAAUk4xspchTzZNmxV0SMxD8P/pHscfcMpVtUrTKKHysPGLTjSols 2aZtRNnbRA80nYy5ZAyPNEERqDA= X-Google-Smtp-Source: APXvYqz909Fzl/Mv16+lZxspbsDGyoBiYnJJXHR2kdCOGJNisRMIBPTjbnRMOa+Vuf4buMe01/NvvA== X-Received: by 2002:aca:f0b:: with SMTP id 11mr3564215oip.34.1581720212297; Fri, 14 Feb 2020 14:43:32 -0800 (PST) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id m69sm2453167otc.78.2020.02.14.14.43.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2020 14:43:31 -0800 (PST) From: Rob Herring To: devicetree@vger.kernel.org, Frank Rowand Cc: linux-kernel@vger.kernel.org, Linus Walleij , Robin Murphy , Christoph Hellwig , Arnd Bergmann , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Michal Simek , Paul Mackerras Subject: [PATCH 7/7] of/address: Support multiple 'dma-ranges' entries Date: Fri, 14 Feb 2020 16:43:22 -0600 Message-Id: <20200214224322.20030-8-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214224322.20030-1-robh@kernel.org> References: <20200214224322.20030-1-robh@kernel.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Currently, the DMA offset and mask for a device are set based only on the first 'dma-ranges' entry. We should really be using all the entries. The kernel doesn't yet support multiple offsets and sizes, so the best we can do is to find the biggest size for a single offset. The algorithm is copied from acpi_dma_get_range(). If there's different offsets from the first entry, then we warn and continue. It really should be an error, but this will likely break existing DTs. Signed-off-by: Rob Herring --- drivers/of/address.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index a2c45812a50e..8eea3f6e29a4 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -944,6 +944,7 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz bool found_dma_ranges = false; struct of_range_parser parser; struct of_range range; + u64 dma_start = U64_MAX, dma_end = 0, dma_offset = 0; while (node) { ranges = of_get_property(node, "dma-ranges", &len); @@ -974,14 +975,33 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz pr_debug("dma_addr(%llx) cpu_addr(%llx) size(%llx)\n", range.bus_addr, range.cpu_addr, range.size); - *dma_addr = range.bus_addr; - *paddr = range.cpu_addr; - *size = range.size; + if (dma_offset && range.cpu_addr - range.bus_addr != dma_offset) { + pr_warn("Can't handle multiple dma-ranges with different offsets on node(%pOF)\n", node); + /* Don't error out as we'd break some existing DTs */ + continue; + } + dma_offset = range.cpu_addr - range.bus_addr; + + /* Take lower and upper limits */ + if (range.bus_addr < dma_start) + dma_start = range.bus_addr; + if (range.bus_addr + range.size > dma_end) + dma_end = range.bus_addr + range.size; + } + if (dma_start >= dma_end) { + ret = -EINVAL; + pr_debug("Invalid DMA ranges configuration on node(%pOF)\n", + node); goto out; } - pr_err("translation of DMA ranges failed on node(%pOF)\n", np); + *dma_addr = dma_start; + *size = dma_end - dma_start; + *paddr = dma_start + dma_offset; + + pr_debug("final: dma_addr(%llx) cpu_addr(%llx) size(%llx)\n", + *dma_addr, *paddr, *size); out: of_node_put(node);