From 4da9dce093357ef108e14353f886fd5d5c28165d Mon Sep 17 00:00:00 2001 From: Marco Visaya Date: Fri, 3 Jan 2025 14:59:33 -0800 Subject: [PATCH] Address feedback - make driver_num a constant - remove parameters for R/W config and just use the default config --- runtime/apps/apis/dma/src/lib.rs | 22 ++++++++++-------- runtime/apps/apis/mailbox/src/lib.rs | 34 ++++++++++++++-------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/runtime/apps/apis/dma/src/lib.rs b/runtime/apps/apis/dma/src/lib.rs index 5850f58..edab413 100644 --- a/runtime/apps/apis/dma/src/lib.rs +++ b/runtime/apps/apis/dma/src/lib.rs @@ -9,8 +9,9 @@ use libtock_platform::{ErrorCode, Syscalls}; use libtockasync::TockSubscribe; /// DMA interface. -pub struct AsyncDMA(S); +pub struct AsyncDMA(S); +const DMA_DRIVER_NUM: u32 = 0x8000_0008; /// Configuration parameters for a DMA transfer. #[derive(Debug, Copy, Clone)] pub struct DMATransaction { @@ -22,7 +23,7 @@ pub struct DMATransaction { pub dest_addr: u64, } -impl AsyncDMA { +impl AsyncDMA { /// Do a DMA transfer. /// /// This method executes a DMA transfer based on the provided `DMATransaction` configuration. @@ -36,16 +37,16 @@ impl AsyncDMA { pub async fn xfer(transaction: DMATransaction) -> Result<(), ErrorCode> { Self::setup(transaction).await?; - let async_start = TockSubscribe::subscribe::(DRIVER_NUM, dma_subscribe::XFER_DONE); - S::command(DRIVER_NUM, dma_cmd::START, 0, 0).to_result::<(), ErrorCode>()?; + let async_start = TockSubscribe::subscribe::(DMA_DRIVER_NUM, dma_subscribe::XFER_DONE); + S::command(DMA_DRIVER_NUM, dma_cmd::START, 0, 0).to_result::<(), ErrorCode>()?; async_start.await.map(|_| ()) } async fn setup(config: DMATransaction) -> Result<(), ErrorCode> { let async_configure = - TockSubscribe::subscribe::(DRIVER_NUM, dma_subscribe::SET_BYTE_XFER_COUNT_DONE); + TockSubscribe::subscribe::(DMA_DRIVER_NUM, dma_subscribe::SET_BYTE_XFER_COUNT_DONE); S::command( - DRIVER_NUM, + DMA_DRIVER_NUM, dma_cmd::SET_BYTE_XFER_COUNT, config.byte_count as u32, 0, @@ -53,9 +54,9 @@ impl AsyncDMA { .to_result::<(), ErrorCode>()?; async_configure.await.map(|_| ())?; - let async_src = TockSubscribe::subscribe::(DRIVER_NUM, dma_subscribe::SET_SRC_DONE); + let async_src = TockSubscribe::subscribe::(DMA_DRIVER_NUM, dma_subscribe::SET_SRC_DONE); S::command( - DRIVER_NUM, + DMA_DRIVER_NUM, dma_cmd::SET_SRC_ADDR, (config.src_addr & 0xFFFF_FFFF) as u32, (config.src_addr >> 32) as u32, @@ -63,9 +64,10 @@ impl AsyncDMA { .to_result::<(), ErrorCode>()?; async_src.await.map(|_| ())?; - let async_dest = TockSubscribe::subscribe::(DRIVER_NUM, dma_subscribe::SET_DEST_DONE); + let async_dest = + TockSubscribe::subscribe::(DMA_DRIVER_NUM, dma_subscribe::SET_DEST_DONE); S::command( - DRIVER_NUM, + DMA_DRIVER_NUM, dma_cmd::SET_DEST_ADDR, (config.dest_addr & 0xFFFF_FFFF) as u32, (config.dest_addr >> 32) as u32, diff --git a/runtime/apps/apis/mailbox/src/lib.rs b/runtime/apps/apis/mailbox/src/lib.rs index 6d2344c..1919878 100644 --- a/runtime/apps/apis/mailbox/src/lib.rs +++ b/runtime/apps/apis/mailbox/src/lib.rs @@ -2,8 +2,8 @@ //! # AsyncMailbox: Mailbox Interface -use libtock_platform::allow_ro::{AllowRo, Config as ReadOnlyConfig}; -use libtock_platform::allow_rw::{AllowRw, Config as ReadWriteConfig}; +use libtock_platform::allow_ro::AllowRo; +use libtock_platform::allow_rw::AllowRw; use libtock_platform::{share, DefaultConfig, ErrorCode, Syscalls}; use libtockasync::TockSubscribe; /// Mailbox interface user interface. @@ -13,16 +13,11 @@ use libtockasync::TockSubscribe; /// - `S`: The syscall implementation. /// - `W`: Configuration for writable buffers (response). /// - `R`: Configuration for read-only buffers (input), defaults to `DefaultConfig`. -pub struct AsyncMailbox< - const DRIVER_NUM: u32, - S: Syscalls, - W: ReadWriteConfig, - R: ReadOnlyConfig = DefaultConfig, ->(S, W, R); +pub struct AsyncMailbox(S); -impl - AsyncMailbox -{ +const MAILBOX_DRIVER_NUM: u32 = 0x8000_0009; + +impl AsyncMailbox { /// Executes a mailbox command and returns the response. /// /// This method sends a mailbox command to the kernel, then waits @@ -44,8 +39,8 @@ impl ) -> Result { share::scope::< ( - AllowRo<_, DRIVER_NUM, { mailbox_buffer::INPUT }>, - AllowRw<_, DRIVER_NUM, { mailbox_buffer::RESPONSE }>, + AllowRo<_, MAILBOX_DRIVER_NUM, { mailbox_buffer::INPUT }>, + AllowRw<_, MAILBOX_DRIVER_NUM, { mailbox_buffer::RESPONSE }>, ), _, _, @@ -53,17 +48,22 @@ impl let (allow_ro, allow_rw) = handle.split(); // Share the input buffer (read-only) - S::allow_ro::(allow_ro, input_data)?; + S::allow_ro::( + allow_ro, input_data, + )?; // Share the response buffer (read-write) - S::allow_rw::(allow_rw, response_buffer)?; + S::allow_rw::( + allow_rw, + response_buffer, + )?; // Subscribe to the asynchronous notification for when the command is processed let async_command = - TockSubscribe::subscribe::(DRIVER_NUM, mailbox_subscribe::COMMAND_DONE); + TockSubscribe::subscribe::(MAILBOX_DRIVER_NUM, mailbox_subscribe::COMMAND_DONE); // Issue the command to the kernel - S::command(DRIVER_NUM, mailbox_cmd::EXECUTE_COMMAND, command, 0) + S::command(MAILBOX_DRIVER_NUM, mailbox_cmd::EXECUTE_COMMAND, command, 0) .to_result::<(), ErrorCode>()?; // Return the subscription for further processing