Patrick Georgi | 11f0079 | 2020-03-04 15:10:45 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Martin Roth | 9df9e939 | 2016-01-12 15:55:28 -0700 | [diff] [blame] | 2 | |
Aaron Durbin | b21e362 | 2016-12-07 00:32:19 -0600 | [diff] [blame] | 3 | #include <bootstate.h> |
Aaron Durbin | f6ada1c | 2016-02-10 10:52:47 -0600 | [diff] [blame] | 4 | #include <boot/coreboot_tables.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 5 | #include <console/console.h> |
| 6 | #include <cpu/cpu.h> |
Kyösti Mälkki | ce39ba9 | 2020-01-04 16:15:50 +0200 | [diff] [blame] | 7 | #include <post.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 8 | #include <string.h> |
Aaron Durbin | b21e362 | 2016-12-07 00:32:19 -0600 | [diff] [blame] | 9 | #include <cpu/x86/mp.h> |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 10 | #include <cpu/x86/lapic.h> |
Aaron Durbin | e0969ae | 2016-02-10 10:56:06 -0600 | [diff] [blame] | 11 | #include <cpu/x86/tsc.h> |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 12 | #include <arch/cpu.h> |
| 13 | #include <device/path.h> |
| 14 | #include <device/device.h> |
| 15 | #include <smp/spinlock.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 16 | |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 17 | #ifndef __x86_64__ |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 18 | /* Standard macro to see if a specific flag is changeable */ |
| 19 | static inline int flag_is_changeable_p(uint32_t flag) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 20 | { |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 21 | uint32_t f1, f2; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 22 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 23 | asm( |
| 24 | "pushfl\n\t" |
| 25 | "pushfl\n\t" |
| 26 | "popl %0\n\t" |
| 27 | "movl %0,%1\n\t" |
| 28 | "xorl %2,%0\n\t" |
| 29 | "pushl %0\n\t" |
| 30 | "popfl\n\t" |
| 31 | "pushfl\n\t" |
| 32 | "popl %0\n\t" |
| 33 | "popfl\n\t" |
| 34 | : "=&r" (f1), "=&r" (f2) |
| 35 | : "ir" (flag)); |
| 36 | return ((f1^f2) & flag) != 0; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 39 | /* |
| 40 | * Cyrix CPUs without cpuid or with cpuid not yet enabled can be detected |
| 41 | * by the fact that they preserve the flags across the division of 5/2. |
| 42 | * PII and PPro exhibit this behavior too, but they have cpuid available. |
| 43 | */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 44 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 45 | /* |
| 46 | * Perform the Cyrix 5/2 test. A Cyrix won't change |
| 47 | * the flags, while other 486 chips will. |
| 48 | */ |
| 49 | static inline int test_cyrix_52div(void) |
| 50 | { |
| 51 | unsigned int test; |
| 52 | |
| 53 | __asm__ __volatile__( |
| 54 | "sahf\n\t" /* clear flags (%eax = 0x0005) */ |
| 55 | "div %b2\n\t" /* divide 5 by 2 */ |
| 56 | "lahf" /* store flags into %ah */ |
| 57 | : "=a" (test) |
| 58 | : "0" (5), "q" (2) |
| 59 | : "cc"); |
| 60 | |
| 61 | /* AH is 0x02 on Cyrix after the divide.. */ |
| 62 | return (unsigned char) (test >> 8) == 0x02; |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * Detect a NexGen CPU running without BIOS hypercode new enough |
| 67 | * to have CPUID. (Thanks to Herbert Oppmann) |
| 68 | */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 69 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 70 | static int deep_magic_nexgen_probe(void) |
| 71 | { |
| 72 | int ret; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 73 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 74 | __asm__ __volatile__ ( |
| 75 | " movw $0x5555, %%ax\n" |
| 76 | " xorw %%dx,%%dx\n" |
| 77 | " movw $2, %%cx\n" |
| 78 | " divw %%cx\n" |
| 79 | " movl $0, %%eax\n" |
| 80 | " jnz 1f\n" |
| 81 | " movl $1, %%eax\n" |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 82 | "1:\n" |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 83 | : "=a" (ret) : : "cx", "dx"); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 84 | return ret; |
| 85 | } |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 86 | #endif |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 87 | |
Elyes HAOUAS | 777ea89 | 2016-07-29 07:40:41 +0200 | [diff] [blame] | 88 | /* List of CPU vendor strings along with their normalized |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 89 | * id values. |
| 90 | */ |
| 91 | static struct { |
| 92 | int vendor; |
| 93 | const char *name; |
| 94 | } x86_vendors[] = { |
| 95 | { X86_VENDOR_INTEL, "GenuineIntel", }, |
| 96 | { X86_VENDOR_CYRIX, "CyrixInstead", }, |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 97 | { X86_VENDOR_AMD, "AuthenticAMD", }, |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 98 | { X86_VENDOR_UMC, "UMC UMC UMC ", }, |
| 99 | { X86_VENDOR_NEXGEN, "NexGenDriven", }, |
| 100 | { X86_VENDOR_CENTAUR, "CentaurHauls", }, |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame] | 101 | { X86_VENDOR_RISE, "RiseRiseRise", }, |
| 102 | { X86_VENDOR_TRANSMETA, "GenuineTMx86", }, |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 103 | { X86_VENDOR_TRANSMETA, "TransmetaCPU", }, |
| 104 | { X86_VENDOR_NSC, "Geode by NSC", }, |
| 105 | { X86_VENDOR_SIS, "SiS SiS SiS ", }, |
Jinke Fan | 8de6cb9 | 2019-05-18 18:07:56 +0800 | [diff] [blame] | 106 | { X86_VENDOR_HYGON, "HygonGenuine", }, |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
Elyes HAOUAS | 6c9737b | 2018-07-08 12:30:02 +0200 | [diff] [blame] | 109 | static const char *const x86_vendor_name[] = { |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 110 | [X86_VENDOR_INTEL] = "Intel", |
| 111 | [X86_VENDOR_CYRIX] = "Cyrix", |
| 112 | [X86_VENDOR_AMD] = "AMD", |
| 113 | [X86_VENDOR_UMC] = "UMC", |
| 114 | [X86_VENDOR_NEXGEN] = "NexGen", |
| 115 | [X86_VENDOR_CENTAUR] = "Centaur", |
| 116 | [X86_VENDOR_RISE] = "Rise", |
| 117 | [X86_VENDOR_TRANSMETA] = "Transmeta", |
| 118 | [X86_VENDOR_NSC] = "NSC", |
| 119 | [X86_VENDOR_SIS] = "SiS", |
Jinke Fan | 8de6cb9 | 2019-05-18 18:07:56 +0800 | [diff] [blame] | 120 | [X86_VENDOR_HYGON] = "Hygon", |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | static const char *cpu_vendor_name(int vendor) |
| 124 | { |
| 125 | const char *name; |
Elyes HAOUAS | 777ea89 | 2016-07-29 07:40:41 +0200 | [diff] [blame] | 126 | name = "<invalid CPU vendor>"; |
Carl-Daniel Hailfinger | 2ee6779 | 2008-10-01 12:52:52 +0000 | [diff] [blame] | 127 | if ((vendor < (ARRAY_SIZE(x86_vendor_name))) && |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 128 | (x86_vendor_name[vendor] != 0)) |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 129 | name = x86_vendor_name[vendor]; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 130 | return name; |
| 131 | } |
| 132 | |
| 133 | static void identify_cpu(struct device *cpu) |
| 134 | { |
| 135 | char vendor_name[16]; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 136 | int i; |
| 137 | |
| 138 | vendor_name[0] = '\0'; /* Unset */ |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 139 | |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 140 | #ifndef __x86_64__ |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 141 | /* Find the id and vendor_name */ |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 142 | if (!cpu_have_cpuid()) { |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 143 | /* Its a 486 if we can modify the AC flag */ |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 144 | if (flag_is_changeable_p(X86_EFLAGS_AC)) |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 145 | cpu->device = 0x00000400; /* 486 */ |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 146 | else |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 147 | cpu->device = 0x00000300; /* 386 */ |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 148 | if ((cpu->device == 0x00000400) && test_cyrix_52div()) |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 149 | memcpy(vendor_name, "CyrixInstead", 13); |
| 150 | /* If we ever care we can enable cpuid here */ |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 151 | /* Detect NexGen with old hypercode */ |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 152 | else if (deep_magic_nexgen_probe()) |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 153 | memcpy(vendor_name, "NexGenDriven", 13); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 154 | } |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 155 | #endif |
Rudolf Marek | 06253cd | 2012-02-25 23:51:12 +0100 | [diff] [blame] | 156 | if (cpu_have_cpuid()) { |
Stefan Reinauer | 4b556a1 | 2009-05-26 12:33:06 +0000 | [diff] [blame] | 157 | int cpuid_level; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 158 | struct cpuid_result result; |
| 159 | result = cpuid(0x00000000); |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 160 | cpuid_level = result.eax; |
| 161 | vendor_name[0] = (result.ebx >> 0) & 0xff; |
| 162 | vendor_name[1] = (result.ebx >> 8) & 0xff; |
| 163 | vendor_name[2] = (result.ebx >> 16) & 0xff; |
| 164 | vendor_name[3] = (result.ebx >> 24) & 0xff; |
| 165 | vendor_name[4] = (result.edx >> 0) & 0xff; |
| 166 | vendor_name[5] = (result.edx >> 8) & 0xff; |
| 167 | vendor_name[6] = (result.edx >> 16) & 0xff; |
| 168 | vendor_name[7] = (result.edx >> 24) & 0xff; |
| 169 | vendor_name[8] = (result.ecx >> 0) & 0xff; |
| 170 | vendor_name[9] = (result.ecx >> 8) & 0xff; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 171 | vendor_name[10] = (result.ecx >> 16) & 0xff; |
| 172 | vendor_name[11] = (result.ecx >> 24) & 0xff; |
| 173 | vendor_name[12] = '\0'; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 174 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 175 | /* Intel-defined flags: level 0x00000001 */ |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 176 | if (cpuid_level >= 0x00000001) |
Subrata Banik | 53b08c3 | 2018-12-10 14:11:35 +0530 | [diff] [blame] | 177 | cpu->device = cpu_get_cpuid(); |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 178 | else |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 179 | /* Have CPUID level 0 only unheard of */ |
| 180 | cpu->device = 0x00000400; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 181 | } |
| 182 | cpu->vendor = X86_VENDOR_UNKNOWN; |
Elyes HAOUAS | dbf3067 | 2016-08-21 17:37:15 +0200 | [diff] [blame] | 183 | for (i = 0; i < ARRAY_SIZE(x86_vendors); i++) { |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 184 | if (memcmp(vendor_name, x86_vendors[i].name, 12) == 0) { |
| 185 | cpu->vendor = x86_vendors[i].vendor; |
| 186 | break; |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
Stefan Reinauer | 6293d30 | 2012-04-03 16:07:56 -0700 | [diff] [blame] | 191 | struct cpu_driver *find_cpu_driver(struct device *cpu) |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 192 | { |
| 193 | struct cpu_driver *driver; |
Aaron Durbin | 0375815 | 2015-09-03 17:23:08 -0500 | [diff] [blame] | 194 | for (driver = _cpu_drivers; driver < _ecpu_drivers; driver++) { |
Jonathan Neuschäfer | 8f06ce3 | 2017-11-20 01:56:44 +0100 | [diff] [blame] | 195 | const struct cpu_device_id *id; |
Stefan Reinauer | 6293d30 | 2012-04-03 16:07:56 -0700 | [diff] [blame] | 196 | for (id = driver->id_table; |
| 197 | id->vendor != X86_VENDOR_INVALID; id++) { |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 198 | if ((cpu->vendor == id->vendor) && |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 199 | (cpu->device == id->device)) |
Stefan Reinauer | 6293d30 | 2012-04-03 16:07:56 -0700 | [diff] [blame] | 200 | return driver; |
Lee Leahy | 0b5678f | 2017-03-16 16:01:40 -0700 | [diff] [blame] | 201 | if (id->vendor == X86_VENDOR_ANY) |
Gerd Hoffmann | cbf3073 | 2013-05-31 09:23:26 +0200 | [diff] [blame] | 202 | return driver; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 203 | } |
| 204 | } |
Stefan Reinauer | 6293d30 | 2012-04-03 16:07:56 -0700 | [diff] [blame] | 205 | return NULL; |
| 206 | } |
| 207 | |
| 208 | static void set_cpu_ops(struct device *cpu) |
| 209 | { |
| 210 | struct cpu_driver *driver = find_cpu_driver(cpu); |
| 211 | cpu->ops = driver ? driver->ops : NULL; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Elyes HAOUAS | a5b0bc4 | 2020-02-20 20:04:29 +0100 | [diff] [blame] | 214 | /* Keep track of default APIC ids for SMM. */ |
Subrata Banik | 7bc9036 | 2019-05-10 11:58:37 +0530 | [diff] [blame] | 215 | static int cpus_default_apic_id[CONFIG_MAX_CPUS]; |
| 216 | |
| 217 | /* |
| 218 | * When CPUID executes with EAX set to 1, additional processor identification |
| 219 | * information is returned to EBX register: |
| 220 | * Default APIC ID: EBX[31-24] - this number is the 8 bit ID that is assigned |
| 221 | * to the local APIC on the processor during power on. |
| 222 | */ |
| 223 | static int initial_lapicid(void) |
| 224 | { |
| 225 | return cpuid_ebx(1) >> 24; |
| 226 | } |
| 227 | |
| 228 | /* Function to keep track of cpu default apic_id */ |
| 229 | void cpu_add_map_entry(unsigned int index) |
| 230 | { |
| 231 | cpus_default_apic_id[index] = initial_lapicid(); |
| 232 | } |
| 233 | |
| 234 | /* Returns default APIC id based on logical_cpu number or < 0 on failure. */ |
| 235 | int cpu_get_apic_id(int logical_cpu) |
| 236 | { |
| 237 | if (logical_cpu >= CONFIG_MAX_CPUS || logical_cpu < 0) |
| 238 | return -1; |
| 239 | |
| 240 | return cpus_default_apic_id[logical_cpu]; |
| 241 | } |
| 242 | |
Ronald G. Minnich | 8b93059 | 2012-06-05 14:41:27 -0700 | [diff] [blame] | 243 | void cpu_initialize(unsigned int index) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 244 | { |
| 245 | /* Because we busy wait at the printk spinlock. |
| 246 | * It is important to keep the number of printed messages |
| 247 | * from secondary cpus to a minimum, when debugging is |
| 248 | * disabled. |
| 249 | */ |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 250 | struct device *cpu; |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 251 | struct cpu_info *info; |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 252 | struct cpuinfo_x86 c; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 253 | |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 254 | info = cpu_info(); |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 255 | |
Ronald G. Minnich | 8b93059 | 2012-06-05 14:41:27 -0700 | [diff] [blame] | 256 | printk(BIOS_INFO, "Initializing CPU #%d\n", index); |
Kyösti Mälkki | bc8c996 | 2012-07-10 10:19:40 +0300 | [diff] [blame] | 257 | |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 258 | cpu = info->cpu; |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 259 | if (!cpu) |
Elyes HAOUAS | 777ea89 | 2016-07-29 07:40:41 +0200 | [diff] [blame] | 260 | die("CPU: missing CPU device structure"); |
Li-Ta Lo | 8cb91dc | 2004-03-26 18:34:48 +0000 | [diff] [blame] | 261 | |
Damien Zammit | 149c4c5 | 2015-11-28 21:27:05 +1100 | [diff] [blame] | 262 | if (cpu->initialized) |
| 263 | return; |
| 264 | |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 265 | post_log_path(cpu); |
| 266 | |
Elyes HAOUAS | 777ea89 | 2016-07-29 07:40:41 +0200 | [diff] [blame] | 267 | /* Find what type of CPU we are dealing with */ |
Yinghai Lu | 30b4abe | 2007-04-06 19:57:42 +0000 | [diff] [blame] | 268 | identify_cpu(cpu); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 269 | printk(BIOS_DEBUG, "CPU: vendor %s device %x\n", |
Yinghai Lu | 30b4abe | 2007-04-06 19:57:42 +0000 | [diff] [blame] | 270 | cpu_vendor_name(cpu->vendor), cpu->device); |
Li-Ta Lo | fd3f2d7 | 2004-05-12 16:34:46 +0000 | [diff] [blame] | 271 | |
Yinghai Lu | 30b4abe | 2007-04-06 19:57:42 +0000 | [diff] [blame] | 272 | get_fms(&c, cpu->device); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 273 | |
Stefan Reinauer | 5f5436f | 2010-04-25 20:42:02 +0000 | [diff] [blame] | 274 | printk(BIOS_DEBUG, "CPU: family %02x, model %02x, stepping %02x\n", |
| 275 | c.x86, c.x86_model, c.x86_mask); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 276 | |
Yinghai Lu | 30b4abe | 2007-04-06 19:57:42 +0000 | [diff] [blame] | 277 | /* Lookup the cpu's operations */ |
| 278 | set_cpu_ops(cpu); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 279 | |
Elyes HAOUAS | dbf3067 | 2016-08-21 17:37:15 +0200 | [diff] [blame] | 280 | if (!cpu->ops) { |
Yinghai Lu | 30b4abe | 2007-04-06 19:57:42 +0000 | [diff] [blame] | 281 | /* mask out the stepping and try again */ |
| 282 | cpu->device -= c.x86_mask; |
Steven J. Magnani | eccc357 | 2005-09-14 13:53:45 +0000 | [diff] [blame] | 283 | set_cpu_ops(cpu); |
Yinghai Lu | 30b4abe | 2007-04-06 19:57:42 +0000 | [diff] [blame] | 284 | cpu->device += c.x86_mask; |
Lee Leahy | 0b5678f | 2017-03-16 16:01:40 -0700 | [diff] [blame] | 285 | if (!cpu->ops) |
| 286 | die("Unknown cpu"); |
Elyes HAOUAS | 777ea89 | 2016-07-29 07:40:41 +0200 | [diff] [blame] | 287 | printk(BIOS_DEBUG, "Using generic CPU ops (good)\n"); |
Ronald G. Minnich | 43225bc | 2005-11-22 00:07:02 +0000 | [diff] [blame] | 288 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 289 | |
Elyes HAOUAS | 777ea89 | 2016-07-29 07:40:41 +0200 | [diff] [blame] | 290 | /* Initialize the CPU */ |
Yinghai Lu | 30b4abe | 2007-04-06 19:57:42 +0000 | [diff] [blame] | 291 | if (cpu->ops && cpu->ops->init) { |
| 292 | cpu->enabled = 1; |
| 293 | cpu->initialized = 1; |
| 294 | cpu->ops->init(cpu); |
| 295 | } |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 296 | post_log_clear(); |
Yinghai Lu | 30b4abe | 2007-04-06 19:57:42 +0000 | [diff] [blame] | 297 | |
Ronald G. Minnich | 8b93059 | 2012-06-05 14:41:27 -0700 | [diff] [blame] | 298 | printk(BIOS_INFO, "CPU #%d initialized\n", index); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 299 | } |
Aaron Durbin | f6ada1c | 2016-02-10 10:52:47 -0600 | [diff] [blame] | 300 | |
| 301 | void lb_arch_add_records(struct lb_header *header) |
| 302 | { |
Aaron Durbin | e0969ae | 2016-02-10 10:56:06 -0600 | [diff] [blame] | 303 | uint32_t freq_khz; |
| 304 | struct lb_tsc_info *tsc_info; |
| 305 | |
| 306 | /* Don't advertise a TSC rate unless it's constant. */ |
Kyösti Mälkki | 0d6ddf8 | 2019-10-31 14:52:20 +0200 | [diff] [blame] | 307 | if (!tsc_constant_rate()) |
Aaron Durbin | e0969ae | 2016-02-10 10:56:06 -0600 | [diff] [blame] | 308 | return; |
| 309 | |
| 310 | freq_khz = tsc_freq_mhz() * 1000; |
| 311 | |
| 312 | /* No use exposing a TSC frequency that is zero. */ |
| 313 | if (freq_khz == 0) |
| 314 | return; |
| 315 | |
| 316 | tsc_info = (void *)lb_new_record(header); |
| 317 | tsc_info->tag = LB_TAG_TSC_INFO; |
| 318 | tsc_info->size = sizeof(*tsc_info); |
| 319 | tsc_info->freq_khz = freq_khz; |
Aaron Durbin | f6ada1c | 2016-02-10 10:52:47 -0600 | [diff] [blame] | 320 | } |
Aaron Durbin | b21e362 | 2016-12-07 00:32:19 -0600 | [diff] [blame] | 321 | |
| 322 | void arch_bootstate_coreboot_exit(void) |
| 323 | { |
| 324 | /* APs are already parked by existing infrastructure. */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 325 | if (!CONFIG(PARALLEL_MP_AP_WORK)) |
Aaron Durbin | b21e362 | 2016-12-07 00:32:19 -0600 | [diff] [blame] | 326 | return; |
| 327 | |
| 328 | /* APs are waiting for work. Last thing to do is park them. */ |
Furquan Shaikh | d6630d1 | 2018-03-29 00:10:02 -0700 | [diff] [blame] | 329 | mp_park_aps(); |
Aaron Durbin | b21e362 | 2016-12-07 00:32:19 -0600 | [diff] [blame] | 330 | } |
Subrata Banik | 095c931 | 2019-05-06 19:51:34 +0530 | [diff] [blame] | 331 | |
| 332 | /* |
| 333 | * Previously cpu_index() implementation assumes that cpu_index() |
| 334 | * function will always getting called from coreboot context |
| 335 | * (ESP stack pointer will always refer to coreboot). |
| 336 | * |
Furquan Shaikh | 5f262be | 2021-02-03 23:10:22 -0800 | [diff] [blame^] | 337 | * But with MP_SERVICES_PPI implementation in coreboot this |
Subrata Banik | 095c931 | 2019-05-06 19:51:34 +0530 | [diff] [blame] | 338 | * assumption might not be true, where FSP context (stack pointer refers |
| 339 | * to FSP) will request to get cpu_index(). |
| 340 | * |
| 341 | * Hence new logic to use cpuid to fetch lapic id and matches with |
| 342 | * cpus_default_apic_id[] variable to return correct cpu_index(). |
| 343 | */ |
Jacob Garber | bc67476 | 2019-05-14 11:21:41 -0600 | [diff] [blame] | 344 | int cpu_index(void) |
Subrata Banik | 095c931 | 2019-05-06 19:51:34 +0530 | [diff] [blame] | 345 | { |
| 346 | int i; |
| 347 | int lapic_id = initial_lapicid(); |
| 348 | |
| 349 | for (i = 0; i < CONFIG_MAX_CPUS; i++) { |
| 350 | if (cpu_get_apic_id(i) == lapic_id) |
| 351 | return i; |
| 352 | } |
| 353 | return -1; |
| 354 | } |
Furquan Shaikh | b1859a6 | 2020-04-30 21:27:47 -0700 | [diff] [blame] | 355 | |
| 356 | uintptr_t cpu_get_lapic_addr(void) |
| 357 | { |
| 358 | return LOCAL_APIC_ADDR; |
| 359 | } |