blob: 4636b3b6092c1dcc6d515cc4caaabe843b0aee66 [file] [log] [blame]
Angel Pons0612b272020-04-05 15:46:56 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +05302
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +05303#include <assert.h>
4#include <bootstate.h>
Elyes HAOUAS20eaef02019-03-29 17:45:28 +01005#include <console/console.h>
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +05306#include <cpu/cpu.h>
7#include <cpu/x86/mtrr.h>
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +05308#include <cpu/x86/mp.h>
9#include <cpu/intel/microcode.h>
Kyösti Mälkki32d47eb2019-09-28 00:00:30 +030010#include <intelblocks/cfg.h>
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +053011#include <intelblocks/cpulib.h>
12#include <intelblocks/fast_spi.h>
13#include <intelblocks/mp_init.h>
14#include <intelblocks/msr.h>
15#include <soc/cpu.h>
16
Subrata Banikbdea3522022-05-31 23:36:59 +053017static void initialize_microcode(void)
18{
19 const void *microcode_patch = intel_microcode_find();
20 intel_microcode_load_unlocked(microcode_patch);
21}
22
Elyes HAOUAS68c851b2018-06-12 22:06:09 +020023static void init_one_cpu(struct device *dev)
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +053024{
Pratik Prajapati9cd6a262017-08-14 13:57:46 -070025 soc_core_init(dev);
Patrick Rudolph3fa23b82021-01-25 09:42:08 +010026
Subrata Banikbdea3522022-05-31 23:36:59 +053027 initialize_microcode();
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +053028}
29
30static struct device_operations cpu_dev_ops = {
31 .init = init_one_cpu,
32};
33
Jonathan Neuschäfer8f06ce32017-11-20 01:56:44 +010034static const struct cpu_device_id cpu_table[] = {
Wonkyu Kim9f401072020-11-13 15:16:32 -080035 { X86_VENDOR_INTEL, CPUID_METEORLAKE_A0_1},
36 { X86_VENDOR_INTEL, CPUID_METEORLAKE_A0_2},
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +053037 { X86_VENDOR_INTEL, CPUID_SKYLAKE_C0 },
38 { X86_VENDOR_INTEL, CPUID_SKYLAKE_D0 },
39 { X86_VENDOR_INTEL, CPUID_SKYLAKE_HQ0 },
40 { X86_VENDOR_INTEL, CPUID_SKYLAKE_HR0 },
41 { X86_VENDOR_INTEL, CPUID_KABYLAKE_G0 },
42 { X86_VENDOR_INTEL, CPUID_KABYLAKE_H0 },
43 { X86_VENDOR_INTEL, CPUID_KABYLAKE_Y0 },
44 { X86_VENDOR_INTEL, CPUID_KABYLAKE_HA0 },
45 { X86_VENDOR_INTEL, CPUID_KABYLAKE_HB0 },
Barnali Sarkarcc22b732017-08-07 18:44:02 +053046 { X86_VENDOR_INTEL, CPUID_CANNONLAKE_A0 },
47 { X86_VENDOR_INTEL, CPUID_CANNONLAKE_B0 },
48 { X86_VENDOR_INTEL, CPUID_CANNONLAKE_C0 },
Lijian Zhaoe9872282018-01-21 21:05:54 -080049 { X86_VENDOR_INTEL, CPUID_CANNONLAKE_D0 },
Barnali Sarkarcc22b732017-08-07 18:44:02 +053050 { X86_VENDOR_INTEL, CPUID_APOLLOLAKE_A0 },
51 { X86_VENDOR_INTEL, CPUID_APOLLOLAKE_B0 },
Mario Scheithauer545593d2017-10-24 17:41:19 +020052 { X86_VENDOR_INTEL, CPUID_APOLLOLAKE_E0 },
Barnali Sarkarcc22b732017-08-07 18:44:02 +053053 { X86_VENDOR_INTEL, CPUID_GLK_A0 },
54 { X86_VENDOR_INTEL, CPUID_GLK_B0 },
John Zhao7528f832019-05-10 10:51:52 -070055 { X86_VENDOR_INTEL, CPUID_GLK_R0 },
Lijian Zhao34745f62019-02-15 05:36:50 -080056 { X86_VENDOR_INTEL, CPUID_WHISKEYLAKE_V0 },
Krzysztof Sywulacdeb4142018-07-16 05:25:34 -070057 { X86_VENDOR_INTEL, CPUID_WHISKEYLAKE_W0 },
Maulikfc19ab52018-01-05 22:40:35 +053058 { X86_VENDOR_INTEL, CPUID_COFFEELAKE_U0 },
Felix Singerd298ffe2019-07-28 13:27:11 +020059 { X86_VENDOR_INTEL, CPUID_COFFEELAKE_B0 },
Lean Sheng Tan38c3ff72019-05-27 13:06:35 +080060 { X86_VENDOR_INTEL, CPUID_COFFEELAKE_P0 },
61 { X86_VENDOR_INTEL, CPUID_COFFEELAKE_R0 },
Ronak Kanabar128bb2a2019-01-29 19:52:53 +053062 { X86_VENDOR_INTEL, CPUID_COMETLAKE_U_A0 },
63 { X86_VENDOR_INTEL, CPUID_COMETLAKE_U_K0_S0 },
Gaggery Tsaifdcc9ab2019-11-04 20:49:10 -080064 { X86_VENDOR_INTEL, CPUID_COMETLAKE_H_S_6_2_G0 },
65 { X86_VENDOR_INTEL, CPUID_COMETLAKE_H_S_6_2_G1 },
Ronak Kanabar128bb2a2019-01-29 19:52:53 +053066 { X86_VENDOR_INTEL, CPUID_COMETLAKE_H_S_10_2_P0 },
Jeremy Sollerc5d07612022-07-26 08:18:38 -060067 { X86_VENDOR_INTEL, CPUID_COMETLAKE_H_S_10_2_P1 },
68 { X86_VENDOR_INTEL, CPUID_COMETLAKE_H_S_10_2_Q0 },
Ravi Sarawadi6b5bf402019-10-21 22:25:04 -070069 { X86_VENDOR_INTEL, CPUID_TIGERLAKE_A0 },
Jamie Ryu5131c6f2020-05-18 10:13:31 -070070 { X86_VENDOR_INTEL, CPUID_TIGERLAKE_B0 },
Jeremy Soller49759f62021-08-12 10:49:58 -060071 { X86_VENDOR_INTEL, CPUID_TIGERLAKE_R0 },
Tan, Lean Sheng26136092020-01-20 19:13:56 -080072 { X86_VENDOR_INTEL, CPUID_ELKHARTLAKE_A0 },
Tan, Lean Sheng7337bdc2020-08-25 08:24:47 -070073 { X86_VENDOR_INTEL, CPUID_ELKHARTLAKE_B0 },
Subrata Banikf672f7f2020-08-03 14:29:25 +053074 { X86_VENDOR_INTEL, CPUID_JASPERLAKE_A0 },
75 { X86_VENDOR_INTEL, CPUID_ALDERLAKE_S_A0 },
Lean Sheng Tan9e78dd12022-04-01 12:03:51 +020076 { X86_VENDOR_INTEL, CPUID_ALDERLAKE_J0 },
77 { X86_VENDOR_INTEL, CPUID_ALDERLAKE_K0 },
Lean Sheng Tan311ddf32022-04-01 18:36:11 +020078 { X86_VENDOR_INTEL, CPUID_ALDERLAKE_L0 },
Lean Sheng Tan9e78dd12022-04-01 12:03:51 +020079 { X86_VENDOR_INTEL, CPUID_ALDERLAKE_Q0 },
80 { X86_VENDOR_INTEL, CPUID_ALDERLAKE_R0 },
Paul Menzelbdaff7e2022-01-08 10:21:59 +010081 { X86_VENDOR_INTEL, CPUID_ALDERLAKE_N_A0 },
Bora Guvendika15b25f2022-02-28 14:43:49 -080082 { X86_VENDOR_INTEL, CPUID_RAPTORLAKE_P_J0 },
zhixingma529a64b2022-06-13 15:06:27 -070083 { X86_VENDOR_INTEL, CPUID_RAPTORLAKE_P_Q0 },
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +053084 { 0, 0 },
85};
86
87static const struct cpu_driver driver __cpu_driver = {
88 .ops = &cpu_dev_ops,
89 .id_table = cpu_table,
90};
91
92/*
93 * MP Init callback function to Find CPU Topology. This function is common
94 * among all SOCs and thus its in Common CPU block.
95 */
96int get_cpu_count(void)
97{
98 unsigned int num_virt_cores, num_phys_cores;
99
100 cpu_read_topology(&num_phys_cores, &num_virt_cores);
101
102 printk(BIOS_DEBUG, "Detected %u core, %u thread CPU.\n",
103 num_phys_cores, num_virt_cores);
104
105 return num_virt_cores;
106}
107
108/*
109 * MP Init callback function(get_microcode_info) to find the Microcode at
110 * Pre MP Init phase. This function is common among all SOCs and thus its in
111 * Common CPU block.
112 * This function also fills in the microcode patch (in *microcode), and also
113 * sets the argument *parallel to 1, which allows microcode loading in all
114 * APs to occur in parallel during MP Init.
115 */
116void get_microcode_info(const void **microcode, int *parallel)
117{
Patrick Rudolph3fa23b82021-01-25 09:42:08 +0100118 *microcode = intel_microcode_find();
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +0530119 *parallel = 1;
120}
121
Subrata Banika3c33c62020-07-31 11:47:42 +0530122/*
123 * Perform BSP and AP initialization
124 * This function can be called in below cases:
125 * 1. During coreboot is doing MP initialization as part of BS_DEV_INIT_CHIPS (exclude
126 * this call if user has selected USE_INTEL_FSP_MP_INIT).
127 * 2. coreboot would like to take APs control back after FSP-S has done with MP
128 * initialization based on user select USE_INTEL_FSP_MP_INIT.
MAULIK V VAGHELA3c0ecd52021-08-02 13:11:46 +0530129 *
130 * This function would use cpu_cluster as a device and APIC device as a linked list to
131 * the cpu cluster. This function adds a node in case the mainboard doesn't have a lapic id
132 * hardcoded in devicetree, and then fills with the actual BSP APIC ID.
133 * This allows coreboot to dynamically detect the LAPIC ID of BSP.
134 * In case the mainboard has an APIC ID defined in devicetree, a link will be present and
135 * creation of the new node will be skipped. This node will have the APIC ID defined
136 * in devicetree.
Subrata Banika3c33c62020-07-31 11:47:42 +0530137 */
138void init_cpus(void)
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +0530139{
Elyes HAOUAS68c851b2018-06-12 22:06:09 +0200140 struct device *dev = dev_find_path(NULL, DEVICE_PATH_CPU_CLUSTER);
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +0530141 assert(dev != NULL);
142
MAULIK V VAGHELA3c0ecd52021-08-02 13:11:46 +0530143 /* In case link to APIC device is not found, create the one */
144 if (!dev->link_list)
145 add_more_links(dev, 1);
146
147 soc_init_cpus(dev->link_list);
Subrata Banika3c33c62020-07-31 11:47:42 +0530148}
149
150static void coreboot_init_cpus(void *unused)
151{
Subrata Banikcf32fd12018-12-19 18:02:17 +0530152 if (CONFIG(USE_INTEL_FSP_MP_INIT))
Subrata Banikf699c142018-06-08 17:57:37 +0530153 return;
154
Subrata Banikbdea3522022-05-31 23:36:59 +0530155 initialize_microcode();
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +0530156
Subrata Banika3c33c62020-07-31 11:47:42 +0530157 init_cpus();
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +0530158}
159
Subrata Banik73ad8182022-03-15 18:29:33 +0530160static void post_cpus_add_romcache(void)
161{
162 if (!CONFIG(BOOT_DEVICE_MEMORY_MAPPED))
163 return;
164
165 fast_spi_cache_bios_region();
166}
167
Subrata Banik33374972018-04-24 13:45:30 +0530168static void wrapper_x86_setup_mtrrs(void *unused)
169{
170 x86_setup_mtrrs_with_detect();
171}
172
Subrata Banike43adb62022-05-31 23:28:57 +0530173static void wrapper_set_bios_done(void *unused)
174{
175 cpu_soc_bios_done();
176}
177
Subrata Banik861ec012022-06-16 00:02:39 +0530178static void wrapper_init_core_prmrr(void *unused)
179{
180 init_core_prmrr();
181}
182
Subrata Banike43adb62022-05-31 23:28:57 +0530183void before_post_cpus_init(void)
184{
Subrata Banik957609d2022-06-16 20:25:08 +0530185 /*
186 * Ensure all APs finish the task and continue if coreboot decides to
187 * perform multiprocessor initialization using native coreboot drivers
188 * instead using FSP MP PPI implementation.
189 *
190 * Ignore if USE_COREBOOT_MP_INIT is not enabled.
191 */
192 if (!CONFIG(USE_COREBOOT_MP_INIT))
193 return;
194
Subrata Banik5a9b7aa2022-08-12 17:14:43 +0530195 if (mp_run_on_all_cpus(wrapper_init_core_prmrr, NULL) != CB_SUCCESS)
Subrata Banik861ec012022-06-16 00:02:39 +0530196 printk(BIOS_ERR, "core PRMRR sync failure\n");
197
Subrata Banik5a9b7aa2022-08-12 17:14:43 +0530198 if (mp_run_on_all_cpus(wrapper_set_bios_done, NULL) != CB_SUCCESS)
Subrata Banike43adb62022-05-31 23:28:57 +0530199 printk(BIOS_ERR, "Set BIOS Done failure\n");
Subrata Banikf4fe21d2022-05-31 23:43:36 +0530200
Subrata Banik46265ab2022-06-15 21:39:06 +0530201 intel_reload_microcode();
Subrata Banike43adb62022-05-31 23:28:57 +0530202}
203
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +0530204/* Ensure to re-program all MTRRs based on DRAM resource settings */
205static void post_cpus_init(void *unused)
206{
Kane Chen2e96eeb2022-04-12 09:12:59 +0800207 /* Ensure all APs finish the task and continue */
208 if (mp_run_on_all_cpus_synchronously(&wrapper_x86_setup_mtrrs, NULL) != CB_SUCCESS)
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +0530209 printk(BIOS_ERR, "MTRR programming failure\n");
210
Subrata Banik73ad8182022-03-15 18:29:33 +0530211 post_cpus_add_romcache();
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +0530212 x86_mtrr_check();
213}
214
215/* Do CPU MP Init before FSP Silicon Init */
Subrata Banika3c33c62020-07-31 11:47:42 +0530216BOOT_STATE_INIT_ENTRY(BS_DEV_INIT_CHIPS, BS_ON_ENTRY, coreboot_init_cpus, NULL);
Barnali Sarkarf43adf02017-12-27 13:48:58 +0530217BOOT_STATE_INIT_ENTRY(BS_WRITE_TABLES, BS_ON_EXIT, post_cpus_init, NULL);
218BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, post_cpus_init, NULL);