Subversion Repositories Kolibri OS

Rev

Rev 4560 | Rev 5271 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4560 Rev 5060
Line 80... Line 80...
80
#define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFUL >> PAGE_SHIFT) + 1)
80
#define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFUL >> PAGE_SHIFT) + 1)
81
#define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFUL >> PAGE_SHIFT) * 16)
81
#define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFUL >> PAGE_SHIFT) * 16)
82
#endif
82
#endif
Line 83... Line 83...
83
 
83
 
84
/**
84
/**
-
 
85
 * drm_gem_init - Initialize the GEM device fields
85
 * Initialize the GEM device fields
86
 * @dev: drm_devic structure to initialize
86
 */
-
 
87
 
87
 */
88
int
88
int
89
drm_gem_init(struct drm_device *dev)
89
drm_gem_init(struct drm_device *dev)
90
{
90
{
Line 115... Line 115...
115
	kfree(dev->vma_offset_manager);
115
	kfree(dev->vma_offset_manager);
116
	dev->vma_offset_manager = NULL;
116
	dev->vma_offset_manager = NULL;
117
}
117
}
Line 118... Line 118...
118
 
118
 
-
 
119
/**
-
 
120
 * drm_gem_object_init - initialize an allocated shmem-backed GEM object
-
 
121
 * @dev: drm_device the object should be initialized for
-
 
122
 * @obj: drm_gem_object to initialize
-
 
123
 * @size: object size
119
/**
124
 *
120
 * Initialize an already allocated GEM object of the specified size with
125
 * Initialize an already allocated GEM object of the specified size with
121
 * shmfs backing store.
126
 * shmfs backing store.
122
 */
127
 */
123
int drm_gem_object_init(struct drm_device *dev,
128
int drm_gem_object_init(struct drm_device *dev,
Line 136... Line 141...
136
	return 0;
141
	return 0;
137
}
142
}
138
EXPORT_SYMBOL(drm_gem_object_init);
143
EXPORT_SYMBOL(drm_gem_object_init);
Line 139... Line 144...
139
 
144
 
-
 
145
/**
-
 
146
 * drm_gem_object_init - initialize an allocated private GEM object
-
 
147
 * @dev: drm_device the object should be initialized for
-
 
148
 * @obj: drm_gem_object to initialize
-
 
149
 * @size: object size
140
/**
150
 *
141
 * Initialize an already allocated GEM object of the specified size with
151
 * Initialize an already allocated GEM object of the specified size with
142
 * no GEM provided backing store. Instead the caller is responsible for
152
 * no GEM provided backing store. Instead the caller is responsible for
143
 * backing the object and handling it.
153
 * backing the object and handling it.
144
 */
154
 */
Line 156... Line 166...
156
	drm_vma_node_reset(&obj->vma_node);
166
	drm_vma_node_reset(&obj->vma_node);
157
}
167
}
158
EXPORT_SYMBOL(drm_gem_private_object_init);
168
EXPORT_SYMBOL(drm_gem_private_object_init);
Line 159... Line 169...
159
 
169
 
-
 
170
/**
-
 
171
 * drm_gem_object_free - release resources bound to userspace handles
-
 
172
 * @obj: GEM object to clean up.
160
/**
173
 *
161
 * Called after the last handle to the object has been closed
174
 * Called after the last handle to the object has been closed
162
 *
175
 *
163
 * Removes any name for the object. Note that this must be
176
 * Removes any name for the object. Note that this must be
164
 * called before drm_gem_object_free or we'll be touching
177
 * called before drm_gem_object_free or we'll be touching
Line 196... Line 209...
196
 
209
 
197
	drm_gem_object_unreference_unlocked(obj);
210
	drm_gem_object_unreference_unlocked(obj);
Line 198... Line 211...
198
}
211
}
-
 
212
 
-
 
213
/**
-
 
214
 * drm_gem_handle_delete - deletes the given file-private handle
-
 
215
 * @filp: drm file-private structure to use for the handle look up
199
 
216
 * @handle: userspace handle to delete
-
 
217
 *
200
/**
218
 * Removes the GEM handle from the @filp lookup table and if this is the last
201
 * Removes the mapping from handle to filp for this object.
219
 * handle also cleans up linked resources like GEM names.
202
 */
220
 */
