diff options
author | Ben Widawsky <ben@bwidawsk.net> | 2012-06-29 13:30:39 -0400 |
---|---|---|
committer | Daniel Vetter <daniel.vetter@ffwll.ch> | 2012-06-29 13:43:59 -0400 |
commit | 146937e5828ede495e11ba3a6f4a01b36b7166dc (patch) | |
tree | e2e3ac42e89e9445e6f22ca5d1d5edef9b41b228 /drivers/gpu/drm/i915/i915_gem_context.c | |
parent | e486fad9136dce21f5ba4322ae0454d23805d342 (diff) |
drm/i915: linuxify create_hw_context()
Daniel complained about this on initial review, but he graciously moved
the patches forward. As promised, I am delivering the desired cleanup
now.
Hopefully I didn't screw the trivial patch up ;-)
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'drivers/gpu/drm/i915/i915_gem_context.c')
-rw-r--r-- | drivers/gpu/drm/i915/i915_gem_context.c | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c index e58e8366f47..9ae3f2cf414 100644 --- a/drivers/gpu/drm/i915/i915_gem_context.c +++ b/drivers/gpu/drm/i915/i915_gem_context.c | |||
@@ -136,37 +136,36 @@ static void do_destroy(struct i915_hw_context *ctx) | |||
136 | kfree(ctx); | 136 | kfree(ctx); |
137 | } | 137 | } |
138 | 138 | ||
139 | static int | 139 | static struct i915_hw_context * |
140 | create_hw_context(struct drm_device *dev, | 140 | create_hw_context(struct drm_device *dev, |
141 | struct drm_i915_file_private *file_priv, | 141 | struct drm_i915_file_private *file_priv) |
142 | struct i915_hw_context **ctx_out) | ||
143 | { | 142 | { |
144 | struct drm_i915_private *dev_priv = dev->dev_private; | 143 | struct drm_i915_private *dev_priv = dev->dev_private; |
144 | struct i915_hw_context *ctx; | ||
145 | int ret, id; | 145 | int ret, id; |
146 | 146 | ||
147 | *ctx_out = kzalloc(sizeof(struct drm_i915_file_private), GFP_KERNEL); | 147 | ctx = kzalloc(sizeof(struct drm_i915_file_private), GFP_KERNEL); |
148 | if (*ctx_out == NULL) | 148 | if (ctx == NULL) |
149 | return -ENOMEM; | 149 | return ERR_PTR(-ENOMEM); |
150 | 150 | ||
151 | (*ctx_out)->obj = i915_gem_alloc_object(dev, | 151 | ctx->obj = i915_gem_alloc_object(dev, dev_priv->hw_context_size); |
152 | dev_priv->hw_context_size); | 152 | if (ctx->obj == NULL) { |
153 | if ((*ctx_out)->obj == NULL) { | 153 | kfree(ctx); |
154 | kfree(*ctx_out); | ||
155 | DRM_DEBUG_DRIVER("Context object allocated failed\n"); | 154 | DRM_DEBUG_DRIVER("Context object allocated failed\n"); |
156 | return -ENOMEM; | 155 | return ERR_PTR(-ENOMEM); |
157 | } | 156 | } |
158 | 157 | ||
159 | /* The ring associated with the context object is handled by the normal | 158 | /* The ring associated with the context object is handled by the normal |
160 | * object tracking code. We give an initial ring value simple to pass an | 159 | * object tracking code. We give an initial ring value simple to pass an |
161 | * assertion in the context switch code. | 160 | * assertion in the context switch code. |
162 | */ | 161 | */ |
163 | (*ctx_out)->ring = &dev_priv->ring[RCS]; | 162 | ctx->ring = &dev_priv->ring[RCS]; |
164 | 163 | ||
165 | /* Default context will never have a file_priv */ | 164 | /* Default context will never have a file_priv */ |
166 | if (file_priv == NULL) | 165 | if (file_priv == NULL) |
167 | return 0; | 166 | return ctx; |
168 | 167 | ||
169 | (*ctx_out)->file_priv = file_priv; | 168 | ctx->file_priv = file_priv; |
170 | 169 | ||
171 | again: | 170 | again: |
172 | if (idr_pre_get(&file_priv->context_idr, GFP_KERNEL) == 0) { | 171 | if (idr_pre_get(&file_priv->context_idr, GFP_KERNEL) == 0) { |
@@ -175,21 +174,21 @@ again: | |||
175 | goto err_out; | 174 | goto err_out; |
176 | } | 175 | } |
177 | 176 | ||
178 | ret = idr_get_new_above(&file_priv->context_idr, *ctx_out, | 177 | ret = idr_get_new_above(&file_priv->context_idr, ctx, |
179 | DEFAULT_CONTEXT_ID + 1, &id); | 178 | DEFAULT_CONTEXT_ID + 1, &id); |
180 | if (ret == 0) | 179 | if (ret == 0) |
181 | (*ctx_out)->id = id; | 180 | ctx->id = id; |
182 | 181 | ||
183 | if (ret == -EAGAIN) | 182 | if (ret == -EAGAIN) |
184 | goto again; | 183 | goto again; |
185 | else if (ret) | 184 | else if (ret) |
186 | goto err_out; | 185 | goto err_out; |
187 | 186 | ||
188 | return 0; | 187 | return ctx; |
189 | 188 | ||
190 | err_out: | 189 | err_out: |
191 | do_destroy(*ctx_out); | 190 | do_destroy(ctx); |
192 | return ret; | 191 | return ERR_PTR(ret); |
193 | } | 192 | } |
194 | 193 | ||
195 | static inline bool is_default_context(struct i915_hw_context *ctx) | 194 | static inline bool is_default_context(struct i915_hw_context *ctx) |
@@ -209,10 +208,9 @@ static int create_default_context(struct drm_i915_private *dev_priv) | |||
209 | 208 | ||
210 | BUG_ON(!mutex_is_locked(&dev_priv->dev->struct_mutex)); | 209 | BUG_ON(!mutex_is_locked(&dev_priv->dev->struct_mutex)); |
211 | 210 | ||
212 | ret = create_hw_context(dev_priv->dev, NULL, | 211 | ctx = create_hw_context(dev_priv->dev, NULL); |
213 | &dev_priv->ring[RCS].default_context); | 212 | if (IS_ERR(ctx)) |
214 | if (ret) | 213 | return PTR_ERR(ctx); |
215 | return ret; | ||
216 | 214 | ||
217 | /* We may need to do things with the shrinker which require us to | 215 | /* We may need to do things with the shrinker which require us to |
218 | * immediately switch back to the default context. This can cause a | 216 | * immediately switch back to the default context. This can cause a |
@@ -220,7 +218,7 @@ static int create_default_context(struct drm_i915_private *dev_priv) | |||
220 | * may not be available. To avoid this we always pin the | 218 | * may not be available. To avoid this we always pin the |
221 | * default context. | 219 | * default context. |
222 | */ | 220 | */ |
223 | ctx = dev_priv->ring[RCS].default_context; | 221 | dev_priv->ring[RCS].default_context = ctx; |
224 | ret = i915_gem_object_pin(ctx->obj, CONTEXT_ALIGN, false); | 222 | ret = i915_gem_object_pin(ctx->obj, CONTEXT_ALIGN, false); |
225 | if (ret) { | 223 | if (ret) { |
226 | do_destroy(ctx); | 224 | do_destroy(ctx); |
@@ -496,13 +494,13 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data, | |||
496 | if (ret) | 494 | if (ret) |
497 | return ret; | 495 | return ret; |
498 | 496 | ||
499 | ret = create_hw_context(dev, file_priv, &ctx); | 497 | ctx = create_hw_context(dev, file_priv); |
500 | mutex_unlock(&dev->struct_mutex); | 498 | mutex_unlock(&dev->struct_mutex); |
501 | 499 | ||
502 | args->ctx_id = ctx->id; | 500 | args->ctx_id = ctx->id; |
503 | DRM_DEBUG_DRIVER("HW context %d created\n", args->ctx_id); | 501 | DRM_DEBUG_DRIVER("HW context %d created\n", args->ctx_id); |
504 | 502 | ||
505 | return ret; | 503 | return PTR_RET(ctx); |
506 | } | 504 | } |
507 | 505 | ||
508 | int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data, | 506 | int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data, |