Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3027yba; Thu, 11 Apr 2019 20:15:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxbUmBiwuqDCPDLb+xLh/oUL3XI5qQhgtP88XByeYsrK+0IzEMzPA60HKmU7QTlW4clQsT2 X-Received: by 2002:a62:12c9:: with SMTP id 70mr54575537pfs.156.1555038957131; Thu, 11 Apr 2019 20:15:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555038957; cv=none; d=google.com; s=arc-20160816; b=vuOcEkTfGd/BRun4PTUiLI8LckTYE4nCNbEj8HjXcSBiLcoBqagNoVLdQa+cACK00K p6TDF8/NU0s8lP6jfVImgEEsQnRko3iPG8BeUsi5o//cHW7eMiBCDL4t5kUbv9LAHQMy FPoSO7ysinsyF9n/zyrs/zAa8po5jvgfB0WHlcrHeHUfGx1Noyc5oIvkYw+HH5m1fZdN wK7X4JtqD1DSGKwG3h+c+87ngckABNiujXcKgw0LUW6g4jKA71BE1AqBJYHPq0TGtnjn ZKgOcY/oIO2j9E5ENdf7Wl7I+39SDNCYYxqNM2S9FS8A123VKFzir+yNb8uQh4aNF9TZ DdsQ== 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=GbNAXqps9xM35Y1qLf6z4pd1dBjGUVG8C9gvux3yeDo=; b=Q6Q+O21a/706Y3E9Uee/NFT/yCvTDAnd5FgkRgQa68023pch7xOgZVplCIOJIOicDF 8aXl23/ByMGx3NhySwNZ2jzAcWSzsbtley9yqUwYdHkJU6sL5XcVVVZQODLv7LWrmXsu BV1aoLJTvDevn8/yDXPsNqiUASuww/z+BpIDHcToj5JhuikpCSxYEc9oI5LBOZHXxkh0 VJUUNeIupOB8VfzYgDTn12eqBPg9WYmxpmJiE+zkCN4HBfQMV6FDlCjxV4yYGqFHOylq RAVWbByRyxR16WX/bcsxqeImT/NyIRm4MUjJLcDfCMWUckRHqxxOX+QDO2whUrjyJCOx d+pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=S0wLQlRQ; 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 q22si29655084pll.365.2019.04.11.20.15.41; Thu, 11 Apr 2019 20:15:57 -0700 (PDT) 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=S0wLQlRQ; 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 S1726925AbfDLDOM (ORCPT + 99 others); Thu, 11 Apr 2019 23:14:12 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:43292 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726905AbfDLDOM (ORCPT ); Thu, 11 Apr 2019 23:14:12 -0400 Received: by mail-ed1-f66.google.com with SMTP id w3so7007771edu.10 for ; Thu, 11 Apr 2019 20:14:11 -0700 (PDT) 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=GbNAXqps9xM35Y1qLf6z4pd1dBjGUVG8C9gvux3yeDo=; b=S0wLQlRQCoHmNALe9CEPyuUjxW8z6XNQk5U5Qa73DDhJc3MnjrlO062YSZPzKc6SQj MiMxfhnzgrfV1b6/wmTVu1D6Rbs8TOabN3fQyCsWo4y8J1fhiHH1m0ykhKdS9pHOBIMo cjFD3wv2x1JSQxhHbdgnMzf0Bvaqdl8ViTF6M= 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=GbNAXqps9xM35Y1qLf6z4pd1dBjGUVG8C9gvux3yeDo=; b=UQoh3QiAQR4Ek3qmxTi0DbyfqRer+KMkXlgFq5XfQarrelk1IDCF4CSMvx/fe92rWT KDfmXh5rcrZ76bny3GcD4Rt+DDUK6zbVVDRFaR8IT3HRNV65Pvc9RDN35AtZ2p/M7XCZ 4SO7JrOsaWDQCTSvp7r/tJ8BXFWX/E8rjPDcjjmT29TY3Ex1q6HdONm/FjwtlNmndRyK ZPqu8XxQ8Z7xQtq8J3adphe4HFRAaicWKcBIThQ4pt3ptYemiYXZzQ4YHLl7UIbkIl4C pzwUdAazBtmsyn9Aulv8LlxtPR5607ZPrurMg803guXXj2U9rNJuJpaQPSY6Hy074H9J KJUw== X-Gm-Message-State: APjAAAWFwaSdv1o2k8ZgOrJ67r4uu6TDtRNsKt1z+85pC70EYPPbLwa+ WkRq3/tAmAgdf88exOzSIlCEAg== X-Received: by 2002:a17:906:6a12:: with SMTP id o18mr29919543ejr.204.1555038850344; Thu, 11 Apr 2019 20:14:10 -0700 (PDT) Received: from mannams-OptiPlex-7010.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id c7sm11533352edt.70.2019.04.11.20.14.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Apr 2019 20:14:09 -0700 (PDT) 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 v4 3/3] PCI: iproc: Add sorted dma ranges resource entries to host bridge Date: Fri, 12 Apr 2019 08:43:35 +0530 Message-Id: <1555038815-31916-4-git-send-email-srinath.mannam@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1555038815-31916-1-git-send-email-srinath.mannam@broadcom.com> References: <1555038815-31916-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 allowed address ranges are listed in dma-ranges DT parameter. These address ranges are converted as resource entries and listed in sorted order add added to dma_ranges list of PCI host bridge structure. 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. Signed-off-by: Srinath Mannam Based-on-patch-by: Oza Pawandeep Reviewed-by: Oza Pawandeep --- drivers/pci/controller/pcie-iproc.c | 44 ++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/pcie-iproc.c b/drivers/pci/controller/pcie-iproc.c index c20fd6b..94ba5c0 100644 --- a/drivers/pci/controller/pcie-iproc.c +++ b/drivers/pci/controller/pcie-iproc.c @@ -1146,11 +1146,43 @@ static int iproc_pcie_setup_ib(struct iproc_pcie *pcie, return ret; } +static int +iproc_pcie_add_dma_range(struct device *dev, struct list_head *resources, + struct of_pci_range *range) +{ + struct resource *res; + struct resource_entry *entry, *tmp; + struct list_head *head = resources; + + res = devm_kzalloc(dev, sizeof(struct resource), GFP_KERNEL); + if (!res) + return -ENOMEM; + + resource_list_for_each_entry(tmp, resources) { + if (tmp->res->start < range->cpu_addr) + head = &tmp->node; + } + + res->start = range->cpu_addr; + res->end = res->start + range->size - 1; + + entry = resource_list_create_entry(res, 0); + if (!entry) + return -ENOMEM; + + entry->offset = res->start - range->cpu_addr; + resource_list_add(entry, head); + + 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; + LIST_HEAD(resources); /* Get the dma-ranges from DT */ ret = of_pci_dma_range_parser_init(&parser, pcie->dev->of_node); @@ -1158,13 +1190,23 @@ static int iproc_pcie_map_dma_ranges(struct iproc_pcie *pcie) return ret; for_each_of_pci_range(&parser, &range) { + ret = iproc_pcie_add_dma_range(pcie->dev, + &resources, + &range); + if (ret) + 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; } + list_splice_init(&resources, &host->dma_ranges); + return 0; +out: + pci_free_resource_list(&resources); + return ret; } static int iproce_pcie_get_msi(struct iproc_pcie *pcie, -- 2.7.4