Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2864000pxb; Fri, 8 Oct 2021 17:40:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyy2py48DQqO5N/BiqnxzDTksGOEnuHJD6VP8dZ0AEOJWku7AstINKpYS52dsysWeE/82ms X-Received: by 2002:a17:90b:1e4f:: with SMTP id pi15mr15033196pjb.231.1633740030090; Fri, 08 Oct 2021 17:40:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633740030; cv=none; d=google.com; s=arc-20160816; b=xVlxAw1tPKuFvyo+f5516DVwidjqDglmmyDT35KEsiQUbMwqT3sw/1J8kasGLBfLeA F60IwE/6hHyIYxTU/SCFBz1FkVmfMLt6C+59SZUmfsJ01O3vP1aYwpcN6Be9f1SuNh6q WYQYY4UWjoROxRf5YsmetpXu4x9m5XomsIR3o8s+nkdprnMXLtTs4AsF6MX73sgcdZ+5 Ee7gIEmuILmFAn1N4CDDMo5xDIOPRJ0+t5yrSbiH0vojnKQlDoPri6EE9fKxrkNfu57p QfvKtKSbFS0YuT+xVBLBG21GOmtB9CGu4AAk/542IZ9UHC76NSCSNhWi4s3hopRzlT7J RUjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=e2rmw3rkR65zdXh9t1cqMfOzf8Sa4J1e7kUI/54Z0IE=; b=RFgMYpbp17HnNi2+eb6wpdo1+UxyfIzs6MEKTnYF5H4j7L35aZnWMwR5efGrTfLkTc pplgGVzhjYfqSg8EgkTY1bpBfOkr3j0opt6jgZrMBQ6MjYVUP2M+u/Tcw3uYt3XcRhGI roo0PkXMD492wTgQL+MrVLjmc41cW0o97iGZx+Nzsyrsf/wjMsMltlt/ECAh56zxjo8j GEEwNe9j72+7mttTyM+KfGbWPVcX0KR6c4IZe27KS20ZVCEKVB9mh0FKmCndTyz8e6ec 1xKxvFRwpwQRWPTszYfWoL1rr9xKF+jbLTyGAwHmOvxMArDyl76ENJchQty6BsXevogr UW8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f19si1053316pgb.357.2021.10.08.17.40.17; Fri, 08 Oct 2021 17:40:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244274AbhJIAk3 (ORCPT + 99 others); Fri, 8 Oct 2021 20:40:29 -0400 Received: from mga02.intel.com ([134.134.136.20]:5260 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244224AbhJIAkB (ORCPT ); Fri, 8 Oct 2021 20:40:01 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10131"; a="213756532" X-IronPort-AV: E=Sophos;i="5.85,358,1624345200"; d="scan'208";a="213756532" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2021 17:37:47 -0700 X-IronPort-AV: E=Sophos;i="5.85,358,1624345200"; d="scan'208";a="624905390" Received: from dmsojoza-mobl3.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.251.135.62]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2021 17:37:45 -0700 From: Kuppuswamy Sathyanarayanan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Andy Lutomirski , Bjorn Helgaas , Richard Henderson , Thomas Bogendoerfer , James E J Bottomley , Helge Deller , "David S . Miller" , Arnd Bergmann , Jonathan Corbet , "Michael S . Tsirkin" , Paolo Bonzini , David Hildenbrand , Andrea Arcangeli , Josh Poimboeuf Cc: Peter H Anvin , Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Sean Christopherson , Kuppuswamy Sathyanarayanan , Kuppuswamy Sathyanarayanan , x86@kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v5 10/16] PCI: Consolidate pci_iomap_range(), pci_iomap_wc_range() Date: Fri, 8 Oct 2021 17:37:05 -0700 Message-Id: <20211009003711.1390019-11-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211009003711.1390019-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20211009003711.1390019-1-sathyanarayanan.kuppuswamy@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andi Kleen pci_iomap_range() and pci_iomap_wc_range() are currently duplicated code, except that the _wc variant does not support IO ports. So, implement them using a common helper, pci_iomap_range_map(). Also add wrappers for the maps because some architectures implement ioremap and friends with macros. This will allow to add more variants without excessive code duplication. This patch has no functional changes. Signed-off-by: Andi Kleen Signed-off-by: Kuppuswamy Sathyanarayanan --- Changes since v4: * Rebased on top of Tom Lendacky's CC guest changes (https://www.spinics.net/lists/linux-tip-commits/msg58716.html) * Fixed commit log as per Bjorns comments. * Added "support_io" argument to pci_iomap_range_map() to support __pci_ioport_map() only in pci_iomap_range(). lib/pci_iomap.c | 86 ++++++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/lib/pci_iomap.c b/lib/pci_iomap.c index 2d3eb1cb73b8..57bd92f599ee 100644 --- a/lib/pci_iomap.c +++ b/lib/pci_iomap.c @@ -10,6 +10,51 @@ #include #ifdef CONFIG_PCI + +/* + * Callback wrappers because some architectures define ioremap et.al. + * as macros. + */ +static void __iomem *map_ioremap(phys_addr_t addr, size_t size) +{ + return ioremap(addr, size); +} + +static void __iomem *map_ioremap_wc(phys_addr_t addr, size_t size) +{ + return ioremap_wc(addr, size); +} + +static void __iomem *pci_iomap_range_map(struct pci_dev *dev, + int bar, + unsigned long offset, + unsigned long maxlen, + void __iomem *(*mapm)(phys_addr_t, + size_t), + bool support_io) +{ + resource_size_t start = pci_resource_start(dev, bar); + resource_size_t len = pci_resource_len(dev, bar); + unsigned long flags = pci_resource_flags(dev, bar); + + if (len <= offset || !start) + return NULL; + len -= offset; + start += offset; + if (maxlen && len > maxlen) + len = maxlen; + if (flags & IORESOURCE_IO) { + if (support_io) + return __pci_ioport_map(dev, start, len); + + return NULL; + } + if (flags & IORESOURCE_MEM) + return mapm(start, len); + /* What? */ + return NULL; +} + /** * pci_iomap_range - create a virtual mapping cookie for a PCI BAR * @dev: PCI device that owns the BAR @@ -30,22 +75,8 @@ void __iomem *pci_iomap_range(struct pci_dev *dev, unsigned long offset, unsigned long maxlen) { - resource_size_t start = pci_resource_start(dev, bar); - resource_size_t len = pci_resource_len(dev, bar); - unsigned long flags = pci_resource_flags(dev, bar); - - if (len <= offset || !start) - return NULL; - len -= offset; - start += offset; - if (maxlen && len > maxlen) - len = maxlen; - if (flags & IORESOURCE_IO) - return __pci_ioport_map(dev, start, len); - if (flags & IORESOURCE_MEM) - return ioremap(start, len); - /* What? */ - return NULL; + return pci_iomap_range_map(dev, bar, offset, maxlen, + map_ioremap, true); } EXPORT_SYMBOL(pci_iomap_range); @@ -70,27 +101,8 @@ void __iomem *pci_iomap_wc_range(struct pci_dev *dev, unsigned long offset, unsigned long maxlen) { - resource_size_t start = pci_resource_start(dev, bar); - resource_size_t len = pci_resource_len(dev, bar); - unsigned long flags = pci_resource_flags(dev, bar); - - - if (flags & IORESOURCE_IO) - return NULL; - - if (len <= offset || !start) - return NULL; - - len -= offset; - start += offset; - if (maxlen && len > maxlen) - len = maxlen; - - if (flags & IORESOURCE_MEM) - return ioremap_wc(start, len); - - /* What? */ - return NULL; + return pci_iomap_range_map(dev, bar, offset, maxlen, + map_ioremap_wc, false); } EXPORT_SYMBOL_GPL(pci_iomap_wc_range); -- 2.25.1