e94fdc3015f83b987132a256e366f5eb61271ba8
[coreboot.git] / src / mainboard / amd / dbm690t / get_bus_conf.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008 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/amdk8_sysconf.h>
30
31 /* Global variables for MB layouts and these will be shared by irqtable mptable 
32 * and acpi_tables busnum is default.
33 */
34 u8 bus_isa;
35 u8 bus_rs690[8];
36 u8 bus_sb600[2];
37 unsigned long apicid_sb600;
38
39 /*
40 * Here you only need to set value in pci1234 for HT-IO that could be installed or not
41 * You may need to preset pci1234 for HTIO board,
42 * please refer to src/northbridge/amd/amdk8/get_sblk_pci1234.c for detail
43 */
44 unsigned long pci1234x[] = {
45         0x0000ff0,
46 };
47
48 /*
49 * HT Chain device num, actually it is unit id base of every ht device in chain,
50 * assume every chain only have 4 ht device at most
51 */
52 unsigned long hcdnx[] = {
53         0x20202020,
54 };
55
56 unsigned long bus_type[256];
57
58 unsigned long sbdn_rs690;
59 unsigned long sbdn_sb600;
60
61 extern void get_sblk_pci1234(void);
62
63 static unsigned long get_bus_conf_done = 0;
64
65 void get_bus_conf(void)
66 {
67         unsigned long apicid_base;
68         device_t dev;
69         int i, j;
70
71         if (get_bus_conf_done == 1)
72                 return;         /* do it only once */
73         get_bus_conf_done = 1;
74
75         sysconf.hc_possible_num = sizeof(pci1234x) / sizeof(pci1234x[0]);
76         for (i = 0; i < sysconf.hc_possible_num; i++) {
77                 sysconf.pci1234[i] = pci1234x[i];
78                 sysconf.hcdn[i] = hcdnx[i];
79         }
80
81         get_sblk_pci1234();
82
83         sysconf.sbdn = (sysconf.hcdn[0] & 0xff);
84         sbdn_rs690 = sysconf.sbdn;
85         sbdn_sb600 = 0;
86
87         for (i = 0; i < 2; i++) {
88                 bus_sb600[i] = 0;
89         }
90         for (i = 0; i < 8; i++) {
91                 bus_rs690[i] = 0;
92         }
93
94         for (i = 0; i < 256; i++) {
95                 bus_type[i] = 0; /* default ISA bus. */
96         }
97
98         bus_type[0] = 1;        /* pci */
99
100         bus_rs690[0] = (sysconf.pci1234[0] >> 16) & 0xff;
101         bus_sb600[0] = bus_rs690[0];
102
103         bus_type[bus_rs690[0]] = 1;
104
105         /* sb600 */
106         dev = dev_find_slot(bus_sb600[0], PCI_DEVFN(sbdn_sb600 + 0x14, 4));
107         if (dev) {
108                 bus_sb600[1] = pci_read_config8(dev, PCI_SECONDARY_BUS);
109                 bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
110                 bus_isa++;
111                 for (j = bus_sb600[1]; j < bus_isa; j++)
112                         bus_type[j] = 1;
113         }
114
115         /* rs690 */
116         for (i = 1; i < 8; i++) {
117                 dev = dev_find_slot(bus_rs690[0], PCI_DEVFN(sbdn_rs690 + i, 0));
118                 if (dev) {
119                         bus_rs690[i] = pci_read_config8(dev, PCI_SECONDARY_BUS);
120                         if(255 != bus_rs690[i]) {
121                                 bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
122                                 bus_isa++;
123                                 bus_type[bus_rs690[i]] = 1; /* PCI bus. */
124                         }
125                 }
126         }
127
128         /* I/O APICs:   APIC ID Version State   Address */
129         bus_isa = 10;
130 #if CONFIG_LOGICAL_CPUS==1
131         apicid_base = get_apicid_base(1);
132 #else
133         apicid_base = CONFIG_MAX_PHYSICAL_CPUS;
134 #endif
135         apicid_sb600 = apicid_base + 0;
136 }