blob: 5599a2481177a8a6373f817d6041b68c4507fae5 [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>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110033#include <northbridge/amd/amdk8/raminit.h>
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000034#include "lib/delay.c"
35
Edward O'Callaghan77757c22015-01-04 21:33:39 +110036#include <cpu/x86/lapic.h>
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000037#include "northbridge/amd/amdk8/reset_test.c"
Edward O'Callaghanf2920022014-04-27 00:41:50 +100038#include <superio/ite/common/ite.h>
39#include <superio/ite/it8712f/it8712f.h>
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000040
Edward O'Callaghan77757c22015-01-04 21:33:39 +110041#include <cpu/x86/bist.h>
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000042
43#include "northbridge/amd/amdk8/setup_resource_map.c"
44
45#include "southbridge/amd/rs690/early_setup.c"
46#include "southbridge/amd/sb600/early_setup.c"
47#include "northbridge/amd/amdk8/debug.c" /* After sb600_early_setup.c! */
48
Dennis Wassenberg498c32a2014-10-14 17:29:36 +020049#define SERIAL_DEV PNP_DEV(0x2e, CONFIG_UART_FOR_CONSOLE == 1 ? IT8712F_SP2 : IT8712F_SP1)
Edward O'Callaghan76d8fd62014-05-14 19:15:08 +100050#define GPIO_DEV PNP_DEV(0x2e, IT8712F_GPIO)
Edward O'Callaghanf2920022014-04-27 00:41:50 +100051
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000052/* CAN'T BE REMOVED! crt0.S will use it. I don't know WHY!*/
53static void memreset(int controllers, const struct mem_controller *ctrl)
54{
55}
56
57/* called in raminit_f.c */
58static inline void activate_spd_rom(const struct mem_controller *ctrl)
59{
60}
61
62/*called in raminit_f.c */
63static inline int spd_read_byte(u32 device, u32 address)
64{
65 return smbus_read_byte(device, address);
66}
67
Edward O'Callaghan77757c22015-01-04 21:33:39 +110068#include <northbridge/amd/amdk8/amdk8.h>
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000069#include "northbridge/amd/amdk8/incoherent_ht.c"
70#include "northbridge/amd/amdk8/raminit_f.c"
71#include "northbridge/amd/amdk8/coherent_ht.c"
72#include "lib/generic_sdram.c"
73#include "resourcemap.c"
74#include "cpu/amd/dualcore/dualcore.c"
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000075#include "cpu/amd/model_fxx/init_cpus.c"
76#include "cpu/amd/model_fxx/fidvid.c"
77#include "northbridge/amd/amdk8/early_ht.c"
78
79#define __WARNING__(fmt, arg...) do_printk(BIOS_WARNING ,fmt, ##arg)
80#define __DEBUG__(fmt, arg...) do_printk(BIOS_DEBUG ,fmt, ##arg)
81#define __INFO__(fmt, arg...) do_printk(BIOS_INFO ,fmt, ##arg)
82
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000083void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
84{
85 static const u16 spd_addr[] = { DIMM0, 0, 0, 0, DIMM1, 0, 0, 0, };
86 int needs_reset = 0;
87 u32 bsp_apicid = 0;
88 msr_t msr;
89 struct cpuid_result cpuid1;
Patrick Georgibbc880e2012-11-20 18:20:56 +010090 struct sys_info *sysinfo = &sysinfo_car;
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070091
Josef Kellermannbfa7ee52011-05-11 07:47:43 +000092 if (!cpu_init_detectedx && boot_cpu()) {
93 /* Nothing special needs to be done to find bus 0 */
94 /* Allow the HT devices to be found */
95 enumerate_ht_chain();
96
97 /* sb600_lpc_port80(); */
98 sb600_pci_port80();
99 }
100
101 if (bist == 0) {
102 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
103 }
104
105 enable_rs690_dev8(); // enable CFG access to Dev8, which is the SB P2P Bridge
106 sb600_lpc_init();
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700107#if defined(DUMP_CMOS_RAM) && (DUMP_CMOS_RAM == 0)
108 check_cmos(); // rebooting in case of corrupted cmos !!!!!
109#endif
Edward O'Callaghanf2920022014-04-27 00:41:50 +1000110 ite_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Edward O'Callaghan76d8fd62014-05-14 19:15:08 +1000111 ite_kill_watchdog(GPIO_DEV);
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000112
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000113 console_init();
114#if defined(DUMP_CMOS_RAM) && (DUMP_CMOS_RAM == 1)
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700115 check_cmos(); // rebooting in case of corrupted cmos !!!!!
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000116#endif
117 post_code(0x03);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700118
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000119 /* Halt if there was a built in self test failure */
120 report_bist_failure(bist);
121 __DEBUG__("bsp_apicid=0x%x\n", bsp_apicid);
122
123 setup_sitemp_resource_map();
124
125 setup_coherent_ht_domain();
126
Patrick Georgie1667822012-05-05 15:29:32 +0200127#if CONFIG_LOGICAL_CPUS
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000128 /* It is said that we should start core1 after all core0 launched */
129 wait_all_core0_started();
130 start_other_cores();
131#endif
132 wait_all_aps_started(bsp_apicid);
133
134 ht_setup_chains_x(sysinfo);
135
136 /* run _early_setup before soft-reset. */
137 rs690_early_setup();
138 sb600_early_setup();
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700139
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000140 post_code(0x04);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700141
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000142 /* Check to see if processor is capable of changing FIDVID */
143 /* otherwise it will throw a GP# when reading FIDVID_STATUS */
144 cpuid1 = cpuid(0x80000007);
145 if( (cpuid1.edx & 0x6) == 0x6 ) {
146
147 /* Read FIDVID_STATUS */
148 msr=rdmsr(0xc0010042);
149 __DEBUG__("begin msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
150
151 enable_fid_change();
152 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
153 init_fidvid_bsp(bsp_apicid);
154
155 /* show final fid and vid */
156 msr=rdmsr(0xc0010042);
157 __DEBUG__("end msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
158
159 } else {
160 __DEBUG__("Changing FIDVID not supported\n");
161 }
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700162
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000163 post_code(0x05);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700164
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000165 needs_reset = optimize_link_coherent_ht();
166 needs_reset |= optimize_link_incoherent_ht(sysinfo);
167 rs690_htinit();
168 __DEBUG__("needs_reset=0x%x\n", needs_reset);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700169
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000170 post_code(0x06);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700171
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000172 if (needs_reset) {
173 __INFO__("ht reset -\n");
174 soft_reset();
175 }
176
177 allow_all_aps_stop(bsp_apicid);
178
179 /* It's the time to set ctrl now; */
180 __DEBUG__("sysinfo->nodes: %2x sysinfo->ctrl: %p spd_addr: %p\n",
181 sysinfo->nodes, sysinfo->ctrl, spd_addr);
182 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700183
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000184 post_code(0x07);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700185
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000186 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700187
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000188 post_code(0x08);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700189
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000190 rs690_before_pci_init(); // does nothing
191 sb600_before_pci_init();
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700192
Josef Kellermannbfa7ee52011-05-11 07:47:43 +0000193 post_cache_as_ram();
194}