blob: b6c3c3f6860c50dcf2bc21980a901b00c8a9d675 [file] [log] [blame]
Rudolf Marek1a002562007-11-02 23:17:57 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Rudolf Marek1a002562007-11-02 23:17:57 +00003 *
4 * Copyright (C) 2006 AMD
Uwe Hermannc4f53652008-03-08 19:14:42 +00005 * (Written by Yinghai Lu <yinghailu@amd.com> for AMD)
Rudolf Marek1a002562007-11-02 23:17:57 +00006 * Copyright (C) 2006 MSI
Uwe Hermannc4f53652008-03-08 19:14:42 +00007 * (Written by Bingxun Shi <bingxunshi@gmail.com> for MSI)
Rudolf Marek1a002562007-11-02 23:17:57 +00008 * 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 ASSEMBLY 1
Myles Watson1d6d45e2009-11-06 17:02:51 +000026#define __PRE_RAM__
Rudolf Marek1a002562007-11-02 23:17:57 +000027
28#define RAMINIT_SYSINFO 1
29
30#define CACHE_AS_RAM_ADDRESS_DEBUG 0
31
32unsigned int get_sbdn(unsigned bus);
33
Uwe Hermannc4f53652008-03-08 19:14:42 +000034/* Used by raminit. */
Rudolf Marek1a002562007-11-02 23:17:57 +000035#define QRANK_DIMM_SUPPORT 1
36
Uwe Hermannc4f53652008-03-08 19:14:42 +000037/* Used by init_cpus and fidvid */
Rudolf Marek1a002562007-11-02 23:17:57 +000038#define K8_SET_FIDVID 1
Uwe Hermannc4f53652008-03-08 19:14:42 +000039
40/* If we want to wait for core1 done before DQS training, set it to 0. */
Rudolf Marek1a002562007-11-02 23:17:57 +000041#define K8_SET_FIDVID_CORE0_ONLY 1
42
Rudolf Marek1a002562007-11-02 23:17:57 +000043#include <stdint.h>
Patrick Georgi12aba822009-04-30 07:07:22 +000044#include <string.h>
Rudolf Marek1a002562007-11-02 23:17:57 +000045#include <device/pci_def.h>
46#include <arch/io.h>
47#include <device/pnp_def.h>
48#include <arch/romcc_io.h>
49#include <cpu/x86/lapic.h>
50#include "option_table.h"
51#include "pc80/mc146818rtc_early.c"
Rudolf Marek1a002562007-11-02 23:17:57 +000052#include "pc80/serial.c"
53#include "arch/i386/lib/console.c"
Rudolf Marek1a002562007-11-02 23:17:57 +000054#include <cpu/amd/model_fxx_rev.h>
55#include "northbridge/amd/amdk8/raminit.h"
56#include "cpu/amd/model_fxx/apic_timer.c"
57#include "lib/delay.c"
Rudolf Marek1a002562007-11-02 23:17:57 +000058#include "cpu/x86/lapic/boot_cpu.c"
59#include "northbridge/amd/amdk8/reset_test.c"
Rudolf Marek1a002562007-11-02 23:17:57 +000060#include "northbridge/amd/amdk8/early_ht.c"
Rudolf Marek1a002562007-11-02 23:17:57 +000061#include "superio/winbond/w83627ehg/w83627ehg_early_serial.c"
62#include "southbridge/via/vt8237r/vt8237r_early_smbus.c"
Uwe Hermann01ce6012010-03-05 10:03:50 +000063#include "northbridge/amd/amdk8/debug.c" /* After vt8237r_early_smbus.c! */
Rudolf Marek1a002562007-11-02 23:17:57 +000064#include "cpu/amd/mtrr/amd_earlymtrr.c"
65#include "cpu/x86/bist.h"
Rudolf Marek1a002562007-11-02 23:17:57 +000066#include "northbridge/amd/amdk8/setup_resource_map.c"
67
68#define SERIAL_DEV PNP_DEV(0x2e, W83627EHG_SP1)
69#define GPIO_DEV PNP_DEV(0x2e, W83627EHG_GPIO_SUSLED)
Rudolf Marek6211ae12008-01-12 22:29:17 +000070#define ACPI_DEV PNP_DEV(0x2e, W83627EHG_ACPI)
Rudolf Marek1a002562007-11-02 23:17:57 +000071#define RTC_DEV PNP_DEV(0x2e, W83627EHG_RTC)
72
73static void memreset_setup(void)
74{
75}
76
77static void memreset(int controllers, const struct mem_controller *ctrl)
78{
79}
80
Rudolf Marek1a002562007-11-02 23:17:57 +000081static inline int spd_read_byte(unsigned device, unsigned address)
82{
83 return smbus_read_byte(device, address);
84}
85
Rudolf Marek1a002562007-11-02 23:17:57 +000086void activate_spd_rom(const struct mem_controller *ctrl)
87{
Rudolf Marek1a002562007-11-02 23:17:57 +000088}
89
Rudolf Marek1a002562007-11-02 23:17:57 +000090void soft_reset(void)
91{
92 uint8_t tmp;
Uwe Hermannc4f53652008-03-08 19:14:42 +000093
Rudolf Marek1a002562007-11-02 23:17:57 +000094 set_bios_reset();
95 print_debug("soft reset \r\n");
96
97 /* PCI reset */
98 tmp = pci_read_config8(PCI_DEV(0, 0x11, 0), 0x4f);
99 tmp |= 0x01;
100 pci_write_config8(PCI_DEV(0, 0x11, 0), 0x4f, tmp);
101
102 while (1) {
103 /* daisy daisy ... */
104 hlt();
105 }
106}
107
Carl-Daniel Hailfinger3f04dad2009-04-13 16:21:16 +0000108#define K8_4RANK_DIMM_SUPPORT 1
109
110#include "northbridge/amd/amdk8/amdk8.h"
111#include "northbridge/amd/amdk8/raminit.c"
112#include "northbridge/amd/amdk8/coherent_ht.c"
113#include "northbridge/amd/amdk8/incoherent_ht.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +0000114#include "lib/generic_sdram.c"
Carl-Daniel Hailfinger3f04dad2009-04-13 16:21:16 +0000115#include "cpu/amd/dualcore/dualcore.c"
116#include "southbridge/via/k8t890/k8t890_early_car.c"
117#include "cpu/amd/car/copy_and_run.c"
118#include "cpu/amd/car/post_cache_as_ram.c"
119#include "cpu/amd/model_fxx/init_cpus.c"
120#include "cpu/amd/model_fxx/fidvid.c"
121#include "northbridge/amd/amdk8/resourcemap.c"
122
123void hard_reset(void)
124{
125 print_info("NO HARD RESET. FIX ME!\n");
126}
127
Rudolf Marek1a002562007-11-02 23:17:57 +0000128unsigned int get_sbdn(unsigned bus)
129{
130 device_t dev;
131
132 dev = pci_locate_device_on_bus(PCI_ID(PCI_VENDOR_ID_VIA,
133 PCI_DEVICE_ID_VIA_VT8237R_LPC), bus);
134 return (dev >> 15) & 0x1f;
135}
136
Uwe Hermannc4f53652008-03-08 19:14:42 +0000137void sio_init(void)
138{
Rudolf Marek1a002562007-11-02 23:17:57 +0000139 u8 reg;
140
141 pnp_enter_ext_func_mode(SERIAL_DEV);
Uwe Hermannc4f53652008-03-08 19:14:42 +0000142 /* We have 24MHz input. */
Rudolf Marek1a002562007-11-02 23:17:57 +0000143 reg = pnp_read_config(SERIAL_DEV, 0x24);
Uwe Hermannc4f53652008-03-08 19:14:42 +0000144 pnp_write_config(SERIAL_DEV, 0x24, (reg & ~0x40));
145 /* We have GPIO for KB/MS pin. */
146 reg = pnp_read_config(SERIAL_DEV, 0x2a);
147 pnp_write_config(SERIAL_DEV, 0x2a, (reg | 1));
148 /* We have all RESTOUT and even some reserved bits, too. */
149 reg = pnp_read_config(SERIAL_DEV, 0x2c);
150 pnp_write_config(SERIAL_DEV, 0x2c, (reg | 0xf0));
Rudolf Marek1a002562007-11-02 23:17:57 +0000151 pnp_exit_ext_func_mode(SERIAL_DEV);
152
Rudolf Marek6211ae12008-01-12 22:29:17 +0000153 pnp_enter_ext_func_mode(ACPI_DEV);
154 pnp_set_logical_device(ACPI_DEV);
Uwe Hermannc4f53652008-03-08 19:14:42 +0000155 /*
156 * Set the delay rising time from PWROK_LP to PWROK_ST to
157 * 300 - 600ms, and 0 to vice versa.
158 */
Rudolf Marek6211ae12008-01-12 22:29:17 +0000159 reg = pnp_read_config(ACPI_DEV, 0xe6);
Rudolf Marek6211ae12008-01-12 22:29:17 +0000160 pnp_write_config(ACPI_DEV, 0xe6, (reg & 0xf0));
161 /* 1 Use external suspend clock source 32.768KHz. Undocumented?? */
162 reg = pnp_read_config(ACPI_DEV, 0xe4);
163 pnp_write_config(ACPI_DEV, 0xe4, (reg | 0x10));
164 pnp_exit_ext_func_mode(ACPI_DEV);
165
Rudolf Marek1a002562007-11-02 23:17:57 +0000166 pnp_enter_ext_func_mode(GPIO_DEV);
167 pnp_set_logical_device(GPIO_DEV);
Uwe Hermannc4f53652008-03-08 19:14:42 +0000168 /* Set memory voltage to 2.75V, vcore offset + 100mV, 1.5V chipset voltage. */
169 pnp_write_config(GPIO_DEV, 0x30, 0x09); /* Enable GPIO 2 & GPIO 5. */
170 pnp_write_config(GPIO_DEV, 0xe2, 0x00); /* No inversion */
171 pnp_write_config(GPIO_DEV, 0xe5, 0x00); /* No inversion */
172 pnp_write_config(GPIO_DEV, 0xe3, 0x03); /* 0000 0011, 0=output 1=input */
173 pnp_write_config(GPIO_DEV, 0xe0, 0xde); /* 1101 1110, 0=output 1=input */
174 pnp_write_config(GPIO_DEV, 0xe1, 0x01); /* Set output val. */
175 pnp_write_config(GPIO_DEV, 0xe4, 0xb4); /* Set output val (1011 0100). */
Rudolf Marek6211ae12008-01-12 22:29:17 +0000176 pnp_exit_ext_func_mode(GPIO_DEV);
177}
Rudolf Marek1a002562007-11-02 23:17:57 +0000178
Stefan Reinauer08670622009-06-30 15:17:49 +0000179#if CONFIG_USE_FALLBACK_IMAGE == 1
Rudolf Marek6211ae12008-01-12 22:29:17 +0000180
181void failover_process(unsigned long bist, unsigned long cpu_init_detectedx)
182{
Uwe Hermannc4f53652008-03-08 19:14:42 +0000183 /* unsigned last_boot_normal_x = last_boot_normal(); */
184 /* FIXME */
Rudolf Marek6211ae12008-01-12 22:29:17 +0000185 unsigned last_boot_normal_x = 1;
186
187 sio_init();
Stefan Reinauer08670622009-06-30 15:17:49 +0000188 w83627ehg_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Rudolf Marek1a002562007-11-02 23:17:57 +0000189 uart_init();
190 console_init();
Rudolf Marek56717872008-03-15 00:26:50 +0000191 enable_rom_decode();
Rudolf Marek1a002562007-11-02 23:17:57 +0000192
193 print_info("now booting... fallback\r\n");
194
Uwe Hermannc4f53652008-03-08 19:14:42 +0000195 /* Is this a CPU only reset? Or is this a secondary CPU? */
Rudolf Marek1a002562007-11-02 23:17:57 +0000196 if ((cpu_init_detectedx) || (!boot_cpu())) {
Uwe Hermannc4f53652008-03-08 19:14:42 +0000197 if (last_boot_normal_x)
Rudolf Marek1a002562007-11-02 23:17:57 +0000198 goto normal_image;
Uwe Hermannc4f53652008-03-08 19:14:42 +0000199 else
Rudolf Marek1a002562007-11-02 23:17:57 +0000200 goto fallback_image;
Rudolf Marek1a002562007-11-02 23:17:57 +0000201 }
202
Uwe Hermannc4f53652008-03-08 19:14:42 +0000203 /* Nothing special needs to be done to find bus 0. */
204 /* Allow the HT devices to be found. */
Rudolf Marek1a002562007-11-02 23:17:57 +0000205 enumerate_ht_chain();
206
Uwe Hermannc4f53652008-03-08 19:14:42 +0000207 /* Is this a deliberate reset by the BIOS? */
Rudolf Marek1a002562007-11-02 23:17:57 +0000208 if (bios_reset_detected() && last_boot_normal_x) {
209 goto normal_image;
210 }
Uwe Hermannc4f53652008-03-08 19:14:42 +0000211 /* This is the primary CPU, how should I boot? */
Rudolf Marek1a002562007-11-02 23:17:57 +0000212 else if (do_normal_boot()) {
213 goto normal_image;
214 } else {
215 goto fallback_image;
216 }
Rudolf Marek1a002562007-11-02 23:17:57 +0000217
Uwe Hermannc4f53652008-03-08 19:14:42 +0000218normal_image:
219 /* print_info("JMP normal image\r\n"); */
Rudolf Marek1a002562007-11-02 23:17:57 +0000220
Uwe Hermannc4f53652008-03-08 19:14:42 +0000221 __asm__ __volatile__("jmp __normal_image":
222 :"a" (bist), "b" (cpu_init_detectedx));
223
224fallback_image:
Rudolf Marek1a002562007-11-02 23:17:57 +0000225 ;
226}
227#endif
228
229void real_main(unsigned long bist, unsigned long cpu_init_detectedx);
230
Uwe Hermannc4f53652008-03-08 19:14:42 +0000231void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
Rudolf Marek1a002562007-11-02 23:17:57 +0000232{
Stefan Reinauer08670622009-06-30 15:17:49 +0000233#if CONFIG_USE_FALLBACK_IMAGE == 1
Rudolf Marek1a002562007-11-02 23:17:57 +0000234 failover_process(bist, cpu_init_detectedx);
235#endif
236 real_main(bist, cpu_init_detectedx);
Rudolf Marek1a002562007-11-02 23:17:57 +0000237}
238
Rudolf Marek1a002562007-11-02 23:17:57 +0000239void real_main(unsigned long bist, unsigned long cpu_init_detectedx)
240{
241 static const uint16_t spd_addr[] = {
242 (0xa << 3) | 0, (0xa << 3) | 2, 0, 0,
243 (0xa << 3) | 1, (0xa << 3) | 3, 0, 0,
244#if CONFIG_MAX_PHYSICAL_CPUS > 1
245 (0xa << 3) | 4, (0xa << 3) | 6, 0, 0,
246 (0xa << 3) | 5, (0xa << 3) | 7, 0, 0,
247#endif
248 };
249 unsigned bsp_apicid = 0;
250 int needs_reset = 0;
251 struct sys_info *sysinfo =
Stefan Reinauer08670622009-06-30 15:17:49 +0000252 (CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);
Rudolf Marek1a002562007-11-02 23:17:57 +0000253 char *p;
Rudolf Marek1a002562007-11-02 23:17:57 +0000254
Rudolf Marek6211ae12008-01-12 22:29:17 +0000255 sio_init();
Stefan Reinauer08670622009-06-30 15:17:49 +0000256 w83627ehg_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Rudolf Marek1a002562007-11-02 23:17:57 +0000257 uart_init();
258 console_init();
Rudolf Marek56717872008-03-15 00:26:50 +0000259 enable_rom_decode();
Rudolf Marek1a002562007-11-02 23:17:57 +0000260
261 print_info("now booting... real_main\r\n");
262
Uwe Hermannc4f53652008-03-08 19:14:42 +0000263 if (bist == 0)
Rudolf Marek1a002562007-11-02 23:17:57 +0000264 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Uwe Hermannc4f53652008-03-08 19:14:42 +0000265
266 /* Halt if there was a built in self test failure. */
Rudolf Marek1a002562007-11-02 23:17:57 +0000267 report_bist_failure(bist);
Uwe Hermannc4f53652008-03-08 19:14:42 +0000268
Rudolf Marek1a002562007-11-02 23:17:57 +0000269 setup_default_resource_map();
270 setup_coherent_ht_domain();
271 wait_all_core0_started();
Uwe Hermannc4f53652008-03-08 19:14:42 +0000272
Rudolf Marek1a002562007-11-02 23:17:57 +0000273 print_info("now booting... Core0 started\r\n");
274
275#if CONFIG_LOGICAL_CPUS==1
Uwe Hermannc4f53652008-03-08 19:14:42 +0000276 /* It is said that we should start core1 after all core0 launched. */
Rudolf Marek1a002562007-11-02 23:17:57 +0000277 start_other_cores();
278 wait_all_other_cores_started(bsp_apicid);
279#endif
280 init_timer();
Uwe Hermannc4f53652008-03-08 19:14:42 +0000281 ht_setup_chains_x(sysinfo); /* Init sblnk and sbbusn, nodes, sbdn. */
Rudolf Marekcc3ccdb2007-11-13 15:40:21 +0000282
Rudolf Marek1a002562007-11-02 23:17:57 +0000283 needs_reset = optimize_link_coherent_ht();
284 needs_reset |= optimize_link_incoherent_ht(sysinfo);
Rudolf Marekc2213492008-03-19 20:24:33 +0000285 needs_reset |= k8t890_early_setup_ht();
Rudolf Marek1a002562007-11-02 23:17:57 +0000286
287 if (needs_reset) {
288 print_debug("ht reset -\r\n");
289 soft_reset();
290 }
Uwe Hermannc4f53652008-03-08 19:14:42 +0000291
Rudolf Marekc2213492008-03-19 20:24:33 +0000292 /* the HT settings needs to be OK, because link freq chnage may cause HT disconnect */
293 enable_fid_change();
294 init_fidvid_bsp(bsp_apicid);
295
Uwe Hermannc4f53652008-03-08 19:14:42 +0000296 /* Stop the APs so we can start them later in init. */
297 allow_all_aps_stop(bsp_apicid);
298
299 /* It's the time to set ctrl now. */
Rudolf Marek1a002562007-11-02 23:17:57 +0000300 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
Uwe Hermannc4f53652008-03-08 19:14:42 +0000301
Rudolf Marek1a002562007-11-02 23:17:57 +0000302 enable_smbus();
303 memreset_setup();
304 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
305 post_cache_as_ram();
306}