Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 1 | #include <console/console.h> |
| 2 | #include <cpu/cpu.h> |
| 3 | #include <cpu/x86/lapic.h> |
| 4 | #include <cpu/intel/hyperthreading.h> |
| 5 | #include <device/device.h> |
| 6 | #include <pc80/mc146818rtc.h> |
| 7 | #include <smp/spinlock.h> |
Kyösti Mälkki | 8b28d50 | 2012-03-09 17:02:37 +0200 | [diff] [blame^] | 8 | #include <assert.h> |
| 9 | |
| 10 | #if CONFIG_SERIAL_CPU_INIT==0 |
| 11 | #error Intel hyper-threading requires serialized cpu init |
| 12 | #endif |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 13 | |
| 14 | static int first_time = 1; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 15 | static int disable_siblings = !CONFIG_LOGICAL_CPUS; |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 16 | |
| 17 | void intel_sibling_init(device_t cpu) |
| 18 | { |
| 19 | unsigned i, siblings; |
| 20 | struct cpuid_result result; |
| 21 | |
| 22 | /* On the bootstrap processor see if I want sibling cpus enabled */ |
| 23 | if (first_time) { |
| 24 | first_time = 0; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 25 | get_option(&disable_siblings, "hyper_threading"); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 26 | } |
| 27 | result = cpuid(1); |
Patrick Georgi | 6af0cb6 | 2009-04-22 08:07:31 +0000 | [diff] [blame] | 28 | /* Is hyperthreading supported */ |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 29 | if (!(result.edx & (1 << 28))) { |
| 30 | return; |
| 31 | } |
| 32 | /* See how many sibling cpus we have */ |
| 33 | siblings = (result.ebx >> 16) & 0xff; |
| 34 | if (siblings < 1) { |
| 35 | siblings = 1; |
| 36 | } |
| 37 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 38 | printk(BIOS_DEBUG, "CPU: %u %d siblings\n", |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 39 | cpu->path.apic.apic_id, |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 40 | siblings); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 41 | |
| 42 | /* See if I am a sibling cpu */ |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 43 | if (cpu->path.apic.apic_id & (siblings -1)) { |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 44 | if (disable_siblings) { |
| 45 | cpu->enabled = 0; |
| 46 | } |
| 47 | return; |
| 48 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 49 | |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 50 | /* I am the primary cpu start up my siblings */ |
| 51 | for(i = 1; i < siblings; i++) { |
| 52 | struct device_path cpu_path; |
| 53 | device_t new; |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 54 | /* Build the cpu device path */ |
| 55 | cpu_path.type = DEVICE_PATH_APIC; |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 56 | cpu_path.apic.apic_id = cpu->path.apic.apic_id + i; |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 57 | |
| 58 | |
Kyösti Mälkki | 8b28d50 | 2012-03-09 17:02:37 +0200 | [diff] [blame^] | 59 | /* Allocate new cpu device structure iff sibling CPU |
| 60 | * was not in static device tree. |
| 61 | */ |
| 62 | new = alloc_find_dev(cpu->bus, &cpu_path); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 63 | |
| 64 | if (!new) { |
| 65 | continue; |
| 66 | } |
| 67 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 68 | printk(BIOS_DEBUG, "CPU: %u has sibling %u\n", |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 69 | cpu->path.apic.apic_id, |
| 70 | new->path.apic.apic_id); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 71 | } |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 72 | } |
| 73 | |