root / hw / acpi_ich9.c @ 9e2c1298
History | View | Annotate | Download (7 kB)
1 | e516572f | Jason Baron | /*
|
---|---|---|---|
2 | e516572f | Jason Baron | * ACPI implementation
|
3 | e516572f | Jason Baron | *
|
4 | e516572f | Jason Baron | * Copyright (c) 2006 Fabrice Bellard
|
5 | e516572f | Jason Baron | *
|
6 | e516572f | Jason Baron | * This library is free software; you can redistribute it and/or
|
7 | e516572f | Jason Baron | * modify it under the terms of the GNU Lesser General Public
|
8 | e516572f | Jason Baron | * License version 2 as published by the Free Software Foundation.
|
9 | e516572f | Jason Baron | *
|
10 | e516572f | Jason Baron | * This library is distributed in the hope that it will be useful,
|
11 | e516572f | Jason Baron | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 | e516572f | Jason Baron | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 | e516572f | Jason Baron | * Lesser General Public License for more details.
|
14 | e516572f | Jason Baron | *
|
15 | e516572f | Jason Baron | * You should have received a copy of the GNU Lesser General Public
|
16 | e516572f | Jason Baron | * License along with this library; if not, see <http://www.gnu.org/licenses/>
|
17 | e516572f | Jason Baron | */
|
18 | e516572f | Jason Baron | /*
|
19 | e516572f | Jason Baron | * Copyright (c) 2009 Isaku Yamahata <yamahata at valinux co jp>
|
20 | e516572f | Jason Baron | * VA Linux Systems Japan K.K.
|
21 | e516572f | Jason Baron | * Copyright (C) 2012 Jason Baron <jbaron@redhat.com>
|
22 | e516572f | Jason Baron | *
|
23 | e516572f | Jason Baron | * This is based on acpi.c.
|
24 | e516572f | Jason Baron | */
|
25 | e516572f | Jason Baron | #include "hw.h" |
26 | e516572f | Jason Baron | #include "pc.h" |
27 | e516572f | Jason Baron | #include "pci.h" |
28 | e516572f | Jason Baron | #include "qemu-timer.h" |
29 | e516572f | Jason Baron | #include "sysemu.h" |
30 | e516572f | Jason Baron | #include "acpi.h" |
31 | 21bcfdd9 | Jan Kiszka | #include "kvm.h" |
32 | cacaab8b | Gerd Hoffmann | #include "exec-memory.h" |
33 | e516572f | Jason Baron | |
34 | e516572f | Jason Baron | #include "ich9.h" |
35 | e516572f | Jason Baron | |
36 | e516572f | Jason Baron | //#define DEBUG
|
37 | e516572f | Jason Baron | |
38 | e516572f | Jason Baron | #ifdef DEBUG
|
39 | e516572f | Jason Baron | #define ICH9_DEBUG(fmt, ...) \
|
40 | e516572f | Jason Baron | do { printf("%s "fmt, __func__, ## __VA_ARGS__); } while (0) |
41 | e516572f | Jason Baron | #else
|
42 | e516572f | Jason Baron | #define ICH9_DEBUG(fmt, ...) do { } while (0) |
43 | e516572f | Jason Baron | #endif
|
44 | e516572f | Jason Baron | |
45 | e516572f | Jason Baron | static void pm_update_sci(ICH9LPCPMRegs *pm) |
46 | e516572f | Jason Baron | { |
47 | e516572f | Jason Baron | int sci_level, pm1a_sts;
|
48 | e516572f | Jason Baron | |
49 | e516572f | Jason Baron | pm1a_sts = acpi_pm1_evt_get_sts(&pm->acpi_regs); |
50 | e516572f | Jason Baron | |
51 | e516572f | Jason Baron | sci_level = (((pm1a_sts & pm->acpi_regs.pm1.evt.en) & |
52 | e516572f | Jason Baron | (ACPI_BITMASK_RT_CLOCK_ENABLE | |
53 | e516572f | Jason Baron | ACPI_BITMASK_POWER_BUTTON_ENABLE | |
54 | e516572f | Jason Baron | ACPI_BITMASK_GLOBAL_LOCK_ENABLE | |
55 | e516572f | Jason Baron | ACPI_BITMASK_TIMER_ENABLE)) != 0);
|
56 | e516572f | Jason Baron | qemu_set_irq(pm->irq, sci_level); |
57 | e516572f | Jason Baron | |
58 | e516572f | Jason Baron | /* schedule a timer interruption if needed */
|
59 | e516572f | Jason Baron | acpi_pm_tmr_update(&pm->acpi_regs, |
60 | e516572f | Jason Baron | (pm->acpi_regs.pm1.evt.en & ACPI_BITMASK_TIMER_ENABLE) && |
61 | e516572f | Jason Baron | !(pm1a_sts & ACPI_BITMASK_TIMER_STATUS)); |
62 | e516572f | Jason Baron | } |
63 | e516572f | Jason Baron | |
64 | e516572f | Jason Baron | static void ich9_pm_update_sci_fn(ACPIREGS *regs) |
65 | e516572f | Jason Baron | { |
66 | e516572f | Jason Baron | ICH9LPCPMRegs *pm = container_of(regs, ICH9LPCPMRegs, acpi_regs); |
67 | e516572f | Jason Baron | pm_update_sci(pm); |
68 | e516572f | Jason Baron | } |
69 | e516572f | Jason Baron | |
70 | 76a7daf9 | Gerd Hoffmann | static uint64_t ich9_gpe_readb(void *opaque, hwaddr addr, unsigned width) |
71 | 76a7daf9 | Gerd Hoffmann | { |
72 | 76a7daf9 | Gerd Hoffmann | ICH9LPCPMRegs *pm = opaque; |
73 | 76a7daf9 | Gerd Hoffmann | return acpi_gpe_ioport_readb(&pm->acpi_regs, addr);
|
74 | 76a7daf9 | Gerd Hoffmann | } |
75 | 76a7daf9 | Gerd Hoffmann | |
76 | 76a7daf9 | Gerd Hoffmann | static void ich9_gpe_writeb(void *opaque, hwaddr addr, uint64_t val, |
77 | 76a7daf9 | Gerd Hoffmann | unsigned width)
|
78 | 76a7daf9 | Gerd Hoffmann | { |
79 | 76a7daf9 | Gerd Hoffmann | ICH9LPCPMRegs *pm = opaque; |
80 | 76a7daf9 | Gerd Hoffmann | acpi_gpe_ioport_writeb(&pm->acpi_regs, addr, val); |
81 | 76a7daf9 | Gerd Hoffmann | } |
82 | 76a7daf9 | Gerd Hoffmann | |
83 | 76a7daf9 | Gerd Hoffmann | static const MemoryRegionOps ich9_gpe_ops = { |
84 | 76a7daf9 | Gerd Hoffmann | .read = ich9_gpe_readb, |
85 | 76a7daf9 | Gerd Hoffmann | .write = ich9_gpe_writeb, |
86 | 76a7daf9 | Gerd Hoffmann | .valid.min_access_size = 1,
|
87 | 76a7daf9 | Gerd Hoffmann | .valid.max_access_size = 4,
|
88 | 76a7daf9 | Gerd Hoffmann | .impl.min_access_size = 1,
|
89 | 76a7daf9 | Gerd Hoffmann | .impl.max_access_size = 1,
|
90 | 76a7daf9 | Gerd Hoffmann | .endianness = DEVICE_LITTLE_ENDIAN, |
91 | 76a7daf9 | Gerd Hoffmann | }; |
92 | 76a7daf9 | Gerd Hoffmann | |
93 | 10cc69b0 | Gerd Hoffmann | static uint64_t ich9_smi_readl(void *opaque, hwaddr addr, unsigned width) |
94 | 10cc69b0 | Gerd Hoffmann | { |
95 | 10cc69b0 | Gerd Hoffmann | ICH9LPCPMRegs *pm = opaque; |
96 | 10cc69b0 | Gerd Hoffmann | switch (addr) {
|
97 | 10cc69b0 | Gerd Hoffmann | case 0: |
98 | 10cc69b0 | Gerd Hoffmann | return pm->smi_en;
|
99 | 10cc69b0 | Gerd Hoffmann | case 4: |
100 | 10cc69b0 | Gerd Hoffmann | return pm->smi_sts;
|
101 | 10cc69b0 | Gerd Hoffmann | default:
|
102 | 10cc69b0 | Gerd Hoffmann | return 0; |
103 | 10cc69b0 | Gerd Hoffmann | } |
104 | 10cc69b0 | Gerd Hoffmann | } |
105 | 10cc69b0 | Gerd Hoffmann | |
106 | 10cc69b0 | Gerd Hoffmann | static void ich9_smi_writel(void *opaque, hwaddr addr, uint64_t val, |
107 | 10cc69b0 | Gerd Hoffmann | unsigned width)
|
108 | 10cc69b0 | Gerd Hoffmann | { |
109 | 10cc69b0 | Gerd Hoffmann | ICH9LPCPMRegs *pm = opaque; |
110 | 10cc69b0 | Gerd Hoffmann | switch (addr) {
|
111 | 10cc69b0 | Gerd Hoffmann | case 0: |
112 | 10cc69b0 | Gerd Hoffmann | pm->smi_en = val; |
113 | 10cc69b0 | Gerd Hoffmann | break;
|
114 | 10cc69b0 | Gerd Hoffmann | } |
115 | 10cc69b0 | Gerd Hoffmann | } |
116 | 10cc69b0 | Gerd Hoffmann | |
117 | 10cc69b0 | Gerd Hoffmann | static const MemoryRegionOps ich9_smi_ops = { |
118 | 10cc69b0 | Gerd Hoffmann | .read = ich9_smi_readl, |
119 | 10cc69b0 | Gerd Hoffmann | .write = ich9_smi_writel, |
120 | 10cc69b0 | Gerd Hoffmann | .valid.min_access_size = 4,
|
121 | 10cc69b0 | Gerd Hoffmann | .valid.max_access_size = 4,
|
122 | 10cc69b0 | Gerd Hoffmann | .endianness = DEVICE_LITTLE_ENDIAN, |
123 | 10cc69b0 | Gerd Hoffmann | }; |
124 | 10cc69b0 | Gerd Hoffmann | |
125 | e516572f | Jason Baron | void ich9_pm_iospace_update(ICH9LPCPMRegs *pm, uint32_t pm_io_base)
|
126 | e516572f | Jason Baron | { |
127 | e516572f | Jason Baron | ICH9_DEBUG("to 0x%x\n", pm_io_base);
|
128 | e516572f | Jason Baron | |
129 | e516572f | Jason Baron | assert((pm_io_base & ICH9_PMIO_MASK) == 0);
|
130 | e516572f | Jason Baron | |
131 | e516572f | Jason Baron | pm->pm_io_base = pm_io_base; |
132 | cacaab8b | Gerd Hoffmann | memory_region_transaction_begin(); |
133 | cacaab8b | Gerd Hoffmann | memory_region_set_enabled(&pm->io, pm->pm_io_base != 0);
|
134 | cacaab8b | Gerd Hoffmann | memory_region_set_address(&pm->io, pm->pm_io_base); |
135 | cacaab8b | Gerd Hoffmann | memory_region_transaction_commit(); |
136 | e516572f | Jason Baron | } |
137 | e516572f | Jason Baron | |
138 | e516572f | Jason Baron | static int ich9_pm_post_load(void *opaque, int version_id) |
139 | e516572f | Jason Baron | { |
140 | e516572f | Jason Baron | ICH9LPCPMRegs *pm = opaque; |
141 | e516572f | Jason Baron | uint32_t pm_io_base = pm->pm_io_base; |
142 | e516572f | Jason Baron | pm->pm_io_base = 0;
|
143 | e516572f | Jason Baron | ich9_pm_iospace_update(pm, pm_io_base); |
144 | e516572f | Jason Baron | return 0; |
145 | e516572f | Jason Baron | } |
146 | e516572f | Jason Baron | |
147 | e516572f | Jason Baron | #define VMSTATE_GPE_ARRAY(_field, _state) \
|
148 | e516572f | Jason Baron | { \ |
149 | e516572f | Jason Baron | .name = (stringify(_field)), \ |
150 | e516572f | Jason Baron | .version_id = 0, \
|
151 | e516572f | Jason Baron | .num = ICH9_PMIO_GPE0_LEN, \ |
152 | e516572f | Jason Baron | .info = &vmstate_info_uint8, \ |
153 | e516572f | Jason Baron | .size = sizeof(uint8_t), \
|
154 | e516572f | Jason Baron | .flags = VMS_ARRAY | VMS_POINTER, \ |
155 | e516572f | Jason Baron | .offset = vmstate_offset_pointer(_state, _field, uint8_t), \ |
156 | e516572f | Jason Baron | } |
157 | e516572f | Jason Baron | |
158 | e516572f | Jason Baron | const VMStateDescription vmstate_ich9_pm = {
|
159 | e516572f | Jason Baron | .name = "ich9_pm",
|
160 | e516572f | Jason Baron | .version_id = 1,
|
161 | e516572f | Jason Baron | .minimum_version_id = 1,
|
162 | e516572f | Jason Baron | .minimum_version_id_old = 1,
|
163 | e516572f | Jason Baron | .post_load = ich9_pm_post_load, |
164 | e516572f | Jason Baron | .fields = (VMStateField[]) { |
165 | e516572f | Jason Baron | VMSTATE_UINT16(acpi_regs.pm1.evt.sts, ICH9LPCPMRegs), |
166 | e516572f | Jason Baron | VMSTATE_UINT16(acpi_regs.pm1.evt.en, ICH9LPCPMRegs), |
167 | e516572f | Jason Baron | VMSTATE_UINT16(acpi_regs.pm1.cnt.cnt, ICH9LPCPMRegs), |
168 | e516572f | Jason Baron | VMSTATE_TIMER(acpi_regs.tmr.timer, ICH9LPCPMRegs), |
169 | e516572f | Jason Baron | VMSTATE_INT64(acpi_regs.tmr.overflow_time, ICH9LPCPMRegs), |
170 | e516572f | Jason Baron | VMSTATE_GPE_ARRAY(acpi_regs.gpe.sts, ICH9LPCPMRegs), |
171 | e516572f | Jason Baron | VMSTATE_GPE_ARRAY(acpi_regs.gpe.en, ICH9LPCPMRegs), |
172 | e516572f | Jason Baron | VMSTATE_UINT32(smi_en, ICH9LPCPMRegs), |
173 | e516572f | Jason Baron | VMSTATE_UINT32(smi_sts, ICH9LPCPMRegs), |
174 | e516572f | Jason Baron | VMSTATE_END_OF_LIST() |
175 | e516572f | Jason Baron | } |
176 | e516572f | Jason Baron | }; |
177 | e516572f | Jason Baron | |
178 | e516572f | Jason Baron | static void pm_reset(void *opaque) |
179 | e516572f | Jason Baron | { |
180 | e516572f | Jason Baron | ICH9LPCPMRegs *pm = opaque; |
181 | e516572f | Jason Baron | ich9_pm_iospace_update(pm, 0);
|
182 | e516572f | Jason Baron | |
183 | e516572f | Jason Baron | acpi_pm1_evt_reset(&pm->acpi_regs); |
184 | e516572f | Jason Baron | acpi_pm1_cnt_reset(&pm->acpi_regs); |
185 | e516572f | Jason Baron | acpi_pm_tmr_reset(&pm->acpi_regs); |
186 | e516572f | Jason Baron | acpi_gpe_reset(&pm->acpi_regs); |
187 | e516572f | Jason Baron | |
188 | 21bcfdd9 | Jan Kiszka | if (kvm_enabled()) {
|
189 | 21bcfdd9 | Jan Kiszka | /* Mark SMM as already inited to prevent SMM from running. KVM does not
|
190 | 21bcfdd9 | Jan Kiszka | * support SMM mode. */
|
191 | 21bcfdd9 | Jan Kiszka | pm->smi_en |= ICH9_PMIO_SMI_EN_APMC_EN; |
192 | 21bcfdd9 | Jan Kiszka | } |
193 | 21bcfdd9 | Jan Kiszka | |
194 | e516572f | Jason Baron | pm_update_sci(pm); |
195 | e516572f | Jason Baron | } |
196 | e516572f | Jason Baron | |
197 | e516572f | Jason Baron | static void pm_powerdown_req(Notifier *n, void *opaque) |
198 | e516572f | Jason Baron | { |
199 | e516572f | Jason Baron | ICH9LPCPMRegs *pm = container_of(n, ICH9LPCPMRegs, powerdown_notifier); |
200 | e516572f | Jason Baron | |
201 | e516572f | Jason Baron | acpi_pm1_evt_power_down(&pm->acpi_regs); |
202 | e516572f | Jason Baron | } |
203 | e516572f | Jason Baron | |
204 | e516572f | Jason Baron | void ich9_pm_init(ICH9LPCPMRegs *pm, qemu_irq sci_irq, qemu_irq cmos_s3)
|
205 | e516572f | Jason Baron | { |
206 | 4a522de0 | Gerd Hoffmann | memory_region_init(&pm->io, "ich9-pm", ICH9_PMIO_SIZE);
|
207 | cacaab8b | Gerd Hoffmann | memory_region_set_enabled(&pm->io, false);
|
208 | cacaab8b | Gerd Hoffmann | memory_region_add_subregion(get_system_io(), 0, &pm->io);
|
209 | cacaab8b | Gerd Hoffmann | |
210 | 77d58b1e | Gerd Hoffmann | acpi_pm_tmr_init(&pm->acpi_regs, ich9_pm_update_sci_fn, &pm->io); |
211 | b5a7c024 | Gerd Hoffmann | acpi_pm1_evt_init(&pm->acpi_regs, ich9_pm_update_sci_fn, &pm->io); |
212 | afafe4bb | Gerd Hoffmann | acpi_pm1_cnt_init(&pm->acpi_regs, &pm->io); |
213 | 76a7daf9 | Gerd Hoffmann | |
214 | e516572f | Jason Baron | acpi_gpe_init(&pm->acpi_regs, ICH9_PMIO_GPE0_LEN); |
215 | 76a7daf9 | Gerd Hoffmann | memory_region_init_io(&pm->io_gpe, &ich9_gpe_ops, pm, "apci-gpe0",
|
216 | 76a7daf9 | Gerd Hoffmann | ICH9_PMIO_GPE0_LEN); |
217 | 76a7daf9 | Gerd Hoffmann | memory_region_add_subregion(&pm->io, ICH9_PMIO_GPE0_STS, &pm->io_gpe); |
218 | e516572f | Jason Baron | |
219 | 10cc69b0 | Gerd Hoffmann | memory_region_init_io(&pm->io_smi, &ich9_smi_ops, pm, "apci-smi",
|
220 | 10cc69b0 | Gerd Hoffmann | 8);
|
221 | 10cc69b0 | Gerd Hoffmann | memory_region_add_subregion(&pm->io, ICH9_PMIO_SMI_EN, &pm->io_smi); |
222 | 10cc69b0 | Gerd Hoffmann | |
223 | e516572f | Jason Baron | pm->irq = sci_irq; |
224 | e516572f | Jason Baron | qemu_register_reset(pm_reset, pm); |
225 | e516572f | Jason Baron | pm->powerdown_notifier.notify = pm_powerdown_req; |
226 | e516572f | Jason Baron | qemu_register_powerdown_notifier(&pm->powerdown_notifier); |
227 | e516572f | Jason Baron | } |