3 * Copyright (C) 2001 Mike Corrigan IBM Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
11 #include <linux/stddef.h>
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include <linux/bootmem.h>
15 #include <linux/seq_file.h>
16 #include <linux/proc_fs.h>
17 #include <asm/system.h>
19 #include <asm/iSeries/ItLpQueue.h>
20 #include <asm/iSeries/HvLpEvent.h>
21 #include <asm/iSeries/HvCallEvent.h>
24 * The LpQueue is used to pass event data from the hypervisor to
25 * the partition. This is where I/O interrupt events are communicated.
27 * It is written to by the hypervisor so cannot end up in the BSS.
29 struct hvlpevent_queue hvlpevent_queue __attribute__((__section__(".data")));
31 static char *event_types[9] = {
33 "Machine Facilities\t",
43 static __inline__ int set_inUse(void)
46 u32 * inUseP = &hvlpevent_queue.xInUseWord;
48 __asm__ __volatile__("\n\
57 : "=&r" (t), "=m" (hvlpevent_queue.xInUseWord)
58 : "r" (inUseP), "m" (hvlpevent_queue.xInUseWord)
64 static __inline__ void clear_inUse(void)
66 hvlpevent_queue.xInUseWord = 0;
69 /* Array of LpEvent handler functions */
70 extern LpEventHandler lpEventHandler[HvLpEvent_Type_NumTypes];
71 unsigned long ItLpQueueInProcess = 0;
73 static struct HvLpEvent * get_next_hvlpevent(void)
75 struct HvLpEvent * nextLpEvent =
76 (struct HvLpEvent *)hvlpevent_queue.xSlicCurEventPtr;
77 if ( nextLpEvent->xFlags.xValid ) {
78 /* rmb() needed only for weakly consistent machines (regatta) */
80 /* Set pointer to next potential event */
81 hvlpevent_queue.xSlicCurEventPtr += ((nextLpEvent->xSizeMinus1 +
85 /* Wrap to beginning if no room at end */
86 if (hvlpevent_queue.xSlicCurEventPtr > hvlpevent_queue.xSlicLastValidEventPtr)
87 hvlpevent_queue.xSlicCurEventPtr = hvlpevent_queue.xSlicEventStackPtr;
95 static unsigned long spread_lpevents = NR_CPUS;
97 int hvlpevent_is_pending(void)
99 struct HvLpEvent *next_event;
101 if (smp_processor_id() >= spread_lpevents)
104 next_event = (struct HvLpEvent *)hvlpevent_queue.xSlicCurEventPtr;
105 return next_event->xFlags.xValid | hvlpevent_queue.xPlicOverflowIntPending;
108 static void hvlpevent_clear_valid( struct HvLpEvent * event )
110 /* Clear the valid bit of the event
111 * Also clear bits within this event that might
112 * look like valid bits (on 64-byte boundaries)
114 unsigned extra = (( event->xSizeMinus1 + LpEventAlign ) /
118 ((struct HvLpEvent*)((char*)event+3*LpEventAlign))->xFlags.xValid=0;
120 ((struct HvLpEvent*)((char*)event+2*LpEventAlign))->xFlags.xValid=0;
122 ((struct HvLpEvent*)((char*)event+1*LpEventAlign))->xFlags.xValid=0;
127 event->xFlags.xValid = 0;
130 void process_hvlpevents(struct pt_regs *regs)
132 unsigned numIntsProcessed = 0;
133 struct HvLpEvent * nextLpEvent;
135 /* If we have recursed, just return */
139 if (ItLpQueueInProcess == 0)
140 ItLpQueueInProcess = 1;
145 nextLpEvent = get_next_hvlpevent();
148 hvlpevent_queue.xLpIntCount++;
149 /* Call appropriate handler here, passing
150 * a pointer to the LpEvent. The handler
151 * must make a copy of the LpEvent if it
152 * needs it in a bottom half. (perhaps for
155 * Handlers are responsible for ACK processing
157 * The Hypervisor guarantees that LpEvents will
158 * only be delivered with types that we have
159 * registered for, so no type check is necessary
162 if ( nextLpEvent->xType < HvLpEvent_Type_NumTypes )
163 hvlpevent_queue.xLpIntCountByType[nextLpEvent->xType]++;
164 if ( nextLpEvent->xType < HvLpEvent_Type_NumTypes &&
165 lpEventHandler[nextLpEvent->xType] )
166 lpEventHandler[nextLpEvent->xType](nextLpEvent, regs);
168 printk(KERN_INFO "Unexpected Lp Event type=%d\n", nextLpEvent->xType );
170 hvlpevent_clear_valid( nextLpEvent );
171 } else if ( hvlpevent_queue.xPlicOverflowIntPending )
173 * No more valid events. If overflow events are
174 * pending process them
176 HvCallEvent_getOverflowLpEvents( hvlpevent_queue.xIndex);
181 ItLpQueueInProcess = 0;
185 get_paca()->lpevent_count += numIntsProcessed;
188 static int set_spread_lpevents(char *str)
190 unsigned long val = simple_strtoul(str, NULL, 0);
193 * The parameter is the number of processors to share in processing
196 if (( val > 0) && (val <= NR_CPUS)) {
197 spread_lpevents = val;
198 printk("lpevent processing spread over %ld processors\n", val);
200 printk("invalid spread_lpevents %ld\n", val);
205 __setup("spread_lpevents=", set_spread_lpevents);
207 void setup_hvlpevent_queue(void)
212 * Allocate a page for the Event Stack. The Hypervisor needs the
213 * absolute real address, so we subtract out the KERNELBASE and add
214 * in the absolute real address of the kernel load area.
216 eventStack = alloc_bootmem_pages(LpEventStackSize);
217 memset(eventStack, 0, LpEventStackSize);
219 /* Invoke the hypervisor to initialize the event stack */
220 HvCallEvent_setLpEventStack(0, eventStack, LpEventStackSize);
222 hvlpevent_queue.xSlicEventStackPtr = (char *)eventStack;
223 hvlpevent_queue.xSlicCurEventPtr = (char *)eventStack;
224 hvlpevent_queue.xSlicLastValidEventPtr = (char *)eventStack +
225 (LpEventStackSize - LpEventMaxSize);
226 hvlpevent_queue.xIndex = 0;
229 static int proc_lpevents_show(struct seq_file *m, void *v)
233 seq_printf(m, "LpEventQueue 0\n");
234 seq_printf(m, " events processed:\t%lu\n",
235 (unsigned long)hvlpevent_queue.xLpIntCount);
237 for (i = 0; i < 9; ++i)
238 seq_printf(m, " %s %10lu\n", event_types[i],
239 (unsigned long)hvlpevent_queue.xLpIntCountByType[i]);
241 seq_printf(m, "\n events processed by processor:\n");
243 for_each_online_cpu(i)
244 seq_printf(m, " CPU%02d %10u\n", i, paca[i].lpevent_count);
249 static int proc_lpevents_open(struct inode *inode, struct file *file)
251 return single_open(file, proc_lpevents_show, NULL);
254 static struct file_operations proc_lpevents_operations = {
255 .open = proc_lpevents_open,
258 .release = single_release,
261 static int __init proc_lpevents_init(void)
263 struct proc_dir_entry *e;
265 e = create_proc_entry("iSeries/lpevents", S_IFREG|S_IRUGO, NULL);
267 e->proc_fops = &proc_lpevents_operations;
271 __initcall(proc_lpevents_init);