blob: d91776c4da3dbe8e67c28324deafa21484b050c6 [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
Elyes HAOUAS023e2842016-10-07 18:07:21 +020016#define SYSTEM_TYPE 1 /* SERVER=0, DESKTOP=1, MOBILE=2 */
Kerry She7b7b2c92011-09-08 21:16:19 +080017
Kerry She7b7b2c92011-09-08 21:16:19 +080018#define FAM10_SCAN_PCI_BUS 0
19#define FAM10_ALLOCATE_IO_RANGE 0
20
21#include <lib.h>
22#include <stdint.h>
23#include <string.h>
24#include <device/pci_def.h>
25#include <device/pci_ids.h>
26#include <arch/io.h>
27#include <device/pnp_def.h>
Kerry She7b7b2c92011-09-08 21:16:19 +080028#include <cpu/x86/lapic.h>
29#include <console/console.h>
Timothy Pearson91e9f672015-03-19 16:44:46 -050030#include <timestamp.h>
Kerry She7b7b2c92011-09-08 21:16:19 +080031#include <cpu/amd/model_10xxx_rev.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110032#include <cpu/x86/lapic.h>
Aaron Durbindc9f5cd2015-09-08 13:34:43 -050033#include <commonlib/loglevel.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110034#include <cpu/x86/bist.h>
Edward O'Callaghanbeb0f262014-04-29 13:09:50 +100035#include <superio/winbond/common/winbond.h>
36#include <superio/winbond/w83627hf/w83627hf.h>
Kerry She7b7b2c92011-09-08 21:16:19 +080037#include <cpu/amd/mtrr.h>
Damien Zammit75a3d1f2016-11-28 00:29:10 +110038#include <cpu/amd/car.h>
39#include <southbridge/amd/sb800/smbus.h>
40#include <northbridge/amd/amdfam10/raminit.h>
41#include <northbridge/amd/amdht/ht_wrapper.h>
42#include <cpu/amd/family_10h-family_15h/init_cpus.h>
43#include <arch/early_variables.h>
44#include <cbmem.h>
45#include "spd.h"
46#include <reset.h>
Arthur Heymans6d1fdb32017-06-21 14:44:13 +020047#include <southbridge/amd/rs780/rs780.h>
Elyes HAOUAS4ad14462018-06-16 18:29:33 +020048#include <southbridge/amd/sb800/early_setup.c>
Damien Zammit75a3d1f2016-11-28 00:29:10 +110049
50#include "resourcemap.c"
51#include "cpu/amd/quadcore/quadcore.c"
Kerry She7b7b2c92011-09-08 21:16:19 +080052
Edward O'Callaghanbeb0f262014-04-29 13:09:50 +100053#define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
Edward O'Callaghanc94d73e2014-06-16 17:24:14 +100054#define CLK_DEV PNP_DEV(0x2e, W83627HF_SP1)
Edward O'Callaghanbeb0f262014-04-29 13:09:50 +100055
Damien Zammit75a3d1f2016-11-28 00:29:10 +110056void activate_spd_rom(const struct mem_controller *ctrl);
Elyes HAOUASdd35e2c2018-09-20 17:33:50 +020057int spd_read_byte(unsigned int device, unsigned int address);
Damien Zammit75a3d1f2016-11-28 00:29:10 +110058extern struct sys_info sysinfo_car;
59
60void activate_spd_rom(const struct mem_controller *ctrl)
Kerry She7b7b2c92011-09-08 21:16:19 +080061{
62}
63
Damien Zammit75a3d1f2016-11-28 00:29:10 +110064int spd_read_byte(u32 device, u32 address)
Kerry She7b7b2c92011-09-08 21:16:19 +080065{
66 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
67}
68
Kerry She7b7b2c92011-09-08 21:16:19 +080069void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
70{
Patrick Georgibbc880e2012-11-20 18:20:56 +010071 struct sys_info *sysinfo = &sysinfo_car;
Kerry She7b7b2c92011-09-08 21:16:19 +080072 static const u8 spd_addr[] = {RC00, DIMM0, DIMM2, 0, 0, DIMM1, DIMM3, 0, 0, };
73 u32 bsp_apicid = 0, val;
74 msr_t msr;
75
Timothy Pearson91e9f672015-03-19 16:44:46 -050076 timestamp_init(timestamp_get());
77 timestamp_add_now(TS_START_ROMSTAGE);
78
Kerry She7b7b2c92011-09-08 21:16:19 +080079 if (!cpu_init_detectedx && boot_cpu()) {
80 /* Nothing special needs to be done to find bus 0 */
81 /* Allow the HT devices to be found */
82 /* mov bsp to bus 0xff when > 8 nodes */
83 set_bsp_node_CHtExtNodeCfgEn();
84 enumerate_ht_chain();
85
Elyes HAOUAS023e2842016-10-07 18:07:21 +020086 /*enable port80 decoding and southbridge poweron init */
Damien Zammit75a3d1f2016-11-28 00:29:10 +110087 sb800_lpc_init();
88 sb800_pci_port80();
Kerry She7b7b2c92011-09-08 21:16:19 +080089 }
90
91 post_code(0x30);
92
93 if (bist == 0) {
94 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo); /* mmconf is inited in init_cpus */
95 /* All cores run this but the BSP(node0,core0) is the only core that returns. */
96 }
97
98 post_code(0x32);
99
100 enable_rs780_dev8();
101 sb800_clk_output_48Mhz();
102
Keith Huiaaa16fe2017-09-01 19:55:49 -0400103 winbond_set_clksel_48(CLK_DEV);
Edward O'Callaghanbeb0f262014-04-29 13:09:50 +1000104 winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Kerry She7b7b2c92011-09-08 21:16:19 +0800105
Kerry She7b7b2c92011-09-08 21:16:19 +0800106 console_init();
107 printk(BIOS_DEBUG, "\n");
108
Kerry She7b7b2c92011-09-08 21:16:19 +0800109 /* Halt if there was a built in self test failure */
110 report_bist_failure(bist);
111
Elyes HAOUAS023e2842016-10-07 18:07:21 +0200112 /* Load MPB */
Kerry She7b7b2c92011-09-08 21:16:19 +0800113 val = cpuid_eax(1);
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200114 printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
Kerry She7b7b2c92011-09-08 21:16:19 +0800115 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200116 printk(BIOS_DEBUG, "bsp_apicid = %02x\n", bsp_apicid);
117 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
Kerry She7b7b2c92011-09-08 21:16:19 +0800118
119 /* Setup sysinfo defaults */
120 set_sysinfo_in_ram(0);
121
Kerry She7b7b2c92011-09-08 21:16:19 +0800122 update_microcode(val);
Kyösti Mälkkif0a13ce2013-12-08 07:20:48 +0200123
Kerry She7b7b2c92011-09-08 21:16:19 +0800124 post_code(0x33);
125
Timothy Pearson730a0432015-10-16 13:51:51 -0500126 cpuSetAMDMSR(0);
Kerry She7b7b2c92011-09-08 21:16:19 +0800127 post_code(0x34);
128
129 amd_ht_init(sysinfo);
130 post_code(0x35);
131
132 /* Setup nodes PCI space and start core 0 AP init. */
133 finalize_node_setup(sysinfo);
134
135 /* Setup any mainboard PCI settings etc. */
136 setup_mb_resource_map();
137 post_code(0x36);
138
139 /* wait for all the APs core0 started by finalize_node_setup. */
140 /* FIXME: A bunch of cores are going to start output to serial at once.
141 It would be nice to fixup prink spinlocks for ROM XIP mode.
142 I think it could be done by putting the spinlock flag in the cache
143 of the BSP located right after sysinfo.
144 */
145 wait_all_core0_started();
146
Martin Rothf95911a2017-06-24 21:45:13 -0600147#if IS_ENABLED(CONFIG_LOGICAL_CPUS)
Kerry She7b7b2c92011-09-08 21:16:19 +0800148 /* Core0 on each node is configured. Now setup any additional cores. */
149 printk(BIOS_DEBUG, "start_other_cores()\n");
Timothy Pearson0122afb2015-07-30 14:07:15 -0500150 start_other_cores(bsp_apicid);
Kerry She7b7b2c92011-09-08 21:16:19 +0800151 post_code(0x37);
152 wait_all_other_cores_started(bsp_apicid);
153#endif
154
155 post_code(0x38);
156
157 /* run _early_setup before soft-reset. */
158 rs780_early_setup();
Damien Zammit75a3d1f2016-11-28 00:29:10 +1100159 sb800_early_setup();
Kerry She7b7b2c92011-09-08 21:16:19 +0800160
Martin Rothf95911a2017-06-24 21:45:13 -0600161#if IS_ENABLED(CONFIG_SET_FIDVID)
Kerry She7b7b2c92011-09-08 21:16:19 +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);
Kerry She7b7b2c92011-09-08 21:16:19 +0800164 post_code(0x39);
165
Damien Zammit75a3d1f2016-11-28 00:29:10 +1100166 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
167
Elyes HAOUAS023e2842016-10-07 18:07:21 +0200168 if (!warm_reset_detect(0)) { /* BSP is node 0 */
Kerry She7b7b2c92011-09-08 21:16:19 +0800169 init_fidvid_bsp(bsp_apicid, sysinfo->nodes);
170 } else {
Elyes HAOUAS023e2842016-10-07 18:07:21 +0200171 init_fidvid_stage2(bsp_apicid, 0); /* BSP is node 0 */
Kerry She7b7b2c92011-09-08 21:16:19 +0800172 }
173
174 post_code(0x3A);
175
176 /* show final fid and vid */
Elyes HAOUAS6350a2e2016-09-16 20:49:38 +0200177 msr = rdmsr(0xc0010071);
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200178 printk(BIOS_DEBUG, "End FIDVIDMSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
Kerry She7b7b2c92011-09-08 21:16:19 +0800179#endif
180
181 rs780_htinit();
182
183 /* Reset for HT, FIDVID, PLL and errata changes to take affect. */
184 if (!warm_reset_detect(0)) {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800185 printk(BIOS_INFO, "...WARM RESET...\n\n\n");
Kerry She7b7b2c92011-09-08 21:16:19 +0800186 soft_reset();
Jonathan Neuschäferec48c742017-09-29 02:45:31 +0200187 die("After soft_reset - shouldn't see this message!!!\n");
Kerry She7b7b2c92011-09-08 21:16:19 +0800188 }
189
190 post_code(0x3B);
191
192 /* It's the time to set ctrl in sysinfo now; */
193 printk(BIOS_DEBUG, "fill_mem_ctrl()\n");
194 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
195
196 post_code(0x40);
197
Timothy Pearson91e9f672015-03-19 16:44:46 -0500198 timestamp_add_now(TS_BEFORE_INITRAM);
Kerry She7b7b2c92011-09-08 21:16:19 +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();
Kerry She7b7b2c92011-09-08 21:16:19 +0800204 post_code(0x41);
205
Timothy Pearson22564082015-03-27 22:49:18 -0500206 amdmct_cbmem_store_info(sysinfo);
207
Damien Zammit75a3d1f2016-11-28 00:29:10 +1100208 sb800_before_pci_init();
Kerry She7b7b2c92011-09-08 21:16:19 +0800209
210 post_code(0x42);
Kerry She7b7b2c92011-09-08 21:16:19 +0800211}
212
213/**
214 * BOOL AMD_CB_ManualBUIDSwapList(u8 Node, u8 Link, u8 **List)
215 * Description:
216 * This routine is called every time a non-coherent chain is processed.
217 * BUID assignment may be controlled explicitly on a non-coherent chain. Provide a
218 * swap list. The first part of the list controls the BUID assignment and the
219 * second part of the list provides the device to device linking. Device orientation
220 * can be detected automatically, or explicitly. See documentation for more details.
221 *
222 * Automatic non-coherent init assigns BUIDs starting at 1 and incrementing sequentially
223 * based on each device's unit count.
224 *
225 * Parameters:
Martin Rothc3fde7e2014-12-29 22:13:37 -0700226 * @param[in] node = The node on which this chain is located
227 * @param[in] link = The link on the host for this chain
228 * @param[out] List = supply a pointer to a list
Kerry She7b7b2c92011-09-08 21:16:19 +0800229 */
230BOOL AMD_CB_ManualBUIDSwapList (u8 node, u8 link, const u8 **List)
231{
232 static const u8 swaplist[] = {0, 1, 0xFF, 0, 0xFF};
233 /* If the BUID was adjusted in early_ht we need to do the manual override */
234 if ((node == 0) && (link == 0)) { /* BSP SB link */
235 *List = swaplist;
236 return 1;
237 }
238
239 return 0;
240}