mm: make wait_on_page_writeback() wait for multiple pending writebacks
[linux/fpc-iii.git] / arch / arm / mach-actions / platsmp.c
blobf26618b435145d255655b711874e48f9b2851eb0
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Actions Semi Leopard
5 * This file is based on arm realview smp platform.
7 * Copyright 2012 Actions Semi Inc.
8 * Author: Actions Semi, Inc.
10 * Copyright (c) 2017 Andreas Färber
13 #include <linux/delay.h>
14 #include <linux/io.h>
15 #include <linux/of.h>
16 #include <linux/of_address.h>
17 #include <linux/smp.h>
18 #include <linux/soc/actions/owl-sps.h>
19 #include <asm/cacheflush.h>
20 #include <asm/smp_plat.h>
21 #include <asm/smp_scu.h>
23 #define OWL_CPU1_ADDR 0x50
24 #define OWL_CPU1_FLAG 0x5c
26 #define OWL_CPUx_FLAG_BOOT 0x55aa
28 #define OWL_SPS_PG_CTL_PWR_CPU2 BIT(5)
29 #define OWL_SPS_PG_CTL_PWR_CPU3 BIT(6)
30 #define OWL_SPS_PG_CTL_ACK_CPU2 BIT(21)
31 #define OWL_SPS_PG_CTL_ACK_CPU3 BIT(22)
33 static void __iomem *scu_base_addr;
34 static void __iomem *sps_base_addr;
35 static void __iomem *timer_base_addr;
36 static int ncores;
38 static int s500_wakeup_secondary(unsigned int cpu)
40 int ret;
42 if (cpu > 3)
43 return -EINVAL;
45 /* The generic PM domain driver is not available this early. */
46 switch (cpu) {
47 case 2:
48 ret = owl_sps_set_pg(sps_base_addr,
49 OWL_SPS_PG_CTL_PWR_CPU2,
50 OWL_SPS_PG_CTL_ACK_CPU2, true);
51 if (ret)
52 return ret;
53 break;
54 case 3:
55 ret = owl_sps_set_pg(sps_base_addr,
56 OWL_SPS_PG_CTL_PWR_CPU3,
57 OWL_SPS_PG_CTL_ACK_CPU3, true);
58 if (ret)
59 return ret;
60 break;
63 /* wait for CPUx to run to WFE instruction */
64 udelay(200);
66 writel(__pa_symbol(secondary_startup),
67 timer_base_addr + OWL_CPU1_ADDR + (cpu - 1) * 4);
68 writel(OWL_CPUx_FLAG_BOOT,
69 timer_base_addr + OWL_CPU1_FLAG + (cpu - 1) * 4);
71 dsb_sev();
72 mb();
74 return 0;
77 static int s500_smp_boot_secondary(unsigned int cpu, struct task_struct *idle)
79 int ret;
81 ret = s500_wakeup_secondary(cpu);
82 if (ret)
83 return ret;
85 udelay(10);
87 smp_send_reschedule(cpu);
89 writel(0, timer_base_addr + OWL_CPU1_ADDR + (cpu - 1) * 4);
90 writel(0, timer_base_addr + OWL_CPU1_FLAG + (cpu - 1) * 4);
92 return 0;
95 static void __init s500_smp_prepare_cpus(unsigned int max_cpus)
97 struct device_node *node;
99 node = of_find_compatible_node(NULL, NULL, "actions,s500-timer");
100 if (!node) {
101 pr_err("%s: missing timer\n", __func__);
102 return;
105 timer_base_addr = of_iomap(node, 0);
106 if (!timer_base_addr) {
107 pr_err("%s: could not map timer registers\n", __func__);
108 return;
111 node = of_find_compatible_node(NULL, NULL, "actions,s500-sps");
112 if (!node) {
113 pr_err("%s: missing sps\n", __func__);
114 return;
117 sps_base_addr = of_iomap(node, 0);
118 if (!sps_base_addr) {
119 pr_err("%s: could not map sps registers\n", __func__);
120 return;
123 if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9) {
124 node = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
125 if (!node) {
126 pr_err("%s: missing scu\n", __func__);
127 return;
130 scu_base_addr = of_iomap(node, 0);
131 if (!scu_base_addr) {
132 pr_err("%s: could not map scu registers\n", __func__);
133 return;
137 * While the number of cpus is gathered from dt, also get the
138 * number of cores from the scu to verify this value when
139 * booting the cores.
141 ncores = scu_get_core_count(scu_base_addr);
142 pr_debug("%s: ncores %d\n", __func__, ncores);
144 scu_enable(scu_base_addr);
148 static const struct smp_operations s500_smp_ops __initconst = {
149 .smp_prepare_cpus = s500_smp_prepare_cpus,
150 .smp_boot_secondary = s500_smp_boot_secondary,
152 CPU_METHOD_OF_DECLARE(s500_smp, "actions,s500-smp", &s500_smp_ops);