blob: 7986d50d6876a97b46b7c046c52e425aa8454725 [file] [log] [blame]
Yinghai Luf55b58d2007-02-17 14:28:11 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Yinghai Luf55b58d2007-02-17 14:28:11 +00003 *
4 * Copyright (C) 2007 AMD
5 * Written by Yinghai Lu <yinghailu@amd.com> for AMD.
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; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Yinghai Luf55b58d2007-02-17 14:28:11 +000016 */
17
Yinghai Luf55b58d2007-02-17 14:28:11 +000018#include <stdint.h>
Patrick Georgi12aba822009-04-30 07:07:22 +000019#include <string.h>
Yinghai Luf55b58d2007-02-17 14:28:11 +000020#include <device/pci_def.h>
21#include <device/pci_ids.h>
22#include <arch/io.h>
23#include <device/pnp_def.h>
Yinghai Luf55b58d2007-02-17 14:28:11 +000024#include <cpu/x86/lapic.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000025#include <pc80/mc146818rtc.h>
Patrick Georgi12584e22010-05-08 09:14:51 +000026#include <console/console.h>
Patrick Georgid0835952010-10-05 09:07:10 +000027#include <lib.h>
Uwe Hermann6dc92f02010-11-21 11:36:03 +000028#include <spd.h>
Yinghai Luf55b58d2007-02-17 14:28:11 +000029#include <cpu/amd/model_fxx_rev.h>
stepan836ae292010-12-08 05:42:47 +000030#include "southbridge/nvidia/mcp55/early_smbus.c" // for enable the FAN
Edward O'Callaghan77757c22015-01-04 21:33:39 +110031#include <northbridge/amd/amdk8/raminit.h>
Patrick Georgi82d9a312016-01-21 12:46:10 +010032#include <delay.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110033#include <cpu/x86/lapic.h>
Yinghai Luf55b58d2007-02-17 14:28:11 +000034#include "northbridge/amd/amdk8/reset_test.c"
Edward O'Callaghanbeb0f262014-04-29 13:09:50 +100035#include <superio/winbond/common/winbond.h>
36#include <superio/winbond/w83627hf/w83627hf.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110037#include <cpu/x86/bist.h>
Yinghai Luf55b58d2007-02-17 14:28:11 +000038#include "northbridge/amd/amdk8/debug.c"
Yinghai Luf55b58d2007-02-17 14:28:11 +000039#include "northbridge/amd/amdk8/setup_resource_map.c"
40
41#define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
Uwe Hermann9b9791c2010-12-06 18:17:01 +000042#define DUMMY_DEV PNP_DEV(0x2e, 0)
Yinghai Luf55b58d2007-02-17 14:28:11 +000043
Damien Zammit75a3d1f2016-11-28 00:29:10 +110044unsigned get_sbdn(unsigned bus);
45
46unsigned get_sbdn(unsigned bus)
47{
48 pci_devfn_t dev;
49
50 /* Find the device. */
51 dev = pci_locate_device_on_bus(PCI_ID(PCI_VENDOR_ID_NVIDIA,
52 PCI_DEVICE_ID_NVIDIA_MCP55_HT), bus);
53
54 return (dev >> 15) & 0x1f;
55}
56
Uwe Hermann7b997052010-11-21 22:47:22 +000057static void memreset(int controllers, const struct mem_controller *ctrl) { }
58static void activate_spd_rom(const struct mem_controller *ctrl) { }
Yinghai Luf55b58d2007-02-17 14:28:11 +000059
60static inline int spd_read_byte(unsigned device, unsigned address)
61{
62 return smbus_read_byte(device, address);
63}
64
Damien Zammit75a3d1f2016-11-28 00:29:10 +110065#include "southbridge/nvidia/mcp55/early_ctrl.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110066#include <northbridge/amd/amdk8/f.h>
Yinghai Luf55b58d2007-02-17 14:28:11 +000067#include "northbridge/amd/amdk8/incoherent_ht.c"
Stefan Reinauer23836e22010-04-15 12:39:29 +000068#include "northbridge/amd/amdk8/coherent_ht.c"
Yinghai Luf55b58d2007-02-17 14:28:11 +000069#include "northbridge/amd/amdk8/raminit_f.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +000070#include "lib/generic_sdram.c"
Stefan Reinauer14e22772010-04-27 06:56:47 +000071#include "resourcemap.c"
Yinghai Luf55b58d2007-02-17 14:28:11 +000072#include "cpu/amd/dualcore/dualcore.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110073#include <southbridge/nvidia/mcp55/early_setup_ss.h>
stepan836ae292010-12-08 05:42:47 +000074#include "southbridge/nvidia/mcp55/early_setup_car.c"
Yinghai Luf55b58d2007-02-17 14:28:11 +000075#include "cpu/amd/model_fxx/init_cpus.c"
Yinghai Luf55b58d2007-02-17 14:28:11 +000076#include "cpu/amd/model_fxx/fidvid.c"
Yinghai Luf55b58d2007-02-17 14:28:11 +000077#include "northbridge/amd/amdk8/early_ht.c"
78
Yinghai Luf55b58d2007-02-17 14:28:11 +000079static void sio_setup(void)
80{
Elyes HAOUAS39aa6302016-09-27 21:22:54 +020081 uint32_t dword;
82 uint8_t byte;
Uwe Hermann7b997052010-11-21 22:47:22 +000083
Elyes HAOUAS39aa6302016-09-27 21:22:54 +020084 enable_smbus();
Elyes HAOUASa5aad2e2016-09-19 09:47:16 -060085// smbusx_write_byte(1, (0x58 >> 1), 0, 0x80); /* select bank0 */
86 smbusx_write_byte(1, (0x58 >> 1), 0xb1, 0xff); /* set FAN ctrl to DC mode */
Yinghai Luf55b58d2007-02-17 14:28:11 +000087
Elyes HAOUAS39aa6302016-09-27 21:22:54 +020088 byte = pci_read_config8(PCI_DEV(0, MCP55_DEVN_BASE+1 , 0), 0x7b);
89 byte |= 0x20;
90 pci_write_config8(PCI_DEV(0, MCP55_DEVN_BASE+1 , 0), 0x7b, byte);
Stefan Reinauer14e22772010-04-27 06:56:47 +000091
Elyes HAOUAS39aa6302016-09-27 21:22:54 +020092 dword = pci_read_config32(PCI_DEV(0, MCP55_DEVN_BASE+1 , 0), 0xa0);
93 dword |= (1 << 0);
94 pci_write_config32(PCI_DEV(0, MCP55_DEVN_BASE+1 , 0), 0xa0, dword);
Stefan Reinauer14e22772010-04-27 06:56:47 +000095
Elyes HAOUAS39aa6302016-09-27 21:22:54 +020096 dword = pci_read_config32(PCI_DEV(0, MCP55_DEVN_BASE+1 , 0), 0xa4);
97 dword |= (1 << 16);
98 pci_write_config32(PCI_DEV(0, MCP55_DEVN_BASE+1 , 0), 0xa4, dword);
Yinghai Luf55b58d2007-02-17 14:28:11 +000099}
100
Patrick Georgice6fb1e2010-03-17 22:44:39 +0000101void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
Yinghai Luf55b58d2007-02-17 14:28:11 +0000102{
103 static const uint16_t spd_addr [] = {
Uwe Hermann7b997052010-11-21 22:47:22 +0000104 // Node 0
105 DIMM0, DIMM2, 0, 0,
106 DIMM1, DIMM3, 0, 0,
107 // Node 1
108 DIMM4, DIMM6, 0, 0,
109 DIMM5, DIMM7, 0, 0,
Yinghai Luf55b58d2007-02-17 14:28:11 +0000110 };
111
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200112 struct sys_info *sysinfo = &sysinfo_car;
113 int needs_reset = 0;
114 unsigned bsp_apicid = 0;
Yinghai Luf55b58d2007-02-17 14:28:11 +0000115
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200116 if (!cpu_init_detectedx && boot_cpu()) {
Patrick Georgice6fb1e2010-03-17 22:44:39 +0000117 /* Nothing special needs to be done to find bus 0 */
118 /* Allow the HT devices to be found */
Patrick Georgice6fb1e2010-03-17 22:44:39 +0000119 enumerate_ht_chain();
Patrick Georgice6fb1e2010-03-17 22:44:39 +0000120 sio_setup();
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200121 }
Patrick Georgice6fb1e2010-03-17 22:44:39 +0000122
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200123 if (bist == 0)
Yinghai Luf55b58d2007-02-17 14:28:11 +0000124 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Yinghai Luf55b58d2007-02-17 14:28:11 +0000125
Edward O'Callaghanbeb0f262014-04-29 13:09:50 +1000126 w83627hf_set_clksel_48(DUMMY_DEV);
127 winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Yinghai Luf55b58d2007-02-17 14:28:11 +0000128
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200129 console_init();
Stefan Reinauer14e22772010-04-27 06:56:47 +0000130
Yinghai Luf55b58d2007-02-17 14:28:11 +0000131 /* Halt if there was a built in self test failure */
132 report_bist_failure(bist);
133
Myles Watson08e0fb82010-03-22 16:33:25 +0000134 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
Yinghai Luf55b58d2007-02-17 14:28:11 +0000135
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200136 setup_mb_resource_map();
Yinghai Luf55b58d2007-02-17 14:28:11 +0000137
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200138 printk(BIOS_DEBUG, "bsp_apicid=%02x\n", bsp_apicid);
Yinghai Luf55b58d2007-02-17 14:28:11 +0000139
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200140 set_sysinfo_in_ram(0); // in BSP so could hold all ap until sysinfo is in ram
141 setup_coherent_ht_domain(); // routing table and start other core0
Yinghai Luf55b58d2007-02-17 14:28:11 +0000142
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200143 wait_all_core0_started();
Patrick Georgie1667822012-05-05 15:29:32 +0200144#if CONFIG_LOGICAL_CPUS
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200145 // It is said that we should start core1 after all core0 launched
146 /* becase optimize_link_coherent_ht is moved out from setup_coherent_ht_domain,
147 * So here need to make sure last core0 is started, esp for two way system,
148 * (there may be apic id conflicts in that case)
149 */
150 start_other_cores();
151 wait_all_other_cores_started(bsp_apicid);
Yinghai Luf55b58d2007-02-17 14:28:11 +0000152#endif
153
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200154 /* it will set up chains and store link pair for optimization later */
155 ht_setup_chains_x(sysinfo); // it will init sblnk and sbbusn, nodes, sbdn
Yinghai Luf55b58d2007-02-17 14:28:11 +0000156
Patrick Georgi76e81522010-11-16 21:25:29 +0000157#if CONFIG_SET_FIDVID
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200158 {
159 msr_t msr;
160 msr = rdmsr(0xc0010042);
161 printk(BIOS_DEBUG, "begin msr fid, vid %08x, %08x\n", msr.hi, msr.lo);
162 }
163 enable_fid_change();
164 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
165 init_fidvid_bsp(bsp_apicid);
166 // show final fid and vid
167 {
168 msr_t msr;
169 msr = rdmsr(0xc0010042);
170 printk(BIOS_DEBUG, "end msr fid, vid %08x, %08x\n", msr.hi, msr.lo);
171 }
Yinghai Luf55b58d2007-02-17 14:28:11 +0000172#endif
173
Paul Menzel4549e5a2014-02-02 22:05:48 +0100174 init_timer(); // Need to use TMICT to synchronize FID/VID
Stefan Reinauerbcb8c972010-04-25 18:06:32 +0000175
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200176 needs_reset |= optimize_link_coherent_ht();
177 needs_reset |= optimize_link_incoherent_ht(sysinfo);
178 needs_reset |= mcp55_early_setup_x();
Yinghai Luf55b58d2007-02-17 14:28:11 +0000179
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200180 // fidvid change will issue one LDTSTOP and the HT change will be effective too
181 if (needs_reset) {
182 printk(BIOS_INFO, "ht reset -\n");
183 soft_reset();
184 }
Stefan Reinauerbcb8c972010-04-25 18:06:32 +0000185
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200186 allow_all_aps_stop(bsp_apicid);
Yinghai Luf55b58d2007-02-17 14:28:11 +0000187
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200188 //It's the time to set ctrl in sysinfo now;
Yinghai Luf55b58d2007-02-17 14:28:11 +0000189 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
190
191// enable_smbus(); /* enable in sio_setup */
192
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200193 /* all ap stopped? */
Yinghai Luf55b58d2007-02-17 14:28:11 +0000194
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200195 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
Yinghai Luf55b58d2007-02-17 14:28:11 +0000196
Elyes HAOUAS39aa6302016-09-27 21:22:54 +0200197 post_cache_as_ram(); // bsp swtich stack to RAM and copy sysinfo RAM now
Yinghai Luf55b58d2007-02-17 14:28:11 +0000198}