0eae634fd106f3692fac7f6432736cd2d581b6cf
[coreboot.git] / src / mainboard / amd / serengeti_cheetah_fam10 / get_bus_conf.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Advanced Micro Devices, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 #include <console/console.h>
21 #include <device/pci.h>
22 #include <device/pci_ids.h>
23 #include <string.h>
24 #include <stdint.h>
25 #if CONFIG_LOGICAL_CPUS==1
26 #include <cpu/amd/dualcore.h>
27 #endif
28
29 #include <cpu/amd/amdfam10_sysconf.h>
30
31 #include <stdlib.h>
32 #include "mb_sysconf.h"
33
34 /* Global variables for MB layouts and these will be shared by irqtable mptable and acpi_tables */
35 struct mb_sysconf_t mb_sysconf;
36
37 /* Here you only need to set value in pci1234 for HT-IO that could be
38 installed or not You may need to preset pci1234 for HTIO board, please
39 refer to src/northbridge/amd/amdfam10/get_sblk_pci1234.c for detail */
40 static u32 pci1234x[] = {
41         0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc,
42         0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc,
43         0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc,
44         0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc,
45         0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc,
46         0x0000ffc, 0x0000ffc,
47         };
48
49
50 /* HT Chain device num, actually it is unit id base of every ht device
51 in chain, assume every chain only have 4 ht device at most */
52
53 static unsigned hcdnx[] = {
54         0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
55         0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
56         0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
57         0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
58         0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
59         0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
60         0x20202020, 0x20202020,
61 };
62
63
64
65 extern void get_pci1234(void);
66
67 static u32 get_bus_conf_done = 0;
68
69 static u32 get_hcid(u32 i)
70 {
71         u32 id = 0;
72         u32 busn = (sysconf.pci1234[i] >> 12) & 0xff;
73         u32 devn = sysconf.hcdn[i] & 0xff;
74         device_t dev;
75
76         dev = dev_find_slot(busn, PCI_DEVFN(devn,0));
77
78         switch (dev->device) {
79         case 0x7458: //8132
80                 id = 1;
81                 break;
82         case 0x7454: //8151
83                 id = 2;
84                 break;
85         case 0x7450: //8131
86                 id = 3;
87                 break;
88         }
89         // we may need more way to find out hcid: subsystem id? GPIO read ?
90         // we need use id for 1. bus num, 2. mptable, 3. acpi table
91         return id;
92 }
93
94 void get_bus_conf(void)
95 {
96         u32 apicid_base;
97
98         device_t dev;
99         int i, j;
100         struct mb_sysconf_t *m;
101
102         if(get_bus_conf_done == 1)
103                 return; //do it only once
104
105         get_bus_conf_done = 1;
106
107         sysconf.mb = &mb_sysconf;
108
109         m = sysconf.mb;
110
111         for(i=0;i<256; i++) {
112                 m->bus_type[i] = 0;
113         }
114
115         sysconf.hc_possible_num = ARRAY_SIZE(pci1234x);
116         for(i=0;i<sysconf.hc_possible_num; i++) {
117                 sysconf.pci1234[i] = pci1234x[i];
118                 sysconf.hcdn[i] = hcdnx[i];
119         }
120
121         get_pci1234();
122
123         m->bus_type[0] = 1; //pci
124
125         sysconf.sbdn = (sysconf.hcdn[0] >> 8) & 0xff;
126         m->sbdn3 = sysconf.hcdn[0] & 0xff;
127
128         m->bus_8132_0 = (sysconf.pci1234[0] >> 12) & 0xff;
129         m->bus_8111_0 = m->bus_8132_0;
130
131         /* 8111 */
132         dev = dev_find_slot(m->bus_8111_0, PCI_DEVFN(sysconf.sbdn,0));
133         if (dev) {
134                 m->bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
135         } else {
136                 printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8111_0, sysconf.sbdn);
137         }
138
139         /* 8132-1 */
140         dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN(m->sbdn3,0));
141         if (dev) {
142                 m->bus_8132_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
143         } else {
144                 printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8132_0, m->sbdn3);
145         }
146
147         /* 8132-2 */
148         dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN(m->sbdn3+1,0));
149         if (dev) {
150                 m->bus_8132_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
151         } else {
152                 printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8132_0, m->sbdn3+1);
153         }
154
155         for(i=0; i< sysconf.hc_possible_num; i++) {
156                 if(!(sysconf.pci1234[i] & 0x1) ) continue;
157
158                 u32 busn = (sysconf.pci1234[i] >> 12) & 0xff;
159                 u32 busn_max = (sysconf.pci1234[i] >> 20) & 0xff;
160                 for (j = busn; j <= busn_max; j++)
161                         m->bus_type[j] = 1;
162                 if(m->bus_isa <= busn_max)
163                         m->bus_isa = busn_max + 1;
164                 printk_debug("i=%d bus range: [%x, %x] bus_isa=%x\n",i, busn, busn_max, m->bus_isa);
165         }
166
167          /* HT chain 1 */
168         j=0;
169         for(i=1; i< sysconf.hc_possible_num; i++) {
170                 if(!(sysconf.pci1234[i] & 0x1) ) continue;
171
172                 // check hcid type here
173                 sysconf.hcid[i] = get_hcid(i);
174
175                 switch(sysconf.hcid[i]) {
176
177                 case 1: //8132
178                 case 3: //8131
179
180                         m->bus_8132a[j][0] = (sysconf.pci1234[i] >> 12) & 0xff;
181
182                         m->sbdn3a[j] = sysconf.hcdn[i] & 0xff;
183
184                         /* 8132-1 */
185                         dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j],0));
186                         if (dev) {
187                                 m->bus_8132a[j][1] = pci_read_config8(dev, PCI_SECONDARY_BUS);
188                         } else {
189                                 printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8132a[j][0], m->sbdn3a[j]);
190                         }
191
192                         /* 8132-2 */
193                         dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j]+1,0));
194                         if (dev) {
195                                 m->bus_8132a[j][2] = pci_read_config8(dev, PCI_SECONDARY_BUS);
196                         } else {
197                                 printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8132a[j][0], m->sbdn3a[j]+1);
198                         }
199
200                         break;
201
202                 case 2: //8151
203
204                         m->bus_8151[j][0] = (sysconf.pci1234[i] >> 12) & 0xff;
205                         m->sbdn5[j] = sysconf.hcdn[i] & 0xff;
206                         /* 8151 */
207                         dev = dev_find_slot(m->bus_8151[j][0], PCI_DEVFN(m->sbdn5[j]+1, 0));
208
209                         if (dev) {
210                                 m->bus_8151[j][1] = pci_read_config8(dev, PCI_SECONDARY_BUS);
211                         } else {
212                                 printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8151[j][0], m->sbdn5[j]+1);
213                         }
214
215                         break;
216                 }
217
218                 j++;
219          }
220
221 /*I/O APICs:    APIC ID Version State           Address*/
222         apicid_base = 0;
223         m->apicid_8111 = apicid_base + 0;
224         m->apicid_8132_1 = apicid_base + 1;
225         m->apicid_8132_2 = apicid_base + 2;
226         for(i=0;i<j;i++) {
227                 m->apicid_8132a[i][0] = apicid_base + 3 + i * 2;
228                 m->apicid_8132a[i][1] = apicid_base + 3 + i * 2 + 1;
229         }
230 }