1 /*
2  *  Copyright (c) 2018-2021 Bastian Koppelmann Paderborn University
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "qemu/osdep.h"
19 #include "qemu/log.h"
20 #include "hw/sysbus.h"
21 #include "hw/qdev-properties.h"
22 #include "hw/tricore/tricore_testdevice.h"
23 
24 static void tricore_testdevice_write(void *opaque, hwaddr offset,
25                                       uint64_t value, unsigned size)
26 {
27     if (value != 0) {
28         qemu_log_mask(LOG_GUEST_ERROR, "Test %" PRIu64 " failed!\n", value);
29     }
30     exit(value);
31 }
32 
33 static uint64_t tricore_testdevice_read(void *opaque, hwaddr offset,
34                                          unsigned size)
35 {
36     return 0xdeadbeef;
37 }
38 
39 static void tricore_testdevice_reset(DeviceState *dev)
40 {
41 }
42 
43 static const MemoryRegionOps tricore_testdevice_ops = {
44     .read = tricore_testdevice_read,
45     .write = tricore_testdevice_write,
46     .valid = {
47         .min_access_size = 4,
48         .max_access_size = 4,
49     },
50     .endianness = DEVICE_NATIVE_ENDIAN,
51 };
52 
53 static void tricore_testdevice_init(Object *obj)
54 {
55     TriCoreTestDeviceState *s = TRICORE_TESTDEVICE(obj);
56    /* map memory */
57     memory_region_init_io(&s->iomem, OBJECT(s), &tricore_testdevice_ops, s,
58                           "tricore_testdevice", 0x4);
59 }
60 
61 static Property tricore_testdevice_properties[] = {
62     DEFINE_PROP_END_OF_LIST()
63 };
64 
65 static void tricore_testdevice_class_init(ObjectClass *klass, void *data)
66 {
67     DeviceClass *dc = DEVICE_CLASS(klass);
68 
69     device_class_set_props(dc, tricore_testdevice_properties);
70     device_class_set_legacy_reset(dc, tricore_testdevice_reset);
71 }
72 
73 static const TypeInfo tricore_testdevice_info = {
74     .name          = TYPE_TRICORE_TESTDEVICE,
75     .parent        = TYPE_SYS_BUS_DEVICE,
76     .instance_size = sizeof(TriCoreTestDeviceState),
77     .instance_init = tricore_testdevice_init,
78     .class_init    = tricore_testdevice_class_init,
79 };
80 
81 static void tricore_testdevice_register_types(void)
82 {
83     type_register_static(&tricore_testdevice_info);
84 }
85 
86 type_init(tricore_testdevice_register_types)
87