source: mainline/kernel/arch/sparc64/src/smp/sun4u/ipi.c@ 1433ecda

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1433ecda was 1433ecda, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Fix cstyle: make ccheck-fix and commit only files where all the changes are good.

  • Property mode set to 100644
File size: 5.5 KB
RevLine 
[a9ac978]1/*
[df4ed85]2 * Copyright (c) 2006 Jakub Jermar
[a9ac978]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
[1b20da0]29/** @addtogroup sparc64
[a9ac978]30 * @{
31 */
32/** @file
33 */
34
35#include <smp/ipi.h>
[cc106e4]36#include <arch/smp/sun4u/ipi.h>
[63e27ef]37#include <assert.h>
[00b38a3]38#include <cpu.h>
[b3f8fb7]39#include <arch.h>
[00b38a3]40#include <arch/cpu.h>
41#include <arch/asm.h>
42#include <config.h>
43#include <mm/tlb.h>
[cc106e4]44#include <smp/smp_call.h>
[00b38a3]45#include <arch/interrupt.h>
46#include <arch/trap/interrupt.h>
47#include <arch/barrier.h>
48#include <preemption.h>
49#include <time/delay.h>
50#include <panic.h>
[a9ac978]51
[965dc18]52/** Set the contents of the outgoing interrupt vector data.
53 *
54 * The first data item (data 0) will be set to the value of func, the
55 * rest of the vector will contain zeros.
56 *
57 * This is a helper function used from within the cross_call function.
58 *
59 * @param func value the first data item of the vector will be set to
60 */
[1433ecda]61static inline void set_intr_w_data(void (*func)(void))
[965dc18]62{
63#if defined (US)
64 asi_u64_write(ASI_INTR_W, ASI_UDB_INTR_W_DATA_0, (uintptr_t) func);
65 asi_u64_write(ASI_INTR_W, ASI_UDB_INTR_W_DATA_1, 0);
66 asi_u64_write(ASI_INTR_W, ASI_UDB_INTR_W_DATA_2, 0);
67#elif defined (US3)
68 asi_u64_write(ASI_INTR_W, VA_INTR_W_DATA_0, (uintptr_t) func);
69 asi_u64_write(ASI_INTR_W, VA_INTR_W_DATA_1, 0);
70 asi_u64_write(ASI_INTR_W, VA_INTR_W_DATA_2, 0);
71 asi_u64_write(ASI_INTR_W, VA_INTR_W_DATA_3, 0);
72 asi_u64_write(ASI_INTR_W, VA_INTR_W_DATA_4, 0);
73 asi_u64_write(ASI_INTR_W, VA_INTR_W_DATA_5, 0);
74 asi_u64_write(ASI_INTR_W, VA_INTR_W_DATA_6, 0);
75 asi_u64_write(ASI_INTR_W, VA_INTR_W_DATA_7, 0);
76#endif
77}
78
[00b38a3]79/** Invoke function on another processor.
80 *
81 * Currently, only functions without arguments are supported.
82 * Supporting more arguments in the future should be no big deal.
83 *
84 * Interrupts must be disabled prior to this call.
85 *
86 * @param mid MID of the target processor.
87 * @param func Function to be invoked.
88 */
[1433ecda]89static void cross_call(int mid, void (*func)(void))
[00b38a3]90{
91 uint64_t status;
92 bool done;
93
94 /*
[771cd22]95 * This function might enable interrupts for a while.
[00b38a3]96 * In order to prevent migration to another processor,
97 * we explicitly disable preemption.
98 */
[a35b458]99
[00b38a3]100 preemption_disable();
[a35b458]101
[00b38a3]102 status = asi_u64_read(ASI_INTR_DISPATCH_STATUS, 0);
103 if (status & INTR_DISPATCH_STATUS_BUSY)
[95c4776]104 panic("Interrupt Dispatch Status busy bit set\n");
[a35b458]105
[63e27ef]106 assert(!(pstate_read() & PSTATE_IE_BIT));
[a35b458]107
[00b38a3]108 do {
[965dc18]109 set_intr_w_data(func);
110 asi_u64_write(ASI_INTR_W,
[454f1da]111 (mid << INTR_VEC_DISPATCH_MID_SHIFT) |
[965dc18]112 VA_INTR_W_DISPATCH, 0);
[a35b458]113
[00b38a3]114 membar();
[a35b458]115
[00b38a3]116 do {
117 status = asi_u64_read(ASI_INTR_DISPATCH_STATUS, 0);
118 } while (status & INTR_DISPATCH_STATUS_BUSY);
[a35b458]119
[00b38a3]120 done = !(status & INTR_DISPATCH_STATUS_NACK);
121 if (!done) {
122 /*
123 * Prevent deadlock.
[1b20da0]124 */
[00b38a3]125 (void) interrupts_enable();
126 delay(20 + (tick_read() & 0xff));
127 (void) interrupts_disable();
128 }
[bb4c9fca]129 } while (!done);
[a35b458]130
[00b38a3]131 preemption_enable();
132}
133
134/*
135 * Deliver IPI to all processors except the current one.
136 *
137 * The sparc64 architecture does not support any group addressing
138 * which is found, for instance, on ia32 and amd64. Therefore we
139 * need to simulate the broadcast by sending the message to
140 * all target processors step by step.
141 *
142 * We assume that interrupts are disabled.
143 *
144 * @param ipi IPI number.
145 */
[a9ac978]146void ipi_broadcast_arch(int ipi)
147{
[6c441cf8]148 unsigned int i;
[a35b458]149
[1433ecda]150 void (*func)(void);
[a35b458]151
[00b38a3]152 switch (ipi) {
153 case IPI_TLB_SHOOTDOWN:
154 func = tlb_shootdown_ipi_recv;
155 break;
156 default:
[95c4776]157 panic("Unknown IPI (%d).\n", ipi);
[00b38a3]158 break;
159 }
[a35b458]160
[00b38a3]161 /*
162 * As long as we don't support hot-plugging
163 * or hot-unplugging of CPUs, we can walk
164 * the cpus array and read processor's MID
165 * without locking.
166 */
[a35b458]167
[00b38a3]168 for (i = 0; i < config.cpu_active; i++) {
169 if (&cpus[i] == CPU)
170 continue; /* skip the current CPU */
171
172 cross_call(cpus[i].arch.mid, func);
173 }
[a9ac978]174}
175
[cc106e4]176
177/*
178 * Deliver an IPI to the specified processors (except the current one).
179 *
180 * Interrupts must be disabled.
181 *
[1b20da0]182 * @param cpu_id Destination cpu id (index into cpus array). Must not
[cc106e4]183 * be the current cpu.
184 * @param ipi IPI number.
185 */
186void ipi_unicast_arch(unsigned int cpu_id, int ipi)
187{
[63e27ef]188 assert(&cpus[cpu_id] != CPU);
[a35b458]189
[cc106e4]190 if (ipi == IPI_SMP_CALL) {
191 cross_call(cpus[cpu_id].arch.mid, smp_call_ipi_recv);
192 } else {
193 panic("Unknown IPI (%d).\n", ipi);
194 return;
195 }
196}
197
[a9ac978]198/** @}
199 */
Note: See TracBrowser for help on using the repository browser.