blob: e052d923a57279fbf014efaedd854b27efd452d1 [file] [log] [blame]
Daniel Toussaintda6d92b2009-04-06 13:38:54 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008 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.
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000014 */
15
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000016#include <stdint.h>
Patrick Georgi12aba822009-04-30 07:07:22 +000017#include <string.h>
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000018#include <device/pci_def.h>
19#include <arch/io.h>
20#include <device/pnp_def.h>
Daniel Toussaintda6d92b2009-04-06 13:38:54 +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>
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000024#include <cpu/amd/model_fxx_rev.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110025#include <northbridge/amd/amdk8/raminit.h>
Edward O'Callaghanebe3a7a2015-01-05 00:27:54 +110026#include <delay.h>
Patrick Georgi9bd9a902010-11-20 10:31:00 +000027#include <spd.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110028#include <cpu/x86/lapic.h>
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000029#include "northbridge/amd/amdk8/reset_test.c"
30#include "northbridge/amd/amdk8/debug.c"
Edward O'Callaghanf2920022014-04-27 00:41:50 +100031#include <superio/ite/common/ite.h>
32#include <superio/ite/it8712f/it8712f.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110033#include <cpu/x86/bist.h>
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000034#include "northbridge/amd/amdk8/setup_resource_map.c"
stepan836ae292010-12-08 05:42:47 +000035#include "southbridge/amd/rs690/early_setup.c"
36#include "southbridge/amd/sb600/early_setup.c"
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000037
Edward O'Callaghanf2920022014-04-27 00:41:50 +100038#define SERIAL_DEV PNP_DEV(0x2e, IT8712F_SP1)
Edward O'Callaghan76d8fd62014-05-14 19:15:08 +100039#define GPIO_DEV PNP_DEV(0x2e, IT8712F_GPIO)
Edward O'Callaghanf2920022014-04-27 00:41:50 +100040
Uwe Hermann7b997052010-11-21 22:47:22 +000041static void memreset(int controllers, const struct mem_controller *ctrl) { }
42static void activate_spd_rom(const struct mem_controller *ctrl) { }
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000043
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000044static inline int spd_read_byte(u32 device, u32 address)
45{
46 return smbus_read_byte(device, address);
47}
48
Edward O'Callaghan77757c22015-01-04 21:33:39 +110049#include <northbridge/amd/amdk8/amdk8.h>
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000050#include "northbridge/amd/amdk8/incoherent_ht.c"
Myles Watson17257032009-06-04 20:18:42 +000051#include "northbridge/amd/amdk8/raminit_f.c"
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000052#include "northbridge/amd/amdk8/coherent_ht.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +000053#include "lib/generic_sdram.c"
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000054#include "resourcemap.c"
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000055#include "cpu/amd/dualcore/dualcore.c"
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000056#include "cpu/amd/model_fxx/init_cpus.c"
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000057#include "cpu/amd/model_fxx/fidvid.c"
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000058#include "northbridge/amd/amdk8/early_ht.c"
59
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000060void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
61{
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000062 static const u16 spd_addr[] = { DIMM0, 0, 0, 0, DIMM1, 0, 0, 0, };
63 int needs_reset = 0;
64 u32 bsp_apicid = 0;
65 msr_t msr;
66 struct cpuid_result cpuid1;
Patrick Georgibbc880e2012-11-20 18:20:56 +010067 struct sys_info *sysinfo = &sysinfo_car;
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000068
Patrick Georgi2bd91002010-03-18 16:46:50 +000069 if (!cpu_init_detectedx && boot_cpu()) {
Patrick Georgi776b85b2010-03-18 16:18:58 +000070 /* Nothing special needs to be done to find bus 0 */
71 /* Allow the HT devices to be found */
72 enumerate_ht_chain();
Patrick Georgi776b85b2010-03-18 16:18:58 +000073 /* sb600_lpc_port80(); */
74 sb600_pci_port80();
75 }
76
Uwe Hermann7b997052010-11-21 22:47:22 +000077 if (bist == 0)
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000078 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000079
80 enable_rs690_dev8();
81 sb600_lpc_init();
82
Edward O'Callaghanf2920022014-04-27 00:41:50 +100083 ite_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Edward O'Callaghan76d8fd62014-05-14 19:15:08 +100084 ite_kill_watchdog(GPIO_DEV);
Uwe Hermannb015d022010-09-24 18:18:20 +000085
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000086 console_init();
87
88 /* Halt if there was a built in self test failure */
89 report_bist_failure(bist);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000090 printk(BIOS_DEBUG, "bsp_apicid=0x%x\n", bsp_apicid);
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000091
92 setup_tim8690_resource_map();
93
94 setup_coherent_ht_domain();
95
Patrick Georgie1667822012-05-05 15:29:32 +020096#if CONFIG_LOGICAL_CPUS
Daniel Toussaintda6d92b2009-04-06 13:38:54 +000097 /* It is said that we should start core1 after all core0 launched */
98 wait_all_core0_started();
99 start_other_cores();
100#endif
101 wait_all_aps_started(bsp_apicid);
102
103 ht_setup_chains_x(sysinfo);
104
105 /* run _early_setup before soft-reset. */
106 rs690_early_setup();
107 sb600_early_setup();
108
109 /* Check to see if processor is capable of changing FIDVID */
110 /* otherwise it will throw a GP# when reading FIDVID_STATUS */
111 cpuid1 = cpuid(0x80000007);
Uwe Hermann7b997052010-11-21 22:47:22 +0000112 if ((cpuid1.edx & 0x6) == 0x6 ) {
Daniel Toussaintda6d92b2009-04-06 13:38:54 +0000113 /* Read FIDVID_STATUS */
114 msr=rdmsr(0xc0010042);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000115 printk(BIOS_DEBUG, "begin msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
Daniel Toussaintda6d92b2009-04-06 13:38:54 +0000116
117 enable_fid_change();
118 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
119 init_fidvid_bsp(bsp_apicid);
120
121 /* show final fid and vid */
122 msr=rdmsr(0xc0010042);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000123 printk(BIOS_DEBUG, "end msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
Daniel Toussaintda6d92b2009-04-06 13:38:54 +0000124 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000125 printk(BIOS_DEBUG, "Changing FIDVID not supported\n");
Daniel Toussaintda6d92b2009-04-06 13:38:54 +0000126 }
127
128 needs_reset = optimize_link_coherent_ht();
129 needs_reset |= optimize_link_incoherent_ht(sysinfo);
130 rs690_htinit();
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000131 printk(BIOS_DEBUG, "needs_reset=0x%x\n", needs_reset);
Daniel Toussaintda6d92b2009-04-06 13:38:54 +0000132
Daniel Toussaintda6d92b2009-04-06 13:38:54 +0000133 if (needs_reset) {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800134 printk(BIOS_INFO, "ht reset -\n");
Daniel Toussaintda6d92b2009-04-06 13:38:54 +0000135 soft_reset();
136 }
137
138 allow_all_aps_stop(bsp_apicid);
139
140 /* It's the time to set ctrl now; */
Myles Watson08e0fb82010-03-22 16:33:25 +0000141 printk(BIOS_DEBUG, "sysinfo->nodes: %2x sysinfo->ctrl: %p spd_addr: %p\n",
Daniel Toussaintda6d92b2009-04-06 13:38:54 +0000142 sysinfo->nodes, sysinfo->ctrl, spd_addr);
143 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
144 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
145
146 rs690_before_pci_init();
147 sb600_before_pci_init();
148
149 post_cache_as_ram();
150}