Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp239316pxt; Wed, 4 Aug 2021 21:23:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJjvfbixUOtgYFshHJyYiSIWsjLTrCW+sOWQrGB2VlQuYP3pyGKuixlEhFgCfDuKpuIOTB X-Received: by 2002:a92:c946:: with SMTP id i6mr293690ilq.228.1628137403473; Wed, 04 Aug 2021 21:23:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628137403; cv=none; d=google.com; s=arc-20160816; b=O1USNV5NL1DhxUFUL7Wb2Hj8XoHgITtB1+Pt7j0w+TLDfqyxN/8/qfQkbWmFVTsFWw WwVsrxk4HjQMbYaHNSex8Q1sTVJTCyd1Wtn9iZ7kXQa3h5OthL/frjdO1Fq7guzNs2ZB z8KElv8x1tNFBPgCzNJH1vQgJ6XZ5mq9GSrv2T8ZiVlP5JFPyySDl9A+Eq4zBFRle1yr sBYbB0HF2SH1eXbDskAbcToPDCCLLh8r0NQtHdBKN6pk6PWYJgZqKw61V8/WGUsLOpm0 Yb2DV2GTfw5UYMOSQOJBHMNaLB7HcC/o6OQeXlV9vUUPrC/+wObMiY2Hg5ry1gptCE5M d0vQ== 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=xsA8sXBKQlZ/JxgtrWTGbUyLXrDQ+RnYiKR/+j2451c=; b=dRLKG76iH6D17CMb78/FARCCAt+uUHxyTH8Etq2MRhQsv8o/ON9WRL/9WEBUQgb+8a OM2e4x4/CQXgVd9RaGMR4RGKEPdX/EUxXsQi071VYz59KedlgUxbCq6Tb4sfpYybNTCg cpU/u4AwCZKsFRNbYjC69ut/foSwN1Xh9o3ZlvLq+1gBfJ/K0JnKuGaYFAWvi+OSSPfy +XG3ltxfzjxbRXvxgJAU7lLB43uvMRD+Fb6A9Nkvns4/xaePDlGLHVNQdNAs0npVhNDt EipFq54Kt3xe5j9m/nE5isXyXb2yfTInAQ7mj18QzSsI6B1KxyO3aQ7WUgeZIuhXwF+f sz+w== 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 m6si4448116iol.83.2021.08.04.21.23.11; Wed, 04 Aug 2021 21:23:23 -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 S237187AbhHEAyT (ORCPT + 99 others); Wed, 4 Aug 2021 20:54:19 -0400 Received: from mga09.intel.com ([134.134.136.24]:27469 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236608AbhHEAyF (ORCPT ); Wed, 4 Aug 2021 20:54:05 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10066"; a="214027473" X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="214027473" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2021 17:53:41 -0700 X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="437617259" Received: from mjkendri-mobl.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.17.117]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2021 17:53:38 -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" Cc: Peter H Anvin , Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Sean Christopherson , 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 v4 09/15] pci: Consolidate pci_iomap* and pci_iomap*wc Date: Wed, 4 Aug 2021 17:52:12 -0700 Message-Id: <20210805005218.2912076-10-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210805005218.2912076-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20210805005218.2912076-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* and pci_iomap*wc are currently duplicated code, except that the _wc variant does not support IO ports. Replace them with a common helper and a callback for the mapping. I used wrappers for the maps because some architectures implement ioremap and friends with macros. This will allow to add more variants without excessive code duplications. This patch should have no behavior change. Signed-off-by: Andi Kleen Signed-off-by: Kuppuswamy Sathyanarayanan --- lib/pci_iomap.c | 81 +++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/lib/pci_iomap.c b/lib/pci_iomap.c index 2d3eb1cb73b8..6251c3f651c6 100644 --- a/lib/pci_iomap.c +++ b/lib/pci_iomap.c @@ -10,6 +10,46 @@ #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)) +{ + 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 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 +70,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); } EXPORT_SYMBOL(pci_iomap_range); @@ -70,27 +96,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); } EXPORT_SYMBOL_GPL(pci_iomap_wc_range); -- 2.25.1