* [PATCH 1/4] PCI legacy I/O port free driver (take5) - changes to generic PCI code
2006-03-07 5:53 [PATCH 0/4] PCI legacy I/O port free driver (take5) Kenji Kaneshige
@ 2006-03-07 5:56 ` Kenji Kaneshige
2006-03-07 5:57 ` [PATCH 2/4] PCI legacy I/O port free driver (take5) - Update Documentation/pci.txt Kenji Kaneshige
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Kenji Kaneshige @ 2006-03-07 5:56 UTC (permalink / raw)
To: Greg KH; +Cc: Kenji Kaneshige, Linux Kernel Mailing List, linux-pci
This patch adds the following changes into generic PCI code especially
for PCI legacy free drivers.
- Moved the following two things from pci_enable_device() into
pci_enable_device_bars(). By this change, we can use
pci_enable_device_bars() to enable only the specific regions.
o Call pci_fixup_device() on the device
o Set dev->is_enabled
- Added new field 'bars_enabled' into struct pci_device to
remember which BARs already enabled. This new field is
initialized at pci_enable_device_bars() time and cleared
at pci_disable_device() time.
- Changed pci_request_regions()/pci_release_regions() to
request/release only the regions which have already been
enabled.
- 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().
Signed-off-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
---
drivers/pci/pci-driver.c | 3 ++-
drivers/pci/pci.c | 30 +++++++++++++++++++++++-------
include/linux/pci.h | 12 ++++++++++++
3 files changed, 37 insertions(+), 8 deletions(-)
Index: linux-2.6.16-rc5-mm2/drivers/pci/pci-driver.c
===================================================================
--- linux-2.6.16-rc5-mm2.orig/drivers/pci/pci-driver.c 2006-03-07 13:45:33.000000000 +0900
+++ linux-2.6.16-rc5-mm2/drivers/pci/pci-driver.c 2006-03-07 13:45:39.000000000 +0900
@@ -294,7 +294,8 @@
pci_restore_state(pci_dev);
/* if the device was enabled before suspend, reenable */
if (pci_dev->is_enabled)
- retval = pci_enable_device(pci_dev);
+ retval = pci_enable_device_bars(pci_dev,
+ pci_dev->bars_enabled);
/* if the device was busmaster before the suspend, make it busmaster again */
if (pci_dev->is_busmaster)
pci_set_master(pci_dev);
Index: linux-2.6.16-rc5-mm2/drivers/pci/pci.c
===================================================================
--- linux-2.6.16-rc5-mm2.orig/drivers/pci/pci.c 2006-03-07 13:45:33.000000000 +0900
+++ linux-2.6.16-rc5-mm2/drivers/pci/pci.c 2006-03-07 14:07:09.000000000 +0900
@@ -493,6 +493,9 @@
err = pcibios_enable_device(dev, bars);
if (err < 0)
return err;
+ pci_fixup_device(pci_fixup_enable, dev);
+ dev->is_enabled = 1;
+ dev->bars_enabled = bars;
return 0;
}
@@ -510,8 +513,6 @@
int err = pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1);
if (err)
return err;
- pci_fixup_device(pci_fixup_enable, dev);
- dev->is_enabled = 1;
return 0;
}
@@ -546,6 +547,7 @@
pcibios_disable_device(dev);
dev->is_enabled = 0;
+ dev->bars_enabled = 0;
}
/**
@@ -628,6 +630,12 @@
{
if (pci_resource_len(pdev, bar) == 0)
return;
+ if (!(pdev->bars_enabled & (1 << bar))) {
+ dev_warn(&pdev->dev,
+ "Trying to release region #%d that is not enabled\n",
+ bar + 1);
+ return;
+ }
if (pci_resource_flags(pdev, bar) & IORESOURCE_IO)
release_region(pci_resource_start(pdev, bar),
pci_resource_len(pdev, bar));
@@ -654,7 +662,12 @@
{
if (pci_resource_len(pdev, bar) == 0)
return 0;
-
+ if (!(pdev->bars_enabled & (1 << bar))) {
+ dev_warn(&pdev->dev,
+ "Trying to request region #%d that is not enabled\n",
+ bar + 1);
+ goto err_out;
+ }
if (pci_resource_flags(pdev, bar) & IORESOURCE_IO) {
if (!request_region(pci_resource_start(pdev, bar),
pci_resource_len(pdev, bar), res_name))
@@ -692,7 +705,8 @@
int i;
for (i = 0; i < 6; i++)
- pci_release_region(pdev, i);
+ if (pdev->bars_enabled & (1 << i))
+ pci_release_region(pdev, i);
}
/**
@@ -713,13 +727,15 @@
int i;
for (i = 0; i < 6; i++)
- if(pci_request_region(pdev, i, res_name))
- goto err_out;
+ if (pdev->bars_enabled & (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->bars_enabled & (1 << i))
+ pci_release_region(pdev, i);
return -EBUSY;
}
Index: linux-2.6.16-rc5-mm2/include/linux/pci.h
===================================================================
--- linux-2.6.16-rc5-mm2.orig/include/linux/pci.h 2006-03-07 13:45:33.000000000 +0900
+++ linux-2.6.16-rc5-mm2/include/linux/pci.h 2006-03-07 13:45:39.000000000 +0900
@@ -169,6 +169,7 @@
struct bin_attribute *rom_attr; /* attribute descriptor for sysfs ROM entry */
int rom_attr_enabled; /* has display of the rom attribute been enabled? */
struct bin_attribute *res_attr[DEVICE_COUNT_RESOURCE]; /* sysfs file for resources */
+ int bars_enabled; /* BARs enabled */
};
#define pci_dev_g(n) list_entry(n, struct pci_dev, global_list)
@@ -732,6 +733,17 @@
}
#endif /* HAVE_ARCH_PCI_RESOURCE_TO_USER */
+/*
+ * This helper routine makes bar mask from the type of resource.
+ */
+static inline 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;
+}
/*
* The world is not perfect and supplies us with broken PCI devices.
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 3/4] PCI legacy I/O port free driver (take5) - Make Intel e1000 driver legacy I/O port free
2006-03-07 5:53 [PATCH 0/4] PCI legacy I/O port free driver (take5) Kenji Kaneshige
2006-03-07 5:56 ` [PATCH 1/4] PCI legacy I/O port free driver (take5) - changes to generic PCI code Kenji Kaneshige
2006-03-07 5:57 ` [PATCH 2/4] PCI legacy I/O port free driver (take5) - Update Documentation/pci.txt Kenji Kaneshige
@ 2006-03-07 5:58 ` Kenji Kaneshige
2006-03-07 5:59 ` [PATCH 4/4] PCI legacy I/O port free driver (take5) - Make Emulex lpfc " Kenji Kaneshige
3 siblings, 0 replies; 5+ messages in thread
From: Kenji Kaneshige @ 2006-03-07 5:58 UTC (permalink / raw)
To: Greg KH; +Cc: Kenji Kaneshige, Linux Kernel Mailing List, linux-pci
This patch makes Intel e1000 driver legacy I/O port free.
Signed-off-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
---
drivers/net/e1000/e1000.h | 6 +-
drivers/net/e1000/e1000_main.c | 117 ++++++++++++++++++++++-------------------
2 files changed, 68 insertions(+), 55 deletions(-)
Index: linux-2.6.16-rc5-mm2/drivers/net/e1000/e1000.h
===================================================================
--- linux-2.6.16-rc5-mm2.orig/drivers/net/e1000/e1000.h 2006-03-07 14:06:49.000000000 +0900
+++ linux-2.6.16-rc5-mm2/drivers/net/e1000/e1000.h 2006-03-07 14:07:21.000000000 +0900
@@ -77,8 +77,9 @@
#define BAR_1 1
#define BAR_5 5
-#define INTEL_E1000_ETHERNET_DEVICE(device_id) {\
- PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
+#define E1000_NO_IOPORT (1 << 0)
+#define INTEL_E1000_ETHERNET_DEVICE(device_id, flags) {\
+ PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id), .driver_data = flags}
struct e1000_adapter;
@@ -358,6 +359,7 @@
#ifdef CONFIG_PCI_MSI
boolean_t have_msi;
#endif
+ int bars; /* BARs to be enabled */
};
Index: linux-2.6.16-rc5-mm2/drivers/net/e1000/e1000_main.c
===================================================================
--- linux-2.6.16-rc5-mm2.orig/drivers/net/e1000/e1000_main.c 2006-03-07 14:06:49.000000000 +0900
+++ linux-2.6.16-rc5-mm2/drivers/net/e1000/e1000_main.c 2006-03-07 14:07:21.000000000 +0900
@@ -115,51 +115,51 @@
* {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
*/
static struct pci_device_id e1000_pci_tbl[] = {
- INTEL_E1000_ETHERNET_DEVICE(0x1000),
- INTEL_E1000_ETHERNET_DEVICE(0x1001),
- INTEL_E1000_ETHERNET_DEVICE(0x1004),
- INTEL_E1000_ETHERNET_DEVICE(0x1008),
- INTEL_E1000_ETHERNET_DEVICE(0x1009),
- INTEL_E1000_ETHERNET_DEVICE(0x100C),
- INTEL_E1000_ETHERNET_DEVICE(0x100D),
- INTEL_E1000_ETHERNET_DEVICE(0x100E),
- INTEL_E1000_ETHERNET_DEVICE(0x100F),
- INTEL_E1000_ETHERNET_DEVICE(0x1010),
- INTEL_E1000_ETHERNET_DEVICE(0x1011),
- INTEL_E1000_ETHERNET_DEVICE(0x1012),
- INTEL_E1000_ETHERNET_DEVICE(0x1013),
- INTEL_E1000_ETHERNET_DEVICE(0x1014),
- INTEL_E1000_ETHERNET_DEVICE(0x1015),
- INTEL_E1000_ETHERNET_DEVICE(0x1016),
- INTEL_E1000_ETHERNET_DEVICE(0x1017),
- INTEL_E1000_ETHERNET_DEVICE(0x1018),
- INTEL_E1000_ETHERNET_DEVICE(0x1019),
- INTEL_E1000_ETHERNET_DEVICE(0x101A),
- INTEL_E1000_ETHERNET_DEVICE(0x101D),
- INTEL_E1000_ETHERNET_DEVICE(0x101E),
- INTEL_E1000_ETHERNET_DEVICE(0x1026),
- INTEL_E1000_ETHERNET_DEVICE(0x1027),
- INTEL_E1000_ETHERNET_DEVICE(0x1028),
- INTEL_E1000_ETHERNET_DEVICE(0x105E),
- INTEL_E1000_ETHERNET_DEVICE(0x105F),
- INTEL_E1000_ETHERNET_DEVICE(0x1060),
- INTEL_E1000_ETHERNET_DEVICE(0x1075),
- INTEL_E1000_ETHERNET_DEVICE(0x1076),
- INTEL_E1000_ETHERNET_DEVICE(0x1077),
- INTEL_E1000_ETHERNET_DEVICE(0x1078),
- INTEL_E1000_ETHERNET_DEVICE(0x1079),
- INTEL_E1000_ETHERNET_DEVICE(0x107A),
- INTEL_E1000_ETHERNET_DEVICE(0x107B),
- INTEL_E1000_ETHERNET_DEVICE(0x107C),
- INTEL_E1000_ETHERNET_DEVICE(0x107D),
- INTEL_E1000_ETHERNET_DEVICE(0x107E),
- INTEL_E1000_ETHERNET_DEVICE(0x107F),
- INTEL_E1000_ETHERNET_DEVICE(0x108A),
- INTEL_E1000_ETHERNET_DEVICE(0x108B),
- INTEL_E1000_ETHERNET_DEVICE(0x108C),
- INTEL_E1000_ETHERNET_DEVICE(0x1099),
- INTEL_E1000_ETHERNET_DEVICE(0x109A),
- INTEL_E1000_ETHERNET_DEVICE(0x10B5),
+ INTEL_E1000_ETHERNET_DEVICE(0x1000, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x1001, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x1004, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x1008, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x1009, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x100C, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x100D, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x100E, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x100F, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x1010, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x1011, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x1012, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x1013, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x1014, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x1015, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x1016, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x1017, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x1018, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x1019, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x101A, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x101D, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x101E, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x1026, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x1027, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x1028, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x105E, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x105F, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x1060, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x1075, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x1076, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x1077, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x1078, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x1079, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x107A, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x107B, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x107C, 0),
+ INTEL_E1000_ETHERNET_DEVICE(0x107D, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x107E, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x107F, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x108A, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x108B, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x108C, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x1099, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x109A, E1000_NO_IOPORT),
+ INTEL_E1000_ETHERNET_DEVICE(0x10B5, E1000_NO_IOPORT),
/* required last entry */
{0,}
};
@@ -652,7 +652,14 @@
int i, err, pci_using_dac;
uint16_t eeprom_data;
uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
- if ((err = pci_enable_device(pdev)))
+ int bars;
+
+ if (ent->driver_data & E1000_NO_IOPORT)
+ bars = pci_select_bars(pdev, IORESOURCE_MEM);
+ else
+ bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
+
+ if ((err = pci_enable_device_bars(pdev, bars)))
return err;
if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
@@ -685,6 +692,7 @@
adapter->pdev = pdev;
adapter->hw.back = adapter;
adapter->msg_enable = (1 << debug) - 1;
+ adapter->bars = bars;
mmio_start = pci_resource_start(pdev, BAR_0);
mmio_len = pci_resource_len(pdev, BAR_0);
@@ -695,12 +703,15 @@
goto err_ioremap;
}
- for (i = BAR_1; i <= BAR_5; i++) {
- if (pci_resource_len(pdev, i) == 0)
- continue;
- if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
- adapter->hw.io_base = pci_resource_start(pdev, i);
- break;
+ if (!(ent->driver_data & E1000_NO_IOPORT)) {
+ for (i = BAR_1; i <= BAR_5; i++) {
+ if (pci_resource_len(pdev, i) == 0)
+ continue;
+ if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
+ adapter->hw.io_base =
+ pci_resource_start(pdev, i);
+ break;
+ }
}
}
@@ -4642,7 +4653,7 @@
if (retval)
DPRINTK(PROBE, ERR, "Error in setting power state\n");
e1000_pci_restore_state(adapter);
- ret_val = pci_enable_device(pdev);
+ ret_val = pci_enable_device_bars(pdev, adapter->bars);
pci_set_master(pdev);
retval = pci_enable_wake(pdev, PCI_D3hot, 0);
^ permalink raw reply [flat|nested] 5+ messages in thread