arnd@arndb.de | 0afacde | 2006-10-24 18:31:18 +0200 | [diff] [blame] | 1 | #define DEBUG |
| 2 | |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 3 | #include <linux/wait.h> |
| 4 | #include <linux/ptrace.h> |
| 5 | |
| 6 | #include <asm/spu.h> |
Jeremy Kerr | c6730ed | 2006-11-20 18:45:10 +0100 | [diff] [blame] | 7 | #include <asm/spu_priv1.h> |
| 8 | #include <asm/io.h> |
Dave Jones | cfff5b2 | 2006-03-31 23:53:09 -0500 | [diff] [blame] | 9 | #include <asm/unistd.h> |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 10 | |
| 11 | #include "spufs.h" |
| 12 | |
| 13 | /* interrupt-level stop callback function. */ |
| 14 | void spufs_stop_callback(struct spu *spu) |
| 15 | { |
| 16 | struct spu_context *ctx = spu->ctx; |
| 17 | |
| 18 | wake_up_all(&ctx->stop_wq); |
| 19 | } |
| 20 | |
| 21 | static inline int spu_stopped(struct spu_context *ctx, u32 * stat) |
| 22 | { |
| 23 | struct spu *spu; |
| 24 | u64 pte_fault; |
| 25 | |
| 26 | *stat = ctx->ops->status_read(ctx); |
| 27 | if (ctx->state != SPU_STATE_RUNNABLE) |
| 28 | return 1; |
| 29 | spu = ctx->spu; |
| 30 | pte_fault = spu->dsisr & |
| 31 | (MFC_DSISR_PTE_NOT_FOUND | MFC_DSISR_ACCESS_DENIED); |
Sebastian Siewior | be70317 | 2007-06-29 10:57:50 +1000 | [diff] [blame] | 32 | return (!(*stat & SPU_STATUS_RUNNING) || pte_fault || spu->class_0_pending) ? |
| 33 | 1 : 0; |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 34 | } |
| 35 | |
Jeremy Kerr | c6730ed | 2006-11-20 18:45:10 +0100 | [diff] [blame] | 36 | static int spu_setup_isolated(struct spu_context *ctx) |
| 37 | { |
| 38 | int ret; |
| 39 | u64 __iomem *mfc_cntl; |
| 40 | u64 sr1; |
| 41 | u32 status; |
| 42 | unsigned long timeout; |
| 43 | const u32 status_loading = SPU_STATUS_RUNNING |
| 44 | | SPU_STATUS_ISOLATED_STATE | SPU_STATUS_ISOLATED_LOAD_STATUS; |
| 45 | |
Christoph Hellwig | 7ec18ab | 2007-04-23 21:08:12 +0200 | [diff] [blame] | 46 | ret = -ENODEV; |
Jeremy Kerr | c6730ed | 2006-11-20 18:45:10 +0100 | [diff] [blame] | 47 | if (!isolated_loader) |
Jeremy Kerr | c6730ed | 2006-11-20 18:45:10 +0100 | [diff] [blame] | 48 | goto out; |
| 49 | |
Christoph Hellwig | 7ec18ab | 2007-04-23 21:08:12 +0200 | [diff] [blame] | 50 | /* |
| 51 | * We need to exclude userspace access to the context. |
| 52 | * |
| 53 | * To protect against memory access we invalidate all ptes |
| 54 | * and make sure the pagefault handlers block on the mutex. |
| 55 | */ |
| 56 | spu_unmap_mappings(ctx); |
| 57 | |
Jeremy Kerr | c6730ed | 2006-11-20 18:45:10 +0100 | [diff] [blame] | 58 | mfc_cntl = &ctx->spu->priv2->mfc_control_RW; |
| 59 | |
| 60 | /* purge the MFC DMA queue to ensure no spurious accesses before we |
| 61 | * enter kernel mode */ |
| 62 | timeout = jiffies + HZ; |
| 63 | out_be64(mfc_cntl, MFC_CNTL_PURGE_DMA_REQUEST); |
| 64 | while ((in_be64(mfc_cntl) & MFC_CNTL_PURGE_DMA_STATUS_MASK) |
| 65 | != MFC_CNTL_PURGE_DMA_COMPLETE) { |
| 66 | if (time_after(jiffies, timeout)) { |
| 67 | printk(KERN_ERR "%s: timeout flushing MFC DMA queue\n", |
| 68 | __FUNCTION__); |
| 69 | ret = -EIO; |
Christoph Hellwig | 7ec18ab | 2007-04-23 21:08:12 +0200 | [diff] [blame] | 70 | goto out; |
Jeremy Kerr | c6730ed | 2006-11-20 18:45:10 +0100 | [diff] [blame] | 71 | } |
| 72 | cond_resched(); |
| 73 | } |
| 74 | |
| 75 | /* put the SPE in kernel mode to allow access to the loader */ |
| 76 | sr1 = spu_mfc_sr1_get(ctx->spu); |
| 77 | sr1 &= ~MFC_STATE1_PROBLEM_STATE_MASK; |
| 78 | spu_mfc_sr1_set(ctx->spu, sr1); |
| 79 | |
| 80 | /* start the loader */ |
| 81 | ctx->ops->signal1_write(ctx, (unsigned long)isolated_loader >> 32); |
| 82 | ctx->ops->signal2_write(ctx, |
| 83 | (unsigned long)isolated_loader & 0xffffffff); |
| 84 | |
| 85 | ctx->ops->runcntl_write(ctx, |
| 86 | SPU_RUNCNTL_RUNNABLE | SPU_RUNCNTL_ISOLATE); |
| 87 | |
| 88 | ret = 0; |
| 89 | timeout = jiffies + HZ; |
| 90 | while (((status = ctx->ops->status_read(ctx)) & status_loading) == |
| 91 | status_loading) { |
| 92 | if (time_after(jiffies, timeout)) { |
| 93 | printk(KERN_ERR "%s: timeout waiting for loader\n", |
| 94 | __FUNCTION__); |
| 95 | ret = -EIO; |
| 96 | goto out_drop_priv; |
| 97 | } |
| 98 | cond_resched(); |
| 99 | } |
| 100 | |
| 101 | if (!(status & SPU_STATUS_RUNNING)) { |
| 102 | /* If isolated LOAD has failed: run SPU, we will get a stop-and |
| 103 | * signal later. */ |
| 104 | pr_debug("%s: isolated LOAD failed\n", __FUNCTION__); |
| 105 | ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_RUNNABLE); |
| 106 | ret = -EACCES; |
Christoph Hellwig | 7ec18ab | 2007-04-23 21:08:12 +0200 | [diff] [blame] | 107 | goto out_drop_priv; |
| 108 | } |
Jeremy Kerr | c6730ed | 2006-11-20 18:45:10 +0100 | [diff] [blame] | 109 | |
Christoph Hellwig | 7ec18ab | 2007-04-23 21:08:12 +0200 | [diff] [blame] | 110 | if (!(status & SPU_STATUS_ISOLATED_STATE)) { |
Jeremy Kerr | c6730ed | 2006-11-20 18:45:10 +0100 | [diff] [blame] | 111 | /* This isn't allowed by the CBEA, but check anyway */ |
| 112 | pr_debug("%s: SPU fell out of isolated mode?\n", __FUNCTION__); |
| 113 | ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_STOP); |
| 114 | ret = -EINVAL; |
Christoph Hellwig | 7ec18ab | 2007-04-23 21:08:12 +0200 | [diff] [blame] | 115 | goto out_drop_priv; |
Jeremy Kerr | c6730ed | 2006-11-20 18:45:10 +0100 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | out_drop_priv: |
| 119 | /* Finished accessing the loader. Drop kernel mode */ |
| 120 | sr1 |= MFC_STATE1_PROBLEM_STATE_MASK; |
| 121 | spu_mfc_sr1_set(ctx->spu, sr1); |
| 122 | |
Jeremy Kerr | c6730ed | 2006-11-20 18:45:10 +0100 | [diff] [blame] | 123 | out: |
| 124 | return ret; |
| 125 | } |
| 126 | |
Christoph Hellwig | aa45e25 | 2007-04-23 21:08:27 +0200 | [diff] [blame] | 127 | static int spu_run_init(struct spu_context *ctx, u32 * npc) |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 128 | { |
Jeremy Kerr | c6730ed | 2006-11-20 18:45:10 +0100 | [diff] [blame] | 129 | if (ctx->flags & SPU_CREATE_ISOLATE) { |
Christoph Hellwig | aa45e25 | 2007-04-23 21:08:27 +0200 | [diff] [blame] | 130 | unsigned long runcntl; |
| 131 | |
Jeremy Kerr | c6730ed | 2006-11-20 18:45:10 +0100 | [diff] [blame] | 132 | if (!(ctx->ops->status_read(ctx) & SPU_STATUS_ISOLATED_STATE)) { |
Christoph Hellwig | aa45e25 | 2007-04-23 21:08:27 +0200 | [diff] [blame] | 133 | int ret = spu_setup_isolated(ctx); |
Christoph Hellwig | 7ec18ab | 2007-04-23 21:08:12 +0200 | [diff] [blame] | 134 | if (ret) |
Christoph Hellwig | aa45e25 | 2007-04-23 21:08:27 +0200 | [diff] [blame] | 135 | return ret; |
Jeremy Kerr | c6730ed | 2006-11-20 18:45:10 +0100 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /* if userspace has set the runcntrl register (eg, to issue an |
| 139 | * isolated exit), we need to re-set it here */ |
| 140 | runcntl = ctx->ops->runcntl_read(ctx) & |
| 141 | (SPU_RUNCNTL_RUNNABLE | SPU_RUNCNTL_ISOLATE); |
| 142 | if (runcntl == 0) |
| 143 | runcntl = SPU_RUNCNTL_RUNNABLE; |
Christoph Hellwig | aa45e25 | 2007-04-23 21:08:27 +0200 | [diff] [blame] | 144 | ctx->ops->runcntl_write(ctx, runcntl); |
Christoph Hellwig | 2eb1b12 | 2007-02-13 21:54:29 +0100 | [diff] [blame] | 145 | } else { |
Benjamin Herrenschmidt | 0516923 | 2007-06-04 15:15:37 +1000 | [diff] [blame] | 146 | unsigned long mode = SPU_PRIVCNTL_MODE_NORMAL; |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 147 | ctx->ops->npc_write(ctx, *npc); |
Benjamin Herrenschmidt | 0516923 | 2007-06-04 15:15:37 +1000 | [diff] [blame] | 148 | if (test_thread_flag(TIF_SINGLESTEP)) |
| 149 | mode = SPU_PRIVCNTL_MODE_SINGLE_STEP; |
| 150 | out_be64(&ctx->spu->priv2->spu_privcntl_RW, mode); |
Christoph Hellwig | aa45e25 | 2007-04-23 21:08:27 +0200 | [diff] [blame] | 151 | ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_RUNNABLE); |
Christoph Hellwig | 2eb1b12 | 2007-02-13 21:54:29 +0100 | [diff] [blame] | 152 | } |
Jeremy Kerr | c6730ed | 2006-11-20 18:45:10 +0100 | [diff] [blame] | 153 | |
Christoph Hellwig | aa45e25 | 2007-04-23 21:08:27 +0200 | [diff] [blame] | 154 | return 0; |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 155 | } |
| 156 | |
Christoph Hellwig | aa45e25 | 2007-04-23 21:08:27 +0200 | [diff] [blame] | 157 | static int spu_run_fini(struct spu_context *ctx, u32 * npc, |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 158 | u32 * status) |
| 159 | { |
| 160 | int ret = 0; |
| 161 | |
| 162 | *status = ctx->ops->status_read(ctx); |
| 163 | *npc = ctx->ops->npc_read(ctx); |
| 164 | spu_release(ctx); |
| 165 | |
| 166 | if (signal_pending(current)) |
| 167 | ret = -ERESTARTSYS; |
Masato Noguchi | 2ebb247 | 2006-11-20 18:45:04 +0100 | [diff] [blame] | 168 | |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 169 | return ret; |
| 170 | } |
| 171 | |
Christoph Hellwig | aa45e25 | 2007-04-23 21:08:27 +0200 | [diff] [blame] | 172 | static int spu_reacquire_runnable(struct spu_context *ctx, u32 *npc, |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 173 | u32 *status) |
| 174 | { |
| 175 | int ret; |
| 176 | |
Christoph Hellwig | aa45e25 | 2007-04-23 21:08:27 +0200 | [diff] [blame] | 177 | ret = spu_run_fini(ctx, npc, status); |
| 178 | if (ret) |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 179 | return ret; |
Christoph Hellwig | aa45e25 | 2007-04-23 21:08:27 +0200 | [diff] [blame] | 180 | |
| 181 | if (*status & (SPU_STATUS_STOPPED_BY_STOP | SPU_STATUS_STOPPED_BY_HALT)) |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 182 | return *status; |
Christoph Hellwig | aa45e25 | 2007-04-23 21:08:27 +0200 | [diff] [blame] | 183 | |
| 184 | ret = spu_acquire_runnable(ctx, 0); |
| 185 | if (ret) |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 186 | return ret; |
Christoph Hellwig | aa45e25 | 2007-04-23 21:08:27 +0200 | [diff] [blame] | 187 | |
| 188 | ret = spu_run_init(ctx, npc); |
| 189 | if (ret) { |
| 190 | spu_release(ctx); |
| 191 | return ret; |
| 192 | } |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 193 | return 0; |
| 194 | } |
| 195 | |
Arnd Bergmann | 2dd1493 | 2006-03-23 00:00:09 +0100 | [diff] [blame] | 196 | /* |
| 197 | * SPU syscall restarting is tricky because we violate the basic |
| 198 | * assumption that the signal handler is running on the interrupted |
| 199 | * thread. Here instead, the handler runs on PowerPC user space code, |
| 200 | * while the syscall was called from the SPU. |
| 201 | * This means we can only do a very rough approximation of POSIX |
| 202 | * signal semantics. |
| 203 | */ |
| 204 | int spu_handle_restartsys(struct spu_context *ctx, long *spu_ret, |
| 205 | unsigned int *npc) |
| 206 | { |
| 207 | int ret; |
| 208 | |
| 209 | switch (*spu_ret) { |
| 210 | case -ERESTARTSYS: |
| 211 | case -ERESTARTNOINTR: |
| 212 | /* |
| 213 | * Enter the regular syscall restarting for |
| 214 | * sys_spu_run, then restart the SPU syscall |
| 215 | * callback. |
| 216 | */ |
| 217 | *npc -= 8; |
| 218 | ret = -ERESTARTSYS; |
| 219 | break; |
| 220 | case -ERESTARTNOHAND: |
| 221 | case -ERESTART_RESTARTBLOCK: |
| 222 | /* |
| 223 | * Restart block is too hard for now, just return -EINTR |
| 224 | * to the SPU. |
| 225 | * ERESTARTNOHAND comes from sys_pause, we also return |
| 226 | * -EINTR from there. |
| 227 | * Assume that we need to be restarted ourselves though. |
| 228 | */ |
| 229 | *spu_ret = -EINTR; |
| 230 | ret = -ERESTARTSYS; |
| 231 | break; |
| 232 | default: |
| 233 | printk(KERN_WARNING "%s: unexpected return code %ld\n", |
| 234 | __FUNCTION__, *spu_ret); |
| 235 | ret = 0; |
| 236 | } |
| 237 | return ret; |
| 238 | } |
| 239 | |
| 240 | int spu_process_callback(struct spu_context *ctx) |
| 241 | { |
| 242 | struct spu_syscall_block s; |
| 243 | u32 ls_pointer, npc; |
Akinobu Mita | 9e2fe2c | 2007-04-23 21:08:22 +0200 | [diff] [blame] | 244 | void __iomem *ls; |
Arnd Bergmann | 2dd1493 | 2006-03-23 00:00:09 +0100 | [diff] [blame] | 245 | long spu_ret; |
| 246 | int ret; |
| 247 | |
| 248 | /* get syscall block from local store */ |
Akinobu Mita | 9e2fe2c | 2007-04-23 21:08:22 +0200 | [diff] [blame] | 249 | npc = ctx->ops->npc_read(ctx) & ~3; |
| 250 | ls = (void __iomem *)ctx->ops->get_ls(ctx); |
| 251 | ls_pointer = in_be32(ls + npc); |
Arnd Bergmann | 2dd1493 | 2006-03-23 00:00:09 +0100 | [diff] [blame] | 252 | if (ls_pointer > (LS_SIZE - sizeof(s))) |
| 253 | return -EFAULT; |
Akinobu Mita | 9e2fe2c | 2007-04-23 21:08:22 +0200 | [diff] [blame] | 254 | memcpy_fromio(&s, ls + ls_pointer, sizeof(s)); |
Arnd Bergmann | 2dd1493 | 2006-03-23 00:00:09 +0100 | [diff] [blame] | 255 | |
| 256 | /* do actual syscall without pinning the spu */ |
| 257 | ret = 0; |
| 258 | spu_ret = -ENOSYS; |
| 259 | npc += 4; |
| 260 | |
| 261 | if (s.nr_ret < __NR_syscalls) { |
| 262 | spu_release(ctx); |
| 263 | /* do actual system call from here */ |
| 264 | spu_ret = spu_sys_callback(&s); |
| 265 | if (spu_ret <= -ERESTARTSYS) { |
| 266 | ret = spu_handle_restartsys(ctx, &spu_ret, &npc); |
| 267 | } |
| 268 | spu_acquire(ctx); |
| 269 | if (ret == -ERESTARTSYS) |
| 270 | return ret; |
| 271 | } |
| 272 | |
| 273 | /* write result, jump over indirect pointer */ |
Akinobu Mita | 9e2fe2c | 2007-04-23 21:08:22 +0200 | [diff] [blame] | 274 | memcpy_toio(ls + ls_pointer, &spu_ret, sizeof(spu_ret)); |
Arnd Bergmann | 2dd1493 | 2006-03-23 00:00:09 +0100 | [diff] [blame] | 275 | ctx->ops->npc_write(ctx, npc); |
| 276 | ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_RUNNABLE); |
| 277 | return ret; |
| 278 | } |
| 279 | |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 280 | static inline int spu_process_events(struct spu_context *ctx) |
| 281 | { |
| 282 | struct spu *spu = ctx->spu; |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 283 | int ret = 0; |
| 284 | |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 285 | if (spu->class_0_pending) |
| 286 | ret = spu_irq_class_0_bottom(spu); |
| 287 | if (!ret && signal_pending(current)) |
| 288 | ret = -ERESTARTSYS; |
| 289 | return ret; |
| 290 | } |
| 291 | |
| 292 | long spufs_run_spu(struct file *file, struct spu_context *ctx, |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 293 | u32 *npc, u32 *event) |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 294 | { |
| 295 | int ret; |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 296 | u32 status; |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 297 | |
Christoph Hellwig | e45d48a | 2007-04-23 21:08:17 +0200 | [diff] [blame] | 298 | if (mutex_lock_interruptible(&ctx->run_mutex)) |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 299 | return -ERESTARTSYS; |
| 300 | |
Arnd Bergmann | ee2d734 | 2006-11-20 18:45:08 +0100 | [diff] [blame] | 301 | ctx->ops->master_start(ctx); |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 302 | ctx->event_return = 0; |
Christoph Hellwig | aa45e25 | 2007-04-23 21:08:27 +0200 | [diff] [blame] | 303 | |
Christoph Hellwig | 2cf2b3b | 2007-06-29 10:57:55 +1000 | [diff] [blame] | 304 | spu_acquire(ctx); |
| 305 | if (ctx->state == SPU_STATE_SAVED) { |
| 306 | __spu_update_sched_info(ctx); |
| 307 | |
| 308 | ret = spu_activate(ctx, 0); |
| 309 | if (ret) { |
| 310 | spu_release(ctx); |
| 311 | goto out; |
| 312 | } |
| 313 | } else { |
| 314 | /* |
| 315 | * We have to update the scheduling priority under active_mutex |
| 316 | * to protect against find_victim(). |
| 317 | */ |
| 318 | spu_update_sched_info(ctx); |
| 319 | } |
Christoph Hellwig | aa45e25 | 2007-04-23 21:08:27 +0200 | [diff] [blame] | 320 | |
| 321 | ret = spu_run_init(ctx, npc); |
| 322 | if (ret) { |
| 323 | spu_release(ctx); |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 324 | goto out; |
Christoph Hellwig | aa45e25 | 2007-04-23 21:08:27 +0200 | [diff] [blame] | 325 | } |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 326 | |
| 327 | do { |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 328 | ret = spufs_wait(ctx->stop_wq, spu_stopped(ctx, &status)); |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 329 | if (unlikely(ret)) |
| 330 | break; |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 331 | if ((status & SPU_STATUS_STOPPED_BY_STOP) && |
| 332 | (status >> SPU_STOP_STATUS_SHIFT == 0x2104)) { |
Arnd Bergmann | 2dd1493 | 2006-03-23 00:00:09 +0100 | [diff] [blame] | 333 | ret = spu_process_callback(ctx); |
| 334 | if (ret) |
| 335 | break; |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 336 | status &= ~SPU_STATUS_STOPPED_BY_STOP; |
Arnd Bergmann | 2dd1493 | 2006-03-23 00:00:09 +0100 | [diff] [blame] | 337 | } |
Arnd Bergmann | 57dace2 | 2007-04-23 21:08:15 +0200 | [diff] [blame] | 338 | ret = spufs_handle_class1(ctx); |
| 339 | if (ret) |
| 340 | break; |
| 341 | |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 342 | if (unlikely(ctx->state != SPU_STATE_RUNNABLE)) { |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 343 | ret = spu_reacquire_runnable(ctx, npc, &status); |
Christoph Hellwig | 3790180 | 2007-06-29 10:57:51 +1000 | [diff] [blame] | 344 | if (ret) |
Masato Noguchi | 2ebb247 | 2006-11-20 18:45:04 +0100 | [diff] [blame] | 345 | goto out2; |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 346 | continue; |
| 347 | } |
| 348 | ret = spu_process_events(ctx); |
| 349 | |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 350 | } while (!ret && !(status & (SPU_STATUS_STOPPED_BY_STOP | |
Benjamin Herrenschmidt | 0516923 | 2007-06-04 15:15:37 +1000 | [diff] [blame] | 351 | SPU_STATUS_STOPPED_BY_HALT | |
| 352 | SPU_STATUS_SINGLE_STEP))); |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 353 | |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 354 | if ((status & SPU_STATUS_STOPPED_BY_STOP) && |
Christoph Hellwig | fe2f896 | 2007-06-29 10:58:07 +1000 | [diff] [blame] | 355 | (((status >> SPU_STOP_STATUS_SHIFT) & 0x3f00) == 0x2100) && |
| 356 | (ctx->state == SPU_STATE_RUNNABLE)) |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 357 | ctx->stats.libassist++; |
| 358 | |
Arnd Bergmann | ee2d734 | 2006-11-20 18:45:08 +0100 | [diff] [blame] | 359 | ctx->ops->master_stop(ctx); |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 360 | ret = spu_run_fini(ctx, npc, &status); |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 361 | spu_yield(ctx); |
| 362 | |
Masato Noguchi | 2ebb247 | 2006-11-20 18:45:04 +0100 | [diff] [blame] | 363 | out2: |
| 364 | if ((ret == 0) || |
| 365 | ((ret == -ERESTARTSYS) && |
| 366 | ((status & SPU_STATUS_STOPPED_BY_HALT) || |
Benjamin Herrenschmidt | 0516923 | 2007-06-04 15:15:37 +1000 | [diff] [blame] | 367 | (status & SPU_STATUS_SINGLE_STEP) || |
Masato Noguchi | 2ebb247 | 2006-11-20 18:45:04 +0100 | [diff] [blame] | 368 | ((status & SPU_STATUS_STOPPED_BY_STOP) && |
| 369 | (status >> SPU_STOP_STATUS_SHIFT != 0x2104))))) |
| 370 | ret = status; |
| 371 | |
Benjamin Herrenschmidt | 0516923 | 2007-06-04 15:15:37 +1000 | [diff] [blame] | 372 | /* Note: we don't need to force_sig SIGTRAP on single-step |
| 373 | * since we have TIF_SINGLESTEP set, thus the kernel will do |
| 374 | * it upon return from the syscall anyawy |
| 375 | */ |
Arnd Bergmann | c2b2226 | 2006-11-27 19:18:53 +0100 | [diff] [blame] | 376 | if ((status & SPU_STATUS_STOPPED_BY_STOP) |
| 377 | && (status >> SPU_STOP_STATUS_SHIFT) == 0x3fff) { |
| 378 | force_sig(SIGTRAP, current); |
| 379 | ret = -ERESTARTSYS; |
Masato Noguchi | 2ebb247 | 2006-11-20 18:45:04 +0100 | [diff] [blame] | 380 | } |
| 381 | |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 382 | out: |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 383 | *event = ctx->event_return; |
Christoph Hellwig | e45d48a | 2007-04-23 21:08:17 +0200 | [diff] [blame] | 384 | mutex_unlock(&ctx->run_mutex); |
Arnd Bergmann | ce8ab85 | 2006-01-04 20:31:29 +0100 | [diff] [blame] | 385 | return ret; |
| 386 | } |