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 <asm/system.h>
16 #include <asm/iSeries/ItLpQueue.h>
17 #include <asm/iSeries/HvLpEvent.h>
18 #include <asm/iSeries/HvCallEvent.h>
20 static __inline__ int set_inUse( struct ItLpQueue * lpQueue )
23 u32 * inUseP = &(lpQueue->xInUseWord);
25 __asm__ __volatile__("\n\
34 : "=&r" (t), "=m" (lpQueue->xInUseWord)
35 : "r" (inUseP), "m" (lpQueue->xInUseWord)
41 static __inline__ void clear_inUse( struct ItLpQueue * lpQueue )
43 lpQueue->xInUseWord = 0;
46 /* Array of LpEvent handler functions */
47 extern LpEventHandler lpEventHandler[HvLpEvent_Type_NumTypes];
48 unsigned long ItLpQueueInProcess = 0;
50 struct HvLpEvent * ItLpQueue_getNextLpEvent( struct ItLpQueue * lpQueue )
52 struct HvLpEvent * nextLpEvent =
53 (struct HvLpEvent *)lpQueue->xSlicCurEventPtr;
54 if ( nextLpEvent->xFlags.xValid ) {
55 /* rmb() needed only for weakly consistent machines (regatta) */
57 /* Set pointer to next potential event */
58 lpQueue->xSlicCurEventPtr += ((nextLpEvent->xSizeMinus1 +
62 /* Wrap to beginning if no room at end */
63 if (lpQueue->xSlicCurEventPtr > lpQueue->xSlicLastValidEventPtr)
64 lpQueue->xSlicCurEventPtr = lpQueue->xSlicEventStackPtr;
72 int ItLpQueue_isLpIntPending( struct ItLpQueue * lpQueue )
75 struct HvLpEvent * nextLpEvent;
77 nextLpEvent = (struct HvLpEvent *)lpQueue->xSlicCurEventPtr;
78 retval = nextLpEvent->xFlags.xValid | lpQueue->xPlicOverflowIntPending;
83 void ItLpQueue_clearValid( struct HvLpEvent * event )
85 /* Clear the valid bit of the event
86 * Also clear bits within this event that might
87 * look like valid bits (on 64-byte boundaries)
89 unsigned extra = (( event->xSizeMinus1 + LpEventAlign ) /
93 ((struct HvLpEvent*)((char*)event+3*LpEventAlign))->xFlags.xValid=0;
95 ((struct HvLpEvent*)((char*)event+2*LpEventAlign))->xFlags.xValid=0;
97 ((struct HvLpEvent*)((char*)event+1*LpEventAlign))->xFlags.xValid=0;
102 event->xFlags.xValid = 0;
105 unsigned ItLpQueue_process( struct ItLpQueue * lpQueue, struct pt_regs *regs )
107 unsigned numIntsProcessed = 0;
108 struct HvLpEvent * nextLpEvent;
110 /* If we have recursed, just return */
111 if ( !set_inUse( lpQueue ) )
114 if (ItLpQueueInProcess == 0)
115 ItLpQueueInProcess = 1;
120 nextLpEvent = ItLpQueue_getNextLpEvent( lpQueue );
122 /* Count events to return to caller
123 * and count processed events in lpQueue
126 lpQueue->xLpIntCount++;
127 /* Call appropriate handler here, passing
128 * a pointer to the LpEvent. The handler
129 * must make a copy of the LpEvent if it
130 * needs it in a bottom half. (perhaps for
133 * Handlers are responsible for ACK processing
135 * The Hypervisor guarantees that LpEvents will
136 * only be delivered with types that we have
137 * registered for, so no type check is necessary
140 if ( nextLpEvent->xType < HvLpEvent_Type_NumTypes )
141 lpQueue->xLpIntCountByType[nextLpEvent->xType]++;
142 if ( nextLpEvent->xType < HvLpEvent_Type_NumTypes &&
143 lpEventHandler[nextLpEvent->xType] )
144 lpEventHandler[nextLpEvent->xType](nextLpEvent, regs);
146 printk(KERN_INFO "Unexpected Lp Event type=%d\n", nextLpEvent->xType );
148 ItLpQueue_clearValid( nextLpEvent );
149 } else if ( lpQueue->xPlicOverflowIntPending )
151 * No more valid events. If overflow events are
152 * pending process them
154 HvCallEvent_getOverflowLpEvents( lpQueue->xIndex);
159 ItLpQueueInProcess = 0;
161 clear_inUse( lpQueue );
163 get_paca()->lpevent_count += numIntsProcessed;
165 return numIntsProcessed;