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