blob: ad688079c4113662ccd38efe248437c47dc5c145 [file] [log] [blame]
Michael Clark88a07992018-03-03 01:31:13 +13001/*
2 * QEMU SiFive Test Finisher
3 *
4 * Copyright (c) 2018 SiFive, Inc.
5 *
6 * Test finisher memory mapped device used to exit simulation
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2 or later, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "qemu/osdep.h"
22#include "hw/sysbus.h"
Markus Armbruster3e80f692020-06-10 07:31:58 +020023#include "qapi/error.h"
Bin Menga2360c82019-09-06 09:19:54 -070024#include "qemu/log.h"
Markus Armbruster0b8fa322019-05-23 16:35:07 +020025#include "qemu/module.h"
Bin Meng9a2551e2019-09-05 08:55:16 -070026#include "sysemu/runstate.h"
Bin Menga4b84602020-09-03 18:40:20 +080027#include "hw/misc/sifive_test.h"
Clément Chigot215128e2023-10-03 09:14:25 +020028#include "sysemu/sysemu.h"
Michael Clark88a07992018-03-03 01:31:13 +130029
30static uint64_t sifive_test_read(void *opaque, hwaddr addr, unsigned int size)
31{
32 return 0;
33}
34
35static void sifive_test_write(void *opaque, hwaddr addr,
36 uint64_t val64, unsigned int size)
37{
38 if (addr == 0) {
39 int status = val64 & 0xffff;
40 int code = (val64 >> 16) & 0xffff;
41 switch (status) {
42 case FINISHER_FAIL:
Clément Chigot215128e2023-10-03 09:14:25 +020043 qemu_system_shutdown_request_with_code(
44 SHUTDOWN_CAUSE_GUEST_PANIC, code);
45 return;
Michael Clark88a07992018-03-03 01:31:13 +130046 case FINISHER_PASS:
Clément Chigot215128e2023-10-03 09:14:25 +020047 qemu_system_shutdown_request_with_code(
48 SHUTDOWN_CAUSE_GUEST_SHUTDOWN, code);
49 return;
Bin Meng9a2551e2019-09-05 08:55:16 -070050 case FINISHER_RESET:
51 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
52 return;
Michael Clark88a07992018-03-03 01:31:13 +130053 default:
54 break;
55 }
56 }
Bin Menga2360c82019-09-06 09:19:54 -070057 qemu_log_mask(LOG_GUEST_ERROR, "%s: write: addr=0x%x val=0x%016" PRIx64 "\n",
58 __func__, (int)addr, val64);
Michael Clark88a07992018-03-03 01:31:13 +130059}
60
61static const MemoryRegionOps sifive_test_ops = {
62 .read = sifive_test_read,
63 .write = sifive_test_write,
64 .endianness = DEVICE_NATIVE_ENDIAN,
65 .valid = {
Nathan Chancellorab3d2072020-08-31 22:58:23 -070066 .min_access_size = 2,
Michael Clark88a07992018-03-03 01:31:13 +130067 .max_access_size = 4
68 }
69};
70
71static void sifive_test_init(Object *obj)
72{
73 SiFiveTestState *s = SIFIVE_TEST(obj);
74
75 memory_region_init_io(&s->mmio, obj, &sifive_test_ops, s,
76 TYPE_SIFIVE_TEST, 0x1000);
77 sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio);
78}
79
80static const TypeInfo sifive_test_info = {
81 .name = TYPE_SIFIVE_TEST,
82 .parent = TYPE_SYS_BUS_DEVICE,
83 .instance_size = sizeof(SiFiveTestState),
84 .instance_init = sifive_test_init,
85};
86
87static void sifive_test_register_types(void)
88{
89 type_register_static(&sifive_test_info);
90}
91
92type_init(sifive_test_register_types)
93
94
95/*
96 * Create Test device.
97 */
98DeviceState *sifive_test_create(hwaddr addr)
99{
Markus Armbruster3e80f692020-06-10 07:31:58 +0200100 DeviceState *dev = qdev_new(TYPE_SIFIVE_TEST);
Markus Armbruster3c6ef472020-06-10 07:32:34 +0200101 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
Michael Clark88a07992018-03-03 01:31:13 +1300102 sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr);
103 return dev;
104}