xref: /qemu/hw/tricore/tricore_testdevice.c (revision 06b40d250ecfa1633209c2e431a7a38acfd03a98)
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 
tricore_testdevice_write(void * opaque,hwaddr offset,uint64_t value,unsigned size)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 
tricore_testdevice_read(void * opaque,hwaddr offset,unsigned size)33 static uint64_t tricore_testdevice_read(void *opaque, hwaddr offset,
34                                          unsigned size)
35 {
36     return 0xdeadbeef;
37 }
38 
tricore_testdevice_reset(DeviceState * dev)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_LITTLE_ENDIAN,
51 };
52 
tricore_testdevice_init(Object * obj)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 
tricore_testdevice_class_init(ObjectClass * klass,const void * data)61 static void tricore_testdevice_class_init(ObjectClass *klass, const void *data)
62 {
63     DeviceClass *dc = DEVICE_CLASS(klass);
64 
65     device_class_set_legacy_reset(dc, tricore_testdevice_reset);
66 }
67 
68 static const TypeInfo tricore_testdevice_info = {
69     .name          = TYPE_TRICORE_TESTDEVICE,
70     .parent        = TYPE_SYS_BUS_DEVICE,
71     .instance_size = sizeof(TriCoreTestDeviceState),
72     .instance_init = tricore_testdevice_init,
73     .class_init    = tricore_testdevice_class_init,
74 };
75 
tricore_testdevice_register_types(void)76 static void tricore_testdevice_register_types(void)
77 {
78     type_register_static(&tricore_testdevice_info);
79 }
80 
81 type_init(tricore_testdevice_register_types)
82