[PATCH] pc386 BSP PCI initialization fix [was: Re: PCI lookup issue: 3c905C-TX not found by RTEMS.]

Karel Gardas kgardas at objectsecurity.com
Tue Jan 25 16:47:30 UTC 2005


Hello,

thanks to help provided by Gregory Menke, I was finally able to get my
K6-2/3c905C-TX NIC machine working with RTEMS. As a result of my debug
trip thorough pcibios/elnk.c sources, I've created attached patch. It adds
some more verbose debugging when PCI_DEBUG is defined and fixes pci
initialization by directly calling pcib_init from BSP_pciFindDevice in
case PCI is not yet initialized. I've also tested applying it to the trunk
and it has gone well.

Thanks,
Karel
--
Karel Gardas                  kgardas at objectsecurity.com
ObjectSecurity Ltd.           http://www.objectsecurity.com
-------------- next part --------------
Index: c/src/lib/libbsp/i386/shared/pci/pcibios.c
===================================================================
RCS file: /usr1/CVS/rtems/c/src/lib/libbsp/i386/shared/pci/pcibios.c,v
retrieving revision 1.3.2.2
diff -u -r1.3.2.2 pcibios.c
--- c/src/lib/libbsp/i386/shared/pci/pcibios.c	27 Sep 2004 21:49:18 -0000	1.3.2.2
+++ c/src/lib/libbsp/i386/shared/pci/pcibios.c	25 Jan 2005 15:52:56 -0000
@@ -18,6 +18,7 @@
  * is flat and that stack is big enough 
  */ 
 
+/* #define PCI_DEBUG 1 */
 
 static int pcibInitialized = 0;
 static unsigned int pcibEntry;
@@ -39,6 +40,9 @@
 int 
 pcib_init(void)
 {
+#ifdef PCI_DEBUG
+  printk("PCI bus init\n");
+#endif /* PCI_DEBUG */
   unsigned char *ucp;
   unsigned char sum;
   int      i;
@@ -80,6 +84,9 @@
     }
 
   /* BIOS-32 found, let us find PCI BIOS */
+#ifdef PCI_DEBUG
+  printk("BIOS-32 found, let us find PCI BIOS\n");
+#endif /* PCI_DEBUG */
   ucp += 4;
 
   pcibExchg[0] = *(unsigned int *)ucp;
@@ -103,6 +110,9 @@
     }
 
   /* Found PCI entry point */
+#ifdef PCI_DEBUG
+  printk("Found PCI entry point\n");
+#endif /* PCI_DEBUG */
   pcibEntry = pcibExchg[1] + pcibExchg[3];
 
   /* Let us check whether PCI bios is present */
@@ -123,17 +133,26 @@
   if((pcibExchg[0] & 0xff00) != 0)
     {
       /* Not found */
+#ifdef PCI_DEBUG
+      printk("PCI BIOS not found!\n");
+#endif /* PCI_DEBUG */
       return PCIB_ERR_NOTPRESENT;
     }
 
   if(pcibExchg[3] != 0x20494350)
     {
       /* Signature does not match */
+#ifdef PCI_DEBUG
+      printk("PCI BIOS not found: signature does not match!\n");
+#endif /* PCI_DEBUG */
       return PCIB_ERR_NOTPRESENT;
     }
 
   /* Success */
   
+#ifdef PCI_DEBUG
+  printk("Found PCI BIOS\n");
+#endif /* PCI_DEBUG */
   pcibInitialized = 1;
   return PCIB_ERR_SUCCESS;
 }
@@ -231,6 +250,9 @@
 int
 BusCountPCI()
 {
+#ifdef PCI_DEBUG
+   printk("BusCountPCI: ");
+#endif /* PCI_DEBUG */
    if( ucBusCount == 0xff )
    {
       unsigned char bus,dev,hd;
@@ -272,8 +294,10 @@
          printk("BusCountPCI() found 0xff busses, assuming 1\n");
          ucBusCount = 1;
       }
-   }                       
-
+   }                  
+#ifdef PCI_DEBUG
+   printk("%d\n", ucBusCount);
+#endif /* PCI_DEBUG */
    return ucBusCount;
 }
 
@@ -285,8 +309,16 @@
    unsigned int d;
    unsigned short s;
    unsigned char bus,dev,fun,hd;
+   int bus_count;
+
+   if(!pcibInitialized)
+     {
+       pcib_init();
+     }
 
-   for (bus=0; bus<BusCountPCI(); bus++) 
+   bus_count = BusCountPCI();
+
+   for (bus=0; bus<bus_count; bus++) 
    {
       for (dev=0; dev<PCI_MAX_DEVICES; dev++) 
       {
@@ -313,11 +345,17 @@
 #endif
             /* pci_read_config_word(bus,dev,fun,PCI_VENDOR_ID,&s); */
             pcib_conf_read16(sig, 0, &s); 
+#ifdef PCI_DEBUG
+            printk("found vendor: %x at %d/%d/%d\n",s,bus,dev,fun);
+#endif
             if (vendorid != s)
                continue;
 
             /* pci_read_config_word(bus,dev,fun,PCI_DEVICE_ID,&s); */
             pcib_conf_read16(sig, 0x2, &s); 
+#ifdef PCI_DEBUG
+            printk("found device id: %x at %d/%d/%d\n",s,bus,dev,fun);
+#endif
             if (deviceid == s) {
                if (instance--) continue;
                *pbus=bus; 


More information about the users mailing list