All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: kraxel@redhat.com, ehabkost@redhat.com, liuxiaojian6@huawei.com,
	mst@redhat.com, rkrcmar@redhat.com, peterx@redhat.com,
	kevin@koconnor.net, pbonzini@redhat.com, lersek@redhat.com,
	chao.gao@intel.com
Subject: [Qemu-devel] [PATCH v4 01/13] pc: acpi: x2APIC support for MADT table and _MAT method
Date: Wed, 19 Oct 2016 14:05:31 +0200	[thread overview]
Message-ID: <1476878743-144953-2-git-send-email-imammedo@redhat.com> (raw)
In-Reply-To: <1476878743-144953-1-git-send-email-imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v4:
  - use cpu_to_le32() when assigning to uid/x2apic_id (Eduardo)
  - squash "acpi: cphp: support x2APIC entry in cpu._MAT"
    into this patch (Eduardo)
---
 include/hw/acpi/acpi-defs.h | 18 +++++++++++
 hw/acpi/cpu.c               |  5 +++
 hw/i386/acpi-build.c        | 78 +++++++++++++++++++++++++++++++--------------
 3 files changed, 77 insertions(+), 24 deletions(-)

diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
index 9c1b7cb..e94123c 100644
--- a/include/hw/acpi/acpi-defs.h
+++ b/include/hw/acpi/acpi-defs.h
@@ -343,6 +343,24 @@ struct AcpiMadtLocalNmi {
 } QEMU_PACKED;
 typedef struct AcpiMadtLocalNmi AcpiMadtLocalNmi;
 
+struct AcpiMadtProcessorX2Apic {
+    ACPI_SUB_HEADER_DEF
+    uint16_t reserved;
+    uint32_t x2apic_id;              /* Processor's local x2APIC ID */
+    uint32_t flags;
+    uint32_t uid;                    /* Processor object _UID */
+} QEMU_PACKED;
+typedef struct AcpiMadtProcessorX2Apic AcpiMadtProcessorX2Apic;
+
+struct AcpiMadtLocalX2ApicNmi {
+    ACPI_SUB_HEADER_DEF
+    uint16_t flags;                  /* MPS INTI flags */
+    uint32_t uid;                    /* Processor object _UID */
+    uint8_t  lint;                   /* Local APIC LINT# */
+    uint8_t  reserved[3];            /* Local APIC LINT# */
+} QEMU_PACKED;
+typedef struct AcpiMadtLocalX2ApicNmi AcpiMadtLocalX2ApicNmi;
+
 struct AcpiMadtGenericInterrupt {
     ACPI_SUB_HEADER_DEF
     uint16_t reserved;
diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
index 902f5c9..5ac89fe 100644
--- a/hw/acpi/cpu.c
+++ b/hw/acpi/cpu.c
@@ -531,6 +531,11 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
                 apic->flags = cpu_to_le32(1);
                 break;
             }
