Skip to content

Commit 6f52b3f

Browse files
committed
HACK: rust: drm: device: Add device initialization without data
Required by the asahi driver. Signed-off-by: Janne Grunau <j@jannau.net>
1 parent 74de534 commit 6f52b3f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

rust/kernel/drm/device.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,25 @@ impl<T: drm::drv::Driver> Device<T> {
107107
Ok(drm)
108108
}
109109

110+
/// Create a new `drm::device::Device` for a `drm::drv::Driver`.
111+
pub fn new_no_data(dev: &device::Device) -> Result<ARef<Self>> {
112+
// SAFETY: `dev` is valid by its type invarants; `VTABLE`, as a `const` is pinned to the
113+
// read-only section of the compilation.
114+
let raw_drm = unsafe { bindings::drm_dev_alloc(&Self::VTABLE, dev.as_raw()) };
115+
let raw_drm = NonNull::new(from_err_ptr(raw_drm)? as *mut _).ok_or(ENOMEM)?;
116+
117+
// SAFETY: The reference count is one, and now we take ownership of that reference as a
118+
// drm::device::Device.
119+
let drm = unsafe { ARef::<Self>::from_raw(raw_drm) };
120+
121+
Ok(drm)
122+
}
123+
124+
pub unsafe fn init_data(&self, data: T::Data) {
125+
let data_ptr = <T::Data as ForeignOwnable>::into_foreign(data);
126+
unsafe { self.set_raw_data(data_ptr) };
127+
}
128+
110129
pub(crate) fn as_raw(&self) -> *mut bindings::drm_device {
111130
self.0.get()
112131
}

0 commit comments

Comments
 (0)