ItLpQueue.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. /*
  22. * The LpQueue is used to pass event data from the hypervisor to
  23. * the partition. This is where I/O interrupt events are communicated.
  24. *
  25. * It is written to by the hypervisor so cannot end up in the BSS.
  26. */
  27. struct hvlpevent_queue hvlpevent_queue __attribute__((__section__(".data")));
  28. DEFINE_PER_CPU(unsigned long[HvLpEvent_Type_NumTypes], hvlpevent_counts);
  29. static char *event_types[HvLpEvent_Type_NumTypes] = {
  30. "Hypervisor\t\t",
  31. "Machine Facilities\t",
  32. "Session Manager\t",
  33. "SPD I/O\t\t",
  34. "Virtual Bus\t\t",
  35. "PCI I/O\t\t",
  36. "RIO I/O\t\t",
  37. "Virtual Lan\t\t",
  38. "Virtual I/O\t\t"
  39. };
  40. static __inline__ int set_inUse(void)
  41. {
  42. int t;
  43. u32 * inUseP = &hvlpevent_queue.xInUseWord;
  44. __asm__ __volatile__("\n\
  45. 1: lwarx %0,0,%2 \n\
  46. cmpwi 0,%0,0 \n\
  47. li %0,0 \n\
  48. bne- 2f \n\
  49. addi %0,%0,1 \n\
  50. stwcx. %0,0,%2 \n\
  51. bne- 1b \n\
  52. 2: eieio"
  53. : "=&r" (t), "=m" (hvlpevent_queue.xInUseWord)
  54. : "r" (inUseP), "m" (hvlpevent_queue.xInUseWord)
  55. : "cc");
  56. return t;
  57. }
  58. static __inline__ void clear_inUse(void)
  59. {
  60. hvlpevent_queue.xInUseWord = 0;
  61. }
  62. /* Array of LpEvent handler functions */
  63. extern LpEventHandler lpEventHandler[HvLpEvent_Type_NumTypes];
  64. unsigned long ItLpQueueInProcess = 0;
  65. static struct HvLpEvent * get_next_hvlpevent(void)
  66. {
  67. struct HvLpEvent * nextLpEvent =
  68. (struct HvLpEvent *)hvlpevent_queue.xSlicCurEventPtr;
  69. if ( nextLpEvent->xFlags.xValid ) {
  70. /* rmb() needed only for weakly consistent machines (regatta) */
  71. rmb();
  72. /* Set pointer to next potential event */
  73. hvlpevent_queue.xSlicCurEventPtr += ((nextLpEvent->xSizeMinus1 +
  74. LpEventAlign ) /
  75. LpEventAlign ) *
  76. LpEventAlign;
  77. /* Wrap to beginning if no room at end */
  78. if (hvlpevent_queue.xSlicCurEventPtr > hvlpevent_queue.xSlicLastValidEventPtr)
  79. hvlpevent_queue.xSlicCurEventPtr = hvlpevent_queue.xSlicEventStackPtr;
  80. }
  81. else
  82. nextLpEvent = NULL;
  83. return nextLpEvent;
  84. }
  85. static unsigned long spread_lpevents = NR_CPUS;
  86. int hvlpevent_is_pending(void)
  87. {
  88. struct HvLpEvent *next_event;
  89. if (smp_processor_id() >= spread_lpevents)
  90. return 0;
  91. next_event = (struct HvLpEvent *)hvlpevent_queue.xSlicCurEventPtr;
  92. return next_event->xFlags.xValid | hvlpevent_queue.xPlicOverflowIntPending;
  93. }
  94. static void hvlpevent_clear_valid( struct HvLpEvent * event )
  95. {
  96. /* Clear the valid bit of the event
  97. * Also clear bits within this event that might
  98. * look like valid bits (on 64-byte boundaries)
  99. */
  100. unsigned extra = (( event->xSizeMinus1 + LpEventAlign ) /
  101. LpEventAlign ) - 1;
  102. switch ( extra ) {
  103. case 3:
  104. ((struct HvLpEvent*)((char*)event+3*LpEventAlign))->xFlags.xValid=0;
  105. case 2:
  106. ((struct HvLpEvent*)((char*)event+2*LpEventAlign))->xFlags.xValid=0;
  107. case 1:
  108. ((struct HvLpEvent*)((char*)event+1*LpEventAlign))->xFlags.xValid=0;
  109. case 0:
  110. ;
  111. }
  112. mb();
  113. event->xFlags.xValid = 0;
  114. }
  115. void process_hvlpevents(struct pt_regs *regs)
  116. {
  117. struct HvLpEvent * nextLpEvent;
  118. /* If we have recursed, just return */
  119. if ( !set_inUse() )
  120. return;
  121. if (ItLpQueueInProcess == 0)
  122. ItLpQueueInProcess = 1;
  123. else
  124. BUG();
  125. for (;;) {
  126. nextLpEvent = get_next_hvlpevent();
  127. if ( nextLpEvent ) {
  128. /* Call appropriate handler here, passing
  129. * a pointer to the LpEvent. The handler
  130. * must make a copy of the LpEvent if it
  131. * needs it in a bottom half. (perhaps for
  132. * an ACK)
  133. *
  134. * Handlers are responsible for ACK processing
  135. *
  136. * The Hypervisor guarantees that LpEvents will
  137. * only be delivered with types that we have
  138. * registered for, so no type check is necessary
  139. * here!
  140. */
  141. if ( nextLpEvent->xType < HvLpEvent_Type_NumTypes )
  142. __get_cpu_var(hvlpevent_counts)[nextLpEvent->xType]++;
  143. if ( nextLpEvent->xType < HvLpEvent_Type_NumTypes &&
  144. lpEventHandler[nextLpEvent->xType] )
  145. lpEventHandler[nextLpEvent->xType](nextLpEvent, regs);
  146. else
  147. printk(KERN_INFO "Unexpected Lp Event type=%d\n", nextLpEvent->xType );
  148. hvlpevent_clear_valid( nextLpEvent );
  149. } else if ( hvlpevent_queue.xPlicOverflowIntPending )
  150. /*
  151. * No more valid events. If overflow events are
  152. * pending process them
  153. */
  154. HvCallEvent_getOverflowLpEvents( hvlpevent_queue.xIndex);
  155. else
  156. break;
  157. }
  158. ItLpQueueInProcess = 0;
  159. mb();
  160. clear_inUse();
  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. hvlpevent_queue.xSlicEventStackPtr = (char *)eventStack;
  191. hvlpevent_queue.xSlicCurEventPtr = (char *)eventStack;
  192. hvlpevent_queue.xSlicLastValidEventPtr = (char *)eventStack +
  193. (LpEventStackSize - LpEventMaxSize);
  194. hvlpevent_queue.xIndex = 0;
  195. }
  196. static int proc_lpevents_show(struct seq_file *m, void *v)
  197. {
  198. int cpu, i;
  199. unsigned long sum;
  200. static unsigned long cpu_totals[NR_CPUS];
  201. /* FIXME: do we care that there's no locking here? */
  202. sum = 0;
  203. for_each_online_cpu(cpu) {
  204. cpu_totals[cpu] = 0;
  205. for (i = 0; i < HvLpEvent_Type_NumTypes; i++) {
  206. cpu_totals[cpu] += per_cpu(hvlpevent_counts, cpu)[i];
  207. }
  208. sum += cpu_totals[cpu];
  209. }
  210. seq_printf(m, "LpEventQueue 0\n");
  211. seq_printf(m, " events processed:\t%lu\n", sum);
  212. for (i = 0; i < HvLpEvent_Type_NumTypes; ++i) {
  213. sum = 0;
  214. for_each_online_cpu(cpu) {
  215. sum += per_cpu(hvlpevent_counts, cpu)[i];
  216. }
  217. seq_printf(m, " %s %10lu\n", event_types[i], sum);
  218. }
  219. seq_printf(m, "\n events processed by processor:\n");
  220. for_each_online_cpu(cpu) {
  221. seq_printf(m, " CPU%02d %10lu\n", cpu, cpu_totals[cpu]);
  222. }
  223. return 0;
  224. }
  225. static int proc_lpevents_open(struct inode *inode, struct file *file)
  226. {
  227. return single_open(file, proc_lpevents_show, NULL);
  228. }
  229. static struct file_operations proc_lpevents_operations = {
  230. .open = proc_lpevents_open,
  231. .read = seq_read,
  232. .llseek = seq_lseek,
  233. .release = single_release,
  234. };
  235. static int __init proc_lpevents_init(void)
  236. {
  237. struct proc_dir_entry *e;
  238. e = create_proc_entry("iSeries/lpevents", S_IFREG|S_IRUGO, NULL);
  239. if (e)
  240. e->proc_fops = &proc_lpevents_operations;
  241. return 0;
  242. }
  243. __initcall(proc_lpevents_init);