+            case ACPI_APIC_LOCAL_X2APIC: {
+                AcpiMadtProcessorX2Apic *apic = (void *)madt_buf->data;
+                apic->flags = cpu_to_le32(1);
+                break;
+            }
             default:
                 assert(0);
             }
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index e999654..385f9fc 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -340,24 +340,38 @@ build_fadt(GArray *table_data, BIOSLinker *linker, AcpiPmInfo *pm,
 void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid,
                        CPUArchIdList *apic_ids, GArray *entry)
 {
-    int apic_id;
-    AcpiMadtProcessorApic *apic = acpi_data_push(entry, sizeof *apic);
-
-    apic_id = apic_ids->cpus[uid].arch_id;
-    apic->type = ACPI_APIC_PROCESSOR;
-    apic->length = sizeof(*apic);
-    apic->processor_id = uid;
-    apic->local_apic_id = apic_id;
-    if (apic_ids->cpus[uid].cpu != NULL) {
-        apic->flags = cpu_to_le32(1);
+    uint32_t apic_id = apic_ids->cpus[uid].arch_id;
+
+    /* ACPI spec says that LAPIC entry for non present
+     * CPU may be omitted from MADT or it must be marked
+     * as disabled. However omitting non present CPU from
+     * MADT breaks hotplug on linux. So possible CPUs
+     * should be put in MADT but kept disabled.
+     */
+    if (apic_id < 255) {
+        AcpiMadtProcessorApic *apic = acpi_data_push(entry, sizeof *apic);
+
+        apic->type = ACPI_APIC_PROCESSOR;
+        apic->length = sizeof(*apic);
+        apic->processor_id = uid;
+        apic->local_apic_id = apic_id;
+        if (apic_ids->cpus[uid].cpu != NULL) {
+            apic->flags = cpu_to_le32(1);
+        } else {
+            apic->flags = cpu_to_le32(0);
+        }
     } else {
-        /* ACPI spec says that LAPIC entry for non present
-         * CPU may be omitted from MADT or it must be marked
-         * as disabled. However omitting non present CPU from
-         * MADT breaks hotplug on linux. So possible CPUs
-         * should be put in MADT but kept disabled.
-         */
-        apic->flags = cpu_to_le32(0);
+        AcpiMadtProcessorX2Apic *apic = acpi_data_push(entry, sizeof *apic);
+
+        apic->type = ACPI_APIC_LOCAL_X2APIC;
+        apic->length = sizeof(*apic);
+        apic->uid = cpu_to_le32(uid);
+        apic->x2apic_id = cpu_to_le32(apic_id);
+        if (apic_ids->cpus[uid].cpu != NULL) {
+            apic->flags = cpu_to_le32(1);
+        } else {
+            apic->flags = cpu_to_le32(0);
+        }
     }
 }
 
@@ -369,11 +383,11 @@ build_madt(GArray *table_data, BIOSLinker *linker, PCMachineState *pcms)
     int madt_start = table_data->len;
     AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(pcms->acpi_dev);
     AcpiDeviceIf *adev = ACPI_DEVICE_IF(pcms->acpi_dev);
+    bool x2apic_mode = false;
 
     AcpiMultipleApicTable *madt;
     AcpiMadtIoApic *io_apic;
     AcpiMadtIntsrcovr *intsrcovr;
-    AcpiMadtLocalNmi *local_nmi;
     int i;
 
     madt = acpi_data_push(table_data, sizeof *madt);
@@ -382,6 +396,9 @@ build_madt(GArray *table_data, BIOSLinker *linker, PCMachineState *pcms)
 
     for (i = 0; i < apic_ids->len; i++) {
         adevc->madt_cpu(adev, i, apic_ids, table_data);
+        if (apic_ids->cpus[i].arch_id > 254) {
+            x2apic_mode = true;
+        }
     }
     g_free(apic_ids);
 
@@ -414,12 +431,25 @@ build_madt(GArray *table_data, BIOSLinker *linker, PCMachineState *pcms)
         intsrcovr->flags  = cpu_to_le16(0xd); /* active high, level triggered */
     }
 
