Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp287036imu; Fri, 25 Jan 2019 02:16:24 -0800 (PST) X-Google-Smtp-Source: ALg8bN5sh7ER+pSJMe+DWET9ephD+mDAqWOFeJ8ue/YwnBrZS6T/xDtUhgXCjZvdLApzZC1kl+Si X-Received: by 2002:a63:7d06:: with SMTP id y6mr9331129pgc.171.1548411383957; Fri, 25 Jan 2019 02:16:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548411383; cv=none; d=google.com; s=arc-20160816; b=u4uel7E9Wsrrngc3xyUGiBTHFiuAawnDEG1lAV0g8Dx2FklYnJJLfso+yPTEZlUxeJ 3XfTBHsOXYaebz6C1/SOXGfoCHHu8gFhY1dPhMZ55fu16wk2BBL1JZte43WZ2pnq2umD JjyxQjIIvhu4mS5/BHtXBZTtXEbuwLwb2cL1TRbA23V9ar+HAl0M2ojd7nTG0vjnq5xb EElve8lj31o7PoTALt1knuoPYOepFnyAPL1YJiA0JXqGDKaUwVOnBXAkTX2BCr/DfIE/ 6xdt0YpDfqnI1uKDd+kCSYp61n7tFYoEeOVGjtGsgzagnD7FYkyINCYu+rjlaVTwrCGM nMFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=aQQQit55QHmXJGswuIk2GPbriFh4OnO1XEAJH5iCl+Q=; b=FKV0XqVHzToSWO1XDZ/9OMVXvR62idwMlYrVL2Z8S5J8ysXuQUtVVpsfLSrxHy2lFV +qWNNqXZapiKLlZltNfvhwFLk0DUlHekk6fDwtsngHfxChR2HuUCwYpWfjNko7fWr0HB QXwG74Zie/T1jJhNTqMG/zYcIZHetOD8M9IorFKAzePgfAlhvRJ/TyoP/SD9Y0sLv2Nl Fd8xePAEE3wWo8ALl73sTxZ6Fr68XlGCqOwg3JNX3LawppER+fHJNcvsP6bt5tnjuS/2 2nlX1XVCfv9+fOQ7R8ON2C8TJMokDctwZDq0iohcMCFk9BggVhUDYYxzGaqtnA++cTwE jsww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=Walw7LEm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id be9si25074221plb.143.2019.01.25.02.16.08; Fri, 25 Jan 2019 02:16:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=Walw7LEm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729302AbfAYKOU (ORCPT + 99 others); Fri, 25 Jan 2019 05:14:20 -0500 Received: from mail-yb1-f195.google.com ([209.85.219.195]:37079 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728047AbfAYKOT (ORCPT ); Fri, 25 Jan 2019 05:14:19 -0500 Received: by mail-yb1-f195.google.com with SMTP id 2so3613206ybw.4 for ; Fri, 25 Jan 2019 02:14:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aQQQit55QHmXJGswuIk2GPbriFh4OnO1XEAJH5iCl+Q=; b=Walw7LEmrY78/PaXGY6jSqrM8c54p67KPHDtUSooLKJuYtwU7JMxagTyaq7ukxU+/2 MrRHR1Ypi+ofX4HJSEuvNLO0+KdgPVktntpdPyW8nNPoTLc2QwZ1fh/h9gjefDYKgmto 6z9Clk39QInS9bM9kjuCJuEnidP5cOjsNPkIc= 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; bh=aQQQit55QHmXJGswuIk2GPbriFh4OnO1XEAJH5iCl+Q=; b=nNlAf6kdVnEe5PdW4hjJuYAN7zN3WOhsXAoRHXiXXR7sm/x/TNMr7OCqVUf7YFjfAt woQX7ftY0mK7tWTtPnMQAaBjYtSBgr/jYQd/BNA9G+AcOiGxFXnlSpD/qcr1BEdBI1U1 Jg3KKWuHfDe9s/epW5QkCSk2xYM5U8xA6Z6X/b5JMpI0HIbl0Gru286AhumdgubeWpTw ivXSHwETbfGgzlALFh321XRfSqqGqopD1pP7AwmSNifrawoEVpsKIUjsEmQGtRNhs135 BGf8MdEqs4p5zy/Rs4xxoW9CbNt3db5dlr7+CkZNU4V8b99/swxYk3M3C9suarn2OauJ lDfA== X-Gm-Message-State: AJcUukdWsJkPHP24G7HmUMRe0I5SzAWdZ9s4O8IZgLqLupukfC3YYAmQ UvQuRghFQDatwZH53kJpI0LcAQ== X-Received: by 2002:a25:3852:: with SMTP id f79mr9926521yba.139.1548411258338; Fri, 25 Jan 2019 02:14:18 -0800 (PST) Received: from mannams-OptiPlex-7010.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id x203sm11868695ywd.41.2019.01.25.02.14.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 25 Jan 2019 02:14:17 -0800 (PST) From: Srinath Mannam To: Bjorn Helgaas , Robin Murphy , Joerg Roedel , Lorenzo Pieralisi , poza@codeaurora.org, Ray Jui Cc: bcm-kernel-feedback-list@broadcom.com, linux-pci@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Srinath Mannam Subject: [PATCH v3 3/3] PCI: iproc: Add dma reserve resources to host Date: Fri, 25 Jan 2019 15:43:51 +0530 Message-Id: <1548411231-27549-4-git-send-email-srinath.mannam@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548411231-27549-1-git-send-email-srinath.mannam@broadcom.com> References: <1548411231-27549-1-git-send-email-srinath.mannam@broadcom.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org IPROC host has the limitation that it can use only those address ranges given by dma-ranges property as inbound address. So that the memory address holes in dma-ranges should be reserved to allocate as DMA address. Inbound address of host accessed by PCIe devices will not be translated before it comes to IOMMU or directly to PE. But the limitation of this host is, access to few address ranges are ignored. So that IOVA ranges for these address ranges have to be reserved. All such addresses ranges are created as resource entries by parsing dma-ranges DT parameter and add to dma_resv list of PCI host bridge. Ex: dma-ranges = < \ 0x43000000 0x00 0x80000000 0x00 0x80000000 0x00 0x80000000 \ 0x43000000 0x08 0x00000000 0x08 0x00000000 0x08 0x00000000 \ 0x43000000 0x80 0x00000000 0x80 0x00000000 0x40 0x00000000> In the above example of dma-ranges, memory address from 0x0 - 0x80000000, 0x100000000 - 0x800000000, 0x1000000000 - 0x8000000000 and 0x10000000000 - 0xffffffffffffffff. are not allowed to use as inbound addresses. So that we need to add these address ranges to dma_resv list to reserve corresponding IOVA address ranges. Signed-off-by: Srinath Mannam Based-on-patch-by: Oza Pawandeep Reviewed-by: Oza Pawandeep --- drivers/pci/controller/pcie-iproc.c | 51 ++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/pcie-iproc.c b/drivers/pci/controller/pcie-iproc.c index c20fd6b..b7bef1c 100644 --- a/drivers/pci/controller/pcie-iproc.c +++ b/drivers/pci/controller/pcie-iproc.c @@ -1146,25 +1146,74 @@ static int iproc_pcie_setup_ib(struct iproc_pcie *pcie, return ret; } +static int +iproc_pcie_add_dma_resv_range(struct device *dev, struct list_head *resources, + uint64_t start, uint64_t end) +{ + struct resource *res; + + res = devm_kzalloc(dev, sizeof(struct resource), GFP_KERNEL); + if (!res) + return -ENOMEM; + + res->start = (resource_size_t)start; + res->end = (resource_size_t)end; + pci_add_resource_offset(resources, res, 0); + + return 0; +} + static int iproc_pcie_map_dma_ranges(struct iproc_pcie *pcie) { + struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie); struct of_pci_range range; struct of_pci_range_parser parser; int ret; + uint64_t start, end; + LIST_HEAD(resources); /* Get the dma-ranges from DT */ ret = of_pci_dma_range_parser_init(&parser, pcie->dev->of_node); if (ret) return ret; + start = 0; for_each_of_pci_range(&parser, &range) { + end = range.pci_addr; + /* dma-ranges list expected in sorted order */ + if (end < start) { + ret = -EINVAL; + goto out; + } /* Each range entry corresponds to an inbound mapping region */ ret = iproc_pcie_setup_ib(pcie, &range, IPROC_PCIE_IB_MAP_MEM); if (ret) - return ret; + goto out; + + if (end - start) { + ret = iproc_pcie_add_dma_resv_range(pcie->dev, + &resources, + start, end); + if (ret) + goto out; + } + start = range.pci_addr + range.size; } + end = DMA_BIT_MASK(sizeof(dma_addr_t) * BITS_PER_BYTE); + if (end - start) { + ret = iproc_pcie_add_dma_resv_range(pcie->dev, &resources, + start, end); + if (ret) + goto out; + } + + list_splice_init(&resources, &host->dma_resv); + return 0; +out: + pci_free_resource_list(&resources); + return ret; } static int iproce_pcie_get_msi(struct iproc_pcie *pcie, -- 2.7.4