Angel Pons | c74dae9 | 2020-04-02 23:48:16 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 2 | |
| 3 | #include <device/device.h> |
| 4 | #include <console/console.h> |
Elyes Haouas | 04c3b5a | 2022-10-07 10:08:05 +0200 | [diff] [blame] | 5 | #include <stddef.h> |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 6 | |
Elyes HAOUAS | 8cf8a63 | 2019-06-09 10:23:25 +0200 | [diff] [blame] | 7 | struct device *add_cpu_device(struct bus *cpu_bus, unsigned int apic_id, |
Elyes HAOUAS | e348066 | 2018-05-06 20:32:23 +0200 | [diff] [blame] | 8 | int enabled) |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 9 | { |
Arthur Heymans | 4f2b5a5 | 2022-11-17 20:36:40 +0100 | [diff] [blame] | 10 | struct device_path cpu_path = {}; |
Elyes HAOUAS | e348066 | 2018-05-06 20:32:23 +0200 | [diff] [blame] | 11 | struct device *cpu; |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 12 | |
Elyes HAOUAS | fa640a2 | 2016-07-28 21:31:40 +0200 | [diff] [blame] | 13 | /* Build the CPU device path */ |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 14 | cpu_path.type = DEVICE_PATH_APIC; |
| 15 | cpu_path.apic.apic_id = apic_id; |
Arthur Heymans | 21ca775 | 2022-05-14 02:14:31 +0200 | [diff] [blame] | 16 | cpu_path.apic.initial_lapicid = apic_id; |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 17 | |
| 18 | /* Update CPU in devicetree. */ |
| 19 | if (enabled) |
| 20 | cpu = alloc_find_dev(cpu_bus, &cpu_path); |
| 21 | else |
| 22 | cpu = find_dev_path(cpu_bus, &cpu_path); |
| 23 | if (!cpu) |
| 24 | return NULL; |
| 25 | |
| 26 | cpu->enabled = enabled; |
| 27 | printk(BIOS_DEBUG, "CPU: %s %s\n", |
| 28 | dev_path(cpu), cpu->enabled?"enabled":"disabled"); |
| 29 | |
| 30 | return cpu; |
| 31 | } |