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