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