Noah Glovsky | abe40e0 | 2016-04-19 14:55:38 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 14 | #include <stdint.h> |
Patrick Georgi | 12aba82 | 2009-04-30 07:07:22 +0000 | [diff] [blame] | 15 | #include <string.h> |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 16 | #include <device/pci_def.h> |
| 17 | #include <device/pci_ids.h> |
| 18 | #include <arch/io.h> |
| 19 | #include <device/pnp_def.h> |
Edwin Beasant | eb50c7d | 2010-07-06 21:05:04 +0000 | [diff] [blame] | 20 | #include <pc80/mc146818rtc.h> |
Patrick Georgi | 12584e2 | 2010-05-08 09:14:51 +0000 | [diff] [blame] | 21 | #include <console/console.h> |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 22 | #include <cpu/amd/model_fxx_rev.h> |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 23 | #include "southbridge/amd/amd8111/early_smbus.c" |
Stefan Reinauer | 8f2c616 | 2010-04-06 21:50:21 +0000 | [diff] [blame] | 24 | #include <reset.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 25 | #include <northbridge/amd/amdk8/raminit.h> |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 26 | #include "northbridge/amd/amdk8/reset_test.c" |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 27 | #include <cpu/x86/bist.h> |
Edward O'Callaghan | ebe3a7a | 2015-01-05 00:27:54 +1100 | [diff] [blame] | 28 | #include <delay.h> |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 29 | #include "northbridge/amd/amdk8/debug.c" |
Stefan Reinauer | 8f2c616 | 2010-04-06 21:50:21 +0000 | [diff] [blame] | 30 | #include <cpu/amd/mtrr.h> |
Edward O'Callaghan | 8199809 | 2014-04-28 18:07:33 +1000 | [diff] [blame] | 31 | #include <superio/winbond/common/winbond.h> |
| 32 | #include <superio/winbond/w83627hf/w83627hf.h> |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 33 | #include "northbridge/amd/amdk8/setup_resource_map.c" |
| 34 | |
| 35 | #define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1) |
| 36 | |
Damien Zammit | 75a3d1f | 2016-11-28 00:29:10 +1100 | [diff] [blame] | 37 | unsigned get_sbdn(unsigned bus); |
| 38 | |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 39 | static void memreset_setup(void) |
| 40 | { |
Elyes HAOUAS | caccd97 | 2016-10-10 21:25:17 +0200 | [diff] [blame] | 41 | /* GPIO on amd8111 to enable MEMRST ???? */ |
| 42 | outb((1 << 2)|(1 << 0), SMBUS_IO_BASE + 0xc0 + 16); /* REVC_MEMRST_EN = 1 */ |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 43 | outb((1 << 2)|(0 << 0), SMBUS_IO_BASE + 0xc0 + 17); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Uwe Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 46 | static void memreset(int controllers, const struct mem_controller *ctrl) { } |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 47 | |
| 48 | static inline void activate_spd_rom(const struct mem_controller *ctrl) |
| 49 | { |
| 50 | #define SMBUS_HUB 0x18 |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 51 | int ret,i; |
| 52 | unsigned device=(ctrl->channel0[0])>>8; |
Elyes HAOUAS | caccd97 | 2016-10-10 21:25:17 +0200 | [diff] [blame] | 53 | /* the very first write always get COL_STS = 1 and ABRT_STS = 1, so try another time */ |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 54 | i = 2; |
| 55 | do { |
| 56 | ret = smbus_write_byte(SMBUS_HUB, 0x01, device); |
| 57 | } while ((ret != 0) && (i-->0)); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 58 | |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 59 | smbus_write_byte(SMBUS_HUB, 0x03, 0); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 60 | } |
Uwe Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 61 | |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 62 | static inline int spd_read_byte(unsigned device, unsigned address) |
| 63 | { |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 64 | return smbus_read_byte(device, address); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Damien Zammit | 75a3d1f | 2016-11-28 00:29:10 +1100 | [diff] [blame] | 67 | #include "southbridge/amd/amd8111/early_ctrl.c" |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 68 | #include <northbridge/amd/amdk8/amdk8.h> |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 69 | #include "northbridge/amd/amdk8/incoherent_ht.c" |
Stefan Reinauer | 23836e2 | 2010-04-15 12:39:29 +0000 | [diff] [blame] | 70 | #include "northbridge/amd/amdk8/coherent_ht.c" |
Myles Watson | 1725703 | 2009-06-04 20:18:42 +0000 | [diff] [blame] | 71 | #include "northbridge/amd/amdk8/raminit_f.c" |
Stefan Reinauer | c13093b | 2009-09-23 18:51:03 +0000 | [diff] [blame] | 72 | #include "lib/generic_sdram.c" |
Uwe Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 73 | #include "resourcemap.c" |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 74 | #include "cpu/amd/dualcore/dualcore.c" |
Patrick Georgi | 9bd9a90 | 2010-11-20 10:31:00 +0000 | [diff] [blame] | 75 | #include <spd.h> |
Uwe Hermann | 57b2ff8 | 2010-11-21 17:29:59 +0000 | [diff] [blame] | 76 | #include "cpu/amd/model_fxx/init_cpus.c" |
| 77 | #include "cpu/amd/model_fxx/fidvid.c" |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 78 | |
Elyes HAOUAS | 6350a2e | 2016-09-16 20:49:38 +0200 | [diff] [blame] | 79 | #define RC0 ((1 << 0)<<8) |
| 80 | #define RC1 ((1 << 1)<<8) |
| 81 | #define RC2 ((1 << 2)<<8) |
| 82 | #define RC3 ((1 << 3)<<8) |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 83 | |
Patrick Georgi | ce6fb1e | 2010-03-17 22:44:39 +0000 | [diff] [blame] | 84 | void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx) |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 85 | { |
| 86 | static const uint16_t spd_addr[] = { |
Elyes HAOUAS | caccd97 | 2016-10-10 21:25:17 +0200 | [diff] [blame] | 87 | /* first node */ |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 88 | RC0|DIMM0, RC0|DIMM2, 0, 0, |
| 89 | RC0|DIMM1, RC0|DIMM3, 0, 0, |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 90 | #if CONFIG_MAX_PHYSICAL_CPUS > 1 |
Elyes HAOUAS | caccd97 | 2016-10-10 21:25:17 +0200 | [diff] [blame] | 91 | /* second node */ |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 92 | RC1|DIMM0, RC1|DIMM2, RC1|DIMM4, RC1|DIMM6, |
| 93 | RC1|DIMM1, RC1|DIMM3, RC1|DIMM5, RC1|DIMM7, |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 94 | #endif |
| 95 | #if CONFIG_MAX_PHYSICAL_CPUS > 2 |
Elyes HAOUAS | caccd97 | 2016-10-10 21:25:17 +0200 | [diff] [blame] | 96 | /* third node */ |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 97 | RC2|DIMM0, RC2|DIMM2, 0, 0, |
| 98 | RC2|DIMM1, RC2|DIMM3, 0, 0, |
Elyes HAOUAS | caccd97 | 2016-10-10 21:25:17 +0200 | [diff] [blame] | 99 | /* four node */ |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 100 | RC3|DIMM0, RC3|DIMM2, RC3|DIMM4, RC3|DIMM6, |
| 101 | RC3|DIMM1, RC3|DIMM3, RC3|DIMM5, RC3|DIMM7, |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 102 | #endif |
| 103 | |
| 104 | }; |
| 105 | |
Patrick Georgi | bbc880e | 2012-11-20 18:20:56 +0100 | [diff] [blame] | 106 | struct sys_info *sysinfo = &sysinfo_car; |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 107 | int needs_reset; |
| 108 | unsigned bsp_apicid = 0; |
Patrick Georgi | 76e8152 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 109 | #if CONFIG_SET_FIDVID |
Dan Lykowski | 6ef8e0f | 2009-01-12 16:16:08 +0000 | [diff] [blame] | 110 | struct cpuid_result cpuid1; |
Myles Watson | 6e23576 | 2009-09-29 14:56:15 +0000 | [diff] [blame] | 111 | #endif |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 112 | |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 113 | if (bist == 0) |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 114 | bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 115 | |
Edward O'Callaghan | 8199809 | 2014-04-28 18:07:33 +1000 | [diff] [blame] | 116 | winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE); |
| 117 | console_init(); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 118 | |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 119 | /* Halt if there was a built in self test failure */ |
| 120 | report_bist_failure(bist); |
| 121 | |
Myles Watson | 08e0fb8 | 2010-03-22 16:33:25 +0000 | [diff] [blame] | 122 | printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 123 | |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 124 | setup_mb_resource_map(); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 125 | |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 126 | printk(BIOS_DEBUG, "bsp_apicid=%02x\n", bsp_apicid); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 127 | |
Elyes HAOUAS | caccd97 | 2016-10-10 21:25:17 +0200 | [diff] [blame] | 128 | set_sysinfo_in_ram(0); /* in BSP so could hold all ap until sysinfo is in ram */ |
| 129 | setup_coherent_ht_domain(); /* routing table and start other core0 */ |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 130 | |
| 131 | wait_all_core0_started(); |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 132 | #if CONFIG_LOGICAL_CPUS |
Elyes HAOUAS | caccd97 | 2016-10-10 21:25:17 +0200 | [diff] [blame] | 133 | /* It is said that we should start core1 after all core0 launched */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 134 | /* becase optimize_link_coherent_ht is moved out from setup_coherent_ht_domain, |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 135 | * So here need to make sure last core0 is started, esp for two way system, |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 136 | * (there may be apic id conflicts in that case) |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 137 | */ |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 138 | start_other_cores(); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 139 | wait_all_other_cores_started(bsp_apicid); |
| 140 | #endif |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 141 | |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 142 | /* it will set up chains and store link pair for optimization later */ |
Elyes HAOUAS | caccd97 | 2016-10-10 21:25:17 +0200 | [diff] [blame] | 143 | ht_setup_chains_x(sysinfo); /* it will init sblnk and sbbusn, nodes, sbdn */ |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 144 | |
Patrick Georgi | 76e8152 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 145 | #if CONFIG_SET_FIDVID |
Dan Lykowski | 6ef8e0f | 2009-01-12 16:16:08 +0000 | [diff] [blame] | 146 | /* Check to see if processor is capable of changing FIDVID */ |
| 147 | /* otherwise it will throw a GP# when reading FIDVID_STATUS */ |
| 148 | cpuid1 = cpuid(0x80000007); |
Uwe Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 149 | if ((cpuid1.edx & 0x6) == 0x6) { |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 150 | |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 151 | { |
Dan Lykowski | 6ef8e0f | 2009-01-12 16:16:08 +0000 | [diff] [blame] | 152 | /* Read FIDVID_STATUS */ |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 153 | msr_t msr; |
| 154 | msr = rdmsr(0xc0010042); |
| 155 | printk(BIOS_DEBUG, "begin msr fid, vid %08x%08x\n", msr.hi, msr.lo); |
| 156 | } |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 157 | |
| 158 | enable_fid_change(); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 159 | enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn); |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 160 | init_fidvid_bsp(bsp_apicid); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 161 | |
Elyes HAOUAS | caccd97 | 2016-10-10 21:25:17 +0200 | [diff] [blame] | 162 | /* show final fid and vid */ |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 163 | { |
| 164 | msr_t msr; |
| 165 | msr = rdmsr(0xc0010042); |
| 166 | printk(BIOS_DEBUG, "end msr fid, vid %08x%08x\n", msr.hi, msr.lo); |
| 167 | } |
Dan Lykowski | 6ef8e0f | 2009-01-12 16:16:08 +0000 | [diff] [blame] | 168 | |
| 169 | } else { |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 170 | printk(BIOS_DEBUG, "Changing FIDVID not supported\n"); |
Dan Lykowski | 6ef8e0f | 2009-01-12 16:16:08 +0000 | [diff] [blame] | 171 | } |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 172 | #endif |
| 173 | |
| 174 | #if 1 |
| 175 | needs_reset = optimize_link_coherent_ht(); |
| 176 | needs_reset |= optimize_link_incoherent_ht(sysinfo); |
| 177 | |
Elyes HAOUAS | caccd97 | 2016-10-10 21:25:17 +0200 | [diff] [blame] | 178 | /* fidvid change will issue one LDTSTOP and the HT change will be effective too */ |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 179 | if (needs_reset) { |
| 180 | printk(BIOS_INFO, "ht reset -\n"); |
| 181 | soft_reset_x(sysinfo->sbbusn, sysinfo->sbdn); |
| 182 | } |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 183 | #endif |
| 184 | allow_all_aps_stop(bsp_apicid); |
| 185 | |
Elyes HAOUAS | caccd97 | 2016-10-10 21:25:17 +0200 | [diff] [blame] | 186 | /* It's the time to set ctrl in sysinfo now; */ |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 187 | fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 188 | |
| 189 | enable_smbus(); |
| 190 | |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 191 | memreset_setup(); |
| 192 | |
Elyes HAOUAS | caccd97 | 2016-10-10 21:25:17 +0200 | [diff] [blame] | 193 | /* do we need apci timer, tsc...., only debug need it for better output */ |
Elyes HAOUAS | 08449eb | 2016-09-29 19:57:09 +0200 | [diff] [blame] | 194 | /* all ap stopped? */ |
Elyes HAOUAS | caccd97 | 2016-10-10 21:25:17 +0200 | [diff] [blame] | 195 | /* Need to use TMICT to synchronize FID/VID */ |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 196 | |
| 197 | sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo); |
| 198 | |
Elyes HAOUAS | caccd97 | 2016-10-10 21:25:17 +0200 | [diff] [blame] | 199 | post_cache_as_ram(); /* bsp swtich stack to RAM and copy sysinfo RAM now */ |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 200 | } |