Subversion Repositories Kolibri OS

Rev

Rev 1600 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1029 serge 1
 
2111 serge 2
#define PCI_MAP_ROM_REG     0x30
3
1029 serge 4
 
2111 serge 5
#define PCI_MAP_IO          0x00000001
6
7
 
8
#define PCI_MAP_IO_TYPE         0x00000003
9
10
 
11
#define PCI_MAP_MEMORY_TYPE_32BIT_1M    0x00000002
12
#define PCI_MAP_MEMORY_TYPE_64BIT   0x00000004
13
#define PCI_MAP_MEMORY_TYPE_MASK    0x00000006
14
#define PCI_MAP_MEMORY_CACHABLE     0x00000008
15
#define PCI_MAP_MEMORY_ATTR_MASK    0x0000000e
16
#define PCI_MAP_MEMORY_ADDRESS_MASK 0xfffffff0
17
18
 
19
20
 
1029 serge 21
                     bool destructive, bool *min)
1600 serge 22
{
1029 serge 23
  int offset;
24
  u32_t addr1;
25
  u32_t addr2;
26
  u32_t mask1;
27
  u32_t mask2;
28
  int bits = 0;
29
30
 
31
   * silently ignore bogus index values.  Valid values are 0-6.  0-5 are
32
   * the 6 base address registers, and 6 is the ROM base address register.
33
   */
34
  if (index < 0 || index > 6)
35
    return 0;
36
37
 
38
    *min = destructive;
39
40
 
41
  if (index == 6)
42
    offset = PCI_MAP_ROM_REG;
43
  else
44
    offset = PCI_MAP_REG_START + (index << 2);
45
46
 
47
  /*
48
   * Check if this is the second part of a 64 bit address.
49
   * XXX need to check how endianness affects 64 bit addresses.
50
   */
51
  if (index > 0 && index < 6) {
52
    addr2 = PciRead32(bus, devfn, offset - 4);
53
    if (PCI_MAP_IS_MEM(addr2) && PCI_MAP_IS64BITMEM(addr2))
54
      return 0;
55
  }
56
57
 
58
     PciWrite32(bus, devfn, offset, 0xffffffff);
59
     mask1 = PciRead32(bus, devfn, offset);
60
     PciWrite32(bus, devfn, offset, addr1);
61
  } else {
62
    mask1 = addr1;
63
  }
64
65
 
66
  if (index < 5 && PCI_MAP_IS_MEM(mask1) && PCI_MAP_IS64BITMEM(mask1))
67
  {
68
    if (PCIGETMEMORY(mask1) == 0)
69
    {
70
      addr2 = PciRead32(bus, devfn, offset + 4);
71
      if (destructive)
72
      {
73
        PciWrite32(bus, devfn, offset + 4, 0xffffffff);
74
        mask2 = PciRead32(bus, devfn, offset + 4);
75
        PciWrite32(bus, devfn, offset + 4, addr2);
76
      }
77
      else
78
     {
79
       mask2 = addr2;
80
     }
81
     if (mask2 == 0)
82
       return 0;
83
     bits = 32;
84
     while ((mask2 & 1) == 0)
85
     {
86
       bits++;
87
       mask2 >>= 1;
88
     }
89
     if (bits > 32)
90
	  return bits;
91
    }
92
  }
93
  if (index < 6)
94
    if (PCI_MAP_IS_MEM(mask1))
95
      mask1 = PCIGETMEMORY(mask1);
96
    else
97
      mask1 = PCIGETIO(mask1);
98
  else
99
    mask1 = PCIGETROM(mask1);
100
  if (mask1 == 0)
101
    return 0;
102
  bits = 0;
103
  while ((mask1 & 1) == 0) {
104
    bits++;
105
    mask1 >>= 1;
106
  }
107
  /* I/O maps can be no larger than 8 bits */
108
109
 
110
    bits = 8;
111
  /* ROM maps can be no larger than 24 bits */
112
  if (index == 6 && bits > 24)
113
    bits = 24;
114
  return bits;
115
}
116