From patchwork Tue May 10 15:19:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Nowicki X-Patchwork-Id: 9059401 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 38945BF29F for ; Tue, 10 May 2016 15:23:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 46CF820154 for ; Tue, 10 May 2016 15:23:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7A2EF20148 for ; Tue, 10 May 2016 15:23:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752195AbcEJPUH (ORCPT ); Tue, 10 May 2016 11:20:07 -0400 Received: from mail-lf0-f53.google.com ([209.85.215.53]:35665 "EHLO mail-lf0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752481AbcEJPUF (ORCPT ); Tue, 10 May 2016 11:20:05 -0400 Received: by mail-lf0-f53.google.com with SMTP id j8so18696891lfd.2 for ; Tue, 10 May 2016 08:20:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HlNOdJTYpPmgxRNjXYivXFLA6rOacZYcKd8y2FXJpmc=; b=DCFMyms3KxALs0qe1lyFpd6kOfsIUzx3Zbo4nkKRTCHUczHZWXtP1FtFQVjJGEv8hG qYBiOdK1w2qUzTC9EaK4JJfwqCXyJmTjosy5DuONHawgY+W/8kdqrRPMah9l9jtadCYu zegcOQfzdzgUP7dhHYO6bRw/2BWvNo48CXQutBOJPI07ADiZFESBe98VODfgEP2GZiPe NndRZ5djDYmHzbNxC1Cb5Qmppb7umr2M7RsGwxN7z3srPsVdRJJUBjBRC/g4lsFB0EuO b1BHUXf216I9+/jLrr5nYqc/7A3x6WbxUD6CdfF4Go8tn8LrbThTVQDA75MHd2C3aIQ5 z09g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HlNOdJTYpPmgxRNjXYivXFLA6rOacZYcKd8y2FXJpmc=; b=nLyiDGEcUf1//BHgqXksGpSLV2ZPMSqCD3BMmCIFIEosQkxd6nOh8GFuLIDjTDRPKq 8sds3z9rTbcDoVe2VGXclH9u/TiYum+i5gLdJ3JUUmytFNqlU8ic6NzPz8FPGQc5GtVv vRZzbwxvSeQMiTWvC4/jXBTI6sjUIGYYS1KGPxTlDQaEknavQrGe8OZ3I/ry/6xmgecI 9twZbvUlGvV9yciNWdPiziHRyyRPlpWFhH7Bi4ui2kJ24tyKXkdbMcssokuMmf1p9qgw GYfeWY7NZsXwDqYO2CMcRLUpzDK7Lo55Y55JNQ/41m0rZqTUzxkKg00GhJVtY6mTHrUY MGVA== X-Gm-Message-State: AOPr4FWVQVAidE9HHWzWNULCM72lG1zy/gRhdqECMhQfQ7+Fxe/tCme9QBCwxjf33KeT6w== X-Received: by 10.112.139.71 with SMTP id qw7mr17486464lbb.40.1462893603482; Tue, 10 May 2016 08:20:03 -0700 (PDT) Received: from tn-HP-4.semihalf.local (cardhu.semihalf.com. [213.17.239.108]) by smtp.gmail.com with ESMTPSA id s194sm468002lfs.40.2016.05.10.08.20.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 May 2016 08:20:02 -0700 (PDT) From: Tomasz Nowicki To: helgaas@kernel.org, arnd@arndb.de, will.deacon@arm.com, catalin.marinas@arm.com, rafael@kernel.org, hanjun.guo@linaro.org, Lorenzo.Pieralisi@arm.com, okaya@codeaurora.org, jchandra@broadcom.com Cc: robert.richter@caviumnetworks.com, mw@semihalf.com, Liviu.Dudau@arm.com, ddaney@caviumnetworks.com, wangyijing@huawei.com, Suravee.Suthikulpanit@amd.com, msalter@redhat.com, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linaro-acpi@lists.linaro.org, jcm@redhat.com, andrea.gallo@linaro.org, dhdang@apm.com, jeremy.linton@arm.com, liudongdong3@huawei.com, cov@codeaurora.org, Tomasz Nowicki Subject: [PATCH V7 04/11] pci: Add new function to unmap IO resources. Date: Tue, 10 May 2016 17:19:54 +0200 Message-Id: <1462893601-8937-5-git-send-email-tn@semihalf.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462893601-8937-1-git-send-email-tn@semihalf.com> References: <1462893601-8937-1-git-send-email-tn@semihalf.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It is very useful to release I/O resources so that the same I/O resources can be allocated again (pci_remap_iospace), like in PCI hotplug removal scenario. Therefore this patch implements new pci_unmap_iospace call which unmaps I/O space as the symmetry to pci_remap_iospace. Signed-off-by: Sinan Kaya Signed-off-by: Tomasz Nowicki --- drivers/pci/pci.c | 24 ++++++++++++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 25 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index bc0c914..ff97a0b 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include "pci.h" @@ -3167,6 +3168,29 @@ int __weak pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr) #endif } +/** + * pci_unmap_iospace - Unmap the memory mapped I/O space + * @res: resource to be unmapped + * + * Unmap the CPU virtual address @res from virtual address space. + * Only architectures that have memory mapped IO functions defined + * (and the PCI_IOBASE value defined) should call this function. + */ +void pci_unmap_iospace(struct resource *res) +{ +#if defined(PCI_IOBASE) && defined(CONFIG_MMU) + unsigned long vaddr = (unsigned long)PCI_IOBASE + res->start; + + unmap_kernel_range(vaddr, resource_size(res)); +#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 +} + 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 d2a57f3..d6ea6ce 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1169,6 +1169,7 @@ int pci_register_io_range(phys_addr_t addr, resource_size_t size); unsigned long pci_address_to_pio(phys_addr_t addr); phys_addr_t pci_pio_to_address(unsigned long pio); int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr); +void pci_unmap_iospace(struct resource *res); static inline pci_bus_addr_t pci_bus_address(struct pci_dev *pdev, int bar) {