203
int
221
int
204
drm_gem_handle_delete(struct drm_file *filp, u32 handle)
222
drm_gem_handle_delete(struct drm_file *filp, u32 handle)
Line 239... Line 257...
239
}
257
}
240
EXPORT_SYMBOL(drm_gem_handle_delete);
258
EXPORT_SYMBOL(drm_gem_handle_delete);
Line 241... Line 259...
241
 
259
 
242
/**
260
/**
-
 
261
 * drm_gem_dumb_destroy - dumb fb callback helper for gem based drivers
-
 
262
 * @file: drm file-private structure to remove the dumb handle from
-
 
263
 * @dev: corresponding drm_device
243
 * drm_gem_dumb_destroy - dumb fb callback helper for gem based drivers
264
 * @handle: the dumb handle to remove
244
 * 
265
 * 
245
 * This implements the ->dumb_destroy kms driver callback for drivers which use
266
 * This implements the ->dumb_destroy kms driver callback for drivers which use
246
 * gem to manage their backing storage.
267
 * gem to manage their backing storage.
247
 */
268
 */
Line 253... Line 274...
253
}
274
}
254
EXPORT_SYMBOL(drm_gem_dumb_destroy);
275
EXPORT_SYMBOL(drm_gem_dumb_destroy);
Line 255... Line 276...
255
 
276
 
256
/**
277
/**
-
 
278
 * drm_gem_handle_create_tail - internal functions to create a handle
-
 
279
 * @file_priv: drm file-private structure to register the handle for
-
 
280
 * @obj: object to register
257
 * drm_gem_handle_create_tail - internal functions to create a handle
281
 * @handlep: pionter to return the created handle to the caller
258
 * 
282
 * 
259
 * This expects the dev->object_name_lock to be held already and will drop it
283
 * This expects the dev->object_name_lock to be held already and will drop it
260
 * before returning. Used to avoid races in establishing new handles when
284
 * before returning. Used to avoid races in establishing new handles when
261
 * importing an object from either an flink name or a dma-buf.
285
 * importing an object from either an flink name or a dma-buf.
Line 305... Line 329...
305
 
329
 
306
	return 0;
330
	return 0;
Line 307... Line 331...
307
}
331
}
-
 
332
 
-
 
333
/**
-
 
334
 * gem_handle_create - create a gem handle for an object
-
 
335
 * @file_priv: drm file-private structure to register the handle for
-
 
336
 * @obj: object to register
308
 
337
 * @handlep: pionter to return the created handle to the caller
309
/**
338
 *
310
 * Create a handle for this object. This adds a handle reference
339
 * Create a handle for this object. This adds a handle reference
311
 * to the object, which includes a regular reference count. Callers
340
 * to the object, which includes a regular reference count. Callers
312
 * will likely want to dereference the object afterwards.
341
 * will likely want to dereference the object afterwards.
Line 381... Line 410...
381
 
410
 
382
/**
411
/**
383
 * drm_gem_get_pages - helper to allocate backing pages for a GEM object
412
 * drm_gem_get_pages - helper to allocate backing pages for a GEM object
384
 * from shmem
413
 * from shmem
-
 
414
 * @obj: obj in question
-
 
415
 *
-
 
416
 * This reads the page-array of the shmem-backing storage of the given gem
-
 
417
 * object. An array of pages is returned. If a page is not allocated or
-
 
418
 * swapped-out, this will allocate/swap-in the required pages. Note that the
-
 
419
 * whole object is covered by the page-array and pinned in memory.
-
 
420
 *
-
 
421
 * Use drm_gem_put_pages() to release the array and unpin all pages.
-
 
422
 *
-
 
423
 * This uses the GFP-mask set on the shmem-mapping (see mapping_set_gfp_mask()).
-
 
424
 * If you require other GFP-masks, you have to do those allocations yourself.
-
 
425
 *
-
 
426
 * Note that you are not allowed to change gfp-zones during runtime. That is,
-
 
427
 * shmem_read_mapping_page_gfp() must be called with the same gfp_zone(gfp) as
-
 
428
 * set during initialization. If you have special zone constraints, set them
385
 * @obj: obj in question
429
 * after drm_gem_init_object() via mapping_set_gfp_mask(). shmem-core takes care
386
 * @gfpmask: gfp mask of requested pages
430
 * to keep pages in the required zone during swap-in.
387
 */
431
 */
