diff mbox series

[v4,06/33] tpm: Return value of actual log in sml-get-handover-size

Message ID 20191211202728.127996-7-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
With the functions for calculating the actual size of the log in place,
use them to determine the exact size of the log that the firmware
API call sml-get-handover-size now returns.

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

Patch

diff --git a/board-qemu/slof/vtpm-sml.fs b/board-qemu/slof/vtpm-sml.fs
index aa75f46..557aa62 100644
--- a/board-qemu/slof/vtpm-sml.fs
+++ b/board-qemu/slof/vtpm-sml.fs
@@ -35,6 +35,13 @@  log-base LOG-SIZE tpm-set-log-parameters
     LOG-SIZE
 ;
 
+: sml-get-handover-size ( -- size )
+    tpm-get-logsize
+    vtpm-debug? IF
+        ." Call to sml-get-handover-size; size = 0x" dup . cr
+    THEN
+;
+
 : sml-handover ( dest size -- )
     vtpm-debug? IF
         2dup
diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index 4a340d9..d655ae1 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -380,6 +380,15 @@  void tpm_set_log_parameters(void *addr, unsigned int size)
 	tpm_state.log_area_size = size;
 }
 
+uint32_t tpm_get_logsize(void)
+{
+	uint32_t logsize = tpm_state.log_area_next_entry - tpm_state.log_base;
+
+	dprintf("log size: %u\n", logsize);
+
+	return logsize;
+}
+
 /*
  * tpm_hash_all: Function for interfacing with the firmware API
  */
diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h
index c54eb91..592ae6d 100644
--- a/lib/libtpm/tcgbios.h
+++ b/lib/libtpm/tcgbios.h
@@ -22,6 +22,7 @@  uint32_t tpm_start(void);
 void tpm_finalize(void);
 uint32_t tpm_unassert_physical_presence(void);
 void tpm_set_log_parameters(void *address, unsigned int size);
+uint32_t tpm_get_logsize(void);
 uint32_t tpm_hash_log_extend_event(struct pcpes *pcpes);
 bool tpm_log_event(struct pcpes *pcpes);
 uint32_t tpm_hash_all(const void *data, uint32_t datalen, void *hashptr);
diff --git a/lib/libtpm/tpm.code b/lib/libtpm/tpm.code
index 80a50f8..eed9fbf 100644
--- a/lib/libtpm/tpm.code
+++ b/lib/libtpm/tpm.code
@@ -87,3 +87,13 @@  PRIM(tpm_X2d_hash_X2d_all)
 	void *dataptr = TOS.a;
 	TOS.n = tpm_hash_all(dataptr, datalen, hashptr);
 MIRP
+
+/************************************************/
+/* Get the size of the log                      */
+/* SLOF:   tpm-get-logsize         ( -- size )  */
+/* LIBTPM: logsize = tpm_get_logsize(void)      */
+/************************************************/
+PRIM(tpm_X2d_get_X2d_logsize)
+	PUSH;
+	TOS.n = tpm_get_logsize();
+MIRP
diff --git a/lib/libtpm/tpm.in b/lib/libtpm/tpm.in
index 0086f33..1e8ffc1 100644
--- a/lib/libtpm/tpm.in
+++ b/lib/libtpm/tpm.in
@@ -17,6 +17,7 @@  cod(tpm-start)
 cod(tpm-finalize)
 cod(tpm-unassert-physical-presence)
 cod(tpm-set-log-parameters)
+cod(tpm-get-logsize)
 cod(tpm-log-event)
 cod(tpm-hash-log-extend-event)
 cod(tpm-hash-all)