drm/gem: Create a drm_gem_object_init_with_mnt() function

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 <mcanal@igalia.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240923141348.2422499-5-mcanal@igalia.com
This commit is contained in:
Maíra Canal 2024-09-23 10:55:08 -03:00
parent 56cf76ed78
commit 0992b2541e
No known key found for this signature in database
GPG Key ID: 6E388F05AB35B7CF
2 changed files with 42 additions and 13 deletions

View File

@ -113,6 +113,42 @@ drm_gem_init(struct drm_device *dev)
return drmm_add_action(dev, drm_gem_init_release, NULL);
}
/**
* 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_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);
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
@ -122,20 +158,10 @@ drm_gem_init(struct drm_device *dev)
* 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(struct drm_device *dev, struct drm_gem_object *obj,
size_t size)
{
struct file *filp;
drm_gem_private_object_init(dev, obj, size);
filp = shmem_file_setup("drm mm object", size, VM_NORESERVE);
if (IS_ERR(filp))
return PTR_ERR(filp);
obj->filp = filp;
return 0;
return drm_gem_object_init_with_mnt(dev, obj, size, NULL);
}
EXPORT_SYMBOL(drm_gem_object_init);

View File

@ -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);