g: implement support for hardware based TRNG

The TRNG operation is simple: once started it begins to fill up an
internal FIFO with random values. The consumer of these values might
have to wait if the next number is not ready yet.

BRANCH=none
BUG=chrome-os-partner:43025
TEST=with the rest of the patches in place TPM2 gets a stream of
     random numbers when required

Change-Id: I877452733377ec5b179fb6df8581af570b4f3668
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/306689
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
This commit is contained in:
Vadim Bendebury
2015-10-16 14:35:32 -07:00
committed by chrome-bot
parent 95fdecb7b4
commit 34a745efe8
2 changed files with 23 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ else
chip-y += uart.o
endif
chip-y+= pmu.o
chip-y+= trng.o
chip-$(CONFIG_SPS)+= sps.o
chip-$(CONFIG_HOSTCMD_SPS)+=sps_hc.o
chip-$(CONFIG_TPM_SPS)+=sps_tpm.o

22
chip/g/trng.c Normal file
View File

@@ -0,0 +1,22 @@
/* Copyright 2015 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "registers.h"
void init_trng(void)
{
GWRITE(TRNG, POWER_DOWN_B, 1);
GWRITE(TRNG, GO_EVENT, 1);
while (GREAD(TRNG, EMPTY))
;
GREAD(TRNG, READ_DATA);
}
uint32_t rand(void)
{
while (GREAD(TRNG, EMPTY))
;
return GREAD(TRNG, READ_DATA);
}