public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-pci@atrey.karlin.mff.cuni.cz, Andrew Morton <akpm@osdl.org>,
	Greg KH <greg@kroah.com>
Cc: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
Subject: [RFC][PATCH 1/4] PCI legacy I/O port free driver - Introduce pci_set_bar_mask*()
Date: Tue, 14 Feb 2006 15:06:49 +0900	[thread overview]
Message-ID: <43F17379.8010900@jp.fujitsu.com> (raw)
In-Reply-To: <43F172BA.1020405@jp.fujitsu.com>

This patch introduces a new interface pci_select_resource() for PCI
device drivers to tell kernel what resources they want to use. This
interface enables some PCI device drivers to handle the devices even
if no I/O resources are allocated to the devices.

Signed-off-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>

 drivers/pci/pci.c   |   14 +++++++++-----
 drivers/pci/probe.c |    1 +
 include/linux/pci.h |   15 +++++++++++++++
 3 files changed, 25 insertions(+), 5 deletions(-)

Index: linux-2.6.16-rc3/drivers/pci/pci.c
===================================================================
--- linux-2.6.16-rc3.orig/drivers/pci/pci.c	2006-02-14 12:25:10.000000000 +0900
+++ linux-2.6.16-rc3/drivers/pci/pci.c	2006-02-14 12:27:59.000000000 +0900
@@ -497,7 +497,7 @@
 {
 	int err;
 
-	if ((err = pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1)))
+	if ((err = pci_enable_device_bars(dev, dev->bar_mask)))
 		return err;
 	pci_fixup_device(pci_fixup_enable, dev);
 	dev->is_enabled = 1;
@@ -535,6 +535,7 @@
 
 	pcibios_disable_device(dev);
 	dev->is_enabled = 0;
+	pci_set_bar_mask(dev, (1 << PCI_NUM_RESOURCES) - 1);
 }
 
 /**
@@ -681,7 +682,8 @@
 	int i;
 	
 	for (i = 0; i < 6; i++)
-		pci_release_region(pdev, i);
+		if (pdev->bar_mask & (1 << i))
+			pci_release_region(pdev, i);
 }
 
 /**
@@ -702,13 +704,15 @@
 	int i;
 	
 	for (i = 0; i < 6; i++)
-		if(pci_request_region(pdev, i, res_name))
-			goto err_out;
+		if (pdev->bar_mask & (1 << i))
+			if (pci_request_region(pdev, i, res_name))
+				goto err_out;
 	return 0;
 
 err_out:
 	while(--i >= 0)
-		pci_release_region(pdev, i);
+		if (pdev->bar_mask & (1 << i))
+			pci_release_region(pdev, i);
 		
 	return -EBUSY;
 }
Index: linux-2.6.16-rc3/drivers/pci/probe.c
===================================================================
--- linux-2.6.16-rc3.orig/drivers/pci/probe.c	2006-02-14 12:25:10.000000000 +0900
+++ linux-2.6.16-rc3/drivers/pci/probe.c	2006-02-14 12:27:59.000000000 +0900
@@ -803,6 +803,7 @@
 	dev->vendor = l & 0xffff;
 	dev->device = (l >> 16) & 0xffff;
 	dev->cfg_size = pci_cfg_space_size(dev);
+	pci_set_bar_mask(dev, (1 << PCI_NUM_RESOURCES) - 1);
 
 	/* Assume 32-bit PCI; let 64-bit PCI cards (which are far rarer)
 	   set this higher, assuming the system even supports it.  */
Index: linux-2.6.16-rc3/include/linux/pci.h
===================================================================
--- linux-2.6.16-rc3.orig/include/linux/pci.h	2006-02-14 12:25:13.000000000 +0900
+++ linux-2.6.16-rc3/include/linux/pci.h	2006-02-14 12:27:59.000000000 +0900
@@ -143,6 +143,7 @@
 	 */
 	unsigned int	irq;
 	struct resource resource[DEVICE_COUNT_RESOURCE]; /* I/O and memory regions + expansion ROMs */
+	int		bar_mask;	/* bitmask of BAR's to be enabled */
 
 	/* These fields are used by common fixups */
 	unsigned int	transparent:1;	/* Transparent PCI bridge */
@@ -695,6 +696,20 @@
 }
 #endif /* HAVE_ARCH_PCI_RESOURCE_TO_USER */
 
+static inline void pci_set_bar_mask(struct pci_dev *dev, int mask)
+{
+	dev->bar_mask = mask;
+}
+
+static inline void pci_set_bar_mask_by_resource(struct pci_dev *dev,
+						unsigned long mask)
+{
+	int i, bar_mask = 0;
+	for (i = 0; i < PCI_NUM_RESOURCES; i++)
+		if (pci_resource_flags(dev, i) & mask)
+			bar_mask |= (1 << i);
+	pci_set_bar_mask(dev, bar_mask);
+}
 
 /*
  *  The world is not perfect and supplies us with broken PCI devices.




  reply	other threads:[~2006-02-14  6:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-14  6:03 [RFC][PATCH 0/4] PCI legacy I/O port free driver Kenji Kaneshige
2006-02-14  6:06 ` Kenji Kaneshige [this message]
2006-02-15  5:07   ` [RFC][PATCH 1/4] PCI legacy I/O port free driver - Introduce pci_set_bar_mask*() Andrew Morton
2006-02-15  6:03     ` Kenji Kaneshige
2006-02-15  9:07       ` Russell King
2006-02-15 12:33         ` Kenji Kaneshige
2006-02-14  6:07 ` [RFC][PATCH 2/4] PCI legacy I/O port free driver - Update Documantion/pci.txt Kenji Kaneshige
2006-02-14  6:09 ` [RFC][PATCH 3/4] PCI legacy I/O port free driver - Make Intel e1000 driver legacy I/O port free Kenji Kaneshige
2006-02-14  6:10 ` [RFC][PATCH 4/4] PCI legacy I/O port free driver - Make Emulex lpfc " Kenji Kaneshige
2006-02-14  9:32 ` [RFC][PATCH 0/4] PCI legacy I/O port free driver Andi Kleen
2006-02-15  3:16   ` Kenji Kaneshige

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=43F17379.8010900@jp.fujitsu.com \
    --to=kaneshige.kenji@jp.fujitsu.com \
    --cc=akpm@osdl.org \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@atrey.karlin.mff.cuni.cz \
    /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