0a122b
From 364834e660cd4143e69126b2fb9a640c3ee9b9c1 Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <364834e660cd4143e69126b2fb9a640c3ee9b9c1.1387298827.git.minovotn@redhat.com>
0a122b
In-Reply-To: <3ed0fb61a3dc912ef036d7ef450bed192090709e.1387298827.git.minovotn@redhat.com>
0a122b
References: <3ed0fb61a3dc912ef036d7ef450bed192090709e.1387298827.git.minovotn@redhat.com>
0a122b
From: "Michael S. Tsirkin" <mst@redhat.com>
0a122b
Date: Tue, 17 Dec 2013 15:18:49 +0100
0a122b
Subject: [PATCH 41/56] piix: APIs for pc guest info
0a122b
0a122b
RH-Author: Michael S. Tsirkin <mst@redhat.com>
0a122b
Message-id: <1387293161-4085-42-git-send-email-mst@redhat.com>
0a122b
Patchwork-id: 56347
0a122b
O-Subject: [PATCH qemu-kvm RHEL7.0 v2 41/57] piix: APIs for pc guest info
0a122b
Bugzilla: 1034876
0a122b
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
0a122b
RH-Acked-by: Marcel Apfelbaum <marcel.a@redhat.com>
0a122b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
0a122b
0a122b
This adds APIs that will be used to fill in guest acpi tables.
0a122b
Some required information is still lacking in QOM, so we
0a122b
fall back on lookups by type and returning explicit types.
0a122b
0a122b
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
0a122b
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
0a122b
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
0a122b
Tested-by: Igor Mammedov <imammedo@redhat.com>
0a122b
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
0a122b
(cherry picked from commit 277e9340e6a1b0a0e8e988d2f0ac82b18b695c0b)
0a122b
0a122b
Conflicts:
0a122b
	hw/acpi/piix4.c
0a122b
---
0a122b
 include/hw/acpi/piix4.h |  8 ++++++++
0a122b
 include/hw/i386/pc.h    |  1 +
0a122b
 hw/acpi/piix4.c         | 45 ++++++++++++++++++++++++++++++++++++++++-----
0a122b
 hw/pci-host/piix.c      |  8 ++++++++
0a122b
 4 files changed, 57 insertions(+), 5 deletions(-)
0a122b
 create mode 100644 include/hw/acpi/piix4.h
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 hw/acpi/piix4.c         | 45 ++++++++++++++++++++++++++++++++++++++++-----
0a122b
 hw/pci-host/piix.c      |  8 ++++++++
0a122b
 include/hw/acpi/piix4.h |  8 ++++++++
0a122b
 include/hw/i386/pc.h    |  1 +
0a122b
 4 files changed, 57 insertions(+), 5 deletions(-)
0a122b
 create mode 100644 include/hw/acpi/piix4.h
0a122b
0a122b
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
0a122b
index 18b1300..6ebabe6 100644
0a122b
--- a/hw/acpi/piix4.c
0a122b
+++ b/hw/acpi/piix4.c
0a122b
@@ -29,6 +29,7 @@
0a122b
 #include "exec/ioport.h"
0a122b
 #include "hw/nvram/fw_cfg.h"
0a122b
 #include "exec/address-spaces.h"
0a122b
+#include "hw/acpi/piix4.h"
0a122b
 
0a122b
 //#define DEBUG
0a122b
 
0a122b
@@ -67,6 +68,8 @@ typedef struct PIIX4PMState {
0a122b
     PCIDevice dev;
0a122b
 
0a122b
     MemoryRegion io;
0a122b
+    uint32_t io_base;
0a122b
+
0a122b
     MemoryRegion io_gpe;
0a122b
     MemoryRegion io_pci;
0a122b
     MemoryRegion io_cpu;
0a122b
@@ -143,14 +146,12 @@ static void apm_ctrl_changed(uint32_t val, void *arg)
0a122b
 
0a122b
 static void pm_io_space_update(PIIX4PMState *s)
0a122b
 {
0a122b
-    uint32_t pm_io_base;
0a122b
-
0a122b
-    pm_io_base = le32_to_cpu(*(uint32_t *)(s->dev.config + 0x40));
0a122b
-    pm_io_base &= 0xffc0;
0a122b
+    s->io_base = le32_to_cpu(*(uint32_t *)(s->dev.config + 0x40));
0a122b
+    s->io_base &= 0xffc0;
0a122b
 
0a122b
     memory_region_transaction_begin();
0a122b
     memory_region_set_enabled(&s->io, s->dev.config[0x80] & 1);
0a122b
-    memory_region_set_address(&s->io, pm_io_base);
0a122b
+    memory_region_set_address(&s->io, s->io_base);
0a122b
     memory_region_transaction_commit();
0a122b
 }
0a122b
 
0a122b
@@ -393,6 +394,28 @@ static void piix4_pm_machine_ready(Notifier *n, void *opaque)
0a122b
 
0a122b
 }
