Subversion Repositories Kolibri OS

Rev

Rev 883 | Go to most recent revision | 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.                     dbgprintf("ChipID 0x%04x is not recognized\n", rhd.PciDeviceID);
  65.                     return FALSE;
  66.                 }
  67.                 dbgprintf("Chipset: \"%s\" (ChipID = 0x%04x)\n",
  68.                            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.                             rhd.ioBase[i] = (u32_t)PCIGETIO(base);
  98.                             rhd.memtype[i]   = base & PCI_MAP_IO_ATTR_MASK;
  99.                         }
  100.                         else{
  101.                             rhd.memBase[i] = (u32_t)PCIGETMEMORY(base);
  102.                             rhd.memtype[i] = base & PCI_MAP_MEMORY_ATTR_MASK;
  103.                         }
  104.                     }
  105.                     rhd.memsize[i] = pciGetBaseSize(bus,devfn, i, TRUE, &validSize);
  106.                 }
  107.                 return &rhd;
  108.             }
  109.         }
  110.     };
  111.     return NULL;
  112. }
  113.  
  114.  
  115.  
  116. u32_t pciGetBaseSize(int bus, int devfn, int index, Bool destructive, Bool *min)
  117. {
  118.   int offset;
  119.   u32_t addr1;
  120.   u32_t addr2;
  121.   u32_t mask1;
  122.   u32_t mask2;
  123.   int bits = 0;
  124.  
  125.   /*
  126.    * silently ignore bogus index values.  Valid values are 0-6.  0-5 are
  127.    * the 6 base address registers, and 6 is the ROM base address register.
  128.    */
  129.   if (index < 0 || index > 6)
  130.     return 0;
  131.  
  132.   if (min)
  133.     *min = destructive;
  134.  
  135.   /* Get the PCI offset */
  136.   if (index == 6)
  137.     offset = PCI_MAP_ROM_REG;
  138.   else
  139.     offset = PCI_MAP_REG_START + (index << 2);
  140.  
  141.   addr1 = PciRead32(bus, devfn, offset);
  142.   /*
  143.    * Check if this is the second part of a 64 bit address.
  144.    * XXX need to check how endianness affects 64 bit addresses.
  145.    */
  146.   if (index > 0 && index < 6) {
  147.     addr2 = PciRead32(bus, devfn, offset - 4);
  148.     if (PCI_MAP_IS_MEM(addr2) && PCI_MAP_IS64BITMEM(addr2))
  149.       return 0;
  150.   }
  151.  
  152.   if (destructive) {
  153.      PciWrite32(bus, devfn, offset, 0xffffffff);
  154.      mask1 = PciRead32(bus, devfn, offset);
  155.      PciWrite32(bus, devfn, offset, addr1);
  156.   } else {
  157.     mask1 = addr1;
  158.   }
  159.  
  160.   /* Check if this is the first part of a 64 bit address. */
  161.   if (index < 5 && PCI_MAP_IS_MEM(mask1) && PCI_MAP_IS64BITMEM(mask1))
  162.   {
  163.     if (PCIGETMEMORY(mask1) == 0)
  164.     {
  165.       addr2 = PciRead32(bus, devfn, offset + 4);
  166.       if (destructive)
  167.       {
  168.         PciWrite32(bus, devfn, offset + 4, 0xffffffff);
  169.         mask2 = PciRead32(bus, devfn, offset + 4);
  170.         PciWrite32(bus, devfn, offset + 4, addr2);
  171.       }
  172.       else
  173.      {
  174.        mask2 = addr2;
  175.      }
  176.      if (mask2 == 0)
  177.        return 0;
  178.      bits = 32;
  179.      while ((mask2 & 1) == 0)
  180.      {
  181.        bits++;
  182.        mask2 >>= 1;
  183.      }
  184.      if (bits > 32)
  185.           return bits;
  186.     }
  187.   }
  188.   if (index < 6)
  189.     if (PCI_MAP_IS_MEM(mask1))
  190.       mask1 = PCIGETMEMORY(mask1);
  191.     else
  192.       mask1 = PCIGETIO(mask1);
  193.   else
  194.     mask1 = PCIGETROM(mask1);
  195.   if (mask1 == 0)
  196.     return 0;
  197.   bits = 0;
  198.   while ((mask1 & 1) == 0) {
  199.     bits++;
  200.     mask1 >>= 1;
  201.   }
  202.   /* I/O maps can be no larger than 8 bits */
  203.  
  204.   if ((index < 6) && PCI_MAP_IS_IO(addr1) && bits > 8)
  205.     bits = 8;
  206.   /* ROM maps can be no larger than 24 bits */
  207.   if (index == 6 && bits > 24)
  208.     bits = 24;
  209.   return bits;
  210. }
  211.  
  212.  
  213.