ItLpQueue.c 6.6 KB

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