[SLOF] [PATCH 13/16] Add TPM firmware API call get-maximum-cmd-size

Nikunj A Dadhania nikunj at linux.vnet.ibm.com
Thu Nov 12 17:19:04 AEDT 2015


Stefan Berger <stefanb at linux.vnet.ibm.com> writes:
> @@ -1461,3 +1468,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 returnCode;
> +	struct tpm_res_getcap_buffersize buffersize;
> +	uint32_t result;
> +	struct tpm_driver *td = tpm_state.tpm_driver_to_use;
> +
> +	if (!has_working_tpm())
> +		return 0;
> +
> +	rc = build_and_send_cmd(TPM_ORD_GetCapability,
> +				GetCapability_BufferSize,
> +				sizeof(GetCapability_BufferSize),
> +				(uint8_t *)&buffersize, sizeof(buffersize),
> +				&returnCode, TPM_DURATION_TYPE_SHORT);
> +
> +	if (rc || returnCode)
> +		goto err_exit;
> +
> +	result = MIN(cpu_to_be32(buffersize.buffersize), td->getbuffersize());
> +
> +	return result;
> +
> +err_exit:
> +	dprintf("TPM malfunctioning (line %d).\n", __LINE__);
> +
> +	tpm_state.tpm_working = 0;

A helper to set this will be good for debugging. As sometimes it can be
difficult to trace where the TPM changed this to not working state.

> +
> +	return 0;
> +}
> diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h
> index 0dacba2..2aa7d20 100644
> --- a/lib/libtpm/tcgbios.h
> +++ b/lib/libtpm/tcgbios.h
> @@ -36,6 +36,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 bedc2f1..249e205 100644
> --- a/lib/libtpm/tcgbios_int.h
> +++ b/lib/libtpm/tcgbios_int.h
> @@ -177,6 +177,13 @@ struct tpm_res_getcap_durations {
>      uint32_t    durations[TPM_NUM_DURATIONS];
>  } __attribute__((packed));
>
> +struct tpm_res_getcap_buffersize {
> +    TPM_RSP_HEADER
> +    uint32_t    size;
> +    uint32_t    buffersize;
> +} __attribute__((packed));
> +
> +
>  struct tpm_res_sha1start {
>      TPM_RSP_HEADER
>      uint32_t    max_num_bytes;
> diff --git a/lib/libtpm/tpm.code b/lib/libtpm/tpm.code
> index acd3a10..5c3d4db 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 ad57631..0923fc0 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 31d3652..fca0058 100644
> --- a/slof/fs/tpm/tpm-static.fs
> +++ b/slof/fs/tpm/tpm-static.fs
> @@ -108,6 +108,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 )
> +        vtpm-debug? IF
> +            ." 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
> -- 
> 1.9.3



More information about the SLOF mailing list