Skip to content

Commit c21eb21

Browse files
committed
Revert "drm: mark context support as a legacy subsystem"
This reverts commit 7c51013. Well looks like not enough digging was done, libdrm_nouveau before 2.4.33 used contexts, 292da616fe1f936ca78a3fa8e1b1b19883e343b6 nouveau: pull in major libdrm rewrite got rid of them, Reported-by: Paul Zimmerman <Paul.Zimmerman@synopsys.com> Reported-by: Mikael Pettersson <mikpe@it.uu.se> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent 928c2f0 commit c21eb21

File tree

4 files changed

+39
-72
lines changed

4 files changed

+39
-72
lines changed

drivers/gpu/drm/drm_context.c

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242

4343
#include <drm/drmP.h>
4444

45+
/******************************************************************/
46+
/** \name Context bitmap support */
47+
/*@{*/
48+
4549
/**
4650
* Free a handle from the context bitmap.
4751
*
@@ -52,48 +56,13 @@
5256
* in drm_device::ctx_idr, while holding the drm_device::struct_mutex
5357
* lock.
5458
*/
55-
static void drm_ctxbitmap_free(struct drm_device * dev, int ctx_handle)
59+
void drm_ctxbitmap_free(struct drm_device * dev, int ctx_handle)
5660
{
57-
if (drm_core_check_feature(dev, DRIVER_MODESET))
58-
return;
59-
6061
mutex_lock(&dev->struct_mutex);
6162
idr_remove(&dev->ctx_idr, ctx_handle);
6263
mutex_unlock(&dev->struct_mutex);
6364
}
6465

65-
/******************************************************************/
66-
/** \name Context bitmap support */
67-
/*@{*/
68-
69-
void drm_legacy_ctxbitmap_release(struct drm_device *dev,
70-
struct drm_file *file_priv)
71-
{
72-
if (drm_core_check_feature(dev, DRIVER_MODESET))
73-
return;
74-
75-
mutex_lock(&dev->ctxlist_mutex);
76-
if (!list_empty(&dev->ctxlist)) {
77-
struct drm_ctx_list *pos, *n;
78-
79-
list_for_each_entry_safe(pos, n, &dev->ctxlist, head) {
80-
if (pos->tag == file_priv &&
81-
pos->handle != DRM_KERNEL_CONTEXT) {
82-
if (dev->driver->context_dtor)
83-
dev->driver->context_dtor(dev,
84-
pos->handle);
85-
86-
drm_ctxbitmap_free(dev, pos->handle);
87-
88-
list_del(&pos->head);
89-
kfree(pos);
90-
--dev->ctx_count;
91-
}
92-
}
93-
}
94-
mutex_unlock(&dev->ctxlist_mutex);
95-
}
96-
9766
/**
9867
* Context bitmap allocation.
9968
*
@@ -121,12 +90,10 @@ static int drm_ctxbitmap_next(struct drm_device * dev)
12190
*
12291
* Initialise the drm_device::ctx_idr
12392
*/
124-
void drm_legacy_ctxbitmap_init(struct drm_device * dev)
93+
int drm_ctxbitmap_init(struct drm_device * dev)
12594
{
126-
if (drm_core_check_feature(dev, DRIVER_MODESET))
127-
return;
128-
12995
idr_init(&dev->ctx_idr);
96+
return 0;
13097
}
13198

