3ec90f80107dc2ad8741eb4559a6c2c476dc9437
[coreboot.git] / src / mainboard / asus / a8v-e_se / romstage.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  * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz> 
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
23  */
24
25 #define RAMINIT_SYSINFO 1
26
27 #define CACHE_AS_RAM_ADDRESS_DEBUG 0
28
29 unsigned int get_sbdn(unsigned bus);
30
31 /* Used by raminit. */
32 #define QRANK_DIMM_SUPPORT 1
33
34 /* Used by init_cpus and fidvid */
35 #define SET_FIDVID 1
36
37 /* If we want to wait for core1 done before DQS training, set it to 0. */
38 #define SET_FIDVID_CORE0_ONLY 1
39
40 #include <stdint.h>
41 #include <string.h>
42 #include <device/pci_def.h>
43 #include <arch/io.h>
44 #include <device/pnp_def.h>
45 #include <arch/romcc_io.h>
46 #include <cpu/x86/lapic.h>
47 #include "option_table.h"
48 #include "pc80/mc146818rtc_early.c"
49 #include "pc80/serial.c"
50 #include "console/console.c"
51 #include <cpu/amd/model_fxx_rev.h>
52 #include "northbridge/amd/amdk8/raminit.h"
53 #include "cpu/amd/model_fxx/apic_timer.c"
54 #include "lib/delay.c"
55 #include "cpu/x86/lapic/boot_cpu.c"
56 #include "northbridge/amd/amdk8/reset_test.c"
57 #include "northbridge/amd/amdk8/early_ht.c"
58 #include "superio/winbond/w83627ehg/w83627ehg_early_serial.c"
59 #include "southbridge/via/vt8237r/vt8237r_early_smbus.c"
60 #include "northbridge/amd/amdk8/debug.c" /* After vt8237r_early_smbus.c! */
61 #include "cpu/x86/mtrr/earlymtrr.c"
62 #include "cpu/x86/bist.h"
63 #include "northbridge/amd/amdk8/setup_resource_map.c"
64
65 #define SERIAL_DEV PNP_DEV(0x2e, W83627EHG_SP1)
66 #define GPIO_DEV PNP_DEV(0x2e, W83627EHG_GPIO_SUSLED)
67 #define ACPI_DEV PNP_DEV(0x2e, W83627EHG_ACPI)
68 #define RTC_DEV PNP_DEV(0x2e, W83627EHG_RTC)
69
70 static void memreset(int controllers, const struct mem_controller *ctrl)
71 {
72 }
73
74 static inline int spd_read_byte(unsigned device, unsigned address)
75 {
76         return smbus_read_byte(device, address);
77 }
78
79 static void activate_spd_rom(const struct mem_controller *ctrl)
80 {
81 }
82
83 #include <reset.h>
84 void soft_reset(void)
85 {
86         uint8_t tmp;
87
88         set_bios_reset();
89         print_debug("soft reset \n");
90
91         /* PCI reset */
92         tmp = pci_read_config8(PCI_DEV(0, 0x11, 0), 0x4f);
93         tmp |= 0x01;
94         pci_write_config8(PCI_DEV(0, 0x11, 0), 0x4f, tmp);
95
96         while (1) {
97                 /* daisy daisy ... */
98                 hlt();
99         }
100 }
101
102 // defines S3_NVRAM_EARLY:
103 #include "southbridge/via/k8t890/k8t890_early_car.c"
104
105 #define K8_4RANK_DIMM_SUPPORT 1
106
107 #include "northbridge/amd/amdk8/amdk8.h"
108 #include "northbridge/amd/amdk8/incoherent_ht.c"
109 #include "northbridge/amd/amdk8/coherent_ht.c"
110 #include "northbridge/amd/amdk8/raminit.c"
111 #include "lib/generic_sdram.c"
112
113 #include "cpu/amd/dualcore/dualcore.c"
114
115 #include "cpu/amd/car/post_cache_as_ram.c"
116 #include "cpu/amd/model_fxx/init_cpus.c"
117 #include "cpu/amd/model_fxx/fidvid.c"
118 #include "northbridge/amd/amdk8/resourcemap.c"
119
120 unsigned int get_sbdn(unsigned bus)
121 {
122         device_t dev;
123
124         dev = pci_locate_device_on_bus(PCI_ID(PCI_VENDOR_ID_VIA,
125                                         PCI_DEVICE_ID_VIA_VT8237R_LPC), bus);
126         return (dev >> 15) & 0x1f;
127 }
128
129 static void sio_init(void)
130 {
131         u8 reg;
132
133         pnp_enter_ext_func_mode(SERIAL_DEV);
134         /* We have 24MHz input. */
135         reg = pnp_read_config(SERIAL_DEV, 0x24);
136         pnp_write_config(SERIAL_DEV, 0x24, (reg & ~0x40));
137         /* We have GPIO for KB/MS pin. */
138         reg = pnp_read_config(SERIAL_DEV, 0x2a);
139         pnp_write_config(SERIAL_DEV, 0x2a, (reg | 1));
140         /* We have all RESTOUT and even some reserved bits, too. */
141         reg = pnp_read_config(SERIAL_DEV, 0x2c);
142         pnp_write_config(SERIAL_DEV, 0x2c, (reg | 0xf0));
143         pnp_exit_ext_func_mode(SERIAL_DEV);
144
145         pnp_enter_ext_func_mode(ACPI_DEV);
146         pnp_set_logical_device(ACPI_DEV);
147         /*
148          * Set the delay rising time from PWROK_LP to PWROK_ST to
149          * 300 - 600ms, and 0 to vice versa.
150          */
151         reg = pnp_read_config(ACPI_DEV, 0xe6);
152         pnp_write_config(ACPI_DEV, 0xe6, (reg & 0xf0));
153         /* 1 Use external suspend clock source 32.768KHz. Undocumented?? */
154         reg = pnp_read_config(ACPI_DEV, 0xe4);
155         pnp_write_config(ACPI_DEV, 0xe4, (reg | 0x10));
156         pnp_exit_ext_func_mode(ACPI_DEV);
157
158         pnp_enter_ext_func_mode(GPIO_DEV);
159         pnp_set_logical_device(GPIO_DEV);
160         /* Set memory voltage to 2.75V, vcore offset + 100mV, 1.5V chipset voltage. */
161         pnp_write_config(GPIO_DEV, 0x30, 0x09); /* Enable GPIO 2 & GPIO 5. */
162         pnp_write_config(GPIO_DEV, 0xe2, 0x00); /* No inversion */
163         pnp_write_config(GPIO_DEV, 0xe5, 0x00); /* No inversion */
164         pnp_write_config(GPIO_DEV, 0xe3, 0x03); /* 0000 0011, 0=output 1=input */
165         pnp_write_config(GPIO_DEV, 0xe0, 0xde); /* 1101 1110, 0=output 1=input */
166         pnp_write_config(GPIO_DEV, 0xe1, 0x01); /* Set output val. */
167         pnp_write_config(GPIO_DEV, 0xe4, 0xb4); /* Set output val (1011 0100). */
168         pnp_exit_ext_func_mode(GPIO_DEV);
169 }
170
171 void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
172 {
173         static const uint16_t spd_addr[] = {
174                 // Node 0
175                 (0xa << 3) | 0, (0xa << 3) | 2, 0, 0,
176                 (0xa << 3) | 1, (0xa << 3) | 3, 0, 0,
177                 // Node 1
178                 (0xa << 3) | 4, (0xa << 3) | 6, 0, 0,
179                 (0xa << 3) | 5, (0xa << 3) | 7, 0, 0,
180         };
181         unsigned bsp_apicid = 0;
182         int needs_reset = 0;
183         struct sys_info *sysinfo = (struct sys_info *)(CONFIG_DCACHE_RAM_BASE 
184                 + CONFIG_DCACHE_RAM_SIZE - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);
185
186         sio_init();
187         w83627ehg_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
188         uart_init();
189         console_init();
190         enable_rom_decode();
191
192         print_info("now booting... fallback\n");
193
194         /* Is this a CPU only reset? Or is this a secondary CPU? */
195         if (!cpu_init_detectedx && boot_cpu()) {
196                 /* Nothing special needs to be done to find bus 0. */
197                 /* Allow the HT devices to be found. */
198                 enumerate_ht_chain();
199         }
200
201         sio_init();
202         w83627ehg_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
203         uart_init();
204         console_init();
205         enable_rom_decode();
206
207         print_info("now booting... real_main\n");
208
209         if (bist == 0)
210                 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
211
212         /* Halt if there was a built in self test failure. */
213         report_bist_failure(bist);
214
215         setup_default_resource_map();
216         setup_coherent_ht_domain();
217         wait_all_core0_started();
218
219         print_info("now booting... Core0 started\n");
220
221 #if CONFIG_LOGICAL_CPUS==1
222         /* It is said that we should start core1 after all core0 launched. */
223         start_other_cores();
224         wait_all_other_cores_started(bsp_apicid);
225 #endif
226         init_timer();
227         ht_setup_chains_x(sysinfo); /* Init sblnk and sbbusn, nodes, sbdn. */
228
229         needs_reset = optimize_link_coherent_ht();
230         needs_reset |= optimize_link_incoherent_ht(sysinfo);
231         needs_reset |= k8t890_early_setup_ht();
232
233         if (needs_reset) {
234                 print_debug("ht reset -\n");
235                 soft_reset();
236         }
237
238         /* the HT settings needs to be OK, because link freq chnage may cause HT disconnect */
239         enable_fid_change();
240         init_fidvid_bsp(bsp_apicid);
241
242         /* Stop the APs so we can start them later in init. */
243         allow_all_aps_stop(bsp_apicid);
244
245         /* It's the time to set ctrl now. */
246         fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
247
248         enable_smbus();
249         sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
250         post_cache_as_ram();
251 }
252