Lines Matching refs:ctx

27 	struct spu_context *ctx;
29 ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
30 if (!ctx)
35 if (spu_init_csa(&ctx->csa))
37 spin_lock_init(&ctx->mmio_lock);
38 mutex_init(&ctx->mapping_lock);
39 kref_init(&ctx->kref);
40 mutex_init(&ctx->state_mutex);
41 mutex_init(&ctx->run_mutex);
42 init_waitqueue_head(&ctx->ibox_wq);
43 init_waitqueue_head(&ctx->wbox_wq);
44 init_waitqueue_head(&ctx->stop_wq);
45 init_waitqueue_head(&ctx->mfc_wq);
46 init_waitqueue_head(&ctx->run_wq);
47 ctx->state = SPU_STATE_SAVED;
48 ctx->ops = &spu_backing_ops;
49 ctx->owner = get_task_mm(current);
50 INIT_LIST_HEAD(&ctx->rq);
51 INIT_LIST_HEAD(&ctx->aff_list);
53 spu_gang_add_ctx(gang, ctx);
55 __spu_update_sched_info(ctx);
56 spu_set_timeslice(ctx);
57 ctx->stats.util_state = SPU_UTIL_IDLE_LOADED;
58 ctx->stats.tstamp = ktime_get_ns();
63 kfree(ctx);
64 ctx = NULL;
66 return ctx;
71 struct spu_context *ctx;
72 ctx = container_of(kref, struct spu_context, kref);
73 spu_context_nospu_trace(destroy_spu_context__enter, ctx);
74 mutex_lock(&ctx->state_mutex);
75 spu_deactivate(ctx);
76 mutex_unlock(&ctx->state_mutex);
77 spu_fini_csa(&ctx->csa);
78 if (ctx->gang)
79 spu_gang_remove_ctx(ctx->gang, ctx);
80 if (ctx->prof_priv_kref)
81 kref_put(ctx->prof_priv_kref, ctx->prof_priv_release);
82 BUG_ON(!list_empty(&ctx->rq));
84 kfree(ctx->switch_log);
85 kfree(ctx);
88 struct spu_context * get_spu_context(struct spu_context *ctx)
90 kref_get(&ctx->kref);
91 return ctx;
94 int put_spu_context(struct spu_context *ctx)
96 return kref_put(&ctx->kref, &destroy_spu_context);
100 void spu_forget(struct spu_context *ctx)
109 mutex_lock(&ctx->state_mutex);
110 if (ctx->state != SPU_STATE_SAVED)
111 spu_deactivate(ctx);
113 mm = ctx->owner;
114 ctx->owner = NULL;
116 spu_release(ctx);
119 void spu_unmap_mappings(struct spu_context *ctx)
121 mutex_lock(&ctx->mapping_lock);
122 if (ctx->local_store)
123 unmap_mapping_range(ctx->local_store, 0, LS_SIZE, 1);
124 if (ctx->mfc)
125 unmap_mapping_range(ctx->mfc, 0, SPUFS_MFC_MAP_SIZE, 1);
126 if (ctx->cntl)
127 unmap_mapping_range(ctx->cntl, 0, SPUFS_CNTL_MAP_SIZE, 1);
128 if (ctx->signal1)
129 unmap_mapping_range(ctx->signal1, 0, SPUFS_SIGNAL_MAP_SIZE, 1);
130 if (ctx->signal2)
131 unmap_mapping_range(ctx->signal2, 0, SPUFS_SIGNAL_MAP_SIZE, 1);
132 if (ctx->mss)
133 unmap_mapping_range(ctx->mss, 0, SPUFS_MSS_MAP_SIZE, 1);
134 if (ctx->psmap)
135 unmap_mapping_range(ctx->psmap, 0, SPUFS_PS_MAP_SIZE, 1);
136 mutex_unlock(&ctx->mapping_lock);
141 * @ctx: spu contex to lock
143 int spu_acquire_saved(struct spu_context *ctx)
147 spu_context_nospu_trace(spu_acquire_saved__enter, ctx);
149 ret = spu_acquire(ctx);
153 if (ctx->state != SPU_STATE_SAVED) {
154 set_bit(SPU_SCHED_WAS_ACTIVE, &ctx->sched_flags);
155 spu_deactivate(ctx);
163 * @ctx: context to unlock
165 void spu_release_saved(struct spu_context *ctx)
167 BUG_ON(ctx->state != SPU_STATE_SAVED);
169 if (test_and_clear_bit(SPU_SCHED_WAS_ACTIVE, &ctx->sched_flags) &&
170 test_bit(SPU_SCHED_SPU_RUN, &ctx->sched_flags))
171 spu_activate(ctx, 0);
173 spu_release(ctx);