]> git.proxmox.com Git - mirror_qemu.git/blob - hw/apm.c
apm: remove #ifdef DEBUG.
[mirror_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
20 #include "apm.h"
21 #include "hw.h"
22 #include "isa.h"
23
24 //#define DEBUG
25
26 #ifdef DEBUG
27 # define APM_DPRINTF(format, ...) printf(format, ## __VA_ARGS__)
28 #else
29 # define APM_DPRINTF(format, ...) do { } while (0)
30 #endif
31
32 /* fixed I/O location */
33 #define APM_CNT_IOPORT 0xb2
34 #define APM_STS_IOPORT 0xb3
35
36 static void apm_ioport_writeb(void *opaque, uint32_t addr, uint32_t val)
37 {
38 APMState *apm = opaque;
39 addr &= 1;
40 APM_DPRINTF("apm_ioport_writeb addr=0x%x val=0x%02x\n", addr, val);
41 if (addr == 0) {
42 apm->apmc = val;
43
44 if (apm->callback) {
45 (apm->callback)(val, apm->arg);
46 }
47 } else {
48 apm->apms = val;
49 }
50 }
51
52 static uint32_t apm_ioport_readb(void *opaque, uint32_t addr)
53 {
54 APMState *apm = opaque;
55 uint32_t val;
56
57 addr &= 1;
58 if (addr == 0) {
59 val = apm->apmc;
60 } else {
61 val = apm->apms;
62 }
63 APM_DPRINTF("apm_ioport_readb addr=0x%x val=0x%02x\n", addr, val);
64 return val;
65 }
66
67 const VMStateDescription vmstate_apm = {
68 .name = "APM State",
69 .version_id = 1,
70 .minimum_version_id = 1,
71 .minimum_version_id_old = 1,
72 .fields = (VMStateField[]) {
73 VMSTATE_UINT8(apmc, APMState),
74 VMSTATE_UINT8(apms, APMState),
75 VMSTATE_END_OF_LIST()
76 }
77 };
78
79 void apm_init(APMState *apm, apm_ctrl_changed_t callback, void *arg)
80 {
81 apm->callback = callback;
82 apm->arg = arg;
83
84 /* ioport 0xb2, 0xb3 */
85 register_ioport_write(APM_CNT_IOPORT, 2, 1, apm_ioport_writeb, apm);
86 register_ioport_read(APM_CNT_IOPORT, 2, 1, apm_ioport_readb, apm);
87 }