forked from M-Labs/artiq
1
0
Fork 0

subkernel: fix DMA return control to wrong master

This commit is contained in:
mwojcik 2024-01-31 16:49:43 +08:00 committed by Sébastien Bourdeauducq
parent d1ee0ffb83
commit 502204cab2
2 changed files with 17 additions and 7 deletions

View File

@ -5,11 +5,11 @@ use board_misoc::{csr, cache::flush_l2_cache};
use proto_artiq::drtioaux_proto::PayloadStatus; use proto_artiq::drtioaux_proto::PayloadStatus;
use routing::{Router, Sliceable}; use routing::{Router, Sliceable};
use kernel::Manager as KernelManager; 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; const ALIGNMENT: usize = 64;
#[derive(Debug, PartialEq)] #[derive(PartialEq)]
enum ManagerState { enum ManagerState {
Idle, Idle,
Playback Playback
@ -32,7 +32,6 @@ pub enum Error {
UploadFail, UploadFail,
} }
#[derive(Debug)]
struct Entry { struct Entry {
trace: Vec<u8>, trace: Vec<u8>,
padding_len: usize, padding_len: usize,
@ -75,7 +74,6 @@ impl Entry {
} }
} }
#[derive(Debug)]
enum RemoteTraceState { enum RemoteTraceState {
Unsent, Unsent,
Sending(usize), Sending(usize),
@ -83,7 +81,6 @@ enum RemoteTraceState {
Running(usize), Running(usize),
} }
#[derive(Debug)]
struct RemoteTraces { struct RemoteTraces {
remote_traces: BTreeMap<u8, Sliceable>, remote_traces: BTreeMap<u8, Sliceable>,
state: RemoteTraceState, state: RemoteTraceState,
@ -177,12 +174,12 @@ impl RemoteTraces {
} }
} }
#[derive(Debug)]
pub struct Manager { pub struct Manager {
entries: BTreeMap<(u8, u32), Entry>, entries: BTreeMap<(u8, u32), Entry>,
state: ManagerState, state: ManagerState,
current_id: u32, current_id: u32,
current_source: u8, current_source: u8,
previous_cri_master: RtioMaster,
remote_entries: BTreeMap<u32, RemoteTraces>, remote_entries: BTreeMap<u32, RemoteTraces>,
name_map: BTreeMap<String, u32>, name_map: BTreeMap<String, u32>,
@ -201,6 +198,7 @@ impl Manager {
entries: BTreeMap::new(), entries: BTreeMap::new(),
current_id: 0, current_id: 0,
current_source: 0, current_source: 0,
previous_cri_master: RtioMaster::Drtio,
state: ManagerState::Idle, state: ManagerState::Idle,
remote_entries: BTreeMap::new(), remote_entries: BTreeMap::new(),
name_map: BTreeMap::new(), name_map: BTreeMap::new(),
@ -401,6 +399,7 @@ impl Manager {
self.state = ManagerState::Playback; self.state = ManagerState::Playback;
self.current_id = id; self.current_id = id;
self.current_source = source; self.current_source = source;
self.previous_cri_master = cricon_read();
unsafe { unsafe {
csr::rtio_dma::base_address_write(ptr as u64); csr::rtio_dma::base_address_write(ptr as u64);
@ -424,7 +423,7 @@ impl Manager {
} else { } else {
self.state = ManagerState::Idle; self.state = ManagerState::Idle;
unsafe { unsafe {
cricon_select(RtioMaster::Drtio); cricon_select(self.previous_cri_master);
let error = csr::rtio_dma::error_read(); let error = csr::rtio_dma::error_read();
let channel = csr::rtio_dma::error_channel_read(); let channel = csr::rtio_dma::error_channel_read();
let timestamp = csr::rtio_dma::error_timestamp_read(); let timestamp = csr::rtio_dma::error_timestamp_read();

View File

@ -72,6 +72,7 @@ fn drtiosat_async_ready() {
} }
} }
#[derive(Clone, Copy)]
pub enum RtioMaster { pub enum RtioMaster {
Drtio, Drtio,
Dma, 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)] #[cfg(has_drtio_routing)]
macro_rules! forward { macro_rules! forward {
($routing_table:expr, $destination:expr, $rank:expr, $repeaters:expr, $packet:expr) => {{ ($routing_table:expr, $destination:expr, $rank:expr, $repeaters:expr, $packet:expr) => {{