blob: b17fb2bcf1c50ff3b24f54a5220397e8a2b959b3 [file] [log] [blame]
Kerry She6401fdb2011-05-07 09:15:02 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Kerry She6401fdb2011-05-07 09:15:02 +000014 */
15
16//#define SYSTEM_TYPE 0 /* SERVER */
17#define SYSTEM_TYPE 1 /* DESKTOP */
18//#define SYSTEM_TYPE 2 /* MOBILE */
19
20//used by incoherent_ht
21#define FAM10_SCAN_PCI_BUS 0
22#define FAM10_ALLOCATE_IO_RANGE 0
23
Kerry She3bf27082011-06-03 10:14:56 +000024#include <lib.h>
Kerry She6401fdb2011-05-07 09:15:02 +000025#include <stdint.h>
26#include <string.h>
27#include <device/pci_def.h>
28#include <device/pci_ids.h>
29#include <arch/io.h>
30#include <device/pnp_def.h>
Kerry She6401fdb2011-05-07 09:15:02 +000031#include <cpu/x86/lapic.h>
32#include <console/console.h>
Timothy Pearson91e9f672015-03-19 16:44:46 -050033#include <timestamp.h>
Kerry She6401fdb2011-05-07 09:15:02 +000034#include <cpu/amd/model_10xxx_rev.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110035#include <northbridge/amd/amdfam10/raminit.h>
36#include <northbridge/amd/amdfam10/amdfam10.h>
37#include <cpu/x86/lapic.h>
Kerry She6401fdb2011-05-07 09:15:02 +000038#include "northbridge/amd/amdfam10/reset_test.c"
Aaron Durbindc9f5cd2015-09-08 13:34:43 -050039#include <commonlib/loglevel.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110040#include <cpu/x86/bist.h>
Edward O'Callaghanbeb0f262014-04-29 13:09:50 +100041#include <superio/winbond/common/winbond.h>
42#include <superio/winbond/w83627hf/w83627hf.h>
Kerry She6401fdb2011-05-07 09:15:02 +000043#include <cpu/amd/mtrr.h>
44#include "northbridge/amd/amdfam10/setup_resource_map.c"
45#include "southbridge/amd/rs780/early_setup.c"
Kerry Shefeed3292011-08-18 18:03:44 +080046#include <sb_cimx.h>
Kerry She6401fdb2011-05-07 09:15:02 +000047#include <SBPLATFORM.h> /* SB OEM constants */
efdesign9805a89ab2011-06-20 17:38:49 -070048#include <southbridge/amd/cimx/sb800/smbus.h>
Kerry She6401fdb2011-05-07 09:15:02 +000049#include "northbridge/amd/amdfam10/debug.c"
50
Edward O'Callaghanbeb0f262014-04-29 13:09:50 +100051#define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
52
Kerry She6401fdb2011-05-07 09:15:02 +000053static void activate_spd_rom(const struct mem_controller *ctrl)
54{
55}
56
57static int spd_read_byte(u32 device, u32 address)
58{
59 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
60}
61
62#include "northbridge/amd/amdfam10/raminit_sysinfo_in_ram.c"
63#include "northbridge/amd/amdfam10/pci.c"
64#include "resourcemap.c"
65#include "cpu/amd/quadcore/quadcore.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110066#include <cpu/amd/microcode.h>
Timothy Pearsonb30d7ed2015-10-16 14:24:06 -050067#include "cpu/amd/family_10h-family_15h/init_cpus.c"
Kerry She6401fdb2011-05-07 09:15:02 +000068#include "northbridge/amd/amdfam10/early_ht.c"
69#include "spd.h"
Kerry She6401fdb2011-05-07 09:15:02 +000070#include <reset.h>
Kerry She6401fdb2011-05-07 09:15:02 +000071
Kerry She6401fdb2011-05-07 09:15:02 +000072void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
73{
Patrick Georgibbc880e2012-11-20 18:20:56 +010074 struct sys_info *sysinfo = &sysinfo_car;
Kerry She6401fdb2011-05-07 09:15:02 +000075 static const u8 spd_addr[] = {RC00, DIMM0, DIMM2, 0, 0, DIMM1, DIMM3, 0, 0, };
76 u32 bsp_apicid = 0, val;
77 msr_t msr;
78
Timothy Pearson91e9f672015-03-19 16:44:46 -050079 timestamp_init(timestamp_get());
80 timestamp_add_now(TS_START_ROMSTAGE);
81
Kerry She6401fdb2011-05-07 09:15:02 +000082 if (!cpu_init_detectedx && boot_cpu()) {
83 /* Nothing special needs to be done to find bus 0 */
84 /* Allow the HT devices to be found */
85 /* mov bsp to bus 0xff when > 8 nodes */
86 set_bsp_node_CHtExtNodeCfgEn();
87 enumerate_ht_chain();
88
89 //enable port80 decoding and southbridge poweron init
Kerry Shefeed3292011-08-18 18:03:44 +080090 sb_Poweron_Init();
Kerry She6401fdb2011-05-07 09:15:02 +000091 }
92
93 post_code(0x30);
94
95 if (bist == 0) {
96 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo); /* mmconf is inited in init_cpus */
97 /* All cores run this but the BSP(node0,core0) is the only core that returns. */
98 }
99
100 post_code(0x32);
101
102 enable_rs780_dev8();
103 sb800_clk_output_48Mhz();
104
105 w83627hf_set_clksel_48(PNP_DEV(0x2e, 0));
Edward O'Callaghanbeb0f262014-04-29 13:09:50 +1000106 winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Kerry She6401fdb2011-05-07 09:15:02 +0000107
Kerry She6401fdb2011-05-07 09:15:02 +0000108 console_init();
109 printk(BIOS_DEBUG, "\n");
110
111// dump_mem(CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE-0x200, CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE);
112
113 /* Halt if there was a built in self test failure */
114 report_bist_failure(bist);
115
116 // Load MPB
117 val = cpuid_eax(1);
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200118 printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
Kerry She6401fdb2011-05-07 09:15:02 +0000119 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200120 printk(BIOS_DEBUG, "bsp_apicid = %02x\n", bsp_apicid);
121 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
Kerry She6401fdb2011-05-07 09:15:02 +0000122
123 /* Setup sysinfo defaults */
124 set_sysinfo_in_ram(0);
125
Kerry She6401fdb2011-05-07 09:15:02 +0000126 update_microcode(val);
Kyösti Mälkkif0a13ce2013-12-08 07:20:48 +0200127
Kerry She6401fdb2011-05-07 09:15:02 +0000128 post_code(0x33);
129
Timothy Pearson730a0432015-10-16 13:51:51 -0500130 cpuSetAMDMSR(0);
Kerry She6401fdb2011-05-07 09:15:02 +0000131 post_code(0x34);
132
133 amd_ht_init(sysinfo);
134 post_code(0x35);
135
136 /* Setup nodes PCI space and start core 0 AP init. */
137 finalize_node_setup(sysinfo);
138
139 /* Setup any mainboard PCI settings etc. */
140 setup_mb_resource_map();
141 post_code(0x36);
142
143 /* wait for all the APs core0 started by finalize_node_setup. */
144 /* FIXME: A bunch of cores are going to start output to serial at once.
145 It would be nice to fixup prink spinlocks for ROM XIP mode.
146 I think it could be done by putting the spinlock flag in the cache
147 of the BSP located right after sysinfo.
148 */
149 wait_all_core0_started();
150
Patrick Georgie1667822012-05-05 15:29:32 +0200151#if CONFIG_LOGICAL_CPUS
Kerry She6401fdb2011-05-07 09:15:02 +0000152 /* Core0 on each node is configured. Now setup any additional cores. */
153 printk(BIOS_DEBUG, "start_other_cores()\n");
154 start_other_cores();
155 post_code(0x37);
156 wait_all_other_cores_started(bsp_apicid);
157#endif
158
159 post_code(0x38);
160
161 /* run _early_setup before soft-reset. */
162 rs780_early_setup();
163
Patrick Georgie1667822012-05-05 15:29:32 +0200164#if CONFIG_SET_FIDVID
Kerry She6401fdb2011-05-07 09:15:02 +0000165 msr = rdmsr(0xc0010071);
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200166 printk(BIOS_DEBUG, "\nBegin FIDVID MSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
Kerry She6401fdb2011-05-07 09:15:02 +0000167 post_code(0x39);
168
169 if (!warm_reset_detect(0)) { // BSP is node 0
170 init_fidvid_bsp(bsp_apicid, sysinfo->nodes);
171 } else {
172 init_fidvid_stage2(bsp_apicid, 0); // BSP is node 0
173 }
174
175 post_code(0x3A);
176
177 /* show final fid and vid */
178 msr=rdmsr(0xc0010071);
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200179 printk(BIOS_DEBUG, "End FIDVIDMSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
Kerry She6401fdb2011-05-07 09:15:02 +0000180#endif
181
182 rs780_htinit();
183
184 /* Reset for HT, FIDVID, PLL and errata changes to take affect. */
185 if (!warm_reset_detect(0)) {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800186 printk(BIOS_INFO, "...WARM RESET...\n\n\n");
Kerry She6401fdb2011-05-07 09:15:02 +0000187 soft_reset();
188 die("After soft_reset_x - shouldn't see this message!!!\n");
189 }
190
191 post_code(0x3B);
192
193 /* It's the time to set ctrl in sysinfo now; */
194 printk(BIOS_DEBUG, "fill_mem_ctrl()\n");
195 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
196
197 post_code(0x40);
198
199// die("Die Before MCT init.");
200
Timothy Pearson91e9f672015-03-19 16:44:46 -0500201 timestamp_add_now(TS_BEFORE_INITRAM);
Kerry She6401fdb2011-05-07 09:15:02 +0000202 printk(BIOS_DEBUG, "raminit_amdmct()\n");
203 raminit_amdmct(sysinfo);
Timothy Pearson91e9f672015-03-19 16:44:46 -0500204 timestamp_add_now(TS_AFTER_INITRAM);
205
Timothy Pearson86f4ca52015-03-13 13:27:58 -0500206 cbmem_initialize_empty();
Kerry She6401fdb2011-05-07 09:15:02 +0000207 post_code(0x41);
208
Timothy Pearson22564082015-03-27 22:49:18 -0500209 amdmct_cbmem_store_info(sysinfo);
210
Kerry She6401fdb2011-05-07 09:15:02 +0000211/*
212 dump_pci_device_range(PCI_DEV(0, 0x18, 0), 0, 0x200);
213 dump_pci_device_range(PCI_DEV(0, 0x18, 1), 0, 0x200);
214 dump_pci_device_range(PCI_DEV(0, 0x18, 2), 0, 0x200);
215 dump_pci_device_range(PCI_DEV(0, 0x18, 3), 0, 0x200);
216*/
217
218// ram_check(0x00200000, 0x00200000 + (640 * 1024));
219// ram_check(0x40200000, 0x40200000 + (640 * 1024));
220
221// die("After MCT init before CAR disabled.");
222
223 rs780_before_pci_init();
224
225 post_code(0x42);
226 post_cache_as_ram(); // BSP switch stack to ram, copy then execute LB.
227 post_code(0x43); // Should never see this post code.
228}
229
230/**
231 * BOOL AMD_CB_ManualBUIDSwapList(u8 Node, u8 Link, u8 **List)
232 * Description:
233 * This routine is called every time a non-coherent chain is processed.
234 * BUID assignment may be controlled explicitly on a non-coherent chain. Provide a
235 * swap list. The first part of the list controls the BUID assignment and the
236 * second part of the list provides the device to device linking. Device orientation
237 * can be detected automatically, or explicitly. See documentation for more details.
238 *
239 * Automatic non-coherent init assigns BUIDs starting at 1 and incrementing sequentially
240 * based on each device's unit count.
241 *
242 * Parameters:
Martin Rothc3fde7e2014-12-29 22:13:37 -0700243 * @param[in] node = The node on which this chain is located
244 * @param[in] link = The link on the host for this chain
245 * @param[out] List = supply a pointer to a list
Kerry She6401fdb2011-05-07 09:15:02 +0000246 */
247BOOL AMD_CB_ManualBUIDSwapList (u8 node, u8 link, const u8 **List)
248{
249 static const u8 swaplist[] = {0, 1, 0xFF, 0, 0xFF};
250 /* If the BUID was adjusted in early_ht we need to do the manual override */
251 if ((node == 0) && (link == 0)) { /* BSP SB link */
252 *List = swaplist;
253 return 1;
254 }
255
256 return 0;
257}