From 502204cab22b9331af0b18e6c7fd2eb95e3aef45 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Wed, 31 Jan 2024 16:49:43 +0800 Subject: [PATCH] subkernel: fix DMA return control to wrong master --- artiq/firmware/satman/dma.rs | 13 ++++++------- artiq/firmware/satman/main.rs | 11 +++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/artiq/firmware/satman/dma.rs b/artiq/firmware/satman/dma.rs index 4fc7a1393..97aea721d 100644 --- a/artiq/firmware/satman/dma.rs +++ b/artiq/firmware/satman/dma.rs @@ -5,11 +5,11 @@ use board_misoc::{csr, cache::flush_l2_cache}; use proto_artiq::drtioaux_proto::PayloadStatus; use routing::{Router, Sliceable}; use kernel::Manager as KernelManager; -use ::{cricon_select, RtioMaster, MASTER_PAYLOAD_MAX_SIZE}; +use ::{cricon_select, cricon_read, RtioMaster, MASTER_PAYLOAD_MAX_SIZE}; const ALIGNMENT: usize = 64; -#[derive(Debug, PartialEq)] +#[derive(PartialEq)] enum ManagerState { Idle, Playback @@ -32,7 +32,6 @@ pub enum Error { UploadFail, } -#[derive(Debug)] struct Entry { trace: Vec, padding_len: usize, @@ -75,7 +74,6 @@ impl Entry { } } -#[derive(Debug)] enum RemoteTraceState { Unsent, Sending(usize), @@ -83,7 +81,6 @@ enum RemoteTraceState { Running(usize), } -#[derive(Debug)] struct RemoteTraces { remote_traces: BTreeMap, state: RemoteTraceState, @@ -177,12 +174,12 @@ impl RemoteTraces { } } -#[derive(Debug)] pub struct Manager { entries: BTreeMap<(u8, u32), Entry>, state: ManagerState, current_id: u32, current_source: u8, + previous_cri_master: RtioMaster, remote_entries: BTreeMap, name_map: BTreeMap, @@ -201,6 +198,7 @@ impl Manager { entries: BTreeMap::new(), current_id: 0, current_source: 0, + previous_cri_master: RtioMaster::Drtio, state: ManagerState::Idle, remote_entries: BTreeMap::new(), name_map: BTreeMap::new(), @@ -401,6 +399,7 @@ impl Manager { self.state = ManagerState::Playback; self.current_id = id; self.current_source = source; + self.previous_cri_master = cricon_read(); unsafe { csr::rtio_dma::base_address_write(ptr as u64); @@ -424,7 +423,7 @@ impl Manager { } else { self.state = ManagerState::Idle; unsafe { - cricon_select(RtioMaster::Drtio); + cricon_select(self.previous_cri_master); let error = csr::rtio_dma::error_read(); let channel = csr::rtio_dma::error_channel_read(); let timestamp = csr::rtio_dma::error_timestamp_read(); diff --git a/artiq/firmware/satman/main.rs b/artiq/firmware/satman/main.rs index 2105b4c26..1b9a4c53f 100644 --- a/artiq/firmware/satman/main.rs +++ b/artiq/firmware/satman/main.rs @@ -72,6 +72,7 @@ fn drtiosat_async_ready() { } } +#[derive(Clone, Copy)] pub enum RtioMaster { Drtio, Dma, @@ -89,6 +90,16 @@ pub fn cricon_select(master: RtioMaster) { } } +pub fn cricon_read() -> RtioMaster { + let val = unsafe { csr::cri_con::selected_read() }; + match val { + 0 => RtioMaster::Drtio, + 1 => RtioMaster::Dma, + 2 => RtioMaster::Kernel, + _ => unreachable!() + } +} + #[cfg(has_drtio_routing)] macro_rules! forward { ($routing_table:expr, $destination:expr, $rank:expr, $repeaters:expr, $packet:expr) => {{