From patchwork Sun Jul 9 08:16:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Huang X-Patchwork-Id: 9831707 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 96E1D60317 for ; Sun, 9 Jul 2017 08:18:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B50E2624A for ; Sun, 9 Jul 2017 08:18:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F06727C0B; Sun, 9 Jul 2017 08:18:38 +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=-3.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 4081F2624A for ; Sun, 9 Jul 2017 08:18:37 +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 1dU7O7-0006dK-67; Sun, 09 Jul 2017 08:16:19 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dU7O5-0006d7-JN for xen-devel@lists.xen.org; Sun, 09 Jul 2017 08:16:17 +0000 Received: from [85.158.143.35] by server-4.bemta-6.messagelabs.com id B6/1F-02962-056E1695; Sun, 09 Jul 2017 08:16:16 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRWlGSWpSXmKPExsVyMfTAEd2AZ4m RBm/2CFgs+biYxYHR4+ju30wBjFGsmXlJ+RUJrBnPv9sV9FtV3Gr5ztrAOFGri5GLQ0hgEqNE X/sWNhCHReAli8SvCX9YQRwJgX5WiRV7bgE5nEBOnMTpJ48ZIewqia93NzCD2EICyhJd346yQ 4xaxCRx7dpEdpAEm4CaxNYl7SwQDbYSC859AWsQEZCWuPb5MtAgDg5mgWSJb+tiQcLCAtYSjV dOg81nEVCVOHr6GJjNKxAvsbbpFxPEGHmJXW0Xwe7hBBr5Zf8CqBtsJH4dW880gVFwASPDKka N4tSistQiXUNzvaSizPSMktzEzBxdQwMzvdzU4uLE9NScxKRiveT83E2MwIBjAIIdjLc3Bhxi lORgUhLlFetNiBTiS8pPqcxILM6ILyrNSS0+xCjDwaEkwfv9SWKkkGBRanpqRVpmDjD0YdISH DxKIrzO04HSvMUFibnFmekQqVOMlhxXrqz7wsQx5cB2IPlqwv9vTEIsefl5qVLivA5PgRoEQB oySvPgxsHi8xKjrJQwLyPQgUI8BalFuZklqPKvGMU5GJWEeX+DXMWTmVcCt/UV0EFMQAex1SW AHFSSiJCSamDUOFTh+Ebevej3hqUPf61hY9vSM/ndi4pn23ctst3yyjxI8v+lUim15Tv8kn6G rTRnU2HYeNJWXvlCzP7u8pWqW0y+Lf3Uupv/vmronKcs1ydMSF5t/Ke5td5/iXSpTYnNy+tSP 3wNdqdw8lZM32q5/7mrpJ+K2VGuu7v2dLnMzvh9kPGJZHCVEktxRqKhFnNRcSIAm7lqzMoCAA A= X-Env-Sender: kaih.linux@gmail.com X-Msg-Ref: server-4.tower-21.messagelabs.com!1499588174!66167455!1 X-Originating-IP: [209.85.192.196] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 20155 invoked from network); 9 Jul 2017 08:16:15 -0000 Received: from mail-pf0-f196.google.com (HELO mail-pf0-f196.google.com) (209.85.192.196) by server-4.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 9 Jul 2017 08:16:15 -0000 Received: by mail-pf0-f196.google.com with SMTP id c24so10361396pfe.1 for ; Sun, 09 Jul 2017 01:16:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=P4gIiWHTKguxh4VgYUFlflEIGElCQIuU430XqV4TbmI=; b=ns0afMeRVgFch4rEKp9w/S7dtM1d4Zw74uTHcDvJwC3DIXo0R+GiARNG34dJ4ODRPf GZMN3R/TEAyY6Xb5pmdDZEP0KdHwg4b0X4VdVP7hSc74mK4gLsjntOreadI+LqDgPiAr IJMwZzD51yAX3387+RVyHgLiwUtLOR/slflgYD3LqmETDs3Kc4d3GCj3m1UCI21cwVEU B6O1NoERDugsC7NceCc7/bOJekQgjNhuCT5lKUEVTnlJEPs1AHBw5MB/1MVwUlEWALBL Bbq55kxFanJBuhtkwUKs2hk67OFIdOvKhWkseDVShc2q1qUULy2AwEGgkLc+k2Y+6e+s pEww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=P4gIiWHTKguxh4VgYUFlflEIGElCQIuU430XqV4TbmI=; b=EEi71x2Yl8MzPA04RluHeoArpYp8zXEmM6PYsogFvw5iA81tPOEFy+5ilv6M0/+C1b ZYIRvGiznMSOxCSxkQe1IzgbG7FyXMC+/Q2r1uWB2NW+3MBFd8BfYiuArmKzzy3zK5Xw ehQy5OpvBqtOu7iPykiR46DPMne1iQ6grYKSm2yZjTTVBnRAwolyUuCBptVGQLNLnc/z nTHbEl6ctAAIboI/BEM/Zw3MTXOs03amdGDUXdbkag9jg55hIy0u5AJ5vD1e6lM4hzhd c5FGuKjPo4ws/q8gOo6mguamEguzoxw2C37YiHifsk9AxM7zAaQPZtRpLTKN++arJaj0 IqBg== X-Gm-Message-State: AIVw1135UZwmRAbZGCvW0/jWqRvMwDA9bssLShO4TUN8UmP3qUcBXi4g pdUQcE37fqAMSLh0 X-Received: by 10.98.129.196 with SMTP id t187mr39784726pfd.0.1499588174187; Sun, 09 Jul 2017 01:16:14 -0700 (PDT) Received: from localhost.localdomain (118-92-234-57.dsl.dyn.ihug.co.nz. [118.92.234.57]) by smtp.gmail.com with ESMTPSA id t23sm14838135pgb.25.2017.07.09.01.16.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Jul 2017 01:16:13 -0700 (PDT) From: Kai Huang X-Google-Original-From: Kai Huang To: xen-devel@lists.xen.org Date: Sun, 9 Jul 2017 20:16:05 +1200 Message-Id: <1a4f90045a0c61518c65fe583c96080f6f461f70.1499586046.git.kai.huang@linux.intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: Cc: wei.liu2@citrix.com, ian.jackson@eu.citrix.com, jbeulich@suse.com, andrew.cooper3@citrix.com Subject: [Xen-devel] [PATCH 15/15] xen: tools: expose EPC in ACPI 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 On physical machine EPC is exposed in ACPI table via "INT0E0C". Although EPC can be discovered by CPUID but Windows driver requires EPC to be exposed in ACPI table as well. This patch exposes EPC in ACPI table. Signed-off-by: Kai Huang --- tools/firmware/hvmloader/util.c | 23 +++++++++++++++++++ tools/firmware/hvmloader/util.h | 3 +++ tools/libacpi/build.c | 3 +++ tools/libacpi/dsdt.asl | 49 ++++++++++++++++++++++++++++++++++++++++ tools/libacpi/dsdt_acpi_info.asl | 6 +++-- tools/libacpi/libacpi.h | 1 + tools/libxl/libxl_x86_acpi.c | 3 +++ 7 files changed, 86 insertions(+), 2 deletions(-) diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c index db5f240bb9..4a1da2d63a 100644 --- a/tools/firmware/hvmloader/util.c +++ b/tools/firmware/hvmloader/util.c @@ -330,6 +330,15 @@ cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) : "0" (idx) ); } +void cpuid_count(uint32_t idx, uint32_t count, uint32_t *eax, + uint32_t *ebx, uint32_t *ecx, uint32_t *edx) +{ + asm volatile ( + "cpuid" + : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) + : "0" (idx), "c" (count) ); +} + static const char hex_digits[] = "0123456789abcdef"; /* Write a two-character hex representation of 'byte' to digits[]. @@ -888,6 +897,18 @@ static uint8_t acpi_lapic_id(unsigned cpu) return LAPIC_ID(cpu); } +static void get_epc_info(struct acpi_config *config) +{ + uint32_t eax, ebx, ecx, edx; + + cpuid_count(0x12, 0x2, &eax, &ebx, &ecx, &edx); + + config->epc_base = (((uint64_t)(ebx & 0xfffff)) << 32) | + (uint64_t)(eax & 0xfffff000); + config->epc_size = (((uint64_t)(edx & 0xfffff)) << 32) | + (uint64_t)(ecx & 0xfffff000); +} + void hvmloader_acpi_build_tables(struct acpi_config *config, unsigned int physical) { @@ -920,6 +941,8 @@ void hvmloader_acpi_build_tables(struct acpi_config *config, config->pci_hi_len = pci_hi_mem_end - pci_hi_mem_start; } + get_epc_info(config); + s = xenstore_read("platform/generation-id", "0:0"); if ( s ) { diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h index 6062f0b8cf..deac0abb86 100644 --- a/tools/firmware/hvmloader/util.h +++ b/tools/firmware/hvmloader/util.h @@ -112,6 +112,9 @@ int hpet_exists(unsigned long hpet_base); void cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx); +void cpuid_count(uint32_t idx, uint32_t count, uint32_t *eax, + uint32_t *ebx, uint32_t *ecx, uint32_t *edx); + /* Read the TSC register. */ static inline uint64_t rdtsc(void) { diff --git a/tools/libacpi/build.c b/tools/libacpi/build.c index f9881c9604..9d64856e26 100644 --- a/tools/libacpi/build.c +++ b/tools/libacpi/build.c @@ -54,6 +54,7 @@ struct acpi_info { uint32_t madt_lapic0_addr; /* 16 - Address of first MADT LAPIC struct */ uint32_t vm_gid_addr; /* 20 - Address of VM generation id buffer */ uint64_t pci_hi_min, pci_hi_len; /* 24, 32 - PCI I/O hole boundaries */ + uint64_t epc_min, epc_len; /* 40, 48 - EPC region */ }; static void set_checksum( @@ -535,6 +536,8 @@ int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config) acpi_info->pci_hi_min = config->pci_hi_start; acpi_info->pci_hi_len = config->pci_hi_len; } + acpi_info->epc_min = config->epc_base; + acpi_info->epc_len = config->epc_size; /* * Fill in high-memory data structures, starting at @buf. diff --git a/tools/libacpi/dsdt.asl b/tools/libacpi/dsdt.asl index fa8ff317b2..25ce196028 100644 --- a/tools/libacpi/dsdt.asl +++ b/tools/libacpi/dsdt.asl @@ -441,6 +441,55 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) } } } + + Device (EPC) + { + Name (_HID, EisaId ("INT0E0C")) + Name (_STR, Unicode ("Enclave Page Cache 1.5")) + Name (_MLS, Package (0x01) + { + Package (0x02) + { + "en", + Unicode ("Enclave Page Cache 1.5") + } + }) + Name (RBUF, ResourceTemplate () + { + QWordMemory (ResourceConsumer, PosDecode, MinFixed, MaxFixed, + Cacheable, ReadWrite, + 0x0000000000000000, // Granularity + 0x0000000000000000, // Range Minimum + 0x0000000000000000, // Range Maximum + 0x0000000000000000, // Translation Offset + 0x0000000000000001, // Length + ,, _Y03, + AddressRangeMemory, TypeStatic) + }) + + Method(_CRS, 0, NotSerialized) // _CRS: Current Resource Settings + { + CreateQwordField (RBUF, \_SB.EPC._Y03._MIN, EMIN) // _MIN: Minimuum Base Address + CreateQwordField (RBUF, \_SB.EPC._Y03._MAX, EMAX) // _MIN: Maximum Base Address + CreateQwordField (RBUF, \_SB.EPC._Y03._LEN, ELEN) // _LEN: Length + Store(\_SB.EMIN, EMIN) + Store(\_SB.ELEN, ELEN) + Add(EMIN, ELEN, EMAX) + Subtract(EMAX, One, EMAX) + + Return (RBUF) + } + + Method(_STA, 0, NotSerialized) // _STA: Status + { + IF ((\_SB.ELEN != Zero)) + { + Return (0x0F) + } + + Return (Zero) + } + } } /* _S3 and _S4 are in separate SSDTs */ Name (\_S5, Package (0x04) { diff --git a/tools/libacpi/dsdt_acpi_info.asl b/tools/libacpi/dsdt_acpi_info.asl index 0136dce55c..ac6b14f82f 100644 --- a/tools/libacpi/dsdt_acpi_info.asl +++ b/tools/libacpi/dsdt_acpi_info.asl @@ -5,7 +5,7 @@ * BIOS region must match struct acpi_info in build.c and * be located at ACPI_INFO_PHYSICAL_ADDRESS = 0xFC000000 */ - OperationRegion(BIOS, SystemMemory, 0xFC000000, 40) + OperationRegion(BIOS, SystemMemory, 0xFC000000, 56) Field(BIOS, ByteAcc, NoLock, Preserve) { UAR1, 1, UAR2, 1, @@ -21,6 +21,8 @@ LMIN, 32, HMIN, 32, LLEN, 32, - HLEN, 32 + HLEN, 32, + EMIN, 64, + ELEN, 64, } } diff --git a/tools/libacpi/libacpi.h b/tools/libacpi/libacpi.h index 2ed1ecfc8e..5645e0866b 100644 --- a/tools/libacpi/libacpi.h +++ b/tools/libacpi/libacpi.h @@ -63,6 +63,7 @@ struct acpi_config { /* PCI I/O hole */ uint32_t pci_start, pci_len; uint64_t pci_hi_start, pci_hi_len; + uint64_t epc_base, epc_size; uint32_t table_flags; uint8_t acpi_revision; diff --git a/tools/libxl/libxl_x86_acpi.c b/tools/libxl/libxl_x86_acpi.c index c0a6e321ec..0d62a76590 100644 --- a/tools/libxl/libxl_x86_acpi.c +++ b/tools/libxl/libxl_x86_acpi.c @@ -156,6 +156,9 @@ static int init_acpi_config(libxl__gc *gc, config->lapic_id = acpi_lapic_id; config->acpi_revision = 5; + config->epc_base = b_info->u.hvm.sgx.epcbase; + config->epc_size = (b_info->u.hvm.sgx.epckb << 10); + rc = 0; out: return rc;