1f865adf0c568104630e0e584c10279c828f8232
[coreboot.git] / src / mainboard / iwill / dk8_htx / romstage.c
1 #define RAMINIT_SYSINFO 1
2 #define CACHE_AS_RAM_ADDRESS_DEBUG 0
3
4 #define SET_NB_CFG_54 1 
5
6 //used by raminit
7 #define QRANK_DIMM_SUPPORT 1
8
9 //used by incoherent_ht
10 //#define K8_ALLOCATE_IO_RANGE 1
11
12 //used by init_cpus and fidvid
13 #define K8_SET_FIDVID 0
14 //if we want to wait for core1 done before DQS training, set it to 0
15 #define K8_SET_FIDVID_CORE0_ONLY 1
16
17 #if CONFIG_K8_REV_F_SUPPORT == 1
18 #define K8_REV_F_SUPPORT_F0_F1_WORKAROUND 0
19 #endif
20
21 #include <stdint.h>
22 #include <string.h>
23 #include <device/pci_def.h>
24 #include <device/pci_ids.h>
25 #include <arch/io.h>
26 #include <device/pnp_def.h>
27 #include <arch/romcc_io.h>
28 #include <cpu/x86/lapic.h>
29 #include "option_table.h"
30 #include "pc80/mc146818rtc_early.c"
31
32 #include "pc80/serial.c"
33 #include "arch/i386/lib/console.c"
34 #include <cpu/amd/model_fxx_rev.h>
35 #include "southbridge/amd/amd8111/amd8111_early_smbus.c"
36 #include "northbridge/amd/amdk8/raminit.h"
37 #include "cpu/amd/model_fxx/apic_timer.c"
38
39 #include "cpu/x86/lapic/boot_cpu.c"
40 #include "northbridge/amd/amdk8/reset_test.c"
41
42 #include "cpu/x86/bist.h"
43
44 #include "lib/delay.c"
45
46 #include "northbridge/amd/amdk8/debug.c"
47 #include "cpu/amd/mtrr/amd_earlymtrr.c"
48 #include "superio/winbond/w83627hf/w83627hf_early_serial.c"
49
50 #include "northbridge/amd/amdk8/setup_resource_map.c"
51
52 #define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
53
54 #include "southbridge/amd/amd8111/amd8111_early_ctrl.c"
55
56 /*
57  * GPIO28 of 8111 will control H0_MEMRESET_L
58  * GPIO29 of 8111 will control H1_MEMRESET_L
59  */
60 static void memreset_setup(void)
61 {
62         if (is_cpu_pre_c0()) {
63                 /* Set the memreset low */
64                 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 28);
65                 /* Ensure the BIOS has control of the memory lines */
66                 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 29);
67         } else {
68                 /* Ensure the CPU has controll of the memory lines */
69                 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(1<<0), SMBUS_IO_BASE + 0xc0 + 29);
70         }
71 }
72
73 static void memreset(int controllers, const struct mem_controller *ctrl)
74 {
75         if (is_cpu_pre_c0()) {
76                 udelay(800);
77                 /* Set memreset_high */
78                 outb((0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<2)|(1<<0), SMBUS_IO_BASE + 0xc0 + 28);
79                 udelay(90);
80         }
81 }
82
83 static inline void activate_spd_rom(const struct mem_controller *ctrl)
84 {
85 }
86
87 static inline int spd_read_byte(unsigned device, unsigned address)
88 {
89         return smbus_read_byte(device, address);
90 }
91
92 #include "northbridge/amd/amdk8/amdk8.h"
93 #include "northbridge/amd/amdk8/coherent_ht.c"
94
95 #include "northbridge/amd/amdk8/incoherent_ht.c"
96
97 #include "northbridge/amd/amdk8/raminit.c"
98
99 #include "lib/generic_sdram.c"
100 #include "lib/ramtest.c"
101
102  /* tyan does not want the default */
103 #include "resourcemap.c" 
104
105 #include "cpu/amd/dualcore/dualcore.c"
106
107 #define DIMM0 0x50
108 #define DIMM1 0x51
109 #define DIMM2 0x52
110 #define DIMM3 0x53
111 #define DIMM4 0x54
112 #define DIMM5 0x55
113 #define DIMM6 0x56
114 #define DIMM7 0x57
115
116 #include "cpu/amd/car/copy_and_run.c"
117 #include "cpu/amd/car/post_cache_as_ram.c"
118
119 #include "cpu/amd/model_fxx/init_cpus.c"
120
121 #include "cpu/amd/model_fxx/fidvid.c"
122
123 #include "southbridge/amd/amd8111/amd8111_enable_rom.c"
124 #include "northbridge/amd/amdk8/early_ht.c"
125
126 void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
127 {
128         static const uint16_t spd_addr[] = {
129                         //first node
130                         DIMM0, DIMM2, 0, 0,
131                         DIMM1, DIMM3, 0, 0,
132 #if CONFIG_MAX_PHYSICAL_CPUS > 1
133                         //second node
134                         DIMM4, DIMM6, 0, 0,
135                         DIMM5, DIMM7, 0, 0,
136 #endif
137
138         };
139
140         struct sys_info *sysinfo = (CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);
141
142         int needs_reset; int i;
143         unsigned bsp_apicid = 0;
144
145         if (!cpu_init_detectedx && boot_cpu()) {
146                 /* Nothing special needs to be done to find bus 0 */
147                 /* Allow the HT devices to be found */
148
149                 enumerate_ht_chain();
150
151                 /* Setup the rom access for 4M */
152                 amd8111_enable_rom();
153         }
154
155         if (bist == 0) {
156                 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
157         }
158
159         w83627hf_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
160         uart_init();
161         console_init();
162
163         /* Halt if there was a built in self test failure */
164         report_bist_failure(bist);
165
166         printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
167
168         setup_mb_resource_map();
169
170         print_debug("bsp_apicid="); print_debug_hex8(bsp_apicid); print_debug("\r\n");
171
172 #if CONFIG_MEM_TRAIN_SEQ == 1
173         set_sysinfo_in_ram(0); // in BSP so could hold all ap until sysinfo is in ram 
174 #endif
175         setup_coherent_ht_domain(); // routing table and start other core0
176
177         wait_all_core0_started();
178 #if CONFIG_LOGICAL_CPUS==1
179         // It is said that we should start core1 after all core0 launched
180         /* becase optimize_link_coherent_ht is moved out from setup_coherent_ht_domain, 
181          * So here need to make sure last core0 is started, esp for two way system,
182          * (there may be apic id conflicts in that case) 
183          */
184         start_other_cores();
185         wait_all_other_cores_started(bsp_apicid);
186 #endif
187         
188         /* it will set up chains and store link pair for optimization later */
189         ht_setup_chains_x(sysinfo); // it will init sblnk and sbbusn, nodes, sbdn
190
191 #if K8_SET_FIDVID == 1
192
193         {
194                 msr_t msr;
195                 msr=rdmsr(0xc0010042);
196                 print_debug("begin msr fid, vid "); print_debug_hex32( msr.hi ); print_debug_hex32(msr.lo); print_debug("\r\n");
197
198         }
199
200         enable_fid_change();
201
202         enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
203
204         init_fidvid_bsp(bsp_apicid);
205
206         // show final fid and vid
207         {
208                 msr_t msr;
209                 msr=rdmsr(0xc0010042);
210                 print_debug("end   msr fid, vid "); print_debug_hex32( msr.hi ); print_debug_hex32(msr.lo); print_debug("\r\n"); 
211
212         }
213 #endif
214
215         needs_reset = optimize_link_coherent_ht();
216         needs_reset |= optimize_link_incoherent_ht(sysinfo);
217
218         // fidvid change will issue one LDTSTOP and the HT change will be effective too
219         if (needs_reset) {
220                 print_info("ht reset -\r\n");
221                 soft_reset_x(sysinfo->sbbusn, sysinfo->sbdn);
222         }
223
224         allow_all_aps_stop(bsp_apicid);
225
226         //It's the time to set ctrl in sysinfo now;
227         fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
228
229         enable_smbus();
230
231 #if 0
232         dump_smbus_registers();
233 #endif
234
235         memreset_setup();
236
237         //do we need apci timer, tsc...., only debug need it for better output
238         /* all ap stopped? */
239         init_timer(); // Need to use TMICT to synconize FID/VID
240         sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
241
242 #if 0
243         dump_pci_devices();
244 #endif
245
246         post_cache_as_ram(); // bsp swtich stack to ram and copy sysinfo ram now
247
248 }
249