sifive_test.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * SPDX-License-Identifier: BSD-3-Clause
  3. *
  4. * Copyright (c) 2020 Western Digital Corporation or its affiliates.
  5. *
  6. * Authors:
  7. * Anup Patel <anup.patel@wdc.com>
  8. */
  9. #include <sbi/riscv_io.h>
  10. #include <sbi/sbi_ecall_interface.h>
  11. #include <sbi/sbi_system.h>
  12. #include <sbi_utils/sys/sifive_test.h>
  13. #define FINISHER_FAIL 0x3333
  14. #define FINISHER_PASS 0x5555
  15. #define FINISHER_RESET 0x7777
  16. static void *sifive_test_base;
  17. static int sifive_test_system_reset_check(u32 type, u32 reason)
  18. {
  19. switch (type) {
  20. case SBI_SRST_RESET_TYPE_SHUTDOWN:
  21. case SBI_SRST_RESET_TYPE_COLD_REBOOT:
  22. case SBI_SRST_RESET_TYPE_WARM_REBOOT:
  23. return 1;
  24. }
  25. return 0;
  26. }
  27. static void sifive_test_system_reset(u32 type, u32 reason)
  28. {
  29. /*
  30. * Tell the "finisher" that the simulation
  31. * was successful so that QEMU exits
  32. */
  33. switch (type) {
  34. case SBI_SRST_RESET_TYPE_SHUTDOWN:
  35. if (reason == SBI_SRST_RESET_REASON_NONE)
  36. writew(FINISHER_PASS, sifive_test_base);
  37. else
  38. writew(FINISHER_FAIL, sifive_test_base);
  39. break;
  40. case SBI_SRST_RESET_TYPE_COLD_REBOOT:
  41. case SBI_SRST_RESET_TYPE_WARM_REBOOT:
  42. writew(FINISHER_RESET, sifive_test_base);
  43. break;
  44. }
  45. }
  46. static struct sbi_system_reset_device sifive_test_reset = {
  47. .name = "sifive_test",
  48. .system_reset_check = sifive_test_system_reset_check,
  49. .system_reset = sifive_test_system_reset
  50. };
  51. int sifive_test_init(unsigned long base)
  52. {
  53. sifive_test_base = (void *)base;
  54. sbi_system_reset_add_device(&sifive_test_reset);
  55. return 0;
  56. }