| // Copyright 2022 Google LLC. |
| // Copyright lowRISC contributors. |
| // Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| // SPDX-License-Identifier: Apache-2.0 |
| |
| // Simple program to turn on the SMC and fall asleep. |
| |
| #include "hw/top_matcha/sw/autogen/top_matcha.h" |
| #include "sw/device/lib/arch/device.h" |
| #include "sw/device/lib/dif/dif_smc_ctrl.h" |
| #include "sw/device/lib/runtime/hart.h" |
| #include "sw/device/lib/testing/test_framework/check.h" |
| #include "sw/device/lib/testing/test_framework/ottf_test_config.h" |
| |
| #if defined(PAGE_BOUNDARY_TEST) |
| #include "sw/device/tests/smc/smc_page_boundary_test_fpga_nexus_bin_c.h" |
| #elif defined(INTERRUPT_BOUNDARY_TEST) |
| #include "sw/device/tests/smc/smc_interrupt_boundary_test_fpga_nexus_bin_c.h" |
| #elif defined(LSU_INTERRUPT_BOUNDARY_TEST) |
| #include "sw/device/tests/smc/smc_lsu_interrupt_boundary_test_fpga_nexus_bin_c.h" |
| #elif defined(LSU_PAGE_BOUNDARY_TEST) |
| #include "sw/device/tests/smc/smc_lsu_page_boundary_test_fpga_nexus_bin_c.h" |
| #endif |
| |
| OTTF_DEFINE_TEST_CONFIG(); |
| |
| static dif_smc_ctrl_t smc_ctrl; |
| |
| void _ottf_main(void) { |
| #if defined(HAS_SMC_BIN) |
| if (kDeviceType == kDeviceFpgaNexus) { |
| memcpy((void*)TOP_MATCHA_RAM_SMC_BASE_ADDR, smc_bin, smc_bin_len); |
| } |
| #endif |
| CHECK_DIF_OK(dif_smc_ctrl_init( |
| mmio_region_from_addr(TOP_MATCHA_SMC_CTRL_BASE_ADDR), &smc_ctrl)); |
| |
| CHECK_DIF_OK(dif_smc_ctrl_set_en(&smc_ctrl)); |
| |
| // Note: the SMC must end the simulation through testing or otherwise, as the |
| // secure core indefinitely sleeps. |
| asm volatile("wfi"); |
| } |