Skip to content

Commit

Permalink
Improve type names in driver adapters
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <nick@nickspinale.com>
  • Loading branch information
nspin committed Jun 19, 2024
1 parent 0a5cc54 commit f64baaa
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 56 deletions.
10 changes: 5 additions & 5 deletions crates/examples/microkit/banscii/pds/serial-driver/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
#![no_main]

use sel4_microkit::{memory_region_symbol, protection_domain, Channel, Handler};
use sel4_microkit_driver_adapters::serial::driver::Driver;
use sel4_microkit_driver_adapters::serial::driver::HandlerImpl;

#[cfg(feature = "board-qemu_virt_aarch64")]
use sel4_pl011_driver::Driver as DriverImpl;
use sel4_pl011_driver::Driver;

const DEVICE: Channel = Channel::new(0);
const ASSISTANT: Channel = Channel::new(1);

#[protection_domain]
fn init() -> impl Handler {
let driver_impl =
unsafe { DriverImpl::new(memory_region_symbol!(serial_register_block: *mut ()).as_ptr()) };
Driver::new(driver_impl, DEVICE, ASSISTANT)
let driver =
unsafe { Driver::new(memory_region_symbol!(serial_register_block: *mut ()).as_ptr()) };
HandlerImpl::new(driver, DEVICE, ASSISTANT)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
#![no_main]

use sel4_microkit::{memory_region_symbol, protection_domain, Channel, Handler};
use sel4_microkit_driver_adapters::rtc::driver::Driver;
use sel4_pl031_driver::Driver as DriverImpl;
use sel4_microkit_driver_adapters::rtc::driver::HandlerImpl;
use sel4_pl031_driver::Driver;

const _DEVICE: Channel = Channel::new(0);
const CLIENT: Channel = Channel::new(1);

#[protection_domain]
fn init() -> impl Handler {
let driver_impl =
unsafe { DriverImpl::new(memory_region_symbol!(pl031_mmio_vaddr: *mut ()).as_ptr()) };
Driver::new(driver_impl, CLIENT)
let driver = unsafe { Driver::new(memory_region_symbol!(pl031_mmio_vaddr: *mut ()).as_ptr()) };
HandlerImpl::new(driver, CLIENT)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

use sel4_driver_interfaces::timer::SingleTimer;
use sel4_microkit::{memory_region_symbol, protection_domain, Channel, Handler};
use sel4_microkit_driver_adapters::timer::driver::Driver;
use sel4_sp804_driver::Driver as DriverImpl;
use sel4_microkit_driver_adapters::timer::driver::HandlerImpl;
use sel4_sp804_driver::Driver;

const DEVICE: Channel = Channel::new(0);
const CLIENT: Channel = Channel::new(1);
Expand All @@ -19,11 +19,11 @@ const FREQ: u64 = 1_000_000;

#[protection_domain]
fn init() -> impl Handler {
let driver_impl = unsafe {
DriverImpl::new(
let driver = unsafe {
Driver::new(
memory_region_symbol!(sp804_mmio_vaddr: *mut ()).as_ptr(),
FREQ,
)
};
Driver::new(SingleTimer(driver_impl), DEVICE, CLIENT).unwrap()
HandlerImpl::new(SingleTimer(driver), DEVICE, CLIENT).unwrap()
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use virtio_drivers::{

use sel4_externally_shared::{ExternallySharedRef, ExternallySharedRefExt};
use sel4_microkit::{memory_region_symbol, protection_domain, var};
use sel4_microkit_driver_adapters::net::driver::Driver;
use sel4_microkit_driver_adapters::net::driver::HandlerImpl;
use sel4_shared_ring_buffer::{roles::Use, RingBuffers};
use sel4_virtio_hal_impl::HalImpl;
use sel4_virtio_net::DeviceWrapper;
Expand All @@ -34,7 +34,7 @@ const NET_BUFFER_LEN: usize = 2048;
#[protection_domain(
heap_size = 512 * 1024,
)]
fn init() -> Driver<DeviceWrapper<HalImpl, MmioTransport>> {
fn init() -> HandlerImpl<DeviceWrapper<HalImpl, MmioTransport>> {
HalImpl::init(
config::VIRTIO_NET_DRIVER_DMA_SIZE,
*var!(virtio_net_driver_dma_vaddr: usize = 0),
Expand Down Expand Up @@ -77,7 +77,7 @@ fn init() -> Driver<DeviceWrapper<HalImpl, MmioTransport>> {
dev.ack_interrupt();
channels::DEVICE.irq_ack().unwrap();

Driver::new(
HandlerImpl::new(
DeviceWrapper::new(dev),
client_region,
rx_ring_buffers,
Expand Down
6 changes: 3 additions & 3 deletions crates/sel4-microkit/driver-adapters/src/net/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use sel4_shared_ring_buffer::{roles::Use, RingBuffers};

use super::message_types::*;

pub struct Driver<Device> {
pub struct HandlerImpl<Device> {
dev: Device,
client_region: ExternallySharedRef<'static, [u8]>,
rx_ring_buffers: RingBuffers<'static, Use, fn()>,
Expand All @@ -30,7 +30,7 @@ pub struct Driver<Device> {
client_channel: Channel,
}

impl<Device> Driver<Device> {
impl<Device> HandlerImpl<Device> {
pub fn new(
dev: Device,
client_region: ExternallySharedRef<'static, [u8]>,
Expand All @@ -50,7 +50,7 @@ impl<Device> Driver<Device> {
}
}

impl<Device: phy::Device + HandleInterrupt + GetNetDeviceMeta> Handler for Driver<Device> {
impl<Device: phy::Device + HandleInterrupt + GetNetDeviceMeta> Handler for HandlerImpl<Device> {
type Error = Infallible;

fn notified(&mut self, channel: Channel) -> Result<(), Self::Error> {
Expand Down
18 changes: 9 additions & 9 deletions crates/sel4-microkit/driver-adapters/src/rtc/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ use super::message_types::*;

/// Handle messages using an implementor of [serial::Read<u8>] and [serial::Write<u8>].
#[derive(Clone, Debug)]
pub struct Driver<Device> {
device: Device,
pub struct HandlerImpl<Driver> {
driver: Driver,
client: Channel,
}

impl<Device> Driver<Device> {
pub fn new(device: Device, client: Channel) -> Self {
Self { device, client }
impl<Driver> HandlerImpl<Driver> {
pub fn new(driver: Driver, client: Channel) -> Self {
Self { driver, client }
}
}

impl<Device> Handler for Driver<Device>
impl<Driver> Handler for HandlerImpl<Driver>
where
Device: DateTimeAccess,
Driver: DateTimeAccess,
{
type Error = Infallible;

Expand All @@ -42,12 +42,12 @@ where
Ok(req) => {
let resp = match req {
Request::DateTime => self
.device
.driver
.datetime()
.map(SuccessResponse::DateTime)
.map_err(|_| ErrorResponse::DateTimeError),
Request::SetDateTime(v) => self
.device
.driver
.set_datetime(&v)
.map(|_| SuccessResponse::SetDateTime)
.map_err(|_| ErrorResponse::SetDateTimeError),
Expand Down
26 changes: 13 additions & 13 deletions crates/sel4-microkit/driver-adapters/src/serial/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use super::message_types::*;

/// Handle messages using an implementor of [serial::Read<u8>] and [serial::Write<u8>].
#[derive(Clone, Debug)]
pub struct Driver<Device, const READ_BUF_SIZE: usize = 256> {
/// Device implementing [serial::Read<u8>] and [serial::Write<u8>].
device: Device,
pub struct HandlerImpl<Driver, const READ_BUF_SIZE: usize = 256> {
/// Driver implementing [serial::Read<u8>] and [serial::Write<u8>].
driver: Driver,
/// Channel for this component.
serial: Channel,
/// Channel for client component.
Expand All @@ -32,13 +32,13 @@ pub struct Driver<Device, const READ_BUF_SIZE: usize = 256> {
notify: bool,
}

impl<Device, const READ_BUF_SIZE: usize> Driver<Device, READ_BUF_SIZE>
impl<Driver, const READ_BUF_SIZE: usize> HandlerImpl<Driver, READ_BUF_SIZE>
where
Device: serial::Read<u8> + serial::Write<u8> + HandleInterrupt,
Driver: serial::Read<u8> + serial::Write<u8> + HandleInterrupt,
{
pub fn new(device: Device, serial: Channel, client: Channel) -> Self {
pub fn new(driver: Driver, serial: Channel, client: Channel) -> Self {
Self {
device,
driver,
serial,
client,
buffer: Deque::new(),
Expand All @@ -47,16 +47,16 @@ where
}
}

impl<Device> Handler for Driver<Device>
impl<Driver> Handler for HandlerImpl<Driver>
where
Device: serial::Read<u8> + serial::Write<u8> + HandleInterrupt,
Driver: serial::Read<u8> + serial::Write<u8> + HandleInterrupt,
{
type Error = Infallible;

fn notified(&mut self, channel: Channel) -> Result<(), Self::Error> {
if channel == self.serial {
while !self.buffer.is_full() {
match self.device.read() {
match self.driver.read() {
Ok(v) => {
self.buffer.push_back(v).unwrap();
}
Expand All @@ -69,7 +69,7 @@ where
}
}
}
self.device.handle_interrupt();
self.driver.handle_interrupt();
self.serial.irq_ack().unwrap();
if self.notify {
self.client.notify();
Expand Down Expand Up @@ -97,10 +97,10 @@ where
}
Ok(SuccessResponse::Read(v.into()))
}
Request::Write(c) => NonBlocking::from_nb_result(self.device.write(c))
Request::Write(c) => NonBlocking::from_nb_result(self.driver.write(c))
.map(SuccessResponse::Write)
.map_err(|_| ErrorResponse::WriteError),
Request::Flush => NonBlocking::from_nb_result(self.device.flush())
Request::Flush => NonBlocking::from_nb_result(self.driver.flush())
.map(SuccessResponse::Flush)
.map_err(|_| ErrorResponse::FlushError),
};
Expand Down
26 changes: 13 additions & 13 deletions crates/sel4-microkit/driver-adapters/src/timer/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ use sel4_microkit_message::MessageInfoExt;
use super::message_types::*;

#[derive(Clone, Debug)]
pub struct Driver<Device> {
device: Device,
pub struct HandlerImpl<Driver> {
driver: Driver,
timer: Channel,
client: Channel,
num_timers: usize,
}

impl<Device: Timers<TimerLayout = NumTimers>> Driver<Device> {
pub fn new(mut device: Device, timer: Channel, client: Channel) -> Result<Self, Device::Error> {
let num_timers = device.timer_layout()?.0;
impl<Driver: Timers<TimerLayout = NumTimers>> HandlerImpl<Driver> {
pub fn new(mut driver: Driver, timer: Channel, client: Channel) -> Result<Self, Driver::Error> {
let num_timers = driver.timer_layout()?.0;
Ok(Self {
device,
driver,
timer,
client,
num_timers,
Expand All @@ -41,15 +41,15 @@ impl<Device: Timers<TimerLayout = NumTimers>> Driver<Device> {
}
}

impl<Device> Handler for Driver<Device>
impl<Driver> Handler for HandlerImpl<Driver>
where
Device: Timers<TimerLayout = NumTimers, Timer = usize> + HandleInterrupt,
Driver: Timers<TimerLayout = NumTimers, Timer = usize> + HandleInterrupt,
{
type Error = Infallible;

fn notified(&mut self, channel: Channel) -> Result<(), Self::Error> {
if channel == self.timer {
self.device.handle_interrupt();
self.driver.handle_interrupt();
self.timer.irq_ack().unwrap();
self.client.notify();
} else {
Expand All @@ -68,25 +68,25 @@ where
Ok(req) => {
let resp = match req {
Request::GetTime => self
.device
.driver
.get_time()
.map(SuccessResponse::GetTime)
.map_err(|_| ErrorResponse::Unspecified),
Request::NumTimers => self
.device
.driver
.timer_layout()
.map(|NumTimers(n)| SuccessResponse::NumTimers(n))
.map_err(|_| ErrorResponse::Unspecified),
Request::SetTimeout { timer, relative } => {
self.guard_timer(timer).and_then(|_| {
self.device
self.driver
.set_timeout_on(timer, relative)
.map(|_| SuccessResponse::SetTimeout)
.map_err(|_| ErrorResponse::Unspecified)
})
}
Request::ClearTimeout { timer } => self.guard_timer(timer).and_then(|_| {
self.device
self.driver
.clear_timeout_on(timer)
.map(|_| SuccessResponse::ClearTimeout)
.map_err(|_| ErrorResponse::Unspecified)
Expand Down

0 comments on commit f64baaa

Please sign in to comment.