diff mbox

[v3,for-2.9,1/3] hw/isa/apm: introduce callback for APM_STS_IOPORT writes

Message ID 20161118103659.10448-2-lersek@redhat.com
State New
Headers show

Commit Message

Laszlo Ersek Nov. 18, 2016, 10:36 a.m. UTC
In the following patches we'll add custom handling for when APM_STS_IOPORT
is written. Introduce a dedicated callback similar to the one that is now
called for APM_CNT_IOPORT writes.

Cc: "Kevin O'Connor" <kevin@koconnor.net>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>

---

Notes:
    v3:
    - feature negotiation is new in v3 [Paolo, Michael]

 include/hw/isa/apm.h |  9 +++++----
 hw/acpi/piix4.c      |  2 +-
 hw/isa/apm.c         | 15 ++++++++++-----
 hw/isa/lpc_ich9.c    |  2 +-
 hw/isa/vt82c686.c    |  2 +-
 5 files changed, 18 insertions(+), 12 deletions(-)

-- 
2.9.2
diff mbox

Patch

diff --git a/include/hw/isa/apm.h b/include/hw/isa/apm.h
index 4839ff1df252..8fc83addde4e 100644
--- a/include/hw/isa/apm.h
+++ b/include/hw/isa/apm.h
@@ -5,19 +5,20 @@ 
 #include "hw/hw.h"
 #include "exec/memory.h"
 
-typedef void (*apm_ctrl_changed_t)(uint32_t val, void *arg);
+typedef void (*apm_reg_changed_t)(uint32_t val, void *arg);
 
 typedef struct APMState {
     uint8_t apmc;
     uint8_t apms;
 
-    apm_ctrl_changed_t callback;
+    apm_reg_changed_t cnt_callback;
+    apm_reg_changed_t sts_callback;
     void *arg;
     MemoryRegion io;
 } APMState;
 
-void apm_init(PCIDevice *dev, APMState *s, apm_ctrl_changed_t callback,
-              void *arg);
+void apm_init(PCIDevice *dev, APMState *s, apm_reg_changed_t cnt_callback,
+              apm_reg_changed_t sts_callback, void *arg);
 
 extern const VMStateDescription vmstate_apm;
 
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 2adc246b0044..bc4087f5f6ef 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -493,7 +493,7 @@  static void piix4_pm_realize(PCIDevice *dev, Error **errp)
     pci_conf[0x3d] = 0x01; // interrupt pin 1
 
     /* APM */
-    apm_init(dev, &s->apm, apm_ctrl_changed, s);
+    apm_init(dev, &s->apm, apm_ctrl_changed, NULL, s);
 
     if (!s->smm_enabled) {
         /* Mark SMM as already inited to prevent SMM from running.  KVM does not
diff --git a/hw/isa/apm.c b/hw/isa/apm.c
index e232b0da033a..67e05b9932d6 100644
--- a/hw/isa/apm.c
+++ b/hw/isa/apm.c
@@ -47,11 +47,15 @@  static void apm_ioport_writeb(void *opaque, hwaddr addr, uint64_t val,
     if (addr == 0) {
         apm->apmc = val;
 
-        if (apm->callback) {
-            (apm->callback)(val, apm->arg);
+        if (apm->cnt_callback) {
+            apm->cnt_callback(val, apm->arg);
         }
     } else {
         apm->apms = val;
+
+        if (apm->sts_callback) {
+            apm->sts_callback(val, apm->arg);
+        }
     }
 }
 
@@ -90,10 +94,11 @@  static const MemoryRegionOps apm_ops = {
     },
 };
 
-void apm_init(PCIDevice *dev, APMState *apm, apm_ctrl_changed_t callback,
-              void *arg)
+void apm_init(PCIDevice *dev, APMState *apm, apm_reg_changed_t cnt_callback,
+              apm_reg_changed_t sts_callback, void *arg)
 {
-    apm->callback = callback;
+    apm->cnt_callback = cnt_callback;
+    apm->sts_callback = sts_callback;
     apm->arg = arg;
 
     /* ioport 0xb2, 0xb3 */
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 10d1ee8b9310..e3556c9f9eae 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -634,7 +634,7 @@  static void ich9_lpc_realize(PCIDevice *d, Error **errp)
     lpc->isa_bus = isa_bus;
 
     ich9_cc_init(lpc);
-    apm_init(d, &lpc->apm, ich9_apm_ctrl_changed, lpc);
+    apm_init(d, &lpc->apm, ich9_apm_ctrl_changed, NULL, lpc);
 
     lpc->machine_ready.notify = ich9_lpc_machine_ready;
     qemu_add_machine_init_done_notifier(&lpc->machine_ready);
diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c
index 41d5254f8e55..eb5258597b1d 100644
--- a/hw/isa/vt82c686.c
+++ b/hw/isa/vt82c686.c
@@ -365,7 +365,7 @@  static void vt82c686b_pm_realize(PCIDevice *dev, Error **errp)
     pm_smbus_init(&s->dev.qdev, &s->smb);
     memory_region_add_subregion(get_system_io(), s->smb_io_base, &s->smb.io);
 
-    apm_init(dev, &s->apm, NULL, s);
+    apm_init(dev, &s->apm, NULL, NULL, s);
 
     memory_region_init(&s->io, OBJECT(dev), "vt82c686-pm", 64);
     memory_region_set_enabled(&s->io, false);