Statistics
| Branch: | Revision:

root / hw / acpi.h @ a1e47211

History | View | Annotate | Download (4.8 kB)

1 990b150e Isaku Yamahata
#ifndef QEMU_HW_ACPI_H
2 990b150e Isaku Yamahata
#define QEMU_HW_ACPI_H
3 990b150e Isaku Yamahata
/*
4 990b150e Isaku Yamahata
 *  Copyright (c) 2009 Isaku Yamahata <yamahata at valinux co jp>
5 990b150e Isaku Yamahata
 *                     VA Linux Systems Japan K.K.
6 990b150e Isaku Yamahata
 *
7 990b150e Isaku Yamahata
 * This library is free software; you can redistribute it and/or
8 990b150e Isaku Yamahata
 * modify it under the terms of the GNU Lesser General Public
9 990b150e Isaku Yamahata
 * License as published by the Free Software Foundation; either
10 990b150e Isaku Yamahata
 * version 2 of the License, or (at your option) any later version.
11 990b150e Isaku Yamahata
 *
12 990b150e Isaku Yamahata
 * This library is distributed in the hope that it will be useful,
13 990b150e Isaku Yamahata
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 990b150e Isaku Yamahata
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 990b150e Isaku Yamahata
 * Lesser General Public License for more details.
16 990b150e Isaku Yamahata
 *
17 990b150e Isaku Yamahata
 * You should have received a copy of the GNU Lesser General Public
18 1012e960 Blue Swirl
 * License along with this library; if not, see
19 1012e960 Blue Swirl
 * <http://www.gnu.org/licenses/>.
20 990b150e Isaku Yamahata
 */
21 990b150e Isaku Yamahata
22 990b150e Isaku Yamahata
/* from linux include/acpi/actype.h */
23 990b150e Isaku Yamahata
/* Default ACPI register widths */
24 990b150e Isaku Yamahata
25 990b150e Isaku Yamahata
#define ACPI_GPE_REGISTER_WIDTH         8
26 990b150e Isaku Yamahata
#define ACPI_PM1_REGISTER_WIDTH         16
27 990b150e Isaku Yamahata
#define ACPI_PM2_REGISTER_WIDTH         8
28 990b150e Isaku Yamahata
#define ACPI_PM_TIMER_WIDTH             32
29 990b150e Isaku Yamahata
30 990b150e Isaku Yamahata
/* PM Timer ticks per second (HZ) */
31 990b150e Isaku Yamahata
#define PM_TIMER_FREQUENCY  3579545
32 990b150e Isaku Yamahata
33 990b150e Isaku Yamahata
34 990b150e Isaku Yamahata
/* ACPI fixed hardware registers */
35 990b150e Isaku Yamahata
36 990b150e Isaku Yamahata
/* from linux/drivers/acpi/acpica/aclocal.h */
37 990b150e Isaku Yamahata
/* Masks used to access the bit_registers */
38 990b150e Isaku Yamahata
39 990b150e Isaku Yamahata
/* PM1x_STS */
40 990b150e Isaku Yamahata
#define ACPI_BITMASK_TIMER_STATUS               0x0001
41 990b150e Isaku Yamahata
#define ACPI_BITMASK_BUS_MASTER_STATUS          0x0010
42 990b150e Isaku Yamahata
#define ACPI_BITMASK_GLOBAL_LOCK_STATUS         0x0020
43 990b150e Isaku Yamahata
#define ACPI_BITMASK_POWER_BUTTON_STATUS        0x0100
44 990b150e Isaku Yamahata
#define ACPI_BITMASK_SLEEP_BUTTON_STATUS        0x0200
45 990b150e Isaku Yamahata
#define ACPI_BITMASK_RT_CLOCK_STATUS            0x0400
46 990b150e Isaku Yamahata
#define ACPI_BITMASK_PCIEXP_WAKE_STATUS         0x4000        /* ACPI 3.0 */
47 990b150e Isaku Yamahata
#define ACPI_BITMASK_WAKE_STATUS                0x8000
48 990b150e Isaku Yamahata
49 990b150e Isaku Yamahata
#define ACPI_BITMASK_ALL_FIXED_STATUS           (\
50 990b150e Isaku Yamahata
        ACPI_BITMASK_TIMER_STATUS          | \
51 990b150e Isaku Yamahata
        ACPI_BITMASK_BUS_MASTER_STATUS     | \
52 990b150e Isaku Yamahata
        ACPI_BITMASK_GLOBAL_LOCK_STATUS    | \
