Skip to content

Commit f1a087c

Browse files
hoshinolinamarcan
authored andcommitted
rust: drm: gem: Add GEM object abstraction
The DRM GEM subsystem is the DRM memory management subsystem used by most modern drivers. Add a Rust abstraction to allow Rust DRM driver implementations to use it. Signed-off-by: Asahi Lina <lina@asahilina.net>
1 parent 258a6b5 commit f1a087c

5 files changed

Lines changed: 398 additions & 2 deletions

File tree

rust/bindings/bindings_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <drm/drm_device.h>
1010
#include <drm/drm_drv.h>
1111
#include <drm/drm_file.h>
12+
#include <drm/drm_gem.h>
1213
#include <drm/drm_ioctl.h>
1314
#include <linux/delay.h>
1415
#include <linux/device.h>

rust/helpers.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* accidentally exposed.
1919
*/
2020

21+
#include <drm/drm_gem.h>
2122
#include <linux/bug.h>
2223
#include <linux/build_bug.h>
2324
#include <linux/device.h>
@@ -422,6 +423,28 @@ resource_size_t rust_helper_resource_size(const struct resource *res)
422423
}
423424
EXPORT_SYMBOL_GPL(rust_helper_resource_size);
424425

426+
#ifdef CONFIG_DRM
427+
428+
void rust_helper_drm_gem_object_get(struct drm_gem_object *obj)
429+
{
430+
drm_gem_object_get(obj);
431+
}
432+
EXPORT_SYMBOL_GPL(rust_helper_drm_gem_object_get);
433+
434+
void rust_helper_drm_gem_object_put(struct drm_gem_object *obj)
435+
{
436+
drm_gem_object_put(obj);
437+
}
438+
EXPORT_SYMBOL_GPL(rust_helper_drm_gem_object_put);
439+
440+
__u64 rust_helper_drm_vma_node_offset_addr(struct drm_vma_offset_node *node)
441+
{
442+
return drm_vma_node_offset_addr(node);
443+
}
444+
EXPORT_SYMBOL_GPL(rust_helper_drm_vma_node_offset_addr);
445+
446+
#endif
447+
425448
/*
426449
* We use `bindgen`'s `--size_t-is-usize` option to bind the C `size_t` type
427450
* as the Rust `usize` type, so we can use it in contexts where Rust

rust/kernel/drm/drv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub struct AllocOps {
120120
}
121121

122122
/// Trait for memory manager implementations. Implemented internally.
123-
pub trait AllocImpl: Sealed {
123+
pub trait AllocImpl: Sealed + drm::gem::IntoGEMObject {
124124
/// The C callback operations for this memory manager.
125125
const ALLOC_OPS: AllocOps;
126126
}
@@ -256,7 +256,7 @@ impl<T: Driver> Registration<T> {
256256
drm,
257257
registered: false,
258258
vtable,
259-
fops: Default::default(), // TODO: GEM abstraction
259+
fops: drm::gem::create_fops(),
260260
_pin: PhantomPinned,
261261
_p: PhantomData,
262262
})

0 commit comments

Comments
 (0)