blob: 68cbaad18ffecf4e99a7d970969940a5015af670 [file] [log] [blame]
Morgan Tsai1602dd52007-10-29 21:00:14 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Morgan Tsai1602dd52007-10-29 21:00:14 +00003 *
4 * Copyright (C) 2007 AMD
5 * Written by Yinghai Lu <yinghailu@amd.com> for AMD.
6 * Copyright (C) 2007 Silicon Integrated Systems Corp. (SiS)
7 * Written by Morgan Tsai <my_tsai@sis.com> for SiS.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
Morgan Tsai1602dd52007-10-29 21:00:14 +000018 */
19
Morgan Tsai1602dd52007-10-29 21:00:14 +000020#include <stdint.h>
Patrick Georgi12aba822009-04-30 07:07:22 +000021#include <string.h>
Morgan Tsai1602dd52007-10-29 21:00:14 +000022#include <device/pci_def.h>
23#include <device/pci_ids.h>
24#include <arch/io.h>
25#include <device/pnp_def.h>
Morgan Tsai1602dd52007-10-29 21:00:14 +000026#include <cpu/x86/lapic.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000027#include <pc80/mc146818rtc.h>
Patrick Georgi12584e22010-05-08 09:14:51 +000028#include <console/console.h>
Uwe Hermann6dc92f02010-11-21 11:36:03 +000029#include <spd.h>
Morgan Tsai1602dd52007-10-29 21:00:14 +000030#include <cpu/amd/model_fxx_rev.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110031#include <southbridge/sis/sis966/sis966.h>
stepan836ae292010-12-08 05:42:47 +000032#include "southbridge/sis/sis966/early_smbus.c"
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>
Morgan Tsai1602dd52007-10-29 21:00:14 +000036#include "northbridge/amd/amdk8/reset_test.c"
Edward O'Callaghanf2920022014-04-27 00:41:50 +100037#include <superio/ite/common/ite.h>
Edward O'Callaghan5c41ee62014-04-23 01:43:38 +100038#include <superio/ite/it8716f/it8716f.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110039#include <cpu/x86/bist.h>
Morgan Tsai1602dd52007-10-29 21:00:14 +000040#include "northbridge/amd/amdk8/debug.c"
Morgan Tsai1602dd52007-10-29 21:00:14 +000041#include "northbridge/amd/amdk8/setup_resource_map.c"
stepan836ae292010-12-08 05:42:47 +000042#include "southbridge/sis/sis966/early_ctrl.c"
Morgan Tsai1602dd52007-10-29 21:00:14 +000043
Morgan Tsai218c2652007-11-02 16:09:58 +000044#define SERIAL_DEV PNP_DEV(0x2e, IT8716F_SP1)
Edward O'Callaghan5c41ee62014-04-23 01:43:38 +100045#define CLKIN_DEV PNP_DEV(0x2e, IT8716F_GPIO)
Morgan Tsai1602dd52007-10-29 21:00:14 +000046
Uwe Hermann7b997052010-11-21 22:47:22 +000047static void memreset(int controllers, const struct mem_controller *ctrl) { }
48static void activate_spd_rom(const struct mem_controller *ctrl) { }
Morgan Tsai1602dd52007-10-29 21:00:14 +000049
50static inline int spd_read_byte(unsigned device, unsigned address)
51{
52 return smbus_read_byte(device, address);
53}
54
Edward O'Callaghan77757c22015-01-04 21:33:39 +110055#include <northbridge/amd/amdk8/f.h>
Morgan Tsai1602dd52007-10-29 21:00:14 +000056#include "northbridge/amd/amdk8/incoherent_ht.c"
Stefan Reinauer23836e22010-04-15 12:39:29 +000057#include "northbridge/amd/amdk8/coherent_ht.c"
Morgan Tsai1602dd52007-10-29 21:00:14 +000058#include "northbridge/amd/amdk8/raminit_f.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +000059#include "lib/generic_sdram.c"
Morgan Tsai218c2652007-11-02 16:09:58 +000060#include "resourcemap.c"
Morgan Tsai1602dd52007-10-29 21:00:14 +000061#include "cpu/amd/dualcore/dualcore.c"
62
63#define SIS966_NUM 1
64#define SIS966_USE_NIC 1
65#define SIS966_USE_AZA 1
66
67#define SIS966_PCI_E_X_0 0
68
69#define SIS966_MB_SETUP \
70 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+37, 0x00, 0x44,/* GPIO38 PCI_REQ3 */ \
71 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+38, 0x00, 0x44,/* GPIO39 PCI_GNT3 */ \
72 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+39, 0x00, 0x44,/* GPIO40 PCI_GNT2 */ \
73 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+40, 0x00, 0x44,/* GPIO41 PCI_REQ2 */ \
74 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+59, 0x00, 0x60,/* GPIP60 FANCTL0 */ \
75 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+60, 0x00, 0x60,/* GPIO61 FANCTL1 */
76
Edward O'Callaghan77757c22015-01-04 21:33:39 +110077#include <southbridge/sis/sis966/early_setup_ss.h>
Morgan Tsai1602dd52007-10-29 21:00:14 +000078#include "cpu/amd/model_fxx/init_cpus.c"
Morgan Tsai1602dd52007-10-29 21:00:14 +000079#include "cpu/amd/model_fxx/fidvid.c"
Morgan Tsai1602dd52007-10-29 21:00:14 +000080#include "northbridge/amd/amdk8/early_ht.c"
81
Morgan Tsai1602dd52007-10-29 21:00:14 +000082static void sio_setup(void)
83{
Morgan Tsai1602dd52007-10-29 21:00:14 +000084 uint32_t dword;
85 uint8_t byte;
86
87 byte = pci_read_config8(PCI_DEV(0, SIS966_DEVN_BASE+1 , 0), 0x7b);
Morgan Tsai218c2652007-11-02 16:09:58 +000088 byte |= 0x20;
Morgan Tsai1602dd52007-10-29 21:00:14 +000089 pci_write_config8(PCI_DEV(0, SIS966_DEVN_BASE+1 , 0), 0x7b, byte);
Morgan Tsai218c2652007-11-02 16:09:58 +000090
Morgan Tsai1602dd52007-10-29 21:00:14 +000091 dword = pci_read_config32(PCI_DEV(0, SIS966_DEVN_BASE+1 , 0), 0xa0);
Elyes HAOUAS531b87a2016-09-19 09:46:33 -060092 dword |= (1 << 0);
Morgan Tsai1602dd52007-10-29 21:00:14 +000093 pci_write_config32(PCI_DEV(0, SIS966_DEVN_BASE+1 , 0), 0xa0, dword);
Morgan Tsai218c2652007-11-02 16:09:58 +000094
Morgan Tsai1602dd52007-10-29 21:00:14 +000095 dword = pci_read_config32(PCI_DEV(0, SIS966_DEVN_BASE+1 , 0), 0xa4);
Elyes HAOUAS531b87a2016-09-19 09:46:33 -060096 dword |= (1 << 16);
Morgan Tsai1602dd52007-10-29 21:00:14 +000097 pci_write_config32(PCI_DEV(0, SIS966_DEVN_BASE+1 , 0), 0xa4, dword);
98}
99
Patrick Georgice6fb1e2010-03-17 22:44:39 +0000100void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
Morgan Tsai1602dd52007-10-29 21:00:14 +0000101{
102 static const uint16_t spd_addr [] = {
Uwe Hermann7b997052010-11-21 22:47:22 +0000103 // Node 0
104 DIMM0, DIMM2, 0, 0,
105 DIMM1, DIMM3, 0, 0,
106 // Node 1
107 DIMM4, DIMM6, 0, 0,
108 DIMM5, DIMM7, 0, 0,
Morgan Tsai1602dd52007-10-29 21:00:14 +0000109 };
110
Patrick Georgibbc880e2012-11-20 18:20:56 +0100111 struct sys_info *sysinfo = &sysinfo_car;
Morgan Tsai1602dd52007-10-29 21:00:14 +0000112 int needs_reset = 0;
113 unsigned bsp_apicid = 0;
114
Patrick Georgi2bd91002010-03-18 16:46:50 +0000115 if (!cpu_init_detectedx && boot_cpu()) {
Patrick Georgice6fb1e2010-03-17 22:44:39 +0000116 /* Nothing special needs to be done to find bus 0 */
117 /* Allow the HT devices to be found */
Patrick Georgice6fb1e2010-03-17 22:44:39 +0000118 enumerate_ht_chain();
Patrick Georgice6fb1e2010-03-17 22:44:39 +0000119 sio_setup();
Patrick Georgice6fb1e2010-03-17 22:44:39 +0000120 }
121
Uwe Hermann7b997052010-11-21 22:47:22 +0000122 if (bist == 0)
Morgan Tsai1602dd52007-10-29 21:00:14 +0000123 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Morgan Tsai1602dd52007-10-29 21:00:14 +0000124
Edward O'Callaghanf2920022014-04-27 00:41:50 +1000125 ite_conf_clkin(CLKIN_DEV, ITE_UART_CLK_PREDIVIDE_48);
126 ite_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Morgan Tsai1602dd52007-10-29 21:00:14 +0000127
128 setup_mb_resource_map();
129
Stefan Reinauer42fa7fe2011-04-20 20:54:07 +0000130 console_init();
Morgan Tsai218c2652007-11-02 16:09:58 +0000131
Morgan Tsai1602dd52007-10-29 21:00:14 +0000132 /* Halt if there was a built in self test failure */
133 report_bist_failure(bist);
134
Myles Watson08e0fb82010-03-22 16:33:25 +0000135 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
Morgan Tsai1602dd52007-10-29 21:00:14 +0000136
Stefan Reinauer069f4762015-01-05 13:02:32 -0800137 printk(BIOS_DEBUG, "bsp_apicid=%02x\n", bsp_apicid);
Morgan Tsai1602dd52007-10-29 21:00:14 +0000138
Morgan Tsai1602dd52007-10-29 21:00:14 +0000139 set_sysinfo_in_ram(0); // in BSP so could hold all ap until sysinfo is in ram
Morgan Tsai1602dd52007-10-29 21:00:14 +0000140 setup_coherent_ht_domain(); // routing table and start other core0
141
142 wait_all_core0_started();
Patrick Georgie1667822012-05-05 15:29:32 +0200143#if CONFIG_LOGICAL_CPUS
Morgan Tsai1602dd52007-10-29 21:00:14 +0000144 // It is said that we should start core1 after all core0 launched
145 /* becase optimize_link_coherent_ht is moved out from setup_coherent_ht_domain,
146 * So here need to make sure last core0 is started, esp for two way system,
147 * (there may be apic id conflicts in that case)
148 */
149 start_other_cores();
150 wait_all_other_cores_started(bsp_apicid);
151#endif
152
153 /* it will set up chains and store link pair for optimization later */
154 ht_setup_chains_x(sysinfo); // it will init sblnk and sbbusn, nodes, sbdn
155
Patrick Georgi76e81522010-11-16 21:25:29 +0000156#if CONFIG_SET_FIDVID
Morgan Tsai1602dd52007-10-29 21:00:14 +0000157 {
158 msr_t msr;
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600159 msr = rdmsr(0xc0010042);
Stefan Reinauer069f4762015-01-05 13:02:32 -0800160 printk(BIOS_DEBUG, "begin msr fid, vid %08x%08x\n", msr.hi, msr.lo);
Morgan Tsai1602dd52007-10-29 21:00:14 +0000161 }
Morgan Tsai1602dd52007-10-29 21:00:14 +0000162 enable_fid_change();
Morgan Tsai1602dd52007-10-29 21:00:14 +0000163 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
Morgan Tsai1602dd52007-10-29 21:00:14 +0000164 init_fidvid_bsp(bsp_apicid);
Morgan Tsai1602dd52007-10-29 21:00:14 +0000165 // show final fid and vid
166 {
167 msr_t msr;
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600168 msr = rdmsr(0xc0010042);
Stefan Reinauer069f4762015-01-05 13:02:32 -0800169 printk(BIOS_DEBUG, "end msr fid, vid %08x%08x\n", msr.hi, msr.lo);
Morgan Tsai1602dd52007-10-29 21:00:14 +0000170 }
171#endif
172
173 needs_reset |= optimize_link_coherent_ht();
174 needs_reset |= optimize_link_incoherent_ht(sysinfo);
Morgan Tsai1602dd52007-10-29 21:00:14 +0000175
176 // fidvid change will issue one LDTSTOP and the HT change will be effective too
177 if (needs_reset) {
Stefan Reinauer069f4762015-01-05 13:02:32 -0800178 printk(BIOS_INFO, "ht reset -\n");
Morgan Tsai1602dd52007-10-29 21:00:14 +0000179 soft_reset();
180 }
181 allow_all_aps_stop(bsp_apicid);
182
183 //It's the time to set ctrl in sysinfo now;
184 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
185
186 sis_init_stage1();
Morgan Tsai218c2652007-11-02 16:09:58 +0000187 enable_smbus();
188
Morgan Tsai1602dd52007-10-29 21:00:14 +0000189 //do we need apci timer, tsc...., only debug need it for better output
190 /* all ap stopped? */
Paul Menzel4549e5a2014-02-02 22:05:48 +0100191// init_timer(); // Need to use TMICT to synchronize FID/VID
Morgan Tsai1602dd52007-10-29 21:00:14 +0000192
193 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
194
195 sis_init_stage2();
Elyes HAOUAS8ab989e2016-07-30 17:46:17 +0200196 post_cache_as_ram(); // bsp swtich stack to RAM and copy sysinfo RAM now
Morgan Tsai1602dd52007-10-29 21:00:14 +0000197}