MAX78000FTHR Implementation
v2 cover MAX78000FTHR Implementation
Quoted 11 lines
A minor note on email patchseries formatting: something odd seems to have happened with your cover letter. Patches in a series are supposed to be followups to the cover letter, but in this case each patch email has a header
In-reply-to: [email protected]
but that doesn't match the message-id of the cover letter mail (which was
[email protected]
).
Quoted 8 lines
It looks like something has rewritten the message-ID header between when git generated it and it got to the mailing list. I don't know if that's something you can fix at your end. (Otherwise I guess you could work around it by sending the cover letter first, finding out what message-ID it got given, and then generating the patch emails with the --in-reply-to=<identifier> option of git send-email so they come out as replies to the cover letter. But that seems a bit of a faff :-/ )
This is probably because my emails are forwarded through duckduckgo with the @duck.com address. Testing that workaround didn't appear to accomplish the desired result, so I'm sending directly from gmail now.
v2 changes:
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 | 234 +++++++++++++++++++++ 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 | 232 +++++++++++++++++++++ hw/misc/max78000_gcr.c | 351 ++++++++++++++++++++++++++++++++ hw/misc/max78000_icc.c | 120 +++++++++++ hw/misc/max78000_trng.c | 127 ++++++++++++ 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, 1831 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 v2 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
Re: [PATCH v2 01/11] MAX78000: Add MAX78000FTHR Machine
Quoted 9 lines · Jackson Donaldson
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.pdfSigned-off-by Jackson Donaldson <[email protected]>
Quoted 10 lines
--- 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
(in case you're not familiar with the email patch workflow, that means that when you do a v3 of this patchset, you should include that line in the commit message for this patch, unless you made changes to this patch:
https://www.qemu.org/docs/master/devel/submitting-a-patch.html#proper-use-of-reviewed-by-tags-can-aid-review
)
thanks
-- PMM
PATCH v2 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
Re: [PATCH v2 02/11] MAX78000: ICC Implementation
Quoted 5 lines · Jackson Donaldson
This commit implements the Instruction Cache Controller for the MAX78000
Signed-off-by Jackson Donaldson <[email protected]>
Quoted 9 lines
--- 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
thanks
-- PMM
PATCH v2 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 | 19 +++++++++++++++---- include/hw/arm/max78000_soc.h | 6 ++++++ 2 files changed, 21 insertions(+), 4 deletions(-)
hw/arm/max78000_soc.c +15 -4
@@ -17,12 +17,19 @@#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++) { +object_initialize_child (obj,"icc[*]" , &s->icc[i],TYPE_MAX78000_ICC ); + } + s->sysclk =qdev_init_clock_in (DEVICE (s),"sysclk" ,NULL ,NULL ,0 ); }
@@ -30,8 +37,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 +82,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 +121,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
Re: [PATCH v2 03/11] MAX78000: Add ICC to SOC
Quoted 19 lines · Jackson Donaldson
This commit adds the instruction cache controller
tomax78000_socSigned-off-by Jackson Donaldson <[email protected]>--- hw/arm/max78000_soc.c | 19 +++++++++++++++---- include/hw/arm/max78000_soc.h | 6 ++++++ 2 files changed, 21 insertions(+), 4 deletions(-)hw/arm/max78000_soc.c +1
-0@@ -17,12 +17,19 @@#include "hw/qdev-clock.h" #include "hw/misc/unimp.h" +static const uint32_t max78000_icc_addr[] = {0x4002a000 ,0x4002a800 };
hw/arm/max78000_soc.c line 30
Quoted 10 lines
hw/arm/max78000_soc.c +4
-0+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++) { +object_initialize_child (obj,"icc[*]" , &s->icc[i],TYPE_MAX78000_ICC );
You should give each child a unique name:
g_autofree char *name = g_strdup_printf("icc%d", i);
object_initialize_child(obj, name, ...);hw/arm/max78000_soc.c line 34
Quoted 4 lines
hw/arm/max78000_soc.c +2
-0+ } + s->sysclk =qdev_init_clock_in (DEVICE (s),"sysclk" ,NULL ,NULL ,0 ); }
Otherwise this looks good.
-- PMM
PATCH v2 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
Re: [PATCH v2 04/11] MAX78000: UART Implementation
Quoted 5 lines · Jackson Donaldson
This commit implements UART support for the MAX78000
Signed-off-by Jackson Donaldson <[email protected]>---
thanks
-- PMM
PATCH v2 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) {
@@ -30,6 +34,11 @@ static void max78000_soc_initfn(Object *obj)object_initialize_child (obj,"icc[*]" , &s->icc[i],TYPE_MAX78000_ICC ); } +for (i =0 ; i <MAX78000_NUM_UART ; i++) { +object_initialize_child (obj,"uart[*]" , &s->uart[i], +TYPE_MAX78000_UART ); + } + s->sysclk =qdev_init_clock_in (DEVICE (s),"sysclk" ,NULL ,NULL ,0 ); }
@@ -38,6 +47,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;
@@ -88,6 +98,20 @@ 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 ; + } + dev->id =g_strdup_printf ("uart%d" , i); + + 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 );
@@ -126,10 +150,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
Re: [PATCH v2 05/11] MAX78000: Add UART to SOC
Quoted 25 lines · Jackson Donaldson
This commit adds UART to
max78000_socSigned-off-by Jackson Donaldson <[email protected]>--- 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 +4
-0@@ -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) {
hw/arm/max78000_soc.c static void max78000_soc_initfn(Object *obj) · line 39
Quoted 6 lines
hw/arm/max78000_soc.c +3
-0@@ -30,6 +34,11 @@ static void max78000_soc_initfn(Object *obj)object_initialize_child (obj,"icc[*]" , &s->icc[i],TYPE_MAX78000_ICC ); } +for (i =0 ; i <MAX78000_NUM_UART ; i++) { +object_initialize_child (obj,"uart[*]" , &s->uart[i], +TYPE_MAX78000_UART );
As with the earlier patch, give each object a unique name.
Quoted 14 lines
hw/arm/max78000_soc.c +3
-0+ } + s->sysclk =qdev_init_clock_in (DEVICE (s),"sysclk" ,NULL ,NULL ,0 ); }@@ -38,6 +47,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;
hw/arm/max78000_soc.c static void max78000_soc_realize(DeviceState *dev_soc, Error **errp) · line 107
Quoted 10 lines
hw/arm/max78000_soc.c +7
-0@@ -88,6 +98,20 @@ 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 ; + } + dev->id =g_strdup_printf ("uart%d" , i);
This looks odd -- the SoC code shouldn't need to reach in and set anything directly in the DeviceState struct.
hw/arm/max78000_soc.c static void max78000_soc_realize(DeviceState *dev_soc, Error **errp) · line 117
Quoted 10 lines
hw/arm/max78000_soc.c +7
-0+ + 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 );
thanks
-- PMM
PATCH v2 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
Re: [PATCH v2 06/11] MAX78000: GCR Implementation
Quoted 6 lines · Jackson Donaldson
This commit implements the Global Control Register for the MAX78000
Signed-off-by Jackson Donaldson <[email protected]>---
thanks
-- PMM
PATCH v2 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 | 21 +++++++++++++++++++-- include/hw/arm/max78000_soc.h | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-)
hw/arm/max78000_soc.c +19 -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++) {object_initialize_child (obj,"icc[*]" , &s->icc[i],TYPE_MAX78000_ICC ); }
@@ -46,7 +48,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;
@@ -67,6 +69,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 ;
@@ -92,12 +99,14 @@ 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]); } +for (i =0 ; i <MAX78000_NUM_UART ; i++) { dev =DEVICE (&(s->uart[i]));qdev_prop_set_chr (dev,"chardev" ,serial_hd (i));
@@ -106,13 +115,21 @@ static void max78000_soc_realize(DeviceState *dev_soc, Error **errp) } dev->id =g_strdup_printf ("uart%d" , i); +object_property_set_link (OBJECT (gcrdev), dev->id,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
Re: [PATCH v2 07/11] MAX78000: Add GCR to SOC
Quoted 9 lines · Jackson Donaldson
This commit adds the Global Control Register to
max78000_socSigned-off-by Jackson Donaldson <[email protected]>
hw/arm/max78000_soc.c static void max78000_soc_realize(DeviceState *dev_soc, Error **errp) · line 119
Quoted 5 lines
hw/arm/max78000_soc.c +2
-0@@ -106,13 +115,21 @@ static void max78000_soc_realize(DeviceState *dev_soc, Error **errp) } dev->id =g_strdup_printf ("uart%d" , i); +object_property_set_link (OBJECT (gcrdev), dev->id,OBJECT (dev), + &err);
The second argument to object_property_set_link() is the name of the link property. That might or might not happen to be the same as the ID of the device you're connecting it to, but you shouldn't be directly accessing DeviceState::id here. Just create the string you need with g_strdup_printf() (and don't forget to use g_autofree so it gets freed).
hw/arm/max78000_soc.c static void max78000_soc_realize(DeviceState *dev_soc, Error **errp) · line 129
Quoted 11 lines
hw/arm/max78000_soc.c +4
-1+ 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 );
thanks
-- PMM
PATCH v2 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 | 127 ++++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + include/hw/misc/max78000_gcr.h | 1 + include/hw/misc/max78000_trng.h | 35 +++++++++ 7 files changed, 174 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 +127 -0
127 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
Re: [PATCH v2 08/11] MAX78000: TRNG Implementation
Quoted 66 lines · Jackson Donaldson
This commit implements the True Random Number
Generator for the MAX78000Signed-off-by Jackson Donaldson <[email protected]>static const MemoryRegionOps
max78000_gcr_ops= {hw/misc/max78000_trng.c new file +53
-0@@ -0,0 +1,127 @@ +/* +* MAX78000 True Random Number Generator +* +* Copyright (c) 2025 Jackson Donaldson <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "trace.h" +#include "hw/irq.h" +#include "migration/vmstate.h" +#include "hw/misc/max78000_trng.h" +#include "qemu/guest-random.h" + +static uint64_t max78000_trng_read (void *opaque,hwaddr addr, +unsigned int size) +{ +uint32_t data; + +Max78000TrngState *s = opaque; +switch (addr) { +case CTRL : +return s->ctrl; + +case STATUS : +return 1 ; + +case DATA : +qemu_guest_getrandom_nofail (&data,sizeof (data)); +return data; + +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" + HWADDR_PRIx"\n" , __func__, addr); +break ; + } +return 0 ; +} + +static void max78000_trng_write (void *opaque,hwaddr addr, +uint64_t val64,unsigned int size) +{ +Max78000TrngState *s = opaque; +uint32_t val = val64; +switch (addr) { +case CTRL : +/* TODO: implement AES keygen */ + s->ctrl = val; +if (val &RND_IE ) { +qemu_set_irq (s->irq,1 ); + }else {
hw/misc/max78000_trng.c line 63
Quoted 10 lines
hw/misc/max78000_trng.c new file +10
-0+qemu_set_irq (s->irq,0 ); + } +break ; + +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" + HWADDR_PRIx"\n" , __func__, addr); +break ; + } +}
The interrupt generation logic still doesn't look right here to me -- see my comments on the TRNG patch in v1 of this patchset.
thanks
-- PMM
PATCH v2 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
@@ -41,6 +41,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 )); + dev->id =g_strdup ("trng" ); +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 );
@@ -168,7 +177,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
Re: [PATCH v2 09/11] MAX78000: Add TRNG to SOC
Quoted 23 lines · Jackson Donaldson
This commit adds TRNG to
max78000_socSigned-off-by Jackson Donaldson--- 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 +2
-0@@ -41,6 +41,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 ); }
hw/arm/max78000_soc.c static void max78000_soc_realize(DeviceState *dev_soc, Error **errp) · line 134
Quoted 9 lines
hw/arm/max78000_soc.c +6
-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 )); + dev->id =g_strdup ("trng" ); +object_property_set_link (OBJECT (gcrdev),"trng" ,OBJECT (dev), &err);
As with the uarts, don't touch dev->id here.
thanks
-- PMM
PATCH v2 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 | 232 +++++++++++++++++++++++++++++++++ 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, 312 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 +232 -0
232 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
Re: [PATCH v2 10/11] MAX78000: AES implementation
Quoted 23 lines · Jackson Donaldson
This commit implements AES for the MAX78000
Signed-off-by Jackson Donaldson---
hw/misc/max78000_aes.c new file +16
-0+static uint64_t max78000_aes_read (void *opaque,hwaddr addr, +unsigned int size) +{ +Max78000AesState *s = opaque; +switch (addr) { +case CTRL : +return s->ctrl; + +case STATUS : +return s->status; + +case INTFL : +return s->intfl; + +case INTEN : +return s->inten;
hw/misc/max78000_aes.c line 59
Quoted 10 lines
hw/misc/max78000_aes.c new file +10
-0+ +case FIFO : +if (s->result_index >=4 ) { + s->intfl &= ~DONE ; + s->result_index -=4 ; +max78000_aes_set_status (s); +return (s->result[s->result_index] <<24 ) + + (s->result[s->result_index +1 ] <<16 ) + + (s->result[s->result_index +2 ] <<8 ) + + s->result[s->result_index +3 ];
You can write this more simply as
return ldl_be_p(&s->result[s->result_index]);
(that's a function which loads a big-endian 32-bit value from the given possibly-unaligned host address).
Quoted 32 lines
hw/misc/max78000_aes.c new file +31
-0+ }else { +return 0 ; + } + +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" + HWADDR_PRIx"\n" , __func__, addr); +break ; + + } +return 0 ; +} +static void max78000_aes_write (void *opaque,hwaddr addr, +uint64_t val64,unsigned int size) +{ +Max78000AesState *s = opaque; +uint32_t val = val64; +int i; +switch (addr) { +case CTRL : +if (val &OUTPUT_FLUSH ) { + s->result_index =0 ; + val &= ~OUTPUT_FLUSH ; + } +if (val &INPUT_FLUSH ) { + s->data_index =0 ; + val &= ~INPUT_FLUSH ; + } +if (val &START ) { +max78000_aes_do_crypto (s); + }
hw/misc/max78000_aes.c line 131
Quoted 10 lines
hw/misc/max78000_aes.c new file +10
-0+ +/* Hardware appears to stay enabled even if 0 written */ + s->ctrl = val | (s->ctrl &AES_EN ); +break ; + +case FIFO : +for (i =0 ; i <4 ; i++) { + s->data[(12 - s->data_index) + i] = + (val >> ((3 - i) *8 )) &0xff ; + }
Similarly here this is
stl_be_p(&s->data[12 - s->data_index], val);
There should be some kind of check here that s->data_index is in range here before we write to s->data[] (either an assert, if the device code is supposed to maintain data_index in range at all times, or else some kind of error handling path if guest software can do funny things to put it out of range).
hw/misc/max78000_aes.c line 142
Quoted 11 lines
hw/misc/max78000_aes.c new file +11
-0+ s->data_index +=4 ; +if (s->data_index >=16 ) { + s->data_index =0 ; +max78000_aes_do_crypto (s); + } +break ; + + case KEY_BASE ... KEY_END - 4: +for (i =0 ; i <4 ; i++) { + s->key[(KEY_END -KEY_BASE -4 ) - (addr -KEY_BASE ) + i] = + (val >> ((3 - i) *8 )) &0xff ;
stl_be_p(&s->key[...something...], val);
hw/misc/max78000_aes.c line 153
Quoted 11 lines
hw/misc/max78000_aes.c new file +11
-0+ } +break ; + +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" + HWADDR_PRIx"\n" , __func__, addr); +break ; + + } +max78000_aes_set_status (s); +}
thanks
-- PMM
PATCH v2 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
@@ -43,6 +43,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) dev->id =g_strdup ("trng" );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 )); + dev->id =g_strdup ("aes" ); +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 );
@@ -150,9 +159,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
Re: [PATCH v2 11/11] MAX78000: Add AES to SOC
Quoted 23 lines · Jackson Donaldson
This commit adds AES to
max78000_socSigned-off-by Jackson Donaldson <[email protected]>--- 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 +2
-0@@ -43,6 +43,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 ); }
hw/arm/max78000_soc.c static void max78000_soc_realize(DeviceState *dev_soc, Error **errp) · line 144
Quoted 10 lines
hw/arm/max78000_soc.c +7
-0@@ -133,6 +135,13 @@ static void max78000_soc_realize(DeviceState *dev_soc, Error **errp) dev->id =g_strdup ("trng" );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 )); + dev->id =g_strdup ("aes" ); +object_property_set_link (OBJECT (gcrdev),"aes" ,OBJECT (dev), &err); +
Same comment about not touching dev->id as for earlier patches.
thanks
-- PMM