hw/misc: implement ESP32-S3 RNG
This commit is contained in:
committed by
Ivan Grokhotkov
parent
c5a5b13d57
commit
015a0fbc4f
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* ESP32S3 Random Number Generator peripheral
|
||||
*
|
||||
* Copyright (c) 2019-2024 Espressif Systems (Shanghai) Co. Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/log.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/guest-random.h"
|
||||
#include "qapi/error.h"
|
||||
#include "hw/hw.h"
|
||||
#include "hw/sysbus.h"
|
||||
#include "hw/misc/esp32s3_rng.h"
|
||||
|
||||
|
||||
static uint64_t esp32s3_rng_read(void *opaque, hwaddr addr, unsigned int size)
|
||||
{
|
||||
uint32_t r = 0;
|
||||
qemu_guest_getrandom_nofail(&r, sizeof(r));
|
||||
return r;
|
||||
}
|
||||
|
||||
static const MemoryRegionOps esp32s3_rng_ops = {
|
||||
.read = esp32s3_rng_read,
|
||||
.endianness = DEVICE_LITTLE_ENDIAN,
|
||||
};
|
||||
|
||||
static void esp32s3_rng_init(Object *obj)
|
||||
{
|
||||
Esp32s3RngState *s = ESP32S3_RNG(obj);
|
||||
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
||||
|
||||
memory_region_init_io(&s->iomem, obj, &esp32s3_rng_ops, s,
|
||||
TYPE_ESP32S3_RNG, sizeof(uint32_t));
|
||||
sysbus_init_mmio(sbd, &s->iomem);
|
||||
}
|
||||
|
||||
|
||||
static const TypeInfo esp32s3_rng_info = {
|
||||
.name = TYPE_ESP32S3_RNG,
|
||||
.parent = TYPE_SYS_BUS_DEVICE,
|
||||
.instance_size = sizeof(Esp32s3RngState),
|
||||
.instance_init = esp32s3_rng_init,
|
||||
};
|
||||
|
||||
static void esp32s3_rng_register_types(void)
|
||||
{
|
||||
type_register_static(&esp32s3_rng_info);
|
||||
}
|
||||
|
||||
type_init(esp32s3_rng_register_types)
|
||||
@@ -165,6 +165,7 @@ system_ss.add(when: 'CONFIG_XTENSA_ESP32S3', if_true: files(
|
||||
'esp32s3_sha.c',
|
||||
'esp32c3_jtag.c',
|
||||
'esp32s3_rtc_cntl.c',
|
||||
'esp32s3_rng.c',
|
||||
))
|
||||
|
||||
if gcrypt.found()
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* ESP32-S3 random number generator
|
||||
*
|
||||
* Copyright (c) 2024 Espressif Systems (Shanghai) Co. Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hw/hw.h"
|
||||
#include "hw/sysbus.h"
|
||||
|
||||
#define DR_REG_WDEV_BASE 0x3ff75000
|
||||
|
||||
#define TYPE_ESP32S3_RNG "misc.esp32s3.rng"
|
||||
#define ESP32S3_RNG(obj) OBJECT_CHECK(Esp32s3RngState, (obj), TYPE_ESP32S3_RNG)
|
||||
|
||||
typedef struct Esp32s3RngState {
|
||||
SysBusDevice parent_obj;
|
||||
MemoryRegion iomem;
|
||||
} Esp32s3RngState;
|
||||
|
||||
#define ESP32S3_RNG_BASE 0x6003507C//(DR_REG_WDEV_BASE + 0x07c)
|
||||
|
||||
Reference in New Issue
Block a user