soundstream: ml fixups Fixes for kelvin handling. With the soundstream model loaded from renode (see below) the full demo works as intended. Changes: - enable ml_top irq's - correct interrupt handling; in particular update the multiwaiter events marked as triggered - correct ml_top_dmem pointer calculations NB: for testing add something like this to sencha.resc: $kelvin_bin?=@out/cheriot/sim/kelvin.bin sysbus LoadBinary $kelvin_bin 0x5A000000 Bug: 330741645 Bypass-Presubmit-Reason: no sencha presubmit tests Change-Id: I0bbe80d745803db185f013f2429cc13bcce9cca5
diff --git a/sw/device/cheriot/soundstream/ml_top.cc b/sw/device/cheriot/soundstream/ml_top.cc index dc931ce..a7b04c8 100644 --- a/sw/device/cheriot/soundstream/ml_top.cc +++ b/sw/device/cheriot/soundstream/ml_top.cc
@@ -55,6 +55,8 @@ CHECK_DIF_OK(dif_ml_top_init(mmio_region_from_addr((uintptr_t)MMIO_CAPABILITY( ml_top_mmio_t, ml_top_core)), &ml_top)); + ml_top_irq_set_enabled(kMlTopIrqFinish, /*enabled=*/true); + ml_top_irq_set_enabled(kMlTopIrqFault, /*enabled=*/true); semaphore_put(&startup); } @@ -83,15 +85,20 @@ for (;;) { Debug::Assert(multiwaiter_wait(&unlimited, mw, events, 2) == 0, "multiwaiter_wait"); - Debug::log("ml_top_isr: Finish:{} Fault:{}", events[0].value, events[1].value); if (events[1].value == 1) { // Fault signaled - LOG_FATAL("ML_TOP fault!"); + Debug::log("ml_top_isr: Fault, Finish:{}", events[0].value); abort(); + + events[1].value = *mlTopFaultFutex; } if (events[0].value == 1) { // Finish signaled + Debug::log("ml_top_isr: Finish"); finish_done = true; - interrupt_complete(STATIC_SEALED_VALUE(mlTopFinishInterruptCapability)); CHECK_DIF_OK(dif_ml_top_reset_ctrl_en(&ml_top)); + CHECK_DIF_OK(dif_ml_top_irq_acknowledge(&ml_top, kMlTopIrqFinish)); + interrupt_complete(STATIC_SEALED_VALUE(mlTopFinishInterruptCapability)); + + events[0].value = *mlTopFinishFutex; } } } @@ -104,11 +111,6 @@ return was_done; } -void ml_top_irq_acknowledge(ml_top_irq_t irq_id) { - CHECK_INIT(); - CHECK_DIF_OK(dif_ml_top_irq_acknowledge(&ml_top, irq_id)); -} - void ml_top_irq_acknowledge_all() { CHECK_INIT(); CHECK_DIF_OK(dif_ml_top_irq_acknowledge_all(&ml_top)); @@ -126,14 +128,14 @@ } void ml_top_set_input(void* const data, size_t data_len_bytes) { - void* input_ptr = (void*)(MMIO_CAPABILITY(ml_top_dmem_t, ml_top_dmem) + - TOP_MATCHA_RAM_ML_DMEM_SIZE_BYTES - 4096); + uint8_t* ml_top_dmem_base = (uint8_t*) MMIO_CAPABILITY(ml_top_dmem_t, ml_top_dmem); + void* input_ptr = ml_top_dmem_base + (TOP_MATCHA_RAM_ML_DMEM_SIZE_BYTES - 4096); memcpy(input_ptr, data, data_len_bytes); } void ml_top_get_output_header(struct output_header* header) { - uint8_t* ml_top_dmem_base = (uint8_t*) MMIO_CAPABILITY(ml_top_dmem_t, ml_top_dmem); - struct output_header* output_header_ptr = (struct output_header*) + const uint8_t* ml_top_dmem_base = (uint8_t*) MMIO_CAPABILITY(ml_top_dmem_t, ml_top_dmem); + const struct output_header* output_header_ptr = (const struct output_header*) (ml_top_dmem_base + (TOP_MATCHA_RAM_ML_DMEM_SIZE_BYTES - 0x40)); header->return_code = output_header_ptr->return_code; header->output_ptr = output_header_ptr->output_ptr; @@ -148,7 +150,6 @@ } void ml_top_get_output_data(struct output_header* const header, void* buffer) { - const void* src = (const void*)(MMIO_CAPABILITY(ml_top_dmem_t, ml_top_dmem) + - header->output_ptr); - memcpy(buffer, src, header->length); + const uint8_t* ml_top_dmem_base = (const uint8_t*) MMIO_CAPABILITY(ml_top_dmem_t, ml_top_dmem); + memcpy(buffer, ml_top_dmem_base + header->output_ptr, header->length); }
diff --git a/sw/device/cheriot/soundstream/ml_top.h b/sw/device/cheriot/soundstream/ml_top.h index 5555576..b860d5f 100644 --- a/sw/device/cheriot/soundstream/ml_top.h +++ b/sw/device/cheriot/soundstream/ml_top.h
@@ -22,7 +22,8 @@ #include "sw/device/lib/dif/dif_ml_top.h" typedef dif_ml_top_irq_t ml_top_irq_t; -const uint32_t kMlTopIrqFinish = kDifMlTopIrqFinish; +const ml_top_irq_t kMlTopIrqFinish = kDifMlTopIrqFinish; +const ml_top_irq_t kMlTopIrqFault = kDifMlTopIrqFault; struct output_header { uint32_t return_code; // Populated in kelvin_start