patch-2.1.93 linux/drivers/pci/pci.c

Next file: linux/drivers/pci/pcisyms.c
Previous file: linux/drivers/pci/oldproc.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.92/linux/drivers/pci/pci.c linux/drivers/pci/pci.c
@@ -1,42 +1,28 @@
 /*
- *	$Id: pci.c,v 1.55 1997/12/27 12:17:54 mj Exp $
+ *	$Id: pci.c,v 1.71 1998/03/30 11:14:35 mj Exp $
  *
- *	PCI services that are built on top of the BIOS32 service.
+ *	PCI Bus Services
  *
- *	Copyright 1993, 1994, 1995, 1997 Drew Eckhardt, Frederic Potter,
+ *	Copyright 1993 -- 1998 Drew Eckhardt, Frederic Potter,
  *	David Mosberger-Tang, Martin Mares
  */
 
 #include <linux/config.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
-#include <linux/bios32.h>
 #include <linux/pci.h>
 #include <linux/string.h>
 #include <linux/init.h>
+#include <linux/malloc.h>
 
 #include <asm/page.h>
 
 struct pci_bus pci_root;
-struct pci_dev *pci_devices = 0;
+struct pci_dev *pci_devices = NULL;
+static struct pci_dev **pci_last_dev_p = &pci_devices;
 
 #undef DEBUG
 
-/*
- * pci_malloc() returns initialized memory of size SIZE.  Can be
- * used only while pci_init() is active.
- */
-__initfunc(static void *pci_malloc(long size, unsigned long *mem_startp))
-{
-	void *mem;
-
-	mem = (void*) *mem_startp;
-	*mem_startp += (size + sizeof(void*) - 1) & ~(sizeof(void*) - 1);
-	memset(mem, 0, size);
-	return mem;
-}
-
-
 const char *pcibios_strerror(int error)
 {
 	static char buf[32];
@@ -68,7 +54,45 @@
 }
 
 
-unsigned int pci_scan_bus(struct pci_bus *bus, unsigned long *mem_startp)
+struct pci_dev *
+pci_find_slot(unsigned int bus, unsigned int devfn)
+{
+	struct pci_dev *dev;
+
+	for(dev=pci_devices; dev; dev=dev->next)
+		if (dev->bus->number == bus && dev->devfn == devfn)
+			break;
+	return dev;
+}
+
+
+struct pci_dev *
+pci_find_device(unsigned int vendor, unsigned int device, struct pci_dev *from)
+{
+	if (!from)
+		from = pci_devices;
+	else
+		from = from->next;
+	while (from && (from->vendor != vendor || from->device != device))
+		from = from->next;
+	return from;
+}
+
+
+struct pci_dev *
+pci_find_class(unsigned int class, struct pci_dev *from)
+{
+	if (!from)
+		from = pci_devices;
+	else
+		from = from->next;
+	while (from && from->class != class)
+		from = from->next;
+	return from;
+}
+
+
+__initfunc(unsigned int pci_scan_bus(struct pci_bus *bus))
 {
 	unsigned int devfn, l, max, class;
 	unsigned char cmd, irq, tmp, hdr_type, is_multi = 0;
@@ -97,7 +121,8 @@
 			continue;
 		}
 
-		dev = pci_malloc(sizeof(*dev), mem_startp);
+		dev = kmalloc(sizeof(*dev), GFP_ATOMIC);
+		memset(dev, 0, sizeof(*dev));
 		dev->bus = bus;
 		dev->devfn  = devfn;
 		dev->vendor = l & 0xffff;
@@ -113,13 +138,19 @@
 		pcibios_read_config_dword(bus->number, devfn, PCI_CLASS_REVISION, &class);
 		class >>= 8;				    /* upper 3 bytes */
 		dev->class = class;
