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