lpevents.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * Copyright (C) 2001 Mike Corrigan IBM Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. */
  9. #include <linux/stddef.h>
  10. #include <linux/kernel.h>
  11. #include <linux/sched.h>
  12. #include <linux/bootmem.h>
  13. #include <linux/seq_file.h>
  14. #include <linux/proc_fs.h>
  15. #include <asm/system.h>
  16. #include <asm/paca.h>
  17. #include <asm/iSeries/ItLpQueue.h>
  18. #include <asm/iSeries/HvLpEvent.h>
  19. #include <asm/iSeries/HvCallEvent.h>
  20. /*
  21. * The LpQueue is used to pass event data from the hypervisor to
  22. * the partition. This is where I/O interrupt events are communicated.
  23. *
  24. * It is written to by the hypervisor so cannot end up in the BSS.
  25. */
  26. struct hvlpevent_queue hvlpevent_queue __attribute__((__section__(".data")));
  27. DEFINE_PER_CPU(unsigned long[HvLpEvent_Type_NumTypes], hvlpevent_counts);
  28. static char *event_types[HvLpEvent_Type_NumTypes] = {
  29. "Hypervisor",
  30. "Machine Facilities",
  31. "Session Manager",
  32. "SPD I/O",
  33. "Virtual Bus",
  34. "PCI I/O",
  35. "RIO I/O",
  36. "Virtual Lan",
  37. "Virtual I/O"
  38. };
  39. /* Array of LpEvent handler functions */
  40. extern LpEventHandler lpEventHandler[HvLpEvent_Type_NumTypes];
  41. static struct HvLpEvent * get_next_hvlpevent(void)
  42. {
  43. struct HvLpEvent * event;
  44. event = (struct HvLpEvent *)hvlpevent_queue.xSlicCurEventPtr;
  45. if (event->xFlags.xValid) {
  46. /* rmb() needed only for weakly consistent machines (regatta) */
  47. rmb();
  48. /* Set pointer to next potential event */
  49. hvlpevent_queue.xSlicCurEventPtr += ((event->xSizeMinus1 +
  50. LpEventAlign) / LpEventAlign) * LpEventAlign;
  51. /* Wrap to beginning if no room at end */
  52. if (hvlpevent_queue.xSlicCurEventPtr >
  53. hvlpevent_queue.xSlicLastValidEventPtr) {
  54. hvlpevent_queue.xSlicCurEventPtr =
  55. hvlpevent_queue.xSlicEventStackPtr;
  56. }
  57. } else {
  58. event = NULL;
  59. }
  60. return event;
  61. }
  62. static unsigned long spread_lpevents = NR_CPUS;
  63. int hvlpevent_is_pending(void)
  64. {
  65. struct HvLpEvent *next_event;
  66. if (smp_processor_id() >= spread_lpevents)
  67. return 0;
  68. next_event = (struct HvLpEvent *)hvlpevent_queue.xSlicCurEventPtr;
  69. return next_event->xFlags.xValid |
  70. hvlpevent_queue.xPlicOverflowIntPending;
  71. }
  72. static void hvlpevent_clear_valid(struct HvLpEvent * event)
  73. {
  74. /* Tell the Hypervisor that we're done with this event.
  75. * Also clear bits within this event that might look like valid bits.
  76. * ie. on 64-byte boundaries.
  77. */
  78. struct HvLpEvent *tmp;
  79. unsigned extra = ((event->xSizeMinus1 + LpEventAlign) /
  80. LpEventAlign) - 1;
  81. switch (extra) {
  82. case 3:
  83. tmp = (struct HvLpEvent*)((char*)event + 3 * LpEventAlign);
  84. tmp->xFlags.xValid = 0;
  85. case 2:
  86. tmp = (struct HvLpEvent*)((char*)event + 2 * LpEventAlign);
  87. tmp->xFlags.xValid = 0;
  88. case 1:
  89. tmp = (struct HvLpEvent*)((char*)event + 1 * LpEventAlign);
  90. tmp->xFlags.xValid = 0;
  91. }
  92. mb();
  93. event->xFlags.xValid = 0;
  94. }
  95. void process_hvlpevents(struct pt_regs *regs)
  96. {
  97. struct HvLpEvent * event;
  98. /* If we have recursed, just return */
  99. if (!spin_trylock(&hvlpevent_queue.lock))
  100. return;
  101. for (;;) {
  102. event = get_next_hvlpevent();
  103. if (event) {
  104. /* Call appropriate handler here, passing
  105. * a pointer to the LpEvent. The handler
  106. * must make a copy of the LpEvent if it
  107. * needs it in a bottom half. (perhaps for
  108. * an ACK)
  109. *
  110. * Handlers are responsible for ACK processing
  111. *
  112. * The Hypervisor guarantees that LpEvents will
  113. * only be delivered with types that we have
  114. * registered for, so no type check is necessary
  115. * here!
  116. */
  117. if (event->xType < HvLpEvent_Type_NumTypes)
  118. __get_cpu_var(hvlpevent_counts)[event->xType]++;
  119. if (event->xType < HvLpEvent_Type_NumTypes &&
  120. lpEventHandler[event->xType])
  121. lpEventHandler[event->xType](event, regs);
  122. else
  123. printk(KERN_INFO "Unexpected Lp Event type=%d\n", event->xType );
  124. hvlpevent_clear_valid(event);
  125. } else if (hvlpevent_queue.xPlicOverflowIntPending)
  126. /*
  127. * No more valid events. If overflow events are
  128. * pending process them
  129. */
  130. HvCallEvent_getOverflowLpEvents(hvlpevent_queue.xIndex);
  131. else
  132. break;
  133. }
  134. spin_unlock(&hvlpevent_queue.lock);
  135. }
  136. static int set_spread_lpevents(char *str)
  137. {
  138. unsigned long val = simple_strtoul(str, NULL, 0);
  139. /*
  140. * The parameter is the number of processors to share in processing
  141. * lp events.
  142. */
  143. if (( val > 0) && (val <= NR_CPUS)) {
  144. spread_lpevents = val;
  145. printk("lpevent processing spread over %ld processors\n", val);
  146. } else {
  147. printk("invalid spread_lpevents %ld\n", val);
  148. }
  149. return 1;
  150. }
  151. __setup("spread_lpevents=", set_spread_lpevents);
  152. void setup_hvlpevent_queue(void)
  153. {
  154. void *eventStack;
  155. /*
  156. * Allocate a page for the Event Stack. The Hypervisor needs the
  157. * absolute real address, so we subtract out the KERNELBASE and add
  158. * in the absolute real address of the kernel load area.
  159. */
  160. eventStack = alloc_bootmem_pages(LpEventStackSize);
  161. memset(eventStack, 0, LpEventStackSize);
  162. /* Invoke the hypervisor to initialize the event stack */
  163. HvCallEvent_setLpEventStack(0, eventStack, LpEventStackSize);
  164. hvlpevent_queue.xSlicEventStackPtr = (char *)eventStack;
  165. hvlpevent_queue.xSlicCurEventPtr = (char *)eventStack;
  166. hvlpevent_queue.xSlicLastValidEventPtr = (char *)eventStack +
  167. (LpEventStackSize - LpEventMaxSize);
  168. hvlpevent_queue.xIndex = 0;
  169. }
  170. static int proc_lpevents_show(struct seq_file *m, void *v)
  171. {
  172. int cpu, i;
  173. unsigned long sum;
  174. static unsigned long cpu_totals[NR_CPUS];
  175. /* FIXME: do we care that there's no locking here? */
  176. sum = 0;
  177. for_each_online_cpu(cpu) {
  178. cpu_totals[cpu] = 0;
  179. for (i = 0; i < HvLpEvent_Type_NumTypes; i++) {
  180. cpu_totals[cpu] += per_cpu(hvlpevent_counts, cpu)[i];
  181. }
  182. sum += cpu_totals[cpu];
  183. }
  184. seq_printf(m, "LpEventQueue 0\n");
  185. seq_printf(m, " events processed:\t%lu\n", sum);
  186. for (i = 0; i < HvLpEvent_Type_NumTypes; ++i) {
  187. sum = 0;
  188. for_each_online_cpu(cpu) {
  189. sum += per_cpu(hvlpevent_counts, cpu)[i];
  190. }
  191. seq_printf(m, " %-20s %10lu\n", event_types[i], sum);
  192. }
  193. seq_printf(m, "\n events processed by processor:\n");
  194. for_each_online_cpu(cpu) {
  195. seq_printf(m, " CPU%02d %10lu\n", cpu, cpu_totals[cpu]);
  196. }
  197. return 0;
  198. }
  199. static int proc_lpevents_open(struct inode *inode, struct file *file)
  200. {
  201. return single_open(file, proc_lpevents_show, NULL);
  202. }
  203. static struct file_operations proc_lpevents_operations = {
  204. .open = proc_lpevents_open,
  205. .read = seq_read,
  206. .llseek = seq_lseek,
  207. .release = single_release,
  208. };
  209. static int __init proc_lpevents_init(void)
  210. {
  211. struct proc_dir_entry *e;
  212. e = create_proc_entry("iSeries/lpevents", S_IFREG|S_IRUGO, NULL);
  213. if (e)
  214. e->proc_fops = &proc_lpevents_operations;
  215. return 0;
  216. }
  217. __initcall(proc_lpevents_init);