From patchwork Mon Sep 8 13:54:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liviu Dudau X-Patchwork-Id: 36982 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E0D6120491 for ; Mon, 8 Sep 2014 13:57:15 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id wp18sf75937208obc.5 for ; Mon, 08 Sep 2014 06:57:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=DhnpE84wUg4qe1pTBBvW958GyZBojyInZjMZhu808oA=; b=RFFAK7EQnEwzOioD8UIs2qXGhCjVV+8Iszsgm1S8OYgNtOfwxKMZQe6yTCmILk0BGr 2jrvf2TPiyxFvdhA3SRBlrAn+eKpb7DcWrc6kUxNnMsSEY+bf2fxn6+vHi+YV7bArAMK zHTg/if1Bti8rw/ZW92boPPgfaLBUCyVC+w1FFaGaeWma0wDBg+6lIpfNqErtXJ7hJxE CzAuNQvXkgjNgmPGIsB69Mwzc2wOMk+dtmMEhvYR4jeU9K3s/HZqg9rZMNlxiQ4dXpm4 q5ZQW1TXb8lvgv3o3PQe/WB/cMPdUNaYVMMoRRfYzBw6Q3/HGGsi+N8RhB2xYi6nP4mo qrEg== X-Gm-Message-State: ALoCoQkdB/cHi2TOu9wSlrVAxYCx5wUtz1+44fm91zn3YguoFGL1ogzDFL8Tbb7NtHmU3AWGOYmz X-Received: by 10.42.26.12 with SMTP id d12mr18112763icc.24.1410184635520; Mon, 08 Sep 2014 06:57:15 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.48.35 with SMTP id n32ls1688263qga.25.gmail; Mon, 08 Sep 2014 06:57:15 -0700 (PDT) X-Received: by 10.220.194.71 with SMTP id dx7mr166989vcb.64.1410184635414; Mon, 08 Sep 2014 06:57:15 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id ey5si3913437vcb.76.2014.09.08.06.57.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 08 Sep 2014 06:57:15 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.177 as permitted sender) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id hq11so15330021vcb.36 for ; Mon, 08 Sep 2014 06:57:15 -0700 (PDT) X-Received: by 10.52.248.232 with SMTP id yp8mr134288vdc.83.1410184635305; Mon, 08 Sep 2014 06:57:15 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp137789vcb; Mon, 8 Sep 2014 06:57:14 -0700 (PDT) X-Received: by 10.66.190.169 with SMTP id gr9mr46082287pac.3.1410184634112; Mon, 08 Sep 2014 06:57:14 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yw3si12435158pac.41.2014.09.08.06.57.13 for ; Mon, 08 Sep 2014 06:57:14 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754062AbaIHN4Z (ORCPT + 26 others); Mon, 8 Sep 2014 09:56:25 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:53526 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753034AbaIHN4W (ORCPT ); Mon, 8 Sep 2014 09:56:22 -0400 Received: from e106497-lin.cambridge.arm.com (e106497-lin.cambridge.arm.com [10.1.195.53]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id s88DsW8N017520; Mon, 8 Sep 2014 14:54:38 +0100 From: Liviu Dudau To: Bjorn Helgaas , Arnd Bergmann , Rob Herring , Jason Gunthorpe , Benjamin Herrenschmidt , Catalin Marinas , Will Deacon , Russell King , linux-pci , Linus Walleij Cc: Tanmay Inamdar , Grant Likely , Sinan Kaya , Jingoo Han , Kukjin Kim , Suravee Suthikulanit , linux-arch , LKML , Device Tree ML , LAKML Subject: [PATCH v10 10/10] PCI: Introduce pci_remap_iospace() for remapping PCI I/O bus resources into CPU space Date: Mon, 8 Sep 2014 14:54:32 +0100 Message-Id: <1410184472-17630-11-git-send-email-Liviu.Dudau@arm.com> X-Mailer: git-send-email 2.0.4 In-Reply-To: <1410184472-17630-1-git-send-email-Liviu.Dudau@arm.com> References: <1410184472-17630-1-git-send-email-Liviu.Dudau@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: liviu.dudau@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.177 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Introduce a default implementation for remapping PCI bus I/O resources onto the CPU address space. Architectures with special needs may provide their own version, but most should be able to use this one. Cc: Bjorn Helgaas Cc: Arnd Bergmann Cc: Rob Herring Reviewed-by: Catalin Marinas Signed-off-by: Liviu Dudau --- drivers/pci/pci.c | 33 +++++++++++++++++++++++++++++++++ include/asm-generic/pgtable.h | 4 ++++ include/linux/pci.h | 3 +++ 3 files changed, 40 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 2c9ac70..654b44c 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2704,6 +2704,39 @@ int pci_request_regions_exclusive(struct pci_dev *pdev, const char *res_name) } EXPORT_SYMBOL(pci_request_regions_exclusive); +/** + * pci_remap_iospace - Remap the memory mapped I/O space + * @res: Resource describing the I/O space + * @phys_addr: physical address where the range will be mapped. + * + * Remap the memory mapped I/O space described by the @res + * into the CPU physical address space. Only architectures + * that have memory mapped IO defined (and hence PCI_IOBASE) + * should call this function. + */ +int __weak pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr) +{ + int err = -ENODEV; + +#ifdef PCI_IOBASE + if (!(res->flags & IORESOURCE_IO)) + return -EINVAL; + + if (res->end > IO_SPACE_LIMIT) + return -EINVAL; + + err = ioremap_page_range(res->start + (unsigned long)PCI_IOBASE, + res->end + 1 + (unsigned long)PCI_IOBASE, + phys_addr, pgprot_device(PAGE_KERNEL)); +#else + /* this architecture does not have memory mapped I/O space, + so this function should never be called */ + WARN_ON(1); +#endif + + return err; +} + static void __pci_set_master(struct pci_dev *dev, bool enable) { u16 old_cmd, cmd; diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h index 53b2acc..977e545 100644 --- a/include/asm-generic/pgtable.h +++ b/include/asm-generic/pgtable.h @@ -249,6 +249,10 @@ static inline int pmd_same(pmd_t pmd_a, pmd_t pmd_b) #define pgprot_writecombine pgprot_noncached #endif +#ifndef pgprot_device +#define pgprot_device pgprot_noncached +#endif + /* * When walking page tables, get the address of the next boundary, * or the end address of the range if that comes earlier. Although no diff --git a/include/linux/pci.h b/include/linux/pci.h index a494e5d..fc8c529 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1100,6 +1100,9 @@ int __must_check pci_bus_alloc_resource(struct pci_bus *bus, resource_size_t), void *alignf_data); + +int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr); + static inline dma_addr_t pci_bus_address(struct pci_dev *pdev, int bar) { struct pci_bus_region region;