blob: 30a1a2aa30957033dbf58fc8048b16641897998e [file] [log] [blame]
Uwe Hermann2e9323e2010-11-14 21:48:14 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2006 AMD
5 * (Written by Yinghai Lu <yinghailu@amd.com> for AMD)
6 * Copyright (C) 2006 MSI
7 * (Written by Bingxun Shi <bingxunshi@gmail.com> for MSI)
8 * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
Uwe Hermann2e9323e2010-11-14 21:48:14 +000019 */
20
21unsigned int get_sbdn(unsigned bus);
22
Uwe Hermann2e9323e2010-11-14 21:48:14 +000023#include <stdint.h>
24#include <string.h>
25#include <device/pci_def.h>
26#include <arch/io.h>
27#include <device/pnp_def.h>
Uwe Hermann2e9323e2010-11-14 21:48:14 +000028#include <cpu/x86/lapic.h>
29#include <pc80/mc146818rtc.h>
30#include <console/console.h>
31#include <cpu/amd/model_fxx_rev.h>
Patrick Georgibd79c5e2014-11-28 22:35:36 +010032#include <halt.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110033#include <northbridge/amd/amdk8/raminit.h>
Edward O'Callaghanebe3a7a2015-01-05 00:27:54 +110034#include <delay.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110035#include <cpu/x86/lapic.h>
Uwe Hermann2e9323e2010-11-14 21:48:14 +000036#include "northbridge/amd/amdk8/reset_test.c"
37#include "northbridge/amd/amdk8/early_ht.c"
Edward O'Callaghan9e308b92014-04-27 23:28:31 +100038#include <superio/winbond/common/winbond.h>
Edward O'Callaghan793a4292014-04-03 14:30:58 +110039#include <superio/winbond/w83627ehg/w83627ehg.h>
stepan836ae292010-12-08 05:42:47 +000040#include "southbridge/via/vt8237r/early_smbus.c"
41#include "northbridge/amd/amdk8/debug.c" /* After vt8237r/early_smbus.c! */
Edward O'Callaghan77757c22015-01-04 21:33:39 +110042#include <cpu/x86/bist.h>
Uwe Hermann2e9323e2010-11-14 21:48:14 +000043#include "northbridge/amd/amdk8/setup_resource_map.c"
Uwe Hermann6dc92f02010-11-21 11:36:03 +000044#include <spd.h>
Uwe Hermann2e9323e2010-11-14 21:48:14 +000045
46#define SERIAL_DEV PNP_DEV(0x2e, W83627EHG_SP1)
Uwe Hermann3a4ed152010-12-05 22:36:14 +000047#define GPIO_DEV PNP_DEV(0x2e, W83627EHG_GPIO_SUSLED_V)
Uwe Hermann2e9323e2010-11-14 21:48:14 +000048#define ACPI_DEV PNP_DEV(0x2e, W83627EHG_ACPI)
Uwe Hermann2e9323e2010-11-14 21:48:14 +000049
Uwe Hermann7b997052010-11-21 22:47:22 +000050static void memreset(int controllers, const struct mem_controller *ctrl) { }
51static void activate_spd_rom(const struct mem_controller *ctrl) { }
Uwe Hermann2e9323e2010-11-14 21:48:14 +000052
53static inline int spd_read_byte(unsigned device, unsigned address)
54{
55 return smbus_read_byte(device, address);
56}
57
Uwe Hermann2e9323e2010-11-14 21:48:14 +000058#include <reset.h>
59void soft_reset(void)
60{
61 uint8_t tmp;
62
63 set_bios_reset();
Stefan Reinauer069f4762015-01-05 13:02:32 -080064 printk(BIOS_DEBUG, "soft reset\n");
Uwe Hermann2e9323e2010-11-14 21:48:14 +000065
66 /* PCI reset */
67 tmp = pci_read_config8(PCI_DEV(0, 0x11, 0), 0x4f);
68 tmp |= 0x01;
69 pci_write_config8(PCI_DEV(0, 0x11, 0), 0x4f, tmp);
70
Patrick Georgibd79c5e2014-11-28 22:35:36 +010071 halt();
Uwe Hermann2e9323e2010-11-14 21:48:14 +000072}
73
stepan836ae292010-12-08 05:42:47 +000074#include "southbridge/via/k8t890/early_car.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110075#include <northbridge/amd/amdk8/amdk8.h>
Uwe Hermann2e9323e2010-11-14 21:48:14 +000076#include "northbridge/amd/amdk8/incoherent_ht.c"
77#include "northbridge/amd/amdk8/coherent_ht.c"
78#include "northbridge/amd/amdk8/raminit.c"
79#include "lib/generic_sdram.c"
Uwe Hermann2e9323e2010-11-14 21:48:14 +000080#include "cpu/amd/dualcore/dualcore.c"
Uwe Hermann2e9323e2010-11-14 21:48:14 +000081#include "cpu/amd/model_fxx/init_cpus.c"
82#include "cpu/amd/model_fxx/fidvid.c"
83#include "northbridge/amd/amdk8/resourcemap.c"
84
85unsigned int get_sbdn(unsigned bus)
86{
87 device_t dev;
88
89 dev = pci_locate_device_on_bus(PCI_ID(PCI_VENDOR_ID_VIA,
90 PCI_DEVICE_ID_VIA_VT8237R_LPC), bus);
91 return (dev >> 15) & 0x1f;
92}
93
94static void sio_init(void)
95{
96 u8 reg;
97
98 pnp_enter_ext_func_mode(SERIAL_DEV);
99 /* We have 24MHz input. */
100 reg = pnp_read_config(SERIAL_DEV, 0x24);
101 pnp_write_config(SERIAL_DEV, 0x24, (reg & ~0x40));
102 /* We have GPIO for KB/MS pin. */
103 reg = pnp_read_config(SERIAL_DEV, 0x2a);
104 pnp_write_config(SERIAL_DEV, 0x2a, (reg | 1));
105 /* We have all RESTOUT and even some reserved bits, too. */
106 reg = pnp_read_config(SERIAL_DEV, 0x2c);
107 pnp_write_config(SERIAL_DEV, 0x2c, (reg | 0xf0));
108 pnp_exit_ext_func_mode(SERIAL_DEV);
109
110 pnp_enter_ext_func_mode(ACPI_DEV);
111 pnp_set_logical_device(ACPI_DEV);
112 /*
113 * Set the delay rising time from PWROK_LP to PWROK_ST to
114 * 300 - 600ms, and 0 to vice versa.
115 */
116 reg = pnp_read_config(ACPI_DEV, 0xe6);
117 pnp_write_config(ACPI_DEV, 0xe6, (reg & 0xf0));
118 /* 1 Use external suspend clock source 32.768KHz. Undocumented?? */
119 reg = pnp_read_config(ACPI_DEV, 0xe4);
120 pnp_write_config(ACPI_DEV, 0xe4, (reg | 0x10));
121 pnp_exit_ext_func_mode(ACPI_DEV);
122
123 pnp_enter_ext_func_mode(GPIO_DEV);
124 pnp_set_logical_device(GPIO_DEV);
125 /* Set memory voltage to 2.75V, vcore offset + 100mV, 1.5V chipset voltage. */
126 pnp_write_config(GPIO_DEV, 0x30, 0x09); /* Enable GPIO 2 & GPIO 5. */
127 pnp_write_config(GPIO_DEV, 0xe2, 0x00); /* No inversion */
128 pnp_write_config(GPIO_DEV, 0xe5, 0x00); /* No inversion */
129 pnp_write_config(GPIO_DEV, 0xe3, 0x03); /* 0000 0011, 0=output 1=input */
130 pnp_write_config(GPIO_DEV, 0xe0, 0xde); /* 1101 1110, 0=output 1=input */
131 pnp_write_config(GPIO_DEV, 0xe1, 0x01); /* Set output val. */
132 pnp_write_config(GPIO_DEV, 0xe4, 0xb4); /* Set output val (1011 0100). */
133 pnp_exit_ext_func_mode(GPIO_DEV);
134}
135
136void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
137{
138 static const uint16_t spd_addr[] = {
139 // Node 0
Uwe Hermann6dc92f02010-11-21 11:36:03 +0000140 DIMM0, DIMM2, 0, 0,
141 DIMM1, DIMM3, 0, 0,
Uwe Hermann2e9323e2010-11-14 21:48:14 +0000142 // Node 1
Uwe Hermann6dc92f02010-11-21 11:36:03 +0000143 DIMM4, DIMM6, 0, 0,
144 DIMM5, DIMM7, 0, 0,
Uwe Hermann2e9323e2010-11-14 21:48:14 +0000145 };
146 unsigned bsp_apicid = 0;
147 int needs_reset = 0;
Patrick Georgibbc880e2012-11-20 18:20:56 +0100148 struct sys_info *sysinfo = &sysinfo_car;
Uwe Hermann2e9323e2010-11-14 21:48:14 +0000149
150 sio_init();
Edward O'Callaghan9e308b92014-04-27 23:28:31 +1000151 winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Uwe Hermann2e9323e2010-11-14 21:48:14 +0000152 console_init();
153 enable_rom_decode();
154
Stefan Reinauer069f4762015-01-05 13:02:32 -0800155 printk(BIOS_INFO, "now booting... romstage\n");
Uwe Hermann2e9323e2010-11-14 21:48:14 +0000156
157 /* Is this a CPU only reset? Or is this a secondary CPU? */
158 if (!cpu_init_detectedx && boot_cpu()) {
159 /* Nothing special needs to be done to find bus 0. */
160 /* Allow the HT devices to be found. */
161 enumerate_ht_chain();
162 }
163
Stefan Reinauer069f4762015-01-05 13:02:32 -0800164 printk(BIOS_INFO, "now booting... real_main\n");
Uwe Hermann2e9323e2010-11-14 21:48:14 +0000165
166 if (bist == 0)
167 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
168
169 /* Halt if there was a built in self test failure. */
170 report_bist_failure(bist);
171
172 setup_default_resource_map();
173 setup_coherent_ht_domain();
174 wait_all_core0_started();
175
Stefan Reinauer069f4762015-01-05 13:02:32 -0800176 printk(BIOS_INFO, "now booting... Core0 started\n");
Uwe Hermann2e9323e2010-11-14 21:48:14 +0000177
Patrick Georgie1667822012-05-05 15:29:32 +0200178#if CONFIG_LOGICAL_CPUS
Uwe Hermann2e9323e2010-11-14 21:48:14 +0000179 /* It is said that we should start core1 after all core0 launched. */
180 start_other_cores();
181 wait_all_other_cores_started(bsp_apicid);
182#endif
183 init_timer();
184 ht_setup_chains_x(sysinfo); /* Init sblnk and sbbusn, nodes, sbdn. */
185
186 needs_reset = optimize_link_coherent_ht();
187 needs_reset |= optimize_link_incoherent_ht(sysinfo);
188 needs_reset |= k8t890_early_setup_ht();
189
190 if (needs_reset) {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800191 printk(BIOS_DEBUG, "ht reset -\n");
Uwe Hermann2e9323e2010-11-14 21:48:14 +0000192 soft_reset();
193 }
194
195 /* the HT settings needs to be OK, because link freq chnage may cause HT disconnect */
196 enable_fid_change();
197 init_fidvid_bsp(bsp_apicid);
198
199 /* Stop the APs so we can start them later in init. */
200 allow_all_aps_stop(bsp_apicid);
201
202 /* It's the time to set ctrl now. */
203 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
204
205 enable_smbus();
206 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
207 post_cache_as_ram();
208}