changeset 8776:298208d7a703

pci_scan cleanup, idea and initial patch by Aurelien Jacobs <aurel@gnuage.org>
author alex
date Sat, 04 Jan 2003 19:01:36 +0000
parents a70875598bf7
children bd9daec7b087
files libdha/pci.c
diffstat 1 files changed, 22 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/libdha/pci.c	Sat Jan 04 17:52:14 2003 +0000
+++ b/libdha/pci.c	Sat Jan 04 19:01:36 2003 +0000
@@ -494,44 +494,42 @@
 #endif
 #endif
  
-static int pcicards=0 ;
 static pciinfo_t *pci_lst;
  
-static void identify_card(struct pci_config_reg *pcr)
+static void identify_card(struct pci_config_reg *pcr, int idx)
 {
- 
-  if (pcicards>=MAX_PCI_DEVICES) return ;
+  /* local overflow test */ 
+  if (idx>=MAX_PCI_DEVICES) return ;
  
-  pci_lst[pcicards].bus     = pcibus ;
-  pci_lst[pcicards].card    = pcicard ;
-  pci_lst[pcicards].func    = pcifunc ;
-  pci_lst[pcicards].vendor  = pcr->_vendor ;
-  pci_lst[pcicards].device  = pcr->_device ;
-  pci_lst[pcicards].base0   = 0xFFFFFFFF ;
-  pci_lst[pcicards].base1   = 0xFFFFFFFF ;
-  pci_lst[pcicards].base2   = 0xFFFFFFFF ;
-  pci_lst[pcicards].baserom = 0x000C0000 ;
-  if (pcr->_base0) pci_lst[pcicards].base0 = pcr->_base0 &
+  pci_lst[idx].bus     = pcibus ;
+  pci_lst[idx].card    = pcicard ;
+  pci_lst[idx].func    = pcifunc ;
+  pci_lst[idx].vendor  = pcr->_vendor ;
+  pci_lst[idx].device  = pcr->_device ;
+  pci_lst[idx].base0   = 0xFFFFFFFF ;
+  pci_lst[idx].base1   = 0xFFFFFFFF ;
+  pci_lst[idx].base2   = 0xFFFFFFFF ;
+  pci_lst[idx].baserom = 0x000C0000 ;
+  if (pcr->_base0) pci_lst[idx].base0 = pcr->_base0 &
                      ((pcr->_base0&0x1) ? 0xFFFFFFFC : 0xFFFFFFF0) ;
-  if (pcr->_base1) pci_lst[pcicards].base1 = pcr->_base1 &
+  if (pcr->_base1) pci_lst[idx].base1 = pcr->_base1 &
                      ((pcr->_base1&0x1) ? 0xFFFFFFFC : 0xFFFFFFF0) ;
-  if (pcr->_base2) pci_lst[pcicards].base2 = pcr->_base2 &
+  if (pcr->_base2) pci_lst[idx].base2 = pcr->_base2 &
                      ((pcr->_base2&0x1) ? 0xFFFFFFFC : 0xFFFFFFF0) ;
-  if (pcr->_baserom) pci_lst[pcicards].baserom = pcr->_baserom ;
- 
-  pcicards++;
+  if (pcr->_baserom) pci_lst[idx].baserom = pcr->_baserom ;
 }
 
 /*main(int argc, char *argv[])*/
 int pci_scan(pciinfo_t *pci_list,unsigned *num_pci)
 {
-    unsigned int idx;
+    unsigned int idx = 0;
     struct pci_config_reg pcr;
     int do_mode1_scan = 0, do_mode2_scan = 0;
     int func, hostbridges=0;
     int ret = -1;
     
     pci_lst = pci_list;
+    *num_pci = 0;
  
     ret = enable_os_io();
     if (ret != 0)
@@ -549,7 +547,6 @@
     pcr._pcibuses[0] = 0;
     pcr._pcinumbus = 1;
     pcr._pcibusidx = 0;
-    idx = 0;
  
     do {
         /*printf("Probing for devices on PCI bus %d:\n\n", pcr._pcibusidx);*/
@@ -624,12 +621,12 @@
 	    if (idx++ >= MAX_PCI_DEVICES)
 	        continue;
  
-	    identify_card(&pcr);
+	    identify_card(&pcr, (*num_pci)++);
 	  } while( func < 8 );
         }
     } while (++pcr._pcibusidx < pcr._pcinumbus);
     }
- 
+
 #if !defined(__alpha__) && !defined(__powerpc__)
     /* Now try pci config 2 probe (deprecated) */
  
@@ -684,17 +681,16 @@
 	    if (idx++ >= MAX_PCI_DEVICES)
 	        continue;
  
-	    identify_card(&pcr);
+	    identify_card(&pcr, (*num_pci)++);
 	}
     } while (++pcr._pcibusidx < pcr._pcinumbus);
  
     outb(PCI_MODE2_ENABLE_REG, 0x00);
     }
  
-#endif /* __alpha__ */
+#endif /* !__alpha__ && !__powerpc__ */
  
     disable_os_io();
-    *num_pci = pcicards;
  
     return 0 ;