Skip to content

Commit 8901cea

Browse files
drm: initial implementation DRM_IOCTL_GET_CAP
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent bb6779b commit 8901cea

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/aero_kernel/src/drivers/drm.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ use crate::mem::paging::VirtAddr;
3333
use uapi::drm::*;
3434

3535
trait DrmDevice: Send + Sync {
36+
/// Returns weather the DRM device supports creating dumb buffers.
37+
fn dumb_create(&self) -> bool;
38+
3639
/// Returns a tuple containg the driver major, minor and patch level respectively.
3740
fn driver_version(&self) -> (usize, usize, usize);
3841
/// Returns a tuple contaning the driver name, desc and date respectively.
@@ -106,6 +109,26 @@ impl INodeInterface for Drm {
106109
Ok(0)
107110
}
108111

112+
DRM_IOCTL_GET_CAP => {
113+
let struc = VirtAddr::new(arg as u64).read_mut::<DrmGetCap>().unwrap();
114+
115+
// NOTE: The user is responsible for zeroing out the structure.
116+
match struc.capability {
117+
DRM_CAP_DUMB_BUFFER => {
118+
if self.device.dumb_create() {
119+
struc.value = 1;
120+
}
121+
}
122+
123+
cap => {
124+
log::warn!("drm: unknown capability (`{cap}`)");
125+
return Err(FileSystemError::NotSupported);
126+
}
127+
}
128+
129+
Ok(0)
130+
}
131+
109132
_ => {
110133
// command[8..16] is the ASCII character supposedly unique to each driver.
111134
if command.get_bits(8..16) == DRM_IOCTL_BASE {
@@ -114,7 +137,7 @@ impl INodeInterface for Drm {
114137
unimplemented!("drm: function (`{function}`) not supported")
115138
}
116139

117-
log::warn!("drm: unknown ioctl (`{command}`) called");
140+
log::warn!("drm: unknown ioctl command (`{command}`)");
118141
Err(FileSystemError::NotSupported)
119142
}
120143
}
@@ -145,6 +168,10 @@ impl DrmDevice for RawFramebuffer {
145168
fn driver_info(&self) -> (&'static str, &'static str, &'static str) {
146169
("rawfb_gpu", "rawfb gpu", "0")
147170
}
171+
172+
fn dumb_create(&self) -> bool {
173+
true
174+
}
148175
}
149176

150177
fn init() {

src/uapi/src/drm.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,31 @@ pub struct DrmVersion {
6868
pub desc: *mut u8, // buffer to hold desc
6969
}
7070

71+
// Refer to the `libdrm` documentation for more information about the
72+
// capabilities.
73+
pub const DRM_CAP_DUMB_BUFFER: u64 = 0x01;
74+
pub const DRM_CAP_VBLANK_HIGH_CRTC: u64 = 0x02;
75+
pub const DRM_CAP_DUMB_PREFERRED_DEPTH: u64 = 0x03;
76+
pub const DRM_CAP_DUMB_PREFER_SHADOW: u64 = 0x04;
77+
pub const DRM_CAP_PRIME: u64 = 0x05;
78+
pub const DRM_PRIME_CAP_IMPORT: u64 = 0x01;
79+
pub const DRM_PRIME_CAP_EXPORT: u64 = 0x02;
80+
pub const DRM_CAP_TIMESTAMP_MONOTONIC: u64 = 0x06;
81+
pub const DRM_CAP_ASYNC_PAGE_FLIP: u64 = 0x07;
82+
pub const DRM_CAP_CURSOR_WIDTH: u64 = 0x08;
83+
pub const DRM_CAP_CURSOR_HEIGHT: u64 = 0x09;
84+
pub const DRM_CAP_ADDFB2_MODIFIERS: u64 = 0x10;
85+
pub const DRM_CAP_PAGE_FLIP_TARGET: u64 = 0x11;
86+
pub const DRM_CAP_CRTC_IN_VBLANK_EVENT: u64 = 0x12;
87+
pub const DRM_CAP_SYNCOBJ: u64 = 0x13;
88+
pub const DRM_CAP_SYNCOBJ_TIMELINE: u64 = 0x14;
89+
90+
#[repr(C)]
91+
pub struct DrmGetCap {
92+
pub capability: u64,
93+
pub value: u64,
94+
}
95+
7196
// DRM IOCTL constants:
7297
pub const DRM_IOCTL_VERSION: usize = drm_iowr::<DrmVersion>(0x00);
98+
pub const DRM_IOCTL_GET_CAP: usize = drm_iowr::<DrmGetCap>(0x0c);

0 commit comments

Comments
 (0)