Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / mainboard / iwill / dk8_htx / 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/multicore.h>
8 #endif
9
10 #include <cpu/amd/amdk8_sysconf.h>
11
12 #include <stdlib.h>
13 #include "mb_sysconf.h"
14
15 // Global variables for MB layouts and these will be shared by irqtable mptable and acpi_tables
16 struct mb_sysconf_t mb_sysconf;
17
18 static unsigned pci1234x[] =
19 {        //Here you only need to set value in pci1234 for HT-IO that could be installed or not
20          //You may need to preset pci1234 for HTIO board, please refer to src/northbridge/amd/amdk8/get_sblk_pci1234.c for detail
21         0x0000ff0, // SB chain m
22         0x0000000, // HTX
23         0x0000100, // co processor on socket 1
24 //        0x0000ff0,
25 //        0x0000ff0,
26 //        0x0000ff0,
27 //        0x0000ff0,
28 //        0x0000ff0
29 };
30 static unsigned hcdnx[] =
31 { //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
32         0x20202020,
33         0x20202020,
34         0x20202020,
35 //        0x20202020,
36 //        0x20202020,
37 //        0x20202020,
38 //        0x20202020,
39 //        0x20202020,
40 };
41
42
43
44 static unsigned get_bus_conf_done = 0;
45
46 static unsigned get_hcid(unsigned i)
47 {
48         unsigned id = 0;
49
50         unsigned busn = (sysconf.pci1234[i] >> 16) & 0xff;
51
52         unsigned devn = sysconf.hcdn[i] & 0xff;
53
54         device_t dev;
55
56         dev = dev_find_slot(busn, PCI_DEVFN(devn,0));
57
58         switch (dev->device) {
59         case 0x7458: //8132
60                 id = 1;
61                 break;
62         case 0x7454: //8151
63                 id = 2;
64                 break;
65         case 0x7450: //8131
66                 id = 3;
67                 break;
68         }
69
70         // we may need more way to find out hcid: subsystem id? GPIO read ?
71
72         // we need use id for 1. bus num, 2. mptable, 3. acpi table
73
74         return id;
75 }
76
77 void get_bus_conf(void)
78 {
79
80         unsigned apicid_base;
81
82         device_t dev;
83         int i, j;
84         struct mb_sysconf_t *m;
85
86         if(get_bus_conf_done == 1) return; //do it only once
87
88         get_bus_conf_done = 1;
89
90         sysconf.mb = &mb_sysconf;
91
92         m = sysconf.mb;
93
94         sysconf.hc_possible_num = ARRAY_SIZE(pci1234x);
95         for(i=0;i<sysconf.hc_possible_num; i++) {
96                 sysconf.pci1234[i] = pci1234x[i];
97                 sysconf.hcdn[i] = hcdnx[i];
98         }
99
100         get_sblk_pci1234();
101
102         sysconf.sbdn = (sysconf.hcdn[0] >> 8) & 0xff;
103         m->sbdn3 = sysconf.hcdn[0] & 0xff;
104
105         m->bus_8132_0 = (sysconf.pci1234[0] >> 16) & 0xff;
106         m->bus_8111_0 = m->bus_8132_0;
107
108                 /* 8111 */
109         dev = dev_find_slot(m->bus_8111_0, PCI_DEVFN(sysconf.sbdn,0));
110         if (dev) {
111                 m->bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
112 #if CONFIG_HT_CHAIN_END_UNITID_BASE >= CONFIG_HT_CHAIN_UNITID_BASE
113                 m->bus_isa    = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
114                 m->bus_isa++;
115 //              printk(BIOS_DEBUG, "bus_isa=%d\n",bus_isa);
116 #endif
117         }
118         else {
119                 printk(BIOS_DEBUG, "ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8111_0, sysconf.sbdn);
120         }
121
122         /* 8132-1 */
123         dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN(m->sbdn3,0));
124         if (dev) {
125                 m->bus_8132_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
126         }
127         else {
128                 printk(BIOS_DEBUG, "ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8132_0, m->sbdn3);
129         }
130
131         /* 8132-2 */
132         dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN(m->sbdn3+1,0));
133         if (dev) {
134                 m->bus_8132_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
135 #if CONFIG_HT_CHAIN_END_UNITID_BASE < CONFIG_HT_CHAIN_UNITID_BASE
136                 m->bus_isa    = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
137                 m->bus_isa++;
138 //              printk(BIOS_DEBUG, "bus_isa=%d\n",bus_isa);
139 #endif
140         }
141         else {
142                 printk(BIOS_DEBUG, "ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8132_0, m->sbdn3+1);
143         }
144
145         /* HT chain 1 */
146         j=0;
147         for(i=1; i< sysconf.hc_possible_num; i++) {
148                 if(!(sysconf.pci1234[i] & 0x1) ) continue;
149
150                 // check hcid type here
151                 sysconf.hcid[i] = get_hcid(i);
152
153                 switch(sysconf.hcid[i]) {
154
155                 case 1: //8132
156                 case 3: //8131
157
158                         m->bus_8132a[j][0] = (sysconf.pci1234[i] >> 16) & 0xff;
159
160                         m->sbdn3a[j] = sysconf.hcdn[i] & 0xff;
161
162                         /* 8132-1 */
163                         dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j],0));
164                         if (dev) {
165                                 m->bus_8132a[j][1] = pci_read_config8(dev, PCI_SECONDARY_BUS);
166                         }
167                         else {
168                         printk(BIOS_DEBUG, "ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8132a[j][0], m->sbdn3a[j]);
169                         }
170
171                         /* 8132-2 */
172                         dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j]+1,0));
173                         if (dev) {
174                                 m->bus_8132a[j][2] = pci_read_config8(dev, PCI_SECONDARY_BUS);
175                                 m->bus_isa    = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
176                                 m->bus_isa++;
177                 //              printk(BIOS_DEBUG, "bus_isa=%d\n",bus_isa);
178                                 }
179                         else {
180                                 printk(BIOS_DEBUG, "ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8132a[j][0], m->sbdn3a[j]+1);
181                         }
182
183                         break;
184
185                 case 2: //8151
186
187                         m->bus_8151[j][0] = (sysconf.pci1234[i] >> 16) & 0xff;
188                         m->sbdn5[j] = sysconf.hcdn[i] & 0xff;
189                         /* 8151 */
190                         dev = dev_find_slot(m->bus_8151[j][0], PCI_DEVFN(m->sbdn5[j]+1, 0));
191
192                         if (dev) {
193                                 m->bus_8151[j][1] = pci_read_config8(dev, PCI_SECONDARY_BUS);
194         //                        printk(BIOS_DEBUG, "bus_8151_1=%d\n",bus_8151[j][1]);
195                                 m->bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
196                                 m->bus_isa++;
197                         }
198                         else {
199                                 printk(BIOS_DEBUG, "ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8151[j][0], m->sbdn5[j]+1);
200                         }
201
202                         break;
203                 }
204
205                 j++;
206         }
207
208
209 /*I/O APICs:    APIC ID Version State           Address*/
210 #if CONFIG_LOGICAL_CPUS==1
211         apicid_base = get_apicid_base(3);
212 #else
213         apicid_base = CONFIG_MAX_PHYSICAL_CPUS;
214 #endif
215         m->apicid_8111 = apicid_base+0;
216         m->apicid_8132_1 = apicid_base+1;
217         m->apicid_8132_2 = apicid_base+2;
218         for(i=0;i<j;i++) {
219                 m->apicid_8132a[i][0] = apicid_base + 3 + i*2;
220                 m->apicid_8132a[i][1] = apicid_base + 3 + i*2 + 1;
221         }
222
223 }