From 78a2a981b0f8d04dff3a8af147576eff839dfef4 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Wed, 25 Oct 2023 23:51:47 +0000 Subject: [PATCH] Remove dependence on setvar patch for Microkit Signed-off-by: Nick Spinale --- .../microkit/http-server/http-server.system | 9 ------ .../http-server/pds/server/src/config.rs | 16 +++++++++++ .../http-server/pds/server/src/main.rs | 28 +++++++++---------- .../pds/sp804-driver/src/config.rs | 14 ++++++++++ .../http-server/pds/sp804-driver/src/main.rs | 17 +++++------ .../pds/virtio-blk-driver/src/config.rs | 16 +++++++++++ .../pds/virtio-blk-driver/src/main.rs | 21 +++++++------- .../pds/virtio-net-driver/src/config.rs | 16 +++++++++++ .../pds/virtio-net-driver/src/main.rs | 21 +++++++------- hacking/nix/scope/sources.nix | 2 +- 10 files changed, 107 insertions(+), 53 deletions(-) create mode 100644 crates/examples/microkit/http-server/pds/server/src/config.rs create mode 100644 crates/examples/microkit/http-server/pds/sp804-driver/src/config.rs create mode 100644 crates/examples/microkit/http-server/pds/virtio-blk-driver/src/config.rs create mode 100644 crates/examples/microkit/http-server/pds/virtio-net-driver/src/config.rs diff --git a/crates/examples/microkit/http-server/http-server.system b/crates/examples/microkit/http-server/http-server.system index f8e8f9700..ee7a48033 100644 --- a/crates/examples/microkit/http-server/http-server.system +++ b/crates/examples/microkit/http-server/http-server.system @@ -27,7 +27,6 @@ - @@ -35,7 +34,6 @@ - @@ -45,21 +43,17 @@ - - - - @@ -73,14 +67,11 @@ - - - diff --git a/crates/examples/microkit/http-server/pds/server/src/config.rs b/crates/examples/microkit/http-server/pds/server/src/config.rs new file mode 100644 index 000000000..b4e383181 --- /dev/null +++ b/crates/examples/microkit/http-server/pds/server/src/config.rs @@ -0,0 +1,16 @@ +// +// Copyright 2023, Colias Group, LLC +// +// SPDX-License-Identifier: BSD-2-Clause +// + +pub mod channels { + use sel4_microkit::Channel; + + pub const TIMER_DRIVER: Channel = Channel::new(0); + pub const NET_DRIVER: Channel = Channel::new(1); + pub const BLOCK_DRIVER: Channel = Channel::new(2); +} + +pub const VIRTIO_NET_CLIENT_DMA_SIZE: usize = 0x200_000; +pub const VIRTIO_BLK_CLIENT_DMA_SIZE: usize = 0x200_000; diff --git a/crates/examples/microkit/http-server/pds/server/src/main.rs b/crates/examples/microkit/http-server/pds/server/src/main.rs index ffd52ef28..da150df08 100644 --- a/crates/examples/microkit/http-server/pds/server/src/main.rs +++ b/crates/examples/microkit/http-server/pds/server/src/main.rs @@ -29,7 +29,7 @@ use sel4_async_block_io::{ use sel4_bounce_buffer_allocator::{Basic, BounceBufferAllocator}; use sel4_externally_shared::{ExternallySharedRef, ExternallySharedRefExt}; use sel4_logging::{LevelFilter, Logger, LoggerBuilder}; -use sel4_microkit::{memory_region_symbol, protection_domain, var, Channel, Handler}; +use sel4_microkit::{memory_region_symbol, protection_domain, Handler}; use sel4_shared_ring_buffer::RingBuffers; use sel4_shared_ring_buffer_block_io::SharedRingBufferBlockIO; use sel4_shared_ring_buffer_smoltcp::DeviceImpl; @@ -37,11 +37,13 @@ use sel4_shared_ring_buffer_smoltcp::DeviceImpl; use microkit_http_server_example_server_core::run_server; mod block_client; +mod config; mod handler; mod net_client; mod timer_client; use block_client::BlockClient; +use config::channels; use handler::HandlerImpl; use net_client::NetClient; use timer_client::TimerClient; @@ -66,10 +68,6 @@ static LOGGER: Logger = LoggerBuilder::const_default() .write(|s| sel4::debug_print!("{}", s)) .build(); -const TIMER_DRIVER: Channel = Channel::new(0); -const NET_DRIVER: Channel = Channel::new(1); -const BLOCK_DRIVER: Channel = Channel::new(2); - #[protection_domain( heap_size = 16 * 1024 * 1024, )] @@ -78,17 +76,17 @@ fn init() -> impl Handler { setup_newlib(); - let timer_client = TimerClient::new(TIMER_DRIVER); - let net_client = NetClient::new(NET_DRIVER); - let block_client = BlockClient::new(BLOCK_DRIVER); + let timer_client = TimerClient::new(channels::TIMER_DRIVER); + let net_client = NetClient::new(channels::NET_DRIVER); + let block_client = BlockClient::new(channels::BLOCK_DRIVER); - let notify_net: fn() = || NET_DRIVER.notify(); - let notify_block: fn() = || BLOCK_DRIVER.notify(); + let notify_net: fn() = || channels::NET_DRIVER.notify(); + let notify_block: fn() = || channels::BLOCK_DRIVER.notify(); let net_device = { let dma_region = unsafe { ExternallySharedRef::<'static, _>::new( - memory_region_symbol!(virtio_net_client_dma_vaddr: *mut [u8], n = *var!(virtio_net_client_dma_size: usize = 0)), + memory_region_symbol!(virtio_net_client_dma_vaddr: *mut [u8], n = config::VIRTIO_NET_CLIENT_DMA_SIZE), ) }; @@ -137,7 +135,7 @@ fn init() -> impl Handler { let shared_block_io = { let dma_region = unsafe { ExternallySharedRef::<'static, _>::new( - memory_region_symbol!(virtio_blk_client_dma_vaddr: *mut [u8], n = *var!(virtio_blk_client_dma_size: usize = 0)), + memory_region_symbol!(virtio_blk_client_dma_vaddr: *mut [u8], n = config::VIRTIO_BLK_CLIENT_DMA_SIZE), ) }; @@ -158,9 +156,9 @@ fn init() -> impl Handler { }; HandlerImpl::new( - TIMER_DRIVER, - NET_DRIVER, - BLOCK_DRIVER, + channels::TIMER_DRIVER, + channels::NET_DRIVER, + channels::BLOCK_DRIVER, timer_client, net_device, net_config, diff --git a/crates/examples/microkit/http-server/pds/sp804-driver/src/config.rs b/crates/examples/microkit/http-server/pds/sp804-driver/src/config.rs new file mode 100644 index 000000000..da8579126 --- /dev/null +++ b/crates/examples/microkit/http-server/pds/sp804-driver/src/config.rs @@ -0,0 +1,14 @@ +// +// Copyright 2023, Colias Group, LLC +// +// SPDX-License-Identifier: BSD-2-Clause +// + +pub mod channels { + use sel4_microkit::Channel; + + pub const DEVICE: Channel = Channel::new(0); + pub const CLIENT: Channel = Channel::new(1); +} + +pub const FREQ: u64 = 1_000_000; diff --git a/crates/examples/microkit/http-server/pds/sp804-driver/src/main.rs b/crates/examples/microkit/http-server/pds/sp804-driver/src/main.rs index 7aba7792b..85783bcb3 100644 --- a/crates/examples/microkit/http-server/pds/sp804-driver/src/main.rs +++ b/crates/examples/microkit/http-server/pds/sp804-driver/src/main.rs @@ -10,21 +10,22 @@ use core::time::Duration; -use sel4_microkit::{memory_region_symbol, protection_domain, var, Channel, Handler, MessageInfo}; +use sel4_microkit::{memory_region_symbol, protection_domain, Channel, Handler, MessageInfo}; use sel4_microkit_message::MessageInfoExt as _; use microkit_http_server_example_sp804_driver_core::Driver; use microkit_http_server_example_sp804_driver_interface_types::*; -const DEVICE: Channel = Channel::new(0); -const CLIENT: Channel = Channel::new(1); +mod config; + +use config::channels; #[protection_domain] fn init() -> HandlerImpl { let driver = unsafe { Driver::new( memory_region_symbol!(sp804_mmio_vaddr: *mut ()).as_ptr(), - (*var!(freq: usize = 0)).try_into().unwrap(), + config::FREQ, ) }; HandlerImpl { driver } @@ -39,10 +40,10 @@ impl Handler for HandlerImpl { fn notified(&mut self, channel: Channel) -> Result<(), Self::Error> { match channel { - DEVICE => { + channels::DEVICE => { self.driver.handle_interrupt(); - DEVICE.irq_ack().unwrap(); - CLIENT.notify(); + channels::DEVICE.irq_ack().unwrap(); + channels::CLIENT.notify(); } _ => { unreachable!() @@ -57,7 +58,7 @@ impl Handler for HandlerImpl { msg_info: MessageInfo, ) -> Result { Ok(match channel { - CLIENT => match msg_info.recv_using_postcard::() { + channels::CLIENT => match msg_info.recv_using_postcard::() { Ok(req) => match req { Request::Now => { let now = self.driver.now(); diff --git a/crates/examples/microkit/http-server/pds/virtio-blk-driver/src/config.rs b/crates/examples/microkit/http-server/pds/virtio-blk-driver/src/config.rs new file mode 100644 index 000000000..a4e6a01b4 --- /dev/null +++ b/crates/examples/microkit/http-server/pds/virtio-blk-driver/src/config.rs @@ -0,0 +1,16 @@ +// +// Copyright 2023, Colias Group, LLC +// +// SPDX-License-Identifier: BSD-2-Clause +// + +pub mod channels { + use sel4_microkit::Channel; + + pub const DEVICE: Channel = Channel::new(0); + pub const CLIENT: Channel = Channel::new(1); +} + +pub const VIRTIO_BLK_MMIO_OFFSET: usize = 0xc00; +pub const VIRTIO_BLK_DRIVER_DMA_SIZE: usize = 0x200_000; +pub const VIRTIO_BLK_CLIENT_DMA_SIZE: usize = 0x200_000; diff --git a/crates/examples/microkit/http-server/pds/virtio-blk-driver/src/main.rs b/crates/examples/microkit/http-server/pds/virtio-blk-driver/src/main.rs index 22cfda96e..c57ddf6bc 100644 --- a/crates/examples/microkit/http-server/pds/virtio-blk-driver/src/main.rs +++ b/crates/examples/microkit/http-server/pds/virtio-blk-driver/src/main.rs @@ -34,8 +34,9 @@ use sel4_shared_ring_buffer_block_io_types::{ use microkit_http_server_example_virtio_blk_driver_interface_types::*; use microkit_http_server_example_virtio_hal_impl::HalImpl; -const DEVICE: Channel = Channel::new(0); -const CLIENT: Channel = Channel::new(1); +mod config; + +use config::channels; // HACK hard-coded in virtio-drivers const QUEUE_SIZE: usize = 4; @@ -45,14 +46,14 @@ const QUEUE_SIZE: usize = 4; )] fn init() -> HandlerImpl { HalImpl::init( - *var!(virtio_blk_driver_dma_size: usize = 0), + config::VIRTIO_BLK_DRIVER_DMA_SIZE, *var!(virtio_blk_driver_dma_vaddr: usize = 0), *var!(virtio_blk_driver_dma_paddr: usize = 0), ); let mut dev = { let header = NonNull::new( - (*var!(virtio_blk_mmio_vaddr: usize = 0) + *var!(virtio_blk_mmio_offset: usize = 0)) + (*var!(virtio_blk_mmio_vaddr: usize = 0) + config::VIRTIO_BLK_MMIO_OFFSET) as *mut VirtIOHeader, ) .unwrap(); @@ -63,11 +64,11 @@ fn init() -> HandlerImpl { let client_region = unsafe { ExternallySharedRef::<'static, _>::new( - memory_region_symbol!(virtio_blk_client_dma_vaddr: *mut [u8], n = *var!(virtio_blk_client_dma_size: usize = 0)), + memory_region_symbol!(virtio_blk_client_dma_vaddr: *mut [u8], n = config::VIRTIO_BLK_CLIENT_DMA_SIZE), ) }; - let notify_client: fn() = || CLIENT.notify(); + let notify_client: fn() = || channels::CLIENT.notify(); let ring_buffers = RingBuffers::<'_, Use, fn(), BlockIORequest>::from_ptrs_using_default_initialization_strategy_for_role( @@ -77,7 +78,7 @@ fn init() -> HandlerImpl { ); dev.ack_interrupt(); - DEVICE.irq_ack().unwrap(); + channels::DEVICE.irq_ack().unwrap(); HandlerImpl { dev, @@ -105,7 +106,7 @@ impl Handler for HandlerImpl { fn notified(&mut self, channel: Channel) -> Result<(), Self::Error> { match channel { - DEVICE | CLIENT => { + channels::DEVICE | channels::CLIENT => { let mut notify = false; while self.dev.peek_used().is_some() { @@ -191,7 +192,7 @@ impl Handler for HandlerImpl { } self.dev.ack_interrupt(); - DEVICE.irq_ack().unwrap(); + channels::DEVICE.irq_ack().unwrap(); } _ => { unreachable!() @@ -206,7 +207,7 @@ impl Handler for HandlerImpl { msg_info: MessageInfo, ) -> Result { Ok(match channel { - CLIENT => match msg_info.recv_using_postcard::() { + channels::CLIENT => match msg_info.recv_using_postcard::() { Ok(req) => match req { Request::GetNumBlocks => { let num_blocks = self.dev.capacity(); diff --git a/crates/examples/microkit/http-server/pds/virtio-net-driver/src/config.rs b/crates/examples/microkit/http-server/pds/virtio-net-driver/src/config.rs new file mode 100644 index 000000000..b39a74057 --- /dev/null +++ b/crates/examples/microkit/http-server/pds/virtio-net-driver/src/config.rs @@ -0,0 +1,16 @@ +// +// Copyright 2023, Colias Group, LLC +// +// SPDX-License-Identifier: BSD-2-Clause +// + +pub mod channels { + use sel4_microkit::Channel; + + pub const DEVICE: Channel = Channel::new(0); + pub const CLIENT: Channel = Channel::new(1); +} + +pub const VIRTIO_NET_MMIO_OFFSET: usize = 0xe00; +pub const VIRTIO_NET_DRIVER_DMA_SIZE: usize = 0x200_000; +pub const VIRTIO_NET_CLIENT_DMA_SIZE: usize = 0x200_000; diff --git a/crates/examples/microkit/http-server/pds/virtio-net-driver/src/main.rs b/crates/examples/microkit/http-server/pds/virtio-net-driver/src/main.rs index 483c63649..82c0cf004 100644 --- a/crates/examples/microkit/http-server/pds/virtio-net-driver/src/main.rs +++ b/crates/examples/microkit/http-server/pds/virtio-net-driver/src/main.rs @@ -26,8 +26,9 @@ use sel4_shared_ring_buffer::{roles::Use, RingBuffers}; use microkit_http_server_example_virtio_hal_impl::HalImpl; use microkit_http_server_example_virtio_net_driver_interface_types::*; -const DEVICE: Channel = Channel::new(0); -const CLIENT: Channel = Channel::new(1); +mod config; + +use config::channels; const NET_QUEUE_SIZE: usize = 16; const NET_BUFFER_LEN: usize = 2048; @@ -37,14 +38,14 @@ const NET_BUFFER_LEN: usize = 2048; )] fn init() -> HandlerImpl { HalImpl::init( - *var!(virtio_net_driver_dma_size: usize = 0), + config::VIRTIO_NET_DRIVER_DMA_SIZE, *var!(virtio_net_driver_dma_vaddr: usize = 0), *var!(virtio_net_driver_dma_paddr: usize = 0), ); let mut dev = { let header = NonNull::new( - (*var!(virtio_net_mmio_vaddr: usize = 0) + *var!(virtio_net_mmio_offset: usize = 0)) + (*var!(virtio_net_mmio_vaddr: usize = 0) + config::VIRTIO_NET_MMIO_OFFSET) as *mut VirtIOHeader, ) .unwrap(); @@ -55,11 +56,11 @@ fn init() -> HandlerImpl { let client_region = unsafe { ExternallySharedRef::<'static, _>::new( - memory_region_symbol!(virtio_net_client_dma_vaddr: *mut [u8], n = *var!(virtio_net_client_dma_size: usize = 0)), + memory_region_symbol!(virtio_net_client_dma_vaddr: *mut [u8], n = config::VIRTIO_NET_CLIENT_DMA_SIZE), ) }; - let notify_client: fn() = || CLIENT.notify(); + let notify_client: fn() = || channels::CLIENT.notify(); let rx_ring_buffers = RingBuffers::<'_, Use, fn()>::from_ptrs_using_default_initialization_strategy_for_role( @@ -76,7 +77,7 @@ fn init() -> HandlerImpl { ); dev.ack_interrupt(); - DEVICE.irq_ack().unwrap(); + channels::DEVICE.irq_ack().unwrap(); HandlerImpl { dev, @@ -98,7 +99,7 @@ impl Handler for HandlerImpl { fn notified(&mut self, channel: Channel) -> Result<(), Self::Error> { match channel { - DEVICE | CLIENT => { + channels::DEVICE | channels::CLIENT => { let mut notify_rx = false; while self.dev.can_recv() && !self.rx_ring_buffers.free_mut().is_empty().unwrap() { @@ -154,7 +155,7 @@ impl Handler for HandlerImpl { } self.dev.ack_interrupt(); - DEVICE.irq_ack().unwrap(); + channels::DEVICE.irq_ack().unwrap(); } _ => { unreachable!() @@ -169,7 +170,7 @@ impl Handler for HandlerImpl { msg_info: MessageInfo, ) -> Result { Ok(match channel { - CLIENT => match msg_info.recv_using_postcard::() { + channels::CLIENT => match msg_info.recv_using_postcard::() { Ok(req) => match req { Request::GetMacAddress => { let mac_address = self.dev.mac_address(); diff --git a/hacking/nix/scope/sources.nix b/hacking/nix/scope/sources.nix index 4bbf381ff..b839b69d0 100644 --- a/hacking/nix/scope/sources.nix +++ b/hacking/nix/scope/sources.nix @@ -65,7 +65,7 @@ in rec { microkit = fetchGit { url = "https://github.com/coliasgroup/microkit.git"; - rev = "3dbabd1205cbee933b1ef42534d7a446f78821d0"; # branch "rust-nix" + rev = "1e561e5b11970a3b61167225ebcaf11aa7ad4959"; # branch "rust-nix" local = localRoot + "/microkit"; # useLocal = true; };