blob: c78f0d24a60e9c1e9884dd8a0bc399c677fec2be [file] [log] [blame]
Maggie Li19ead962008-12-09 21:52:42 +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.
Maggie Li19ead962008-12-09 21:52:42 +000014 */
15
Maggie Li19ead962008-12-09 21:52:42 +000016#include <stdint.h>
Patrick Georgi12aba822009-04-30 07:07:22 +000017#include <string.h>
Maggie Li19ead962008-12-09 21:52:42 +000018#include <device/pci_def.h>
19#include <arch/io.h>
20#include <device/pnp_def.h>
Maggie Li19ead962008-12-09 21:52:42 +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>
Maggie Li19ead962008-12-09 21:52:42 +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>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110027#include <cpu/x86/lapic.h>
Maggie Li19ead962008-12-09 21:52:42 +000028#include "northbridge/amd/amdk8/reset_test.c"
Patrick Georgi9bd9a902010-11-20 10:31:00 +000029#include <spd.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110030#include <cpu/x86/bist.h>
Maggie Li19ead962008-12-09 21:52:42 +000031#include "northbridge/amd/amdk8/setup_resource_map.c"
stepan836ae292010-12-08 05:42:47 +000032#include "southbridge/amd/rs690/early_setup.c"
33#include "southbridge/amd/sb600/early_setup.c"
34#include "northbridge/amd/amdk8/debug.c" /* After sb600/early_setup.c! */
Maggie Li19ead962008-12-09 21:52:42 +000035
Uwe Hermann7b997052010-11-21 22:47:22 +000036static void memreset(int controllers, const struct mem_controller *ctrl) { }
37static void activate_spd_rom(const struct mem_controller *ctrl) { }
Maggie Li19ead962008-12-09 21:52:42 +000038
Maggie Li19ead962008-12-09 21:52:42 +000039static inline int spd_read_byte(u32 device, u32 address)
40{
41 return smbus_read_byte(device, address);
42}
43
Edward O'Callaghan77757c22015-01-04 21:33:39 +110044#include <northbridge/amd/amdk8/amdk8.h>
Maggie Li19ead962008-12-09 21:52:42 +000045#include "northbridge/amd/amdk8/incoherent_ht.c"
Myles Watson17257032009-06-04 20:18:42 +000046#include "northbridge/amd/amdk8/raminit_f.c"
Maggie Li19ead962008-12-09 21:52:42 +000047#include "northbridge/amd/amdk8/coherent_ht.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +000048#include "lib/generic_sdram.c"
Maggie Li19ead962008-12-09 21:52:42 +000049#include "resourcemap.c"
Maggie Li19ead962008-12-09 21:52:42 +000050#include "cpu/amd/dualcore/dualcore.c"
Maggie Li19ead962008-12-09 21:52:42 +000051#include "cpu/amd/model_fxx/init_cpus.c"
Maggie Li19ead962008-12-09 21:52:42 +000052#include "cpu/amd/model_fxx/fidvid.c"
Maggie Li19ead962008-12-09 21:52:42 +000053#include "northbridge/amd/amdk8/early_ht.c"
54
Maggie Li19ead962008-12-09 21:52:42 +000055void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
56{
Maggie Li19ead962008-12-09 21:52:42 +000057 static const u16 spd_addr[] = { DIMM0, 0, 0, 0, DIMM1, 0, 0, 0, };
58 int needs_reset = 0;
59 u32 bsp_apicid = 0;
60 msr_t msr;
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +000061 struct cpuid_result cpuid1;
Patrick Georgibbc880e2012-11-20 18:20:56 +010062 struct sys_info *sysinfo = &sysinfo_car;
Maggie Li19ead962008-12-09 21:52:42 +000063
Patrick Georgi2bd91002010-03-18 16:46:50 +000064 if (!cpu_init_detectedx && boot_cpu()) {
Patrick Georgi776b85b2010-03-18 16:18:58 +000065 /* Nothing special needs to be done to find bus 0 */
66 /* Allow the HT devices to be found */
67 enumerate_ht_chain();
Patrick Georgi776b85b2010-03-18 16:18:58 +000068 sb600_lpc_port80();
69 /* sb600_pci_port80(); */
70 }
71
Uwe Hermann7b997052010-11-21 22:47:22 +000072 if (bist == 0)
Maggie Li19ead962008-12-09 21:52:42 +000073 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Maggie Li19ead962008-12-09 21:52:42 +000074
75 enable_rs690_dev8();
76 sb600_lpc_init();
77
78 /* Pistachio used a FPGA to enable serial debug instead of a SIO
Uwe Hermannb015d022010-09-24 18:18:20 +000079 * and it doesn't require any special setup. */
Uwe Hermannb015d022010-09-24 18:18:20 +000080
Maggie Li19ead962008-12-09 21:52:42 +000081 console_init();
82
83 post_code(0x03);
84
85 /* Halt if there was a built in self test failure */
86 report_bist_failure(bist);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000087 printk(BIOS_DEBUG, "bsp_apicid=0x%x\n", bsp_apicid);
Maggie Li19ead962008-12-09 21:52:42 +000088
89 setup_pistachio_resource_map();
90
91 setup_coherent_ht_domain();
92
Patrick Georgie1667822012-05-05 15:29:32 +020093#if CONFIG_LOGICAL_CPUS
Maggie Li19ead962008-12-09 21:52:42 +000094 /* It is said that we should start core1 after all core0 launched */
95 wait_all_core0_started();
96 start_other_cores();
97#endif
98 wait_all_aps_started(bsp_apicid);
99
100 /* it will set up chains and store link pair for optimization later,
101 * it will init sblnk and sbbusn, nodes, sbdn */
102 ht_setup_chains_x(sysinfo);
103
104 /* run _early_setup before soft-reset. */
105 rs690_early_setup();
106 sb600_early_setup();
107
108 post_code(0x04);
109
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000110 /* 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) {
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000114 /* Read FIDVID_STATUS */
115 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);
Maggie Li19ead962008-12-09 21:52:42 +0000117
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000118 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 */
123 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);
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000125 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000126 printk(BIOS_DEBUG, "Changing FIDVID not supported\n");
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000127 }
Maggie Li19ead962008-12-09 21:52:42 +0000128
129 post_code(0x05);
130
131 needs_reset = optimize_link_coherent_ht();
132 needs_reset |= optimize_link_incoherent_ht(sysinfo);
Carl-Daniel Hailfinger33f96332008-12-23 17:20:46 +0000133 rs690_htinit();
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000134 printk(BIOS_DEBUG, "needs_reset=0x%x\n", needs_reset);
Maggie Li19ead962008-12-09 21:52:42 +0000135
136 post_code(0x06);
137
138 if (needs_reset) {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800139 printk(BIOS_INFO, "ht reset -\n");
Maggie Li19ead962008-12-09 21:52:42 +0000140 soft_reset();
141 }
142
143 allow_all_aps_stop(bsp_apicid);
144
145 /* It's the time to set ctrl now; */
Myles Watson08e0fb82010-03-22 16:33:25 +0000146 printk(BIOS_DEBUG, "sysinfo->nodes: %2x sysinfo->ctrl: %p spd_addr: %p\n",
Maggie Li19ead962008-12-09 21:52:42 +0000147 sysinfo->nodes, sysinfo->ctrl, spd_addr);
148 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
149
150 post_code(0x07);
151
152 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
153
154 post_code(0x08);
155
156 rs690_before_pci_init();
157 sb600_before_pci_init();
158
159 post_cache_as_ram();
160}