blob: fff950af253b44b97132c5fad816fdcde98dd544 [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"
stepan836ae292010-12-08 05:42:47 +000034#include "southbridge/amd/amd8111/early_ctrl.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +000035
36#define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
37
Yinghai Lud4b278c2006-10-04 20:46:15 +000038static void memreset_setup(void)
39{
40 //GPIO on amd8111 to enable MEMRST ????
Elyes HAOUAS08449eb2016-09-29 19:57:09 +020041 outb((1 << 2)|(1 << 0), SMBUS_IO_BASE + 0xc0 + 16); //REVC_MEMRST_EN = 1
42 outb((1 << 2)|(0 << 0), SMBUS_IO_BASE + 0xc0 + 17);
Yinghai Lud4b278c2006-10-04 20:46:15 +000043}
44
Uwe Hermann7b997052010-11-21 22:47:22 +000045static void memreset(int controllers, const struct mem_controller *ctrl) { }
Yinghai Lud4b278c2006-10-04 20:46:15 +000046
47static inline void activate_spd_rom(const struct mem_controller *ctrl)
48{
49#define SMBUS_HUB 0x18
Elyes HAOUAS08449eb2016-09-29 19:57:09 +020050 int ret,i;
51 unsigned device=(ctrl->channel0[0])>>8;
52 /* the very first write always get COL_STS = 1 and ABRT_STS = 1, so try another time*/
53 i = 2;
54 do {
55 ret = smbus_write_byte(SMBUS_HUB, 0x01, device);
56 } while ((ret != 0) && (i-->0));
Yinghai Lud4b278c2006-10-04 20:46:15 +000057
Elyes HAOUAS08449eb2016-09-29 19:57:09 +020058 smbus_write_byte(SMBUS_HUB, 0x03, 0);
Yinghai Lud4b278c2006-10-04 20:46:15 +000059}
Uwe Hermann7b997052010-11-21 22:47:22 +000060
Yinghai Lud4b278c2006-10-04 20:46:15 +000061static inline int spd_read_byte(unsigned device, unsigned address)
62{
Elyes HAOUAS08449eb2016-09-29 19:57:09 +020063 return smbus_read_byte(device, address);
Yinghai Lud4b278c2006-10-04 20:46:15 +000064}
65
Edward O'Callaghan77757c22015-01-04 21:33:39 +110066#include <northbridge/amd/amdk8/amdk8.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000067#include "northbridge/amd/amdk8/incoherent_ht.c"
Stefan Reinauer23836e22010-04-15 12:39:29 +000068#include "northbridge/amd/amdk8/coherent_ht.c"
Myles Watson17257032009-06-04 20:18:42 +000069#include "northbridge/amd/amdk8/raminit_f.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +000070#include "lib/generic_sdram.c"
Uwe Hermann7b997052010-11-21 22:47:22 +000071#include "resourcemap.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +000072#include "cpu/amd/dualcore/dualcore.c"
Patrick Georgi9bd9a902010-11-20 10:31:00 +000073#include <spd.h>
Uwe Hermann57b2ff82010-11-21 17:29:59 +000074#include "cpu/amd/model_fxx/init_cpus.c"
75#include "cpu/amd/model_fxx/fidvid.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +000076
Elyes HAOUAS6350a2e2016-09-16 20:49:38 +020077#define RC0 ((1 << 0)<<8)
78#define RC1 ((1 << 1)<<8)
79#define RC2 ((1 << 2)<<8)
80#define RC3 ((1 << 3)<<8)
Yinghai Lud4b278c2006-10-04 20:46:15 +000081
Patrick Georgice6fb1e2010-03-17 22:44:39 +000082void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
Yinghai Lud4b278c2006-10-04 20:46:15 +000083{
84 static const uint16_t spd_addr[] = {
85 //first node
Elyes HAOUAS08449eb2016-09-29 19:57:09 +020086 RC0|DIMM0, RC0|DIMM2, 0, 0,
87 RC0|DIMM1, RC0|DIMM3, 0, 0,
Yinghai Lud4b278c2006-10-04 20:46:15 +000088#if CONFIG_MAX_PHYSICAL_CPUS > 1
89 //second node
Elyes HAOUAS08449eb2016-09-29 19:57:09 +020090 RC1|DIMM0, RC1|DIMM2, RC1|DIMM4, RC1|DIMM6,
91 RC1|DIMM1, RC1|DIMM3, RC1|DIMM5, RC1|DIMM7,
Yinghai Lud4b278c2006-10-04 20:46:15 +000092#endif
93#if CONFIG_MAX_PHYSICAL_CPUS > 2
Elyes HAOUAS08449eb2016-09-29 19:57:09 +020094 // third node
95 RC2|DIMM0, RC2|DIMM2, 0, 0,
96 RC2|DIMM1, RC2|DIMM3, 0, 0,
97 // four node
98 RC3|DIMM0, RC3|DIMM2, RC3|DIMM4, RC3|DIMM6,
99 RC3|DIMM1, RC3|DIMM3, RC3|DIMM5, RC3|DIMM7,
Yinghai Lud4b278c2006-10-04 20:46:15 +0000100#endif
101
102 };
103
Patrick Georgibbc880e2012-11-20 18:20:56 +0100104 struct sys_info *sysinfo = &sysinfo_car;
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200105 int needs_reset;
106 unsigned bsp_apicid = 0;
Patrick Georgi76e81522010-11-16 21:25:29 +0000107#if CONFIG_SET_FIDVID
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000108 struct cpuid_result cpuid1;
Myles Watson6e235762009-09-29 14:56:15 +0000109#endif
Yinghai Lud4b278c2006-10-04 20:46:15 +0000110
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200111 if (bist == 0)
Yinghai Lud4b278c2006-10-04 20:46:15 +0000112 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000113
Edward O'Callaghan81998092014-04-28 18:07:33 +1000114 winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
115 console_init();
Yinghai Lud4b278c2006-10-04 20:46:15 +0000116
Stefan Reinauer08670622009-06-30 15:17:49 +0000117// dump_mem(CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE-0x200, CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE);
Stefan Reinauer14e22772010-04-27 06:56:47 +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#if 0
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200126 dump_pci_device(PCI_DEV(0, 0x18, 0));
Yinghai Lud4b278c2006-10-04 20:46:15 +0000127 dump_pci_device(PCI_DEV(0, 0x19, 0));
128#endif
129
Stefan Reinauer069f4762015-01-05 13:02:32 -0800130 printk(BIOS_DEBUG, "bsp_apicid=%02x\n", bsp_apicid);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000131
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200132 set_sysinfo_in_ram(0); // in BSP so could hold all ap until sysinfo is in ram
Yinghai Lud4b278c2006-10-04 20:46:15 +0000133 setup_coherent_ht_domain(); // routing table and start other core0
134
135 wait_all_core0_started();
Patrick Georgie1667822012-05-05 15:29:32 +0200136#if CONFIG_LOGICAL_CPUS
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200137 // It is said that we should start core1 after all core0 launched
Stefan Reinauer14e22772010-04-27 06:56:47 +0000138 /* becase optimize_link_coherent_ht is moved out from setup_coherent_ht_domain,
Yinghai Lud4b278c2006-10-04 20:46:15 +0000139 * So here need to make sure last core0 is started, esp for two way system,
Stefan Reinauer14e22772010-04-27 06:56:47 +0000140 * (there may be apic id conflicts in that case)
Yinghai Lud4b278c2006-10-04 20:46:15 +0000141 */
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200142 start_other_cores();
Yinghai Lud4b278c2006-10-04 20:46:15 +0000143 wait_all_other_cores_started(bsp_apicid);
144#endif
Stefan Reinauer14e22772010-04-27 06:56:47 +0000145
Yinghai Lud4b278c2006-10-04 20:46:15 +0000146 /* it will set up chains and store link pair for optimization later */
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200147 ht_setup_chains_x(sysinfo); // it will init sblnk and sbbusn, nodes, sbdn
Yinghai Lud4b278c2006-10-04 20:46:15 +0000148
149#if 0
150 //it your CPU min fid is 1G, you can change HT to 1G and FID to max one time.
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200151 needs_reset = optimize_link_coherent_ht();
152 needs_reset |= optimize_link_incoherent_ht(sysinfo);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000153#endif
154
Patrick Georgi76e81522010-11-16 21:25:29 +0000155#if CONFIG_SET_FIDVID
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000156 /* Check to see if processor is capable of changing FIDVID */
157 /* otherwise it will throw a GP# when reading FIDVID_STATUS */
158 cpuid1 = cpuid(0x80000007);
Uwe Hermann7b997052010-11-21 22:47:22 +0000159 if ((cpuid1.edx & 0x6) == 0x6) {
Yinghai Lud4b278c2006-10-04 20:46:15 +0000160
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200161 {
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000162 /* Read FIDVID_STATUS */
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200163 msr_t msr;
164 msr = rdmsr(0xc0010042);
165 printk(BIOS_DEBUG, "begin msr fid, vid %08x%08x\n", msr.hi, msr.lo);
166 }
Yinghai Lud4b278c2006-10-04 20:46:15 +0000167
168 enable_fid_change();
Yinghai Lud4b278c2006-10-04 20:46:15 +0000169 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200170 init_fidvid_bsp(bsp_apicid);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000171
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200172 // show final fid and vid
173 {
174 msr_t msr;
175 msr = rdmsr(0xc0010042);
176 printk(BIOS_DEBUG, "end msr fid, vid %08x%08x\n", msr.hi, msr.lo);
177 }
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000178
179 } else {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800180 printk(BIOS_DEBUG, "Changing FIDVID not supported\n");
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000181 }
Yinghai Lud4b278c2006-10-04 20:46:15 +0000182#endif
183
184#if 1
185 needs_reset = optimize_link_coherent_ht();
186 needs_reset |= optimize_link_incoherent_ht(sysinfo);
187
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200188 // fidvid change will issue one LDTSTOP and the HT change will be effective too
189 if (needs_reset) {
190 printk(BIOS_INFO, "ht reset -\n");
191 soft_reset_x(sysinfo->sbbusn, sysinfo->sbdn);
192 }
Yinghai Lud4b278c2006-10-04 20:46:15 +0000193#endif
194 allow_all_aps_stop(bsp_apicid);
195
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200196 //It's the time to set ctrl in sysinfo now;
Yinghai Lud4b278c2006-10-04 20:46:15 +0000197 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000198
199 enable_smbus();
200
201#if 0
Myles Watson6e235762009-09-29 14:56:15 +0000202 int i;
Elyes HAOUAS6350a2e2016-09-16 20:49:38 +0200203 for(i = 0; i < 4; i++) {
Yinghai Lud4b278c2006-10-04 20:46:15 +0000204 activate_spd_rom(&cpu[i]);
205 dump_smbus_registers();
206 }
207#endif
208
Yinghai Lud4b278c2006-10-04 20:46:15 +0000209 memreset_setup();
210
211 //do we need apci timer, tsc...., only debug need it for better output
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200212 /* all ap stopped? */
213// init_timer(); // Need to use TMICT to synchronize FID/VID
Yinghai Lud4b278c2006-10-04 20:46:15 +0000214
215 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
216
217#if 0
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200218 print_pci_devices();
Yinghai Lud4b278c2006-10-04 20:46:15 +0000219#endif
220
221#if 0
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200222// dump_pci_devices();
223 dump_pci_device_index_wait(PCI_DEV(0, 0x18, 2), 0x98);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000224 dump_pci_device_index_wait(PCI_DEV(0, 0x19, 2), 0x98);
225#endif
226
Elyes HAOUAS08449eb2016-09-29 19:57:09 +0200227 post_cache_as_ram(); // bsp swtich stack to RAM and copy sysinfo RAM now
Yinghai Lud4b278c2006-10-04 20:46:15 +0000228}