Angel Pons | f23ae0b | 2020-04-02 23:48:12 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Damien Roth | 07a196e | 2016-01-19 20:20:15 -0700 | [diff] [blame] | 3 | |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 4 | #include <console/console.h> |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 5 | #include <cpu/x86/lapic.h> |
| 6 | #include <cpu/intel/hyperthreading.h> |
| 7 | #include <device/device.h> |
Kyösti Mälkki | cbf9571 | 2020-01-05 08:05:45 +0200 | [diff] [blame] | 8 | #include <option.h> |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 9 | #include <smp/spinlock.h> |
Kyösti Mälkki | 8b28d50 | 2012-03-09 17:02:37 +0200 | [diff] [blame] | 10 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 11 | #if CONFIG(PARALLEL_CPU_INIT) |
Elyes HAOUAS | d82be92 | 2016-07-28 18:58:27 +0200 | [diff] [blame] | 12 | #error Intel hyper-threading requires serialized CPU init |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 13 | #endif |
| 14 | |
| 15 | static int first_time = 1; |
Julius Werner | 5d1f9a0 | 2019-03-07 17:07:26 -0800 | [diff] [blame] | 16 | static int disable_siblings = !CONFIG(LOGICAL_CPUS); |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 17 | |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 18 | void intel_sibling_init(struct device *cpu) |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 19 | { |
Lee Leahy | 73a2894 | 2017-03-15 17:52:06 -0700 | [diff] [blame] | 20 | unsigned int i, siblings; |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 21 | struct cpuid_result result; |
| 22 | |
| 23 | /* On the bootstrap processor see if I want sibling cpus enabled */ |
| 24 | if (first_time) { |
| 25 | first_time = 0; |
| 26 | get_option(&disable_siblings, "hyper_threading"); |
| 27 | } |
| 28 | result = cpuid(1); |
| 29 | /* Is hyperthreading supported */ |
Lee Leahy | 26eeb0f | 2017-03-15 18:08:50 -0700 | [diff] [blame] | 30 | if (!(result.edx & (1 << 28))) |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 31 | return; |
Lee Leahy | 26eeb0f | 2017-03-15 18:08:50 -0700 | [diff] [blame] | 32 | |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 33 | /* See how many sibling cpus we have */ |
| 34 | siblings = (result.ebx >> 16) & 0xff; |
Lee Leahy | 26eeb0f | 2017-03-15 18:08:50 -0700 | [diff] [blame] | 35 | if (siblings < 1) |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 36 | siblings = 1; |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 37 | |
| 38 | printk(BIOS_DEBUG, "CPU: %u %d siblings\n", |
| 39 | cpu->path.apic.apic_id, |
| 40 | siblings); |
| 41 | |
| 42 | /* See if I am a sibling cpu */ |
Lee Leahy | 9d62e7e | 2017-03-15 17:40:50 -0700 | [diff] [blame] | 43 | if (cpu->path.apic.apic_id & (siblings - 1)) { |
Lee Leahy | 26eeb0f | 2017-03-15 18:08:50 -0700 | [diff] [blame] | 44 | if (disable_siblings) |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 45 | cpu->enabled = 0; |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 46 | return; |
| 47 | } |
| 48 | |
Elyes HAOUAS | d82be92 | 2016-07-28 18:58:27 +0200 | [diff] [blame] | 49 | /* I am the primary CPU start up my siblings */ |
Elyes HAOUAS | cbe7464c | 2016-08-23 21:07:28 +0200 | [diff] [blame] | 50 | for (i = 1; i < siblings; i++) { |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 51 | struct device_path cpu_path; |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 52 | struct device *new; |
Elyes HAOUAS | d82be92 | 2016-07-28 18:58:27 +0200 | [diff] [blame] | 53 | /* Build the CPU device path */ |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 54 | cpu_path.type = DEVICE_PATH_APIC; |
| 55 | cpu_path.apic.apic_id = cpu->path.apic.apic_id + i; |
| 56 | |
| 57 | |
Elyes HAOUAS | d82be92 | 2016-07-28 18:58:27 +0200 | [diff] [blame] | 58 | /* Allocate new CPU device structure iff sibling CPU |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 59 | * was not in static device tree. |
| 60 | */ |
| 61 | new = alloc_find_dev(cpu->bus, &cpu_path); |
| 62 | |
Lee Leahy | 26eeb0f | 2017-03-15 18:08:50 -0700 | [diff] [blame] | 63 | if (!new) |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 64 | continue; |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame] | 65 | |
| 66 | printk(BIOS_DEBUG, "CPU: %u has sibling %u\n", |
| 67 | cpu->path.apic.apic_id, |
| 68 | new->path.apic.apic_id); |
| 69 | } |
| 70 | } |