Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ItLpQueue.c |
| 3 | * Copyright (C) 2001 Mike Corrigan IBM Corporation |
Michael Ellerman | 38fcdcfe | 2005-06-30 15:16:28 +1000 | [diff] [blame] | 4 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 11 | #include <linux/stddef.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/sched.h> |
Michael Ellerman | 512d31d | 2005-06-30 15:08:27 +1000 | [diff] [blame] | 14 | #include <linux/bootmem.h> |
Michael Ellerman | 7b01328 | 2005-06-30 15:08:44 +1000 | [diff] [blame] | 15 | #include <linux/seq_file.h> |
| 16 | #include <linux/proc_fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <asm/system.h> |
| 18 | #include <asm/paca.h> |
| 19 | #include <asm/iSeries/ItLpQueue.h> |
| 20 | #include <asm/iSeries/HvLpEvent.h> |
| 21 | #include <asm/iSeries/HvCallEvent.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Michael Ellerman | ab354b6 | 2005-06-30 15:12:21 +1000 | [diff] [blame] | 23 | /* |
| 24 | * The LpQueue is used to pass event data from the hypervisor to |
| 25 | * the partition. This is where I/O interrupt events are communicated. |
| 26 | * |
| 27 | * It is written to by the hypervisor so cannot end up in the BSS. |
| 28 | */ |
Michael Ellerman | a618746 | 2005-06-30 15:15:32 +1000 | [diff] [blame] | 29 | struct hvlpevent_queue hvlpevent_queue __attribute__((__section__(".data"))); |
Michael Ellerman | ab354b6 | 2005-06-30 15:12:21 +1000 | [diff] [blame] | 30 | |
Michael Ellerman | ed09415 | 2005-06-30 15:16:09 +1000 | [diff] [blame] | 31 | DEFINE_PER_CPU(unsigned long[HvLpEvent_Type_NumTypes], hvlpevent_counts); |
| 32 | |
| 33 | static char *event_types[HvLpEvent_Type_NumTypes] = { |
Michael Ellerman | 9b04702 | 2005-06-30 15:16:18 +1000 | [diff] [blame] | 34 | "Hypervisor", |
| 35 | "Machine Facilities", |
| 36 | "Session Manager", |
| 37 | "SPD I/O", |
| 38 | "Virtual Bus", |
| 39 | "PCI I/O", |
| 40 | "RIO I/O", |
| 41 | "Virtual Lan", |
| 42 | "Virtual I/O" |
Michael Ellerman | 7b01328 | 2005-06-30 15:08:44 +1000 | [diff] [blame] | 43 | }; |
| 44 | |
Michael Ellerman | 1b19bc7 | 2005-06-30 15:07:57 +1000 | [diff] [blame] | 45 | static __inline__ int set_inUse(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | { |
| 47 | int t; |
Michael Ellerman | a618746 | 2005-06-30 15:15:32 +1000 | [diff] [blame] | 48 | u32 * inUseP = &hvlpevent_queue.xInUseWord; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | __asm__ __volatile__("\n\ |
| 51 | 1: lwarx %0,0,%2 \n\ |
| 52 | cmpwi 0,%0,0 \n\ |
| 53 | li %0,0 \n\ |
| 54 | bne- 2f \n\ |
| 55 | addi %0,%0,1 \n\ |
| 56 | stwcx. %0,0,%2 \n\ |
| 57 | bne- 1b \n\ |
| 58 | 2: eieio" |
Michael Ellerman | a618746 | 2005-06-30 15:15:32 +1000 | [diff] [blame] | 59 | : "=&r" (t), "=m" (hvlpevent_queue.xInUseWord) |
| 60 | : "r" (inUseP), "m" (hvlpevent_queue.xInUseWord) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | : "cc"); |
| 62 | |
| 63 | return t; |
| 64 | } |
| 65 | |
Michael Ellerman | 1b19bc7 | 2005-06-30 15:07:57 +1000 | [diff] [blame] | 66 | static __inline__ void clear_inUse(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
Michael Ellerman | a618746 | 2005-06-30 15:15:32 +1000 | [diff] [blame] | 68 | hvlpevent_queue.xInUseWord = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /* Array of LpEvent handler functions */ |
| 72 | extern LpEventHandler lpEventHandler[HvLpEvent_Type_NumTypes]; |
| 73 | unsigned long ItLpQueueInProcess = 0; |
| 74 | |
Michael Ellerman | 937b31b | 2005-06-30 15:15:42 +1000 | [diff] [blame] | 75 | static struct HvLpEvent * get_next_hvlpevent(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
Michael Ellerman | ffe1b7e | 2005-06-30 15:16:48 +1000 | [diff] [blame^] | 77 | struct HvLpEvent * event; |
| 78 | event = (struct HvLpEvent *)hvlpevent_queue.xSlicCurEventPtr; |
| 79 | |
| 80 | if (event->xFlags.xValid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | /* rmb() needed only for weakly consistent machines (regatta) */ |
| 82 | rmb(); |
| 83 | /* Set pointer to next potential event */ |
Michael Ellerman | ffe1b7e | 2005-06-30 15:16:48 +1000 | [diff] [blame^] | 84 | hvlpevent_queue.xSlicCurEventPtr += ((event->xSizeMinus1 + |
| 85 | LpEventAlign) / LpEventAlign) * LpEventAlign; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Michael Ellerman | ffe1b7e | 2005-06-30 15:16:48 +1000 | [diff] [blame^] | 87 | /* Wrap to beginning if no room at end */ |
| 88 | if (hvlpevent_queue.xSlicCurEventPtr > |
| 89 | hvlpevent_queue.xSlicLastValidEventPtr) { |
| 90 | hvlpevent_queue.xSlicCurEventPtr = |
| 91 | hvlpevent_queue.xSlicEventStackPtr; |
| 92 | } |
| 93 | } else { |
| 94 | event = NULL; |
| 95 | } |
| 96 | |
| 97 | return event; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Michael Ellerman | 0c885c1 | 2005-06-30 15:07:33 +1000 | [diff] [blame] | 100 | static unsigned long spread_lpevents = NR_CPUS; |
Michael Ellerman | bea248f | 2005-06-30 15:07:09 +1000 | [diff] [blame] | 101 | |
Michael Ellerman | 937b31b | 2005-06-30 15:15:42 +1000 | [diff] [blame] | 102 | int hvlpevent_is_pending(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { |
Michael Ellerman | bea248f | 2005-06-30 15:07:09 +1000 | [diff] [blame] | 104 | struct HvLpEvent *next_event; |
| 105 | |
| 106 | if (smp_processor_id() >= spread_lpevents) |
| 107 | return 0; |
| 108 | |
Michael Ellerman | a618746 | 2005-06-30 15:15:32 +1000 | [diff] [blame] | 109 | next_event = (struct HvLpEvent *)hvlpevent_queue.xSlicCurEventPtr; |
Michael Ellerman | ffe1b7e | 2005-06-30 15:16:48 +1000 | [diff] [blame^] | 110 | |
| 111 | return next_event->xFlags.xValid | |
| 112 | hvlpevent_queue.xPlicOverflowIntPending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Michael Ellerman | 38fcdcfe | 2005-06-30 15:16:28 +1000 | [diff] [blame] | 115 | static void hvlpevent_clear_valid(struct HvLpEvent * event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { |
Michael Ellerman | ffe1b7e | 2005-06-30 15:16:48 +1000 | [diff] [blame^] | 117 | /* Tell the Hypervisor that we're done with this event. |
| 118 | * Also clear bits within this event that might look like valid bits. |
| 119 | * ie. on 64-byte boundaries. |
Michael Ellerman | 38fcdcfe | 2005-06-30 15:16:28 +1000 | [diff] [blame] | 120 | */ |
Michael Ellerman | ffe1b7e | 2005-06-30 15:16:48 +1000 | [diff] [blame^] | 121 | struct HvLpEvent *tmp; |
Michael Ellerman | 38fcdcfe | 2005-06-30 15:16:28 +1000 | [diff] [blame] | 122 | unsigned extra = ((event->xSizeMinus1 + LpEventAlign) / |
| 123 | LpEventAlign) - 1; |
Michael Ellerman | ffe1b7e | 2005-06-30 15:16:48 +1000 | [diff] [blame^] | 124 | |
Michael Ellerman | 38fcdcfe | 2005-06-30 15:16:28 +1000 | [diff] [blame] | 125 | switch (extra) { |
| 126 | case 3: |
Michael Ellerman | ffe1b7e | 2005-06-30 15:16:48 +1000 | [diff] [blame^] | 127 | tmp = (struct HvLpEvent*)((char*)event + 3 * LpEventAlign); |
| 128 | tmp->xFlags.xValid = 0; |
Michael Ellerman | 38fcdcfe | 2005-06-30 15:16:28 +1000 | [diff] [blame] | 129 | case 2: |
Michael Ellerman | ffe1b7e | 2005-06-30 15:16:48 +1000 | [diff] [blame^] | 130 | tmp = (struct HvLpEvent*)((char*)event + 2 * LpEventAlign); |
| 131 | tmp->xFlags.xValid = 0; |
Michael Ellerman | 38fcdcfe | 2005-06-30 15:16:28 +1000 | [diff] [blame] | 132 | case 1: |
Michael Ellerman | ffe1b7e | 2005-06-30 15:16:48 +1000 | [diff] [blame^] | 133 | tmp = (struct HvLpEvent*)((char*)event + 1 * LpEventAlign); |
| 134 | tmp->xFlags.xValid = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
Michael Ellerman | ffe1b7e | 2005-06-30 15:16:48 +1000 | [diff] [blame^] | 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | mb(); |
Michael Ellerman | ffe1b7e | 2005-06-30 15:16:48 +1000 | [diff] [blame^] | 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | event->xFlags.xValid = 0; |
| 140 | } |
| 141 | |
Michael Ellerman | 7488980 | 2005-06-30 15:15:53 +1000 | [diff] [blame] | 142 | void process_hvlpevents(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | { |
Michael Ellerman | ffe1b7e | 2005-06-30 15:16:48 +1000 | [diff] [blame^] | 144 | struct HvLpEvent * event; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | /* If we have recursed, just return */ |
Michael Ellerman | 1b19bc7 | 2005-06-30 15:07:57 +1000 | [diff] [blame] | 147 | if ( !set_inUse() ) |
Michael Ellerman | 7488980 | 2005-06-30 15:15:53 +1000 | [diff] [blame] | 148 | return; |
Michael Ellerman | 38fcdcfe | 2005-06-30 15:16:28 +1000 | [diff] [blame] | 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | if (ItLpQueueInProcess == 0) |
| 151 | ItLpQueueInProcess = 1; |
| 152 | else |
| 153 | BUG(); |
| 154 | |
| 155 | for (;;) { |
Michael Ellerman | ffe1b7e | 2005-06-30 15:16:48 +1000 | [diff] [blame^] | 156 | event = get_next_hvlpevent(); |
| 157 | if (event) { |
Michael Ellerman | 38fcdcfe | 2005-06-30 15:16:28 +1000 | [diff] [blame] | 158 | /* Call appropriate handler here, passing |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | * a pointer to the LpEvent. The handler |
| 160 | * must make a copy of the LpEvent if it |
| 161 | * needs it in a bottom half. (perhaps for |
| 162 | * an ACK) |
Michael Ellerman | 38fcdcfe | 2005-06-30 15:16:28 +1000 | [diff] [blame] | 163 | * |
| 164 | * Handlers are responsible for ACK processing |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | * |
| 166 | * The Hypervisor guarantees that LpEvents will |
| 167 | * only be delivered with types that we have |
| 168 | * registered for, so no type check is necessary |
| 169 | * here! |
Michael Ellerman | 38fcdcfe | 2005-06-30 15:16:28 +1000 | [diff] [blame] | 170 | */ |
Michael Ellerman | ffe1b7e | 2005-06-30 15:16:48 +1000 | [diff] [blame^] | 171 | if (event->xType < HvLpEvent_Type_NumTypes) |
| 172 | __get_cpu_var(hvlpevent_counts)[event->xType]++; |
| 173 | if (event->xType < HvLpEvent_Type_NumTypes && |
| 174 | lpEventHandler[event->xType]) |
| 175 | lpEventHandler[event->xType](event, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | else |
Michael Ellerman | ffe1b7e | 2005-06-30 15:16:48 +1000 | [diff] [blame^] | 177 | printk(KERN_INFO "Unexpected Lp Event type=%d\n", event->xType ); |
Michael Ellerman | 38fcdcfe | 2005-06-30 15:16:28 +1000 | [diff] [blame] | 178 | |
Michael Ellerman | ffe1b7e | 2005-06-30 15:16:48 +1000 | [diff] [blame^] | 179 | hvlpevent_clear_valid(event); |
Michael Ellerman | 38fcdcfe | 2005-06-30 15:16:28 +1000 | [diff] [blame] | 180 | } else if (hvlpevent_queue.xPlicOverflowIntPending) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | /* |
| 182 | * No more valid events. If overflow events are |
| 183 | * pending process them |
| 184 | */ |
Michael Ellerman | 38fcdcfe | 2005-06-30 15:16:28 +1000 | [diff] [blame] | 185 | HvCallEvent_getOverflowLpEvents(hvlpevent_queue.xIndex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | else |
| 187 | break; |
| 188 | } |
| 189 | |
| 190 | ItLpQueueInProcess = 0; |
| 191 | mb(); |
Michael Ellerman | 1b19bc7 | 2005-06-30 15:07:57 +1000 | [diff] [blame] | 192 | clear_inUse(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
Michael Ellerman | 0c885c1 | 2005-06-30 15:07:33 +1000 | [diff] [blame] | 194 | |
| 195 | static int set_spread_lpevents(char *str) |
| 196 | { |
| 197 | unsigned long val = simple_strtoul(str, NULL, 0); |
| 198 | |
| 199 | /* |
| 200 | * The parameter is the number of processors to share in processing |
| 201 | * lp events. |
| 202 | */ |
| 203 | if (( val > 0) && (val <= NR_CPUS)) { |
| 204 | spread_lpevents = val; |
| 205 | printk("lpevent processing spread over %ld processors\n", val); |
| 206 | } else { |
| 207 | printk("invalid spread_lpevents %ld\n", val); |
| 208 | } |
| 209 | |
| 210 | return 1; |
| 211 | } |
| 212 | __setup("spread_lpevents=", set_spread_lpevents); |
| 213 | |
Michael Ellerman | 512d31d | 2005-06-30 15:08:27 +1000 | [diff] [blame] | 214 | void setup_hvlpevent_queue(void) |
| 215 | { |
| 216 | void *eventStack; |
| 217 | |
| 218 | /* |
| 219 | * Allocate a page for the Event Stack. The Hypervisor needs the |
| 220 | * absolute real address, so we subtract out the KERNELBASE and add |
| 221 | * in the absolute real address of the kernel load area. |
| 222 | */ |
| 223 | eventStack = alloc_bootmem_pages(LpEventStackSize); |
| 224 | memset(eventStack, 0, LpEventStackSize); |
| 225 | |
| 226 | /* Invoke the hypervisor to initialize the event stack */ |
| 227 | HvCallEvent_setLpEventStack(0, eventStack, LpEventStackSize); |
| 228 | |
Michael Ellerman | a618746 | 2005-06-30 15:15:32 +1000 | [diff] [blame] | 229 | hvlpevent_queue.xSlicEventStackPtr = (char *)eventStack; |
| 230 | hvlpevent_queue.xSlicCurEventPtr = (char *)eventStack; |
| 231 | hvlpevent_queue.xSlicLastValidEventPtr = (char *)eventStack + |
Michael Ellerman | 512d31d | 2005-06-30 15:08:27 +1000 | [diff] [blame] | 232 | (LpEventStackSize - LpEventMaxSize); |
Michael Ellerman | a618746 | 2005-06-30 15:15:32 +1000 | [diff] [blame] | 233 | hvlpevent_queue.xIndex = 0; |
Michael Ellerman | 512d31d | 2005-06-30 15:08:27 +1000 | [diff] [blame] | 234 | } |
Michael Ellerman | 7b01328 | 2005-06-30 15:08:44 +1000 | [diff] [blame] | 235 | |
| 236 | static int proc_lpevents_show(struct seq_file *m, void *v) |
| 237 | { |
Michael Ellerman | ed09415 | 2005-06-30 15:16:09 +1000 | [diff] [blame] | 238 | int cpu, i; |
| 239 | unsigned long sum; |
| 240 | static unsigned long cpu_totals[NR_CPUS]; |
| 241 | |
| 242 | /* FIXME: do we care that there's no locking here? */ |
| 243 | sum = 0; |
| 244 | for_each_online_cpu(cpu) { |
| 245 | cpu_totals[cpu] = 0; |
| 246 | for (i = 0; i < HvLpEvent_Type_NumTypes; i++) { |
| 247 | cpu_totals[cpu] += per_cpu(hvlpevent_counts, cpu)[i]; |
| 248 | } |
| 249 | sum += cpu_totals[cpu]; |
| 250 | } |
Michael Ellerman | 7b01328 | 2005-06-30 15:08:44 +1000 | [diff] [blame] | 251 | |
| 252 | seq_printf(m, "LpEventQueue 0\n"); |
Michael Ellerman | ed09415 | 2005-06-30 15:16:09 +1000 | [diff] [blame] | 253 | seq_printf(m, " events processed:\t%lu\n", sum); |
Michael Ellerman | 7b01328 | 2005-06-30 15:08:44 +1000 | [diff] [blame] | 254 | |
Michael Ellerman | ed09415 | 2005-06-30 15:16:09 +1000 | [diff] [blame] | 255 | for (i = 0; i < HvLpEvent_Type_NumTypes; ++i) { |
| 256 | sum = 0; |
| 257 | for_each_online_cpu(cpu) { |
| 258 | sum += per_cpu(hvlpevent_counts, cpu)[i]; |
| 259 | } |
| 260 | |
Michael Ellerman | 9b04702 | 2005-06-30 15:16:18 +1000 | [diff] [blame] | 261 | seq_printf(m, " %-20s %10lu\n", event_types[i], sum); |
Michael Ellerman | ed09415 | 2005-06-30 15:16:09 +1000 | [diff] [blame] | 262 | } |
Michael Ellerman | 7b01328 | 2005-06-30 15:08:44 +1000 | [diff] [blame] | 263 | |
| 264 | seq_printf(m, "\n events processed by processor:\n"); |
| 265 | |
Michael Ellerman | ed09415 | 2005-06-30 15:16:09 +1000 | [diff] [blame] | 266 | for_each_online_cpu(cpu) { |
| 267 | seq_printf(m, " CPU%02d %10lu\n", cpu, cpu_totals[cpu]); |
| 268 | } |
Michael Ellerman | 7b01328 | 2005-06-30 15:08:44 +1000 | [diff] [blame] | 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | static int proc_lpevents_open(struct inode *inode, struct file *file) |
| 274 | { |
| 275 | return single_open(file, proc_lpevents_show, NULL); |
| 276 | } |
| 277 | |
| 278 | static struct file_operations proc_lpevents_operations = { |
| 279 | .open = proc_lpevents_open, |
| 280 | .read = seq_read, |
| 281 | .llseek = seq_lseek, |
| 282 | .release = single_release, |
| 283 | }; |
| 284 | |
| 285 | static int __init proc_lpevents_init(void) |
| 286 | { |
| 287 | struct proc_dir_entry *e; |
| 288 | |
| 289 | e = create_proc_entry("iSeries/lpevents", S_IFREG|S_IRUGO, NULL); |
| 290 | if (e) |
| 291 | e->proc_fops = &proc_lpevents_operations; |
| 292 | |
| 293 | return 0; |
| 294 | } |
| 295 | __initcall(proc_lpevents_init); |
| 296 | |