]> Git Repo - qemu.git/blame - hw/acpi/piix4.c
migration: create savevm_state
[qemu.git] / hw / acpi / piix4.c
CommitLineData
93d89f63
IY
1/*
2 * ACPI implementation
3 *
4 * Copyright (c) 2006 Fabrice Bellard
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2 as published by the Free Software Foundation.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <http://www.gnu.org/licenses/>
6b620ca3
PB
17 *
18 * Contributions after 2012-01-13 are licensed under the terms of the
19 * GNU GPL, version 2 or (at your option) any later version.
93d89f63 20 */
83c9f4ca 21#include "hw/hw.h"
0d09e41a
PB
22#include "hw/i386/pc.h"
23#include "hw/isa/apm.h"
24#include "hw/i2c/pm_smbus.h"
83c9f4ca 25#include "hw/pci/pci.h"
0d09e41a 26#include "hw/acpi/acpi.h"
9c17d615 27#include "sysemu/sysemu.h"
1de7afc9 28#include "qemu/range.h"
022c62cb 29#include "exec/ioport.h"
0d09e41a 30#include "hw/nvram/fw_cfg.h"
022c62cb 31#include "exec/address-spaces.h"
277e9340 32#include "hw/acpi/piix4.h"
9e047b98 33#include "hw/acpi/pcihp.h"
81cea5e7 34#include "hw/acpi/cpu_hotplug.h"
c24d5e0b 35#include "hw/hotplug.h"
34774320
IM
36#include "hw/mem/pc-dimm.h"
37#include "hw/acpi/memory_hotplug.h"
43f50410 38#include "hw/acpi/acpi_dev_interface.h"
91ab2ed7 39#include "hw/xen/xen.h"
93d89f63
IY
40
41//#define DEBUG
42
50d8ff8b
IY
43#ifdef DEBUG
44# define PIIX4_DPRINTF(format, ...) printf(format, ## __VA_ARGS__)
45#else
46# define PIIX4_DPRINTF(format, ...) do { } while (0)
47#endif
48
ac404095 49#define GPE_BASE 0xafe0
23910d3f 50#define GPE_LEN 4
c177684c 51
ac404095 52struct pci_status {
7faa8075 53 uint32_t up; /* deprecated, maintained for migration compatibility */
ac404095
IY
54 uint32_t down;
55};
56
93d89f63 57typedef struct PIIX4PMState {
6a6b5580
AF
58 /*< private >*/
59 PCIDevice parent_obj;
60 /*< public >*/
56e5b2a1 61
af11110b 62 MemoryRegion io;
277e9340
MT
63 uint32_t io_base;
64
b65b93f2 65 MemoryRegion io_gpe;
355bf2e5 66 ACPIREGS ar;
93d89f63
IY
67
68 APMState apm;
69
93d89f63 70 PMSMBus smb;
e8ec0571 71 uint32_t smb_io_base;
93d89f63
IY
72
73 qemu_irq irq;
93d89f63
IY
74 qemu_irq smi_irq;
75 int kvm_enabled;
6141dbfe 76 Notifier machine_ready;
d010f91c 77 Notifier powerdown_notifier;
ac404095 78
9e047b98
MT
79 AcpiPciHpState acpi_pci_hotplug;
80 bool use_acpi_pci_hotplug;
81
459ae5ea
GN
82 uint8_t disable_s3;
83 uint8_t disable_s4;
84 uint8_t s4_val;
b8622725 85
81cea5e7 86 AcpiCpuHotplug gpe_cpu;
34774320
IM
87
88 MemHotplugState acpi_memory_hotplug;
93d89f63
IY
89} PIIX4PMState;
90
74e445f6
PC
91#define TYPE_PIIX4_PM "PIIX4_PM"
92
93#define PIIX4_PM(obj) \
94 OBJECT_CHECK(PIIX4PMState, (obj), TYPE_PIIX4_PM)
95
56e5b2a1
GH
96static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
97 PCIBus *bus, PIIX4PMState *s);
ac404095 98
93d89f63
IY
99#define ACPI_ENABLE 0xf1
100#define ACPI_DISABLE 0xf0
101
355bf2e5 102static void pm_tmr_timer(ACPIREGS *ar)
93d89f63 103{
355bf2e5 104 PIIX4PMState *s = container_of(ar, PIIX4PMState, ar);
06313503 105 acpi_update_sci(&s->ar, s->irq);
93d89f63
IY
106}
107
93d89f63
IY
108static void apm_ctrl_changed(uint32_t val, void *arg)
109{
110 PIIX4PMState *s = arg;
6a6b5580 111 PCIDevice *d = PCI_DEVICE(s);
93d89f63
IY
112
113 /* ACPI specs 3.0, 4.7.2.5 */
355bf2e5 114 acpi_pm1_cnt_update(&s->ar, val == ACPI_ENABLE, val == ACPI_DISABLE);
93d89f63 115
6a6b5580 116 if (d->config[0x5b] & (1 << 1)) {
93d89f63
IY
117 if (s->smi_irq) {
118 qemu_irq_raise(s->smi_irq);
119 }
120 }
121}
122
93d89f63
IY
123static void pm_io_space_update(PIIX4PMState *s)
124{
6a6b5580 125 PCIDevice *d = PCI_DEVICE(s);
93d89f63 126
277e9340
MT
127 s->io_base = le32_to_cpu(*(uint32_t *)(d->config + 0x40));
128 s->io_base &= 0xffc0;
93d89f63 129
af11110b 130 memory_region_transaction_begin();
6a6b5580 131 memory_region_set_enabled(&s->io, d->config[0x80] & 1);
277e9340 132 memory_region_set_address(&s->io, s->io_base);
af11110b 133 memory_region_transaction_commit();
93d89f63
IY
134}
135
24fe083d
GH
136static void smbus_io_space_update(PIIX4PMState *s)
137{
6a6b5580
AF
138 PCIDevice *d = PCI_DEVICE(s);
139
140 s->smb_io_base = le32_to_cpu(*(uint32_t *)(d->config + 0x90));
24fe083d
GH
141 s->smb_io_base &= 0xffc0;
142
143 memory_region_transaction_begin();
6a6b5580 144 memory_region_set_enabled(&s->smb.io, d->config[0xd2] & 1);
24fe083d
GH
145 memory_region_set_address(&s->smb.io, s->smb_io_base);
146 memory_region_transaction_commit();
93d89f63
IY
147}
148
149static void pm_write_config(PCIDevice *d,
150 uint32_t address, uint32_t val, int len)
151{
152 pci_default_write_config(d, address, val, len);
24fe083d
GH
153 if (range_covers_byte(address, len, 0x80) ||
154 ranges_overlap(address, len, 0x40, 4)) {
93d89f63 155 pm_io_space_update((PIIX4PMState *)d);
24fe083d
GH
156 }
157 if (range_covers_byte(address, len, 0xd2) ||
158 ranges_overlap(address, len, 0x90, 4)) {
159 smbus_io_space_update((PIIX4PMState *)d);
160 }
93d89f63
IY
161}
162
163static int vmstate_acpi_post_load(void *opaque, int version_id)
164{
165 PIIX4PMState *s = opaque;
166
167 pm_io_space_update(s);
168 return 0;
169}
170
23910d3f
IY
171#define VMSTATE_GPE_ARRAY(_field, _state) \
172 { \
173 .name = (stringify(_field)), \
174 .version_id = 0, \
23910d3f
IY
175 .info = &vmstate_info_uint16, \
176 .size = sizeof(uint16_t), \
b0b873a0 177 .flags = VMS_SINGLE | VMS_POINTER, \
23910d3f
IY
178 .offset = vmstate_offset_pointer(_state, _field, uint8_t), \
179 }
180
4cf3e6f3
AW
181static const VMStateDescription vmstate_gpe = {
182 .name = "gpe",
183 .version_id = 1,
184 .minimum_version_id = 1,
d49805ae 185 .fields = (VMStateField[]) {
23910d3f
IY
186 VMSTATE_GPE_ARRAY(sts, ACPIGPE),
187 VMSTATE_GPE_ARRAY(en, ACPIGPE),
4cf3e6f3
AW
188 VMSTATE_END_OF_LIST()
189 }
190};
191
192static const VMStateDescription vmstate_pci_status = {
193 .name = "pci_status",
194 .version_id = 1,
195 .minimum_version_id = 1,
d49805ae 196 .fields = (VMStateField[]) {
e358edc8
IM
197 VMSTATE_UINT32(up, struct AcpiPciHpPciStatus),
198 VMSTATE_UINT32(down, struct AcpiPciHpPciStatus),
4cf3e6f3
AW
199 VMSTATE_END_OF_LIST()
200 }
201};
202
b0b873a0
MT
203static int acpi_load_old(QEMUFile *f, void *opaque, int version_id)
204{
205 PIIX4PMState *s = opaque;
206 int ret, i;
207 uint16_t temp;
208
6a6b5580 209 ret = pci_device_load(PCI_DEVICE(s), f);
b0b873a0
MT
210 if (ret < 0) {
211 return ret;
212 }
213 qemu_get_be16s(f, &s->ar.pm1.evt.sts);
214 qemu_get_be16s(f, &s->ar.pm1.evt.en);
215 qemu_get_be16s(f, &s->ar.pm1.cnt.cnt);
216
ded67782 217 ret = vmstate_load_state(f, &vmstate_apm, &s->apm, 1);
b0b873a0
MT
218 if (ret) {
219 return ret;
220 }
221
40daca54 222 timer_get(f, s->ar.tmr.timer);
b0b873a0
MT
223 qemu_get_sbe64s(f, &s->ar.tmr.overflow_time);
224
225 qemu_get_be16s(f, (uint16_t *)s->ar.gpe.sts);
226 for (i = 0; i < 3; i++) {
227 qemu_get_be16s(f, &temp);
228 }
229
230 qemu_get_be16s(f, (uint16_t *)s->ar.gpe.en);
231 for (i = 0; i < 3; i++) {
232 qemu_get_be16s(f, &temp);
233 }
234
e358edc8
IM
235 ret = vmstate_load_state(f, &vmstate_pci_status,
236 &s->acpi_pci_hotplug.acpi_pcihp_pci_status[ACPI_PCIHP_BSEL_DEFAULT], 1);
b0b873a0
MT
237 return ret;
238}
239
9e047b98
MT
240static bool vmstate_test_use_acpi_pci_hotplug(void *opaque, int version_id)
241{
242 PIIX4PMState *s = opaque;
243 return s->use_acpi_pci_hotplug;
244}
245
246static bool vmstate_test_no_use_acpi_pci_hotplug(void *opaque, int version_id)
247{
248 PIIX4PMState *s = opaque;
249 return !s->use_acpi_pci_hotplug;
250}
251
f816a62d
IM
252static bool vmstate_test_use_memhp(void *opaque)
253{
254 PIIX4PMState *s = opaque;
255 return s->acpi_memory_hotplug.is_enabled;
256}
257
258static const VMStateDescription vmstate_memhp_state = {
259 .name = "piix4_pm/memhp",
260 .version_id = 1,
261 .minimum_version_id = 1,
262 .minimum_version_id_old = 1,
263 .fields = (VMStateField[]) {
264 VMSTATE_MEMORY_HOTPLUG(acpi_memory_hotplug, PIIX4PMState),
265 VMSTATE_END_OF_LIST()
266 }
267};
268
b0b873a0
MT
269/* qemu-kvm 1.2 uses version 3 but advertised as 2
270 * To support incoming qemu-kvm 1.2 migration, change version_id
271 * and minimum_version_id to 2 below (which breaks migration from
272 * qemu 1.2).
273 *
274 */
93d89f63
IY
275static const VMStateDescription vmstate_acpi = {
276 .name = "piix4_pm",
b0b873a0
MT
277 .version_id = 3,
278 .minimum_version_id = 3,
93d89f63 279 .minimum_version_id_old = 1,
b0b873a0 280 .load_state_old = acpi_load_old,
93d89f63 281 .post_load = vmstate_acpi_post_load,
d49805ae 282 .fields = (VMStateField[]) {
6a6b5580 283 VMSTATE_PCI_DEVICE(parent_obj, PIIX4PMState),
355bf2e5
GH
284 VMSTATE_UINT16(ar.pm1.evt.sts, PIIX4PMState),
285 VMSTATE_UINT16(ar.pm1.evt.en, PIIX4PMState),
286 VMSTATE_UINT16(ar.pm1.cnt.cnt, PIIX4PMState),
93d89f63 287 VMSTATE_STRUCT(apm, PIIX4PMState, 0, vmstate_apm, APMState),
e720677e 288 VMSTATE_TIMER_PTR(ar.tmr.timer, PIIX4PMState),
355bf2e5
GH
289 VMSTATE_INT64(ar.tmr.overflow_time, PIIX4PMState),
290 VMSTATE_STRUCT(ar.gpe, PIIX4PMState, 2, vmstate_gpe, ACPIGPE),
e358edc8
IM
291 VMSTATE_STRUCT_TEST(
292 acpi_pci_hotplug.acpi_pcihp_pci_status[ACPI_PCIHP_BSEL_DEFAULT],
293 PIIX4PMState,
294 vmstate_test_no_use_acpi_pci_hotplug,
295 2, vmstate_pci_status,
296 struct AcpiPciHpPciStatus),
9e047b98
MT
297 VMSTATE_PCI_HOTPLUG(acpi_pci_hotplug, PIIX4PMState,
298 vmstate_test_use_acpi_pci_hotplug),
93d89f63 299 VMSTATE_END_OF_LIST()
f816a62d
IM
300 },
301 .subsections = (VMStateSubsection[]) {
302 {
303 .vmsd = &vmstate_memhp_state,
304 .needed = vmstate_test_use_memhp,
305 },
306 VMSTATE_END_OF_LIST()
93d89f63
IY
307 }
308};
309
310static void piix4_reset(void *opaque)
311{
312 PIIX4PMState *s = opaque;
6a6b5580
AF
313 PCIDevice *d = PCI_DEVICE(s);
314 uint8_t *pci_conf = d->config;
93d89f63
IY
315
316 pci_conf[0x58] = 0;
317 pci_conf[0x59] = 0;
318 pci_conf[0x5a] = 0;
319 pci_conf[0x5b] = 0;
320
4d09d37c
GN
321 pci_conf[0x40] = 0x01; /* PM io base read only bit */
322 pci_conf[0x80] = 0;
323
93d89f63
IY
324 if (s->kvm_enabled) {
325 /* Mark SMM as already inited (until KVM supports SMM). */
326 pci_conf[0x5B] = 0x02;
327 }
c046e8c4 328 pm_io_space_update(s);
e358edc8 329 acpi_pcihp_reset(&s->acpi_pci_hotplug);
93d89f63
IY
330}
331
d010f91c 332static void piix4_pm_powerdown_req(Notifier *n, void *opaque)
93d89f63 333{
d010f91c 334 PIIX4PMState *s = container_of(n, PIIX4PMState, powerdown_notifier);
93d89f63 335
355bf2e5
GH
336 assert(s != NULL);
337 acpi_pm1_evt_power_down(&s->ar);
93d89f63
IY
338}
339
f1adc360
IM
340static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,
341 DeviceState *dev, Error **errp)
9e047b98 342{
c24d5e0b 343 PIIX4PMState *s = PIIX4_PM(hotplug_dev);
f1adc360 344
34774320
IM
345 if (s->acpi_memory_hotplug.is_enabled &&
346 object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
347 acpi_memory_plug_cb(&s->ar, s->irq, &s->acpi_memory_hotplug, dev, errp);
348 } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
f1adc360
IM
349 acpi_pcihp_device_plug_cb(&s->ar, s->irq, &s->acpi_pci_hotplug, dev,
350 errp);
08bba95b
GZ
351 } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
352 acpi_cpu_plug_cb(&s->ar, s->irq, &s->gpe_cpu, dev, errp);
f1adc360
IM
353 } else {
354 error_setg(errp, "acpi: device plug request for not supported device"
355 " type: %s", object_get_typename(OBJECT(dev)));
356 }
c24d5e0b 357}
9e047b98 358
14d5a28f
IM
359static void piix4_device_unplug_request_cb(HotplugHandler *hotplug_dev,
360 DeviceState *dev, Error **errp)
c24d5e0b
IM
361{
362 PIIX4PMState *s = PIIX4_PM(hotplug_dev);
f1adc360 363
64fec58e
TC
364 if (s->acpi_memory_hotplug.is_enabled &&
365 object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
366 acpi_memory_unplug_request_cb(&s->ar, s->irq, &s->acpi_memory_hotplug,
367 dev, errp);
368 } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
f1adc360
IM
369 acpi_pcihp_device_unplug_cb(&s->ar, s->irq, &s->acpi_pci_hotplug, dev,
370 errp);
371 } else {
372 error_setg(errp, "acpi: device unplug request for not supported device"
373 " type: %s", object_get_typename(OBJECT(dev)));
374 }
9e047b98
MT
375}
376
c0e57a60
TC
377static void piix4_device_unplug_cb(HotplugHandler *hotplug_dev,
378 DeviceState *dev, Error **errp)
379{
f7d3e29d
TC
380 PIIX4PMState *s = PIIX4_PM(hotplug_dev);
381
382 if (s->acpi_memory_hotplug.is_enabled &&
383 object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
384 acpi_memory_unplug_cb(&s->acpi_memory_hotplug, dev, errp);
385 } else {
386 error_setg(errp, "acpi: device unplug for not supported device"
387 " type: %s", object_get_typename(OBJECT(dev)));
388 }
c0e57a60
TC
389}
390
c24d5e0b 391static void piix4_update_bus_hotplug(PCIBus *pci_bus, void *opaque)
9e047b98
MT
392{
393 PIIX4PMState *s = opaque;
c24d5e0b
IM
394
395 qbus_set_hotplug_handler(BUS(pci_bus), DEVICE(s), &error_abort);
9e047b98
MT
396}
397
9e8dd451 398static void piix4_pm_machine_ready(Notifier *n, void *opaque)
6141dbfe
PB
399{
400 PIIX4PMState *s = container_of(n, PIIX4PMState, machine_ready);
6a6b5580
AF
401 PCIDevice *d = PCI_DEVICE(s);
402 MemoryRegion *io_as = pci_address_space_io(d);
6141dbfe
PB
403 uint8_t *pci_conf;
404
6a6b5580 405 pci_conf = d->config;
b6f32962 406 pci_conf[0x5f] = 0x10 |
3ce10901 407 (memory_region_present(io_as, 0x378) ? 0x80 : 0);
6141dbfe 408 pci_conf[0x63] = 0x60;
3ce10901
PB
409 pci_conf[0x67] = (memory_region_present(io_as, 0x3f8) ? 0x08 : 0) |
410 (memory_region_present(io_as, 0x2f8) ? 0x90 : 0);
9e047b98
MT
411
412 if (s->use_acpi_pci_hotplug) {
413 pci_for_each_bus(d->bus, piix4_update_bus_hotplug, s);
e358edc8
IM
414 } else {
415 piix4_update_bus_hotplug(d->bus, s);
9e047b98 416 }
6141dbfe
PB
417}
418
277e9340
MT
419static void piix4_pm_add_propeties(PIIX4PMState *s)
420{
421 static const uint8_t acpi_enable_cmd = ACPI_ENABLE;
422 static const uint8_t acpi_disable_cmd = ACPI_DISABLE;
423 static const uint32_t gpe0_blk = GPE_BASE;
424 static const uint32_t gpe0_blk_len = GPE_LEN;
425 static const uint16_t sci_int = 9;
426
427 object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_ENABLE_CMD,
428 &acpi_enable_cmd, NULL);
429 object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_DISABLE_CMD,
430 &acpi_disable_cmd, NULL);
431 object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK,
432 &gpe0_blk, NULL);
433 object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK_LEN,
434 &gpe0_blk_len, NULL);
435 object_property_add_uint16_ptr(OBJECT(s), ACPI_PM_PROP_SCI_INT,
436 &sci_int, NULL);
437 object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_PM_IO_BASE,
438 &s->io_base, NULL);
439}
440
9af21dbe 441static void piix4_pm_realize(PCIDevice *dev, Error **errp)
93d89f63 442{
74e445f6 443 PIIX4PMState *s = PIIX4_PM(dev);
93d89f63
IY
444 uint8_t *pci_conf;
445
6a6b5580 446 pci_conf = dev->config;
93d89f63
IY
447 pci_conf[0x06] = 0x80;
448 pci_conf[0x07] = 0x02;
93d89f63 449 pci_conf[0x09] = 0x00;
93d89f63
IY
450 pci_conf[0x3d] = 0x01; // interrupt pin 1
451
93d89f63 452 /* APM */
42d8a3cf 453 apm_init(dev, &s->apm, apm_ctrl_changed, s);
93d89f63 454
93d89f63
IY
455 if (s->kvm_enabled) {
456 /* Mark SMM as already inited to prevent SMM from running. KVM does not
457 * support SMM mode. */
458 pci_conf[0x5B] = 0x02;
459 }
460
461 /* XXX: which specification is used ? The i82731AB has different
462 mappings */
e8ec0571
IY
463 pci_conf[0x90] = s->smb_io_base | 1;
464 pci_conf[0x91] = s->smb_io_base >> 8;
93d89f63 465 pci_conf[0xd2] = 0x09;
74e445f6 466 pm_smbus_init(DEVICE(dev), &s->smb);
24fe083d 467 memory_region_set_enabled(&s->smb.io, pci_conf[0xd2] & 1);
56e5b2a1
GH
468 memory_region_add_subregion(pci_address_space_io(dev),
469 s->smb_io_base, &s->smb.io);
93d89f63 470
64bde0f3 471 memory_region_init(&s->io, OBJECT(s), "piix4-pm", 64);
af11110b 472 memory_region_set_enabled(&s->io, false);
56e5b2a1
GH
473 memory_region_add_subregion(pci_address_space_io(dev),
474 0, &s->io);
93d89f63 475
77d58b1e 476 acpi_pm_tmr_init(&s->ar, pm_tmr_timer, &s->io);
b5a7c024 477 acpi_pm1_evt_init(&s->ar, pm_tmr_timer, &s->io);
9a10bbb4 478 acpi_pm1_cnt_init(&s->ar, &s->io, s->disable_s3, s->disable_s4, s->s4_val);
355bf2e5 479 acpi_gpe_init(&s->ar, GPE_LEN);
93d89f63 480
d010f91c
IM
481 s->powerdown_notifier.notify = piix4_pm_powerdown_req;
482 qemu_register_powerdown_notifier(&s->powerdown_notifier);
93d89f63 483
6141dbfe
PB
484 s->machine_ready.notify = piix4_pm_machine_ready;
485 qemu_add_machine_init_done_notifier(&s->machine_ready);
e8ec0571 486 qemu_register_reset(piix4_reset, s);
56e5b2a1
GH
487
488 piix4_acpi_system_hot_add_init(pci_address_space_io(dev), dev->bus, s);
e8ec0571 489
277e9340 490 piix4_pm_add_propeties(s);
e8ec0571
IY
491}
492
277e9340
MT
493Object *piix4_pm_find(void)
494{
495 bool ambig;
496 Object *o = object_resolve_path_type("", TYPE_PIIX4_PM, &ambig);
497
498 if (ambig || !o) {
499 return NULL;
500 }
501 return o;
502}
503
a5c82852
AF
504I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
505 qemu_irq sci_irq, qemu_irq smi_irq,
6e7d8249 506 int kvm_enabled, DeviceState **piix4_pm)
e8ec0571 507{
74e445f6 508 DeviceState *dev;
e8ec0571
IY
509 PIIX4PMState *s;
510
74e445f6
PC
511 dev = DEVICE(pci_create(bus, devfn, TYPE_PIIX4_PM));
512 qdev_prop_set_uint32(dev, "smb_io_base", smb_io_base);
781bbd6b
IM
513 if (piix4_pm) {
514 *piix4_pm = dev;
515 }
93d89f63 516
74e445f6 517 s = PIIX4_PM(dev);
93d89f63 518 s->irq = sci_irq;
93d89f63 519 s->smi_irq = smi_irq;
e8ec0571 520 s->kvm_enabled = kvm_enabled;
91ab2ed7
IM
521 if (xen_enabled()) {
522 s->use_acpi_pci_hotplug = false;
523 }
e8ec0571 524
74e445f6 525 qdev_init_nofail(dev);
93d89f63
IY
526
527 return s->smb.smbus;
528}
529
b65b93f2 530static uint64_t gpe_readb(void *opaque, hwaddr addr, unsigned width)
93d89f63 531{
633aa0ac 532 PIIX4PMState *s = opaque;
355bf2e5 533 uint32_t val = acpi_gpe_ioport_readb(&s->ar, addr);
93d89f63 534
ba275adb 535 PIIX4_DPRINTF("gpe read %" HWADDR_PRIx " == %" PRIu32 "\n", addr, val);
93d89f63
IY
536 return val;
537}
538
b65b93f2
GH
539static void gpe_writeb(void *opaque, hwaddr addr, uint64_t val,
540 unsigned width)
93d89f63 541{
633aa0ac 542 PIIX4PMState *s = opaque;
633aa0ac 543
355bf2e5 544 acpi_gpe_ioport_writeb(&s->ar, addr, val);
06313503 545 acpi_update_sci(&s->ar, s->irq);
93d89f63 546
ba275adb 547 PIIX4_DPRINTF("gpe write %" HWADDR_PRIx " <== %" PRIu64 "\n", addr, val);
93d89f63
IY
548}
549
b65b93f2
GH
550static const MemoryRegionOps piix4_gpe_ops = {
551 .read = gpe_readb,
552 .write = gpe_writeb,
553 .valid.min_access_size = 1,
554 .valid.max_access_size = 4,
555 .impl.min_access_size = 1,
556 .impl.max_access_size = 1,
557 .endianness = DEVICE_LITTLE_ENDIAN,
558};
559
56e5b2a1
GH
560static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
561 PCIBus *bus, PIIX4PMState *s)
93d89f63 562{
64bde0f3
PB
563 memory_region_init_io(&s->io_gpe, OBJECT(s), &piix4_gpe_ops, s,
564 "acpi-gpe0", GPE_LEN);
56e5b2a1 565 memory_region_add_subregion(parent, GPE_BASE, &s->io_gpe);
ac404095 566
78c2d872 567 acpi_pcihp_init(OBJECT(s), &s->acpi_pci_hotplug, bus, parent,
e358edc8 568 s->use_acpi_pci_hotplug);
b8622725 569
411b5db8
GZ
570 acpi_cpu_hotplug_init(parent, OBJECT(s), &s->gpe_cpu,
571 PIIX4_CPU_HOTPLUG_IO_BASE);
34774320
IM
572
573 if (s->acpi_memory_hotplug.is_enabled) {
574 acpi_memory_hotplug_init(parent, OBJECT(s), &s->acpi_memory_hotplug);
575 }
93d89f63 576}
5fdae20c 577
43f50410
IM
578static void piix4_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
579{
580 PIIX4PMState *s = PIIX4_PM(adev);
581
582 acpi_memory_ospm_status(&s->acpi_memory_hotplug, list);
583}
584
5fdae20c
IM
585static Property piix4_pm_properties[] = {
586 DEFINE_PROP_UINT32("smb_io_base", PIIX4PMState, smb_io_base, 0),
587 DEFINE_PROP_UINT8(ACPI_PM_PROP_S3_DISABLED, PIIX4PMState, disable_s3, 0),
588 DEFINE_PROP_UINT8(ACPI_PM_PROP_S4_DISABLED, PIIX4PMState, disable_s4, 0),
589 DEFINE_PROP_UINT8(ACPI_PM_PROP_S4_VAL, PIIX4PMState, s4_val, 2),
590 DEFINE_PROP_BOOL("acpi-pci-hotplug-with-bridge-support", PIIX4PMState,
591 use_acpi_pci_hotplug, true),
34774320
IM
592 DEFINE_PROP_BOOL("memory-hotplug-support", PIIX4PMState,
593 acpi_memory_hotplug.is_enabled, true),
5fdae20c
IM
594 DEFINE_PROP_END_OF_LIST(),
595};
596
597static void piix4_pm_class_init(ObjectClass *klass, void *data)
598{
599 DeviceClass *dc = DEVICE_CLASS(klass);
600 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
c24d5e0b 601 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
43f50410 602 AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_CLASS(klass);
5fdae20c 603
9af21dbe 604 k->realize = piix4_pm_realize;
5fdae20c
IM
605 k->config_write = pm_write_config;
606 k->vendor_id = PCI_VENDOR_ID_INTEL;
607 k->device_id = PCI_DEVICE_ID_INTEL_82371AB_3;
608 k->revision = 0x03;
609 k->class_id = PCI_CLASS_BRIDGE_OTHER;
610 dc->desc = "PM";
611 dc->vmsd = &vmstate_acpi;
612 dc->props = piix4_pm_properties;
613 /*
614 * Reason: part of PIIX4 southbridge, needs to be wired up,
615 * e.g. by mips_malta_init()
616 */
617 dc->cannot_instantiate_with_device_add_yet = true;
2897ae02 618 dc->hotpluggable = false;
f1adc360 619 hc->plug = piix4_device_plug_cb;
14d5a28f 620 hc->unplug_request = piix4_device_unplug_request_cb;
c0e57a60 621 hc->unplug = piix4_device_unplug_cb;
43f50410 622 adevc->ospm_status = piix4_ospm_status;
5fdae20c
IM
623}
624
625static const TypeInfo piix4_pm_info = {
626 .name = TYPE_PIIX4_PM,
627 .parent = TYPE_PCI_DEVICE,
628 .instance_size = sizeof(PIIX4PMState),
629 .class_init = piix4_pm_class_init,
c24d5e0b
IM
630 .interfaces = (InterfaceInfo[]) {
631 { TYPE_HOTPLUG_HANDLER },
43f50410 632 { TYPE_ACPI_DEVICE_IF },
c24d5e0b
IM
633 { }
634 }
5fdae20c
IM
635};
636
637static void piix4_pm_register_types(void)
638{
639 type_register_static(&piix4_pm_info);
640}
641
642type_init(piix4_pm_register_types)
This page took 0.490618 seconds and 4 git commands to generate.