3decafb71e24ce161e9739f075ee7c6f326c05bb
[coreboot.git] / src / mainboard / tyan / s2895 / get_bus_conf.c
1 #include <console/console.h>
2 #include <device/pci.h>
3 #include <device/pci_ids.h>
4 #include <string.h>
5 #include <stdint.h>
6 #if CONFIG_LOGICAL_CPUS==1
7 #include <cpu/amd/dualcore.h>
8 #endif
9
10
11 // Global variables for MB layouts and these will be shared by irqtable mptable and acpi_tables
12 //busnum is default
13         unsigned char bus_isa;
14         unsigned char bus_ck804_0; //1
15         unsigned char bus_ck804_1; //2
16         unsigned char bus_ck804_2; //3
17         unsigned char bus_ck804_3; //4
18         unsigned char bus_ck804_4; //5
19         unsigned char bus_ck804_5; //6
20         unsigned char bus_8131_0;  //7
21         unsigned char bus_8131_1;  //8
22         unsigned char bus_8131_2;  //9
23         unsigned char bus_ck804b_0;//a
24         unsigned char bus_ck804b_1;//b
25         unsigned char bus_ck804b_2;//c
26         unsigned char bus_ck804b_3;//d
27         unsigned char bus_ck804b_4;//e
28         unsigned char bus_ck804b_5;//f
29         unsigned apicid_ck804;
30         unsigned apicid_8131_1;
31         unsigned apicid_8131_2;
32         unsigned apicid_ck804b;
33
34 unsigned sblk;
35 unsigned pci1234[] = 
36 {        //Here you only need to set value in pci1234 for HT-IO that could be installed or not
37          //You may need to preset pci1234 for HTIO board, please refer to src/northbridge/amd/amdk8/get_sblk_pci1234.c for detail
38         0x0000ff0,
39         0x0000ff0,
40         0x0000ff0,
41 //        0x0000ff0,
42 //        0x0000ff0,
43 //        0x0000ff0,
44 //        0x0000ff0,
45 //        0x0000ff0
46 };
47 unsigned hc_possible_num;
48 unsigned sbdn;
49 unsigned hcdn[] = 
50 { //HT Chain device num, actually it is unit id base of every ht device in chain, assume every chain only have 4 ht device at most
51         0x20202020,
52         0x20202020,
53         0x20202020,
54 //        0x20202020,
55 //        0x20202020,
56 //        0x20202020,
57 //        0x20202020,
58 //        0x20202020,
59 };
60 unsigned sbdn3;
61 unsigned sbdnb;
62
63 extern void get_sblk_pci1234(void);
64
65 static unsigned get_bus_conf_done = 0;
66
67 void get_bus_conf(void)
68 {
69
70         unsigned apicid_base;
71
72         device_t dev;
73
74         if(get_bus_conf_done==1) return; //do it only once
75
76         get_bus_conf_done = 1;
77
78         hc_possible_num = sizeof(pci1234)/sizeof(pci1234[0]);   
79         
80         get_sblk_pci1234();
81         
82         sbdn = (hcdn[0] & 0xff); // first byte of first chain
83
84         sbdn3 = (hcdn[1] & 0xff);
85
86         sbdnb = (hcdn[2] & 0xff); // first byte of second chain
87
88 //      bus_ck804_0 = node_link_to_bus(0, sblk);
89         bus_ck804_0 = (pci1234[0] >> 16) & 0xff;
90
91                 /* CK804 */
92                 dev = dev_find_slot(bus_ck804_0, PCI_DEVFN(sbdn + 0x09,0));
93                 if (dev) {
94                         bus_ck804_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
95 #if 0
96                         bus_ck804_2 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
97                         bus_ck804_2++;
98 #else
99                         bus_ck804_5 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
100                         bus_ck804_5++;
101 #endif
102                 }
103                 else {
104                         printk_debug("ERROR - could not find PCI 1:%02x.0, using defaults\n", sbdn + 0x09);
105
106                         bus_ck804_1 = 2;
107 #if 0
108                         bus_ck804_2 = 3;
109 #else
110                         bus_ck804_5 = 3;
111 #endif
112
113                 }
114 #if 0
115                 dev = dev_find_slot(bus_ck804_0, PCI_DEVFN(sbdn + 0x0b,0));
116                 if (dev) {
117                         bus_ck804_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
118                         bus_ck804_3 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
119                         bus_ck804_3++;
120                 }
121                 else {
122                         printk_debug("ERROR - could not find PCI 1:%02x.0, using defaults\n", sbdn + 0x0b);
123
124                         bus_ck804_3 = bus_ck804_2+1;
125                 }
126
127                 dev = dev_find_slot(bus_ck804_0, PCI_DEVFN(sbdn + 0x0c,0));
128                 if (dev) {
129                         bus_ck804_3 = pci_read_config8(dev, PCI_SECONDARY_BUS);
130                         bus_ck804_4 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
131                         bus_ck804_4++;
132                 }
133                 else {
134                         printk_debug("ERROR - could not find PCI 1:%02x.0, using defaults\n", sbdn + 0x0c);
135
136                         bus_ck804_4 = bus_ck804_3+1;
137                 }
138
139
140                 dev = dev_find_slot(bus_ck804_0, PCI_DEVFN(sbdn + 0x0d,0));
141                 if (dev) {
142                         bus_ck804_4 = pci_read_config8(dev, PCI_SECONDARY_BUS);
143                         bus_ck804_5 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
144                         bus_ck804_5++;
145                 }
146                 else {
147                         printk_debug("ERROR - could not find PCI 1:%02x.0, using defaults\n",sbdn + 0x0d);
148
149                         bus_ck804_5 = bus_ck804_4+1;
150                 }
151 #endif
152
153                 dev = dev_find_slot(bus_ck804_0, PCI_DEVFN(sbdn+ 0x0e,0));
154                 if (dev) {
155                         bus_ck804_5 = pci_read_config8(dev, PCI_SECONDARY_BUS);
156                 }
157                 else {
158                         printk_debug("ERROR - could not find PCI 1:%02x.0, using defaults\n", sbdn+ 0x0e);
159                 }
160
161                 bus_8131_0 = (pci1234[1] >> 16) & 0xff;
162                 /* 8131-1 */
163                 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3,0));
164                 if (dev) {
165                         bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
166                         bus_8131_2 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
167                         bus_8131_2++;
168                 }
169                 else {
170                         printk_debug("ERROR - could not find PCI %02x:01.0, using defaults\n", bus_8131_0);
171
172                         bus_8131_1 = bus_8131_0+1;
173                         bus_8131_2 = bus_8131_0+2;
174                 }
175                 /* 8131-2 */
176                 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3,0));
177                 if (dev) {
178                         bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
179                         bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
180                         bus_isa++;
181                 }
182                 else {
183                         printk_debug("ERROR - could not find PCI %02x:02.0, using defaults\n", bus_8131_0);
184
185                         bus_8131_2 = bus_8131_1+1;
186                 }
187
188                 /* CK804b */
189
190         if(pci1234[2] & 0xf) { //if the second cpu is installed
191                 bus_ck804b_0 = (pci1234[2]>>16) & 0xff;
192 #if 0
193                 dev = dev_find_slot(bus_ck804b_0, PCI_DEVFN(sbdnb + 0x09,0));
194                 if (dev) {
195                         bus_ck804b_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
196                         bus_ck804b_2 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
197                         bus_ck804b_2++;
198                 }
199                 else {
200                         printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", bus_ck804b_0,sbdnb+0x09);
201
202                         bus_ck804b_1 = bus_ck804b_0+1;
203                         bus_ck804b_2 = bus_ck804b_0+2;
204                 }
205
206                 dev = dev_find_slot(bus_ck804b_0, PCI_DEVFN(sbdnb + 0x0b,0));
207                 if (dev) {
208                         bus_ck804b_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
209                         bus_ck804b_3 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
210                         bus_ck804b_3++;
211                 }
212                 else {
213                         printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", bus_ck804b_0,sbdnb+0x0b);
214
215                         bus_ck804b_2 = bus_ck804b_0+1;
216                         bus_ck804b_3 = bus_ck804b_0+2;
217                 }
218
219                 dev = dev_find_slot(bus_ck804b_0, PCI_DEVFN(sbdnb + 0x0c,0));
220                 if (dev) {
221                         bus_ck804b_3 = pci_read_config8(dev, PCI_SECONDARY_BUS);
222                         bus_ck804b_4 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
223                         bus_ck804b_4++;
224                 }
225                 else {
226                         printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", bus_ck804b_0,sbdnb+0x0c);
227
228                         bus_ck804b_4 = bus_ck804b_3+1;
229                 }
230                 dev = dev_find_slot(bus_ck804b_0, PCI_DEVFN(sbdnb + 0x0d,0));
231                 if (dev) {
232                         bus_ck804b_4 = pci_read_config8(dev, PCI_SECONDARY_BUS);
233                         bus_ck804b_5 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
234                         bus_ck804b_5++;
235                 }
236                 else {
237                         printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", bus_ck804b_0,sbdnb+0x0d);
238
239                         bus_ck804b_5 = bus_ck804b_4+1;
240                 }
241 #endif
242
243                 dev = dev_find_slot(bus_ck804b_0, PCI_DEVFN(sbdnb + 0x0e,0));
244                 if (dev) {
245                         bus_ck804b_5 = pci_read_config8(dev, PCI_SECONDARY_BUS);
246                         bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
247                         bus_isa++;
248                 }
249                 else {
250                         printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", bus_ck804b_0,sbdnb+0x0e);
251 #if 1
252                         bus_ck804b_5 = bus_ck804b_4+1;
253 #endif
254
255                         bus_isa = bus_ck804b_5+1;
256                 }
257         }
258
259
260 /*I/O APICs:    APIC ID Version State           Address*/
261 #if CONFIG_LOGICAL_CPUS==1
262         apicid_base = get_apicid_base(4);
263 #else 
264         apicid_base = CONFIG_MAX_PHYSICAL_CPUS; 
265 #endif
266         apicid_ck804 = apicid_base+0;
267         apicid_8131_1 = apicid_base+1;
268         apicid_8131_2 = apicid_base+2;
269         apicid_ck804b = apicid_base+3;
270
271 }