Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4722684yba; Tue, 30 Apr 2019 03:21:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwAUleRw6X3SmZ8nGty5LDGjwWuzxmJ1Ak1lQ1kV3S0vGxXcuAbMNyVJP69jVss2Qjy47tp X-Received: by 2002:a62:a503:: with SMTP id v3mr37336557pfm.32.1556619682927; Tue, 30 Apr 2019 03:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556619682; cv=none; d=google.com; s=arc-20160816; b=V35eUqZXzH125SyW4Oe7iEHWt1NZOl5IVsxYjBjADbKCXnibIkVSnC5iBT7CZFiAqf J1XQKPSjaSeKsfTd2Mjx6cdWGy92kjw45fsTlFotk2dY2yTnZKHOhpBi4IdOW2tTEtGs 1PCIgeCUbNGQVGHacpV5iXXAKSzcER+MRJzWqbigsnXeAjgt+XP6jRQDenDPZxrvhQEw 29/pNGf4YOnoCYgxbDpOzKN3uR24piEYqm1NJ2XzJbJ9vtSqXYy9x1yZI/pwqQnbnDVV iGoYyJTf+eMRPTMtWqThzEihcyYGIuVtQJZbzr2ypjAhj+NU84P91T55d4Lz0BG9ej/8 iacA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=cpz8RmT8DqpjC+m1s5hSxJN0GnnYj+n7TJ0HvtimYMI=; b=kcloE12dgRH7c71GE4udoboei97h5gYxU2unJ3WBHBzym4TKXWbAAERnFPIkchJCzE INSXDQBKHnUGc5vjfKy0bB5GAvxUTdRNqumgx1QbXXRgATt63RFN0jqtFEgMWqS2thrh TJjS0N68lcYKbo4I5D0ms3YiKZFju10scte9YPf+jmUY0KP8er0AAdssxgVovXkAnX+b syXWTimrFhhK4pWpJjev+J5Rqrg95TqDENJOIFqWD6MYQGvHYriEfGqMc9KA2SSP/bxK GdOzVrMzEz0XkTSi3fB+9jDO1ZfJTJuL2gpKjHHPIBBHlrvb/Sen4oegntm/MkkotkTX pAFA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t16si20243474pgl.97.2019.04.30.03.21.06; Tue, 30 Apr 2019 03:21:22 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727218AbfD3KTx (ORCPT + 99 others); Tue, 30 Apr 2019 06:19:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42712 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726145AbfD3KTx (ORCPT ); Tue, 30 Apr 2019 06:19:53 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 678E185360; Tue, 30 Apr 2019 10:19:52 +0000 (UTC) Received: from [10.36.116.17] (ovpn-116-17.ams2.redhat.com [10.36.116.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A57386152B; Tue, 30 Apr 2019 10:19:48 +0000 (UTC) Subject: Re: [PATCH v4 3/3] PCI: iproc: Add sorted dma ranges resource entries to host bridge To: Srinath Mannam , 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 References: <1555038815-31916-1-git-send-email-srinath.mannam@broadcom.com> <1555038815-31916-4-git-send-email-srinath.mannam@broadcom.com> From: Auger Eric Message-ID: <53a7463f-0b31-42ad-96a1-a3f40f02b119@redhat.com> Date: Tue, 30 Apr 2019 12:19:47 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <1555038815-31916-4-git-send-email-srinath.mannam@broadcom.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 30 Apr 2019 10:19:52 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Srinath, On 4/12/19 5:13 AM, Srinath Mannam wrote: > 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. s/add added/and added > > 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. s/to use/to be used > > 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, > Reviewed-by: Eric Auger Thanks Eric