Thomas Gleixner | caab277 | 2019-06-03 07:44:50 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Mark Rutland | cd1aebf | 2013-10-24 20:30:15 +0100 | [diff] [blame] | 2 | /* |
| 3 | * CPU kernel entry/exit control |
| 4 | * |
| 5 | * Copyright (C) 2013 ARM Ltd. |
Mark Rutland | cd1aebf | 2013-10-24 20:30:15 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
Lorenzo Pieralisi | 0f07833 | 2015-05-13 14:12:47 +0100 | [diff] [blame] | 8 | #include <linux/acpi.h> |
Jisheng Zhang | 5a9e3e1 | 2016-08-15 14:45:46 +0800 | [diff] [blame] | 9 | #include <linux/cache.h> |
Mark Rutland | e8765b2 | 2013-10-24 20:30:17 +0100 | [diff] [blame] | 10 | #include <linux/errno.h> |
| 11 | #include <linux/of.h> |
Mark Rutland | cd1aebf | 2013-10-24 20:30:15 +0100 | [diff] [blame] | 12 | #include <linux/string.h> |
Lorenzo Pieralisi | 0f07833 | 2015-05-13 14:12:47 +0100 | [diff] [blame] | 13 | #include <asm/acpi.h> |
| 14 | #include <asm/cpu_ops.h> |
| 15 | #include <asm/smp_plat.h> |
Mark Rutland | cd1aebf | 2013-10-24 20:30:15 +0100 | [diff] [blame] | 16 | |
| 17 | extern const struct cpu_operations smp_spin_table_ops; |
Gavin Shan | 7fec52b | 2020-03-19 10:01:42 +1100 | [diff] [blame] | 18 | #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL |
Lorenzo Pieralisi | 5e89c55 | 2016-01-26 11:10:38 +0000 | [diff] [blame] | 19 | extern const struct cpu_operations acpi_parking_protocol_ops; |
Gavin Shan | 7fec52b | 2020-03-19 10:01:42 +1100 | [diff] [blame] | 20 | #endif |
Mark Rutland | cd1aebf | 2013-10-24 20:30:15 +0100 | [diff] [blame] | 21 | extern const struct cpu_operations cpu_psci_ops; |
| 22 | |
Gavin Shan | de58ed5e | 2020-03-19 10:01:44 +1100 | [diff] [blame] | 23 | static const struct cpu_operations *cpu_ops[NR_CPUS] __ro_after_init; |
Mark Rutland | cd1aebf | 2013-10-24 20:30:15 +0100 | [diff] [blame] | 24 | |
Yury Norov | 770ba06 | 2017-11-29 17:03:03 +0300 | [diff] [blame] | 25 | static const struct cpu_operations *const dt_supported_cpu_ops[] __initconst = { |
Mark Rutland | cd1aebf | 2013-10-24 20:30:15 +0100 | [diff] [blame] | 26 | &smp_spin_table_ops, |
Lorenzo Pieralisi | 756854d | 2014-07-17 18:19:18 +0100 | [diff] [blame] | 27 | &cpu_psci_ops, |
Mark Rutland | cd1aebf | 2013-10-24 20:30:15 +0100 | [diff] [blame] | 28 | NULL, |
| 29 | }; |
| 30 | |
Yury Norov | 770ba06 | 2017-11-29 17:03:03 +0300 | [diff] [blame] | 31 | static const struct cpu_operations *const acpi_supported_cpu_ops[] __initconst = { |
Lorenzo Pieralisi | 5e89c55 | 2016-01-26 11:10:38 +0000 | [diff] [blame] | 32 | #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL |
| 33 | &acpi_parking_protocol_ops, |
| 34 | #endif |
| 35 | &cpu_psci_ops, |
| 36 | NULL, |
| 37 | }; |
| 38 | |
Lorenzo Pieralisi | 0f07833 | 2015-05-13 14:12:47 +0100 | [diff] [blame] | 39 | static const struct cpu_operations * __init cpu_get_ops(const char *name) |
Mark Rutland | cd1aebf | 2013-10-24 20:30:15 +0100 | [diff] [blame] | 40 | { |
Yury Norov | 770ba06 | 2017-11-29 17:03:03 +0300 | [diff] [blame] | 41 | const struct cpu_operations *const *ops; |
Lorenzo Pieralisi | 5e89c55 | 2016-01-26 11:10:38 +0000 | [diff] [blame] | 42 | |
| 43 | ops = acpi_disabled ? dt_supported_cpu_ops : acpi_supported_cpu_ops; |
Mark Rutland | cd1aebf | 2013-10-24 20:30:15 +0100 | [diff] [blame] | 44 | |
| 45 | while (*ops) { |
| 46 | if (!strcmp(name, (*ops)->name)) |
| 47 | return *ops; |
| 48 | |
| 49 | ops++; |
| 50 | } |
| 51 | |
| 52 | return NULL; |
| 53 | } |
Mark Rutland | e8765b2 | 2013-10-24 20:30:17 +0100 | [diff] [blame] | 54 | |
Lorenzo Pieralisi | 0f07833 | 2015-05-13 14:12:47 +0100 | [diff] [blame] | 55 | static const char *__init cpu_read_enable_method(int cpu) |
| 56 | { |
| 57 | const char *enable_method; |
| 58 | |
| 59 | if (acpi_disabled) { |
| 60 | struct device_node *dn = of_get_cpu_node(cpu, NULL); |
| 61 | |
| 62 | if (!dn) { |
| 63 | if (!cpu) |
| 64 | pr_err("Failed to find device node for boot cpu\n"); |
| 65 | return NULL; |
| 66 | } |
| 67 | |
| 68 | enable_method = of_get_property(dn, "enable-method", NULL); |
| 69 | if (!enable_method) { |
| 70 | /* |
| 71 | * The boot CPU may not have an enable method (e.g. |
| 72 | * when spin-table is used for secondaries). |
| 73 | * Don't warn spuriously. |
| 74 | */ |
| 75 | if (cpu != 0) |
Rob Herring | a270f32 | 2017-07-18 16:42:42 -0500 | [diff] [blame] | 76 | pr_err("%pOF: missing enable-method property\n", |
| 77 | dn); |
Lorenzo Pieralisi | 0f07833 | 2015-05-13 14:12:47 +0100 | [diff] [blame] | 78 | } |
Wen Yang | 92606ec | 2019-03-05 19:34:05 +0800 | [diff] [blame] | 79 | of_node_put(dn); |
Lorenzo Pieralisi | 0f07833 | 2015-05-13 14:12:47 +0100 | [diff] [blame] | 80 | } else { |
| 81 | enable_method = acpi_get_enable_method(cpu); |
Lorenzo Pieralisi | 5e89c55 | 2016-01-26 11:10:38 +0000 | [diff] [blame] | 82 | if (!enable_method) { |
| 83 | /* |
| 84 | * In ACPI systems the boot CPU does not require |
| 85 | * checking the enable method since for some |
| 86 | * boot protocol (ie parking protocol) it need not |
| 87 | * be initialized. Don't warn spuriously. |
| 88 | */ |
| 89 | if (cpu != 0) |
| 90 | pr_err("Unsupported ACPI enable-method\n"); |
| 91 | } |
Lorenzo Pieralisi | 0f07833 | 2015-05-13 14:12:47 +0100 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | return enable_method; |
| 95 | } |
Mark Rutland | e8765b2 | 2013-10-24 20:30:17 +0100 | [diff] [blame] | 96 | /* |
Lorenzo Pieralisi | 0f07833 | 2015-05-13 14:12:47 +0100 | [diff] [blame] | 97 | * Read a cpu's enable method and record it in cpu_ops. |
Mark Rutland | e8765b2 | 2013-10-24 20:30:17 +0100 | [diff] [blame] | 98 | */ |
Gavin Shan | 6885fb1 | 2020-03-19 10:01:43 +1100 | [diff] [blame] | 99 | int __init init_cpu_ops(int cpu) |
Mark Rutland | e8765b2 | 2013-10-24 20:30:17 +0100 | [diff] [blame] | 100 | { |
Lorenzo Pieralisi | 0f07833 | 2015-05-13 14:12:47 +0100 | [diff] [blame] | 101 | const char *enable_method = cpu_read_enable_method(cpu); |
Lorenzo Pieralisi | 819a882 | 2015-05-13 14:12:46 +0100 | [diff] [blame] | 102 | |
Lorenzo Pieralisi | 0f07833 | 2015-05-13 14:12:47 +0100 | [diff] [blame] | 103 | if (!enable_method) |
Lorenzo Pieralisi | 819a882 | 2015-05-13 14:12:46 +0100 | [diff] [blame] | 104 | return -ENODEV; |
Mark Rutland | e8765b2 | 2013-10-24 20:30:17 +0100 | [diff] [blame] | 105 | |
| 106 | cpu_ops[cpu] = cpu_get_ops(enable_method); |
| 107 | if (!cpu_ops[cpu]) { |
Lorenzo Pieralisi | 0f07833 | 2015-05-13 14:12:47 +0100 | [diff] [blame] | 108 | pr_warn("Unsupported enable-method: %s\n", enable_method); |
Mark Rutland | e8765b2 | 2013-10-24 20:30:17 +0100 | [diff] [blame] | 109 | return -EOPNOTSUPP; |
| 110 | } |
| 111 | |
| 112 | return 0; |
| 113 | } |
Gavin Shan | de58ed5e | 2020-03-19 10:01:44 +1100 | [diff] [blame] | 114 | |
| 115 | const struct cpu_operations *get_cpu_ops(int cpu) |
| 116 | { |
| 117 | return cpu_ops[cpu]; |
| 118 | } |