blob: cbe320b62f76d0f1332e6302cbe821344c4b17a2 [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.
Rudolf Marek133647a2010-04-05 19:47:34 +000015 */
16
Rudolf Marek133647a2010-04-05 19:47:34 +000017#include <stdint.h>
18#include <string.h>
19#include <device/pci_def.h>
20#include <arch/io.h>
21#include <device/pnp_def.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000022#include <cpu/x86/lapic.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000023#include <pc80/mc146818rtc.h>
Patrick Georgi12584e22010-05-08 09:14:51 +000024#include <console/console.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000025#include <cpu/amd/model_fxx_rev.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110026#include <northbridge/amd/amdk8/raminit.h>
Edward O'Callaghanebe3a7a2015-01-05 00:27:54 +110027#include <delay.h>
Patrick Georgi9bd9a902010-11-20 10:31:00 +000028#include <spd.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110029#include <cpu/x86/lapic.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000030#include "northbridge/amd/amdk8/reset_test.c"
Edward O'Callaghanffe460d2014-04-27 22:51:40 +100031#include <superio/winbond/common/winbond.h>
32#include <superio/winbond/w83627dhg/w83627dhg.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110033#include <cpu/x86/bist.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000034#include "northbridge/amd/amdk8/setup_resource_map.c"
stepan836ae292010-12-08 05:42:47 +000035#include "southbridge/amd/rs780/early_setup.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110036#include <southbridge/amd/sb700/sb700.h>
37#include <southbridge/amd/sb700/smbus.h>
stepan836ae292010-12-08 05:42:47 +000038#include "northbridge/amd/amdk8/debug.c" /* After sb700/early_setup.c! */
Rudolf Marek133647a2010-04-05 19:47:34 +000039
40#define SERIAL_DEV PNP_DEV(0x2e, W83627DHG_SP1)
Uwe Hermann3a4ed152010-12-05 22:36:14 +000041#define GPIO2345_DEV PNP_DEV(0x2e, W83627DHG_GPIO2345_V)
Rudolf Marek133647a2010-04-05 19:47:34 +000042
Uwe Hermann7b997052010-11-21 22:47:22 +000043static void memreset(int controllers, const struct mem_controller *ctrl) { }
44static void activate_spd_rom(const struct mem_controller *ctrl) { }
Rudolf Marek133647a2010-04-05 19:47:34 +000045
Rudolf Marek133647a2010-04-05 19:47:34 +000046static inline int spd_read_byte(u32 device, u32 address)
47{
efdesign9800c8c4a2011-07-20 12:37:58 -060048 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
Rudolf Marek133647a2010-04-05 19:47:34 +000049}
50
Edward O'Callaghan77757c22015-01-04 21:33:39 +110051#include <northbridge/amd/amdk8/amdk8.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000052#include "northbridge/amd/amdk8/incoherent_ht.c"
53#include "northbridge/amd/amdk8/raminit.c"
54#include "northbridge/amd/amdk8/coherent_ht.c"
55#include "lib/generic_sdram.c"
56#include "resourcemap.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000057#include "cpu/amd/dualcore/dualcore.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000058#include "cpu/amd/model_fxx/init_cpus.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000059#include "cpu/amd/model_fxx/fidvid.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000060#include "northbridge/amd/amdk8/early_ht.c"
61
Stefan Reinauer56a684a2010-04-07 15:40:26 +000062static void sio_init(void)
Rudolf Marek133647a2010-04-05 19:47:34 +000063{
64 u8 reg;
65
66 pnp_enter_ext_func_mode(GPIO2345_DEV);
67 pnp_set_logical_device(GPIO2345_DEV);
68
Rudolf Marekaa55f372011-01-16 16:23:51 +000069 /* Pin 119 ~ 120 is GP21, GP20 */
Rudolf Marek133647a2010-04-05 19:47:34 +000070 reg = pnp_read_config(GPIO2345_DEV, 0x29);
71 pnp_write_config(GPIO2345_DEV, 0x29, (reg | 2));
72
Rudolf Marek9c9ae3a2010-11-30 21:21:33 +000073 /* Turn on the Power LED ("Suspend LED" in Super I/O) */
74 reg = pnp_read_config(GPIO2345_DEV, 0xf3);
75 pnp_write_config(GPIO2345_DEV, 0xf3, (reg | 0x40));
76
Rudolf Marek133647a2010-04-05 19:47:34 +000077 /* todo document this */
78 pnp_write_config(GPIO2345_DEV, 0x2c, 0x1);
79 pnp_write_config(GPIO2345_DEV, 0x2d, 0x1);
80
Rudolf Marekaa55f372011-01-16 16:23:51 +000081 /* GPO20 - sideport voltage 1 = 1.82 0 = 1.92
82 GPI21 - unknown input (NC?)
83 GPI22 - unknown input (NC?)
84 GPO23 - mgpuV bit0
Rudolf Mareka1125232011-01-16 17:15:36 +000085 GP24-27 - PS/2 mouse/keyb (only keyb is connected use flip interface for mouse)
Rudolf Marekaa55f372011-01-16 16:23:51 +000086 */
Rudolf Marek133647a2010-04-05 19:47:34 +000087 pnp_write_config(GPIO2345_DEV, 0x30, 0x07); /* Enable GPIO 2,3,4. */
88 pnp_write_config(GPIO2345_DEV, 0xe3, 0xf6); /* dir of GPIO2 11110110*/
89 pnp_write_config(GPIO2345_DEV, 0xe4, 0x0e); /* data */
90 pnp_write_config(GPIO2345_DEV, 0xe5, 0x00); /* No inversion */
91
efdesign9800c8c4a2011-07-20 12:37:58 -060092 /* GPIO30 - unknown output, set to 0
Rudolf Marekaa55f372011-01-16 16:23:51 +000093 GPI31 - unknown input NC?
94 GPI32 - unknown input NC?
95 GPIO33 - unknown output, set to 0.
96 GPI34 - unknown input NC?
97 GPO35 - loadline control 1 = enabled (2 phase clock) 0 = disabled 4 phase clock
98 GPIO36 - input = HT voltage 1.30V output (low) = HT voltage 1.35V
99 GP37 - unknown input NC? */
100
Rudolf Marek133647a2010-04-05 19:47:34 +0000101 pnp_write_config(GPIO2345_DEV, 0xf0, 0xd6); /* dir of GPIO3 11010110*/
102 pnp_write_config(GPIO2345_DEV, 0xf1, 0x96); /* data */
103 pnp_write_config(GPIO2345_DEV, 0xf2, 0x00); /* No inversion */
104
Rudolf Marekaa55f372011-01-16 16:23:51 +0000105 /* GPO40 - mgpuV bit2
106 GPO41 - mgpuV bit1
107 GPO42 - IRTX
108 GPO43 - IRRX
109 GPIO44 - memory voltage bit2 (input/outputlow)
110 GPIO45 - memory voltage bit1 (2.60 (000) - 2.95 (111))
111 GPIO46 - memory voltage bit0
112 GPIO47 - unknown input? */
113
Rudolf Marek133647a2010-04-05 19:47:34 +0000114 pnp_write_config(GPIO2345_DEV, 0xf4, 0xd0); /* dir of GPIO4 11010000 */
115 pnp_write_config(GPIO2345_DEV, 0xf5, 0x83); /* data */
116 pnp_write_config(GPIO2345_DEV, 0xf6, 0x00); /* No inversion */
117
118 pnp_write_config(GPIO2345_DEV, 0xf7, 0x00); /* MFC */
119 pnp_write_config(GPIO2345_DEV, 0xf8, 0x00); /* MFC */
120 pnp_write_config(GPIO2345_DEV, 0xfe, 0x07); /* trig type */
121 pnp_exit_ext_func_mode(GPIO2345_DEV);
122}
123
124void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
125{
Rudolf Marekf41752c2010-11-30 20:18:53 +0000126 static const u16 spd_addr[] = { DIMM0, DIMM2, 0, 0, DIMM1, DIMM3, 0, 0, };
Rudolf Marek133647a2010-04-05 19:47:34 +0000127 int needs_reset = 0;
128 u32 bsp_apicid = 0;
129 msr_t msr;
130 struct cpuid_result cpuid1;
Patrick Georgibbc880e2012-11-20 18:20:56 +0100131 struct sys_info *sysinfo = &sysinfo_car;
Rudolf Marek133647a2010-04-05 19:47:34 +0000132
133 if (!cpu_init_detectedx && boot_cpu()) {
134 /* Nothing special needs to be done to find bus 0 */
135 /* Allow the HT devices to be found */
136 enumerate_ht_chain();
Zheng Baoc3422232011-03-28 03:33:10 +0000137 /* sb7xx_51xx_lpc_port80(); */
138 sb7xx_51xx_pci_port80();
Rudolf Marek133647a2010-04-05 19:47:34 +0000139 }
140
Uwe Hermann7b997052010-11-21 22:47:22 +0000141 if (bist == 0)
Rudolf Marek133647a2010-04-05 19:47:34 +0000142 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Rudolf Marek133647a2010-04-05 19:47:34 +0000143
144 enable_rs780_dev8();
Zheng Baoc3422232011-03-28 03:33:10 +0000145 sb7xx_51xx_lpc_init();
Rudolf Marek133647a2010-04-05 19:47:34 +0000146
147 sio_init();
Edward O'Callaghanffe460d2014-04-27 22:51:40 +1000148 winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Uwe Hermannb015d022010-09-24 18:18:20 +0000149
Rudolf Marek133647a2010-04-05 19:47:34 +0000150 console_init();
151
152 /* Halt if there was a built in self test failure */
153 report_bist_failure(bist);
154 printk(BIOS_DEBUG, "bsp_apicid=0x%x\n", bsp_apicid);
155
156 setup_939a785gmh_resource_map();
157
158 setup_coherent_ht_domain();
159
Patrick Georgie1667822012-05-05 15:29:32 +0200160#if CONFIG_LOGICAL_CPUS
Rudolf Marek133647a2010-04-05 19:47:34 +0000161 /* It is said that we should start core1 after all core0 launched */
162 wait_all_core0_started();
163 start_other_cores();
164#endif
165 wait_all_aps_started(bsp_apicid);
166
167 ht_setup_chains_x(sysinfo);
168
169 /* run _early_setup before soft-reset. */
170 rs780_early_setup();
Zheng Baoc3422232011-03-28 03:33:10 +0000171 sb7xx_51xx_early_setup();
Rudolf Marek133647a2010-04-05 19:47:34 +0000172
173 /* Check to see if processor is capable of changing FIDVID */
174 /* otherwise it will throw a GP# when reading FIDVID_STATUS */
175 cpuid1 = cpuid(0x80000007);
Uwe Hermann7b997052010-11-21 22:47:22 +0000176 if ((cpuid1.edx & 0x6) == 0x6) {
Rudolf Marek133647a2010-04-05 19:47:34 +0000177 /* Read FIDVID_STATUS */
Elyes HAOUAS6350a2e2016-09-16 20:49:38 +0200178 msr = rdmsr(0xc0010042);
Rudolf Marek133647a2010-04-05 19:47:34 +0000179 printk(BIOS_DEBUG, "begin msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
180
181 enable_fid_change();
182 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
183 init_fidvid_bsp(bsp_apicid);
184
185 /* show final fid and vid */
Elyes HAOUAS6350a2e2016-09-16 20:49:38 +0200186 msr = rdmsr(0xc0010042);
Rudolf Marek133647a2010-04-05 19:47:34 +0000187 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 +0000188 } else {
189 printk(BIOS_DEBUG, "Changing FIDVID not supported\n");
190 }
191
192 needs_reset = optimize_link_coherent_ht();
193 needs_reset |= optimize_link_incoherent_ht(sysinfo);
194 rs780_htinit();
195 printk(BIOS_DEBUG, "needs_reset=0x%x\n", needs_reset);
196
197 if (needs_reset) {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800198 printk(BIOS_INFO, "ht reset -\n");
Rudolf Marek133647a2010-04-05 19:47:34 +0000199 soft_reset();
200 }
201
202 allow_all_aps_stop(bsp_apicid);
203
204 /* It's the time to set ctrl now; */
205 printk(BIOS_DEBUG, "sysinfo->nodes: %2x sysinfo->ctrl: %p spd_addr: %p\n",
206 sysinfo->nodes, sysinfo->ctrl, spd_addr);
207 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
208 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
209
210 rs780_before_pci_init();
Zheng Baoc3422232011-03-28 03:33:10 +0000211 sb7xx_51xx_before_pci_init();
Rudolf Marek133647a2010-04-05 19:47:34 +0000212
213 post_cache_as_ram();
214}