Subversion Repositories Kolibri OS

Rev

Rev 1029 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2.  
  3. Bool FindPciDevice()
  4. {
  5.     Bool retval = FALSE;
  6.     u32_t bus, last_bus;
  7.     PCITAG tag;
  8.  
  9.     if( (last_bus = PciApi(1))==-1)
  10.         return retval;
  11.  
  12.     for(bus=0;bus<=last_bus;bus++)
  13.     {
  14.         u32_t devfn;
  15.  
  16.         for(devfn=0;devfn<256;devfn++)
  17.         {
  18.             hc_t *hc;
  19.  
  20.             u32_t id;
  21.             u16_t pcicmd;
  22.             u16_t devclass;
  23.             u8_t  interface;
  24.             int i;
  25.  
  26.             interface = PciRead8(bus,devfn, 0x09);
  27.             devclass = PciRead16(bus,devfn, 0x0A);
  28.             if( devclass != 0x0C03)
  29.                 continue;
  30.  
  31.             if( interface != 0)
  32.                 continue;
  33.  
  34.             pcicmd = PciRead16(bus,devfn, PCI_COMMAND);
  35.             if (! pcicmd & PCI_COMMAND_IO)
  36.                 continue;
  37.  
  38.             hc = (hc_t*)malloc(sizeof(hc_t));
  39.             memset(hc, 0, sizeof(hc_t));
  40.             link_initialize(&hc->link);
  41.  
  42.             hc->pciId  = PciRead32(bus,devfn, 0);
  43.             hc->PciTag = pciTag(bus,(devfn>>3)&0x1F,devfn&0x7);
  44.  
  45.             for (i = 0; i < 6; i++)
  46.             {
  47.                 u32_t base;
  48.                 Bool validSize;
  49.  
  50.                 base = PciRead32(bus,devfn, PCI_MAP_REG_START + (i << 2));
  51.                 if(base)
  52.                 {
  53.                     if (base & PCI_MAP_IO) {
  54.                         hc->ioBase[i] = (addr_t)PCIGETIO(base);
  55.                         hc->memType[i]   = base & PCI_MAP_IO_ATTR_MASK;
  56.                     } else {
  57.                         hc->memBase[i] = (u32_t)PCIGETMEMORY(base);
  58.                         hc->memType[i] = base & PCI_MAP_MEMORY_ATTR_MASK;
  59.                     }
  60.                 }
  61.             };
  62.             list_prepend(&hc->link, &hc_list);
  63.             retval = TRUE;
  64.         };
  65.     };
  66.     return retval;
  67. };
  68.