Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 1 | #if CONFIG_K8_REV_F_SUPPORT |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 2 | #define K8_REV_F_SUPPORT_F0_F1_WORKAROUND 0 |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 3 | #endif |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 4 | |
| 5 | #include <stdint.h> |
Patrick Georgi | 12aba82 | 2009-04-30 07:07:22 +0000 | [diff] [blame] | 6 | #include <string.h> |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 7 | #include <device/pci_def.h> |
| 8 | #include <device/pci_ids.h> |
| 9 | #include <arch/io.h> |
| 10 | #include <device/pnp_def.h> |
| 11 | #include <arch/romcc_io.h> |
Edwin Beasant | eb50c7d | 2010-07-06 21:05:04 +0000 | [diff] [blame] | 12 | #include <pc80/mc146818rtc.h> |
Patrick Georgi | 12584e2 | 2010-05-08 09:14:51 +0000 | [diff] [blame] | 13 | #include <console/console.h> |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 14 | #include <cpu/amd/model_fxx_rev.h> |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 15 | #include "southbridge/amd/amd8111/early_smbus.c" |
Stefan Reinauer | 8f2c616 | 2010-04-06 21:50:21 +0000 | [diff] [blame] | 16 | #include <reset.h> |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 17 | #include "northbridge/amd/amdk8/raminit.h" |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 18 | #include "northbridge/amd/amdk8/reset_test.c" |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 19 | #include "cpu/x86/bist.h" |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 20 | #include "lib/delay.c" |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 21 | #include "northbridge/amd/amdk8/debug.c" |
Stefan Reinauer | 8f2c616 | 2010-04-06 21:50:21 +0000 | [diff] [blame] | 22 | #include "cpu/x86/mtrr/earlymtrr.c" |
| 23 | #include <cpu/amd/mtrr.h> |
stepan | 8301d83 | 2010-12-08 07:07:33 +0000 | [diff] [blame] | 24 | #include "superio/winbond/w83627hf/early_serial.c" |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 25 | #include "northbridge/amd/amdk8/setup_resource_map.c" |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 26 | #include "southbridge/amd/amd8111/early_ctrl.c" |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 27 | |
| 28 | #define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1) |
| 29 | |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 30 | static void memreset_setup(void) |
| 31 | { |
| 32 | //GPIO on amd8111 to enable MEMRST ???? |
Uwe Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 33 | outb((1<<2)|(1<<0), SMBUS_IO_BASE + 0xc0 + 16); //REVC_MEMRST_EN=1 |
| 34 | outb((1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 17); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Uwe Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 37 | static void memreset(int controllers, const struct mem_controller *ctrl) { } |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 38 | |
| 39 | static inline void activate_spd_rom(const struct mem_controller *ctrl) |
| 40 | { |
| 41 | #define SMBUS_HUB 0x18 |
| 42 | int ret,i; |
| 43 | unsigned device=(ctrl->channel0[0])>>8; |
| 44 | /* the very first write always get COL_STS=1 and ABRT_STS=1, so try another time*/ |
| 45 | i=2; |
| 46 | do { |
| 47 | ret = smbus_write_byte(SMBUS_HUB, 0x01, device); |
| 48 | } while ((ret!=0) && (i-->0)); |
| 49 | |
| 50 | smbus_write_byte(SMBUS_HUB, 0x03, 0); |
| 51 | } |
Uwe Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 52 | |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 53 | #if 0 |
| 54 | static inline void change_i2c_mux(unsigned device) |
| 55 | { |
| 56 | #define SMBUS_HUB 0x18 |
| 57 | int ret, i; |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 58 | print_debug("change_i2c_mux i="); print_debug_hex8(device); print_debug("\n"); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 59 | i=2; |
| 60 | do { |
| 61 | ret = smbus_write_byte(SMBUS_HUB, 0x01, device); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 62 | print_debug("change_i2c_mux 1 ret="); print_debug_hex32(ret); print_debug("\n"); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 63 | } while ((ret!=0) && (i-->0)); |
| 64 | ret = smbus_write_byte(SMBUS_HUB, 0x03, 0); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 65 | print_debug("change_i2c_mux 2 ret="); print_debug_hex32(ret); print_debug("\n"); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 66 | } |
| 67 | #endif |
| 68 | |
| 69 | static inline int spd_read_byte(unsigned device, unsigned address) |
| 70 | { |
| 71 | return smbus_read_byte(device, address); |
| 72 | } |
| 73 | |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 74 | #include "northbridge/amd/amdk8/amdk8.h" |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 75 | #include "northbridge/amd/amdk8/incoherent_ht.c" |
Stefan Reinauer | 23836e2 | 2010-04-15 12:39:29 +0000 | [diff] [blame] | 76 | #include "northbridge/amd/amdk8/coherent_ht.c" |
Myles Watson | 1725703 | 2009-06-04 20:18:42 +0000 | [diff] [blame] | 77 | #include "northbridge/amd/amdk8/raminit_f.c" |
Stefan Reinauer | c13093b | 2009-09-23 18:51:03 +0000 | [diff] [blame] | 78 | #include "lib/generic_sdram.c" |
Uwe Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 79 | #include "resourcemap.c" |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 80 | #include "cpu/amd/dualcore/dualcore.c" |
Patrick Georgi | 9bd9a90 | 2010-11-20 10:31:00 +0000 | [diff] [blame] | 81 | #include <spd.h> |
Uwe Hermann | 57b2ff8 | 2010-11-21 17:29:59 +0000 | [diff] [blame] | 82 | #include "cpu/amd/car/post_cache_as_ram.c" |
| 83 | #include "cpu/amd/model_fxx/init_cpus.c" |
| 84 | #include "cpu/amd/model_fxx/fidvid.c" |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 85 | |
| 86 | #define RC0 ((1<<0)<<8) |
| 87 | #define RC1 ((1<<1)<<8) |
| 88 | #define RC2 ((1<<2)<<8) |
| 89 | #define RC3 ((1<<3)<<8) |
| 90 | |
Patrick Georgi | ce6fb1e | 2010-03-17 22:44:39 +0000 | [diff] [blame] | 91 | 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] | 92 | { |
| 93 | static const uint16_t spd_addr[] = { |
| 94 | //first node |
| 95 | RC0|DIMM0, RC0|DIMM2, 0, 0, |
| 96 | RC0|DIMM1, RC0|DIMM3, 0, 0, |
| 97 | #if CONFIG_MAX_PHYSICAL_CPUS > 1 |
| 98 | //second node |
| 99 | RC1|DIMM0, RC1|DIMM2, RC1|DIMM4, RC1|DIMM6, |
| 100 | RC1|DIMM1, RC1|DIMM3, RC1|DIMM5, RC1|DIMM7, |
| 101 | #endif |
| 102 | #if CONFIG_MAX_PHYSICAL_CPUS > 2 |
| 103 | // third node |
| 104 | RC2|DIMM0, RC2|DIMM2, 0, 0, |
| 105 | RC2|DIMM1, RC2|DIMM3, 0, 0, |
| 106 | // four node |
| 107 | RC3|DIMM0, RC3|DIMM2, RC3|DIMM4, RC3|DIMM6, |
| 108 | RC3|DIMM1, RC3|DIMM3, RC3|DIMM5, RC3|DIMM7, |
| 109 | #endif |
| 110 | |
| 111 | }; |
| 112 | |
Patrick Georgi | bbc880e | 2012-11-20 18:20:56 +0100 | [diff] [blame^] | 113 | struct sys_info *sysinfo = &sysinfo_car; |
Myles Watson | 6e23576 | 2009-09-29 14:56:15 +0000 | [diff] [blame] | 114 | int needs_reset; |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 115 | unsigned bsp_apicid = 0; |
Patrick Georgi | 76e8152 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 116 | #if CONFIG_SET_FIDVID |
Dan Lykowski | 6ef8e0f | 2009-01-12 16:16:08 +0000 | [diff] [blame] | 117 | struct cpuid_result cpuid1; |
Myles Watson | 6e23576 | 2009-09-29 14:56:15 +0000 | [diff] [blame] | 118 | #endif |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 119 | |
Uwe Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 120 | if (bist == 0) |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 121 | bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 122 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 123 | w83627hf_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 124 | console_init(); |
| 125 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 126 | // dump_mem(CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE-0x200, CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 127 | |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 128 | /* Halt if there was a built in self test failure */ |
| 129 | report_bist_failure(bist); |
| 130 | |
Myles Watson | 08e0fb8 | 2010-03-22 16:33:25 +0000 | [diff] [blame] | 131 | printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 132 | |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 133 | setup_mb_resource_map(); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 134 | #if 0 |
| 135 | dump_pci_device(PCI_DEV(0, 0x18, 0)); |
| 136 | dump_pci_device(PCI_DEV(0, 0x19, 0)); |
| 137 | #endif |
| 138 | |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 139 | print_debug("bsp_apicid="); print_debug_hex8(bsp_apicid); print_debug("\n"); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 140 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 141 | #if CONFIG_MEM_TRAIN_SEQ == 1 |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 142 | set_sysinfo_in_ram(0); // in BSP so could hold all ap until sysinfo is in ram |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 143 | #endif |
| 144 | setup_coherent_ht_domain(); // routing table and start other core0 |
| 145 | |
| 146 | wait_all_core0_started(); |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 147 | #if CONFIG_LOGICAL_CPUS |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 148 | // It is said that we should start core1 after all core0 launched |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 149 | /* 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] | 150 | * 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] | 151 | * (there may be apic id conflicts in that case) |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 152 | */ |
| 153 | start_other_cores(); |
| 154 | wait_all_other_cores_started(bsp_apicid); |
| 155 | #endif |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 156 | |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 157 | /* it will set up chains and store link pair for optimization later */ |
| 158 | ht_setup_chains_x(sysinfo); // it will init sblnk and sbbusn, nodes, sbdn |
| 159 | |
| 160 | #if 0 |
| 161 | //it your CPU min fid is 1G, you can change HT to 1G and FID to max one time. |
| 162 | needs_reset = optimize_link_coherent_ht(); |
| 163 | needs_reset |= optimize_link_incoherent_ht(sysinfo); |
| 164 | #endif |
| 165 | |
Patrick Georgi | 76e8152 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 166 | #if CONFIG_SET_FIDVID |
Dan Lykowski | 6ef8e0f | 2009-01-12 16:16:08 +0000 | [diff] [blame] | 167 | /* Check to see if processor is capable of changing FIDVID */ |
| 168 | /* otherwise it will throw a GP# when reading FIDVID_STATUS */ |
| 169 | cpuid1 = cpuid(0x80000007); |
Uwe Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 170 | if ((cpuid1.edx & 0x6) == 0x6) { |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 171 | |
| 172 | { |
Dan Lykowski | 6ef8e0f | 2009-01-12 16:16:08 +0000 | [diff] [blame] | 173 | /* Read FIDVID_STATUS */ |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 174 | msr_t msr; |
| 175 | msr=rdmsr(0xc0010042); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 176 | print_debug("begin msr fid, vid "); print_debug_hex32( msr.hi ); print_debug_hex32(msr.lo); print_debug("\n"); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | enable_fid_change(); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 180 | enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 181 | init_fidvid_bsp(bsp_apicid); |
| 182 | |
| 183 | // show final fid and vid |
| 184 | { |
| 185 | msr_t msr; |
| 186 | msr=rdmsr(0xc0010042); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 187 | print_debug("end msr fid, vid "); print_debug_hex32( msr.hi ); print_debug_hex32(msr.lo); print_debug("\n"); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 188 | } |
Dan Lykowski | 6ef8e0f | 2009-01-12 16:16:08 +0000 | [diff] [blame] | 189 | |
| 190 | } else { |
| 191 | print_debug("Changing FIDVID not supported\n"); |
| 192 | } |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 193 | #endif |
| 194 | |
| 195 | #if 1 |
| 196 | needs_reset = optimize_link_coherent_ht(); |
| 197 | needs_reset |= optimize_link_incoherent_ht(sysinfo); |
| 198 | |
| 199 | // fidvid change will issue one LDTSTOP and the HT change will be effective too |
| 200 | if (needs_reset) { |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 201 | print_info("ht reset -\n"); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 202 | soft_reset_x(sysinfo->sbbusn, sysinfo->sbdn); |
| 203 | } |
| 204 | #endif |
| 205 | allow_all_aps_stop(bsp_apicid); |
| 206 | |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 207 | //It's the time to set ctrl in sysinfo now; |
| 208 | fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 209 | |
| 210 | enable_smbus(); |
| 211 | |
| 212 | #if 0 |
Myles Watson | 6e23576 | 2009-09-29 14:56:15 +0000 | [diff] [blame] | 213 | int i; |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 214 | for(i=0;i<4;i++) { |
| 215 | activate_spd_rom(&cpu[i]); |
| 216 | dump_smbus_registers(); |
| 217 | } |
| 218 | #endif |
| 219 | |
| 220 | #if 0 |
| 221 | for(i=1;i<256;i<<=1) { |
| 222 | change_i2c_mux(i); |
| 223 | dump_smbus_registers(); |
| 224 | } |
| 225 | #endif |
| 226 | |
| 227 | memreset_setup(); |
| 228 | |
| 229 | //do we need apci timer, tsc...., only debug need it for better output |
| 230 | /* all ap stopped? */ |
| 231 | // init_timer(); // Need to use TMICT to synconize FID/VID |
| 232 | |
| 233 | sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo); |
| 234 | |
| 235 | #if 0 |
| 236 | print_pci_devices(); |
| 237 | #endif |
| 238 | |
| 239 | #if 0 |
| 240 | // dump_pci_devices(); |
| 241 | dump_pci_device_index_wait(PCI_DEV(0, 0x18, 2), 0x98); |
| 242 | dump_pci_device_index_wait(PCI_DEV(0, 0x19, 2), 0x98); |
| 243 | #endif |
| 244 | |
| 245 | 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] | 246 | } |