From nobody Sat Feb 7 10:15:20 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1557729522; cv=none; d=zoho.com; s=zohoarc; b=fjvbGoH/nBWXq621JFuzAWQdSZcJf4Npry/CzmaGMh3d92EvEQW0ftROHOhPtKW/A+O4AE2XKzctq98YTkvknl1wejGHsOSNmhUU/PKWQAULPvPkSCKbRuajqEAVhF7HidTDMKMKaOTUtZntIWphNImRtmgdYBO4N87VhjGKdXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557729522; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=dumnOo66lpib9llY0+XcEazfkmJGPSii/W+Z5VQkR2c=; b=m8qkqKhv6A/z25PafnePZXpnIYLP6pSXK2s0q0h91E95XfIbY75woom0SrOz/wmwj6pjoxeY66zhUvdPLt99zDlNyqW3Vx3q+S1vAxsM8PxRghf5gkaKhdJm2l0x4OPWxtaN7Mffy2aWdkYlTxlqcZfOOmjmkx6D+/QFoqvnzWk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557729522681985.4567226088708; Sun, 12 May 2019 23:38:42 -0700 (PDT) Received: from localhost ([127.0.0.1]:51958 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQ4bf-0004CK-G6 for importer@patchew.org; Mon, 13 May 2019 02:38:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQ4Zt-0002z4-RI for qemu-devel@nongnu.org; Mon, 13 May 2019 02:36:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQ4KG-0004w1-Q1 for qemu-devel@nongnu.org; Mon, 13 May 2019 02:20:42 -0400 Received: from mga07.intel.com ([134.134.136.100]:24552) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hQ4KG-0004ds-I4 for qemu-devel@nongnu.org; Mon, 13 May 2019 02:20:40 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 May 2019 23:20:40 -0700 Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by orsmga003.jf.intel.com with ESMTP; 12 May 2019 23:20:38 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 From: Wei Yang To: qemu-devel@nongnu.org Date: Mon, 13 May 2019 14:19:12 +0800 Message-Id: <20190513061913.9284-9-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190513061913.9284-1-richardw.yang@linux.intel.com> References: <20190513061913.9284-1-richardw.yang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.100 Subject: [Qemu-devel] [RFC PATCH 8/9] hw/acpi: factor build_madt with madt_input X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, ehabkost@redhat.com, mst@redhat.com, Wei Yang , pbonzini@redhat.com, imammedo@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" struct madt_input is introduced to represent one sub madt table. With help of madt_sub[] for related sub madt table, build_madt could be agnostic. Signed-off-by: Wei Yang --- hw/i386/acpi-build.c | 103 +++++++++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 38 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index a7aeb215fc..74a34e297e 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -284,6 +284,54 @@ static void acpi_get_pci_holes(Range *hole, Range *hol= e64) NULL)); } =20 +struct madt_input { + int sub_id; + void *opaque; +}; + +int xrupt_override_idx[] =3D {0, 5, 9, 10, 11}; +static struct madt_input * +acpi_get_madt_input(PCMachineState *pcms, int *processor_id) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(pcms); + const CPUArchIdList *apic_ids =3D mc->possible_cpu_arch_ids(MACHINE(pc= ms)); + int i, sub_heads =3D 0; + uint32_t apic_id; + struct madt_input *input =3D NULL; + + sub_heads =3D apic_ids->len /* PROCESSOR/X2APIC */ + + 1 /* APIC_IO */ + + ARRAY_SIZE(xrupt_override_idx) /* XRUPT_OVERRIDE */ + + 1 /* NMI/X2APIC_NMI */ + + 1; /* END MARK */ + input =3D g_new0(struct madt_input, sub_heads); + for (i =3D 0, sub_heads =3D 0; i < apic_ids->len; i++, sub_heads++) { + apic_id =3D apic_ids->cpus[i].arch_id; + if (apic_id < 255) { + input[sub_heads].sub_id =3D ACPI_APIC_PROCESSOR; + } else { + input[sub_heads].sub_id =3D ACPI_APIC_LOCAL_X2APIC; + } + input[sub_heads].opaque =3D processor_id; + } + input[sub_heads++].sub_id =3D ACPI_APIC_IO; + for (i =3D 0; i < ARRAY_SIZE(xrupt_override_idx); i++, sub_heads++) { + if (i =3D=3D 0 && !pcms->apic_xrupt_override) { + continue; + } + input[sub_heads].sub_id =3D ACPI_APIC_XRUPT_OVERRIDE; + input[sub_heads].opaque =3D &xrupt_override_idx[i]; + } + if (apic_id > 254) { + input[sub_heads++].sub_id =3D ACPI_APIC_LOCAL_X2APIC_NMI; + } else { + input[sub_heads++].sub_id =3D ACPI_APIC_LOCAL_NMI; + } + input[sub_heads].sub_id =3D ACPI_APIC_RESERVED; + + return input; +} + static void acpi_align_size(GArray *blob, unsigned align) { /* Align size to multiple of given size. This reduces the chance @@ -318,6 +366,7 @@ static void pc_madt_apic_entry(GArray *entry, void *opa= que) } else { apic->flags =3D cpu_to_le32(0); } + (*processor_id)++; } =20 static void pc_madt_x2apic_entry(GArray *entry, void *opaque) @@ -337,6 +386,7 @@ static void pc_madt_x2apic_entry(GArray *entry, void *o= paque) } else { apic->flags =3D cpu_to_le32(0); } + (*processor_id)++; } =20 static void pc_madt_io_entry(GArray *entry, void *opaque) @@ -405,54 +455,27 @@ madt_operations i386_madt_sub =3D { }; =20 static void -build_madt(GArray *table_data, BIOSLinker *linker, PCMachineState *pcms) +build_madt(GArray *table_data, BIOSLinker *linker, PCMachineState *pcms, + struct madt_input *input) { - MachineClass *mc =3D MACHINE_GET_CLASS(pcms); - const CPUArchIdList *apic_ids =3D mc->possible_cpu_arch_ids(MACHINE(pc= ms)); int madt_start =3D table_data->len; AcpiDeviceIfClass *adevc =3D ACPI_DEVICE_IF_GET_CLASS(pcms->acpi_dev); =20 - bool x2apic_mode =3D false; - AcpiMultipleApicTable *madt; - int i; + int i, sub_id; + void *opaque; =20 madt =3D acpi_data_push(table_data, sizeof *madt); madt->local_apic_address =3D cpu_to_le32(APIC_DEFAULT_ADDRESS); madt->flags =3D cpu_to_le32(1); =20 - for (i =3D 0; i < apic_ids->len; i++) { - uint32_t apic_id =3D apic_ids->cpus[i].arch_id; - int processor_id =3D i; - if (apic_id < 255) { - adevc->madt_sub[ACPI_APIC_PROCESSOR](table_data, &processor_id= ); - } else { - adevc->madt_sub[ACPI_APIC_LOCAL_X2APIC](table_data, &processor= _id); + for (i =3D 0; ; i++) { + sub_id =3D input[i].sub_id; + if (sub_id =3D=3D ACPI_APIC_RESERVED) { + break; } - if (apic_id > 254) { - x2apic_mode =3D true; - } - } - - adevc->madt_sub[ACPI_APIC_IO](table_data, NULL); - - if (pcms->apic_xrupt_override) { - i =3D 0; - adevc->madt_sub[ACPI_APIC_XRUPT_OVERRIDE](table_data, &i); - } - for (i =3D 1; i < 16; i++) { -#define ACPI_BUILD_PCI_IRQS ((1<<5) | (1<<9) | (1<<10) | (1<<11)) - if (!(ACPI_BUILD_PCI_IRQS & (1 << i))) { - /* No need for a INT source override structure. */ - continue; - } - adevc->madt_sub[ACPI_APIC_XRUPT_OVERRIDE](table_data, &i); - } - - if (x2apic_mode) { - adevc->madt_sub[ACPI_APIC_LOCAL_X2APIC_NMI](table_data, NULL); - } else { - adevc->madt_sub[ACPI_APIC_LOCAL_NMI](table_data, NULL); + opaque =3D input[i].opaque; + adevc->madt_sub[sub_id](table_data, opaque); } =20 build_header(linker, table_data, @@ -2627,6 +2650,8 @@ void acpi_build(AcpiBuildTables *tables, MachineState= *machine) GArray *tables_blob =3D tables->table_data; AcpiSlicOem slic_oem =3D { .id =3D NULL, .table_id =3D NULL }; Object *vmgenid_dev; + struct madt_input *input =3D NULL; + int processor_id =3D 0; =20 acpi_get_pm_info(&pm); acpi_get_misc_info(&misc); @@ -2671,7 +2696,9 @@ void acpi_build(AcpiBuildTables *tables, MachineState= *machine) aml_len +=3D tables_blob->len - fadt; =20 acpi_add_table(table_offsets, tables_blob); - build_madt(tables_blob, tables->linker, pcms); + input =3D acpi_get_madt_input(pcms, &processor_id); + build_madt(tables_blob, tables->linker, pcms, input); + g_free(input); =20 vmgenid_dev =3D find_vmgenid_dev(); if (vmgenid_dev) { --=20 2.19.1