From patchwork Fri Sep 22 03:01:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 9965567 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 CBEA1600C5 for ; Fri, 22 Sep 2017 09:12:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C50AC2970F for ; Fri, 22 Sep 2017 09:12:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B87F32980B; Fri, 22 Sep 2017 09:12:00 +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=-2.7 required=2.0 tests=BAYES_00, DATE_IN_PAST_06_12, 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 333ED2970F for ; Fri, 22 Sep 2017 09:11:59 +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 1dvJy5-0003L2-Cp; Fri, 22 Sep 2017 09:09:53 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dvJy3-0003JZ-O1 for xen-devel@lists.xen.org; Fri, 22 Sep 2017 09:09:51 +0000 Received: from [85.158.143.35] by server-9.bemta-6.messagelabs.com id 3C/18-03422-F53D4C95; Fri, 22 Sep 2017 09:09:51 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBLMWRWlGSWpSXmKPExsXS1tYhrxt3+Ui kwb0ZbBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8axz0dZCn4rVFzffYutgXGvVBcjB4eQQKXE oaPeXYycHBICvBJHls1ghbD9JTbPusPUxcgFVNLBKHH1y2RmkASbgLrEicUTGUFsEQFpiWufL zOCFDELbGaSmLtmFgvIUGGBEIkXx5lBTBYBVYndOwpBynkFXCT+Hl/IDjFfQWLKw/dgIzkFXC V+9W1nArGFgGpal+5nmsDIu4CRYRWjRnFqUVlqka6xkV5SUWZ6RkluYmaOrqGBmV5uanFxYnp qTmJSsV5yfu4mRmAoMADBDsbT6wIPMUpyMCmJ8r4/fyRSiC8pP6UyI7E4I76oNCe1+BCjDAeH kgSv3yWgnGBRanpqRVpmDjAoYdISHDxKIryvLgKleYsLEnOLM9MhUqcYdTk6bt79wyTEkpefl yolzrsYZIYASFFGaR7cCFiEXGKUlRLmZQQ6SoinILUoN7MEVf4VozgHo5IwrwHIFJ7MvBK4Ta +AjmACOqJ8NdgRJYkIKakGRstr8u18CbqvV9crqb+b9uXX9kq3f+4CZyP9LaoVyvk97eY3zHG 8FSIYJjBn182UV8y5+n/O/rNcxeyrYVcstmjTH9eFxpNFt99xeiq/WlpU6q/fuQ/1Clsk15/N +TZj/6kLh2Xajiw8cFKH4UJGRXDd/4e6Jz7/Yb78l3WFh+mD459M9IXfKCixFGckGmoxFxUnA gCTx1dYiwIAAA== X-Env-Sender: tianyu.lan@intel.com X-Msg-Ref: server-8.tower-21.messagelabs.com!1506071388!83988953!1 X-Originating-IP: [134.134.136.31] X-SpamReason: No, hits=0.8 required=7.0 tests=DATE_IN_PAST_06_12 X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9883 invoked from network); 22 Sep 2017 09:09:49 -0000 Received: from mga06.intel.com (HELO mga06.intel.com) (134.134.136.31) by server-8.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Sep 2017 09:09:49 -0000 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP; 22 Sep 2017 02:09:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,427,1500966000"; d="scan'208";a="154276353" Received: from sky-ws.sh.intel.com (HELO localhost) ([10.239.48.141]) by fmsmga005.fm.intel.com with ESMTP; 22 Sep 2017 02:09:44 -0700 From: Lan Tianyu To: xen-devel@lists.xen.org Date: Thu, 21 Sep 2017 23:01:46 -0400 Message-Id: <1506049330-11196-6-git-send-email-tianyu.lan@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1506049330-11196-1-git-send-email-tianyu.lan@intel.com> References: <1506049330-11196-1-git-send-email-tianyu.lan@intel.com> Cc: Lan Tianyu , kevin.tian@intel.com, sstabellini@kernel.org, wei.liu2@citrix.com, George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, tim@xen.org, jbeulich@suse.com, roger.pau@citrix.com, Chao Gao Subject: [Xen-devel] [PATCH V3 5/29] 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 From: Chao Gao The BIOS reports the remapping hardware units in a platform to system software through the DMA Remapping Reporting (DMAR) ACPI table. New fields are introduces 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. Signed-off-by: Chao Gao Signed-off-by: Lan Tianyu --- v3: - Remove chip-set specific IOAPIC BDF. Instead, let IOAPIC-related info be passed by struct acpi_config. --- tools/libacpi/build.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ tools/libacpi/libacpi.h | 12 +++++++++++ 2 files changed, 65 insertions(+) diff --git a/tools/libacpi/build.c b/tools/libacpi/build.c index f9881c9..5ee8fcd 100644 --- a/tools/libacpi/build.c +++ b/tools/libacpi/build.c @@ -303,6 +303,59 @@ 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 *dmar; + struct acpi_dmar_hardware_unit *drhd; + struct dmar_device_scope *scope; + unsigned int size; + unsigned int ioapic_scope_size = sizeof(*scope) + sizeof(scope->path[0]); + + size = sizeof(*dmar) + sizeof(*drhd) + ioapic_scope_size; + + 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; + if ( !config->iommu_x2apic_supported ) + dmar->flags |= ACPI_DMAR_X2APIC_OPT_OUT; + + drhd = (struct acpi_dmar_hardware_unit *)((void*)dmar + sizeof(*dmar)); + drhd->type = ACPI_DMAR_TYPE_HARDWARE_UNIT; + 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_DEVICE_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..fdd6a78 100644 --- a/tools/libacpi/libacpi.h +++ b/tools/libacpi/libacpi.h @@ -20,6 +20,8 @@ #ifndef __LIBACPI_H__ #define __LIBACPI_H__ +#include + #define ACPI_HAS_COM1 (1<<0) #define ACPI_HAS_COM2 (1<<1) #define ACPI_HAS_LPT1 (1<<2) @@ -96,8 +98,18 @@ 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; + bool iommu_x2apic_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__ */