]> git.proxmox.com Git - qemu.git/blob - hw/apm.c
prepare for future GPLv2+ relicensing
[qemu.git] / hw / apm.c
1 /*
2 * QEMU PC APM controller Emulation
3 * This is split out from acpi.c
4 *
5 * Copyright (c) 2006 Fabrice Bellard
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License version 2 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>
18 *
19 * Contributions after 2012-01-13 are licensed under the terms of the
20 * GNU GPL, version 2 or (at your option) any later version.
21 */
22
23 #include "apm.h"
24 #include "hw.h"
25
26 //#define DEBUG
27
28 #ifdef DEBUG
29 # define APM_DPRINTF(format, ...) printf(format, ## __VA_ARGS__)
30 #else
31 # define APM_DPRINTF(format, ...) do { } while (0)
32 #endif
33
34 /* fixed I/O location */
35 #define APM_CNT_IOPORT 0xb2
36 #define APM_STS_IOPORT 0xb3
37
38 static void apm_ioport_writeb(void *opaque, uint32_t addr, uint32_t val)
39 {
40 APMState *apm = opaque;
41 addr &= 1;
42 APM_DPRINTF("apm_ioport_writeb addr=0x%x val=0x%02x\n", addr, val);
43 if (addr == 0) {
44 apm->apmc = val;
45
46 if (apm->callback) {
47 (apm->callback)(val, apm->arg);
48 }
49 } else {
50 apm->apms = val;
51 }
52 }
53
54 static uint32_t apm_ioport_readb(void *opaque, uint32_t addr)
55 {
56 APMState *apm = opaque;
57 uint32_t val;
58
59 addr &= 1;
60 if (addr == 0) {
61 val = apm->apmc;
62 } else {
63 val = apm->apms;
64 }
65 APM_DPRINTF("apm_ioport_readb addr=0x%x val=0x%02x\n", addr, val);
66 return val;
67 }
68
69 const VMStateDescription vmstate_apm = {
70 .name = "APM State",
71 .version_id = 1,
72 .minimum_version_id = 1,
73 .minimum_version_id_old = 1,
74 .fields = (VMStateField[]) {
75 VMSTATE_UINT8(apmc, APMState),
76 VMSTATE_UINT8(apms, APMState),
77 VMSTATE_END_OF_LIST()
78 }
79 };
80
81 void apm_init(APMState *apm, apm_ctrl_changed_t callback, void *arg)
82 {
83 apm->callback = callback;
84 apm->arg = arg;
85
86 /* ioport 0xb2, 0xb3 */
87 register_ioport_write(APM_CNT_IOPORT, 2, 1, apm_ioport_writeb, apm);
88 register_ioport_read(APM_CNT_IOPORT, 2, 1, apm_ioport_readb, apm);
89 }