+		dev->hdr_type = hdr_type;
 
 		switch (hdr_type & 0x7f) {		    /* header type */
-		case 0:					    /* standard header */
+		case PCI_HEADER_TYPE_NORMAL:		    /* standard header */
 			if (class >> 8 == PCI_CLASS_BRIDGE_PCI)
 				goto bad;
-			/* read irq level (may be changed during pcibios_fixup()): */
-			pcibios_read_config_byte(bus->number, dev->devfn, PCI_INTERRUPT_LINE, &irq);
+			/*
+			 * If the card generates interrupts, read IRQ number
+			 * (some architectures change it during pcibios_fixup())
+			 */
+			pcibios_read_config_byte(bus->number, dev->devfn, PCI_INTERRUPT_PIN, &irq);
+			if (irq)
+				pcibios_read_config_byte(bus->number, dev->devfn, PCI_INTERRUPT_LINE, &irq);
 			dev->irq = irq;
 			/*
 			 * read base address registers, again pcibios_fixup() can
@@ -130,7 +161,7 @@
 				dev->base_address[reg] = (l == 0xffffffff) ? 0 : l;
 			}
 			break;
-		case 1:					    /* bridge header */
+		case PCI_HEADER_TYPE_BRIDGE:		    /* bridge header */
 			if (class >> 8 != PCI_CLASS_BRIDGE_PCI)
 				goto bad;
 			for (reg = 0; reg < 2; reg++) {
@@ -138,6 +169,14 @@
 				dev->base_address[reg] = (l == 0xffffffff) ? 0 : l;
 			}
 			break;
+		case PCI_HEADER_TYPE_CARDBUS:		    /* CardBus bridge header */
+			if (class >> 16 != PCI_BASE_CLASS_BRIDGE)
+				goto bad;
+			for (reg = 0; reg < 2; reg++) {
+				pcibios_read_config_dword(bus->number, devfn, PCI_CB_MEMORY_BASE_0 + (reg << 3), &l);
+				dev->base_address[reg] = (l == 0xffffffff) ? 0 : l;
+			}
+			break;
 		default:				    /* unknown header */
 		bad:
 			printk(KERN_ERR "PCI: %02x:%02x [%04x/%04x/%06x] has unknown header type %02x, ignoring.\n",
@@ -154,8 +193,8 @@
 		 * Put it into the global PCI device chain. It's used to
 		 * find devices once everything is set up.
 		 */
-		dev->next = pci_devices;
-		pci_devices = dev;
+		*pci_last_dev_p = dev;
+		pci_last_dev_p = &dev->next;
 
 		/*
 		 * Now insert it into the list of devices held
@@ -174,7 +213,8 @@
 			/*
 			 * Insert it into the tree of buses.
 			 */
-			child = pci_malloc(sizeof(*child), mem_startp);
+			child = kmalloc(sizeof(*child), GFP_ATOMIC);
+			memset(child, 0, sizeof(*child));
 			child->next = bus->children;
 			bus->children = child;
 			child->self = dev;
@@ -203,11 +243,14 @@
 			pcibios_read_config_dword(bus->number, devfn, PCI_PRIMARY_BUS, &buses);
 			if ((buses & 0xFFFFFF) != 0)
 			  {
+			    unsigned int cmax;
+
 			    child->primary = buses & 0xFF;
 			    child->secondary = (buses >> 8) & 0xFF;
 			    child->subordinate = (buses >> 16) & 0xFF;
 			    child->number = child->secondary;
-			    max = pci_scan_bus(child, mem_startp);
+			    cmax = pci_scan_bus(child);
+			    if (cmax > max) max = cmax;
 			  }
 			else
 			  {
@@ -223,7 +266,7 @@
 			    /*
 			     * Now we can scan all subordinate buses:
 			     */
-			    max = pci_scan_bus(child, mem_startp);
+			    max = pci_scan_bus(child);
 			    /*
 			     * Set the subordinate bus number to its real
 			     * value:
@@ -250,36 +293,31 @@
 }
 
 
-__initfunc(unsigned long pci_init (unsigned long mem_start, unsigned long mem_end))
+__initfunc(void pci_init(void))
 {
-	mem_start = pcibios_init(mem_start, mem_end);
+	pcibios_init();
 
-	if (!pcibios_present()) {
+	if (!pci_present()) {
 		printk("PCI: No PCI bus detected\n");
-		return mem_start;
 	}
 
-	printk("Probing PCI hardware.\n");
+	printk("PCI: Probing PCI hardware.\n");
 
 	memset(&pci_root, 0, sizeof(pci_root));
-	pci_root.subordinate = pci_scan_bus(&pci_root, &mem_start);
+	pci_root.subordinate = pci_scan_bus(&pci_root);
 
 	/* give BIOS a chance to apply platform specific fixes: */
-	mem_start = pcibios_fixup(mem_start, mem_end);
+	pcibios_fixup();
 
 #ifdef CONFIG_PCI_OPTIMIZE
 	pci_quirks_init();
 #endif
-
-	return mem_start;
 }
 
-struct pci_dev *pci_find_dev(unsigned char bus, unsigned char devfn)
-{
-	struct pci_dev *pdev;
-	for (pdev = pci_devices; pdev; pdev = pdev->next) {
-		if ((pdev->bus->number==bus) && (pdev->devfn==devfn)) break;
 
-	}
-	return pdev;
+__initfunc(void pci_setup (char *str, int *ints))
+{
+	str = pcibios_setup(str);
+	if (*str)
+		printk(KERN_ERR "PCI: Unknown option `%s'\n", str);
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov