From nobody Fri May 3 08:57:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516118396335963.7452682257976; Tue, 16 Jan 2018 07:59:56 -0800 (PST) Received: from localhost ([::1]:43444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebTeV-0000io-Ee for importer@patchew.org; Tue, 16 Jan 2018 10:59:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebTWo-0002m8-HV for qemu-devel@nongnu.org; Tue, 16 Jan 2018 10:52:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebTWi-0003sD-Kt for qemu-devel@nongnu.org; Tue, 16 Jan 2018 10:51:58 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:43140 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ebTWi-0003rM-F4 for qemu-devel@nongnu.org; Tue, 16 Jan 2018 10:51:52 -0500 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0GFnbnW037709 for ; Tue, 16 Jan 2018 10:51:50 -0500 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 2fhm4m0vfx-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 16 Jan 2018 10:51:49 -0500 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 16 Jan 2018 08:51:49 -0700 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 16 Jan 2018 08:51:45 -0700 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w0GFpjm48126770; Tue, 16 Jan 2018 08:51:45 -0700 Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 634126A03F; Tue, 16 Jan 2018 08:51:45 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP id BED876A03C; Tue, 16 Jan 2018 08:51:44 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Tue, 16 Jan 2018 10:51:37 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1516117900-11382-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1516117900-11382-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18011615-8235-0000-0000-00000CE0A843 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008389; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000246; SDB=6.00975899; UDB=6.00494662; IPR=6.00755827; BA=6.00005781; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00019072; XFM=3.00000015; UTC=2018-01-16 15:51:47 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18011615-8236-0000-0000-00003F45B456 Message-Id: <1516117900-11382-2-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-16_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1801160221 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v2 1/4] tpm: implement virtual memory device for TPM PPI 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: marcandre.lureau@redhat.com, kevin@koconnor.net, stefanb@linux.vnet.ibm.com, lersek@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Implement a virtual memory device for the TPM Physical Presence interface. The memory is located at 0xfffef000 and used by ACPI to send messages to the firmware (BIOS) and by the firmware to provide parameters for each one of the supported codes. This device should be used by all TPM interfaces on x86 and can be added by calling tpm_ppi_init_io(). Signed-off-by: Stefan Berger --- v1->v2: - moved to byte access since an infrequently used device; this simplifies code - increase size of device to 0x400 - move device to 0xfffef000 since SeaBIOS has some code at 0xffff0000: 'On the emulators, the bios at 0xf0000 is also at 0xffff0000' --- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_ppi.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ hw/tpm/tpm_ppi.h | 26 ++++++++++++++++++++ hw/tpm/tpm_tis.c | 5 ++++ include/hw/acpi/tpm.h | 6 +++++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 hw/tpm/tpm_ppi.c create mode 100644 hw/tpm/tpm_ppi.h diff --git a/hw/tpm/Makefile.objs b/hw/tpm/Makefile.objs index 7a93b24..3eb0558 100644 --- a/hw/tpm/Makefile.objs +++ b/hw/tpm/Makefile.objs @@ -1,4 +1,4 @@ -common-obj-y +=3D tpm_util.o +common-obj-y +=3D tpm_util.o tpm_ppi.o common-obj-$(CONFIG_TPM_TIS) +=3D tpm_tis.o common-obj-$(CONFIG_TPM_PASSTHROUGH) +=3D tpm_passthrough.o common-obj-$(CONFIG_TPM_EMULATOR) +=3D tpm_emulator.o diff --git a/hw/tpm/tpm_ppi.c b/hw/tpm/tpm_ppi.c new file mode 100644 index 0000000..98e8318 --- /dev/null +++ b/hw/tpm/tpm_ppi.c @@ -0,0 +1,67 @@ +/* + * tpm_ppi.c - TPM Physical Presence Interface + * + * Copyright (C) 2018 IBM Corporation + * + * Authors: + * Stefan Berger + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "exec/memory.h" +#include "exec/address-spaces.h" + +#include "tpm_ppi.h" + +#define DEBUG_PPI 0 + +#define DPRINTF(fmt, ...) do { \ + if (DEBUG_PPI) { \ + printf(fmt, ## __VA_ARGS__); \ + } \ +} while (0) + +static uint64_t tpm_ppi_mmio_read(void *opaque, hwaddr addr, + unsigned size) +{ + TPMPPI *s =3D opaque; + + DPRINTF("tpm_ppi: read(%04x) =3D %02x\n", + (unsigned int)addr, (unsigned int)s->ram[addr]); + + return s->ram[addr]; +} + +static void tpm_ppi_mmio_write(void *opaque, hwaddr addr, + uint64_t val, unsigned size) +{ + TPMPPI *s =3D opaque; + + DPRINTF("tpm_ppi: write(%04x) =3D %02x\n", + (unsigned int)addr, (unsigned int)val); + + s->ram[addr] =3D val; +} + +static const MemoryRegionOps tpm_ppi_memory_ops =3D { + .read =3D tpm_ppi_mmio_read, + .write =3D tpm_ppi_mmio_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid =3D { + .min_access_size =3D 1, + .max_access_size =3D 1, + }, +}; + +void tpm_ppi_init_io(TPMPPI *tpmppi, struct MemoryRegion *m, Object *obj) +{ + memory_region_init_io(&tpmppi->mmio, obj, &tpm_ppi_memory_ops, + tpmppi, "tpm-ppi-mmio", + TPM_PPI_ADDR_SIZE); + + memory_region_add_subregion(m, TPM_PPI_ADDR_BASE, &tpmppi->mmio); +} diff --git a/hw/tpm/tpm_ppi.h b/hw/tpm/tpm_ppi.h new file mode 100644 index 0000000..17030bd --- /dev/null +++ b/hw/tpm/tpm_ppi.h @@ -0,0 +1,26 @@ +/* + * TPM Physical Presence Interface + * + * Copyright (C) 2018 IBM Corporation + * + * Authors: + * Stefan Berger + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ +#ifndef TPM_TPM_PPI_H +#define TPM_TPM_PPI_H + +#include "hw/acpi/tpm.h" +#include "exec/address-spaces.h" + +typedef struct TPMPPI { + MemoryRegion mmio; + + uint8_t ram[TPM_PPI_ADDR_SIZE]; +} TPMPPI; + +void tpm_ppi_init_io(TPMPPI *tpmppi, struct MemoryRegion *m, Object *obj); + +#endif /* TPM_TPM_PPI_H */ diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 561384c..13e7dd3 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -31,6 +31,7 @@ #include "sysemu/tpm_backend.h" #include "tpm_int.h" #include "tpm_util.h" +#include "tpm_ppi.h" =20 #define TPM_TIS_NUM_LOCALITIES 5 /* per spec */ #define TPM_TIS_LOCALITY_SHIFT 12 @@ -80,6 +81,8 @@ typedef struct TPMState { TPMVersion be_tpm_version; =20 size_t be_buffer_size; + + TPMPPI ppi; } TPMState; =20 #define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) @@ -1041,6 +1044,8 @@ static void tpm_tis_realizefn(DeviceState *dev, Error= **errp) =20 memory_region_add_subregion(isa_address_space(ISA_DEVICE(dev)), TPM_TIS_ADDR_BASE, &s->mmio); + + tpm_ppi_init_io(&s->ppi, isa_address_space(ISA_DEVICE(dev)), OBJECT(s)= ); } =20 static void tpm_tis_initfn(Object *obj) diff --git a/include/hw/acpi/tpm.h b/include/hw/acpi/tpm.h index 6d516c6..16227bc 100644 --- a/include/hw/acpi/tpm.h +++ b/include/hw/acpi/tpm.h @@ -31,4 +31,10 @@ =20 #define TPM2_START_METHOD_MMIO 6 =20 +/* + * Physical Presence Interface + */ +#define TPM_PPI_ADDR_SIZE 0x400 +#define TPM_PPI_ADDR_BASE 0xfffef000 + #endif /* HW_ACPI_TPM_H */ --=20 2.5.5 From nobody Fri May 3 08:57:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516118190301625.2375633417678; Tue, 16 Jan 2018 07:56:30 -0800 (PST) Received: from localhost ([::1]:43320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebTay-0005yh-5w for importer@patchew.org; Tue, 16 Jan 2018 10:56:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53607) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebTWm-0002kK-HD for qemu-devel@nongnu.org; Tue, 16 Jan 2018 10:51:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebTWj-0003sx-9E for qemu-devel@nongnu.org; Tue, 16 Jan 2018 10:51:56 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:52182 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ebTWj-0003sQ-40 for qemu-devel@nongnu.org; Tue, 16 Jan 2018 10:51:53 -0500 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0GFnjNm102371 for ; Tue, 16 Jan 2018 10:51:52 -0500 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 2fhkkcub6g-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 16 Jan 2018 10:51:52 -0500 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 16 Jan 2018 08:51:51 -0700 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 16 Jan 2018 08:51:47 -0700 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w0GFplWZ11076044; Tue, 16 Jan 2018 08:51:47 -0700 Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2F5F06A03B; Tue, 16 Jan 2018 08:51:47 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP id 896276A03C; Tue, 16 Jan 2018 08:51:46 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Tue, 16 Jan 2018 10:51:38 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1516117900-11382-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1516117900-11382-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18011615-8235-0000-0000-00000CE0A845 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008389; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000246; SDB=6.00975899; UDB=6.00494662; IPR=6.00755827; BA=6.00005781; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00019072; XFM=3.00000015; UTC=2018-01-16 15:51:49 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18011615-8236-0000-0000-00003F45B45A Message-Id: <1516117900-11382-3-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-16_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1801160221 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v2 2/4] acpi: build QEMU table for PPI virtual memory device 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: marcandre.lureau@redhat.com, kevin@koconnor.net, stefanb@linux.vnet.ibm.com, lersek@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" To avoid having to hard code the base address of the PPI virtual memory device we introduce a QEMU ACPI table that holds the base address, if a TPM 1.2 or 2 is used. This table gives us flexibility to move the base address later on. Signed-off-by: Stefan Berger --- hw/i386/acpi-build.c | 19 +++++++++++++++++++ include/hw/acpi/acpi-defs.h | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 18b939e..522d6d2 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2628,6 +2628,20 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg) return true; } =20 +static void build_qemu(GArray *table_data, BIOSLinker *linker, + TPMVersion tpm_version) +{ + AcpiTableQemu *qemu =3D acpi_data_push(table_data, sizeof(*qemu)); + + if (tpm_version !=3D TPM_VERSION_UNSPEC) { + qemu->tpmppi_addr =3D TPM_PPI_ADDR_BASE; + qemu->tpm_version =3D tpm_version; + } + + build_header(linker, table_data, + (void *)qemu, "QEMU", sizeof(*qemu), 1, "QEMU", "CONF"); +} + static void acpi_build(AcpiBuildTables *tables, MachineState *machine) { @@ -2734,6 +2748,11 @@ void acpi_build(AcpiBuildTables *tables, MachineStat= e *machine) &pcms->acpi_nvdimm_state, machine->ram_slots); } =20 + if (misc.tpm_version !=3D TPM_VERSION_UNSPEC) { + acpi_add_table(table_offsets, tables_blob); + build_qemu(tables_blob, tables->linker, misc.tpm_version); + } + /* Add tables supplied by user (if any) */ for (u =3D acpi_table_first(); u; u =3D acpi_table_next(u)) { unsigned len =3D acpi_table_len(u); diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h index 80c8099..98764c1 100644 --- a/include/hw/acpi/acpi-defs.h +++ b/include/hw/acpi/acpi-defs.h @@ -573,6 +573,14 @@ struct Acpi20TPM2 { } QEMU_PACKED; typedef struct Acpi20TPM2 Acpi20TPM2; =20 +/* QEMU - Custom QEMU table */ +struct AcpiTableQemu { + ACPI_TABLE_HEADER_DEF + uint32_t tpmppi_addr; + uint8_t tpm_version; /* 1 =3D 1.2, 2 =3D 2 */ +}; +typedef struct AcpiTableQemu AcpiTableQemu; + /* DMAR - DMA Remapping table r2.2 */ struct AcpiTableDmar { ACPI_TABLE_HEADER_DEF --=20 2.5.5 From nobody Fri May 3 08:57:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516119399299311.77585175493437; Tue, 16 Jan 2018 08:16:39 -0800 (PST) Received: from localhost ([::1]:45014 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebTug-0008KC-HV for importer@patchew.org; Tue, 16 Jan 2018 11:16:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53640) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebTWp-0002ma-2O for qemu-devel@nongnu.org; Tue, 16 Jan 2018 10:52:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebTWl-0003uO-7G for qemu-devel@nongnu.org; Tue, 16 Jan 2018 10:51:59 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:50328 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ebTWl-0003u6-1u for qemu-devel@nongnu.org; Tue, 16 Jan 2018 10:51:55 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0GFnhXL054280 for ; Tue, 16 Jan 2018 10:51:53 -0500 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0b-001b2d01.pphosted.com with ESMTP id 2fhkkrju0e-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 16 Jan 2018 10:51:52 -0500 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 16 Jan 2018 08:51:51 -0700 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 16 Jan 2018 08:51:49 -0700 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w0GFpngF12779920; Tue, 16 Jan 2018 08:51:49 -0700 Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD53D6A03B; Tue, 16 Jan 2018 08:51:48 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP id 4B5EA6A048; Tue, 16 Jan 2018 08:51:48 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Tue, 16 Jan 2018 10:51:39 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1516117900-11382-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1516117900-11382-1-git-send-email-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18011615-0012-0000-0000-0000159B6EC2 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008389; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000246; SDB=6.00975899; UDB=6.00494662; IPR=6.00755827; BA=6.00005781; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00019072; XFM=3.00000015; UTC=2018-01-16 15:51:51 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18011615-0013-0000-0000-000051161BA1 Message-Id: <1516117900-11382-4-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-16_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1801160221 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0b-001b2d01.pphosted.com id w0GFnhXL054280 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v2 3/4] acpi: implement aml_lless_equal 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: marcandre.lureau@redhat.com, kevin@koconnor.net, stefanb@linux.vnet.ibm.com, lersek@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" LLessEqualOp =3D LNotOp LGreaterOp Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Igor Mammedov Reviewed-by: Michael S. Tsirkin --- hw/acpi/aml-build.c | 11 +++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 12 insertions(+) diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index 36a6cc4..c475f56 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -568,6 +568,17 @@ Aml *aml_lless(Aml *arg1, Aml *arg2) return var; } =20 +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLLessEqual */ +Aml *aml_lless_equal(Aml *arg1, Aml *arg2) +{ + /* LLessEqualOp :=3D LNotOp LGreaterOp */ + Aml *var =3D aml_opcode(0x92 /* LNotOp */); + build_append_byte(var->buf, 0x94 /* LGreaterOp */); + aml_append(var, arg1); + aml_append(var, arg2); + return var; +} + /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefAdd */ Aml *aml_add(Aml *arg1, Aml *arg2, Aml *dst) { diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index 88d0738..c4398cc 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -267,6 +267,7 @@ Aml *aml_lor(Aml *arg1, Aml *arg2); Aml *aml_shiftleft(Aml *arg1, Aml *count); Aml *aml_shiftright(Aml *arg1, Aml *count, Aml *dst); Aml *aml_lless(Aml *arg1, Aml *arg2); +Aml *aml_lless_equal(Aml *arg1, Aml *arg2); Aml *aml_add(Aml *arg1, Aml *arg2, Aml *dst); Aml *aml_subtract(Aml *arg1, Aml *arg2, Aml *dst); Aml *aml_increment(Aml *arg); --=20 2.5.5 From nobody Fri May 3 08:57:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516118358148271.0533334010246; Tue, 16 Jan 2018 07:59:18 -0800 (PST) Received: from localhost ([::1]:43416 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebTdt-00009T-6h for importer@patchew.org; Tue, 16 Jan 2018 10:59:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53652) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebTWr-0002mq-2J for qemu-devel@nongnu.org; Tue, 16 Jan 2018 10:52:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebTWm-0003vn-VY for qemu-devel@nongnu.org; Tue, 16 Jan 2018 10:52:01 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:45062) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ebTWm-0003vB-MY for qemu-devel@nongnu.org; Tue, 16 Jan 2018 10:51:56 -0500 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0GFoqdu026128 for ; Tue, 16 Jan 2018 10:51:55 -0500 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0a-001b2d01.pphosted.com with ESMTP id 2fhgrpmmbx-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 16 Jan 2018 10:51:54 -0500 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 16 Jan 2018 08:51:54 -0700 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 16 Jan 2018 08:51:51 -0700 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w0GFponv14221612; Tue, 16 Jan 2018 08:51:50 -0700 Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A54486A043; Tue, 16 Jan 2018 08:51:50 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP id 05E156A03B; Tue, 16 Jan 2018 08:51:49 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Tue, 16 Jan 2018 10:51:40 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1516117900-11382-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1516117900-11382-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18011615-0016-0000-0000-0000081E716E X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008389; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000246; SDB=6.00975899; UDB=6.00494662; IPR=6.00755827; BA=6.00005781; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00019072; XFM=3.00000015; UTC=2018-01-16 15:51:52 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18011615-0017-0000-0000-00003D120853 Message-Id: <1516117900-11382-5-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-16_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1801160221 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v2 4/4] acpi: build TPM Physical Presence interface 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: marcandre.lureau@redhat.com, kevin@koconnor.net, stefanb@linux.vnet.ibm.com, lersek@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The TPM Physical Presence interface consists of an ACPI part, a shared memory part, and code in the firmware. Users can send messages to the firmware by writing a code into the shared memory through invoking the ACPI code. When a reboot happens, the firmware looks for the code and acts on it by sending sequences of commands to the TPM. This patch adds the ACPI code. It is similar to the one in EDK2 but doesn't assume that SMIs are necessary to use. It uses a similar datastructure for the shared memory as EDK2 does so that EDK2 and SeaBIOS could both make use of it. I extended the shared memory data structure with an array of 256 bytes, one for each code that could be implemented. The array contains flags describing the individual codes. This decouples the ACPI implementati= on from the firmware implementation. The underlying TCG specification is accessible from the following page. https://trustedcomputinggroup.org/tcg-physical-presence-interface-specifica= tion/ This patch implements version 1.30. Signed-off-by: Stefan Berger --- v1->v2: - get rid of FAIL variable; function 5 was using it and always returns 0; the value is related to the ACPI function call not a possible failure of the TPM function call. - extend shared memory data structure with per-opcode entries holding flags and use those flags to determine what to return to caller - implement interface version 1.3 --- hw/i386/acpi-build.c | 273 ++++++++++++++++++++++++++++++++++++++++= ++++ include/hw/acpi/acpi-defs.h | 2 + include/hw/acpi/tpm.h | 31 +++++ 3 files changed, 306 insertions(+) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 522d6d2..f8c2d01 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -42,6 +42,7 @@ #include "hw/acpi/memory_hotplug.h" #include "sysemu/tpm.h" #include "hw/acpi/tpm.h" +#include "hw/tpm/tpm_ppi.h" #include "hw/acpi/vmgenid.h" #include "sysemu/tpm_backend.h" #include "hw/timer/mc146818rtc_regs.h" @@ -1860,6 +1861,276 @@ static Aml *build_q35_osc_method(void) } =20 static void +build_tpm_ppi(Aml *dev, TPMVersion tpm_version) +{ + Aml *method, *field, *ifctx, *ifctx2, *ifctx3, *pak; + + aml_append(dev, + aml_operation_region("TPPI", AML_SYSTEM_MEMORY, + aml_int(TPM_PPI_ADDR_BASE), + TPM_PPI_STRUCT_SIZE)); + + field =3D aml_field("TPPI", AML_ANY_ACC, AML_NOLOCK, AML_PRESERVE); + aml_append(field, aml_named_field("PPIN", + sizeof(uint8_t) * BITS_PER_BYTE)); + aml_append(field, aml_named_field("PPIP", + sizeof(uint32_t) * BITS_PER_BYTE)); + aml_append(field, aml_named_field("PPRP", + sizeof(uint32_t) * BITS_PER_BYTE)); + aml_append(field, aml_named_field("PPRQ", + sizeof(uint32_t) * BITS_PER_BYTE)); + aml_append(field, aml_named_field("PPRM", + sizeof(uint32_t) * BITS_PER_BYTE)); + aml_append(field, aml_named_field("LPPR", + sizeof(uint32_t) * BITS_PER_BYTE)); + aml_append(field, aml_reserved_field( + sizeof(uint32_t) * BITS_PER_BYTE /* FRET */ + + sizeof(uint8_t) * BITS_PER_BYTE /* MCIN */ + + sizeof(uint32_t) * BITS_PER_BYTE * 4 /* MCIP .. UCRQ */ + + sizeof(uint8_t) * BITS_PER_BYTE * 214)); + aml_append(field, aml_named_field("FUNC", + sizeof(uint8_t) * BITS_PER_BYTE * 256)); + aml_append(dev, field); + + method =3D aml_method("_DSM", 4, AML_SERIALIZED); + { + uint8_t zerobyte[1] =3D { 0 }; + + ifctx =3D aml_if( + aml_equal(aml_arg(0), + aml_touuid("3DDDFAA6-361B-4EB4-A424-8D10089D16= 53")) + ); + { + aml_append(ifctx, + aml_store(aml_to_integer(aml_arg(2)), aml_local(0))= ); + + /* standard DSM query function */ + ifctx2 =3D aml_if(aml_equal(aml_local(0), aml_int(0))); + { + uint8_t byte_list[2] =3D { 0xff, 0x01 }; + aml_append(ifctx2, aml_return(aml_buffer(2, byte_list))); + } + aml_append(ifctx, ifctx2); + + /* interface version: 1.3 */ + ifctx2 =3D aml_if(aml_equal(aml_local(0), aml_int(1))); + { + aml_append(ifctx2, aml_return(aml_string("1.3"))); + } + aml_append(ifctx, ifctx2); + + /* submit TPM operation */ + ifctx2 =3D aml_if(aml_equal(aml_local(0), aml_int(2))); + { + /* get opcode */ + aml_append(ifctx2, + aml_store(aml_derefof(aml_index(aml_arg(3), + aml_int(0))), + aml_local(0))); + /* get opcode flags */ + aml_append(ifctx2, + aml_store(aml_derefof(aml_index(aml_name("FUNC"= ), + aml_local(0))), + aml_local(1))); + ifctx3 =3D aml_if( + aml_equal( + aml_and(aml_local(1), + aml_int(TPM_PPI_FUNC_IMPLEMENTED= ), + NULL), + aml_int(0) + ) + ); + { + /* 1: not implemented */ + aml_append(ifctx3, aml_return(aml_int(1))); + } + aml_append(ifctx2, ifctx3); + aml_append(ifctx2, aml_store(aml_local(0), aml_name("PPRQ"= ))); + aml_append(ifctx2, aml_store(aml_int(0), aml_name("PPRM"))= ); + /* 0: success */ + aml_append(ifctx2, aml_return(aml_int(0))); + } + aml_append(ifctx, ifctx2); + + /* get pending TPM operation */ + ifctx2 =3D aml_if(aml_equal(aml_local(0), aml_int(3))); + { + /* revision to integer */ + aml_append(ifctx2, + aml_store( + aml_to_integer(aml_arg(1)), + aml_local(1))); + ifctx3 =3D aml_if(aml_equal(aml_local(1), aml_int(1))); + { + pak =3D aml_package(2); + aml_append(pak, aml_int(0)); + aml_append(pak, aml_name("PPRQ")); + aml_append(ifctx3, aml_return(pak)); + } + aml_append(ifctx2, ifctx3); + + ifctx3 =3D aml_if(aml_equal(aml_local(1), aml_int(2))); + { + pak =3D aml_package(3); + aml_append(pak, aml_int(0)); + aml_append(pak, aml_name("PPRQ")); + aml_append(pak, aml_name("PPRM")); + aml_append(ifctx3, aml_return(pak)); + } + aml_append(ifctx2, ifctx3); + } + aml_append(ifctx, ifctx2); + + /* get platform-specific action to transition to pre-OS env. */ + ifctx2 =3D aml_if(aml_equal(aml_local(0), aml_int(4))); + { + /* get opcode */ + aml_append(ifctx2, + aml_store(aml_name("PPRQ"), + aml_local(0))); + /* get opcode flags */ + aml_append(ifctx2, + aml_store(aml_derefof(aml_index(aml_name("FUNC"= ), + aml_local(0))), + aml_local(1))); + /* return action flags */ + aml_append(ifctx2, + aml_return( + aml_shiftright( + aml_and(aml_local(1), + aml_int(TPM_PPI_FUNC_ACTION_MAS= K), + NULL), + aml_int(1), + NULL))); + } + aml_append(ifctx, ifctx2); + + /* get TPM operation response */ + ifctx2 =3D aml_if(aml_equal(aml_local(0), aml_int(5))); + { + pak =3D aml_package(3); + + aml_append(pak, aml_int(0)); + aml_append(pak, aml_name("LPPR")); + aml_append(pak, aml_name("PPRP")); + + aml_append(ifctx2, aml_return(pak)); + } + aml_append(ifctx, ifctx2); + + /* submit preferred user language */ + ifctx2 =3D aml_if(aml_equal(aml_local(0), aml_int(6))); + { + /* 3 =3D not implemented */ + aml_append(ifctx2, aml_return(aml_int(3))); + } + aml_append(ifctx, ifctx2); + + /* submit TPM operation v2 */ + ifctx2 =3D aml_if(aml_equal(aml_local(0), aml_int(7))); + { + /* get opcode */ + aml_append(ifctx2, + aml_store(aml_derefof(aml_index(aml_arg(3), + aml_int(0))), + aml_local(0))); + /* get opcode flags */ + aml_append(ifctx2, + aml_store(aml_derefof(aml_index(aml_name("FUNC"= ), + aml_local(0))), + aml_local(1))); + ifctx3 =3D aml_if( + aml_equal( + aml_and(aml_local(1), + aml_int(TPM_PPI_FUNC_MASK), + NULL), + aml_int(TPM_PPI_FUNC_NOT_IMPLEMENTED) + ) + ); + { + /* 1: not implemented */ + aml_append(ifctx3, aml_return(aml_int(1))); + } + aml_append(ifctx2, ifctx3); + + ifctx3 =3D aml_if( + aml_equal( + aml_and( + aml_local(1), + aml_int(TPM_PPI_FUNC_MASK), + NULL), + aml_int(TPM_PPI_FUNC_BLOCKED) + ) + ); + { + /* 3: blocked by firmware */ + aml_append(ifctx3, aml_return(aml_int(3))); + } + aml_append(ifctx2, ifctx3); + + /* revision to integer */ + aml_append(ifctx2, + aml_store( + aml_to_integer(aml_arg(1)), + aml_local(1))); + + ifctx3 =3D aml_if(aml_equal(aml_local(1), aml_int(1))); + { + /* revision 1 */ + aml_append(ifctx3, aml_store(aml_local(0), aml_name("P= PRQ"))); + aml_append(ifctx3, aml_store(aml_int(0), aml_name("PPR= M"))); + } + aml_append(ifctx2, ifctx3); + + ifctx3 =3D aml_if(aml_equal(aml_local(1), aml_int(2))); + { + /* revision 2 */ + aml_append(ifctx3, aml_store(aml_local(0), aml_name("P= PRQ"))); + aml_append(ifctx3, aml_store( + aml_derefof( + aml_index(aml_arg(3), + aml_int(1))), + aml_name("PPRM"))); + } + aml_append(ifctx2, ifctx3); + /* 0: success */ + aml_append(ifctx2, aml_return(aml_int(0))); + } + aml_append(ifctx, ifctx2); + + /* get user confirmation status for operation */ + ifctx2 =3D aml_if(aml_equal(aml_local(0), aml_int(8))); + { + /* get opcode */ + aml_append(ifctx2, + aml_store(aml_derefof(aml_index(aml_arg(3), + aml_int(0))), + aml_local(0))); + /* get opcode flags */ + aml_append(ifctx2, + aml_store(aml_derefof(aml_index(aml_name("FUNC"= ), + aml_local(0))), + aml_local(1))); + /* return confirmation status code */ + aml_append(ifctx2, + aml_return( + aml_shiftright( + aml_and(aml_local(1), + aml_int(TPM_PPI_FUNC_MASK), + NULL), + aml_int(3), + NULL))); + } + aml_append(ifctx, ifctx2); + + aml_append(ifctx, aml_return(aml_buffer(1, zerobyte))); + } + aml_append(method, ifctx); + } + aml_append(dev, method); +} + +static void build_dsdt(GArray *table_data, BIOSLinker *linker, AcpiPmInfo *pm, AcpiMiscInfo *misc, Range *pci_hole, Range *pci_hole64, MachineState *machine) @@ -2218,6 +2489,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, */ /* aml_append(crs, aml_irq_no_flags(TPM_TIS_IRQ)); */ aml_append(dev, aml_name_decl("_CRS", crs)); + build_tpm_ppi(dev, misc->tpm_version); aml_append(scope, dev); } =20 @@ -2636,6 +2908,7 @@ static void build_qemu(GArray *table_data, BIOSLinker= *linker, if (tpm_version !=3D TPM_VERSION_UNSPEC) { qemu->tpmppi_addr =3D TPM_PPI_ADDR_BASE; qemu->tpm_version =3D tpm_version; + qemu->tpmppi_version =3D TPM_PPI_VERSION_1_30; } =20 build_header(linker, table_data, diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h index 98764c1..a182194 100644 --- a/include/hw/acpi/acpi-defs.h +++ b/include/hw/acpi/acpi-defs.h @@ -578,6 +578,8 @@ struct AcpiTableQemu { ACPI_TABLE_HEADER_DEF uint32_t tpmppi_addr; uint8_t tpm_version; /* 1 =3D 1.2, 2 =3D 2 */ + uint8_t tpmppi_version; +#define TPM_PPI_VERSION_1_30 1 }; typedef struct AcpiTableQemu AcpiTableQemu; =20 diff --git a/include/hw/acpi/tpm.h b/include/hw/acpi/tpm.h index 16227bc..130a039 100644 --- a/include/hw/acpi/tpm.h +++ b/include/hw/acpi/tpm.h @@ -37,4 +37,35 @@ #define TPM_PPI_ADDR_SIZE 0x400 #define TPM_PPI_ADDR_BASE 0xfffef000 =20 +struct tpm_ppi { + uint8_t ppin; /* 0: set by BIOS */ + uint32_t ppip; /* 1: set by ACPI; not used */ + uint32_t pprp; /* 5: response from TPM; set by BIOS */ + uint32_t pprq; /* 9: opcode; set by ACPI */ + uint32_t pprm; /* 13: parameter for opcode; set by ACPI */ + uint32_t lppr; /* 17: last opcode; set by BIOS */ + uint32_t fret; /* 21: set by ACPI; not used */ + uint8_t res1; /* 25: reserved */ + uint32_t res2[4]; /* 26: reserved */ + uint8_t res3[214]; /* 42: reserved */ + uint8_t func[256]; /* 256: per TPM function implementation flags; + set by BIOS */ +/* indication whether function is implemented; bit 0 */ +#define TPM_PPI_FUNC_IMPLEMENTED (1 << 0) +/* actions OS should take to transition to the pre-OS env.; bits 1, 2 */ +#define TPM_PPI_FUNC_ACTION_SHUTDOWN (1 << 1) +#define TPM_PPI_FUNC_ACTION_REBOOT (2 << 1) +#define TPM_PPI_FUNC_ACTION_VENDOR (3 << 1) +#define TPM_PPI_FUNC_ACTION_MASK (3 << 1) +/* whether function is blocked by BIOS settings; bits 3,4,5 */ +#define TPM_PPI_FUNC_NOT_IMPLEMENTED (0 << 3) +#define TPM_PPI_FUNC_BIOS_ONLY (1 << 3) +#define TPM_PPI_FUNC_BLOCKED (2 << 3) +#define TPM_PPI_FUNC_ALLOWED_USR_REQ (3 << 3) +#define TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ (4 << 3) +#define TPM_PPI_FUNC_MASK (7 << 3) +} QEMU_PACKED; + +#define TPM_PPI_STRUCT_SIZE sizeof(struct tpm_ppi) + #endif /* HW_ACPI_TPM_H */ --=20 2.5.5