Subversion Repositories Kolibri OS

Rev

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