Please bear with me - another rename checkin. This qualifies as trivial, no
[coreboot.git] / src / mainboard / asus / a8v-e_se / cache_as_ram_auto.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2006 AMD
5  * Written by Yinghai Lu <yinghailu@amd.com> for AMD.
6  * Copyright (C) 2006 MSI
7  * Written by Bingxun Shi <bingxunshi@gmail.com> for MSI.
8  *
9  * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz> 
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
24  */
25
26 #define ASSEMBLY 1
27 #define __ROMCC__
28
29 #define RAMINIT_SYSINFO 1
30
31 #define CACHE_AS_RAM_ADDRESS_DEBUG 0
32
33 unsigned int get_sbdn(unsigned bus);
34
35 //used by raminit
36 #define QRANK_DIMM_SUPPORT 1
37
38 //used by init_cpus and fidvid
39 #define K8_SET_FIDVID 1
40 //if we want to wait for core1 done before DQS training, set it to 0
41 #define K8_SET_FIDVID_CORE0_ONLY 1
42
43 //#define DEBUG_SMBUS 1
44
45 #include <stdint.h>
46 #include <device/pci_def.h>
47 #include <arch/io.h>
48 #include <device/pnp_def.h>
49 #include <arch/romcc_io.h>
50 #include <cpu/x86/lapic.h>
51 #include "option_table.h"
52 #include "pc80/mc146818rtc_early.c"
53
54 #include "pc80/serial.c"
55 #include "arch/i386/lib/console.c"
56
57 #include <cpu/amd/model_fxx_rev.h>
58 #include "northbridge/amd/amdk8/raminit.h"
59 #include "cpu/amd/model_fxx/apic_timer.c"
60 #include "lib/delay.c"
61
62 #if CONFIG_USE_INIT == 0
63 #include "lib/memcpy.c"
64 #endif
65
66 #include "cpu/x86/lapic/boot_cpu.c"
67 #include "northbridge/amd/amdk8/reset_test.c"
68 #include "northbridge/amd/amdk8/debug.c"
69 #include "northbridge/amd/amdk8/early_ht.c"
70
71
72 #include "superio/winbond/w83627ehg/w83627ehg_early_serial.c"
73 #include "southbridge/via/vt8237r/vt8237r_early_smbus.c"
74
75 #include "cpu/amd/mtrr/amd_earlymtrr.c"
76 #include "cpu/x86/bist.h"
77
78 #include "northbridge/amd/amdk8/setup_resource_map.c"
79
80 #define SERIAL_DEV PNP_DEV(0x2e, W83627EHG_SP1)
81 #define GPIO_DEV PNP_DEV(0x2e, W83627EHG_GPIO_SUSLED)
82 #define ACPI_DEV PNP_DEV(0x2e, W83627EHG_ACPI)
83 #define RTC_DEV PNP_DEV(0x2e, W83627EHG_RTC)
84
85 static void memreset_setup(void)
86 {
87 }
88
89 static void memreset(int controllers, const struct mem_controller *ctrl)
90 {
91 }
92
93
94 static inline int spd_read_byte(unsigned device, unsigned address)
95 {
96         return smbus_read_byte(device, address);
97 }
98
99 #define K8_4RANK_DIMM_SUPPORT 1
100
101 #include "northbridge/amd/amdk8/amdk8.h"
102 #include "northbridge/amd/amdk8/raminit.c"
103 #include "northbridge/amd/amdk8/coherent_ht.c"
104 #include "northbridge/amd/amdk8/incoherent_ht.c"
105 #include "sdram/generic_sdram.c"
106
107 #include "cpu/amd/dualcore/dualcore.c"
108
109 #include "southbridge/via/k8t890/k8t890_early_car.c"
110
111 #include "cpu/amd/car/copy_and_run.c"
112
113 #include "cpu/amd/car/post_cache_as_ram.c"
114
115 #include "cpu/amd/model_fxx/init_cpus.c"
116 #include "cpu/amd/model_fxx/fidvid.c"
117
118 #include "northbridge/amd/amdk8/resourcemap.c"
119
120
121 void activate_spd_rom(const struct mem_controller *ctrl)
122 {
123
124 }
125
126 void hard_reset(void)
127 {
128         print_info("NO HARD RESET  FIX ME!\n");
129 }
130
131 void soft_reset(void)
132 {
133         uint8_t tmp;
134         set_bios_reset();
135         print_debug("soft reset \r\n");
136
137         /* PCI reset */
138         tmp = pci_read_config8(PCI_DEV(0, 0x11, 0), 0x4f);
139         tmp |= 0x01;
140         pci_write_config8(PCI_DEV(0, 0x11, 0), 0x4f, tmp);
141
142         while (1) {
143                 /* daisy daisy ... */
144                 hlt();
145         }
146 }
147
148 unsigned int get_sbdn(unsigned bus)
149 {
150         device_t dev;
151
152         dev = pci_locate_device_on_bus(PCI_ID(PCI_VENDOR_ID_VIA,
153                                         PCI_DEVICE_ID_VIA_VT8237R_LPC), bus);
154         return (dev >> 15) & 0x1f;
155 }
156
157
158 void sio_init(void) {
159         u8 reg;
160
161         pnp_enter_ext_func_mode(SERIAL_DEV);
162         reg = pnp_read_config(SERIAL_DEV, 0x24);
163         pnp_write_config(SERIAL_DEV, 0x24, (reg & ~0x40));      /* we have 24MHz input */
164
165         reg = pnp_read_config(SERIAL_DEV, 0x2A);
166         pnp_write_config(SERIAL_DEV, 0x2A, (reg | 1));  /* we have GPIO for KB/MS PIN */
167
168         reg = pnp_read_config(SERIAL_DEV, 0x2C);
169         pnp_write_config(SERIAL_DEV, 0x2C, (reg | 0xf0));       /* we have all RESTOUT and even some reserved bits too */
170
171         pnp_exit_ext_func_mode(SERIAL_DEV);
172
173         pnp_enter_ext_func_mode(ACPI_DEV);
174         pnp_set_logical_device(ACPI_DEV);
175         reg = pnp_read_config(ACPI_DEV, 0xe6);
176         /* Set the delay rising time from PWROK_LP to PWROK_ST to 300 - 600ms, and 0 to vice versa */ 
177         pnp_write_config(ACPI_DEV, 0xe6, (reg & 0xf0));
178         /* 1 Use external suspend clock source 32.768KHz. Undocumented?? */
179         reg = pnp_read_config(ACPI_DEV, 0xe4);
180         pnp_write_config(ACPI_DEV, 0xe4, (reg | 0x10));
181         pnp_exit_ext_func_mode(ACPI_DEV);
182
183         pnp_enter_ext_func_mode(GPIO_DEV);
184         pnp_set_logical_device(GPIO_DEV);
185         pnp_exit_ext_func_mode(GPIO_DEV);
186
187         /* set memory voltage to 2.75V, vcore offset + 100mV, 1.5V Chipset voltage */
188         pnp_write_config(GPIO_DEV, 0xe0, 0xde); /* 1101110  0=output 1=input */
189         pnp_write_config(GPIO_DEV, 0xe1, 0x1);  /* set output val */
190         pnp_write_config(GPIO_DEV, 0xe2, 0x0);  /* no inversion */
191         pnp_write_config(GPIO_DEV, 0xe3, 0x3);  /* 0000 0011 0=output 1=input */
192         pnp_write_config(GPIO_DEV, 0xe4, 0xa4); /* set output val  1010 0100 */
193         pnp_write_config(GPIO_DEV, 0xe5, 0x0);  /* no inversion */
194         pnp_write_config(GPIO_DEV, 0x30, 0x9);  /* Enable GPIO 2 & GPIO 5 */
195         pnp_exit_ext_func_mode(GPIO_DEV);
196 }
197
198 #if USE_FALLBACK_IMAGE == 1
199
200 void failover_process(unsigned long bist, unsigned long cpu_init_detectedx)
201 {
202 //        unsigned last_boot_normal_x = last_boot_normal();
203 //FIXME
204         unsigned last_boot_normal_x = 1;
205
206         sio_init();
207         w83627ehg_enable_serial(SERIAL_DEV, TTYS0_BASE);
208         uart_init();
209         console_init();
210
211         print_info("now booting... fallback\r\n");
212
213         /* Is this a cpu only reset? or Is this a secondary cpu? */
214         if ((cpu_init_detectedx) || (!boot_cpu())) {
215                 if (last_boot_normal_x) {
216                         goto normal_image;
217                 } else {
218                         goto fallback_image;
219                 }
220         }
221
222         /* Nothing special needs to be done to find bus 0 */
223         /* Allow the HT devices to be found */
224
225         enumerate_ht_chain();
226
227         /* Is this a deliberate reset by the bios */
228         if (bios_reset_detected() && last_boot_normal_x) {
229                 goto normal_image;
230         }
231         /* This is the primary cpu how should I boot? */
232         else if (do_normal_boot()) {
233                 goto normal_image;
234         } else {
235                 goto fallback_image;
236         }
237       normal_image:
238         //print_info("JMP normal image\r\n");
239
240         __asm__ volatile ("jmp __normal_image": /* outputs */
241                           :"a" (bist), "b"(cpu_init_detectedx)  /* inputs */
242             );
243
244       fallback_image:
245         ;
246 }
247 #endif
248
249 void real_main(unsigned long bist, unsigned long cpu_init_detectedx);
250
251 void cache_as_ram_main(unsigned long bist,
252                        unsigned long cpu_init_detectedx)
253 {
254
255 #if USE_FALLBACK_IMAGE == 1
256         failover_process(bist, cpu_init_detectedx);
257 #endif
258         real_main(bist, cpu_init_detectedx);
259
260 }
261
262
263 void real_main(unsigned long bist, unsigned long cpu_init_detectedx)
264 {
265         static const uint16_t spd_addr[] = {
266                 (0xa << 3) | 0, (0xa << 3) | 2, 0, 0,
267                 (0xa << 3) | 1, (0xa << 3) | 3, 0, 0,
268 #if CONFIG_MAX_PHYSICAL_CPUS > 1
269                 (0xa << 3) | 4, (0xa << 3) | 6, 0, 0,
270                 (0xa << 3) | 5, (0xa << 3) | 7, 0, 0,
271 #endif
272         };
273         unsigned bsp_apicid = 0;
274         int needs_reset = 0;
275         struct sys_info *sysinfo =
276             (DCACHE_RAM_BASE + DCACHE_RAM_SIZE -
277              DCACHE_RAM_GLOBAL_VAR_SIZE);
278         char *p;
279
280         sio_init();
281         w83627ehg_enable_serial(SERIAL_DEV, TTYS0_BASE);
282         uart_init();
283         console_init();
284
285         print_info("now booting... real_main\r\n");
286
287         if (bist == 0) {
288                 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
289         }
290         /* Halt if there was a built in self test failure */
291         report_bist_failure(bist);
292         setup_default_resource_map();
293         setup_coherent_ht_domain();
294         wait_all_core0_started();
295         print_info("now booting... Core0 started\r\n");
296
297 #if CONFIG_LOGICAL_CPUS==1
298         // It is said that we should start core1 after all core0 launched
299         start_other_cores();
300         wait_all_other_cores_started(bsp_apicid);
301 #endif
302         init_timer();
303         ht_setup_chains_x(sysinfo);     // it will init sblnk and sbbusn, nodes, sbdn
304
305         enable_fid_change();
306         init_fidvid_bsp(bsp_apicid);
307
308         needs_reset = optimize_link_coherent_ht();
309         needs_reset |= optimize_link_incoherent_ht(sysinfo);
310
311         /* Fixme it assumes that 1000MHz LDT is selected. */
312         needs_reset |= k8t890_early_setup_car(16, 0x6);
313
314         if (needs_reset) {
315                 print_debug("ht reset -\r\n");
316                 soft_reset();
317         }
318         /* stop the APs so we can start them later in init */
319         allow_all_aps_stop(bsp_apicid);
320         /* It's the time to set ctrl now; */
321         fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
322         enable_smbus();
323         memreset_setup();
324         sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
325         post_cache_as_ram();
326 }
327