Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | //#define SYSTEM_TYPE 0 /* SERVER */ |
| 21 | #define SYSTEM_TYPE 1 /* DESKTOP */ |
| 22 | //#define SYSTEM_TYPE 2 /* MOBILE */ |
| 23 | |
| 24 | //used by incoherent_ht |
| 25 | #define FAM10_SCAN_PCI_BUS 0 |
| 26 | #define FAM10_ALLOCATE_IO_RANGE 0 |
| 27 | |
Kerry She | 3bf2708 | 2011-06-03 10:14:56 +0000 | [diff] [blame] | 28 | #include <lib.h> |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 29 | #include <stdint.h> |
| 30 | #include <string.h> |
| 31 | #include <device/pci_def.h> |
| 32 | #include <device/pci_ids.h> |
| 33 | #include <arch/io.h> |
| 34 | #include <device/pnp_def.h> |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 35 | #include <cpu/x86/lapic.h> |
| 36 | #include <console/console.h> |
| 37 | #include <cpu/amd/model_10xxx_rev.h> |
| 38 | #include "northbridge/amd/amdfam10/raminit.h" |
| 39 | #include "northbridge/amd/amdfam10/amdfam10.h" |
Kyösti Mälkki | c66f1cb | 2013-08-12 16:09:00 +0300 | [diff] [blame] | 40 | #include "cpu/x86/lapic.h" |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 41 | #include "northbridge/amd/amdfam10/reset_test.c" |
| 42 | #include <console/loglevel.h> |
| 43 | #include "cpu/x86/bist.h" |
Edward O'Callaghan | beb0f26 | 2014-04-29 13:09:50 +1000 | [diff] [blame^] | 44 | #include <superio/winbond/common/winbond.h> |
| 45 | #include <superio/winbond/w83627hf/w83627hf.h> |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 46 | #include <cpu/amd/mtrr.h> |
| 47 | #include "northbridge/amd/amdfam10/setup_resource_map.c" |
| 48 | #include "southbridge/amd/rs780/early_setup.c" |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 49 | #include <sb_cimx.h> |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 50 | #include <SBPLATFORM.h> /* SB OEM constants */ |
efdesign98 | 05a89ab | 2011-06-20 17:38:49 -0700 | [diff] [blame] | 51 | #include <southbridge/amd/cimx/sb800/smbus.h> |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 52 | #include "northbridge/amd/amdfam10/debug.c" |
| 53 | |
Edward O'Callaghan | beb0f26 | 2014-04-29 13:09:50 +1000 | [diff] [blame^] | 54 | #define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1) |
| 55 | |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 56 | static void activate_spd_rom(const struct mem_controller *ctrl) |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | static int spd_read_byte(u32 device, u32 address) |
| 61 | { |
| 62 | return do_smbus_read_byte(SMBUS_IO_BASE, device, address); |
| 63 | } |
| 64 | |
| 65 | #include "northbridge/amd/amdfam10/raminit_sysinfo_in_ram.c" |
| 66 | #include "northbridge/amd/amdfam10/pci.c" |
| 67 | #include "resourcemap.c" |
| 68 | #include "cpu/amd/quadcore/quadcore.c" |
Kyösti Mälkki | f0a13ce | 2013-12-08 07:20:48 +0200 | [diff] [blame] | 69 | #include "cpu/amd/microcode.h" |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 70 | #include "cpu/amd/model_10xxx/init_cpus.c" |
| 71 | #include "northbridge/amd/amdfam10/early_ht.c" |
| 72 | #include "spd.h" |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 73 | #include <reset.h> |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 74 | |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 75 | void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx) |
| 76 | { |
Patrick Georgi | bbc880e | 2012-11-20 18:20:56 +0100 | [diff] [blame] | 77 | struct sys_info *sysinfo = &sysinfo_car; |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 78 | static const u8 spd_addr[] = {RC00, DIMM0, DIMM2, 0, 0, DIMM1, DIMM3, 0, 0, }; |
| 79 | u32 bsp_apicid = 0, val; |
| 80 | msr_t msr; |
| 81 | |
| 82 | if (!cpu_init_detectedx && boot_cpu()) { |
| 83 | /* Nothing special needs to be done to find bus 0 */ |
| 84 | /* Allow the HT devices to be found */ |
| 85 | /* mov bsp to bus 0xff when > 8 nodes */ |
| 86 | set_bsp_node_CHtExtNodeCfgEn(); |
| 87 | enumerate_ht_chain(); |
| 88 | |
| 89 | //enable port80 decoding and southbridge poweron init |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 90 | sb_Poweron_Init(); |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | post_code(0x30); |
| 94 | |
| 95 | if (bist == 0) { |
| 96 | bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo); /* mmconf is inited in init_cpus */ |
| 97 | /* All cores run this but the BSP(node0,core0) is the only core that returns. */ |
| 98 | } |
| 99 | |
| 100 | post_code(0x32); |
| 101 | |
| 102 | enable_rs780_dev8(); |
| 103 | sb800_clk_output_48Mhz(); |
| 104 | |
| 105 | w83627hf_set_clksel_48(PNP_DEV(0x2e, 0)); |
Edward O'Callaghan | beb0f26 | 2014-04-29 13:09:50 +1000 | [diff] [blame^] | 106 | winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE); |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 107 | |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 108 | console_init(); |
| 109 | printk(BIOS_DEBUG, "\n"); |
| 110 | |
| 111 | // dump_mem(CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE-0x200, CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE); |
| 112 | |
| 113 | /* Halt if there was a built in self test failure */ |
| 114 | report_bist_failure(bist); |
| 115 | |
| 116 | // Load MPB |
| 117 | val = cpuid_eax(1); |
| 118 | printk(BIOS_DEBUG, "BSP Family_Model: %08x \n", val); |
| 119 | printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1); |
| 120 | printk(BIOS_DEBUG, "bsp_apicid = %02x \n", bsp_apicid); |
| 121 | printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx \n", cpu_init_detectedx); |
| 122 | |
| 123 | /* Setup sysinfo defaults */ |
| 124 | set_sysinfo_in_ram(0); |
| 125 | |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 126 | update_microcode(val); |
Kyösti Mälkki | f0a13ce | 2013-12-08 07:20:48 +0200 | [diff] [blame] | 127 | |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 128 | post_code(0x33); |
| 129 | |
| 130 | cpuSetAMDMSR(); |
| 131 | post_code(0x34); |
| 132 | |
| 133 | amd_ht_init(sysinfo); |
| 134 | post_code(0x35); |
| 135 | |
| 136 | /* Setup nodes PCI space and start core 0 AP init. */ |
| 137 | finalize_node_setup(sysinfo); |
| 138 | |
| 139 | /* Setup any mainboard PCI settings etc. */ |
| 140 | setup_mb_resource_map(); |
| 141 | post_code(0x36); |
| 142 | |
| 143 | /* wait for all the APs core0 started by finalize_node_setup. */ |
| 144 | /* FIXME: A bunch of cores are going to start output to serial at once. |
| 145 | It would be nice to fixup prink spinlocks for ROM XIP mode. |
| 146 | I think it could be done by putting the spinlock flag in the cache |
| 147 | of the BSP located right after sysinfo. |
| 148 | */ |
| 149 | wait_all_core0_started(); |
| 150 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 151 | #if CONFIG_LOGICAL_CPUS |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 152 | /* Core0 on each node is configured. Now setup any additional cores. */ |
| 153 | printk(BIOS_DEBUG, "start_other_cores()\n"); |
| 154 | start_other_cores(); |
| 155 | post_code(0x37); |
| 156 | wait_all_other_cores_started(bsp_apicid); |
| 157 | #endif |
| 158 | |
| 159 | post_code(0x38); |
| 160 | |
| 161 | /* run _early_setup before soft-reset. */ |
| 162 | rs780_early_setup(); |
| 163 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 164 | #if CONFIG_SET_FIDVID |
Kerry She | 6401fdb | 2011-05-07 09:15:02 +0000 | [diff] [blame] | 165 | msr = rdmsr(0xc0010071); |
| 166 | printk(BIOS_DEBUG, "\nBegin FIDVID MSR 0xc0010071 0x%08x 0x%08x \n", msr.hi, msr.lo); |
| 167 | post_code(0x39); |
| 168 | |
| 169 | if (!warm_reset_detect(0)) { // BSP is node 0 |
| 170 | init_fidvid_bsp(bsp_apicid, sysinfo->nodes); |
| 171 | } else { |
| 172 | init_fidvid_stage2(bsp_apicid, 0); // BSP is node 0 |
| 173 | } |
| 174 | |
| 175 | post_code(0x3A); |
| 176 | |
| 177 | /* show final fid and vid */ |
| 178 | msr=rdmsr(0xc0010071); |
| 179 | printk(BIOS_DEBUG, "End FIDVIDMSR 0xc0010071 0x%08x 0x%08x \n", msr.hi, msr.lo); |
| 180 | #endif |
| 181 | |
| 182 | rs780_htinit(); |
| 183 | |
| 184 | /* Reset for HT, FIDVID, PLL and errata changes to take affect. */ |
| 185 | if (!warm_reset_detect(0)) { |
| 186 | print_info("...WARM RESET...\n\n\n"); |
| 187 | soft_reset(); |
| 188 | die("After soft_reset_x - shouldn't see this message!!!\n"); |
| 189 | } |
| 190 | |
| 191 | post_code(0x3B); |
| 192 | |
| 193 | /* It's the time to set ctrl in sysinfo now; */ |
| 194 | printk(BIOS_DEBUG, "fill_mem_ctrl()\n"); |
| 195 | fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr); |
| 196 | |
| 197 | post_code(0x40); |
| 198 | |
| 199 | // die("Die Before MCT init."); |
| 200 | |
| 201 | printk(BIOS_DEBUG, "raminit_amdmct()\n"); |
| 202 | raminit_amdmct(sysinfo); |
| 203 | post_code(0x41); |
| 204 | |
| 205 | /* |
| 206 | dump_pci_device_range(PCI_DEV(0, 0x18, 0), 0, 0x200); |
| 207 | dump_pci_device_range(PCI_DEV(0, 0x18, 1), 0, 0x200); |
| 208 | dump_pci_device_range(PCI_DEV(0, 0x18, 2), 0, 0x200); |
| 209 | dump_pci_device_range(PCI_DEV(0, 0x18, 3), 0, 0x200); |
| 210 | */ |
| 211 | |
| 212 | // ram_check(0x00200000, 0x00200000 + (640 * 1024)); |
| 213 | // ram_check(0x40200000, 0x40200000 + (640 * 1024)); |
| 214 | |
| 215 | // die("After MCT init before CAR disabled."); |
| 216 | |
| 217 | rs780_before_pci_init(); |
| 218 | |
| 219 | post_code(0x42); |
| 220 | post_cache_as_ram(); // BSP switch stack to ram, copy then execute LB. |
| 221 | post_code(0x43); // Should never see this post code. |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * BOOL AMD_CB_ManualBUIDSwapList(u8 Node, u8 Link, u8 **List) |
| 226 | * Description: |
| 227 | * This routine is called every time a non-coherent chain is processed. |
| 228 | * BUID assignment may be controlled explicitly on a non-coherent chain. Provide a |
| 229 | * swap list. The first part of the list controls the BUID assignment and the |
| 230 | * second part of the list provides the device to device linking. Device orientation |
| 231 | * can be detected automatically, or explicitly. See documentation for more details. |
| 232 | * |
| 233 | * Automatic non-coherent init assigns BUIDs starting at 1 and incrementing sequentially |
| 234 | * based on each device's unit count. |
| 235 | * |
| 236 | * Parameters: |
| 237 | * @param[in] u8 node = The node on which this chain is located |
| 238 | * @param[in] u8 link = The link on the host for this chain |
| 239 | * @param[out] u8** list = supply a pointer to a list |
| 240 | * @param[out] BOOL result = true to use a manual list |
| 241 | * false to initialize the link automatically |
| 242 | */ |
| 243 | BOOL AMD_CB_ManualBUIDSwapList (u8 node, u8 link, const u8 **List) |
| 244 | { |
| 245 | static const u8 swaplist[] = {0, 1, 0xFF, 0, 0xFF}; |
| 246 | /* If the BUID was adjusted in early_ht we need to do the manual override */ |
| 247 | if ((node == 0) && (link == 0)) { /* BSP SB link */ |
| 248 | *List = swaplist; |
| 249 | return 1; |
| 250 | } |
| 251 | |
| 252 | return 0; |
| 253 | } |