Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce more driver abstractions #152

Merged
merged 64 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
0355ea6
Bump virtio_drivers dependency
nspin Jun 11, 2024
b1afdb9
Remove unused dependency
nspin Jun 11, 2024
e92624b
crates/sel4-drivers/virtio-hal-impl: Move here
nspin Jun 11, 2024
d27393b
crates/sel4-shared-ring-buffer/smoltcp: Use entire DeviceCapabilities…
nspin Jun 11, 2024
7c90e63
crates/sel4-async/io: Use embedded-io-async error types
nspin Jun 11, 2024
5a390ba
crates/sel4-async/io: Leverage the embedded-io-async crate
nspin Jun 11, 2024
bd5320b
crates/sel4-microkit/smoltcp-device-adapter: Move out of sel4-hal-ada…
nspin Jun 11, 2024
929a0e4
crates/sel4-hal-adapters: Update code
nspin Jun 11, 2024
85bf800
crates/sel4-hal-adapters: Rename module
nspin Jun 11, 2024
230d072
crates/sel4-hal-adapters: Split into modules
nspin Jun 11, 2024
4468fa0
crates/sel4-hal-adapters: Simplify idents
nspin Jun 11, 2024
ac94fe5
crates/sel4-hal-adapters: Reorder items
nspin Jun 11, 2024
5f69824
Rename GetCharSomeResponse -> GetCharResponse
nspin Jun 11, 2024
79aaf58
crates/sel4-hal-adapters: Refactor errors
nspin Jun 11, 2024
3f7bc07
crates/sel4-hal-adapters: Remove fmt::Write impl
nspin Jun 11, 2024
e882b3b
crates/sel4-microkit/embedded-hal-adapters: Move here
nspin Jun 11, 2024
1ba20bb
crates/sel4-microkit/smoltcp-device-adapter: Split into modules
nspin Jun 12, 2024
099fa72
nix: Add non-ukit config for zcu102
nspin Jun 11, 2024
dfd9d5f
Use driver abstractions in examples
nspin Jun 12, 2024
2db6cb4
Fix attribution
nspin Jun 12, 2024
e430ff5
crates/drivers: Initialize serial device in new()
nspin Jun 12, 2024
316230b
Set up Banscii for portability
nspin Jun 12, 2024
13c4357
nix: Work around issue with Z3 upstream aarch64 binary release
nspin Jun 14, 2024
9b18612
crates/sel4-microkit/drivers: Organize crates
nspin Jun 15, 2024
13313e6
crates/drivers: Organize crates
nspin Jun 15, 2024
4831e5e
Rename sel4-driver-traits -> sel4-driver-interfaces
nspin Jun 15, 2024
378aba6
Use structured reponse types for Microkit IPC
nspin Jun 15, 2024
1486016
crates/sel4-microkit: Ensure empty message is empty
nspin Jun 15, 2024
3dc8a2c
crates/sel4-microkit/message: Rework
nspin Jun 15, 2024
70f7005
Switch serial HAL adapter to non-blocking
nspin Jun 16, 2024
dca3dd4
Add write buffered serial wrapper
nspin Jun 16, 2024
766b0df
Improve rigidity of channel types
nspin Jun 16, 2024
a19f92d
Add RTC driver interface
nspin Jun 16, 2024
385f2a3
crates/sel4-driver-interfaces: Move here
nspin Jun 16, 2024
bc6b47d
Remove note
nspin Jun 16, 2024
95aa8c2
Factor out smoltcp_device_adapter::driver::handle_client_request
nspin Jun 16, 2024
b92840f
Rename sel4-microkit-embedded-hal-adapters -> sel4-microkit-driver-ad…
nspin Jun 16, 2024
dd5e2a3
crates/sel4-microkit/driver-adapters: Move here
nspin Jun 16, 2024
4063c91
crates/sel4-microkit/driver-adapters: Move net here
nspin Jun 16, 2024
504b252
crates/drivers: Flatten directory structure
nspin Jun 16, 2024
da103a7
Organize module structure
nspin Jun 16, 2024
2299539
Move WriteBuffered wrapper
nspin Jun 16, 2024
2f09fb6
crates/sel4-driver-interfaces: Add timer module
nspin Jun 16, 2024
a1111a0
Improve style
nspin Jun 17, 2024
5b2c1e9
crates/sel4-driver-interfaces: Add block module
nspin Jun 17, 2024
d05d290
crates/drivers/virtio/net: Rename to this
nspin Jun 17, 2024
0f33289
crates/drivers/virtio/blk: Add wrapper
nspin Jun 17, 2024
d9c2fac
Use sel4-driver-interfaces::block in driver
nspin Jun 17, 2024
0458407
Use sel4-driver-interfaces::block in HTTP server
nspin Jun 17, 2024
1ca42c0
Fix attribution
nspin Jun 17, 2024
4fcacfc
nix: Update seL4 dependency
nspin Jun 17, 2024
4a8c391
crates/sel4: Update after upstream change to seL4_VCPUReg
nspin Jun 17, 2024
137a246
Fix attribution
nspin Jun 17, 2024
6af1ea7
crates/sel4-driver-interfaces: Add wrappers for shared access
nspin Jun 17, 2024
fb1750e
Rework GetNetDeviceMeta trait
nspin Jun 19, 2024
33fda22
Rework GetBlockDeviceLayout trait
nspin Jun 19, 2024
3eebc8c
crates/sel4-driver-interfaces: Re-export rtcc items
nspin Jun 19, 2024
a2aaba2
crates/drivers: Clean up APIs
nspin Jun 19, 2024
a06847c
crates/examples/microkit: Clean up fn signatures
nspin Jun 19, 2024
3b9a846
crates/sel4-kernel-loader: Use driver crates
nspin Jun 19, 2024
c039f1a
crates/sel4-logging: Add SynchronizedLogger
nspin Jun 19, 2024
b0d4058
crates/sel4-immediate-sync-once-cell: Limit scope of unsafe ref
nspin Jun 19, 2024
d4f5ccb
crates/drivers: Fix const fns
nspin Jun 19, 2024
bd22742
Improve type names in driver adapters
nspin Jun 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
323 changes: 187 additions & 136 deletions Cargo.lock

