Statistics
| Branch: | Revision:

root / hw / apm.c @ 04762841

History | View | Annotate | Download (2.1 kB)

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
/* fixed I/O location */
27
#define APM_CNT_IOPORT  0xb2
28
#define APM_STS_IOPORT  0xb3
29

    
30
static void apm_ioport_writeb(void *opaque, uint32_t addr, uint32_t val)
31
{
32
    APMState *apm = opaque;
33
    addr &= 1;
34
#ifdef DEBUG
35
    printf("apm_ioport_writeb addr=0x%x val=0x%02x\n", addr, val);
36
#endif
37
    if (addr == 0) {
38
        apm->apmc = val;
39

    
40
        if (apm->callback) {
41
            (apm->callback)(val, apm->arg);
42
        }
43
    } else {
44
        apm->apms = val;
45
    }
46
}
47

    
48
static uint32_t apm_ioport_readb(void *opaque, uint32_t addr)
49
{
50
    APMState *apm = opaque;
51
    uint32_t val;
52

    
53
    addr &= 1;
54
    if (addr == 0) {
55
        val = apm->apmc;
56
    } else {
57
        val = apm->apms;
58
    }
59
#ifdef DEBUG
60
    printf("apm_ioport_readb addr=0x%x val=0x%02x\n", addr, val);
61
#endif
62
    return val;
63
}
64

    
65
const VMStateDescription vmstate_apm = {
66
    .name = "APM State",
67
    .version_id = 1,
68
    .minimum_version_id = 1,
69
    .minimum_version_id_old = 1,
70
    .fields = (VMStateField[]) {
71
        VMSTATE_UINT8(apmc, APMState),
72
        VMSTATE_UINT8(apms, APMState),
73
        VMSTATE_END_OF_LIST()
74
    }
75
};
76

    
77
void apm_init(APMState *apm, apm_ctrl_changed_t callback, void *arg)
78
{
79
    apm->callback = callback;
80
    apm->arg = arg;
81

    
82
    /* ioport 0xb2, 0xb3 */
83
    register_ioport_write(APM_CNT_IOPORT, 2, 1, apm_ioport_writeb, apm);
84
    register_ioport_read(APM_CNT_IOPORT, 2, 1, apm_ioport_readb, apm);
85
}