security/tpm: replace CONFIG(TPMx) checks with runtime check

This prepares the code for enabling both CONFIG_TPM1 and CONFIG_TPM2
during compilation, in which case actual TPM family in use can be
determined at runtime.

In some places both compile-time and runtime checks are necessary.
Yet in places like probe functions runtime state checks don't make sense
as runtime state is defined by results of probing.

Change-Id: Id9cc25aad8d1d7bfad12b7a92059b1b3641bbfa9
Ticket: https://ticket.coreboot.org/issues/433
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/69161
Reviewed-by: Jérémy Compostella <jeremy.compostella@intel.com>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Sergii Dmytruk
2022-11-02 00:50:03 +02:00
committed by Martin L Roth
parent 094a051732
commit 47e9e8cde1
13 changed files with 153 additions and 70 deletions

View File

@@ -25,7 +25,9 @@
#include <device/device.h>
#include <device/mmio.h>
#include <device/pci.h>
#include <drivers/crb/tpm.h>
#include <drivers/uart/pl011.h>
#include <security/tpm/tss.h>
#include <string.h>
#include <types.h>
#include <version.h>
@@ -205,7 +207,7 @@ static void *get_tcpa_log(u32 *size)
static void acpi_create_tcpa(acpi_header_t *header, void *unused)
{
if (!CONFIG(TPM1))
if (tlcl_get_family() != TPM_1)
return;
acpi_tcpa_t *tcpa = (acpi_tcpa_t *)header;
@@ -251,7 +253,7 @@ static void *get_tpm2_log(u32 *size)
static void acpi_create_tpm2(acpi_header_t *header, void *unused)
{
if (!CONFIG(TPM2))
if (tlcl_get_family() != TPM_2)
return;
acpi_tpm2_t *tpm2 = (acpi_tpm2_t *)header;
@@ -271,7 +273,7 @@ static void acpi_create_tpm2(acpi_header_t *header, void *unused)
/* Hard to detect for coreboot. Just set it to 0 */
tpm2->platform_class = 0;
if (CONFIG(CRB_TPM)) {
if (CONFIG(CRB_TPM) && tpm2_has_crb_active()) {
/* Must be set to 7 for CRB Support */
tpm2->control_area = CONFIG_CRB_TPM_BASE_ADDRESS + 0x40;
tpm2->start_method = 7;