diff mbox

[v3,09/14] i386: define pc guest info

Message ID 1374681580-17439-10-git-send-email-mst@redhat.com
State New
Headers show

Commit Message

Michael S. Tsirkin July 24, 2013, 4:02 p.m. UTC
This defines a structure that will be used to fill in guest info table.
This structure will be filled in in follow-up patches, using QOM.  Fill
in NUMA node info is not available in QOM so it is filled in directly.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
 hw/i386/pc.c            | 33 +++++++++++++++++++++++++++++++++
 include/hw/i386/pc.h    | 31 +++++++++++++++++++++++++++++++
 include/qemu/typedefs.h |  1 +
 3 files changed, 65 insertions(+)

Comments

Gerd Hoffmann July 25, 2013, 12:31 p.m. UTC | #1
On 07/24/13 18:02, Michael S. Tsirkin wrote:
> This defines a structure that will be used to fill in guest info table.
> This structure will be filled in in follow-up patches, using QOM.  Fill
> in NUMA node info is not available in QOM so it is filled in directly.

Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>

cheers,
  Gerd
Andreas Färber July 28, 2013, 12:41 a.m. UTC | #2
Am 24.07.2013 18:02, schrieb Michael S. Tsirkin:
> This defines a structure that will be used to fill in guest info table.
> This structure will be filled in in follow-up patches, using QOM.  Fill
> in NUMA node info is not available in QOM so it is filled in directly.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
> ---
>  hw/i386/pc.c            | 33 +++++++++++++++++++++++++++++++++
>  include/hw/i386/pc.h    | 31 +++++++++++++++++++++++++++++++
>  include/qemu/typedefs.h |  1 +
>  3 files changed, 65 insertions(+)
> 
> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> index b0b98a8..b9b8f92 100644
> --- a/hw/i386/pc.c
> +++ b/hw/i386/pc.c
> @@ -1017,6 +1017,27 @@ static void pc_fw_cfg_guest_info(PcGuestInfo *guest_info)
>      fw_cfg_add_file(guest_info->fw_cfg, "etc/pci-info", info, sizeof *info);
>  }
>  
> +static void pc_set_cpu_guest_info(CPUState *cpu, void *arg)
> +{
> +    PcGuestInfo *guest_info = arg;
> +    CPUClass *klass = CPU_GET_CLASS(cpu);
> +    uint64_t apic_id = klass->get_arch_id(cpu);

Please use "cc" to avoid the dreaded "klass".

> +    int j;
> +
> +    assert(apic_id <= MAX_CPUMASK_BITS);
> +    assert(apic_id < guest_info->apic_id_limit);
> +
> +    set_bit(apic_id, guest_info->found_cpus);
> +
> +    for (j = 0; j < guest_info->numa_nodes; j++) {
> +        assert(cpu->cpu_index < max_cpus);
> +        if (test_bit(cpu->cpu_index, node_cpumask[j])) {
> +            guest_info->node_cpu[apic_id] = cpu_to_le64(j);
> +            break;
> +        }
> +    }
> +}
> +
>  typedef struct PcGuestInfoState {
>      PcGuestInfo info;
>      Notifier machine_done;
> @@ -1037,6 +1058,18 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
>      PcGuestInfoState *guest_info_state = g_malloc0(sizeof *guest_info_state);
>      PcGuestInfo *guest_info = &guest_info_state->info;
>  
> +    guest_info->ram_size = below_4g_mem_size + above_4g_mem_size;
> +    guest_info->apic_id_limit = pc_apic_id_limit(max_cpus);
> +    guest_info->apic_xrupt_override = kvm_allows_irq0_override();
> +    guest_info->numa_nodes = nb_numa_nodes;
> +    guest_info->node_mem = g_memdup(node_mem, guest_info->numa_nodes *
> +                                    sizeof *guest_info->node_mem);
> +    guest_info->node_cpu = g_malloc0(guest_info->apic_id_limit *
> +                                     sizeof *guest_info->node_cpu);
> +
> +    memset(&guest_info->found_cpus, 0, sizeof guest_info->found_cpus);
> +    qemu_for_each_cpu(pc_set_cpu_guest_info, guest_info);
> +
>      guest_info->pci_info.w32.end = IO_APIC_DEFAULT_ADDRESS;
>      if (sizeof(hwaddr) == 4) {
>          guest_info->pci_info.w64.begin = 0;
> diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
> index 7fb97b0..7c0bd50 100644
> --- a/include/hw/i386/pc.h
> +++ b/include/hw/i386/pc.h
> @@ -9,6 +9,9 @@
>  #include "hw/i386/ioapic.h"
>  
>  #include "qemu/range.h"
> +#include "qemu/bitmap.h"
> +#include "sysemu/sysemu.h"
> +#include "hw/pci/pci.h"
>  
>  /* PC-style peripherals (also used by other machines).  */
>  
> @@ -17,9 +20,37 @@ typedef struct PcPciInfo {
>      Range w64;
>  } PcPciInfo;
>  
> +/* Matches the value hard-coded in BIOS */
> +#define PC_GUEST_PORT_ACPI_PM_BASE      0xb000
> +
> +struct AcpiPmInfo {
> +    bool s3_disabled;
> +    bool s4_disabled;
> +    uint8_t s4_val;
> +    uint16_t sci_int;
> +    uint8_t acpi_enable_cmd;
> +    uint8_t acpi_disable_cmd;
> +    uint32_t gpe0_blk;
> +    uint32_t gpe0_blk_len;
> +};
> +
>  struct PcGuestInfo {
>      PcPciInfo pci_info;

These capitalizations look weird. Can't we use at least PM rather than Pm?

Andreas

>      bool has_pci_info;
> +    hwaddr ram_size;
> +    unsigned apic_id_limit;
> +    bool apic_xrupt_override;
> +    bool has_hpet;
> +    uint64_t numa_nodes;
> +    uint64_t *node_mem;
> +    uint64_t *node_cpu;
> +    DECLARE_BITMAP(found_cpus, MAX_CPUMASK_BITS + 1);
> +    DECLARE_BITMAP(slot_hotplug_enable, PCI_SLOT_MAX);
> +    AcpiPmInfo pm;
> +    uint64_t mcfg_base;
> +    const unsigned char *dsdt_code;
> +    unsigned dsdt_size;
> +    uint16_t pvpanic_port;
>      FWCfgState *fw_cfg;
>  };
>  
> diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
> index ac9f8d4..cb66e19 100644
> --- a/include/qemu/typedefs.h
> +++ b/include/qemu/typedefs.h
> @@ -65,5 +65,6 @@ typedef struct QEMUSGList QEMUSGList;
>  typedef struct SHPCDevice SHPCDevice;
>  typedef struct FWCfgState FWCfgState;
>  typedef struct PcGuestInfo PcGuestInfo;
> +typedef struct AcpiPmInfo AcpiPmInfo;
>  
>  #endif /* QEMU_TYPEDEFS_H */
>
Michael S. Tsirkin July 28, 2013, 7:36 a.m. UTC | #3
On Sun, Jul 28, 2013 at 02:41:51AM +0200, Andreas Färber wrote:
> Am 24.07.2013 18:02, schrieb Michael S. Tsirkin:
> > This defines a structure that will be used to fill in guest info table.
> > This structure will be filled in in follow-up patches, using QOM.  Fill
> > in NUMA node info is not available in QOM so it is filled in directly.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > Reviewed-by: Laszlo Ersek <lersek@redhat.com>
> > ---
> >  hw/i386/pc.c            | 33 +++++++++++++++++++++++++++++++++
> >  include/hw/i386/pc.h    | 31 +++++++++++++++++++++++++++++++
> >  include/qemu/typedefs.h |  1 +
> >  3 files changed, 65 insertions(+)
> > 
> > diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> > index b0b98a8..b9b8f92 100644
> > --- a/hw/i386/pc.c
> > +++ b/hw/i386/pc.c
> > @@ -1017,6 +1017,27 @@ static void pc_fw_cfg_guest_info(PcGuestInfo *guest_info)
> >      fw_cfg_add_file(guest_info->fw_cfg, "etc/pci-info", info, sizeof *info);
> >  }
> >  
> > +static void pc_set_cpu_guest_info(CPUState *cpu, void *arg)
> > +{
> > +    PcGuestInfo *guest_info = arg;
> > +    CPUClass *klass = CPU_GET_CLASS(cpu);
> > +    uint64_t apic_id = klass->get_arch_id(cpu);
> 
> Please use "cc" to avoid the dreaded "klass".
> 
> > +    int j;
> > +
> > +    assert(apic_id <= MAX_CPUMASK_BITS);
> > +    assert(apic_id < guest_info->apic_id_limit);
> > +
> > +    set_bit(apic_id, guest_info->found_cpus);
> > +
> > +    for (j = 0; j < guest_info->numa_nodes; j++) {
> > +        assert(cpu->cpu_index < max_cpus);
> > +        if (test_bit(cpu->cpu_index, node_cpumask[j])) {
> > +            guest_info->node_cpu[apic_id] = cpu_to_le64(j);
> > +            break;
> > +        }
> > +    }
> > +}
> > +
> >  typedef struct PcGuestInfoState {
> >      PcGuestInfo info;
> >      Notifier machine_done;
> > @@ -1037,6 +1058,18 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
> >      PcGuestInfoState *guest_info_state = g_malloc0(sizeof *guest_info_state);
> >      PcGuestInfo *guest_info = &guest_info_state->info;
> >  
> > +    guest_info->ram_size = below_4g_mem_size + above_4g_mem_size;
> > +    guest_info->apic_id_limit = pc_apic_id_limit(max_cpus);
> > +    guest_info->apic_xrupt_override = kvm_allows_irq0_override();
> > +    guest_info->numa_nodes = nb_numa_nodes;
> > +    guest_info->node_mem = g_memdup(node_mem, guest_info->numa_nodes *
> > +                                    sizeof *guest_info->node_mem);
> > +    guest_info->node_cpu = g_malloc0(guest_info->apic_id_limit *
> > +                                     sizeof *guest_info->node_cpu);
> > +
> > +    memset(&guest_info->found_cpus, 0, sizeof guest_info->found_cpus);
> > +    qemu_for_each_cpu(pc_set_cpu_guest_info, guest_info);
> > +
> >      guest_info->pci_info.w32.end = IO_APIC_DEFAULT_ADDRESS;
> >      if (sizeof(hwaddr) == 4) {
> >          guest_info->pci_info.w64.begin = 0;
> > diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
> > index 7fb97b0..7c0bd50 100644
> > --- a/include/hw/i386/pc.h
> > +++ b/include/hw/i386/pc.h
> > @@ -9,6 +9,9 @@
> >  #include "hw/i386/ioapic.h"
> >  
> >  #include "qemu/range.h"
> > +#include "qemu/bitmap.h"
> > +#include "sysemu/sysemu.h"
> > +#include "hw/pci/pci.h"
> >  
> >  /* PC-style peripherals (also used by other machines).  */
> >  
> > @@ -17,9 +20,37 @@ typedef struct PcPciInfo {
> >      Range w64;
> >  } PcPciInfo;
> >  
> > +/* Matches the value hard-coded in BIOS */
> > +#define PC_GUEST_PORT_ACPI_PM_BASE      0xb000
> > +
> > +struct AcpiPmInfo {
> > +    bool s3_disabled;
> > +    bool s4_disabled;
> > +    uint8_t s4_val;
> > +    uint16_t sci_int;
> > +    uint8_t acpi_enable_cmd;
> > +    uint8_t acpi_disable_cmd;
> > +    uint32_t gpe0_blk;
> > +    uint32_t gpe0_blk_len;
> > +};
> > +
> >  struct PcGuestInfo {
> >      PcPciInfo pci_info;
> 
> These capitalizations look weird. Can't we use at least PM rather than Pm?
> 
> Andreas

I prefer making a first letter in each work upper case consistently but
I don't mind so much.

> >      bool has_pci_info;
> > +    hwaddr ram_size;
> > +    unsigned apic_id_limit;
> > +    bool apic_xrupt_override;
> > +    bool has_hpet;
> > +    uint64_t numa_nodes;
> > +    uint64_t *node_mem;
> > +    uint64_t *node_cpu;
> > +    DECLARE_BITMAP(found_cpus, MAX_CPUMASK_BITS + 1);
> > +    DECLARE_BITMAP(slot_hotplug_enable, PCI_SLOT_MAX);
> > +    AcpiPmInfo pm;
> > +    uint64_t mcfg_base;
> > +    const unsigned char *dsdt_code;
> > +    unsigned dsdt_size;
> > +    uint16_t pvpanic_port;
> >      FWCfgState *fw_cfg;
> >  };
> >  
> > diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
> > index ac9f8d4..cb66e19 100644
> > --- a/include/qemu/typedefs.h
> > +++ b/include/qemu/typedefs.h
> > @@ -65,5 +65,6 @@ typedef struct QEMUSGList QEMUSGList;
> >  typedef struct SHPCDevice SHPCDevice;
> >  typedef struct FWCfgState FWCfgState;
> >  typedef struct PcGuestInfo PcGuestInfo;
> > +typedef struct AcpiPmInfo AcpiPmInfo;
> >  
> >  #endif /* QEMU_TYPEDEFS_H */
> > 
> 
> 
> -- 
> SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
> GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
diff mbox

Patch

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index b0b98a8..b9b8f92 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1017,6 +1017,27 @@  static void pc_fw_cfg_guest_info(PcGuestInfo *guest_info)
     fw_cfg_add_file(guest_info->fw_cfg, "etc/pci-info", info, sizeof *info);
 }
 
+static void pc_set_cpu_guest_info(CPUState *cpu, void *arg)
+{
+    PcGuestInfo *guest_info = arg;
+    CPUClass *klass = CPU_GET_CLASS(cpu);
+    uint64_t apic_id = klass->get_arch_id(cpu);
+    int j;
+
+    assert(apic_id <= MAX_CPUMASK_BITS);
+    assert(apic_id < guest_info->apic_id_limit);
+
+    set_bit(apic_id, guest_info->found_cpus);
+
+    for (j = 0; j < guest_info->numa_nodes; j++) {
+        assert(cpu->cpu_index < max_cpus);
+        if (test_bit(cpu->cpu_index, node_cpumask[j])) {
+            guest_info->node_cpu[apic_id] = cpu_to_le64(j);
+            break;
+        }
+    }
+}
+
 typedef struct PcGuestInfoState {
     PcGuestInfo info;
     Notifier machine_done;
@@ -1037,6 +1058,18 @@  PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
     PcGuestInfoState *guest_info_state = g_malloc0(sizeof *guest_info_state);
     PcGuestInfo *guest_info = &guest_info_state->info;
 
+    guest_info->ram_size = below_4g_mem_size + above_4g_mem_size;
+    guest_info->apic_id_limit = pc_apic_id_limit(max_cpus);
+    guest_info->apic_xrupt_override = kvm_allows_irq0_override();
+    guest_info->numa_nodes = nb_numa_nodes;
+    guest_info->node_mem = g_memdup(node_mem, guest_info->numa_nodes *
+                                    sizeof *guest_info->node_mem);
+    guest_info->node_cpu = g_malloc0(guest_info->apic_id_limit *
+                                     sizeof *guest_info->node_cpu);
+
+    memset(&guest_info->found_cpus, 0, sizeof guest_info->found_cpus);
+    qemu_for_each_cpu(pc_set_cpu_guest_info, guest_info);
+
     guest_info->pci_info.w32.end = IO_APIC_DEFAULT_ADDRESS;
     if (sizeof(hwaddr) == 4) {
         guest_info->pci_info.w64.begin = 0;
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 7fb97b0..7c0bd50 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -9,6 +9,9 @@ 
 #include "hw/i386/ioapic.h"
 
 #include "qemu/range.h"
+#include "qemu/bitmap.h"
+#include "sysemu/sysemu.h"
+#include "hw/pci/pci.h"
 
 /* PC-style peripherals (also used by other machines).  */
 
@@ -17,9 +20,37 @@  typedef struct PcPciInfo {
     Range w64;
 } PcPciInfo;
 
+/* Matches the value hard-coded in BIOS */
+#define PC_GUEST_PORT_ACPI_PM_BASE      0xb000
+
+struct AcpiPmInfo {
+    bool s3_disabled;
+    bool s4_disabled;
+    uint8_t s4_val;
+    uint16_t sci_int;
+    uint8_t acpi_enable_cmd;
+    uint8_t acpi_disable_cmd;
+    uint32_t gpe0_blk;
+    uint32_t gpe0_blk_len;
+};
+
 struct PcGuestInfo {
     PcPciInfo pci_info;
     bool has_pci_info;
+    hwaddr ram_size;
+    unsigned apic_id_limit;
+    bool apic_xrupt_override;
+    bool has_hpet;
+    uint64_t numa_nodes;
+    uint64_t *node_mem;
+    uint64_t *node_cpu;
+    DECLARE_BITMAP(found_cpus, MAX_CPUMASK_BITS + 1);
+    DECLARE_BITMAP(slot_hotplug_enable, PCI_SLOT_MAX);
+    AcpiPmInfo pm;
+    uint64_t mcfg_base;
+    const unsigned char *dsdt_code;
+    unsigned dsdt_size;
+    uint16_t pvpanic_port;
     FWCfgState *fw_cfg;
 };
 
diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
index ac9f8d4..cb66e19 100644
--- a/include/qemu/typedefs.h
+++ b/include/qemu/typedefs.h
@@ -65,5 +65,6 @@  typedef struct QEMUSGList QEMUSGList;
 typedef struct SHPCDevice SHPCDevice;
 typedef struct FWCfgState FWCfgState;
 typedef struct PcGuestInfo PcGuestInfo;
+typedef struct AcpiPmInfo AcpiPmInfo;
 
 #endif /* QEMU_TYPEDEFS_H */