0a122b
 
0a122b
+static void piix4_pm_add_propeties(PIIX4PMState *s)
0a122b
+{
0a122b
+    static const uint8_t acpi_enable_cmd = ACPI_ENABLE;
0a122b
+    static const uint8_t acpi_disable_cmd = ACPI_DISABLE;
0a122b
+    static const uint32_t gpe0_blk = GPE_BASE;
0a122b
+    static const uint32_t gpe0_blk_len = GPE_LEN;
0a122b
+    static const uint16_t sci_int = 9;
0a122b
+
0a122b
+    object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_ENABLE_CMD,
0a122b
+                                  &acpi_enable_cmd, NULL);
0a122b
+    object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_DISABLE_CMD,
0a122b
+                                  &acpi_disable_cmd, NULL);
0a122b
+    object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK,
0a122b
+                                  &gpe0_blk, NULL);
0a122b
+    object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK_LEN,
0a122b
+                                  &gpe0_blk_len, NULL);
0a122b
+    object_property_add_uint16_ptr(OBJECT(s), ACPI_PM_PROP_SCI_INT,
0a122b
+                                  &sci_int, NULL);
0a122b
+    object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_PM_IO_BASE,
0a122b
+                                  &s->io_base, NULL);
0a122b
+}
0a122b
+
0a122b
 static int piix4_pm_initfn(PCIDevice *dev)
0a122b
 {
0a122b
     PIIX4PMState *s = DO_UPCAST(PIIX4PMState, dev, dev);
0a122b
@@ -442,9 +465,21 @@ static int piix4_pm_initfn(PCIDevice *dev)
0a122b
 
0a122b
     piix4_acpi_system_hot_add_init(pci_address_space_io(dev), dev->bus, s);
0a122b
 
0a122b
+    piix4_pm_add_propeties(s);
0a122b
     return 0;
0a122b
 }
0a122b
 
0a122b
+Object *piix4_pm_find(void)
0a122b
+{
0a122b
+    bool ambig;
0a122b
+    Object *o = object_resolve_path_type("", "PIIX4_PM", &ambig);
0a122b
+
0a122b
+    if (ambig || !o) {
0a122b
+        return NULL;
0a122b
+    }
0a122b
+    return o;
0a122b
+}
0a122b
+
0a122b
 i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
0a122b
                        qemu_irq sci_irq, qemu_irq smi_irq,
0a122b
                        int kvm_enabled, FWCfgState *fw_cfg)
0a122b
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
0a122b
index 6502d1c..9284c8d 100644
0a122b
--- a/hw/pci-host/piix.c
0a122b
+++ b/hw/pci-host/piix.c
0a122b
@@ -408,6 +408,14 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
0a122b
     return b;
0a122b
 }
0a122b
 
0a122b
+PCIBus *find_i440fx(void)
0a122b
+{
0a122b
+    PCIHostState *s = OBJECT_CHECK(PCIHostState,
0a122b
+                                   object_resolve_path("/machine/i440fx", NULL),
0a122b
+                                   TYPE_PCI_HOST_BRIDGE);
0a122b
+    return s ? s->bus : NULL;
0a122b
+}
0a122b
+
0a122b
 /* PIIX3 PCI to ISA bridge */
0a122b
 static void piix3_set_irq_pic(PIIX3State *piix3, int pic_irq)
0a122b
 {
0a122b
diff --git a/include/hw/acpi/piix4.h b/include/hw/acpi/piix4.h
0a122b
new file mode 100644
0a122b
index 0000000..65e6fd7
0a122b
--- /dev/null
0a122b
+++ b/include/hw/acpi/piix4.h
0a122b
@@ -0,0 +1,8 @@
0a122b
+#ifndef HW_ACPI_PIIX4_H
0a122b
+#define HW_ACPI_PIIX4_H
0a122b
+
0a122b
+#include "qemu/typedefs.h"
0a122b
+
0a122b
+Object *piix4_pm_find(void);
0a122b
+
0a122b
+#endif
0a122b
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
0a122b
index 5011c87..d78e45b 100644
0a122b
--- a/include/hw/i386/pc.h
0a122b
+++ b/include/hw/i386/pc.h
0a122b
@@ -191,6 +191,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn,
0a122b
                     MemoryRegion *pci_memory,
0a122b
                     MemoryRegion *ram_memory);
0a122b
 
0a122b
+PCIBus *find_i440fx(void);
0a122b
 /* piix4.c */
0a122b
 extern PCIDevice *piix4_dev;
0a122b
 int piix4_init(PCIBus *bus, ISABus **isa_bus, int devfn);
0a122b
-- 
0a122b
1.7.11.7
0a122b