From 959bbbafc3ba59e2aa00b83c88fa84a32d500def Mon Sep 17 00:00:00 2001
From: jiangfangjie <jiangfangjie@huawei.com>
Date: Wed, 5 Aug 2020 12:54:43 +0800
Subject: [PATCH] libvirt: support aarch64 vtpm with parameter tpm-tis-device

Signed-off-by: jiangfangjie <jiangfangjie@huawei.com>
---
 src/conf/domain_conf.c       | 1 +
 src/conf/domain_conf.h       | 1 +
 src/qemu/qemu_capabilities.c | 8 ++++++++
 src/qemu/qemu_capabilities.h | 3 +++
 src/qemu/qemu_domain.c       | 3 +++
 5 files changed, 16 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index cf93a59..6192c08 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1140,6 +1140,7 @@ VIR_ENUM_IMPL(virDomainTPMModel,
               "tpm-tis",
               "tpm-crb",
               "tpm-spapr",
+              "tpm-tis-device",
 );
 
 VIR_ENUM_IMPL(virDomainTPMBackend,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 33875d9..a40773a 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1274,6 +1274,7 @@ typedef enum {
     VIR_DOMAIN_TPM_MODEL_TIS,
     VIR_DOMAIN_TPM_MODEL_CRB,
     VIR_DOMAIN_TPM_MODEL_SPAPR,
+    VIR_DOMAIN_TPM_MODEL_TIS_DEVICE,
 
     VIR_DOMAIN_TPM_MODEL_LAST
 } virDomainTPMModel;
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 73a8856..18bf37b 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -568,6 +568,9 @@ VIR_ENUM_IMPL(virQEMUCaps,
               "blockdev-snapshot.allow-write-only-overlay",
               "blockdev-reopen",
               "storage.werror",
+	      
+              /* 360 */
+              "tpm-tis-device",
     );
 
 
@@ -1285,6 +1288,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = {
     { "rng-builtin", QEMU_CAPS_OBJECT_RNG_BUILTIN },
     { "tpm-spapr", QEMU_CAPS_DEVICE_TPM_SPAPR },
     { "vhost-user-fs-device", QEMU_CAPS_DEVICE_VHOST_USER_FS },
+    { "tpm-tis-device", QEMU_CAPS_DEVICE_TPM_TIS_DEVICE },
 };
 
 static struct virQEMUCapsStringFlags virQEMUCapsDevicePropsVirtioBalloon[] = {
@@ -3065,6 +3069,10 @@ const struct tpmTypeToCaps virQEMUCapsTPMModelsToCaps[] = {
         .type = VIR_DOMAIN_TPM_MODEL_SPAPR,
         .caps = QEMU_CAPS_DEVICE_TPM_SPAPR,
     },
+    {
+	.type = VIR_DOMAIN_TPM_MODEL_TIS_DEVICE,
+	.caps = QEMU_CAPS_DEVICE_TPM_TIS_DEVICE,
+    },
 };
 
 static int
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 51ec1a5..8e16fc0 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -549,6 +549,9 @@ typedef enum { /* virQEMUCapsFlags grouping marker for syntax-check */
     QEMU_CAPS_BLOCKDEV_SNAPSHOT_ALLOW_WRITE_ONLY, /* blockdev-snapshot has the 'allow-write-only-overlay' feature */
     QEMU_CAPS_BLOCKDEV_REOPEN, /* 'blockdev-reopen' qmp command is supported */
     QEMU_CAPS_STORAGE_WERROR, /* virtio-blk,scsi-hd.werror */
+    
+    /* 360 */
+    QEMU_CAPS_DEVICE_TPM_TIS_DEVICE, /* -device tpm-tis-device */
 
     QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index dd48b6f..b1a4647 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8118,6 +8118,9 @@ qemuDomainDeviceDefValidateTPM(virDomainTPMDef *tpm,
     case VIR_DOMAIN_TPM_MODEL_SPAPR:
         flag = QEMU_CAPS_DEVICE_TPM_SPAPR;
         break;
+    case VIR_DOMAIN_TPM_MODEL_TIS_DEVICE:
+        flag = QEMU_CAPS_DEVICE_TPM_TIS_DEVICE;
+        break;
     case VIR_DOMAIN_TPM_MODEL_LAST:
     default:
         virReportEnumRangeError(virDomainTPMModel, tpm->model);
-- 
2.23.0

