2 * SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2024 IBM Corp.
5 * IBM Flexible Service Interface
7 #include "qemu/osdep.h"
8 #include "qapi/error.h"
12 #include "hw/fsi/fsi.h"
14 #define TO_REG(x) ((x) >> 2)
16 static const TypeInfo fsi_bus_info
= {
19 .instance_size
= sizeof(FSIBus
),
22 static uint64_t fsi_slave_read(void *opaque
, hwaddr addr
, unsigned size
)
24 FSISlaveState
*s
= FSI_SLAVE(opaque
);
25 int reg
= TO_REG(addr
);
27 trace_fsi_slave_read(addr
, size
);
29 if (reg
>= FSI_SLAVE_CONTROL_NR_REGS
) {
30 qemu_log_mask(LOG_GUEST_ERROR
,
31 "%s: Out of bounds read: 0x%"HWADDR_PRIx
" for %u\n",
32 __func__
, addr
, size
);
39 static void fsi_slave_write(void *opaque
, hwaddr addr
, uint64_t data
,
42 FSISlaveState
*s
= FSI_SLAVE(opaque
);
43 int reg
= TO_REG(addr
);
45 trace_fsi_slave_write(addr
, size
, data
);
47 if (reg
>= FSI_SLAVE_CONTROL_NR_REGS
) {
48 qemu_log_mask(LOG_GUEST_ERROR
,
49 "%s: Out of bounds write: 0x%"HWADDR_PRIx
" for %u\n",
50 __func__
, addr
, size
);
57 static const struct MemoryRegionOps fsi_slave_ops
= {
58 .read
= fsi_slave_read
,
59 .write
= fsi_slave_write
,
60 .endianness
= DEVICE_BIG_ENDIAN
,
63 static void fsi_slave_reset(DeviceState
*dev
)
65 FSISlaveState
*s
= FSI_SLAVE(dev
);
67 /* Initialize registers */
68 memset(s
->regs
, 0, sizeof(s
->regs
));
71 static void fsi_slave_init(Object
*o
)
73 FSISlaveState
*s
= FSI_SLAVE(o
);
75 memory_region_init_io(&s
->iomem
, OBJECT(s
), &fsi_slave_ops
,
76 s
, TYPE_FSI_SLAVE
, 0x400);
79 static void fsi_slave_class_init(ObjectClass
*klass
, void *data
)
81 DeviceClass
*dc
= DEVICE_CLASS(klass
);
83 dc
->bus_type
= TYPE_FSI_BUS
;
84 dc
->desc
= "FSI Slave";
85 device_class_set_legacy_reset(dc
, fsi_slave_reset
);
88 static const TypeInfo fsi_slave_info
= {
89 .name
= TYPE_FSI_SLAVE
,
90 .parent
= TYPE_DEVICE
,
91 .instance_init
= fsi_slave_init
,
92 .instance_size
= sizeof(FSISlaveState
),
93 .class_init
= fsi_slave_class_init
,
96 static void fsi_register_types(void)
98 type_register_static(&fsi_bus_info
);
99 type_register_static(&fsi_slave_info
);
102 type_init(fsi_register_types
);