linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tejun Heo <htejun@gmail.com>
To: jgarzik@pobox.com, gregkh@suse.de, alan@lxorguk.ukuu.org.uk,
	linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org
Cc: Tejun Heo <htejun@gmail.com>
Subject: [PATCH 12/13] devres: implement pcim_iomap_regions()
Date: Wed, 10 Jan 2007 14:35:38 +0900	[thread overview]
Message-ID: <1168407338988-git-send-email-htejun@gmail.com> (raw)
In-Reply-To: <11684073353213-git-send-email-htejun@gmail.com>

Implement pcim_iomap_regions().  This function takes mask of BARs to
request and iomap.  No BAR should have length of zero.  BARs are
iomapped using pcim_iomap_table().

Signed-off-by: Tejun Heo <htejun@gmail.com>
---
 include/linux/io.h |    2 +
 lib/iomap.c        |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/include/linux/io.h b/include/linux/io.h
index f5edf9c..45a9c94 100644
--- a/include/linux/io.h
+++ b/include/linux/io.h
@@ -45,6 +45,8 @@ void __iomem * pcim_iomap(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, u16 mask, const char *name);
+
 /**
  *	check_signature		-	find BIOS signatures
  *	@io_addr: mmio address to check
diff --git a/lib/iomap.c b/lib/iomap.c
index 3214028..4990c73 100644
--- a/lib/iomap.c
+++ b/lib/iomap.c
@@ -498,3 +498,56 @@ void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr)
 	WARN_ON(1);
 }
 EXPORT_SYMBOL(pcim_iounmap);
+
+/**
+ * pcim_iomap_regions - Request and iomap PCI BARs
+ * @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.
+ */
+int pcim_iomap_regions(struct pci_dev *pdev, u16 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_region;
+
+		rc = -ENOMEM;
+		if (!pcim_iomap(pdev, i, 0))
+			goto err_iomap;
+	}
+
+	return 0;
+
+ err_iomap:
+	pcim_iounmap(pdev, iomap[i]);
+ err_region:
+	pci_release_region(pdev, i);
+ err_inval:
+	while (--i >= 0) {
+		pcim_iounmap(pdev, iomap[i]);
+		pci_release_region(pdev, i);
+	}
+
+	return rc;
+}
+EXPORT_SYMBOL(pcim_iomap_regions);
-- 
1.4.4.3



  parent reply	other threads:[~2007-01-10  5:36 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-10  5:35 [PATCHSET] Managed device resources, take #2 Tejun Heo
2007-01-10  5:35 ` [PATCH 3/13] devres: implement managed IRQ interface Tejun Heo
2007-01-10  5:35 ` [PATCH 4/13] devres: implement managed DMA interface Tejun Heo
2007-01-10  5:35 ` [PATCH 2/13] devres: implement managed IO region interface Tejun Heo
2007-01-10  5:35 ` [PATCH 1/13] devres: device resource management core Tejun Heo
2007-01-10  5:35 ` [PATCH 8/13] libata: implement ata_host_detach() Tejun Heo
2007-01-10  5:35 ` [PATCH 9/13] libata: update libata core layer to use devres Tejun Heo
2007-01-10  5:35 ` [PATCH 7/13] devres: add Documentation/driver-model/devres.txt Tejun Heo
2007-01-10  5:35 ` [PATCH 6/13] devres: implement managed iomap interface Tejun Heo
2008-04-07 16:46   ` Sergei Shtylyov
2008-04-08 14:48     ` Tejun Heo
2008-04-08 14:55       ` Sergei Shtylyov
2008-04-08 15:03         ` Tejun Heo
2008-04-10 16:56         ` Sergei Shtylyov
2008-04-10 17:44           ` Kumar Gala
2008-04-10 18:24             ` Sergei Shtylyov
2008-04-10 19:40               ` Kumar Gala
2008-04-11  2:08                 ` Tejun Heo
2007-01-10  5:35 ` [PATCH 5/13] devres: implement managed PCI interface Tejun Heo
2007-01-10  5:35 ` Tejun Heo [this message]
2007-01-10  5:35 ` [PATCH 11/13] libata: remove unused functions Tejun Heo
2007-01-20  0:31 ` [PATCHSET] Managed device resources, take #2 Jeff Garzik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1168407338988-git-send-email-htejun@gmail.com \
    --to=htejun@gmail.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=gregkh@suse.de \
    --cc=jgarzik@pobox.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).