blob: bd45c166af76798a06f88b403e1786ef354c755b [file] [log] [blame]
Rudolf Marek133647a2010-04-05 19:47:34 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2010 Advanced Micro Devices, Inc.
5 * Copyright (C) 2010 Rudolf Marek <r.marek@assembler.cz>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
Rudolf Marek133647a2010-04-05 19:47:34 +000021#define RC0 (6<<8)
22#define RC1 (7<<8)
23
Rudolf Marek133647a2010-04-05 19:47:34 +000024#define SMBUS_HUB 0x71
25
26#include <stdint.h>
27#include <string.h>
28#include <device/pci_def.h>
29#include <arch/io.h>
30#include <device/pnp_def.h>
31#include <arch/romcc_io.h>
32#include <cpu/x86/lapic.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000033#include <pc80/mc146818rtc.h>
Patrick Georgi12584e22010-05-08 09:14:51 +000034#include <console/console.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000035#include <cpu/amd/model_fxx_rev.h>
36#include "northbridge/amd/amdk8/raminit.h"
37#include "cpu/amd/model_fxx/apic_timer.c"
38#include "lib/delay.c"
Patrick Georgi9bd9a902010-11-20 10:31:00 +000039#include <spd.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000040#include "cpu/x86/lapic/boot_cpu.c"
41#include "northbridge/amd/amdk8/reset_test.c"
stepan8301d832010-12-08 07:07:33 +000042#include "superio/winbond/w83627dhg/early_serial.c"
Patrick Georgi5692c572010-10-05 13:40:31 +000043#include <usbdebug.h>
Stefan Reinauer5d3dee82010-04-14 11:40:34 +000044#include "cpu/x86/mtrr/earlymtrr.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000045#include "cpu/x86/bist.h"
Rudolf Marek133647a2010-04-05 19:47:34 +000046#include "northbridge/amd/amdk8/setup_resource_map.c"
stepan836ae292010-12-08 05:42:47 +000047#include "southbridge/amd/rs780/early_setup.c"
efdesign9800c8c4a2011-07-20 12:37:58 -060048#include "southbridge/amd/sb700/sb700.h"
49#include "southbridge/amd/sb700/smbus.h"
stepan836ae292010-12-08 05:42:47 +000050#include "northbridge/amd/amdk8/debug.c" /* After sb700/early_setup.c! */
Rudolf Marek133647a2010-04-05 19:47:34 +000051
52#define SERIAL_DEV PNP_DEV(0x2e, W83627DHG_SP1)
Uwe Hermann3a4ed152010-12-05 22:36:14 +000053#define GPIO2345_DEV PNP_DEV(0x2e, W83627DHG_GPIO2345_V)
Rudolf Marek133647a2010-04-05 19:47:34 +000054
Uwe Hermann7b997052010-11-21 22:47:22 +000055static void memreset(int controllers, const struct mem_controller *ctrl) { }
56static void activate_spd_rom(const struct mem_controller *ctrl) { }
Rudolf Marek133647a2010-04-05 19:47:34 +000057
Rudolf Marek133647a2010-04-05 19:47:34 +000058static inline int spd_read_byte(u32 device, u32 address)
59{
efdesign9800c8c4a2011-07-20 12:37:58 -060060 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
Rudolf Marek133647a2010-04-05 19:47:34 +000061}
62
63#include "northbridge/amd/amdk8/amdk8.h"
64#include "northbridge/amd/amdk8/incoherent_ht.c"
65#include "northbridge/amd/amdk8/raminit.c"
66#include "northbridge/amd/amdk8/coherent_ht.c"
67#include "lib/generic_sdram.c"
68#include "resourcemap.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000069#include "cpu/amd/dualcore/dualcore.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000070#include "cpu/amd/car/post_cache_as_ram.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000071#include "cpu/amd/model_fxx/init_cpus.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000072#include "cpu/amd/model_fxx/fidvid.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000073#include "northbridge/amd/amdk8/early_ht.c"
74
Stefan Reinauer56a684a2010-04-07 15:40:26 +000075static void sio_init(void)
Rudolf Marek133647a2010-04-05 19:47:34 +000076{
77 u8 reg;
78
79 pnp_enter_ext_func_mode(GPIO2345_DEV);
80 pnp_set_logical_device(GPIO2345_DEV);
81
Rudolf Marekaa55f372011-01-16 16:23:51 +000082 /* Pin 119 ~ 120 is GP21, GP20 */
Rudolf Marek133647a2010-04-05 19:47:34 +000083 reg = pnp_read_config(GPIO2345_DEV, 0x29);
84 pnp_write_config(GPIO2345_DEV, 0x29, (reg | 2));
85
Rudolf Marek9c9ae3a2010-11-30 21:21:33 +000086 /* Turn on the Power LED ("Suspend LED" in Super I/O) */
87 reg = pnp_read_config(GPIO2345_DEV, 0xf3);
88 pnp_write_config(GPIO2345_DEV, 0xf3, (reg | 0x40));
89
Rudolf Marek133647a2010-04-05 19:47:34 +000090 /* todo document this */
91 pnp_write_config(GPIO2345_DEV, 0x2c, 0x1);
92 pnp_write_config(GPIO2345_DEV, 0x2d, 0x1);
93
Rudolf Marekaa55f372011-01-16 16:23:51 +000094 /* GPO20 - sideport voltage 1 = 1.82 0 = 1.92
95 GPI21 - unknown input (NC?)
96 GPI22 - unknown input (NC?)
97 GPO23 - mgpuV bit0
Rudolf Mareka1125232011-01-16 17:15:36 +000098 GP24-27 - PS/2 mouse/keyb (only keyb is connected use flip interface for mouse)
Rudolf Marekaa55f372011-01-16 16:23:51 +000099 */
Rudolf Marek133647a2010-04-05 19:47:34 +0000100 pnp_write_config(GPIO2345_DEV, 0x30, 0x07); /* Enable GPIO 2,3,4. */
101 pnp_write_config(GPIO2345_DEV, 0xe3, 0xf6); /* dir of GPIO2 11110110*/
102 pnp_write_config(GPIO2345_DEV, 0xe4, 0x0e); /* data */
103 pnp_write_config(GPIO2345_DEV, 0xe5, 0x00); /* No inversion */
104
efdesign9800c8c4a2011-07-20 12:37:58 -0600105 /* GPIO30 - unknown output, set to 0
Rudolf Marekaa55f372011-01-16 16:23:51 +0000106 GPI31 - unknown input NC?
107 GPI32 - unknown input NC?
108 GPIO33 - unknown output, set to 0.
109 GPI34 - unknown input NC?
110 GPO35 - loadline control 1 = enabled (2 phase clock) 0 = disabled 4 phase clock
111 GPIO36 - input = HT voltage 1.30V output (low) = HT voltage 1.35V
112 GP37 - unknown input NC? */
113
Rudolf Marek133647a2010-04-05 19:47:34 +0000114 pnp_write_config(GPIO2345_DEV, 0xf0, 0xd6); /* dir of GPIO3 11010110*/
115 pnp_write_config(GPIO2345_DEV, 0xf1, 0x96); /* data */
116 pnp_write_config(GPIO2345_DEV, 0xf2, 0x00); /* No inversion */
117
Rudolf Marekaa55f372011-01-16 16:23:51 +0000118 /* GPO40 - mgpuV bit2
119 GPO41 - mgpuV bit1
120 GPO42 - IRTX
121 GPO43 - IRRX
122 GPIO44 - memory voltage bit2 (input/outputlow)
123 GPIO45 - memory voltage bit1 (2.60 (000) - 2.95 (111))
124 GPIO46 - memory voltage bit0
125 GPIO47 - unknown input? */
126
Rudolf Marek133647a2010-04-05 19:47:34 +0000127 pnp_write_config(GPIO2345_DEV, 0xf4, 0xd0); /* dir of GPIO4 11010000 */
128 pnp_write_config(GPIO2345_DEV, 0xf5, 0x83); /* data */
129 pnp_write_config(GPIO2345_DEV, 0xf6, 0x00); /* No inversion */
130
131 pnp_write_config(GPIO2345_DEV, 0xf7, 0x00); /* MFC */
132 pnp_write_config(GPIO2345_DEV, 0xf8, 0x00); /* MFC */
133 pnp_write_config(GPIO2345_DEV, 0xfe, 0x07); /* trig type */
134 pnp_exit_ext_func_mode(GPIO2345_DEV);
135}
136
137void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
138{
Rudolf Marekf41752c2010-11-30 20:18:53 +0000139 static const u16 spd_addr[] = { DIMM0, DIMM2, 0, 0, DIMM1, DIMM3, 0, 0, };
Rudolf Marek133647a2010-04-05 19:47:34 +0000140 int needs_reset = 0;
141 u32 bsp_apicid = 0;
142 msr_t msr;
143 struct cpuid_result cpuid1;
144 struct sys_info *sysinfo = (struct sys_info *)(CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);
145
146 if (!cpu_init_detectedx && boot_cpu()) {
147 /* Nothing special needs to be done to find bus 0 */
148 /* Allow the HT devices to be found */
149 enumerate_ht_chain();
Zheng Baoc3422232011-03-28 03:33:10 +0000150 /* sb7xx_51xx_lpc_port80(); */
151 sb7xx_51xx_pci_port80();
Rudolf Marek133647a2010-04-05 19:47:34 +0000152 }
153
Uwe Hermann7b997052010-11-21 22:47:22 +0000154 if (bist == 0)
Rudolf Marek133647a2010-04-05 19:47:34 +0000155 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Rudolf Marek133647a2010-04-05 19:47:34 +0000156
157 enable_rs780_dev8();
Zheng Baoc3422232011-03-28 03:33:10 +0000158 sb7xx_51xx_lpc_init();
Rudolf Marek133647a2010-04-05 19:47:34 +0000159
160 sio_init();
161 w83627dhg_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Uwe Hermannb015d022010-09-24 18:18:20 +0000162
Rudolf Marek133647a2010-04-05 19:47:34 +0000163 console_init();
164
165 /* Halt if there was a built in self test failure */
166 report_bist_failure(bist);
167 printk(BIOS_DEBUG, "bsp_apicid=0x%x\n", bsp_apicid);
168
169 setup_939a785gmh_resource_map();
170
171 setup_coherent_ht_domain();
172
173#if CONFIG_LOGICAL_CPUS==1
174 /* It is said that we should start core1 after all core0 launched */
175 wait_all_core0_started();
176 start_other_cores();
177#endif
178 wait_all_aps_started(bsp_apicid);
179
180 ht_setup_chains_x(sysinfo);
181
182 /* run _early_setup before soft-reset. */
183 rs780_early_setup();
Zheng Baoc3422232011-03-28 03:33:10 +0000184 sb7xx_51xx_early_setup();
Rudolf Marek133647a2010-04-05 19:47:34 +0000185
186 /* Check to see if processor is capable of changing FIDVID */
187 /* otherwise it will throw a GP# when reading FIDVID_STATUS */
188 cpuid1 = cpuid(0x80000007);
Uwe Hermann7b997052010-11-21 22:47:22 +0000189 if ((cpuid1.edx & 0x6) == 0x6) {
Rudolf Marek133647a2010-04-05 19:47:34 +0000190 /* Read FIDVID_STATUS */
191 msr=rdmsr(0xc0010042);
192 printk(BIOS_DEBUG, "begin msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
193
194 enable_fid_change();
195 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
196 init_fidvid_bsp(bsp_apicid);
197
198 /* show final fid and vid */
199 msr=rdmsr(0xc0010042);
200 printk(BIOS_DEBUG, "end msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
Rudolf Marek133647a2010-04-05 19:47:34 +0000201 } else {
202 printk(BIOS_DEBUG, "Changing FIDVID not supported\n");
203 }
204
205 needs_reset = optimize_link_coherent_ht();
206 needs_reset |= optimize_link_incoherent_ht(sysinfo);
207 rs780_htinit();
208 printk(BIOS_DEBUG, "needs_reset=0x%x\n", needs_reset);
209
210 if (needs_reset) {
211 print_info("ht reset -\n");
212 soft_reset();
213 }
214
215 allow_all_aps_stop(bsp_apicid);
216
217 /* It's the time to set ctrl now; */
218 printk(BIOS_DEBUG, "sysinfo->nodes: %2x sysinfo->ctrl: %p spd_addr: %p\n",
219 sysinfo->nodes, sysinfo->ctrl, spd_addr);
220 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
221 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
222
223 rs780_before_pci_init();
Zheng Baoc3422232011-03-28 03:33:10 +0000224 sb7xx_51xx_before_pci_init();
Rudolf Marek133647a2010-04-05 19:47:34 +0000225
226 post_cache_as_ram();
227}