82,9 → 82,9 |
#endif |
|
/** |
* Initialize the GEM device fields |
* drm_gem_init - Initialize the GEM device fields |
* @dev: drm_devic structure to initialize |
*/ |
|
int |
drm_gem_init(struct drm_device *dev) |
{ |
117,6 → 117,11 |
} |
|
/** |
* drm_gem_object_init - initialize an allocated shmem-backed GEM object |
* @dev: drm_device the object should be initialized for |
* @obj: drm_gem_object to initialize |
* @size: object size |
* |
* Initialize an already allocated GEM object of the specified size with |
* shmfs backing store. |
*/ |
138,6 → 143,11 |
EXPORT_SYMBOL(drm_gem_object_init); |
|
/** |
* drm_gem_object_init - initialize an allocated private GEM object |
* @dev: drm_device the object should be initialized for |
* @obj: drm_gem_object to initialize |
* @size: object size |
* |
* Initialize an already allocated GEM object of the specified size with |
* no GEM provided backing store. Instead the caller is responsible for |
* backing the object and handling it. |
158,6 → 168,9 |
EXPORT_SYMBOL(drm_gem_private_object_init); |
|
/** |
* drm_gem_object_free - release resources bound to userspace handles |
* @obj: GEM object to clean up. |
* |
* Called after the last handle to the object has been closed |
* |
* Removes any name for the object. Note that this must be |
198,7 → 211,12 |
} |
|
/** |
* Removes the mapping from handle to filp for this object. |
* drm_gem_handle_delete - deletes the given file-private handle |
* @filp: drm file-private structure to use for the handle look up |
* @handle: userspace handle to delete |
* |
* Removes the GEM handle from the @filp lookup table and if this is the last |
* handle also cleans up linked resources like GEM names. |
*/ |
int |
drm_gem_handle_delete(struct drm_file *filp, u32 handle) |
241,6 → 259,9 |
|
/** |
* drm_gem_dumb_destroy - dumb fb callback helper for gem based drivers |
* @file: drm file-private structure to remove the dumb handle from |
* @dev: corresponding drm_device |
* @handle: the dumb handle to remove |
* |
* This implements the ->dumb_destroy kms driver callback for drivers which use |
* gem to manage their backing storage. |
255,6 → 276,9 |
|
/** |
* drm_gem_handle_create_tail - internal functions to create a handle |
* @file_priv: drm file-private structure to register the handle for |
* @obj: object to register |
* @handlep: pionter to return the created handle to the caller |
* |
* This expects the dev->object_name_lock to be held already and will drop it |
* before returning. Used to avoid races in establishing new handles when |
307,6 → 331,11 |
} |
|
/** |
* gem_handle_create - create a gem handle for an object |
* @file_priv: drm file-private structure to register the handle for |
* @obj: object to register |
* @handlep: pionter to return the created handle to the caller |
* |
* Create a handle for this object. This adds a handle reference |
* to the object, which includes a regular reference count. Callers |
* will likely want to dereference the object afterwards. |
383,18 → 412,31 |
* drm_gem_get_pages - helper to allocate backing pages for a GEM object |
* from shmem |
* @obj: obj in question |
* @gfpmask: gfp mask of requested pages |
* |
* This reads the page-array of the shmem-backing storage of the given gem |
* object. An array of pages is returned. If a page is not allocated or |
* swapped-out, this will allocate/swap-in the required pages. Note that the |
* whole object is covered by the page-array and pinned in memory. |
* |
* Use drm_gem_put_pages() to release the array and unpin all pages. |
* |
* This uses the GFP-mask set on the shmem-mapping (see mapping_set_gfp_mask()). |
* If you require other GFP-masks, you have to do those allocations yourself. |
* |
* Note that you are not allowed to change gfp-zones during runtime. That is, |
* shmem_read_mapping_page_gfp() must be called with the same gfp_zone(gfp) as |
* set during initialization. If you have special zone constraints, set them |
* after drm_gem_init_object() via mapping_set_gfp_mask(). shmem-core takes care |
* to keep pages in the required zone during swap-in. |
*/ |
struct page **drm_gem_get_pages(struct drm_gem_object *obj, gfp_t gfpmask) |
struct page **drm_gem_get_pages(struct drm_gem_object *obj) |
{ |
struct inode *inode; |
struct address_space *mapping; |
struct page *p, **pages; |
int i, npages; |
|
/* This is the shared memory object that backs the GEM resource */ |
inode = file_inode(obj->filp); |
mapping = inode->i_mapping; |
mapping = file_inode(obj->filp)->i_mapping; |
|
/* We already BUG_ON() for non-page-aligned sizes in |
* drm_gem_object_init(), so we should never hit this unless |
408,31 → 450,18 |
if (pages == NULL) |
return ERR_PTR(-ENOMEM); |
|
gfpmask |= mapping_gfp_mask(mapping); |
|
for (i = 0; i < npages; i++) { |
p = shmem_read_mapping_page_gfp(mapping, i, gfpmask); |
p = shmem_read_mapping_page(mapping, i); |
if (IS_ERR(p)) |
goto fail; |
pages[i] = p; |
|
/* There is a hypothetical issue w/ drivers that require |
* buffer memory in the low 4GB.. if the pages are un- |
* pinned, and swapped out, they can end up swapped back |
* in above 4GB. If pages are already in memory, then |
* shmem_read_mapping_page_gfp will ignore the gfpmask, |
* even if the already in-memory page disobeys the mask. |
* |
* It is only a theoretical issue today, because none of |
* the devices with this limitation can be populated with |
* enough memory to trigger the issue. But this BUG_ON() |
* is here as a reminder in case the problem with |
* shmem_read_mapping_page_gfp() isn't solved by the time |
* it does become a real issue. |
* |
* See this thread: http://lkml.org/lkml/2011/7/11/238 |
/* Make sure shmem keeps __GFP_DMA32 allocated pages in the |
* correct region during swapin. Note that this requires |
* __GFP_DMA32 to be set in mapping_gfp_mask(inode->i_mapping) |
* so shmem can relocate pages during swapin if required. |
*/ |
BUG_ON((gfpmask & __GFP_DMA32) && |
BUG_ON((mapping_gfp_mask(mapping) & __GFP_DMA32) && |
(page_to_pfn(p) >= 0x00100000UL)); |
} |
|
508,6 → 537,11 |
EXPORT_SYMBOL(drm_gem_object_lookup); |
|
/** |
* drm_gem_close_ioctl - implementation of the GEM_CLOSE ioctl |
* @dev: drm_device |
* @data: ioctl data |
* @file_priv: drm file-private structure |
* |
* Releases the handle to an mm object. |
*/ |
int |
517,6 → 551,9 |
struct drm_gem_close *args = data; |
int ret; |
|
if (!(dev->driver->driver_features & DRIVER_GEM)) |
return -ENODEV; |
|
ret = drm_gem_handle_delete(file_priv, args->handle); |
|
return ret; |
523,6 → 560,11 |
} |
|
/** |
* drm_gem_flink_ioctl - implementation of the GEM_FLINK ioctl |
* @dev: drm_device |
* @data: ioctl data |
* @file_priv: drm file-private structure |
* |
* Create a global name for an object, returning the name. |
* |
* Note that the name does not hold a reference; when the object |
570,6 → 612,11 |
} |
|
/** |
* drm_gem_open - implementation of the GEM_OPEN ioctl |
* @dev: drm_device |
* @data: ioctl data |
* @file_priv: drm file-private structure |
* |
* Open an object using the global name, returning a handle and the size. |
* |
* This handle (of course) holds a reference to the object, so the object |
610,6 → 657,10 |
|
#if 0 |
/** |
* gem_gem_open - initalizes GEM file-private structures at devnode open time |
* @dev: drm_device which is being opened by userspace |
* @file_private: drm file-private structure to set up |
* |
* Called at device open time, sets up the structure for handling refcounting |
* of mm objects. |
*/ |
620,7 → 671,7 |
spin_lock_init(&file_private->table_lock); |
} |
|
/** |
/* |
* Called at device close to release the file's |
* handle references on objects. |
*/ |
642,6 → 693,10 |
} |
|
/** |
* drm_gem_release - release file-private GEM resources |
* @dev: drm_device which is being closed by userspace |
* @file_private: drm file-private structure to clean up |
* |
* Called at close time when the filp is going away. |
* |
* Releases any remaining references on objects by this filp. |
658,6 → 713,8 |
void |
drm_gem_object_release(struct drm_gem_object *obj) |
{ |
WARN_ON(obj->dma_buf); |
|
if (obj->filp) |
free(obj->filp); |
} |
664,6 → 721,9 |
EXPORT_SYMBOL(drm_gem_object_release); |
|
/** |
* drm_gem_object_free - free a GEM object |
* @kref: kref of the object to free |
* |
* Called after the last reference to the object has been lost. |
* Must be called holding struct_ mutex |
* |