blob: 35921c3ab3948190bbf4b7b82bf617a3080e5c44 [file] [log] [blame]
Vineet Gupta82fea5a2014-09-10 19:05:38 +05301/*
2 * ARC ARConnect (MultiCore IP) support (formerly known as MCIP)
3 *
4 * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com)
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/smp.h>
12#include <linux/irq.h>
13#include <linux/spinlock.h>
14#include <asm/mcip.h>
15
16static char smp_cpuinfo_buf[128];
17
18static DEFINE_RAW_SPINLOCK(mcip_lock);
19
20
21/*
22 * Any SMP specific init any CPU does when it comes up.
23 * Here we setup the CPU to enable Inter-Processor-Interrupts
24 * Called for each CPU
25 * -Master : init_IRQ()
26 * -Other(s) : start_kernel_secondary()
27 */
28void mcip_init_smp(unsigned int cpu)
29{
30 smp_ipi_irq_setup(cpu, IPI_IRQ);
31}
32
33static void mcip_ipi_send(int cpu)
34{
35 unsigned long flags;
Vineet Guptaaa6083e2014-11-07 10:45:28 +053036 int ipi_was_pending;
Vineet Gupta82fea5a2014-09-10 19:05:38 +053037
Vineet Guptaaa6083e2014-11-07 10:45:28 +053038 /*
39 * NOTE: We must spin here if the other cpu hasn't yet
40 * serviced a previous message. This can burn lots
41 * of time, but we MUST follows this protocol or
42 * ipi messages can be lost!!!
43 * Also, we must release the lock in this loop because
44 * the other side may get to this same loop and not
45 * be able to ack -- thus causing deadlock.
46 */
47
48 do {
49 raw_spin_lock_irqsave(&mcip_lock, flags);
50 __mcip_cmd(CMD_INTRPT_READ_STATUS, cpu);
51 ipi_was_pending = read_aux_reg(ARC_REG_MCIP_READBACK);
52 if (ipi_was_pending == 0)
53 break; /* break out but keep lock */
54 raw_spin_unlock_irqrestore(&mcip_lock, flags);
55 } while (1);
56
Vineet Gupta82fea5a2014-09-10 19:05:38 +053057 __mcip_cmd(CMD_INTRPT_GENERATE_IRQ, cpu);
58 raw_spin_unlock_irqrestore(&mcip_lock, flags);
Vineet Guptaaa6083e2014-11-07 10:45:28 +053059
60#ifdef CONFIG_ARC_IPI_DBG
61 if (ipi_was_pending)
62 pr_info("IPI ACK delayed from cpu %d\n", cpu);
63#endif
Vineet Gupta82fea5a2014-09-10 19:05:38 +053064}
65
66static void mcip_ipi_clear(int irq)
67{
Vineet Guptaaa6083e2014-11-07 10:45:28 +053068 unsigned int cpu, c;
Vineet Gupta82fea5a2014-09-10 19:05:38 +053069 unsigned long flags;
Vineet Guptaaa6083e2014-11-07 10:45:28 +053070 unsigned int __maybe_unused copy;
Vineet Gupta82fea5a2014-09-10 19:05:38 +053071
72 raw_spin_lock_irqsave(&mcip_lock, flags);
73
74 /* Who sent the IPI */
75 __mcip_cmd(CMD_INTRPT_CHECK_SOURCE, 0);
76
Vineet Guptaaa6083e2014-11-07 10:45:28 +053077 copy = cpu = read_aux_reg(ARC_REG_MCIP_READBACK); /* 1,2,4,8... */
Vineet Gupta82fea5a2014-09-10 19:05:38 +053078
Vineet Guptaaa6083e2014-11-07 10:45:28 +053079 /*
80 * In rare case, multiple concurrent IPIs sent to same target can
81 * possibly be coalesced by MCIP into 1 asserted IRQ, so @cpus can be
82 * "vectored" (multiple bits sets) as opposed to typical single bit
83 */
84 do {
85 c = __ffs(cpu); /* 0,1,2,3 */
86 __mcip_cmd(CMD_INTRPT_GENERATE_ACK, c);
87 cpu &= ~(1U << c);
88 } while (cpu);
Vineet Gupta82fea5a2014-09-10 19:05:38 +053089
90 raw_spin_unlock_irqrestore(&mcip_lock, flags);
Vineet Guptaaa6083e2014-11-07 10:45:28 +053091
92#ifdef CONFIG_ARC_IPI_DBG
93 if (c != __ffs(copy))
94 pr_info("IPIs from %x coalesced to %x\n",
95 copy, raw_smp_processor_id());
96#endif
Vineet Gupta82fea5a2014-09-10 19:05:38 +053097}
98
99volatile int wake_flag;
100
101static void mcip_wakeup_cpu(int cpu, unsigned long pc)
102{
103 BUG_ON(cpu == 0);
104 wake_flag = cpu;
105}
106
107void arc_platform_smp_wait_to_boot(int cpu)
108{
109 while (wake_flag != cpu)
110 ;
111
112 wake_flag = 0;
113 __asm__ __volatile__("j @first_lines_of_secondary \n");
114}
115
116struct plat_smp_ops plat_smp_ops = {
117 .info = smp_cpuinfo_buf,
118 .cpu_kick = mcip_wakeup_cpu,
119 .ipi_send = mcip_ipi_send,
120 .ipi_clear = mcip_ipi_clear,
121};
122
123void mcip_init_early_smp(void)
124{
125#define IS_AVAIL1(var, str) ((var) ? str : "")
126
127 struct mcip_bcr {
128#ifdef CONFIG_CPU_BIG_ENDIAN
129 unsigned int pad3:8,
130 idu:1, llm:1, num_cores:6,
131 iocoh:1, grtc:1, dbg:1, pad2:1,
132 msg:1, sem:1, ipi:1, pad:1,
133 ver:8;
134#else
135 unsigned int ver:8,
136 pad:1, ipi:1, sem:1, msg:1,
137 pad2:1, dbg:1, grtc:1, iocoh:1,
138 num_cores:6, llm:1, idu:1,
139 pad3:8;
140#endif
141 } mp;
142
143 READ_BCR(ARC_REG_MCIP_BCR, mp);
144
145 sprintf(smp_cpuinfo_buf,
146 "Extn [SMP]\t: ARConnect (v%d): %d cores with %s%s%s%s\n",
147 mp.ver, mp.num_cores,
148 IS_AVAIL1(mp.ipi, "IPI "),
149 IS_AVAIL1(mp.idu, "IDU "),
150 IS_AVAIL1(mp.dbg, "DEBUG "),
151 IS_AVAIL1(mp.grtc, "GRTC"));
152
153 if (mp.dbg) {
154 __mcip_cmd_data(CMD_DEBUG_SET_SELECT, 0, 0xf);
155 __mcip_cmd_data(CMD_DEBUG_SET_MASK, 0xf, 0xf);
156 }
157}