Patchwork [V11,20/27] rtc: make rtc_xxx accept/return ISADevice instead of RTCState.

login
register
mail settings
Submitter Isaku Yamahata
Date Jan. 5, 2010, 6:27 a.m.
Message ID <1262672870-22607-21-git-send-email-yamahata@valinux.co.jp>
Download mbox | patch
Permalink /patch/42188/
State New
Headers show

Comments

Isaku Yamahata - Jan. 5, 2010, 6:27 a.m.
To match rtc_xxx with qdev, make rtc_xxx accept and return ISADevice
instead of RTCState.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 hw/mc146818rtc.c |   26 +++++++++++++++-----------
 hw/mc146818rtc.h |    8 ++++----
 hw/mips_jazz.c   |    1 +
 hw/mips_malta.c  |    3 ++-
 hw/mips_r4k.c    |    3 ++-
 hw/pc.c          |   11 ++++++-----
 hw/pc.h          |    5 ++---
 hw/pc_piix.c     |    2 +-
 hw/ppc_prep.c    |    1 +
 9 files changed, 34 insertions(+), 26 deletions(-)

Patch

diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index e4d55c7..1eb991c 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -27,6 +27,7 @@ 
 #include "pc.h"
 #include "isa.h"
 #include "hpet_emul.h"
+#include "mc146818rtc.h"
 
 //#define DEBUG_CMOS
 
@@ -64,7 +65,7 @@ 
 #define REG_C_PF   0x40
 #define REG_C_AF   0x20
 
-struct RTCState {
+typedef struct RTCState {
     ISADevice dev;
     uint8_t cmos_data[128];
     uint8_t cmos_index;
@@ -84,7 +85,7 @@  struct RTCState {
     QEMUTimer *coalesced_timer;
     QEMUTimer *second_timer;
     QEMUTimer *second_timer2;
-};
+} RTCState;
 
 static void rtc_irq_raise(qemu_irq irq)
 {
@@ -489,14 +490,16 @@  static uint32_t cmos_ioport_read(void *opaque, uint32_t addr)
     }
 }
 
-void rtc_set_memory(RTCState *s, int addr, int val)
+void rtc_set_memory(ISADevice *dev, int addr, int val)
 {
+    RTCState *s = DO_UPCAST(RTCState, dev, dev);
     if (addr >= 0 && addr <= 127)
         s->cmos_data[addr] = val;
 }
 
-void rtc_set_date(RTCState *s, const struct tm *tm)
+void rtc_set_date(ISADevice *dev, const struct tm *tm)
 {
+    RTCState *s = DO_UPCAST(RTCState, dev, dev);
     s->current_tm = *tm;
     rtc_copy_date(s);
 }
@@ -505,18 +508,19 @@  void rtc_set_date(RTCState *s, const struct tm *tm)
 #define REG_IBM_CENTURY_BYTE        0x32
 #define REG_IBM_PS2_CENTURY_BYTE    0x37
 
-static void rtc_set_date_from_host(RTCState *s)
+static void rtc_set_date_from_host(ISADevice *dev)
 {
+    RTCState *s = DO_UPCAST(RTCState, dev, dev);
     struct tm tm;
     int val;
 
     /* set the CMOS date */
     qemu_get_timedate(&tm, 0);
-    rtc_set_date(s, &tm);
+    rtc_set_date(dev, &tm);
 
     val = rtc_to_bcd(s, (tm.tm_year / 100) + 19);
-    rtc_set_memory(s, REG_IBM_CENTURY_BYTE, val);
-    rtc_set_memory(s, REG_IBM_PS2_CENTURY_BYTE, val);
+    rtc_set_memory(dev, REG_IBM_CENTURY_BYTE, val);
+    rtc_set_memory(dev, REG_IBM_PS2_CENTURY_BYTE, val);
 }
 
 static int rtc_post_load(void *opaque, int version_id)
@@ -588,7 +592,7 @@  static int rtc_initfn(ISADevice *dev)
     s->cmos_data[RTC_REG_C] = 0x00;
     s->cmos_data[RTC_REG_D] = 0x80;
 
-    rtc_set_date_from_host(s);
+    rtc_set_date_from_host(dev);
 
     s->periodic_timer = qemu_new_timer(rtc_clock, rtc_periodic_timer, s);
 #ifdef TARGET_I386
@@ -611,14 +615,14 @@  static int rtc_initfn(ISADevice *dev)
     return 0;
 }
 
-RTCState *rtc_init(int base_year)
+ISADevice *rtc_init(int base_year)
 {
     ISADevice *dev;
 
     dev = isa_create("mc146818rtc");
     qdev_prop_set_int32(&dev->qdev, "base_year", base_year);
     qdev_init_nofail(&dev->qdev);
-    return DO_UPCAST(RTCState, dev, dev);
+    return dev;
 }
 
 static ISADeviceInfo mc146818rtc_info = {
diff --git a/hw/mc146818rtc.h b/hw/mc146818rtc.h
index 7211dae..6f46a68 100644
--- a/hw/mc146818rtc.h
+++ b/hw/mc146818rtc.h
@@ -1,10 +1,10 @@ 
 #ifndef MC146818RTC_H
 #define MC146818RTC_H
 
-typedef struct RTCState RTCState;
+#include "isa.h"
 
-RTCState *rtc_init(int base_year);
-void rtc_set_memory(RTCState *s, int addr, int val);
-void rtc_set_date(RTCState *s, const struct tm *tm);
+ISADevice *rtc_init(int base_year);
+void rtc_set_memory(ISADevice *dev, int addr, int val);
+void rtc_set_date(ISADevice *dev, const struct tm *tm);
 
 #endif /* !MC146818RTC_H */
diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index 94ebd36..cd63fc9 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -34,6 +34,7 @@ 
 #include "esp.h"
 #include "mips-bios.h"
 #include "loader.h"
+#include "mc146818rtc.h"
 
 enum jazz_model_e
 {
diff --git a/hw/mips_malta.c b/hw/mips_malta.c
index a507bc7..8f33e74 100644
--- a/hw/mips_malta.c
+++ b/hw/mips_malta.c
@@ -43,6 +43,7 @@ 
 #include "ide.h"
 #include "loader.h"
 #include "elf.h"
+#include "mc146818rtc.h"
 
 //#define DEBUG_BOARD_INIT
 
@@ -779,7 +780,7 @@  void mips_malta_init (ram_addr_t ram_size,
     PCIBus *pci_bus;
     ISADevice *isa_dev;
     CPUState *env;
-    RTCState *rtc_state;
+    ISADevice *rtc_state;
     fdctrl_t *floppy_controller;
     MaltaFPGAState *malta_fpga;
     qemu_irq *i8259;
diff --git a/hw/mips_r4k.c b/hw/mips_r4k.c
index b69d7c3..104cf29 100644
--- a/hw/mips_r4k.c
+++ b/hw/mips_r4k.c
@@ -20,6 +20,7 @@ 
 #include "ide.h"
 #include "loader.h"
 #include "elf.h"
+#include "mc146818rtc.h"
 
 #define PHYS_TO_VIRT(x) ((x) | ~(target_ulong)0x7fffffff)
 
@@ -167,7 +168,7 @@  void mips_r4k_init (ram_addr_t ram_size,
     int bios_size;
     CPUState *env;
     ResetData *reset_info;
-    RTCState *rtc_state;
+    ISADevice *rtc_state;
     int i;
     qemu_irq *i8259;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
diff --git a/hw/pc.c b/hw/pc.c
index 12afaf2..bf8d272 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -44,6 +44,7 @@ 
 #include "ide.h"
 #include "loader.h"
 #include "elf.h"
+#include "mc146818rtc.h"
 
 /* output Bochs bios info messages */
 //#define DEBUG_BIOS
@@ -189,7 +190,7 @@  static int cmos_get_fd_drive_type(int fd0)
 }
 
 static void cmos_init_hd(int type_ofs, int info_ofs, BlockDriverState *hd,
-                         RTCState *s)
+                         ISADevice *s)
 {
     int cylinders, heads, sectors;
     bdrv_get_geometry_hint(hd, &cylinders, &heads, &sectors);
@@ -228,7 +229,7 @@  static int pc_boot_set(void *opaque, const char *boot_device)
 {
     Monitor *mon = cur_mon;
 #define PC_MAX_BOOT_DEVICES 3
-    RTCState *s = (RTCState *)opaque;
+    ISADevice *s = opaque;
     int nbds, bds[3] = { 0, };
     int i;
 
@@ -253,7 +254,7 @@  static int pc_boot_set(void *opaque, const char *boot_device)
 /* hd_table must contain 4 block drivers */
 void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
                   const char *boot_device, DriveInfo **hd_table,
-                  fdctrl_t *floppy_controller, RTCState *s)
+                  fdctrl_t *floppy_controller, ISADevice *s)
 {
     int nbds, bds[3] = { 0, };
     int val;
@@ -1134,7 +1135,7 @@  void pc_vga_init(PCIBus *pci_bus)
 void pc_basic_device_init(qemu_irq *isa_irq,
                           ISADevice **isa_dev,
                           fdctrl_t **floppy_controller,
-                          RTCState **rtc_state)
+                          ISADevice **rtc_state)
 {
     int i;
     DriveInfo *fd[MAX_FD];
@@ -1200,6 +1201,6 @@  void pc_pci_device_init(PCIBus *pci_bus)
    BIOS will read it and start S3 resume at POST Entry */
 void cmos_set_s3_resume_fn(void *opaque, int n, int level)
 {
-    RTCState *rtc_state = opaque;
+    ISADevice *rtc_state = opaque;
     rtc_set_memory(rtc_state, 0xF, 0xFE);
 }
diff --git a/hw/pc.h b/hw/pc.h
index b748615..2088cfd 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -3,7 +3,6 @@ 
 
 #include "qemu-common.h"
 #include "isa.h"
-#include "mc146818rtc.h"
 
 /* PC-style peripherals (also used by other machines).  */
 
@@ -110,14 +109,14 @@  struct fdctrl_t;
 void pc_basic_device_init(qemu_irq *isa_irq,
                           ISADevice **isa_dev,
                           struct fdctrl_t **floppy_controller,
-                          RTCState **rtc_state);
+                          ISADevice **rtc_state);
 void pc_init_ne2k_isa(NICInfo *nd);
 #ifdef HAS_AUDIO
 void pc_audio_init (PCIBus *pci_bus, qemu_irq *pic);
 #endif
 void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
                   const char *boot_device, DriveInfo **hd_table,
-                  struct fdctrl_t *floppy_controller, RTCState *s);
+                  struct fdctrl_t *floppy_controller, ISADevice *s);
 void pc_pci_device_init(PCIBus *pci_bus);
 
 void ioport_set_a20(int enable);
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index 69ba02b..682b64c 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -69,7 +69,7 @@  static void pc_init1(ram_addr_t ram_size,
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
     void *fw_cfg;
     fdctrl_t *floppy_controller;
-    RTCState *rtc_state;
+    ISADevice *rtc_state;
 
     pc_cpus_init(cpu_model);
 
diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c
index eb758f2..cf0db83 100644
--- a/hw/ppc_prep.c
+++ b/hw/ppc_prep.c
@@ -36,6 +36,7 @@ 
 #include "qemu-log.h"
 #include "ide.h"
 #include "loader.h"
+#include "mc146818rtc.h"
 
 //#define HARD_DEBUG_PPC_IO
 //#define DEBUG_PPC_IO