7bb5f767888c29bb28b3be39a00dfabe5ac901bc
[coreboot.git] / src / mainboard / tyan / s2912 / 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  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 #include <console/console.h>
23 #include <device/pci.h>
24 #include <device/pci_ids.h>
25 #include <string.h>
26 #include <stdint.h>
27 #if CONFIG_LOGICAL_CPUS==1
28 #include <cpu/amd/dualcore.h>
29 #endif
30
31 #include <cpu/amd/amdk8_sysconf.h>
32
33 #include "mb_sysconf.h"
34
35 // Global variables for MB layouts and these will be shared by irqtable mptable and acpi_tables
36 struct mb_sysconf_t mb_sysconf;
37
38 unsigned pci1234x[] = 
39 {        //Here you only need to set value in pci1234 for HT-IO that could be installed or not
40          //You may need to preset pci1234 for HTIO board, please refer to src/northbridge/amd/amdk8/get_sblk_pci1234.c for detail
41         0x0000ff0,
42         0x0000ff0,
43         0x0000ff0,
44 //        0x0000ff0,
45 //        0x0000ff0,
46 //        0x0000ff0,
47 //        0x0000ff0,
48 //        0x0000ff0
49 };
50 unsigned hcdnx[] = 
51 { //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
52         0x20202020,
53         0x20202020,
54         0x20202020,
55 //        0x20202020,
56 //        0x20202020,
57 //        0x20202020,
58 //        0x20202020,
59 //        0x20202020,
60 };
61
62
63 extern void get_sblk_pci1234(void);
64
65 static unsigned get_bus_conf_done = 0;
66
67 static unsigned get_hcid(unsigned i)
68 {
69         unsigned id = 0;
70
71         unsigned busn = (sysconf.pci1234[i] >> 16) & 0xff;
72
73         unsigned devn = sysconf.hcdn[i] & 0xff;
74
75         device_t dev;
76
77         dev = dev_find_slot(busn, PCI_DEVFN(devn,0));
78
79         switch (dev->device) {
80         case 0x0369: //IO55
81                 id = 4;
82                 break;
83         }
84
85         // we may need more way to find out hcid: subsystem id? GPIO read ?
86
87         // we need use id for 1. bus num, 2. mptable, 3. acpi table
88
89         return id;
90 }
91
92 void get_bus_conf(void)
93 {
94
95         unsigned apicid_base;
96         struct mb_sysconf_t *m;
97
98         device_t dev;
99         int i, j;
100
101         if(get_bus_conf_done==1) return; //do it only once
102
103         get_bus_conf_done = 1;
104
105         sysconf.mb = &mb_sysconf;
106         
107         m = sysconf.mb;
108         memset(m, 0, sizeof(struct mb_sysconf_t));
109
110         sysconf.hc_possible_num = sizeof(pci1234x)/sizeof(pci1234x[0]);
111         for(i=0;i<sysconf.hc_possible_num; i++) {
112                 sysconf.pci1234[i] = pci1234x[i];
113                 sysconf.hcdn[i] = hcdnx[i];
114         }
115
116         get_sblk_pci1234();
117
118         sysconf.sbdn = (sysconf.hcdn[0] & 0xff); // first byte of first chain
119
120         m->bus_type[0] = 1; //pci
121         
122         m->bus_mcp55[0] = (sysconf.pci1234[0] >> 16) & 0xff;
123
124                 /* MCP55 */
125                 dev = dev_find_slot(m->bus_mcp55[0], PCI_DEVFN(sysconf.sbdn + 0x06,0));
126                 if (dev) {
127                         m->bus_mcp55[1] = pci_read_config8(dev, PCI_SECONDARY_BUS);
128                 }
129                 else {
130                         printk_debug("ERROR - could not find PCI 1:%02x.0, using defaults\n", sysconf.sbdn + 0x06);
131                 }
132
133                 for(i=2; i<8;i++) {
134                         dev = dev_find_slot(m->bus_mcp55[0], PCI_DEVFN(sysconf.sbdn + 0x0a + i - 2 , 0));
135                         if (dev) {
136                                 m->bus_mcp55[i] = pci_read_config8(dev, PCI_SECONDARY_BUS);
137                         }
138                         else {
139                                 printk_debug("ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_mcp55[0], sysconf.sbdn + 0x0a + i - 2 );
140                         }
141                 }
142
143         for(i=0; i< sysconf.hc_possible_num; i++) {
144                 if(!(sysconf.pci1234[i] & 0x1) ) continue;
145
146                 unsigned busn = (sysconf.pci1234[i] >> 16) & 0xff;
147                 unsigned busn_max = (sysconf.pci1234[i] >> 24) & 0xff;
148                 for (j = busn; j <= busn_max; j++) 
149                         m->bus_type[j] = 1;
150                 if(m->bus_isa <= busn_max) 
151                         m->bus_isa = busn_max + 1;
152                 printk_debug("i=%d bus range: [%x, %x] bus_isa=%x\n",i, busn, busn_max, m->bus_isa);
153         }
154
155
156
157 /*I/O APICs:    APIC ID Version State           Address*/
158 #if CONFIG_LOGICAL_CPUS==1
159         apicid_base = get_apicid_base(1);
160 #else 
161         apicid_base = CONFIG_MAX_PHYSICAL_CPUS; 
162 #endif
163         m->apicid_mcp55 = apicid_base+0;
164
165 }