Statistics
| Branch: | Revision:

root / include / hw / acpi / acpi.h @ 0445259b

History | View | Annotate | Download (4.9 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 77d58b1e Gerd Hoffmann
    MemoryRegion io;
88 a54d41a8 Isaku Yamahata
    int64_t overflow_time;
89 a54d41a8 Isaku Yamahata
90 a54d41a8 Isaku Yamahata
    acpi_update_sci_fn update_sci;
91 a54d41a8 Isaku Yamahata
};
92 a54d41a8 Isaku Yamahata
93 067866d6 Gerd Hoffmann
struct ACPIPM1EVT {
94 b5a7c024 Gerd Hoffmann
    MemoryRegion io;
95 067866d6 Gerd Hoffmann
    uint16_t sts;
96 067866d6 Gerd Hoffmann
    uint16_t en;
97 b5a7c024 Gerd Hoffmann
    acpi_update_sci_fn update_sci;
98 067866d6 Gerd Hoffmann
};
99 067866d6 Gerd Hoffmann
100 067866d6 Gerd Hoffmann
struct ACPIPM1CNT {
101 afafe4bb Gerd Hoffmann
    MemoryRegion io;
102 067866d6 Gerd Hoffmann
    uint16_t cnt;
103 afafe4bb Gerd Hoffmann
    uint8_t s4_val;
104 067866d6 Gerd Hoffmann
};
105 067866d6 Gerd Hoffmann
106 067866d6 Gerd Hoffmann
struct ACPIGPE {
107 067866d6 Gerd Hoffmann
    uint8_t len;
108 067866d6 Gerd Hoffmann
109 067866d6 Gerd Hoffmann
    uint8_t *sts;
110 067866d6 Gerd Hoffmann
    uint8_t *en;
111 067866d6 Gerd Hoffmann
};
112 067866d6 Gerd Hoffmann
113 355bf2e5 Gerd Hoffmann
struct ACPIREGS {
114 355bf2e5 Gerd Hoffmann
    ACPIPMTimer     tmr;
115 355bf2e5 Gerd Hoffmann
    ACPIGPE         gpe;
116 355bf2e5 Gerd Hoffmann
    struct {
117 355bf2e5 Gerd Hoffmann
        ACPIPM1EVT  evt;
118 355bf2e5 Gerd Hoffmann
        ACPIPM1CNT  cnt;
119 355bf2e5 Gerd Hoffmann
    } pm1;
120 da98c8eb Gerd Hoffmann
    Notifier wakeup;
121 355bf2e5 Gerd Hoffmann
};
122 355bf2e5 Gerd Hoffmann
123 067866d6 Gerd Hoffmann
/* PM_TMR */
124 355bf2e5 Gerd Hoffmann
void acpi_pm_tmr_update(ACPIREGS *ar, bool enable);
125 355bf2e5 Gerd Hoffmann
void acpi_pm_tmr_calc_overflow_time(ACPIREGS *ar);
126 77d58b1e Gerd Hoffmann
void acpi_pm_tmr_init(ACPIREGS *ar, acpi_update_sci_fn update_sci,
127 77d58b1e Gerd Hoffmann
                      MemoryRegion *parent);
128 355bf2e5 Gerd Hoffmann
void acpi_pm_tmr_reset(ACPIREGS *ar);
129 a54d41a8 Isaku Yamahata
130 1de7afc9 Paolo Bonzini
#include "qemu/timer.h"
131 a54d41a8 Isaku Yamahata
static inline int64_t acpi_pm_tmr_get_clock(void)
132 a54d41a8 Isaku Yamahata
{
133 a54d41a8 Isaku Yamahata
    return muldiv64(qemu_get_clock_ns(vm_clock), PM_TIMER_FREQUENCY,
134 a54d41a8 Isaku Yamahata
                    get_ticks_per_sec());
135 a54d41a8 Isaku Yamahata
}
136 990b150e Isaku Yamahata
137 04dc308f Isaku Yamahata
/* PM1a_EVT: piix and ich9 don't implement PM1b. */
138 2886be1b Gerd Hoffmann
uint16_t acpi_pm1_evt_get_sts(ACPIREGS *ar);
139 355bf2e5 Gerd Hoffmann
void acpi_pm1_evt_power_down(ACPIREGS *ar);
140 355bf2e5 Gerd Hoffmann
void acpi_pm1_evt_reset(ACPIREGS *ar);
141 b5a7c024 Gerd Hoffmann
void acpi_pm1_evt_init(ACPIREGS *ar, acpi_update_sci_fn update_sci,
142 b5a7c024 Gerd Hoffmann
                       MemoryRegion *parent);
143 04dc308f Isaku Yamahata
144 eaba51c5 Isaku Yamahata
/* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */
145 560e6396 Bruce Rogers
void acpi_pm1_cnt_init(ACPIREGS *ar, MemoryRegion *parent, uint8_t s4_val);
146 355bf2e5 Gerd Hoffmann
void acpi_pm1_cnt_update(ACPIREGS *ar,
147 eaba51c5 Isaku Yamahata
                         bool sci_enable, bool sci_disable);
148 355bf2e5 Gerd Hoffmann
void acpi_pm1_cnt_reset(ACPIREGS *ar);
149 eaba51c5 Isaku Yamahata
150 23910d3f Isaku Yamahata
/* GPE0 */
151 355bf2e5 Gerd Hoffmann
void acpi_gpe_init(ACPIREGS *ar, uint8_t len);
152 355bf2e5 Gerd Hoffmann
void acpi_gpe_reset(ACPIREGS *ar);
153 23910d3f Isaku Yamahata
154 355bf2e5 Gerd Hoffmann
void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val);
155 355bf2e5 Gerd Hoffmann
uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr);
156 23910d3f Isaku Yamahata
157 0445259b Michael S. Tsirkin
/* acpi.c */
158 0445259b Michael S. Tsirkin
extern int acpi_enabled;
159 0445259b Michael S. Tsirkin
extern char unsigned *acpi_tables;
160 0445259b Michael S. Tsirkin
extern size_t acpi_tables_len;
161 0445259b Michael S. Tsirkin
162 0445259b Michael S. Tsirkin
void acpi_table_add(const QemuOpts *opts, Error **errp);
163 0445259b Michael S. Tsirkin
164 990b150e Isaku Yamahata
#endif /* !QEMU_HW_ACPI_H */