co processor support with s2891
[coreboot.git] / src / mainboard / tyan / s2891 / 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_coproc_0;
24         unsigned apicid_ck804;
25         unsigned apicid_8131_1;
26         unsigned apicid_8131_2;
27
28 unsigned sblk;
29 unsigned pci1234[] = 
30 {        //Here you only need to set value in pci1234 for HT-IO that could be installed or not
31          //You may need to preset pci1234 for HTIO board, please refer to src/northbridge/amd/amdk8/get_sblk_pci1234.c for detail
32         0x0000000,
33         0x0000200,
34         0x0000100,
35 //        0x0000ff0,
36 //        0x0000ff0,
37 //        0x0000ff0,
38 //        0x0000ff0,
39 //        0x0000ff0
40 };
41 unsigned hc_possible_num;
42 unsigned sbdn;
43 unsigned hcdn[] = 
44 { //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
45         0x20202020,
46         0x20202020,
47         0x20202020,
48 //        0x20202020,
49 //        0x20202020,
50 //        0x20202020,
51 //        0x20202020,
52 //        0x20202020,
53 };
54
55 unsigned sbdn3;
56 unsigned coprocdn;
57
58 extern void get_sblk_pci1234(void);
59
60 static unsigned get_bus_conf_done = 0;
61
62 void get_bus_conf(void)
63 {
64
65         unsigned apicid_base;
66
67         device_t dev;
68
69         if(get_bus_conf_done==1) return; //do it only once
70
71         get_bus_conf_done = 1;
72
73         hc_possible_num = sizeof(pci1234)/sizeof(pci1234[0]);   
74         
75         get_sblk_pci1234();
76         
77         sbdn = (hcdn[0] & 0xff); // first byte of first chain
78
79         sbdn3 = (hcdn[1] & 0xff); // first byte of second chain
80
81 //      bus_ck804_0 = node_link_to_bus(0, sblk);
82         bus_ck804_0 = (pci1234[0] >> 16) & 0xff;
83
84         if(pci1234[2] & 1) {
85                 bus_coproc_0 = (pci1234[2] >> 16) & 0xff;
86                 coprocdn =  (hcdn[2] & 0xff);
87         }
88
89
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_4 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
100                         bus_ck804_4++;
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_4 = 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 #endif
140
141                 dev = dev_find_slot(bus_ck804_0, PCI_DEVFN(sbdn + 0x0d,0));
142                 if (dev) {
143                         bus_ck804_4 = pci_read_config8(dev, PCI_SECONDARY_BUS);
144                         bus_ck804_5 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
145                         bus_ck804_5++;
146                 }
147                 else {
148                         printk_debug("ERROR - could not find PCI 1:%02x.0, using defaults\n",sbdn + 0x0d);
149
150                         bus_ck804_5 = bus_ck804_4+1;
151                 }
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                         bus_8131_0 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
157                         bus_8131_0++;
158                         bus_isa = bus_8131_0; // incase only one installed
159                 }
160                 else {
161                         printk_debug("ERROR - could not find PCI 1:%02x.0, using defaults\n", sbdn+ 0x0e);
162
163                 }
164
165                 bus_8131_0 = (pci1234[1] >> 16) & 0xff;
166
167                 /* 8131-1 */
168                 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3,0));
169                 if (dev) {
170                         bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
171                         bus_8131_2 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
172                         bus_8131_2++;
173                 }
174                 else {
175                         printk_debug("ERROR - could not find PCI %02x:01.0, using defaults\n", bus_8131_0);
176
177                         bus_8131_1 = bus_8131_0+1;
178                         bus_8131_2 = bus_8131_0+2;
179                 }
180                 /* 8131-2 */
181                 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3+1,0));
182                 if (dev) {
183                         bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
184                         bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
185                         bus_isa++;
186                 }
187                 else {
188                         printk_debug("ERROR - could not find PCI %02x:02.0, using defaults\n", bus_8131_0);
189
190                         bus_8131_2 = bus_8131_1+1;
191                         bus_isa = bus_8131_1+2;
192                 }
193
194
195
196 /*I/O APICs:    APIC ID Version State           Address*/
197 #if CONFIG_LOGICAL_CPUS==1
198         apicid_base = get_apicid_base(3);
199 #else 
200         apicid_base = CONFIG_MAX_PHYSICAL_CPUS; 
201 #endif
202         apicid_ck804 = apicid_base+0;
203         apicid_8131_1 = apicid_base+1;
204         apicid_8131_2 = apicid_base+2;
205 }