hw/rtc: Rename RTCState -> MC146818RtcState and adapt API
cover hw/rtc: Rename RTCState -> MC146818RtcState and adapt API
rtc_get_memory() and rtc_set_memory() helpers only work with MC146818 RTC devices, not any ISA device. Rename accordingly including 'MC146818' in the method names.
Philippe Mathieu-Daudé (3):
hw/rtc/mc146818rtc: Rename RTCState -> MC146818RtcState hw/rtc/mc146818rtc: Pass MC146818RtcState instead of ISADevice
argument
hw/rtc: Rename rtc_[get|set]_memory -> mc146818rtc_[get|set]_cmos_data
hw/i386/microvm.c | 28 ++++---- hw/i386/pc.c | 74 +++++++++++---------- hw/i386/x86.c | 8 ++- hw/isa/piix4.c | 2 +- hw/isa/vt82c686.c | 2 +- hw/ppc/prep.c | 11 ++- hw/rtc/mc146818rtc.c | 125 +++++++++++++++++------------------ include/hw/rtc/mc146818rtc.h | 14 ++-- 8 files changed, 132 insertions(+), 132 deletions(-)
Signature · 1 line
2.38.1
PATCH 1/3 hw/rtc/mc146818rtc: Rename RTCState -> MC146818RtcState
RTCState only represents a Motorola MC146818 model, not any RTC chipset. Rename the structure as MC146818RtcState using:
$ sed -i -e s/RTCState/MC146818RtcState/g $(git grep -wl RTCState)
--- hw/isa/piix4.c | 2 +- hw/isa/vt82c686.c | 2 +- hw/rtc/mc146818rtc.c | 116 +++++++++++++++++------------------ include/hw/rtc/mc146818rtc.h | 6 +- 4 files changed, 63 insertions(+), 63 deletions(-)
hw/isa/piix4.c +1 -1
@@ -47,7 +47,7 @@ struct PIIX4State {qemu_irq cpu_intr;qemu_irq *isa; -RTCState rtc; +MC146818RtcState rtc;PCIIDEState ide;UHCIState uhci;PIIX4PMState pm;
hw/isa/vt82c686.c +1 -1
@@ -550,7 +550,7 @@ struct ViaISAState {qemu_irq cpu_intr;qemu_irq *isa_irqs;ViaSuperIOState via_sio; -RTCState rtc; +MC146818RtcState rtc;PCIIDEState ide;UHCIState uhci[2 ];ViaPMState pm;
hw/rtc/mc146818rtc.c +58 -58
356 lines not on this page · raw message
include/hw/rtc/mc146818rtc.h +3 -3
@@ -16,9 +16,9 @@#include "qom/object.h" #define TYPE_MC146818_RTC "mc146818rtc" -OBJECT_DECLARE_SIMPLE_TYPE(RTCState, MC146818_RTC) +OBJECT_DECLARE_SIMPLE_TYPE(MC146818RtcState, MC146818_RTC) -struct RTCState { +struct MC146818RtcState {ISADevice parent_obj;MemoryRegion io;
@@ -46,7 +46,7 @@ struct RTCState {Notifier clock_reset_notifier;LostTickPolicy lost_tick_policy;Notifier suspend_notifier; -QLIST_ENTRY (RTCState) link; +QLIST_ENTRY (MC146818RtcState) link; };#define RTC_ISA_IRQ 8
Signature · 1 line
2.38.1
Re: [PATCH 1/3] hw/rtc/mc146818rtc: Rename RTCState -> MC146818RtcState
Quoted 6 lines · Philippe Mathieu-Daudé
RTCState only represents a Motorola MC146818 model, not any RTC chipset. Rename the structure as MC146818RtcState using:
$ sed -i -e s/RTCState/MC146818RtcState/g $(git grep -wl RTCState)
Quoted 7 lines
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/isa/piix4.c | 2 +- hw/isa/vt82c686.c | 2 +- hw/rtc/mc146818rtc.c | 116 +++++++++++++++++------------------ include/hw/rtc/mc146818rtc.h | 6 +- 4 files changed, 63 insertions(+), 63 deletions(-)
r~
PATCH 2/3 hw/rtc/mc146818rtc: Pass MC146818RtcState instead of ISADevice argument
In reply to Philippe Mathieu-Daudértc_get_memory() and rtc_set_memory() methods can not take any TYPE_ISA_DEVICE object. They expect a TYPE_MC146818_RTC one.
Simplify the API by passing a MC146818RtcState.
--- hw/i386/microvm.c | 6 ++---- hw/i386/pc.c | 16 +++++++++------- hw/i386/x86.c | 4 +++- hw/ppc/prep.c | 3 +-- hw/rtc/mc146818rtc.c | 13 ++++++------- include/hw/rtc/mc146818rtc.h | 8 ++++---- 6 files changed, 25 insertions(+), 25 deletions(-)
hw/i386/microvm.c +2 -4
@@ -57,7 +57,7 @@#define MICROVM_QBOOT_FILENAME "qboot.rom"#define MICROVM_BIOS_FILENAME "bios-microvm.bin" -static void microvm_set_rtc (MicrovmMachineState *mms,ISADevice *s) +static void microvm_set_rtc (MicrovmMachineState *mms,MC146818RtcState *s) {X86MachineState *x86ms =X86_MACHINE (mms);int val;
@@ -161,7 +161,6 @@ static void microvm_devices_init(MicrovmMachineState *mms)const char *default_firmware;X86MachineState *x86ms =X86_MACHINE (mms);ISABus *isa_bus; -ISADevice *rtc_state;GSIState *gsi_state;int ioapics;int i;
@@ -267,8 +266,7 @@ static void microvm_devices_init(MicrovmMachineState *mms)if (mms->rtc ==ON_OFF_AUTO_ON || (mms->rtc ==ON_OFF_AUTO_AUTO && !kvm_enabled ())) { - rtc_state =mc146818_rtc_init (isa_bus,2000 ,NULL ); -microvm_set_rtc (mms, rtc_state); +microvm_set_rtc (mms,mc146818_rtc_init (isa_bus,2000 ,NULL )); }if (mms->isa_serial) {
hw/i386/pc.c +9 -7
@@ -439,7 +439,7 @@ static uint64_t ioportF0_read(void *opaque, hwaddr addr, unsigned size)#define REG_EQUIPMENT_BYTE 0x14 -static void cmos_init_hd (ISADevice *s,int type_ofs,int info_ofs, +static void cmos_init_hd (MC146818RtcState *s,int type_ofs,int info_ofs,int16_t cylinders,int8_t heads,int8_t sectors) {rtc_set_memory (s, type_ofs,47 );
@@ -471,7 +471,8 @@ static int boot_device2nibble(char boot_device)return 0 ; } -static void set_boot_dev (ISADevice *s,const char *boot_device,Error **errp) +static void set_boot_dev (MC146818RtcState *s,const char *boot_device, +Error **errp) {#define PC_MAX_BOOT_DEVICES 3int nbds, bds[3 ] = {0 , };
@@ -499,7 +500,7 @@ static void pc_boot_set(void *opaque, const char *boot_device, Error **errp)set_boot_dev (opaque, boot_device, errp); } -static void pc_cmos_init_floppy (ISADevice *rtc_state,ISADevice *floppy) +static void pc_cmos_init_floppy (MC146818RtcState *rtc_state,ISADevice *floppy) {int val, nb, i;FloppyDriveType fd_type[2 ] = {FLOPPY_DRIVE_TYPE_NONE ,
@@ -537,7 +538,7 @@ static void pc_cmos_init_floppy(ISADevice *rtc_state, ISADevice *floppy) }typedef struct pc_cmos_init_late_arg { -ISADevice *rtc_state; +MC146818RtcState *rtc_state;BusState *idebus[2 ]; }pc_cmos_init_late_arg ;
@@ -604,7 +605,7 @@ static ISADevice *pc_find_fdc0(void)static void pc_cmos_init_late (void *opaque) {pc_cmos_init_late_arg *arg = opaque; -ISADevice *s = arg->rtc_state; +MC146818RtcState *s = arg->rtc_state;int16_t cylinders;int8_t heads, sectors;int val;
@@ -646,11 +647,12 @@ static void pc_cmos_init_late(void *opaque)void pc_cmos_init (PCMachineState *pcms,BusState *idebus0,BusState *idebus1, -ISADevice *s) +ISADevice *rtc) {int val;static pc_cmos_init_late_arg arg;X86MachineState *x86ms =X86_MACHINE (pcms); +MC146818RtcState *s =MC146818_RTC (rtc);/* various important CMOS locations needed by PC/Bochs bios */
@@ -1304,7 +1306,7 @@ void pc_basic_device_init(struct PCMachineState *pcms, pit_alt_irq =qdev_get_gpio_in (hpet,HPET_LEGACY_PIT_INT ); rtc_irq =qdev_get_gpio_in (hpet,HPET_LEGACY_RTC_INT ); } - *rtc_state =mc146818_rtc_init (isa_bus,2000 , rtc_irq); + *rtc_state =ISA_DEVICE (mc146818_rtc_init (isa_bus,2000 , rtc_irq));qemu_register_boot_set (pc_boot_set, *rtc_state);
hw/i386/x86.c +3 -1
@@ -151,8 +151,10 @@ void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version) } } -void x86_rtc_set_cpus_count (ISADevice *rtc,uint16_t cpus_count) +void x86_rtc_set_cpus_count (ISADevice *s,uint16_t cpus_count) { +MC146818RtcState *rtc =MC146818_RTC (s); +if (cpus_count >0xff ) {/* * If the number of CPUs can't be represented in 8 bits, the
hw/ppc/prep.c +1 -2
@@ -212,10 +212,9 @@ static int PPC_NVRAM_set_params (Nvram *nvram, uint16_t NVRAM_size,static int prep_set_cmos_checksum (DeviceState *dev,void *opaque) {uint16_t checksum = *(uint16_t *)opaque; -ISADevice *rtc;if (object_dynamic_cast (OBJECT (dev),TYPE_MC146818_RTC )) { - rtc =ISA_DEVICE (dev); +MC146818RtcState *rtc =MC146818_RTC (dev);rtc_set_memory (rtc,0x2e , checksum &0xff );rtc_set_memory (rtc,0x3e , checksum &0xff );rtc_set_memory (rtc,0x2f , checksum >>8 );
hw/rtc/mc146818rtc.c +6 -7
@@ -739,16 +739,14 @@ static uint64_t cmos_ioport_read(void *opaque, hwaddr addr, } } -void rtc_set_memory (ISADevice *dev,int addr,int val) +void rtc_set_memory (MC146818RtcState *s,int addr,int val) { -MC146818RtcState *s =MC146818_RTC (dev);if (addr >=0 && addr <=127 ) s->cmos_data[addr] = val; } -int rtc_get_memory (ISADevice *dev,int addr) +int rtc_get_memory (MC146818RtcState *s,int addr) { -MC146818RtcState *s =MC146818_RTC (dev);assert (addr >=0 && addr <=127 );return s->cmos_data[addr]; }
@@ -858,7 +856,7 @@ static const VMStateDescription vmstate_rtc = {static void rtc_notify_suspend (Notifier *notifier,void *data) {MC146818RtcState *s =container_of (notifier, MC146818RtcState, suspend_notifier); -rtc_set_memory (ISA_DEVICE (s),0xF ,0xFE ); +rtc_set_memory (s,0xF ,0xFE ); }static const MemoryRegionOps cmos_ops = {
@@ -945,7 +943,8 @@ static void rtc_realizefn(DeviceState *dev, Error **errp)QLIST_INSERT_HEAD (&rtc_devices, s, link); } -ISADevice *mc146818_rtc_init (ISABus *bus,int base_year,qemu_irq intercept_irq) +MC146818RtcState *mc146818_rtc_init (ISABus *bus,int base_year, +qemu_irq intercept_irq) {DeviceState *dev;ISADevice *isadev;
@@ -965,7 +964,7 @@ ISADevice *mc146818_rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)object_property_add_alias (qdev_get_machine (),"rtc-time" ,OBJECT (isadev),"date" ); -return isadev; +return s; }static Property mc146818rtc_properties[] = {
include/hw/rtc/mc146818rtc.h +4 -4
@@ -51,10 +51,10 @@ struct MC146818RtcState {#define RTC_ISA_IRQ 8 -ISADevice *mc146818_rtc_init (ISABus *bus,int base_year, -qemu_irq intercept_irq); -void rtc_set_memory (ISADevice *dev,int addr,int val); -int rtc_get_memory (ISADevice *dev,int addr); +MC146818RtcState *mc146818_rtc_init (ISABus *bus,int base_year, +qemu_irq intercept_irq); +void rtc_set_memory (MC146818RtcState *s,int addr,int val); +int rtc_get_memory (MC146818RtcState *s,int addr);void qmp_rtc_reset_reinjection (Error **errp);#endif /* HW_RTC_MC146818RTC_H */
Signature · 1 line
2.38.1
Re: [PATCH 2/3] hw/rtc/mc146818rtc: Pass MC146818RtcState instead of ISADevice argument
Quoted 6 lines · Philippe Mathieu-Daudé
rtc_get_memory()andrtc_set_memory()methods can not take anyTYPE_ISA_DEVICEobject. They expect aTYPE_MC146818_RTCone.Simplify the API by passing a MC146818RtcState.
Signed-off-by Philippe Mathieu-Daudé<[email protected]>
Quoted 8 lines
--- hw/i386/microvm.c | 6 ++---- hw/i386/pc.c | 16 +++++++++------- hw/i386/x86.c | 4 +++- hw/ppc/prep.c | 3 +-- hw/rtc/mc146818rtc.c | 13 ++++++------- include/hw/rtc/mc146818rtc.h | 8 ++++---- 6 files changed, 25 insertions(+), 25 deletions(-)
r~
PATCH 3/3 hw/rtc: Rename rtc_[get|set]_memory -> mc146818rtc_[get|set]_cmos_data
In reply to Philippe Mathieu-Daudértc_get_memory() and rtc_set_memory() helpers only work with TYPE_MC146818_RTC devices. 'memory' in their name refer to the CMOS region. Rename them as mc146818rtc_get_cmos_data() and mc146818rtc_set_cmos_data() to be explicit about what they are doing.
Mechanical change doing:
$ sed -i -e 's/rtc_set_memory/mc146818rtc_set_cmos_data/g' \
$(git grep -wl rtc_set_memory)
$ sed -i -e 's/rtc_get_memory/mc146818rtc_get_cmos_data/g' \
$(git grep -wl rtc_get_memory)--- hw/i386/microvm.c | 22 +++++++------- hw/i386/pc.c | 58 ++++++++++++++++++------------------ hw/i386/x86.c | 4 +-- hw/ppc/prep.c | 8 ++--- hw/rtc/mc146818rtc.c | 6 ++-- include/hw/rtc/mc146818rtc.h | 4 +-- 6 files changed, 51 insertions(+), 51 deletions(-)
hw/i386/microvm.c +11 -11
@@ -63,8 +63,8 @@ static void microvm_set_rtc(MicrovmMachineState *mms, MC146818RtcState *s)int val; val =MIN (x86ms->below_4g_mem_size / KiB,640 ); -rtc_set_memory (s,0x15 , val); -rtc_set_memory (s,0x16 , val >>8 ); +mc146818rtc_set_cmos_data (s,0x15 , val); +mc146818rtc_set_cmos_data (s,0x16 , val >>8 );/* extended memory (next 64MiB) */ if (x86ms->below_4g_mem_size >1 * MiB) { val = (x86ms->below_4g_mem_size -1 * MiB) / KiB;
@@ -74,10 +74,10 @@ static void microvm_set_rtc(MicrovmMachineState *mms, MC146818RtcState *s)if (val >65535 ) { val =65535 ; } -rtc_set_memory (s,0x17 , val); -rtc_set_memory (s,0x18 , val >>8 ); -rtc_set_memory (s,0x30 , val); -rtc_set_memory (s,0x31 , val >>8 ); +mc146818rtc_set_cmos_data (s,0x17 , val); +mc146818rtc_set_cmos_data (s,0x18 , val >>8 ); +mc146818rtc_set_cmos_data (s,0x30 , val); +mc146818rtc_set_cmos_data (s,0x31 , val >>8 );/* memory between 16MiB and 4GiB */ if (x86ms->below_4g_mem_size >16 * MiB) { val = (x86ms->below_4g_mem_size -16 * MiB) / (64 * KiB);
@@ -87,13 +87,13 @@ static void microvm_set_rtc(MicrovmMachineState *mms, MC146818RtcState *s)if (val >65535 ) { val =65535 ; } -rtc_set_memory (s,0x34 , val); -rtc_set_memory (s,0x35 , val >>8 ); +mc146818rtc_set_cmos_data (s,0x34 , val); +mc146818rtc_set_cmos_data (s,0x35 , val >>8 );/* memory above 4GiB */ val = x86ms->above_4g_mem_size /65536 ; -rtc_set_memory (s,0x5b , val); -rtc_set_memory (s,0x5c , val >>8 ); -rtc_set_memory (s,0x5d , val >>16 ); +mc146818rtc_set_cmos_data (s,0x5b , val); +mc146818rtc_set_cmos_data (s,0x5c , val >>8 ); +mc146818rtc_set_cmos_data (s,0x5d , val >>16 ); }static void create_gpex (MicrovmMachineState *mms)
hw/i386/pc.c +29 -29
121 lines not on this page · raw message
hw/i386/x86.c +2 -2
@@ -161,9 +161,9 @@ void x86_rtc_set_cpus_count(ISADevice *s, uint16_t cpus_count)* BIOS must use "FW_CFG_NB_CPUS". Set RTC field to 0 just * to make old BIOSes fail more predictably. */ -rtc_set_memory (rtc,0x5f ,0 ); +mc146818rtc_set_cmos_data (rtc,0x5f ,0 ); }else { -rtc_set_memory (rtc,0x5f , cpus_count -1 ); +mc146818rtc_set_cmos_data (rtc,0x5f , cpus_count -1 ); } }
hw/ppc/prep.c +4 -4
@@ -215,10 +215,10 @@ static int prep_set_cmos_checksum(DeviceState *dev, void *opaque)if (object_dynamic_cast (OBJECT (dev),TYPE_MC146818_RTC )) {MC146818RtcState *rtc =MC146818_RTC (dev); -rtc_set_memory (rtc,0x2e , checksum &0xff ); -rtc_set_memory (rtc,0x3e , checksum &0xff ); -rtc_set_memory (rtc,0x2f , checksum >>8 ); -rtc_set_memory (rtc,0x3f , checksum >>8 ); +mc146818rtc_set_cmos_data (rtc,0x2e , checksum &0xff ); +mc146818rtc_set_cmos_data (rtc,0x3e , checksum &0xff ); +mc146818rtc_set_cmos_data (rtc,0x2f , checksum >>8 ); +mc146818rtc_set_cmos_data (rtc,0x3f , checksum >>8 );object_property_add_alias (qdev_get_machine (),"rtc-time" ,OBJECT (rtc),"date" );
hw/rtc/mc146818rtc.c +3 -3
@@ -739,13 +739,13 @@ static uint64_t cmos_ioport_read(void *opaque, hwaddr addr, } } -void rtc_set_memory (MC146818RtcState *s,int addr,int val) +void mc146818rtc_set_cmos_data (MC146818RtcState *s,int addr,int val) {if (addr >=0 && addr <=127 ) s->cmos_data[addr] = val; } -int rtc_get_memory (MC146818RtcState *s,int addr) +int mc146818rtc_get_cmos_data (MC146818RtcState *s,int addr) {assert (addr >=0 && addr <=127 );return s->cmos_data[addr];
@@ -856,7 +856,7 @@ static const VMStateDescription vmstate_rtc = {static void rtc_notify_suspend (Notifier *notifier,void *data) {MC146818RtcState *s =container_of (notifier, MC146818RtcState, suspend_notifier); -rtc_set_memory (s,0xF ,0xFE ); +mc146818rtc_set_cmos_data (s,0xF ,0xFE ); }static const MemoryRegionOps cmos_ops = {
include/hw/rtc/mc146818rtc.h +2 -2
@@ -53,8 +53,8 @@ struct MC146818RtcState {MC146818RtcState *mc146818_rtc_init (ISABus *bus,int base_year,qemu_irq intercept_irq); -void rtc_set_memory (MC146818RtcState *s,int addr,int val); -int rtc_get_memory (MC146818RtcState *s,int addr); +void mc146818rtc_set_cmos_data (MC146818RtcState *s,int addr,int val); +int mc146818rtc_get_cmos_data (MC146818RtcState *s,int addr);void qmp_rtc_reset_reinjection (Error **errp);#endif /* HW_RTC_MC146818RTC_H */
Signature · 1 line
2.38.1
Re: [PATCH 3/3] hw/rtc: Rename rtc_[get|set]_memory -> mc146818rtc_[get|set]_cmos_data
Quoted 14 lines · Philippe Mathieu-Daudé
rtc_get_memory()andrtc_set_memory()helpers only work withTYPE_MC146818_RTCdevices. 'memory' in their name refer to the CMOS region. Rename them asmc146818rtc_get_cmos_data()andmc146818rtc_set_cmos_data()to be explicit about what they are doing.Mechanical change doing:
$ sed -i -e 's/rtc_set_memory/mc146818rtc_set_cmos_data/g' \ $(git grep -wl rtc_set_memory) $ sed -i -e 's/rtc_get_memory/mc146818rtc_get_cmos_data/g' \ $(git grep -wl rtc_get_memory)Signed-off-by Philippe Mathieu-Daudé<[email protected]>
Quoted 8 lines
--- hw/i386/microvm.c | 22 +++++++------- hw/i386/pc.c | 58 ++++++++++++++++++------------------ hw/i386/x86.c | 4 +-- hw/ppc/prep.c | 8 ++--- hw/rtc/mc146818rtc.c | 6 ++-- include/hw/rtc/mc146818rtc.h | 4 +-- 6 files changed, 51 insertions(+), 51 deletions(-)
r~