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