blob: 9b5b38db7267b5e7e91fc5292cf451dc2c27e568 [file] [log] [blame]
Yinghai Luc34e3ab2006-10-12 00:58:20 +00001#include <stdint.h>
Patrick Georgi12aba822009-04-30 07:07:22 +00002#include <string.h>
Yinghai Luc34e3ab2006-10-12 00:58:20 +00003#include <device/pci_def.h>
4#include <device/pci_ids.h>
5#include <arch/io.h>
6#include <device/pnp_def.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +00007#include <pc80/mc146818rtc.h>
Patrick Georgi12584e22010-05-08 09:14:51 +00008#include <console/console.h>
Yinghai Luc34e3ab2006-10-12 00:58:20 +00009#include <cpu/amd/model_fxx_rev.h>
stepan836ae292010-12-08 05:42:47 +000010#include "southbridge/amd/amd8111/early_smbus.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110011#include <northbridge/amd/amdk8/raminit.h>
Yinghai Luc34e3ab2006-10-12 00:58:20 +000012#include "northbridge/amd/amdk8/reset_test.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110013#include <cpu/x86/bist.h>
Edward O'Callaghanebe3a7a2015-01-05 00:27:54 +110014#include <delay.h>
Yinghai Luc34e3ab2006-10-12 00:58:20 +000015#include "northbridge/amd/amdk8/debug.c"
Edward O'Callaghan81998092014-04-28 18:07:33 +100016#include <superio/winbond/common/winbond.h>
17#include <superio/winbond/w83627hf/w83627hf.h>
Yinghai Luc34e3ab2006-10-12 00:58:20 +000018#include "northbridge/amd/amdk8/setup_resource_map.c"
stepan836ae292010-12-08 05:42:47 +000019#include "southbridge/amd/amd8111/early_ctrl.c"
Yinghai Luc34e3ab2006-10-12 00:58:20 +000020
21#define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
22
Yinghai Luc34e3ab2006-10-12 00:58:20 +000023/*
24 * GPIO28 of 8111 will control H0_MEMRESET_L
25 * GPIO29 of 8111 will control H1_MEMRESET_L
26 */
27static void memreset_setup(void)
28{
29 if (is_cpu_pre_c0()) {
Uwe Hermann7b997052010-11-21 22:47:22 +000030 /* Set the memreset low. */
31 outb((1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 28);
32 /* Ensure the BIOS has control of the memory lines. */
33 outb((1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 29);
Yinghai Luc34e3ab2006-10-12 00:58:20 +000034 } else {
Uwe Hermann7b997052010-11-21 22:47:22 +000035 /* Ensure the CPU has control of the memory lines. */
36 outb((1<<2)|(1<<0), SMBUS_IO_BASE + 0xc0 + 29);
Yinghai Luc34e3ab2006-10-12 00:58:20 +000037 }
38}
39
40static void memreset(int controllers, const struct mem_controller *ctrl)
41{
42 if (is_cpu_pre_c0()) {
43 udelay(800);
44 /* Set memreset_high */
Uwe Hermann7b997052010-11-21 22:47:22 +000045 outb((1<<2)|(1<<0), SMBUS_IO_BASE + 0xc0 + 28);
Yinghai Luc34e3ab2006-10-12 00:58:20 +000046 udelay(90);
47 }
48}
49
Uwe Hermann7b997052010-11-21 22:47:22 +000050static void activate_spd_rom(const struct mem_controller *ctrl) { }
Yinghai Luc34e3ab2006-10-12 00:58:20 +000051
52static inline int spd_read_byte(unsigned device, unsigned address)
53{
54 return smbus_read_byte(device, address);
55}
56
Edward O'Callaghan77757c22015-01-04 21:33:39 +110057#include <northbridge/amd/amdk8/amdk8.h>
Yinghai Luc34e3ab2006-10-12 00:58:20 +000058#include "northbridge/amd/amdk8/incoherent_ht.c"
Stefan Reinauer23836e22010-04-15 12:39:29 +000059#include "northbridge/amd/amdk8/coherent_ht.c"
Yinghai Luc34e3ab2006-10-12 00:58:20 +000060#include "northbridge/amd/amdk8/raminit.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +000061#include "lib/generic_sdram.c"
Uwe Hermann7b997052010-11-21 22:47:22 +000062#include "resourcemap.c"
Yinghai Luc34e3ab2006-10-12 00:58:20 +000063#include "cpu/amd/dualcore/dualcore.c"
Patrick Georgi9bd9a902010-11-20 10:31:00 +000064#include <spd.h>
Yinghai Luc34e3ab2006-10-12 00:58:20 +000065#include "cpu/amd/model_fxx/init_cpus.c"
Yinghai Luc34e3ab2006-10-12 00:58:20 +000066#include "cpu/amd/model_fxx/fidvid.c"
Yinghai Luc34e3ab2006-10-12 00:58:20 +000067
Patrick Georgice6fb1e2010-03-17 22:44:39 +000068void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
Yinghai Luc34e3ab2006-10-12 00:58:20 +000069{
70 static const uint16_t spd_addr[] = {
Uwe Hermann7b997052010-11-21 22:47:22 +000071 // first node
72 DIMM0, DIMM2, 0, 0,
73 DIMM1, DIMM3, 0, 0,
74 // second node
75 DIMM4, DIMM6, 0, 0,
76 DIMM5, DIMM7, 0, 0,
Yinghai Luc34e3ab2006-10-12 00:58:20 +000077 };
78
Patrick Georgibbc880e2012-11-20 18:20:56 +010079 struct sys_info *sysinfo = &sysinfo_car;
Stefan Reinauer5d3dee82010-04-14 11:40:34 +000080 int needs_reset;
Yinghai Luc34e3ab2006-10-12 00:58:20 +000081 unsigned bsp_apicid = 0;
82
Uwe Hermann7b997052010-11-21 22:47:22 +000083 if (bist == 0)
Yinghai Luc34e3ab2006-10-12 00:58:20 +000084 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Yinghai Luc34e3ab2006-10-12 00:58:20 +000085
Edward O'Callaghan81998092014-04-28 18:07:33 +100086 winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
87 console_init();
Yinghai Luc34e3ab2006-10-12 00:58:20 +000088
89 /* Halt if there was a built in self test failure */
90 report_bist_failure(bist);
91
Myles Watson08e0fb82010-03-22 16:33:25 +000092 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
Yinghai Luc34e3ab2006-10-12 00:58:20 +000093
94 setup_mb_resource_map();
95
Stefan Reinauer069f4762015-01-05 13:02:32 -080096 printk(BIOS_DEBUG, "bsp_apicid=%02x\n", bsp_apicid);
Yinghai Luc34e3ab2006-10-12 00:58:20 +000097
Yinghai Luc34e3ab2006-10-12 00:58:20 +000098 setup_coherent_ht_domain(); // routing table and start other core0
99
100 wait_all_core0_started();
Patrick Georgie1667822012-05-05 15:29:32 +0200101#if CONFIG_LOGICAL_CPUS
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000102 // It is said that we should start core1 after all core0 launched
Stefan Reinauer14e22772010-04-27 06:56:47 +0000103 /* becase optimize_link_coherent_ht is moved out from setup_coherent_ht_domain,
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000104 * So here need to make sure last core0 is started, esp for two way system,
Stefan Reinauer14e22772010-04-27 06:56:47 +0000105 * (there may be apic id conflicts in that case)
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000106 */
107 start_other_cores();
108 wait_all_other_cores_started(bsp_apicid);
109#endif
Stefan Reinauer14e22772010-04-27 06:56:47 +0000110
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000111 /* it will set up chains and store link pair for optimization later */
112 ht_setup_chains_x(sysinfo); // it will init sblnk and sbbusn, nodes, sbdn
113
Patrick Georgi76e81522010-11-16 21:25:29 +0000114#if CONFIG_SET_FIDVID
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000115 {
116 msr_t msr;
117 msr=rdmsr(0xc0010042);
Stefan Reinauer069f4762015-01-05 13:02:32 -0800118 printk(BIOS_DEBUG, "begin msr fid, vid %08x%08x\n", msr.hi, msr.lo);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000119 }
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000120 enable_fid_change();
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000121 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000122 init_fidvid_bsp(bsp_apicid);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000123 // show final fid and vid
124 {
125 msr_t msr;
126 msr=rdmsr(0xc0010042);
Stefan Reinauer069f4762015-01-05 13:02:32 -0800127 printk(BIOS_DEBUG, "end msr fid, vid %08x%08x\n", msr.hi, msr.lo);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000128 }
129#endif
130
131 needs_reset = optimize_link_coherent_ht();
132 needs_reset |= optimize_link_incoherent_ht(sysinfo);
133
134 // fidvid change will issue one LDTSTOP and the HT change will be effective too
135 if (needs_reset) {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800136 printk(BIOS_INFO, "ht reset -\n");
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000137 soft_reset_x(sysinfo->sbbusn, sysinfo->sbdn);
138 }
139
140 allow_all_aps_stop(bsp_apicid);
141
142 //It's the time to set ctrl in sysinfo now;
143 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
144
145 enable_smbus();
146
147#if 0
148 dump_smbus_registers();
149#endif
150
151 memreset_setup();
152
153 //do we need apci timer, tsc...., only debug need it for better output
154 /* all ap stopped? */
Paul Menzel4549e5a2014-02-02 22:05:48 +0100155 init_timer(); // Need to use TMICT to synchronize FID/VID
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000156 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
157
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000158#if 0
159 dump_pci_devices();
160#endif
161
162 post_cache_as_ram(); // bsp swtich stack to ram and copy sysinfo ram now
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000163}