From patchwork Thu Jun 25 01:22:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Luis R. Rodriguez" X-Patchwork-Id: 6671731 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 25F1F9F380 for ; Thu, 25 Jun 2015 01:38:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EC69120555 for ; Thu, 25 Jun 2015 01:38:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 56F4720575 for ; Thu, 25 Jun 2015 01:38:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751335AbbFYBhu (ORCPT ); Wed, 24 Jun 2015 21:37:50 -0400 Received: from mail-pd0-f175.google.com ([209.85.192.175]:36699 "EHLO mail-pd0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750903AbbFYBhr (ORCPT ); Wed, 24 Jun 2015 21:37:47 -0400 Received: by pdcu2 with SMTP id u2so42048435pdc.3; Wed, 24 Jun 2015 18:37:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=J3gr+1iYvJ/BIwiiWuvR35PqS4pRn6EYdVtQol5WCn8=; b=agMiTxvdfm/qus0+JQnoCm7VF76XFDH7Vwf5kndeGGSROXQgDxIi3kQDo4MKxhFXxe yV/LU/wH/q3YkCIDQlojQaIuSRIg9SsKTKWQu+BBbaJUdooPGVUfYZTS9RKMSH5KrOUn eyPi7C6PJE5eP53hVqRxEPrTcODmFHxFxqvRV0wnuqcqdf3A34i7E5Rn9W39OMC/v1iY PeEfTzT/AfAS4Dlx8mREl9Mi7zfiIYrSA1LFdkkIQqZ4F97dsOAoNoSlJ2zgkXhzTc4b G3tpyVMds28VgOvZXz2KvWDm+B7GGd1N+XL7kjWqq4XiihMOqhH94csYxMGqhV8dQhGZ ZE1A== X-Received: by 10.70.135.129 with SMTP id ps1mr84803078pdb.110.1435196266980; Wed, 24 Jun 2015 18:37:46 -0700 (PDT) Received: from mcgrof@gmail.com (c-98-234-145-61.hsd1.ca.comcast.net. [98.234.145.61]) by mx.google.com with ESMTPSA id zf1sm28044060pbc.43.2015.06.24.18.37.43 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 24 Jun 2015 18:37:45 -0700 (PDT) Received: by mcgrof@gmail.com (sSMTP sendmail emulation); Wed, 24 Jun 2015 18:35:35 -0700 From: "Luis R. Rodriguez" To: bp@suse.de Cc: mingo@kernel.org, arnd@arndb.de, bhelgaas@google.com, luto@amacapital.net, akpm@linux-foundation.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, tomi.valkeinen@ti.com, mst@redhat.com, toshi.kani@hp.com, linux-fbdev@vger.kernel.org, xen-devel@lists.xensource.com, benh@kernel.crashing.org, "Luis R. Rodriguez" , Suresh Siddha , Ingo Molnar , Thomas Gleixner , Juergen Gross , Daniel Vetter , Dave Airlie , Antonino Daplas , Jean-Christophe Plagniol-Villard , Dave Hansen , venkatesh.pallipadi@intel.com, Stefan Bader , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Mel Gorman , Vlastimil Babka , Davidlohr Bueso , konrad.wilk@oracle.com, ville.syrjala@linux.intel.com, david.vrabel@citrix.com, jbeulich@suse.com, =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v8 6/9] lib: devres: add pcim_iomap_wc() variants Date: Wed, 24 Jun 2015 18:22:19 -0700 Message-Id: <1435195342-26879-7-git-send-email-mcgrof@do-not-panic.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1435195342-26879-1-git-send-email-mcgrof@do-not-panic.com> References: <1435195342-26879-1-git-send-email-mcgrof@do-not-panic.com> MIME-Version: 1.0 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, 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 From: "Luis R. Rodriguez" Now that we have pci_iomap_wc() add the respective devres helpers. These go unexported for now but note that should they later be exported this must go with EXPORT_SYMBOL_GPL(). Cc: Toshi Kani Cc: Andy Lutomirski Cc: Suresh Siddha Cc: Ingo Molnar Cc: Thomas Gleixner Cc: Juergen Gross Cc: Daniel Vetter Cc: Dave Airlie Cc: Bjorn Helgaas Cc: Antonino Daplas Cc: Jean-Christophe Plagniol-Villard Cc: Tomi Valkeinen Cc: Dave Hansen Cc: Arnd Bergmann Cc: Michael S. Tsirkin Cc: venkatesh.pallipadi@intel.com Cc: Stefan Bader Cc: Ville Syrjälä Cc: Mel Gorman Cc: Vlastimil Babka Cc: Borislav Petkov Cc: Davidlohr Bueso Cc: konrad.wilk@oracle.com Cc: ville.syrjala@linux.intel.com Cc: david.vrabel@citrix.com Cc: jbeulich@suse.com Cc: Roger Pau Monné Cc: linux-fbdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: xen-devel@lists.xensource.com Acked-by: Arnd Bergmann Signed-off-by: Luis R. Rodriguez --- include/linux/pci.h | 2 ++ lib/devres.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/include/linux/pci.h b/include/linux/pci.h index 1193975..5ff15c1 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1609,9 +1609,11 @@ static inline void pci_dev_specific_enable_acs(struct pci_dev *dev) { } #endif void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen); +void __iomem *pcim_iomap_wc(struct pci_dev *pdev, int bar, unsigned long maxlen); void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr); void __iomem * const *pcim_iomap_table(struct pci_dev *pdev); int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name); +int pcim_iomap_wc_regions(struct pci_dev *pdev, int mask, const char *name); int pcim_iomap_regions_request_all(struct pci_dev *pdev, int mask, const char *name); void pcim_iounmap_regions(struct pci_dev *pdev, int mask); diff --git a/lib/devres.c b/lib/devres.c index fbe2aac..38acc53 100644 --- a/lib/devres.c +++ b/lib/devres.c @@ -304,6 +304,29 @@ void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen) EXPORT_SYMBOL(pcim_iomap); /** + * pcim_iomap_wc - Managed pcim_iomap_wc() + * @pdev: PCI device to iomap for + * @bar: BAR to iomap + * @maxlen: Maximum length of iomap + * + * Managed pci_iomap_wc(). Map is automatically unmapped on driver + * detach. + */ +void __iomem *pcim_iomap_wc(struct pci_dev *pdev, int bar, unsigned long maxlen) +{ + void __iomem **tbl; + + BUG_ON(bar >= PCIM_IOMAP_MAX); + + tbl = (void __iomem **)pcim_iomap_table(pdev); + if (!tbl || tbl[bar]) /* duplicate mappings not allowed */ + return NULL; + + tbl[bar] = pci_iomap_wc(pdev, bar, maxlen); + return tbl[bar]; +} + +/** * pcim_iounmap - Managed pci_iounmap() * @pdev: PCI device to iounmap for * @addr: Address to unmap @@ -383,6 +406,59 @@ int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name) EXPORT_SYMBOL(pcim_iomap_regions); /** + * pcim_iomap_wc_regions - Request and iomap PCI BARs with write-combining + * @pdev: PCI device to map IO resources for + * @mask: Mask of BARs to request and iomap + * @name: Name used when requesting regions + * + * Request and iomap regions specified by @mask with a preference for + * write-combining. + */ +int pcim_iomap_wc_regions(struct pci_dev *pdev, int mask, const char *name) +{ + void __iomem * const *iomap; + int i, rc; + + iomap = pcim_iomap_table(pdev); + if (!iomap) + return -ENOMEM; + + for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { + unsigned long len; + + if (!(mask & (1 << i))) + continue; + + rc = -EINVAL; + len = pci_resource_len(pdev, i); + if (!len) + goto err_inval; + + rc = pci_request_region(pdev, i, name); + if (rc) + goto err_inval; + + rc = -ENOMEM; + if (!pcim_iomap_wc(pdev, i, 0)) + goto err_region; + } + + return 0; + + err_region: + pci_release_region(pdev, i); + err_inval: + while (--i >= 0) { + if (!(mask & (1 << i))) + continue; + pcim_iounmap(pdev, iomap[i]); + pci_release_region(pdev, i); + } + + return rc; +} + +/** * pcim_iomap_regions_request_all - Request all BARs and iomap specified ones * @pdev: PCI device to map IO resources for * @mask: Mask of BARs to iomap