[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 02/17] acpi.c: split out apm register emulation.
From: |
Isaku Yamahata |
Subject: |
[Qemu-devel] [PATCH 02/17] acpi.c: split out apm register emulation. |
Date: |
Tue, 7 Jul 2009 15:35:45 +0900 |
Split out apm register emulation for acpi.c into pc_apm.c.
The apm emulation will be used later.
Signed-off-by: Isaku Yamahata <address@hidden>
---
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 28e2edb..3d09eeb 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -567,7 +567,7 @@ obj-y += fdc.o mc146818rtc.o serial.o i8259.o i8254.o
pcspk.o pc.o
obj-y += cirrus_vga.o apic.o ioapic.o parallel.o acpi.o piix_pci.o
obj-y += usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
obj-y += device-hotplug.o pci-hotplug.o smbios.o
-obj-y += pc_smbus.o
+obj-y += pc_smbus.o pc_apm.o
CPPFLAGS += -DHAS_AUDIO -DHAS_AUDIO_CHOICE
endif
ifeq ($(TARGET_BASE_ARCH), ppc)
@@ -600,7 +600,7 @@ obj-y += mips_timer.o mips_int.o dma.o vga.o serial.o
i8254.o i8259.o rc4030.o
obj-y += g364fb.o jazz_led.o dp8393x.o
obj-y += ide.o gt64xxx.o pckbd.o fdc.o mc146818rtc.o usb-uhci.o acpi.o
ds1225y.o
obj-y += piix_pci.o parallel.o cirrus_vga.o pcspk.o $(sound-obj-y)
-obj-y += pc_smbus.o
+obj-y += pc_smbus.o pc_apm.o
obj-y += mipsnet.o
obj-y += pflash_cfi01.o
obj-y += vmware_vga.o
diff --git a/hw/acpi.c b/hw/acpi.c
index 8e58c67..7351947 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -18,6 +18,7 @@
*/
#include "hw.h"
#include "pc.h"
+#include "pc_apm.h"
#include "pc_smbus.h"
#include "pci.h"
#include "qemu-timer.h"
@@ -38,8 +39,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;
@@ -217,46 +219,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)
@@ -302,8 +278,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);
}
@@ -323,8 +298,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);
@@ -372,8 +346,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
- [Qemu-devel] [PATCH 00/17] split out piix specific part from pc emulator. v3, Isaku Yamahata, 2009/07/07
- [Qemu-devel] [PATCH 01/17] acpi.c: split out pc smbus routines from acpi.c into pc_smbus.c, Isaku Yamahata, 2009/07/07
- [Qemu-devel] [PATCH 04/17] acpi: add acpi constants from linux header files and use them., Isaku Yamahata, 2009/07/07
- [Qemu-devel] [PATCH 17/17] pc.c: split out piix specific part from pc.c into pc_piix.c, Isaku Yamahata, 2009/07/07
- [Qemu-devel] [PATCH 07/17] pc.c: remove unnecessary global variables, pit and ioapic.., Isaku Yamahata, 2009/07/07
- [Qemu-devel] [PATCH 02/17] acpi.c: split out apm register emulation.,
Isaku Yamahata <=
- [Qemu-devel] [PATCH 11/17] pc.c: make pc_init1() not refer ferr_irq directly., Isaku Yamahata, 2009/07/07
- [Qemu-devel] [PATCH 03/17] acpi.c: make qemu_system_powerdown() piix independent., Isaku Yamahata, 2009/07/07
- [Qemu-devel] [PATCH 13/17] pc.c: split out memory allocation from pc_init1() into pc_memory_init(), Isaku Yamahata, 2009/07/07
- [Qemu-devel] [PATCH 09/17] pc.c: remove a global variable, RTCState *rtc_state., Isaku Yamahata, 2009/07/07
- [Qemu-devel] [PATCH 14/17] pc.c: split out vga initialization from pc_init1() into pc_vga_init()., Isaku Yamahata, 2009/07/07
- [Qemu-devel] [PATCH 06/17] pc.c: Make smm enable/disable function i440fx independent., Isaku Yamahata, 2009/07/07
- [Qemu-devel] [PATCH 05/17] acpi.c: split acpi.c into the common part and the piix4 part., Isaku Yamahata, 2009/07/07
- [Qemu-devel] [PATCH 08/17] pc.c: remove a global variable, floppy_controller., Isaku Yamahata, 2009/07/07
- [Qemu-devel] [PATCH 12/17] pc.c: split out cpu initialization from pc_init1() into pc_cpus_init()., Isaku Yamahata, 2009/07/07