Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp680303imu; Thu, 13 Dec 2018 02:35:55 -0800 (PST) X-Google-Smtp-Source: AFSGD/UnNTmZGSMxJKLUf+S3LJdw3iv7G5ouRCGXRvbz2jkCmahoy5Mr7O4aRzX/L5MVihbsHRMR X-Received: by 2002:a17:902:9a98:: with SMTP id w24mr23250377plp.213.1544697354952; Thu, 13 Dec 2018 02:35:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544697354; cv=none; d=google.com; s=arc-20160816; b=ySIZTJzpQ8zT60Mq+cwOcVXzcIlO+PwSIzC22uwU//rxkWn21jNOy6qtMYpaOR3D/r 2Nk2Rb+pTy5XKjbG7J6C5HsXvOd2Adfe49Gmgcrk6JbM0XkuDtP8sOeTP/HkM+xwsbf9 B18HzinpiXD5rbKVPOoUPKKDLSRcvpUi+shhGkYde8BHob5i0h8jIsFpKyFfzkbKRqns iX6KFRwH36R8MkMTfw2cFi9bKZbfxnYJ08E1c6AhIJHhUbk+9Zudmj+KLquGSaiEYJrK y6ronNGIA9g4sRY5B4DxPNoF7W3fs7OkX4pabiLEVpUqBru15A2MogmR/TgC+9fqhxQ/ uk6Q== 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=KsLuq/w2+4wqAK3w1JgIljoenhpHR4ZyQN2xHQt5mAo=; b=Um2jH27yv2ioLdjDzM2QfvteSiAAivmn4AWlaU+Xv3pwU77ePxWhHhJfJIPDoKinK7 Tw8K3qEgunYbUCMIZp4deTzpiHBafXOouwr9aG0qn89lhy+upqGqEdvQ6PLpAcoz3fDm vbaggPYPj3jgsqSf26AocObzLruXFnrf68X9u2nzp1hLbyVZp4FRjgH4RQA6U9wOt1Lc tTMaU5SZUdXzk/AJVUhMfpx23/+G9TKqdHajYTG9xQQynJ8VwrlQqHp0nhGxJHXzVGPh 8MTQ3W6fXWCMBq7G1e177kJ9HiTsWGLC28bDTGgmxU/4FidulPSq4RDeosOmbZ8E15iA MSSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=BuYqOYAG; 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 f13si1329523plm.393.2018.12.13.02.35.40; Thu, 13 Dec 2018 02:35:54 -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=BuYqOYAG; 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 S1728659AbeLMKdc (ORCPT + 99 others); Thu, 13 Dec 2018 05:33:32 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:34433 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727374AbeLMKdb (ORCPT ); Thu, 13 Dec 2018 05:33:31 -0500 Received: by mail-wr1-f67.google.com with SMTP id j2so1457118wrw.1 for ; Thu, 13 Dec 2018 02:33:30 -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=KsLuq/w2+4wqAK3w1JgIljoenhpHR4ZyQN2xHQt5mAo=; b=BuYqOYAGhory4gRz4+f3zZ1cpevXvNvZRNWlLzPUD53iF/w8IlaDeHT0wOw3Vplr10 6WUvAg/kMiKqusZhcf9IU0jadnGSg4OflOBOPghzbU3NISvlQNgUpSKLZQ7ybqK/VRd0 BraSgBOqy1xDUlmAwu2nFtf7JJTravNmW8z6g= 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=KsLuq/w2+4wqAK3w1JgIljoenhpHR4ZyQN2xHQt5mAo=; b=OhTVHAPR3167artrvAwNP8k3cmR+y9YFjH806/vp+uDdXLE0x+2YIQJkY4HlU06IwL o2SM1PQyiDfiPsXKVTI+aIvW0kZJpoD3xdqIcO6UMB33SFMQSoV4GFq8Z05mK98eY8is VvhfsH+lg+wIUfDNyWp916+wxaFOEUrBN/pXEKze8CzeCB9JxFnTMMA55IsHLcOivnBE aF2HjNWf76fSr/nwXrCRjjqlqi74WtOnL4JoPSzQpE5QPNc+BaHtI93riXyrdL/BP7Fi 1wYNlICwPWEglDqczZYRAM5BPyrr9PCJCG9ZqGdK/McYaK+t6i6Hs4J2BpPLtagY2mth 4CBg== X-Gm-Message-State: AA+aEWa1m9UoPEE92b95zgcv2YIQ6eXUytwEoBFBxkD1A82FfiNwhYt3 qmLQU7qGGUz5RsCX0kBt8PZBfQ== X-Received: by 2002:adf:84e4:: with SMTP id 91mr20254748wrg.237.1544697209674; Thu, 13 Dec 2018 02:33:29 -0800 (PST) Received: from mannams-OptiPlex-7010.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id x76sm3327058wmd.27.2018.12.13.02.33.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Dec 2018 02:33:28 -0800 (PST) From: Srinath Mannam To: Bjorn Helgaas , Robin Murphy , poza@codeaurora.org, Joerg Roedel , Lorenzo Pieralisi , 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 v2 3/3] PCI: iproc: Add dma reserve resources to host Date: Thu, 13 Dec 2018 16:02:54 +0530 Message-Id: <1544697174-6029-4-git-send-email-srinath.mannam@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544697174-6029-1-git-send-email-srinath.mannam@broadcom.com> References: <1544697174-6029-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 --- 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 3160e93..636e92d 100644 --- a/drivers/pci/controller/pcie-iproc.c +++ b/drivers/pci/controller/pcie-iproc.c @@ -1154,25 +1154,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