bafd6e9c9b49cae4a3a5ae9f7b99e9c7e42d2c08
[coreboot.git] / src / mainboard / tyan / s2892 / cache_as_ram_auto.c
1 #define ASSEMBLY 1
2 #define __ROMCC__
3
4 #include <stdint.h>
5 #include <string.h>
6 #include <device/pci_def.h>
7 #include <arch/io.h>
8 #include <device/pnp_def.h>
9 #include <arch/romcc_io.h>
10 #include <cpu/x86/lapic.h>
11 #include "option_table.h"
12 #include "pc80/mc146818rtc_early.c"
13 #include "pc80/serial.c"
14 #include "arch/i386/lib/console.c"
15 #include "ram/ramtest.c"
16
17 #include <cpu/amd/model_fxx_rev.h>
18
19 #include "northbridge/amd/amdk8/incoherent_ht.c"
20 #include "southbridge/nvidia/ck804/ck804_early_smbus.c"
21 #include "northbridge/amd/amdk8/raminit.h"
22 #include "cpu/amd/model_fxx/apic_timer.c"
23 #include "lib/delay.c"
24
25 #include "cpu/x86/lapic/boot_cpu.c"
26 #include "northbridge/amd/amdk8/reset_test.c"
27 #include "northbridge/amd/amdk8/debug.c"
28 #include "superio/winbond/w83627hf/w83627hf_early_serial.c"
29
30 #include "cpu/amd/mtrr/amd_earlymtrr.c"
31 #include "cpu/x86/bist.h"
32
33 #include "northbridge/amd/amdk8/setup_resource_map.c"
34
35 #define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
36
37 static void memreset_setup(void)
38 {
39 }
40
41 static void memreset(int controllers, const struct mem_controller *ctrl)
42 {
43 }
44
45 static inline void activate_spd_rom(const struct mem_controller *ctrl)
46 {
47         /* nothing to do */
48 }
49
50 static inline int spd_read_byte(unsigned device, unsigned address)
51 {
52         return smbus_read_byte(device, address);
53 }
54
55 #define QRANK_DIMM_SUPPORT 1
56
57 #include "northbridge/amd/amdk8/raminit.c"
58 #include "northbridge/amd/amdk8/coherent_ht.c"
59 #include "sdram/generic_sdram.c"
60
61  /* tyan does not want the default */
62 #include "resourcemap.c"
63
64 #if CONFIG_LOGICAL_CPUS==1
65 #define SET_NB_CFG_54 1
66 #endif
67 #include "cpu/amd/dualcore/dualcore.c"
68
69 #define CK804_NUM 1
70 #include "southbridge/nvidia/ck804/ck804_early_setup_ss.h"
71 //set GPIO to input mode
72 #define CK804_MB_SETUP \
73                 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+15, ~(0xff), ((0<<4)|(0<<2)|(0<<0)),/* M8,GPIO16, PCIXA_PRSNT2_L*/ \
74                 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+44, ~(0xff), ((0<<4)|(0<<2)|(0<<0)),/* P5,GPIO45, PCIXA_PRSNT1_L*/ \
75                 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+16, ~(0xff), ((0<<4)|(0<<2)|(0<<0)),/* K4,GPIO17, PCIXB_PRSNT1_L*/ \
76                 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+45, ~(0xff), ((0<<4)|(0<<2)|(0<<0)),/* P7,GPIO46, PCIXB_PRSNT2_L*/ \
77
78 #include "southbridge/nvidia/ck804/ck804_early_setup.c"
79
80 #include "cpu/amd/car/copy_and_run.c"
81
82 #include "cpu/amd/car/post_cache_as_ram.c"
83
84 #include "cpu/amd/model_fxx/init_cpus.c"
85
86 #if USE_FALLBACK_IMAGE == 1
87
88 #include "southbridge/nvidia/ck804/ck804_enable_rom.c"
89 #include "northbridge/amd/amdk8/early_ht.c"
90
91 static void sio_setup(void)
92 {
93         uint32_t dword;
94         uint8_t byte;
95
96         byte = pci_read_config8(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0x7b);
97         byte |= 0x20;
98         pci_write_config8(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0x7b, byte);
99
100         dword = pci_read_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0xa0);
101         dword |= (1<<0);
102         pci_write_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0xa0, dword);
103 }
104
105 void failover_process(unsigned long bist, unsigned long cpu_init_detectedx)
106 {
107         unsigned last_boot_normal_x = last_boot_normal();
108
109         /* Is this a cpu only reset? or Is this a secondary cpu? */
110         if ((cpu_init_detectedx) || (!boot_cpu())) {
111         if (last_boot_normal_x) {
112         goto normal_image;
113         } else {
114         goto fallback_image;
115         }
116         }
117
118         /* Nothing special needs to be done to find bus 0 */
119         /* Allow the HT devices to be found */
120
121         enumerate_ht_chain();
122
123         sio_setup();
124
125         /* Setup the ck804 */
126         ck804_enable_rom();
127
128         /* Is this a deliberate reset by the bios */
129 //      post_code(0x22);
130         if (bios_reset_detected() && last_boot_normal_x) {
131         goto normal_image;
132         }
133         /* This is the primary cpu how should I boot? */
134         else if (do_normal_boot()) {
135         goto normal_image;
136         }
137         else {
138         goto fallback_image;
139         }
140  normal_image:
141 //      post_code(0x23);
142         __asm__ volatile ("jmp __normal_image"
143         : /* outputs */
144         : "a" (bist), "b"(cpu_init_detectedx) /* inputs */
145         );
146
147  fallback_image:
148 //      post_code(0x25);
149         ;
150 }
151 #endif
152
153 void real_main(unsigned long bist, unsigned long cpu_init_detectedx);
154
155 void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
156 {
157
158 #if USE_FALLBACK_IMAGE == 1
159                 failover_process(bist, cpu_init_detectedx);
160 #endif
161         real_main(bist, cpu_init_detectedx);
162
163 }
164
165 void real_main(unsigned long bist, unsigned long cpu_init_detectedx)
166 {
167         static const uint16_t spd_addr [] = {
168                 (0xa<<3)|0, (0xa<<3)|2, 0, 0,
169                 (0xa<<3)|1, (0xa<<3)|3, 0, 0,
170 #if CONFIG_MAX_PHYSICAL_CPUS > 1
171                 (0xa<<3)|4, (0xa<<3)|6, 0, 0,
172                 (0xa<<3)|5, (0xa<<3)|7, 0, 0,
173 #endif
174         };
175
176         int needs_reset;
177         unsigned bsp_apicid = 0;
178
179         struct mem_controller ctrl[8];
180         unsigned nodes;
181
182         if (bist == 0) {
183                 init_cpus(cpu_init_detectedx);
184         }
185
186 //      post_code(0x32);
187
188         w83627hf_enable_serial(SERIAL_DEV, TTYS0_BASE);
189         uart_init();
190         console_init();
191
192         /* Halt if there was a built in self test failure */
193         report_bist_failure(bist);
194
195         setup_s2892_resource_map();
196 #if 0
197         dump_pci_device(PCI_DEV(0, 0x18, 0));
198         dump_pci_device(PCI_DEV(0, 0x19, 0));
199 #endif
200
201         needs_reset = setup_coherent_ht_domain();
202
203         wait_all_core0_started();
204 #if CONFIG_LOGICAL_CPUS==1
205         // It is said that we should start core1 after all core0 launched
206         start_other_cores();
207         wait_all_other_cores_started(bsp_apicid);
208 #endif
209
210         needs_reset |= ht_setup_chains_x();
211
212         needs_reset |= ck804_early_setup_x();
213
214         if (needs_reset) {
215                 print_info("ht reset -\r\n");
216                 soft_reset();
217         }
218
219         allow_all_aps_stop(bsp_apicid);
220
221         nodes = get_nodes();
222         //It's the time to set ctrl now;
223         fill_mem_ctrl(nodes, ctrl, spd_addr);
224
225         enable_smbus();
226 #if 0
227         dump_spd_registers(&cpu[0]);
228 #endif
229 #if 0
230         dump_smbus_registers();
231 #endif
232
233         memreset_setup();
234         sdram_initialize(nodes, ctrl);
235
236 #if 0
237         print_pci_devices();
238 #endif
239
240 #if 0
241         dump_pci_devices();
242 #endif
243
244         post_cache_as_ram();
245 }