From patchwork Tue Aug 12 16:25: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: 35293 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 78C0D203C5 for ; Tue, 12 Aug 2014 16:28:04 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id lf10sf72550852pab.5 for ; Tue, 12 Aug 2014 09:28:03 -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=B1BN0iODB+X6ZcRoSCsZ4FDMYIzv8Sf8tW52TgylGdE=; b=A5DXHzz6jKZNkUeRE0GyhS7Lzp+qaK0HIjEnnbpSzzeoWERVumEHf5yGYbvs1Nrdjq 3S6bL1RFIOiJ+xG0uUek3qS8hBJRI2ucfAjfQlQEvTUSOHqiPun+lwPM43r2nMuFtdPq c6IS+fvXFZ3sgtm2ukA9/rPU6xjGUf0gI85GBirro/OkcQdI7hBiBBuMheFx0uqnXqXp qOXd7H5INZAMoZn7JR7bhBxvNniKDfChI+5daEWJK1nO7GP2QNXsn9GM/rj+bKjIGd/w 6LscV8/WX49iJp8JmtRlqpN52hlHrBaNECJ4OmbYX/wKpxMHHEEuDrgsc36wElKMxgl/ lyBw== X-Gm-Message-State: ALoCoQl/yDuizgGDVUt8PWkvw00IaDWPw3uCyqTswDxm7GwqOhjILSE6OnQxiD16HFayG/KWkh5S X-Received: by 10.66.196.70 with SMTP id ik6mr967057pac.44.1407860883824; Tue, 12 Aug 2014 09:28:03 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.104.130 with SMTP id a2ls170312qgf.90.gmail; Tue, 12 Aug 2014 09:28:03 -0700 (PDT) X-Received: by 10.52.228.67 with SMTP id sg3mr12591645vdc.6.1407860883720; Tue, 12 Aug 2014 09:28:03 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id ik1si3878360vdb.29.2014.08.12.09.28.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 12 Aug 2014 09:28:03 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id la4so13569912vcb.19 for ; Tue, 12 Aug 2014 09:28:03 -0700 (PDT) X-Received: by 10.52.129.200 with SMTP id ny8mr4816377vdb.27.1407860883625; Tue, 12 Aug 2014 09:28:03 -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.37.5 with SMTP id tc5csp262615vcb; Tue, 12 Aug 2014 09:28:03 -0700 (PDT) X-Received: by 10.68.196.226 with SMTP id ip2mr5245563pbc.120.1407860882662; Tue, 12 Aug 2014 09:28:02 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id mx10si12842750pdb.66.2014.08.12.09.28.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Aug 2014 09:28:02 -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 1XHEua-00036B-MQ; Tue, 12 Aug 2014 16:27:00 +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 1XHEuI-0002uY-Ic for linux-arm-kernel@lists.infradead.org; Tue, 12 Aug 2014 16:26:43 +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 s7CGPPgg026280; Tue, 12 Aug 2014 17:25:28 +0100 From: Liviu Dudau To: Bjorn Helgaas , Catalin Marinas , Will Deacon , Benjamin Herrenschmidt , Arnd Bergmann , Russell King , Tanmay Inamdar , Grant Likely , Sinan Kaya , Jingoo Han , Kukjin Kim , Suravee Suthikulanit , linux-pci Subject: [PATCH v9 12/12] PCI: Introduce pci_remap_iospace() for remapping PCI I/O bus resources into CPU space Date: Tue, 12 Aug 2014 17:25:25 +0100 Message-Id: <1407860725-25202-13-git-send-email-Liviu.Dudau@arm.com> X-Mailer: git-send-email 2.0.4 In-Reply-To: <1407860725-25202-1-git-send-email-Liviu.Dudau@arm.com> References: <1407860725-25202-1-git-send-email-Liviu.Dudau@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140812_092643_137819_1A865BD2 X-CRM114-Status: GOOD ( 11.96 ) 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 , Device Tree ML , LKML , 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.220.174 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 Signed-off-by: Liviu Dudau Reviewed-by: Rob Herring --- drivers/pci/pci.c | 33 +++++++++++++++++++++++++++++++++ include/linux/pci.h | 3 +++ 2 files changed, 36 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 29d1775..76d21b6 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2707,6 +2707,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/linux/pci.h b/include/linux/pci.h index e1e0d80..988c2f5 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1098,6 +1098,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;