blob: b69fd80518d5ab18c32333182968c32e74552888 [file] [log] [blame]
QingPei Wangcc66d972011-09-13 17:54:12 +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.
QingPei Wangcc66d972011-09-13 17:54:12 +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>
QingPei Wangcc66d972011-09-13 17:54:12 +080031#include <cpu/x86/lapic.h>
32#include <console/console.h>
Timothy Pearson91e9f672015-03-19 16:44:46 -050033#include <timestamp.h>
QingPei Wangcc66d972011-09-13 17:54:12 +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>
QingPei Wangcc66d972011-09-13 17:54:12 +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'Callaghanf2920022014-04-27 00:41:50 +100041#include <superio/ite/common/ite.h>
Edward O'Callaghan03ad2a22014-04-21 17:34:38 +100042#include <superio/ite/it8721f/it8721f.h>
QingPei Wangcc66d972011-09-13 17:54:12 +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
51static void activate_spd_rom(const struct mem_controller *ctrl)
52{
53}
54
55static int spd_read_byte(u32 device, u32 address)
56{
57 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
58}
59
60#include "northbridge/amd/amdfam10/raminit_sysinfo_in_ram.c"
61#include "northbridge/amd/amdfam10/pci.c"
62#include "resourcemap.c"
63#include "cpu/amd/quadcore/quadcore.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110064#include <cpu/amd/microcode.h>
Timothy Pearsonb30d7ed2015-10-16 14:24:06 -050065#include "cpu/amd/family_10h-family_15h/init_cpus.c"
QingPei Wangcc66d972011-09-13 17:54:12 +080066#include "northbridge/amd/amdfam10/early_ht.c"
67#include "spd.h"
QingPei Wangcc66d972011-09-13 17:54:12 +080068#include <reset.h>
QingPei Wangcc66d972011-09-13 17:54:12 +080069
70#define SERIAL_DEV PNP_DEV(0x4e, IT8721F_SP1)
71void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
72{
Patrick Georgibbc880e2012-11-20 18:20:56 +010073 struct sys_info *sysinfo = &sysinfo_car;
QingPei Wangcc66d972011-09-13 17:54:12 +080074 static const u8 spd_addr[] = {RC00, DIMM0, DIMM2, 0, 0, DIMM1, DIMM3, 0, 0, };
75 u32 bsp_apicid = 0, val;
76 msr_t msr;
77
Timothy Pearson91e9f672015-03-19 16:44:46 -050078 timestamp_init(timestamp_get());
79 timestamp_add_now(TS_START_ROMSTAGE);
80
QingPei Wangcc66d972011-09-13 17:54:12 +080081 if (!cpu_init_detectedx && boot_cpu()) {
82 /* Nothing special needs to be done to find bus 0 */
83 /* Allow the HT devices to be found */
84 /* mov bsp to bus 0xff when > 8 nodes */
85 set_bsp_node_CHtExtNodeCfgEn();
86 enumerate_ht_chain();
87
88 //enable port80 decoding and southbridge poweron init
89 sb_Poweron_Init();
90 }
91
92 post_code(0x30);
93
94 if (bist == 0) {
95 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo); /* mmconf is inited in init_cpus */
96 /* All cores run this but the BSP(node0,core0) is the only core that returns. */
97 }
98
99 post_code(0x32);
100
101 enable_rs780_dev8();
102 sb800_clk_output_48Mhz();
103
Edward O'Callaghanf2920022014-04-27 00:41:50 +1000104 ite_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
QingPei Wangcc66d972011-09-13 17:54:12 +0800105 console_init();
106 printk(BIOS_DEBUG, "\n");
107
108// dump_mem(CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE-0x200, CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE);
109
110 /* Halt if there was a built in self test failure */
111 report_bist_failure(bist);
112
113 // Load MPB
114 val = cpuid_eax(1);
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200115 printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
QingPei Wangcc66d972011-09-13 17:54:12 +0800116 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200117 printk(BIOS_DEBUG, "bsp_apicid = %02x\n", bsp_apicid);
118 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
QingPei Wangcc66d972011-09-13 17:54:12 +0800119
120 /* Setup sysinfo defaults */
121 set_sysinfo_in_ram(0);
122
QingPei Wangcc66d972011-09-13 17:54:12 +0800123 update_microcode(val);
Kyösti Mälkkif0a13ce2013-12-08 07:20:48 +0200124
QingPei Wangcc66d972011-09-13 17:54:12 +0800125 post_code(0x33);
126
Timothy Pearson730a0432015-10-16 13:51:51 -0500127 cpuSetAMDMSR(0);
QingPei Wangcc66d972011-09-13 17:54:12 +0800128 post_code(0x34);
129
130 amd_ht_init(sysinfo);
131 post_code(0x35);
132
133 /* Setup nodes PCI space and start core 0 AP init. */
134 finalize_node_setup(sysinfo);
135
136 /* Setup any mainboard PCI settings etc. */
137 setup_mb_resource_map();
138 post_code(0x36);
139
140 /* wait for all the APs core0 started by finalize_node_setup. */
141 /* FIXME: A bunch of cores are going to start output to serial at once.
142 It would be nice to fixup prink spinlocks for ROM XIP mode.
143 I think it could be done by putting the spinlock flag in the cache
144 of the BSP located right after sysinfo.
145 */
146 wait_all_core0_started();
147
Patrick Georgie1667822012-05-05 15:29:32 +0200148#if CONFIG_LOGICAL_CPUS
QingPei Wangcc66d972011-09-13 17:54:12 +0800149 /* Core0 on each node is configured. Now setup any additional cores. */
150 printk(BIOS_DEBUG, "start_other_cores()\n");
151 start_other_cores();
152 post_code(0x37);
153 wait_all_other_cores_started(bsp_apicid);
154#endif
155
156 post_code(0x38);
157
158 /* run _early_setup before soft-reset. */
159 rs780_early_setup();
160
Patrick Georgie1667822012-05-05 15:29:32 +0200161#if CONFIG_SET_FIDVID
QingPei Wangcc66d972011-09-13 17:54:12 +0800162 msr = rdmsr(0xc0010071);
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200163 printk(BIOS_DEBUG, "\nBegin FIDVID MSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
QingPei Wangcc66d972011-09-13 17:54:12 +0800164 post_code(0x39);
165
166 if (!warm_reset_detect(0)) { // BSP is node 0
167 init_fidvid_bsp(bsp_apicid, sysinfo->nodes);
168 } else {
169 init_fidvid_stage2(bsp_apicid, 0); // BSP is node 0
170 }
171
172 post_code(0x3A);
173
174 /* show final fid and vid */
175 msr=rdmsr(0xc0010071);
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200176 printk(BIOS_DEBUG, "End FIDVIDMSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
QingPei Wangcc66d972011-09-13 17:54:12 +0800177#endif
178
179 rs780_htinit();
180
181 /* Reset for HT, FIDVID, PLL and errata changes to take affect. */
182 if (!warm_reset_detect(0)) {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800183 printk(BIOS_INFO, "...WARM RESET...\n\n\n");
QingPei Wangcc66d972011-09-13 17:54:12 +0800184 soft_reset();
185 die("After soft_reset_x - shouldn't see this message!!!\n");
186 }
187
188 post_code(0x3B);
189
190 /* It's the time to set ctrl in sysinfo now; */
191 printk(BIOS_DEBUG, "fill_mem_ctrl()\n");
192 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
193
194 post_code(0x40);
195
196// die("Die Before MCT init.");
197
Timothy Pearson91e9f672015-03-19 16:44:46 -0500198 timestamp_add_now(TS_BEFORE_INITRAM);
QingPei Wangcc66d972011-09-13 17:54:12 +0800199 printk(BIOS_DEBUG, "raminit_amdmct()\n");
200 raminit_amdmct(sysinfo);
Timothy Pearson91e9f672015-03-19 16:44:46 -0500201 timestamp_add_now(TS_AFTER_INITRAM);
202
Timothy Pearson86f4ca52015-03-13 13:27:58 -0500203 cbmem_initialize_empty();
QingPei Wangcc66d972011-09-13 17:54:12 +0800204 post_code(0x41);
205
Timothy Pearson22564082015-03-27 22:49:18 -0500206 amdmct_cbmem_store_info(sysinfo);
207
QingPei Wangcc66d972011-09-13 17:54:12 +0800208/*
209 dump_pci_device_range(PCI_DEV(0, 0x18, 0), 0, 0x200);
210 dump_pci_device_range(PCI_DEV(0, 0x18, 1), 0, 0x200);
211 dump_pci_device_range(PCI_DEV(0, 0x18, 2), 0, 0x200);
212 dump_pci_device_range(PCI_DEV(0, 0x18, 3), 0, 0x200);
213*/
214
215// ram_check(0x00200000, 0x00200000 + (640 * 1024));
216// ram_check(0x40200000, 0x40200000 + (640 * 1024));
217
218// die("After MCT init before CAR disabled.");
219
220 rs780_before_pci_init();
221
222 post_code(0x42);
223 post_cache_as_ram(); // BSP switch stack to ram, copy then execute LB.
224 post_code(0x43); // Should never see this post code.
225}
226
227/**
228 * BOOL AMD_CB_ManualBUIDSwapList(u8 Node, u8 Link, u8 **List)
229 * Description:
230 * This routine is called every time a non-coherent chain is processed.
231 * BUID assignment may be controlled explicitly on a non-coherent chain. Provide a
232 * swap list. The first part of the list controls the BUID assignment and the
233 * second part of the list provides the device to device linking. Device orientation
234 * can be detected automatically, or explicitly. See documentation for more details.
235 *
236 * Automatic non-coherent init assigns BUIDs starting at 1 and incrementing sequentially
237 * based on each device's unit count.
238 *
239 * Parameters:
Martin Rothc3fde7e2014-12-29 22:13:37 -0700240 * @param[in] node = The node on which this chain is located
241 * @param[in] link = The link on the host for this chain
242 * @param[out] List = supply a pointer to a list
QingPei Wangcc66d972011-09-13 17:54:12 +0800243 */
244BOOL AMD_CB_ManualBUIDSwapList (u8 node, u8 link, const u8 **List)
245{
246 static const u8 swaplist[] = {0, 1, 0xFF, 0, 0xFF};
247 /* If the BUID was adjusted in early_ht we need to do the manual override */
248 if ((node == 0) && (link == 0)) { /* BSP SB link */
249 *List = swaplist;
250 return 1;
251 }
252
253 return 0;
254}