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 unsigned long spread_lpevents = 1;
74 int ItLpQueue_isLpIntPending( struct ItLpQueue * lpQueue )
76 struct HvLpEvent *next_event;
78 if (smp_processor_id() >= spread_lpevents)
81 next_event = (struct HvLpEvent *)lpQueue->xSlicCurEventPtr;
82 return next_event->xFlags.xValid | lpQueue->xPlicOverflowIntPending;
85 void ItLpQueue_clearValid( struct HvLpEvent * event )
87 /* Clear the valid bit of the event
88 * Also clear bits within this event that might
89 * look like valid bits (on 64-byte boundaries)
91 unsigned extra = (( event->xSizeMinus1 + LpEventAlign ) /
95 ((struct HvLpEvent*)((char*)event+3*LpEventAlign))->xFlags.xValid=0;
97 ((struct HvLpEvent*)((char*)event+2*LpEventAlign))->xFlags.xValid=0;
99 ((struct HvLpEvent*)((char*)event+1*LpEventAlign))->xFlags.xValid=0;
104 event->xFlags.xValid = 0;
107 unsigned ItLpQueue_process( struct ItLpQueue * lpQueue, struct pt_regs *regs )
109 unsigned numIntsProcessed = 0;
110 struct HvLpEvent * nextLpEvent;
112 /* If we have recursed, just return */
113 if ( !set_inUse( lpQueue ) )
116 if (ItLpQueueInProcess == 0)
117 ItLpQueueInProcess = 1;
122 nextLpEvent = ItLpQueue_getNextLpEvent( lpQueue );
124 /* Count events to return to caller
125 * and count processed events in lpQueue
128 lpQueue->xLpIntCount++;
129 /* Call appropriate handler here, passing
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
135 * Handlers are responsible for ACK processing
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
142 if ( nextLpEvent->xType < HvLpEvent_Type_NumTypes )
143 lpQueue->xLpIntCountByType[nextLpEvent->xType]++;
144 if ( nextLpEvent->xType < HvLpEvent_Type_NumTypes &&
145 lpEventHandler[nextLpEvent->xType] )
146 lpEventHandler[nextLpEvent->xType](nextLpEvent, regs);
148 printk(KERN_INFO "Unexpected Lp Event type=%d\n", nextLpEvent->xType );
150 ItLpQueue_clearValid( nextLpEvent );
151 } else if ( lpQueue->xPlicOverflowIntPending )
153 * No more valid events. If overflow events are
154 * pending process them
156 HvCallEvent_getOverflowLpEvents( lpQueue->xIndex);
161 ItLpQueueInProcess = 0;
163 clear_inUse( lpQueue );
165 get_paca()->lpevent_count += numIntsProcessed;
167 return numIntsProcessed;