Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 3 | * |
| 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 Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 18 | #include <stdint.h> |
Patrick Georgi | 12aba82 | 2009-04-30 07:07:22 +0000 | [diff] [blame] | 19 | #include <string.h> |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 20 | #include <device/pci_def.h> |
| 21 | #include <device/pci_ids.h> |
| 22 | #include <arch/io.h> |
| 23 | #include <device/pnp_def.h> |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 24 | #include <cpu/x86/lapic.h> |
Edwin Beasant | eb50c7d | 2010-07-06 21:05:04 +0000 | [diff] [blame] | 25 | #include <pc80/mc146818rtc.h> |
Patrick Georgi | 12584e2 | 2010-05-08 09:14:51 +0000 | [diff] [blame] | 26 | #include <console/console.h> |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 27 | #include <lib.h> |
Uwe Hermann | 6dc92f0 | 2010-11-21 11:36:03 +0000 | [diff] [blame] | 28 | #include <spd.h> |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 29 | #include <cpu/amd/model_fxx_rev.h> |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 30 | #include "southbridge/nvidia/mcp55/early_smbus.c" // for enable the FAN |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 31 | #include <northbridge/amd/amdk8/raminit.h> |
Patrick Georgi | 82d9a31 | 2016-01-21 12:46:10 +0100 | [diff] [blame] | 32 | #include <delay.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 33 | #include <cpu/x86/lapic.h> |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 34 | #include "northbridge/amd/amdk8/reset_test.c" |
Edward O'Callaghan | beb0f26 | 2014-04-29 13:09:50 +1000 | [diff] [blame] | 35 | #include <superio/winbond/common/winbond.h> |
| 36 | #include <superio/winbond/w83627hf/w83627hf.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 37 | #include <cpu/x86/bist.h> |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 38 | #include "northbridge/amd/amdk8/debug.c" |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 39 | #include "northbridge/amd/amdk8/setup_resource_map.c" |
| 40 | |
| 41 | #define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1) |
Uwe Hermann | 9b9791c | 2010-12-06 18:17:01 +0000 | [diff] [blame] | 42 | #define DUMMY_DEV PNP_DEV(0x2e, 0) |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 43 | |
Damien Zammit | 75a3d1f | 2016-11-28 00:29:10 +1100 | [diff] [blame] | 44 | unsigned get_sbdn(unsigned bus); |
| 45 | |
| 46 | unsigned 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 Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 57 | static void memreset(int controllers, const struct mem_controller *ctrl) { } |
| 58 | static void activate_spd_rom(const struct mem_controller *ctrl) { } |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 59 | |
| 60 | static inline int spd_read_byte(unsigned device, unsigned address) |
| 61 | { |
| 62 | return smbus_read_byte(device, address); |
| 63 | } |
| 64 | |
Damien Zammit | 75a3d1f | 2016-11-28 00:29:10 +1100 | [diff] [blame] | 65 | #include "southbridge/nvidia/mcp55/early_ctrl.c" |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 66 | #include <northbridge/amd/amdk8/f.h> |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 67 | #include "northbridge/amd/amdk8/incoherent_ht.c" |
Stefan Reinauer | 23836e2 | 2010-04-15 12:39:29 +0000 | [diff] [blame] | 68 | #include "northbridge/amd/amdk8/coherent_ht.c" |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 69 | #include "northbridge/amd/amdk8/raminit_f.c" |
Stefan Reinauer | c13093b | 2009-09-23 18:51:03 +0000 | [diff] [blame] | 70 | #include "lib/generic_sdram.c" |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 71 | #include "resourcemap.c" |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 72 | #include "cpu/amd/dualcore/dualcore.c" |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 73 | #include <southbridge/nvidia/mcp55/early_setup_ss.h> |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 74 | #include "southbridge/nvidia/mcp55/early_setup_car.c" |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 75 | #include "cpu/amd/model_fxx/init_cpus.c" |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 76 | #include "cpu/amd/model_fxx/fidvid.c" |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 77 | #include "northbridge/amd/amdk8/early_ht.c" |
| 78 | |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 79 | static void sio_setup(void) |
| 80 | { |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 81 | uint32_t dword; |
| 82 | uint8_t byte; |
Uwe Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 83 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 84 | enable_smbus(); |
Elyes HAOUAS | a5aad2e | 2016-09-19 09:47:16 -0600 | [diff] [blame] | 85 | // 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 Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 87 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 88 | 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 Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 91 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 92 | 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 Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 95 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 96 | 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 Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Patrick Georgi | ce6fb1e | 2010-03-17 22:44:39 +0000 | [diff] [blame] | 101 | void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx) |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 102 | { |
| 103 | static const uint16_t spd_addr [] = { |
Uwe Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 104 | // 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 Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 112 | struct sys_info *sysinfo = &sysinfo_car; |
| 113 | int needs_reset = 0; |
| 114 | unsigned bsp_apicid = 0; |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 115 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 116 | if (!cpu_init_detectedx && boot_cpu()) { |
Patrick Georgi | ce6fb1e | 2010-03-17 22:44:39 +0000 | [diff] [blame] | 117 | /* Nothing special needs to be done to find bus 0 */ |
| 118 | /* Allow the HT devices to be found */ |
Patrick Georgi | ce6fb1e | 2010-03-17 22:44:39 +0000 | [diff] [blame] | 119 | enumerate_ht_chain(); |
Patrick Georgi | ce6fb1e | 2010-03-17 22:44:39 +0000 | [diff] [blame] | 120 | sio_setup(); |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 121 | } |
Patrick Georgi | ce6fb1e | 2010-03-17 22:44:39 +0000 | [diff] [blame] | 122 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 123 | if (bist == 0) |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 124 | bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 125 | |
Edward O'Callaghan | beb0f26 | 2014-04-29 13:09:50 +1000 | [diff] [blame] | 126 | w83627hf_set_clksel_48(DUMMY_DEV); |
| 127 | winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 128 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 129 | console_init(); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 130 | |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 131 | /* Halt if there was a built in self test failure */ |
| 132 | report_bist_failure(bist); |
| 133 | |
Myles Watson | 08e0fb8 | 2010-03-22 16:33:25 +0000 | [diff] [blame] | 134 | printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 135 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 136 | setup_mb_resource_map(); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 137 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 138 | printk(BIOS_DEBUG, "bsp_apicid=%02x\n", bsp_apicid); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 139 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 140 | 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 Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 142 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 143 | wait_all_core0_started(); |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 144 | #if CONFIG_LOGICAL_CPUS |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 145 | // 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 Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 152 | #endif |
| 153 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 154 | /* 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 Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 156 | |
Patrick Georgi | 76e8152 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 157 | #if CONFIG_SET_FIDVID |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 158 | { |
| 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 Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 172 | #endif |
| 173 | |
Paul Menzel | 4549e5a | 2014-02-02 22:05:48 +0100 | [diff] [blame] | 174 | init_timer(); // Need to use TMICT to synchronize FID/VID |
Stefan Reinauer | bcb8c97 | 2010-04-25 18:06:32 +0000 | [diff] [blame] | 175 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 176 | needs_reset |= optimize_link_coherent_ht(); |
| 177 | needs_reset |= optimize_link_incoherent_ht(sysinfo); |
| 178 | needs_reset |= mcp55_early_setup_x(); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 179 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 180 | // 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 Reinauer | bcb8c97 | 2010-04-25 18:06:32 +0000 | [diff] [blame] | 185 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 186 | allow_all_aps_stop(bsp_apicid); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 187 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 188 | //It's the time to set ctrl in sysinfo now; |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 189 | fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr); |
| 190 | |
| 191 | // enable_smbus(); /* enable in sio_setup */ |
| 192 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 193 | /* all ap stopped? */ |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 194 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 195 | sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 196 | |
Elyes HAOUAS | 39aa630 | 2016-09-27 21:22:54 +0200 | [diff] [blame] | 197 | post_cache_as_ram(); // bsp swtich stack to RAM and copy sysinfo RAM now |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 198 | } |