Large diffs are not rendered by default.

21 changes: 10 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,26 @@
default-members = []
resolver = "2"
members = [
"crates/drivers/bcm2835-aux-uart",
"crates/drivers/pl011",
"crates/drivers/pl031",
"crates/drivers/sp804",
"crates/drivers/virtio/blk",
"crates/drivers/virtio/hal-impl",
"crates/drivers/virtio/net",
"crates/examples/microkit/banscii/pds/artist",
"crates/examples/microkit/banscii/pds/artist/interface-types",
"crates/examples/microkit/banscii/pds/assistant",
"crates/examples/microkit/banscii/pds/assistant/core",
"crates/examples/microkit/banscii/pds/assistant/core/test",
"crates/examples/microkit/banscii/pds/pl011-driver",
"crates/examples/microkit/banscii/pds/pl011-driver/core",
"crates/examples/microkit/banscii/pds/pl011-driver/interface-types",
"crates/examples/microkit/banscii/pds/serial-driver",
"crates/examples/microkit/hello/pds/hello",
"crates/examples/microkit/http-server/helpers/virtio-hal-impl",
"crates/examples/microkit/http-server/pds/pl031-driver",
"crates/examples/microkit/http-server/pds/pl031-driver/core",
"crates/examples/microkit/http-server/pds/pl031-driver/interface-types",
"crates/examples/microkit/http-server/pds/server",
"crates/examples/microkit/http-server/pds/server/core",
"crates/examples/microkit/http-server/pds/sp804-driver",
"crates/examples/microkit/http-server/pds/sp804-driver/core",
"crates/examples/microkit/http-server/pds/sp804-driver/interface-types",
"crates/examples/microkit/http-server/pds/virtio-blk-driver",
"crates/examples/microkit/http-server/pds/virtio-blk-driver/interface-types",
"crates/examples/microkit/http-server/pds/virtio-net-driver",
"crates/examples/microkit/http-server/pds/virtio-net-driver/interface-types",
"crates/examples/root-task/example-root-task",
"crates/examples/root-task/example-root-task-without-runtime",
"crates/examples/root-task/hello",
Expand Down Expand Up @@ -96,10 +94,10 @@ members = [
"crates/sel4-capdl-initializer/with-embedded-spec/embedded-spec",
"crates/sel4-capdl-initializer/with-embedded-spec/embedded-spec/validate",
"crates/sel4-dlmalloc",
"crates/sel4-driver-interfaces",
"crates/sel4-elf-header",
"crates/sel4-externally-shared",
"crates/sel4-generate-target-specs",
"crates/sel4-hal-adapters",
"crates/sel4-immediate-sync-once-cell",
"crates/sel4-immutable-cell",
"crates/sel4-initialize-tls",
Expand All @@ -112,6 +110,7 @@ members = [
"crates/sel4-logging",
"crates/sel4-microkit",
"crates/sel4-microkit/base",
"crates/sel4-microkit/driver-adapters",
"crates/sel4-microkit/macros",
"crates/sel4-microkit/message",
"crates/sel4-microkit/message/types",
Expand Down
15 changes: 15 additions & 0 deletions crates/drivers/bcm2835-aux-uart/Cargo.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Copyright 2024, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#

{ mk, versions, localCrates }:

mk {
package.name = "sel4-bcm2835-aux-uart-driver";
dependencies = {
inherit (versions) tock-registers embedded-hal-nb;
inherit (localCrates) sel4-driver-interfaces;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
#

[package]
name = "banscii-pl011-driver-interface-types"
name = "sel4-bcm2835-aux-uart-driver"
version = "0.1.0"
authors = ["Nick Spinale <[email protected]>"]
edition = "2021"
license = "BSD-2-Clause"

[dependencies]
serde = { version = "1.0.147", default-features = false }
embedded-hal-nb = "1.0"
sel4-driver-interfaces = { path = "../../sel4-driver-interfaces" }
tock-registers = "0.8.1"
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const MU_LSR_DATAREADY: u32 = 1 << 0;

register_structs! {
#[allow(non_snake_case)]
pub(crate)Bcm2835AuxUartRegisterBlock {
pub(crate) RegisterBlock {
(0x000 => _reserved0),
(0x040 => IO: ReadWrite<u8>),
(0x041 => _reserved1),
Expand All @@ -30,31 +30,31 @@ register_structs! {
}
}

pub(crate) struct Bcm2835AuxUartDevice {
base_addr: usize,
pub(crate) struct Device {
ptr: *mut RegisterBlock,
}

impl Bcm2835AuxUartDevice {
pub(crate) const unsafe fn new(base_addr: usize) -> Self {
Self { base_addr }
impl Device {
pub(crate) const unsafe fn new(ptr: *mut RegisterBlock) -> Self {
Self { ptr }
}

fn ptr(&self) -> *const Bcm2835AuxUartRegisterBlock {
self.base_addr as *const _
fn ptr(&self) -> *const RegisterBlock {
self.ptr
}

pub(crate) fn init(&self) {}
}

impl Deref for Bcm2835AuxUartDevice {
type Target = Bcm2835AuxUartRegisterBlock;
impl Deref for Device {
type Target = RegisterBlock;

fn deref(&self) -> &Self::Target {
unsafe { &*self.ptr() }
}
}

impl Bcm2835AuxUartDevice {
impl Device {
pub(crate) fn put_char(&self, c: u8) {
loop {
if self.LSR.get() & MU_LSR_TXIDLE != 0 {
Expand Down
74 changes: 74 additions & 0 deletions crates/drivers/bcm2835-aux-uart/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// Copyright 2024, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

#![no_std]

use core::convert::Infallible;

use embedded_hal_nb::nb;
use embedded_hal_nb::serial;

// use sel4_driver_interfaces::HandleInterrupt;

mod device;

use device::Device;

pub struct Driver {
device: Device,
}

unsafe impl Send for Driver {}
unsafe impl Sync for Driver {}

impl Driver {
#[allow(clippy::missing_safety_doc)]
pub const unsafe fn new_uninit(ptr: *mut ()) -> Self {
Self {
device: Device::new(ptr.cast()),
}
}

#[allow(clippy::missing_safety_doc)]
pub unsafe fn new(ptr: *mut ()) -> Self {
let mut this = Self::new_uninit(ptr);
this.init();
this
}

pub fn init(&mut self) {
self.device.init();
}
}

impl serial::ErrorType for Driver {
type Error = Infallible;
}

// TODO
// impl serial::Read for Driver {
// fn read(&mut self) -> nb::Result<u8, Self::Error> {
// self.device.get_char().ok_or(nb::Error::WouldBlock)
// }
// }

impl serial::Write for Driver {
fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
self.device.put_char(word);
Ok(())
}

fn flush(&mut self) -> nb::Result<(), Self::Error> {
Ok(())
}
}

// TODO
// impl HandleInterrupt for Driver {
// fn handle_interrupt(&mut self) {
// self.device.clear_all_interrupts()
// }
// }
15 changes: 15 additions & 0 deletions crates/drivers/pl011/Cargo.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Copyright 2023, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#

{ mk, versions, localCrates }:

mk {
package.name = "sel4-pl011-driver";
dependencies = {
inherit (versions) tock-registers embedded-hal-nb;
inherit (localCrates) sel4-driver-interfaces;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
#

[package]
name = "microkit-http-server-example-sp804-driver-core"
name = "sel4-pl011-driver"
version = "0.1.0"
authors = ["Nick Spinale <[email protected]>"]
edition = "2021"
license = "BSD-2-Clause"

[dependencies]
log = "0.4.17"
embedded-hal-nb = "1.0"
sel4-driver-interfaces = { path = "../../sel4-driver-interfaces" }
tock-registers = "0.8.1"
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ pub struct Device {
}

impl Device {
pub unsafe fn new(ptr: *mut RegisterBlock) -> Self {
pub const unsafe fn new(ptr: *mut RegisterBlock) -> Self {
Self { ptr }
}

fn ptr(&self) -> *mut RegisterBlock {
const fn ptr(&self) -> *mut RegisterBlock {
self.ptr
}

Expand Down
72 changes: 72 additions & 0 deletions crates/drivers/pl011/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// Copyright 2023, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

#![no_std]

use core::convert::Infallible;

use embedded_hal_nb::nb;
use embedded_hal_nb::serial;

use sel4_driver_interfaces::HandleInterrupt;

mod device;

use device::Device;

pub struct Driver {
device: Device,
}

unsafe impl Send for Driver {}
unsafe impl Sync for Driver {}

impl Driver {
#[allow(clippy::missing_safety_doc)]
pub const unsafe fn new_uninit(ptr: *mut ()) -> Self {
Self {
device: Device::new(ptr.cast()),
}
}

#[allow(clippy::missing_safety_doc)]
pub unsafe fn new(ptr: *mut ()) -> Self {
let mut this = Self::new_uninit(ptr);
this.init();
this
}

pub fn init(&mut self) {
self.device.init();
}
}

impl serial::ErrorType for Driver {
type Error = Infallible;
}

impl serial::Read for Driver {
fn read(&mut self) -> nb::Result<u8, Self::Error> {
self.device.get_char().ok_or(nb::Error::WouldBlock)
}
}

impl serial::Write for Driver {
fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
self.device.put_char(word);
Ok(())
}

fn flush(&mut self) -> nb::Result<(), Self::Error> {
Ok(())
}
}

impl HandleInterrupt for Driver {
fn handle_interrupt(&mut self) {
self.device.clear_all_interrupts()
}
}
14 changes: 14 additions & 0 deletions crates/drivers/pl031/Cargo.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Copyright 2024, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#

{ mk, versions, localCrates }:

mk {
package.name = "sel4-pl031-driver";
dependencies = {
inherit (versions) tock-registers rtcc;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#

[package]
name = "banscii-pl011-driver-core"
name = "sel4-pl031-driver"
version = "0.1.0"
authors = ["Nick Spinale <[email protected]>"]
edition = "2021"
license = "BSD-2-Clause"

[dependencies]
rtcc = "0.3.2"
tock-registers = "0.8.1"
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub struct Device {

#[allow(dead_code)]
impl Device {
pub unsafe fn new(ptr: *const ()) -> Self {
pub const unsafe fn new(ptr: *const ()) -> Self {
let ptr = ptr.cast::<RtcRegisterBlock>();
Self { ptr }
}
Expand Down
Loading
Loading