Skip to content

Commit 08d5bc3

Browse files
drm: initial implementation DRM_IOCTL_GET_CONNECTOR
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent a720000 commit 08d5bc3

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

src/aero_kernel/src/drivers/drm/mod.rs

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ struct Encoder {
129129
// index: u32,
130130
}
131131

132+
impl Encoder {
133+
pub fn new(object_id: u32) -> Arc<Self> {
134+
Arc::new_cyclic(|sref| Self {
135+
sref: sref.clone(),
136+
137+
object_id,
138+
})
139+
}
140+
}
141+
132142
impl ModeObject for Encoder {
133143
fn id(&self) -> u32 {
134144
self.object_id
@@ -144,13 +154,31 @@ impl ModeObject for Encoder {
144154
struct Connector {
145155
sref: Weak<Self>,
146156

157+
/// The current status of the connector.
158+
status: DrmModeConStatus,
159+
/// The current encoder for this connector.
160+
current_encoder: Arc<Encoder>,
161+
/// A vector contaning all the possible encoders for this connector.
162+
possible_encoders: Vec<Arc<Encoder>>,
163+
connector_typ: u32,
164+
147165
object_id: u32,
148166
}
149167

150168
impl Connector {
151-
pub fn new(object_id: u32) -> Arc<Self> {
169+
pub fn new(
170+
current_encoder: Arc<Encoder>,
171+
possible_encoders: Vec<Arc<Encoder>>,
172+
status: DrmModeConStatus,
173+
object_id: u32,
174+
) -> Arc<Self> {
152175
Arc::new_cyclic(|sref| Self {
153176
sref: sref.clone(),
177+
178+
status,
179+
current_encoder,
180+
possible_encoders,
181+
connector_typ: 0, // todo
154182
object_id,
155183
})
156184
}
@@ -378,6 +406,35 @@ impl INodeInterface for Drm {
378406

379407
let object = self.find_object(struc.connector_id).unwrap().as_connector();
380408

409+
// Fill in the array contaning all of the possible encoders and its length.
410+
let encoder_ids_ptr = struc.encoders_ptr as *mut u32;
411+
let mut encoder_count = 0;
412+
413+
copy_field::<u32>(
414+
encoder_ids_ptr,
415+
&mut encoder_count,
416+
object
417+
.possible_encoders
418+
.iter()
419+
.map(|e| e.id())
420+
.collect::<Vec<_>>()
421+
.as_slice(),
422+
);
423+
424+
struc.count_encoders = encoder_count as _;
425+
426+
struc.encoder_id = object.current_encoder.id();
427+
struc.connector_type = object.connector_typ;
428+
struc.connector_type_id = 0; // todo
429+
struc.connection = object.status as _;
430+
431+
// NOTE: The physical size will come from the EDID.
432+
struc.mm_width = 0; // todo
433+
struc.mm_height = 0; // todo
434+
struc.subpixel = 0; // todo
435+
struc.count_modes = 0; // todo
436+
struc.modes_ptr = 0; // todo
437+
381438
Ok(0)
382439
}
383440

src/aero_kernel/src/drivers/drm/rawfb.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,14 @@ fn init() {
5555
let rfb = Drm::new(Arc::new(RawFramebuffer {}));
5656

5757
let crtc = Crtc::new(&rfb, rfb.allocate_object_id());
58-
let connector = Connector::new(rfb.allocate_object_id());
58+
let encoder = Encoder::new(rfb.allocate_object_id());
59+
60+
let connector = Connector::new(
61+
encoder.clone(),
62+
alloc::vec![encoder.clone()],
63+
DrmModeConStatus::Connected,
64+
rfb.allocate_object_id(),
65+
);
5966

6067
let dri = devfs::DEV_FILESYSTEM
6168
.root_dir()

src/uapi/src/drm.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ pub struct DrmModeCardRes {
109109
pub max_height: u32,
110110
}
111111

112+
#[repr(u32)]
113+
#[derive(Copy, Clone, Debug)]
114+
pub enum DrmModeConStatus {
115+
Connected = 1, // connector has the sink plugged in
116+
Disconnected = 2,
117+
Unknown = 3,
118+
}
119+
112120
const DRM_DISPLAY_MODE_LEN: usize = 32;
113121

114122
#[repr(C)]

0 commit comments

Comments
 (0)