qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Isaku Yamahata <yamahata@valinux.co.jp>
To: qemu-devel@nongnu.org, anthony@codemonkey.ws
Cc: yamahata@valinux.co.jp
Subject: [Qemu-devel] [PATCH 02/17] acpi.c: split out apm register emulation.
Date: Fri, 17 Jul 2009 16:22:50 +0900	[thread overview]
Message-ID: <1247815385-23779-3-git-send-email-yamahata@valinux.co.jp> (raw)
In-Reply-To: <1247815385-23779-1-git-send-email-yamahata@valinux.co.jp>

Split out apm register emulation for acpi.c into pc_apm.c.
The apm emulation will be used later.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 Makefile.target |    4 +-
 hw/acpi.c       |   60 ++++++++++-------------------------
 hw/pc_apm.c     |   92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/pc_apm.h     |   39 +++++++++++++++++++++++
 4 files changed, 150 insertions(+), 45 deletions(-)
 create mode 100644 hw/pc_apm.c
 create mode 100644 hw/pc_apm.h

diff --git a/Makefile.target b/Makefile.target
index 6fdebe5..2b7c27e 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -493,7 +493,7 @@ obj-i386-y += fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
 obj-i386-y += cirrus_vga.o apic.o ioapic.o parallel.o acpi.o piix_pci.o
 obj-i386-y += usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
 obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o
-obj-i386-y += pc_smbus.o
+obj-i386-y += pc_smbus.o pc_apm.o
 
 ifeq ($(TARGET_BASE_ARCH), i386)
 CPPFLAGS += -DHAS_AUDIO -DHAS_AUDIO_CHOICE
@@ -531,7 +531,7 @@ obj-mips-y += mips_timer.o mips_int.o dma.o vga.o serial.o i8254.o i8259.o rc403
 obj-mips-y += g364fb.o jazz_led.o dp8393x.o
 obj-mips-y += ide.o gt64xxx.o pckbd.o fdc.o mc146818rtc.o usb-uhci.o acpi.o ds1225y.o
 obj-mips-y += piix_pci.o parallel.o cirrus_vga.o pcspk.o $(sound-obj-y)
-obj-mips-y += pc_smbus.o
+obj-mips-y += pc_smbus.o pc_apm.o
 obj-mips-y += mipsnet.o
 obj-mips-y += pflash_cfi01.o
 obj-mips-y += vmware_vga.o
diff --git a/hw/acpi.c b/hw/acpi.c
index d036fd2..751d0db 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -17,6 +17,7 @@
  */
 #include "hw.h"
 #include "pc.h"
+#include "pc_apm.h"
 #include "pc_smbus.h"
 #include "pci.h"
 #include "qemu-timer.h"
@@ -37,8 +38,9 @@ typedef struct PIIX4PMState {
     uint16_t pmsts;
     uint16_t pmen;
     uint16_t pmcntrl;
-    uint8_t apmc;
-    uint8_t apms;
+
+    APMState apm;
+
     QEMUTimer *tmr_timer;
     int64_t tmr_overflow_time;
 
@@ -216,46 +218,20 @@ static uint32_t pm_ioport_readl(void *opaque, uint32_t addr)
     return val;
 }
 
