blob: 63d2113b86566e7a3596d7b64c09f416f40ab496 [file] [log] [blame]
Isaku Yamahata93d89f62010-05-14 16:29:02 +09001/*
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
Chetan Pant61f3c912020-10-23 12:44:24 +00008 * License version 2.1 as published by the Free Software Foundation.
Isaku Yamahata93d89f62010-05-14 16:29:02 +09009 *
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/>
Paolo Bonzini6b620ca2012-01-13 17:44:23 +010017 *
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.
Isaku Yamahata93d89f62010-05-14 16:29:02 +090020 */
Markus Armbruster71e8a912019-08-12 07:23:38 +020021
Peter Maydellb6a0aa02016-01-26 18:17:03 +000022#include "qemu/osdep.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010023#include "hw/i386/pc.h"
Markus Armbruster64552b62019-08-12 07:23:42 +020024#include "hw/irq.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010025#include "hw/isa/apm.h"
26#include "hw/i2c/pm_smbus.h"
Paolo Bonzini83c9f4c2013-02-04 15:40:22 +010027#include "hw/pci/pci.h"
Markus Armbrustera27bd6c2019-08-12 07:23:51 +020028#include "hw/qdev-properties.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010029#include "hw/acpi/acpi.h"
Mark Cave-Ayland2bfd0842022-05-28 10:02:11 +010030#include "hw/acpi/pcihp.h"
31#include "hw/acpi/piix4.h"
Markus Armbruster54d31232019-08-12 07:23:59 +020032#include "sysemu/runstate.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010033#include "sysemu/sysemu.h"
Philippe Mathieu-Daudéda278d52020-05-08 12:02:22 +020034#include "sysemu/xen.h"
Markus Armbrusterda34e652016-03-14 09:01:28 +010035#include "qapi/error.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010036#include "qemu/range.h"
Igor Mammedov81cea5e2014-01-09 17:36:31 +010037#include "hw/acpi/cpu_hotplug.h"
Igor Mammedov5e1b5d92016-06-14 16:02:06 +020038#include "hw/acpi/cpu.h"
Igor Mammedovc24d5e02014-02-05 16:36:49 +010039#include "hw/hotplug.h"
Igor Mammedov34774322014-06-02 15:25:20 +020040#include "hw/mem/pc-dimm.h"
Philippe Mathieu-Daudé132a9082020-02-28 12:46:46 +010041#include "hw/mem/nvdimm.h"
Igor Mammedov34774322014-06-02 15:25:20 +020042#include "hw/acpi/memory_hotplug.h"
Igor Mammedov43f50412014-06-16 19:12:27 +020043#include "hw/acpi/acpi_dev_interface.h"
Markus Armbrusterd6454272019-08-12 07:23:45 +020044#include "migration/vmstate.h"
Markus Armbruster2e5b09f2019-07-09 17:20:52 +020045#include "hw/core/cpu.h"
Markus Armbrusterb37d56e2019-04-02 18:18:58 +020046#include "trace.h"
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040047#include "qom/object.h"
Isaku Yamahata50d8ff82010-05-14 16:29:22 +090048
Isaku Yamahataac404092010-05-14 16:29:20 +090049#define GPE_BASE 0xafe0
Isaku Yamahata23910d32011-03-25 19:54:41 +090050#define GPE_LEN 4
Gerd Hoffmannc1776842012-11-23 16:03:19 +010051
Julia Suvorovacaf108b2021-07-13 02:42:00 +020052#define ACPI_PCIHP_ADDR_PIIX4 0xae00
53
Isaku Yamahataac404092010-05-14 16:29:20 +090054struct pci_status {
Alex Williamson7faa8072012-04-05 11:07:15 -060055 uint32_t up; /* deprecated, maintained for migration compatibility */
Isaku Yamahataac404092010-05-14 16:29:20 +090056 uint32_t down;
57};
58
Gerd Hoffmann56e5b2a2012-12-11 09:40:45 +010059static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
60 PCIBus *bus, PIIX4PMState *s);
Isaku Yamahataac404092010-05-14 16:29:20 +090061
Isaku Yamahata93d89f62010-05-14 16:29:02 +090062#define ACPI_ENABLE 0xf1
63#define ACPI_DISABLE 0xf0
64
Gerd Hoffmann355bf2e2012-02-23 13:45:16 +010065static void pm_tmr_timer(ACPIREGS *ar)
Isaku Yamahata93d89f62010-05-14 16:29:02 +090066{
Gerd Hoffmann355bf2e2012-02-23 13:45:16 +010067 PIIX4PMState *s = container_of(ar, PIIX4PMState, ar);
Igor Mammedov06313502013-12-13 17:22:07 +010068 acpi_update_sci(&s->ar, s->irq);
Isaku Yamahata93d89f62010-05-14 16:29:02 +090069}
70
Isaku Yamahata93d89f62010-05-14 16:29:02 +090071static void apm_ctrl_changed(uint32_t val, void *arg)
72{
73 PIIX4PMState *s = arg;
Andreas Färber6a6b5582013-06-30 14:40:37 +020074 PCIDevice *d = PCI_DEVICE(s);
Isaku Yamahata93d89f62010-05-14 16:29:02 +090075
76 /* ACPI specs 3.0, 4.7.2.5 */
Gerd Hoffmann355bf2e2012-02-23 13:45:16 +010077 acpi_pm1_cnt_update(&s->ar, val == ACPI_ENABLE, val == ACPI_DISABLE);
Paolo Bonziniafd68952015-06-18 18:28:41 +020078 if (val == ACPI_ENABLE || val == ACPI_DISABLE) {
79 return;
80 }
Isaku Yamahata93d89f62010-05-14 16:29:02 +090081
Andreas Färber6a6b5582013-06-30 14:40:37 +020082 if (d->config[0x5b] & (1 << 1)) {
Isaku Yamahata93d89f62010-05-14 16:29:02 +090083 if (s->smi_irq) {
84 qemu_irq_raise(s->smi_irq);
85 }
86 }
87}
88
Isaku Yamahata93d89f62010-05-14 16:29:02 +090089static void pm_io_space_update(PIIX4PMState *s)
90{
Andreas Färber6a6b5582013-06-30 14:40:37 +020091 PCIDevice *d = PCI_DEVICE(s);
Isaku Yamahata93d89f62010-05-14 16:29:02 +090092
Michael S. Tsirkin277e9342013-07-24 18:56:11 +030093 s->io_base = le32_to_cpu(*(uint32_t *)(d->config + 0x40));
94 s->io_base &= 0xffc0;
Isaku Yamahata93d89f62010-05-14 16:29:02 +090095
Gerd Hoffmannaf111102012-11-22 11:34:44 +010096 memory_region_transaction_begin();
Andreas Färber6a6b5582013-06-30 14:40:37 +020097 memory_region_set_enabled(&s->io, d->config[0x80] & 1);
Michael S. Tsirkin277e9342013-07-24 18:56:11 +030098 memory_region_set_address(&s->io, s->io_base);
Gerd Hoffmannaf111102012-11-22 11:34:44 +010099 memory_region_transaction_commit();
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900100}
101
Gerd Hoffmann24fe0832012-11-23 14:58:04 +0100102static void smbus_io_space_update(PIIX4PMState *s)
103{
Andreas Färber6a6b5582013-06-30 14:40:37 +0200104 PCIDevice *d = PCI_DEVICE(s);
105
106 s->smb_io_base = le32_to_cpu(*(uint32_t *)(d->config + 0x90));
Gerd Hoffmann24fe0832012-11-23 14:58:04 +0100107 s->smb_io_base &= 0xffc0;
108
109 memory_region_transaction_begin();
Andreas Färber6a6b5582013-06-30 14:40:37 +0200110 memory_region_set_enabled(&s->smb.io, d->config[0xd2] & 1);
Gerd Hoffmann24fe0832012-11-23 14:58:04 +0100111 memory_region_set_address(&s->smb.io, s->smb_io_base);
112 memory_region_transaction_commit();
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900113}
114
115static void pm_write_config(PCIDevice *d,
116 uint32_t address, uint32_t val, int len)
117{
118 pci_default_write_config(d, address, val, len);
Gerd Hoffmann24fe0832012-11-23 14:58:04 +0100119 if (range_covers_byte(address, len, 0x80) ||
120 ranges_overlap(address, len, 0x40, 4)) {
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900121 pm_io_space_update((PIIX4PMState *)d);
Gerd Hoffmann24fe0832012-11-23 14:58:04 +0100122 }
123 if (range_covers_byte(address, len, 0xd2) ||
124 ranges_overlap(address, len, 0x90, 4)) {
125 smbus_io_space_update((PIIX4PMState *)d);
126 }
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900127}
128
129static int vmstate_acpi_post_load(void *opaque, int version_id)
130{
131 PIIX4PMState *s = opaque;
132
133 pm_io_space_update(s);
Corey Minyard2b4e5732018-11-26 12:28:44 -0600134 smbus_io_space_update(s);
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900135 return 0;
136}
137
Isaku Yamahata23910d32011-03-25 19:54:41 +0900138#define VMSTATE_GPE_ARRAY(_field, _state) \
139 { \
140 .name = (stringify(_field)), \
141 .version_id = 0, \
Isaku Yamahata23910d32011-03-25 19:54:41 +0900142 .info = &vmstate_info_uint16, \
143 .size = sizeof(uint16_t), \
Marcelo Tosattib0b873a2012-10-30 21:14:19 -0200144 .flags = VMS_SINGLE | VMS_POINTER, \
Isaku Yamahata23910d32011-03-25 19:54:41 +0900145 .offset = vmstate_offset_pointer(_state, _field, uint8_t), \
146 }
147
Alex Williamson4cf3e6f2010-06-02 10:58:29 -0600148static const VMStateDescription vmstate_gpe = {
149 .name = "gpe",
150 .version_id = 1,
151 .minimum_version_id = 1,
Juan Quintelad49805a2014-04-16 15:32:32 +0200152 .fields = (VMStateField[]) {
Isaku Yamahata23910d32011-03-25 19:54:41 +0900153 VMSTATE_GPE_ARRAY(sts, ACPIGPE),
154 VMSTATE_GPE_ARRAY(en, ACPIGPE),
Alex Williamson4cf3e6f2010-06-02 10:58:29 -0600155 VMSTATE_END_OF_LIST()
156 }
157};
158
159static const VMStateDescription vmstate_pci_status = {
160 .name = "pci_status",
161 .version_id = 1,
162 .minimum_version_id = 1,
Juan Quintelad49805a2014-04-16 15:32:32 +0200163 .fields = (VMStateField[]) {
Igor Mammedove358edc2014-02-03 11:45:01 +0100164 VMSTATE_UINT32(up, struct AcpiPciHpPciStatus),
165 VMSTATE_UINT32(down, struct AcpiPciHpPciStatus),
Alex Williamson4cf3e6f2010-06-02 10:58:29 -0600166 VMSTATE_END_OF_LIST()
167 }
168};
169
Ani Sinha0affda02020-06-16 12:31:39 +0000170static bool vmstate_test_use_acpi_hotplug_bridge(void *opaque, int version_id)
Michael S. Tsirkin9e047b92013-10-14 18:01:20 +0300171{
172 PIIX4PMState *s = opaque;
Igor Mammedov6536e422023-03-02 17:15:42 +0100173 return s->acpi_pci_hotplug.use_acpi_hotplug_bridge;
Michael S. Tsirkin9e047b92013-10-14 18:01:20 +0300174}
175
Ani Sinha0affda02020-06-16 12:31:39 +0000176static bool vmstate_test_no_use_acpi_hotplug_bridge(void *opaque,
177 int version_id)
Michael S. Tsirkin9e047b92013-10-14 18:01:20 +0300178{
179 PIIX4PMState *s = opaque;
Igor Mammedov6536e422023-03-02 17:15:42 +0100180 return !s->acpi_pci_hotplug.use_acpi_hotplug_bridge;
Michael S. Tsirkin9e047b92013-10-14 18:01:20 +0300181}
182
Igor Mammedovf816a622014-06-02 15:25:23 +0200183static bool vmstate_test_use_memhp(void *opaque)
184{
185 PIIX4PMState *s = opaque;
186 return s->acpi_memory_hotplug.is_enabled;
187}
188
189static const VMStateDescription vmstate_memhp_state = {
190 .name = "piix4_pm/memhp",
191 .version_id = 1,
192 .minimum_version_id = 1,
Juan Quintela5cd8cad2014-09-23 14:09:54 +0200193 .needed = vmstate_test_use_memhp,
Igor Mammedovf816a622014-06-02 15:25:23 +0200194 .fields = (VMStateField[]) {
195 VMSTATE_MEMORY_HOTPLUG(acpi_memory_hotplug, PIIX4PMState),
196 VMSTATE_END_OF_LIST()
197 }
198};
199
Igor Mammedov679dd1a2016-06-15 11:25:23 +0200200static bool vmstate_test_use_cpuhp(void *opaque)
201{
202 PIIX4PMState *s = opaque;
203 return !s->cpu_hotplug_legacy;
204}
205
206static int vmstate_cpuhp_pre_load(void *opaque)
207{
208 Object *obj = OBJECT(opaque);
Markus Armbruster5325cc32020-07-07 18:05:54 +0200209 object_property_set_bool(obj, "cpu-hotplug-legacy", false, &error_abort);
Igor Mammedov679dd1a2016-06-15 11:25:23 +0200210 return 0;
211}
212
213static const VMStateDescription vmstate_cpuhp_state = {
214 .name = "piix4_pm/cpuhp",
215 .version_id = 1,
216 .minimum_version_id = 1,
Igor Mammedov679dd1a2016-06-15 11:25:23 +0200217 .needed = vmstate_test_use_cpuhp,
218 .pre_load = vmstate_cpuhp_pre_load,
219 .fields = (VMStateField[]) {
220 VMSTATE_CPU_HOTPLUG(cpuhp_state, PIIX4PMState),
221 VMSTATE_END_OF_LIST()
222 }
223};
224
Corey Minyard4ab2f2a2016-12-22 12:28:23 -0600225static bool piix4_vmstate_need_smbus(void *opaque, int version_id)
226{
227 return pm_smbus_vmstate_needed();
228}
229
Dr. David Alan Gilberta83c2842022-04-06 14:58:12 -0400230/*
231 * This is a fudge to turn off the acpi_index field,
232 * whose test was always broken on piix4 with 6.2 and older machine types.
233 */
234static bool vmstate_test_migrate_acpi_index(void *opaque, int version_id)
235{
236 PIIX4PMState *s = PIIX4_PM(opaque);
Igor Mammedov6536e422023-03-02 17:15:42 +0100237 return s->acpi_pci_hotplug.use_acpi_hotplug_bridge &&
238 !s->not_migrate_acpi_index;
Dr. David Alan Gilberta83c2842022-04-06 14:58:12 -0400239}
240
Marcelo Tosattib0b873a2012-10-30 21:14:19 -0200241/* qemu-kvm 1.2 uses version 3 but advertised as 2
242 * To support incoming qemu-kvm 1.2 migration, change version_id
243 * and minimum_version_id to 2 below (which breaks migration from
244 * qemu 1.2).
245 *
246 */
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900247static const VMStateDescription vmstate_acpi = {
248 .name = "piix4_pm",
Marcelo Tosattib0b873a2012-10-30 21:14:19 -0200249 .version_id = 3,
250 .minimum_version_id = 3,
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900251 .post_load = vmstate_acpi_post_load,
Juan Quintelad49805a2014-04-16 15:32:32 +0200252 .fields = (VMStateField[]) {
Andreas Färber6a6b5582013-06-30 14:40:37 +0200253 VMSTATE_PCI_DEVICE(parent_obj, PIIX4PMState),
Gerd Hoffmann355bf2e2012-02-23 13:45:16 +0100254 VMSTATE_UINT16(ar.pm1.evt.sts, PIIX4PMState),
255 VMSTATE_UINT16(ar.pm1.evt.en, PIIX4PMState),
256 VMSTATE_UINT16(ar.pm1.cnt.cnt, PIIX4PMState),
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900257 VMSTATE_STRUCT(apm, PIIX4PMState, 0, vmstate_apm, APMState),
Corey Minyard4ab2f2a2016-12-22 12:28:23 -0600258 VMSTATE_STRUCT_TEST(smb, PIIX4PMState, piix4_vmstate_need_smbus, 3,
259 pmsmb_vmstate, PMSMBus),
Paolo Bonzinie7206772015-01-08 10:18:59 +0100260 VMSTATE_TIMER_PTR(ar.tmr.timer, PIIX4PMState),
Gerd Hoffmann355bf2e2012-02-23 13:45:16 +0100261 VMSTATE_INT64(ar.tmr.overflow_time, PIIX4PMState),
262 VMSTATE_STRUCT(ar.gpe, PIIX4PMState, 2, vmstate_gpe, ACPIGPE),
Igor Mammedove358edc2014-02-03 11:45:01 +0100263 VMSTATE_STRUCT_TEST(
264 acpi_pci_hotplug.acpi_pcihp_pci_status[ACPI_PCIHP_BSEL_DEFAULT],
265 PIIX4PMState,
Ani Sinha0affda02020-06-16 12:31:39 +0000266 vmstate_test_no_use_acpi_hotplug_bridge,
Igor Mammedove358edc2014-02-03 11:45:01 +0100267 2, vmstate_pci_status,
268 struct AcpiPciHpPciStatus),
Michael S. Tsirkin9e047b92013-10-14 18:01:20 +0300269 VMSTATE_PCI_HOTPLUG(acpi_pci_hotplug, PIIX4PMState,
Igor Mammedovb32bd762021-03-15 14:00:58 -0400270 vmstate_test_use_acpi_hotplug_bridge,
Dr. David Alan Gilberta83c2842022-04-06 14:58:12 -0400271 vmstate_test_migrate_acpi_index),
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900272 VMSTATE_END_OF_LIST()
Igor Mammedovf816a622014-06-02 15:25:23 +0200273 },
Juan Quintela5cd8cad2014-09-23 14:09:54 +0200274 .subsections = (const VMStateDescription*[]) {
275 &vmstate_memhp_state,
Igor Mammedov679dd1a2016-06-15 11:25:23 +0200276 &vmstate_cpuhp_state,
Juan Quintela5cd8cad2014-09-23 14:09:54 +0200277 NULL
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900278 }
279};
280
Philippe Mathieu-Daudé217e8ef2019-10-10 15:15:20 +0200281static void piix4_pm_reset(DeviceState *dev)
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900282{
Philippe Mathieu-Daudé217e8ef2019-10-10 15:15:20 +0200283 PIIX4PMState *s = PIIX4_PM(dev);
Andreas Färber6a6b5582013-06-30 14:40:37 +0200284 PCIDevice *d = PCI_DEVICE(s);
285 uint8_t *pci_conf = d->config;
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900286
287 pci_conf[0x58] = 0;
288 pci_conf[0x59] = 0;
289 pci_conf[0x5a] = 0;
290 pci_conf[0x5b] = 0;
291
Gleb Natapov4d09d372012-08-07 15:52:03 +0300292 pci_conf[0x40] = 0x01; /* PM io base read only bit */
293 pci_conf[0x80] = 0;
294
Paolo Bonzini61e66c62015-06-18 18:30:17 +0200295 if (!s->smm_enabled) {
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900296 /* Mark SMM as already inited (until KVM supports SMM). */
297 pci_conf[0x5B] = 0x02;
298 }
Isaku Yamahata0fd74322021-03-23 13:52:24 -0700299
300 acpi_pm1_evt_reset(&s->ar);
301 acpi_pm1_cnt_reset(&s->ar);
302 acpi_pm_tmr_reset(&s->ar);
303 acpi_gpe_reset(&s->ar);
304 acpi_update_sci(&s->ar, s->irq);
305
Michael S. Tsirkinc046e8c2013-09-11 13:33:31 +0300306 pm_io_space_update(s);
Igor Mammedov6536e422023-03-02 17:15:42 +0100307 if (s->acpi_pci_hotplug.use_acpi_hotplug_bridge ||
308 s->acpi_pci_hotplug.use_acpi_root_pci_hotplug) {
309 acpi_pcihp_reset(&s->acpi_pci_hotplug);
Igor Mammedov45284cf2023-01-12 15:02:42 +0100310 }
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900311}
312
Igor Mammedovd010f912012-09-05 23:06:22 +0200313static void piix4_pm_powerdown_req(Notifier *n, void *opaque)
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900314{
Igor Mammedovd010f912012-09-05 23:06:22 +0200315 PIIX4PMState *s = container_of(n, PIIX4PMState, powerdown_notifier);
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900316
Gerd Hoffmann355bf2e2012-02-23 13:45:16 +0100317 assert(s != NULL);
318 acpi_pm1_evt_power_down(&s->ar);
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900319}
320
David Hildenbrandec266f42018-12-12 10:16:17 +0100321static void piix4_device_pre_plug_cb(HotplugHandler *hotplug_dev,
322 DeviceState *dev, Error **errp)
323{
Wei Yang9040e6d2019-03-01 11:35:48 +0800324 PIIX4PMState *s = PIIX4_PM(hotplug_dev);
325
David Hildenbrandec266f42018-12-12 10:16:17 +0100326 if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
327 acpi_pcihp_device_pre_plug_cb(hotplug_dev, dev, errp);
Wei Yang9040e6d2019-03-01 11:35:48 +0800328 } else if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
329 if (!s->acpi_memory_hotplug.is_enabled) {
330 error_setg(errp,
331 "memory hotplug is not enabled: %s.memory-hotplug-support "
332 "is not set", object_get_typename(OBJECT(s)));
333 }
334 } else if (
David Hildenbrandec266f42018-12-12 10:16:17 +0100335 !object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
336 error_setg(errp, "acpi: device pre plug request for not supported"
337 " device type: %s", object_get_typename(OBJECT(dev)));
338 }
339}
340
Igor Mammedovf1adc362014-06-02 15:25:19 +0200341static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,
342 DeviceState *dev, Error **errp)
Michael S. Tsirkin9e047b92013-10-14 18:01:20 +0300343{
Igor Mammedovc24d5e02014-02-05 16:36:49 +0100344 PIIX4PMState *s = PIIX4_PM(hotplug_dev);
Igor Mammedovf1adc362014-06-02 15:25:19 +0200345
Wei Yang9040e6d2019-03-01 11:35:48 +0800346 if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
Xiao Guangrong75f27492016-11-07 19:13:38 +0800347 if (object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM)) {
348 nvdimm_acpi_plug_cb(hotplug_dev, dev);
349 } else {
350 acpi_memory_plug_cb(hotplug_dev, &s->acpi_memory_hotplug,
351 dev, errp);
352 }
Igor Mammedov34774322014-06-02 15:25:20 +0200353 } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
Anthony PERARD2bed1ba2017-09-06 14:40:33 +0100354 acpi_pcihp_device_plug_cb(hotplug_dev, &s->acpi_pci_hotplug, dev, errp);
Igor Mammedov5e1b5d92016-06-14 16:02:06 +0200355 } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
356 if (s->cpu_hotplug_legacy) {
357 legacy_acpi_cpu_plug_cb(hotplug_dev, &s->gpe_cpu, dev, errp);
358 } else {
359 acpi_cpu_plug_cb(hotplug_dev, &s->cpuhp_state, dev, errp);
360 }
Igor Mammedovf1adc362014-06-02 15:25:19 +0200361 } else {
David Hildenbrandec266f42018-12-12 10:16:17 +0100362 g_assert_not_reached();
Igor Mammedovf1adc362014-06-02 15:25:19 +0200363 }
Michael S. Tsirkin9e047b92013-10-14 18:01:20 +0300364}
365
Igor Mammedov14d5a282014-09-26 09:28:19 +0000366static void piix4_device_unplug_request_cb(HotplugHandler *hotplug_dev,
367 DeviceState *dev, Error **errp)
Igor Mammedovc24d5e02014-02-05 16:36:49 +0100368{
369 PIIX4PMState *s = PIIX4_PM(hotplug_dev);
Igor Mammedovf1adc362014-06-02 15:25:19 +0200370
Tang Chen64fec582015-04-27 16:47:17 +0800371 if (s->acpi_memory_hotplug.is_enabled &&
372 object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
Igor Mammedov0058c082016-05-31 12:01:17 +0200373 acpi_memory_unplug_request_cb(hotplug_dev, &s->acpi_memory_hotplug,
Tang Chen64fec582015-04-27 16:47:17 +0800374 dev, errp);
375 } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
David Hildenbrandc97adf32018-12-12 10:16:19 +0100376 acpi_pcihp_device_unplug_request_cb(hotplug_dev, &s->acpi_pci_hotplug,
377 dev, errp);
Igor Mammedov8872c252016-06-14 16:14:02 +0200378 } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU) &&
379 !s->cpu_hotplug_legacy) {
380 acpi_cpu_unplug_request_cb(hotplug_dev, &s->cpuhp_state, dev, errp);
Igor Mammedovf1adc362014-06-02 15:25:19 +0200381 } else {
382 error_setg(errp, "acpi: device unplug request for not supported device"
383 " type: %s", object_get_typename(OBJECT(dev)));
384 }
Igor Mammedovc24d5e02014-02-05 16:36:49 +0100385}
386
Tang Chenc0e57a62015-01-28 15:45:41 +0800387static void piix4_device_unplug_cb(HotplugHandler *hotplug_dev,
388 DeviceState *dev, Error **errp)
389{
Tang Chenf7d3e292015-04-27 16:47:18 +0800390 PIIX4PMState *s = PIIX4_PM(hotplug_dev);
391
392 if (s->acpi_memory_hotplug.is_enabled &&
393 object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
394 acpi_memory_unplug_cb(&s->acpi_memory_hotplug, dev, errp);
David Hildenbrandc97adf32018-12-12 10:16:19 +0100395 } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
396 acpi_pcihp_device_unplug_cb(hotplug_dev, &s->acpi_pci_hotplug, dev,
397 errp);
Igor Mammedov8872c252016-06-14 16:14:02 +0200398 } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU) &&
399 !s->cpu_hotplug_legacy) {
400 acpi_cpu_unplug_cb(&s->cpuhp_state, dev, errp);
Tang Chenf7d3e292015-04-27 16:47:18 +0800401 } else {
402 error_setg(errp, "acpi: device unplug for not supported device"
403 " type: %s", object_get_typename(OBJECT(dev)));
404 }
Tang Chenc0e57a62015-01-28 15:45:41 +0800405}
406
Igor Mammedovf18e29f2023-03-02 17:15:43 +0100407static bool piix4_is_hotpluggable_bus(HotplugHandler *hotplug_dev,
408 BusState *bus)
409{
410 PIIX4PMState *s = PIIX4_PM(hotplug_dev);
411 return acpi_pcihp_is_hotpluggbale_bus(&s->acpi_pci_hotplug, bus);
412}
413
Jan Kiszka9e8dd452011-06-20 14:06:26 +0200414static void piix4_pm_machine_ready(Notifier *n, void *opaque)
Paolo Bonzini6141dbf2011-07-15 17:10:15 +0200415{
416 PIIX4PMState *s = container_of(n, PIIX4PMState, machine_ready);
Andreas Färber6a6b5582013-06-30 14:40:37 +0200417 PCIDevice *d = PCI_DEVICE(s);
418 MemoryRegion *io_as = pci_address_space_io(d);
Paolo Bonzini6141dbf2011-07-15 17:10:15 +0200419 uint8_t *pci_conf;
420
Andreas Färber6a6b5582013-06-30 14:40:37 +0200421 pci_conf = d->config;
Jan Kiszkab6f32962013-06-22 08:07:01 +0200422 pci_conf[0x5f] = 0x10 |
Paolo Bonzini3ce10902013-07-02 13:40:48 +0200423 (memory_region_present(io_as, 0x378) ? 0x80 : 0);
Paolo Bonzini6141dbf2011-07-15 17:10:15 +0200424 pci_conf[0x63] = 0x60;
Paolo Bonzini3ce10902013-07-02 13:40:48 +0200425 pci_conf[0x67] = (memory_region_present(io_as, 0x3f8) ? 0x08 : 0) |
426 (memory_region_present(io_as, 0x2f8) ? 0x90 : 0);
Paolo Bonzini6141dbf2011-07-15 17:10:15 +0200427}
428
Greg Kurz5ad10372020-10-02 18:06:07 +0200429static void piix4_pm_add_properties(PIIX4PMState *s)
Michael S. Tsirkin277e9342013-07-24 18:56:11 +0300430{
431 static const uint8_t acpi_enable_cmd = ACPI_ENABLE;
432 static const uint8_t acpi_disable_cmd = ACPI_DISABLE;
433 static const uint32_t gpe0_blk = GPE_BASE;
434 static const uint32_t gpe0_blk_len = GPE_LEN;
435 static const uint16_t sci_int = 9;
436
437 object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_ENABLE_CMD,
Markus Armbrusterd2623122020-05-05 17:29:22 +0200438 &acpi_enable_cmd, OBJ_PROP_FLAG_READ);
Michael S. Tsirkin277e9342013-07-24 18:56:11 +0300439 object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_DISABLE_CMD,
Markus Armbrusterd2623122020-05-05 17:29:22 +0200440 &acpi_disable_cmd, OBJ_PROP_FLAG_READ);
Michael S. Tsirkin277e9342013-07-24 18:56:11 +0300441 object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK,
Markus Armbrusterd2623122020-05-05 17:29:22 +0200442 &gpe0_blk, OBJ_PROP_FLAG_READ);
Michael S. Tsirkin277e9342013-07-24 18:56:11 +0300443 object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK_LEN,
Markus Armbrusterd2623122020-05-05 17:29:22 +0200444 &gpe0_blk_len, OBJ_PROP_FLAG_READ);
Michael S. Tsirkin277e9342013-07-24 18:56:11 +0300445 object_property_add_uint16_ptr(OBJECT(s), ACPI_PM_PROP_SCI_INT,
Markus Armbrusterd2623122020-05-05 17:29:22 +0200446 &sci_int, OBJ_PROP_FLAG_READ);
Michael S. Tsirkin277e9342013-07-24 18:56:11 +0300447 object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_PM_IO_BASE,
Markus Armbrusterd2623122020-05-05 17:29:22 +0200448 &s->io_base, OBJ_PROP_FLAG_READ);
Michael S. Tsirkin277e9342013-07-24 18:56:11 +0300449}
450
Markus Armbruster9af21db2015-01-19 15:52:30 +0100451static void piix4_pm_realize(PCIDevice *dev, Error **errp)
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900452{
Peter Crosthwaite74e445f2013-06-24 16:57:14 +1000453 PIIX4PMState *s = PIIX4_PM(dev);
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900454 uint8_t *pci_conf;
455
Andreas Färber6a6b5582013-06-30 14:40:37 +0200456 pci_conf = dev->config;
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900457 pci_conf[0x06] = 0x80;
458 pci_conf[0x07] = 0x02;
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900459 pci_conf[0x09] = 0x00;
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900460 pci_conf[0x3d] = 0x01; // interrupt pin 1
461
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900462 /* APM */
Julien Grall42d8a3c2012-09-19 12:50:03 +0100463 apm_init(dev, &s->apm, apm_ctrl_changed, s);
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900464
Paolo Bonzini61e66c62015-06-18 18:30:17 +0200465 if (!s->smm_enabled) {
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900466 /* Mark SMM as already inited to prevent SMM from running. KVM does not
467 * support SMM mode. */
468 pci_conf[0x5B] = 0x02;
469 }
470
471 /* XXX: which specification is used ? The i82731AB has different
472 mappings */
Isaku Yamahatae8ec0572010-05-14 16:29:18 +0900473 pci_conf[0x90] = s->smb_io_base | 1;
474 pci_conf[0x91] = s->smb_io_base >> 8;
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900475 pci_conf[0xd2] = 0x09;
Corey Minyard45726b62018-08-20 15:26:08 -0500476 pm_smbus_init(DEVICE(dev), &s->smb, true);
Gerd Hoffmann24fe0832012-11-23 14:58:04 +0100477 memory_region_set_enabled(&s->smb.io, pci_conf[0xd2] & 1);
Gerd Hoffmann56e5b2a2012-12-11 09:40:45 +0100478 memory_region_add_subregion(pci_address_space_io(dev),
479 s->smb_io_base, &s->smb.io);
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900480
Paolo Bonzini64bde0f2013-06-06 21:25:08 -0400481 memory_region_init(&s->io, OBJECT(s), "piix4-pm", 64);
Gerd Hoffmannaf111102012-11-22 11:34:44 +0100482 memory_region_set_enabled(&s->io, false);
Gerd Hoffmann56e5b2a2012-12-11 09:40:45 +0100483 memory_region_add_subregion(pci_address_space_io(dev),
484 0, &s->io);
Gerd Hoffmannaf111102012-11-22 11:34:44 +0100485
Gerd Hoffmann77d58b12012-11-22 12:12:30 +0100486 acpi_pm_tmr_init(&s->ar, pm_tmr_timer, &s->io);
Gerd Hoffmannb5a7c022012-11-22 13:25:10 +0100487 acpi_pm1_evt_init(&s->ar, pm_tmr_timer, &s->io);
Isaku Yamahata6be8cf52021-02-17 21:51:12 -0800488 acpi_pm1_cnt_init(&s->ar, &s->io, s->disable_s3, s->disable_s4, s->s4_val,
489 !s->smm_compat && !s->smm_enabled);
Gerd Hoffmann355bf2e2012-02-23 13:45:16 +0100490 acpi_gpe_init(&s->ar, GPE_LEN);
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900491
Igor Mammedovd010f912012-09-05 23:06:22 +0200492 s->powerdown_notifier.notify = piix4_pm_powerdown_req;
493 qemu_register_powerdown_notifier(&s->powerdown_notifier);
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900494
Paolo Bonzini6141dbf2011-07-15 17:10:15 +0200495 s->machine_ready.notify = piix4_pm_machine_ready;
496 qemu_add_machine_init_done_notifier(&s->machine_ready);
Gerd Hoffmann56e5b2a2012-12-11 09:40:45 +0100497
Mark Cave-Ayland3f0efca2022-05-28 10:02:11 +0100498 if (xen_enabled()) {
Igor Mammedov6536e422023-03-02 17:15:42 +0100499 s->acpi_pci_hotplug.use_acpi_hotplug_bridge = false;
Mark Cave-Ayland3f0efca2022-05-28 10:02:11 +0100500 }
501
David Gibsonfd56e062017-11-29 19:46:27 +1100502 piix4_acpi_system_hot_add_init(pci_address_space_io(dev),
503 pci_get_bus(dev), s);
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900504
Greg Kurz5ad10372020-10-02 18:06:07 +0200505 piix4_pm_add_properties(s);
Isaku Yamahatae8ec0572010-05-14 16:29:18 +0900506}
507
Mark Cave-Ayland29786d42022-05-28 10:02:11 +0100508static void piix4_pm_init(Object *obj)
509{
510 PIIX4PMState *s = PIIX4_PM(obj);
511
512 qdev_init_gpio_out(DEVICE(obj), &s->irq, 1);
Mark Cave-Aylandb49e9442022-05-28 10:02:11 +0100513 qdev_init_gpio_out_named(DEVICE(obj), &s->smi_irq, "smi-irq", 1);
Mark Cave-Ayland29786d42022-05-28 10:02:11 +0100514}
515
Gerd Hoffmannb65b93f2012-11-23 15:35:13 +0100516static uint64_t gpe_readb(void *opaque, hwaddr addr, unsigned width)
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900517{
Gleb Natapov633aa0a2010-10-17 11:45:25 +0200518 PIIX4PMState *s = opaque;
Gerd Hoffmann355bf2e2012-02-23 13:45:16 +0100519 uint32_t val = acpi_gpe_ioport_readb(&s->ar, addr);
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900520
Markus Armbrusterb37d56e2019-04-02 18:18:58 +0200521 trace_piix4_gpe_readb(addr, width, val);
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900522 return val;
523}
524
Gerd Hoffmannb65b93f2012-11-23 15:35:13 +0100525static void gpe_writeb(void *opaque, hwaddr addr, uint64_t val,
526 unsigned width)
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900527{
Gleb Natapov633aa0a2010-10-17 11:45:25 +0200528 PIIX4PMState *s = opaque;
Gleb Natapov633aa0a2010-10-17 11:45:25 +0200529
Markus Armbrusterb37d56e2019-04-02 18:18:58 +0200530 trace_piix4_gpe_writeb(addr, width, val);
Gerd Hoffmann355bf2e2012-02-23 13:45:16 +0100531 acpi_gpe_ioport_writeb(&s->ar, addr, val);
Igor Mammedov06313502013-12-13 17:22:07 +0100532 acpi_update_sci(&s->ar, s->irq);
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900533}
534
Gerd Hoffmannb65b93f2012-11-23 15:35:13 +0100535static const MemoryRegionOps piix4_gpe_ops = {
536 .read = gpe_readb,
537 .write = gpe_writeb,
538 .valid.min_access_size = 1,
539 .valid.max_access_size = 4,
540 .impl.min_access_size = 1,
541 .impl.max_access_size = 1,
542 .endianness = DEVICE_LITTLE_ENDIAN,
543};
544
Igor Mammedov16bcab92016-04-11 17:25:54 +0200545
546static bool piix4_get_cpu_hotplug_legacy(Object *obj, Error **errp)
547{
548 PIIX4PMState *s = PIIX4_PM(obj);
549
550 return s->cpu_hotplug_legacy;
551}
552
553static void piix4_set_cpu_hotplug_legacy(Object *obj, bool value, Error **errp)
554{
555 PIIX4PMState *s = PIIX4_PM(obj);
556
Igor Mammedov679dd1a2016-06-15 11:25:23 +0200557 assert(!value);
558 if (s->cpu_hotplug_legacy && value == false) {
559 acpi_switch_to_modern_cphp(&s->gpe_cpu, &s->cpuhp_state,
560 PIIX4_CPU_HOTPLUG_IO_BASE);
561 }
Igor Mammedov16bcab92016-04-11 17:25:54 +0200562 s->cpu_hotplug_legacy = value;
563}
564
Gerd Hoffmann56e5b2a2012-12-11 09:40:45 +0100565static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
566 PCIBus *bus, PIIX4PMState *s)
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900567{
Paolo Bonzini64bde0f2013-06-06 21:25:08 -0400568 memory_region_init_io(&s->io_gpe, OBJECT(s), &piix4_gpe_ops, s,
569 "acpi-gpe0", GPE_LEN);
Gerd Hoffmann56e5b2a2012-12-11 09:40:45 +0100570 memory_region_add_subregion(parent, GPE_BASE, &s->io_gpe);
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900571
Igor Mammedov6536e422023-03-02 17:15:42 +0100572 if (s->acpi_pci_hotplug.use_acpi_hotplug_bridge ||
573 s->acpi_pci_hotplug.use_acpi_root_pci_hotplug) {
Ani Sinhadf4008c2020-09-18 14:11:08 +0530574 acpi_pcihp_init(OBJECT(s), &s->acpi_pci_hotplug, bus, parent,
Igor Mammedov6536e422023-03-02 17:15:42 +0100575 ACPI_PCIHP_ADDR_PIIX4);
Igor Mammedovf40e6a42023-03-02 17:15:20 +0100576 qbus_set_hotplug_handler(BUS(pci_get_bus(PCI_DEVICE(s))), OBJECT(s));
Ani Sinhadf4008c2020-09-18 14:11:08 +0530577 }
Igor Mammedovb8622722013-04-25 16:05:25 +0200578
Igor Mammedov16bcab92016-04-11 17:25:54 +0200579 s->cpu_hotplug_legacy = true;
580 object_property_add_bool(OBJECT(s), "cpu-hotplug-legacy",
581 piix4_get_cpu_hotplug_legacy,
Markus Armbrusterd2623122020-05-05 17:29:22 +0200582 piix4_set_cpu_hotplug_legacy);
Igor Mammedov96e3e122016-05-17 16:43:00 +0200583 legacy_acpi_cpu_hotplug_init(parent, OBJECT(s), &s->gpe_cpu,
584 PIIX4_CPU_HOTPLUG_IO_BASE);
Igor Mammedov34774322014-06-02 15:25:20 +0200585
586 if (s->acpi_memory_hotplug.is_enabled) {
Igor Mammedov80db0e72016-12-06 00:32:28 +0100587 acpi_memory_hotplug_init(parent, OBJECT(s), &s->acpi_memory_hotplug,
588 ACPI_MEMORY_HOTPLUG_BASE);
Igor Mammedov34774322014-06-02 15:25:20 +0200589 }
Isaku Yamahata93d89f62010-05-14 16:29:02 +0900590}
Igor Mammedov5fdae202014-02-05 16:36:47 +0100591
Igor Mammedov43f50412014-06-16 19:12:27 +0200592static void piix4_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
593{
594 PIIX4PMState *s = PIIX4_PM(adev);
595
596 acpi_memory_ospm_status(&s->acpi_memory_hotplug, list);
Igor Mammedov76623d02016-04-22 19:06:36 +0200597 if (!s->cpu_hotplug_legacy) {
598 acpi_cpu_ospm_status(&s->cpuhp_state, list);
599 }
Igor Mammedov43f50412014-06-16 19:12:27 +0200600}
601
Igor Mammedoveaf23bf2016-05-31 11:57:57 +0200602static void piix4_send_gpe(AcpiDeviceIf *adev, AcpiEventStatusBits ev)
603{
604 PIIX4PMState *s = PIIX4_PM(adev);
605
606 acpi_send_gpe_event(&s->ar, s->irq, ev);
607}
608
Igor Mammedov5fdae202014-02-05 16:36:47 +0100609static Property piix4_pm_properties[] = {
610 DEFINE_PROP_UINT32("smb_io_base", PIIX4PMState, smb_io_base, 0),
611 DEFINE_PROP_UINT8(ACPI_PM_PROP_S3_DISABLED, PIIX4PMState, disable_s3, 0),
612 DEFINE_PROP_UINT8(ACPI_PM_PROP_S4_DISABLED, PIIX4PMState, disable_s4, 0),
613 DEFINE_PROP_UINT8(ACPI_PM_PROP_S4_VAL, PIIX4PMState, s4_val, 2),
Ani Sinhaaa294662021-08-16 14:02:14 +0530614 DEFINE_PROP_BOOL(ACPI_PM_PROP_ACPI_PCIHP_BRIDGE, PIIX4PMState,
Igor Mammedov6536e422023-03-02 17:15:42 +0100615 acpi_pci_hotplug.use_acpi_hotplug_bridge, true),
Ani Sinhaaa294662021-08-16 14:02:14 +0530616 DEFINE_PROP_BOOL(ACPI_PM_PROP_ACPI_PCI_ROOTHP, PIIX4PMState,
Igor Mammedov6536e422023-03-02 17:15:42 +0100617 acpi_pci_hotplug.use_acpi_root_pci_hotplug, true),
Igor Mammedov34774322014-06-02 15:25:20 +0200618 DEFINE_PROP_BOOL("memory-hotplug-support", PIIX4PMState,
619 acpi_memory_hotplug.is_enabled, true),
Isaku Yamahata24cd04f2021-02-17 21:51:11 -0800620 DEFINE_PROP_BOOL("smm-compat", PIIX4PMState, smm_compat, false),
Mark Cave-Ayland7ace6b42022-05-28 10:02:11 +0100621 DEFINE_PROP_BOOL("smm-enabled", PIIX4PMState, smm_enabled, false),
Dr. David Alan Gilberta83c2842022-04-06 14:58:12 -0400622 DEFINE_PROP_BOOL("x-not-migrate-acpi-index", PIIX4PMState,
623 not_migrate_acpi_index, false),
Igor Mammedov5fdae202014-02-05 16:36:47 +0100624 DEFINE_PROP_END_OF_LIST(),
625};
626
627static void piix4_pm_class_init(ObjectClass *klass, void *data)
628{
629 DeviceClass *dc = DEVICE_CLASS(klass);
630 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
Igor Mammedovc24d5e02014-02-05 16:36:49 +0100631 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
Igor Mammedov43f50412014-06-16 19:12:27 +0200632 AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_CLASS(klass);
Igor Mammedov5fdae202014-02-05 16:36:47 +0100633
Markus Armbruster9af21db2015-01-19 15:52:30 +0100634 k->realize = piix4_pm_realize;
Igor Mammedov5fdae202014-02-05 16:36:47 +0100635 k->config_write = pm_write_config;
636 k->vendor_id = PCI_VENDOR_ID_INTEL;
637 k->device_id = PCI_DEVICE_ID_INTEL_82371AB_3;
638 k->revision = 0x03;
639 k->class_id = PCI_CLASS_BRIDGE_OTHER;
Philippe Mathieu-Daudé217e8ef2019-10-10 15:15:20 +0200640 dc->reset = piix4_pm_reset;
Igor Mammedov5fdae202014-02-05 16:36:47 +0100641 dc->desc = "PM";
642 dc->vmsd = &vmstate_acpi;
Marc-André Lureau4f67d302020-01-10 19:30:32 +0400643 device_class_set_props(dc, piix4_pm_properties);
Igor Mammedov5fdae202014-02-05 16:36:47 +0100644 /*
645 * Reason: part of PIIX4 southbridge, needs to be wired up,
646 * e.g. by mips_malta_init()
647 */
Eduardo Habkoste90f2a82017-05-03 17:35:44 -0300648 dc->user_creatable = false;
Igor Mammedov2897ae02014-02-05 16:36:48 +0100649 dc->hotpluggable = false;
David Hildenbrandec266f42018-12-12 10:16:17 +0100650 hc->pre_plug = piix4_device_pre_plug_cb;
Igor Mammedovf1adc362014-06-02 15:25:19 +0200651 hc->plug = piix4_device_plug_cb;
Igor Mammedov14d5a282014-09-26 09:28:19 +0000652 hc->unplug_request = piix4_device_unplug_request_cb;
Tang Chenc0e57a62015-01-28 15:45:41 +0800653 hc->unplug = piix4_device_unplug_cb;
Igor Mammedovf18e29f2023-03-02 17:15:43 +0100654 hc->is_hotpluggable_bus = piix4_is_hotpluggable_bus;
Igor Mammedov43f50412014-06-16 19:12:27 +0200655 adevc->ospm_status = piix4_ospm_status;
Igor Mammedoveaf23bf2016-05-31 11:57:57 +0200656 adevc->send_event = piix4_send_gpe;
Igor Mammedovac35f132016-04-20 11:28:57 +0200657 adevc->madt_cpu = pc_madt_cpu_entry;
Igor Mammedov5fdae202014-02-05 16:36:47 +0100658}
659
660static const TypeInfo piix4_pm_info = {
661 .name = TYPE_PIIX4_PM,
662 .parent = TYPE_PCI_DEVICE,
Mark Cave-Ayland29786d42022-05-28 10:02:11 +0100663 .instance_init = piix4_pm_init,
Igor Mammedov5fdae202014-02-05 16:36:47 +0100664 .instance_size = sizeof(PIIX4PMState),
665 .class_init = piix4_pm_class_init,
Igor Mammedovc24d5e02014-02-05 16:36:49 +0100666 .interfaces = (InterfaceInfo[]) {
667 { TYPE_HOTPLUG_HANDLER },
Igor Mammedov43f50412014-06-16 19:12:27 +0200668 { TYPE_ACPI_DEVICE_IF },
Eduardo Habkostfd3b02c2017-09-27 16:56:34 -0300669 { INTERFACE_CONVENTIONAL_PCI_DEVICE },
Igor Mammedovc24d5e02014-02-05 16:36:49 +0100670 { }
671 }
Igor Mammedov5fdae202014-02-05 16:36:47 +0100672};
673
674static void piix4_pm_register_types(void)
675{
676 type_register_static(&piix4_pm_info);
677}
678
679type_init(piix4_pm_register_types)