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