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