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