388
struct page **drm_gem_get_pages(struct drm_gem_object *obj, gfp_t gfpmask)
432
struct page **drm_gem_get_pages(struct drm_gem_object *obj)
389
{
-
 
390
	struct inode *inode;
433
{
391
	struct address_space *mapping;
434
	struct address_space *mapping;
392
	struct page *p, **pages;
435
	struct page *p, **pages;
Line 393... Line 436...
393
	int i, npages;
436
	int i, npages;
394
 
-
 
395
	/* This is the shared memory object that backs the GEM resource */
437
 
Line 396... Line 438...
396
	inode = file_inode(obj->filp);
438
	/* This is the shared memory object that backs the GEM resource */
397
	mapping = inode->i_mapping;
439
	mapping = file_inode(obj->filp)->i_mapping;
398
 
440
 
399
	/* We already BUG_ON() for non-page-aligned sizes in
441
	/* We already BUG_ON() for non-page-aligned sizes in
Line 406... Line 448...
406
 
448
 
407
	pages = drm_malloc_ab(npages, sizeof(struct page *));
449
	pages = drm_malloc_ab(npages, sizeof(struct page *));
408
	if (pages == NULL)
450
	if (pages == NULL)
Line 409... Line -...
409
		return ERR_PTR(-ENOMEM);
-
 
410
 
-
 
411
	gfpmask |= mapping_gfp_mask(mapping);
451
		return ERR_PTR(-ENOMEM);
412
 
452
 
413
	for (i = 0; i < npages; i++) {
453
	for (i = 0; i < npages; i++) {
414
		p = shmem_read_mapping_page_gfp(mapping, i, gfpmask);
454
		p = shmem_read_mapping_page(mapping, i);
415
		if (IS_ERR(p))
455
		if (IS_ERR(p))
Line 416... Line -...
416
			goto fail;
-
 
417
		pages[i] = p;
456
			goto fail;
418
 
-
 
419
		/* There is a hypothetical issue w/ drivers that require
-
 
420
		 * buffer memory in the low 4GB.. if the pages are un-
-
 
421
		 * pinned, and swapped out, they can end up swapped back
-
 
422
		 * in above 4GB.  If pages are already in memory, then
-
 
423
		 * shmem_read_mapping_page_gfp will ignore the gfpmask,
-
 
424
		 * even if the already in-memory page disobeys the mask.
-
 
425
		 *
457
		pages[i] = p;
426
		 * It is only a theoretical issue today, because none of
458
 
427
		 * the devices with this limitation can be populated with
459
		/* Make sure shmem keeps __GFP_DMA32 allocated pages in the
428
		 * enough memory to trigger the issue.  But this BUG_ON()
-
 
429
		 * is here as a reminder in case the problem with
-
 
430
		 * shmem_read_mapping_page_gfp() isn't solved by the time
-
 
431
		 * it does become a real issue.
460
		 * correct region during swapin. Note that this requires
432
		 *
461
		 * __GFP_DMA32 to be set in mapping_gfp_mask(inode->i_mapping)
433
		 * See this thread: http://lkml.org/lkml/2011/7/11/238
462
		 * so shmem can relocate pages during swapin if required.
434
		 */
463
		 */
Line 435... Line 464...
435
		BUG_ON((gfpmask & __GFP_DMA32) &&
464
		BUG_ON((mapping_gfp_mask(mapping) & __GFP_DMA32) &&
Line 506... Line 535...
506
	return obj;
535
	return obj;
507
}
536
}
508
EXPORT_SYMBOL(drm_gem_object_lookup);
537
EXPORT_SYMBOL(drm_gem_object_lookup);
Line 509... Line 538...
509
 
538
 
-
 
539
/**
-
 
540
 * drm_gem_close_ioctl - implementation of the GEM_CLOSE ioctl
-
 
541
 * @dev: drm_device
-
 
542
 * @data: ioctl data
-
 
543
 * @file_priv: drm file-private structure
510
/**
544
 *
511
 * Releases the handle to an mm object.
545
 * Releases the handle to an mm object.
512
 */
546
 */
513
int
547
int
514
drm_gem_close_ioctl(struct drm_device *dev, void *data,
548
drm_gem_close_ioctl(struct drm_device *dev, void *data,
515
		    struct drm_file *file_priv)
549
		    struct drm_file *file_priv)
516
{
550
{
517
	struct drm_gem_close *args = data;
551
	struct drm_gem_close *args = data;
Line -... Line 552...
-
 
552
	int ret;
-
 
553
 
-
 
554
	if (!(dev->driver->driver_features & DRIVER_GEM))
518
	int ret;
555
		return -ENODEV;
Line 519... Line 556...
519
 
556
 
520
	ret = drm_gem_handle_delete(file_priv, args->handle);
557
	ret = drm_gem_handle_delete(file_priv, args->handle);
Line 521... Line 558...
521
 
558
 
-
 
559
	return ret;
-
 
560
}
-
 
561
 
-
 
562
/**
-
 
563
 * drm_gem_flink_ioctl - implementation of the GEM_FLINK ioctl
522
	return ret;
564
 * @dev: drm_device
523
}
565
 * @data: ioctl data
524
 
566
 * @file_priv: drm file-private structure
525
/**
567
 *
526
 * Create a global name for an object, returning the name.
568
 * Create a global name for an object, returning the name.
Line 568... Line 610...
568
	drm_gem_object_unreference_unlocked(obj);
610
	drm_gem_object_unreference_unlocked(obj);
569
	return ret;
611
	return ret;
570
}
612
}
Line 571... Line 613...
571
 
613
 
-
 
614
/**
-
 
615
 * drm_gem_open - implementation of the GEM_OPEN ioctl
-
 
616
 * @dev: drm_device
-
 
617
 * @data: ioctl data
-
 
618
 * @file_priv: drm file-private structure
572
/**
619
 *
573
 * Open an object using the global name, returning a handle and the size.
620
 * Open an object using the global name, returning a handle and the size.
574
 *
621
 *
575
 * This handle (of course) holds a reference to the object, so the object
622
 * This handle (of course) holds a reference to the object, so the object
576
 * will not go away until the handle is deleted.
623
 * will not go away until the handle is deleted.
Line 608... Line 655...
608
	return 0;
655
	return 0;
609
}
656
}
Line 610... Line 657...
610
 
657
 
611
#if 0
658
#if 0
-
 
659
/**
-
 
660
 * gem_gem_open - initalizes GEM file-private structures at devnode open time
-
 
661
 * @dev: drm_device which is being opened by userspace
-
 
662
 * @file_private: drm file-private structure to set up
612
/**
663
 *
613
 * Called at device open time, sets up the structure for handling refcounting
664
 * Called at device open time, sets up the structure for handling refcounting
614
 * of mm objects.
665
 * of mm objects.
615
 */
666
 */
616
void
667
void
617
drm_gem_open(struct drm_device *dev, struct drm_file *file_private)
668
drm_gem_open(struct drm_device *dev, struct drm_file *file_private)
618
{
669
{
619
	idr_init(&file_private->object_idr);
670
	idr_init(&file_private->object_idr);
620
	spin_lock_init(&file_private->table_lock);
671
	spin_lock_init(&file_private->table_lock);
Line 621... Line 672...
621
}
672
}
622
 
673
 
623
/**
674
/*
624
 * Called at device close to release the file's
675
 * Called at device close to release the file's
625
 * handle references on objects.
676
 * handle references on objects.
626
 */
677
 */
Line 640... Line 691...
640
 
691
 
641
	return 0;
692
	return 0;
Line 642... Line 693...
642
}
693
}
-
 
694
 
-
 
695
/**
-
 
696
 * drm_gem_release - release file-private GEM resources
-
 
697
 * @dev: drm_device which is being closed by userspace
643
 
698
 * @file_private: drm file-private structure to clean up
644
/**
699
 *
645
 * Called at close time when the filp is going away.
700
 * Called at close time when the filp is going away.
646
 *
701
 *
647
 * Releases any remaining references on objects by this filp.
702
 * Releases any remaining references on objects by this filp.
Line 656... Line 711...
656
#endif
711
#endif
Line 657... Line 712...
657
 
712
 
658
void
713
void
659
drm_gem_object_release(struct drm_gem_object *obj)
714
drm_gem_object_release(struct drm_gem_object *obj)
-
 
715
{
-
 
716
	WARN_ON(obj->dma_buf);
660
{
717
 
661
	if (obj->filp)
718
	if (obj->filp)
662
	    free(obj->filp);
719
	    free(obj->filp);
663
}
720
}
Line 664... Line 721...
664
EXPORT_SYMBOL(drm_gem_object_release);
721
EXPORT_SYMBOL(drm_gem_object_release);
-
 
722
 
-
 
723
/**
-
 
724
 * drm_gem_object_free - free a GEM object
665
 
725
 * @kref: kref of the object to free
666
/**
726
 *
667
 * Called after the last reference to the object has been lost.
727
 * Called after the last reference to the object has been lost.
668
 * Must be called holding struct_ mutex
728
 * Must be called holding struct_ mutex
669
 *
729
 *