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