From nobody Thu Nov 13 20:44:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582712932; cv=none; d=zohomail.com; s=zohoarc; b=VylgmumrYJoYpFfJRU73fsvZKB7BPTlxLqXvR68+rLaadzkaCauQ+hTFn4E7wc7QmenUafsMD3Kx3HZE4OyeKAR578bQPhMT1J6KzkX6dV+evxrtLLhAYdTwKjjaQodfZoqE3OalI4HtTkyrTQIg3iZ1KzV1GUcItDwPNF4dQ9o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582712932; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dczexdrzKnZ7PKgnzotlQQq1ZEpy0uEpqYyknsl6HD4=; b=nEESRI211bt4OJJtNYSyMBEGJURztmo6Cof2vMrLM05NYulrFTO15wwOCzgGgtI2LkDj2ILd2HTPS3MJvm5eIMblZumXZ5W1YAdPQc7scIiBkYgLLKp1qeI3Pe/SbgPWtl1MvNdyJGpEoODfQZXgRnMQoeUcfxiflblIR9ZqXOQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582712932894867.1440002516337; Wed, 26 Feb 2020 02:28:52 -0800 (PST) Received: from localhost ([::1]:42054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6tvv-0000b0-O2 for importer@patchew.org; Wed, 26 Feb 2020 05:28:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51978) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ttO-0004AS-Rq for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ttN-0003Kx-Mx for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:14 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:54779 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6ttN-0003KU-JI for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:13 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-40-heVrupBnO3iOb6I5zH8k1A-1; Wed, 26 Feb 2020 05:26:09 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 223FB1882CCC; Wed, 26 Feb 2020 10:26:08 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5ECE60BE1; Wed, 26 Feb 2020 10:26:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582712772; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dczexdrzKnZ7PKgnzotlQQq1ZEpy0uEpqYyknsl6HD4=; b=ch+Cy7HjTIxuN54OawWbTFBIstCHB0WDLRPgxgEAlo9wL0JgmZ/jPW4d/oI2Fy6LVQVlER +cvkbLFj4Hdwy7AIJB4VogKxTLTR+pZh2awkQr926WH/QJltd7e2ejjZbzGsrdAaEiDQlH KNO9W0ohgGBwKdHRyw+9hweMBsF9W/8= X-MC-Unique: heVrupBnO3iOb6I5zH8k1A-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, stefanb@linux.ibm.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org Subject: [PATCH v3 01/10] tpm: rename TPM_TIS into TPM_TIS_ISA Date: Wed, 26 Feb 2020 11:25:40 +0100 Message-Id: <20200226102549.12158-2-eric.auger@redhat.com> In-Reply-To: <20200226102549.12158-1-eric.auger@redhat.com> References: <20200226102549.12158-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, lersek@redhat.com, ardb@kernel.org, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" As we plan to introduce a sysbus TPM_TIS, let's rename TPM_TIS into TPM_TIS_ISA. Signed-off-by: Eric Auger Reviewed-by: Stefan Berger Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- RFC v2 -> PATCH: - added Philippe and Stefan's R-b --- hw/i386/acpi-build.c | 6 +++--- hw/tpm/tpm_tis.c | 4 ++-- include/sysemu/tpm.h | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 9c4e46fa74..26777f8828 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2026,7 +2026,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, } } =20 - if (TPM_IS_TIS(tpm_find())) { + if (TPM_IS_TIS_ISA(tpm_find())) { aml_append(crs, aml_memory32_fixed(TPM_TIS_ADDR_BASE, TPM_TIS_ADDR_SIZE, AML_READ_WRITE)); } @@ -2197,7 +2197,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, /* Scan all PCI buses. Generate tables to support hotplug. */ build_append_pci_bus_devices(scope, bus, pm->pcihp_bridge_en); =20 - if (TPM_IS_TIS(tpm)) { + if (TPM_IS_TIS_ISA(tpm)) { if (misc->tpm_version =3D=3D TPM_VERSION_2_0) { dev =3D aml_device("TPM"); aml_append(dev, aml_name_decl("_HID", @@ -2304,7 +2304,7 @@ build_tpm2(GArray *table_data, BIOSLinker *linker, GA= rray *tcpalog) (char *)&tpm2_ptr->log_area_start_address - table_data->data; =20 tpm2_ptr->platform_class =3D cpu_to_le16(TPM2_ACPI_CLASS_CLIENT); - if (TPM_IS_TIS(tpm_find())) { + if (TPM_IS_TIS_ISA(tpm_find())) { tpm2_ptr->control_area_address =3D cpu_to_le64(0); tpm2_ptr->start_method =3D cpu_to_le32(TPM2_START_METHOD_MMIO); } else if (TPM_IS_CRB(tpm_find())) { diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 31facb896d..c609737272 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -91,7 +91,7 @@ typedef struct TPMState { TPMPPI ppi; } TPMState; =20 -#define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) +#define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS_ISA) =20 #define DEBUG_TIS 0 =20 @@ -1008,7 +1008,7 @@ static void tpm_tis_class_init(ObjectClass *klass, vo= id *data) } =20 static const TypeInfo tpm_tis_info =3D { - .name =3D TYPE_TPM_TIS, + .name =3D TYPE_TPM_TIS_ISA, .parent =3D TYPE_ISA_DEVICE, .instance_size =3D sizeof(TPMState), .instance_init =3D tpm_tis_initfn, diff --git a/include/sysemu/tpm.h b/include/sysemu/tpm.h index 15979a3647..1691b92c28 100644 --- a/include/sysemu/tpm.h +++ b/include/sysemu/tpm.h @@ -43,12 +43,12 @@ typedef struct TPMIfClass { enum TPMVersion (*get_version)(TPMIf *obj); } TPMIfClass; =20 -#define TYPE_TPM_TIS "tpm-tis" +#define TYPE_TPM_TIS_ISA "tpm-tis" #define TYPE_TPM_CRB "tpm-crb" #define TYPE_TPM_SPAPR "tpm-spapr" =20 -#define TPM_IS_TIS(chr) \ - object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS) +#define TPM_IS_TIS_ISA(chr) \ + object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_ISA) #define TPM_IS_CRB(chr) \ object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB) #define TPM_IS_SPAPR(chr) \ --=20 2.20.1 From nobody Thu Nov 13 20:44:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582712834; cv=none; d=zohomail.com; s=zohoarc; b=MbYRiv3oZd+bYbpvsXBYR+Tx6XM/ctPZiIALMSNraJJEZqA+qQrHgI6vw8Gsa7UXs4m7GyOwxC19u8gpppHWouCylkTKVPeYMMNIlXEyS4x5eYyGSjOXFgsoflwIacWzSusN4iUazveIfxI6nrP6OYJ5iswVFrVK8AveCpRXTUQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582712834; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9uMhQHMXH71Sb887zTkI8TLK1u6tYlprGIRZNEHnVkk=; b=FvtheLVP5qoJ1iE6sq59hcwHmdso0HuOauPh8n0U04ZRsaLv4Qf66z36KIjrSoX5m2wkBiLl9DzJXXpohR63v1TdXqiVNARb179dZx7ciybNrYK1gahDKCsvRpaRROWlVEFFDobPf7vGGzWhBkoo9kEgaO+Rnj/jNFN7H9smJO4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582712834273253.60631383335158; Wed, 26 Feb 2020 02:27:14 -0800 (PST) Received: from localhost ([::1]:42024 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6tuL-0005ux-22 for importer@patchew.org; Wed, 26 Feb 2020 05:27:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52009) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ttQ-0004DJ-Dv for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ttO-0003Mq-NK for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:16 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:34425 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6ttO-0003Ls-Hp for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:14 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-84-5xkjpLqaPAKjHQtBiemdPg-1; Wed, 26 Feb 2020 05:26:12 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 60477107ACCC; Wed, 26 Feb 2020 10:26:11 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7BBB460BE1; Wed, 26 Feb 2020 10:26:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582712774; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9uMhQHMXH71Sb887zTkI8TLK1u6tYlprGIRZNEHnVkk=; b=ZafmLnrrPIrCaoBemMJdqle4iuhzanErkjP1bGZIsXrdiux9GmAM5j8xLgSElC6hLm4YHR tnNRkNZvBe2ZgSks+n3trX4yKQYokwieQvEL/WFRNCR3YW1OSbRFowE4HrkkKy/YoWcREq U46TWF8npXasOAGUNiLGpQ33TTpZKP0= X-MC-Unique: 5xkjpLqaPAKjHQtBiemdPg-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, stefanb@linux.ibm.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org Subject: [PATCH v3 02/10] tpm: Use TPMState as a common struct Date: Wed, 26 Feb 2020 11:25:41 +0100 Message-Id: <20200226102549.12158-3-eric.auger@redhat.com> In-Reply-To: <20200226102549.12158-1-eric.auger@redhat.com> References: <20200226102549.12158-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, lersek@redhat.com, ardb@kernel.org, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" As we plan to introduce a SysBus TPM TIS device, let's make the TPMState a common struct usable by both the ISADevice and the SysBusDevice. TPMStateISA embeds the struct and inherits from the ISADevice. The prototype of functions bound to be used by both the ISA and SysBus devices is changed to take TPMState handle. A bunch of structs also are renamed to be specialized for the ISA device. Besides those transformations, no functional change is expected. Signed-off-by: Eric Auger Reviewed-by: Stefan Berger --- v2 -> v3: - Added Stefan's R-b --- hw/tpm/tpm_tis.c | 146 +++++++++++++++++++++++++++++------------------ 1 file changed, 91 insertions(+), 55 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index c609737272..fc6d7ca579 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -65,7 +65,6 @@ typedef struct TPMLocality { } TPMLocality; =20 typedef struct TPMState { - ISADevice busdev; MemoryRegion mmio; =20 unsigned char buffer[TPM_TIS_BUFFER_MAX]; @@ -91,7 +90,15 @@ typedef struct TPMState { TPMPPI ppi; } TPMState; =20 -#define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS_ISA) +typedef struct TPMStateISA { + /*< private >*/ + ISADevice parent_obj; + + /*< public >*/ + TPMState state; /* not a QOM object */ +} TPMStateISA; + +#define TPM_TIS_ISA(obj) OBJECT_CHECK(TPMStateISA, (obj), TYPE_TPM_TIS_ISA) =20 #define DEBUG_TIS 0 =20 @@ -281,9 +288,8 @@ static void tpm_tis_prep_abort(TPMState *s, uint8_t loc= ty, uint8_t newlocty) /* * Callback from the TPM to indicate that the response was received. */ -static void tpm_tis_request_completed(TPMIf *ti, int ret) +static void tpm_tis_request_completed(TPMState *s, int ret) { - TPMState *s =3D TPM(ti); uint8_t locty =3D s->cmd.locty; uint8_t l; =20 @@ -338,7 +344,7 @@ static uint32_t tpm_tis_data_read(TPMState *s, uint8_t = locty) } =20 #ifdef DEBUG_TIS -static void tpm_tis_dump_state(void *opaque, hwaddr addr) +static void tpm_tis_dump_state(TPMState *s, hwaddr addr) { static const unsigned regs[] =3D { TPM_TIS_REG_ACCESS, @@ -353,7 +359,6 @@ static void tpm_tis_dump_state(void *opaque, hwaddr add= r) int idx; uint8_t locty =3D tpm_tis_locality_from_addr(addr); hwaddr base =3D addr & ~0xfff; - TPMState *s =3D opaque; =20 printf("tpm_tis: active locality : %d\n" "tpm_tis: state of locality %d : %d\n" @@ -363,7 +368,7 @@ static void tpm_tis_dump_state(void *opaque, hwaddr add= r) =20 for (idx =3D 0; regs[idx] !=3D 0xfff; idx++) { printf("tpm_tis: 0x%04x : 0x%08x\n", regs[idx], - (int)tpm_tis_mmio_read(opaque, base + regs[idx], 4)); + (int)tpm_tis_mmio_read(s, base + regs[idx], 4)); } =20 printf("tpm_tis: r/w offset : %d\n" @@ -488,7 +493,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr = addr, break; #ifdef DEBUG_TIS case TPM_TIS_REG_DEBUG: - tpm_tis_dump_state(opaque, addr); + tpm_tis_dump_state(s, addr); break; #endif } @@ -835,10 +840,8 @@ static const MemoryRegionOps tpm_tis_memory_ops =3D { /* * Get the TPMVersion of the backend device being used */ -static enum TPMVersion tpm_tis_get_tpm_version(TPMIf *ti) +static enum TPMVersion tpm_tis_get_tpm_version(TPMState *s) { - TPMState *s =3D TPM(ti); - if (tpm_backend_had_startup_error(s->be_driver)) { return TPM_VERSION_UNSPEC; } @@ -850,9 +853,8 @@ static enum TPMVersion tpm_tis_get_tpm_version(TPMIf *t= i) * This function is called when the machine starts, resets or due to * S3 resume. */ -static void tpm_tis_reset(DeviceState *dev) +static void tpm_tis_reset(TPMState *s) { - TPMState *s =3D TPM(dev); int c; =20 s->be_tpm_version =3D tpm_backend_get_tpm_version(s->be_driver); @@ -896,15 +898,14 @@ static void tpm_tis_reset(DeviceState *dev) =20 /* persistent state handling */ =20 -static int tpm_tis_pre_save(void *opaque) +static int tpm_tis_pre_save(TPMState *s) { - TPMState *s =3D opaque; uint8_t locty =3D s->active_locty; =20 trace_tpm_tis_pre_save(locty, s->rw_offset); =20 if (DEBUG_TIS) { - tpm_tis_dump_state(opaque, 0); + tpm_tis_dump_state(s, 0); } =20 /* @@ -929,34 +930,78 @@ static const VMStateDescription vmstate_locty =3D { } }; =20 -static const VMStateDescription vmstate_tpm_tis =3D { +/* ISA */ + +static int tpm_tis_pre_save_isa(void *opaque) +{ + TPMStateISA *isadev =3D opaque; + + return tpm_tis_pre_save(&isadev->state); +} + +static const VMStateDescription vmstate_tpm_tis_isa =3D { .name =3D "tpm-tis", .version_id =3D 0, - .pre_save =3D tpm_tis_pre_save, + .pre_save =3D tpm_tis_pre_save_isa, .fields =3D (VMStateField[]) { - VMSTATE_BUFFER(buffer, TPMState), - VMSTATE_UINT16(rw_offset, TPMState), - VMSTATE_UINT8(active_locty, TPMState), - VMSTATE_UINT8(aborting_locty, TPMState), - VMSTATE_UINT8(next_locty, TPMState), + VMSTATE_BUFFER(state.buffer, TPMStateISA), + VMSTATE_UINT16(state.rw_offset, TPMStateISA), + VMSTATE_UINT8(state.active_locty, TPMStateISA), + VMSTATE_UINT8(state.aborting_locty, TPMStateISA), + VMSTATE_UINT8(state.next_locty, TPMStateISA), =20 - VMSTATE_STRUCT_ARRAY(loc, TPMState, TPM_TIS_NUM_LOCALITIES, 0, + VMSTATE_STRUCT_ARRAY(state.loc, TPMStateISA, TPM_TIS_NUM_LOCALITIE= S, 0, vmstate_locty, TPMLocality), =20 VMSTATE_END_OF_LIST() } }; =20 -static Property tpm_tis_properties[] =3D { - DEFINE_PROP_UINT32("irq", TPMState, irq_num, TPM_TIS_IRQ), - DEFINE_PROP_TPMBE("tpmdev", TPMState, be_driver), - DEFINE_PROP_BOOL("ppi", TPMState, ppi_enabled, true), +static void tpm_tis_isa_request_completed(TPMIf *ti, int ret) +{ + TPMStateISA *isadev =3D TPM_TIS_ISA(ti); + TPMState *s =3D &isadev->state; + + tpm_tis_request_completed(s, ret); +} + +static enum TPMVersion tpm_tis_isa_get_tpm_version(TPMIf *ti) +{ + TPMStateISA *isadev =3D TPM_TIS_ISA(ti); + TPMState *s =3D &isadev->state; + + return tpm_tis_get_tpm_version(s); +} + +static void tpm_tis_isa_reset(DeviceState *dev) +{ + TPMStateISA *isadev =3D TPM_TIS_ISA(dev); + TPMState *s =3D &isadev->state; + + return tpm_tis_reset(s); +} + +static Property tpm_tis_isa_properties[] =3D { + DEFINE_PROP_UINT32("irq", TPMStateISA, state.irq_num, TPM_TIS_IRQ), + DEFINE_PROP_TPMBE("tpmdev", TPMStateISA, state.be_driver), + DEFINE_PROP_BOOL("ppi", TPMStateISA, state.ppi_enabled, true), DEFINE_PROP_END_OF_LIST(), }; =20 -static void tpm_tis_realizefn(DeviceState *dev, Error **errp) +static void tpm_tis_isa_initfn(Object *obj) { - TPMState *s =3D TPM(dev); + TPMStateISA *isadev =3D TPM_TIS_ISA(obj); + TPMState *s =3D &isadev->state; + + memory_region_init_io(&s->mmio, obj, &tpm_tis_memory_ops, + s, "tpm-tis-mmio", + TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT= ); +} + +static void tpm_tis_isa_realizefn(DeviceState *dev, Error **errp) +{ + TPMStateISA *isadev =3D TPM_TIS_ISA(dev); + TPMState *s =3D &isadev->state; =20 if (!tpm_find()) { error_setg(errp, "at most one TPM device is permitted"); @@ -973,55 +1018,46 @@ static void tpm_tis_realizefn(DeviceState *dev, Erro= r **errp) return; } =20 - isa_init_irq(&s->busdev, &s->irq, s->irq_num); + isa_init_irq(ISA_DEVICE(dev), &s->irq, s->irq_num); =20 memory_region_add_subregion(isa_address_space(ISA_DEVICE(dev)), TPM_TIS_ADDR_BASE, &s->mmio); =20 if (s->ppi_enabled) { tpm_ppi_init(&s->ppi, isa_address_space(ISA_DEVICE(dev)), - TPM_PPI_ADDR_BASE, OBJECT(s)); + TPM_PPI_ADDR_BASE, OBJECT(dev)); } } =20 -static void tpm_tis_initfn(Object *obj) -{ - TPMState *s =3D TPM(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= ); -} - -static void tpm_tis_class_init(ObjectClass *klass, void *data) +static void tpm_tis_isa_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); TPMIfClass *tc =3D TPM_IF_CLASS(klass); =20 - dc->realize =3D tpm_tis_realizefn; - device_class_set_props(dc, tpm_tis_properties); - dc->reset =3D tpm_tis_reset; - dc->vmsd =3D &vmstate_tpm_tis; + device_class_set_props(dc, tpm_tis_isa_properties); + dc->vmsd =3D &vmstate_tpm_tis_isa; tc->model =3D TPM_MODEL_TPM_TIS; - tc->get_version =3D tpm_tis_get_tpm_version; - tc->request_completed =3D tpm_tis_request_completed; + dc->realize =3D tpm_tis_isa_realizefn; + dc->reset =3D tpm_tis_isa_reset; + tc->request_completed =3D tpm_tis_isa_request_completed; + tc->get_version =3D tpm_tis_isa_get_tpm_version; } =20 -static const TypeInfo tpm_tis_info =3D { +static const TypeInfo tpm_tis_isa_info =3D { .name =3D TYPE_TPM_TIS_ISA, .parent =3D TYPE_ISA_DEVICE, - .instance_size =3D sizeof(TPMState), - .instance_init =3D tpm_tis_initfn, - .class_init =3D tpm_tis_class_init, + .instance_size =3D sizeof(TPMStateISA), + .instance_init =3D tpm_tis_isa_initfn, + .class_init =3D tpm_tis_isa_class_init, .interfaces =3D (InterfaceInfo[]) { { TYPE_TPM_IF }, { } } }; =20 -static void tpm_tis_register(void) +static void tpm_tis_isa_register(void) { - type_register_static(&tpm_tis_info); + type_register_static(&tpm_tis_isa_info); } =20 -type_init(tpm_tis_register) +type_init(tpm_tis_isa_register) --=20 2.20.1 From nobody Thu Nov 13 20:44:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582712845; cv=none; d=zohomail.com; s=zohoarc; b=Y9X197xdD9UNHW83ZFbKSGxEw8UAlgrvh8tnfIxAAb2RWV6n5B5RoO9rNmEbZ/MI3StSkG4JNx8hORpHykwModnd/o+pva4qMYkJxmVec6oqpM+h/EyWeyOcBmOfXO1p2U7EKLmoKfeWyl4izAwfpBFcH4TXhdhMED5pEqrWQSM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582712845; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EWdP1NY+Cn0bWcyTn34IfuarV3mde9P1Lt77lcBKdCg=; b=Tafit18yj/ArSKgVjstg0UxQm5+twuQH2QxzjB9Ucx08DNoH7Gi2/oG9jBZwt7ySpSDhozMeNshPH7p4Jw9d8FqEXlpy2GBFXCsYufjl5zAbyjT94BXMPBo0n8SPkNF2kU89wmyTl0KLZte3rIoWCyPZ5smGI4GY3ulgLEQeIEo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15827128459591022.7963826065818; Wed, 26 Feb 2020 02:27:25 -0800 (PST) Received: from localhost ([::1]:42026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6tuW-0006PS-Ou for importer@patchew.org; Wed, 26 Feb 2020 05:27:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52079) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ttV-0004PL-Vn for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ttS-0003WF-39 for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:21 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:39285 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6ttR-0003Td-T9 for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:18 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-337-0Xpaac3kN2yGJ4YA-eak9Q-1; Wed, 26 Feb 2020 05:26:15 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 38E5D1882CCC; Wed, 26 Feb 2020 10:26:14 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id BBA9C60BE1; Wed, 26 Feb 2020 10:26:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582712777; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EWdP1NY+Cn0bWcyTn34IfuarV3mde9P1Lt77lcBKdCg=; b=Fv8bKq1up6vBAUn8vCjseKuJEE7RxeVz4W45Da1MHucAKDs5KBi1xw7zD3ZpWyR+LKbCcA i2XhEDkzoAaHXlrzOq7OqEz2jHMOXlYzrOAAh49QfYt/3G09Yi0/G6l5FaEGGGl5BdITMO qgcWrPiZLFZ2V6WWopzfuGHN3H9KK+g= X-MC-Unique: 0Xpaac3kN2yGJ4YA-eak9Q-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, stefanb@linux.ibm.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org Subject: [PATCH v3 03/10] tpm: Separate tpm_tis common functions from isa code Date: Wed, 26 Feb 2020 11:25:42 +0100 Message-Id: <20200226102549.12158-4-eric.auger@redhat.com> In-Reply-To: <20200226102549.12158-1-eric.auger@redhat.com> References: <20200226102549.12158-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, lersek@redhat.com, ardb@kernel.org, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Move the device agnostic code into tpm_tis_common.c and put the ISA device specific code into tpm_tis_isa.c Signed-off-by: Eric Auger Reviewed-by: Stefan Berger --- v2 -> v3: - Added Stefan's R-b --- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_tis.h | 91 +++++++++++ hw/tpm/{tpm_tis.c =3D> tpm_tis_common.c} | 209 ++----------------------- hw/tpm/tpm_tis_isa.c | 170 ++++++++++++++++++++ 4 files changed, 271 insertions(+), 201 deletions(-) create mode 100644 hw/tpm/tpm_tis.h rename hw/tpm/{tpm_tis.c =3D> tpm_tis_common.c} (83%) create mode 100644 hw/tpm/tpm_tis_isa.c diff --git a/hw/tpm/Makefile.objs b/hw/tpm/Makefile.objs index 85eb99ae05..fcc4c2f27c 100644 --- a/hw/tpm/Makefile.objs +++ b/hw/tpm/Makefile.objs @@ -1,6 +1,6 @@ common-obj-$(CONFIG_TPM) +=3D tpm_util.o obj-$(call lor,$(CONFIG_TPM_TIS),$(CONFIG_TPM_CRB)) +=3D tpm_ppi.o -common-obj-$(CONFIG_TPM_TIS) +=3D tpm_tis.o +common-obj-$(CONFIG_TPM_TIS) +=3D tpm_tis_isa.o tpm_tis_common.o common-obj-$(CONFIG_TPM_CRB) +=3D tpm_crb.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_tis.h b/hw/tpm/tpm_tis.h new file mode 100644 index 0000000000..5554989395 --- /dev/null +++ b/hw/tpm/tpm_tis.h @@ -0,0 +1,91 @@ +/* + * tpm_tis.h - QEMU's TPM TIS common header + * + * Copyright (C) 2006,2010-2013 IBM Corporation + * + * Authors: + * Stefan Berger + * David Safford + * + * Xen 4 support: Andrease Niederl + * + * 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. + * + * Implementation of the TIS interface according to specs found at + * http://www.trustedcomputinggroup.org. This implementation currently + * supports version 1.3, 21 March 2013 + * In the developers menu choose the PC Client section then find the TIS + * specification. + * + * TPM TIS for TPM 2 implementation following TCG PC Client Platform + * TPM Profile (PTP) Specification, Familiy 2.0, Revision 00.43 + */ +#ifndef TPM_TPM_TIS_H +#define TPM_TPM_TIS_H + +#include "qemu/osdep.h" +#include "sysemu/tpm_backend.h" +#include "tpm_ppi.h" + +#define TPM_TIS_NUM_LOCALITIES 5 /* per spec */ +#define TPM_TIS_LOCALITY_SHIFT 12 +#define TPM_TIS_NO_LOCALITY 0xff + +#define TPM_TIS_IS_VALID_LOCTY(x) ((x) < TPM_TIS_NUM_LOCALITIES) + +#define TPM_TIS_BUFFER_MAX 4096 + +typedef enum { + TPM_TIS_STATE_IDLE =3D 0, + TPM_TIS_STATE_READY, + TPM_TIS_STATE_COMPLETION, + TPM_TIS_STATE_EXECUTION, + TPM_TIS_STATE_RECEPTION, +} TPMTISState; + +/* locality data -- all fields are persisted */ +typedef struct TPMLocality { + TPMTISState state; + uint8_t access; + uint32_t sts; + uint32_t iface_id; + uint32_t inte; + uint32_t ints; +} TPMLocality; + +typedef struct TPMState { + MemoryRegion mmio; + + unsigned char buffer[TPM_TIS_BUFFER_MAX]; + uint16_t rw_offset; + + uint8_t active_locty; + uint8_t aborting_locty; + uint8_t next_locty; + + TPMLocality loc[TPM_TIS_NUM_LOCALITIES]; + + qemu_irq irq; + uint32_t irq_num; + + TPMBackendCmd cmd; + + TPMBackend *be_driver; + TPMVersion be_tpm_version; + + size_t be_buffer_size; + + bool ppi_enabled; + TPMPPI ppi; +} TPMState; + +extern const VMStateDescription vmstate_locty; +extern const MemoryRegionOps tpm_tis_memory_ops; + +int tpm_tis_pre_save(TPMState *s); +void tpm_tis_reset(TPMState *s); +enum TPMVersion tpm_tis_get_tpm_version(TPMState *s); +void tpm_tis_request_completed(TPMState *s, int ret); + +#endif /* TPM_TPM_TIS_H */ diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis_common.c similarity index 83% rename from hw/tpm/tpm_tis.c rename to hw/tpm/tpm_tis_common.c index fc6d7ca579..9ce64d4836 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis_common.c @@ -1,5 +1,6 @@ /* - * tpm_tis.c - QEMU's TPM TIS interface emulator + * tpm_tis_common.c - QEMU's TPM TIS interface emulator + * device agnostic functions * * Copyright (C) 2006,2010-2013 IBM Corporation * @@ -21,7 +22,6 @@ * TPM TIS for TPM 2 implementation following TCG PC Client Platform * TPM Profile (PTP) Specification, Familiy 2.0, Revision 00.43 */ - #include "qemu/osdep.h" #include "hw/irq.h" #include "hw/isa/isa.h" @@ -38,67 +38,7 @@ #include "tpm_ppi.h" #include "trace.h" =20 -#define TPM_TIS_NUM_LOCALITIES 5 /* per spec */ -#define TPM_TIS_LOCALITY_SHIFT 12 -#define TPM_TIS_NO_LOCALITY 0xff - -#define TPM_TIS_IS_VALID_LOCTY(x) ((x) < TPM_TIS_NUM_LOCALITIES) - -#define TPM_TIS_BUFFER_MAX 4096 - -typedef enum { - TPM_TIS_STATE_IDLE =3D 0, - TPM_TIS_STATE_READY, - TPM_TIS_STATE_COMPLETION, - TPM_TIS_STATE_EXECUTION, - TPM_TIS_STATE_RECEPTION, -} TPMTISState; - -/* locality data -- all fields are persisted */ -typedef struct TPMLocality { - TPMTISState state; - uint8_t access; - uint32_t sts; - uint32_t iface_id; - uint32_t inte; - uint32_t ints; -} TPMLocality; - -typedef struct TPMState { - MemoryRegion mmio; - - unsigned char buffer[TPM_TIS_BUFFER_MAX]; - uint16_t rw_offset; - - uint8_t active_locty; - uint8_t aborting_locty; - uint8_t next_locty; - - TPMLocality loc[TPM_TIS_NUM_LOCALITIES]; - - qemu_irq irq; - uint32_t irq_num; - - TPMBackendCmd cmd; - - TPMBackend *be_driver; - TPMVersion be_tpm_version; - - size_t be_buffer_size; - - bool ppi_enabled; - TPMPPI ppi; -} TPMState; - -typedef struct TPMStateISA { - /*< private >*/ - ISADevice parent_obj; - - /*< public >*/ - TPMState state; /* not a QOM object */ -} TPMStateISA; - -#define TPM_TIS_ISA(obj) OBJECT_CHECK(TPMStateISA, (obj), TYPE_TPM_TIS_ISA) +#include "tpm_tis.h" =20 #define DEBUG_TIS 0 =20 @@ -288,7 +228,7 @@ static void tpm_tis_prep_abort(TPMState *s, uint8_t loc= ty, uint8_t newlocty) /* * Callback from the TPM to indicate that the response was received. */ -static void tpm_tis_request_completed(TPMState *s, int ret) +void tpm_tis_request_completed(TPMState *s, int ret) { uint8_t locty =3D s->cmd.locty; uint8_t l; @@ -827,7 +767,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, } } =20 -static const MemoryRegionOps tpm_tis_memory_ops =3D { +const MemoryRegionOps tpm_tis_memory_ops =3D { .read =3D tpm_tis_mmio_read, .write =3D tpm_tis_mmio_write, .endianness =3D DEVICE_LITTLE_ENDIAN, @@ -840,7 +780,7 @@ static const MemoryRegionOps tpm_tis_memory_ops =3D { /* * Get the TPMVersion of the backend device being used */ -static enum TPMVersion tpm_tis_get_tpm_version(TPMState *s) +enum TPMVersion tpm_tis_get_tpm_version(TPMState *s) { if (tpm_backend_had_startup_error(s->be_driver)) { return TPM_VERSION_UNSPEC; @@ -853,7 +793,7 @@ static enum TPMVersion tpm_tis_get_tpm_version(TPMState= *s) * This function is called when the machine starts, resets or due to * S3 resume. */ -static void tpm_tis_reset(TPMState *s) +void tpm_tis_reset(TPMState *s) { int c; =20 @@ -898,7 +838,7 @@ static void tpm_tis_reset(TPMState *s) =20 /* persistent state handling */ =20 -static int tpm_tis_pre_save(TPMState *s) +int tpm_tis_pre_save(TPMState *s) { uint8_t locty =3D s->active_locty; =20 @@ -916,7 +856,7 @@ static int tpm_tis_pre_save(TPMState *s) return 0; } =20 -static const VMStateDescription vmstate_locty =3D { +const VMStateDescription vmstate_locty =3D { .name =3D "tpm-tis/locty", .version_id =3D 0, .fields =3D (VMStateField[]) { @@ -930,134 +870,3 @@ static const VMStateDescription vmstate_locty =3D { } }; =20 -/* ISA */ - -static int tpm_tis_pre_save_isa(void *opaque) -{ - TPMStateISA *isadev =3D opaque; - - return tpm_tis_pre_save(&isadev->state); -} - -static const VMStateDescription vmstate_tpm_tis_isa =3D { - .name =3D "tpm-tis", - .version_id =3D 0, - .pre_save =3D tpm_tis_pre_save_isa, - .fields =3D (VMStateField[]) { - VMSTATE_BUFFER(state.buffer, TPMStateISA), - VMSTATE_UINT16(state.rw_offset, TPMStateISA), - VMSTATE_UINT8(state.active_locty, TPMStateISA), - VMSTATE_UINT8(state.aborting_locty, TPMStateISA), - VMSTATE_UINT8(state.next_locty, TPMStateISA), - - VMSTATE_STRUCT_ARRAY(state.loc, TPMStateISA, TPM_TIS_NUM_LOCALITIE= S, 0, - vmstate_locty, TPMLocality), - - VMSTATE_END_OF_LIST() - } -}; - -static void tpm_tis_isa_request_completed(TPMIf *ti, int ret) -{ - TPMStateISA *isadev =3D TPM_TIS_ISA(ti); - TPMState *s =3D &isadev->state; - - tpm_tis_request_completed(s, ret); -} - -static enum TPMVersion tpm_tis_isa_get_tpm_version(TPMIf *ti) -{ - TPMStateISA *isadev =3D TPM_TIS_ISA(ti); - TPMState *s =3D &isadev->state; - - return tpm_tis_get_tpm_version(s); -} - -static void tpm_tis_isa_reset(DeviceState *dev) -{ - TPMStateISA *isadev =3D TPM_TIS_ISA(dev); - TPMState *s =3D &isadev->state; - - return tpm_tis_reset(s); -} - -static Property tpm_tis_isa_properties[] =3D { - DEFINE_PROP_UINT32("irq", TPMStateISA, state.irq_num, TPM_TIS_IRQ), - DEFINE_PROP_TPMBE("tpmdev", TPMStateISA, state.be_driver), - DEFINE_PROP_BOOL("ppi", TPMStateISA, state.ppi_enabled, true), - DEFINE_PROP_END_OF_LIST(), -}; - -static void tpm_tis_isa_initfn(Object *obj) -{ - TPMStateISA *isadev =3D TPM_TIS_ISA(obj); - TPMState *s =3D &isadev->state; - - memory_region_init_io(&s->mmio, obj, &tpm_tis_memory_ops, - s, "tpm-tis-mmio", - TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT= ); -} - -static void tpm_tis_isa_realizefn(DeviceState *dev, Error **errp) -{ - TPMStateISA *isadev =3D TPM_TIS_ISA(dev); - TPMState *s =3D &isadev->state; - - if (!tpm_find()) { - error_setg(errp, "at most one TPM device is permitted"); - return; - } - - if (!s->be_driver) { - error_setg(errp, "'tpmdev' property is required"); - return; - } - if (s->irq_num > 15) { - error_setg(errp, "IRQ %d is outside valid range of 0 to 15", - s->irq_num); - return; - } - - isa_init_irq(ISA_DEVICE(dev), &s->irq, s->irq_num); - - memory_region_add_subregion(isa_address_space(ISA_DEVICE(dev)), - TPM_TIS_ADDR_BASE, &s->mmio); - - if (s->ppi_enabled) { - tpm_ppi_init(&s->ppi, isa_address_space(ISA_DEVICE(dev)), - TPM_PPI_ADDR_BASE, OBJECT(dev)); - } -} - -static void tpm_tis_isa_class_init(ObjectClass *klass, void *data) -{ - DeviceClass *dc =3D DEVICE_CLASS(klass); - TPMIfClass *tc =3D TPM_IF_CLASS(klass); - - device_class_set_props(dc, tpm_tis_isa_properties); - dc->vmsd =3D &vmstate_tpm_tis_isa; - tc->model =3D TPM_MODEL_TPM_TIS; - dc->realize =3D tpm_tis_isa_realizefn; - dc->reset =3D tpm_tis_isa_reset; - tc->request_completed =3D tpm_tis_isa_request_completed; - tc->get_version =3D tpm_tis_isa_get_tpm_version; -} - -static const TypeInfo tpm_tis_isa_info =3D { - .name =3D TYPE_TPM_TIS_ISA, - .parent =3D TYPE_ISA_DEVICE, - .instance_size =3D sizeof(TPMStateISA), - .instance_init =3D tpm_tis_isa_initfn, - .class_init =3D tpm_tis_isa_class_init, - .interfaces =3D (InterfaceInfo[]) { - { TYPE_TPM_IF }, - { } - } -}; - -static void tpm_tis_isa_register(void) -{ - type_register_static(&tpm_tis_isa_info); -} - -type_init(tpm_tis_isa_register) diff --git a/hw/tpm/tpm_tis_isa.c b/hw/tpm/tpm_tis_isa.c new file mode 100644 index 0000000000..30ba37079d --- /dev/null +++ b/hw/tpm/tpm_tis_isa.c @@ -0,0 +1,170 @@ +/* + * tpm_tis_isa.c - QEMU's TPM TIS ISA Device + * + * Copyright (C) 2006,2010-2013 IBM Corporation + * + * Authors: + * Stefan Berger + * David Safford + * + * Xen 4 support: Andrease Niederl + * + * 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. + * + * Implementation of the TIS interface according to specs found at + * http://www.trustedcomputinggroup.org. This implementation currently + * supports version 1.3, 21 March 2013 + * In the developers menu choose the PC Client section then find the TIS + * specification. + * + * TPM TIS for TPM 2 implementation following TCG PC Client Platform + * TPM Profile (PTP) Specification, Familiy 2.0, Revision 00.43 + */ + +#include "qemu/osdep.h" +#include "hw/isa/isa.h" +#include "hw/qdev-properties.h" +#include "migration/vmstate.h" +#include "tpm_util.h" +#include "tpm_tis.h" + +typedef struct TPMStateISA { + /*< private >*/ + ISADevice parent_obj; + + /*< public >*/ + TPMState state; /* not a QOM object */ +} TPMStateISA; + +#define TPM_TIS_ISA(obj) OBJECT_CHECK(TPMStateISA, (obj), TYPE_TPM_TIS_ISA) + +static int tpm_tis_pre_save_isa(void *opaque) +{ + TPMStateISA *isadev =3D opaque; + + return tpm_tis_pre_save(&isadev->state); +} + +static const VMStateDescription vmstate_tpm_tis_isa =3D { + .name =3D "tpm-tis", + .version_id =3D 0, + .pre_save =3D tpm_tis_pre_save_isa, + .fields =3D (VMStateField[]) { + VMSTATE_BUFFER(state.buffer, TPMStateISA), + VMSTATE_UINT16(state.rw_offset, TPMStateISA), + VMSTATE_UINT8(state.active_locty, TPMStateISA), + VMSTATE_UINT8(state.aborting_locty, TPMStateISA), + VMSTATE_UINT8(state.next_locty, TPMStateISA), + + VMSTATE_STRUCT_ARRAY(state.loc, TPMStateISA, TPM_TIS_NUM_LOCALITIE= S, 0, + vmstate_locty, TPMLocality), + + VMSTATE_END_OF_LIST() + } +}; + +static void tpm_tis_isa_request_completed(TPMIf *ti, int ret) +{ + TPMStateISA *isadev =3D TPM_TIS_ISA(ti); + TPMState *s =3D &isadev->state; + + tpm_tis_request_completed(s, ret); +} + +static enum TPMVersion tpm_tis_isa_get_tpm_version(TPMIf *ti) +{ + TPMStateISA *isadev =3D TPM_TIS_ISA(ti); + TPMState *s =3D &isadev->state; + + return tpm_tis_get_tpm_version(s); +} + +static void tpm_tis_isa_reset(DeviceState *dev) +{ + TPMStateISA *isadev =3D TPM_TIS_ISA(dev); + TPMState *s =3D &isadev->state; + + return tpm_tis_reset(s); +} + +static Property tpm_tis_isa_properties[] =3D { + DEFINE_PROP_UINT32("irq", TPMStateISA, state.irq_num, TPM_TIS_IRQ), + DEFINE_PROP_TPMBE("tpmdev", TPMStateISA, state.be_driver), + DEFINE_PROP_BOOL("ppi", TPMStateISA, state.ppi_enabled, true), + DEFINE_PROP_END_OF_LIST(), +}; + +static void tpm_tis_isa_initfn(Object *obj) +{ + TPMStateISA *isadev =3D TPM_TIS_ISA(obj); + TPMState *s =3D &isadev->state; + + memory_region_init_io(&s->mmio, obj, &tpm_tis_memory_ops, + s, "tpm-tis-mmio", + TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT= ); +} + +static void tpm_tis_isa_realizefn(DeviceState *dev, Error **errp) +{ + TPMStateISA *isadev =3D TPM_TIS_ISA(dev); + TPMState *s =3D &isadev->state; + + if (!tpm_find()) { + error_setg(errp, "at most one TPM device is permitted"); + return; + } + + if (!s->be_driver) { + error_setg(errp, "'tpmdev' property is required"); + return; + } + if (s->irq_num > 15) { + error_setg(errp, "IRQ %d is outside valid range of 0 to 15", + s->irq_num); + return; + } + + isa_init_irq(ISA_DEVICE(dev), &s->irq, s->irq_num); + + memory_region_add_subregion(isa_address_space(ISA_DEVICE(dev)), + TPM_TIS_ADDR_BASE, &s->mmio); + + if (s->ppi_enabled) { + tpm_ppi_init(&s->ppi, isa_address_space(ISA_DEVICE(dev)), + TPM_PPI_ADDR_BASE, OBJECT(dev)); + } +} + +static void tpm_tis_isa_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + TPMIfClass *tc =3D TPM_IF_CLASS(klass); + + device_class_set_props(dc, tpm_tis_isa_properties); + dc->vmsd =3D &vmstate_tpm_tis_isa; + tc->model =3D TPM_MODEL_TPM_TIS; + dc->realize =3D tpm_tis_isa_realizefn; + dc->reset =3D tpm_tis_isa_reset; + tc->request_completed =3D tpm_tis_isa_request_completed; + tc->get_version =3D tpm_tis_isa_get_tpm_version; +} + +static const TypeInfo tpm_tis_isa_info =3D { + .name =3D TYPE_TPM_TIS_ISA, + .parent =3D TYPE_ISA_DEVICE, + .instance_size =3D sizeof(TPMStateISA), + .instance_init =3D tpm_tis_isa_initfn, + .class_init =3D tpm_tis_isa_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_TPM_IF }, + { } + } +}; + +static void tpm_tis_isa_register(void) +{ + type_register_static(&tpm_tis_isa_info); +} + +type_init(tpm_tis_isa_register) --=20 2.20.1 From nobody Thu Nov 13 20:44:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582713029; cv=none; d=zohomail.com; s=zohoarc; b=hdtXLzB03kxcNa7ThvWZF8dITo1cm00v6jneoL6w2lqTyFbHyhSlTE5lo1JvD7ial2k3dzPq0U3jQHq22cXzFWwBfBgTdWFrb9D9qM2xXoTJGKWEVIrCaqCcyAVBagM8zglhsY+mdlo9392gJvi7ivZxt24tGz8hhbWbpGBjSHM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582713029; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ajDOVbPHWi72NoV7MIp4a4+jzaXjbTWs3x00zhiGkGc=; b=RUKot5X9zV4LnvuWAlRVHrt0i5ViABQvF+MyrwrmA9KKLRwNXp4GFlK4Z0p1daw7okChzDCbOA9pHS80QjWlTOUS2zcNu0DHyTYPHiZmGThNl0Ds+kZV0/JleLEuxiswaGENP+TaJOIBsxRrOgfkjXwjnGMQGlt0iSvYVSBqc5c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582713029630954.5640487569245; Wed, 26 Feb 2020 02:30:29 -0800 (PST) Received: from localhost ([::1]:42094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6txU-0003ed-Jo for importer@patchew.org; Wed, 26 Feb 2020 05:30:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52073) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ttV-0004OJ-Gk for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ttU-0003bL-9B for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:21 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:25462 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6ttU-0003a1-4Z for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:20 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-417-VDdbP1KpMF-sdBvUG87giw-1; Wed, 26 Feb 2020 05:26:18 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 031691882CCC; Wed, 26 Feb 2020 10:26:17 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9447260BE1; Wed, 26 Feb 2020 10:26:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582712779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ajDOVbPHWi72NoV7MIp4a4+jzaXjbTWs3x00zhiGkGc=; b=NC6SlPW7iL20j5KLcmjuR3g38n3smVvpbdCP/jn2KzAXRBoATreMBEXMhzim8qQf9mU0qc IJtE8hKR0f4FTAtHTp0TH8mXGNyc7kxNGYv9c81eZ3uIqC68bmfyPjR1rA6sKBWWEU/jPE aBiP53RT09wzEJsM/tZFqW1fi7K5iYQ= X-MC-Unique: VDdbP1KpMF-sdBvUG87giw-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, stefanb@linux.ibm.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org Subject: [PATCH v3 04/10] tpm: Separate TPM_TIS and TPM_TIS_ISA configs Date: Wed, 26 Feb 2020 11:25:43 +0100 Message-Id: <20200226102549.12158-5-eric.auger@redhat.com> In-Reply-To: <20200226102549.12158-1-eric.auger@redhat.com> References: <20200226102549.12158-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, lersek@redhat.com, ardb@kernel.org, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Let's separate the compilation of tpm_tis_common.c from the compilation of tpm_tis_isa.c The common part will be also compiled along with the tpm_tis_sysbus device. Signed-off-by: Eric Auger Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- v2 -> v3: - added Phillipe's R-b --- default-configs/i386-softmmu.mak | 2 +- hw/i386/Kconfig | 2 +- hw/tpm/Kconfig | 7 ++++++- hw/tpm/Makefile.objs | 3 ++- tests/qtest/Makefile.include | 4 ++-- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmm= u.mak index 4cc64dafa2..84d1a2487c 100644 --- a/default-configs/i386-softmmu.mak +++ b/default-configs/i386-softmmu.mak @@ -20,7 +20,7 @@ #CONFIG_SGA=3Dn #CONFIG_TEST_DEVICES=3Dn #CONFIG_TPM_CRB=3Dn -#CONFIG_TPM_TIS=3Dn +#CONFIG_TPM_TIS_ISA=3Dn #CONFIG_VTD=3Dn =20 # Boards: diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig index cdc851598c..c93f32f657 100644 --- a/hw/i386/Kconfig +++ b/hw/i386/Kconfig @@ -20,7 +20,7 @@ config PC imply SGA imply TEST_DEVICES imply TPM_CRB - imply TPM_TIS + imply TPM_TIS_ISA imply VGA_PCI imply VIRTIO_VGA select FDC diff --git a/hw/tpm/Kconfig b/hw/tpm/Kconfig index 9e67d990e8..686f8206bb 100644 --- a/hw/tpm/Kconfig +++ b/hw/tpm/Kconfig @@ -2,9 +2,14 @@ config TPMDEV bool depends on TPM =20 -config TPM_TIS +config TPM_TIS_ISA bool depends on TPM && ISA_BUS + select TPM_TIS + +config TPM_TIS + bool + depends on TPM select TPMDEV =20 config TPM_CRB diff --git a/hw/tpm/Makefile.objs b/hw/tpm/Makefile.objs index fcc4c2f27c..3ef2036cca 100644 --- a/hw/tpm/Makefile.objs +++ b/hw/tpm/Makefile.objs @@ -1,6 +1,7 @@ common-obj-$(CONFIG_TPM) +=3D tpm_util.o obj-$(call lor,$(CONFIG_TPM_TIS),$(CONFIG_TPM_CRB)) +=3D tpm_ppi.o -common-obj-$(CONFIG_TPM_TIS) +=3D tpm_tis_isa.o tpm_tis_common.o +common-obj-$(CONFIG_TPM_TIS_ISA) +=3D tpm_tis_isa.o +common-obj-$(CONFIG_TPM_TIS) +=3D tpm_tis_common.o common-obj-$(CONFIG_TPM_CRB) +=3D tpm_crb.o common-obj-$(CONFIG_TPM_PASSTHROUGH) +=3D tpm_passthrough.o common-obj-$(CONFIG_TPM_EMULATOR) +=3D tpm_emulator.o diff --git a/tests/qtest/Makefile.include b/tests/qtest/Makefile.include index e769c1ad70..028af5b782 100644 --- a/tests/qtest/Makefile.include +++ b/tests/qtest/Makefile.include @@ -54,8 +54,8 @@ check-qtest-i386-y +=3D q35-test check-qtest-i386-y +=3D vmgenid-test check-qtest-i386-$(CONFIG_TPM_CRB) +=3D tpm-crb-swtpm-test check-qtest-i386-$(CONFIG_TPM_CRB) +=3D tpm-crb-test -check-qtest-i386-$(CONFIG_TPM_TIS) +=3D tpm-tis-swtpm-test -check-qtest-i386-$(CONFIG_TPM_TIS) +=3D tpm-tis-test +check-qtest-i386-$(CONFIG_TPM_TIS_ISA) +=3D tpm-tis-swtpm-test +check-qtest-i386-$(CONFIG_TPM_TIS_ISA) +=3D tpm-tis-test check-qtest-i386-$(CONFIG_SLIRP) +=3D test-netfilter check-qtest-i386-$(CONFIG_POSIX) +=3D test-filter-mirror check-qtest-i386-$(CONFIG_RTL8139_PCI) +=3D test-filter-redirector --=20 2.20.1 From nobody Thu Nov 13 20:44:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582712863; cv=none; d=zohomail.com; s=zohoarc; b=X/wpZC7vH1YVeLT3awkfrD2kscL++4zIeALfvrurRFi/rxVU5NMBJLXHZQXa8sPXuf2aXdfrW4d858YC3C0XTNcZV0YdDfV5a9j0UyISYWQS5yhqFVVbT+GE2hcsOLahEO1LRAouh/UONLhvXhFLY+q7N49ao6pOeXE8diwki1g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582712863; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2s05qc0nTF97lGAI+jMpFSbJdz8B2Xkk6Xnwf0WV97g=; b=LK8CwOFusko/CKIr8brepGWNoenhbUUZH5izn+PCgCQtoOYjzw02c7XKIHhcY90GaQrYdX0cADq1rZokWvhXSiadGxfEwhYzWKuVxjhAadKb1cpV+bOfiYhr63HFKH3c/u2RJVTYeZTqMjplZq4uiIjPBST5emTGFPeSdwOzq9I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582712863533560.2550004500152; Wed, 26 Feb 2020 02:27:43 -0800 (PST) Received: from localhost ([::1]:42028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6tuo-000783-7O for importer@patchew.org; Wed, 26 Feb 2020 05:27:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52176) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ttf-0004ne-Ku for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ttb-0003vA-PA for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:31 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:56504 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6ttb-0003t5-Ja for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:27 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-404-yEXFB85NOh6ez9In7fJ20A-1; Wed, 26 Feb 2020 05:26:25 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9FCC01005512; Wed, 26 Feb 2020 10:26:24 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F35260BE1; Wed, 26 Feb 2020 10:26:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582712787; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2s05qc0nTF97lGAI+jMpFSbJdz8B2Xkk6Xnwf0WV97g=; b=BksekiFOdp3XZTtZuVkBdlZl59Du1RyQieiP0wcHosA9wkFMHMSSSEIdGIVFsKGawovhYG Bhcpfu2v7ktpo2mmvggCoAgCZFciM9UQ8M8fgcONmO9njXfB7FCgvPo9vv6oWgRXKCmm6v sqwhAngo6FRVA6zl78Ha9pKFlNQdj+Y= X-MC-Unique: yEXFB85NOh6ez9In7fJ20A-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, stefanb@linux.ibm.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org Subject: [PATCH v3 05/10] tpm: Add the SysBus TPM TIS device Date: Wed, 26 Feb 2020 11:25:44 +0100 Message-Id: <20200226102549.12158-6-eric.auger@redhat.com> In-Reply-To: <20200226102549.12158-1-eric.auger@redhat.com> References: <20200226102549.12158-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, lersek@redhat.com, ardb@kernel.org, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Introduce the tpm-tis-device which is a sysbus device and is bound to be used on ARM. Signed-off-by: Eric Auger Reviewed-by: Stefan Berger --- v2 -> v3: - Added Stefan's R-b --- hw/tpm/Kconfig | 5 ++ hw/tpm/Makefile.objs | 1 + hw/tpm/tpm_tis_sysbus.c | 159 ++++++++++++++++++++++++++++++++++++++++ include/sysemu/tpm.h | 1 + 4 files changed, 166 insertions(+) create mode 100644 hw/tpm/tpm_tis_sysbus.c diff --git a/hw/tpm/Kconfig b/hw/tpm/Kconfig index 686f8206bb..4794e7fe28 100644 --- a/hw/tpm/Kconfig +++ b/hw/tpm/Kconfig @@ -7,6 +7,11 @@ config TPM_TIS_ISA depends on TPM && ISA_BUS select TPM_TIS =20 +config TPM_TIS_SYSBUS + bool + depends on TPM + select TPM_TIS + config TPM_TIS bool depends on TPM diff --git a/hw/tpm/Makefile.objs b/hw/tpm/Makefile.objs index 3ef2036cca..f1ec4beb95 100644 --- a/hw/tpm/Makefile.objs +++ b/hw/tpm/Makefile.objs @@ -1,6 +1,7 @@ common-obj-$(CONFIG_TPM) +=3D tpm_util.o obj-$(call lor,$(CONFIG_TPM_TIS),$(CONFIG_TPM_CRB)) +=3D tpm_ppi.o common-obj-$(CONFIG_TPM_TIS_ISA) +=3D tpm_tis_isa.o +common-obj-$(CONFIG_TPM_TIS_SYSBUS) +=3D tpm_tis_sysbus.o common-obj-$(CONFIG_TPM_TIS) +=3D tpm_tis_common.o common-obj-$(CONFIG_TPM_CRB) +=3D tpm_crb.o common-obj-$(CONFIG_TPM_PASSTHROUGH) +=3D tpm_passthrough.o diff --git a/hw/tpm/tpm_tis_sysbus.c b/hw/tpm/tpm_tis_sysbus.c new file mode 100644 index 0000000000..18c02aed67 --- /dev/null +++ b/hw/tpm/tpm_tis_sysbus.c @@ -0,0 +1,159 @@ +/* + * tpm_tis_sysbus.c - QEMU's TPM TIS SYSBUS Device + * + * Copyright (C) 2006,2010-2013 IBM Corporation + * + * Authors: + * Stefan Berger + * David Safford + * + * Xen 4 support: Andrease Niederl + * + * 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. + * + * Implementation of the TIS interface according to specs found at + * http://www.trustedcomputinggroup.org. This implementation currently + * supports version 1.3, 21 March 2013 + * In the developers menu choose the PC Client section then find the TIS + * specification. + * + * TPM TIS for TPM 2 implementation following TCG PC Client Platform + * TPM Profile (PTP) Specification, Familiy 2.0, Revision 00.43 + */ + +#include "qemu/osdep.h" +#include "hw/qdev-properties.h" +#include "migration/vmstate.h" +#include "tpm_util.h" +#include "hw/sysbus.h" +#include "tpm_tis.h" + +typedef struct TPMStateSysBus { + /*< private >*/ + SysBusDevice parent_obj; + + /*< public >*/ + TPMState state; /* not a QOM object */ +} TPMStateSysBus; + +#define TPM_TIS_SYSBUS(obj) OBJECT_CHECK(TPMStateSysBus, (obj), TYPE_TPM_T= IS_SYSBUS) + +static int tpm_tis_pre_save_sysbus(void *opaque) +{ + TPMStateSysBus *sbdev =3D opaque; + + return tpm_tis_pre_save(&sbdev->state); +} + +static const VMStateDescription vmstate_tpm_tis_sysbus =3D { + .name =3D "tpm-tis", + .version_id =3D 0, + .pre_save =3D tpm_tis_pre_save_sysbus, + .fields =3D (VMStateField[]) { + VMSTATE_BUFFER(state.buffer, TPMStateSysBus), + VMSTATE_UINT16(state.rw_offset, TPMStateSysBus), + VMSTATE_UINT8(state.active_locty, TPMStateSysBus), + VMSTATE_UINT8(state.aborting_locty, TPMStateSysBus), + VMSTATE_UINT8(state.next_locty, TPMStateSysBus), + + VMSTATE_STRUCT_ARRAY(state.loc, TPMStateSysBus, TPM_TIS_NUM_LOCALI= TIES, + 0, vmstate_locty, TPMLocality), + + VMSTATE_END_OF_LIST() + } +}; + +static void tpm_tis_sysbus_request_completed(TPMIf *ti, int ret) +{ + TPMStateSysBus *sbdev =3D TPM_TIS_SYSBUS(ti); + TPMState *s =3D &sbdev->state; + + tpm_tis_request_completed(s, ret); +} + +static enum TPMVersion tpm_tis_sysbus_get_tpm_version(TPMIf *ti) +{ + TPMStateSysBus *sbdev =3D TPM_TIS_SYSBUS(ti); + TPMState *s =3D &sbdev->state; + + return tpm_tis_get_tpm_version(s); +} + +static void tpm_tis_sysbus_reset(DeviceState *dev) +{ + TPMStateSysBus *sbdev =3D TPM_TIS_SYSBUS(dev); + TPMState *s =3D &sbdev->state; + + return tpm_tis_reset(s); +} + +static Property tpm_tis_sysbus_properties[] =3D { + DEFINE_PROP_UINT32("irq", TPMStateSysBus, state.irq_num, TPM_TIS_IRQ), + DEFINE_PROP_TPMBE("tpmdev", TPMStateSysBus, state.be_driver), + DEFINE_PROP_BOOL("ppi", TPMStateSysBus, state.ppi_enabled, true), + DEFINE_PROP_END_OF_LIST(), +}; + +static void tpm_tis_sysbus_initfn(Object *obj) +{ + TPMStateSysBus *sbdev =3D TPM_TIS_SYSBUS(obj); + TPMState *s =3D &sbdev->state; + + memory_region_init_io(&s->mmio, obj, &tpm_tis_memory_ops, + s, "tpm-tis-mmio", + TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT= ); + + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); + sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq); +} + +static void tpm_tis_sysbus_realizefn(DeviceState *dev, Error **errp) +{ + TPMStateSysBus *sbdev =3D TPM_TIS_SYSBUS(dev); + TPMState *s =3D &sbdev->state; + + if (!tpm_find()) { + error_setg(errp, "at most one TPM device is permitted"); + return; + } + + if (!s->be_driver) { + error_setg(errp, "'tpmdev' property is required"); + return; + } +} + +static void tpm_tis_sysbus_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + TPMIfClass *tc =3D TPM_IF_CLASS(klass); + + device_class_set_props(dc, tpm_tis_sysbus_properties); + dc->vmsd =3D &vmstate_tpm_tis_sysbus; + tc->model =3D TPM_MODEL_TPM_TIS; + dc->realize =3D tpm_tis_sysbus_realizefn; + dc->user_creatable =3D true; + dc->reset =3D tpm_tis_sysbus_reset; + tc->request_completed =3D tpm_tis_sysbus_request_completed; + tc->get_version =3D tpm_tis_sysbus_get_tpm_version; +} + +static const TypeInfo tpm_tis_sysbus_info =3D { + .name =3D TYPE_TPM_TIS_SYSBUS, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(TPMStateSysBus), + .instance_init =3D tpm_tis_sysbus_initfn, + .class_init =3D tpm_tis_sysbus_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_TPM_IF }, + { } + } +}; + +static void tpm_tis_sysbus_register(void) +{ + type_register_static(&tpm_tis_sysbus_info); +} + +type_init(tpm_tis_sysbus_register) diff --git a/include/sysemu/tpm.h b/include/sysemu/tpm.h index 1691b92c28..f37851b1aa 100644 --- a/include/sysemu/tpm.h +++ b/include/sysemu/tpm.h @@ -44,6 +44,7 @@ typedef struct TPMIfClass { } TPMIfClass; =20 #define TYPE_TPM_TIS_ISA "tpm-tis" +#define TYPE_TPM_TIS_SYSBUS "tpm-tis-device" #define TYPE_TPM_CRB "tpm-crb" #define TYPE_TPM_SPAPR "tpm-spapr" =20 --=20 2.20.1 From nobody Thu Nov 13 20:44:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582713102; cv=none; d=zohomail.com; s=zohoarc; b=IBM7dPIsQjElQ9y2qUqw2Ps3xQMq1nVoJtu2M8CrJmdHJtceSZ7VN0K9MQ9/jVipw+wTl54EHosM4uvGZMLPh+nxGyvIPlZ9Nl+78zZzoTdtmYdpmAeSqhGGIroesN/76lxwf+TRdEYwJH8H+CHsIlgtdfaibaJ64yfglIQhKGU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582713102; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=A7tK9fGAnXW2msKRe6WVo0L9RclFBp3c9oCciDpfXXk=; b=l4uTufI8v+k6yql0Nv5tEREkasAtVB4HAytor+ErDAToTb6lhcke4Q8XuNl0LUJROIPGL/Me3CirBcSTAM9ZAMI5EeOkQzQI05Llm4LD14Op96yU0dt0ReNSY7pW9d/WEGHjOMHbJgOvo1wHJ2IxUrZD25Rb0DDtpQPsco4mAY0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158271310208027.88548034609903; Wed, 26 Feb 2020 02:31:42 -0800 (PST) Received: from localhost ([::1]:42114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6tyf-0004cG-0N for importer@patchew.org; Wed, 26 Feb 2020 05:31:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52183) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ttf-0004oK-UP for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6tte-0003zh-Kb for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:31 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:28281 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6tte-0003yx-Fr for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:30 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-328-Nsdn5a5YPkmbo-iR2dAJFQ-1; Wed, 26 Feb 2020 05:26:28 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6517D107ACCA; Wed, 26 Feb 2020 10:26:27 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04E5460BE1; Wed, 26 Feb 2020 10:26:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582712790; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A7tK9fGAnXW2msKRe6WVo0L9RclFBp3c9oCciDpfXXk=; b=Y5ddyzdxeJQeo6wJ9UY7zJRCe4OL95/+LGJERQ3btpwo69/SkJAdM/ZCJIJZBoDaLW0Pdd M//y84Cp97SaHbumTBq1PLjXznFqrH8izA99T2aGiE9FkXD4tUQGwcmzGaSlcrPoHeUd0c 91CbzilHdYKURZhhpCQDoHnn84F2d88= X-MC-Unique: Nsdn5a5YPkmbo-iR2dAJFQ-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, stefanb@linux.ibm.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org Subject: [PATCH v3 06/10] hw/arm/virt: vTPM support Date: Wed, 26 Feb 2020 11:25:45 +0100 Message-Id: <20200226102549.12158-7-eric.auger@redhat.com> In-Reply-To: <20200226102549.12158-1-eric.auger@redhat.com> References: <20200226102549.12158-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, lersek@redhat.com, ardb@kernel.org, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Let the TPM TIS SYSBUS device be dynamically instantiable in ARM virt. A device tree node is dynamically created (TPM via MMIO). The TPM Physical Presence interface (PPI) is not supported. To run with the swtmp TPM emulator, the qemu command line must be augmented with: -chardev socket,id=3Dchrtpm,path=3Dswtpm-sock \ -tpmdev emulator,id=3Dtpm0,chardev=3Dchrtpm \ -device tpm-tis-device,tpmdev=3Dtpm0 \ swtpm/libtpms command line example: swtpm socket --tpm2 -t -d --tpmstate dir=3D/tmp/tpm \ --ctrl type=3Dunixio,path=3Dswtpm-sock Signed-off-by: Eric Auger Reviewed-by: Stefan Berger --- v2 -> v3: - use qemu_fdt_setprop_string() --- hw/arm/Kconfig | 1 + hw/arm/sysbus-fdt.c | 33 +++++++++++++++++++++++++++++++++ hw/arm/virt.c | 7 +++++++ 3 files changed, 41 insertions(+) diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 3d86691ae0..b6f03f7f53 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -5,6 +5,7 @@ config ARM_VIRT imply VFIO_AMD_XGBE imply VFIO_PLATFORM imply VFIO_XGMAC + imply TPM_TIS_SYSBUS select A15MPCORE select ACPI select ARM_SMMUV3 diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c index 022fc97ecd..f603787b65 100644 --- a/hw/arm/sysbus-fdt.c +++ b/hw/arm/sysbus-fdt.c @@ -30,6 +30,7 @@ #include "hw/arm/sysbus-fdt.h" #include "qemu/error-report.h" #include "sysemu/device_tree.h" +#include "sysemu/tpm.h" #include "hw/platform-bus.h" #include "hw/vfio/vfio-platform.h" #include "hw/vfio/vfio-calxeda-xgmac.h" @@ -434,6 +435,37 @@ static bool vfio_platform_match(SysBusDevice *sbdev, #define VFIO_PLATFORM_BINDING(compat, add_fn) \ {TYPE_VFIO_PLATFORM, (compat), (add_fn), vfio_platform_match} =20 +/* + * add_tpm_tis_fdt_node: Create a DT node for TPM TIS + * + * See kernel documentation: + * Documentation/devicetree/bindings/security/tpm/tpm_tis_mmio.txt + * Optional interrupt for command completion is not exposed + */ +static int add_tpm_tis_fdt_node(SysBusDevice *sbdev, void *opaque) +{ + PlatformBusFDTData *data =3D opaque; + PlatformBusDevice *pbus =3D data->pbus; + void *fdt =3D data->fdt; + const char *parent_node =3D data->pbus_node_name; + char *nodename; + uint32_t reg_attr[2]; + uint64_t mmio_base; + + mmio_base =3D platform_bus_get_mmio_addr(pbus, sbdev, 0); + nodename =3D g_strdup_printf("%s/tpm_tis@%" PRIx64, parent_node, mmio_= base); + qemu_fdt_add_subnode(fdt, nodename); + + qemu_fdt_setprop_string(fdt, nodename, "compatible", "tcg,tpm-tis-mmio= "); + + reg_attr[0] =3D cpu_to_be32(mmio_base); + reg_attr[1] =3D cpu_to_be32(0x5000); + qemu_fdt_setprop(fdt, nodename, "reg", reg_attr, 2 * sizeof(uint32_t)); + + g_free(nodename); + return 0; +} + #endif /* CONFIG_LINUX */ =20 static int no_fdt_node(SysBusDevice *sbdev, void *opaque) @@ -455,6 +487,7 @@ static const BindingEntry bindings[] =3D { TYPE_BINDING(TYPE_VFIO_CALXEDA_XGMAC, add_calxeda_midway_xgmac_fdt_nod= e), TYPE_BINDING(TYPE_VFIO_AMD_XGBE, add_amd_xgbe_fdt_node), VFIO_PLATFORM_BINDING("amd,xgbe-seattle-v1a", add_amd_xgbe_fdt_node), + TYPE_BINDING(TYPE_TPM_TIS_SYSBUS, add_tpm_tis_fdt_node), #endif TYPE_BINDING(TYPE_RAMFB_DEVICE, no_fdt_node), TYPE_BINDING("", NULL), /* last element */ diff --git a/hw/arm/virt.c b/hw/arm/virt.c index f788fe27d6..4b967e39d1 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -47,6 +47,7 @@ #include "sysemu/numa.h" #include "sysemu/runstate.h" #include "sysemu/sysemu.h" +#include "sysemu/tpm.h" #include "sysemu/kvm.h" #include "hw/loader.h" #include "exec/address-spaces.h" @@ -2041,6 +2042,7 @@ static void virt_machine_class_init(ObjectClass *oc, = void *data) machine_class_allow_dynamic_sysbus_dev(mc, TYPE_VFIO_AMD_XGBE); machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE); machine_class_allow_dynamic_sysbus_dev(mc, TYPE_VFIO_PLATFORM); + machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS); mc->block_default_type =3D IF_VIRTIO; mc->no_cdrom =3D 1; mc->pci_allow_0_address =3D true; @@ -2153,6 +2155,11 @@ type_init(machvirt_machine_init); =20 static void virt_machine_5_0_options(MachineClass *mc) { + static GlobalProperty compat[] =3D { + { TYPE_TPM_TIS_SYSBUS, "ppi", "false" }, + }; + + compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat)); } DEFINE_VIRT_MACHINE_AS_LATEST(5, 0) =20 --=20 2.20.1 From nobody Thu Nov 13 20:44:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582713168; cv=none; d=zohomail.com; s=zohoarc; b=k1WVorClWNyBSrE9TUfW5/fRuBlfhq1YYyjxGr3FdRBoiho+mEHhLpNYyoD9weFBBxOv+K+/lkZQoZ8xIz0UikhZEZe0Th4f2I8dcjGkBCWmZeKGCoY+c6ONNJHkQv+hU/E8IvlZKedP6CExBAqcCL6FBeK+XDY0NJTzRPwG7JU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582713168; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IwQmZv0xaQVkdsJzKqedRVySFq+XxBho2HOp8v1kkcI=; b=euVtNT/q9tM2LsZ4gEqsWazmSSj3xuG+rpLAjItEc4/aIVlOzMN41nXMWNsVUMmrHqDycAeA6CryOWln3RtPIoNvnsdR7lzNVTVv8g/abWb/8xKHs2owJEwITi5bJ2IGP2FAIW/Q2DobKIRa536eQfpSjS7fZmp4nHoPZGRRhgQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158271316851159.68808693792346; Wed, 26 Feb 2020 02:32:48 -0800 (PST) Received: from localhost ([::1]:42138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6tzj-0005cA-43 for importer@patchew.org; Wed, 26 Feb 2020 05:32:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52239) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6tti-0004v3-Ir for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6tth-000495-F0 for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:34 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:21705 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6tth-00046X-9Q for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:33 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-157-CqJTAGU5PJOICpJIJRwGBw-1; Wed, 26 Feb 2020 05:26:31 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2A98D800D54; Wed, 26 Feb 2020 10:26:30 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id C05F860C18; Wed, 26 Feb 2020 10:26:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582712792; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IwQmZv0xaQVkdsJzKqedRVySFq+XxBho2HOp8v1kkcI=; b=WmG7ZK4kLnFSdivqZYmcoLNMR/bJi1uHgenRgyrQXmz6I0SQPwPizwaSCrW6i0Nzmeulra HPmaoaTq8mmtVzb75YIq76DMUgPOHfZFtzfNPHhCtc7dJGYBbPzQyqBhdYsZSPz8KPcySM mCV3/d+Jmc5bG28g8bWHLL0lUjz+jdM= X-MC-Unique: CqJTAGU5PJOICpJIJRwGBw-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, stefanb@linux.ibm.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org Subject: [PATCH v3 07/10] docs/specs/tpm: Document TPM_TIS sysbus device for ARM Date: Wed, 26 Feb 2020 11:25:46 +0100 Message-Id: <20200226102549.12158-8-eric.auger@redhat.com> In-Reply-To: <20200226102549.12158-1-eric.auger@redhat.com> References: <20200226102549.12158-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, lersek@redhat.com, ardb@kernel.org, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Update the documentation with recent changes related to the sysbus TPM_TIS device addition and add the command line to be used with arm VIRT. Signed-off-by: Eric Auger Reviewed-by: Stefan Berger --- docs/specs/tpm.rst | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/specs/tpm.rst b/docs/specs/tpm.rst index 2bdf637f55..932cb57049 100644 --- a/docs/specs/tpm.rst +++ b/docs/specs/tpm.rst @@ -18,9 +18,15 @@ The TIS interface makes a memory mapped IO region in the= area 0xfed40000-0xfed44fff available to the guest operating system. =20 QEMU files related to TPM TIS interface: - - ``hw/tpm/tpm_tis.c`` + - ``hw/tpm/tpm_tis_common.c`` + - ``hw/tpm/tpm_tis_isa.c`` + - ``hw/tpm/tpm_tis_sysbus.c`` - ``hw/tpm/tpm_tis.h`` =20 +Both an ISA device and a sysbus device are available. The former is +used with pc/q35 machine while the later can be instantiated in the +ARM virt machine. + CRB interface ------------- =20 @@ -325,6 +331,23 @@ In case a pSeries machine is emulated, use the followi= ng command line: -device virtio-blk-pci,scsi=3Doff,bus=3Dpci.0,addr=3D0x3,drive=3Ddrive= -virtio-disk0,id=3Dvirtio-disk0 \ -drive file=3Dtest.img,format=3Draw,if=3Dnone,id=3Ddrive-virtio-disk0 =20 +In case an ARM virt machine is emulated, use the following command line: + +.. code-block:: console + + qemu-system-aarch64 -machine virt,gic-version=3D3,accel=3Dkvm \ + -cpu host -m 4G \ + -nographic -no-acpi \ + -chardev socket,id=3Dchrtpm,path=3D/tmp/mytpm1/swtpm-sock \ + -tpmdev emulator,id=3Dtpm0,chardev=3Dchrtpm \ + -device tpm-tis-device,tpmdev=3Dtpm0 \ + -device virtio-blk-pci,drive=3Ddrv0 \ + -drive format=3Dqcow2,file=3Dhda.qcow2,if=3Dnone,id=3Ddrv0 \ + -drive if=3Dpflash,format=3Draw,file=3Dflash0.img,readonly \ + -drive if=3Dpflash,format=3Draw,file=3Dflash1.img + + On ARM, ACPI boot with TPM is not yet supported. + In case SeaBIOS is used as firmware, it should show the TPM menu item after entering the menu with 'ESC'. =20 --=20 2.20.1 From nobody Thu Nov 13 20:44:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582712962; cv=none; d=zohomail.com; s=zohoarc; b=RhvBSUpoPDvU8jl8maeDL/QCFDHCJubZsGykfA7qSHQ6irSo8EHxMXwotsMgONl2yzB6gyTHRp016wswzXRZT5xVxHeQBllu7yRbkPOKJgGByk+OOPttZa6K3m/F1kWEF7btw3dawN0m1amxLZIGBbH/8ThCe0Pd0+XQNMwG7uU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582712962; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7Wf4euxvQqm184X5l9kHBAJdIyr0XaU63xoKs35+NVo=; b=AiZ+bTfK/FyvR0gKu2dXCQ/dNCbe0E1cebY9OvAcwMu57BxP1eAIdWCHQkvoDYWBw1UL5NPKHvdl3mIm5CcBbAGJz3b7YWjk7xsTkpI4FmCvvH1oczEDrWUsqbIpkDI/n3mUI6MgnNKEBYYBBN1adYPpwu1fBJNfiytxl0NUeNY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582712962323306.92724582652374; Wed, 26 Feb 2020 02:29:22 -0800 (PST) Received: from localhost ([::1]:42062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6twP-0001bU-7y for importer@patchew.org; Wed, 26 Feb 2020 05:29:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52272) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ttm-00052S-2f for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ttk-0004GJ-Fu for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:37 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:44437 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6ttk-0004Ec-CQ for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:36 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-325-gnuYjmESM9-Dk6HUZl00HA-1; Wed, 26 Feb 2020 05:26:34 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EC377108442E; Wed, 26 Feb 2020 10:26:32 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83DB460BE1; Wed, 26 Feb 2020 10:26:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582712796; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7Wf4euxvQqm184X5l9kHBAJdIyr0XaU63xoKs35+NVo=; b=eaETiD+oT//9HOIGbGL7w0KmYmMycqnNk2M9QZ2O+Kow3yPhzojxbWRHig3M1nC1kpfS2k MQZckLzjFR4DV6IH6wbdPXXSGDQmWtuRSWs9qYnaaGTS8LhVZSJgDWDuAJfFu19p6gmQKI z01uuU+MDYgZj/fRCJn4TN4eRFfFN0U= X-MC-Unique: gnuYjmESM9-Dk6HUZl00HA-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, stefanb@linux.ibm.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org Subject: [PATCH v3 08/10] test: tpm: pass optional machine options to swtpm test functions Date: Wed, 26 Feb 2020 11:25:47 +0100 Message-Id: <20200226102549.12158-9-eric.auger@redhat.com> In-Reply-To: <20200226102549.12158-1-eric.auger@redhat.com> References: <20200226102549.12158-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, lersek@redhat.com, ardb@kernel.org, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We plan to use swtpm test functions on ARM for testing the sysbus TPM-TIS device. However on ARM there is no default machine type. So we need to explictly pass some machine options on startup. Let's allow this by adding a new parameter to both swtpm test functions and update all call sites. Signed-off-by: Eric Auger Reviewed-by: Stefan Berger --- tests/qtest/tpm-crb-swtpm-test.c | 5 +++-- tests/qtest/tpm-tests.c | 10 ++++++---- tests/qtest/tpm-tests.h | 5 +++-- tests/qtest/tpm-tis-swtpm-test.c | 5 +++-- tests/qtest/tpm-util.c | 8 ++++++-- tests/qtest/tpm-util.h | 3 ++- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/tests/qtest/tpm-crb-swtpm-test.c b/tests/qtest/tpm-crb-swtpm-t= est.c index 2c4fb8ae29..5228cb7af4 100644 --- a/tests/qtest/tpm-crb-swtpm-test.c +++ b/tests/qtest/tpm-crb-swtpm-test.c @@ -29,7 +29,8 @@ static void tpm_crb_swtpm_test(const void *data) { const TestState *ts =3D data; =20 - tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_crb_transfer, "tpm-crb"= ); + tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_crb_transfer, + "tpm-crb", NULL); } =20 static void tpm_crb_swtpm_migration_test(const void *data) @@ -37,7 +38,7 @@ static void tpm_crb_swtpm_migration_test(const void *data) const TestState *ts =3D data; =20 tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->= uri, - tpm_util_crb_transfer, "tpm-crb"); + tpm_util_crb_transfer, "tpm-crb", NULL); } =20 int main(int argc, char **argv) diff --git a/tests/qtest/tpm-tests.c b/tests/qtest/tpm-tests.c index 6e45a0ba85..a2f2838e15 100644 --- a/tests/qtest/tpm-tests.c +++ b/tests/qtest/tpm-tests.c @@ -30,7 +30,7 @@ tpm_test_swtpm_skip(void) } =20 void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx, - const char *ifmodel) + const char *ifmodel, const char *machine_options) { char *args =3D NULL; QTestState *s; @@ -47,10 +47,11 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_f= unc *tx, g_assert_true(succ); =20 args =3D g_strdup_printf( + "%s " "-chardev socket,id=3Dchr,path=3D%s " "-tpmdev emulator,id=3Ddev,chardev=3Dchr " "-device %s,tpmdev=3Ddev", - addr->u.q_unix.path, ifmodel); + machine_options ? : "", addr->u.q_unix.path, ifmodel); =20 s =3D qtest_start(args); g_free(args); @@ -78,7 +79,8 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_fun= c *tx, void tpm_test_swtpm_migration_test(const char *src_tpm_path, const char *dst_tpm_path, const char *uri, tx_func *tx, - const char *ifmodel) + const char *ifmodel, + const char *machine_options) { gboolean succ; GPid src_tpm_pid, dst_tpm_pid; @@ -100,7 +102,7 @@ void tpm_test_swtpm_migration_test(const char *src_tpm_= path, =20 tpm_util_migration_start_qemu(&src_qemu, &dst_qemu, src_tpm_addr, dst_tpm_addr, uri, - ifmodel); + ifmodel, machine_options); =20 tpm_util_startup(src_qemu, tx); tpm_util_pcrextend(src_qemu, tx); diff --git a/tests/qtest/tpm-tests.h b/tests/qtest/tpm-tests.h index b97688fe75..a5df35ab5b 100644 --- a/tests/qtest/tpm-tests.h +++ b/tests/qtest/tpm-tests.h @@ -16,11 +16,12 @@ #include "tpm-util.h" =20 void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx, - const char *ifmodel); + const char *ifmodel, const char *machine_options); =20 void tpm_test_swtpm_migration_test(const char *src_tpm_path, const char *dst_tpm_path, const char *uri, tx_func *tx, - const char *ifmodel); + const char *ifmodel, + const char *machine_options); =20 #endif /* TESTS_TPM_TESTS_H */ diff --git a/tests/qtest/tpm-tis-swtpm-test.c b/tests/qtest/tpm-tis-swtpm-t= est.c index 9f58a3a92b..9470f15751 100644 --- a/tests/qtest/tpm-tis-swtpm-test.c +++ b/tests/qtest/tpm-tis-swtpm-test.c @@ -29,7 +29,8 @@ static void tpm_tis_swtpm_test(const void *data) { const TestState *ts =3D data; =20 - tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_tis_transfer, "tpm-tis"= ); + tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_tis_transfer, + "tpm-tis", NULL); } =20 static void tpm_tis_swtpm_migration_test(const void *data) @@ -37,7 +38,7 @@ static void tpm_tis_swtpm_migration_test(const void *data) const TestState *ts =3D data; =20 tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->= uri, - tpm_util_tis_transfer, "tpm-tis"); + tpm_util_tis_transfer, "tpm-tis", NULL); } =20 int main(int argc, char **argv) diff --git a/tests/qtest/tpm-util.c b/tests/qtest/tpm-util.c index e08b137651..7ecdae2fc6 100644 --- a/tests/qtest/tpm-util.c +++ b/tests/qtest/tpm-util.c @@ -258,23 +258,27 @@ void tpm_util_migration_start_qemu(QTestState **src_q= emu, SocketAddress *src_tpm_addr, SocketAddress *dst_tpm_addr, const char *miguri, - const char *ifmodel) + const char *ifmodel, + const char *machine_options) { char *src_qemu_args, *dst_qemu_args; =20 src_qemu_args =3D g_strdup_printf( + "%s " "-chardev socket,id=3Dchr,path=3D%s " "-tpmdev emulator,id=3Ddev,chardev=3Dchr " "-device %s,tpmdev=3Ddev ", - src_tpm_addr->u.q_unix.path, ifmodel); + machine_options ? : "", src_tpm_addr->u.q_unix.path, ifmodel); =20 *src_qemu =3D qtest_init(src_qemu_args); =20 dst_qemu_args =3D g_strdup_printf( + "%s " "-chardev socket,id=3Dchr,path=3D%s " "-tpmdev emulator,id=3Ddev,chardev=3Dchr " "-device %s,tpmdev=3Ddev " "-incoming %s", + machine_options ? : "", dst_tpm_addr->u.q_unix.path, ifmodel, miguri); =20 diff --git a/tests/qtest/tpm-util.h b/tests/qtest/tpm-util.h index 5755698ad2..15e3924942 100644 --- a/tests/qtest/tpm-util.h +++ b/tests/qtest/tpm-util.h @@ -44,7 +44,8 @@ void tpm_util_migration_start_qemu(QTestState **src_qemu, SocketAddress *src_tpm_addr, SocketAddress *dst_tpm_addr, const char *miguri, - const char *ifmodel); + const char *ifmodel, + const char *machine_options); =20 void tpm_util_wait_for_migration_complete(QTestState *who); =20 --=20 2.20.1 From nobody Thu Nov 13 20:44:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582713263; cv=none; d=zohomail.com; s=zohoarc; b=Ay3+tXthRjKDISKSnBhoN6LcBaTd2Q/PypoDblOUklYd0Kq20fK3b9oegRPZVhb9OYZXPBmPOhDk5xZmy5dwWfgk6w14Mql3bvxxYD/2LmXsyNzO7SO9kMMH3zlbYoBvU2fjhi7akg1GK97obFnG5DzF1GM3CBdu3l+KM2j3NRM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582713263; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kNCHVVuco+PBY1XG3cdwNfMQtkAiw6D57iodH3NqKZA=; b=a+IkXjqZWvB6HO0Kjl74gQwjYXi4Urn/2FUf4h4yLBt6qHuy683nifFkT7MOjRgCOOaqrIYTd89nYDhSK2JHVT6SG59l2NCsFUIQgUfPsU7wDoD3rbpWcJfqJwNwm5PZ6yhPTNr6st1WGg4iq8jXbA1A9Da9zDCONriXmjR23OA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582713263135347.38128642215224; Wed, 26 Feb 2020 02:34:23 -0800 (PST) Received: from localhost ([::1]:42176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6u1F-0007Wg-Ny for importer@patchew.org; Wed, 26 Feb 2020 05:34:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52336) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6tts-0005JV-N0 for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ttp-0004UY-1L for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:44 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:58649 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6tto-0004R2-Qs for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:40 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-478-PbXWlfVdMKW3j0Q5U0DXdQ-1; Wed, 26 Feb 2020 05:26:37 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2EDF7800D54; Wed, 26 Feb 2020 10:26:36 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 515F560BE1; Wed, 26 Feb 2020 10:26:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582712799; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kNCHVVuco+PBY1XG3cdwNfMQtkAiw6D57iodH3NqKZA=; b=UJzuxAPqLboB2XQTbZI3dHER7IdnR+PW6l+2Im/+591G5xAB5qD/Wk6bVcTivT5AjYnKav 5WDHb5jqfEEBGOEu6ZSbnqfzR/w5j241UrauimeMbvbN1pZ6ttDKRFCXki3m6HM0r4QCwf FzFEdBs89GTBFHiuCYEXBmLkF52+J4o= X-MC-Unique: PbXWlfVdMKW3j0Q5U0DXdQ-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, stefanb@linux.ibm.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org Subject: [PATCH v3 09/10] test: tpm-tis: Get prepared to share tests between ISA and sysbus devices Date: Wed, 26 Feb 2020 11:25:48 +0100 Message-Id: <20200226102549.12158-10-eric.auger@redhat.com> In-Reply-To: <20200226102549.12158-1-eric.auger@redhat.com> References: <20200226102549.12158-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, lersek@redhat.com, ardb@kernel.org, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" ISA and sysbus TPM-TIS devices will share their tests. Only the main() will change (instantiation option is different). Also the base address of the TPM-TIS device is going to be different. on x86 it is located at 0xFED40000 while on ARM it can be located at any location, discovered through the device tree description. So we put shared test functions in a new object module. Each test needs to set tpm_tis_base_addr global variable. Signed-off-by: Eric Auger Reviewed-by: Stefan Berger --- tests/qtest/Makefile.include | 2 +- tests/qtest/tpm-crb-swtpm-test.c | 3 + tests/qtest/tpm-crb-test.c | 2 + tests/qtest/tpm-tis-swtpm-test.c | 3 + tests/qtest/tpm-tis-test.c | 414 +---------------------------- tests/qtest/tpm-tis-util.c | 433 +++++++++++++++++++++++++++++++ tests/qtest/tpm-tis-util.h | 23 ++ tests/qtest/tpm-util.c | 3 - tests/qtest/tpm-util.h | 5 + 9 files changed, 473 insertions(+), 415 deletions(-) create mode 100644 tests/qtest/tpm-tis-util.c create mode 100644 tests/qtest/tpm-tis-util.h diff --git a/tests/qtest/Makefile.include b/tests/qtest/Makefile.include index 028af5b782..44aac68b25 100644 --- a/tests/qtest/Makefile.include +++ b/tests/qtest/Makefile.include @@ -302,7 +302,7 @@ tests/qtest/tpm-crb-swtpm-test$(EXESUF): tests/qtest/tp= m-crb-swtpm-test.o tests/ tests/qtest/tpm-crb-test$(EXESUF): tests/qtest/tpm-crb-test.o tests/qtest/= tpm-emu.o $(test-io-obj-y) tests/qtest/tpm-tis-swtpm-test$(EXESUF): tests/qtest/tpm-tis-swtpm-test.o = tests/qtest/tpm-emu.o \ tests/qtest/tpm-util.o tests/qtest/tpm-tests.o $(test-io-obj-y) -tests/qtest/tpm-tis-test$(EXESUF): tests/qtest/tpm-tis-test.o tests/qtest/= tpm-emu.o $(test-io-obj-y) +tests/qtest/tpm-tis-test$(EXESUF): tests/qtest/tpm-tis-test.o tests/qtest/= tpm-tis-util.o tests/qtest/tpm-emu.o $(test-io-obj-y) =20 # QTest rules =20 diff --git a/tests/qtest/tpm-crb-swtpm-test.c b/tests/qtest/tpm-crb-swtpm-t= est.c index 5228cb7af4..ac92f08bee 100644 --- a/tests/qtest/tpm-crb-swtpm-test.c +++ b/tests/qtest/tpm-crb-swtpm-test.c @@ -18,6 +18,9 @@ #include "libqtest.h" #include "qemu/module.h" #include "tpm-tests.h" +#include "hw/acpi/tpm.h" + +uint64_t tpm_tis_base_addr =3D TPM_TIS_ADDR_BASE; =20 typedef struct TestState { char *src_tpm_path; diff --git a/tests/qtest/tpm-crb-test.c b/tests/qtest/tpm-crb-test.c index 632fb7fbd8..cdd09e5396 100644 --- a/tests/qtest/tpm-crb-test.c +++ b/tests/qtest/tpm-crb-test.c @@ -19,6 +19,8 @@ #include "qemu/module.h" #include "tpm-emu.h" =20 +uint64_t tpm_tis_base_addr =3D TPM_TIS_ADDR_BASE; + #define TPM_CMD "\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00" =20 static void tpm_crb_test(const void *data) diff --git a/tests/qtest/tpm-tis-swtpm-test.c b/tests/qtest/tpm-tis-swtpm-t= est.c index 9470f15751..90131cb3c4 100644 --- a/tests/qtest/tpm-tis-swtpm-test.c +++ b/tests/qtest/tpm-tis-swtpm-test.c @@ -18,6 +18,9 @@ #include "libqtest.h" #include "qemu/module.h" #include "tpm-tests.h" +#include "hw/acpi/tpm.h" + +uint64_t tpm_tis_base_addr =3D TPM_TIS_ADDR_BASE; =20 typedef struct TestState { char *src_tpm_path; diff --git a/tests/qtest/tpm-tis-test.c b/tests/qtest/tpm-tis-test.c index dcf30e05b7..79ffbc943e 100644 --- a/tests/qtest/tpm-tis-test.c +++ b/tests/qtest/tpm-tis-test.c @@ -1,5 +1,5 @@ /* - * QTest testcase for TPM TIS + * QTest testcase for ISA TPM TIS * * Copyright (c) 2018 Red Hat, Inc. * Copyright (c) 2018 IBM Corporation @@ -20,417 +20,9 @@ #include "libqtest-single.h" #include "qemu/module.h" #include "tpm-emu.h" +#include "tpm-tis-util.h" =20 -#define TIS_REG(LOCTY, REG) \ - (TPM_TIS_ADDR_BASE + ((LOCTY) << 12) + REG) - -#define DEBUG_TIS_TEST 0 - -#define DPRINTF(fmt, ...) do { \ - if (DEBUG_TIS_TEST) { \ - printf(fmt, ## __VA_ARGS__); \ - } \ -} while (0) - -#define DPRINTF_ACCESS \ - DPRINTF("%s: %d: locty=3D%d l=3D%d access=3D0x%02x pending_request_fla= g=3D0x%x\n", \ - __func__, __LINE__, locty, l, access, pending_request_flag) - -#define DPRINTF_STS \ - DPRINTF("%s: %d: sts =3D 0x%08x\n", __func__, __LINE__, sts) - -static const uint8_t TPM_CMD[12] =3D - "\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00"; - -static void tpm_tis_test_check_localities(const void *data) -{ - uint8_t locty; - uint8_t access; - uint32_t ifaceid; - uint32_t capability; - uint32_t didvid; - uint32_t rid; - - for (locty =3D 0; locty < TPM_TIS_NUM_LOCALITIES; locty++) { - access =3D readb(TIS_REG(0, TPM_TIS_REG_ACCESS)); - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - capability =3D readl(TIS_REG(locty, TPM_TIS_REG_INTF_CAPABILITY)); - g_assert_cmpint(capability, =3D=3D, TPM_TIS_CAPABILITIES_SUPPORTED= 2_0); - - ifaceid =3D readl(TIS_REG(locty, TPM_TIS_REG_INTERFACE_ID)); - g_assert_cmpint(ifaceid, =3D=3D, TPM_TIS_IFACE_ID_SUPPORTED_FLAGS2= _0); - - didvid =3D readl(TIS_REG(locty, TPM_TIS_REG_DID_VID)); - g_assert_cmpint(didvid, !=3D, 0); - g_assert_cmpint(didvid, !=3D, 0xffffffff); - - rid =3D readl(TIS_REG(locty, TPM_TIS_REG_RID)); - g_assert_cmpint(rid, !=3D, 0); - g_assert_cmpint(rid, !=3D, 0xffffffff); - } -} - -static void tpm_tis_test_check_access_reg(const void *data) -{ - uint8_t locty; - uint8_t access; - - /* do not test locality 4 (hw only) */ - for (locty =3D 0; locty < TPM_TIS_NUM_LOCALITIES - 1; locty++) { - access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - /* request use of locality */ - writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_= USE); - - access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | - TPM_TIS_ACCESS_ACTIVE_LOCALITY | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - /* release access */ - writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS), - TPM_TIS_ACCESS_ACTIVE_LOCALITY); - access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - } -} - -/* - * Test case for seizing access by a higher number locality - */ -static void tpm_tis_test_check_access_reg_seize(const void *data) -{ - int locty, l; - uint8_t access; - uint8_t pending_request_flag; - - /* do not test locality 4 (hw only) */ - for (locty =3D 0; locty < TPM_TIS_NUM_LOCALITIES - 1; locty++) { - pending_request_flag =3D 0; - - access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - /* request use of locality */ - writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_= USE); - access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | - TPM_TIS_ACCESS_ACTIVE_LOCALITY | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - /* lower localities cannot seize access */ - for (l =3D 0; l < locty; l++) { - /* lower locality is not active */ - access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); - DPRINTF_ACCESS; - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | - pending_request_flag | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - /* try to request use from 'l' */ - writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_= USE); - - /* requesting use from 'l' was not possible; - we must see REQUEST_USE and possibly PENDING_REQUEST */ - access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); - DPRINTF_ACCESS; - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | - TPM_TIS_ACCESS_REQUEST_USE | - pending_request_flag | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - /* locality 'locty' must be unchanged; - we must see PENDING_REQUEST */ - access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | - TPM_TIS_ACCESS_ACTIVE_LOCALITY | - TPM_TIS_ACCESS_PENDING_REQUEST | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - /* try to seize from 'l' */ - writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_SEIZE); - /* seize from 'l' was not possible */ - access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); - DPRINTF_ACCESS; - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | - TPM_TIS_ACCESS_REQUEST_USE | - pending_request_flag | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - /* locality 'locty' must be unchanged */ - access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | - TPM_TIS_ACCESS_ACTIVE_LOCALITY | - TPM_TIS_ACCESS_PENDING_REQUEST | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - /* on the next loop we will have a PENDING_REQUEST flag - set for locality 'l' */ - pending_request_flag =3D TPM_TIS_ACCESS_PENDING_REQUEST; - } - - /* higher localities can 'seize' access but not 'request use'; - note: this will activate first l+1, then l+2 etc. */ - for (l =3D locty + 1; l < TPM_TIS_NUM_LOCALITIES - 1; l++) { - /* try to 'request use' from 'l' */ - writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_= USE); - - /* requesting use from 'l' was not possible; we should see - REQUEST_USE and may see PENDING_REQUEST */ - access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); - DPRINTF_ACCESS; - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | - TPM_TIS_ACCESS_REQUEST_USE | - pending_request_flag | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - /* locality 'l-1' must be unchanged; we should always - see PENDING_REQUEST from 'l' requesting access */ - access =3D readb(TIS_REG(l - 1, TPM_TIS_REG_ACCESS)); - DPRINTF_ACCESS; - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | - TPM_TIS_ACCESS_ACTIVE_LOCALITY | - TPM_TIS_ACCESS_PENDING_REQUEST | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - /* try to seize from 'l' */ - writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_SEIZE); - - /* seize from 'l' was possible */ - access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); - DPRINTF_ACCESS; - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | - TPM_TIS_ACCESS_ACTIVE_LOCALITY | - pending_request_flag | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - /* l - 1 should show that it has BEEN_SEIZED */ - access =3D readb(TIS_REG(l - 1, TPM_TIS_REG_ACCESS)); - DPRINTF_ACCESS; - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | - TPM_TIS_ACCESS_BEEN_SEIZED | - pending_request_flag | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - /* clear the BEEN_SEIZED flag and make sure it's gone */ - writeb(TIS_REG(l - 1, TPM_TIS_REG_ACCESS), - TPM_TIS_ACCESS_BEEN_SEIZED); - - access =3D readb(TIS_REG(l - 1, TPM_TIS_REG_ACCESS)); - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | - pending_request_flag | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - } - - /* PENDING_REQUEST will not be set if locty =3D 0 since all locali= ties - were active; in case of locty =3D 1, locality 0 will be active - but no PENDING_REQUEST anywhere */ - if (locty <=3D 1) { - pending_request_flag =3D 0; - } - - /* release access from l - 1; this activates locty - 1 */ - l--; - - access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); - DPRINTF_ACCESS; - - DPRINTF("%s: %d: relinquishing control on l =3D %d\n", - __func__, __LINE__, l); - writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), - TPM_TIS_ACCESS_ACTIVE_LOCALITY); - - access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); - DPRINTF_ACCESS; - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | - pending_request_flag | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - for (l =3D locty - 1; l >=3D 0; l--) { - access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); - DPRINTF_ACCESS; - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | - TPM_TIS_ACCESS_ACTIVE_LOCALITY | - pending_request_flag | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - /* release this locality */ - writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), - TPM_TIS_ACCESS_ACTIVE_LOCALITY); - - if (l =3D=3D 1) { - pending_request_flag =3D 0; - } - } - - /* no locality may be active now */ - for (l =3D 0; l < TPM_TIS_NUM_LOCALITIES - 1; l++) { - access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); - DPRINTF_ACCESS; - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - } - } -} - -/* - * Test case for getting access when higher number locality relinquishes a= ccess - */ -static void tpm_tis_test_check_access_reg_release(const void *data) -{ - int locty, l; - uint8_t access; - uint8_t pending_request_flag; - - /* do not test locality 4 (hw only) */ - for (locty =3D TPM_TIS_NUM_LOCALITIES - 2; locty >=3D 0; locty--) { - pending_request_flag =3D 0; - - access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - /* request use of locality */ - writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_= USE); - access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | - TPM_TIS_ACCESS_ACTIVE_LOCALITY | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - /* request use of all other localities */ - for (l =3D 0; l < TPM_TIS_NUM_LOCALITIES - 1; l++) { - if (l =3D=3D locty) { - continue; - } - /* request use of locality 'l' -- we MUST see REQUEST USE and - may see PENDING_REQUEST */ - writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_= USE); - access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); - DPRINTF_ACCESS; - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | - TPM_TIS_ACCESS_REQUEST_USE | - pending_request_flag | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - pending_request_flag =3D TPM_TIS_ACCESS_PENDING_REQUEST; - } - /* release locality 'locty' */ - writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS), - TPM_TIS_ACCESS_ACTIVE_LOCALITY); - /* highest locality should now be active; release it and make sure= the - next higest locality is active afterwards */ - for (l =3D TPM_TIS_NUM_LOCALITIES - 2; l >=3D 0; l--) { - if (l =3D=3D locty) { - continue; - } - /* 'l' should be active now */ - access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); - DPRINTF_ACCESS; - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | - TPM_TIS_ACCESS_ACTIVE_LOCALITY | - pending_request_flag | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - /* 'l' relinquishes access */ - writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), - TPM_TIS_ACCESS_ACTIVE_LOCALITY); - access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); - DPRINTF_ACCESS; - if (l =3D=3D 1 || (locty <=3D 1 && l =3D=3D 2)) { - pending_request_flag =3D 0; - } - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | - pending_request_flag | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - } - } -} - -/* - * Test case for transmitting packets - */ -static void tpm_tis_test_check_transmit(const void *data) -{ - const TestState *s =3D data; - uint8_t access; - uint32_t sts; - uint16_t bcount; - size_t i; - - /* request use of locality 0 */ - writeb(TIS_REG(0, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE); - access =3D readb(TIS_REG(0, TPM_TIS_REG_ACCESS)); - g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | - TPM_TIS_ACCESS_ACTIVE_LOCALITY | - TPM_TIS_ACCESS_TPM_ESTABLISHMENT); - - sts =3D readl(TIS_REG(0, TPM_TIS_REG_STS)); - DPRINTF_STS; - - g_assert_cmpint(sts & 0xff, =3D=3D, 0); - g_assert_cmpint(sts & TPM_TIS_STS_TPM_FAMILY_MASK, =3D=3D, - TPM_TIS_STS_TPM_FAMILY2_0); - - bcount =3D (sts >> 8) & 0xffff; - g_assert_cmpint(bcount, >=3D, 128); - - writel(TIS_REG(0, TPM_TIS_REG_STS), TPM_TIS_STS_COMMAND_READY); - sts =3D readl(TIS_REG(0, TPM_TIS_REG_STS)); - DPRINTF_STS; - g_assert_cmpint(sts & 0xff, =3D=3D, TPM_TIS_STS_COMMAND_READY); - - /* transmit command */ - for (i =3D 0; i < sizeof(TPM_CMD); i++) { - writeb(TIS_REG(0, TPM_TIS_REG_DATA_FIFO), TPM_CMD[i]); - sts =3D readl(TIS_REG(0, TPM_TIS_REG_STS)); - DPRINTF_STS; - if (i < sizeof(TPM_CMD) - 1) { - g_assert_cmpint(sts & 0xff, =3D=3D, - TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID); - } else { - g_assert_cmpint(sts & 0xff, =3D=3D, TPM_TIS_STS_VALID); - } - g_assert_cmpint((sts >> 8) & 0xffff, =3D=3D, --bcount); - } - /* start processing */ - writeb(TIS_REG(0, TPM_TIS_REG_STS), TPM_TIS_STS_TPM_GO); - - uint64_t end_time =3D g_get_monotonic_time() + 50 * G_TIME_SPAN_SECOND; - do { - sts =3D readl(TIS_REG(0, TPM_TIS_REG_STS)); - if ((sts & TPM_TIS_STS_DATA_AVAILABLE) !=3D 0) { - break; - } - } while (g_get_monotonic_time() < end_time); - - sts =3D readl(TIS_REG(0, TPM_TIS_REG_STS)); - DPRINTF_STS; - g_assert_cmpint(sts & 0xff, =3D=3D , - TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE); - bcount =3D (sts >> 8) & 0xffff; - - /* read response */ - uint8_t tpm_msg[sizeof(struct tpm_hdr)]; - g_assert_cmpint(sizeof(tpm_msg), =3D=3D, bcount); - - for (i =3D 0; i < sizeof(tpm_msg); i++) { - tpm_msg[i] =3D readb(TIS_REG(0, TPM_TIS_REG_DATA_FIFO)); - sts =3D readl(TIS_REG(0, TPM_TIS_REG_STS)); - DPRINTF_STS; - if (sts & TPM_TIS_STS_DATA_AVAILABLE) { - g_assert_cmpint((sts >> 8) & 0xffff, =3D=3D, --bcount); - } - } - g_assert_cmpmem(tpm_msg, sizeof(tpm_msg), s->tpm_msg, sizeof(*s->tpm_m= sg)); - - /* relinquish use of locality 0 */ - writeb(TIS_REG(0, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_ACTIVE_LOCALITY); - access =3D readb(TIS_REG(0, TPM_TIS_REG_ACCESS)); -} +uint64_t tpm_tis_base_addr =3D TPM_TIS_ADDR_BASE; =20 int main(int argc, char **argv) { diff --git a/tests/qtest/tpm-tis-util.c b/tests/qtest/tpm-tis-util.c new file mode 100644 index 0000000000..8d3e5f1cc3 --- /dev/null +++ b/tests/qtest/tpm-tis-util.c @@ -0,0 +1,433 @@ +/* + * QTest testcase for TPM TIS: common test functions used for both + * the ISA and SYSBUS devices + * + * Copyright (c) 2018 Red Hat, Inc. + * Copyright (c) 2018 IBM Corporation + * + * Authors: + * Marc-Andr=C3=A9 Lureau + * 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 + +#include "hw/acpi/tpm.h" +#include "io/channel-socket.h" +#include "libqtest-single.h" +#include "qemu/module.h" +#include "tpm-emu.h" +#include "tpm-util.h" +#include "tpm-tis-util.h" + +#define DEBUG_TIS_TEST 0 + +#define DPRINTF(fmt, ...) do { \ + if (DEBUG_TIS_TEST) { \ + printf(fmt, ## __VA_ARGS__); \ + } \ +} while (0) + +#define DPRINTF_ACCESS \ + DPRINTF("%s: %d: locty=3D%d l=3D%d access=3D0x%02x pending_request_fla= g=3D0x%x\n", \ + __func__, __LINE__, locty, l, access, pending_request_flag) + +#define DPRINTF_STS \ + DPRINTF("%s: %d: sts =3D 0x%08x\n", __func__, __LINE__, sts) + +static const uint8_t TPM_CMD[12] =3D + "\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00"; + +void tpm_tis_test_check_localities(const void *data) +{ + uint8_t locty; + uint8_t access; + uint32_t ifaceid; + uint32_t capability; + uint32_t didvid; + uint32_t rid; + + for (locty =3D 0; locty < TPM_TIS_NUM_LOCALITIES; locty++) { + access =3D readb(TIS_REG(0, TPM_TIS_REG_ACCESS)); + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + capability =3D readl(TIS_REG(locty, TPM_TIS_REG_INTF_CAPABILITY)); + g_assert_cmpint(capability, =3D=3D, TPM_TIS_CAPABILITIES_SUPPORTED= 2_0); + + ifaceid =3D readl(TIS_REG(locty, TPM_TIS_REG_INTERFACE_ID)); + g_assert_cmpint(ifaceid, =3D=3D, TPM_TIS_IFACE_ID_SUPPORTED_FLAGS2= _0); + + didvid =3D readl(TIS_REG(locty, TPM_TIS_REG_DID_VID)); + g_assert_cmpint(didvid, !=3D, 0); + g_assert_cmpint(didvid, !=3D, 0xffffffff); + + rid =3D readl(TIS_REG(locty, TPM_TIS_REG_RID)); + g_assert_cmpint(rid, !=3D, 0); + g_assert_cmpint(rid, !=3D, 0xffffffff); + } +} + +void tpm_tis_test_check_access_reg(const void *data) +{ + uint8_t locty; + uint8_t access; + + /* do not test locality 4 (hw only) */ + for (locty =3D 0; locty < TPM_TIS_NUM_LOCALITIES - 1; locty++) { + access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + /* request use of locality */ + writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_= USE); + + access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | + TPM_TIS_ACCESS_ACTIVE_LOCALITY | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + /* release access */ + writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS), + TPM_TIS_ACCESS_ACTIVE_LOCALITY); + access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + } +} + +/* + * Test case for seizing access by a higher number locality + */ +void tpm_tis_test_check_access_reg_seize(const void *data) +{ + int locty, l; + uint8_t access; + uint8_t pending_request_flag; + + /* do not test locality 4 (hw only) */ + for (locty =3D 0; locty < TPM_TIS_NUM_LOCALITIES - 1; locty++) { + pending_request_flag =3D 0; + + access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + /* request use of locality */ + writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_= USE); + access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | + TPM_TIS_ACCESS_ACTIVE_LOCALITY | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + /* lower localities cannot seize access */ + for (l =3D 0; l < locty; l++) { + /* lower locality is not active */ + access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); + DPRINTF_ACCESS; + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | + pending_request_flag | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + /* try to request use from 'l' */ + writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_= USE); + + /* requesting use from 'l' was not possible; + we must see REQUEST_USE and possibly PENDING_REQUEST */ + access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); + DPRINTF_ACCESS; + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | + TPM_TIS_ACCESS_REQUEST_USE | + pending_request_flag | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + /* locality 'locty' must be unchanged; + we must see PENDING_REQUEST */ + access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | + TPM_TIS_ACCESS_ACTIVE_LOCALITY | + TPM_TIS_ACCESS_PENDING_REQUEST | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + /* try to seize from 'l' */ + writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_SEIZE); + /* seize from 'l' was not possible */ + access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); + DPRINTF_ACCESS; + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | + TPM_TIS_ACCESS_REQUEST_USE | + pending_request_flag | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + /* locality 'locty' must be unchanged */ + access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | + TPM_TIS_ACCESS_ACTIVE_LOCALITY | + TPM_TIS_ACCESS_PENDING_REQUEST | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + /* on the next loop we will have a PENDING_REQUEST flag + set for locality 'l' */ + pending_request_flag =3D TPM_TIS_ACCESS_PENDING_REQUEST; + } + + /* higher localities can 'seize' access but not 'request use'; + note: this will activate first l+1, then l+2 etc. */ + for (l =3D locty + 1; l < TPM_TIS_NUM_LOCALITIES - 1; l++) { + /* try to 'request use' from 'l' */ + writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_= USE); + + /* requesting use from 'l' was not possible; we should see + REQUEST_USE and may see PENDING_REQUEST */ + access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); + DPRINTF_ACCESS; + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | + TPM_TIS_ACCESS_REQUEST_USE | + pending_request_flag | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + /* locality 'l-1' must be unchanged; we should always + see PENDING_REQUEST from 'l' requesting access */ + access =3D readb(TIS_REG(l - 1, TPM_TIS_REG_ACCESS)); + DPRINTF_ACCESS; + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | + TPM_TIS_ACCESS_ACTIVE_LOCALITY | + TPM_TIS_ACCESS_PENDING_REQUEST | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + /* try to seize from 'l' */ + writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_SEIZE); + + /* seize from 'l' was possible */ + access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); + DPRINTF_ACCESS; + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | + TPM_TIS_ACCESS_ACTIVE_LOCALITY | + pending_request_flag | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + /* l - 1 should show that it has BEEN_SEIZED */ + access =3D readb(TIS_REG(l - 1, TPM_TIS_REG_ACCESS)); + DPRINTF_ACCESS; + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | + TPM_TIS_ACCESS_BEEN_SEIZED | + pending_request_flag | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + /* clear the BEEN_SEIZED flag and make sure it's gone */ + writeb(TIS_REG(l - 1, TPM_TIS_REG_ACCESS), + TPM_TIS_ACCESS_BEEN_SEIZED); + + access =3D readb(TIS_REG(l - 1, TPM_TIS_REG_ACCESS)); + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | + pending_request_flag | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + } + + /* PENDING_REQUEST will not be set if locty =3D 0 since all locali= ties + were active; in case of locty =3D 1, locality 0 will be active + but no PENDING_REQUEST anywhere */ + if (locty <=3D 1) { + pending_request_flag =3D 0; + } + + /* release access from l - 1; this activates locty - 1 */ + l--; + + access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); + DPRINTF_ACCESS; + + DPRINTF("%s: %d: relinquishing control on l =3D %d\n", + __func__, __LINE__, l); + writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), + TPM_TIS_ACCESS_ACTIVE_LOCALITY); + + access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); + DPRINTF_ACCESS; + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | + pending_request_flag | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + for (l =3D locty - 1; l >=3D 0; l--) { + access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); + DPRINTF_ACCESS; + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | + TPM_TIS_ACCESS_ACTIVE_LOCALITY | + pending_request_flag | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + /* release this locality */ + writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), + TPM_TIS_ACCESS_ACTIVE_LOCALITY); + + if (l =3D=3D 1) { + pending_request_flag =3D 0; + } + } + + /* no locality may be active now */ + for (l =3D 0; l < TPM_TIS_NUM_LOCALITIES - 1; l++) { + access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); + DPRINTF_ACCESS; + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + } + } +} + +/* + * Test case for getting access when higher number locality relinquishes a= ccess + */ +void tpm_tis_test_check_access_reg_release(const void *data) +{ + int locty, l; + uint8_t access; + uint8_t pending_request_flag; + + /* do not test locality 4 (hw only) */ + for (locty =3D TPM_TIS_NUM_LOCALITIES - 2; locty >=3D 0; locty--) { + pending_request_flag =3D 0; + + access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + /* request use of locality */ + writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_= USE); + access =3D readb(TIS_REG(locty, TPM_TIS_REG_ACCESS)); + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | + TPM_TIS_ACCESS_ACTIVE_LOCALITY | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + /* request use of all other localities */ + for (l =3D 0; l < TPM_TIS_NUM_LOCALITIES - 1; l++) { + if (l =3D=3D locty) { + continue; + } + /* request use of locality 'l' -- we MUST see REQUEST USE and + may see PENDING_REQUEST */ + writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_= USE); + access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); + DPRINTF_ACCESS; + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | + TPM_TIS_ACCESS_REQUEST_USE | + pending_request_flag | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + pending_request_flag =3D TPM_TIS_ACCESS_PENDING_REQUEST; + } + /* release locality 'locty' */ + writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS), + TPM_TIS_ACCESS_ACTIVE_LOCALITY); + /* highest locality should now be active; release it and make sure= the + next higest locality is active afterwards */ + for (l =3D TPM_TIS_NUM_LOCALITIES - 2; l >=3D 0; l--) { + if (l =3D=3D locty) { + continue; + } + /* 'l' should be active now */ + access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); + DPRINTF_ACCESS; + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | + TPM_TIS_ACCESS_ACTIVE_LOCALITY | + pending_request_flag | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + /* 'l' relinquishes access */ + writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), + TPM_TIS_ACCESS_ACTIVE_LOCALITY); + access =3D readb(TIS_REG(l, TPM_TIS_REG_ACCESS)); + DPRINTF_ACCESS; + if (l =3D=3D 1 || (locty <=3D 1 && l =3D=3D 2)) { + pending_request_flag =3D 0; + } + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_S= TS | + pending_request_flag | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + } + } +} + +/* + * Test case for transmitting packets + */ +void tpm_tis_test_check_transmit(const void *data) +{ + const TestState *s =3D data; + uint8_t access; + uint32_t sts; + uint16_t bcount; + size_t i; + + /* request use of locality 0 */ + writeb(TIS_REG(0, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE); + access =3D readb(TIS_REG(0, TPM_TIS_REG_ACCESS)); + g_assert_cmpint(access, =3D=3D, TPM_TIS_ACCESS_TPM_REG_VALID_STS | + TPM_TIS_ACCESS_ACTIVE_LOCALITY | + TPM_TIS_ACCESS_TPM_ESTABLISHMENT); + + sts =3D readl(TIS_REG(0, TPM_TIS_REG_STS)); + DPRINTF_STS; + + g_assert_cmpint(sts & 0xff, =3D=3D, 0); + g_assert_cmpint(sts & TPM_TIS_STS_TPM_FAMILY_MASK, =3D=3D, + TPM_TIS_STS_TPM_FAMILY2_0); + + bcount =3D (sts >> 8) & 0xffff; + g_assert_cmpint(bcount, >=3D, 128); + + writel(TIS_REG(0, TPM_TIS_REG_STS), TPM_TIS_STS_COMMAND_READY); + sts =3D readl(TIS_REG(0, TPM_TIS_REG_STS)); + DPRINTF_STS; + g_assert_cmpint(sts & 0xff, =3D=3D, TPM_TIS_STS_COMMAND_READY); + + /* transmit command */ + for (i =3D 0; i < sizeof(TPM_CMD); i++) { + writeb(TIS_REG(0, TPM_TIS_REG_DATA_FIFO), TPM_CMD[i]); + sts =3D readl(TIS_REG(0, TPM_TIS_REG_STS)); + DPRINTF_STS; + if (i < sizeof(TPM_CMD) - 1) { + g_assert_cmpint(sts & 0xff, =3D=3D, + TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID); + } else { + g_assert_cmpint(sts & 0xff, =3D=3D, TPM_TIS_STS_VALID); + } + g_assert_cmpint((sts >> 8) & 0xffff, =3D=3D, --bcount); + } + /* start processing */ + writeb(TIS_REG(0, TPM_TIS_REG_STS), TPM_TIS_STS_TPM_GO); + + uint64_t end_time =3D g_get_monotonic_time() + 50 * G_TIME_SPAN_SECOND; + do { + sts =3D readl(TIS_REG(0, TPM_TIS_REG_STS)); + if ((sts & TPM_TIS_STS_DATA_AVAILABLE) !=3D 0) { + break; + } + } while (g_get_monotonic_time() < end_time); + + sts =3D readl(TIS_REG(0, TPM_TIS_REG_STS)); + DPRINTF_STS; + g_assert_cmpint(sts & 0xff, =3D=3D , + TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE); + bcount =3D (sts >> 8) & 0xffff; + + /* read response */ + uint8_t tpm_msg[sizeof(struct tpm_hdr)]; + g_assert_cmpint(sizeof(tpm_msg), =3D=3D, bcount); + + for (i =3D 0; i < sizeof(tpm_msg); i++) { + tpm_msg[i] =3D readb(TIS_REG(0, TPM_TIS_REG_DATA_FIFO)); + sts =3D readl(TIS_REG(0, TPM_TIS_REG_STS)); + DPRINTF_STS; + if (sts & TPM_TIS_STS_DATA_AVAILABLE) { + g_assert_cmpint((sts >> 8) & 0xffff, =3D=3D, --bcount); + } + } + g_assert_cmpmem(tpm_msg, sizeof(tpm_msg), s->tpm_msg, sizeof(*s->tpm_m= sg)); + + /* relinquish use of locality 0 */ + writeb(TIS_REG(0, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_ACTIVE_LOCALITY); + access =3D readb(TIS_REG(0, TPM_TIS_REG_ACCESS)); +} diff --git a/tests/qtest/tpm-tis-util.h b/tests/qtest/tpm-tis-util.h new file mode 100644 index 0000000000..d10efe86ae --- /dev/null +++ b/tests/qtest/tpm-tis-util.h @@ -0,0 +1,23 @@ +/* + * QTest TPM TIS: Common test functions used for both the + * ISA and SYSBUS devices + * + * 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 TESTS_TPM_TIS_UTIL_H +#define TESTS_TPM_TIS_UTIL_H + +void tpm_tis_test_check_localities(const void *data); +void tpm_tis_test_check_access_reg(const void *data); +void tpm_tis_test_check_access_reg_seize(const void *data); +void tpm_tis_test_check_access_reg_release(const void *data); +void tpm_tis_test_check_transmit(const void *data); + +#endif /* TESTS_TPM_TIS_UTIL_H */ diff --git a/tests/qtest/tpm-util.c b/tests/qtest/tpm-util.c index 7ecdae2fc6..34efae8f18 100644 --- a/tests/qtest/tpm-util.c +++ b/tests/qtest/tpm-util.c @@ -19,9 +19,6 @@ #include "tpm-util.h" #include "qapi/qmp/qdict.h" =20 -#define TIS_REG(LOCTY, REG) \ - (TPM_TIS_ADDR_BASE + ((LOCTY) << 12) + REG) - void tpm_util_crb_transfer(QTestState *s, const unsigned char *req, size_t req_size, unsigned char *rsp, size_t rsp_size) diff --git a/tests/qtest/tpm-util.h b/tests/qtest/tpm-util.h index 15e3924942..3f5fa6eee9 100644 --- a/tests/qtest/tpm-util.h +++ b/tests/qtest/tpm-util.h @@ -15,6 +15,11 @@ =20 #include "io/channel-socket.h" =20 +#define TIS_REG(LOCTY, REG) \ + (tpm_tis_base_addr + ((LOCTY) << 12) + REG) + +extern uint64_t tpm_tis_base_addr; + typedef void (tx_func)(QTestState *s, const unsigned char *req, size_t req_size, unsigned char *rsp, size_t rsp_size); --=20 2.20.1 From nobody Thu Nov 13 20:44:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582712985; cv=none; d=zohomail.com; s=zohoarc; b=IFi/h55NRqrJ7mu1BgRSbFlROl8wjUAWMvKnEYUz2JNRnGaEaiXgo5cpCHdSU6ICy671Mb/wxkKBw87+9X63Dzl+Cblp7SX95dgo+JHFJeP+m1yESrHW3SlgqhD0DdxTktHMMPbRmbwEy8PvBL8YVEq0HqBy/YdmC50XAgJBLbA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582712985; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=npn9w/MCI9DAphGptm+Tea0GCFNfsaS3pdMetjxfAJ8=; b=QJmhuTnO4GfPmNBxsnBIxwflpKM2SyeS+hUzHXda62t/yk0YetXlf34K2zRkny6MUUnWKWC5GYfhQSS+Xjc0Ad3QlQ2R6FRmjruDdjx1C8t473tIAjI3jJ9ILxa79N/bIagevmodwDnNKtEaSZxTeOlhTIw+iIBzIW3Ed9igtSE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15827129859041012.4220420081517; Wed, 26 Feb 2020 02:29:45 -0800 (PST) Received: from localhost ([::1]:42070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6twm-0002Jq-S6 for importer@patchew.org; Wed, 26 Feb 2020 05:29:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52388) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ttx-0005Uh-30 for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ttv-0004oV-Dh for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:48 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:49165 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6ttv-0004o1-9R for qemu-devel@nongnu.org; Wed, 26 Feb 2020 05:26:47 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-199-GFLACBLjOu2FiIPy3LIEgQ-1; Wed, 26 Feb 2020 05:26:45 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E15131882CCC; Wed, 26 Feb 2020 10:26:43 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8990C60BE2; Wed, 26 Feb 2020 10:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582712806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=npn9w/MCI9DAphGptm+Tea0GCFNfsaS3pdMetjxfAJ8=; b=Eq4MWL5HbsNU1XZ9kygfqNCyqdfwVs9DJZC9pl5JetFgVaap309DM4xbmPMt7cKorIA/uA bJOYa3n5ooxevEq8zsQOHktwt0Ou8EE4n8S+biZitQsUdD8Qu6OxKsX+DX9vmSDGUy06/d KTpGqshnaJwJ73yv1K7lIOCYeTNissc= X-MC-Unique: GFLACBLjOu2FiIPy3LIEgQ-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, stefanb@linux.ibm.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org Subject: [PATCH v3 10/10] test: tpm-tis: Add Sysbus TPM-TIS device test Date: Wed, 26 Feb 2020 11:25:49 +0100 Message-Id: <20200226102549.12158-11-eric.auger@redhat.com> In-Reply-To: <20200226102549.12158-1-eric.auger@redhat.com> References: <20200226102549.12158-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, lersek@redhat.com, ardb@kernel.org, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The tests themselves are the same as the ISA device ones. Only the main() changes as the "tpm-tis-device" device gets instantiated. Also the base address of the device is not 0xFED40000 anymore but matches the base address of the ARM virt platform bus. Signed-off-by: Eric Auger Reviewed-by: Stefan Berger --- tests/qtest/Makefile.include | 5 ++ tests/qtest/tpm-tis-device-swtpm-test.c | 76 +++++++++++++++++++++ tests/qtest/tpm-tis-device-test.c | 87 +++++++++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 tests/qtest/tpm-tis-device-swtpm-test.c create mode 100644 tests/qtest/tpm-tis-device-test.c diff --git a/tests/qtest/Makefile.include b/tests/qtest/Makefile.include index 44aac68b25..383b0ab217 100644 --- a/tests/qtest/Makefile.include +++ b/tests/qtest/Makefile.include @@ -130,6 +130,8 @@ check-qtest-arm-y +=3D hexloader-test check-qtest-arm-$(CONFIG_PFLASH_CFI02) +=3D pflash-cfi02-test =20 check-qtest-aarch64-y +=3D arm-cpu-features +check-qtest-aarch64-$(CONFIG_TPM_TIS_SYSBUS) +=3D tpm-tis-device-test +check-qtest-aarch64-$(CONFIG_TPM_TIS_SYSBUS) +=3D tpm-tis-device-swtpm-test check-qtest-aarch64-y +=3D numa-test check-qtest-aarch64-y +=3D boot-serial-test check-qtest-aarch64-y +=3D migration-test @@ -302,7 +304,10 @@ tests/qtest/tpm-crb-swtpm-test$(EXESUF): tests/qtest/t= pm-crb-swtpm-test.o tests/ tests/qtest/tpm-crb-test$(EXESUF): tests/qtest/tpm-crb-test.o tests/qtest/= tpm-emu.o $(test-io-obj-y) tests/qtest/tpm-tis-swtpm-test$(EXESUF): tests/qtest/tpm-tis-swtpm-test.o = tests/qtest/tpm-emu.o \ tests/qtest/tpm-util.o tests/qtest/tpm-tests.o $(test-io-obj-y) +tests/qtest/tpm-tis-device-swtpm-test$(EXESUF): tests/qtest/tpm-tis-device= -swtpm-test.o tests/qtest/tpm-emu.o \ + tests/qtest/tpm-util.o tests/qtest/tpm-tests.o $(test-io-obj-y) tests/qtest/tpm-tis-test$(EXESUF): tests/qtest/tpm-tis-test.o tests/qtest/= tpm-tis-util.o tests/qtest/tpm-emu.o $(test-io-obj-y) +tests/qtest/tpm-tis-device-test$(EXESUF): tests/qtest/tpm-tis-device-test.= o tests/qtest/tpm-tis-util.o tests/qtest/tpm-emu.o $(test-io-obj-y) =20 # QTest rules =20 diff --git a/tests/qtest/tpm-tis-device-swtpm-test.c b/tests/qtest/tpm-tis-= device-swtpm-test.c new file mode 100644 index 0000000000..7b20035142 --- /dev/null +++ b/tests/qtest/tpm-tis-device-swtpm-test.c @@ -0,0 +1,76 @@ +/* + * QTest testcase for Sysbus TPM TIS talking to external swtpm and swtpm + * migration + * + * Copyright (c) 2018 IBM Corporation + * with parts borrowed from migration-test.c that is: + * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates + * + * 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 + +#include "libqtest.h" +#include "qemu/module.h" +#include "tpm-tests.h" +#include "hw/acpi/tpm.h" + +uint64_t tpm_tis_base_addr =3D 0xc000000; +#define MACHINE_OPTIONS "-machine virt,gic-version=3Dmax -accel tcg" + +typedef struct TestState { + char *src_tpm_path; + char *dst_tpm_path; + char *uri; +} TestState; + +static void tpm_tis_swtpm_test(const void *data) +{ + const TestState *ts =3D data; + + tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_tis_transfer, + "tpm-tis-device", MACHINE_OPTIONS); +} + +static void tpm_tis_swtpm_migration_test(const void *data) +{ + const TestState *ts =3D data; + + tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->= uri, + tpm_util_tis_transfer, "tpm-tis-device", + MACHINE_OPTIONS); +} + +int main(int argc, char **argv) +{ + int ret; + TestState ts =3D { 0 }; + + ts.src_tpm_path =3D g_dir_make_tmp("qemu-tpm-tis-device-swtpm-test.XXX= XXX", + NULL); + ts.dst_tpm_path =3D g_dir_make_tmp("qemu-tpm-tis-device-swtpm-test.XXX= XXX", + NULL); + ts.uri =3D g_strdup_printf("unix:%s/migsocket", ts.src_tpm_path); + + module_call_init(MODULE_INIT_QOM); + g_test_init(&argc, &argv, NULL); + + qtest_add_data_func("/tpm/tis-swtpm/test", &ts, tpm_tis_swtpm_test); + qtest_add_data_func("/tpm/tis-swtpm-migration/test", &ts, + tpm_tis_swtpm_migration_test); + ret =3D g_test_run(); + + g_rmdir(ts.dst_tpm_path); + g_free(ts.dst_tpm_path); + g_rmdir(ts.src_tpm_path); + g_free(ts.src_tpm_path); + g_free(ts.uri); + + return ret; +} diff --git a/tests/qtest/tpm-tis-device-test.c b/tests/qtest/tpm-tis-device= -test.c new file mode 100644 index 0000000000..63ed36440f --- /dev/null +++ b/tests/qtest/tpm-tis-device-test.c @@ -0,0 +1,87 @@ +/* + * QTest testcase for SYSBUS TPM TIS + * + * Copyright (c) 2018 Red Hat, Inc. + * Copyright (c) 2018 IBM Corporation + * + * Authors: + * Marc-Andr=C3=A9 Lureau + * 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 + +#include "io/channel-socket.h" +#include "libqtest-single.h" +#include "qemu/module.h" +#include "tpm-emu.h" +#include "tpm-util.h" +#include "tpm-tis-util.h" + +/* + * As the Sysbus tpm-tis-device is instantiated on the ARM virt + * platform bus and it is the only sysbus device dynamically + * instantiated, it gets plugged at its base address + */ +uint64_t tpm_tis_base_addr =3D 0xc000000; + +int main(int argc, char **argv) +{ + char *tmp_path =3D g_dir_make_tmp("qemu-tpm-tis-device-test.XXXXXX", N= ULL); + GThread *thread; + TestState test; + char *args; + int ret; + + module_call_init(MODULE_INIT_QOM); + g_test_init(&argc, &argv, NULL); + + test.addr =3D g_new0(SocketAddress, 1); + test.addr->type =3D SOCKET_ADDRESS_TYPE_UNIX; + test.addr->u.q_unix.path =3D g_build_filename(tmp_path, "sock", NULL); + g_mutex_init(&test.data_mutex); + g_cond_init(&test.data_cond); + test.data_cond_signal =3D false; + + thread =3D g_thread_new(NULL, tpm_emu_ctrl_thread, &test); + tpm_emu_test_wait_cond(&test); + + args =3D g_strdup_printf( + "-machine virt,gic-version=3Dmax -accel tcg " + "-chardev socket,id=3Dchr,path=3D%s " + "-tpmdev emulator,id=3Ddev,chardev=3Dchr " + "-device tpm-tis-device,tpmdev=3Ddev", + test.addr->u.q_unix.path); + qtest_start(args); + + qtest_add_data_func("/tpm-tis/test_check_localities", &test, + tpm_tis_test_check_localities); + + qtest_add_data_func("/tpm-tis/test_check_access_reg", &test, + tpm_tis_test_check_access_reg); + + qtest_add_data_func("/tpm-tis/test_check_access_reg_seize", &test, + tpm_tis_test_check_access_reg_seize); + + qtest_add_data_func("/tpm-tis/test_check_access_reg_release", &test, + tpm_tis_test_check_access_reg_release); + + qtest_add_data_func("/tpm-tis/test_check_transmit", &test, + tpm_tis_test_check_transmit); + + ret =3D g_test_run(); + + qtest_end(); + + g_thread_join(thread); + g_unlink(test.addr->u.q_unix.path); + qapi_free_SocketAddress(test.addr); + g_rmdir(tmp_path); + g_free(tmp_path); + g_free(args); + return ret; +} --=20 2.20.1