Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [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; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 13 | */ |
| 14 | |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 15 | #include <stdint.h> |
Patrick Georgi | 12aba82 | 2009-04-30 07:07:22 +0000 | [diff] [blame] | 16 | #include <string.h> |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 17 | #include <device/pci_def.h> |
| 18 | #include <device/pci_ids.h> |
| 19 | #include <arch/io.h> |
| 20 | #include <device/pnp_def.h> |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 21 | #include <cpu/x86/lapic.h> |
Edwin Beasant | eb50c7d | 2010-07-06 21:05:04 +0000 | [diff] [blame] | 22 | #include <pc80/mc146818rtc.h> |
Patrick Georgi | 12584e2 | 2010-05-08 09:14:51 +0000 | [diff] [blame] | 23 | #include <console/console.h> |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 24 | #include <lib.h> |
Uwe Hermann | 6dc92f0 | 2010-11-21 11:36:03 +0000 | [diff] [blame] | 25 | #include <spd.h> |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 26 | #include <cpu/amd/model_fxx_rev.h> |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 27 | #include "southbridge/nvidia/mcp55/early_smbus.c" // for enable the FAN |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 28 | #include <northbridge/amd/amdk8/raminit.h> |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 29 | #include "lib/delay.c" |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 30 | #include <cpu/x86/lapic.h> |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 31 | #include "northbridge/amd/amdk8/reset_test.c" |
Edward O'Callaghan | beb0f26 | 2014-04-29 13:09:50 +1000 | [diff] [blame] | 32 | #include <superio/winbond/common/winbond.h> |
| 33 | #include <superio/winbond/w83627hf/w83627hf.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 34 | #include <cpu/x86/bist.h> |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 35 | #include "northbridge/amd/amdk8/debug.c" |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 36 | #include "northbridge/amd/amdk8/setup_resource_map.c" |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 37 | #include "southbridge/nvidia/mcp55/early_ctrl.c" |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 38 | |
| 39 | #define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1) |
Uwe Hermann | 9b9791c | 2010-12-06 18:17:01 +0000 | [diff] [blame] | 40 | #define DUMMY_DEV PNP_DEV(0x2e, 0) |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 41 | |
Uwe Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 42 | static void memreset(int controllers, const struct mem_controller *ctrl) { } |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 43 | |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 44 | static inline void activate_spd_rom(const struct mem_controller *ctrl) |
| 45 | { |
Stefan Reinauer | 523ebd9 | 2010-04-14 18:59:42 +0000 | [diff] [blame] | 46 | #if 0 |
| 47 | /* We don't do any switching yet. */ |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 48 | #define SMBUS_SWITCH1 0x48 |
| 49 | #define SMBUS_SWITCH2 0x49 |
| 50 | unsigned device=(ctrl->channel0[0])>>8; |
| 51 | smbus_send_byte(SMBUS_SWITCH1, device); |
| 52 | smbus_send_byte(SMBUS_SWITCH2, (device >> 4) & 0x0f); |
Stefan Reinauer | 523ebd9 | 2010-04-14 18:59:42 +0000 | [diff] [blame] | 53 | #endif |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 56 | static inline int spd_read_byte(unsigned device, unsigned address) |
| 57 | { |
| 58 | return smbus_read_byte(device, address); |
| 59 | } |
| 60 | |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 61 | #include <northbridge/amd/amdk8/f.h> |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 62 | #include "northbridge/amd/amdk8/incoherent_ht.c" |
Stefan Reinauer | 23836e2 | 2010-04-15 12:39:29 +0000 | [diff] [blame] | 63 | #include "northbridge/amd/amdk8/coherent_ht.c" |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 64 | #include "northbridge/amd/amdk8/raminit_f.c" |
Stefan Reinauer | c13093b | 2009-09-23 18:51:03 +0000 | [diff] [blame] | 65 | #include "lib/generic_sdram.c" |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 66 | #include "resourcemap.c" |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 67 | #include "cpu/amd/dualcore/dualcore.c" |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 68 | #include <southbridge/nvidia/mcp55/early_setup_ss.h> |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 69 | #include "southbridge/nvidia/mcp55/early_setup_car.c" |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 70 | #include "cpu/amd/model_fxx/init_cpus.c" |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 71 | #include "cpu/amd/model_fxx/fidvid.c" |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 72 | #include "northbridge/amd/amdk8/early_ht.c" |
| 73 | |
| 74 | static void sio_setup(void) |
| 75 | { |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 76 | uint32_t dword; |
| 77 | uint8_t byte; |
| 78 | |
| 79 | enable_smbus(); |
| 80 | // smbusx_write_byte(1, (0x58>>1), 0, 0x80); /* select bank0 */ |
| 81 | smbusx_write_byte(1, (0x58 >> 1), 0xb1, 0xff); /* set FAN ctrl to DC mode */ |
| 82 | |
| 83 | byte = pci_read_config8(PCI_DEV(0, MCP55_DEVN_BASE + 1, 0), 0x7b); |
| 84 | byte |= 0x20; |
| 85 | pci_write_config8(PCI_DEV(0, MCP55_DEVN_BASE + 1, 0), 0x7b, byte); |
| 86 | |
| 87 | dword = pci_read_config32(PCI_DEV(0, MCP55_DEVN_BASE + 1, 0), 0xa0); |
| 88 | dword |= (1 << 0); |
| 89 | pci_write_config32(PCI_DEV(0, MCP55_DEVN_BASE + 1, 0), 0xa0, dword); |
| 90 | |
| 91 | dword = pci_read_config32(PCI_DEV(0, MCP55_DEVN_BASE + 1, 0), 0xa4); |
| 92 | dword |= (1 << 16); |
| 93 | pci_write_config32(PCI_DEV(0, MCP55_DEVN_BASE + 1, 0), 0xa4, dword); |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 96 | /* We have no idea where the SMBUS switch is. This doesn't do anything ATM. */ |
| 97 | #define RC0 (2<<8) |
| 98 | #define RC1 (1<<8) |
| 99 | |
Patrick Georgi | ce6fb1e | 2010-03-17 22:44:39 +0000 | [diff] [blame] | 100 | void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx) |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 101 | { |
| 102 | /* The SPD is being read from the CPU1 (marked CPU2 on the board) and we |
| 103 | don't know how to switch the SMBus to decode the CPU0 SPDs. So, The |
| 104 | memory on each CPU must be an exact match. |
| 105 | */ |
| 106 | static const uint16_t spd_addr[] = { |
Stefan Reinauer | 523ebd9 | 2010-04-14 18:59:42 +0000 | [diff] [blame] | 107 | // Node 0 |
Uwe Hermann | 6dc92f0 | 2010-11-21 11:36:03 +0000 | [diff] [blame] | 108 | RC0 | DIMM0, RC0 | DIMM2, |
| 109 | RC0 | DIMM4, RC0 | DIMM6, |
| 110 | RC0 | DIMM1, RC0 | DIMM3, |
| 111 | RC0 | DIMM5, RC0 | DIMM7, |
Stefan Reinauer | 523ebd9 | 2010-04-14 18:59:42 +0000 | [diff] [blame] | 112 | // Node 1 |
Uwe Hermann | 6dc92f0 | 2010-11-21 11:36:03 +0000 | [diff] [blame] | 113 | RC1 | DIMM0, RC1 | DIMM2, |
| 114 | RC1 | DIMM4, RC1 | DIMM6, |
| 115 | RC1 | DIMM1, RC1 | DIMM3, |
| 116 | RC1 | DIMM5, RC1 | DIMM7, |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 117 | }; |
| 118 | |
Patrick Georgi | bbc880e | 2012-11-20 18:20:56 +0100 | [diff] [blame] | 119 | struct sys_info *sysinfo = &sysinfo_car; |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 120 | int needs_reset = 0; |
| 121 | unsigned bsp_apicid = 0; |
| 122 | |
Patrick Georgi | 2bd9100 | 2010-03-18 16:46:50 +0000 | [diff] [blame] | 123 | if (!cpu_init_detectedx && boot_cpu()) { |
Patrick Georgi | ce6fb1e | 2010-03-17 22:44:39 +0000 | [diff] [blame] | 124 | /* Nothing special needs to be done to find bus 0 */ |
| 125 | /* Allow the HT devices to be found */ |
Patrick Georgi | ce6fb1e | 2010-03-17 22:44:39 +0000 | [diff] [blame] | 126 | enumerate_ht_chain(); |
Patrick Georgi | ce6fb1e | 2010-03-17 22:44:39 +0000 | [diff] [blame] | 127 | sio_setup(); |
Patrick Georgi | ce6fb1e | 2010-03-17 22:44:39 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Uwe Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 130 | if (bist == 0) |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 131 | bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo); |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 132 | |
Uwe Hermann | 9b9791c | 2010-12-06 18:17:01 +0000 | [diff] [blame] | 133 | w83627hf_set_clksel_48(DUMMY_DEV); |
Edward O'Callaghan | beb0f26 | 2014-04-29 13:09:50 +1000 | [diff] [blame] | 134 | winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE); |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 135 | |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 136 | console_init(); |
| 137 | |
| 138 | /* Halt if there was a built in self test failure */ |
| 139 | report_bist_failure(bist); |
| 140 | |
Myles Watson | 08e0fb8 | 2010-03-22 16:33:25 +0000 | [diff] [blame] | 141 | printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1); |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 142 | |
| 143 | setup_mb_resource_map(); |
| 144 | |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 145 | printk(BIOS_DEBUG, "bsp_apicid=%02x\n", bsp_apicid); |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 146 | |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 147 | set_sysinfo_in_ram(0); // in BSP so could hold all ap until sysinfo is in ram |
Kyösti Mälkki | a1e924c | 2014-06-06 08:32:42 +0300 | [diff] [blame] | 148 | #if CONFIG_DEBUG_SMBUS |
| 149 | dump_smbus_registers(); |
| 150 | #endif |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 151 | setup_coherent_ht_domain(); // routing table and start other core0 |
| 152 | |
| 153 | wait_all_core0_started(); |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 154 | #if CONFIG_LOGICAL_CPUS |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 155 | // It is said that we should start core1 after all core0 launched |
| 156 | /* becase optimize_link_coherent_ht is moved out from setup_coherent_ht_domain, |
| 157 | * So here need to make sure last core0 is started, esp for two way system, |
| 158 | * (there may be apic id conflicts in that case) |
| 159 | */ |
| 160 | start_other_cores(); |
| 161 | wait_all_other_cores_started(bsp_apicid); |
| 162 | #endif |
| 163 | |
| 164 | /* it will set up chains and store link pair for optimization later */ |
| 165 | ht_setup_chains_x(sysinfo); // it will init sblnk and sbbusn, nodes, sbdn |
| 166 | |
Patrick Georgi | 76e8152 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 167 | #if CONFIG_SET_FIDVID |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 168 | { |
| 169 | msr_t msr; |
| 170 | msr = rdmsr(0xc0010042); |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 171 | printk(BIOS_DEBUG, "begin msr fid, vid %08x%08x\n", msr.hi, msr.lo); |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 172 | } |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 173 | enable_fid_change(); |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 174 | enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn); |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 175 | init_fidvid_bsp(bsp_apicid); |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 176 | // show final fid and vid |
| 177 | { |
| 178 | msr_t msr; |
| 179 | msr = rdmsr(0xc0010042); |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 180 | printk(BIOS_DEBUG, "end msr fid, vid %08x%08x\n", msr.hi, msr.lo); |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 181 | } |
| 182 | #endif |
| 183 | |
Paul Menzel | 4549e5a | 2014-02-02 22:05:48 +0100 | [diff] [blame] | 184 | init_timer(); /* Need to use TMICT to synchronize FID/VID. */ |
Stefan Reinauer | bcb8c97 | 2010-04-25 18:06:32 +0000 | [diff] [blame] | 185 | |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 186 | needs_reset |= optimize_link_coherent_ht(); |
| 187 | needs_reset |= optimize_link_incoherent_ht(sysinfo); |
| 188 | needs_reset |= mcp55_early_setup_x(); |
| 189 | |
| 190 | // fidvid change will issue one LDTSTOP and the HT change will be effective too |
| 191 | if (needs_reset) { |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 192 | printk(BIOS_INFO, "ht reset -\n"); |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 193 | soft_reset(); |
| 194 | } |
Stefan Reinauer | bcb8c97 | 2010-04-25 18:06:32 +0000 | [diff] [blame] | 195 | |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 196 | allow_all_aps_stop(bsp_apicid); |
| 197 | |
| 198 | //It's the time to set ctrl in sysinfo now; |
| 199 | fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr); |
| 200 | |
| 201 | enable_smbus(); /* enable in sio_setup */ |
| 202 | |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 203 | /* all ap stopped? */ |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 204 | |
| 205 | sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo); |
| 206 | |
| 207 | post_cache_as_ram(); // bsp swtich stack to ram and copy sysinfo ram now |
Marc Jones | 5dd4a20 | 2009-03-20 16:36:05 +0000 | [diff] [blame] | 208 | } |