Skip to content

Commit

Permalink
drm/gem: Create a drm_gem_object_init_with_mnt() function
Browse files Browse the repository at this point in the history
For some applications, such as applications that uses huge pages, we might
want to have a different mountpoint, for which we pass mount flags that
better match our usecase.

Therefore, create a new function `drm_gem_object_init_with_mnt()` that
allow us to define the tmpfs mountpoint where the GEM object will be
created. If this parameter is NULL, then we fallback to `shmem_file_setup()`.

Signed-off-by: Maíra Canal <[email protected]>
Reviewed-by: Tvrtko Ursulin <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
  • Loading branch information
mairacanal committed Sep 25, 2024
1 parent 56cf76e commit 0992b25
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
34 changes: 30 additions & 4 deletions drivers/gpu/drm/drm_gem.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,29 +114,55 @@ drm_gem_init(struct drm_device *dev)
}

/**
* drm_gem_object_init - initialize an allocated shmem-backed GEM object
* drm_gem_object_init_with_mnt - initialize an allocated shmem-backed GEM
* object in a given shmfs mountpoint
*
* @dev: drm_device the object should be initialized for
* @obj: drm_gem_object to initialize
* @size: object size
* @gemfs: tmpfs mount where the GEM object will be created. If NULL, use
* the usual tmpfs mountpoint (`shm_mnt`).
*
* Initialize an already allocated GEM object of the specified size with
* shmfs backing store.
*/
int drm_gem_object_init(struct drm_device *dev,
struct drm_gem_object *obj, size_t size)
int drm_gem_object_init_with_mnt(struct drm_device *dev,
struct drm_gem_object *obj, size_t size,
struct vfsmount *gemfs)
{
struct file *filp;

drm_gem_private_object_init(dev, obj, size);

filp = shmem_file_setup("drm mm object", size, VM_NORESERVE);
if (gemfs)
filp = shmem_file_setup_with_mnt(gemfs, "drm mm object", size,
VM_NORESERVE);
else
filp = shmem_file_setup("drm mm object", size, VM_NORESERVE);

if (IS_ERR(filp))
return PTR_ERR(filp);

obj->filp = filp;

return 0;
}
EXPORT_SYMBOL(drm_gem_object_init_with_mnt);

/**
* 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.
*/
int drm_gem_object_init(struct drm_device *dev, struct drm_gem_object *obj,
size_t size)
{
return drm_gem_object_init_with_mnt(dev, obj, size, NULL);
}
EXPORT_SYMBOL(drm_gem_object_init);

/**
Expand Down
3 changes: 3 additions & 0 deletions include/drm/drm_gem.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ void drm_gem_object_release(struct drm_gem_object *obj);
void drm_gem_object_free(struct kref *kref);
int drm_gem_object_init(struct drm_device *dev,
struct drm_gem_object *obj, size_t size);
int drm_gem_object_init_with_mnt(struct drm_device *dev,
struct drm_gem_object *obj, size_t size,
struct vfsmount *gemfs);
void drm_gem_private_object_init(struct drm_device *dev,
struct drm_gem_object *obj, size_t size);
void drm_gem_private_object_fini(struct drm_gem_object *obj);
Expand Down

0 comments on commit 0992b25

Please sign in to comment.