1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include "apm.h"
21#include "hw.h"
22
23
24
25#ifdef DEBUG
26# define APM_DPRINTF(format, ...) printf(format, ## __VA_ARGS__)
27#else
28# define APM_DPRINTF(format, ...) do { } while (0)
29#endif
30
31
32#define APM_CNT_IOPORT 0xb2
33#define APM_STS_IOPORT 0xb3
34
35static void apm_ioport_writeb(void *opaque, uint32_t addr, uint32_t val)
36{
37 APMState *apm = opaque;
38 addr &= 1;
39 APM_DPRINTF("apm_ioport_writeb addr=0x%x val=0x%02x\n", addr, val);
40 if (addr == 0) {
41 apm->apmc = val;
42
43 if (apm->callback) {
44 (apm->callback)(val, apm->arg);
45 }
46 } else {
47 apm->apms = val;
48 }
49}
50
51static uint32_t apm_ioport_readb(void *opaque, uint32_t addr)
52{
53 APMState *apm = opaque;
54 uint32_t val;
55
56 addr &= 1;
57 if (addr == 0) {
58 val = apm->apmc;
59 } else {
60 val = apm->apms;
61 }
62 APM_DPRINTF("apm_ioport_readb addr=0x%x val=0x%02x\n", addr, val);
63 return val;
64}
65
66const VMStateDescription vmstate_apm = {
67 .name = "APM State",
68 .version_id = 1,
69 .minimum_version_id = 1,
70 .minimum_version_id_old = 1,
71 .fields = (VMStateField[]) {
72 VMSTATE_UINT8(apmc, APMState),
73 VMSTATE_UINT8(apms, APMState),
74 VMSTATE_END_OF_LIST()
75 }
76};
77
78void apm_init(APMState *apm, apm_ctrl_changed_t callback, void *arg)
79{
80 apm->callback = callback;
81 apm->arg = arg;
82
83
84 register_ioport_write(APM_CNT_IOPORT, 2, 1, apm_ioport_writeb, apm);
85 register_ioport_read(APM_CNT_IOPORT, 2, 1, apm_ioport_readb, apm);
86}
87