From patchwork Fri May 29 17:14:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wdavis@nvidia.com X-Patchwork-Id: 477998 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3B707140F9B for ; Sat, 30 May 2015 03:28:16 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756151AbbE2R2P (ORCPT ); Fri, 29 May 2015 13:28:15 -0400 Received: from hqemgate15.nvidia.com ([216.228.121.64]:10299 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756191AbbE2R2O (ORCPT ); Fri, 29 May 2015 13:28:14 -0400 Received: from hqnvupgp08.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com id ; Fri, 29 May 2015 10:28:13 -0700 Received: from HQMAIL107.nvidia.com ([172.20.12.94]) by hqnvupgp08.nvidia.com (PGP Universal service); Fri, 29 May 2015 10:24:47 -0700 X-PGP-Universal: processed; by hqnvupgp08.nvidia.com on Fri, 29 May 2015 10:24:47 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1044.25; Fri, 29 May 2015 17:28:13 +0000 Received: from hqnvemgw02.nvidia.com (172.16.227.111) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server id 15.0.1044.25 via Frontend Transport; Fri, 29 May 2015 17:28:13 +0000 Received: from wdavis-lt.nvidia.com (Not Verified[10.20.168.59]) by hqnvemgw02.nvidia.com with MailMarshal (v7, 1, 2, 5326) id ; Fri, 29 May 2015 10:28:13 -0700 From: To: Joerg Roedel , Bjorn Helgaas CC: Terence Ripperda , John Hubbard , Jerome Glisse , Mark Hounschell , Konrad Rzeszutek Wilk , Jonathan Corbet , "David S. Miller" , Yijing Wang , Alex Williamson , Dave Jiang , , , Will Davis Subject: [PATCH v3 7/7] x86: add pci-nommu implementation of map_resource Date: Fri, 29 May 2015 12:14:46 -0500 Message-ID: <1432919686-32306-8-git-send-email-wdavis@nvidia.com> X-Mailer: git-send-email 2.4.0 In-Reply-To: <1432919686-32306-1-git-send-email-wdavis@nvidia.com> References: <1432919686-32306-1-git-send-email-wdavis@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Will Davis Lookup the bus address of the resource by finding the parent host bridge, which may be different than the parent host bridge of the target device. Signed-off-by: Will Davis --- arch/x86/kernel/pci-nommu.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/arch/x86/kernel/pci-nommu.c b/arch/x86/kernel/pci-nommu.c index da15918..6384482 100644 --- a/arch/x86/kernel/pci-nommu.c +++ b/arch/x86/kernel/pci-nommu.c @@ -38,6 +38,37 @@ static dma_addr_t nommu_map_page(struct device *dev, struct page *page, return bus; } +static dma_addr_t nommu_map_resource(struct device *dev, struct resource *res, + unsigned long offset, size_t size, + enum dma_data_direction dir, + struct dma_attrs *attrs) +{ + struct pci_bus *bus; + struct pci_host_bridge *bridge; + struct resource_entry *window; + resource_size_t bus_offset = 0; + dma_addr_t dma_address; + + /* Find the parent host bridge of the resource, and determine the + * relative offset. + */ + list_for_each_entry(bus, &pci_root_buses, node) { + bridge = to_pci_host_bridge(bus->bridge); + resource_list_for_each_entry(window, &bridge->windows) { + if (resource_contains(window->res, res)) + bus_offset = window->offset; + } + } + + dma_address = (res->start - bus_offset) + offset; + WARN_ON(size == 0); + if (!check_addr("map_resource", dev, dma_address, size)) + return DMA_ERROR_CODE; + flush_write_buffers(); + return dma_address; +} + + /* Map a set of buffers described by scatterlist in streaming * mode for DMA. This is the scatter-gather version of the * above pci_map_single interface. Here the scatter gather list @@ -93,6 +124,7 @@ struct dma_map_ops nommu_dma_ops = { .free = dma_generic_free_coherent, .map_sg = nommu_map_sg, .map_page = nommu_map_page, + .map_resource = nommu_map_resource, .sync_single_for_device = nommu_sync_single_for_device, .sync_sg_for_device = nommu_sync_sg_for_device, .is_phys = 1,