Extend QEMU with tpm-spapr support. Assign a device address to the
vTPM device model.
Signed-off-by: Stefan Berger <stefanb(a)linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau(a)redhat.com>
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
---
src/qemu/qemu_command.c | 15 ++++++++++-----
src/qemu/qemu_domain.c | 2 ++
src/qemu/qemu_domain_address.c | 9 +++++++++
3 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 81f5fa3416..0dbd78124b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9064,15 +9064,19 @@ qemuBuildDomainLoaderCommandLine(virCommandPtr cmd,
static char *
-qemuBuildTPMDevStr(const virDomainDef *def)
+qemuBuildTPMDevStr(const virDomainDef *def,
+ virQEMUCapsPtr qemuCaps)
{
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
- const virDomainTPMDef *tpm = def->tpm;
+ virDomainTPMDef *tpm = def->tpm;
const char *model = virDomainTPMModelTypeToString(tpm->model);
virBufferAsprintf(&buf, "%s,tpmdev=tpm-%s,id=%s",
model, tpm->info.alias, tpm->info.alias);
+ if (qemuBuildDeviceAddressStr(&buf, def, &tpm->info, qemuCaps) < 0)
+ return NULL;
+
return virBufferContentAndReset(&buf);
}
@@ -9162,7 +9166,8 @@ qemuBuildTPMBackendStr(const virDomainDef *def,
static int
qemuBuildTPMCommandLine(virCommandPtr cmd,
- const virDomainDef *def)
+ const virDomainDef *def,
+ virQEMUCapsPtr qemuCaps)
{
char *optstr;
g_autofree char *chardev = NULL;
@@ -9202,7 +9207,7 @@ qemuBuildTPMCommandLine(virCommandPtr cmd,
VIR_FREE(fdset);
}
- if (!(optstr = qemuBuildTPMDevStr(def)))
+ if (!(optstr = qemuBuildTPMDevStr(def, qemuCaps)))
return -1;
virCommandAddArgList(cmd, "-device", optstr, NULL);
@@ -9918,7 +9923,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
chardevStdioLogd) < 0)
return NULL;
- if (qemuBuildTPMCommandLine(cmd, def) < 0)
+ if (qemuBuildTPMCommandLine(cmd, def, qemuCaps) < 0)
return NULL;
if (qemuBuildInputCommandLine(cmd, def, qemuCaps) < 0)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 39513a726e..851f750bd7 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -7798,6 +7798,8 @@ qemuDomainDeviceDefValidateTPM(virDomainTPMDef *tpm,
flag = QEMU_CAPS_DEVICE_TPM_CRB;
break;
case VIR_DOMAIN_TPM_MODEL_SPAPR:
+ flag = QEMU_CAPS_DEVICE_TPM_SPAPR;
+ break;
case VIR_DOMAIN_TPM_MODEL_LAST:
default:
virReportEnumRangeError(virDomainTPMModel, tpm->model);
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 409d850a06..c7d8a3ac3b 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -35,6 +35,7 @@ VIR_LOG_INIT("qemu.qemu_domain_address");
#define VIO_ADDR_SCSI 0x2000ul
#define VIO_ADDR_SERIAL 0x30000000ul
#define VIO_ADDR_NVRAM 0x3000ul
+#define VIO_ADDR_TPM 0x4000ul
/**
@@ -267,6 +268,14 @@ qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def)
return -1;
}
+ if (def->tpm) {
+ if (qemuDomainIsPSeries(def))
+ def->tpm->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO;
+ if (qemuDomainAssignSpaprVIOAddress(def, &def->tpm->info,
+ VIO_ADDR_TPM) < 0)
+ return -1;
+ }
+
/* No other devices are currently supported on spapr-vio */
return 0;
--
2.17.1