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 
10 #include <sbi/riscv_io.h>
11 #include <sbi/sbi_ecall_interface.h>
12 #include <sbi_utils/sys/sifive_test.h>
13 
14 #define FINISHER_FAIL		0x3333
15 #define FINISHER_PASS		0x5555
16 #define FINISHER_RESET		0x7777
17 
18 static void *sifive_test_base;
19 
sifive_test_system_reset_check(u32 type,u32 reason)20 int sifive_test_system_reset_check(u32 type, u32 reason)
21 {
22 	switch (type) {
23 	case SBI_SRST_RESET_TYPE_SHUTDOWN:
24 	case SBI_SRST_RESET_TYPE_COLD_REBOOT:
25 	case SBI_SRST_RESET_TYPE_WARM_REBOOT:
26 		return 1;
27 	}
28 
29 	return 0;
30 }
31 
sifive_test_system_reset(u32 type,u32 reason)32 void sifive_test_system_reset(u32 type, u32 reason)
33 {
34 	/*
35 	 * Tell the "finisher" that the simulation
36 	 * was successful so that QEMU exits
37 	 */
38 	switch (type) {
39 	case SBI_SRST_RESET_TYPE_SHUTDOWN:
40 		if (reason == SBI_SRST_RESET_REASON_NONE)
41 			writew(FINISHER_PASS, sifive_test_base);
42 		else
43 			writew(FINISHER_FAIL, sifive_test_base);
44 		break;
45 	case SBI_SRST_RESET_TYPE_COLD_REBOOT:
46 	case SBI_SRST_RESET_TYPE_WARM_REBOOT:
47 		writew(FINISHER_RESET, sifive_test_base);
48 		break;
49 	}
50 }
51 
sifive_test_init(unsigned long base)52 int sifive_test_init(unsigned long base)
53 {
54 	sifive_test_base = (void *)base;
55 
56 	return 0;
57 }
58