blob: ae89b05015bce534fc6e01ac4b617c5d5f496e25 [file] [log] [blame]
Noah Glovskyabe40e02016-04-19 14:55:38 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
Yinghai Lud4b278c2006-10-04 20:46:15 +000014#include <stdint.h>
Patrick Georgi12aba822009-04-30 07:07:22 +000015#include <string.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000016#include <device/pci_def.h>
17#include <device/pci_ids.h>
18#include <arch/io.h>
19#include <device/pnp_def.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000020#include <pc80/mc146818rtc.h>
Patrick Georgi12584e22010-05-08 09:14:51 +000021#include <console/console.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000022#include <cpu/amd/model_fxx_rev.h>
stepan836ae292010-12-08 05:42:47 +000023#include "southbridge/amd/amd8111/early_smbus.c"
Stefan Reinauer8f2c6162010-04-06 21:50:21 +000024#include <reset.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110025#include <northbridge/amd/amdk8/raminit.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000026#include "northbridge/amd/amdk8/reset_test.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110027#include <cpu/x86/bist.h>
Edward O'Callaghanebe3a7a2015-01-05 00:27:54 +110028#include <delay.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000029#include "northbridge/amd/amdk8/debug.c"
Stefan Reinauer8f2c6162010-04-06 21:50:21 +000030#include <cpu/amd/mtrr.h>
Edward O'Callaghan81998092014-04-28 18:07:33 +100031#include <superio/winbond/common/winbond.h>
32#include <superio/winbond/w83627hf/w83627hf.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000033#include "northbridge/amd/amdk8/setup_resource_map.c"
34
35#define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
36
Damien Zammit75a3d1f2016-11-28 00:29:10 +110037unsigned get_sbdn(unsigned bus);
38
Yinghai Lud4b278c2006-10-04 20:46:15 +000039static void memreset_setup(void)
40{
Elyes HAOUAScaccd972016-10-10 21:25:17 +020041 /* GPIO on amd8111 to enable MEMRST ???? */
42 outb((1 << 2)|(1 << 0), SMBUS_IO_BASE + 0xc0 + 16); /* REVC_MEMRST_EN = 1 */
Elyes HAOUAS08449eb2016-09-29 19:57:09 +020043 outb((1 << 2)|(0 << 0), SMBUS_IO_BASE + 0xc0 + 17);
Yinghai Lud4b278c2006-10-04 20:46:15 +000044}
45
Uwe Hermann7b997052010-11-21 22:47:22 +000046static void memreset(int controllers, const struct mem_controller *ctrl) { }
Yinghai Lud4b278c2006-10-04 20:46:15 +000047
48static inline void activate_spd_rom(const struct mem_controller *ctrl)
49{
50#define SMBUS_HUB 0x18
Elyes HAOUAS08449eb2016-09-29 19:57:09 +020051 int ret,i;
52 unsigned device=(ctrl->channel0[0])>>8;
Elyes HAOUAScaccd972016-10-10 21:25:17 +020053 /* the very first write always get COL_STS = 1 and ABRT_STS = 1, so try another time */
Elyes HAOUAS08449eb2016-09-29 19:57:09 +020054 i = 2;
55 do {
56 ret = smbus_write_byte(SMBUS_HUB, 0x01, device);
57 } while ((ret != 0) && (i-->0));
Yinghai Lud4b278c2006-10-04 20:46:15 +000058
Elyes HAOUAS08449eb2016-09-29 19:57:09 +020059 smbus_write_byte(SMBUS_HUB, 0x03, 0);
Yinghai Lud4b278c2006-10-04 20:46:15 +000060}
Uwe Hermann7b997052010-11-21 22:47:22 +000061
Yinghai Lud4b278c2006-10-04 20:46:15 +000062static inline int spd_read_byte(unsigned device, unsigned address)
63{
Elyes HAOUAS08449eb2016-09-29 19:57:09 +020064 return smbus_read_byte(device, address);
Yinghai Lud4b278c2006-10-04 20:46:15 +000065}
66
Damien Zammit75a3d1f2016-11-28 00:29:10 +110067#include "southbridge/amd/amd8111/early_ctrl.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110068#include <northbridge/amd/amdk8/amdk8.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000069#include "northbridge/amd/amdk8/incoherent_ht.c"
Stefan Reinauer23836e22010-04-15 12:39:29 +000070#include "northbridge/amd/amdk8/coherent_ht.c"
Myles Watson17257032009-06-04 20:18:42 +000071#include "northbridge/amd/amdk8/raminit_f.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +000072#include "lib/generic_sdram.c"
Uwe Hermann7b997052010-11-21 22:47:22 +000073#include "resourcemap.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +000074#include "cpu/amd/dualcore/dualcore.c"
Patrick Georgi9bd9a902010-11-20 10:31:00 +000075#include <spd.h>
Uwe Hermann57b2ff82010-11-21 17:29:59 +000076#include "cpu/amd/model_fxx/init_cpus.c"
77#include "cpu/amd/model_fxx/fidvid.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +000078
Elyes HAOUAS6350a2e2016-09-16 20:49:38 +020079#define RC0 ((1 << 0)<<8)
80#define RC1 ((1 << 1)<<8)
81#define RC2 ((1 << 2)<<8)
82#define RC3 ((1 << 3)<<8)
Yinghai Lud4b278c2006-10-04 20:46:15 +000083
Patrick Georgice6fb1e2010-03-17 22:44:39 +000084void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
Yinghai Lud4b278c2006-10-04 20:46:15 +000085{
86 static const uint16_t spd_addr[] = {
Elyes HAOUAScaccd972016-10-10 21:25:17 +020087 /* first node */
Elyes HAOUAS08449eb2016-09-29 19:57:09 +020088 RC0|DIMM0, RC0|DIMM2, 0, 0,
89 RC0|DIMM1, RC0|DIMM3, 0, 0,
Yinghai Lud4b278c2006-10-04 20:46:15 +000090#if CONFIG_MAX_PHYSICAL_CPUS > 1
Elyes HAOUAScaccd972016-10-10 21:25:17 +020091 /* second node */
Elyes HAOUAS08449eb2016-09-29 19:57:09 +020092 RC1|DIMM0, RC1|DIMM2, RC1|DIMM4, RC1|DIMM6,
93 RC1|DIMM1, RC1|DIMM3, RC1|DIMM5, RC1|DIMM7,
Yinghai Lud4b278c2006-10-04 20:46:15 +000094#endif
95#if CONFIG_MAX_PHYSICAL_CPUS > 2
Elyes HAOUAScaccd972016-10-10 21:25:17 +020096 /* third node */
Elyes HAOUAS08449eb2016-09-29 19:57:09 +020097 RC2|DIMM0, RC2|DIMM2, 0, 0,
98 RC2|DIMM1, RC2|DIMM3, 0, 0,
Elyes HAOUAScaccd972016-10-10 21:25:17 +020099 /* four node */
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200100 RC3|DIMM0, RC3|DIMM2, RC3|DIMM4, RC3|DIMM6,
101 RC3|DIMM1, RC3|DIMM3, RC3|DIMM5, RC3|DIMM7,
Yinghai Lud4b278c2006-10-04 20:46:15 +0000102#endif
103
104 };
105
Patrick Georgibbc880e2012-11-20 18:20:56 +0100106 struct sys_info *sysinfo = &sysinfo_car;
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200107 int needs_reset;
108 unsigned bsp_apicid = 0;
Patrick Georgi76e81522010-11-16 21:25:29 +0000109#if CONFIG_SET_FIDVID
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000110 struct cpuid_result cpuid1;
Myles Watson6e235762009-09-29 14:56:15 +0000111#endif
Yinghai Lud4b278c2006-10-04 20:46:15 +0000112
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200113 if (bist == 0)
Yinghai Lud4b278c2006-10-04 20:46:15 +0000114 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000115
Edward O'Callaghan81998092014-04-28 18:07:33 +1000116 winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
117 console_init();
Yinghai Lud4b278c2006-10-04 20:46:15 +0000118
Yinghai Lud4b278c2006-10-04 20:46:15 +0000119 /* Halt if there was a built in self test failure */
120 report_bist_failure(bist);
121
Myles Watson08e0fb82010-03-22 16:33:25 +0000122 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000123
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200124 setup_mb_resource_map();
Yinghai Lud4b278c2006-10-04 20:46:15 +0000125
Stefan Reinauer069f4762015-01-05 13:02:32 -0800126 printk(BIOS_DEBUG, "bsp_apicid=%02x\n", bsp_apicid);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000127
Elyes HAOUAScaccd972016-10-10 21:25:17 +0200128 set_sysinfo_in_ram(0); /* in BSP so could hold all ap until sysinfo is in ram */
129 setup_coherent_ht_domain(); /* routing table and start other core0 */
Yinghai Lud4b278c2006-10-04 20:46:15 +0000130
131 wait_all_core0_started();
Patrick Georgie1667822012-05-05 15:29:32 +0200132#if CONFIG_LOGICAL_CPUS
Elyes HAOUAScaccd972016-10-10 21:25:17 +0200133 /* It is said that we should start core1 after all core0 launched */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000134 /* becase optimize_link_coherent_ht is moved out from setup_coherent_ht_domain,
Yinghai Lud4b278c2006-10-04 20:46:15 +0000135 * So here need to make sure last core0 is started, esp for two way system,
Stefan Reinauer14e22772010-04-27 06:56:47 +0000136 * (there may be apic id conflicts in that case)
Yinghai Lud4b278c2006-10-04 20:46:15 +0000137 */
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200138 start_other_cores();
Yinghai Lud4b278c2006-10-04 20:46:15 +0000139 wait_all_other_cores_started(bsp_apicid);
140#endif
Stefan Reinauer14e22772010-04-27 06:56:47 +0000141
Yinghai Lud4b278c2006-10-04 20:46:15 +0000142 /* it will set up chains and store link pair for optimization later */
Elyes HAOUAScaccd972016-10-10 21:25:17 +0200143 ht_setup_chains_x(sysinfo); /* it will init sblnk and sbbusn, nodes, sbdn */
Yinghai Lud4b278c2006-10-04 20:46:15 +0000144
Patrick Georgi76e81522010-11-16 21:25:29 +0000145#if CONFIG_SET_FIDVID
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000146 /* Check to see if processor is capable of changing FIDVID */
147 /* otherwise it will throw a GP# when reading FIDVID_STATUS */
148 cpuid1 = cpuid(0x80000007);
Uwe Hermann7b997052010-11-21 22:47:22 +0000149 if ((cpuid1.edx & 0x6) == 0x6) {
Yinghai Lud4b278c2006-10-04 20:46:15 +0000150
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200151 {
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000152 /* Read FIDVID_STATUS */
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200153 msr_t msr;
154 msr = rdmsr(0xc0010042);
155 printk(BIOS_DEBUG, "begin msr fid, vid %08x%08x\n", msr.hi, msr.lo);
156 }
Yinghai Lud4b278c2006-10-04 20:46:15 +0000157
158 enable_fid_change();
Yinghai Lud4b278c2006-10-04 20:46:15 +0000159 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200160 init_fidvid_bsp(bsp_apicid);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000161
Elyes HAOUAScaccd972016-10-10 21:25:17 +0200162 /* show final fid and vid */
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200163 {
164 msr_t msr;
165 msr = rdmsr(0xc0010042);
166 printk(BIOS_DEBUG, "end msr fid, vid %08x%08x\n", msr.hi, msr.lo);
167 }
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000168
169 } else {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800170 printk(BIOS_DEBUG, "Changing FIDVID not supported\n");
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000171 }
Yinghai Lud4b278c2006-10-04 20:46:15 +0000172#endif
173
174#if 1
175 needs_reset = optimize_link_coherent_ht();
176 needs_reset |= optimize_link_incoherent_ht(sysinfo);
177
Elyes HAOUAScaccd972016-10-10 21:25:17 +0200178 /* fidvid change will issue one LDTSTOP and the HT change will be effective too */
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200179 if (needs_reset) {
180 printk(BIOS_INFO, "ht reset -\n");
181 soft_reset_x(sysinfo->sbbusn, sysinfo->sbdn);
182 }
Yinghai Lud4b278c2006-10-04 20:46:15 +0000183#endif
184 allow_all_aps_stop(bsp_apicid);
185
Elyes HAOUAScaccd972016-10-10 21:25:17 +0200186 /* It's the time to set ctrl in sysinfo now; */
Yinghai Lud4b278c2006-10-04 20:46:15 +0000187 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000188
189 enable_smbus();
190
Yinghai Lud4b278c2006-10-04 20:46:15 +0000191 memreset_setup();
192
Elyes HAOUAScaccd972016-10-10 21:25:17 +0200193 /* do we need apci timer, tsc...., only debug need it for better output */
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200194 /* all ap stopped? */
Elyes HAOUAScaccd972016-10-10 21:25:17 +0200195 /* Need to use TMICT to synchronize FID/VID */
Yinghai Lud4b278c2006-10-04 20:46:15 +0000196
197 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
198
Elyes HAOUAScaccd972016-10-10 21:25:17 +0200199 post_cache_as_ram(); /* bsp swtich stack to RAM and copy sysinfo RAM now */
Yinghai Lud4b278c2006-10-04 20:46:15 +0000200}