[SLOF] [PATCH v3 14/17] Add TPM firmware API call get-state

Stefan Berger stefanb at us.ibm.com
Tue Dec 1 09:01:57 AEDT 2015


From: Stefan Berger <stefanb at linux.vnet.ibm.com>

This patch adds support for the TPM firmware API call get-state.

Signed-off-by: Stefan Berger <stefanb at linux.vnet.ibm.com>
Reviewed-by: Nikunj A Dadhania <nikunj at linux.vnet.ibm.com>
---
 board-qemu/slof/vio-vtpm-cdriver.fs |  8 ++++++++
 board-qemu/slof/vtpm-sml.fs         | 10 ++++++++++
 lib/libtpm/tcgbios.c                | 12 ++++++++++++
 lib/libtpm/tcgbios.h                |  1 +
 lib/libtpm/tpm.code                 | 10 ++++++++++
 lib/libtpm/tpm.in                   |  1 +
 6 files changed, 42 insertions(+)

diff --git a/board-qemu/slof/vio-vtpm-cdriver.fs b/board-qemu/slof/vio-vtpm-cdriver.fs
index 6f4a0fe..1d3f4e9 100644
--- a/board-qemu/slof/vio-vtpm-cdriver.fs
+++ b/board-qemu/slof/vio-vtpm-cdriver.fs
@@ -99,6 +99,14 @@ false VALUE vtpm-debug?
 ;
 
 \ firmware API call
+: get-state ( -- state )
+    " get-state" vtpm-call-forward IF
+        \ vtpm-call-forward failed; return a value
+        0 \ invalid
+    THEN
+;
+
+\ firmware API call
 : hash-all ( data-ptr data-len hash-ptr -- )
     " hash-all" vtpm-call-forward IF
         \ vtpm-call-forward failed; clean up stack
diff --git a/board-qemu/slof/vtpm-sml.fs b/board-qemu/slof/vtpm-sml.fs
index 403c366..1c88884 100644
--- a/board-qemu/slof/vtpm-sml.fs
+++ b/board-qemu/slof/vtpm-sml.fs
@@ -52,6 +52,16 @@ log-base LOG-SIZE tpm-set-log-parameters
     move
 ;
 
+: get-state ( -- state )
+    vtpm-debug? IF
+        ." Call to get-state" cr
+    THEN
+    tpm-driver-get-state                           ( -- state )
+    vtpm-debug? IF
+        ." VTPM: Return value from tpm-driver-get-state: " dup . cr
+    THEN
+;
+
 : hash-all ( data-ptr data-len hash-ptr -- )
     vtpm-debug? IF
         ." Call to hash-all" cr
diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index 450db05..d084b96 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -196,6 +196,18 @@ bool tpm_is_working(void)
 	return has_working_tpm();
 }
 
+/*
+ * tpm_driver_get_state: Function for interfacing with the firmware API
+ */
+uint32_t tpm_driver_get_state(void)
+{
+	/* do not check for a working TPM here */
+	if (!tpm_state.tpm_found)
+		return VTPM_DRV_STATE_INVALID;
+
+	return spapr_vtpm_get_state();
+}
+
 static uint32_t transmit(struct tpm_req_header *req,
 			 uint8_t *respbuffer, uint32_t *respbufferlen,
 			 enum tpm_duration_type to_t)
diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h
index 5beaa53..25c7518 100644
--- a/lib/libtpm/tcgbios.h
+++ b/lib/libtpm/tcgbios.h
@@ -36,6 +36,7 @@ uint32_t tpm_add_event_separators(uint32_t start_pcr, uint32_t end_pcr);
 uint32_t tpm_process_opcode(uint8_t op, bool verbose);
 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);
 
 /* flags returned by tpm_get_state */
 #define TPM_STATE_ENABLED        1
diff --git a/lib/libtpm/tpm.code b/lib/libtpm/tpm.code
index b8ffa37..705052b 100644
--- a/lib/libtpm/tpm.code
+++ b/lib/libtpm/tpm.code
@@ -77,6 +77,16 @@ PRIM(tpm_X2d_hash_X2d_log_X2d_extend_X2d_event)
 	TOS.n = tpm_hash_log_extend_event(eventptr);
 MIRP
 
+/****************************************************/
+/* Firmware API                                     */
+/* SLOF:   tpm-driver-get-state ( -- state)         */
+/* LIBTPM: state = tpm_driver_get_state(void)       */
+/****************************************************/
+PRIM(tpm_X2d_driver_X2d_get_X2d_state)
+	PUSH;
+	TOS.n = tpm_driver_get_state();
+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 f0c92e2..52b4b4f 100644
--- a/lib/libtpm/tpm.in
+++ b/lib/libtpm/tpm.in
@@ -29,3 +29,4 @@ cod(tpm-is-working)
 cod(tpm-measure-scrtm)
 cod(tpm-get-maximum-cmd-size)
 cod(tpm-pass-through-to-tpm)
+cod(tpm-driver-get-state)
-- 
2.4.3



More information about the SLOF mailing list