Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6359515yba; Wed, 1 May 2019 10:40:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqzXkFi6KBo6FamydYWBUf64f1lJoxDjFGnGLvy7Uwun0CoBhr+pK/PvkpNKLiEGySwv5yzC X-Received: by 2002:a17:902:bf44:: with SMTP id u4mr6046109pls.171.1556732404964; Wed, 01 May 2019 10:40:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556732404; cv=none; d=google.com; s=arc-20160816; b=wBlPbpkKoX+gZ5zrdRM9GmvC4yTxpzOK9MQadrhkunBE0vlP43PiJAG3KTtfCol5mA 7HOy2GejcNIdlvTl21vBE5DuALX+JJxfnYNq0YyuJmRXXtAfBweOmEd80vknyCn79678 szOreECU3FA27wRjW+mC5WOnwGjBAKZJC5rpF7grPuBtygRJ97lR0fR1ygAMvGq8woDd WQK6Kr7cdHoy57zq3wwGuwOevCyFNbQihkr76GydgVRAmEEReYPBF4RQ1EWv9jD4NdH1 3qga8kc1cnAiPAk8njPO21byunckGxzcWnRC+Xi33KtbR4p+G4ECJjsYnqZH2uYegc6k moAw== 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=3xPTSPJw6iXFSiPTAFBwEzjmdm3DJtxn26MyBE7/ci4=; b=b5kziiDhzF5eSKidLDsyuDdiXC7oStbhMMWq/B+h+BzeV6PkWZBr4EPDbZ9ygrLG5K tOPC1CiXMTvgzzqJxFEXfXp2vYvahgPo3rBrRsMOVPh3nMBGzi1J4auX/6/GccNViEZe UtyBbUlsBFWcJZYyQ39m7n0YV+06kD8aqFSLP3uDhMBrsjd3Il0qnacWOE1edMWpH5As aiX5kwPHolc0l1Zg2/Cg+BAYg1EvhpNS1Z0K90h+314880FhVDtLgKUAIAre8EFoOsSp 9fGQY5NXzdrzj9jrTWDay8oPcjaMXEq93KkIddR3tanhE45Ui/A12VZkM0S8YgZ708+P LoJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=CVI1N4Bl; 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 q187si27491804pga.254.2019.05.01.10.39.49; Wed, 01 May 2019 10:40:04 -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=CVI1N4Bl; 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 S1726320AbfEARhM (ORCPT + 99 others); Wed, 1 May 2019 13:37:12 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:39795 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726019AbfEARhM (ORCPT ); Wed, 1 May 2019 13:37:12 -0400 Received: by mail-ed1-f68.google.com with SMTP id e24so4355057edq.6 for ; Wed, 01 May 2019 10:37:10 -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=3xPTSPJw6iXFSiPTAFBwEzjmdm3DJtxn26MyBE7/ci4=; b=CVI1N4BlG8HwXPhLobOU6JAKTbRtMIUjDK6ECuX9wHHKeV08OuvfPs7JCW/zhln6zx VeRfsSMzyuQzlAQP4XUJGGYxkwegvObFdmcJ7eXh2y4mdwktDgaPQY4+scz4a/eqMGMg IvcHOuRD+rxgwsloHSZJoKCD2uIgDL4cTg7Gg= 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=3xPTSPJw6iXFSiPTAFBwEzjmdm3DJtxn26MyBE7/ci4=; b=g44eSnWtz6gthASgp5UtYP/8RAdDh9CTk6C1JpJX0wAqvITPyHeCoM+VI+GCmQDfZ/ Tb0i7Wp3Ftoi2sVOmGhVtLj6Og61ByUnlp9gfow1m66h3u8mWQIMtO2V5023ybQPkTCJ DtlGb9QrjNFFz7xU10AeLeZMvv3ET+sA06KlEILg9JQIBmdemZVh92+Hkscob7z3tcpj T4RYRHR5Ol24FMys0ytPq6DOEmz/zQ/YDXS3CUQI4Y7StDaoQBOhdK2yWJTtUu+HNc5v EpZntm5weIl9LNoqFTf6WefzjgHubMvGTZPnCzDwr+Ov9+QHbtnD4zZVvQAYmGj0Mmqy sDog== X-Gm-Message-State: APjAAAWp9SgXdbhM+xcojjEohE0IHrYK2YM8IOpYaNoMufqS0pg9Cxnv vSBk6XN9nZvQmsCy0KV6KsMDJw== X-Received: by 2002:a17:906:49c4:: with SMTP id w4mr34032869ejv.0.1556732230217; Wed, 01 May 2019 10:37:10 -0700 (PDT) Received: from mannams-OptiPlex-7010.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id s6sm2462671eji.13.2019.05.01.10.37.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 May 2019 10:37:09 -0700 (PDT) From: Srinath Mannam To: Bjorn Helgaas , Robin Murphy , Eric Auger , 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 v5 2/3] iommu/dma: Reserve IOVA for PCIe inaccessible DMA address Date: Wed, 1 May 2019 23:06:25 +0530 Message-Id: <1556732186-21630-3-git-send-email-srinath.mannam@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556732186-21630-1-git-send-email-srinath.mannam@broadcom.com> References: <1556732186-21630-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 dma_ranges field of PCI host bridge structure has resource entries in sorted order of address range given through dma-ranges DT property. This list is the accessible DMA address range. So that this resource list will be processed and reserve IOVA address to the inaccessible address holes in the list. This method is similar to PCI IO resources address ranges reserving in IOMMU for each EP connected to host bridge. Signed-off-by: Srinath Mannam Based-on-patch-by: Oza Pawandeep Reviewed-by: Oza Pawandeep Acked-by: Robin Murphy --- drivers/iommu/dma-iommu.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 77aabe6..da94844 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -212,6 +212,7 @@ static void iova_reserve_pci_windows(struct pci_dev *dev, struct pci_host_bridge *bridge = pci_find_host_bridge(dev->bus); struct resource_entry *window; unsigned long lo, hi; + phys_addr_t start = 0, end; resource_list_for_each_entry(window, &bridge->windows) { if (resource_type(window->res) != IORESOURCE_MEM) @@ -221,6 +222,24 @@ static void iova_reserve_pci_windows(struct pci_dev *dev, hi = iova_pfn(iovad, window->res->end - window->offset); reserve_iova(iovad, lo, hi); } + + /* Get reserved DMA windows from host bridge */ + resource_list_for_each_entry(window, &bridge->dma_ranges) { + end = window->res->start - window->offset; +resv_iova: + if (end - start) { + lo = iova_pfn(iovad, start); + hi = iova_pfn(iovad, end); + reserve_iova(iovad, lo, hi); + } + start = window->res->end - window->offset + 1; + /* If window is last entry */ + if (window->node.next == &bridge->dma_ranges && + end != ~(dma_addr_t)0) { + end = ~(dma_addr_t)0; + goto resv_iova; + } + } } static int iova_reserve_iommu_regions(struct device *dev, -- 2.7.4