From patchwork Fri Nov 17 06:22:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Gao X-Patchwork-Id: 10062355 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 587D86023A for ; Fri, 17 Nov 2017 06:27:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B8292A539 for ; Fri, 17 Nov 2017 06:27:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 406972A990; Fri, 17 Nov 2017 06:27:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CE2762A539 for ; Fri, 17 Nov 2017 06:27:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eFa65-0001iz-64; Fri, 17 Nov 2017 06:25:53 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eFa64-0001h7-CF for xen-devel@lists.xen.org; Fri, 17 Nov 2017 06:25:52 +0000 Received: from [85.158.139.211] by server-6.bemta-5.messagelabs.com id EC/C7-32721-FE08E0A5; Fri, 17 Nov 2017 06:25:51 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpkkeJIrShJLcpLzFFi42Jpa+uQ0H3fwBd lMHE+q8WSj4tZHBg9ju7+zRTAGMWamZeUX5HAmnHm+n72ggfKFf/v7mNvYOyU7WLk4hASmM4o sW3OIuYuRk4OCQFeiSPLZrBC2AESZ49+ALOFBKokVt1+zgZiswkoS1z82gtmiwhIS1z7fJkRZ BCzwHNmiePbmlhAEsICoRKn3zaBNbMIqErcnHiAHcTmFXCWmHt7ExvEAgWJKQ/fgy3mBIrvf3 OQCWKZk8TBddOYJjDyLmBkWMWoUZxaVJZapGtoqpdUlJmeUZKbmJmja2hgqpebWlycmJ6ak5h UrJecn7uJERgQDECwg7Fhu+chRkkOJiVRXh5zvighvqT8lMqMxOKM+KLSnNTiQ4wyHBxKErzH 6oFygkWp6akVaZk5wNCESUtw8CiJ8CYCw1OIt7ggMbc4Mx0idYrRmOPZzNcNzBzTrrY2MQux5 OXnpUqJ894HmSQAUppRmgc3CBYzlxhlpYR5GYFOE+IpSC3KzSxBlX/FKM7BqCTMWwkyhSczrw Ru3yugU5iATrG5wQ1ySkkiQkqqgdFJlD/EZsGKwrWrvWfuPWSqbLnnWHMzb1F82RTlTdlZHAW 9/DuuW7Ly/3v3tbJZXSks4uQb0yIRcUXniczvnOdeqHrWY7ns2RxWNRvbkG8ypkyVLvo2vPfn J+377q+gkPawedozwYkldYsmnPgZ2TbzxIxNKixbyuse7Mv/F6fYZ84zwTo7WomlOCPRUIu5q DgRAFK5KFmUAgAA X-Env-Sender: chao.gao@intel.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1510899922!87798367!10 X-Originating-IP: [134.134.136.24] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjQgPT4gMzkwOTcx\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 54228 invoked from network); 17 Nov 2017 06:25:50 -0000 Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by server-11.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 17 Nov 2017 06:25:50 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Nov 2017 22:25:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.44,407,1505804400"; d="scan'208"; a="1245165354" Received: from skl-4s-chao.sh.intel.com ([10.239.48.9]) by fmsmga002.fm.intel.com with ESMTP; 16 Nov 2017 22:25:47 -0800 From: Chao Gao To: xen-devel@lists.xen.org Date: Fri, 17 Nov 2017 14:22:31 +0800 Message-Id: <1510899755-40237-25-git-send-email-chao.gao@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1510899755-40237-1-git-send-email-chao.gao@intel.com> References: <1510899755-40237-1-git-send-email-chao.gao@intel.com> Cc: Lan Tianyu , Kevin Tian , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Ian Jackson , Tim Deegan , Jan Beulich , Andrew Cooper , Chao Gao , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [Xen-devel] [PATCH v4 24/28] tools/libacpi: Add new fields in acpi_config for DMAR table X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP The BIOS reports the remapping hardware units in a platform to system software through the DMA Remapping Reporting (DMAR) ACPI table. New fields are introduced for DMAR table. These new fields are set by toolstack through parsing guest's config file. construct_dmar() is added to build DMAR table according to the new fields. The header files in ovmf.c are re-ordered to avoid including in tools/libacpi/libacpi.h. Signed-off-by: Chao Gao Signed-off-by: Lan Tianyu --- v4: - initialize variables during declaration if possible - reorder the sequence of header files to avoid including in tools/libacpi/libacpi.h v3: - Remove chip-set specific IOAPIC BDF. Instead, let IOAPIC-related info be passed by struct acpi_config. --- tools/firmware/hvmloader/ovmf.c | 2 +- tools/libacpi/build.c | 49 +++++++++++++++++++++++++++++++++++++++++ tools/libacpi/libacpi.h | 9 ++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/tools/firmware/hvmloader/ovmf.c b/tools/firmware/hvmloader/ovmf.c index a17a11c..606ab4d 100644 --- a/tools/firmware/hvmloader/ovmf.c +++ b/tools/firmware/hvmloader/ovmf.c @@ -23,10 +23,10 @@ #include "config.h" #include "smbios_types.h" +#include "util.h" #include "libacpi.h" #include "apic_regs.h" #include "../rombios/config.h" -#include "util.h" #include "pci_regs.h" #include "hypercall.h" diff --git a/tools/libacpi/build.c b/tools/libacpi/build.c index f9881c9..bd759da 100644 --- a/tools/libacpi/build.c +++ b/tools/libacpi/build.c @@ -303,6 +303,55 @@ static struct acpi_20_slit *construct_slit(struct acpi_ctxt *ctxt, return slit; } +/* + * Only one DMA remapping hardware unit is exposed and all devices + * are under the remapping hardware unit. I/O APIC should be explicitly + * enumerated. + */ +struct acpi_dmar *construct_dmar(struct acpi_ctxt *ctxt, + const struct acpi_config *config) +{ + struct acpi_dmar_hardware_unit *drhd; + struct dmar_device_scope *scope; + unsigned int ioapic_scope_size = sizeof(*scope) + sizeof(scope->path[0]); + unsigned int size = sizeof(struct acpi_dmar) + sizeof(*drhd) + + ioapic_scope_size; + struct acpi_dmar *dmar = ctxt->mem_ops.alloc(ctxt, size, 16); + + if ( !dmar ) + return NULL; + + memset(dmar, 0, size); + dmar->header.signature = ACPI_2_0_DMAR_SIGNATURE; + dmar->header.revision = ACPI_2_0_DMAR_REVISION; + dmar->header.length = size; + fixed_strcpy(dmar->header.oem_id, ACPI_OEM_ID); + fixed_strcpy(dmar->header.oem_table_id, ACPI_OEM_TABLE_ID); + dmar->header.oem_revision = ACPI_OEM_REVISION; + dmar->header.creator_id = ACPI_CREATOR_ID; + dmar->header.creator_revision = ACPI_CREATOR_REVISION; + dmar->host_address_width = config->host_addr_width - 1; + if ( config->iommu_intremap_supported ) + dmar->flags |= ACPI_DMAR_INTR_REMAP; + + drhd = (struct acpi_dmar_hardware_unit *)((void*)dmar + sizeof(*dmar)); + drhd->type = ACPI_DMAR_TYPE_DRHD; + drhd->length = sizeof(*drhd) + ioapic_scope_size; + drhd->flags = ACPI_DMAR_INCLUDE_PCI_ALL; + drhd->pci_segment = 0; + drhd->base_address = config->iommu_base_addr; + + scope = &drhd->scope[0]; + scope->type = ACPI_DMAR_DEV_SCOPE_IOAPIC; + scope->length = ioapic_scope_size; + scope->enumeration_id = config->ioapic_id; + scope->bus = config->ioapic_bus; + scope->path[0] = config->ioapic_devfn; + + set_checksum(dmar, offsetof(struct acpi_header, checksum), size); + return dmar; +} + static int construct_passthrough_tables(struct acpi_ctxt *ctxt, unsigned long *table_ptrs, int nr_tables, diff --git a/tools/libacpi/libacpi.h b/tools/libacpi/libacpi.h index a2efd23..c09afdc 100644 --- a/tools/libacpi/libacpi.h +++ b/tools/libacpi/libacpi.h @@ -96,8 +96,17 @@ struct acpi_config { uint32_t ioapic_base_address; uint16_t pci_isa_irq_mask; uint8_t ioapic_id; + + /* Emulated IOMMU features, location and IOAPIC under the scope of IOMMU */ + bool iommu_intremap_supported; + uint8_t host_addr_width; + uint8_t ioapic_bus; + uint16_t ioapic_devfn; + uint64_t iommu_base_addr; }; +struct acpi_dmar *construct_dmar(struct acpi_ctxt *ctxt, + const struct acpi_config *config); int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config); #endif /* __LIBACPI_H__ */