0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/delay.h>
0009 #include <linux/init.h>
0010 #include <linux/of.h>
0011 #include <linux/smp.h>
0012 #include <linux/types.h>
0013 #include <linux/mm.h>
0014
0015 #include <asm/cacheflush.h>
0016 #include <asm/cpu_ops.h>
0017 #include <asm/cputype.h>
0018 #include <asm/io.h>
0019 #include <asm/smp_plat.h>
0020
0021 extern void secondary_holding_pen(void);
0022 volatile unsigned long __section(".mmuoff.data.read")
0023 secondary_holding_pen_release = INVALID_HWID;
0024
0025 static phys_addr_t cpu_release_addr[NR_CPUS];
0026
0027
0028
0029
0030
0031
0032
0033 static void write_pen_release(u64 val)
0034 {
0035 void *start = (void *)&secondary_holding_pen_release;
0036 unsigned long size = sizeof(secondary_holding_pen_release);
0037
0038 secondary_holding_pen_release = val;
0039 dcache_clean_inval_poc((unsigned long)start, (unsigned long)start + size);
0040 }
0041
0042
0043 static int smp_spin_table_cpu_init(unsigned int cpu)
0044 {
0045 struct device_node *dn;
0046 int ret;
0047
0048 dn = of_get_cpu_node(cpu, NULL);
0049 if (!dn)
0050 return -ENODEV;
0051
0052
0053
0054
0055 ret = of_property_read_u64(dn, "cpu-release-addr",
0056 &cpu_release_addr[cpu]);
0057 if (ret)
0058 pr_err("CPU %d: missing or invalid cpu-release-addr property\n",
0059 cpu);
0060
0061 of_node_put(dn);
0062
0063 return ret;
0064 }
0065
0066 static int smp_spin_table_cpu_prepare(unsigned int cpu)
0067 {
0068 __le64 __iomem *release_addr;
0069 phys_addr_t pa_holding_pen = __pa_symbol(function_nocfi(secondary_holding_pen));
0070
0071 if (!cpu_release_addr[cpu])
0072 return -ENODEV;
0073
0074
0075
0076
0077
0078
0079
0080 release_addr = ioremap_cache(cpu_release_addr[cpu],
0081 sizeof(*release_addr));
0082 if (!release_addr)
0083 return -ENOMEM;
0084
0085
0086
0087
0088
0089
0090
0091
0092 writeq_relaxed(pa_holding_pen, release_addr);
0093 dcache_clean_inval_poc((__force unsigned long)release_addr,
0094 (__force unsigned long)release_addr +
0095 sizeof(*release_addr));
0096
0097
0098
0099
0100 sev();
0101
0102 iounmap(release_addr);
0103
0104 return 0;
0105 }
0106
0107 static int smp_spin_table_cpu_boot(unsigned int cpu)
0108 {
0109
0110
0111
0112 write_pen_release(cpu_logical_map(cpu));
0113
0114
0115
0116
0117 sev();
0118
0119 return 0;
0120 }
0121
0122 const struct cpu_operations smp_spin_table_ops = {
0123 .name = "spin-table",
0124 .cpu_init = smp_spin_table_cpu_init,
0125 .cpu_prepare = smp_spin_table_cpu_prepare,
0126 .cpu_boot = smp_spin_table_cpu_boot,
0127 };