blob: f602ccded702b4804f6d25c6909cc6cb821b21a5 [file] [log] [blame]
Damien Roth07a196e2016-01-19 20:20:15 -07001/*
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 Biedermanfcd5ace2004-10-14 19:29:29 +000014#include <console/console.h>
Eric Biedermanfcd5ace2004-10-14 19:29:29 +000015#include <cpu/x86/lapic.h>
16#include <cpu/intel/hyperthreading.h>
17#include <device/device.h>
Kyösti Mälkkicbf95712020-01-05 08:05:45 +020018#include <option.h>
Eric Biedermanfcd5ace2004-10-14 19:29:29 +000019#include <smp/spinlock.h>
Kyösti Mälkki8b28d502012-03-09 17:02:37 +020020
Julius Wernercd49cce2019-03-05 16:53:33 -080021#if CONFIG(PARALLEL_CPU_INIT)
Elyes HAOUASd82be922016-07-28 18:58:27 +020022#error Intel hyper-threading requires serialized CPU init
Sven Schnelle51676b12012-07-29 19:18:03 +020023#endif
24
25static int first_time = 1;
Julius Werner5d1f9a02019-03-07 17:07:26 -080026static int disable_siblings = !CONFIG(LOGICAL_CPUS);
Sven Schnelle51676b12012-07-29 19:18:03 +020027
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +110028void intel_sibling_init(struct device *cpu)
Sven Schnelle51676b12012-07-29 19:18:03 +020029{
Lee Leahy73a28942017-03-15 17:52:06 -070030 unsigned int i, siblings;
Sven Schnelle51676b12012-07-29 19:18:03 +020031 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 Leahy26eeb0f2017-03-15 18:08:50 -070040 if (!(result.edx & (1 << 28)))
Sven Schnelle51676b12012-07-29 19:18:03 +020041 return;
Lee Leahy26eeb0f2017-03-15 18:08:50 -070042
Sven Schnelle51676b12012-07-29 19:18:03 +020043 /* See how many sibling cpus we have */
44 siblings = (result.ebx >> 16) & 0xff;
Lee Leahy26eeb0f2017-03-15 18:08:50 -070045 if (siblings < 1)
Sven Schnelle51676b12012-07-29 19:18:03 +020046 siblings = 1;
Sven Schnelle51676b12012-07-29 19:18:03 +020047
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 Leahy9d62e7e2017-03-15 17:40:50 -070053 if (cpu->path.apic.apic_id & (siblings - 1)) {
Lee Leahy26eeb0f2017-03-15 18:08:50 -070054 if (disable_siblings)
Sven Schnelle51676b12012-07-29 19:18:03 +020055 cpu->enabled = 0;
Sven Schnelle51676b12012-07-29 19:18:03 +020056 return;
57 }
58
Elyes HAOUASd82be922016-07-28 18:58:27 +020059 /* I am the primary CPU start up my siblings */
Elyes HAOUAScbe7464c2016-08-23 21:07:28 +020060 for (i = 1; i < siblings; i++) {
Sven Schnelle51676b12012-07-29 19:18:03 +020061 struct device_path cpu_path;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +110062 struct device *new;
Elyes HAOUASd82be922016-07-28 18:58:27 +020063 /* Build the CPU device path */
Sven Schnelle51676b12012-07-29 19:18:03 +020064 cpu_path.type = DEVICE_PATH_APIC;
65 cpu_path.apic.apic_id = cpu->path.apic.apic_id + i;
66
67
Elyes HAOUASd82be922016-07-28 18:58:27 +020068 /* Allocate new CPU device structure iff sibling CPU
Sven Schnelle51676b12012-07-29 19:18:03 +020069 * was not in static device tree.
70 */
71 new = alloc_find_dev(cpu->bus, &cpu_path);
72
Lee Leahy26eeb0f2017-03-15 18:08:50 -070073 if (!new)
Sven Schnelle51676b12012-07-29 19:18:03 +020074 continue;
Sven Schnelle51676b12012-07-29 19:18:03 +020075
76 printk(BIOS_DEBUG, "CPU: %u has sibling %u\n",
77 cpu->path.apic.apic_id,
78 new->path.apic.apic_id);
79 }
80}