Skip to contentSkip to conversation

Remove dummy cb_config() and cb_release()

PATCH New Russell King 1 participant 6 messages Feb 23, 2003 Pcmcia

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 Remove dummy cb_config() and cb_release()

This patch appears not to be in 2.5.62, but applies cleanly.

Subject: [1/6] Remove dummy cb_config() and cb_release() cb_config() and cb_release() are just simple dummy functions that are only used in the internals of the PCMCIA code. We inline them where used.

 drivers/pcmcia/cardbus.c     |   32 --------------------------------
 drivers/pcmcia/cs.c          |    7 ++-----
 drivers/pcmcia/cs_internal.h |    2 --
 3 files changed, 2 insertions, 39 deletions
drivers/pcmcia/cardbus.c +0 -32
diff -ur orig/drivers/pcmcia/cardbus.c linux/drivers/pcmcia/cardbus.c
@@ -335,38 +335,6 @@
 
 /*=====================================================================
 
-    cb_config() has the job of allocating all system resources that
-    a Cardbus card requires.  Rather than using the CIS (which seems
-    to not always be present), it treats the card as an ordinary PCI
-    device, and probes the base address registers to determine each
-    function's IO and memory space needs.
-
-    It is called from the RequestIO card service.
-    
-======================================================================*/
-
-int cb_config(socket_info_t * s)
-{
-	return CS_SUCCESS;
-}
-
-/*======================================================================
-
-    cb_release() releases all the system resources (IO and memory
-    space, and interrupt) committed for a Cardbus card by a prior call
-    to cb_config().
-
-    It is called from the ReleaseIO() service.
-    
-======================================================================*/
-
-void cb_release(socket_info_t * s)
-{
-	DEBUG(0, "cs: cb_release(bus %d)\n", s->cap.cb_dev->subordinate->number);
-}
-
-/*=====================================================================
-
     cb_enable() has the job of configuring a socket for a Cardbus
     card, and initializing the card's PCI configuration registers.
 
drivers/pcmcia/cs.c +2 -5
diff -ur orig/drivers/pcmcia/cs.c linux/drivers/pcmcia/cs.c
@@ -1562,7 +1562,6 @@
     
 #ifdef CONFIG_CARDBUS
     if (handle->state & CLIENT_CARDBUS) {
-	cb_release(s);
 	return CS_SUCCESS;
     }
 #endif
@@ -1804,10 +1803,8 @@
 
     if (handle->state & CLIENT_CARDBUS) {
 #ifdef CONFIG_CARDBUS
-	int ret = cb_config(s);
-	if (ret == CS_SUCCESS)
-	    handle->state |= CLIENT_IO_REQ;
-	return ret;
+	handle->state |= CLIENT_IO_REQ;
+	return CS_SUCCESS;
 #else
 	return CS_UNSUPPORTED_FUNCTION;
 #endif
drivers/pcmcia/cs_internal.h +0 -2
diff -ur orig/drivers/pcmcia/cs_internal.h linux/drivers/pcmcia/cs_internal.h
@@ -198,8 +198,6 @@
 /* In cardbus.c */
 int cb_alloc(socket_info_t *s);
 void cb_free(socket_info_t *s);
-int cb_config(socket_info_t *s);
-void cb_release(socket_info_t *s);
 void cb_enable(socket_info_t *s);
 void cb_disable(socket_info_t *s);
 int read_cb_mem(socket_info_t *s, u_char fn, int space,
#1 lore raw

PATCH 2/6 Remove unused "dev" argument from cb_setup_cis_mem

This patch appears not to be in 2.5.62, but applies cleanly.

Subject: [2/6] Remove unused "dev" argument from cb_setup_cis_mem cb_setup_cis_mem doesn't reference the pci device. Remove this unused argument.

 drivers/pcmcia/cardbus.c |    4 ++--
 1 files changed, 2 insertions, 2 deletions
drivers/pcmcia/cardbus.c +2 -2
diff -ur -x sa11* -x Kconfig -x Makefile orig/drivers/pcmcia/cardbus.c linux/drivers/pcmcia/cardbus.c
@@ -146,7 +146,7 @@
 	}
 }
 
