[SLOF] [PATCH v2 14/20] Add TPM firmware API call get-maximum-cmd-size
Stefan Berger
stefanb at us.ibm.com
Wed Nov 18 04:02:30 AEDT 2015
From: Stefan Berger <stefanb at linux.vnet.ibm.com>
This patch adds support for the firmware API call get-maximum-cmd-size.
Signed-off-by: Stefan Berger <stefanb at linux.vnet.ibm.com>
---
board-qemu/slof/vio-vtpm-cdriver.fs | 7 ++++++
board-qemu/slof/vtpm-sml.fs | 6 +++++
lib/libtpm/tcgbios.c | 44 +++++++++++++++++++++++++++++++++++++
lib/libtpm/tcgbios.h | 1 +
lib/libtpm/tcgbios_int.h | 9 ++++++++
lib/libtpm/tpm.code | 10 +++++++++
lib/libtpm/tpm.in | 1 +
slof/fs/tpm/tpm-static.fs | 12 ++++++++++
8 files changed, 90 insertions(+)
diff --git a/board-qemu/slof/vio-vtpm-cdriver.fs b/board-qemu/slof/vio-vtpm-cdriver.fs
index 28a5eab..fe84129 100644
--- a/board-qemu/slof/vio-vtpm-cdriver.fs
+++ b/board-qemu/slof/vio-vtpm-cdriver.fs
@@ -121,6 +121,13 @@ false VALUE vtpm-debug?
THEN
;
+\ firmware API call
+: get-maximum-cmd-size ( -- maximum-size )
+ " get-maximum-cmd-size" vtpm-call-forward IF
+ 0
+ THEN
+;
+
: open ( )
vtpm-debug? IF ." VTPM: vTPM open()" cr THEN
true
diff --git a/board-qemu/slof/vtpm-sml.fs b/board-qemu/slof/vtpm-sml.fs
index 6235549..eb3dd6c 100644
--- a/board-qemu/slof/vtpm-sml.fs
+++ b/board-qemu/slof/vtpm-sml.fs
@@ -73,6 +73,12 @@ log-base LOG-SIZE tpm-set-log-parameters
vtpm-hash-log-extend-event
;
+: get-maximum-cmd-size ( -- max-size )
+ vtpm-debug? IF
+ ." Call to get-maximum-cmd-size" cr
+ THEN
+ vtpm-get-maximum-cmd-size
+;
: open true ;
: close ;
diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index 8670c8b..9231d46 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -38,6 +38,8 @@
#endif
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+
static const uint8_t startup_st_clear[] = { 0x00, TPM_ST_CLEAR };
static const uint8_t startup_st_state[] = { 0x00, TPM_ST_STATE };
@@ -74,6 +76,11 @@ static const uint8_t get_capability_durations[] = {
0x00, 0x00, 0x01, 0x20
};
+static const uint8_t get_capability_buffer_size[] = {
+ 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04,
+ 0x00, 0x00, 0x01, 0x24
+};
+
static uint8_t evt_separator[] = {0xff,0xff,0xff,0xff};
struct tpm_state {
@@ -1510,3 +1517,40 @@ uint32_t tpm_measure_scrtm(void)
return rc;
}
+
+/*
+ * tpm_get_maximum_cmd_size: Function for interfacing with the firmware API
+ *
+ * This function returns the maximum size a TPM command (or response) may have.
+ */
+uint32_t tpm_get_maximum_cmd_size(void)
+{
+ uint32_t rc;
+ uint32_t return_code;
+ struct tpm_res_getcap_buffersize buffersize;
+ uint32_t result;
+ struct tpm_driver *td = tpm_state.tpm_drv;
+
+ if (!has_working_tpm())
+ return 0;
+
+ rc = build_and_send_cmd(TPM_ORD_GET_CAPABILITY,
+ get_capability_buffer_size,
+ sizeof(get_capability_buffer_size),
+ (uint8_t *)&buffersize, sizeof(buffersize),
+ &return_code, TPM_DURATION_TYPE_SHORT);
+
+ if (rc || return_code)
+ goto err_exit;
+
+ result = MIN(cpu_to_be32(buffersize.buffersize), td->getbuffersize());
+
+ return result;
+
+err_exit:
+ dprintf("TPM malfunctioning (line %d).\n", __LINE__);
+
+ tpm_set_failure();
+
+ return 0;
+}
diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h
index 4e0c560..9ea772d 100644
--- a/lib/libtpm/tcgbios.h
+++ b/lib/libtpm/tcgbios.h
@@ -41,6 +41,7 @@ uint32_t tpm_process_opcode(uint8_t op, bool verbose);
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);
+uint32_t tpm_get_maximum_cmd_size(void);
/* flags returned by tpm_get_state */
#define TPM_STATE_ENABLED 1
diff --git a/lib/libtpm/tcgbios_int.h b/lib/libtpm/tcgbios_int.h
index 5cbc09f..ee3169e 100644
--- a/lib/libtpm/tcgbios_int.h
+++ b/lib/libtpm/tcgbios_int.h
@@ -189,6 +189,15 @@ struct tpm_res_getcap_durations {
uint32_t durations[TPM_NUM_DURATIONS];
} __attribute__((packed));
+struct tpm_res_getcap_buffersize {
+ uint16_t tag;
+ uint32_t totlen;
+ uint32_t errcode;
+ uint32_t size;
+ uint32_t buffersize;
+} __attribute__((packed));
+
+
struct tpm_res_sha1start {
uint16_t tag;
uint32_t totlen;
diff --git a/lib/libtpm/tpm.code b/lib/libtpm/tpm.code
index a1311f8..b63b720 100644
--- a/lib/libtpm/tpm.code
+++ b/lib/libtpm/tpm.code
@@ -164,3 +164,13 @@ PRIM(tpm_X2d_hash_X2d_all)
void *dataptr = TOS.a;
TOS.n = tpm_hash_all(dataptr, datalen, hashptr);
MIRP
+
+/****************************************************/
+/* Firmware API */
+/* SLOF: tpm-get-maximum-cmd-size ( -- max-size) */
+/* LIBTPM: maxsize = tpm_get_maximum_cmd_size() */
+/****************************************************/
+PRIM(tpm_X2d_get_X2d_maximum_X2d_cmd_X2d_size)
+ PUSH;
+ TOS.n = tpm_get_maximum_cmd_size();
+MIRP
diff --git a/lib/libtpm/tpm.in b/lib/libtpm/tpm.in
index 7d8f3c7..e98c01e 100644
--- a/lib/libtpm/tpm.in
+++ b/lib/libtpm/tpm.in
@@ -27,3 +27,4 @@ cod(tpm-measure-scrtm)
cod(tpm-log-event)
cod(tpm-hash-log-extend-event)
cod(tpm-hash-all)
+cod(tpm-get-maximum-cmd-size)
diff --git a/slof/fs/tpm/tpm-static.fs b/slof/fs/tpm/tpm-static.fs
index a40117f..7e353a0 100644
--- a/slof/fs/tpm/tpm-static.fs
+++ b/slof/fs/tpm/tpm-static.fs
@@ -112,6 +112,18 @@ false VALUE vtpm-debug?
THEN
;
+\ firmware API function
+: vtpm-get-maximum-cmd-size ( -- max-size )
+ vtpm-available? IF
+ tpm-get-maximum-cmd-size ( -- max-size )
+ dup 0= IF \ Display if return value is 0
+ ." VTPM: Return value from tpm-get-maximum-cmd-size: " dup . cr
+ THEN
+ ELSE
+ 0
+ THEN
+;
+
1 CONSTANT TPM_ST_ENABLED
2 CONSTANT TPM_ST_ACTIVE
4 CONSTANT TPM_ST_OWNED
--
2.4.3
More information about the SLOF
mailing list