e2f868e56685e4a74d57a6e7c3eaab2b3b5475fb
[coreboot.git] / src / mainboard / msi / ms7135 / get_bus_conf.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 AMD
5  * (Written by Yinghai Lu <yinghailu@amd.com> for AMD)
6  * Copyright (C) 2007 Philipp Degler <pdegler@rumms.uni-mannheim.de>
7  * (Thanks to LSRA University of Mannheim for their support)
8  * Copyright (C) 2008 Jonathan A. Kollasch <jakllsch@kollasch.net>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
23  */
24
25 #include <console/console.h>
26 #include <device/pci.h>
27 #include <device/pci_ids.h>
28 #include <string.h>
29 #include <stdint.h>
30 #if CONFIG_LOGICAL_CPUS == 1
31 #include <cpu/amd/dualcore.h>
32 #endif
33
34 #include <cpu/amd/amdk8_sysconf.h>
35
36 /* Global variables for MB layouts and these will be shared by irqtable,
37  * mptable and acpi_tables.
38  */
39 /* busnum is default */
40 unsigned char bus_isa;
41 unsigned char bus_ck804[6];
42 unsigned apicid_ck804;
43
44 unsigned pci1234x[] = {         //Here you only need to set value in pci1234 for HT-IO that could be installed or not
45         //You may need to preset pci1234 for HTIO board, please refer to src/northbridge/amd/amdk8/get_sblk_pci1234.c for detail
46         0x0000ff0,              //no HTIO for ms7135
47 };
48 unsigned hcdnx[] = {            //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
49         0x20202020,             //ms7135 has only one ht-chain 
50 };
51 unsigned bus_type[256];
52
53 extern void get_sblk_pci1234(void);
54
55 static unsigned get_bus_conf_done = 0;
56
57 void get_bus_conf(void)
58 {
59         unsigned apicid_base;
60
61         device_t dev;
62         unsigned sbdn;
63         int i, j;
64
65         if (get_bus_conf_done == 1)
66                 return;         //do it only once
67
68         get_bus_conf_done = 1;
69
70         sysconf.hc_possible_num = sizeof(pci1234x) / sizeof(pci1234x[0]);
71         sysconf.hc_possible_num = sizeof(pci1234x) / sizeof(pci1234x[0]);
72         for (i = 0; i < sysconf.hc_possible_num; i++) {
73                 sysconf.pci1234[i] = pci1234x[i];
74                 sysconf.hcdn[i] = hcdnx[i];
75         }
76
77         get_sblk_pci1234();
78
79         sysconf.sbdn = (sysconf.hcdn[0] & 0xff);        // first byte of first chain
80         sbdn = sysconf.sbdn;
81
82         for (i = 0; i < 6; i++) {
83                 bus_ck804[i] = 0;
84         }
85
86         for (i = 0; i < 256; i++) {
87                 bus_type[i] = 0;
88         }
89
90         bus_type[0] = 1;        //pci
91
92         bus_ck804[0] = (sysconf.pci1234[0] >> 16) & 0xff;
93
94         bus_type[bus_ck804[0]] = 1;
95
96         /* CK804 */
97         int dn = -1;
98         for (i = 1; i < 4; i++) {
99                 switch (i) {
100                         case 1: dn = 9; break;
101                         case 2: dn = 13; break;
102                         case 3: dn = 14; break; 
103                         default: dn = -1; break;
104                 }
105                 dev = dev_find_slot(bus_ck804[0], PCI_DEVFN(sbdn + dn, 0));
106                 if (dev) {
107                         bus_ck804[i] = pci_read_config8(dev, PCI_SECONDARY_BUS);
108                         bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
109                         bus_isa++;
110                         for (j = bus_ck804[i]; j < bus_isa; j++)
111                                 bus_type[j] = 1;
112                 } else {
113                         printk_debug
114                             ("ERROR - could not find PCI %02x:%02x.0, using defaults\n",
115                              bus_ck804[0], sbdn + dn);
116                         bus_isa = bus_ck804[i - 1] + 1;
117                 }
118         }
119
120 /*I/O APICs:    APIC ID Version State           Address*/
121 #if CONFIG_LOGICAL_CPUS==1
122         apicid_base = get_apicid_base(3);
123 #else
124         apicid_base = CONFIG_MAX_PHYSICAL_CPUS;
125 #endif
126         apicid_ck804 = apicid_base + 0;
127 }