From patchwork Tue Jul 1 18:43:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liviu Dudau X-Patchwork-Id: 32927 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f198.google.com (mail-ve0-f198.google.com [209.85.128.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 50A0F203C0 for ; Tue, 1 Jul 2014 18:45:41 +0000 (UTC) Received: by mail-ve0-f198.google.com with SMTP id db11sf24771065veb.9 for ; Tue, 01 Jul 2014 11:45:41 -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=yph+82Ro3aGnGmtz3SPtM7nrLhcQHud/glw8yHuF7c8=; b=EFTja7sLFy1j8OmHpczSVHSIC5Ia4w048P6VtAggV6l0cPzKA5Cc+3YFLWnkhRmd6v 0A63geR7EjfU8Gn4SEND7ptdC5NfVFpa5mtWpTmfE+5IdlXK5QZB9eLAl77/WCFCTTFy lpU4HnkDhvzuoUV48oMnLZ3nG872REl8u8xEADnbJbdj9h8a2ZW4RwtBE22Ws9hMaeh8 RAz/w0WQ/RiiQMR0WYVmN2DVrA6GR/xqUzaP89OGYBQ1oyX3B8O9HTt6gZzX6KtuodT6 NB7ZNUhC/0kPMt0Vwm885fYIgMz0oIutg1yYtKTqd1UjrKSg2o6XN0CmQT+uUd19Yiif CWvw== X-Gm-Message-State: ALoCoQlKCJIL2GflVeh9+TO5Bu6qEzboNltdEfAgtAat/s4iZnl3E6+EsjukmKITeC6VW8LJUNM9 X-Received: by 10.52.231.97 with SMTP id tf1mr6939717vdc.3.1404240341085; Tue, 01 Jul 2014 11:45:41 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.87.53 with SMTP id q50ls597127qgd.2.gmail; Tue, 01 Jul 2014 11:45:40 -0700 (PDT) X-Received: by 10.52.166.10 with SMTP id zc10mr1652483vdb.61.1404240340956; Tue, 01 Jul 2014 11:45:40 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id ut8si11801105vec.4.2014.07.01.11.45.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Jul 2014 11:45:40 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id ij19so9362307vcb.37 for ; Tue, 01 Jul 2014 11:45:40 -0700 (PDT) X-Received: by 10.58.12.73 with SMTP id w9mr7469842veb.13.1404240340839; Tue, 01 Jul 2014 11:45:40 -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 tc5csp236937vcb; Tue, 1 Jul 2014 11:45:40 -0700 (PDT) X-Received: by 10.68.96.194 with SMTP id du2mr13387299pbb.105.1404240340071; Tue, 01 Jul 2014 11:45:40 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id kk10si24713114pbd.238.2014.07.01.11.45.39; Tue, 01 Jul 2014 11:45:39 -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 S964905AbaGASp3 (ORCPT + 27 others); Tue, 1 Jul 2014 14:45:29 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:50171 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S964784AbaGASog (ORCPT ); Tue, 1 Jul 2014 14:44:36 -0400 Received: from e106497-lin.cambridge.arm.com (e106497-lin.cambridge.arm.com [10.1.195.170]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id s61IhYJd027921; Tue, 1 Jul 2014 19:43:38 +0100 From: Liviu Dudau To: linux-pci , Bjorn Helgaas , Catalin Marinas , Will Deacon , Benjamin Herrenschmidt , Arnd Bergmann , linaro-kernel , Tanmay Inamdar , Grant Likely , Sinan Kaya , Jingoo Han , Kukjin Kim , Suravee Suthikulanit Cc: LKML , Device Tree ML , LAKML Subject: [PATCH v8 9/9] pci: Remap I/O bus resources into CPU space with pci_remap_iospace() Date: Tue, 1 Jul 2014 19:43:34 +0100 Message-Id: <1404240214-9804-10-git-send-email-Liviu.Dudau@arm.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1404240214-9804-1-git-send-email-Liviu.Dudau@arm.com> References: <1404240214-9804-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.178 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. Signed-off-by: Liviu Dudau --- 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 8e65dc3..a90df97 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2708,6 +2708,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(PROT_DEVICE_nGnRE)); +#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 556dc5f..65fb1fc 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;