Statistics
| Branch: | Revision:

root / hw / apm.c @ 3871481c

History | View | Annotate | Download (2.4 kB)

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