53 990b150e Isaku Yamahata
        ACPI_BITMASK_POWER_BUTTON_STATUS   | \
54 990b150e Isaku Yamahata
        ACPI_BITMASK_SLEEP_BUTTON_STATUS   | \
55 990b150e Isaku Yamahata
        ACPI_BITMASK_RT_CLOCK_STATUS       | \
56 990b150e Isaku Yamahata
        ACPI_BITMASK_WAKE_STATUS)
57 990b150e Isaku Yamahata
58 990b150e Isaku Yamahata
/* PM1x_EN */
59 990b150e Isaku Yamahata
#define ACPI_BITMASK_TIMER_ENABLE               0x0001
60 990b150e Isaku Yamahata
#define ACPI_BITMASK_GLOBAL_LOCK_ENABLE         0x0020
61 990b150e Isaku Yamahata
#define ACPI_BITMASK_POWER_BUTTON_ENABLE        0x0100
62 990b150e Isaku Yamahata
#define ACPI_BITMASK_SLEEP_BUTTON_ENABLE        0x0200
63 990b150e Isaku Yamahata
#define ACPI_BITMASK_RT_CLOCK_ENABLE            0x0400
64 990b150e Isaku Yamahata
#define ACPI_BITMASK_PCIEXP_WAKE_DISABLE        0x4000        /* ACPI 3.0 */
65 990b150e Isaku Yamahata
66 990b150e Isaku Yamahata
/* PM1x_CNT */
67 990b150e Isaku Yamahata
#define ACPI_BITMASK_SCI_ENABLE                 0x0001
68 990b150e Isaku Yamahata
#define ACPI_BITMASK_BUS_MASTER_RLD             0x0002
69 990b150e Isaku Yamahata
#define ACPI_BITMASK_GLOBAL_LOCK_RELEASE        0x0004
70 990b150e Isaku Yamahata
#define ACPI_BITMASK_SLEEP_TYPE                 0x1C00
71 990b150e Isaku Yamahata
#define ACPI_BITMASK_SLEEP_ENABLE               0x2000
72 990b150e Isaku Yamahata
73 990b150e Isaku Yamahata
/* PM2_CNT */
74 990b150e Isaku Yamahata
#define ACPI_BITMASK_ARB_DISABLE                0x0001
75 990b150e Isaku Yamahata
76 067866d6 Gerd Hoffmann
/* structs */
77 a54d41a8 Isaku Yamahata
typedef struct ACPIPMTimer ACPIPMTimer;
78 067866d6 Gerd Hoffmann
typedef struct ACPIPM1EVT ACPIPM1EVT;
79 067866d6 Gerd Hoffmann
typedef struct ACPIPM1CNT ACPIPM1CNT;
80 067866d6 Gerd Hoffmann
typedef struct ACPIGPE ACPIGPE;
81 355bf2e5 Gerd Hoffmann
typedef struct ACPIREGS ACPIREGS;
82 a54d41a8 Isaku Yamahata
83 355bf2e5 Gerd Hoffmann
typedef void (*acpi_update_sci_fn)(ACPIREGS *ar);
84 a54d41a8 Isaku Yamahata
85 a54d41a8 Isaku Yamahata
struct ACPIPMTimer {
86 a54d41a8 Isaku Yamahata
    QEMUTimer *timer;
87 a54d41a8 Isaku Yamahata
    int64_t overflow_time;
88 a54d41a8 Isaku Yamahata
89 a54d41a8 Isaku Yamahata
    acpi_update_sci_fn update_sci;
90 a54d41a8 Isaku Yamahata
};
91 a54d41a8 Isaku Yamahata
92 067866d6 Gerd Hoffmann
struct ACPIPM1EVT {
93 067866d6 Gerd Hoffmann
    uint16_t sts;
94 067866d6 Gerd Hoffmann
    uint16_t en;
95 067866d6 Gerd Hoffmann
};
96 067866d6 Gerd Hoffmann
97 067866d6 Gerd Hoffmann
struct ACPIPM1CNT {
98 067866d6 Gerd Hoffmann
    uint16_t cnt;
99 067866d6 Gerd Hoffmann
};
100 067866d6 Gerd Hoffmann
101 067866d6 Gerd Hoffmann
struct ACPIGPE {
102 067866d6 Gerd Hoffmann
    uint32_t blk;
103 067866d6 Gerd Hoffmann
    uint8_t len;
104 067866d6 Gerd Hoffmann
105 067866d6 Gerd Hoffmann
    uint8_t *sts;
106 067866d6 Gerd Hoffmann
    uint8_t *en;
107 067866d6 Gerd Hoffmann
};
108 067866d6 Gerd Hoffmann
109 355bf2e5 Gerd Hoffmann
struct ACPIREGS {
110 355bf2e5 Gerd Hoffmann
    ACPIPMTimer     tmr;
111 355bf2e5 Gerd Hoffmann
    ACPIGPE         gpe;
112 355bf2e5 Gerd Hoffmann
    struct {
113 355bf2e5 Gerd Hoffmann
        ACPIPM1EVT  evt;
114 355bf2e5 Gerd Hoffmann
        ACPIPM1CNT  cnt;
115 355bf2e5 Gerd Hoffmann
    } pm1;
116 da98c8eb Gerd Hoffmann
    Notifier wakeup;
117 355bf2e5 Gerd Hoffmann
};
118 355bf2e5 Gerd Hoffmann
119 067866d6 Gerd Hoffmann
/* PM_TMR */
120 355bf2e5 Gerd Hoffmann
void acpi_pm_tmr_update(ACPIREGS *ar, bool enable);
121 355bf2e5 Gerd Hoffmann
void acpi_pm_tmr_calc_overflow_time(ACPIREGS *ar);
122 355bf2e5 Gerd Hoffmann
uint32_t acpi_pm_tmr_get(ACPIREGS *ar);
123 355bf2e5 Gerd Hoffmann
void acpi_pm_tmr_init(ACPIREGS *ar, acpi_update_sci_fn update_sci);
124 355bf2e5 Gerd Hoffmann
void acpi_pm_tmr_reset(ACPIREGS *ar);
125 a54d41a8 Isaku Yamahata
126 a54d41a8 Isaku Yamahata
#include "qemu-timer.h"
127 a54d41a8 Isaku Yamahata
static inline int64_t acpi_pm_tmr_get_clock(void)
128 a54d41a8 Isaku Yamahata
{
129 a54d41a8 Isaku Yamahata
    return muldiv64(qemu_get_clock_ns(vm_clock), PM_TIMER_FREQUENCY,
130 a54d41a8 Isaku Yamahata
                    get_ticks_per_sec());
131 a54d41a8 Isaku Yamahata
}
132 990b150e Isaku Yamahata
133 04dc308f Isaku Yamahata
/* PM1a_EVT: piix and ich9 don't implement PM1b. */
134 2886be1b Gerd Hoffmann
uint16_t acpi_pm1_evt_get_sts(ACPIREGS *ar);
135 355bf2e5 Gerd Hoffmann
void acpi_pm1_evt_write_sts(ACPIREGS *ar, uint16_t val);
136 8283c4f5 Gerd Hoffmann
void acpi_pm1_evt_write_en(ACPIREGS *ar, uint16_t val);
137 355bf2e5 Gerd Hoffmann
void acpi_pm1_evt_power_down(ACPIREGS *ar);
138 355bf2e5 Gerd Hoffmann
void acpi_pm1_evt_reset(ACPIREGS *ar);
139 04dc308f Isaku Yamahata
140 eaba51c5 Isaku Yamahata
/* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */
141 da98c8eb Gerd Hoffmann
void acpi_pm1_cnt_init(ACPIREGS *ar);
142 459ae5ea Gleb Natapov
void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val, char s4);
143 355bf2e5 Gerd Hoffmann
void acpi_pm1_cnt_update(ACPIREGS *ar,
144 eaba51c5 Isaku Yamahata
                         bool sci_enable, bool sci_disable);
145 355bf2e5 Gerd Hoffmann
void acpi_pm1_cnt_reset(ACPIREGS *ar);
146 eaba51c5 Isaku Yamahata
147 23910d3f Isaku Yamahata
/* GPE0 */
148 355bf2e5 Gerd Hoffmann
void acpi_gpe_init(ACPIREGS *ar, uint8_t len);
149 355bf2e5 Gerd Hoffmann
void acpi_gpe_blk(ACPIREGS *ar, uint32_t blk);
150 355bf2e5 Gerd Hoffmann
void acpi_gpe_reset(ACPIREGS *ar);
151 23910d3f Isaku Yamahata
152 355bf2e5 Gerd Hoffmann
void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val);
153 355bf2e5 Gerd Hoffmann
uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr);
154 23910d3f Isaku Yamahata
155 990b150e Isaku Yamahata
#endif /* !QEMU_HW_ACPI_H */