blob: 544873cbdd6b08f83d6e11cbcf9edc2007087745 [file] [log] [blame]
Rudolf Marek05839972008-09-23 20:36:03 +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)
Stefan Reinauer14e22772010-04-27 06:56:47 +00008 * Copyright (C) 2008 Rudolf Marek <r.marek@assembler.cz>
Rudolf Marek05839972008-09-23 20:36:03 +00009 *
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.
Rudolf Marek05839972008-09-23 20:36:03 +000019 */
20
Rudolf Marek05839972008-09-23 20:36:03 +000021unsigned int get_sbdn(unsigned bus);
22
Rudolf Marek05839972008-09-23 20:36:03 +000023#include <stdint.h>
Patrick Georgi12aba822009-04-30 07:07:22 +000024#include <string.h>
Rudolf Marek05839972008-09-23 20:36:03 +000025#include <device/pci_def.h>
26#include <arch/io.h>
27#include <device/pnp_def.h>
Rudolf Marek05839972008-09-23 20:36:03 +000028#include <cpu/amd/mtrr.h>
29#include <cpu/x86/lapic.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000030#include <pc80/mc146818rtc.h>
Patrick Georgi12584e22010-05-08 09:14:51 +000031#include <console/console.h>
Rudolf Marek05839972008-09-23 20:36:03 +000032#include <cpu/amd/model_fxx_rev.h>
Patrick Georgibd79c5e2014-11-28 22:35:36 +010033#include <halt.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110034#include <northbridge/amd/amdk8/raminit.h>
Edward O'Callaghanebe3a7a2015-01-05 00:27:54 +110035#include <delay.h>
Rudolf Marek05839972008-09-23 20:36:03 +000036#include "northbridge/amd/amdk8/reset_test.c"
37#include "northbridge/amd/amdk8/debug.c"
Edward O'Callaghanf2920022014-04-27 00:41:50 +100038#include <superio/ite/common/ite.h>
39#include <superio/ite/it8712f/it8712f.h>
stepan836ae292010-12-08 05:42:47 +000040#include "southbridge/via/vt8237r/early_smbus.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110041#include <cpu/x86/bist.h>
Rudolf Marek05839972008-09-23 20:36:03 +000042#include "northbridge/amd/amdk8/setup_resource_map.c"
Uwe Hermann6dc92f02010-11-21 11:36:03 +000043#include <spd.h>
Rudolf Marek05839972008-09-23 20:36:03 +000044
45#define SERIAL_DEV PNP_DEV(0x2e, IT8712F_SP1)
Edward O'Callaghan76d8fd62014-05-14 19:15:08 +100046#define GPIO_DEV PNP_DEV(0x2e, IT8712F_GPIO)
Rudolf Marek05839972008-09-23 20:36:03 +000047
Uwe Hermann7b997052010-11-21 22:47:22 +000048static void memreset(int controllers, const struct mem_controller *ctrl) { }
49static void activate_spd_rom(const struct mem_controller *ctrl) { }
Rudolf Marek05839972008-09-23 20:36:03 +000050
51static inline int spd_read_byte(unsigned device, unsigned address)
52{
53 return smbus_read_byte(device, address);
54}
55
stepan836ae292010-12-08 05:42:47 +000056#include "southbridge/via/k8t890/early_car.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110057#include <northbridge/amd/amdk8/amdk8.h>
Rudolf Marek05839972008-09-23 20:36:03 +000058#include "northbridge/amd/amdk8/incoherent_ht.c"
Stefan Reinauer23836e22010-04-15 12:39:29 +000059#include "northbridge/amd/amdk8/coherent_ht.c"
60#include "northbridge/amd/amdk8/raminit_f.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +000061#include "lib/generic_sdram.c"
Rudolf Marek05839972008-09-23 20:36:03 +000062#include "cpu/amd/dualcore/dualcore.c"
Rudolf Marek05839972008-09-23 20:36:03 +000063#include "cpu/amd/model_fxx/init_cpus.c"
Rudolf Mareke94e2e32008-12-04 23:42:36 +000064
65#define SB_VFSMAF 0
66
Rudolf Mareke94e2e32008-12-04 23:42:36 +000067static void ldtstop_sb(void)
68{
Stefan Reinauer069f4762015-01-05 13:02:32 -080069 printk(BIOS_DEBUG, "toggle LDTSTP#\n");
Rudolf Marek43358a52011-06-29 23:59:13 +020070
71 /* fix errata #181, disable DRAM controller it will get enabled later */
72 u8 tmp = pci_read_config8(PCI_DEV(0, 0x18, 2), 0x94);
73 tmp |= (( 1 << 14) | (1 << 3));
74 pci_write_config8(PCI_DEV(0, 0x18, 2), 0x94, tmp);
75
Rudolf Mareke94e2e32008-12-04 23:42:36 +000076 u8 reg = inb (VT8237R_ACPI_IO_BASE + 0x5c);
77 reg = reg ^ (1 << 0);
78 outb(reg, VT8237R_ACPI_IO_BASE + 0x5c);
79 reg = inb(VT8237R_ACPI_IO_BASE + 0x15);
Stefan Reinauer069f4762015-01-05 13:02:32 -080080 printk(BIOS_DEBUG, "done\n");
Rudolf Mareke94e2e32008-12-04 23:42:36 +000081}
82
Rudolf Marek05839972008-09-23 20:36:03 +000083#include "cpu/amd/model_fxx/fidvid.c"
84#include "northbridge/amd/amdk8/resourcemap.c"
85
Rudolf Marek05839972008-09-23 20:36:03 +000086void soft_reset(void)
87{
88 uint8_t tmp;
89
90 set_bios_reset();
Stefan Reinauer069f4762015-01-05 13:02:32 -080091 printk(BIOS_DEBUG, "soft reset\n");
Rudolf Marek05839972008-09-23 20:36:03 +000092
93 /* PCI reset */
94 tmp = pci_read_config8(PCI_DEV(0, 0x11, 0), 0x4f);
95 tmp |= 0x01;
96 /* FIXME from S3 set bit1 to disable USB reset VT8237A/S */
97 pci_write_config8(PCI_DEV(0, 0x11, 0), 0x4f, tmp);
98
Patrick Georgibd79c5e2014-11-28 22:35:36 +010099 halt();
Rudolf Marek05839972008-09-23 20:36:03 +0000100}
101
102unsigned int get_sbdn(unsigned bus)
103{
104 device_t dev;
105
106 dev = pci_locate_device_on_bus(PCI_ID(PCI_VENDOR_ID_VIA,
107 PCI_DEVICE_ID_VIA_VT8237R_LPC), bus);
108 return (dev >> 15) & 0x1f;
109}
110
Rudolf Marek05839972008-09-23 20:36:03 +0000111void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
112{
Rudolf Marek05839972008-09-23 20:36:03 +0000113 static const uint16_t spd_addr[] = {
Stefan Reinauer23836e22010-04-15 12:39:29 +0000114 // Node 0
Uwe Hermann6dc92f02010-11-21 11:36:03 +0000115 DIMM0, DIMM2, 0, 0,
116 DIMM1, DIMM3, 0, 0,
Stefan Reinauer23836e22010-04-15 12:39:29 +0000117 // Node 1
Uwe Hermann6dc92f02010-11-21 11:36:03 +0000118 DIMM4, DIMM6, 0, 0,
119 DIMM5, DIMM7, 0, 0,
Rudolf Marek05839972008-09-23 20:36:03 +0000120 };
121 unsigned bsp_apicid = 0;
122 int needs_reset = 0;
Patrick Georgibbc880e2012-11-20 18:20:56 +0100123 struct sys_info *sysinfo = &sysinfo_car;
Rudolf Marek05839972008-09-23 20:36:03 +0000124
Edward O'Callaghanf2920022014-04-27 00:41:50 +1000125 ite_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Edward O'Callaghan76d8fd62014-05-14 19:15:08 +1000126 ite_kill_watchdog(GPIO_DEV);
127 ite_enable_3vsbsw(GPIO_DEV);
Rudolf Marek05839972008-09-23 20:36:03 +0000128 console_init();
129 enable_rom_decode();
130
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200131 printk(BIOS_INFO, "now booting...\n");
Rudolf Marek05839972008-09-23 20:36:03 +0000132
Rudolf Marek05839972008-09-23 20:36:03 +0000133 if (bist == 0)
134 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
135
136 /* Halt if there was a built in self test failure. */
137 report_bist_failure(bist);
138 setup_default_resource_map();
139 setup_coherent_ht_domain();
140 wait_all_core0_started();
141
Stefan Reinauer64d3baf2010-04-22 13:18:09 +0000142 printk(BIOS_INFO, "now booting... All core 0 started\n");
Rudolf Marek05839972008-09-23 20:36:03 +0000143
Patrick Georgie1667822012-05-05 15:29:32 +0200144#if CONFIG_LOGICAL_CPUS
Rudolf Marek05839972008-09-23 20:36:03 +0000145 /* It is said that we should start core1 after all core0 launched. */
146 start_other_cores();
147 wait_all_other_cores_started(bsp_apicid);
148#endif
149 init_timer();
150 ht_setup_chains_x(sysinfo); /* Init sblnk and sbbusn, nodes, sbdn. */
151
152 needs_reset = optimize_link_coherent_ht();
Stefan Reinauer069f4762015-01-05 13:02:32 -0800153 printk(BIOS_DEBUG, "%02x", needs_reset);
Rudolf Marek05839972008-09-23 20:36:03 +0000154 needs_reset |= optimize_link_incoherent_ht(sysinfo);
Stefan Reinauer069f4762015-01-05 13:02:32 -0800155 printk(BIOS_DEBUG, "%02x", needs_reset);
Rudolf Marek05839972008-09-23 20:36:03 +0000156 needs_reset |= k8t890_early_setup_ht();
Stefan Reinauer069f4762015-01-05 13:02:32 -0800157 printk(BIOS_DEBUG, "%02x", needs_reset);
Rudolf Marek05839972008-09-23 20:36:03 +0000158
159 vt8237_early_network_init(NULL);
160 vt8237_early_spi_init();
161
162 if (needs_reset) {
Stefan Reinauer64d3baf2010-04-22 13:18:09 +0000163 printk(BIOS_DEBUG, "ht reset -\n");
Rudolf Marek05839972008-09-23 20:36:03 +0000164 soft_reset();
Stefan Reinauer64d3baf2010-04-22 13:18:09 +0000165 printk(BIOS_DEBUG, "FAILED!\n");
Rudolf Marek05839972008-09-23 20:36:03 +0000166 }
167
Rudolf Marek05839972008-09-23 20:36:03 +0000168 /* the HT settings needs to be OK, because link freq chnage may cause HT disconnect */
169 /* allow LDT STOP asserts */
170 vt8237_sb_enable_fid_vid();
171
172 enable_fid_change();
Stefan Reinauer069f4762015-01-05 13:02:32 -0800173 printk(BIOS_DEBUG, "after enable_fid_change\n");
Rudolf Marek05839972008-09-23 20:36:03 +0000174
Rudolf Marek31e52e62008-12-04 23:37:12 +0000175 init_fidvid_bsp(bsp_apicid);
Rudolf Marek05839972008-09-23 20:36:03 +0000176
177 /* Stop the APs so we can start them later in init. */
178 allow_all_aps_stop(bsp_apicid);
179
180 /* It's the time to set ctrl now. */
181 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
182 enable_smbus();
Rudolf Marek05839972008-09-23 20:36:03 +0000183 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
184 post_cache_as_ram();
185}