-static int cb_setup_cis_mem(socket_info_t * s, struct pci_dev *dev, struct resource *res)
+static int cb_setup_cis_mem(socket_info_t * s, struct resource *res)
 {
 	unsigned int start, size;
 
@@ -201,7 +201,7 @@
 	if (!res->flags)
 		goto fail;
 
-	if (cb_setup_cis_mem(s, dev, res) != 0)
+	if (cb_setup_cis_mem(s, res) != 0)
 		goto fail;
 
 	if (space == 7) {
#2 lore raw

PATCH 3/6 Remove "fn" argument from read_cb_mem()

This patch appears not to be in 2.5.62, but applies cleanly.

Subject: [3/6] Remove "fn" argument from read_cb_mem() read_cb_mem is only ever called with its "fn" argument set to zero. We therefore do not need to pass it.

 drivers/pcmcia/cardbus.c     |    5 ++---
 drivers/pcmcia/cistpl.c      |    4 ++--
 drivers/pcmcia/cs_internal.h |    3 +--
 3 files changed, 5 insertions, 7 deletions
drivers/pcmcia/cardbus.c +2 -3
diff -ur -x sa11* -x Kconfig -x Makefile orig/drivers/pcmcia/cardbus.c linux/drivers/pcmcia/cardbus.c
@@ -175,8 +175,7 @@
     
 =====================================================================*/
 
-int read_cb_mem(socket_info_t * s, u_char fn, int space,
-		u_int addr, u_int len, void *ptr)
+int read_cb_mem(socket_info_t * s, int space, u_int addr, u_int len, void *ptr)
 {
 	struct pci_dev *dev;
 	struct resource *res;
@@ -186,7 +185,7 @@
 	if (!s->cb_config)
 		goto fail;
 
-	dev = &s->cb_config[fn].dev;
+	dev = &s->cb_config[0].dev;
 
 	/* Config space? */
 	if (space == 0) {
drivers/pcmcia/cistpl.c +2 -2
diff -ur -x sa11* -x Kconfig -x Makefile orig/drivers/pcmcia/cistpl.c linux/drivers/pcmcia/cistpl.c
@@ -327,7 +327,7 @@
     }
 #ifdef CONFIG_CARDBUS
     if (s->state & SOCKET_CARDBUS)
-	ret = read_cb_mem(s, 0, attr, addr, len, ptr);
+	ret = read_cb_mem(s, attr, addr, len, ptr);
     else
 #endif
 	ret = read_cis_mem(s, attr, addr, len, ptr);
@@ -358,7 +358,7 @@
     for (i = 0; i < s->cis_used; i++) {
 #ifdef CONFIG_CARDBUS
 	if (s->state & SOCKET_CARDBUS)
-	    read_cb_mem(s, 0, s->cis_table[i].attr, s->cis_table[i].addr,
+	    read_cb_mem(s, s->cis_table[i].attr, s->cis_table[i].addr,
 			s->cis_table[i].len, buf);
 	else
 #endif
drivers/pcmcia/cs_internal.h +1 -2
diff -ur -x sa11* -x Kconfig -x Makefile orig/drivers/pcmcia/cs_internal.h linux/drivers/pcmcia/cs_internal.h
@@ -200,8 +200,7 @@
 void cb_free(socket_info_t *s);
 void cb_enable(socket_info_t *s);
 void cb_disable(socket_info_t *s);
-int read_cb_mem(socket_info_t *s, u_char fn, int space,
-		u_int addr, u_int len, void *ptr);
+int read_cb_mem(socket_info_t *s, int space, u_int addr, u_int len, void *ptr);
 void cb_release_cis_mem(socket_info_t *s);
 
 /* In cistpl.c */
#3 lore raw

PATCH 4/6 Remove pci_{read,write}[bwl]

This patch appears not to be in 2.5.62, but applies cleanly.

Subject: [4/6] Remove pci_{read,write}[bwl]
cardbus.c uses its own names for our PCI config space functions. Make it use our names.

 drivers/pcmcia/cardbus.c |   34 +++++++++++++++-------------------
 1 files changed, 15 insertions, 19 deletions
drivers/pcmcia/cardbus.c +15 -19
diff -ur -x sa11* -x Kconfig -x Makefile orig/drivers/pcmcia/cardbus.c linux/drivers/pcmcia/cardbus.c
@@ -75,13 +75,6 @@
 
 #define FIND_FIRST_BIT(n)	((n) - ((n) & ((n)-1)))
 
-#define pci_readb		pci_read_config_byte
-#define pci_writeb		pci_write_config_byte
-#define pci_readw		pci_read_config_word
-#define pci_writew		pci_write_config_word
-#define pci_readl		pci_read_config_dword
-#define pci_writel		pci_write_config_dword
-
 /* Offsets in the Expansion ROM Image Header */
 #define ROM_SIGNATURE		0x0000	/* 2 bytes */
 #define ROM_DATA_PTR		0x0018	/* 2 bytes */
@@ -192,7 +185,7 @@
 		if (addr + len > 0x100)
 			goto fail;
 		for (; len; addr++, ptr++, len--)
-			pci_readb(dev, addr, (u_char *) ptr);
+			pci_read_config_byte(dev, addr, ptr);
 		return 0;
 	}
 
@@ -243,17 +236,18 @@
 	tmp.sysdata = bus->sysdata;
 	tmp.devfn = 0;
 
-	pci_readw(&tmp, PCI_VENDOR_ID, &vend);
-	pci_readw(&tmp, PCI_DEVICE_ID, &dev);
+	pci_read_config_word(&tmp, PCI_VENDOR_ID, &vend);
+	pci_read_config_word(&tmp, PCI_DEVICE_ID, &dev);
 	printk(KERN_INFO "cs: cb_alloc(bus %d): vendor 0x%04x, "
 	       "device 0x%04x\n", bus->number, vend, dev);
 
-	pci_readb(&tmp, PCI_HEADER_TYPE, &hdr);
+	pci_read_config_byte(&tmp, PCI_HEADER_TYPE, &hdr);
 	fn = 1;
 	if (hdr & 0x80) {
 		do {
 			tmp.devfn = fn;
-			if (pci_readw(&tmp, PCI_VENDOR_ID, &v) || !v || v == 0xffff)
+			if (pci_read_config_word(&tmp, PCI_VENDOR_ID, &v) ||
+			    !v || v == 0xffff)
 				break;
 			fn++;
 		} while (fn < 8);
@@ -278,7 +272,7 @@
 
 		dev->devfn = i;
 		dev->vendor = vend;
-		pci_readw(dev, PCI_DEVICE_ID, &dev->device);
+		pci_read_config_word(dev, PCI_DEVICE_ID, &dev->device);
 		dev->hdr_type = hdr & 0x7f;
 		dev->dma_mask = 0xffffffff;
 		dev->dev.dma_mask = &dev->dma_mask;
@@ -295,7 +289,7 @@
 		}
 
 		/* Does this function have an interrupt at all? */
-		pci_readb(dev, PCI_INTERRUPT_PIN, &irq_pin);
+		pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &irq_pin);
 		if (irq_pin)
 			dev->irq = irq;
 		
@@ -305,7 +299,7 @@
 			continue;
 
 		if (irq_pin)
-			pci_writeb(dev, PCI_INTERRUPT_LINE, irq);
+			pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
 		
 		device_register(&dev->dev);
 		pci_insert_device(dev, bus);
@@ -360,15 +354,17 @@
 	/* Set up PCI interrupt and command registers */
 	for (i = 0; i < s->functions; i++) {
 		dev = &s->cb_config[i].dev;
-		pci_writeb(dev, PCI_COMMAND, PCI_COMMAND_MASTER |
-			   PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
-		pci_writeb(dev, PCI_CACHE_LINE_SIZE, L1_CACHE_BYTES / 4);
+		pci_write_config_byte(dev, PCI_COMMAND, PCI_COMMAND_MASTER |
+				      PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
+		pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,
+				      L1_CACHE_BYTES / 4);
 	}
 
 	if (s->irq.AssignedIRQ) {
 		for (i = 0; i < s->functions; i++) {
 			dev = &s->cb_config[i].dev;
-			pci_writeb(dev, PCI_INTERRUPT_LINE, s->irq.AssignedIRQ);
+			pci_write_config_byte(dev, PCI_INTERRUPT_LINE,
+					      s->irq.AssignedIRQ);
 		}
 		s->socket.io_irq = s->irq.AssignedIRQ;
 		s->ss_entry->set_socket(s->sock, &s->socket);
#4 lore raw

PATCH 5/6 Remove stack allocation of struct pci_dev

This patch appears not to be in 2.5.62, but applies cleanly.

Subject: [5/6] Remove stack allocation of struct pci_dev cb_alloc() allocated a pci_dev on the stack to access PCI space. This is unnecessary since we have pci_bus_*_config_* functions. Use these functions instead.

 drivers/pcmcia/cardbus.c |   14 ++++----------
 1 files changed, 4 insertions, 10 deletions
drivers/pcmcia/cardbus.c +4 -10
diff -ur -x sa11* -x Kconfig -x Makefile orig/drivers/pcmcia/cardbus.c linux/drivers/pcmcia/cardbus.c
@@ -224,29 +224,23 @@
 int cb_alloc(socket_info_t * s)
 {
 	struct pci_bus *bus;
-	struct pci_dev tmp;
 	u_short vend, v, dev;
 	u_char i, hdr, fn;
 	cb_config_t *c;
 	int irq;
 
 	bus = s->cap.cb_dev->subordinate;
-	memset(&tmp, 0, sizeof(tmp));
-	tmp.bus = bus;
-	tmp.sysdata = bus->sysdata;
-	tmp.devfn = 0;
 
-	pci_read_config_word(&tmp, PCI_VENDOR_ID, &vend);
-	pci_read_config_word(&tmp, PCI_DEVICE_ID, &dev);
+	pci_bus_read_config_word(bus, 0, PCI_VENDOR_ID, &vend);
+	pci_bus_read_config_word(bus, 0, PCI_DEVICE_ID, &dev);
 	printk(KERN_INFO "cs: cb_alloc(bus %d): vendor 0x%04x, "
 	       "device 0x%04x\n", bus->number, vend, dev);
 
-	pci_read_config_byte(&tmp, PCI_HEADER_TYPE, &hdr);
+	pci_bus_read_config_byte(bus, 0, PCI_HEADER_TYPE, &hdr);
 	fn = 1;
 	if (hdr & 0x80) {
 		do {
-			tmp.devfn = fn;
-			if (pci_read_config_word(&tmp, PCI_VENDOR_ID, &v) ||
+			if (pci_bus_read_config_word(bus, fn, PCI_VENDOR_ID, &v) ||
 			    !v || v == 0xffff)
 				break;
 			fn++;
#5 lore raw

PATCH 6/6 Always re-read vendor for each function

This patch appears not to be in 2.5.62, but applies cleanly.

Subject: [6/6] Always re-read vendor for each function We should probably always read the vendor ID from each function rather than assuming that it is identical to function 0.

 drivers/pcmcia/cardbus.c |    4 ++--
 1 files changed, 2 insertions, 2 deletions
drivers/pcmcia/cardbus.c +2 -2
diff -ur -x sa11* -x Kconfig -x Makefile orig/drivers/pcmcia/cardbus.c linux/drivers/pcmcia/cardbus.c
@@ -263,9 +263,9 @@
 		dev->sysdata = bus->sysdata;
 		dev->dev.parent = bus->dev;
 		dev->dev.bus = &pci_bus_type;
-
 		dev->devfn = i;
-		dev->vendor = vend;
+
+		pci_read_config_word(dev, PCI_VENDOR_ID, &dev->vendor);
 		pci_read_config_word(dev, PCI_DEVICE_ID, &dev->device);
 		dev->hdr_type = hdr & 0x7f;
 		dev->dma_mask = 0xffffffff;