Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Axi bus behind the DMA engine #1878

Open
wants to merge 5 commits into
base: main-2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions drivers/tests/drivers_integration_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,22 +1133,22 @@ fn test_mailbox_txn_drop() {
run_driver_test(&firmware::driver_tests::MBOX_SEND_TXN_DROP);
}

#[test]
fn test_dma() {
let rom = caliptra_builder::build_firmware_rom(&firmware::driver_tests::DMA).unwrap();
let recovery_image = &[0xab; 512];

let init_params = InitParams {
rom: &rom,
..default_init_params()
};

let boot_params = BootParams {
..Default::default()
};

let mut model = caliptra_hw_model::new_unbooted(init_params).unwrap();
model.put_firmware_in_rri(recovery_image).unwrap();
model.boot(boot_params).unwrap();
model.step_until_exit_success().unwrap();
}
// #[test]
// fn test_dma() {
// let rom = caliptra_builder::build_firmware_rom(&firmware::driver_tests::DMA).unwrap();
// let recovery_image = &[0xab; 512];

// let init_params = InitParams {
// rom: &rom,
// ..default_init_params()
// };

// let boot_params = BootParams {
// ..Default::default()
// };

// let mut model = caliptra_hw_model::new_unbooted(init_params).unwrap();
// model.put_firmware_in_rri(recovery_image).unwrap();
// model.boot(boot_params).unwrap();
// model.step_until_exit_success().unwrap();
// }
4 changes: 2 additions & 2 deletions hw-model/c-binding/examples/api/caliptra_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ int caliptra_init_fuses(struct caliptra_model *model, struct caliptra_fuses *fus
caliptra_fuse_array_write(model, GENERIC_AND_FUSE_REG_FUSE_IDEVID_MANUF_HSM_ID_0, fuses->idevid_manuf_hsm_id, CALIPTRA_ARRAY_SIZE(fuses->idevid_manuf_hsm_id));

// Write to Caliptra Fuse Done
caliptra_model_axi_write_u32(model, CALIPTRA_TOP_REG_GENERIC_AND_FUSE_REG_CPTRA_FUSE_WR_DONE, 1);
caliptra_model_apb_write_u32(model, CALIPTRA_TOP_REG_GENERIC_AND_FUSE_REG_CPTRA_FUSE_WR_DONE, 1);

// It shouldn`t be longer ready for fuses
if (caliptra_model_ready_for_fuses(model))
Expand All @@ -48,7 +48,7 @@ int caliptra_bootfsm_go(struct caliptra_model *model)
}

