diff options
author | Isaku Yamahata <yamahata@valinux.co.jp> | 2010-05-14 16:29:00 +0900 |
---|---|---|
committer | Blue Swirl <blauwirbel@gmail.com> | 2010-05-15 15:27:19 +0000 |
commit | 04762841d8803429fd9bf71eff481d3c5915fa3e (patch) | |
tree | cc0ca1c2fe8454d2633b8b1f0fd15aad850a1a62 /hw/apm.c | |
parent | fc0bdd995ca36a34cc576ee706df239dd5ff79a9 (diff) | |
download | hqemu-04762841d8803429fd9bf71eff481d3c5915fa3e.zip hqemu-04762841d8803429fd9bf71eff481d3c5915fa3e.tar.gz |
acpi: split out apm register emulation from acpi.c
Split out apm register emulation for acpi.c into apm.c.
The apm emulation will be used later.
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Cc: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Diffstat (limited to 'hw/apm.c')
-rw-r--r-- | hw/apm.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/hw/apm.c b/hw/apm.c new file mode 100644 index 0000000..d20db3d --- /dev/null +++ b/hw/apm.c @@ -0,0 +1,85 @@ +/* + * QEMU PC APM controller Emulation + * This is split out from acpi.c + * + * Copyright (c) 2006 Fabrice Bellard + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * 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, see <http://www.gnu.org/licenses/> + */ + +#include "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_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; +} + +const VMStateDescription vmstate_apm = { + .name = "APM State", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT8(apmc, APMState), + VMSTATE_UINT8(apms, APMState), + VMSTATE_END_OF_LIST() + } +}; + +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); +} |