Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 1 | /* |
| 2 | * SH-X3 SMP |
| 3 | * |
Paul Mundt | 3366e35 | 2010-03-30 12:38:01 +0900 | [diff] [blame] | 4 | * Copyright (C) 2007 - 2010 Paul Mundt |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 5 | * Copyright (C) 2007 Magnus Damm |
| 6 | * |
| 7 | * This file is subject to the terms and conditions of the GNU General Public |
| 8 | * License. See the file "COPYING" in the main directory of this archive |
| 9 | * for more details. |
| 10 | */ |
| 11 | #include <linux/init.h> |
Paul Mundt | e7dc951 | 2010-04-26 19:09:57 +0900 | [diff] [blame] | 12 | #include <linux/kernel.h> |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 13 | #include <linux/cpumask.h> |
| 14 | #include <linux/smp.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/io.h> |
Paul Mundt | e7dc951 | 2010-04-26 19:09:57 +0900 | [diff] [blame] | 17 | #include <linux/sched.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/cpu.h> |
| 20 | #include <asm/sections.h> |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 21 | |
Paul Mundt | 94eab0b | 2009-10-16 17:19:08 +0900 | [diff] [blame] | 22 | #define STBCR_REG(phys_id) (0xfe400004 | (phys_id << 12)) |
| 23 | #define RESET_REG(phys_id) (0xfe400008 | (phys_id << 12)) |
| 24 | |
| 25 | #define STBCR_MSTP 0x00000001 |
| 26 | #define STBCR_RESET 0x00000002 |
Paul Mundt | e7dc951 | 2010-04-26 19:09:57 +0900 | [diff] [blame] | 27 | #define STBCR_SLEEP 0x00000004 |
Paul Mundt | 94eab0b | 2009-10-16 17:19:08 +0900 | [diff] [blame] | 28 | #define STBCR_LTSLP 0x80000000 |
| 29 | |
Paul Mundt | c7936b9 | 2008-08-06 18:05:09 +0900 | [diff] [blame] | 30 | static irqreturn_t ipi_interrupt_handler(int irq, void *arg) |
| 31 | { |
| 32 | unsigned int message = (unsigned int)(long)arg; |
| 33 | unsigned int cpu = hard_smp_processor_id(); |
| 34 | unsigned int offs = 4 * cpu; |
| 35 | unsigned int x; |
| 36 | |
Paul Mundt | 94eab0b | 2009-10-16 17:19:08 +0900 | [diff] [blame] | 37 | x = __raw_readl(0xfe410070 + offs); /* C0INITICI..CnINTICI */ |
Paul Mundt | c7936b9 | 2008-08-06 18:05:09 +0900 | [diff] [blame] | 38 | x &= (1 << (message << 2)); |
Paul Mundt | 94eab0b | 2009-10-16 17:19:08 +0900 | [diff] [blame] | 39 | __raw_writel(x, 0xfe410080 + offs); /* C0INTICICLR..CnINTICICLR */ |
Paul Mundt | c7936b9 | 2008-08-06 18:05:09 +0900 | [diff] [blame] | 40 | |
| 41 | smp_message_recv(message); |
| 42 | |
| 43 | return IRQ_HANDLED; |
| 44 | } |
| 45 | |
Paul Mundt | 3366e35 | 2010-03-30 12:38:01 +0900 | [diff] [blame] | 46 | static void shx3_smp_setup(void) |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 47 | { |
| 48 | unsigned int cpu = 0; |
| 49 | int i, num; |
| 50 | |
Rusty Russell | e09377b | 2009-06-12 22:33:14 +0930 | [diff] [blame] | 51 | init_cpu_possible(cpumask_of(cpu)); |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 52 | |
Paul Mundt | 94eab0b | 2009-10-16 17:19:08 +0900 | [diff] [blame] | 53 | /* Enable light sleep for the boot CPU */ |
| 54 | __raw_writel(__raw_readl(STBCR_REG(cpu)) | STBCR_LTSLP, STBCR_REG(cpu)); |
| 55 | |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 56 | __cpu_number_map[0] = 0; |
| 57 | __cpu_logical_map[0] = 0; |
| 58 | |
| 59 | /* |
| 60 | * Do this stupidly for now.. we don't have an easy way to probe |
| 61 | * for the total number of cores. |
| 62 | */ |
| 63 | for (i = 1, num = 0; i < NR_CPUS; i++) { |
Rusty Russell | e09377b | 2009-06-12 22:33:14 +0930 | [diff] [blame] | 64 | set_cpu_possible(i, true); |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 65 | __cpu_number_map[i] = ++num; |
| 66 | __cpu_logical_map[num] = i; |
| 67 | } |
| 68 | |
| 69 | printk(KERN_INFO "Detected %i available secondary CPU(s)\n", num); |
| 70 | } |
| 71 | |
Paul Mundt | 3366e35 | 2010-03-30 12:38:01 +0900 | [diff] [blame] | 72 | static void shx3_prepare_cpus(unsigned int max_cpus) |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 73 | { |
Paul Mundt | c7936b9 | 2008-08-06 18:05:09 +0900 | [diff] [blame] | 74 | int i; |
| 75 | |
| 76 | BUILD_BUG_ON(SMP_MSG_NR >= 8); |
| 77 | |
| 78 | for (i = 0; i < SMP_MSG_NR; i++) |
Paul Mundt | fecf066 | 2010-04-15 11:59:28 +0900 | [diff] [blame] | 79 | request_irq(104 + i, ipi_interrupt_handler, |
Yong Zhang | d11584a | 2011-10-22 17:56:28 +0800 | [diff] [blame] | 80 | IRQF_PERCPU, "IPI", (void *)(long)i); |
Paul Mundt | 7acb59e | 2010-04-26 18:44:04 +0900 | [diff] [blame] | 81 | |
| 82 | for (i = 0; i < max_cpus; i++) |
| 83 | set_cpu_present(i, true); |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 84 | } |
| 85 | |
Paul Mundt | 3366e35 | 2010-03-30 12:38:01 +0900 | [diff] [blame] | 86 | static void shx3_start_cpu(unsigned int cpu, unsigned long entry_point) |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 87 | { |
Paul Mundt | f0cb773 | 2010-01-15 15:13:48 +0900 | [diff] [blame] | 88 | if (__in_29bit_mode()) |
| 89 | __raw_writel(entry_point, RESET_REG(cpu)); |
| 90 | else |
| 91 | __raw_writel(virt_to_phys(entry_point), RESET_REG(cpu)); |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 92 | |
Paul Mundt | 94eab0b | 2009-10-16 17:19:08 +0900 | [diff] [blame] | 93 | if (!(__raw_readl(STBCR_REG(cpu)) & STBCR_MSTP)) |
| 94 | __raw_writel(STBCR_MSTP, STBCR_REG(cpu)); |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 95 | |
Paul Mundt | 94eab0b | 2009-10-16 17:19:08 +0900 | [diff] [blame] | 96 | while (!(__raw_readl(STBCR_REG(cpu)) & STBCR_MSTP)) |
Paul Mundt | 71f0bdc | 2008-08-06 18:39:32 +0900 | [diff] [blame] | 97 | cpu_relax(); |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 98 | |
| 99 | /* Start up secondary processor by sending a reset */ |
Paul Mundt | 94eab0b | 2009-10-16 17:19:08 +0900 | [diff] [blame] | 100 | __raw_writel(STBCR_RESET | STBCR_LTSLP, STBCR_REG(cpu)); |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 101 | } |
| 102 | |
Paul Mundt | 3366e35 | 2010-03-30 12:38:01 +0900 | [diff] [blame] | 103 | static unsigned int shx3_smp_processor_id(void) |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 104 | { |
Paul Mundt | 94eab0b | 2009-10-16 17:19:08 +0900 | [diff] [blame] | 105 | return __raw_readl(0xff000048); /* CPIDR */ |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 106 | } |
| 107 | |
Paul Mundt | 3366e35 | 2010-03-30 12:38:01 +0900 | [diff] [blame] | 108 | static void shx3_send_ipi(unsigned int cpu, unsigned int message) |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 109 | { |
| 110 | unsigned long addr = 0xfe410070 + (cpu * 4); |
| 111 | |
| 112 | BUG_ON(cpu >= 4); |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 113 | |
Paul Mundt | 94eab0b | 2009-10-16 17:19:08 +0900 | [diff] [blame] | 114 | __raw_writel(1 << (message << 2), addr); /* C0INTICI..CnINTICI */ |
Paul Mundt | 1a442fe | 2007-09-21 19:16:05 +0900 | [diff] [blame] | 115 | } |
Paul Mundt | 3366e35 | 2010-03-30 12:38:01 +0900 | [diff] [blame] | 116 | |
Paul Mundt | e7dc951 | 2010-04-26 19:09:57 +0900 | [diff] [blame] | 117 | static void shx3_update_boot_vector(unsigned int cpu) |
| 118 | { |
| 119 | __raw_writel(STBCR_MSTP, STBCR_REG(cpu)); |
| 120 | while (!(__raw_readl(STBCR_REG(cpu)) & STBCR_MSTP)) |
| 121 | cpu_relax(); |
| 122 | __raw_writel(STBCR_RESET, STBCR_REG(cpu)); |
| 123 | } |
| 124 | |
Sebastian Andrzej Siewior | 5153323 | 2016-09-06 19:04:41 +0200 | [diff] [blame^] | 125 | static int shx3_cpu_prepare(unsigned int cpu) |
Paul Mundt | e7dc951 | 2010-04-26 19:09:57 +0900 | [diff] [blame] | 126 | { |
Sebastian Andrzej Siewior | 5153323 | 2016-09-06 19:04:41 +0200 | [diff] [blame^] | 127 | shx3_update_boot_vector(cpu); |
| 128 | return 0; |
Paul Mundt | e7dc951 | 2010-04-26 19:09:57 +0900 | [diff] [blame] | 129 | } |
| 130 | |
Paul Gortmaker | 4603f53 | 2013-06-18 17:10:12 -0400 | [diff] [blame] | 131 | static int register_shx3_cpu_notifier(void) |
Paul Mundt | e7dc951 | 2010-04-26 19:09:57 +0900 | [diff] [blame] | 132 | { |
Sebastian Andrzej Siewior | 5153323 | 2016-09-06 19:04:41 +0200 | [diff] [blame^] | 133 | cpuhp_setup_state_nocalls(CPUHP_SH_SH3X_PREPARE, "sh/shx3:prepare", |
| 134 | shx3_cpu_prepare, NULL); |
Paul Mundt | e7dc951 | 2010-04-26 19:09:57 +0900 | [diff] [blame] | 135 | return 0; |
| 136 | } |
| 137 | late_initcall(register_shx3_cpu_notifier); |
| 138 | |
Paul Mundt | 3366e35 | 2010-03-30 12:38:01 +0900 | [diff] [blame] | 139 | struct plat_smp_ops shx3_smp_ops = { |
| 140 | .smp_setup = shx3_smp_setup, |
| 141 | .prepare_cpus = shx3_prepare_cpus, |
| 142 | .start_cpu = shx3_start_cpu, |
| 143 | .smp_processor_id = shx3_smp_processor_id, |
| 144 | .send_ipi = shx3_send_ipi, |
Paul Mundt | e7dc951 | 2010-04-26 19:09:57 +0900 | [diff] [blame] | 145 | .cpu_die = native_cpu_die, |
| 146 | .cpu_disable = native_cpu_disable, |
| 147 | .play_dead = native_play_dead, |
Paul Mundt | 3366e35 | 2010-03-30 12:38:01 +0900 | [diff] [blame] | 148 | }; |