From nobody Thu May 2 14:27:37 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 1515609575812781.1223007195349; Wed, 10 Jan 2018 10:39:35 -0800 (PST) Received: from localhost ([::1]:59348 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZLHi-0008Hj-Vo for importer@patchew.org; Wed, 10 Jan 2018 13:39:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43481) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZLDs-0005I5-Bz for qemu-devel@nongnu.org; Wed, 10 Jan 2018 13:35:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZLDn-0000rp-AD for qemu-devel@nongnu.org; Wed, 10 Jan 2018 13:35:36 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:44300) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eZLDm-0000r4-VU for qemu-devel@nongnu.org; Wed, 10 Jan 2018 13:35:31 -0500 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0AIYKnr060882 for ; Wed, 10 Jan 2018 13:35:29 -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 2fdkucnjkr-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 10 Jan 2018 13:35:29 -0500 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 10 Jan 2018 11:35:27 -0700 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 10 Jan 2018 11:35:25 -0700 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w0AIZPtW11207046; Wed, 10 Jan 2018 11:35:25 -0700 Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 528856E041; Wed, 10 Jan 2018 11:35:25 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP id C57726E040; Wed, 10 Jan 2018 11:35:24 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Wed, 10 Jan 2018 13:35:16 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1515609318-1897-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1515609318-1897-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18011018-8235-0000-0000-00000CD9F3A1 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008355; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000245; SDB=6.00973082; UDB=6.00493022; IPR=6.00753032; BA=6.00005772; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018965; XFM=3.00000015; UTC=2018-01-10 18:35:27 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18011018-8236-0000-0000-00003F30370D Message-Id: <1515609318-1897-2-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-10_09:, , 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=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1801100259 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [RFC PATCH 1/3] 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, 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 0xffff0000 and used by ACPI to send messages to the firmware (BIOS). This device should be used by all TPM interfaces on x86 and can be added through by calling tpm_ppi_init_io(). Signed-off-by: Stefan Berger --- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_ppi.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ hw/tpm/tpm_ppi.h | 25 ++++++++++++++++ hw/tpm/tpm_tis.c | 5 ++++ include/hw/acpi/tpm.h | 6 ++++ 5 files changed, 116 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..fa8c3c3 --- /dev/null +++ b/hw/tpm/tpm_ppi.c @@ -0,0 +1,79 @@ +/* + * 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 1 + +#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; + uint32_t val =3D 0; + int c; + + for (c =3D size - 1; c >=3D 0; c--) { + val <<=3D 8; + val |=3D s->ram[addr + c]; + } + + DPRINTF("tpm_ppi: read.%u(%08x) =3D %08x\n", size, + (unsigned int)addr, (unsigned int)val); + + return val; +} + +static void tpm_ppi_mmio_write(void *opaque, hwaddr addr, + uint64_t val, unsigned size) +{ + TPMPPI *s =3D opaque; + int c; + + DPRINTF("tpm_ppi: write.%u(%08x) =3D %08x\n", size, + (unsigned int)addr, (unsigned int)val); + + for (c =3D 0; c <=3D size - 1; c++) { + s->ram[addr + c] =3D val; + val >>=3D 8; + } +} + +static const MemoryRegionOps tpm_ppi_memory_ops =3D { + .read =3D tpm_ppi_mmio_read, + .write =3D tpm_ppi_mmio_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 1, + .max_access_size =3D 4, + }, +}; + +void tpm_ppi_init_io(TPMPPI *tpmppi, 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(get_system_memory(), + 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..8959912 --- /dev/null +++ b/hw/tpm/tpm_ppi.h @@ -0,0 +1,25 @@ +/* + * 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" + +typedef struct TPMPPI { + MemoryRegion mmio; + + uint8_t ram[TPM_PPI_ADDR_SIZE]; +} TPMPPI; + +void tpm_ppi_init_io(TPMPPI *tpmppi, Object *obj); + +#endif /* TPM_TPM_PPI_H */ diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 561384c..f980972 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) @@ -1050,6 +1053,8 @@ static void tpm_tis_initfn(Object *obj) memory_region_init_io(&s->mmio, OBJECT(s), &tpm_tis_memory_ops, s, "tpm-tis-mmio", TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT= ); + + tpm_ppi_init_io(&s->ppi, obj); } =20 static void tpm_tis_class_init(ObjectClass *klass, void *data) diff --git a/include/hw/acpi/tpm.h b/include/hw/acpi/tpm.h index 6d516c6..d9b7452 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 0x100 +#define TPM_PPI_ADDR_BASE 0xffff0000 + #endif /* HW_ACPI_TPM_H */ --=20 2.5.5 From nobody Thu May 2 14:27:37 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 1515609475608666.9667872012844; Wed, 10 Jan 2018 10:37:55 -0800 (PST) Received: from localhost ([::1]:59269 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZLG6-0006ou-Ou for importer@patchew.org; Wed, 10 Jan 2018 13:37:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZLDu-0005Ih-4k for qemu-devel@nongnu.org; Wed, 10 Jan 2018 13:35:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZLDp-0000t9-0C for qemu-devel@nongnu.org; Wed, 10 Jan 2018 13:35:38 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:57474 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 1eZLDo-0000sf-KB for qemu-devel@nongnu.org; Wed, 10 Jan 2018 13:35:32 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0AIYJsd036124 for ; Wed, 10 Jan 2018 13:35:31 -0500 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0b-001b2d01.pphosted.com with ESMTP id 2fdnxm7dr3-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 10 Jan 2018 13:35:31 -0500 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 10 Jan 2018 11:35:30 -0700 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 10 Jan 2018 11:35:27 -0700 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w0AIZRwm11469204; Wed, 10 Jan 2018 11:35:27 -0700 Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E58BC6E041; Wed, 10 Jan 2018 11:35:26 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP id 700326E045; Wed, 10 Jan 2018 11:35:26 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Wed, 10 Jan 2018 13:35:17 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1515609318-1897-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1515609318-1897-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18011018-0008-0000-0000-00000926AD30 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008355; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000245; SDB=6.00973082; UDB=6.00493022; IPR=6.00753032; BA=6.00005772; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018965; XFM=3.00000015; UTC=2018-01-10 18:35:29 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18011018-0009-0000-0000-0000457E9C82 Message-Id: <1515609318-1897-3-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-10_09:, , 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=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1801100259 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [RFC PATCH 2/3] 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, 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" LLessEqualOp =3D LNotOp LGreaterOp Signed-off-by: Stefan Berger Reviewed-by: Igor Mammedov Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/acpi/aml-build.c | 10 ++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 11 insertions(+) diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index 36a6cc4..597a58d 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -568,6 +568,16 @@ Aml *aml_lless(Aml *arg1, Aml *arg2) return var; } =20 +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 Thu May 2 14:27:37 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 1515609445897293.95976881161744; Wed, 10 Jan 2018 10:37:25 -0800 (PST) Received: from localhost ([::1]:59259 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZLFd-0006Pv-0A for importer@patchew.org; Wed, 10 Jan 2018 13:37:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43522) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZLDu-0005Ig-3g for qemu-devel@nongnu.org; Wed, 10 Jan 2018 13:35:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZLDq-0000uQ-EH for qemu-devel@nongnu.org; Wed, 10 Jan 2018 13:35:38 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:40846 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 1eZLDq-0000to-1b for qemu-devel@nongnu.org; Wed, 10 Jan 2018 13:35:34 -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 w0AIYLs6042046 for ; Wed, 10 Jan 2018 13:35:33 -0500 Received: from e37.co.us.ibm.com (e37.co.us.ibm.com [32.97.110.158]) by mx0b-001b2d01.pphosted.com with ESMTP id 2fdny4f3qc-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 10 Jan 2018 13:35:32 -0500 Received: from localhost by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 10 Jan 2018 11:35:31 -0700 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 10 Jan 2018 11:35:29 -0700 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w0AIZS9B9109990; Wed, 10 Jan 2018 11:35:28 -0700 Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A407E6E038; Wed, 10 Jan 2018 11:35:28 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP id 185CF6E04A; Wed, 10 Jan 2018 11:35:28 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Wed, 10 Jan 2018 13:35:18 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1515609318-1897-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1515609318-1897-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18011018-0024-0000-0000-000017C5C74B X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008355; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000245; SDB=6.00973082; UDB=6.00493022; IPR=6.00753032; BA=6.00005772; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018965; XFM=3.00000015; UTC=2018-01-10 18:35:30 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18011018-0025-0000-0000-00004E3C6BDD Message-Id: <1515609318-1897-4-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-10_09:, , 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-1801100259 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [RFC PATCH 3/3] 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, 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. Besides that it tests the code entered by the user and checks whether it is supported. The range of codes supported matches the range of codes supported in SeaBIOS. It uses the same datastructure for the shared memory as EDK2 does so that EDK2 and SeaBIOS could both make use of the shared memory. The underlying TCG specification is accessible from the following page. https://trustedcomputinggroup.org/tcg-physical-presence-interface-specifica= tion/ This patch implements version 1.20. Signed-off-by: Stefan Berger --- hw/i386/acpi-build.c | 227 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ include/hw/acpi/tpm.h | 15 ++++ 2 files changed, 242 insertions(+) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 18b939e..e3905a3 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,231 @@ 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_named_field("FRET", + sizeof(uint32_t) * BITS_PER_BYTE)); + aml_append(field, aml_named_field("RES1", + sizeof(uint8_t) * BITS_PER_BYTE)); + aml_append(field, aml_named_field("RES2", + sizeof(uint32_t) * BITS_PER_BYTE * 4)); + aml_append(field, aml_named_field("FAIL", + sizeof(uint32_t) * BITS_PER_BYTE)); + aml_append(dev, field); + + /* + * Write the given operations code into 'PPRQ'. + */ + method =3D aml_method("WRAM", 2, AML_SERIALIZED); + { + aml_append(method, aml_store(aml_arg(0), aml_name("PPRQ"))); + aml_append(method, aml_store(aml_arg(1), aml_name("PPRM"))); + /* 0 =3D Success */ + aml_append(method, aml_return(aml_int(0))); + } + aml_append(dev, method); + + /* + * CKOP: Check whether the opcode is valid + */ + if (tpm_version =3D=3D TPM_VERSION_1_2) { + method =3D aml_method("CKOP", 1, AML_NOTSERIALIZED); + { + ifctx =3D aml_if( + aml_or( + aml_or( + aml_and( + aml_lgreater_equal(aml_arg(0), aml_int(0)), + aml_lless_equal(aml_arg(0), aml_int(11)), + NULL + ), + aml_equal(aml_arg(0), aml_int(14)), + NULL + ), + aml_and( + aml_lgreater_equal(aml_arg(0), aml_int(21)), + aml_lless_equal(aml_arg(0), aml_int(22)), + NULL + ), + NULL + ) + ); + { + aml_append(ifctx, aml_return(aml_int(1))); + } + aml_append(method, ifctx); + + aml_append(method, aml_return(aml_int(0))); + } + } else { + method =3D aml_method("CKOP", 1, AML_NOTSERIALIZED); + { + ifctx =3D aml_if( + aml_equal(aml_arg(0), aml_int(0)) + ); + { + aml_append(ifctx, aml_return(aml_int(1))); + } + aml_append(method, ifctx); + + aml_append(method, aml_return(aml_int(0))); + } + } + aml_append(dev, method); + + 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.2 */ + ifctx2 =3D aml_if(aml_equal(aml_local(0), aml_int(1))); + { + aml_append(ifctx2, aml_return(aml_string("1.2"))); + } + aml_append(ifctx, ifctx2); + + /* submit TPM operation */ + ifctx2 =3D aml_if(aml_equal(aml_local(0), aml_int(2))); + { + aml_append(ifctx2, + aml_store(aml_derefof(aml_index(aml_arg(3), + aml_int(0))), + aml_local(0))); + ifctx3 =3D aml_if(aml_call1("CKOP", aml_local(0))); + { + aml_append(ifctx3, + aml_return(aml_call2("WRAM", + aml_local(0), + aml_int(0)))); + } + aml_append(ifctx2, ifctx3); + aml_append(ifctx2, aml_return(aml_int(1))); + } + aml_append(ifctx, ifctx2); + + /* get pending TPM operation */ + ifctx2 =3D aml_if(aml_equal(aml_local(0), aml_int(3))); + { + pak =3D aml_package(2); + aml_append(pak, aml_int(0)); + aml_append(pak, aml_name("PPRQ")); + aml_append(ifctx2, aml_return(pak)); + } + 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))); + { + /* 2 =3D reboot */ + aml_append(ifctx2, aml_return(aml_int(2))); + } + 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_name("FAIL")); + 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))); + { + aml_append(ifctx2, + aml_store(aml_derefof(aml_index(aml_arg(3), + aml_int(0))), + aml_local(0))); + ifctx3 =3D aml_if(aml_call1("CKOP", aml_local(0))); + { + aml_append(ifctx3, + aml_store(aml_call2("WRAM", + aml_local(0), + aml_int(0)), + aml_local(1))); + aml_append(ifctx3, aml_return(aml_local(1))); + } + aml_append(ifctx2, ifctx3); + /* 1 =3D requested operation not implemented */ + aml_append(ifctx2, aml_return(aml_int(1))); + } + aml_append(ifctx, ifctx2); + + /* get user confirmation status for operation */ + ifctx2 =3D aml_if(aml_equal(aml_local(0), aml_int(8))); + { + aml_append(ifctx2, + aml_store(aml_derefof(aml_index(aml_arg(3), + aml_int(0))), + aml_local(0))); + ifctx3 =3D aml_if(aml_call1("CKOP", aml_local(0))); + { + /* 4 =3D Allowed and physically present user not requi= red */ + aml_append(ifctx3, aml_return(aml_int(4))); + } + aml_append(ifctx2, ifctx3); + /* 0 =3D requested operation not implemented */ + aml_append(ifctx2, aml_return(aml_int(0))); + } + 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 +2444,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 diff --git a/include/hw/acpi/tpm.h b/include/hw/acpi/tpm.h index d9b7452..23f5da1 100644 --- a/include/hw/acpi/tpm.h +++ b/include/hw/acpi/tpm.h @@ -37,4 +37,19 @@ #define TPM_PPI_ADDR_SIZE 0x100 #define TPM_PPI_ADDR_BASE 0xffff0000 =20 +struct tpm_ppi { + uint8_t ppin; /* set by BIOS; currently initialization flag= */ + uint32_t ppip; /* set by ACPI; not used */ + uint32_t pprp; /* response from TPM; set by BIOS */ + uint32_t pprq; /* opcode; set by ACPI */ + uint32_t pprm; /* parameter for opcode; set by ACPI */ + uint32_t lppr; /* last opcode; set by BIOS */ + uint32_t fret; /* set by ACPI; not used*/ + uint32_t res1; /* reserved */ + uint32_t res2[4]; /* reserved */ + uint32_t fail; /* set by BIOS (0 =3D success) */ +} QEMU_PACKED; + +#define TPM_PPI_STRUCT_SIZE sizeof(struct tpm_ppi) + #endif /* HW_ACPI_TPM_H */ --=20 2.5.5