fix bugs in implementation

This commit is contained in:
bunnie 2025-12-31 23:34:35 +08:00
parent 06501a9032
commit 24b6d4cb42
2 changed files with 42 additions and 22 deletions

View file

@ -66,7 +66,7 @@ impl<'a> BioApi<'a> for Bio {
ArchivedBioError::Uninit => panic!("Error in message passing"), ArchivedBioError::Uninit => panic!("Error in message passing"),
ArchivedBioError::InvalidCore => Err(BioError::InvalidCore), ArchivedBioError::InvalidCore => Err(BioError::InvalidCore),
ArchivedBioError::NoFreeMachines => Err(BioError::NoFreeMachines), ArchivedBioError::NoFreeMachines => Err(BioError::NoFreeMachines),
ArchivedBioError::CoreInUse => Err(BioError::CoreInUse), ArchivedBioError::ResourceInUse => Err(BioError::ResourceInUse),
ArchivedBioError::Oom => Err(BioError::Oom), ArchivedBioError::Oom => Err(BioError::Oom),
_ => Err(BioError::InternalError), _ => Err(BioError::InternalError),
} }
@ -81,39 +81,40 @@ impl<'a> BioApi<'a> for Bio {
Ok(()) Ok(())
} }
unsafe fn get_core_handle(&'a mut self) -> Result<Option<CoreHandle<'a>>, BioError> { unsafe fn get_core_handle(&'a self, fifo: Fifo) -> Result<Option<CoreHandle<'a>>, BioError> {
match send_message( match send_message(
self.conn, self.conn,
Message::new_blocking_scalar(BioOp::GetCoreHandle.to_usize().unwrap(), 0, 0, 0, 0), Message::new_blocking_scalar(BioOp::GetCoreHandle.to_usize().unwrap(), fifo as usize, 0, 0, 0),
) )
.map_err(|e| <xous::Error as Into<BioError>>::into(e))? .map_err(|e| <xous::Error as Into<BioError>>::into(e))?
{ {
xous::Result::Scalar5(_, bank, valid, _, _) => { xous::Result::Scalar5(_, valid, _, _, _) => {
if valid == 0 { if valid == 0 {
// no handles available // no handles available
return Ok(None); return Ok(None);
} }
let base = match bank { let base = match fifo {
0 => utralib::HW_BIO_FIFO0_BASE, Fifo::Fifo0 => utralib::HW_BIO_FIFO0_BASE,
1 => utralib::HW_BIO_FIFO1_BASE, Fifo::Fifo1 => utralib::HW_BIO_FIFO1_BASE,
2 => utralib::HW_BIO_FIFO2_BASE, Fifo::Fifo2 => utralib::HW_BIO_FIFO2_BASE,
3 => utralib::HW_BIO_FIFO3_BASE, Fifo::Fifo3 => utralib::HW_BIO_FIFO3_BASE,
_ => panic!("Incorrect bank value"),
}; };
// the actual mapping is requested in the process space of the caller: this allows // the actual mapping is requested in the process space of the caller: this allows
// us to directly interact with the BIO without having to use a syscall. // us to directly interact with the BIO without having to use a syscall.
let virtual_page = xous::map_memory( if let Ok(virtual_page) = xous::map_memory(
MemoryAddress::new(base), MemoryAddress::new(base),
None, None,
utralib::HW_BIO_FIFO1_MEM_LEN, utralib::HW_BIO_FIFO0_MEM_LEN,
xous::MemoryFlags::R | xous::MemoryFlags::W, xous::MemoryFlags::R | xous::MemoryFlags::W,
) ) {
.expect("couldn't map BIO memory handle"); Ok(Some(CoreHandle::new(
Ok(Some(CoreHandle::new( self.conn,
self.conn, virtual_page.as_ptr() as usize,
virtual_page.as_ptr() as usize, arbitrary_int::u2::from_u32(fifo as u32),
arbitrary_int::u2::from_u32(bank as u32), )))
))) } else {
Err(BioError::Oom)
}
} }
_ => unimplemented!("Unhandled return type on get_core_handle()"), _ => unimplemented!("Unhandled return type on get_core_handle()"),
} }

View file

@ -403,8 +403,8 @@ impl<'a> BioApi<'a> for BioSharedState {
offset: usize, offset: usize,
config: CoreConfig, config: CoreConfig,
) -> Result<Option<u32>, BioError> { ) -> Result<Option<u32>, BioError> {
if self.core_config[core as usize].is_none() { if self.core_config[core as usize].is_some() {
return Err(BioError::CoreInUse); return Err(BioError::ResourceInUse);
} }
self.core_config[core as usize] = Some(config); self.core_config[core as usize] = Some(config);
self.load_code(code, offset, core); self.load_code(code, offset, core);
@ -453,7 +453,7 @@ impl<'a> BioApi<'a> for BioSharedState {
prev_freq prev_freq
} }
unsafe fn get_core_handle(&'a mut self) -> Result<Option<CoreHandle<'a>>, BioError> { unsafe fn get_core_handle(&'a self, _fifo: Fifo) -> Result<Option<CoreHandle<'a>>, BioError> {
unimplemented!("This is managed by the main loop server, not the hardware interface"); unimplemented!("This is managed by the main loop server, not the hardware interface");
} }
@ -467,11 +467,30 @@ impl<'a> BioApi<'a> for BioSharedState {
CoreRunSetting::Unchanged => (), CoreRunSetting::Unchanged => (),
} }
} }
let core_code = start_mask;
start_mask = start_mask | start_mask << 4 | start_mask << 8; start_mask = start_mask | start_mask << 4 | start_mask << 8;
stop_mask = stop_mask | stop_mask << 4 | stop_mask << 8; stop_mask = stop_mask | stop_mask << 4 | stop_mask << 8;
let ctrl = self.bio.r(bio_bdma::SFR_CTRL); let ctrl = self.bio.r(bio_bdma::SFR_CTRL);
self.bio.wo(bio_bdma::SFR_CTRL, (ctrl & !stop_mask) | start_mask); self.bio.wo(bio_bdma::SFR_CTRL, (ctrl & !stop_mask) | start_mask);
let mut timeout = 0;
loop {
let ctrl = self.bio.r(utra::bio_bdma::SFR_CTRL) & 0xFF0;
if ctrl == 0 {
break;
}
timeout += 1;
if timeout > 100000 {
crate::println!("Timeout on set_core_run_states: req {:x} != rbk {:x}", core_code, ctrl);
break;
}
}
let check = self.bio.r(utra::bio_bdma::SFR_CTRL);
if check != core_code {
crate::println!("run-state check failed: {:x}", check);
}
Ok(()) Ok(())
} }