| /* |
| * Copyright 2023 Google LLC |
| * Copyright lowRISC contributors |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| |
| #include "hw/top_matcha/ip/ml_top/data/ml_top_regs.h" // Generated. |
| #include "hw/top_matcha/sw/autogen/top_matcha.h" |
| #include "sw/device/lib/arch/device.h" |
| #include "sw/device/lib/dif/dif_uart.h" |
| #include "sw/device/lib/runtime/hart.h" |
| #include "sw/device/lib/runtime/log.h" |
| #include "sw/device/lib/runtime/print.h" |
| #include "sw/device/lib/testing/test_framework/check.h" |
| #include "sw/device/lib/testing/test_framework/ottf_test_config.h" |
| #include "sw/device/lib/testing/test_framework/status.h" |
| #include "sw/device/lib/testing/test_framework/test_util.h" |
| |
| OTTF_DEFINE_TEST_CONFIG(); |
| |
| static dif_uart_t smc_uart; |
| |
| void _ottf_main(void) { |
| uint32_t mem_val; |
| uint32_t intr_state; |
| |
| const uint32_t kKelvinDataOffset = 0x100000; // 1MB |
| const uint32_t kKelvinDataSize = 0x1000; // 1024 32-bit words |
| |
| // Initialize the SMC UART to enable logging for non-DV simulation platforms. |
| if (kDeviceType != kDeviceSimDV) { |
| init_uart(TOP_MATCHA_SMC_UART_BASE_ADDR, &smc_uart); |
| } |
| |
| LOG_INFO("Hello Shodan! let's do a Kelvin core simple test!"); |
| |
| // Start testing ML_TOP_Core |
| test_status_set(kTestStatusInTest); |
| mmio_region_t base_addr = |
| mmio_region_from_addr(TOP_MATCHA_ML_TOP_CORE_BASE_ADDR); |
| |
| intr_state = mmio_region_read32(base_addr, ML_TOP_INTR_STATE_REG_OFFSET); |
| CHECK(intr_state == 0, |
| "ML_TOP_Core offset 0 INTR_STATE - Expected: 0 | Actual: 0x%x", |
| intr_state); |
| // Write 1 to clear INTR_STATE |
| mmio_region_write32(base_addr, ML_TOP_INTR_STATE_REG_OFFSET, 0x1); |
| intr_state = mmio_region_read32(base_addr, ML_TOP_INTR_STATE_REG_OFFSET); |
| CHECK(intr_state == 0, |
| "ML_TOP_Core offset 0 INTR_STATE read again - Expected: 0 | Actual: " |
| "0x%x", |
| intr_state); |
| |
| mem_val = mmio_region_read32(base_addr, ML_TOP_INTR_ENABLE_REG_OFFSET); |
| CHECK(mem_val == 0, |
| "ML_TOP_TOP offset 4 INTR_ENABLE - Expected: 0 | Actual: 0x%x", |
| mem_val); |
| mem_val = mmio_region_read32(base_addr, ML_TOP_INTR_TEST_REG_OFFSET); |
| CHECK(mem_val == 0, |
| "ML_TOP_TOP offset 8 INTR_TEST - Expected: 0 | Actual: 0x%x", mem_val); |
| |
| mem_val = mmio_region_read32(base_addr, ML_TOP_CTRL_REG_OFFSET); |
| CHECK(mem_val == ML_TOP_CTRL_REG_RESVAL, |
| "ML_TOP_TOP offset 0xc ML_CTRL - Expected: 0x%x | Actual: 0x%x", |
| ML_TOP_CTRL_REG_OFFSET, mem_val); |
| |
| // Write DMEM with initial values |
| mmio_region_t ml_dmem = |
| mmio_region_from_addr(TOP_MATCHA_ML_TOP_DMEM_BASE_ADDR); |
| for (uint32_t i = kKelvinDataOffset; i < kKelvinDataOffset + kKelvinDataSize; |
| i += sizeof(uint32_t)) { |
| mmio_region_write32(ml_dmem, i, i); |
| } |
| |
| // Un-freeze clock and Reset of ML_TOP |
| mmio_region_write32(base_addr, ML_TOP_CTRL_REG_OFFSET, |
| ML_TOP_CTRL_REG_RESVAL); |
| mem_val = mmio_region_read32(base_addr, ML_TOP_CTRL_REG_OFFSET); |
| CHECK(mem_val == ML_TOP_CTRL_REG_RESVAL, |
| "ML_TOP_CTRL read out: expected : 0x%x | actual: 0x%x", |
| ML_TOP_CTRL_REG_RESVAL, mem_val); |
| |
| // Release the Reset of ML_TOP |
| mmio_region_write32(base_addr, ML_TOP_CTRL_REG_OFFSET, 0x0); |
| mem_val = mmio_region_read32(base_addr, ML_TOP_CTRL_REG_OFFSET); |
| CHECK(mem_val == 0x0, "ML_TOP_CTRL read out: expected : 0x0 | actual: 0x%x", |
| mem_val); |
| |
| // Wait for a interrupt |
| intr_state = mmio_region_read32(base_addr, ML_TOP_INTR_STATE_REG_OFFSET); |
| CHECK(intr_state == 0, |
| "ML_TOP_Core offset 0 INTR_STATE - Expected: 0x0 | Actual: 0x%x", |
| intr_state); |
| |
| while (intr_state == 0x0) { |
| intr_state = mmio_region_read32(base_addr, ML_TOP_INTR_STATE_REG_OFFSET); |
| busy_spin_micros(200); |
| } |
| |
| // Received interrupts from Kelvin core, check if only FINISH asserted |
| CHECK(intr_state == (1 << ML_TOP_INTR_STATE_FINISH_BIT), |
| "INTR_STATE read out: expected : 0x%x | actual: 0x%x", |
| (1 << ML_TOP_INTR_STATE_FINISH_BIT), intr_state); |
| |
| // Check Kelvin result. The program adds 1 to the data stored in the test |
| // range 0x5A100000 to 0x5A101000. |
| for (uint32_t i = kKelvinDataOffset; i < kKelvinDataOffset + kKelvinDataSize; |
| i += sizeof(uint32_t)) { |
| uint32_t val = mmio_region_read32(ml_dmem, i); |
| CHECK(val == i + 1, |
| "Mismatch data at offset 0x%x - Expected: 0x%x | Actual: 0x%x", i, |
| i + 1, val); |
| } |
| test_status_set(kTestStatusPassed); |
| } |