Rework boolean expression (DeMorgan and all) for
[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 #include <cpu/amd/amdk8_sysconf.h>
11 #include <stdlib.h>
12
13 // Global variables for MB layouts and these will be shared by irqtable mptable and acpi_tables
14 //busnum is default
15         unsigned char bus_isa;
16         unsigned char bus_ck804_0; //1
17         unsigned char bus_ck804_1; //2
18         unsigned char bus_ck804_2; //3
19         unsigned char bus_ck804_3; //4
20         unsigned char bus_ck804_4; //5
21         unsigned char bus_ck804_5; //6
22         unsigned char bus_8131_0;  //7
23         unsigned char bus_8131_1;  //8
24         unsigned char bus_8131_2;  //9
25         unsigned char bus_ck804b_0;//a
26         unsigned char bus_ck804b_1;//b
27         unsigned char bus_ck804b_2;//c
28         unsigned char bus_ck804b_3;//d
29         unsigned char bus_ck804b_4;//e
30         unsigned char bus_ck804b_5;//f
31         unsigned apicid_ck804;
32         unsigned apicid_8131_1;
33         unsigned apicid_8131_2;
34         unsigned apicid_ck804b;
35
36 unsigned pci1234x[] =
37 {        //Here you only need to set value in pci1234 for HT-IO that could be installed or not
38          //You may need to preset pci1234 for HTIO board, please refer to src/northbridge/amd/amdk8/get_sblk_pci1234.c for detail
39         0x0000ff0,
40         0x0000ff0,
41         0x0000ff0,
42 //        0x0000ff0,
43 //        0x0000ff0,
44 //        0x0000ff0,
45 //        0x0000ff0,
46 //        0x0000ff0
47 };
48 unsigned hcdnx[] =
49 { //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
50         0x20202020,
51         0x20202020,
52         0x20202020,
53 //        0x20202020,
54 //        0x20202020,
55 //        0x20202020,
56 //        0x20202020,
57 //        0x20202020,
58 };
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         unsigned sbdn;
72
73         device_t dev;
74         int i;
75
76         if(get_bus_conf_done==1) return; //do it only once
77
78         get_bus_conf_done = 1;
79
80         sysconf.hc_possible_num = ARRAY_SIZE(pci1234x);
81         for(i=0;i<sysconf.hc_possible_num; i++) {
82                 sysconf.pci1234[i] = pci1234x[i];
83                 sysconf.hcdn[i] = hcdnx[i];
84         }
85
86         get_sblk_pci1234();
87
88         sysconf.sbdn = (sysconf.hcdn[0] & 0xff); // first byte of first chain
89         sbdn = sysconf.sbdn;
90
91         sbdn3 = (sysconf.hcdn[1] & 0xff);
92
93         sbdnb = (sysconf.hcdn[2] & 0xff); // first byte of second chain
94
95         bus_ck804_0 = (sysconf.pci1234[0] >> 16) & 0xff;
96
97                 /* CK804 */
98                 dev = dev_find_slot(bus_ck804_0, PCI_DEVFN(sbdn + 0x09,0));
99                 if (dev) {
100                         bus_ck804_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
101                         bus_ck804_5 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
102                         bus_ck804_5++;
103                 }
104                 else {
105                         printk_debug("ERROR - could not find PCI 1:%02x.0, using defaults\n", sbdn + 0x09);
106
107                         bus_ck804_1 = 2;
108                         bus_ck804_5 = 3;
109                 }
110
111                 dev = dev_find_slot(bus_ck804_0, PCI_DEVFN(sbdn+ 0x0e,0));
112                 if (dev) {
113                         bus_ck804_5 = pci_read_config8(dev, PCI_SECONDARY_BUS);
114                 }
115                 else {
116                         printk_debug("ERROR - could not find PCI 1:%02x.0, using defaults\n", sbdn+ 0x0e);
117                 }
118
119                 bus_8131_0 = (sysconf.pci1234[1] >> 16) & 0xff;
120                 /* 8131-1 */
121                 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3,0));
122                 if (dev) {
123                         bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
124                         bus_8131_2 = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
125                         bus_8131_2++;
126                 }
127                 else {
128                         printk_debug("ERROR - could not find PCI %02x:01.0, using defaults\n", bus_8131_0);
129
130                         bus_8131_1 = bus_8131_0+1;
131                         bus_8131_2 = bus_8131_0+2;
132                 }
133                 /* 8131-2 */
134                 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3,0));
135                 if (dev) {
136                         bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
137                         bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
138                         bus_isa++;
139                 }
140                 else {
141                         printk_debug("ERROR - could not find PCI %02x:02.0, using defaults\n", bus_8131_0);
142
143                         bus_8131_2 = bus_8131_1+1;
144                 }
145
146                 /* CK804b */
147
148         if(sysconf.pci1234[2] & 0x0f) { //if the second cpu is installed
149                 bus_ck804b_0 = (sysconf.pci1234[2]>>16) & 0xff;
150
151                 dev = dev_find_slot(bus_ck804b_0, PCI_DEVFN(sbdnb + 0x0e,0));
152                 if (dev) {
153                         bus_ck804b_5 = pci_read_config8(dev, PCI_SECONDARY_BUS);
154                         bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
155                         bus_isa++;
156                 }
157                 else {
158                         printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", bus_ck804b_0,sbdnb+0x0e);
159                         bus_ck804b_5 = bus_ck804b_4+1;
160                         bus_isa = bus_ck804b_5+1;
161                 }
162         }
163
164
165 /*I/O APICs:    APIC ID Version State           Address*/
166 #if CONFIG_LOGICAL_CPUS==1
167         apicid_base = get_apicid_base(4);
168 #else
169         apicid_base = CONFIG_MAX_PHYSICAL_CPUS;
170 #endif
171         apicid_ck804 = apicid_base+0;
172         apicid_8131_1 = apicid_base+1;
173         apicid_8131_2 = apicid_base+2;
174         apicid_ck804b = apicid_base+3;
175 }