[parisc-linux-cvs] PCI IO port mapping cleanup

Bjorn Helgaas bjorn_helgaas@hp.com
Wed, 16 May 2001 15:02:45 -0600


Reviewed by Grant.  Just replaces some bare numbers with macros.

Index: arch/parisc/kernel/lba_pci.c
===================================================================
RCS file: /home/cvs/parisc/linux/arch/parisc/kernel/lba_pci.c,v
retrieving revision 1.25
diff -u -p -r1.25 lba_pci.c
--- lba_pci.c	2001/04/06 05:10:54	1.25
+++ lba_pci.c	2001/05/16 20:37:12
@@ -1115,8 +1115,8 @@ lba_pat_resources( struct hp_device *d, 
 
 			r = &(lba_dev->hba.io_space);
 			r->name   = "LBA I/O Port";
-			r->start = lba_dev->hba.hba_num << 16;
-			r->end   = r->start + 0xffffUL;
+			r->start  = HBA_PORT_BASE(lba_dev->hba.hba_num);
+			r->end    = r->start + HBA_PORT_SPACE_SIZE - 1;
 			r->flags  = IORESOURCE_IO;
 			r->parent = r->sibling = r->child = NULL;
 			break;
@@ -1200,10 +1200,11 @@ lba_legacy_resources( struct hp_device *
 	r->name  = "LBA PCI I/O Ports";
 	r->flags = IORESOURCE_IO;
 	r->start = READ_REG32(d->hpa + LBA_IOS_BASE) & ~1L;
-	r->end   = r->start + (READ_REG32(d->hpa + LBA_IOS_MASK) ^ 0xffff) - 1;
+	r->end   = r->start +
+	    (READ_REG32(d->hpa + LBA_IOS_MASK) ^ (HBA_PORT_SPACE_SIZE - 1)) - 1;
 
 	/* Virtualize the I/O Port space ranges */
-	lba_num = lba_dev->hba.hba_num << 16;
+	lba_num = HBA_PORT_BASE(lba_dev->hba.hba_num);
 	r->start |= lba_num;
 	r->end   |= lba_num;
 }
Index: arch/parisc/kernel/pci.c
===================================================================
RCS file: /home/cvs/parisc/linux/arch/parisc/kernel/pci.c,v
retrieving revision 1.20
diff -u -p -r1.20 pci.c
--- pci.c	2001/03/11 07:05:58	1.20
+++ pci.c	2001/05/16 20:37:12
@@ -59,9 +59,6 @@ static struct pci_hba_data *parisc_pci_h
 **
 *********************************************************************/
 
-#define PCI_PORT_HBA(a) ((a)>>16)
-#define PCI_PORT_ADDR(a) ((a) & 0xffffUL)
-
 /* KLUGE : inb needs to be defined differently for PCI devices than
 ** for other bus interfaces. Doing this at runtime sucks but is the
 ** only way one driver binary can support devices on different bus types.
Index: drivers/gsc/dino.c
===================================================================
RCS file: /home/cvs/parisc/linux/drivers/gsc/dino.c,v
retrieving revision 1.26
diff -u -p -r1.26 dino.c
--- dino.c	2001/03/11 07:05:59	1.26
+++ dino.c	2001/05/16 20:37:12
@@ -660,7 +660,7 @@ dino_fixup_bus(struct pci_bus *bus)
 	struct list_head *ln;
         struct pci_dev *dev;
         struct dino_device *dino_dev = DINO_DEV(bus->sysdata);
-	int hba_num = dino_dev->hba.hba_num << 16;
+	int port_base = HBA_PORT_BASE(dino_dev->hba.hba_num);
 
 	DBG(KERN_WARNING __FUNCTION__ "(0x%p) bus %d sysdata 0x%p\n",
 				bus, bus->secondary, bus->sysdata);
@@ -687,8 +687,8 @@ dino_fixup_bus(struct pci_bus *bus)
 		for (i = 0; i < 6; i++) {
 			struct resource *res = &dev->resource[i];
 			if (res->flags & IORESOURCE_IO) {
-				res->start |= hba_num;
-				res->end |= hba_num;
+				res->start |= port_base;
+				res->end |= port_base;
 			}
 #ifdef __LP64__
 			/* Sign Extend MMIO addresses */
@@ -875,8 +875,8 @@ dino_common_init(struct dino_device *din
 	/* allocate I/O Port resource region */
 	res = &dino_dev->hba.io_space;
 	res->name = "Dino I/O Port space";
-	res->start = (unsigned long) dino_dev->hba.hba_num << 16;
-	res->end = res->start + 0xffffUL;
+	res->start = HBA_PORT_BASE(dino_dev->hba.hba_num);
+	res->end = res->start + (HBA_PORT_SPACE_SIZE - 1);
 	res->flags = IORESOURCE_IO; /* do not mark it busy ! */
 	res->child = NULL;
 	if (request_resource(&ioport_resource, res) < 0) {
Index: include/asm-parisc/pci.h
===================================================================
RCS file: /home/cvs/parisc/linux/include/asm-parisc/pci.h,v
retrieving revision 1.25
diff -u -p -r1.25 pci.h
--- pci.h	2001/03/02 10:31:51	1.25
+++ pci.h	2001/05/16 20:37:13
@@ -61,6 +61,18 @@ struct pci_hba_data {
 	/* REVISIT - spinlock to protect resources? */
 };
 
+/* 
+** We support 2^16 I/O ports per HBA.  These are set up in the form
+** 0xbbxxxx, where bb is the bus number and xxxx is the I/O port
+** space address.
+*/
+#define HBA_PORT_SPACE_BITS	16
+
+#define HBA_PORT_BASE(h)	((h) << HBA_PORT_SPACE_BITS)
+#define HBA_PORT_SPACE_SIZE	(1UL << HBA_PORT_SPACE_BITS)
+
+#define PCI_PORT_HBA(a)		((a) >> HBA_PORT_SPACE_BITS)
+#define PCI_PORT_ADDR(a)	((a) & (HBA_PORT_SPACE_SIZE - 1))
 
 /*
 ** KLUGE: linux/pci.h include asm/pci.h BEFORE declaring struct pci_bus