aboutsummaryrefslogtreecommitdiffstats
path: root/src/tcgbios.c
diff options
context:
space:
mode:
authorStefan Berger <stefanb@linux.vnet.ibm.com>2016-08-05 11:07:08 -0400
committerKevin O'Connor <kevin@koconnor.net>2016-08-10 15:01:03 -0400
commit74544faa47b7fefebfe3a65c1419d5e436986d1b (patch)
tree6bf10f8537d15749eae9b4aad3942c8ab969ad19 /src/tcgbios.c
parent996a8a9504f33e318750fbdfa3d0d529654e215a (diff)
downloadseabios-74544faa47b7fefebfe3a65c1419d5e436986d1b.tar.gz
tpm: Retrieve the PCR Bank configuration
Implement tpm20_get_capability and retrieve the PCR Bank configuration from the TPM using this function. Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Diffstat (limited to 'src/tcgbios.c')
-rw-r--r--src/tcgbios.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/tcgbios.c b/src/tcgbios.c
index 334d99b3..f9c6f74d 100644
--- a/src/tcgbios.c
+++ b/src/tcgbios.c
@@ -24,6 +24,7 @@
#include "tcgbios.h"// tpm_*, prototypes
#include "util.h" // printf, get_keystroke
#include "stacks.h" // wait_threads, reset
+#include "malloc.h" // malloc_high
/****************************************************************
* TPM 1.2 commands
@@ -76,6 +77,9 @@ static int TPM_has_physical_presence;
static TPMVersion TPM_version;
+static u32 tpm20_pcr_selection_size;
+static struct tpml_pcr_selection *tpm20_pcr_selection;
+
static struct tcpa_descriptor_rev2 *
find_tcpa_by_rsdp(struct rsdp_descriptor *rsdp)
{
@@ -366,6 +370,57 @@ tpm12_get_capability(u32 cap, u32 subcap, struct tpm_rsp_header *rsp, u32 rsize)
}
static int
+tpm20_getcapability(u32 capability, u32 property, u32 count,
+ struct tpm_rsp_header *rsp, u32 rsize)
+{
+ struct tpm2_req_getcapability trg = {
+ .hdr.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
+ .hdr.totlen = cpu_to_be32(sizeof(trg)),
+ .hdr.ordinal = cpu_to_be32(TPM2_CC_GetCapability),
+ .capability = cpu_to_be32(capability),
+ .property = cpu_to_be32(property),
+ .propertycount = cpu_to_be32(count),
+ };
+
+ u32 resp_size = rsize;
+ int ret = tpmhw_transmit(0, &trg.hdr, rsp, &resp_size,
+ TPM_DURATION_TYPE_SHORT);
+ ret = (ret ||
+ rsize < be32_to_cpu(rsp->totlen)) ? -1 : be32_to_cpu(rsp->errcode);
+
+ dprintf(DEBUG_tcg, "TCGBIOS: Return value from sending TPM2_CC_GetCapability = 0x%08x\n",
+ ret);
+
+ return ret;
+}
+
+static int
+tpm20_get_pcrbanks(void)
+{
+ u8 buffer[128];
+ struct tpm2_res_getcapability *trg =
+ (struct tpm2_res_getcapability *)&buffer;
+
+ int ret = tpm20_getcapability(TPM2_CAP_PCRS, 0, 8, &trg->hdr,
+ sizeof(buffer));
+ if (ret)
+ return ret;
+
+ u32 size = be32_to_cpu(trg->hdr.totlen) -
+ offsetof(struct tpm2_res_getcapability, data);
+ tpm20_pcr_selection = malloc_high(size);
+ if (tpm20_pcr_selection) {
+ memcpy(tpm20_pcr_selection, &trg->data, size);
+ tpm20_pcr_selection_size = size;
+ } else {
+ warn_noalloc();
+ ret = -1;
+ }
+
+ return ret;
+}
+
+static int
tpm12_determine_timeouts(void)
{
struct tpm_res_getcap_timeouts timeouts;
@@ -701,6 +756,10 @@ tpm20_startup(void)
if (ret)
goto err_exit;
+ ret = tpm20_get_pcrbanks();
+ if (ret)
+ goto err_exit;
+
return 0;
err_exit: