qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH V9 20/20] rtc: make rtc_xxx accept/return ISADevice


From: Isaku Yamahata
Subject: [Qemu-devel] [PATCH V9 20/20] rtc: make rtc_xxx accept/return ISADevice instead of RTCState.
Date: Tue, 8 Dec 2009 17:33:39 +0900

To match rtc_xxx with qdev, make rtc_xxx accept and return ISADevice
instead of RTCState.

Signed-off-by: Isaku Yamahata <address@hidden>
---
 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          |   13 +++++++------
 hw/pc.h          |    7 +++----
 hw/pc_piix.c     |    2 +-
 hw/ppc_prep.c    |    1 +
 9 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index b8c7b0c..a9811a8 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
 
@@ -62,7 +63,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;
@@ -81,7 +82,7 @@ struct RTCState {
     QEMUTimer *coalesced_timer;
     QEMUTimer *second_timer;
     QEMUTimer *second_timer2;
-};
+} RTCState;
 
 static void rtc_irq_raise(qemu_irq irq)
 {
@@ -472,14 +473,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);
 }
@@ -488,18 +491,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)
@@ -571,7 +575,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
@@ -594,14 +598,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 571d8ce..7cff0c0 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 8290939..6f25ba8 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;
@@ -1123,7 +1124,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];
@@ -1188,8 +1189,8 @@ void pc_pci_device_init(PCIBus *pci_bus)
 
 /* set CMOS shutdown status register (index 0xF) as S3_resume(0xFE)
    BIOS will read it and start S3 resume at POST Entry */
-static RTCState *rtc_state;
-void cmos_set_s3_resume_init(RTCState *s)
+static ISADevice *rtc_state; /* RTCState device */
+void cmos_set_s3_resume_init(ISADevice *s)
 {
     rtc_state = s;
 }
diff --git a/hw/pc.h b/hw/pc.h
index 50fec4f..be5230e 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).  */
 
@@ -90,7 +89,7 @@ void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
                    target_phys_addr_t mask);
 
 /* pc.c */
-void cmos_set_s3_resume_init(RTCState *s);
+void cmos_set_s3_resume_init(ISADevice *s);
 void cmos_set_s3_resume(void);
 
 extern int fd_bootchk;
@@ -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 fcf8aaf..2f776f8 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -67,7 +67,7 @@ static void pc_init1(ram_addr_t ram_size,
     IsaIrqState *isa_irq_state;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
     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
-- 
1.6.5.4





reply via email to

[Prev in Thread] Current Thread [Next in Thread]