From patchwork Tue Sep 23 19:01:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liviu Dudau X-Patchwork-Id: 37760 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C221C20792 for ; Tue, 23 Sep 2014 20:03:09 +0000 (UTC) Received: by mail-la0-f71.google.com with SMTP id q1sf4716828lam.10 for ; Tue, 23 Sep 2014 13:03:08 -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=2a7wLG3WVKbNb3Zw8JrkkFvwNuMvC+wIgx9G5Z4qn0U=; b=ddIdCkhwTCN4MdU6SLr/Scc7rQcNlPLmwEjzxPm+sPezAbA4XJR8KIsu7BiIAfQ9zx FNW+kZo9wEmS7EltFORaNokdIGz9uELfXU2eZFePN5a1FqxRAA73THKF3r3XK0dZaeGg +hAuW8xftykVOStldrSViScXzpo2pzGtV1fIsIuYvOI60uSI6gE0Wdi73nykpkZV5RGd Py+ow9j4eg/7H+Cmuw/Z3QKjyeYaCXxLfH81Ls1n039xrZUTM8TaKUCr9SceWByfCHXU Y6Mt4CKShNuwKDT4JcEIRnJdTe7l1TtDIQWE9NAchlMrVZDEkjtsi1viyY87ucV899Te sdOA== X-Gm-Message-State: ALoCoQn8h3qpdRXhzrHA4VNtViey+eX6QQ46SxnEexUV/xgYxC/JFZg8S9fINNcXkUqnyVAkul+W X-Received: by 10.194.100.3 with SMTP id eu3mr5060wjb.6.1411502588559; Tue, 23 Sep 2014 13:03:08 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.4.43 with SMTP id cb11ls90842lad.23.gmail; Tue, 23 Sep 2014 13:03:08 -0700 (PDT) X-Received: by 10.152.21.195 with SMTP id x3mr1820057lae.11.1411502588180; Tue, 23 Sep 2014 13:03:08 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com [209.85.215.44]) by mx.google.com with ESMTPS id ck13si20102870lbb.57.2014.09.23.13.03.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 23 Sep 2014 13:03:08 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by mail-la0-f44.google.com with SMTP id q1so9385570lam.17 for ; Tue, 23 Sep 2014 13:03:08 -0700 (PDT) X-Received: by 10.112.62.200 with SMTP id a8mr1827746lbs.34.1411502588071; Tue, 23 Sep 2014 13:03:08 -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.112.130.169 with SMTP id of9csp476937lbb; Tue, 23 Sep 2014 13:03:07 -0700 (PDT) X-Received: by 10.66.237.206 with SMTP id ve14mr2819804pac.40.1411502585943; Tue, 23 Sep 2014 13:03:05 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5si22704221pdh.87.2014.09.23.13.03.05 for ; Tue, 23 Sep 2014 13:03:05 -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 S1756834AbaIWUC5 (ORCPT + 27 others); Tue, 23 Sep 2014 16:02:57 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:54803 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756577AbaIWUCx (ORCPT ); Tue, 23 Sep 2014 16:02:53 -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 s8NJ1Eh8027659; Tue, 23 Sep 2014 20:01:26 +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 v12 11/12] PCI: Introduce pci_remap_iospace() for remapping PCI I/O bus resources into CPU space Date: Tue, 23 Sep 2014 20:01:13 +0100 Message-Id: <1411498874-9864-12-git-send-email-Liviu.Dudau@arm.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1411498874-9864-1-git-send-email-Liviu.Dudau@arm.com> References: <1411498874-9864-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.215.44 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. This function is useful for PCI host bridge drivers that need to map the PCI I/O resources into virtual memory space. Cc: Bjorn Helgaas Cc: Arnd Bergmann Reviewed-by: Rob Herring Reviewed-by: Catalin Marinas Signed-off-by: Liviu Dudau --- drivers/pci/pci.c | 34 ++++++++++++++++++++++++++++++++++ include/asm-generic/pgtable.h | 4 ++++ include/linux/pci.h | 3 +++ 3 files changed, 41 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index d36f35f..ad046a2 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2704,6 +2704,40 @@ 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 + * and the CPU physical address @phys_addr into virtual address space. + * Only architectures that have memory mapped IO functions defined + * (and the PCI_IOBASE value defined) should call this function. + */ +int __weak pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr) +{ + int err = -ENODEV; + +#if defined(PCI_IOBASE) && defined(CONFIG_MMU) + unsigned long vaddr = (unsigned long)PCI_IOBASE + res->start; + + if (!(res->flags & IORESOURCE_IO)) + return -EINVAL; + + if (res->end > IO_SPACE_LIMIT) + return -EINVAL; + + err = ioremap_page_range(vaddr, vaddr + resource_size(res), + 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_ONCE(1, "This architecture does not support memory mapped I/O\n"); +#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 150da2d..b4995fd 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;