MAX78000FTHR Implementation
v5 cover MAX78000FTHR Implementation
v5:
Quoted 20 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ AES_KEY key; + if ((s->ctrl & TYPE) == 0) { + AES_set_encrypt_key(keydata, keylen, &key); + AES_set_decrypt_key(keydata, keylen, &s->internal_key); + AES_encrypt(s->data, s->result, &key);Here we call
AES_set_encrypt_key()andAES_set_decrypt_key()before callingAES_encrypt()...Review
Quoted 5 lines
(quoted diff) +5
-0+ s->result_index = 16; + } else if ((s->ctrl & TYPE) == 1 << 8) { + AES_set_decrypt_key(keydata, keylen, &key); + AES_set_decrypt_key(keydata, keylen, &s->internal_key); + AES_decrypt(s->data, s->result, &key);...here we call
AES_set_decrypt_key()twice before callingAES_decrypt(). This looks a bit odd: should we either
(a) call bothAES_set_decrypt_key()andAES_set_encrypt_key()in each half of theif(), or (b) callAES_set_encyrypt_key()twice in theAES_encrypt()code path ?
Quoted 6 lines
(Coverity is sometimes wrong, as it's only using a heuristic here, so the other option is "the code as written is correct", but in that case a comment might be helpful for human readers.)
thanks
-- PMM
The AES engine stores an internal key which it uses only for decryption when in the last TYPE. This results in the odd-looking call pairs. I've added the requested comment.
- Jackson
v4:
Spacing and style standard changes in GCR SOC, TRNG SOC, and AES SOC
v3:
Addresses a few more comments by Peter. Really appreciate the review, thank you.
ICC SOC:
Gave each device a unique name
UART SOC:
Removed references to DeviceState and gave each device a unique name
GCR SOC:
Set object property links statically, instead of by reference to device id
TRNG:
Added comments explaining interrupt generation logic. See further rationale under v2. It's certainly possible I'm missing something here, but I think what I have is correct.
TRNG SOC:
Removed reference to DeviceState
AES:
Simplified integer load & stores, added assertion before writing to memory_region_init_ram
AES SOC:
Removed reference to DeviceState
v2:
Addresses comments by Peter.
For each device:
- Switched soc to use sysbus_realize
- Standardized switch case bracing, indentation, and error case
- Added valid min and max access size
- Changed endianness to DEVICE_LITTLE_ENDIAN
- Added reset method, if not already implemented
- Added migration support
- Split soc integration into separate commit
Machine Implementation:
Added user guide URL
Removed refclk. According to https://developer.arm.com/documentation/ddi0403/d/System-Level-Architecture/System-Address-Map/The-system-timer--SysTick/SysTick-Control-and-Status-Register--SYST-CSR the systick clock can be either the processor clock or an implementation defined external reference clock. As far as I can tell based on the user guide, the MAX78000 does not define an external reference clock. I have not confirmed this in hardware. Changed IRQ count to 120 and noted that the user guide is unclear on this number
Fixed unimplemented device lengths and names
ICC:
Removed ICC_Invalidate
Added number to device names
UART:
Fixed interrupts, allowing async UART
Added number to device names
GCR:
Changed string-based device search to prop links for device reset Changed cpu_physical_memory_write to address_space_write
TRNG:
Changed source of randomness to qemu_guest_getrandom_nofail Did not change interrupt generation
Quoted 7 lines
Your interrupt generation code in this device doesn't look
right: the interrupt is supposed to be generated when each new random number is ready, so in our "generation takes zero time" model a read from DATA should provoke a new interrupt immediately (assuming the interrupt is enabled):
you need to simulate the ready status bit going low and then high again.
I believe the interrupt generation is fine in this case; by latching it high so long as the interrupt is enabled, the interrupt handler gets called repeatedly until it receives the desired amount of data and disables the interrupt. I've tested this and it works with the maxim sdk's implementation of asynchronous trng.
Quoted 3 lines
See also my comments on an earlier patch about the usual logic being to have an update function which does "set interrupt to (condition && enabled)".
In this case there is only one possible interrupt condition (is there random data ready), which is always true when enabled. As such I don't think a handler function is really necessary
v1:
This patch series implements basic support for the MAX78000FTHR machine
https://github.com/JacksonDonaldson/max78000Test
Contains instructions for building a test program against the MAX78000FTHR as well as results of the test suite run on QEMU and hardware.
Jackson Donaldson (11):
MAX78000: Add MAX78000FTHR Machine
MAX78000: ICC Implementation
MAX78000: Add ICC to SOC
MAX78000: UART Implementation
MAX78000: Add UART to SOC
MAX78000: GCR Implementation
MAX78000: Add GCR to SOC
MAX78000: TRNG Implementation
MAX78000: Add TRNG to SOC
MAX78000: AES implementation
MAX78000: Add AES to SOC
hw/arm/Kconfig | 15 ++ hw/arm/max78000_soc.c | 232 +++++++++++++++++++++ hw/arm/max78000fthr.c | 50 +++++ hw/arm/meson.build | 2 + hw/char/Kconfig | 3 + hw/char/max78000_uart.c | 285 ++++++++++++++++++++++++++ hw/char/meson.build | 1 + hw/misc/Kconfig | 12 ++ hw/misc/max78000_aes.c | 229 +++++++++++++++++++++ hw/misc/max78000_gcr.c | 351 ++++++++++++++++++++++++++++++++ hw/misc/max78000_icc.c | 120 +++++++++++ hw/misc/max78000_trng.c | 139 +++++++++++++ hw/misc/meson.build | 4 + include/hw/arm/max78000_soc.h | 50 +++++ include/hw/char/max78000_uart.h | 78 +++++++ include/hw/misc/max78000_aes.h | 68 +++++++ include/hw/misc/max78000_gcr.h | 131 ++++++++++++ include/hw/misc/max78000_icc.h | 33 +++ include/hw/misc/max78000_trng.h | 35 ++++ 19 files changed, 1838 insertions(+) create mode 100644 hw/arm/max78000_soc.c create mode 100644 hw/arm/max78000fthr.c create mode 100644 hw/char/max78000_uart.c create mode 100644 hw/misc/max78000_aes.c create mode 100644 hw/misc/max78000_gcr.c create mode 100644 hw/misc/max78000_icc.c create mode 100644 hw/misc/max78000_trng.c create mode 100644 include/hw/arm/max78000_soc.h create mode 100644 include/hw/char/max78000_uart.h create mode 100644 include/hw/misc/max78000_aes.h create mode 100644 include/hw/misc/max78000_gcr.h create mode 100644 include/hw/misc/max78000_icc.h create mode 100644 include/hw/misc/max78000_trng.h
Signature · 1 line
2.34.1
PATCH v5 1/11 MAX78000: Add MAX78000FTHR Machine
This patch adds support for the MAX78000FTHR machine.
The MAX78000FTHR contains a MAX78000 and a RISC-V core. This patch implements only the MAX78000, which is Cortex-M4 based. Details can be found at:
https://www.analog.com/media/en/technical-documentation/user-guides/max78000-user-guide.pdf
--- hw/arm/Kconfig | 10 ++ hw/arm/max78000_soc.c | 172 ++++++++++++++++++++++++++++++++++ hw/arm/max78000fthr.c | 50 ++++++++++ hw/arm/meson.build | 2 + include/hw/arm/max78000_soc.h | 35 +++++++ 5 files changed, 269 insertions(+) create mode 100644 hw/arm/max78000_soc.c create mode 100644 hw/arm/max78000fthr.c create mode 100644 include/hw/arm/max78000_soc.h
hw/arm/Kconfig +10 -0
@@ -95,6 +95,12 @@ config INTEGRATOR select PL181 # display select SMC91C111 +config MAX78000FTHR + bool + default y + depends on TCG && ARM + select MAX78000_SOC + config MPS3R bool default y
@@ -357,6 +363,10 @@ config ALLWINNER_R40 select USB_EHCI_SYSBUS select SD +config MAX78000_SOC + bool + select ARM_V7M + config RASPI bool default y
hw/arm/max78000_soc.c new file +172 -0
172 lines not on this page · raw message
hw/arm/max78000fthr.c new file +50 -0
50 lines not on this page · raw message
hw/arm/meson.build +2 -0
@@ -27,6 +27,7 @@ arm_common_ss.add(when: 'CONFIG_OMAP', if_true: files('omap1.c')) arm_common_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true: files('allwinner-a10.c', 'cubieboard.c')) arm_common_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-h3.c', 'orangepi.c')) arm_common_ss.add(when: 'CONFIG_ALLWINNER_R40', if_true: files('allwinner-r40.c', 'bananapi_m2u.c')) +arm_common_ss.add(when: 'CONFIG_MAX78000_SOC', if_true: files('max78000_soc.c')) arm_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2836.c', 'raspi.c')) arm_common_ss.add(when: ['CONFIG_RASPI', 'TARGET_AARCH64'], if_true: files('bcm2838.c', 'raspi4b.c')) arm_common_ss.add(when: 'CONFIG_STM32F100_SOC', if_true: files('stm32f100_soc.c'))
@@ -71,6 +72,7 @@ arm_ss.add(when: 'CONFIG_XEN', if_true: files( arm_common_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmu-common.c')) arm_common_ss.add(when: 'CONFIG_COLLIE', if_true: files('collie.c')) arm_common_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4_boards.c')) +arm_common_ss.add(when: 'CONFIG_MAX78000FTHR', if_true: files('max78000fthr.c')) arm_common_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c')) arm_common_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_peripherals.c')) arm_common_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2838_peripherals.c'))
include/hw/arm/max78000_soc.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* MAX78000 SOC +* +* Copyright (c) 2025 Jackson Donaldson <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_ARM_MAX78000_SOC_H +#define HW_ARM_MAX78000_SOC_H + +#include "hw/or-irq.h" +#include "hw/arm/armv7m.h" +#include "qom/object.h" + +#define TYPE_MAX78000_SOC "max78000-soc" +OBJECT_DECLARE_SIMPLE_TYPE(MAX78000State, MAX78000_SOC) + +#define FLASH_BASE_ADDRESS 0x10000000 +#define FLASH_SIZE (512 * 1024) +#define SRAM_BASE_ADDRESS 0x20000000 +#define SRAM_SIZE (128 * 1024) + +struct MAX78000State { +SysBusDevice parent_obj; + +ARMv7MState armv7m; + +MemoryRegion sram; +MemoryRegion flash; + +Clock *sysclk; +}; + +#endif
Signature · 1 line
2.34.1
PATCH v5 2/11 MAX78000: ICC Implementation
In reply to Jackson DonaldsonThis commit implements the Instruction Cache Controller for the MAX78000
--- hw/arm/Kconfig | 1 + hw/misc/Kconfig | 3 + hw/misc/max78000_icc.c | 120 +++++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + include/hw/misc/max78000_icc.h | 33 +++++++++ 5 files changed, 158 insertions(+) create mode 100644 hw/misc/max78000_icc.c create mode 100644 include/hw/misc/max78000_icc.h
hw/arm/Kconfig +1 -0
@@ -366,6 +366,7 @@ config ALLWINNER_R40 config MAX78000_SOC bool select ARM_V7M + select MAX78000_ICC config RASPI bool
hw/misc/Kconfig +3 -0
@@ -47,6 +47,9 @@ config A9SCU config ARM11SCU bool +config MAX78000_ICC + bool + config MOS6522 bool
hw/misc/max78000_icc.c new file +120 -0
120 lines not on this page · raw message
hw/misc/meson.build +1 -0
@@ -70,6 +70,7 @@ system_ss.add(when: 'CONFIG_IMX', if_true: files( 'imx_ccm.c', 'imx_rngc.c', )) +system_ss.add(when: 'CONFIG_MAX78000_ICC', if_true: files('max78000_icc.c')) system_ss.add(when: 'CONFIG_NPCM7XX', if_true: files( 'npcm_clk.c', 'npcm_gcr.c',
include/hw/misc/max78000_icc.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* MAX78000 Instruction Cache +* +* Copyright (c) 2025 Jackson Donaldson <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_MAX78000_ICC_H +#define HW_MAX78000_ICC_H + +#include "hw/sysbus.h" +#include "qom/object.h" + +#define TYPE_MAX78000_ICC "max78000-icc" +OBJECT_DECLARE_SIMPLE_TYPE(Max78000IccState, MAX78000_ICC) + +#define ICC_INFO 0x0 +#define ICC_SZ 0x4 +#define ICC_CTRL 0x100 +#define ICC_INVALIDATE 0x700 + +struct Max78000IccState { +SysBusDevice parent_obj; + +MemoryRegion mmio; + +uint32_t info; +uint32_t sz; +uint32_t ctrl; +}; + +#endif
Signature · 1 line
2.34.1
PATCH v5 3/11 MAX78000: Add ICC to SOC
In reply to Jackson DonaldsonThis commit adds the instruction cache controller
to max78000_soc
--- hw/arm/max78000_soc.c | 20 ++++++++++++++++---- include/hw/arm/max78000_soc.h | 6 ++++++ 2 files changed, 22 insertions(+), 4 deletions(-)
hw/arm/max78000_soc.c +16 -4
@@ -17,12 +17,20 @@#include "hw/qdev-clock.h" #include "hw/misc/unimp.h" +static const uint32_t max78000_icc_addr[] = {0x4002a000 ,0x4002a800 }; +static void max78000_soc_initfn (Object *obj) {MAX78000State *s =MAX78000_SOC (obj); +int i;object_initialize_child (obj,"armv7m" , &s->armv7m,TYPE_ARMV7M ); +for (i =0 ; i <MAX78000_NUM_ICC ; i++) { + g_autofree char *name = g_strdup_printf("icc%d", i); +object_initialize_child (obj, name, &s->icc[i],TYPE_MAX78000_ICC ); + } + s->sysclk =qdev_init_clock_in (DEVICE (s),"sysclk" ,NULL ,NULL ,0 ); }
@@ -30,8 +38,9 @@ static void max78000_soc_realize(DeviceState *dev_soc, Error **errp) {MAX78000State *s =MAX78000_SOC (dev_soc);MemoryRegion *system_memory =get_system_memory (); -DeviceState *armv7m; +DeviceState *dev, *armv7m;Error *err =NULL ; +int i;if (!clock_has_source (s->sysclk)) {error_setg (errp,"sysclk clock must be wired up by the board code" );
@@ -74,6 +83,12 @@ static void max78000_soc_realize(DeviceState *dev_soc, Error **errp)return ; } +for (i =0 ; i <MAX78000_NUM_ICC ; i++) { + dev =DEVICE (&(s->icc[i])); +sysbus_realize (SYS_BUS_DEVICE (dev), errp); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , max78000_icc_addr[i]); + } +create_unimplemented_device ("globalControl" ,0x40000000 ,0x400 );create_unimplemented_device ("systemInterface" ,0x40000400 ,0x400 );create_unimplemented_device ("functionControl" ,0x40000800 ,0x400 );
@@ -107,9 +122,6 @@ static void max78000_soc_realize(DeviceState *dev_soc, Error **errp)create_unimplemented_device ("standardDMA" ,0x40028000 ,0x1000 );create_unimplemented_device ("flashController0" ,0x40029000 ,0x400 ); -create_unimplemented_device ("icc0" ,0x4002a000 ,0x800 ); -create_unimplemented_device ("icc1" ,0x4002a800 ,0x800 ); -create_unimplemented_device ("adc" ,0x40034000 ,0x1000 );create_unimplemented_device ("pulseTrainEngine" ,0x4003c000 ,0xa0 );create_unimplemented_device ("oneWireMaster" ,0x4003d000 ,0x1000 );
include/hw/arm/max78000_soc.h +6 -0
@@ -11,6 +11,7 @@#include "hw/or-irq.h" #include "hw/arm/armv7m.h" +#include "hw/misc/max78000_icc.h" #include "qom/object.h" #define TYPE_MAX78000_SOC "max78000-soc"
@@ -21,6 +22,9 @@ OBJECT_DECLARE_SIMPLE_TYPE(MAX78000State, MAX78000_SOC)#define SRAM_BASE_ADDRESS 0x20000000#define SRAM_SIZE (128 * 1024) +/* The MAX78k has 2 instruction caches; only icc0 matters, icc1 is for RISC */ +#define MAX78000_NUM_ICC 2 +struct MAX78000State {SysBusDevice parent_obj;
@@ -29,6 +33,8 @@ struct MAX78000State {MemoryRegion sram;MemoryRegion flash; +Max78000IccState icc[MAX78000_NUM_ICC ]; +Clock *sysclk; };
Signature · 1 line
2.34.1
PATCH v5 4/11 MAX78000: UART Implementation
In reply to Jackson DonaldsonThis commit implements UART support for the MAX78000
--- hw/arm/Kconfig | 1 + hw/char/Kconfig | 3 + hw/char/max78000_uart.c | 285 ++++++++++++++++++++++++++++++++ hw/char/meson.build | 1 + include/hw/char/max78000_uart.h | 78 +++++++++ 5 files changed, 368 insertions(+) create mode 100644 hw/char/max78000_uart.c create mode 100644 include/hw/char/max78000_uart.h
hw/arm/Kconfig +1 -0
@@ -367,6 +367,7 @@ config MAX78000_SOC bool select ARM_V7M select MAX78000_ICC + select MAX78000_UART config RASPI bool
hw/char/Kconfig +3 -0
@@ -48,6 +48,9 @@ config VIRTIO_SERIAL default y depends on VIRTIO +config MAX78000_UART + bool + config STM32F2XX_USART bool
hw/char/max78000_uart.c new file +285 -0
285 lines not on this page · raw message
hw/char/meson.build +1 -0
@@ -26,6 +26,7 @@ system_ss.add(when: 'CONFIG_AVR_USART', if_true: files('avr_usart.c')) system_ss.add(when: 'CONFIG_COLDFIRE', if_true: files('mcf_uart.c')) system_ss.add(when: 'CONFIG_DIGIC', if_true: files('digic-uart.c')) system_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4210_uart.c')) +system_ss.add(when: 'CONFIG_MAX78000_UART', if_true: files('max78000_uart.c')) system_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_uart.c')) system_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_aux.c')) system_ss.add(when: 'CONFIG_RENESAS_SCI', if_true: files('renesas_sci.c'))
include/hw/char/max78000_uart.h new file +78 -0
78 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v5 5/11 MAX78000: Add UART to SOC
In reply to Jackson DonaldsonThis commit adds UART to max78000_soc
--- hw/arm/max78000_soc.c | 28 ++++++++++++++++++++++++---- include/hw/arm/max78000_soc.h | 3 +++ 2 files changed, 27 insertions(+), 4 deletions(-)
hw/arm/max78000_soc.c +24 -4
@@ -18,6 +18,10 @@#include "hw/misc/unimp.h" static const uint32_t max78000_icc_addr[] = {0x4002a000 ,0x4002a800 }; +static const uint32_t max78000_uart_addr[] = {0x40042000 ,0x40043000 , +0x40044000 }; + +static const int max78000_uart_irq[] = {14 ,15 ,34 };static void max78000_soc_initfn (Object *obj) {
@@ -31,6 +35,12 @@ static void max78000_soc_initfn(Object *obj)object_initialize_child (obj, name, &s->icc[i],TYPE_MAX78000_ICC ); } +for (i =0 ; i <MAX78000_NUM_UART ; i++) { + g_autofree char *name = g_strdup_printf("uart%d", i); +object_initialize_child (obj, name, &s->uart[i], +TYPE_MAX78000_UART ); + } + s->sysclk =qdev_init_clock_in (DEVICE (s),"sysclk" ,NULL ,NULL ,0 ); }
@@ -39,6 +49,7 @@ static void max78000_soc_realize(DeviceState *dev_soc, Error **errp)MAX78000State *s =MAX78000_SOC (dev_soc);MemoryRegion *system_memory =get_system_memory ();DeviceState *dev, *armv7m; +SysBusDevice *busdev;Error *err =NULL ;int i;
@@ -89,6 +100,19 @@ static void max78000_soc_realize(DeviceState *dev_soc, Error **errp)sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , max78000_icc_addr[i]); } +for (i =0 ; i <MAX78000_NUM_UART ; i++) { + dev =DEVICE (&(s->uart[i])); +qdev_prop_set_chr (dev,"chardev" ,serial_hd (i)); +if (!sysbus_realize (SYS_BUS_DEVICE (&s->uart[i]), errp)) { +return ; + } + + busdev =SYS_BUS_DEVICE (dev); +sysbus_mmio_map (busdev,0 , max78000_uart_addr[i]); +sysbus_connect_irq (busdev,0 ,qdev_get_gpio_in (armv7m, + max78000_uart_irq[i])); + } +create_unimplemented_device ("globalControl" ,0x40000000 ,0x400 );create_unimplemented_device ("systemInterface" ,0x40000400 ,0x400 );create_unimplemented_device ("functionControl" ,0x40000800 ,0x400 );
@@ -127,10 +151,6 @@ static void max78000_soc_realize(DeviceState *dev_soc, Error **errp)create_unimplemented_device ("oneWireMaster" ,0x4003d000 ,0x1000 );create_unimplemented_device ("semaphore" ,0x4003e000 ,0x1000 ); -create_unimplemented_device ("uart0" ,0x40042000 ,0x1000 ); -create_unimplemented_device ("uart1" ,0x40043000 ,0x1000 ); -create_unimplemented_device ("uart2" ,0x40044000 ,0x1000 ); -create_unimplemented_device ("spi1" ,0x40046000 ,0x2000 );create_unimplemented_device ("trng" ,0x4004d000 ,0x1000 );create_unimplemented_device ("i2s" ,0x40060000 ,0x1000 );
include/hw/arm/max78000_soc.h +3 -0
@@ -12,6 +12,7 @@#include "hw/or-irq.h" #include "hw/arm/armv7m.h" #include "hw/misc/max78000_icc.h" +#include "hw/char/max78000_uart.h" #include "qom/object.h" #define TYPE_MAX78000_SOC "max78000-soc"
@@ -24,6 +25,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(MAX78000State, MAX78000_SOC)/* The MAX78k has 2 instruction caches; only icc0 matters, icc1 is for RISC */ #define MAX78000_NUM_ICC 2 +#define MAX78000_NUM_UART 3struct MAX78000State {SysBusDevice parent_obj;
@@ -34,6 +36,7 @@ struct MAX78000State {MemoryRegion flash;Max78000IccState icc[MAX78000_NUM_ICC ]; +Max78000UartState uart[MAX78000_NUM_UART ];Clock *sysclk; };
Signature · 1 line
2.34.1
PATCH v5 6/11 MAX78000: GCR Implementation
In reply to Jackson DonaldsonThis commit implements the Global Control Register for the MAX78000
--- hw/arm/Kconfig | 1 + hw/misc/Kconfig | 3 + hw/misc/max78000_gcr.c | 339 +++++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + include/hw/misc/max78000_gcr.h | 129 +++++++++++++ 5 files changed, 473 insertions(+) create mode 100644 hw/misc/max78000_gcr.c create mode 100644 include/hw/misc/max78000_gcr.h
hw/arm/Kconfig +1 -0
@@ -368,6 +368,7 @@ config MAX78000_SOC select ARM_V7M select MAX78000_ICC select MAX78000_UART + select MAX78000_GCR config RASPI bool
hw/misc/Kconfig +3 -0
@@ -47,6 +47,9 @@ config A9SCU config ARM11SCU bool +config MAX78000_GCR + bool + config MAX78000_ICC bool
hw/misc/max78000_gcr.c new file +339 -0
339 lines not on this page · raw message
hw/misc/meson.build +1 -0
@@ -70,6 +70,7 @@ system_ss.add(when: 'CONFIG_IMX', if_true: files( 'imx_ccm.c', 'imx_rngc.c', )) +system_ss.add(when: 'CONFIG_MAX78000_GCR', if_true: files('max78000_gcr.c')) system_ss.add(when: 'CONFIG_MAX78000_ICC', if_true: files('max78000_icc.c')) system_ss.add(when: 'CONFIG_NPCM7XX', if_true: files( 'npcm_clk.c',
include/hw/misc/max78000_gcr.h new file +129 -0
129 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v5 7/11 MAX78000: Add GCR to SOC
In reply to Jackson DonaldsonThis commit adds the Global Control Register tomax78000_soc
--- hw/arm/max78000_soc.c | 18 ++++++++++++++++-- include/hw/arm/max78000_soc.h | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-)
hw/arm/max78000_soc.c +16 -2
@@ -30,6 +30,8 @@ static void max78000_soc_initfn(Object *obj)object_initialize_child (obj,"armv7m" , &s->armv7m,TYPE_ARMV7M ); +object_initialize_child (obj,"gcr" , &s->gcr,TYPE_MAX78000_GCR ); +for (i =0 ; i <MAX78000_NUM_ICC ; i++) { g_autofree char *name = g_strdup_printf("icc%d", i);object_initialize_child (obj, name, &s->icc[i],TYPE_MAX78000_ICC );
@@ -48,7 +50,7 @@ static void max78000_soc_realize(DeviceState *dev_soc, Error **errp) {MAX78000State *s =MAX78000_SOC (dev_soc);MemoryRegion *system_memory =get_system_memory (); -DeviceState *dev, *armv7m; +DeviceState *dev, *gcrdev, *armv7m;SysBusDevice *busdev;Error *err =NULL ;int i;
@@ -69,6 +71,11 @@ static void max78000_soc_realize(DeviceState *dev_soc, Error **errp)memory_region_init_ram (&s->sram,NULL ,"MAX78000.sram" ,SRAM_SIZE , &err); + + gcrdev =DEVICE (&s->gcr); +object_property_set_link (OBJECT (gcrdev),"sram" ,OBJECT (&s->sram), + &err); +if (err !=NULL ) {error_propagate (errp, err);return ;
@@ -101,19 +108,26 @@ static void max78000_soc_realize(DeviceState *dev_soc, Error **errp) }for (i =0 ; i <MAX78000_NUM_UART ; i++) { + g_autofree char *link = g_strdup_printf("uart%d", i); dev =DEVICE (&(s->uart[i]));qdev_prop_set_chr (dev,"chardev" ,serial_hd (i));if (!sysbus_realize (SYS_BUS_DEVICE (&s->uart[i]), errp)) {return ; } +object_property_set_link (OBJECT (gcrdev), link,OBJECT (dev), + &err); + busdev =SYS_BUS_DEVICE (dev);sysbus_mmio_map (busdev,0 , max78000_uart_addr[i]);sysbus_connect_irq (busdev,0 ,qdev_get_gpio_in (armv7m, max78000_uart_irq[i])); } -create_unimplemented_device ("globalControl" ,0x40000000 ,0x400 ); + dev =DEVICE (&s->gcr); +sysbus_realize (SYS_BUS_DEVICE (dev), errp); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,0x40000000 ); +create_unimplemented_device ("systemInterface" ,0x40000400 ,0x400 );create_unimplemented_device ("functionControl" ,0x40000800 ,0x400 );create_unimplemented_device ("watchdogTimer0" ,0x40003000 ,0x400 );
include/hw/arm/max78000_soc.h +2 -0
@@ -11,6 +11,7 @@#include "hw/or-irq.h" #include "hw/arm/armv7m.h" +#include "hw/misc/max78000_gcr.h" #include "hw/misc/max78000_icc.h" #include "hw/char/max78000_uart.h" #include "qom/object.h"
@@ -35,6 +36,7 @@ struct MAX78000State {MemoryRegion sram;MemoryRegion flash; +Max78000GcrState gcr;Max78000IccState icc[MAX78000_NUM_ICC ];Max78000UartState uart[MAX78000_NUM_UART ];
Signature · 1 line
2.34.1
PATCH v5 8/11 MAX78000: TRNG Implementation
In reply to Jackson DonaldsonThis commit implements the True Random Number
Generator for the MAX78000
--- hw/arm/Kconfig | 1 + hw/misc/Kconfig | 3 + hw/misc/max78000_gcr.c | 6 ++ hw/misc/max78000_trng.c | 139 ++++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + include/hw/misc/max78000_gcr.h | 1 + include/hw/misc/max78000_trng.h | 35 ++++++++ 7 files changed, 186 insertions(+) create mode 100644 hw/misc/max78000_trng.c create mode 100644 include/hw/misc/max78000_trng.h
hw/arm/Kconfig +1 -0
@@ -369,6 +369,7 @@ config MAX78000_SOC select MAX78000_ICC select MAX78000_UART select MAX78000_GCR + select MAX78000_TRNG config RASPI bool
hw/misc/Kconfig +3 -0
@@ -53,6 +53,9 @@ config MAX78000_GCR config MAX78000_ICC bool +config MAX78000_TRNG + bool + config MOS6522 bool
hw/misc/max78000_gcr.c +6 -0
@@ -14,6 +14,7 @@#include "migration/vmstate.h" #include "hw/qdev-properties.h" #include "hw/char/max78000_uart.h" +#include "hw/misc/max78000_trng.h" #include "hw/misc/max78000_gcr.h"
@@ -157,6 +158,9 @@ static void max78000_gcr_write(void *opaque, hwaddr addr,if (val &UART0_RESET ) {device_cold_reset (s->uart0); } +if (val &TRNG_RESET ) { +device_cold_reset (s->trng); + }/* TODO: As other devices are implemented, add them here */ break ;
@@ -257,6 +261,8 @@ static const Property max78000_gcr_properties[] = { TYPE_MAX78000_UART, DeviceState*),DEFINE_PROP_LINK ("uart2" , Max78000GcrState, uart2, TYPE_MAX78000_UART, DeviceState*), +DEFINE_PROP_LINK ("trng" , Max78000GcrState, trng, + TYPE_MAX78000_TRNG, DeviceState*), }; static const MemoryRegionOps max78000_gcr_ops = {
hw/misc/max78000_trng.c new file +139 -0
139 lines not on this page · raw message
hw/misc/meson.build +1 -0
@@ -72,6 +72,7 @@ system_ss.add(when: 'CONFIG_IMX', if_true: files( )) system_ss.add(when: 'CONFIG_MAX78000_GCR', if_true: files('max78000_gcr.c')) system_ss.add(when: 'CONFIG_MAX78000_ICC', if_true: files('max78000_icc.c')) +system_ss.add(when: 'CONFIG_MAX78000_TRNG', if_true: files('max78000_trng.c')) system_ss.add(when: 'CONFIG_NPCM7XX', if_true: files( 'npcm_clk.c', 'npcm_gcr.c',
include/hw/misc/max78000_gcr.h +1 -0
@@ -123,6 +123,7 @@ struct Max78000GcrState {DeviceState *uart0;DeviceState *uart1;DeviceState *uart2; +DeviceState *trng; };
include/hw/misc/max78000_trng.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* MAX78000 True Random Number Generator +* +* Copyright (c) 2025 Jackson Donaldson <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#ifndef HW_MAX78000_TRNG_H +#define HW_MAX78000_TRNG_H + +#include "hw/sysbus.h" +#include "qom/object.h" + +#define TYPE_MAX78000_TRNG "max78000-trng" +OBJECT_DECLARE_SIMPLE_TYPE(Max78000TrngState, MAX78000_TRNG) + +#define CTRL 0 +#define STATUS 4 +#define DATA 8 + +#define RND_IE (1 << 1) + +struct Max78000TrngState { +SysBusDevice parent_obj; + +MemoryRegion mmio; + +uint32_t ctrl; +uint32_t status; +uint32_t data; + +qemu_irq irq; +}; + +#endif
Signature · 1 line
2.34.1
PATCH v5 9/11 MAX78000: Add TRNG to SOC
In reply to Jackson DonaldsonThis commit adds TRNG to max78000_soc
--- hw/arm/max78000_soc.c | 10 +++++++++- include/hw/arm/max78000_soc.h | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-)
hw/arm/max78000_soc.c +9 -1
@@ -43,6 +43,8 @@ static void max78000_soc_initfn(Object *obj) TYPE_MAX78000_UART); } +object_initialize_child (obj,"trng" , &s->trng,TYPE_MAX78000_TRNG ); + s->sysclk =qdev_init_clock_in (DEVICE (s),"sysclk" ,NULL ,NULL ,0 ); }
@@ -124,6 +126,13 @@ static void max78000_soc_realize(DeviceState *dev_soc, Error **errp) max78000_uart_irq[i])); } + dev =DEVICE (&s->trng); +sysbus_realize (SYS_BUS_DEVICE (dev), errp); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,0x4004d000 ); +sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 ,qdev_get_gpio_in (armv7m,4 )); + +object_property_set_link (OBJECT (gcrdev),"trng" ,OBJECT (dev), &err); + dev =DEVICE (&s->gcr);sysbus_realize (SYS_BUS_DEVICE (dev), errp);sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,0x40000000 );
@@ -166,7 +175,6 @@ static void max78000_soc_realize(DeviceState *dev_soc, Error **errp)create_unimplemented_device ("semaphore" ,0x4003e000 ,0x1000 );create_unimplemented_device ("spi1" ,0x40046000 ,0x2000 ); -create_unimplemented_device ("trng" ,0x4004d000 ,0x1000 );create_unimplemented_device ("i2s" ,0x40060000 ,0x1000 );create_unimplemented_device ("lowPowerControl" ,0x40080000 ,0x400 );create_unimplemented_device ("gpio2" ,0x40080400 ,0x200 );
include/hw/arm/max78000_soc.h +2 -0
@@ -14,6 +14,7 @@#include "hw/misc/max78000_gcr.h" #include "hw/misc/max78000_icc.h" #include "hw/char/max78000_uart.h" +#include "hw/misc/max78000_trng.h" #include "qom/object.h" #define TYPE_MAX78000_SOC "max78000-soc"
@@ -39,6 +40,7 @@ struct MAX78000State {Max78000GcrState gcr;Max78000IccState icc[MAX78000_NUM_ICC ];Max78000UartState uart[MAX78000_NUM_UART ]; +Max78000TrngState trng;Clock *sysclk; };
Signature · 1 line
2.34.1
PATCH v5 10/11 MAX78000: AES implementation
In reply to Jackson DonaldsonThis commit implements AES for the MAX78000
--- hw/arm/Kconfig | 1 + hw/misc/Kconfig | 3 + hw/misc/max78000_aes.c | 229 +++++++++++++++++++++++++++++++++ hw/misc/max78000_gcr.c | 6 + hw/misc/meson.build | 1 + include/hw/misc/max78000_aes.h | 68 ++++++++++ include/hw/misc/max78000_gcr.h | 1 + 7 files changed, 309 insertions(+) create mode 100644 hw/misc/max78000_aes.c create mode 100644 include/hw/misc/max78000_aes.h
hw/arm/Kconfig +1 -0
@@ -370,6 +370,7 @@ config MAX78000_SOC select MAX78000_UART select MAX78000_GCR select MAX78000_TRNG + select MAX78000_AES config RASPI bool
hw/misc/Kconfig +3 -0
@@ -47,6 +47,9 @@ config A9SCU config ARM11SCU bool +config MAX78000_AES + bool + config MAX78000_GCR bool
hw/misc/max78000_aes.c new file +229 -0
229 lines not on this page · raw message
hw/misc/max78000_gcr.c +6 -0
@@ -15,6 +15,7 @@#include "hw/qdev-properties.h" #include "hw/char/max78000_uart.h" #include "hw/misc/max78000_trng.h" +#include "hw/misc/max78000_aes.h" #include "hw/misc/max78000_gcr.h"
@@ -161,6 +162,9 @@ static void max78000_gcr_write(void *opaque, hwaddr addr,if (val &TRNG_RESET ) {device_cold_reset (s->trng); } +if (val &AES_RESET ) { +device_cold_reset (s->aes); + }/* TODO: As other devices are implemented, add them here */ break ;
@@ -263,6 +267,8 @@ static const Property max78000_gcr_properties[] = { TYPE_MAX78000_UART, DeviceState*),DEFINE_PROP_LINK ("trng" , Max78000GcrState, trng, TYPE_MAX78000_TRNG, DeviceState*), +DEFINE_PROP_LINK ("aes" , Max78000GcrState, aes, + TYPE_MAX78000_AES, DeviceState*), }; static const MemoryRegionOps max78000_gcr_ops = {
hw/misc/meson.build +1 -0
@@ -70,6 +70,7 @@ system_ss.add(when: 'CONFIG_IMX', if_true: files( 'imx_ccm.c', 'imx_rngc.c', )) +system_ss.add(when: 'CONFIG_MAX78000_AES', if_true: files('max78000_aes.c')) system_ss.add(when: 'CONFIG_MAX78000_GCR', if_true: files('max78000_gcr.c')) system_ss.add(when: 'CONFIG_MAX78000_ICC', if_true: files('max78000_icc.c')) system_ss.add(when: 'CONFIG_MAX78000_TRNG', if_true: files('max78000_trng.c'))
include/hw/misc/max78000_aes.h new file +68 -0
68 lines not on this page · raw message
include/hw/misc/max78000_gcr.h +1 -0
@@ -124,6 +124,7 @@ struct Max78000GcrState {DeviceState *uart1;DeviceState *uart2;DeviceState *trng; +DeviceState *aes; };
Signature · 1 line
2.34.1
PATCH v5 11/11 MAX78000: Add AES to SOC
In reply to Jackson DonaldsonThis commit adds AES to max78000_soc
--- hw/arm/max78000_soc.c | 12 +++++++++--- include/hw/arm/max78000_soc.h | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-)
hw/arm/max78000_soc.c +9 -3
@@ -45,6 +45,8 @@ static void max78000_soc_initfn(Object *obj)object_initialize_child (obj,"trng" , &s->trng,TYPE_MAX78000_TRNG ); +object_initialize_child (obj,"aes" , &s->aes,TYPE_MAX78000_AES ); + s->sysclk =qdev_init_clock_in (DEVICE (s),"sysclk" ,NULL ,NULL ,0 ); }
@@ -133,6 +135,13 @@ static void max78000_soc_realize(DeviceState *dev_soc, Error **errp)object_property_set_link (OBJECT (gcrdev),"trng" ,OBJECT (dev), &err); + dev =DEVICE (&s->aes); +sysbus_realize (SYS_BUS_DEVICE (dev), errp); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,0x40007400 ); +sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 ,qdev_get_gpio_in (armv7m,5 )); + +object_property_set_link (OBJECT (gcrdev),"aes" ,OBJECT (dev), &err); + dev =DEVICE (&s->gcr);sysbus_realize (SYS_BUS_DEVICE (dev), errp);sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,0x40000000 );
@@ -148,9 +157,6 @@ static void max78000_soc_realize(DeviceState *dev_soc, Error **errp)create_unimplemented_device ("powerSequencer" ,0x40006800 ,0x400 );create_unimplemented_device ("miscControl" ,0x40006c00 ,0x400 ); -create_unimplemented_device ("aes" ,0x40007400 ,0x400 ); -create_unimplemented_device ("aesKey" ,0x40007800 ,0x400 ); -create_unimplemented_device ("gpio0" ,0x40008000 ,0x1000 );create_unimplemented_device ("gpio1" ,0x40009000 ,0x1000 );
include/hw/arm/max78000_soc.h +2 -0
@@ -11,6 +11,7 @@#include "hw/or-irq.h" #include "hw/arm/armv7m.h" +#include "hw/misc/max78000_aes.h" #include "hw/misc/max78000_gcr.h" #include "hw/misc/max78000_icc.h" #include "hw/char/max78000_uart.h"
@@ -41,6 +42,7 @@ struct MAX78000State {Max78000IccState icc[MAX78000_NUM_ICC ];Max78000UartState uart[MAX78000_NUM_UART ];Max78000TrngState trng; +Max78000AesState aes;Clock *sysclk; };
Signature · 1 line
2.34.1
Quoted 27 lines · Jackson Donaldson
v5:
Quoted 23 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ AES_KEY key; + if ((s->ctrl & TYPE) == 0) { + AES_set_encrypt_key(keydata, keylen, &key); + AES_set_decrypt_key(keydata, keylen, &s->internal_key); + AES_encrypt(s->data, s->result, &key);Here we call
AES_set_encrypt_key()andAES_set_decrypt_key()before callingAES_encrypt()...Review
Quoted 5 lines
(quoted diff) +5
-0+ s->result_index = 16; + } else if ((s->ctrl & TYPE) == 1 << 8) { + AES_set_decrypt_key(keydata, keylen, &key); + AES_set_decrypt_key(keydata, keylen, &s->internal_key); + AES_decrypt(s->data, s->result, &key);...here we call
AES_set_decrypt_key()twice before callingAES_decrypt(). This looks a bit odd: should we either
(a) call bothAES_set_decrypt_key()andAES_set_encrypt_key()in each half of theif(), or (b) callAES_set_encyrypt_key()twice in theAES_encrypt()code path ?(Coverity is sometimes wrong, as it's only using a heuristic here, so the other option is "the code as written is correct", but in that case a comment might be helpful for human readers.)
Quoted 6 lines
Quoted 2 lines
thanks
-- PMMThe AES engine stores an internal key which it uses only for decryption when in the last TYPE. This results in the odd-looking call pairs. I've added the requested comment.
Your patches are already upstream, so rather than sending a new version of the whole series, please rebase on current head-of-git and just send a patch that adds the comment.
thnaks
-- PMM