Skip to contentSkip to conversation

PCI : Add selected_regions funcs

PATCH In review Hidetoshi Seto 4 participants 4 messages Nov 22, 2006 – Nov 23, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/5 PCI : Add selected_regions funcs

This patch adds the following changes into generic PCI code especially for PCI legacy I/O port free drivers.

- Added new pci_request_selected_regions() and pci_release_selected_regions() for PCI legacy I/O port free drivers in order to request/release only the selected regions.

- Added helper routine pci_select_bars() which makes proper mask of BARs from the specified resource type. This would be very helpful for users of pci_enable_device_bars().

---
 drivers/pci/pci.c   |   78 +++++++++++++++++++++++++++++++++++++++++-----------
 include/linux/pci.h |    3 ++
 2 files changed, 65 insertions(+), 16 deletions(-)
drivers/pci/pci.c +62 -16
Index: linux-2.6.19-rc6/drivers/pci/pci.c
===================================================================
@@ -758,6 +758,47 @@
 	return -EBUSY;
 }
 
+/**
+ * pci_release_selected_regions - Release selected PCI I/O and memory resources
+ * @pdev: PCI device whose resources were previously reserved
+ * @bars: Bitmask of BARs to be released
+ *
+ * Release selected PCI I/O and memory resources previously reserved.
+ * Call this function only after all use of the PCI regions has ceased.
+ */
+void pci_release_selected_regions(struct pci_dev *pdev, int bars)
+{
+	int i;
+
+	for (i = 0; i < 6; i++)
+		if (bars & (1 << i))
+			pci_release_region(pdev, i);
+}
+
+/**
+ * pci_request_selected_regions - Reserve selected PCI I/O and memory resources
+ * @pdev: PCI device whose resources are to be reserved
+ * @bars: Bitmask of BARs to be requested
+ * @res_name: Name to be associated with resource
+ */
+int pci_request_selected_regions(struct pci_dev *pdev, int bars,
+				 const char *res_name)
+{
+	int i;
+
+	for (i = 0; i < 6; i++)
+		if (bars & (1 << i))
+			if(pci_request_region(pdev, i, res_name))
+				goto err_out;
+	return 0;
+
+err_out:
+	while(--i >= 0)
+		if (bars & (1 << i))
+			pci_release_region(pdev, i);
+
+	return -EBUSY;
+}
 
 /**
  *	pci_release_regions - Release reserved PCI I/O and memory resources
@@ -770,10 +811,7 @@
 
 void pci_release_regions(struct pci_dev *pdev)
 {
-	int i;
-	
-	for (i = 0; i < 6; i++)
-		pci_release_region(pdev, i);
+	pci_release_selected_regions(pdev, (1 << 6) - 1);
 }
 
 /**
@@ -791,18 +829,7 @@
  */
 int pci_request_regions(struct pci_dev *pdev, const char *res_name)
 {
-	int i;
-	
-	for (i = 0; i < 6; i++)
-		if(pci_request_region(pdev, i, res_name))
-			goto err_out;
-	return 0;
-
-err_out:
-	while(--i >= 0)
-		pci_release_region(pdev, i);
-		
-	return -EBUSY;
+	return pci_request_selected_regions(pdev, ((1 << 6) - 1), res_name);
 }
 
 /**
@@ -975,6 +1002,22 @@
 }
 #endif
 
+/**
+ * pci_select_bars - Make BAR mask from the type of resource
+ * @pdev: the PCI device for which BAR mask is made
+ * @flags: resource type mask to be selected
+ *
+ * This helper routine makes bar mask from the type of resource.
+ */
+int pci_select_bars(struct pci_dev *dev, unsigned long flags)
+{
+	int i, bars = 0;
+	for (i = 0; i < PCI_NUM_RESOURCES; i++)
+		if (pci_resource_flags(dev, i) & flags)
+			bars |= (1 << i);
+	return bars;
+}
+
 static int __devinit pci_init(void)
 {
 	struct pci_dev *dev = NULL;
@@ -1023,6 +1066,8 @@
 EXPORT_SYMBOL(pci_request_regions);
 EXPORT_SYMBOL(pci_release_region);
 EXPORT_SYMBOL(pci_request_region);
+EXPORT_SYMBOL(pci_release_selected_regions);
+EXPORT_SYMBOL(pci_request_selected_regions);
 EXPORT_SYMBOL(pci_set_master);
 EXPORT_SYMBOL(pci_set_mwi);
 EXPORT_SYMBOL(pci_clear_mwi);
@@ -1031,6 +1076,7 @@
 EXPORT_SYMBOL(pci_set_consistent_dma_mask);
 EXPORT_SYMBOL(pci_assign_resource);
 EXPORT_SYMBOL(pci_find_parent_resource);
+EXPORT_SYMBOL(pci_select_bars);
 
 EXPORT_SYMBOL(pci_set_power_state);
 EXPORT_SYMBOL(pci_save_state);
include/linux/pci.h +3 -0
Index: linux-2.6.19-rc6/include/linux/pci.h
===================================================================
@@ -514,6 +514,7 @@
 int __must_check pci_assign_resource(struct pci_dev *dev, int i);
 int __must_check pci_assign_resource_fixed(struct pci_dev *dev, int i);
 void pci_restore_bars(struct pci_dev *dev);
+int pci_select_bars(struct pci_dev *dev, unsigned long flags);
 
 /* ROM control related routines */
 void __iomem __must_check *pci_map_rom(struct pci_dev *pdev, size_t *size);
@@ -542,6 +543,8 @@
 void pci_release_regions(struct pci_dev *);
 int __must_check pci_request_region(struct pci_dev *, int, const char *);
 void pci_release_region(struct pci_dev *, int);
+int pci_request_selected_regions(struct pci_dev *, int, const char *);
+void pci_release_selected_regions(struct pci_dev *, int);
 
 /* drivers/pci/bus.c */
 int __must_check pci_bus_alloc_resource(struct pci_bus *bus,
#1 lore raw

Hi Hidetoshi Seto,

bitfields (and bitmask) should be unsigned and use machine word size, which is usually "long". So please pass them in "unsigned long" instead of "int".

Quoted 5 lines · Hidetoshi Seto
drivers/pci/pci.c +0 -0
@@ -758,6 +758,47 @@
 	return -EBUSY;
 }

drivers/pci/pci.c line 769

Quoted 10 lines
drivers/pci/pci.c +9 -0
 
+/**
+ * pci_release_selected_regions - Release selected PCI I/O and memory resources
+ * @pdev: PCI device whose resources were previously reserved
+ * @bars: Bitmask of BARs to be released
+ *
+ * Release selected PCI I/O and memory resources previously reserved.
+ * Call this function only after all use of the PCI regions has ceased.
+ */
+void pci_release_selected_regions(struct pci_dev *pdev, int bars)

"unsigned long bars" here

drivers/pci/pci.c line 771

Quoted 2 lines
drivers/pci/pci.c +2 -0
+{
+	int i;

"unsigned long i" here

Quoted 5 lines
drivers/pci/pci.c +5 -0
+
+	for (i = 0; i < 6; i++)
+		if (bars & (1 << i))
+			pci_release_region(pdev, i);
+}

drivers/pci/pci.c line 786

Quoted 10 lines
drivers/pci/pci.c +10 -0
+
+/**
+ * pci_request_selected_regions - Reserve selected PCI I/O and memory resources
+ * @pdev: PCI device whose resources are to be reserved
+ * @bars: Bitmask of BARs to be requested
+ * @res_name: Name to be associated with resource
+ */
+int pci_request_selected_regions(struct pci_dev *pdev, int bars,
+				 const char *res_name)
+{

"unsigned long bars" here

drivers/pci/pci.c line 787

Quoted 1 line
drivers/pci/pci.c +1 -0
+	int i;

"unsigned long i" here

drivers/pci/pci.c line 1012

Quoted 12 lines
drivers/pci/pci.c +8 -0
@@ -975,6 +1002,22 @@
 }
 #endif
 
+/**
+ * pci_select_bars - Make BAR mask from the type of resource
+ * @pdev: the PCI device for which BAR mask is made
+ * @flags: resource type mask to be selected
+ *
+ * This helper routine makes bar mask from the type of resource.
+ */
+int pci_select_bars(struct pci_dev *dev, unsigned long flags)

unsigned long pci_select_bars(struct pci_dev *dev, unsigned long flags)

drivers/pci/pci.c line 1014

Quoted 2 lines
drivers/pci/pci.c +2 -0
+{
+	int i, bars = 0;

"unsigned long i, bars" here

Quoted 31 lines
drivers/pci/pci.c +9 -0
+	for (i = 0; i < PCI_NUM_RESOURCES; i++)
+		if (pci_resource_flags(dev, i) & flags)
+			bars |= (1 << i);
+	return bars;
+}
+
 static int __devinit pci_init(void)
 {
 	struct pci_dev *dev = NULL;
@@ -1023,6 +1066,8 @@
 EXPORT_SYMBOL(pci_request_regions);
 EXPORT_SYMBOL(pci_release_region);
 EXPORT_SYMBOL(pci_request_region);
+EXPORT_SYMBOL(pci_release_selected_regions);
+EXPORT_SYMBOL(pci_request_selected_regions);
 EXPORT_SYMBOL(pci_set_master);
 EXPORT_SYMBOL(pci_set_mwi);
 EXPORT_SYMBOL(pci_clear_mwi);
@@ -1031,6 +1076,7 @@
 EXPORT_SYMBOL(pci_set_consistent_dma_mask);
 EXPORT_SYMBOL(pci_assign_resource);
 EXPORT_SYMBOL(pci_find_parent_resource);
+EXPORT_SYMBOL(pci_select_bars);
 
 EXPORT_SYMBOL(pci_set_power_state);
 EXPORT_SYMBOL(pci_save_state);

Index: linux-2.6.19-rc6/include/linux/pci.h
===================================================================

include/linux/pci.h line 517

Quoted 4 lines
include/linux/pci.h +1 -0
@@ -514,6 +514,7 @@
 int __must_check pci_assign_resource(struct pci_dev *dev, int i);
 int __must_check pci_assign_resource_fixed(struct pci_dev *dev, int i);
 void pci_restore_bars(struct pci_dev *dev);
+int pci_select_bars(struct pci_dev *dev, unsigned long flags);

unsigned long pci_select_bars(struct pci_dev *dev, unsigned long flags)

include/linux/pci.h line 547

Quoted 9 lines
include/linux/pci.h +2 -0
 /* ROM control related routines */
 void __iomem __must_check *pci_map_rom(struct pci_dev *pdev, size_t *size);
@@ -542,6 +543,8 @@
 void pci_release_regions(struct pci_dev *);
 int __must_check pci_request_region(struct pci_dev *, int, const char *);
 void pci_release_region(struct pci_dev *, int);
+int pci_request_selected_regions(struct pci_dev *, int, const char *);
+void pci_release_selected_regions(struct pci_dev *, int);

int pci_request_selected_regions(struct pci_dev *, unsigned long, const char *); void pci_release_selected_regions(struct pci_dev *, unsigned long);

Regards

Ingo Oeser

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

#2 lore raw
Quoted 2 lines · Ingo Oeser

bitfields (and bitmask) should be unsigned and use machine word size, which is usually "long". So please pass them in "unsigned long" instead of "int".

Why? We know how many BARs PCI devices have (6. Plus ROM. Plus 4 bridge resources, making 11). We could even use a u16. An int is fine, there's no need to re-spin this patch.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

#3 lore raw
In reply to Ingo Oeser
Quoted 4 lines · On Thu, 23 Nov 2006 20:33:32 +0100 Ingo Oeser <[email protected]> wrote:

Hi Hidetoshi Seto,

bitfields (and bitmask) should be unsigned and use machine word size, which is usually "long". So please pass them in "unsigned long" instead of "int".

There are a fixed number of BARs , besides which the interface already uses int for the mask in pci_enable_device_bars() so the use of int is fine and continues the existing API.