Skip to content

Commit 4910069

Browse files
mcaylandhuth
authored andcommitted
next-cube: QOMify NeXTRTC
This is to allow the RTC functionality to be maintained within its own separate device rather than as part of the next-pc device. Signed-off-by: Mark Cave-Ayland <[email protected]> Message-ID: <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: Thomas Huth <[email protected]>
1 parent 501b509 commit 4910069

File tree

1 file changed

+50
-21
lines changed

1 file changed

+50
-21
lines changed

hw/m68k/next-cube.c

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,21 @@
4242
#define RAM_SIZE 0x4000000
4343
#define ROM_FILE "Rev_2.5_v66.bin"
4444

45-
typedef struct NeXTRTC {
45+
46+
#define TYPE_NEXT_RTC "next-rtc"
47+
OBJECT_DECLARE_SIMPLE_TYPE(NeXTRTC, NEXT_RTC)
48+
49+
struct NeXTRTC {
50+
SysBusDevice parent_obj;
51+
4652
int8_t phase;
4753
uint8_t ram[32];
4854
uint8_t command;
4955
uint8_t value;
5056
uint8_t status;
5157
uint8_t control;
5258
uint8_t retval;
53-
} NeXTRTC;
59+
};
5460

5561
#define TYPE_NEXT_SCSI "next-scsi"
5662
OBJECT_DECLARE_SIMPLE_TYPE(NeXTSCSI, NEXT_SCSI)
@@ -1012,6 +1018,37 @@ static const MemoryRegionOps next_dummy_en_ops = {
10121018
.endianness = DEVICE_BIG_ENDIAN,
10131019
};
10141020

1021+
static const VMStateDescription next_rtc_vmstate = {
1022+
.name = "next-rtc",
1023+
.version_id = 3,
1024+
.minimum_version_id = 3,
1025+
.fields = (const VMStateField[]) {
1026+
VMSTATE_INT8(phase, NeXTRTC),
1027+
VMSTATE_UINT8_ARRAY(ram, NeXTRTC, 32),
1028+
VMSTATE_UINT8(command, NeXTRTC),
1029+
VMSTATE_UINT8(value, NeXTRTC),
1030+
VMSTATE_UINT8(status, NeXTRTC),
1031+
VMSTATE_UINT8(control, NeXTRTC),
1032+
VMSTATE_UINT8(retval, NeXTRTC),
1033+
VMSTATE_END_OF_LIST()
1034+
},
1035+
};
1036+
1037+
static void next_rtc_class_init(ObjectClass *klass, void *data)
1038+
{
1039+
DeviceClass *dc = DEVICE_CLASS(klass);
1040+
1041+
dc->desc = "NeXT RTC";
1042+
dc->vmsd = &next_rtc_vmstate;
1043+
}
1044+
1045+
static const TypeInfo next_rtc_info = {
1046+
.name = TYPE_NEXT_RTC,
1047+
.parent = TYPE_SYS_BUS_DEVICE,
1048+
.instance_size = sizeof(NeXTRTC),
1049+
.class_init = next_rtc_class_init,
1050+
};
1051+
10151052
static void next_pc_rtc_data_in_irq(void *opaque, int n, int level)
10161053
{
10171054
NeXTPC *s = NEXT_PC(opaque);
@@ -1078,6 +1115,12 @@ static void next_pc_realize(DeviceState *dev, Error **errp)
10781115
}
10791116
sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(dev, NEXT_SCC_I));
10801117
sysbus_connect_irq(sbd, 1, qdev_get_gpio_in(dev, NEXT_SCC_DMA_I));
1118+
1119+
/* RTC */
1120+
d = DEVICE(&s->rtc);
1121+
if (!sysbus_realize(SYS_BUS_DEVICE(d), errp)) {
1122+
return;
1123+
}
10811124
}
10821125

10831126
static void next_pc_init(Object *obj)
@@ -1111,6 +1154,8 @@ static void next_pc_init(Object *obj)
11111154
"next.timer", 4);
11121155
sysbus_init_mmio(sbd, &s->timer_mem);
11131156

1157+
object_initialize_child(obj, "rtc", &s->rtc, TYPE_NEXT_RTC);
1158+
11141159
s->rtc_power_irq = qdev_get_gpio_in(DEVICE(obj), NEXT_PWR_I);
11151160
qdev_init_gpio_in_named(DEVICE(obj), next_pc_rtc_data_in_irq,
11161161
"pc-rtc-data-in", 1);
@@ -1128,34 +1173,17 @@ static const Property next_pc_properties[] = {
11281173
DEFINE_PROP_LINK("cpu", NeXTPC, cpu, TYPE_M68K_CPU, M68kCPU *),
11291174
};
11301175

1131-
static const VMStateDescription next_rtc_vmstate = {
1132-
.name = "next-rtc",
1133-
.version_id = 2,
1134-
.minimum_version_id = 2,
1135-
.fields = (const VMStateField[]) {
1136-
VMSTATE_INT8(phase, NeXTRTC),
1137-
VMSTATE_UINT8_ARRAY(ram, NeXTRTC, 32),
1138-
VMSTATE_UINT8(command, NeXTRTC),
1139-
VMSTATE_UINT8(value, NeXTRTC),
1140-
VMSTATE_UINT8(status, NeXTRTC),
1141-
VMSTATE_UINT8(control, NeXTRTC),
1142-
VMSTATE_UINT8(retval, NeXTRTC),
1143-
VMSTATE_END_OF_LIST()
1144-
},
1145-
};
1146-
11471176
static const VMStateDescription next_pc_vmstate = {
11481177
.name = "next-pc",
1149-
.version_id = 3,
1150-
.minimum_version_id = 3,
1178+
.version_id = 4,
1179+
.minimum_version_id = 4,
11511180
.fields = (const VMStateField[]) {
11521181
VMSTATE_UINT32(scr1, NeXTPC),
11531182
VMSTATE_UINT32(scr2, NeXTPC),
11541183
VMSTATE_UINT32(old_scr2, NeXTPC),
11551184
VMSTATE_UINT32(int_mask, NeXTPC),
11561185
VMSTATE_UINT32(int_status, NeXTPC),
11571186
VMSTATE_UINT32(led, NeXTPC),
1158-
VMSTATE_STRUCT(rtc, NeXTPC, 0, next_rtc_vmstate, NeXTRTC),
11591187
VMSTATE_END_OF_LIST()
11601188
},
11611189
};
@@ -1305,6 +1333,7 @@ static void next_register_type(void)
13051333
type_register_static(&next_typeinfo);
13061334
type_register_static(&next_pc_info);
13071335
type_register_static(&next_scsi_info);
1336+
type_register_static(&next_rtc_info);
13081337
}
13091338

13101339
type_init(next_register_type)

0 commit comments

Comments
 (0)