blob: 56ee31b27f79b6abc9a0ac08028ba8f69a9e6a78 [file] [log] [blame]
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2006 Tyan
5 * Copyright (C) 2006 AMD
6 * Written by Yinghai Lu <yinghailu@gmail.com> for Tyan and AMD.
7 *
8 * Copyright (C) 2007 University of Mannheim
9 * Written by Philipp Degler <pdegler@rumms.uni-mannheim.de> for University of Mannheim
10 * Copyright (C) 2009 University of Heidelberg
11 * Written by Mondrian Nuessle <nuessle@uni-heidelberg.de> for University of Heidelberg
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000028#define FAM10_SCAN_PCI_BUS 0
29#define FAM10_ALLOCATE_IO_RANGE 1
30
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000031#include <stdint.h>
32#include <string.h>
33#include <device/pci_def.h>
34#include <device/pci_ids.h>
35#include <arch/io.h>
36#include <device/pnp_def.h>
37#include <arch/romcc_io.h>
38#include <cpu/x86/lapic.h>
39#include "option_table.h"
40#include <console/console.h>
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000041#include <cpu/amd/model_10xxx_rev.h>
stepan836ae292010-12-08 05:42:47 +000042#include "southbridge/broadcom/bcm5785/early_smbus.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000043#include "northbridge/amd/amdfam10/raminit.h"
44#include "northbridge/amd/amdfam10/amdfam10.h"
Patrick Georgid0835952010-10-05 09:07:10 +000045#include <lib.h>
Uwe Hermann26535d62010-11-20 20:36:40 +000046#include <spd.h>
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000047#include "cpu/amd/model_10xxx/apic_timer.c"
48#include "lib/delay.c"
49#include "cpu/x86/lapic/boot_cpu.c"
50#include "northbridge/amd/amdfam10/reset_test.c"
stepan8301d832010-12-08 07:07:33 +000051#include "superio/serverengines/pilot/early_serial.c"
52#include "superio/serverengines/pilot/early_init.c"
53#include "superio/nsc/pc87417/early_serial.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000054#include "cpu/x86/bist.h"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000055#include "northbridge/amd/amdfam10/debug.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000056#include "cpu/x86/mtrr/earlymtrr.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000057//#include "northbridge/amd/amdfam10/setup_resource_map.c"
stepan836ae292010-12-08 05:42:47 +000058#include "southbridge/broadcom/bcm5785/early_setup.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000059
60#define SERIAL_DEV PNP_DEV(0x2e, PILOT_SP1)
61#define RTC_DEV PNP_DEV(0x4e, PC87417_RTC)
62
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000063static inline void activate_spd_rom(const struct mem_controller *ctrl)
64{
65 u8 val;
66 outb(0x3d, 0x0cd6);
67 outb(0x87, 0x0cd7);
68
69 outb(0x44, 0xcd6);
70 val = inb(0xcd7);
71 outb((val & ~3) | ctrl->spd_switch_addr, 0xcd7);
72}
73
74static inline int spd_read_byte(unsigned device, unsigned address)
75{
76 return smbus_read_byte(device, address);
77}
78
79#include "northbridge/amd/amdfam10/amdfam10.h"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000080#include "northbridge/amd/amdfam10/raminit_sysinfo_in_ram.c"
stepan8301d832010-12-08 07:07:33 +000081#include "northbridge/amd/amdfam10/pci.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000082#include "cpu/amd/quadcore/quadcore.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000083#include "cpu/amd/car/post_cache_as_ram.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000084#include "cpu/amd/microcode/microcode.c"
85#include "cpu/amd/model_10xxx/update_microcode.c"
86#include "cpu/amd/model_10xxx/init_cpus.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000087#include "northbridge/amd/amdfam10/early_ht.c"
88
Uwe Hermann26535d62010-11-20 20:36:40 +000089static const u8 spd_addr[] = {
90 // switch addr, 1A addr, 2A addr, 3A addr, 4A addr, 1B addr, 2B addr, 3B addr 4B addr
91 //first node
92 RC00, DIMM0, DIMM2, 0, 0, DIMM1, DIMM3, 0, 0,
93#if CONFIG_MAX_PHYSICAL_CPUS > 1
94 //second node
95 RC01, DIMM0, DIMM2, 0, 0, DIMM1, DIMM3, 0, 0,
96#endif
97};
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000098
99void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
100{
101 struct sys_info *sysinfo = (struct sys_info *)(CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);
Uwe Hermann7b997052010-11-21 22:47:22 +0000102 u32 bsp_apicid = 0, val;
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000103 msr_t msr;
104
105 if (!cpu_init_detectedx && boot_cpu()) {
Uwe Hermann7b997052010-11-21 22:47:22 +0000106 /* Nothing special needs to be done to find bus 0 */
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000107 /* Allow the HT devices to be found */
108 /* mov bsp to bus 0xff when > 8 nodes */
109 set_bsp_node_CHtExtNodeCfgEn();
110 enumerate_ht_chain();
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000111 bcm5785_enable_lpc();
Uwe Hermann7b997052010-11-21 22:47:22 +0000112 pc87417_enable_dev(RTC_DEV); /* Enable RTC */
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000113 }
114
115 post_code(0x30);
116
Uwe Hermann7b997052010-11-21 22:47:22 +0000117 if (bist == 0)
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000118 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000119
120 pilot_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
121
122 uart_init();
123
124 /* Halt if there was a built in self test failure */
125 report_bist_failure(bist);
126
127 console_init();
128 pilot_early_init(SERIAL_DEV); //config port is being taken from SERIAL_DEV
129
130 val = cpuid_eax(1);
131 printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
132 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
133 printk(BIOS_DEBUG, "bsp_apicid = %02x\n", bsp_apicid);
134 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
135
136 /* Setup sysinfo defaults */
137 set_sysinfo_in_ram(0);
138
139 update_microcode(val);
140 post_code(0x33);
141
142 cpuSetAMDMSR();
143 post_code(0x34);
144
145 amd_ht_init(sysinfo);
146 post_code(0x35);
147
148 /* Setup nodes PCI space and start core 0 AP init. */
149 finalize_node_setup(sysinfo);
150
151 post_code(0x36);
152
153 /* wait for all the APs core0 started by finalize_node_setup. */
154 /* FIXME: A bunch of cores are going to start output to serial at once.
155 * It would be nice to fixup prink spinlocks for ROM XIP mode.
156 * I think it could be done by putting the spinlock flag in the cache
157 * of the BSP located right after sysinfo.
158 */
159
160 wait_all_core0_started();
161
162#if CONFIG_LOGICAL_CPUS==1
163 /* Core0 on each node is configured. Now setup any additional cores. */
164 printk(BIOS_DEBUG, "start_other_cores()\n");
165 start_other_cores();
166 post_code(0x37);
167 wait_all_other_cores_started(bsp_apicid);
168#endif
169
Patrick Georgi76e81522010-11-16 21:25:29 +0000170#if CONFIG_SET_FIDVID
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000171 msr = rdmsr(0xc0010071);
172 printk(BIOS_DEBUG, "\nBegin FIDVID MSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
173
174 /* FIXME: The sb fid change may survive the warm reset and only
175 * need to be done once.*/
176
177 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
178
179 post_code(0x39);
180
181 if (!warm_reset_detect(0)) { // BSP is node 0
182 init_fidvid_bsp(bsp_apicid, sysinfo->nodes);
183 } else {
184 init_fidvid_stage2(bsp_apicid, 0); // BSP is node 0
185 }
186
187 post_code(0x3A);
188
189 /* show final fid and vid */
190 msr=rdmsr(0xc0010071);
191 printk(BIOS_DEBUG, "End FIDVIDMSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
192#endif
193
194 init_timer();
195
196 /* Reset for HT, FIDVID, PLL and errata changes to take affect. */
197 if (!warm_reset_detect(0)) {
198 print_info("...WARM RESET...\n\n\n");
199 soft_reset();
200 die("After soft_reset_x - shouldn't see this message!!!\n");
201 }
202
203 /* It's the time to set ctrl in sysinfo now; */
204 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
205 enable_smbus();
206
207 //do we need apci timer, tsc...., only debug need it for better output
208 /* all ap stopped? */
209// init_timer(); // Need to use TMICT to synconize FID/VID
210
211 printk(BIOS_DEBUG, "raminit_amdmct()\n");
212 raminit_amdmct(sysinfo);
213 post_code(0x41);
214
215 bcm5785_early_setup();
216
217 post_cache_as_ram();
218}