]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 | 2 | * Copyright (C) 2001 Mike Corrigan IBM Corporation |
38fcdcfe | 3 | * |
1da177e4 LT |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | */ | |
9 | ||
10 | #include <linux/stddef.h> | |
11 | #include <linux/kernel.h> | |
12 | #include <linux/sched.h> | |
512d31d6 | 13 | #include <linux/bootmem.h> |
7b01328d ME |
14 | #include <linux/seq_file.h> |
15 | #include <linux/proc_fs.h> | |
cabb5587 SR |
16 | #include <linux/module.h> |
17 | ||
1da177e4 LT |
18 | #include <asm/system.h> |
19 | #include <asm/paca.h> | |
8875ccfb | 20 | #include <asm/iseries/it_lp_queue.h> |
e45423ea | 21 | #include <asm/iseries/hv_lp_event.h> |
c0a8d05c | 22 | #include <asm/iseries/hv_call_event.h> |
f218aab5 | 23 | #include <asm/iseries/it_lp_naca.h> |
1da177e4 | 24 | |
ab354b63 ME |
25 | /* |
26 | * The LpQueue is used to pass event data from the hypervisor to | |
27 | * the partition. This is where I/O interrupt events are communicated. | |
28 | * | |
29 | * It is written to by the hypervisor so cannot end up in the BSS. | |
30 | */ | |
a6187464 | 31 | struct hvlpevent_queue hvlpevent_queue __attribute__((__section__(".data"))); |
ab354b63 | 32 | |
ed094150 ME |
33 | DEFINE_PER_CPU(unsigned long[HvLpEvent_Type_NumTypes], hvlpevent_counts); |
34 | ||
35 | static char *event_types[HvLpEvent_Type_NumTypes] = { | |
9b047020 ME |
36 | "Hypervisor", |
37 | "Machine Facilities", | |
38 | "Session Manager", | |
39 | "SPD I/O", | |
40 | "Virtual Bus", | |
41 | "PCI I/O", | |
42 | "RIO I/O", | |
43 | "Virtual Lan", | |
44 | "Virtual I/O" | |
7b01328d ME |
45 | }; |
46 | ||
1da177e4 | 47 | /* Array of LpEvent handler functions */ |
544cbbae SR |
48 | static LpEventHandler lpEventHandler[HvLpEvent_Type_NumTypes]; |
49 | static unsigned lpEventHandlerPaths[HvLpEvent_Type_NumTypes]; | |
1da177e4 | 50 | |
937b31b1 | 51 | static struct HvLpEvent * get_next_hvlpevent(void) |
1da177e4 | 52 | { |
ffe1b7e1 ME |
53 | struct HvLpEvent * event; |
54 | event = (struct HvLpEvent *)hvlpevent_queue.xSlicCurEventPtr; | |
55 | ||
677f8c0d | 56 | if (hvlpevent_is_valid(event)) { |
1da177e4 LT |
57 | /* rmb() needed only for weakly consistent machines (regatta) */ |
58 | rmb(); | |
59 | /* Set pointer to next potential event */ | |
ffe1b7e1 ME |
60 | hvlpevent_queue.xSlicCurEventPtr += ((event->xSizeMinus1 + |
61 | LpEventAlign) / LpEventAlign) * LpEventAlign; | |
62 | ||
1da177e4 | 63 | /* Wrap to beginning if no room at end */ |
ffe1b7e1 ME |
64 | if (hvlpevent_queue.xSlicCurEventPtr > |
65 | hvlpevent_queue.xSlicLastValidEventPtr) { | |
66 | hvlpevent_queue.xSlicCurEventPtr = | |
67 | hvlpevent_queue.xSlicEventStackPtr; | |
68 | } | |
69 | } else { | |
70 | event = NULL; | |
1da177e4 | 71 | } |
1da177e4 | 72 | |
ffe1b7e1 | 73 | return event; |
1da177e4 LT |
74 | } |
75 | ||
0c885c17 | 76 | static unsigned long spread_lpevents = NR_CPUS; |
bea248fb | 77 | |
937b31b1 | 78 | int hvlpevent_is_pending(void) |
1da177e4 | 79 | { |
bea248fb ME |
80 | struct HvLpEvent *next_event; |
81 | ||
82 | if (smp_processor_id() >= spread_lpevents) | |
83 | return 0; | |
84 | ||
a6187464 | 85 | next_event = (struct HvLpEvent *)hvlpevent_queue.xSlicCurEventPtr; |
ffe1b7e1 | 86 | |
677f8c0d | 87 | return hvlpevent_is_valid(next_event) || |
ffe1b7e1 | 88 | hvlpevent_queue.xPlicOverflowIntPending; |
1da177e4 LT |
89 | } |
90 | ||
38fcdcfe | 91 | static void hvlpevent_clear_valid(struct HvLpEvent * event) |
1da177e4 | 92 | { |
ffe1b7e1 ME |
93 | /* Tell the Hypervisor that we're done with this event. |
94 | * Also clear bits within this event that might look like valid bits. | |
95 | * ie. on 64-byte boundaries. | |
38fcdcfe | 96 | */ |
ffe1b7e1 | 97 | struct HvLpEvent *tmp; |
38fcdcfe ME |
98 | unsigned extra = ((event->xSizeMinus1 + LpEventAlign) / |
99 | LpEventAlign) - 1; | |
ffe1b7e1 | 100 | |
38fcdcfe ME |
101 | switch (extra) { |
102 | case 3: | |
ffe1b7e1 | 103 | tmp = (struct HvLpEvent*)((char*)event + 3 * LpEventAlign); |
677f8c0d | 104 | hvlpevent_invalidate(tmp); |
38fcdcfe | 105 | case 2: |
ffe1b7e1 | 106 | tmp = (struct HvLpEvent*)((char*)event + 2 * LpEventAlign); |
677f8c0d | 107 | hvlpevent_invalidate(tmp); |
38fcdcfe | 108 | case 1: |
ffe1b7e1 | 109 | tmp = (struct HvLpEvent*)((char*)event + 1 * LpEventAlign); |
677f8c0d | 110 | hvlpevent_invalidate(tmp); |
1da177e4 | 111 | } |
ffe1b7e1 | 112 | |
1da177e4 | 113 | mb(); |
ffe1b7e1 | 114 | |
677f8c0d | 115 | hvlpevent_invalidate(event); |
1da177e4 LT |
116 | } |
117 | ||
74889802 | 118 | void process_hvlpevents(struct pt_regs *regs) |
1da177e4 | 119 | { |
ffe1b7e1 | 120 | struct HvLpEvent * event; |
1da177e4 LT |
121 | |
122 | /* If we have recursed, just return */ | |
719d1cd8 | 123 | if (!spin_trylock(&hvlpevent_queue.lock)) |
74889802 | 124 | return; |
38fcdcfe | 125 | |
1da177e4 | 126 | for (;;) { |
ffe1b7e1 ME |
127 | event = get_next_hvlpevent(); |
128 | if (event) { | |
38fcdcfe | 129 | /* Call appropriate handler here, passing |
1da177e4 LT |
130 | * a pointer to the LpEvent. The handler |
131 | * must make a copy of the LpEvent if it | |
132 | * needs it in a bottom half. (perhaps for | |
133 | * an ACK) | |
38fcdcfe ME |
134 | * |
135 | * Handlers are responsible for ACK processing | |
1da177e4 LT |
136 | * |
137 | * The Hypervisor guarantees that LpEvents will | |
138 | * only be delivered with types that we have | |
139 | * registered for, so no type check is necessary | |
140 | * here! | |
38fcdcfe | 141 | */ |
ffe1b7e1 ME |
142 | if (event->xType < HvLpEvent_Type_NumTypes) |
143 | __get_cpu_var(hvlpevent_counts)[event->xType]++; | |
144 | if (event->xType < HvLpEvent_Type_NumTypes && | |
145 | lpEventHandler[event->xType]) | |
146 | lpEventHandler[event->xType](event, regs); | |
1da177e4 | 147 | else |
ffe1b7e1 | 148 | printk(KERN_INFO "Unexpected Lp Event type=%d\n", event->xType ); |
38fcdcfe | 149 | |
ffe1b7e1 | 150 | hvlpevent_clear_valid(event); |
38fcdcfe | 151 | } else if (hvlpevent_queue.xPlicOverflowIntPending) |
1da177e4 LT |
152 | /* |
153 | * No more valid events. If overflow events are | |
154 | * pending process them | |
155 | */ | |
38fcdcfe | 156 | HvCallEvent_getOverflowLpEvents(hvlpevent_queue.xIndex); |
1da177e4 LT |
157 | else |
158 | break; | |
159 | } | |
160 | ||
719d1cd8 | 161 | spin_unlock(&hvlpevent_queue.lock); |
1da177e4 | 162 | } |
0c885c17 ME |
163 | |
164 | static int set_spread_lpevents(char *str) | |
165 | { | |
166 | unsigned long val = simple_strtoul(str, NULL, 0); | |
167 | ||
168 | /* | |
169 | * The parameter is the number of processors to share in processing | |
170 | * lp events. | |
171 | */ | |
172 | if (( val > 0) && (val <= NR_CPUS)) { | |
173 | spread_lpevents = val; | |
174 | printk("lpevent processing spread over %ld processors\n", val); | |
175 | } else { | |
176 | printk("invalid spread_lpevents %ld\n", val); | |
177 | } | |
178 | ||
179 | return 1; | |
180 | } | |
181 | __setup("spread_lpevents=", set_spread_lpevents); | |
182 | ||
512d31d6 ME |
183 | void setup_hvlpevent_queue(void) |
184 | { | |
185 | void *eventStack; | |
186 | ||
bd6ef57e ME |
187 | spin_lock_init(&hvlpevent_queue.lock); |
188 | ||
7c7eb284 | 189 | /* Allocate a page for the Event Stack. */ |
512d31d6 ME |
190 | eventStack = alloc_bootmem_pages(LpEventStackSize); |
191 | memset(eventStack, 0, LpEventStackSize); | |
192 | ||
193 | /* Invoke the hypervisor to initialize the event stack */ | |
194 | HvCallEvent_setLpEventStack(0, eventStack, LpEventStackSize); | |
195 | ||
a6187464 ME |
196 | hvlpevent_queue.xSlicEventStackPtr = (char *)eventStack; |
197 | hvlpevent_queue.xSlicCurEventPtr = (char *)eventStack; | |
198 | hvlpevent_queue.xSlicLastValidEventPtr = (char *)eventStack + | |
512d31d6 | 199 | (LpEventStackSize - LpEventMaxSize); |
a6187464 | 200 | hvlpevent_queue.xIndex = 0; |
512d31d6 | 201 | } |
7b01328d | 202 | |
544cbbae SR |
203 | /* Register a handler for an LpEvent type */ |
204 | int HvLpEvent_registerHandler(HvLpEvent_Type eventType, LpEventHandler handler) | |
205 | { | |
206 | if (eventType < HvLpEvent_Type_NumTypes) { | |
207 | lpEventHandler[eventType] = handler; | |
208 | return 0; | |
209 | } | |
210 | return 1; | |
211 | } | |
212 | EXPORT_SYMBOL(HvLpEvent_registerHandler); | |
213 | ||
214 | int HvLpEvent_unregisterHandler(HvLpEvent_Type eventType) | |
215 | { | |
216 | might_sleep(); | |
217 | ||
218 | if (eventType < HvLpEvent_Type_NumTypes) { | |
219 | if (!lpEventHandlerPaths[eventType]) { | |
220 | lpEventHandler[eventType] = NULL; | |
221 | /* | |
222 | * We now sleep until all other CPUs have scheduled. | |
223 | * This ensures that the deletion is seen by all | |
224 | * other CPUs, and that the deleted handler isn't | |
225 | * still running on another CPU when we return. | |
226 | */ | |
227 | synchronize_rcu(); | |
228 | return 0; | |
229 | } | |
230 | } | |
231 | return 1; | |
232 | } | |
233 | EXPORT_SYMBOL(HvLpEvent_unregisterHandler); | |
234 | ||
235 | /* | |
236 | * lpIndex is the partition index of the target partition. | |
237 | * needed only for VirtualIo, VirtualLan and SessionMgr. Zero | |
238 | * indicates to use our partition index - for the other types. | |
239 | */ | |
240 | int HvLpEvent_openPath(HvLpEvent_Type eventType, HvLpIndex lpIndex) | |
241 | { | |
242 | if ((eventType < HvLpEvent_Type_NumTypes) && | |
243 | lpEventHandler[eventType]) { | |
244 | if (lpIndex == 0) | |
245 | lpIndex = itLpNaca.xLpIndex; | |
246 | HvCallEvent_openLpEventPath(lpIndex, eventType); | |
247 | ++lpEventHandlerPaths[eventType]; | |
248 | return 0; | |
249 | } | |
250 | return 1; | |
251 | } | |
252 | ||
253 | int HvLpEvent_closePath(HvLpEvent_Type eventType, HvLpIndex lpIndex) | |
254 | { | |
255 | if ((eventType < HvLpEvent_Type_NumTypes) && | |
256 | lpEventHandler[eventType] && | |
257 | lpEventHandlerPaths[eventType]) { | |
258 | if (lpIndex == 0) | |
259 | lpIndex = itLpNaca.xLpIndex; | |
260 | HvCallEvent_closeLpEventPath(lpIndex, eventType); | |
261 | --lpEventHandlerPaths[eventType]; | |
262 | return 0; | |
263 | } | |
264 | return 1; | |
265 | } | |
266 | ||
7b01328d ME |
267 | static int proc_lpevents_show(struct seq_file *m, void *v) |
268 | { | |
ed094150 ME |
269 | int cpu, i; |
270 | unsigned long sum; | |
271 | static unsigned long cpu_totals[NR_CPUS]; | |
272 | ||
273 | /* FIXME: do we care that there's no locking here? */ | |
274 | sum = 0; | |
275 | for_each_online_cpu(cpu) { | |
276 | cpu_totals[cpu] = 0; | |
277 | for (i = 0; i < HvLpEvent_Type_NumTypes; i++) { | |
278 | cpu_totals[cpu] += per_cpu(hvlpevent_counts, cpu)[i]; | |
279 | } | |
280 | sum += cpu_totals[cpu]; | |
281 | } | |
7b01328d ME |
282 | |
283 | seq_printf(m, "LpEventQueue 0\n"); | |
ed094150 | 284 | seq_printf(m, " events processed:\t%lu\n", sum); |
7b01328d | 285 | |
ed094150 ME |
286 | for (i = 0; i < HvLpEvent_Type_NumTypes; ++i) { |
287 | sum = 0; | |
288 | for_each_online_cpu(cpu) { | |
289 | sum += per_cpu(hvlpevent_counts, cpu)[i]; | |
290 | } | |
291 | ||
9b047020 | 292 | seq_printf(m, " %-20s %10lu\n", event_types[i], sum); |
ed094150 | 293 | } |
7b01328d ME |
294 | |
295 | seq_printf(m, "\n events processed by processor:\n"); | |
296 | ||
ed094150 ME |
297 | for_each_online_cpu(cpu) { |
298 | seq_printf(m, " CPU%02d %10lu\n", cpu, cpu_totals[cpu]); | |
299 | } | |
7b01328d ME |
300 | |
301 | return 0; | |
302 | } | |
303 | ||
304 | static int proc_lpevents_open(struct inode *inode, struct file *file) | |
305 | { | |
306 | return single_open(file, proc_lpevents_show, NULL); | |
307 | } | |
308 | ||
309 | static struct file_operations proc_lpevents_operations = { | |
310 | .open = proc_lpevents_open, | |
311 | .read = seq_read, | |
312 | .llseek = seq_lseek, | |
313 | .release = single_release, | |
314 | }; | |
315 | ||
316 | static int __init proc_lpevents_init(void) | |
317 | { | |
318 | struct proc_dir_entry *e; | |
319 | ||
320 | e = create_proc_entry("iSeries/lpevents", S_IFREG|S_IRUGO, NULL); | |
321 | if (e) | |
322 | e->proc_fops = &proc_lpevents_operations; | |
323 | ||
324 | return 0; | |
325 | } | |
326 | __initcall(proc_lpevents_init); | |
327 |