ItLpQueue.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * ItLpQueue.c
  3. * Copyright (C) 2001 Mike Corrigan IBM Corporation
  4. *
  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.
  9. */
  10. #include <linux/stddef.h>
  11. #include <linux/kernel.h>
  12. #include <linux/sched.h>
  13. #include <linux/bootmem.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/proc_fs.h>
  16. #include <asm/system.h>
  17. #include <asm/paca.h>
  18. #include <asm/iSeries/ItLpQueue.h>
  19. #include <asm/iSeries/HvLpEvent.h>
  20. #include <asm/iSeries/HvCallEvent.h>
  21. static char *event_types[9] = {
  22. "Hypervisor\t\t",
  23. "Machine Facilities\t",
  24. "Session Manager\t",
  25. "SPD I/O\t\t",
  26. "Virtual Bus\t\t",
  27. "PCI I/O\t\t",
  28. "RIO I/O\t\t",
  29. "Virtual Lan\t\t",
  30. "Virtual I/O\t\t"
  31. };
  32. static __inline__ int set_inUse(void)
  33. {
  34. int t;
  35. u32 * inUseP = &xItLpQueue.xInUseWord;
  36. __asm__ __volatile__("\n\
  37. 1: lwarx %0,0,%2 \n\
  38. cmpwi 0,%0,0 \n\
  39. li %0,0 \n\
  40. bne- 2f \n\
  41. addi %0,%0,1 \n\
  42. stwcx. %0,0,%2 \n\
  43. bne- 1b \n\
  44. 2: eieio"
  45. : "=&r" (t), "=m" (xItLpQueue.xInUseWord)
  46. : "r" (inUseP), "m" (xItLpQueue.xInUseWord)
  47. : "cc");
  48. return t;
  49. }
  50. static __inline__ void clear_inUse(void)
  51. {
  52. xItLpQueue.xInUseWord = 0;
  53. }
  54. /* Array of LpEvent handler functions */
  55. extern LpEventHandler lpEventHandler[HvLpEvent_Type_NumTypes];
  56. unsigned long ItLpQueueInProcess = 0;
  57. struct HvLpEvent * ItLpQueue_getNextLpEvent(void)
  58. {
  59. struct HvLpEvent * nextLpEvent =
  60. (struct HvLpEvent *)xItLpQueue.xSlicCurEventPtr;
  61. if ( nextLpEvent->xFlags.xValid ) {
  62. /* rmb() needed only for weakly consistent machines (regatta) */
  63. rmb();
  64. /* Set pointer to next potential event */
  65. xItLpQueue.xSlicCurEventPtr += ((nextLpEvent->xSizeMinus1 +
  66. LpEventAlign ) /
  67. LpEventAlign ) *
  68. LpEventAlign;
  69. /* Wrap to beginning if no room at end */
  70. if (xItLpQueue.xSlicCurEventPtr > xItLpQueue.xSlicLastValidEventPtr)
  71. xItLpQueue.xSlicCurEventPtr = xItLpQueue.xSlicEventStackPtr;
  72. }
  73. else
  74. nextLpEvent = NULL;
  75. return nextLpEvent;
  76. }
  77. static unsigned long spread_lpevents = NR_CPUS;
  78. int ItLpQueue_isLpIntPending(void)
  79. {
  80. struct HvLpEvent *next_event;
  81. if (smp_processor_id() >= spread_lpevents)
  82. return 0;
  83. next_event = (struct HvLpEvent *)xItLpQueue.xSlicCurEventPtr;
  84. return next_event->xFlags.xValid | xItLpQueue.xPlicOverflowIntPending;
  85. }
  86. void ItLpQueue_clearValid( struct HvLpEvent * event )
  87. {
  88. /* Clear the valid bit of the event
  89. * Also clear bits within this event that might
  90. * look like valid bits (on 64-byte boundaries)
  91. */
  92. unsigned extra = (( event->xSizeMinus1 + LpEventAlign ) /
  93. LpEventAlign ) - 1;
  94. switch ( extra ) {
  95. case 3:
  96. ((struct HvLpEvent*)((char*)event+3*LpEventAlign))->xFlags.xValid=0;
  97. case 2:
  98. ((struct HvLpEvent*)((char*)event+2*LpEventAlign))->xFlags.xValid=0;
  99. case 1:
  100. ((struct HvLpEvent*)((char*)event+1*LpEventAlign))->xFlags.xValid=0;
  101. case 0:
  102. ;
  103. }
  104. mb();
  105. event->xFlags.xValid = 0;
  106. }
  107. unsigned ItLpQueue_process(struct pt_regs *regs)
  108. {
  109. unsigned numIntsProcessed = 0;
  110. struct HvLpEvent * nextLpEvent;
  111. /* If we have recursed, just return */
  112. if ( !set_inUse() )
  113. return 0;
  114. if (ItLpQueueInProcess == 0)
  115. ItLpQueueInProcess = 1;
  116. else
  117. BUG();
  118. for (;;) {
  119. nextLpEvent = ItLpQueue_getNextLpEvent();
  120. if ( nextLpEvent ) {
  121. /* Count events to return to caller
  122. * and count processed events in xItLpQueue
  123. */
  124. ++numIntsProcessed;
  125. xItLpQueue.xLpIntCount++;
  126. /* Call appropriate handler here, passing
  127. * a pointer to the LpEvent. The handler
  128. * must make a copy of the LpEvent if it
  129. * needs it in a bottom half. (perhaps for
  130. * an ACK)
  131. *
  132. * Handlers are responsible for ACK processing
  133. *
  134. * The Hypervisor guarantees that LpEvents will
  135. * only be delivered with types that we have
  136. * registered for, so no type check is necessary
  137. * here!
  138. */
  139. if ( nextLpEvent->xType < HvLpEvent_Type_NumTypes )
  140. xItLpQueue.xLpIntCountByType[nextLpEvent->xType]++;
  141. if ( nextLpEvent->xType < HvLpEvent_Type_NumTypes &&
  142. lpEventHandler[nextLpEvent->xType] )
  143. lpEventHandler[nextLpEvent->xType](nextLpEvent, regs);
  144. else
  145. printk(KERN_INFO "Unexpected Lp Event type=%d\n", nextLpEvent->xType );
  146. ItLpQueue_clearValid( nextLpEvent );
  147. } else if ( xItLpQueue.xPlicOverflowIntPending )
  148. /*
  149. * No more valid events. If overflow events are
  150. * pending process them
  151. */
  152. HvCallEvent_getOverflowLpEvents( xItLpQueue.xIndex);
  153. else
  154. break;
  155. }
  156. ItLpQueueInProcess = 0;
  157. mb();
  158. clear_inUse();
  159. get_paca()->lpevent_count += numIntsProcessed;
  160. return numIntsProcessed;
  161. }
  162. static int set_spread_lpevents(char *str)
  163. {
  164. unsigned long val = simple_strtoul(str, NULL, 0);
  165. /*
  166. * The parameter is the number of processors to share in processing
  167. * lp events.
  168. */
  169. if (( val > 0) && (val <= NR_CPUS)) {
  170. spread_lpevents = val;
  171. printk("lpevent processing spread over %ld processors\n", val);
  172. } else {
  173. printk("invalid spread_lpevents %ld\n", val);
  174. }
  175. return 1;
  176. }
  177. __setup("spread_lpevents=", set_spread_lpevents);
  178. void setup_hvlpevent_queue(void)
  179. {
  180. void *eventStack;
  181. /*
  182. * Allocate a page for the Event Stack. The Hypervisor needs the
  183. * absolute real address, so we subtract out the KERNELBASE and add
  184. * in the absolute real address of the kernel load area.
  185. */
  186. eventStack = alloc_bootmem_pages(LpEventStackSize);
  187. memset(eventStack, 0, LpEventStackSize);
  188. /* Invoke the hypervisor to initialize the event stack */
  189. HvCallEvent_setLpEventStack(0, eventStack, LpEventStackSize);
  190. xItLpQueue.xSlicEventStackPtr = (char *)eventStack;
  191. xItLpQueue.xSlicCurEventPtr = (char *)eventStack;
  192. xItLpQueue.xSlicLastValidEventPtr = (char *)eventStack +
  193. (LpEventStackSize - LpEventMaxSize);
  194. xItLpQueue.xIndex = 0;
  195. }
  196. static int proc_lpevents_show(struct seq_file *m, void *v)
  197. {
  198. unsigned int i;
  199. seq_printf(m, "LpEventQueue 0\n");
  200. seq_printf(m, " events processed:\t%lu\n",
  201. (unsigned long)xItLpQueue.xLpIntCount);
  202. for (i = 0; i < 9; ++i)
  203. seq_printf(m, " %s %10lu\n", event_types[i],
  204. (unsigned long)xItLpQueue.xLpIntCountByType[i]);
  205. seq_printf(m, "\n events processed by processor:\n");
  206. for_each_online_cpu(i)
  207. seq_printf(m, " CPU%02d %10u\n", i, paca[i].lpevent_count);
  208. return 0;
  209. }
  210. static int proc_lpevents_open(struct inode *inode, struct file *file)
  211. {
  212. return single_open(file, proc_lpevents_show, NULL);
  213. }
  214. static struct file_operations proc_lpevents_operations = {
  215. .open = proc_lpevents_open,
  216. .read = seq_read,
  217. .llseek = seq_lseek,
  218. .release = single_release,
  219. };
  220. static int __init proc_lpevents_init(void)
  221. {
  222. struct proc_dir_entry *e;
  223. e = create_proc_entry("iSeries/lpevents", S_IFREG|S_IRUGO, NULL);
  224. if (e)
  225. e->proc_fops = &proc_lpevents_operations;
  226. return 0;
  227. }
  228. __initcall(proc_lpevents_init);