92fefa6a0cd11c10e72a3a045fed05a993a2203d
[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 apicid_ck804;
24         unsigned apicid_8131_1;
25         unsigned apicid_8131_2;
26
27 unsigned sblk;
28 unsigned pci1234[] = 
29 {        //Here you only need to set value in pci1234 for HT-IO that could be installed or not
30          //You may need to preset pci1234 for HTIO board, please refer to src/northbridge/amd/amdk8/get_sblk_pci1234.c for detail
31         0x0000ff0,
32         0x0000ff0,
33 //        0x0000ff0,
34 //        0x0000ff0,
35 //        0x0000ff0,
36 //        0x0000ff0,
37 //        0x0000ff0,
38 //        0x0000ff0
39 };
40 unsigned hc_possible_num;
41 unsigned sbdn;
42 unsigned hcdn[] = 
43 { //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
44         0x20202020,
45         0x20202020,
46 //        0x20202020,
47 //        0x20202020,
48 //        0x20202020,
49 //        0x20202020,
50 //        0x20202020,
51 //        0x20202020,
52 };
53
54 unsigned sbdn3;
55
56 extern void get_sblk_pci1234(void);
57
58 static unsigned get_bus_conf_done = 0;
59
60 void get_bus_conf(void)
61 {
62
63         unsigned apicid_base;
64
65         device_t dev;
66
67         if(get_bus_conf_done==1) return; //do it only once
68
69         get_bus_conf_done = 1;
70
71         hc_possible_num = sizeof(pci1234)/sizeof(pci1234[0]);   
72         
73         get_sblk_pci1234();
74         
75         sbdn = (hcdn[0] & 0xff); // first byte of first chain
76
77         sbdn3 = (hcdn[1] & 0xff); // first byte of second chain
78
79 //      bus_ck804_0 = node_link_to_bus(0, sblk);
80         bus_ck804_0 = (pci1234[0] >> 16) & 0xff;
81
82
83                 /* CK804 */
84                 dev = dev_find_slot(bus_ck804_0, PCI_DEVFN(sbdn + 0x09,0));
85                 if (dev) {
86                         bus_ck804_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
87 #if 0
88                         bus_ck804_2 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
89                         bus_ck804_2++;
90 #else
91                         bus_ck804_4 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
92                         bus_ck804_4++;
93 #endif
94                 }
95                 else {
96                         printk_debug("ERROR - could not find PCI 1:%02x.0, using defaults\n", sbdn + 0x09);
97
98                         bus_ck804_1 = 2;
99 #if 0
100                         bus_ck804_2 = 3;
101 #else
102                         bus_ck804_4 = 3;
103 #endif
104
105                 }
106 #if 0
107                 dev = dev_find_slot(bus_ck804_0, PCI_DEVFN(sbdn + 0x0b,0));
108                 if (dev) {
109                         bus_ck804_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
110                         bus_ck804_3 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
111                         bus_ck804_3++;
112                 }
113                 else {
114                         printk_debug("ERROR - could not find PCI 1:%02x.0, using defaults\n", sbdn + 0x0b);
115
116                         bus_ck804_3 = bus_ck804_2+1;
117                 }
118
119                 dev = dev_find_slot(bus_ck804_0, PCI_DEVFN(sbdn + 0x0c,0));
120                 if (dev) {
121                         bus_ck804_3 = pci_read_config8(dev, PCI_SECONDARY_BUS);
122                         bus_ck804_4 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
123                         bus_ck804_4++;
124                 }
125                 else {
126                         printk_debug("ERROR - could not find PCI 1:%02x.0, using defaults\n", sbdn + 0x0c);
127
128                         bus_ck804_4 = bus_ck804_3+1;
129                 }
130
131 #endif
132
133                 dev = dev_find_slot(bus_ck804_0, PCI_DEVFN(sbdn + 0x0d,0));
134                 if (dev) {
135                         bus_ck804_4 = pci_read_config8(dev, PCI_SECONDARY_BUS);
136                         bus_ck804_5 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
137                         bus_ck804_5++;
138                 }
139                 else {
140                         printk_debug("ERROR - could not find PCI 1:%02x.0, using defaults\n",sbdn + 0x0d);
141
142                         bus_ck804_5 = bus_ck804_4+1;
143                 }
144
145                 dev = dev_find_slot(bus_ck804_0, PCI_DEVFN(sbdn+ 0x0e,0));
146                 if (dev) {
147                         bus_ck804_5 = pci_read_config8(dev, PCI_SECONDARY_BUS);
148                         bus_8131_0 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
149                         bus_8131_0++;
150                         bus_isa = bus_8131_0; // incase only one installed
151                 }
152                 else {
153                         printk_debug("ERROR - could not find PCI 1:%02x.0, using defaults\n", sbdn+ 0x0e);
154
155                         bus_8131_0 = bus_ck804_5+1;
156                 }
157
158                 /* 8131-1 */
159                 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3,0));
160                 if (dev) {
161                         bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
162                         bus_8131_2 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
163                         bus_8131_2++;
164                 }
165                 else {
166                         printk_debug("ERROR - could not find PCI %02x:01.0, using defaults\n", bus_8131_0);
167
168                         bus_8131_1 = bus_8131_0+1;
169                         bus_8131_2 = bus_8131_0+2;
170                 }
171                 /* 8131-2 */
172                 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3+1,0));
173                 if (dev) {
174                         bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
175                         bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
176                         bus_isa++;
177                 }
178                 else {
179                         printk_debug("ERROR - could not find PCI %02x:02.0, using defaults\n", bus_8131_0);
180
181                         bus_8131_2 = bus_8131_1+1;
182                         bus_isa = bus_8131_1+2;
183                 }
184
185
186
187 /*I/O APICs:    APIC ID Version State           Address*/
188 #if CONFIG_LOGICAL_CPUS==1
189         apicid_base = get_apicid_base(3);
190 #else 
191         apicid_base = CONFIG_MAX_PHYSICAL_CPUS; 
192 #endif
193         apicid_ck804 = apicid_base+0;
194         apicid_8131_1 = apicid_base+1;
195         apicid_8131_2 = apicid_base+2;
196 }