50
50
#include <linux/atomic.h>
51
51
#include <linux/module.h>
52
52
#include "ttm_object.h"
53
+ #include "vmwgfx_drv.h"
53
54
54
55
MODULE_IMPORT_NS (DMA_BUF );
55
56
@@ -73,7 +74,7 @@ struct ttm_object_file {
73
74
struct ttm_object_device * tdev ;
74
75
spinlock_t lock ;
75
76
struct list_head ref_list ;
76
- struct vmwgfx_open_hash ref_hash [ TTM_REF_NUM ] ;
77
+ struct vmwgfx_open_hash ref_hash ;
77
78
struct kref refcount ;
78
79
};
79
80
@@ -124,7 +125,6 @@ struct ttm_ref_object {
124
125
struct vmwgfx_hash_item hash ;
125
126
struct list_head head ;
126
127
struct kref kref ;
127
- enum ttm_ref_type ref_type ;
128
128
struct ttm_base_object * obj ;
129
129
struct ttm_object_file * tfile ;
130
130
};
@@ -160,17 +160,14 @@ int ttm_base_object_init(struct ttm_object_file *tfile,
160
160
struct ttm_base_object * base ,
161
161
bool shareable ,
162
162
enum ttm_object_type object_type ,
163
- void (* refcount_release ) (struct ttm_base_object * * ),
164
- void (* ref_obj_release ) (struct ttm_base_object * ,
165
- enum ttm_ref_type ref_type ))
163
+ void (* refcount_release ) (struct ttm_base_object * * ))
166
164
{
167
165
struct ttm_object_device * tdev = tfile -> tdev ;
168
166
int ret ;
169
167
170
168
base -> shareable = shareable ;
171
169
base -> tfile = ttm_object_file_ref (tfile );
172
170
base -> refcount_release = refcount_release ;
173
- base -> ref_obj_release = ref_obj_release ;
174
171
base -> object_type = object_type ;
175
172
kref_init (& base -> refcount );
176
173
idr_preload (GFP_KERNEL );
@@ -182,7 +179,7 @@ int ttm_base_object_init(struct ttm_object_file *tfile,
182
179
return ret ;
183
180
184
181
base -> handle = ret ;
185
- ret = ttm_ref_object_add (tfile , base , TTM_REF_USAGE , NULL , false);
182
+ ret = ttm_ref_object_add (tfile , base , NULL , false);
186
183
if (unlikely (ret != 0 ))
187
184
goto out_err1 ;
188
185
@@ -246,7 +243,7 @@ struct ttm_base_object *
246
243
ttm_base_object_noref_lookup (struct ttm_object_file * tfile , uint32_t key )
247
244
{
248
245
struct vmwgfx_hash_item * hash ;
249
- struct vmwgfx_open_hash * ht = & tfile -> ref_hash [ TTM_REF_USAGE ] ;
246
+ struct vmwgfx_open_hash * ht = & tfile -> ref_hash ;
250
247
int ret ;
251
248
252
249
rcu_read_lock ();
@@ -266,7 +263,7 @@ struct ttm_base_object *ttm_base_object_lookup(struct ttm_object_file *tfile,
266
263
{
267
264
struct ttm_base_object * base = NULL ;
268
265
struct vmwgfx_hash_item * hash ;
269
- struct vmwgfx_open_hash * ht = & tfile -> ref_hash [ TTM_REF_USAGE ] ;
266
+ struct vmwgfx_open_hash * ht = & tfile -> ref_hash ;
270
267
int ret ;
271
268
272
269
rcu_read_lock ();
@@ -297,57 +294,12 @@ ttm_base_object_lookup_for_ref(struct ttm_object_device *tdev, uint32_t key)
297
294
return base ;
298
295
}
299
296
300
- /**
301
- * ttm_ref_object_exists - Check whether a caller has a valid ref object
302
- * (has opened) a base object.
303
- *
304
- * @tfile: Pointer to a struct ttm_object_file identifying the caller.
305
- * @base: Pointer to a struct base object.
306
- *
307
- * Checks wether the caller identified by @tfile has put a valid USAGE
308
- * reference object on the base object identified by @base.
309
- */
310
- bool ttm_ref_object_exists (struct ttm_object_file * tfile ,
311
- struct ttm_base_object * base )
312
- {
313
- struct vmwgfx_open_hash * ht = & tfile -> ref_hash [TTM_REF_USAGE ];
314
- struct vmwgfx_hash_item * hash ;
315
- struct ttm_ref_object * ref ;
316
-
317
- rcu_read_lock ();
318
- if (unlikely (vmwgfx_ht_find_item_rcu (ht , base -> handle , & hash ) != 0 ))
319
- goto out_false ;
320
-
321
- /*
322
- * Verify that the ref object is really pointing to our base object.
323
- * Our base object could actually be dead, and the ref object pointing
324
- * to another base object with the same handle.
325
- */
326
- ref = drm_hash_entry (hash , struct ttm_ref_object , hash );
327
- if (unlikely (base != ref -> obj ))
328
- goto out_false ;
329
-
330
- /*
331
- * Verify that the ref->obj pointer was actually valid!
332
- */
333
- rmb ();
334
- if (unlikely (kref_read (& ref -> kref ) == 0 ))
335
- goto out_false ;
336
-
337
- rcu_read_unlock ();
338
- return true;
339
-
340
- out_false :
341
- rcu_read_unlock ();
342
- return false;
343
- }
344
-
345
297
int ttm_ref_object_add (struct ttm_object_file * tfile ,
346
298
struct ttm_base_object * base ,
347
- enum ttm_ref_type ref_type , bool * existed ,
299
+ bool * existed ,
348
300
bool require_existed )
349
301
{
350
- struct vmwgfx_open_hash * ht = & tfile -> ref_hash [ ref_type ] ;
302
+ struct vmwgfx_open_hash * ht = & tfile -> ref_hash ;
351
303
struct ttm_ref_object * ref ;
352
304
struct vmwgfx_hash_item * hash ;
353
305
int ret = - EINVAL ;
@@ -382,7 +334,6 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,
382
334
ref -> hash .key = base -> handle ;
383
335
ref -> obj = base ;
384
336
ref -> tfile = tfile ;
385
- ref -> ref_type = ref_type ;
386
337
kref_init (& ref -> kref );
387
338
388
339
spin_lock (& tfile -> lock );
@@ -411,27 +362,23 @@ ttm_ref_object_release(struct kref *kref)
411
362
{
412
363
struct ttm_ref_object * ref =
413
364
container_of (kref , struct ttm_ref_object , kref );
414
- struct ttm_base_object * base = ref -> obj ;
415
365
struct ttm_object_file * tfile = ref -> tfile ;
416
366
struct vmwgfx_open_hash * ht ;
417
367
418
- ht = & tfile -> ref_hash [ ref -> ref_type ] ;
368
+ ht = & tfile -> ref_hash ;
419
369
(void )vmwgfx_ht_remove_item_rcu (ht , & ref -> hash );
420
370
list_del (& ref -> head );
421
371
spin_unlock (& tfile -> lock );
422
372
423
- if (ref -> ref_type != TTM_REF_USAGE && base -> ref_obj_release )
424
- base -> ref_obj_release (base , ref -> ref_type );
425
-
426
373
ttm_base_object_unref (& ref -> obj );
427
374
kfree_rcu (ref , rcu_head );
428
375
spin_lock (& tfile -> lock );
429
376
}
430
377
431
378
int ttm_ref_object_base_unref (struct ttm_object_file * tfile ,
432
- unsigned long key , enum ttm_ref_type ref_type )
379
+ unsigned long key )
433
380
{
434
- struct vmwgfx_open_hash * ht = & tfile -> ref_hash [ ref_type ] ;
381
+ struct vmwgfx_open_hash * ht = & tfile -> ref_hash ;
435
382
struct ttm_ref_object * ref ;
436
383
struct vmwgfx_hash_item * hash ;
437
384
int ret ;
@@ -452,7 +399,6 @@ void ttm_object_file_release(struct ttm_object_file **p_tfile)
452
399
{
453
400
struct ttm_ref_object * ref ;
454
401
struct list_head * list ;
455
- unsigned int i ;
456
402
struct ttm_object_file * tfile = * p_tfile ;
457
403
458
404
* p_tfile = NULL ;
@@ -470,8 +416,7 @@ void ttm_object_file_release(struct ttm_object_file **p_tfile)
470
416
}
471
417
472
418
spin_unlock (& tfile -> lock );
473
- for (i = 0 ; i < TTM_REF_NUM ; ++ i )
474
- vmwgfx_ht_remove (& tfile -> ref_hash [i ]);
419
+ vmwgfx_ht_remove (& tfile -> ref_hash );
475
420
476
421
ttm_object_file_unref (& tfile );
477
422
}
@@ -480,8 +425,6 @@ struct ttm_object_file *ttm_object_file_init(struct ttm_object_device *tdev,
480
425
unsigned int hash_order )
481
426
{
482
427
struct ttm_object_file * tfile = kmalloc (sizeof (* tfile ), GFP_KERNEL );
483
- unsigned int i ;
484
- unsigned int j = 0 ;
485
428
int ret ;
486
429
487
430
if (unlikely (tfile == NULL ))
@@ -492,18 +435,13 @@ struct ttm_object_file *ttm_object_file_init(struct ttm_object_device *tdev,
492
435
kref_init (& tfile -> refcount );
493
436
INIT_LIST_HEAD (& tfile -> ref_list );
494
437
495
- for (i = 0 ; i < TTM_REF_NUM ; ++ i ) {
496
- ret = vmwgfx_ht_create (& tfile -> ref_hash [i ], hash_order );
497
- if (ret ) {
498
- j = i ;
499
- goto out_err ;
500
- }
501
- }
438
+ ret = vmwgfx_ht_create (& tfile -> ref_hash , hash_order );
439
+ if (ret )
440
+ goto out_err ;
502
441
503
442
return tfile ;
504
443
out_err :
505
- for (i = 0 ; i < j ; ++ i )
506
- vmwgfx_ht_remove (& tfile -> ref_hash [i ]);
444
+ vmwgfx_ht_remove (& tfile -> ref_hash );
507
445
508
446
kfree (tfile );
509
447
@@ -526,7 +464,15 @@ ttm_object_device_init(unsigned int hash_order,
526
464
if (ret != 0 )
527
465
goto out_no_object_hash ;
528
466
529
- idr_init_base (& tdev -> idr , 1 );
467
+ /*
468
+ * Our base is at VMWGFX_NUM_MOB + 1 because we want to create
469
+ * a seperate namespace for GEM handles (which are
470
+ * 1..VMWGFX_NUM_MOB) and the surface handles. Some ioctl's
471
+ * can take either handle as an argument so we want to
472
+ * easily be able to tell whether the handle refers to a
473
+ * GEM buffer or a surface.
474
+ */
475
+ idr_init_base (& tdev -> idr , VMWGFX_NUM_MOB + 1 );
530
476
tdev -> ops = * ops ;
531
477
tdev -> dmabuf_release = tdev -> ops .release ;
532
478
tdev -> ops .release = ttm_prime_dmabuf_release ;
@@ -647,7 +593,7 @@ int ttm_prime_fd_to_handle(struct ttm_object_file *tfile,
647
593
prime = (struct ttm_prime_object * ) dma_buf -> priv ;
648
594
base = & prime -> base ;
649
595
* handle = base -> handle ;
650
- ret = ttm_ref_object_add (tfile , base , TTM_REF_USAGE , NULL , false);
596
+ ret = ttm_ref_object_add (tfile , base , NULL , false);
651
597
652
598
dma_buf_put (dma_buf );
653
599
@@ -741,17 +687,14 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,
741
687
* @shareable: See ttm_base_object_init
742
688
* @type: See ttm_base_object_init
743
689
* @refcount_release: See ttm_base_object_init
744
- * @ref_obj_release: See ttm_base_object_init
745
690
*
746
691
* Initializes an object which is compatible with the drm_prime model
747
692
* for data sharing between processes and devices.
748
693
*/
749
694
int ttm_prime_object_init (struct ttm_object_file * tfile , size_t size ,
750
695
struct ttm_prime_object * prime , bool shareable ,
751
696
enum ttm_object_type type ,
752
- void (* refcount_release ) (struct ttm_base_object * * ),
753
- void (* ref_obj_release ) (struct ttm_base_object * ,
754
- enum ttm_ref_type ref_type ))
697
+ void (* refcount_release ) (struct ttm_base_object * * ))
755
698
{
756
699
mutex_init (& prime -> mutex );
757
700
prime -> size = PAGE_ALIGN (size );
@@ -760,6 +703,5 @@ int ttm_prime_object_init(struct ttm_object_file *tfile, size_t size,
760
703
prime -> refcount_release = refcount_release ;
761
704
return ttm_base_object_init (tfile , & prime -> base , shareable ,
762
705
ttm_prime_type ,
763
- ttm_prime_refcount_release ,
764
- ref_obj_release );
706
+ ttm_prime_refcount_release );
765
707
}
0 commit comments