-    local_nmi = acpi_data_push(table_data, sizeof *local_nmi);
-    local_nmi->type         = ACPI_APIC_LOCAL_NMI;
-    local_nmi->length       = sizeof(*local_nmi);
-    local_nmi->processor_id = 0xff; /* all processors */
-    local_nmi->flags        = cpu_to_le16(0);
-    local_nmi->lint         = 1; /* ACPI_LINT1 */
+    if (x2apic_mode) {
+        AcpiMadtLocalX2ApicNmi *local_nmi;
+
+        local_nmi = acpi_data_push(table_data, sizeof *local_nmi);
+        local_nmi->type   = ACPI_APIC_LOCAL_X2APIC_NMI;
+        local_nmi->length = sizeof(*local_nmi);
+        local_nmi->uid    = 0xFFFFFFFF; /* all processors */
+        local_nmi->flags  = cpu_to_le16(0);
+        local_nmi->lint   = 1; /* ACPI_LINT1 */
+    } else {
+        AcpiMadtLocalNmi *local_nmi;
+
+        local_nmi = acpi_data_push(table_data, sizeof *local_nmi);
+        local_nmi->type         = ACPI_APIC_LOCAL_NMI;
+        local_nmi->length       = sizeof(*local_nmi);
+        local_nmi->processor_id = 0xff; /* all processors */
+        local_nmi->flags        = cpu_to_le16(0);
+        local_nmi->lint         = 1; /* ACPI_LINT1 */
+    }
 
     build_header(linker, table_data,
                  (void *)(table_data->data + madt_start), "APIC",
-- 
2.7.4

  reply	other threads:[~2016-10-19 12:05 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-19 12:05 [Qemu-devel] [PATCH v4 00/13] pc: q35: x2APIC support in kvm_apic mode Igor Mammedov
2016-10-19 12:05 ` Igor Mammedov [this message]
2016-10-19 12:54   ` [Qemu-devel] [PATCH v4 01/13] pc: acpi: x2APIC support for MADT table and _MAT method Eduardo Habkost
2016-10-19 12:05 ` [Qemu-devel] [PATCH v4 02/13] pc: acpi: x2APIC support for SRAT table Igor Mammedov
2016-10-19 12:54   ` Eduardo Habkost
2016-10-19 12:05 ` [Qemu-devel] [PATCH v4 03/13] acpi: cphp: force switch to modern cpu hotplug if APIC ID > 254 Igor Mammedov
2016-10-19 12:54   ` Eduardo Habkost
2016-10-19 12:05 ` [Qemu-devel] [PATCH v4 04/13] pc: leave max apic_id_limit only in legacy cpu hotplug code Igor Mammedov
2016-10-19 12:05 ` [Qemu-devel] [PATCH v4 05/13] pc: apic_common: extend APIC ID property to 32bit Igor Mammedov
2016-10-19 12:55   ` Eduardo Habkost
2016-10-19 12:05 ` [Qemu-devel] [PATCH v4 06/13] pc: apic_common: restore APIC ID to initial ID on reset Igor Mammedov
2016-10-19 12:56   ` Eduardo Habkost
2016-10-19 12:05 ` [Qemu-devel] [PATCH v4 07/13] pc: apic_common: reset APIC ID to initial ID when switching into x2APIC mode Igor Mammedov
2016-10-19 12:56   ` Eduardo Habkost
2016-10-19 12:05 ` [Qemu-devel] [PATCH v4 08/13] pc: kvm_apic: pass APIC ID depending on xAPIC/x2APIC mode Igor Mammedov
2016-10-19 12:05 ` [Qemu-devel] [PATCH v4 09/13] pc: clarify FW_CFG_MAX_CPUS usage comment Igor Mammedov
2016-10-19 12:58   ` Eduardo Habkost
2016-10-19 12:05 ` [Qemu-devel] [PATCH v4 10/13] increase MAX_CPUMASK_BITS from 255 to 288 Igor Mammedov
2016-10-19 13:16   ` Eduardo Habkost
2016-10-19 12:05 ` [Qemu-devel] [PATCH v4 11/13] pc: add 'etc/boot-cpus' fw_cfg file for machine with more than 255 CPUs Igor Mammedov
2016-10-19 13:15   ` Eduardo Habkost
2016-10-19 15:18     ` Igor Mammedov
2016-10-19 18:29       ` Eduardo Habkost
2016-10-20 11:27         ` Igor Mammedov
2016-10-20 12:27           ` Eduardo Habkost
2016-10-20 13:27             ` Igor Mammedov
2016-10-20 14:15               ` Eduardo Habkost
2016-10-20 14:42                 ` Igor Mammedov
2016-10-20 14:49             ` Kevin O'Connor
2016-10-20 14:58   ` [Qemu-devel] [PATCH v5 " Igor Mammedov
2016-10-20 18:11     ` Eduardo Habkost
2016-10-20 18:51     ` [Qemu-devel] [PATCH] fixup! " Eduardo Habkost
2016-10-21  8:53       ` Igor Mammedov
2016-10-21 11:41         ` Eduardo Habkost
2016-10-27 22:08         ` Michael S. Tsirkin
2016-10-28  0:53           ` Eduardo Habkost
2016-10-19 12:05 ` [Qemu-devel] [PATCH v4 12/13] pc: require IRQ remapping and EIM if there could be x2APIC CPUs Igor Mammedov
2016-10-19 13:17   ` Eduardo Habkost
2016-10-19 12:05 ` [Qemu-devel] [PATCH v4 13/13] pc: q35: bump max_cpus to 288 Igor Mammedov
2016-10-19 13:19   ` Eduardo Habkost
2016-10-19 13:29 ` [Qemu-devel] [PATCH v4 00/13] pc: q35: x2APIC support in kvm_apic mode Daniel P. Berrange
2016-10-19 15:22   ` Igor Mammedov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1476878743-144953-2-git-send-email-imammedo@redhat.com \
    --to=imammedo@redhat.com \
    --cc=chao.gao@intel.com \
    --cc=ehabkost@redhat.com \
    --cc=kevin@koconnor.net \
    --cc=kraxel@redhat.com \
    --cc=lersek@redhat.com \
    --cc=liuxiaojian6@huawei.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rkrcmar@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.