13299
/**
@@ -137,7 +104,7 @@ void drm_legacy_ctxbitmap_init(struct drm_device * dev)
137104
* Free all idr members using drm_ctx_sarea_free helper function
138105
* while holding the drm_device::struct_mutex lock.
139106
*/
140-
void drm_legacy_ctxbitmap_cleanup(struct drm_device * dev)
107+
void drm_ctxbitmap_cleanup(struct drm_device * dev)
141108
{
142109
mutex_lock(&dev->struct_mutex);
143110
idr_destroy(&dev->ctx_idr);
@@ -169,9 +136,6 @@ int drm_getsareactx(struct drm_device *dev, void *data,
169136
struct drm_local_map *map;
170137
struct drm_map_list *_entry;
171138

172-
if (drm_core_check_feature(dev, DRIVER_MODESET))
173-
return -EINVAL;
174-
175139
mutex_lock(&dev->struct_mutex);
176140

177141
map = idr_find(&dev->ctx_idr, request->ctx_id);
@@ -216,9 +180,6 @@ int drm_setsareactx(struct drm_device *dev, void *data,
216180
struct drm_local_map *map = NULL;
217181
struct drm_map_list *r_list = NULL;
218182

219-
if (drm_core_check_feature(dev, DRIVER_MODESET))
220-
return -EINVAL;
221-
222183
mutex_lock(&dev->struct_mutex);
223184
list_for_each_entry(r_list, &dev->maplist, head) {
224185
if (r_list->map
@@ -319,9 +280,6 @@ int drm_resctx(struct drm_device *dev, void *data,
319280
struct drm_ctx ctx;
320281
int i;
321282

322-
if (drm_core_check_feature(dev, DRIVER_MODESET))
323-
return -EINVAL;
324-
325283
if (res->count >= DRM_RESERVED_CONTEXTS) {
326284
memset(&ctx, 0, sizeof(ctx));
327285
for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
@@ -352,9 +310,6 @@ int drm_addctx(struct drm_device *dev, void *data,
352310
struct drm_ctx_list *ctx_entry;
353311
struct drm_ctx *ctx = data;
354312

355-
if (drm_core_check_feature(dev, DRIVER_MODESET))
356-
return -EINVAL;
357-
358313
ctx->handle = drm_ctxbitmap_next(dev);
359314
if (ctx->handle == DRM_KERNEL_CONTEXT) {
360315
/* Skip kernel's context and get a new one. */
@@ -398,9 +353,6 @@ int drm_getctx(struct drm_device *dev, void *data, struct drm_file *file_priv)
398353
{
399354
struct drm_ctx *ctx = data;
400355

401-
if (drm_core_check_feature(dev, DRIVER_MODESET))
402-
return -EINVAL;
403-
404356
/* This is 0, because we don't handle any context flags */
405357
ctx->flags = 0;
406358

@@ -423,9 +375,6 @@ int drm_switchctx(struct drm_device *dev, void *data,
423375
{
424376
struct drm_ctx *ctx = data;
425377

426-
if (drm_core_check_feature(dev, DRIVER_MODESET))
427-
return -EINVAL;
428-
429378
DRM_DEBUG("%d\n", ctx->handle);
430379
return drm_context_switch(dev, dev->last_context, ctx->handle);
431380
}
@@ -446,9 +395,6 @@ int drm_newctx(struct drm_device *dev, void *data,
446395
{
447396
struct drm_ctx *ctx = data;
448397

449-
if (drm_core_check_feature(dev, DRIVER_MODESET))
450-
return -EINVAL;
451-
452398
DRM_DEBUG("%d\n", ctx->handle);
453399
drm_context_switch_complete(dev, file_priv, ctx->handle);
454400

@@ -471,9 +417,6 @@ int drm_rmctx(struct drm_device *dev, void *data,
471417
{
472418
struct drm_ctx *ctx = data;
473419

474-
if (drm_core_check_feature(dev, DRIVER_MODESET))
475-
return -EINVAL;
476-
477420
DRM_DEBUG("%d\n", ctx->handle);
478421
if (ctx->handle != DRM_KERNEL_CONTEXT) {
479422
if (dev->driver->context_dtor)

drivers/gpu/drm/drm_fops.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,26 @@ int drm_release(struct inode *inode, struct file *filp)
439439
if (dev->driver->driver_features & DRIVER_GEM)
440440
drm_gem_release(dev, file_priv);
441441

442-
drm_legacy_ctxbitmap_release(dev, file_priv);
442+
mutex_lock(&dev->ctxlist_mutex);
443+
if (!list_empty(&dev->ctxlist)) {
444+
struct drm_ctx_list *pos, *n;
445+
446+
list_for_each_entry_safe(pos, n, &dev->ctxlist, head) {
447+
if (pos->tag == file_priv &&
448+
pos->handle != DRM_KERNEL_CONTEXT) {
449+
if (dev->driver->context_dtor)
450+
dev->driver->context_dtor(dev,
451+
pos->handle);
452+
453+
drm_ctxbitmap_free(dev, pos->handle);
454+
455+
list_del(&pos->head);
456+
kfree(pos);
457+
--dev->ctx_count;
458+
}
459+
}
460+
}
461+
mutex_unlock(&dev->ctxlist_mutex);
443462

444463
mutex_lock(&dev->struct_mutex);
445464

drivers/gpu/drm/drm_stub.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,13 @@ int drm_fill_in_dev(struct drm_device *dev,
292292
goto error_out_unreg;
293293
}
294294

295-
drm_legacy_ctxbitmap_init(dev);
295+
296+
297+
retcode = drm_ctxbitmap_init(dev);
298+
if (retcode) {
299+
DRM_ERROR("Cannot allocate memory for context bitmap.\n");
300+
goto error_out_unreg;
301+
}
296302

297303
if (driver->driver_features & DRIVER_GEM) {
298304
retcode = drm_gem_init(dev);
@@ -446,7 +452,7 @@ void drm_put_dev(struct drm_device *dev)
446452
drm_rmmap(dev, r_list->map);
447453
drm_ht_remove(&dev->map_hash);
448454

449-
drm_legacy_ctxbitmap_cleanup(dev);
455+
drm_ctxbitmap_cleanup(dev);
450456

451457
if (drm_core_check_feature(dev, DRIVER_MODESET))
452458
drm_put_minor(&dev->control);

include/drm/drmP.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,10 +1322,9 @@ extern int drm_newctx(struct drm_device *dev, void *data,
13221322
extern int drm_rmctx(struct drm_device *dev, void *data,
13231323
struct drm_file *file_priv);
13241324

1325-
extern void drm_legacy_ctxbitmap_init(struct drm_device *dev);
1326-
extern void drm_legacy_ctxbitmap_cleanup(struct drm_device *dev);
1327-
extern void drm_legacy_ctxbitmap_release(struct drm_device *dev,
1328-
struct drm_file *file_priv);
1325+
extern int drm_ctxbitmap_init(struct drm_device *dev);
1326+
extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
1327+
extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
13291328

13301329
extern int drm_setsareactx(struct drm_device *dev, void *data,
13311330
struct drm_file *file_priv);

0 commit comments

Comments
 (0)