Skip to content

Commit

Permalink
Implements dce + hmd devices (obhq#859)
Browse files Browse the repository at this point in the history
Co-authored-by: tompro <[email protected]>
  • Loading branch information
SuchAFuriousDeath and tompro authored May 4, 2024
1 parent 4bbb9d1 commit fa5ea8e
Show file tree
Hide file tree
Showing 16 changed files with 487 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/kernel/src/dev/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl CameraManager {
Gid::ROOT,
Mode::new(0o666).unwrap(),
None,
MakeDevFlags::MAKEDEV_ETERNAL,
MakeDevFlags::ETERNAL,
)?;

Ok(Arc::new(Self { camera }))
Expand Down
115 changes: 115 additions & 0 deletions src/kernel/src/dev/dce.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
use crate::{
errno::Errno,
fs::{
make_dev, CharacterDevice, DeviceDriver, DriverFlags, IoCmd, MakeDevError, MakeDevFlags,
Mode, OpenFlags,
},
process::VThread,
ucred::{Gid, Uid},
};
use std::sync::Arc;
use thiserror::Error;

#[derive(Debug)]
struct Dce {}

impl Dce {
fn new() -> Self {
Self {}
}
}

impl DeviceDriver for Dce {
#[allow(unused_variables)] // TODO: remove when implementing
fn open(
&self,
dev: &Arc<CharacterDevice>,
mode: OpenFlags,
devtype: i32,
td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
todo!()
}

fn ioctl(
&self,
_: &Arc<CharacterDevice>,
cmd: IoCmd,
_: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
match cmd {
IoCmd::DCEFLIPCONTROL(_) => todo!("DCEFLIPCONTROL ioctl"),
IoCmd::DCESUBMITFLIP(_) => todo!("DCESUBMITFLIP ioctl"),
IoCmd::DCEREGBUFPTRS(_) => todo!("DCEREGBUFPOINTERS ioctl"),
IoCmd::DCEREGBUFATTR(_) => todo!("DCEREGBUFATTR ioctl"),
IoCmd::DCEDEREGIDENT(_) => todo!("DCEDEREGIDENT ioctl"),
_ => todo!(),
}
}
}

pub struct DceManager {
dce: Arc<CharacterDevice>,
}

impl DceManager {
pub fn new() -> Result<Arc<Self>, DceInitError> {
let dce = make_dev(
Dce::new(),
DriverFlags::INIT,
0,
"dce",
Uid::ROOT,
Gid::ROOT,
Mode::new(0o666).unwrap(),
None,
MakeDevFlags::empty(),
)?;

Ok(Arc::new(Self { dce }))
}
}

#[repr(C)]
#[derive(Debug)]
pub struct DceFlipControlArg {
id: u32,
arg1: usize,
arg2: usize,
arg3: usize,
arg4: u64,
arg5: u64,
}

#[repr(C)]
#[derive(Debug)]
pub struct DceSubmitFlipArg {
canary: usize,
buffer_index: usize,
flip_mode: u32,
arg1: usize,
arg2: usize,
eop_nz: u32,
eop_val: usize,
unk: usize,
rout: usize,
}

#[repr(C)]
#[derive(Debug)]
pub struct DceRegisterBufferPtrsArg {
canary: usize,
index: u32,
attrid: u32,
left: usize,
right: usize,
unk: u32,
_align: u64,
}

/// Represents an error when [`DceManager`] fails to initialize.
#[derive(Debug, Error)]
pub enum DceInitError {
#[error("cannot create dce device")]
CreateDceFailed(#[from] MakeDevError),
}
2 changes: 1 addition & 1 deletion src/kernel/src/dev/dipsw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl DipswManager {
Gid::ROOT,
Mode::new(0o644).unwrap(),
None,
MakeDevFlags::MAKEDEV_ETERNAL,
MakeDevFlags::ETERNAL,
)?;

Ok(Arc::new(Self { dipsw }))
Expand Down
48 changes: 43 additions & 5 deletions src/kernel/src/dev/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ use std::sync::Arc;
use thiserror::Error;

#[derive(Debug)]
struct Gc {}
struct Gc {
suspended: bool,
}

impl Gc {
fn new() -> Self {
Self {}
Self { suspended: false }
}
}

Expand All @@ -35,15 +37,30 @@ impl DeviceDriver for Gc {
&self,
_: &Arc<CharacterDevice>,
cmd: IoCmd,
_: Option<&VThread>,
td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
if self.suspended {
todo!("gc suspended")
}

let td = td.unwrap();

let gc_check_passed = td.cred().unk_gc_check();
// TODO: implement devfs_get_cdevpriv

match cmd {
IoCmd::GCSETWAVELIMITMULTIPLIER(mult) => todo!("GCSETWAVELIMITMULTIPLIER: {mult:?}"),
IoCmd::GCSUBMIT(submit_arg) => todo!("GCSUBMIT ioctl: {submit_arg:?}"),
IoCmd::GCGETCUMASK(mask) => todo!("GCGETCUMASK ioctl: {mask:?}"),
IoCmd::GCMAPCOMPUTEQUEUE(queue) => todo!("GCMAPCOMPUTEQUEUE ioctl: {queue:?}"),
IoCmd::GCUNMAPCOMPUTEQUEUE(unk) => todo!("GCUNMAPCOMPUTEQUEUE ioctl: {unk:?}"),
IoCmd::GCSETGSRINGSIZES(unk1) => todo!("GCSETGSRINGSIZES ioctl: {unk1:?}"),
IoCmd::GCSETGSRINGSIZES(unk1) => {
for _ in 0..100 {
todo!()
}

todo!("GCSETGSRINGSIZES ioctl: {unk1:?}")
}
IoCmd::GCMIPSTATSREPORT(report) => todo!("GCMIPSTATSREPORT ioctl: {report:?}"),
IoCmd::GCARESUBMITSALLOWED(unk) => todo!("GCARESUBMITSALLOWED ioctl: {unk:?}"),
IoCmd::GCGETNUMTCAUNITS(num) => todo!("GCGETNUMTCAUNITS ioctl: {num:?}"),
Expand All @@ -68,7 +85,7 @@ impl GcManager {
Gid::ROOT,
Mode::new(0o666).unwrap(),
None,
MakeDevFlags::MAKEDEV_ETERNAL,
MakeDevFlags::ETERNAL,
)?;

Ok(Arc::new(Self { gc }))
Expand All @@ -92,6 +109,27 @@ pub struct CuMask {
unk4: i32,
}

#[derive(Debug)]
#[repr(C)]
pub struct MapComputeQueueArg {
pipe_hi: u32,
pipe_lo: u32,
queue_id: u32,
offset: u32,
ring_base_address: usize,
read_ptr_address: usize,
ding_dong: usize,
len_log: u32,
}

#[derive(Debug)]
#[repr(C)]
pub struct UnmapComputeQueueArg {
unk1: u32,
unk2: u32,
unk3: u32,
}

#[derive(Debug)]
#[repr(C)]
pub struct MipStatsReport {
Expand Down
Loading

0 comments on commit fa5ea8e

Please sign in to comment.