blob: 39cd0e339d4eeedc4c712d7e2720df5ef261a82a [file] [log] [blame]
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2006 Tyan
5 * Copyright (C) 2006 AMD
6 * Written by Yinghai Lu <yinghailu@gmail.com> for Tyan and AMD.
7 *
8 * Copyright (C) 2007 University of Mannheim
9 * Written by Philipp Degler <pdegler@rumms.uni-mannheim.de> for University of Mannheim
10 * Copyright (C) 2009 University of Heidelberg
11 * Written by Mondrian Nuessle <nuessle@uni-heidelberg.de> for University of Heidelberg
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000022 */
23
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000024#define FAM10_SCAN_PCI_BUS 0
25#define FAM10_ALLOCATE_IO_RANGE 1
26
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000027#include <stdint.h>
28#include <string.h>
29#include <device/pci_def.h>
30#include <device/pci_ids.h>
31#include <arch/io.h>
32#include <device/pnp_def.h>
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000033#include <cpu/x86/lapic.h>
34#include "option_table.h"
35#include <console/console.h>
Timothy Pearson91e9f672015-03-19 16:44:46 -050036#include <timestamp.h>
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000037#include <cpu/amd/model_10xxx_rev.h>
stepan836ae292010-12-08 05:42:47 +000038#include "southbridge/broadcom/bcm5785/early_smbus.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110039#include <northbridge/amd/amdfam10/raminit.h>
40#include <northbridge/amd/amdfam10/amdfam10.h>
Patrick Georgid0835952010-10-05 09:07:10 +000041#include <lib.h>
Uwe Hermann26535d62010-11-20 20:36:40 +000042#include <spd.h>
Edward O'Callaghanebe3a7a2015-01-05 00:27:54 +110043#include <delay.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110044#include <cpu/x86/lapic.h>
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000045#include "northbridge/amd/amdfam10/reset_test.c"
Edward O'Callaghanf18abab2014-03-31 21:53:32 +110046#include <superio/serverengines/pilot/pilot.h>
Edward O'Callaghanb8f05d42015-01-04 16:17:54 +110047#include <superio/nsc/pc87417/pc87417.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110048#include <cpu/x86/bist.h>
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000049#include "northbridge/amd/amdfam10/debug.c"
stepan836ae292010-12-08 05:42:47 +000050#include "southbridge/broadcom/bcm5785/early_setup.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000051
52#define SERIAL_DEV PNP_DEV(0x2e, PILOT_SP1)
53#define RTC_DEV PNP_DEV(0x4e, PC87417_RTC)
54
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000055static inline void activate_spd_rom(const struct mem_controller *ctrl)
56{
57 u8 val;
58 outb(0x3d, 0x0cd6);
59 outb(0x87, 0x0cd7);
60
61 outb(0x44, 0xcd6);
62 val = inb(0xcd7);
63 outb((val & ~3) | ctrl->spd_switch_addr, 0xcd7);
64}
65
66static inline int spd_read_byte(unsigned device, unsigned address)
67{
68 return smbus_read_byte(device, address);
69}
70
Edward O'Callaghan77757c22015-01-04 21:33:39 +110071#include <northbridge/amd/amdfam10/amdfam10.h>
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000072#include "northbridge/amd/amdfam10/raminit_sysinfo_in_ram.c"
stepan8301d832010-12-08 07:07:33 +000073#include "northbridge/amd/amdfam10/pci.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000074#include "cpu/amd/quadcore/quadcore.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110075#include <cpu/amd/microcode.h>
Xavi Drudis Ferran4c28a6f2011-02-26 23:29:44 +000076
Timothy Pearsonb30d7ed2015-10-16 14:24:06 -050077#include "cpu/amd/family_10h-family_15h/init_cpus.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000078#include "northbridge/amd/amdfam10/early_ht.c"
79
Uwe Hermann26535d62010-11-20 20:36:40 +000080static const u8 spd_addr[] = {
81 // switch addr, 1A addr, 2A addr, 3A addr, 4A addr, 1B addr, 2B addr, 3B addr 4B addr
82 //first node
83 RC00, DIMM0, DIMM2, 0, 0, DIMM1, DIMM3, 0, 0,
84#if CONFIG_MAX_PHYSICAL_CPUS > 1
85 //second node
86 RC01, DIMM0, DIMM2, 0, 0, DIMM1, DIMM3, 0, 0,
87#endif
88};
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000089
90void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
91{
Patrick Georgibbc880e2012-11-20 18:20:56 +010092 struct sys_info *sysinfo = &sysinfo_car;
Uwe Hermann7b997052010-11-21 22:47:22 +000093 u32 bsp_apicid = 0, val;
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000094 msr_t msr;
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070095
Timothy Pearson91e9f672015-03-19 16:44:46 -050096 timestamp_init(timestamp_get());
97 timestamp_add_now(TS_START_ROMSTAGE);
98
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000099 if (!cpu_init_detectedx && boot_cpu()) {
Uwe Hermann7b997052010-11-21 22:47:22 +0000100 /* Nothing special needs to be done to find bus 0 */
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000101 /* Allow the HT devices to be found */
102 /* mov bsp to bus 0xff when > 8 nodes */
103 set_bsp_node_CHtExtNodeCfgEn();
104 enumerate_ht_chain();
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000105 bcm5785_enable_lpc();
Uwe Hermann7b997052010-11-21 22:47:22 +0000106 pc87417_enable_dev(RTC_DEV); /* Enable RTC */
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000107 }
108
109 post_code(0x30);
110
Uwe Hermann7b997052010-11-21 22:47:22 +0000111 if (bist == 0)
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000112 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000113
114 pilot_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
115
Stefan Reinauer42fa7fe2011-04-20 20:54:07 +0000116 console_init();
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000117
118 /* Halt if there was a built in self test failure */
119 report_bist_failure(bist);
120
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000121 pilot_early_init(SERIAL_DEV); //config port is being taken from SERIAL_DEV
122
123 val = cpuid_eax(1);
124 printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
125 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
126 printk(BIOS_DEBUG, "bsp_apicid = %02x\n", bsp_apicid);
127 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
128
129 /* Setup sysinfo defaults */
130 set_sysinfo_in_ram(0);
131
132 update_microcode(val);
Kyösti Mälkkif0a13ce2013-12-08 07:20:48 +0200133
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000134 post_code(0x33);
135
Timothy Pearson730a0432015-10-16 13:51:51 -0500136 cpuSetAMDMSR(0);
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000137 post_code(0x34);
138
139 amd_ht_init(sysinfo);
140 post_code(0x35);
141
142 /* Setup nodes PCI space and start core 0 AP init. */
143 finalize_node_setup(sysinfo);
144
145 post_code(0x36);
146
147 /* wait for all the APs core0 started by finalize_node_setup. */
148 /* FIXME: A bunch of cores are going to start output to serial at once.
149 * It would be nice to fixup prink spinlocks for ROM XIP mode.
150 * I think it could be done by putting the spinlock flag in the cache
151 * of the BSP located right after sysinfo.
152 */
153
154 wait_all_core0_started();
155
Patrick Georgie1667822012-05-05 15:29:32 +0200156#if CONFIG_LOGICAL_CPUS
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000157 /* Core0 on each node is configured. Now setup any additional cores. */
158 printk(BIOS_DEBUG, "start_other_cores()\n");
Timothy Pearson0122afb2015-07-30 14:07:15 -0500159 start_other_cores(bsp_apicid);
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000160 post_code(0x37);
161 wait_all_other_cores_started(bsp_apicid);
162#endif
163
Patrick Georgi76e81522010-11-16 21:25:29 +0000164#if CONFIG_SET_FIDVID
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000165 msr = rdmsr(0xc0010071);
166 printk(BIOS_DEBUG, "\nBegin FIDVID MSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
167
168 /* FIXME: The sb fid change may survive the warm reset and only
169 * need to be done once.*/
170
171 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
172
173 post_code(0x39);
174
175 if (!warm_reset_detect(0)) { // BSP is node 0
176 init_fidvid_bsp(bsp_apicid, sysinfo->nodes);
177 } else {
178 init_fidvid_stage2(bsp_apicid, 0); // BSP is node 0
179 }
180
181 post_code(0x3A);
182
183 /* show final fid and vid */
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600184 msr = rdmsr(0xc0010071);
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000185 printk(BIOS_DEBUG, "End FIDVIDMSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
186#endif
187
188 init_timer();
189
190 /* Reset for HT, FIDVID, PLL and errata changes to take affect. */
191 if (!warm_reset_detect(0)) {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800192 printk(BIOS_INFO, "...WARM RESET...\n\n\n");
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000193 soft_reset();
194 die("After soft_reset_x - shouldn't see this message!!!\n");
195 }
196
197 /* It's the time to set ctrl in sysinfo now; */
198 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
199 enable_smbus();
200
201 //do we need apci timer, tsc...., only debug need it for better output
202 /* all ap stopped? */
Paul Menzel4549e5a2014-02-02 22:05:48 +0100203// init_timer(); // Need to use TMICT to synchronize FID/VID
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000204
Timothy Pearson91e9f672015-03-19 16:44:46 -0500205 timestamp_add_now(TS_BEFORE_INITRAM);
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000206 printk(BIOS_DEBUG, "raminit_amdmct()\n");
207 raminit_amdmct(sysinfo);
Timothy Pearson91e9f672015-03-19 16:44:46 -0500208 timestamp_add_now(TS_AFTER_INITRAM);
209
Timothy Pearson86f4ca52015-03-13 13:27:58 -0500210 cbmem_initialize_empty();
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000211 post_code(0x41);
212
Timothy Pearson22564082015-03-27 22:49:18 -0500213 amdmct_cbmem_store_info(sysinfo);
214
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000215 bcm5785_early_setup();
216
217 post_cache_as_ram();
218}
Scott Duplichan314dd0b2011-03-08 23:01:46 +0000219
220/**
221 * BOOL AMD_CB_ManualBUIDSwapList(u8 Node, u8 Link, u8 **List)
222 * Description:
223 * This routine is called every time a non-coherent chain is processed.
224 * BUID assignment may be controlled explicitly on a non-coherent chain. Provide a
225 * swap list. The first part of the list controls the BUID assignment and the
226 * second part of the list provides the device to device linking. Device orientation
227 * can be detected automatically, or explicitly. See documentation for more details.
228 *
229 * Automatic non-coherent init assigns BUIDs starting at 1 and incrementing sequentially
230 * based on each device's unit count.
231 *
232 * Parameters:
Martin Rothc3fde7e2014-12-29 22:13:37 -0700233 * @param[in] node = The node on which this chain is located
234 * @param[in] link = The link on the host for this chain
235 * @param[out] List = supply a pointer to a list
Scott Duplichan314dd0b2011-03-08 23:01:46 +0000236 */
237BOOL AMD_CB_ManualBUIDSwapList (u8 node, u8 link, const u8 **List)
238{
239 static const u8 swaplist[] = { 0xFF, CONFIG_HT_CHAIN_UNITID_BASE, CONFIG_HT_CHAIN_END_UNITID_BASE, 0xFF };
240 /* If the BUID was adjusted in early_ht we need to do the manual override */
241 if ((CONFIG_HT_CHAIN_UNITID_BASE != 0) && (CONFIG_HT_CHAIN_END_UNITID_BASE != 0)) {
242 printk(BIOS_DEBUG, "AMD_CB_ManualBUIDSwapList()\n");
243 if ((node == 0) && (link == 0)) { /* BSP SB link */
244 *List = swaplist;
245 return 1;
246 }
247 }
248
249 return 0;
250}