blob: ed85c8258df82376960b01f5ba562920415bc160 [file] [log] [blame]
Kerry She7b7b2c92011-09-08 21:16:19 +08001/*
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 She7b7b2c92011-09-08 21:16:19 +080014 */
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
24#include <lib.h>
25#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 She7b7b2c92011-09-08 21:16:19 +080031#include <cpu/x86/lapic.h>
32#include <console/console.h>
Timothy Pearson91e9f672015-03-19 16:44:46 -050033#include <timestamp.h>
Kerry She7b7b2c92011-09-08 21:16:19 +080034#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 She7b7b2c92011-09-08 21:16:19 +080038#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 She7b7b2c92011-09-08 21:16:19 +080043#include <cpu/amd/mtrr.h>
44#include "northbridge/amd/amdfam10/setup_resource_map.c"
45#include "southbridge/amd/rs780/early_setup.c"
46#include <sb_cimx.h>
47#include <SBPLATFORM.h> /* SB OEM constants */
48#include <southbridge/amd/cimx/sb800/smbus.h>
49#include "northbridge/amd/amdfam10/debug.c"
50
Edward O'Callaghanbeb0f262014-04-29 13:09:50 +100051#define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
Edward O'Callaghanc94d73e2014-06-16 17:24:14 +100052#define CLK_DEV PNP_DEV(0x2e, W83627HF_SP1)
Edward O'Callaghanbeb0f262014-04-29 13:09:50 +100053
Kerry She7b7b2c92011-09-08 21:16:19 +080054static void activate_spd_rom(const struct mem_controller *ctrl)
55{
56}
57
58static int spd_read_byte(u32 device, u32 address)
59{
60 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
61}
62
63#include "northbridge/amd/amdfam10/raminit_sysinfo_in_ram.c"
64#include "northbridge/amd/amdfam10/pci.c"
65#include "resourcemap.c"
66#include "cpu/amd/quadcore/quadcore.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110067#include <cpu/amd/microcode.h>
Timothy Pearsonb30d7ed2015-10-16 14:24:06 -050068#include "cpu/amd/family_10h-family_15h/init_cpus.c"
Kerry She7b7b2c92011-09-08 21:16:19 +080069#include "northbridge/amd/amdfam10/early_ht.c"
70#include "spd.h"
Kerry She7b7b2c92011-09-08 21:16:19 +080071#include <reset.h>
Kerry She7b7b2c92011-09-08 21:16:19 +080072
73void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
74{
Patrick Georgibbc880e2012-11-20 18:20:56 +010075 struct sys_info *sysinfo = &sysinfo_car;
Kerry She7b7b2c92011-09-08 21:16:19 +080076 static const u8 spd_addr[] = {RC00, DIMM0, DIMM2, 0, 0, DIMM1, DIMM3, 0, 0, };
77 u32 bsp_apicid = 0, val;
78 msr_t msr;
79
Timothy Pearson91e9f672015-03-19 16:44:46 -050080 timestamp_init(timestamp_get());
81 timestamp_add_now(TS_START_ROMSTAGE);
82
Kerry She7b7b2c92011-09-08 21:16:19 +080083 if (!cpu_init_detectedx && boot_cpu()) {
84 /* Nothing special needs to be done to find bus 0 */
85 /* Allow the HT devices to be found */
86 /* mov bsp to bus 0xff when > 8 nodes */
87 set_bsp_node_CHtExtNodeCfgEn();
88 enumerate_ht_chain();
89
90 //enable port80 decoding and southbridge poweron init
91 sb_Poweron_Init();
92 }
93
94 post_code(0x30);
95
96 if (bist == 0) {
97 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo); /* mmconf is inited in init_cpus */
98 /* All cores run this but the BSP(node0,core0) is the only core that returns. */
99 }
100
101 post_code(0x32);
102
103 enable_rs780_dev8();
104 sb800_clk_output_48Mhz();
105
Edward O'Callaghanc94d73e2014-06-16 17:24:14 +1000106 w83627hf_set_clksel_48(CLK_DEV);
Edward O'Callaghanbeb0f262014-04-29 13:09:50 +1000107 winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Kerry She7b7b2c92011-09-08 21:16:19 +0800108
Kerry She7b7b2c92011-09-08 21:16:19 +0800109 console_init();
110 printk(BIOS_DEBUG, "\n");
111
112// dump_mem(CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE-0x200, CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE);
113
114 /* Halt if there was a built in self test failure */
115 report_bist_failure(bist);
116
117 // Load MPB
118 val = cpuid_eax(1);
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200119 printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
Kerry She7b7b2c92011-09-08 21:16:19 +0800120 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200121 printk(BIOS_DEBUG, "bsp_apicid = %02x\n", bsp_apicid);
122 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
Kerry She7b7b2c92011-09-08 21:16:19 +0800123
124 /* Setup sysinfo defaults */
125 set_sysinfo_in_ram(0);
126
Kerry She7b7b2c92011-09-08 21:16:19 +0800127 update_microcode(val);
Kyösti Mälkkif0a13ce2013-12-08 07:20:48 +0200128
Kerry She7b7b2c92011-09-08 21:16:19 +0800129 post_code(0x33);
130
Timothy Pearson730a0432015-10-16 13:51:51 -0500131 cpuSetAMDMSR(0);
Kerry She7b7b2c92011-09-08 21:16:19 +0800132 post_code(0x34);
133
134 amd_ht_init(sysinfo);
135 post_code(0x35);
136
137 /* Setup nodes PCI space and start core 0 AP init. */
138 finalize_node_setup(sysinfo);
139
140 /* Setup any mainboard PCI settings etc. */
141 setup_mb_resource_map();
142 post_code(0x36);
143
144 /* wait for all the APs core0 started by finalize_node_setup. */
145 /* FIXME: A bunch of cores are going to start output to serial at once.
146 It would be nice to fixup prink spinlocks for ROM XIP mode.
147 I think it could be done by putting the spinlock flag in the cache
148 of the BSP located right after sysinfo.
149 */
150 wait_all_core0_started();
151
Patrick Georgie1667822012-05-05 15:29:32 +0200152#if CONFIG_LOGICAL_CPUS
Kerry She7b7b2c92011-09-08 21:16:19 +0800153 /* Core0 on each node is configured. Now setup any additional cores. */
154 printk(BIOS_DEBUG, "start_other_cores()\n");
155 start_other_cores();
156 post_code(0x37);
157 wait_all_other_cores_started(bsp_apicid);
158#endif
159
160 post_code(0x38);
161
162 /* run _early_setup before soft-reset. */
163 rs780_early_setup();
164
Patrick Georgie1667822012-05-05 15:29:32 +0200165#if CONFIG_SET_FIDVID
Kerry She7b7b2c92011-09-08 21:16:19 +0800166 msr = rdmsr(0xc0010071);
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200167 printk(BIOS_DEBUG, "\nBegin FIDVID MSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
Kerry She7b7b2c92011-09-08 21:16:19 +0800168 post_code(0x39);
169
170 if (!warm_reset_detect(0)) { // BSP is node 0
171 init_fidvid_bsp(bsp_apicid, sysinfo->nodes);
172 } else {
173 init_fidvid_stage2(bsp_apicid, 0); // BSP is node 0
174 }
175
176 post_code(0x3A);
177
178 /* show final fid and vid */
179 msr=rdmsr(0xc0010071);
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200180 printk(BIOS_DEBUG, "End FIDVIDMSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
Kerry She7b7b2c92011-09-08 21:16:19 +0800181#endif
182
183 rs780_htinit();
184
185 /* Reset for HT, FIDVID, PLL and errata changes to take affect. */
186 if (!warm_reset_detect(0)) {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800187 printk(BIOS_INFO, "...WARM RESET...\n\n\n");
Kerry She7b7b2c92011-09-08 21:16:19 +0800188 soft_reset();
189 die("After soft_reset_x - shouldn't see this message!!!\n");
190 }
191
192 post_code(0x3B);
193
194 /* It's the time to set ctrl in sysinfo now; */
195 printk(BIOS_DEBUG, "fill_mem_ctrl()\n");
196 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
197
198 post_code(0x40);
199
200// die("Die Before MCT init.");
201
Timothy Pearson91e9f672015-03-19 16:44:46 -0500202 timestamp_add_now(TS_BEFORE_INITRAM);
Kerry She7b7b2c92011-09-08 21:16:19 +0800203 printk(BIOS_DEBUG, "raminit_amdmct()\n");
204 raminit_amdmct(sysinfo);
Timothy Pearson91e9f672015-03-19 16:44:46 -0500205 timestamp_add_now(TS_AFTER_INITRAM);
206
Timothy Pearson86f4ca52015-03-13 13:27:58 -0500207 cbmem_initialize_empty();
Kerry She7b7b2c92011-09-08 21:16:19 +0800208 post_code(0x41);
209
Timothy Pearson22564082015-03-27 22:49:18 -0500210 amdmct_cbmem_store_info(sysinfo);
211
Kerry She7b7b2c92011-09-08 21:16:19 +0800212/*
213 dump_pci_device_range(PCI_DEV(0, 0x18, 0), 0, 0x200);
214 dump_pci_device_range(PCI_DEV(0, 0x18, 1), 0, 0x200);
215 dump_pci_device_range(PCI_DEV(0, 0x18, 2), 0, 0x200);
216 dump_pci_device_range(PCI_DEV(0, 0x18, 3), 0, 0x200);
217*/
218
219// ram_check(0x00200000, 0x00200000 + (640 * 1024));
220// ram_check(0x40200000, 0x40200000 + (640 * 1024));
221
222// die("After MCT init before CAR disabled.");
223
224 rs780_before_pci_init();
225
226 post_code(0x42);
227 post_cache_as_ram(); // BSP switch stack to ram, copy then execute LB.
228 post_code(0x43); // Should never see this post code.
229}
230
231/**
232 * BOOL AMD_CB_ManualBUIDSwapList(u8 Node, u8 Link, u8 **List)
233 * Description:
234 * This routine is called every time a non-coherent chain is processed.
235 * BUID assignment may be controlled explicitly on a non-coherent chain. Provide a
236 * swap list. The first part of the list controls the BUID assignment and the
237 * second part of the list provides the device to device linking. Device orientation
238 * can be detected automatically, or explicitly. See documentation for more details.
239 *
240 * Automatic non-coherent init assigns BUIDs starting at 1 and incrementing sequentially
241 * based on each device's unit count.
242 *
243 * Parameters:
Martin Rothc3fde7e2014-12-29 22:13:37 -0700244 * @param[in] node = The node on which this chain is located
245 * @param[in] link = The link on the host for this chain
246 * @param[out] List = supply a pointer to a list
Kerry She7b7b2c92011-09-08 21:16:19 +0800247 */
248BOOL AMD_CB_ManualBUIDSwapList (u8 node, u8 link, const u8 **List)
249{
250 static const u8 swaplist[] = {0, 1, 0xFF, 0, 0xFF};
251 /* If the BUID was adjusted in early_ht we need to do the manual override */
252 if ((node == 0) && (link == 0)) { /* BSP SB link */
253 *List = swaplist;
254 return 1;
255 }
256
257 return 0;
258}