Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4868744imm; Tue, 9 Oct 2018 06:31:09 -0700 (PDT) X-Google-Smtp-Source: ACcGV618sTMzTwJsN5TtYsVocsLjkWTsWsDTiFIFNddYpEx1PByrdKGlQ3yi0Ho9ZsOF76DRwSHn X-Received: by 2002:a17:902:70c3:: with SMTP id l3-v6mr28500448plt.185.1539091869158; Tue, 09 Oct 2018 06:31:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539091869; cv=none; d=google.com; s=arc-20160816; b=CU2ggD3EYUdB2MoAyFXGW2/9KtO64L6jhGoli6zglHEVeyv3elYmiWWbNOdZFtOBx4 Efx8PnVGwkYqh7aEpjP+0UVvgkP6pCn0PSb+UjMdMKC5ui9Lhlt8AkiWZLx0Ka88JHl5 C61orPP2AYAR9VPAQlrCKfxS6ZlCSdTpSAk5oboZbcOgbeVd9y2azXxtuc0CyKZXcAyk 78KxtDSGMkH60jcs9W35DiQP95ZV/Hd/dxX2xK8clyVbEcX0uaqpuT7MnWtILMcjlyud GzZn0fWZqV0yV3Xaw2IO8LsDf/bBZSpTytf/FyO70bWMmltcwP/KXtx/80A6WYu+MF9R 45tw== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iBezZyCUYUHpLQ5Y3LKMHLLyBboeGujJBJLf+LkXLnA=; b=z0CN9+dR9kpVro9Dbb+KIna68cHkgRQIOxoxF0T92suIiwuU4+pWWdVo2aUgRR0Zdd GS8MWuizA6vZ1neeXYaYM9qogwK2Lb7T8cl/0KM1zZUR+PUGN5hzfzbbCjaLweCuShTQ fmVEYdyLNRzqDsq+yfgUGPVTcFJIFTkuah13MsLqIkIvxltvFGrsZ4ztJk7IgQHxIopb Pom05Zyelm7bKwQsmvvcMPdC9BF+osH22e3r1Gnqz1lHVT2/yDgYvl62VrV3uoGtTCky kLzhtbrx3k2rgQSse7t2ePLuLZP4KyRpKCxzbAHOE/9wSxIp/awIgj7UrhjmyaorzUwY CIRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=bUOPlX+g; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j12-v6si17671392pgq.57.2018.10.09.06.30.54; Tue, 09 Oct 2018 06:31:09 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=bUOPlX+g; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727398AbeJIUnH (ORCPT + 99 others); Tue, 9 Oct 2018 16:43:07 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:49430 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727374AbeJIUnG (ORCPT ); Tue, 9 Oct 2018 16:43:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=iBezZyCUYUHpLQ5Y3LKMHLLyBboeGujJBJLf+LkXLnA=; b=bUOPlX+gR0aQqEckjE1Q7voPc7 eecdKM5E0BO906GDTzCM3rqqcTN6BOkXIAOMyKwQPyZbDLrgLyMGNse2JOecBVfX1HhaCcbNgRaIl QDuKmcTcS6M5lgAGvhULYVhYiprSq+CbYf9PwBIxpgTqKkjCplgda9p8uYkjUODiqhudnDExjCrIw jSfSAZlQ/wTzU4XpmHSPD0zD4zHNyz+LaUQPGwCmW31N2bd1ZmZ8jQoU+bpj7hDeal+5RFPDCdxp0 TgvkuIyayUdvtSsE5KEWaE1EbLHTmn6jrFt17PWtH//et0xf9DvCyppJPf22sAWbrtk/6dYFR4Iyh kdEcNwbA==; Received: from clnet-p19-102.ikbnet.co.at ([83.175.77.102] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9s1A-0001Fg-FM; Tue, 09 Oct 2018 13:25:44 +0000 From: Christoph Hellwig To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linuxppc-dev@lists.ozlabs.org, iommu@lists.linux-foundation.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 17/33] powerpc/powernv: use the generic iommu bypass code Date: Tue, 9 Oct 2018 15:24:44 +0200 Message-Id: <20181009132500.17643-18-hch@lst.de> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181009132500.17643-1-hch@lst.de> References: <20181009132500.17643-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the generic iommu bypass code instead of overriding set_dma_mask. Signed-off-by: Christoph Hellwig --- arch/powerpc/platforms/powernv/pci-ioda.c | 92 ++++++----------------- 1 file changed, 25 insertions(+), 67 deletions(-) diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c index b6db65917bb4..5748b62e2e86 100644 --- a/arch/powerpc/platforms/powernv/pci-ioda.c +++ b/arch/powerpc/platforms/powernv/pci-ioda.c @@ -1739,86 +1739,45 @@ static int pnv_pci_ioda_dma_64bit_bypass(struct pnv_ioda_pe *pe) return -EIO; } -static int pnv_pci_ioda_dma_set_mask(struct pci_dev *pdev, u64 dma_mask) +static bool pnv_pci_ioda_iommu_bypass_supported(struct pci_dev *pdev, + u64 dma_mask) { struct pci_controller *hose = pci_bus_to_host(pdev->bus); struct pnv_phb *phb = hose->private_data; struct pci_dn *pdn = pci_get_pdn(pdev); struct pnv_ioda_pe *pe; - uint64_t top; - bool bypass = false; - s64 rc; if (WARN_ON(!pdn || pdn->pe_number == IODA_INVALID_PE)) return -ENODEV; pe = &phb->ioda.pe_array[pdn->pe_number]; if (pe->tce_bypass_enabled) { - top = pe->tce_bypass_base + memblock_end_of_DRAM() - 1; - bypass = (dma_mask >= top); + u64 top = pe->tce_bypass_base + memblock_end_of_DRAM() - 1; + if (dma_mask >= top) + return true; } - if (bypass) { - dev_info(&pdev->dev, "Using 64-bit DMA iommu bypass\n"); - set_dma_ops(&pdev->dev, &dma_nommu_ops); - } else { - /* - * If the device can't set the TCE bypass bit but still wants - * to access 4GB or more, on PHB3 we can reconfigure TVE#0 to - * bypass the 32-bit region and be usable for 64-bit DMAs. - * The device needs to be able to address all of this space. - */ - if (dma_mask >> 32 && - dma_mask > (memory_hotplug_max() + (1ULL << 32)) && - /* pe->pdev should be set if it's a single device, pe->pbus if not */ - (pe->device_count == 1 || !pe->pbus) && - phb->model == PNV_PHB_MODEL_PHB3) { - /* Configure the bypass mode */ - rc = pnv_pci_ioda_dma_64bit_bypass(pe); - if (rc) - return rc; - /* 4GB offset bypasses 32-bit space */ - set_dma_offset(&pdev->dev, (1ULL << 32)); - set_dma_ops(&pdev->dev, &dma_nommu_ops); - } else if (dma_mask >> 32 && dma_mask != DMA_BIT_MASK(64)) { - /* - * Fail the request if a DMA mask between 32 and 64 bits - * was requested but couldn't be fulfilled. Ideally we - * would do this for 64-bits but historically we have - * always fallen back to 32-bits. - */ - return -ENOMEM; - } else { - dev_info(&pdev->dev, "Using 32-bit DMA via iommu\n"); - set_dma_ops(&pdev->dev, &dma_iommu_ops); - } + /* + * If the device can't set the TCE bypass bit but still wants + * to access 4GB or more, on PHB3 we can reconfigure TVE#0 to + * bypass the 32-bit region and be usable for 64-bit DMAs. + * The device needs to be able to address all of this space. + */ + if (dma_mask >> 32 && + dma_mask > (memory_hotplug_max() + (1ULL << 32)) && + /* pe->pdev should be set if it's a single device, pe->pbus if not */ + (pe->device_count == 1 || !pe->pbus) && + phb->model == PNV_PHB_MODEL_PHB3) { + /* Configure the bypass mode */ + s64 rc = pnv_pci_ioda_dma_64bit_bypass(pe); + if (rc) + return rc; + /* 4GB offset bypasses 32-bit space */ + set_dma_offset(&pdev->dev, (1ULL << 32)); + return true; } - *pdev->dev.dma_mask = dma_mask; - return 0; -} - -static u64 pnv_pci_ioda_dma_get_required_mask(struct pci_dev *pdev) -{ - struct pci_controller *hose = pci_bus_to_host(pdev->bus); - struct pnv_phb *phb = hose->private_data; - struct pci_dn *pdn = pci_get_pdn(pdev); - struct pnv_ioda_pe *pe; - u64 end, mask; - - if (WARN_ON(!pdn || pdn->pe_number == IODA_INVALID_PE)) - return 0; - - pe = &phb->ioda.pe_array[pdn->pe_number]; - if (!pe->tce_bypass_enabled) - return __dma_get_required_mask(&pdev->dev); - - - end = pe->tce_bypass_base + memblock_end_of_DRAM(); - mask = 1ULL << (fls64(end) - 1); - mask += mask - 1; - - return mask; + return false; } static void pnv_ioda_setup_bus_dma(struct pnv_ioda_pe *pe, @@ -3456,6 +3415,7 @@ static void pnv_pci_ioda_shutdown(struct pci_controller *hose) static const struct pci_controller_ops pnv_pci_ioda_controller_ops = { .dma_dev_setup = pnv_pci_dma_dev_setup, .dma_bus_setup = pnv_pci_dma_bus_setup, + .iommu_bypass_supported = pnv_pci_ioda_iommu_bypass_supported, #ifdef CONFIG_PCI_MSI .setup_msi_irqs = pnv_setup_msi_irqs, .teardown_msi_irqs = pnv_teardown_msi_irqs, @@ -3465,8 +3425,6 @@ static const struct pci_controller_ops pnv_pci_ioda_controller_ops = { .window_alignment = pnv_pci_window_alignment, .setup_bridge = pnv_pci_setup_bridge, .reset_secondary_bus = pnv_pci_reset_secondary_bus, - .dma_set_mask = pnv_pci_ioda_dma_set_mask, - .dma_get_required_mask = pnv_pci_ioda_dma_get_required_mask, .shutdown = pnv_pci_ioda_shutdown, }; -- 2.19.0