diff mbox series

[v4,17/33] tpm: Set the driver in pseudo failure state after handover

Message ID 20191211202728.127996-18-stefanb@linux.vnet.ibm.com
State Superseded
Headers show
Series Add vTPM support to SLOF | expand

Commit Message

Stefan Berger Dec. 11, 2019, 8:27 p.m. UTC
Once sml-handover has been called, set the driver into
pseudo failure state.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
---
 board-qemu/slof/vtpm-sml.fs |  4 ++++
 lib/libtpm/tcgbios.c        | 12 ++++++++++++
 lib/libtpm/tcgbios.h        |  1 +
 lib/libtpm/tpm.code         | 10 ++++++++++
 lib/libtpm/tpm.in           |  1 +
 lib/libtpm/tpm_drivers.c    |  5 +++++
 lib/libtpm/tpm_drivers.h    |  1 +
 7 files changed, 34 insertions(+)
diff mbox series

Patch

diff --git a/board-qemu/slof/vtpm-sml.fs b/board-qemu/slof/vtpm-sml.fs
index 8d57c22..3752700 100644
--- a/board-qemu/slof/vtpm-sml.fs
+++ b/board-qemu/slof/vtpm-sml.fs
@@ -20,6 +20,8 @@  false VALUE    vtpm-debug?
 0     VALUE    log-base
 40000 CONSTANT LOG-SIZE   \ 256k per VTPM FW spec.
 
+e     CONSTANT VTPM_DRV_ERROR_SML_HANDED_OVER
+
 LOG-SIZE BUFFER: log-base
 
 \ create /ibm,vtpm
@@ -50,6 +52,8 @@  log-base LOG-SIZE tpm-set-log-parameters
     log-base        ( dest size src )
     -rot            ( src dest size )
     move
+
+    VTPM_DRV_ERROR_SML_HANDED_OVER tpm-driver-set-failure-reason
 ;
 
 : get-state ( -- state )
diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index 66b1cca..b7f86d4 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -914,3 +914,15 @@  uint32_t tpm_driver_get_failure_reason(void)
 
 	return spapr_vtpm_get_error();
 }
+
+/*
+ * tpm_driver_set_failure_reason: Function for interfacing with the firmware
+ *                                API
+ */
+void tpm_driver_set_failure_reason(uint32_t errcode)
+{
+	if (!tpm_state.tpm_found)
+		return;
+
+	spapr_vtpm_set_error(errcode);
+}
diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h
index 0ddd537..e37d075 100644
--- a/lib/libtpm/tcgbios.h
+++ b/lib/libtpm/tcgbios.h
@@ -38,6 +38,7 @@  uint32_t tpm_get_maximum_cmd_size(void);
 uint32_t tpm_pass_through_to_tpm(unsigned char *buf, uint32_t cmdlen);
 uint32_t tpm_driver_get_state(void);
 uint32_t tpm_driver_get_failure_reason(void);
+void tpm_driver_set_failure_reason(uint32_t errcode);
 
 /* flags returned by tpm_get_state */
 #define TPM_STATE_ENABLED        1
diff --git a/lib/libtpm/tpm.code b/lib/libtpm/tpm.code
index 3f2bd7f..235f368 100644
--- a/lib/libtpm/tpm.code
+++ b/lib/libtpm/tpm.code
@@ -97,6 +97,16 @@  PRIM(tpm_X2d_driver_X2d_get_X2d_failure_X2d_reason)
 	TOS.n = tpm_driver_get_failure_reason();
 MIRP
 
+/********************************************************/
+/* Firmware API                                         */
+/* SLOF:   tpm-driver-set-failure_reason ( errcode -- ) */
+/* LIBTPM: tpm_driver_set_failure_reason(errcode)       */
+/********************************************************/
+PRIM(tpm_X2d_driver_X2d_set_X2d_failure_X2d_reason)
+	int errcode = TOS.u; POP;
+	tpm_driver_set_failure_reason(errcode);
+MIRP
+
 /*****************************************************************/
 /* Firmware API                                                  */
 /* SLOF:   tpm-hash-all ( data-ptr data-len hash-ptr -- errcode) */
diff --git a/lib/libtpm/tpm.in b/lib/libtpm/tpm.in
index 88d8a14..3c3b745 100644
--- a/lib/libtpm/tpm.in
+++ b/lib/libtpm/tpm.in
@@ -31,3 +31,4 @@  cod(tpm-get-maximum-cmd-size)
 cod(tpm-pass-through-to-tpm)
 cod(tpm-driver-get-state)
 cod(tpm-driver-get-failure-reason)
+cod(tpm-driver-set-failure-reason)
diff --git a/lib/libtpm/tpm_drivers.c b/lib/libtpm/tpm_drivers.c
index 7b1c9c8..4384f7f 100644
--- a/lib/libtpm/tpm_drivers.c
+++ b/lib/libtpm/tpm_drivers.c
@@ -464,6 +464,11 @@  vtpm_drv_error spapr_vtpm_get_error(void)
 	return vtpm_drv_error_get();
 }
 
+void spapr_vtpm_set_error(vtpm_drv_error errcode)
+{
+	spapr_vtpm.driver_error = errcode;
+}
+
 /**** higher layer interface ****/
 
 bool spapr_is_vtpm_present(void)
diff --git a/lib/libtpm/tpm_drivers.h b/lib/libtpm/tpm_drivers.h
index 96bd32d..38976d0 100644
--- a/lib/libtpm/tpm_drivers.h
+++ b/lib/libtpm/tpm_drivers.h
@@ -80,6 +80,7 @@  void spapr_vtpm_set_durations(const uint32_t durations[TPM_NUM_DURATIONS]);
 uint32_t spapr_vtpm_get_buffersize(void);
 vtpm_drv_state spapr_vtpm_get_state(void);
 vtpm_drv_error spapr_vtpm_get_error(void);
+void spapr_vtpm_set_error(vtpm_drv_error errcode);
 
 struct tpm_req_header;
 int tpmhw_transmit(uint8_t locty, struct tpm_req_header *req,