65a0eb979640eece014d03337d2a174d27b52f54
[coreboot.git] / src / mainboard / hp / dl145_g3 / get_bus_conf.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2006 AMD
5  * Written by Yinghai Lu <yinghailu@gmail.com> for AMD.
6  *
7  * Copyright (C) 2006 MSI
8  * Written by bxshi <bingxunshi@gmail.com> for MSI.
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 #include <console/console.h>
25 #include <device/pci.h>
26 #include <device/pci_ids.h>
27 #include <string.h>
28 #include <stdint.h>
29 #if CONFIG_LOGICAL_CPUS==1
30 #include <cpu/amd/dualcore.h>
31 #endif
32
33 #include <cpu/amd/amdk8_sysconf.h>
34
35 #include "mb_sysconf.h"
36
37 // Global variables for MB layouts and these will be shared by irqtable mptable and acpi_tables
38 struct mb_sysconf_t mb_sysconf;
39
40 static unsigned pci1234x[] =
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, please refer to src/northbridge/amd/amdk8/get_sblk_pci1234.c for detail
43         0x0000ff0,
44         0x0000ff0,
45 //      0x0000ff0,
46 //      0x0000ff0,
47 //      0x0000ff0,
48 //      0x0000ff0,
49 //      0x0000ff0,
50 //      0x0000ff0
51 };
52 static unsigned hcdnx[] =
53 { //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
54         0x20202020,
55         0x20202020,
56 //      0x20202020,
57 //      0x20202020,
58 //      0x20202020,
59 //      0x20202020,
60 //      0x20202020,
61 //      0x20202020,
62 };
63
64 extern void get_sblk_pci1234(void);
65
66 static unsigned get_bus_conf_done = 0;
67
68 void get_bus_conf(void)
69 {
70
71         unsigned apicid_base;
72
73         device_t dev;
74         int i;
75         struct mb_sysconf_t *m;
76
77         if(get_bus_conf_done==1) return; //do it only once
78
79         get_bus_conf_done = 1;
80
81         sysconf.mb = &mb_sysconf;
82
83         m = sysconf.mb;
84
85         sysconf.hc_possible_num = sizeof(pci1234x)/sizeof(pci1234x[0]);
86
87         for(i=0;i<sysconf.hc_possible_num; i++) {
88                 sysconf.pci1234[i] = pci1234x[i];
89                 sysconf.hcdn[i] = hcdnx[i];
90         }
91
92         get_sblk_pci1234();
93
94         sysconf.sbdn = (sysconf.hcdn[0] >> 8) & 0xff;
95         m->sbdn2 = sysconf.hcdn[0] & 0xff; // bcm5780
96
97         m->bus_bcm5785_0 = (sysconf.pci1234[0] >> 16) & 0xff;
98         m->bus_bcm5780[0] = m->bus_bcm5785_0;
99
100                 /* bcm5785 */
101         printk_debug("search for def %d.0 on bus %d\n",sysconf.sbdn,m->bus_bcm5785_0);
102         dev = dev_find_slot(m->bus_bcm5785_0, PCI_DEVFN(sysconf.sbdn,0));
103         if (dev) {
104                 printk_debug("found dev %s...\n",dev_path(dev));
105                 m->bus_bcm5785_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
106                 printk_debug("secondary is %d...\n",m->bus_bcm5785_1);
107                 dev = dev_find_slot(m->bus_bcm5785_1, PCI_DEVFN(0xd,0));
108                 printk_debug("now found %s...\n",dev_path(dev));
109                 if(dev) {
110                         m->bus_bcm5785_1_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
111 #if CONFIG_HT_CHAIN_END_UNITID_BASE >= CONFIG_HT_CHAIN_UNITID_BASE
112                         m->bus_isa    = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
113                         m->bus_isa++;
114                         printk_debug("bus_isa 1=%d\n",m->bus_isa);
115 #endif
116                 }
117         }
118         else {
119                 printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_bcm5785_0, sysconf.sbdn);
120         }
121
122                 /* bcm5780 */
123         for(i = 1; i < 6; i++) {
124                 dev = dev_find_slot(m->bus_bcm5780[0], PCI_DEVFN(m->sbdn2 + i - 1,0));
125                 if(dev) {
126                         m->bus_bcm5780[i] = pci_read_config8(dev, PCI_SECONDARY_BUS);
127 #if CONFIG_HT_CHAIN_END_UNITID_BASE < CONFIG_HT_CHAIN_UNITID_BASE
128                         m->bus_isa    = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
129                         m->bus_isa++;
130                         printk_debug("bus_isa 2=%d\n",m->bus_isa);
131 #endif
132
133                 }
134                 else {
135                         printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_bcm5780[0], m->sbdn2+i-1);
136                 }
137         }
138
139
140 /*I/O APICs:   APIC ID Version State       Address*/
141 #if CONFIG_LOGICAL_CPUS==1
142         apicid_base = get_apicid_base(3);
143 #else
144         apicid_base = CONFIG_MAX_PHYSICAL_CPUS;
145 #endif
146         for(i=0;i<3;i++)
147                 m->apicid_bcm5785[i] = apicid_base+i;
148 }