Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. #include "common.h"
  3. #include "pci.h"
  4.  
  5.  
  6. int
  7. pciGetBaseSize(int bus, int devfn, int index, Bool destructive, Bool *min)
  8. {
  9.   int offset;
  10.   CARD32 addr1;
  11.   CARD32 addr2;
  12.   CARD32 mask1;
  13.   CARD32 mask2;
  14.   int bits = 0;
  15.  
  16.   /*
  17.    * silently ignore bogus index values.  Valid values are 0-6.  0-5 are
  18.    * the 6 base address registers, and 6 is the ROM base address register.
  19.    */
  20.   if (index < 0 || index > 6)
  21.     return 0;
  22.  
  23.   if (min)
  24.     *min = destructive;
  25.  
  26.   /* Get the PCI offset */
  27.   if (index == 6)
  28.     offset = PCI_MAP_ROM_REG;
  29.   else
  30.     offset = PCI_MAP_REG_START + (index << 2);
  31.  
  32.   addr1 = PciRead32(bus, devfn, offset);
  33.   /*
  34.    * Check if this is the second part of a 64 bit address.
  35.    * XXX need to check how endianness affects 64 bit addresses.
  36.    */
  37.   if (index > 0 && index < 6) {
  38.     addr2 = PciRead32(bus, devfn, offset - 4);
  39.     if (PCI_MAP_IS_MEM(addr2) && PCI_MAP_IS64BITMEM(addr2))
  40.       return 0;
  41.   }
  42.  
  43.   if (destructive) {
  44.      PciWrite32(bus, devfn, offset, 0xffffffff);
  45.      mask1 = PciRead32(bus, devfn, offset);
  46.      PciWrite32(bus, devfn, offset, addr1);
  47.   } else {
  48.     mask1 = addr1;
  49.   }
  50.  
  51.   /* Check if this is the first part of a 64 bit address. */
  52.   if (index < 5 && PCI_MAP_IS_MEM(mask1) && PCI_MAP_IS64BITMEM(mask1))
  53.   {
  54.     if (PCIGETMEMORY(mask1) == 0)
  55.     {
  56.       addr2 = PciRead32(bus, devfn, offset + 4);
  57.       if (destructive)
  58.       {
  59.         PciWrite32(bus, devfn, offset + 4, 0xffffffff);
  60.         mask2 = PciRead32(bus, devfn, offset + 4);
  61.         PciWrite32(bus, devfn, offset + 4, addr2);
  62.       }
  63.       else
  64.      {
  65.        mask2 = addr2;
  66.      }
  67.      if (mask2 == 0)
  68.        return 0;
  69.      bits = 32;
  70.      while ((mask2 & 1) == 0)
  71.      {
  72.        bits++;
  73.        mask2 >>= 1;
  74.      }
  75.      if (bits > 32)
  76.           return bits;
  77.     }
  78.   }
  79.   if (index < 6)
  80.     if (PCI_MAP_IS_MEM(mask1))
  81.       mask1 = PCIGETMEMORY(mask1);
  82.     else
  83.       mask1 = PCIGETIO(mask1);
  84.   else
  85.     mask1 = PCIGETROM(mask1);
  86.   if (mask1 == 0)
  87.     return 0;
  88.   bits = 0;
  89.   while ((mask1 & 1) == 0) {
  90.     bits++;
  91.     mask1 >>= 1;
  92.   }
  93.   /* I/O maps can be no larger than 8 bits */
  94.  
  95.   if ((index < 6) && PCI_MAP_IS_IO(addr1) && bits > 8)
  96.     bits = 8;
  97.   /* ROM maps can be no larger than 24 bits */
  98.   if (index == 6 && bits > 24)
  99.     bits = 24;
  100.   return bits;
  101. }
  102.  
  103. /*
  104.     int       chipRev;
  105.     int       subsysVendor;
  106.     int       subsysCard;
  107.     int       bus;
  108.     int       devfn;
  109. //    int       func;
  110.     int       class;
  111.     int       subclass;
  112.     int       interface;
  113.     memType   memBase[6];
  114.     memType   ioBase[6];
  115.     int       size[6];
  116.     unsigned char       type[6];
  117.     memType   biosBase;
  118.     int       biosSize;
  119. */
  120.  
  121. int pciGetInfo(pciVideoPtr pci)
  122. {
  123.   CARD32 reg0,reg2C;
  124.   int i;
  125.  
  126.   reg0  = PciRead32(pci->bus,pci->devfn, 0);
  127.   reg2C = PciRead32(pci->bus,pci->devfn, 0x2C);
  128.  
  129.   pci->vendor  = reg0 & 0xFFFF;
  130.   pci->devtype = reg0 >> 16;
  131.  
  132.   pci->subsysVendor = reg2C & 0xFFFF;
  133.   pci->subsysCard = reg2C >> 16;
  134.  
  135.   for (i = 0; i < 6; i++)
  136.   {
  137.     CARD32 base;
  138.  
  139.     base = PciRead32(pci->bus,pci->devfn, PCI_MAP_REG_START + (i << 2));
  140.     if(base)
  141.     {
  142.       if (base & PCI_MAP_IO)
  143.       {
  144.         pci->ioBase[i] = (memType)PCIGETIO(base);
  145.         pci->type[i] = base & PCI_MAP_IO_ATTR_MASK;
  146.       }
  147.       else
  148.       {
  149.         pci->type[i] = base & PCI_MAP_MEMORY_ATTR_MASK;
  150.         pci->memBase[i] = (memType)PCIGETMEMORY(base);
  151.       }
  152.                 }
  153.  
  154.     pci->size[i] =
  155.       pciGetBaseSize(pci->bus,pci->devfn, i, TRUE, &pci->validSize);
  156.   }
  157.  
  158. }
  159.  
  160.