blob: bbbe869e35936ece6f2e832f11f76a59082f9054 [file] [log] [blame]
Zheng Baodec279f2010-03-16 01:42:50 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2010 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.
Zheng Baodec279f2010-03-16 01:42:50 +000014 */
15
Zheng Baodec279f2010-03-16 01:42:50 +000016#include <stdint.h>
17#include <string.h>
18#include <device/pci_def.h>
19#include <arch/io.h>
20#include <device/pnp_def.h>
Zheng Baodec279f2010-03-16 01:42:50 +000021#include <cpu/x86/lapic.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000022#include <pc80/mc146818rtc.h>
Patrick Georgi12584e22010-05-08 09:14:51 +000023#include <console/console.h>
Patrick Georgi9bd9a902010-11-20 10:31:00 +000024#include <spd.h>
Zheng Baodec279f2010-03-16 01:42:50 +000025#include <cpu/amd/model_fxx_rev.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110026#include <northbridge/amd/amdk8/raminit.h>
Edward O'Callaghanebe3a7a2015-01-05 00:27:54 +110027#include <delay.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110028#include <cpu/x86/lapic.h>
Zheng Baodec279f2010-03-16 01:42:50 +000029#include "northbridge/amd/amdk8/reset_test.c"
Edward O'Callaghanf2920022014-04-27 00:41:50 +100030#include <superio/ite/common/ite.h>
31#include <superio/ite/it8718f/it8718f.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110032#include <cpu/x86/bist.h>
Zheng Baodec279f2010-03-16 01:42:50 +000033#include "northbridge/amd/amdk8/setup_resource_map.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110034#include <southbridge/amd/sb700/sb700.h>
35#include <southbridge/amd/sb700/smbus.h>
stepan836ae292010-12-08 05:42:47 +000036#include "northbridge/amd/amdk8/debug.c" /* After sb700/early_setup.c! */
Zheng Baodec279f2010-03-16 01:42:50 +000037
Damien Zammit75a3d1f2016-11-28 00:29:10 +110038unsigned get_sbdn(unsigned bus);
39
Edward O'Callaghanf2920022014-04-27 00:41:50 +100040#define SERIAL_DEV PNP_DEV(0x2e, IT8718F_SP1)
41
Uwe Hermann7b997052010-11-21 22:47:22 +000042static void memreset(int controllers, const struct mem_controller *ctrl) { }
43static void activate_spd_rom(const struct mem_controller *ctrl) { }
Zheng Baodec279f2010-03-16 01:42:50 +000044
Zheng Baodec279f2010-03-16 01:42:50 +000045static inline int spd_read_byte(u32 device, u32 address)
46{
efdesign9800c8c4a2011-07-20 12:37:58 -060047 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
Zheng Baodec279f2010-03-16 01:42:50 +000048}
49
Damien Zammit75a3d1f2016-11-28 00:29:10 +110050#include "southbridge/amd/rs780/early_setup.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110051#include <northbridge/amd/amdk8/amdk8.h>
Zheng Baodec279f2010-03-16 01:42:50 +000052#include "northbridge/amd/amdk8/incoherent_ht.c"
53#include "northbridge/amd/amdk8/raminit_f.c"
54#include "northbridge/amd/amdk8/coherent_ht.c"
55#include "lib/generic_sdram.c"
56#include "resourcemap.c"
Zheng Baodec279f2010-03-16 01:42:50 +000057#include "cpu/amd/dualcore/dualcore.c"
Zheng Baodec279f2010-03-16 01:42:50 +000058#include "cpu/amd/model_fxx/init_cpus.c"
Zheng Baodec279f2010-03-16 01:42:50 +000059#include "cpu/amd/model_fxx/fidvid.c"
Zheng Baodec279f2010-03-16 01:42:50 +000060#include "northbridge/amd/amdk8/early_ht.c"
61
Zheng Baodec279f2010-03-16 01:42:50 +000062void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
63{
Zheng Baodec279f2010-03-16 01:42:50 +000064 static const u16 spd_addr[] = { DIMM0, 0, 0, 0, DIMM1, 0, 0, 0, };
65 int needs_reset = 0;
66 u32 bsp_apicid = 0;
67 msr_t msr;
68 struct cpuid_result cpuid1;
Patrick Georgibbc880e2012-11-20 18:20:56 +010069 struct sys_info *sysinfo = &sysinfo_car;
Zheng Baodec279f2010-03-16 01:42:50 +000070
Patrick Georgi2bd91002010-03-18 16:46:50 +000071 if (!cpu_init_detectedx && boot_cpu()) {
Patrick Georgi776b85b2010-03-18 16:18:58 +000072 /* Nothing special needs to be done to find bus 0 */
73 /* Allow the HT devices to be found */
74 enumerate_ht_chain();
Zheng Baoc3422232011-03-28 03:33:10 +000075 /* sb7xx_51xx_lpc_port80(); */
76 sb7xx_51xx_pci_port80();
Patrick Georgi776b85b2010-03-18 16:18:58 +000077 }
78
Uwe Hermann7b997052010-11-21 22:47:22 +000079 if (bist == 0)
Zheng Baodec279f2010-03-16 01:42:50 +000080 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Zheng Baodec279f2010-03-16 01:42:50 +000081
82 enable_rs780_dev8();
Zheng Baoc3422232011-03-28 03:33:10 +000083 sb7xx_51xx_lpc_init();
Zheng Baodec279f2010-03-16 01:42:50 +000084
Edward O'Callaghanf2920022014-04-27 00:41:50 +100085 ite_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Uwe Hermannb015d022010-09-24 18:18:20 +000086
Zheng Baodec279f2010-03-16 01:42:50 +000087 console_init();
88
89 /* Halt if there was a built in self test failure */
90 report_bist_failure(bist);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000091 printk(BIOS_DEBUG, "bsp_apicid=0x%x\n", bsp_apicid);
Zheng Baodec279f2010-03-16 01:42:50 +000092
93 setup_mahogany_resource_map();
94
95 setup_coherent_ht_domain();
96
Patrick Georgie1667822012-05-05 15:29:32 +020097#if CONFIG_LOGICAL_CPUS
Zheng Baodec279f2010-03-16 01:42:50 +000098 /* It is said that we should start core1 after all core0 launched */
99 wait_all_core0_started();
100 start_other_cores();
101#endif
102 wait_all_aps_started(bsp_apicid);
103
104 ht_setup_chains_x(sysinfo);
105
106 /* run _early_setup before soft-reset. */
107 rs780_early_setup();
Zheng Baoc3422232011-03-28 03:33:10 +0000108 sb7xx_51xx_early_setup();
Zheng Baodec279f2010-03-16 01:42:50 +0000109
110 /* Check to see if processor is capable of changing FIDVID */
111 /* otherwise it will throw a GP# when reading FIDVID_STATUS */
112 cpuid1 = cpuid(0x80000007);
Uwe Hermann7b997052010-11-21 22:47:22 +0000113 if ((cpuid1.edx & 0x6) == 0x6) {
Zheng Baodec279f2010-03-16 01:42:50 +0000114 /* Read FIDVID_STATUS */
Elyes HAOUAS6350a2e2016-09-16 20:49:38 +0200115 msr = rdmsr(0xc0010042);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000116 printk(BIOS_DEBUG, "begin msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
Zheng Baodec279f2010-03-16 01:42:50 +0000117
118 enable_fid_change();
119 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
120 init_fidvid_bsp(bsp_apicid);
121
122 /* show final fid and vid */
Elyes HAOUAS6350a2e2016-09-16 20:49:38 +0200123 msr = rdmsr(0xc0010042);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000124 printk(BIOS_DEBUG, "end msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
Zheng Baodec279f2010-03-16 01:42:50 +0000125 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000126 printk(BIOS_DEBUG, "Changing FIDVID not supported\n");
Zheng Baodec279f2010-03-16 01:42:50 +0000127 }
128
129 needs_reset = optimize_link_coherent_ht();
130 needs_reset |= optimize_link_incoherent_ht(sysinfo);
131 rs780_htinit();
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000132 printk(BIOS_DEBUG, "needs_reset=0x%x\n", needs_reset);
Zheng Baodec279f2010-03-16 01:42:50 +0000133
134 if (needs_reset) {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800135 printk(BIOS_INFO, "ht reset -\n");
Zheng Baodec279f2010-03-16 01:42:50 +0000136 soft_reset();
137 }
138
139 allow_all_aps_stop(bsp_apicid);
140
141 /* It's the time to set ctrl now; */
Myles Watson08e0fb82010-03-22 16:33:25 +0000142 printk(BIOS_DEBUG, "sysinfo->nodes: %2x sysinfo->ctrl: %p spd_addr: %p\n",
Zheng Baodec279f2010-03-16 01:42:50 +0000143 sysinfo->nodes, sysinfo->ctrl, spd_addr);
144 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
145 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
146
147 rs780_before_pci_init();
Zheng Baoc3422232011-03-28 03:33:10 +0000148 sb7xx_51xx_before_pci_init();
Zheng Baodec279f2010-03-16 01:42:50 +0000149
150 post_cache_as_ram();
151}