From: Stefano Garzarella <sgarz...@redhat.com> SNP platform can provide a vTPM device emulated by SVSM.
The "tpm-svsm" device can be handled by the platform driver added by the previous commit in drivers/char/tpm/tpm_svsm.c Register the platform device only when SVSM is available and it supports vTPM commands as checked by snp_svsm_vtpm_probe(). Reviewed-by: Tom Lendacky <thomas.lenda...@amd.com> Reviewed-by: Jarkko Sakkinen <jar...@kernel.org> Signed-off-by: Stefano Garzarella <sgarz...@redhat.com> --- v7: - added Jarkko's R-b - call snp_svsm_vtpm_probe() before registering the device [Borislav] - s/device/devices in pr_info [Tom] - updated commit description v6: - added Tom's R-b v4: - explained better why we register it anyway in the commit message --- arch/x86/coco/sev/core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index 3bc5b47e7304..54272c9777cf 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -2688,6 +2688,11 @@ static struct platform_device sev_guest_device = { .id = -1, }; +static struct platform_device tpm_svsm_device = { + .name = "tpm-svsm", + .id = -1, +}; + static int __init snp_init_platform_device(void) { if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) @@ -2696,7 +2701,11 @@ static int __init snp_init_platform_device(void) if (platform_device_register(&sev_guest_device)) return -ENODEV; - pr_info("SNP guest platform device initialized.\n"); + if (snp_svsm_vtpm_probe() && + platform_device_register(&tpm_svsm_device)) + return -ENODEV; + + pr_info("SNP guest platform devices initialized.\n"); return 0; } device_initcall(snp_init_platform_device); -- 2.49.0