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