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