diff mbox

[V9,10/20] pc: Remove reference to a global variable, RTCState *rtc_state.

Message ID 1260261219-16103-11-git-send-email-yamahata@valinux.co.jp
State New
Headers show

Commit Message

Isaku Yamahata Dec. 8, 2009, 8:33 a.m. UTC
Remove unnecessary reference to a global variable, RTCState *rtc_state,
by passing it as function argument.
Only the cmos_set_s3_resume_init() needs it global.
So introduce a registering function and use it.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Cc: Paolo Bonzini <bonzini@gnu.org>
---
 hw/pc.c |   25 ++++++++++++++++---------
 hw/pc.h |    1 +
 2 files changed, 17 insertions(+), 9 deletions(-)
diff mbox

Patch

diff --git a/hw/pc.c b/hw/pc.c
index dcf7eeb..ffe4b9c 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -64,8 +64,6 @@ 
 
 #define MAX_IDE_BUS 2
 
-static RTCState *rtc_state;
-
 typedef struct isa_irq_state {
     qemu_irq *i8259;
     qemu_irq *ioapic;
@@ -191,9 +189,9 @@  static int cmos_get_fd_drive_type(int fd0)
     return val;
 }
 
-static void cmos_init_hd(int type_ofs, int info_ofs, BlockDriverState *hd)
+static void cmos_init_hd(int type_ofs, int info_ofs, BlockDriverState *hd,
+                         RTCState *s)
 {
-    RTCState *s = rtc_state;
     int cylinders, heads, sectors;
     bdrv_get_geometry_hint(hd, &cylinders, &heads, &sectors);
     rtc_set_memory(s, type_ofs, 47);
@@ -256,9 +254,8 @@  static int pc_boot_set(void *opaque, const char *boot_device)
 /* hd_table must contain 4 block drivers */
 static void 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)
+                      fdctrl_t *floppy_controller, RTCState *s)
 {
-    RTCState *s = rtc_state;
     int nbds, bds[3] = { 0, };
     int val;
     int fd0, fd1, nb;
@@ -347,9 +344,9 @@  static void cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
 
     rtc_set_memory(s, 0x12, (hd_table[0] ? 0xf0 : 0) | (hd_table[1] ? 0x0f : 0));
     if (hd_table[0])
-        cmos_init_hd(0x19, 0x1b, hd_table[0]->bdrv);
+        cmos_init_hd(0x19, 0x1b, hd_table[0]->bdrv, s);
     if (hd_table[1])
-        cmos_init_hd(0x1a, 0x24, hd_table[1]->bdrv);
+        cmos_init_hd(0x1a, 0x24, hd_table[1]->bdrv, s);
 
     val = 0;
     for (i = 0; i < 4; i++) {
@@ -1006,6 +1003,7 @@  static void pc_init1(ram_addr_t ram_size,
     DriveInfo *fd[MAX_FD];
     void *fw_cfg;
     fdctrl_t *floppy_controller;
+    RTCState *rtc_state;
     PITState *pit;
 
     if (ram_size >= 0xe0000000 ) {
@@ -1154,6 +1152,7 @@  static void pc_init1(ram_addr_t ram_size,
     }
 
     rtc_state = rtc_init(2000);
+    cmos_set_s3_resume_init(rtc_state);
 
     qemu_register_boot_set(pc_boot_set, rtc_state);
 
@@ -1217,7 +1216,7 @@  static void pc_init1(ram_addr_t ram_size,
     floppy_controller = fdctrl_init_isa(fd);
 
     cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device, hd,
-              floppy_controller);
+              floppy_controller, rtc_state);
 
     if (pci_enabled && usb_enabled) {
         usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
@@ -1292,10 +1291,18 @@  static void pc_init_isa(ram_addr_t ram_size,
 
 /* 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)
+{
+    rtc_state = s;
+}
+
 void cmos_set_s3_resume(void)
 {
+#if defined(TARGET_I386)
     if (rtc_state)
         rtc_set_memory(rtc_state, 0xF, 0xFE);
+#endif
 }
 
 static QEMUMachine pc_machine = {
diff --git a/hw/pc.h b/hw/pc.h
index cbecc07..c937243 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -86,6 +86,7 @@  typedef struct RTCState RTCState;
 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);
+void cmos_set_s3_resume_init(RTCState *s);
 void cmos_set_s3_resume(void);
 
 /* pc.c */