xref: /OK3568_Linux_fs/kernel/arch/arm/mach-hisi/platsmp.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2013 Linaro Ltd.
4*4882a593Smuzhiyun  * Copyright (c) 2013 Hisilicon Limited.
5*4882a593Smuzhiyun  * Based on arch/arm/mach-vexpress/platsmp.c, Copyright (C) 2002 ARM Ltd.
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun #include <linux/smp.h>
8*4882a593Smuzhiyun #include <linux/io.h>
9*4882a593Smuzhiyun #include <linux/of_address.h>
10*4882a593Smuzhiyun #include <linux/delay.h>
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <asm/cacheflush.h>
13*4882a593Smuzhiyun #include <asm/smp_plat.h>
14*4882a593Smuzhiyun #include <asm/smp_scu.h>
15*4882a593Smuzhiyun #include <asm/mach/map.h>
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #include "core.h"
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #define HIX5HD2_BOOT_ADDRESS		0xffff0000
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun static void __iomem *ctrl_base;
22*4882a593Smuzhiyun 
hi3xxx_set_cpu_jump(int cpu,void * jump_addr)23*4882a593Smuzhiyun void hi3xxx_set_cpu_jump(int cpu, void *jump_addr)
24*4882a593Smuzhiyun {
25*4882a593Smuzhiyun 	cpu = cpu_logical_map(cpu);
26*4882a593Smuzhiyun 	if (!cpu || !ctrl_base)
27*4882a593Smuzhiyun 		return;
28*4882a593Smuzhiyun 	writel_relaxed(__pa_symbol(jump_addr), ctrl_base + ((cpu - 1) << 2));
29*4882a593Smuzhiyun }
30*4882a593Smuzhiyun 
hi3xxx_get_cpu_jump(int cpu)31*4882a593Smuzhiyun int hi3xxx_get_cpu_jump(int cpu)
32*4882a593Smuzhiyun {
33*4882a593Smuzhiyun 	cpu = cpu_logical_map(cpu);
34*4882a593Smuzhiyun 	if (!cpu || !ctrl_base)
35*4882a593Smuzhiyun 		return 0;
36*4882a593Smuzhiyun 	return readl_relaxed(ctrl_base + ((cpu - 1) << 2));
37*4882a593Smuzhiyun }
38*4882a593Smuzhiyun 
hisi_enable_scu_a9(void)39*4882a593Smuzhiyun static void __init hisi_enable_scu_a9(void)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun 	unsigned long base = 0;
42*4882a593Smuzhiyun 	void __iomem *scu_base = NULL;
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun 	if (scu_a9_has_base()) {
45*4882a593Smuzhiyun 		base = scu_a9_get_base();
46*4882a593Smuzhiyun 		scu_base = ioremap(base, SZ_4K);
47*4882a593Smuzhiyun 		if (!scu_base) {
48*4882a593Smuzhiyun 			pr_err("ioremap(scu_base) failed\n");
49*4882a593Smuzhiyun 			return;
50*4882a593Smuzhiyun 		}
51*4882a593Smuzhiyun 		scu_enable(scu_base);
52*4882a593Smuzhiyun 		iounmap(scu_base);
53*4882a593Smuzhiyun 	}
54*4882a593Smuzhiyun }
55*4882a593Smuzhiyun 
hi3xxx_smp_prepare_cpus(unsigned int max_cpus)56*4882a593Smuzhiyun static void __init hi3xxx_smp_prepare_cpus(unsigned int max_cpus)
57*4882a593Smuzhiyun {
58*4882a593Smuzhiyun 	struct device_node *np = NULL;
59*4882a593Smuzhiyun 	u32 offset = 0;
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun 	hisi_enable_scu_a9();
62*4882a593Smuzhiyun 	if (!ctrl_base) {
63*4882a593Smuzhiyun 		np = of_find_compatible_node(NULL, NULL, "hisilicon,sysctrl");
64*4882a593Smuzhiyun 		if (!np) {
65*4882a593Smuzhiyun 			pr_err("failed to find hisilicon,sysctrl node\n");
66*4882a593Smuzhiyun 			return;
67*4882a593Smuzhiyun 		}
68*4882a593Smuzhiyun 		ctrl_base = of_iomap(np, 0);
69*4882a593Smuzhiyun 		if (!ctrl_base) {
70*4882a593Smuzhiyun 			of_node_put(np);
71*4882a593Smuzhiyun 			pr_err("failed to map address\n");
72*4882a593Smuzhiyun 			return;
73*4882a593Smuzhiyun 		}
74*4882a593Smuzhiyun 		if (of_property_read_u32(np, "smp-offset", &offset) < 0) {
75*4882a593Smuzhiyun 			of_node_put(np);
76*4882a593Smuzhiyun 			pr_err("failed to find smp-offset property\n");
77*4882a593Smuzhiyun 			return;
78*4882a593Smuzhiyun 		}
79*4882a593Smuzhiyun 		ctrl_base += offset;
80*4882a593Smuzhiyun 		of_node_put(np);
81*4882a593Smuzhiyun 	}
82*4882a593Smuzhiyun }
83*4882a593Smuzhiyun 
hi3xxx_boot_secondary(unsigned int cpu,struct task_struct * idle)84*4882a593Smuzhiyun static int hi3xxx_boot_secondary(unsigned int cpu, struct task_struct *idle)
85*4882a593Smuzhiyun {
86*4882a593Smuzhiyun 	hi3xxx_set_cpu(cpu, true);
87*4882a593Smuzhiyun 	hi3xxx_set_cpu_jump(cpu, secondary_startup);
88*4882a593Smuzhiyun 	arch_send_wakeup_ipi_mask(cpumask_of(cpu));
89*4882a593Smuzhiyun 	return 0;
90*4882a593Smuzhiyun }
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun static const struct smp_operations hi3xxx_smp_ops __initconst = {
93*4882a593Smuzhiyun 	.smp_prepare_cpus	= hi3xxx_smp_prepare_cpus,
94*4882a593Smuzhiyun 	.smp_boot_secondary	= hi3xxx_boot_secondary,
95*4882a593Smuzhiyun #ifdef CONFIG_HOTPLUG_CPU
96*4882a593Smuzhiyun 	.cpu_die		= hi3xxx_cpu_die,
97*4882a593Smuzhiyun 	.cpu_kill		= hi3xxx_cpu_kill,
98*4882a593Smuzhiyun #endif
99*4882a593Smuzhiyun };
100*4882a593Smuzhiyun 
hisi_common_smp_prepare_cpus(unsigned int max_cpus)101*4882a593Smuzhiyun static void __init hisi_common_smp_prepare_cpus(unsigned int max_cpus)
102*4882a593Smuzhiyun {
103*4882a593Smuzhiyun 	hisi_enable_scu_a9();
104*4882a593Smuzhiyun }
105*4882a593Smuzhiyun 
hix5hd2_set_scu_boot_addr(phys_addr_t start_addr,phys_addr_t jump_addr)106*4882a593Smuzhiyun static void hix5hd2_set_scu_boot_addr(phys_addr_t start_addr, phys_addr_t jump_addr)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun 	void __iomem *virt;
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun 	virt = ioremap(start_addr, PAGE_SIZE);
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun 	writel_relaxed(0xe51ff004, virt);	/* ldr pc, [pc, #-4] */
113*4882a593Smuzhiyun 	writel_relaxed(jump_addr, virt + 4);	/* pc jump phy address */
114*4882a593Smuzhiyun 	iounmap(virt);
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun 
hix5hd2_boot_secondary(unsigned int cpu,struct task_struct * idle)117*4882a593Smuzhiyun static int hix5hd2_boot_secondary(unsigned int cpu, struct task_struct *idle)
118*4882a593Smuzhiyun {
119*4882a593Smuzhiyun 	phys_addr_t jumpaddr;
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun 	jumpaddr = __pa_symbol(secondary_startup);
122*4882a593Smuzhiyun 	hix5hd2_set_scu_boot_addr(HIX5HD2_BOOT_ADDRESS, jumpaddr);
123*4882a593Smuzhiyun 	hix5hd2_set_cpu(cpu, true);
124*4882a593Smuzhiyun 	arch_send_wakeup_ipi_mask(cpumask_of(cpu));
125*4882a593Smuzhiyun 	return 0;
126*4882a593Smuzhiyun }
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun static const struct smp_operations hix5hd2_smp_ops __initconst = {
130*4882a593Smuzhiyun 	.smp_prepare_cpus	= hisi_common_smp_prepare_cpus,
131*4882a593Smuzhiyun 	.smp_boot_secondary	= hix5hd2_boot_secondary,
132*4882a593Smuzhiyun #ifdef CONFIG_HOTPLUG_CPU
133*4882a593Smuzhiyun 	.cpu_die		= hix5hd2_cpu_die,
134*4882a593Smuzhiyun #endif
135*4882a593Smuzhiyun };
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun #define SC_SCTL_REMAP_CLR      0x00000100
139*4882a593Smuzhiyun #define HIP01_BOOT_ADDRESS     0x80000000
140*4882a593Smuzhiyun #define REG_SC_CTRL            0x000
141*4882a593Smuzhiyun 
hip01_set_boot_addr(phys_addr_t start_addr,phys_addr_t jump_addr)142*4882a593Smuzhiyun static void hip01_set_boot_addr(phys_addr_t start_addr, phys_addr_t jump_addr)
143*4882a593Smuzhiyun {
144*4882a593Smuzhiyun 	void __iomem *virt;
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun 	virt = phys_to_virt(start_addr);
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun 	writel_relaxed(0xe51ff004, virt);
149*4882a593Smuzhiyun 	writel_relaxed(jump_addr, virt + 4);
150*4882a593Smuzhiyun }
151*4882a593Smuzhiyun 
hip01_boot_secondary(unsigned int cpu,struct task_struct * idle)152*4882a593Smuzhiyun static int hip01_boot_secondary(unsigned int cpu, struct task_struct *idle)
153*4882a593Smuzhiyun {
154*4882a593Smuzhiyun 	phys_addr_t jumpaddr;
155*4882a593Smuzhiyun 	unsigned int remap_reg_value = 0;
156*4882a593Smuzhiyun 	struct device_node *node;
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	jumpaddr = __pa_symbol(secondary_startup);
160*4882a593Smuzhiyun 	hip01_set_boot_addr(HIP01_BOOT_ADDRESS, jumpaddr);
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	node = of_find_compatible_node(NULL, NULL, "hisilicon,hip01-sysctrl");
163*4882a593Smuzhiyun 	if (WARN_ON(!node))
164*4882a593Smuzhiyun 		return -1;
165*4882a593Smuzhiyun 	ctrl_base = of_iomap(node, 0);
166*4882a593Smuzhiyun 	of_node_put(node);
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun 	/* set the secondary core boot from DDR */
169*4882a593Smuzhiyun 	remap_reg_value = readl_relaxed(ctrl_base + REG_SC_CTRL);
170*4882a593Smuzhiyun 	barrier();
171*4882a593Smuzhiyun 	remap_reg_value |= SC_SCTL_REMAP_CLR;
172*4882a593Smuzhiyun 	barrier();
173*4882a593Smuzhiyun 	writel_relaxed(remap_reg_value, ctrl_base + REG_SC_CTRL);
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun 	hip01_set_cpu(cpu, true);
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun 	return 0;
178*4882a593Smuzhiyun }
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun static const struct smp_operations hip01_smp_ops __initconst = {
181*4882a593Smuzhiyun 	.smp_prepare_cpus       = hisi_common_smp_prepare_cpus,
182*4882a593Smuzhiyun 	.smp_boot_secondary     = hip01_boot_secondary,
183*4882a593Smuzhiyun };
184*4882a593Smuzhiyun 
185*4882a593Smuzhiyun CPU_METHOD_OF_DECLARE(hi3xxx_smp, "hisilicon,hi3620-smp", &hi3xxx_smp_ops);
186*4882a593Smuzhiyun CPU_METHOD_OF_DECLARE(hix5hd2_smp, "hisilicon,hix5hd2-smp", &hix5hd2_smp_ops);
187*4882a593Smuzhiyun CPU_METHOD_OF_DECLARE(hip01_smp, "hisilicon,hip01-smp", &hip01_smp_ops);
188