2 * This file is part of the coreboot project.
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.
9 * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
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.
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.
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
29 #define RAMINIT_SYSINFO 1
31 #define CACHE_AS_RAM_ADDRESS_DEBUG 0
33 unsigned int get_sbdn(unsigned bus);
36 #define QRANK_DIMM_SUPPORT 1
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
43 //#define DEBUG_SMBUS 1
46 #include <device/pci_def.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"
54 #include "pc80/serial.c"
55 #include "arch/i386/lib/console.c"
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"
62 #if CONFIG_USE_INIT == 0
63 #include "lib/memcpy.c"
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"
72 #include "superio/winbond/w83627ehg/w83627ehg_early_serial.c"
73 #include "southbridge/via/vt8237r/vt8237r_early_smbus.c"
75 #include "cpu/amd/mtrr/amd_earlymtrr.c"
76 #include "cpu/x86/bist.h"
78 #include "northbridge/amd/amdk8/setup_resource_map.c"
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)
85 static void memreset_setup(void)
89 static void memreset(int controllers, const struct mem_controller *ctrl)
94 static inline int spd_read_byte(unsigned device, unsigned address)
96 return smbus_read_byte(device, address);
99 #define K8_4RANK_DIMM_SUPPORT 1
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"
107 #include "cpu/amd/dualcore/dualcore.c"
109 #include "southbridge/via/k8t890/k8t890_early_car.c"
111 #include "cpu/amd/car/copy_and_run.c"
113 #include "cpu/amd/car/post_cache_as_ram.c"
115 #include "cpu/amd/model_fxx/init_cpus.c"
116 #include "cpu/amd/model_fxx/fidvid.c"
118 #include "northbridge/amd/amdk8/resourcemap.c"
121 void activate_spd_rom(const struct mem_controller *ctrl)
126 void hard_reset(void)
128 print_info("NO HARD RESET FIX ME!\n");
131 void soft_reset(void)
135 print_debug("soft reset \r\n");
138 tmp = pci_read_config8(PCI_DEV(0, 0x11, 0), 0x4f);
140 pci_write_config8(PCI_DEV(0, 0x11, 0), 0x4f, tmp);
143 /* daisy daisy ... */
148 unsigned int get_sbdn(unsigned bus)
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;
158 void sio_init(void) {
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 */
165 reg = pnp_read_config(SERIAL_DEV, 0x2A);
166 pnp_write_config(SERIAL_DEV, 0x2A, (reg | 1)); /* we have GPIO for KB/MS PIN */
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 */
171 pnp_exit_ext_func_mode(SERIAL_DEV);
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);
183 pnp_enter_ext_func_mode(GPIO_DEV);
184 pnp_set_logical_device(GPIO_DEV);
185 pnp_exit_ext_func_mode(GPIO_DEV);
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);
198 #if USE_FALLBACK_IMAGE == 1
200 void failover_process(unsigned long bist, unsigned long cpu_init_detectedx)
202 // unsigned last_boot_normal_x = last_boot_normal();
204 unsigned last_boot_normal_x = 1;
207 w83627ehg_enable_serial(SERIAL_DEV, TTYS0_BASE);
211 print_info("now booting... fallback\r\n");
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) {
222 /* Nothing special needs to be done to find bus 0 */
223 /* Allow the HT devices to be found */
225 enumerate_ht_chain();
227 /* Is this a deliberate reset by the bios */
228 if (bios_reset_detected() && last_boot_normal_x) {
231 /* This is the primary cpu how should I boot? */
232 else if (do_normal_boot()) {
238 //print_info("JMP normal image\r\n");
240 __asm__ volatile ("jmp __normal_image": /* outputs */
241 :"a" (bist), "b"(cpu_init_detectedx) /* inputs */
249 void real_main(unsigned long bist, unsigned long cpu_init_detectedx);
251 void cache_as_ram_main(unsigned long bist,
252 unsigned long cpu_init_detectedx)
255 #if USE_FALLBACK_IMAGE == 1
256 failover_process(bist, cpu_init_detectedx);
258 real_main(bist, cpu_init_detectedx);
263 void real_main(unsigned long bist, unsigned long cpu_init_detectedx)
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,
273 unsigned bsp_apicid = 0;
275 struct sys_info *sysinfo =
276 (DCACHE_RAM_BASE + DCACHE_RAM_SIZE -
277 DCACHE_RAM_GLOBAL_VAR_SIZE);
281 w83627ehg_enable_serial(SERIAL_DEV, TTYS0_BASE);
285 print_info("now booting... real_main\r\n");
288 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
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");
297 #if CONFIG_LOGICAL_CPUS==1
298 // It is said that we should start core1 after all core0 launched
300 wait_all_other_cores_started(bsp_apicid);
303 ht_setup_chains_x(sysinfo); // it will init sblnk and sbbusn, nodes, sbdn
306 init_fidvid_bsp(bsp_apicid);
308 needs_reset = optimize_link_coherent_ht();
309 needs_reset |= optimize_link_incoherent_ht(sysinfo);
311 /* Fixme it assumes that 1000MHz LDT is selected. */
312 needs_reset |= k8t890_early_setup_car(16, 0x6);
315 print_debug("ht reset -\r\n");
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);
324 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);