Subversion Repositories Kolibri OS

Rev

Rev 881 | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #include "ati_pciids_gen.h"
  3. #include "radeon_chipset_gen.h"
  4. #include "radeon_chipinfo_gen.h"
  5.  
  6.  
  7.  
  8. const char *
  9. xf86TokenToString(SymTabPtr table, int token)
  10. {
  11.     int i;
  12.  
  13.     for (i = 0; table[i].token >= 0 && table[i].token != token; i++){};
  14.  
  15.     if (table[i].token < 0)
  16.       return NULL;
  17.     else
  18.       return(table[i].name);
  19. }
  20.  
  21.  
  22.  
  23. const RADEONCardInfo *RadeonDevMatch(u16_t dev,const RADEONCardInfo *list)
  24. {
  25.   while(list->pci_device_id)
  26.   {
  27.     if(dev == list->pci_device_id)
  28.       return list;
  29.     list++;
  30.   }
  31.   return 0;
  32. }
  33.  
  34.  
  35. RHDPtr FindPciDevice()
  36. {
  37.   const RADEONCardInfo *dev;
  38.   u32_t bus, last_bus;
  39.  
  40.   if( (last_bus = PciApi(1))==-1)
  41.     return 0;
  42.  
  43.   for(bus=0;bus<=last_bus;bus++)
  44.   {
  45.     u32_t devfn;
  46.  
  47.     for(devfn=0;devfn<256;devfn++)
  48.     {
  49.       u32_t id;
  50.       id = PciRead32(bus,devfn, 0);
  51.  
  52.       if( (u16_t)id != VENDOR_ATI)
  53.         continue;
  54.  
  55.       rhd.PciDeviceID = (id>>16);
  56.  
  57.       if( (dev = RadeonDevMatch(rhd.PciDeviceID, RADEONCards))!=NULL)
  58.       {
  59.         u32_t reg2C;
  60.         int i;
  61.  
  62.         rhd.chipset = (char*)xf86TokenToString(RADEONChipsets, rhd.PciDeviceID);
  63.         if (!rhd.chipset)
  64.         {
  65.            dbgprintf("ChipID 0x%04x is not recognized\n", rhd.PciDeviceID);
  66.            return FALSE;
  67.         }
  68.         dbgprintf("Chipset: \"%s\" (ChipID = 0x%04x)\n",rhd.chipset,rhd.PciDeviceID);
  69.  
  70.         rhd.bus = bus;
  71.         rhd.devfn = devfn;
  72.         rhd.PciTag = pciTag(bus,(devfn>>3)&0x1F,devfn&0x7);
  73.  
  74.         rhd.ChipFamily  = dev->chip_family;
  75.         rhd.IsMobility  = dev->mobility;
  76.         rhd.IsIGP       = dev->igp;
  77.         rhd.HasCRTC2    = !dev->nocrtc2;
  78.  
  79.         reg2C = PciRead32(bus,devfn, 0x2C);
  80.  
  81.         rhd.subvendor_id = reg2C & 0xFFFF;;
  82.         rhd.subdevice_id = reg2C >> 16;
  83.  
  84.         if (rhd.ChipFamily >= CHIP_FAMILY_R600)
  85.            dbgprintf("R600 unsupported yet.\nExit\n");
  86.  
  87.  
  88.         for (i = 0; i < 6; i++)
  89.         {
  90.           u32_t base;
  91.           Bool validSize;
  92.  
  93.           base = PciRead32(bus,devfn, PCI_MAP_REG_START + (i << 2));
  94.           if(base)
  95.           {
  96.             if (base & PCI_MAP_IO)
  97.             {
  98.               rhd.ioBase[i] = (u32_t)PCIGETIO(base);
  99.               rhd.memtype[i]   = base & PCI_MAP_IO_ATTR_MASK;
  100.             }
  101.             else
  102.             {
  103.               rhd.memBase[i] = (u32_t)PCIGETMEMORY(base);
  104.               rhd.memtype[i] = base & PCI_MAP_MEMORY_ATTR_MASK;
  105.             }
  106.           }
  107.           rhd.memsize[i] = pciGetBaseSize(bus,devfn, i, TRUE, &validSize);
  108.         }
  109.         return &rhd;
  110.       }
  111.     };
  112.   };
  113.   return NULL;
  114. }
  115.  
  116.  
  117.  
  118. u32_t pciGetBaseSize(int bus, int devfn, int index, Bool destructive, Bool *min)
  119. {
  120.   int offset;
  121.   u32_t addr1;
  122.   u32_t addr2;
  123.   u32_t mask1;
  124.   u32_t mask2;
  125.   int bits = 0;
  126.  
  127.   /*
  128.    * silently ignore bogus index values.  Valid values are 0-6.  0-5 are
  129.    * the 6 base address registers, and 6 is the ROM base address register.
  130.    */
  131.   if (index < 0 || index > 6)
  132.     return 0;
  133.  
  134.   if (min)
  135.     *min = destructive;
  136.  
  137.   /* Get the PCI offset */
  138.   if (index == 6)
  139.     offset = PCI_MAP_ROM_REG;
  140.   else
  141.     offset = PCI_MAP_REG_START + (index << 2);
  142.  
  143.   addr1 = PciRead32(bus, devfn, offset);
  144.   /*
  145.    * Check if this is the second part of a 64 bit address.
  146.    * XXX need to check how endianness affects 64 bit addresses.
  147.    */
  148.   if (index > 0 && index < 6) {
  149.     addr2 = PciRead32(bus, devfn, offset - 4);
  150.     if (PCI_MAP_IS_MEM(addr2) && PCI_MAP_IS64BITMEM(addr2))
  151.       return 0;
  152.   }
  153.  
  154.   if (destructive) {
  155.      PciWrite32(bus, devfn, offset, 0xffffffff);
  156.      mask1 = PciRead32(bus, devfn, offset);
  157.      PciWrite32(bus, devfn, offset, addr1);
  158.   } else {
  159.     mask1 = addr1;
  160.   }
  161.  
  162.   /* Check if this is the first part of a 64 bit address. */
  163.   if (index < 5 && PCI_MAP_IS_MEM(mask1) && PCI_MAP_IS64BITMEM(mask1))
  164.   {
  165.     if (PCIGETMEMORY(mask1) == 0)
  166.     {
  167.       addr2 = PciRead32(bus, devfn, offset + 4);
  168.       if (destructive)
  169.       {
  170.         PciWrite32(bus, devfn, offset + 4, 0xffffffff);
  171.         mask2 = PciRead32(bus, devfn, offset + 4);
  172.         PciWrite32(bus, devfn, offset + 4, addr2);
  173.       }
  174.       else
  175.      {
  176.        mask2 = addr2;
  177.      }
  178.      if (mask2 == 0)
  179.        return 0;
  180.      bits = 32;
  181.      while ((mask2 & 1) == 0)
  182.      {
  183.        bits++;
  184.        mask2 >>= 1;
  185.      }
  186.      if (bits > 32)
  187.           return bits;
  188.     }
  189.   }
  190.   if (index < 6)
  191.     if (PCI_MAP_IS_MEM(mask1))
  192.       mask1 = PCIGETMEMORY(mask1);
  193.     else
  194.       mask1 = PCIGETIO(mask1);
  195.   else
  196.     mask1 = PCIGETROM(mask1);
  197.   if (mask1 == 0)
  198.     return 0;
  199.   bits = 0;
  200.   while ((mask1 & 1) == 0) {
  201.     bits++;
  202.     mask1 >>= 1;
  203.   }
  204.   /* I/O maps can be no larger than 8 bits */
  205.  
  206.   if ((index < 6) && PCI_MAP_IS_IO(addr1) && bits > 8)
  207.     bits = 8;
  208.   /* ROM maps can be no larger than 24 bits */
  209.   if (index == 6 && bits > 24)
  210.     bits = 24;
  211.   return bits;
  212. }
  213.  
  214.  
  215.