|
8 | 8 | * Copyright (C) 2017 SiFive
|
9 | 9 | */
|
10 | 10 |
|
| 11 | +#include <linux/acpi.h> |
11 | 12 | #include <linux/arch_topology.h>
|
12 | 13 | #include <linux/module.h>
|
13 | 14 | #include <linux/init.h>
|
@@ -70,6 +71,72 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
|
70 | 71 | }
|
71 | 72 | }
|
72 | 73 |
|
| 74 | +#ifdef CONFIG_ACPI |
| 75 | +static unsigned int cpu_count = 1; |
| 76 | + |
| 77 | +static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const unsigned long end) |
| 78 | +{ |
| 79 | + unsigned long hart; |
| 80 | + static bool found_boot_cpu; |
| 81 | + struct acpi_madt_rintc *processor = (struct acpi_madt_rintc *)header; |
| 82 | + |
| 83 | + /* |
| 84 | + * Each RINTC structure in MADT will have a flag. If ACPI_MADT_ENABLED |
| 85 | + * bit in the flag is not enabled, it means OS should not try to enable |
| 86 | + * the cpu to which RINTC belongs. |
| 87 | + */ |
| 88 | + if (!(processor->flags & ACPI_MADT_ENABLED)) |
| 89 | + return 0; |
| 90 | + |
| 91 | + if (BAD_MADT_ENTRY(processor, end)) |
| 92 | + return -EINVAL; |
| 93 | + |
| 94 | + acpi_table_print_madt_entry(&header->common); |
| 95 | + |
| 96 | + hart = processor->hart_id; |
| 97 | + if (hart == INVALID_HARTID) { |
| 98 | + pr_warn("Invalid hartid\n"); |
| 99 | + return 0; |
| 100 | + } |
| 101 | + |
| 102 | + if (hart == cpuid_to_hartid_map(0)) { |
| 103 | + BUG_ON(found_boot_cpu); |
| 104 | + found_boot_cpu = true; |
| 105 | + early_map_cpu_to_node(0, acpi_numa_get_nid(cpu_count)); |
| 106 | + return 0; |
| 107 | + } |
| 108 | + |
| 109 | + if (cpu_count >= NR_CPUS) { |
| 110 | + pr_warn("NR_CPUS is too small for the number of ACPI tables.\n"); |
| 111 | + return 0; |
| 112 | + } |
| 113 | + |
| 114 | + cpuid_to_hartid_map(cpu_count) = hart; |
| 115 | + early_map_cpu_to_node(cpu_count, acpi_numa_get_nid(cpu_count)); |
| 116 | + cpu_count++; |
| 117 | + |
| 118 | + return 0; |
| 119 | +} |
| 120 | + |
| 121 | +static void __init acpi_parse_and_init_cpus(void) |
| 122 | +{ |
| 123 | + int cpuid; |
| 124 | + |
| 125 | + cpu_set_ops(0); |
| 126 | + |
| 127 | + acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_parse_rintc, 0); |
| 128 | + |
| 129 | + for (cpuid = 1; cpuid < nr_cpu_ids; cpuid++) { |
| 130 | + if (cpuid_to_hartid_map(cpuid) != INVALID_HARTID) { |
| 131 | + cpu_set_ops(cpuid); |
| 132 | + set_cpu_possible(cpuid, true); |
| 133 | + } |
| 134 | + } |
| 135 | +} |
| 136 | +#else |
| 137 | +#define acpi_parse_and_init_cpus(...) do { } while (0) |
| 138 | +#endif |
| 139 | + |
73 | 140 | static void __init of_parse_and_init_cpus(void)
|
74 | 141 | {
|
75 | 142 | struct device_node *dn;
|
@@ -118,7 +185,10 @@ static void __init of_parse_and_init_cpus(void)
|
118 | 185 |
|
119 | 186 | void __init setup_smp(void)
|
120 | 187 | {
|
121 |
| - of_parse_and_init_cpus(); |
| 188 | + if (acpi_disabled) |
| 189 | + of_parse_and_init_cpus(); |
| 190 | + else |
| 191 | + acpi_parse_and_init_cpus(); |
122 | 192 | }
|
123 | 193 |
|
124 | 194 | static int start_secondary_cpu(int cpu, struct task_struct *tidle)
|
|
0 commit comments