From patchwork Thu Sep 18 01:30:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liviu Dudau X-Patchwork-Id: 37573 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 52DBA2054D for ; Thu, 18 Sep 2014 01:33:53 +0000 (UTC) Received: by mail-wi0-f198.google.com with SMTP id hi2sf156155wib.1 for ; Wed, 17 Sep 2014 18:33:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=xOE/iKxsVp6uVRdnqM3a9ap4Bph937V9ZCO3VuiDAwQ=; b=OBOYPD8zsVVIMKnSMlDZRZ8zw3XjN2iQmBFAdJGBmgsGhkcHIYrK7DvOdqJHFWZgGD lO7qLrqHEJXOvufEgNr9DZQfV9Ly32qBxjSrnUJyuRFuJm5bBC+y0+UD+IxrOQo6FWXH 3ptHG9V42aNvGJR7Rg8qoF3dG6zOi7GhsMmPlW1pL9MmgnGItl4xUwjLCr+uJO8kuDLt LdNKQzd1BseXWyMQPXkDgGZSZSZvwQtUSC5IPnG3tshO6MAsSZPLTCiFWqNUjvSEgpA7 5OCK42tr+ceY25BE2AzINwFmbDOhks7hsQZCFQv2J7YgNqWrIu7oRxLH8NGdAWdspw1u 6LvQ== X-Gm-Message-State: ALoCoQlg17RVBt0h0nwJ8/KYbS5NmUrKjVnIZDo1lFQXPnjL9ISdLMdR7FphLWWh1QTqYLODTCvp X-Received: by 10.181.25.225 with SMTP id it1mr884230wid.0.1411004032569; Wed, 17 Sep 2014 18:33:52 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.201 with SMTP id u9ls342lau.107.gmail; Wed, 17 Sep 2014 18:33:52 -0700 (PDT) X-Received: by 10.112.130.41 with SMTP id ob9mr962282lbb.12.1411004032288; Wed, 17 Sep 2014 18:33:52 -0700 (PDT) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com [209.85.215.49]) by mx.google.com with ESMTPS id f12si30618506lbo.96.2014.09.17.18.33.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 17 Sep 2014 18:33:52 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by mail-la0-f49.google.com with SMTP id pn19so203486lab.36 for ; Wed, 17 Sep 2014 18:33:52 -0700 (PDT) X-Received: by 10.152.4.39 with SMTP id h7mr1216283lah.49.1411004032181; Wed, 17 Sep 2014 18:33:52 -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 of9csp679711lbb; Wed, 17 Sep 2014 18:33:51 -0700 (PDT) X-Received: by 10.68.105.197 with SMTP id go5mr1446788pbb.73.1411004030576; Wed, 17 Sep 2014 18:33:50 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id rb5si37178107pab.183.2014.09.17.18.33.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Sep 2014 18:33:50 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XUQaN-0002Z9-A6; Thu, 18 Sep 2014 01:32:39 +0000 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21] helo=cam-smtp0.cambridge.arm.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XUQZU-0001i4-3S for linux-arm-kernel@lists.infradead.org; Thu, 18 Sep 2014 01:31:47 +0000 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 s8I1UPlE003595; Thu, 18 Sep 2014 02:30:30 +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 Subject: [PATCH v11 10/10] PCI: Introduce pci_remap_iospace() for remapping PCI I/O bus resources into CPU space Date: Thu, 18 Sep 2014 02:30:25 +0100 Message-Id: <1411003825-21521-11-git-send-email-Liviu.Dudau@arm.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1411003825-21521-1-git-send-email-Liviu.Dudau@arm.com> References: <1411003825-21521-1-git-send-email-Liviu.Dudau@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140917_183144_504561_EA64CE97 X-CRM114-Status: GOOD ( 14.11 ) X-Spam-Score: -3.0 (---) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-3.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [217.140.96.21 listed in list.dnswl.org] -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record Cc: linux-arch , Sinan Kaya , Kukjin Kim , Device Tree ML , Jingoo Han , LKML , Grant Likely , Tanmay Inamdar , Suravee Suthikulanit , LAKML X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.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.49 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 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;