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