Initialize
[sdk/emulator/qemu.git] / tizen / src / hw / maru_pm.c
1 /*
2  * Maru power management emulator
3  * Based on qemu/hw/acpi_piix4.c
4  *
5  * Copyright (C) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
6  *
7  * Contact:
8  * Hyunjun Son <hj79.son@samsung.com>
9  * GiWoong Kim <giwoong.kim@samsung.com>
10  * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
25  *
26  * Contributors:
27  * - S-Core Co., Ltd
28  *
29  */
30
31 #include "maru_pm.h"
32 #include "hw.h"
33 #include "pc.h"
34 #include "apm.h"
35 #include "pm_smbus.h"
36 #include "pci.h"
37 #include "acpi.h"
38 #include "sysemu.h"
39 #include "range.h"
40 #include "tizen/src/debug_ch.h"
41
42 //#define DEBUG
43
44 #ifdef DEBUG
45 # define PIIX4_DPRINTF(format, ...)     printf(format, ## __VA_ARGS__)
46 #else
47 # define PIIX4_DPRINTF(format, ...)     do { } while (0)
48 #endif
49
50 #define ACPI_DBG_IO_ADDR  0xb044
51
52 #define GPE_BASE 0xafe0
53 #define PCI_BASE 0xae00
54 #define PCI_EJ_BASE 0xae08
55 #define PCI_RMV_BASE 0xae0c
56
57 #define PIIX4_PCI_HOTPLUG_STATUS 2
58
59 /* define debug channel */
60 MULTI_DEBUG_CHANNEL(qemu, tizen_acpi_piix4);
61
62 struct gpe_regs {
63     uint16_t sts; /* status */
64     uint16_t en;  /* enabled */
65 };
66
67 struct pci_status {
68     uint32_t up;
69     uint32_t down;
70 };
71
72 typedef struct PIIX4PMState {
73     PCIDevice dev;
74     IORange ioport;
75     uint16_t pmsts;
76     uint16_t pmen;
77     uint16_t pmcntrl;
78
79     APMState apm;
80
81     QEMUTimer *tmr_timer;
82     int64_t tmr_overflow_time;
83
84     PMSMBus smb;
85     uint32_t smb_io_base;
86
87     qemu_irq irq;
88     qemu_irq cmos_s3;
89     qemu_irq smi_irq;
90     int kvm_enabled;
91
92     /* for pci hotplug */
93     struct gpe_regs gpe;
94     struct pci_status pci0_status;
95     uint32_t pci0_hotplug_enable;
96 } PIIX4PMState;
97
98 static PIIX4PMState* acpi_state;
99 static int is_suspended;
100
101 static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s);
102
103 #define ACPI_ENABLE 0xf1
104 #define ACPI_DISABLE 0xf0
105
106 static uint32_t get_pmtmr(PIIX4PMState *s)
107 {
108     uint32_t d;
109     d = muldiv64(qemu_get_clock(vm_clock), PM_TIMER_FREQUENCY, get_ticks_per_sec());
110     return d & 0xffffff;
111 }
112
113 static int get_pmsts(PIIX4PMState *s)
114 {
115     int64_t d;
116
117     d = muldiv64(qemu_get_clock(vm_clock), PM_TIMER_FREQUENCY,
118                  get_ticks_per_sec());
119     if (d >= s->tmr_overflow_time)
120         s->pmsts |= ACPI_BITMASK_TIMER_STATUS;
121     return s->pmsts;
122 }
123
124 static void pm_update_sci(PIIX4PMState *s)
125 {
126     int sci_level, pmsts;
127     int64_t expire_time;
128
129     pmsts = get_pmsts(s);
130     sci_level = (((pmsts & s->pmen) &
131                   (ACPI_BITMASK_RT_CLOCK_ENABLE |
132                    ACPI_BITMASK_POWER_BUTTON_ENABLE |
133                    ACPI_BITMASK_GLOBAL_LOCK_ENABLE |
134                    ACPI_BITMASK_TIMER_ENABLE)) != 0) ||
135         (((s->gpe.sts & s->gpe.en) & PIIX4_PCI_HOTPLUG_STATUS) != 0);
136
137     qemu_set_irq(s->irq, sci_level);
138     /* schedule a timer interruption if needed */
139     if ((s->pmen & ACPI_BITMASK_TIMER_ENABLE) &&
140         !(pmsts & ACPI_BITMASK_TIMER_STATUS)) {
141         expire_time = muldiv64(s->tmr_overflow_time, get_ticks_per_sec(),
142                                PM_TIMER_FREQUENCY);
143         qemu_mod_timer(s->tmr_timer, expire_time);
144     } else {
145         qemu_del_timer(s->tmr_timer);
146     }
147 }
148
149 static void pm_tmr_timer(void *opaque)
150 {
151     PIIX4PMState *s = opaque;
152     pm_update_sci(s);
153 }
154
155 static void pm_ioport_write(IORange *ioport, uint64_t addr, unsigned width,
156                             uint64_t val)
157 {
158     PIIX4PMState *s = container_of(ioport, PIIX4PMState, ioport);
159
160     if (width != 2) {
161         PIIX4_DPRINTF("PM write port=0x%04x width=%d val=0x%08x\n",
162                       (unsigned)addr, width, (unsigned)val);
163     }
164
165     switch(addr) {
166     case 0x00:
167         {
168             int64_t d;
169             int pmsts;
170             pmsts = get_pmsts(s);
171             if (pmsts & val & ACPI_BITMASK_TIMER_STATUS) {
172                 /* if TMRSTS is reset, then compute the new overflow time */
173                 d = muldiv64(qemu_get_clock(vm_clock), PM_TIMER_FREQUENCY,
174                              get_ticks_per_sec());
175                 s->tmr_overflow_time = (d + 0x800000LL) & ~0x7fffffLL;
176             }
177             s->pmsts &= ~val;
178             pm_update_sci(s);
179         }
180         break;
181     case 0x02:
182         s->pmen = val;
183         pm_update_sci(s);
184         break;
185     case 0x04:
186         {
187             int sus_typ;
188             s->pmcntrl = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
189             if (val & ACPI_BITMASK_SLEEP_ENABLE) {
190                 /* change suspend type */
191                 sus_typ = (val >> 10) & 7;
192                 switch(sus_typ) {
193                 case 0: /* soft power off */
194                     qemu_system_shutdown_request();
195                     break;
196                 case 1:
197 #if 0 // changed suspend operation for emulator
198                     /* ACPI_BITMASK_WAKE_STATUS should be set on resume.
199                        Pretend that resume was caused by power button */
200                     s->pmsts |= (ACPI_BITMASK_WAKE_STATUS |
201                                  ACPI_BITMASK_POWER_BUTTON_STATUS);
202                     qemu_system_reset_request();
203                     if (s->cmos_s3) {
204                         qemu_irq_raise(s->cmos_s3);
205                     }
206 #else
207                     INFO( "suspend is requested.\n" );
208                     is_suspended = 1;
209                     break;
210 #endif
211                 default:
212                     break;
213                 }
214             }
215         }
216         break;
217     default:
218         break;
219     }
220     PIIX4_DPRINTF("PM writew port=0x%04x val=0x%04x\n", addr, val);
221 }
222
223 static void pm_ioport_read(IORange *ioport, uint64_t addr, unsigned width,
224                             uint64_t *data)
225 {
226     PIIX4PMState *s = container_of(ioport, PIIX4PMState, ioport);
227     uint32_t val;
228
229     switch(addr) {
230     case 0x00:
231         val = get_pmsts(s);
232         break;
233     case 0x02:
234         val = s->pmen;
235         break;
236     case 0x04:
237         val = s->pmcntrl;
238         break;
239     case 0x08:
240         val = get_pmtmr(s);
241         break;
242     default:
243         val = 0;
244         break;
245     }
246     PIIX4_DPRINTF("PM readw port=0x%04x val=0x%04x\n", addr, val);
247     *data = val;
248 }
249
250 static const IORangeOps pm_iorange_ops = {
251     .read = pm_ioport_read,
252     .write = pm_ioport_write,
253 };
254
255 static void apm_ctrl_changed(uint32_t val, void *arg)
256 {
257     PIIX4PMState *s = arg;
258
259     /* ACPI specs 3.0, 4.7.2.5 */
260     if (val == ACPI_ENABLE) {
261         s->pmcntrl |= ACPI_BITMASK_SCI_ENABLE;
262     } else if (val == ACPI_DISABLE) {
263         s->pmcntrl &= ~ACPI_BITMASK_SCI_ENABLE;
264     }
265
266     if (s->dev.config[0x5b] & (1 << 1)) {
267         if (s->smi_irq) {
268             qemu_irq_raise(s->smi_irq);
269         }
270     }
271 }
272
273 static void acpi_dbg_writel(void *opaque, uint32_t addr, uint32_t val)
274 {
275     PIIX4_DPRINTF("ACPI: DBG: 0x%08x\n", val);
276 }
277
278 static void pm_io_space_update(PIIX4PMState *s)
279 {
280     uint32_t pm_io_base;
281
282     if (s->dev.config[0x80] & 1) {
283         pm_io_base = le32_to_cpu(*(uint32_t *)(s->dev.config + 0x40));
284         pm_io_base &= 0xffc0;
285
286         /* XXX: need to improve memory and ioport allocation */
287         PIIX4_DPRINTF("PM: mapping to 0x%x\n", pm_io_base);
288         iorange_init(&s->ioport, &pm_iorange_ops, pm_io_base, 64);
289         ioport_register(&s->ioport);
290     }
291 }
292
293 static void pm_write_config(PCIDevice *d,
294                             uint32_t address, uint32_t val, int len)
295 {
296     pci_default_write_config(d, address, val, len);
297     if (range_covers_byte(address, len, 0x80))
298         pm_io_space_update((PIIX4PMState *)d);
299 }
300
301 static int vmstate_acpi_post_load(void *opaque, int version_id)
302 {
303     PIIX4PMState *s = opaque;
304
305     pm_io_space_update(s);
306     return 0;
307 }
308
309 static const VMStateDescription vmstate_gpe = {
310     .name = "gpe",
311     .version_id = 1,
312     .minimum_version_id = 1,
313     .minimum_version_id_old = 1,
314     .fields      = (VMStateField []) {
315         VMSTATE_UINT16(sts, struct gpe_regs),
316         VMSTATE_UINT16(en, struct gpe_regs),
317         VMSTATE_END_OF_LIST()
318     }
319 };
320
321 static const VMStateDescription vmstate_pci_status = {
322     .name = "pci_status",
323     .version_id = 1,
324     .minimum_version_id = 1,
325     .minimum_version_id_old = 1,
326     .fields      = (VMStateField []) {
327         VMSTATE_UINT32(up, struct pci_status),
328         VMSTATE_UINT32(down, struct pci_status),
329         VMSTATE_END_OF_LIST()
330     }
331 };
332
333 static const VMStateDescription vmstate_acpi = {
334     .name = "piix4_pm",
335     .version_id = 2,
336     .minimum_version_id = 1,
337     .minimum_version_id_old = 1,
338     .post_load = vmstate_acpi_post_load,
339     .fields      = (VMStateField []) {
340         VMSTATE_PCI_DEVICE(dev, PIIX4PMState),
341         VMSTATE_UINT16(pmsts, PIIX4PMState),
342         VMSTATE_UINT16(pmen, PIIX4PMState),
343         VMSTATE_UINT16(pmcntrl, PIIX4PMState),
344         VMSTATE_STRUCT(apm, PIIX4PMState, 0, vmstate_apm, APMState),
345         VMSTATE_TIMER(tmr_timer, PIIX4PMState),
346         VMSTATE_INT64(tmr_overflow_time, PIIX4PMState),
347         VMSTATE_STRUCT(gpe, PIIX4PMState, 2, vmstate_gpe, struct gpe_regs),
348         VMSTATE_STRUCT(pci0_status, PIIX4PMState, 2, vmstate_pci_status,
349                        struct pci_status),
350         VMSTATE_END_OF_LIST()
351     }
352 };
353
354 static void piix4_update_hotplug(PIIX4PMState *s)
355 {
356     PCIDevice *dev = &s->dev;
357     BusState *bus = qdev_get_parent_bus(&dev->qdev);
358     DeviceState *qdev, *next;
359
360     s->pci0_hotplug_enable = ~0;
361
362     QLIST_FOREACH_SAFE(qdev, &bus->children, sibling, next) {
363         PCIDeviceInfo *info = container_of(qdev->info, PCIDeviceInfo, qdev);
364         PCIDevice *pdev = DO_UPCAST(PCIDevice, qdev, qdev);
365         int slot = PCI_SLOT(pdev->devfn);
366
367         if (info->no_hotplug) {
368             s->pci0_hotplug_enable &= ~(1 << slot);
369         }
370     }
371 }
372
373 static void piix4_reset(void *opaque)
374 {
375     PIIX4PMState *s = opaque;
376     uint8_t *pci_conf = s->dev.config;
377
378     pci_conf[0x58] = 0;
379     pci_conf[0x59] = 0;
380     pci_conf[0x5a] = 0;
381     pci_conf[0x5b] = 0;
382
383     if (s->kvm_enabled) {
384         /* Mark SMM as already inited (until KVM supports SMM). */
385         pci_conf[0x5B] = 0x02;
386     }
387     piix4_update_hotplug(s);
388 }
389
390 static void piix4_powerdown(void *opaque, int irq, int power_failing)
391 {
392     PIIX4PMState *s = opaque;
393
394     if (!s) {
395         qemu_system_shutdown_request();
396     } else if (s->pmen & ACPI_BITMASK_POWER_BUTTON_ENABLE) {
397         s->pmsts |= ACPI_BITMASK_POWER_BUTTON_STATUS;
398         pm_update_sci(s);
399     }
400 }
401
402 static int piix4_pm_initfn(PCIDevice *dev)
403 {
404     PIIX4PMState *s = DO_UPCAST(PIIX4PMState, dev, dev);
405     uint8_t *pci_conf;
406
407     pci_conf = s->dev.config;
408     pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
409     pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371AB_3);
410     pci_conf[0x06] = 0x80;
411     pci_conf[0x07] = 0x02;
412     pci_conf[0x08] = 0x03; // revision number
413     pci_conf[0x09] = 0x00;
414     pci_config_set_class(pci_conf, PCI_CLASS_BRIDGE_OTHER);
415     pci_conf[0x3d] = 0x01; // interrupt pin 1
416
417     pci_conf[0x40] = 0x01; /* PM io base read only bit */
418
419     /* APM */
420     apm_init(&s->apm, apm_ctrl_changed, s);
421
422     register_ioport_write(ACPI_DBG_IO_ADDR, 4, 4, acpi_dbg_writel, s);
423
424     if (s->kvm_enabled) {
425         /* Mark SMM as already inited to prevent SMM from running.  KVM does not
426          * support SMM mode. */
427         pci_conf[0x5B] = 0x02;
428     }
429
430     /* XXX: which specification is used ? The i82731AB has different
431        mappings */
432     pci_conf[0x5f] = (parallel_hds[0] != NULL ? 0x80 : 0) | 0x10;
433     pci_conf[0x63] = 0x60;
434     pci_conf[0x67] = (serial_hds[0] != NULL ? 0x08 : 0) |
435     (serial_hds[1] != NULL ? 0x90 : 0);
436
437     pci_conf[0x90] = s->smb_io_base | 1;
438     pci_conf[0x91] = s->smb_io_base >> 8;
439     pci_conf[0xd2] = 0x09;
440     register_ioport_write(s->smb_io_base, 64, 1, smb_ioport_writeb, &s->smb);
441     register_ioport_read(s->smb_io_base, 64, 1, smb_ioport_readb, &s->smb);
442
443     s->tmr_timer = qemu_new_timer(vm_clock, pm_tmr_timer, s);
444
445     qemu_system_powerdown = *qemu_allocate_irqs(piix4_powerdown, s, 1);
446
447     pm_smbus_init(&s->dev.qdev, &s->smb);
448     qemu_register_reset(piix4_reset, s);
449     piix4_acpi_system_hot_add_init(dev->bus, s);
450
451     return 0;
452 }
453
454 i2c_bus *maru_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
455                        qemu_irq sci_irq, qemu_irq cmos_s3, qemu_irq smi_irq,
456                        int kvm_enabled)
457 {
458     PCIDevice *dev;
459     PIIX4PMState *s;
460
461     dev = pci_create(bus, devfn, "TIZEN-PIIX4_PM");
462     qdev_prop_set_uint32(&dev->qdev, "smb_io_base", smb_io_base);
463
464     s = DO_UPCAST(PIIX4PMState, dev, dev);
465     s->irq = sci_irq;
466     s->cmos_s3 = cmos_s3;
467     s->smi_irq = smi_irq;
468     s->kvm_enabled = kvm_enabled;
469
470     acpi_state = s;
471
472     qdev_init_nofail(&dev->qdev);
473
474     return s->smb.smbus;
475 }
476
477 static PCIDeviceInfo piix4_pm_info = {
478     .qdev.name          = "TIZEN-PIIX4_PM",
479     .qdev.desc          = "TIZEN PM",
480     .qdev.size          = sizeof(PIIX4PMState),
481     .qdev.vmsd          = &vmstate_acpi,
482     .qdev.no_user       = 1,
483     .no_hotplug         = 1,
484     .init               = piix4_pm_initfn,
485     .config_write       = pm_write_config,
486     .qdev.props         = (Property[]) {
487         DEFINE_PROP_UINT32("smb_io_base", PIIX4PMState, smb_io_base, 0),
488         DEFINE_PROP_END_OF_LIST(),
489     }
490 };
491
492 static void piix4_pm_register(void)
493 {
494     pci_qdev_register(&piix4_pm_info);
495 }
496
497 device_init(piix4_pm_register);
498
499 static uint32_t gpe_read_val(uint16_t val, uint32_t addr)
500 {
501     if (addr & 1)
502         return (val >> 8) & 0xff;
503     return val & 0xff;
504 }
505
506 static uint32_t gpe_readb(void *opaque, uint32_t addr)
507 {
508     uint32_t val = 0;
509     PIIX4PMState *s = opaque;
510     struct gpe_regs *g = &s->gpe;
511
512     switch (addr) {
513         case GPE_BASE:
514         case GPE_BASE + 1:
515             val = gpe_read_val(g->sts, addr);
516             break;
517         case GPE_BASE + 2:
518         case GPE_BASE + 3:
519             val = gpe_read_val(g->en, addr);
520             break;
521         default:
522             break;
523     }
524
525     PIIX4_DPRINTF("gpe read %x == %x\n", addr, val);
526     return val;
527 }
528
529 static void gpe_write_val(uint16_t *cur, int addr, uint32_t val)
530 {
531     if (addr & 1)
532         *cur = (*cur & 0xff) | (val << 8);
533     else
534         *cur = (*cur & 0xff00) | (val & 0xff);
535 }
536
537 static void gpe_reset_val(uint16_t *cur, int addr, uint32_t val)
538 {
539     uint16_t x1, x0 = val & 0xff;
540     int shift = (addr & 1) ? 8 : 0;
541
542     x1 = (*cur >> shift) & 0xff;
543
544     x1 = x1 & ~x0;
545
546     *cur = (*cur & (0xff << (8 - shift))) | (x1 << shift);
547 }
548
549 static void gpe_writeb(void *opaque, uint32_t addr, uint32_t val)
550 {
551     PIIX4PMState *s = opaque;
552     struct gpe_regs *g = &s->gpe;
553
554     switch (addr) {
555         case GPE_BASE:
556         case GPE_BASE + 1:
557             gpe_reset_val(&g->sts, addr, val);
558             break;
559         case GPE_BASE + 2:
560         case GPE_BASE + 3:
561             gpe_write_val(&g->en, addr, val);
562             break;
563         default:
564             break;
565     }
566
567     pm_update_sci(s);
568
569     PIIX4_DPRINTF("gpe write %x <== %d\n", addr, val);
570 }
571
572 static uint32_t pcihotplug_read(void *opaque, uint32_t addr)
573 {
574     uint32_t val = 0;
575     struct pci_status *g = opaque;
576     switch (addr) {
577         case PCI_BASE:
578             val = g->up;
579             break;
580         case PCI_BASE + 4:
581             val = g->down;
582             break;
583         default:
584             break;
585     }
586
587     PIIX4_DPRINTF("pcihotplug read %x == %x\n", addr, val);
588     return val;
589 }
590
591 static void pcihotplug_write(void *opaque, uint32_t addr, uint32_t val)
592 {
593     struct pci_status *g = opaque;
594     switch (addr) {
595         case PCI_BASE:
596             g->up = val;
597             break;
598         case PCI_BASE + 4:
599             g->down = val;
600             break;
601    }
602
603     PIIX4_DPRINTF("pcihotplug write %x <== %d\n", addr, val);
604 }
605
606 static uint32_t pciej_read(void *opaque, uint32_t addr)
607 {
608     PIIX4_DPRINTF("pciej read %x\n", addr);
609     return 0;
610 }
611
612 static void pciej_write(void *opaque, uint32_t addr, uint32_t val)
613 {
614     BusState *bus = opaque;
615     DeviceState *qdev, *next;
616     PCIDevice *dev;
617     int slot = ffs(val) - 1;
618
619     QLIST_FOREACH_SAFE(qdev, &bus->children, sibling, next) {
620         dev = DO_UPCAST(PCIDevice, qdev, qdev);
621         if (PCI_SLOT(dev->devfn) == slot) {
622             qdev_free(qdev);
623         }
624     }
625
626
627     PIIX4_DPRINTF("pciej write %x <== %d\n", addr, val);
628 }
629
630 static uint32_t pcirmv_read(void *opaque, uint32_t addr)
631 {
632     PIIX4PMState *s = opaque;
633
634     return s->pci0_hotplug_enable;
635 }
636
637 static void pcirmv_write(void *opaque, uint32_t addr, uint32_t val)
638 {
639     return;
640 }
641
642 static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
643                                 PCIHotplugState state);
644
645 static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s)
646 {
647     struct pci_status *pci0_status = &s->pci0_status;
648
649     register_ioport_write(GPE_BASE, 4, 1, gpe_writeb, s);
650     register_ioport_read(GPE_BASE, 4, 1,  gpe_readb, s);
651
652     register_ioport_write(PCI_BASE, 8, 4, pcihotplug_write, pci0_status);
653     register_ioport_read(PCI_BASE, 8, 4,  pcihotplug_read, pci0_status);
654
655     register_ioport_write(PCI_EJ_BASE, 4, 4, pciej_write, bus);
656     register_ioport_read(PCI_EJ_BASE, 4, 4,  pciej_read, bus);
657
658     register_ioport_write(PCI_RMV_BASE, 4, 4, pcirmv_write, s);
659     register_ioport_read(PCI_RMV_BASE, 4, 4,  pcirmv_read, s);
660
661     pci_bus_hotplug(bus, piix4_device_hotplug, &s->dev.qdev);
662 }
663
664 static void enable_device(PIIX4PMState *s, int slot)
665 {
666     s->gpe.sts |= PIIX4_PCI_HOTPLUG_STATUS;
667     s->pci0_status.up |= (1 << slot);
668 }
669
670 static void disable_device(PIIX4PMState *s, int slot)
671 {
672     s->gpe.sts |= PIIX4_PCI_HOTPLUG_STATUS;
673     s->pci0_status.down |= (1 << slot);
674 }
675
676 static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
677                 PCIHotplugState state)
678 {
679     int slot = PCI_SLOT(dev->devfn);
680     PIIX4PMState *s = DO_UPCAST(PIIX4PMState, dev,
681                                 DO_UPCAST(PCIDevice, qdev, qdev));
682
683     /* Don't send event when device is enabled during qemu machine creation:
684      * it is present on boot, no hotplug event is necessary. We do send an
685      * event when the device is disabled later. */
686     if (state == PCI_COLDPLUG_ENABLED) {
687         return 0;
688     }
689
690     s->pci0_status.up = 0;
691     s->pci0_status.down = 0;
692     if (state == PCI_HOTPLUG_ENABLED) {
693         enable_device(s, slot);
694     } else {
695         disable_device(s, slot);
696     }
697
698     pm_update_sci(s);
699
700     return 0;
701 }
702
703 void resume( void ) {
704
705     is_suspended = 0;
706
707     if ( acpi_state ) {
708
709         if ( acpi_state->cmos_s3 ) {
710             acpi_state->pmsts |= ( ACPI_BITMASK_WAKE_STATUS | ACPI_BITMASK_POWER_BUTTON_STATUS );
711             INFO( "raise irq for ACPI wake." );
712             qemu_irq_raise( acpi_state->cmos_s3 );
713         }else {
714             ERR( "acpi cmos_s3 is NULL." );
715         }
716
717     }else {
718         ERR( "acpi state is NULL." );
719     }
720
721 }
722
723 int is_suspended_state( void ) {
724     return is_suspended;
725 }