xref: /openbmc/qemu/include/hw/acpi/acpi.h (revision d6032e06)
1 #ifndef QEMU_HW_ACPI_H
2 #define QEMU_HW_ACPI_H
3 /*
4  *  Copyright (c) 2009 Isaku Yamahata <yamahata at valinux co jp>
5  *                     VA Linux Systems Japan K.K.
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 as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, see
19  * <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "qapi/error.h"
23 #include "qemu/typedefs.h"
24 #include "qemu/notify.h"
25 #include "qemu/option.h"
26 #include "exec/memory.h"
27 #include "hw/irq.h"
28 
29 /* from linux include/acpi/actype.h */
30 /* Default ACPI register widths */
31 
32 #define ACPI_GPE_REGISTER_WIDTH         8
33 #define ACPI_PM1_REGISTER_WIDTH         16
34 #define ACPI_PM2_REGISTER_WIDTH         8
35 #define ACPI_PM_TIMER_WIDTH             32
36 
37 /* PM Timer ticks per second (HZ) */
38 #define PM_TIMER_FREQUENCY  3579545
39 
40 
41 /* ACPI fixed hardware registers */
42 
43 /* from linux/drivers/acpi/acpica/aclocal.h */
44 /* Masks used to access the bit_registers */
45 
46 /* PM1x_STS */
47 #define ACPI_BITMASK_TIMER_STATUS               0x0001
48 #define ACPI_BITMASK_BUS_MASTER_STATUS          0x0010
49 #define ACPI_BITMASK_GLOBAL_LOCK_STATUS         0x0020
50 #define ACPI_BITMASK_POWER_BUTTON_STATUS        0x0100
51 #define ACPI_BITMASK_SLEEP_BUTTON_STATUS        0x0200
52 #define ACPI_BITMASK_RT_CLOCK_STATUS            0x0400
53 #define ACPI_BITMASK_PCIEXP_WAKE_STATUS         0x4000	/* ACPI 3.0 */
54 #define ACPI_BITMASK_WAKE_STATUS                0x8000
55 
56 #define ACPI_BITMASK_ALL_FIXED_STATUS           (\
57 	ACPI_BITMASK_TIMER_STATUS          | \
58 	ACPI_BITMASK_BUS_MASTER_STATUS     | \
59 	ACPI_BITMASK_GLOBAL_LOCK_STATUS    | \
60 	ACPI_BITMASK_POWER_BUTTON_STATUS   | \
61 	ACPI_BITMASK_SLEEP_BUTTON_STATUS   | \
62 	ACPI_BITMASK_RT_CLOCK_STATUS       | \
63 	ACPI_BITMASK_WAKE_STATUS)
64 
65 /* PM1x_EN */
66 #define ACPI_BITMASK_TIMER_ENABLE               0x0001
67 #define ACPI_BITMASK_GLOBAL_LOCK_ENABLE         0x0020
68 #define ACPI_BITMASK_POWER_BUTTON_ENABLE        0x0100
69 #define ACPI_BITMASK_SLEEP_BUTTON_ENABLE        0x0200
70 #define ACPI_BITMASK_RT_CLOCK_ENABLE            0x0400
71 #define ACPI_BITMASK_PCIEXP_WAKE_DISABLE        0x4000	/* ACPI 3.0 */
72 
73 #define ACPI_BITMASK_PM1_COMMON_ENABLED         ( \
74         ACPI_BITMASK_RT_CLOCK_ENABLE        | \
75         ACPI_BITMASK_POWER_BUTTON_ENABLE    | \
76         ACPI_BITMASK_GLOBAL_LOCK_ENABLE     | \
77         ACPI_BITMASK_TIMER_ENABLE)
78 
79 /* PM1x_CNT */
80 #define ACPI_BITMASK_SCI_ENABLE                 0x0001
81 #define ACPI_BITMASK_BUS_MASTER_RLD             0x0002
82 #define ACPI_BITMASK_GLOBAL_LOCK_RELEASE        0x0004
83 #define ACPI_BITMASK_SLEEP_TYPE                 0x1C00
84 #define ACPI_BITMASK_SLEEP_ENABLE               0x2000
85 
86 /* PM2_CNT */
87 #define ACPI_BITMASK_ARB_DISABLE                0x0001
88 
89 /* structs */
90 typedef struct ACPIPMTimer ACPIPMTimer;
91 typedef struct ACPIPM1EVT ACPIPM1EVT;
92 typedef struct ACPIPM1CNT ACPIPM1CNT;
93 typedef struct ACPIGPE ACPIGPE;
94 typedef struct ACPIREGS ACPIREGS;
95 
96 typedef void (*acpi_update_sci_fn)(ACPIREGS *ar);
97 
98 struct ACPIPMTimer {
99     QEMUTimer *timer;
100     MemoryRegion io;
101     int64_t overflow_time;
102 
103     acpi_update_sci_fn update_sci;
104 };
105 
106 struct ACPIPM1EVT {
107     MemoryRegion io;
108     uint16_t sts;
109     uint16_t en;
110     acpi_update_sci_fn update_sci;
111 };
112 
113 struct ACPIPM1CNT {
114     MemoryRegion io;
115     uint16_t cnt;
116     uint8_t s4_val;
117 };
118 
119 struct ACPIGPE {
120     uint8_t len;
121 
122     uint8_t *sts;
123     uint8_t *en;
124 };
125 
126 struct ACPIREGS {
127     ACPIPMTimer     tmr;
128     ACPIGPE         gpe;
129     struct {
130         ACPIPM1EVT  evt;
131         ACPIPM1CNT  cnt;
132     } pm1;
133     Notifier wakeup;
134 };
135 
136 /* PM_TMR */
137 void acpi_pm_tmr_update(ACPIREGS *ar, bool enable);
138 void acpi_pm_tmr_calc_overflow_time(ACPIREGS *ar);
139 void acpi_pm_tmr_init(ACPIREGS *ar, acpi_update_sci_fn update_sci,
140                       MemoryRegion *parent);
141 void acpi_pm_tmr_reset(ACPIREGS *ar);
142 
143 #include "qemu/timer.h"
144 static inline int64_t acpi_pm_tmr_get_clock(void)
145 {
146     return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), PM_TIMER_FREQUENCY,
147                     get_ticks_per_sec());
148 }
149 
150 /* PM1a_EVT: piix and ich9 don't implement PM1b. */
151 uint16_t acpi_pm1_evt_get_sts(ACPIREGS *ar);
152 void acpi_pm1_evt_power_down(ACPIREGS *ar);
153 void acpi_pm1_evt_reset(ACPIREGS *ar);
154 void acpi_pm1_evt_init(ACPIREGS *ar, acpi_update_sci_fn update_sci,
155                        MemoryRegion *parent);
156 
157 /* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */
158 void acpi_pm1_cnt_init(ACPIREGS *ar, MemoryRegion *parent, uint8_t s4_val);
159 void acpi_pm1_cnt_update(ACPIREGS *ar,
160                          bool sci_enable, bool sci_disable);
161 void acpi_pm1_cnt_reset(ACPIREGS *ar);
162 
163 /* GPE0 */
164 void acpi_gpe_init(ACPIREGS *ar, uint8_t len);
165 void acpi_gpe_reset(ACPIREGS *ar);
166 
167 void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val);
168 uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr);
169 
170 void acpi_update_sci(ACPIREGS *acpi_regs, qemu_irq irq);
171 
172 /* acpi.c */
173 extern int acpi_enabled;
174 extern char unsigned *acpi_tables;
175 extern size_t acpi_tables_len;
176 
177 uint8_t *acpi_table_first(void);
178 uint8_t *acpi_table_next(uint8_t *current);
179 unsigned acpi_table_len(void *current);
180 void acpi_table_add(const QemuOpts *opts, Error **errp);
181 void acpi_table_add_builtin(const QemuOpts *opts, Error **errp);
182 
183 #endif /* !QEMU_HW_ACPI_H */
184