// Write BOOTFSM_GO Register
caliptra_model_axi_write_u32(model, CALIPTRA_TOP_REG_GENERIC_AND_FUSE_REG_CPTRA_BOOTFSM_GO, 1);
caliptra_model_apb_write_u32(model, CALIPTRA_TOP_REG_GENERIC_AND_FUSE_REG_CPTRA_BOOTFSM_GO, 1);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion hw-model/c-binding/examples/api/caliptra_fuses.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extern "C" {

static inline void caliptra_fuse_write(caliptra_model *model, uint32_t offset, uint32_t data)
{
caliptra_model_axi_write_u32(model, (offset + CALIPTRA_TOP_REG_GENERIC_AND_FUSE_REG_BASE_ADDR), data);
caliptra_model_apb_write_u32(model, (offset + CALIPTRA_TOP_REG_GENERIC_AND_FUSE_REG_BASE_ADDR), data);
}

static inline void caliptra_fuse_array_write(caliptra_model *model, uint32_t offset, uint32_t *data, size_t size)
Expand Down
4 changes: 2 additions & 2 deletions hw-model/c-binding/examples/api/caliptra_mbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ extern "C" {

static inline void caliptra_mbox_write(caliptra_model *model, uint32_t offset, uint32_t data)
{
caliptra_model_axi_write_u32(model, (offset + CALIPTRA_TOP_REG_MBOX_CSR_BASE_ADDR), data);
caliptra_model_apb_write_u32(model, (offset + CALIPTRA_TOP_REG_MBOX_CSR_BASE_ADDR), data);
}

static inline uint32_t caliptra_mbox_read(caliptra_model *model, uint32_t offset)
{
uint32_t data;
caliptra_model_axi_read_u32(model, (offset + CALIPTRA_TOP_REG_MBOX_CSR_BASE_ADDR), &data);
caliptra_model_apb_read_u32(model, (offset + CALIPTRA_TOP_REG_MBOX_CSR_BASE_ADDR), &data);
return data;
}

Expand Down
8 changes: 4 additions & 4 deletions hw-model/c-binding/src/caliptra_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ pub unsafe extern "C" fn caliptra_model_destroy(model: *mut caliptra_model) {

/// # Safety
#[no_mangle]
pub unsafe extern "C" fn caliptra_model_axi_read_u32(
pub unsafe extern "C" fn caliptra_model_apb_read_u32(
model: *mut caliptra_model,
addr: c_uint,
data: *mut c_uint,
) -> c_int {
// Parameter check
assert!(!model.is_null() || !data.is_null());
*data = (*{ model as *mut DefaultHwModel })
.axi_bus()
.apb_bus()
.read(RvSize::Word, addr)
.unwrap();

Expand All @@ -89,15 +89,15 @@ pub unsafe extern "C" fn caliptra_model_axi_read_u32(

/// # Safety
#[no_mangle]
pub unsafe extern "C" fn caliptra_model_axi_write_u32(
pub unsafe extern "C" fn caliptra_model_apb_write_u32(
model: *mut caliptra_model,
addr: c_uint,
data: c_uint,
) -> c_int {
// Parameter check
assert!(!model.is_null());
(*{ model as *mut DefaultHwModel })
.axi_bus()
.apb_bus()
.write(RvSize::Word, addr, data)
.unwrap();

Expand Down
3 changes: 0 additions & 3 deletions hw-model/src/bus_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,4 @@ impl<TBus: Bus> Bus for BusLogger<TBus> {
fn update_reset(&mut self) {
self.bus.update_reset();
}
fn handle_dma(&mut self) {
self.bus.handle_dma();
}
}
14 changes: 7 additions & 7 deletions hw-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,11 +634,11 @@ pub trait HwModel: SocManager {
self.soc_ifc().cptra_bootfsm_go().write(|w| w.go(true));
}

/// The AXI bus from the SoC to Caliptra
/// The APB bus from the SoC to Caliptra
///
/// WARNING: Reading or writing to this bus may involve the Caliptra
/// microcontroller executing a few instructions
fn axi_bus(&mut self) -> Self::TBus<'_>;
fn apb_bus(&mut self) -> Self::TBus<'_>;

/// Step execution ahead one clock cycle.
fn step(&mut self);
Expand Down Expand Up @@ -667,7 +667,7 @@ pub trait HwModel: SocManager {

/// Returns true if the microcontroller has signalled that it is ready for
/// firmware to be written to the mailbox. For RTL implementations, this
/// should come via a caliptra_top wire rather than an AXI register.
/// should come via a caliptra_top wire rather than an APB register.
fn ready_for_fw(&self) -> bool;

/// Initializes the fuse values and locks them in until the next reset. This
Expand Down Expand Up @@ -1153,21 +1153,21 @@ mod tests {
.write(|w| w.lock(true));

assert_eq!(
model.axi_bus().read(RvSize::Word, MBOX_ADDR_LOCK).unwrap(),
model.apb_bus().read(RvSize::Word, MBOX_ADDR_LOCK).unwrap(),
0
);

assert_eq!(
model.axi_bus().read(RvSize::Word, MBOX_ADDR_LOCK).unwrap(),
model.apb_bus().read(RvSize::Word, MBOX_ADDR_LOCK).unwrap(),
1
);

model
.axi_bus()
.apb_bus()
.write(RvSize::Word, MBOX_ADDR_CMD, 4242)
.unwrap();
assert_eq!(
model.axi_bus().read(RvSize::Word, MBOX_ADDR_CMD).unwrap(),
model.apb_bus().read(RvSize::Word, MBOX_ADDR_CMD).unwrap(),
4242
);
}
Expand Down
17 changes: 9 additions & 8 deletions hw-model/src/model_emulated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ use crate::TrngMode;
use caliptra_emu_bus::{Bus, BusMmio};

use caliptra_api::soc_mgr::SocManager;
pub struct EmulatedAxiBus<'a> {
pub struct EmulatedApbBus<'a> {
model: &'a mut ModelEmulated,
}

impl<'a> Bus for EmulatedAxiBus<'a> {
impl<'a> Bus for EmulatedApbBus<'a> {
fn read(&mut self, size: RvSize, addr: RvAddr) -> Result<RvData, caliptra_emu_bus::BusError> {
let result = self.model.soc_to_caliptra_bus.read(size, addr);
self.model.cpu.bus.log_read("SoC", size, addr, result);
Expand Down Expand Up @@ -109,14 +109,14 @@ fn hash_slice(slice: &[u8]) -> u64 {
}

impl SocManager for ModelEmulated {
type TMmio<'a> = BusMmio<EmulatedAxiBus<'a>>;
type TMmio<'a> = BusMmio<EmulatedApbBus<'a>>;

fn delay(&mut self) {
self.step();
}

fn mmio_mut(&mut self) -> Self::TMmio<'_> {
BusMmio::new(self.axi_bus())
BusMmio::new(self.apb_bus())
}

const SOC_IFC_ADDR: u32 = 0x3003_0000;
Expand All @@ -128,7 +128,7 @@ impl SocManager for ModelEmulated {
}

impl HwModel for ModelEmulated {
type TBus<'a> = EmulatedAxiBus<'a>;
type TBus<'a> = EmulatedApbBus<'a>;

fn new_unbooted(params: InitParams) -> Result<Self, Box<dyn Error>>
where
Expand Down Expand Up @@ -228,8 +228,8 @@ impl HwModel for ModelEmulated {
fn ready_for_fw(&self) -> bool {
self.ready_for_fw.get()
}
fn axi_bus(&mut self) -> Self::TBus<'_> {
EmulatedAxiBus { model: self }
fn apb_bus(&mut self) -> Self::TBus<'_> {
EmulatedApbBus { model: self }
}

fn step(&mut self) {
Expand Down Expand Up @@ -297,8 +297,9 @@ impl HwModel for ModelEmulated {
self.step();
}

// [TODO][CAP2] Should it be statically provisioned?
fn put_firmware_in_rri(&mut self, firmware: &[u8]) -> Result<(), ModelError> {
self.cpu.bus.bus.recovery.cms_data = Some(Rc::new(firmware.to_vec()));
self.cpu.bus.bus.dma.axi.recovery.cms_data = Some(Rc::new(firmware.to_vec()));
Ok(())
}
}
4 changes: 2 additions & 2 deletions hw-model/src/model_fpga_realtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl SocManager for ModelFpgaRealtime {
type TMmio<'a> = BusMmio<FpgaRealtimeBus<'a>>;

fn mmio_mut(&mut self) -> Self::TMmio<'_> {
BusMmio::new(self.axi_bus())
BusMmio::new(self.apb_bus())
}

fn delay(&mut self) {
Expand All @@ -344,7 +344,7 @@ impl SocManager for ModelFpgaRealtime {
impl HwModel for ModelFpgaRealtime {
type TBus<'a> = FpgaRealtimeBus<'a>;

fn axi_bus(&mut self) -> Self::TBus<'_> {
fn apb_bus(&mut self) -> Self::TBus<'_> {
FpgaRealtimeBus {
mmio: self.mmio,
phantom: Default::default(),
Expand Down
18 changes: 9 additions & 9 deletions hw-model/src/model_verilated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ const DEFAULT_AXI_PAUSER: u32 = 0x1;
// How many clock cycles before emitting a TRNG nibble
const TRNG_DELAY: u32 = 4;

pub struct VerilatedAxiBus<'a> {
pub struct VerilatedApbBus<'a> {
model: &'a mut ModelVerilated,
}
impl<'a> Bus for VerilatedAxiBus<'a> {
impl<'a> Bus for VerilatedApbBus<'a> {
fn read(&mut self, size: RvSize, addr: RvAddr) -> Result<RvData, caliptra_emu_bus::BusError> {
if addr & 0x3 != 0 {
return Err(caliptra_emu_bus::BusError::LoadAddrMisaligned);
}
let result = Ok(self.model.v.axi_read_u32(self.model.soc_axi_pauser, addr));
let result = Ok(self.model.v.apb_read_u32(self.model.soc_axi_pauser, addr));
self.model
.log
.borrow_mut()
Expand All @@ -53,7 +53,7 @@ impl<'a> Bus for VerilatedAxiBus<'a> {
}
self.model
.v
.axi_write_u32(self.model.soc_axi_pauser, addr, val);
.apb_write_u32(self.model.soc_axi_pauser, addr, val);
self.model
.log
.borrow_mut()
Expand Down Expand Up @@ -113,10 +113,10 @@ fn ahb_txn_size(ty: AhbTxnType) -> RvSize {
}
}
impl SocManager for ModelVerilated {
type TMmio<'a> = BusMmio<VerilatedAxiBus<'a>>;
type TMmio<'a> = BusMmio<VerilatedApbBus<'a>>;

fn mmio_mut(&mut self) -> Self::TMmio<'_> {
BusMmio::new(self.axi_bus())
BusMmio::new(self.apb_bus())
}

fn delay(&mut self) {
Expand All @@ -132,7 +132,7 @@ impl SocManager for ModelVerilated {
}

impl HwModel for ModelVerilated {
type TBus<'a> = VerilatedAxiBus<'a>;
type TBus<'a> = VerilatedApbBus<'a>;

fn new_unbooted(params: crate::InitParams) -> Result<Self, Box<dyn std::error::Error>>
where
Expand Down Expand Up @@ -271,8 +271,8 @@ impl HwModel for ModelVerilated {
self.trng_mode
}

fn axi_bus(&mut self) -> Self::TBus<'_> {
VerilatedAxiBus { model: self }
fn apb_bus(&mut self) -> Self::TBus<'_> {
VerilatedApbBus { model: self }
}

fn step(&mut self) {
Expand Down
Loading