Please bear with me - another rename checkin. This qualifies as trivial, no
[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 "mb_sysconf.h"
32
33 /* Global variables for MB layouts and these will be shared by irqtable mptable and acpi_tables */
34 struct mb_sysconf_t mb_sysconf;
35
36 /* Here you only need to set value in pci1234 for HT-IO that could be
37 installed or not You may need to preset pci1234 for HTIO board, please
38 refer to src/northbridge/amd/amdfam10/get_sblk_pci1234.c for detail */
39 static u32 pci1234x[] = {
40         0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc,
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,
46         };
47
48
49 /* HT Chain device num, actually it is unit id base of every ht device
50 in chain, assume every chain only have 4 ht device at most */
51
52 static unsigned hcdnx[] = {
53         0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
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,
60 };
61
62
63
64 extern void get_pci1234(void);
65
66 static u32 get_bus_conf_done = 0;
67
68 static u32 get_hcid(u32 i)
69 {
70         u32 id = 0;
71         u32 busn = (sysconf.pci1234[i] >> 12) & 0xff;
72         u32 devn = sysconf.hcdn[i] & 0xff;
73         device_t dev;
74
75         dev = dev_find_slot(busn, PCI_DEVFN(devn,0));
76
77         switch (dev->device) {
78         case 0x7458: //8132
79                 id = 1;
80                 break;
81         case 0x7454: //8151
82                 id = 2;
83                 break;
84         case 0x7450: //8131
85                 id = 3;
86                 break;
87         }
88         // we may need more way to find out hcid: subsystem id? GPIO read ?
89         // we need use id for 1. bus num, 2. mptable, 3. acpi table
90         return id;
91 }
92
93 void get_bus_conf(void)
94 {
95         u32 apicid_base;
96
97         device_t dev;
98         int i, j;
99         struct mb_sysconf_t *m;
100
101         if(get_bus_conf_done == 1)
102                 return; //do it only once
103
104         get_bus_conf_done = 1;
105
106         sysconf.mb = &mb_sysconf;
107
108         m = sysconf.mb;
109
110         for(i=0;i<256; i++) {
111                 m->bus_type[i] = 0;
112         }
113
114         sysconf.hc_possible_num = sizeof(pci1234x)/sizeof(pci1234x[0]);
115         for(i=0;i<sysconf.hc_possible_num; i++) {
116                 sysconf.pci1234[i] = pci1234x[i];
117                 sysconf.hcdn[i] = hcdnx[i];
118         }
119
120         get_pci1234();
121
122         m->bus_type[0] = 1; //pci
123
124         sysconf.sbdn = (sysconf.hcdn[0] >> 8) & 0xff;
125         m->sbdn3 = sysconf.hcdn[0] & 0xff;
126
127         m->bus_8132_0 = (sysconf.pci1234[0] >> 12) & 0xff;
128         m->bus_8111_0 = m->bus_8132_0;
129
130         /* 8111 */
131         dev = dev_find_slot(m->bus_8111_0, PCI_DEVFN(sysconf.sbdn,0));
132         if (dev) {
133                 m->bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
134         } else {
135                 printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8111_0, sysconf.sbdn);
136         }
137
138         /* 8132-1 */
139         dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN(m->sbdn3,0));
140         if (dev) {
141                 m->bus_8132_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
142         } else {
143                 printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8132_0, m->sbdn3);
144         }
145
146         /* 8132-2 */
147         dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN(m->sbdn3+1,0));
148         if (dev) {
149                 m->bus_8132_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
150         } else {
151                 printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8132_0, m->sbdn3+1);
152         }
153
154         for(i=0; i< sysconf.hc_possible_num; i++) {
155                 if(!(sysconf.pci1234[i] & 0x1) ) continue;
156
157                 u32 busn = (sysconf.pci1234[i] >> 12) & 0xff;
158                 u32 busn_max = (sysconf.pci1234[i] >> 20) & 0xff;
159                 for (j = busn; j <= busn_max; j++)
160                         m->bus_type[j] = 1;
161                 if(m->bus_isa <= busn_max)
162                         m->bus_isa = busn_max + 1;
163                 printk_debug("i=%d bus range: [%x, %x] bus_isa=%x\n",i, busn, busn_max, m->bus_isa);
164         }
165
166          /* HT chain 1 */
167         j=0;
168         for(i=1; i< sysconf.hc_possible_num; i++) {
169                 if(!(sysconf.pci1234[i] & 0x1) ) continue;
170
171                 // check hcid type here
172                 sysconf.hcid[i] = get_hcid(i);
173
174                 switch(sysconf.hcid[i]) {
175
176                 case 1: //8132
177                 case 3: //8131
178
179                         m->bus_8132a[j][0] = (sysconf.pci1234[i] >> 12) & 0xff;
180
181                         m->sbdn3a[j] = sysconf.hcdn[i] & 0xff;
182
183                         /* 8132-1 */
184                         dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j],0));
185                         if (dev) {
186                                 m->bus_8132a[j][1] = pci_read_config8(dev, PCI_SECONDARY_BUS);
187                         } else {
188                                 printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8132a[j][0], m->sbdn3a[j]);
189                         }
190
191                         /* 8132-2 */
192                         dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j]+1,0));
193                         if (dev) {
194                                 m->bus_8132a[j][2] = pci_read_config8(dev, PCI_SECONDARY_BUS);
195                         } else {
196                                 printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8132a[j][0], m->sbdn3a[j]+1);
197                         }
198
199                         break;
200
201                 case 2: //8151
202
203                         m->bus_8151[j][0] = (sysconf.pci1234[i] >> 12) & 0xff;
204                         m->sbdn5[j] = sysconf.hcdn[i] & 0xff;
205                         /* 8151 */
206                         dev = dev_find_slot(m->bus_8151[j][0], PCI_DEVFN(m->sbdn5[j]+1, 0));
207
208                         if (dev) {
209                                 m->bus_8151[j][1] = pci_read_config8(dev, PCI_SECONDARY_BUS);
210                         } else {
211                                 printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8151[j][0], m->sbdn5[j]+1);
212                         }
213
214                         break;
215                 }
216
217                 j++;
218          }
219
220 /*I/O APICs:    APIC ID Version State           Address*/
221         apicid_base = 0;
222         m->apicid_8111 = apicid_base + 0;
223         m->apicid_8132_1 = apicid_base + 1;
224         m->apicid_8132_2 = apicid_base + 2;
225         for(i=0;i<j;i++) {
226                 m->apicid_8132a[i][0] = apicid_base + 3 + i * 2;
227                 m->apicid_8132a[i][1] = apicid_base + 3 + i * 2 + 1;
228         }
229 }