blob: d00779d0a4de79089e0f76dae393d15c5dc98e93 [file] [log] [blame]
Yinghai Lud4b278c2006-10-04 20:46:15 +00001#include <stdint.h>
Patrick Georgi12aba822009-04-30 07:07:22 +00002#include <string.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +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 Lud4b278c2006-10-04 20:46:15 +00009#include <cpu/amd/model_fxx_rev.h>
stepan836ae292010-12-08 05:42:47 +000010#include "southbridge/amd/amd8111/early_smbus.c"
Stefan Reinauer8f2c6162010-04-06 21:50:21 +000011#include <reset.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110012#include <northbridge/amd/amdk8/raminit.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000013#include "northbridge/amd/amdk8/reset_test.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110014#include <cpu/x86/bist.h>
Edward O'Callaghanebe3a7a2015-01-05 00:27:54 +110015#include <delay.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000016#include "northbridge/amd/amdk8/debug.c"
Stefan Reinauer8f2c6162010-04-06 21:50:21 +000017#include <cpu/amd/mtrr.h>
Edward O'Callaghan81998092014-04-28 18:07:33 +100018#include <superio/winbond/common/winbond.h>
19#include <superio/winbond/w83627hf/w83627hf.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000020#include "northbridge/amd/amdk8/setup_resource_map.c"
stepan836ae292010-12-08 05:42:47 +000021#include "southbridge/amd/amd8111/early_ctrl.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +000022
23#define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
24
Yinghai Lud4b278c2006-10-04 20:46:15 +000025static void memreset_setup(void)
26{
27 //GPIO on amd8111 to enable MEMRST ????
Uwe Hermann7b997052010-11-21 22:47:22 +000028 outb((1<<2)|(1<<0), SMBUS_IO_BASE + 0xc0 + 16); //REVC_MEMRST_EN=1
29 outb((1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 17);
Yinghai Lud4b278c2006-10-04 20:46:15 +000030}
31
Uwe Hermann7b997052010-11-21 22:47:22 +000032static void memreset(int controllers, const struct mem_controller *ctrl) { }
Yinghai Lud4b278c2006-10-04 20:46:15 +000033
34static inline void activate_spd_rom(const struct mem_controller *ctrl)
35{
36#define SMBUS_HUB 0x18
37 int ret,i;
38 unsigned device=(ctrl->channel0[0])>>8;
39 /* the very first write always get COL_STS=1 and ABRT_STS=1, so try another time*/
40 i=2;
41 do {
42 ret = smbus_write_byte(SMBUS_HUB, 0x01, device);
43 } while ((ret!=0) && (i-->0));
44
45 smbus_write_byte(SMBUS_HUB, 0x03, 0);
46}
Uwe Hermann7b997052010-11-21 22:47:22 +000047
Yinghai Lud4b278c2006-10-04 20:46:15 +000048static inline int spd_read_byte(unsigned device, unsigned address)
49{
50 return smbus_read_byte(device, address);
51}
52
Edward O'Callaghan77757c22015-01-04 21:33:39 +110053#include <northbridge/amd/amdk8/amdk8.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000054#include "northbridge/amd/amdk8/incoherent_ht.c"
Stefan Reinauer23836e22010-04-15 12:39:29 +000055#include "northbridge/amd/amdk8/coherent_ht.c"
Myles Watson17257032009-06-04 20:18:42 +000056#include "northbridge/amd/amdk8/raminit_f.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +000057#include "lib/generic_sdram.c"
Uwe Hermann7b997052010-11-21 22:47:22 +000058#include "resourcemap.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +000059#include "cpu/amd/dualcore/dualcore.c"
Patrick Georgi9bd9a902010-11-20 10:31:00 +000060#include <spd.h>
Uwe Hermann57b2ff82010-11-21 17:29:59 +000061#include "cpu/amd/model_fxx/init_cpus.c"
62#include "cpu/amd/model_fxx/fidvid.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +000063
64#define RC0 ((1<<0)<<8)
65#define RC1 ((1<<1)<<8)
66#define RC2 ((1<<2)<<8)
67#define RC3 ((1<<3)<<8)
68
Patrick Georgice6fb1e2010-03-17 22:44:39 +000069void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
Yinghai Lud4b278c2006-10-04 20:46:15 +000070{
71 static const uint16_t spd_addr[] = {
72 //first node
73 RC0|DIMM0, RC0|DIMM2, 0, 0,
74 RC0|DIMM1, RC0|DIMM3, 0, 0,
75#if CONFIG_MAX_PHYSICAL_CPUS > 1
76 //second node
77 RC1|DIMM0, RC1|DIMM2, RC1|DIMM4, RC1|DIMM6,
78 RC1|DIMM1, RC1|DIMM3, RC1|DIMM5, RC1|DIMM7,
79#endif
80#if CONFIG_MAX_PHYSICAL_CPUS > 2
81 // third node
82 RC2|DIMM0, RC2|DIMM2, 0, 0,
83 RC2|DIMM1, RC2|DIMM3, 0, 0,
84 // four node
85 RC3|DIMM0, RC3|DIMM2, RC3|DIMM4, RC3|DIMM6,
86 RC3|DIMM1, RC3|DIMM3, RC3|DIMM5, RC3|DIMM7,
87#endif
88
89 };
90
Patrick Georgibbc880e2012-11-20 18:20:56 +010091 struct sys_info *sysinfo = &sysinfo_car;
Myles Watson6e235762009-09-29 14:56:15 +000092 int needs_reset;
Yinghai Lud4b278c2006-10-04 20:46:15 +000093 unsigned bsp_apicid = 0;
Patrick Georgi76e81522010-11-16 21:25:29 +000094#if CONFIG_SET_FIDVID
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +000095 struct cpuid_result cpuid1;
Myles Watson6e235762009-09-29 14:56:15 +000096#endif
Yinghai Lud4b278c2006-10-04 20:46:15 +000097
Uwe Hermann7b997052010-11-21 22:47:22 +000098 if (bist == 0)
Yinghai Lud4b278c2006-10-04 20:46:15 +000099 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000100
Edward O'Callaghan81998092014-04-28 18:07:33 +1000101 winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
102 console_init();
Yinghai Lud4b278c2006-10-04 20:46:15 +0000103
Stefan Reinauer08670622009-06-30 15:17:49 +0000104// 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 +0000105
Yinghai Lud4b278c2006-10-04 20:46:15 +0000106 /* Halt if there was a built in self test failure */
107 report_bist_failure(bist);
108
Myles Watson08e0fb82010-03-22 16:33:25 +0000109 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000110
Yinghai Lu5f9624d2006-10-04 22:56:21 +0000111 setup_mb_resource_map();
Yinghai Lud4b278c2006-10-04 20:46:15 +0000112#if 0
113 dump_pci_device(PCI_DEV(0, 0x18, 0));
114 dump_pci_device(PCI_DEV(0, 0x19, 0));
115#endif
116
Stefan Reinauer069f4762015-01-05 13:02:32 -0800117 printk(BIOS_DEBUG, "bsp_apicid=%02x\n", bsp_apicid);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000118
Stefan Reinauer14e22772010-04-27 06:56:47 +0000119 set_sysinfo_in_ram(0); // in BSP so could hold all ap until sysinfo is in ram
Yinghai Lud4b278c2006-10-04 20:46:15 +0000120 setup_coherent_ht_domain(); // routing table and start other core0
121
122 wait_all_core0_started();
Patrick Georgie1667822012-05-05 15:29:32 +0200123#if CONFIG_LOGICAL_CPUS
Yinghai Lud4b278c2006-10-04 20:46:15 +0000124 // It is said that we should start core1 after all core0 launched
Stefan Reinauer14e22772010-04-27 06:56:47 +0000125 /* becase optimize_link_coherent_ht is moved out from setup_coherent_ht_domain,
Yinghai Lud4b278c2006-10-04 20:46:15 +0000126 * So here need to make sure last core0 is started, esp for two way system,
Stefan Reinauer14e22772010-04-27 06:56:47 +0000127 * (there may be apic id conflicts in that case)
Yinghai Lud4b278c2006-10-04 20:46:15 +0000128 */
129 start_other_cores();
130 wait_all_other_cores_started(bsp_apicid);
131#endif
Stefan Reinauer14e22772010-04-27 06:56:47 +0000132
Yinghai Lud4b278c2006-10-04 20:46:15 +0000133 /* it will set up chains and store link pair for optimization later */
134 ht_setup_chains_x(sysinfo); // it will init sblnk and sbbusn, nodes, sbdn
135
136#if 0
137 //it your CPU min fid is 1G, you can change HT to 1G and FID to max one time.
138 needs_reset = optimize_link_coherent_ht();
139 needs_reset |= optimize_link_incoherent_ht(sysinfo);
140#endif
141
Patrick Georgi76e81522010-11-16 21:25:29 +0000142#if CONFIG_SET_FIDVID
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000143 /* Check to see if processor is capable of changing FIDVID */
144 /* otherwise it will throw a GP# when reading FIDVID_STATUS */
145 cpuid1 = cpuid(0x80000007);
Uwe Hermann7b997052010-11-21 22:47:22 +0000146 if ((cpuid1.edx & 0x6) == 0x6) {
Yinghai Lud4b278c2006-10-04 20:46:15 +0000147
148 {
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000149 /* Read FIDVID_STATUS */
Yinghai Lud4b278c2006-10-04 20:46:15 +0000150 msr_t msr;
151 msr=rdmsr(0xc0010042);
Stefan Reinauer069f4762015-01-05 13:02:32 -0800152 printk(BIOS_DEBUG, "begin msr fid, vid %08x%08x\n", msr.hi, msr.lo);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000153 }
154
155 enable_fid_change();
Yinghai Lud4b278c2006-10-04 20:46:15 +0000156 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000157 init_fidvid_bsp(bsp_apicid);
158
159 // show final fid and vid
160 {
161 msr_t msr;
162 msr=rdmsr(0xc0010042);
Stefan Reinauer069f4762015-01-05 13:02:32 -0800163 printk(BIOS_DEBUG, "end msr fid, vid %08x%08x\n", msr.hi, msr.lo);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000164 }
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000165
166 } else {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800167 printk(BIOS_DEBUG, "Changing FIDVID not supported\n");
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000168 }
Yinghai Lud4b278c2006-10-04 20:46:15 +0000169#endif
170
171#if 1
172 needs_reset = optimize_link_coherent_ht();
173 needs_reset |= optimize_link_incoherent_ht(sysinfo);
174
175 // fidvid change will issue one LDTSTOP and the HT change will be effective too
176 if (needs_reset) {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800177 printk(BIOS_INFO, "ht reset -\n");
Yinghai Lud4b278c2006-10-04 20:46:15 +0000178 soft_reset_x(sysinfo->sbbusn, sysinfo->sbdn);
179 }
180#endif
181 allow_all_aps_stop(bsp_apicid);
182
Yinghai Lud4b278c2006-10-04 20:46:15 +0000183 //It's the time to set ctrl in sysinfo now;
184 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000185
186 enable_smbus();
187
188#if 0
Myles Watson6e235762009-09-29 14:56:15 +0000189 int i;
Yinghai Lud4b278c2006-10-04 20:46:15 +0000190 for(i=0;i<4;i++) {
191 activate_spd_rom(&cpu[i]);
192 dump_smbus_registers();
193 }
194#endif
195
Yinghai Lud4b278c2006-10-04 20:46:15 +0000196 memreset_setup();
197
198 //do we need apci timer, tsc...., only debug need it for better output
199 /* all ap stopped? */
200// init_timer(); // Need to use TMICT to synconize FID/VID
201
202 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
203
204#if 0
205 print_pci_devices();
206#endif
207
208#if 0
209// dump_pci_devices();
210 dump_pci_device_index_wait(PCI_DEV(0, 0x18, 2), 0x98);
211 dump_pci_device_index_wait(PCI_DEV(0, 0x19, 2), 0x98);
212#endif
213
214 post_cache_as_ram(); // bsp swtich stack to ram and copy sysinfo ram now
Yinghai Lud4b278c2006-10-04 20:46:15 +0000215}