Skip to content

Commit acd9575

Browse files
shenkipm215
authored andcommitted
aspeed_scu: Implement RNG register
The ASPEED SoCs contain a single register that returns random data when read. This models that register so that guests can use it. The random number data register has a corresponding control register, however it returns data regardless of the state of the enabled bit, so the model follows this behaviour. When the qcrypto call fails we exit as the guest uses the random number device to feed it's entropy pool, which is used for cryptographic purposes. Reviewed-by: Cédric Le Goater <clg@kaod.org> Signed-off-by: Joel Stanley <joel@jms.id.au> Message-id: 20180613114836.9265-1-joel@jms.id.au Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
1 parent 29b8046 commit acd9575

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

hw/misc/aspeed_scu.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "qapi/visitor.h"
1717
#include "qemu/bitops.h"
1818
#include "qemu/log.h"
19+
#include "crypto/random.h"
1920
#include "trace.h"
2021

2122
#define TO_REG(offset) ((offset) >> 2)
@@ -154,6 +155,19 @@ static const uint32_t ast2500_a1_resets[ASPEED_SCU_NR_REGS] = {
154155
[BMC_DEV_ID] = 0x00002402U
155156
};
156157

158+
static uint32_t aspeed_scu_get_random(void)
159+
{
160+
Error *err = NULL;
161+
uint32_t num;
162+
163+
if (qcrypto_random_bytes((uint8_t *)&num, sizeof(num), &err)) {
164+
error_report_err(err);
165+
exit(1);
166+
}
167+
168+
return num;
169+
}
170+
157171
static uint64_t aspeed_scu_read(void *opaque, hwaddr offset, unsigned size)
158172
{
159173
AspeedSCUState *s = ASPEED_SCU(opaque);
@@ -167,6 +181,12 @@ static uint64_t aspeed_scu_read(void *opaque, hwaddr offset, unsigned size)
167181
}
168182

169183
switch (reg) {
184+
case RNG_DATA:
185+
/* On hardware, RNG_DATA works regardless of
186+
* the state of the enable bit in RNG_CTRL
187+
*/
188+
s->regs[RNG_DATA] = aspeed_scu_get_random();
189+
break;
170190
case WAKEUP_EN:
171191
qemu_log_mask(LOG_GUEST_ERROR,
172192
"%s: Read of write-only offset 0x%" HWADDR_PRIx "\n",

0 commit comments

Comments
 (0)