Felix Held | 060b8ad | 2021-02-05 22:51:33 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Felix Held | aa77d13 | 2021-02-10 16:13:56 +0100 | [diff] [blame] | 3 | #include <amdblocks/cpu.h> |
Felix Held | a5cdf75 | 2021-03-10 15:47:00 +0100 | [diff] [blame] | 4 | #include <amdblocks/reset.h> |
Felix Held | 7aacdd1 | 2021-02-10 23:27:47 +0100 | [diff] [blame] | 5 | #include <amdblocks/smm.h> |
Felix Held | 79f705f | 2021-04-22 17:08:50 +0200 | [diff] [blame] | 6 | #include <assert.h> |
Felix Held | 060b8ad | 2021-02-05 22:51:33 +0100 | [diff] [blame] | 7 | #include <console/console.h> |
Raul E Rangel | 35dc4b0 | 2021-02-12 16:04:27 -0700 | [diff] [blame] | 8 | #include <cpu/amd/microcode.h> |
Felix Held | 060b8ad | 2021-02-05 22:51:33 +0100 | [diff] [blame] | 9 | #include <cpu/cpu.h> |
Felix Held | aa77d13 | 2021-02-10 16:13:56 +0100 | [diff] [blame] | 10 | #include <cpu/x86/lapic.h> |
Felix Held | 7aacdd1 | 2021-02-10 23:27:47 +0100 | [diff] [blame] | 11 | #include <cpu/x86/mp.h> |
| 12 | #include <cpu/x86/mtrr.h> |
| 13 | #include <cpu/x86/smm.h> |
Felix Held | 060b8ad | 2021-02-05 22:51:33 +0100 | [diff] [blame] | 14 | #include <device/device.h> |
| 15 | #include <soc/cpu.h> |
Felix Held | 7aacdd1 | 2021-02-10 23:27:47 +0100 | [diff] [blame] | 16 | #include <soc/iomap.h> |
Felix Held | 7aacdd1 | 2021-02-10 23:27:47 +0100 | [diff] [blame] | 17 | |
Felix Held | 79f705f | 2021-04-22 17:08:50 +0200 | [diff] [blame] | 18 | _Static_assert(CONFIG_MAX_CPUS == 16, "Do not override MAX_CPUS. To reduce the number of " |
| 19 | "available cores, use the downcore_mode and disable_smt devicetree settings instead."); |
| 20 | |
Felix Held | 7aacdd1 | 2021-02-10 23:27:47 +0100 | [diff] [blame] | 21 | /* MP and SMM loading initialization */ |
| 22 | |
| 23 | /* |
| 24 | * Do essential initialization tasks before APs can be fired up - |
| 25 | * |
| 26 | * 1. Prevent race condition in MTRR solution. Enable MTRRs on the BSP. This |
| 27 | * creates the MTRR solution that the APs will use. Otherwise APs will try to |
| 28 | * apply the incomplete solution as the BSP is calculating it. |
| 29 | */ |
| 30 | static void pre_mp_init(void) |
| 31 | { |
| 32 | x86_setup_mtrrs_with_detect_no_above_4gb(); |
| 33 | x86_mtrr_check(); |
| 34 | } |
| 35 | |
| 36 | static void post_mp_init(void) |
| 37 | { |
| 38 | global_smi_enable(); |
| 39 | apm_control(APM_CNT_SMMINFO); |
| 40 | } |
| 41 | |
| 42 | static const struct mp_ops mp_ops = { |
| 43 | .pre_mp_init = pre_mp_init, |
| 44 | .get_cpu_count = get_cpu_count, |
| 45 | .get_smm_info = get_smm_info, |
| 46 | .relocation_handler = smm_relocation_handler, |
| 47 | .post_mp_init = post_mp_init, |
| 48 | }; |
Felix Held | 060b8ad | 2021-02-05 22:51:33 +0100 | [diff] [blame] | 49 | |
Felix Held | b2d8a5c | 2021-02-10 16:17:13 +0100 | [diff] [blame] | 50 | void mp_init_cpus(struct bus *cpu_bus) |
| 51 | { |
Felix Held | 7aacdd1 | 2021-02-10 23:27:47 +0100 | [diff] [blame] | 52 | /* Clear for take-off */ |
| 53 | if (mp_init_with_smm(cpu_bus, &mp_ops) < 0) |
| 54 | printk(BIOS_ERR, "MP initialization failure.\n"); |
| 55 | |
| 56 | /* pre_mp_init made the flash not cacheable. Reset to WP for performance. */ |
| 57 | mtrr_use_temp_range(FLASH_BASE_ADDR, CONFIG_ROM_SIZE, MTRR_TYPE_WRPROT); |
Felix Held | b2d8a5c | 2021-02-10 16:17:13 +0100 | [diff] [blame] | 58 | } |
| 59 | |
Felix Held | 060b8ad | 2021-02-05 22:51:33 +0100 | [diff] [blame] | 60 | static void zen_2_3_init(struct device *dev) |
| 61 | { |
Felix Held | a24472a | 2021-07-13 18:21:27 +0200 | [diff] [blame] | 62 | check_mca(); |
Felix Held | aa77d13 | 2021-02-10 16:13:56 +0100 | [diff] [blame] | 63 | setup_lapic(); |
| 64 | set_cstate_io_addr(); |
Raul E Rangel | 35dc4b0 | 2021-02-12 16:04:27 -0700 | [diff] [blame] | 65 | |
| 66 | amd_update_microcode_from_cbfs(); |
Felix Held | 060b8ad | 2021-02-05 22:51:33 +0100 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static struct device_operations cpu_dev_ops = { |
| 70 | .init = zen_2_3_init, |
| 71 | }; |
| 72 | |
| 73 | static struct cpu_device_id cpu_table[] = { |
| 74 | { X86_VENDOR_AMD, CEZANNE_A0_CPUID}, |
| 75 | { 0, 0 }, |
| 76 | }; |
| 77 | |
| 78 | static const struct cpu_driver zen_2_3 __cpu_driver = { |
| 79 | .ops = &cpu_dev_ops, |
| 80 | .id_table = cpu_table, |
| 81 | }; |