blob: 6ae4989d15488671f13d28f7fb3ea9f6c9164d61 [file] [log] [blame]
Josef Kellermannbfa7ee52011-05-11 07:47:43 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
5 * Copyright (C) 2010 Siemens AG, Inc.
6 * (Written by Josef Kellermann <joseph.kellermann@heitec.de> for Siemens AG, Inc.)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
Paul Menzela46a7122013-02-23 18:37:27 +010019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000020 */
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070021
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000022#include <stdint.h>
23#include <string.h>
24#include <device/pci_def.h>
25#include <arch/io.h>
26#include <device/pnp_def.h>
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000027#include <cpu/x86/lapic.h>
28#include <pc80/mc146818rtc.h>
29#include <console/console.h>
Patrick Georgif771e562014-05-03 09:12:55 +020030#include <spd.h>
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000031
32#include <cpu/amd/model_fxx_rev.h>
33#include "northbridge/amd/amdk8/raminit.h"
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000034#include "lib/delay.c"
35
Kyösti Mälkkic66f1cb2013-08-12 16:09:00 +030036#include "cpu/x86/lapic.h"
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000037#include "northbridge/amd/amdk8/reset_test.c"
38#include "superio/ite/it8712f/early_serial.c"
39
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000040#include "cpu/x86/bist.h"
41
42#include "northbridge/amd/amdk8/setup_resource_map.c"
43
44#include "southbridge/amd/rs690/early_setup.c"
45#include "southbridge/amd/sb600/early_setup.c"
46#include "northbridge/amd/amdk8/debug.c" /* After sb600_early_setup.c! */
47
48/* CAN'T BE REMOVED! crt0.S will use it. I don't know WHY!*/
49static void memreset(int controllers, const struct mem_controller *ctrl)
50{
51}
52
53/* called in raminit_f.c */
54static inline void activate_spd_rom(const struct mem_controller *ctrl)
55{
56}
57
58/*called in raminit_f.c */
59static inline int spd_read_byte(u32 device, u32 address)
60{
61 return smbus_read_byte(device, address);
62}
63
64#include "northbridge/amd/amdk8/amdk8.h"
65#include "northbridge/amd/amdk8/incoherent_ht.c"
66#include "northbridge/amd/amdk8/raminit_f.c"
67#include "northbridge/amd/amdk8/coherent_ht.c"
68#include "lib/generic_sdram.c"
69#include "resourcemap.c"
70#include "cpu/amd/dualcore/dualcore.c"
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000071#include "cpu/amd/model_fxx/init_cpus.c"
72#include "cpu/amd/model_fxx/fidvid.c"
73#include "northbridge/amd/amdk8/early_ht.c"
74
75#define __WARNING__(fmt, arg...) do_printk(BIOS_WARNING ,fmt, ##arg)
76#define __DEBUG__(fmt, arg...) do_printk(BIOS_DEBUG ,fmt, ##arg)
77#define __INFO__(fmt, arg...) do_printk(BIOS_INFO ,fmt, ##arg)
78
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000079void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
80{
81 static const u16 spd_addr[] = { DIMM0, 0, 0, 0, DIMM1, 0, 0, 0, };
82 int needs_reset = 0;
83 u32 bsp_apicid = 0;
84 msr_t msr;
85 struct cpuid_result cpuid1;
Patrick Georgibbc880e2012-11-20 18:20:56 +010086 struct sys_info *sysinfo = &sysinfo_car;
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070087
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000088 if (!cpu_init_detectedx && boot_cpu()) {
89 /* Nothing special needs to be done to find bus 0 */
90 /* Allow the HT devices to be found */
91 enumerate_ht_chain();
92
93 /* sb600_lpc_port80(); */
94 sb600_pci_port80();
95 }
96
97 if (bist == 0) {
98 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
99 }
100
101 enable_rs690_dev8(); // enable CFG access to Dev8, which is the SB P2P Bridge
102 sb600_lpc_init();
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700103#if defined(DUMP_CMOS_RAM) && (DUMP_CMOS_RAM == 0)
104 check_cmos(); // rebooting in case of corrupted cmos !!!!!
105#endif
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000106 /* it8712f_enable_serial does not use its 1st parameter. */
107 it8712f_enable_serial(0, CONFIG_TTYS0_BASE);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700108 it8712f_kill_watchdog();
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000109
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000110 console_init();
111#if defined(DUMP_CMOS_RAM) && (DUMP_CMOS_RAM == 1)
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700112 check_cmos(); // rebooting in case of corrupted cmos !!!!!
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000113#endif
114 post_code(0x03);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700115
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000116 /* Halt if there was a built in self test failure */
117 report_bist_failure(bist);
118 __DEBUG__("bsp_apicid=0x%x\n", bsp_apicid);
119
120 setup_sitemp_resource_map();
121
122 setup_coherent_ht_domain();
123
Patrick Georgie1667822012-05-05 15:29:32 +0200124#if CONFIG_LOGICAL_CPUS
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000125 /* It is said that we should start core1 after all core0 launched */
126 wait_all_core0_started();
127 start_other_cores();
128#endif
129 wait_all_aps_started(bsp_apicid);
130
131 ht_setup_chains_x(sysinfo);
132
133 /* run _early_setup before soft-reset. */
134 rs690_early_setup();
135 sb600_early_setup();
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700136
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000137 post_code(0x04);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700138
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000139 /* Check to see if processor is capable of changing FIDVID */
140 /* otherwise it will throw a GP# when reading FIDVID_STATUS */
141 cpuid1 = cpuid(0x80000007);
142 if( (cpuid1.edx & 0x6) == 0x6 ) {
143
144 /* Read FIDVID_STATUS */
145 msr=rdmsr(0xc0010042);
146 __DEBUG__("begin msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
147
148 enable_fid_change();
149 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
150 init_fidvid_bsp(bsp_apicid);
151
152 /* show final fid and vid */
153 msr=rdmsr(0xc0010042);
154 __DEBUG__("end msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
155
156 } else {
157 __DEBUG__("Changing FIDVID not supported\n");
158 }
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700159
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000160 post_code(0x05);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700161
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000162 needs_reset = optimize_link_coherent_ht();
163 needs_reset |= optimize_link_incoherent_ht(sysinfo);
164 rs690_htinit();
165 __DEBUG__("needs_reset=0x%x\n", needs_reset);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700166
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000167 post_code(0x06);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700168
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000169 if (needs_reset) {
170 __INFO__("ht reset -\n");
171 soft_reset();
172 }
173
174 allow_all_aps_stop(bsp_apicid);
175
176 /* It's the time to set ctrl now; */
177 __DEBUG__("sysinfo->nodes: %2x sysinfo->ctrl: %p spd_addr: %p\n",
178 sysinfo->nodes, sysinfo->ctrl, spd_addr);
179 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700180
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000181 post_code(0x07);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700182
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000183 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700184
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000185 post_code(0x08);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700186
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000187 rs690_before_pci_init(); // does nothing
188 sb600_before_pci_init();
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700189
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000190 post_cache_as_ram();
191}
192