-static void pm_smi_writeb(void *opaque, uint32_t addr, uint32_t val)
+static void apm_ctrl_changed(uint32_t val, void *arg)
 {
-    PIIX4PMState *s = opaque;
-    addr &= 1;
-#ifdef DEBUG
-    printf("pm_smi_writeb addr=0x%x val=0x%02x\n", addr, val);
-#endif
-    if (addr == 0) {
-        s->apmc = val;
-
-        /* ACPI specs 3.0, 4.7.2.5 */
-        if (val == ACPI_ENABLE) {
-            s->pmcntrl |= SCI_EN;
-        } else if (val == ACPI_DISABLE) {
-            s->pmcntrl &= ~SCI_EN;
-        }
+    PIIX4PMState *s = arg;
 
-        if (s->dev.config[0x5b] & (1 << 1)) {
-            cpu_interrupt(first_cpu, CPU_INTERRUPT_SMI);
-        }
-    } else {
-        s->apms = val;
+    /* ACPI specs 3.0, 4.7.2.5 */
+    if (val == ACPI_ENABLE) {
+        s->pmcntrl |= SCI_EN;
+    } else if (val == ACPI_DISABLE) {
+        s->pmcntrl &= ~SCI_EN;
     }
-}
 
-static uint32_t pm_smi_readb(void *opaque, uint32_t addr)
-{
-    PIIX4PMState *s = opaque;
-    uint32_t val;
-
-    addr &= 1;
-    if (addr == 0) {
-        val = s->apmc;
-    } else {
-        val = s->apms;
+    if (s->dev.config[0x5b] & (1 << 1)) {
+        cpu_interrupt(first_cpu, CPU_INTERRUPT_SMI);
     }
-#ifdef DEBUG
-    printf("pm_smi_readb addr=0x%x val=0x%02x\n", addr, val);
-#endif
-    return val;
 }
 
 static void acpi_dbg_writel(void *opaque, uint32_t addr, uint32_t val)
@@ -301,8 +277,7 @@ static void pm_save(QEMUFile* f,void *opaque)
     qemu_put_be16s(f, &s->pmsts);
     qemu_put_be16s(f, &s->pmen);
     qemu_put_be16s(f, &s->pmcntrl);
-    qemu_put_8s(f, &s->apmc);
-    qemu_put_8s(f, &s->apms);
+    apm_save(f, &s->apm);
     qemu_put_timer(f, s->tmr_timer);
     qemu_put_be64(f, s->tmr_overflow_time);
 }
@@ -322,8 +297,7 @@ static int pm_load(QEMUFile* f,void* opaque,int version_id)
     qemu_get_be16s(f, &s->pmsts);
     qemu_get_be16s(f, &s->pmen);
     qemu_get_be16s(f, &s->pmcntrl);
-    qemu_get_8s(f, &s->apmc);
-    qemu_get_8s(f, &s->apms);
+    apm_load(f, &s->apm);
     qemu_get_timer(f, s->tmr_timer);
     s->tmr_overflow_time=qemu_get_be64(f);
 
@@ -371,8 +345,8 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
 
     pci_conf[0x40] = 0x01; /* PM io base read only bit */
 
-    register_ioport_write(0xb2, 2, 1, pm_smi_writeb, s);
-    register_ioport_read(0xb2, 2, 1, pm_smi_readb, s);
+    /* APM */
+    apm_init(&s->apm, apm_ctrl_changed, s);
 
     register_ioport_write(ACPI_DBG_IO_ADDR, 4, 4, acpi_dbg_writel, s);
 
diff --git a/hw/pc_apm.c b/hw/pc_apm.c
new file mode 100644
index 0000000..dac43fb
--- /dev/null
+++ b/hw/pc_apm.c
@@ -0,0 +1,92 @@
+/*
+ * QEMU PC APM controller Emulation
+ *
+ *  Copyright (c) 2009 Isaku Yamahata <yamahata at valinux co jp>
+ *                     VA Linux Systems Japan K.K.
+ *
+ * This is split out from acpi.c
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  02110-1301 USA
+ */
+
+#include "pc_apm.h"
+#include "hw.h"
+#include "isa.h"
+
+//#define DEBUG
+
+/* fixed I/O location */
+#define APM_CNT_IOPORT  0xb2
+#define APM_STS_IOPORT  0xb3
+
+static void *apm_arg;
+static apm_ctrl_changed_t apm_callback;
+
+static void apm_ioport_writeb(void *opaque, uint32_t addr, uint32_t val)
+{
+    APMState *apm = opaque;
+    addr &= 1;
+#ifdef DEBUG
+    printf("apm_ioport_writeb addr=0x%x val=0x%02x\n", addr, val);
+#endif
+    if (addr == 0) {
+        apm->apmc = val;
+
+        if (apm_callback) {
+            apm_callback(val, apm_arg);
+        }
+    } else {
+        apm->apms = val;
+    }
+}
+
+static uint32_t apm_ioport_readb(void *opaque, uint32_t addr)
+{
+    APMState *apm = opaque;
+    uint32_t val;
+
+    addr &= 1;
+    if (addr == 0) {
+        val = apm->apmc;
+    } else {
+        val = apm->apms;
+    }
+#ifdef DEBUG
+    printf("apm_ioport_readb addr=0x%x val=0x%02x\n", addr, val);
+#endif
+    return val;
+}
+
+void apm_save(QEMUFile *f, APMState *apm)
+{
+    qemu_put_8s(f, &apm->apmc);
+    qemu_put_8s(f, &apm->apms);
+}
+
+void apm_load(QEMUFile *f, APMState *apm)
+{
+    qemu_get_8s(f, &apm->apmc);
+    qemu_get_8s(f, &apm->apms);
+}
+
+void apm_init(APMState *apm, apm_ctrl_changed_t callback, void *arg)
+{
+    apm_callback = callback;
+    apm_arg = arg;
+
+    /* ioport 0xb2, 0xb3 */
+    register_ioport_write(APM_CNT_IOPORT, 2, 1, apm_ioport_writeb, apm);
+    register_ioport_read(APM_CNT_IOPORT, 2, 1, apm_ioport_readb, apm);
+}
diff --git a/hw/pc_apm.h b/hw/pc_apm.h
new file mode 100644
index 0000000..9f4120c
--- /dev/null
+++ b/hw/pc_apm.h
@@ -0,0 +1,39 @@
+/*
+ * QEMU PC APM controller Emulation
+ *
+ *  Copyright (c) 2009 Isaku Yamahata <yamahata at valinux co jp>
+ *                     VA Linux Systems Japan K.K.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  02110-1301 USA
+ */
+
+#ifndef PC_APM_H
+#define PC_APM_H
+
+#include <stdint.h>
+#include "qemu-common.h"
+
+typedef struct APMState {
+    uint8_t apmc;
+    uint8_t apms;
+} APMState;
+
+typedef void (*apm_ctrl_changed_t)(uint32_t val, void *arg);
+void apm_init(APMState *s, apm_ctrl_changed_t callback, void *arg);
+
+void apm_save(QEMUFile *f, APMState *apm);
+void apm_load(QEMUFile *f, APMState *apm);
+
+#endif /* PC_APM_H */
-- 
1.6.0.2

  parent reply	other threads:[~2009-07-17  7:25 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-17  7:22 [Qemu-devel] [PATCH 00/17] split out piix specific part from pc emulator. V6 Isaku Yamahata
2009-07-17  7:22 ` [Qemu-devel] [PATCH 01/17] acpi.c: split out pc smbus routines from acpi.c into pc_smbus.c Isaku Yamahata
2009-07-17  7:22 ` Isaku Yamahata [this message]
2009-07-17  7:22 ` [Qemu-devel] [PATCH 03/17] acpi.c: make qemu_system_powerdown() piix independent Isaku Yamahata
2009-07-17  7:22 ` [Qemu-devel] [PATCH 04/17] acpi: add acpi constants from linux header files and use them Isaku Yamahata
2009-07-17  7:22 ` [Qemu-devel] [PATCH 05/17] acpi.c: split acpi.c into the common part and the piix4 part Isaku Yamahata
2009-07-17  7:22 ` [Qemu-devel] [PATCH 06/17] pc.c: Make smm enable/disable function i440fx independent Isaku Yamahata
2009-07-17  7:22 ` [Qemu-devel] [PATCH 07/17] pc.c: remove unnecessary global variables, pit and ioapic Isaku Yamahata
2009-07-17  7:22 ` [Qemu-devel] [PATCH 08/17] pc.c: remove a global variable, floppy_controller Isaku Yamahata
2009-07-17  7:22 ` [Qemu-devel] [PATCH 09/17] pc.c: remove a global variable, RTCState *rtc_state Isaku Yamahata
2009-07-17  7:22 ` [Qemu-devel] [PATCH 10/17] pc.c: introduce a function to allocate cpu irq Isaku Yamahata
2009-07-17  7:22 ` [Qemu-devel] [PATCH 11/17] pc.c: make pc_init1() not refer ferr_irq directly Isaku Yamahata
2009-07-17  7:23 ` [Qemu-devel] [PATCH 12/17] pc.c: split out cpu initialization from pc_init1() into pc_cpus_init() Isaku Yamahata
2009-07-17  7:23 ` [Qemu-devel] [PATCH 13/17] pc.c: split out memory allocation from pc_init1() into pc_memory_init() Isaku Yamahata
2009-07-17  7:23 ` [Qemu-devel] [PATCH 14/17] pc.c: split out vga initialization from pc_init1() into pc_vga_init() Isaku Yamahata
2009-07-17  7:23 ` [Qemu-devel] [PATCH 15/17] pc.c: split out basic device init from pc_init1() into pc_basic_device_init() Isaku Yamahata
2009-07-17  7:23 ` [Qemu-devel] [PATCH 16/17] pc.c: split out pci device init from pc_init1() into pc_pci_device_init() Isaku Yamahata
2009-07-17  7:23 ` [Qemu-devel] [PATCH 17/17] pc.c: split out piix specific part from pc.c into pc_piix.c Isaku Yamahata
  -- strict thread matches above, loose matches on Subject: below --
2009-07-15  7:19 [Qemu-devel] [PATCH 00/17] split out piix specific part from pc emulator. v5 Isaku Yamahata
2009-07-15  7:19 ` [Qemu-devel] [PATCH 02/17] acpi.c: split out apm register emulation Isaku Yamahata
2009-07-09  8:13 [Qemu-devel] [PATCH 00/17] split out piix specific part from pc emulator. v3 Isaku Yamahata
2009-07-09  8:13 ` [Qemu-devel] [PATCH 02/17] acpi.c: split out apm register emulation Isaku Yamahata
2009-07-07  6:35 [Qemu-devel] [PATCH 00/17] split out piix specific part from pc emulator. v3 Isaku Yamahata
2009-07-07  6:35 ` [Qemu-devel] [PATCH 02/17] acpi.c: split out apm register emulation Isaku Yamahata
2009-07-03  7:11 [Qemu-devel] [PATCH 00/17] split out piix specific part from pc emulator. v2 Isaku Yamahata
2009-07-03  7:11 ` [Qemu-devel] [PATCH 02/17] acpi.c: split out apm register emulation Isaku Yamahata

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1247815385-23779-3-git-send-email-yamahata@valinux.co.jp \
    --to=yamahata@valinux.co.jp \
    --cc=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).