Add support for Smartfusion2 SoC
v10 cover Add support for Smartfusion2 SoC
Hi Qemu-devel,
I am trying to add Smartfusion2 SoC.
SoC is from Microsemi and System on Module(SOM) board is from Emcraft systems. Smartfusion2 has hardened Microcontroller(Cortex-M3)based Sub System and FPGA fabric. At the moment only system timer, sysreg and SPI controller are modelled.
Testing:
./arm-softmmu/qemu-system-arm -M emcraft-sf2 -serial mon:stdio \
-kernel u-boot.bin -display none -drive file=spi.bin,if=mtd,format=raw
Binaries u-boot.bin and spi.bin are at:
https://github.com/Subbaraya-Sundeep/qemu-test-binaries.git
U-boot is from Emcraft with modified
- SPI driver not to use PDMA.
- ugly hack to pass dtb to kernel in r1.
@
https://github.com/Subbaraya-Sundeep/emcraft-uboot-sf2.git
Linux is 4.5 linux with Smartfusion2 SoC dts and clocksource driver added by myself @
https://github.com/Subbaraya-Sundeep/linux.git
v10:
Added msf2_sysreg_realize in msf2-sysreg.c modified unimplemented devices names:
pdma->dma and hpdma->hs-dma
used uint8_t for apb divisors properties simplified msf2_divbits() using ctz32()
v9:
used trace instead of DB_PRINT in msf2-sysreg.c used LOG_UNIMP for non guest errors in msf2-sysreg.c added unimplemented devices in msf2-soc.c
removed .alias suffix in alias memory region name for eNVM removed mc->ignore_memory_transaction_failures in msf2-som.c
v8:
memory_region_init_ram to memory_region_init_rom in soc %s/emcraft_sf2_init/emcraft_sf2_s2s010_init/g in som Added mc->ignore_memory_transaction_failures = true in som
as per latest commit.
Code simplifications as suggested by Alistair in sysreg and ssi.
v7:
Removed vmstate_register_ram_global as per latest commit Moved header files to C which are local to C source files Removed abort() from msf2-sysreg.c
Added VMStateDescription in mss-timer.c
v6:
Moved some defines from header files to source files Added properties m3clk, apb0div, apb0div1 properties to soc.
Added properties apb0divisor, apb1divisor to sysreg Update system_clock_source in msf2-soc.c Changed machine name smartfusion2-som->emcraft-sf2
v5
As per Philippe comments:
Added abort in Sysreg if guest tries to remap memory other than default mapping.
Use of CONFIG_MSF2 in Makefile for soc.c
Fixed incorrect logic in timer model.
Renamed msf2-timer.c -> mss-timer.c
msf2-spi.c -> mss-spi.c also type names
Renamed function msf2_init->emcraft_sf2_init in msf2-som.c Added part-name,eNVM-size,eSRAM-size,pclk0 and pclk1
properties to soc.
Pass soc part-name,memory size and clock rate properties from som.
v4:
Fixed build failure by using PRIx macros.
v3:
Added SoC file and board file as per Alistair comments.
v2:
Added SPI controller so that u-boot loads kernel from spi flash.
v1:
Initial patch set with timer and sysreg
Thanks,
Sundeep
Subbaraya Sundeep (5):
msf2: Add Smartfusion2 System timer
msf2: Microsemi Smartfusion2 System Register block
msf2: Add Smartfusion2 SPI controller
msf2: Add Smartfusion2 SoC
msf2: Add Emcraft's Smartfusion2 SOM kit
default-configs/arm-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/msf2-soc.c | 232 +++++++++++++++++++++++ hw/arm/msf2-som.c | 94 ++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/msf2-sysreg.c | 160 ++++++++++++++++ hw/misc/trace-events | 5 + hw/ssi/Makefile.objs | 1 + hw/ssi/mss-spi.c | 404 ++++++++++++++++++++++++++++++++++++++++ hw/timer/Makefile.objs | 1 + hw/timer/mss-timer.c | 289 ++++++++++++++++++++++++++++ include/hw/arm/msf2-soc.h | 66 +++++++ include/hw/misc/msf2-sysreg.h | 77 ++++++++ include/hw/ssi/mss-spi.h | 58 ++++++ include/hw/timer/mss-timer.h | 64 +++++++ 15 files changed, 1454 insertions(+) create mode 100644 hw/arm/msf2-soc.c create mode 100644 hw/arm/msf2-som.c create mode 100644 hw/misc/msf2-sysreg.c create mode 100644 hw/ssi/mss-spi.c create mode 100644 hw/timer/mss-timer.c create mode 100644 include/hw/arm/msf2-soc.h create mode 100644 include/hw/misc/msf2-sysreg.h create mode 100644 include/hw/ssi/mss-spi.h create mode 100644 include/hw/timer/mss-timer.h
Signature · 1 line
2.5.0
PATCH v10 1/5 msf2: Add Smartfusion2 System timer
Modelled System Timer in Microsemi's Smartfusion2 Soc. Timer has two 32bit down counters and two interrupts.
--- hw/timer/Makefile.objs | 1 + hw/timer/mss-timer.c | 289 +++++++++++++++++++++++++++++++++++++++++++ include/hw/timer/mss-timer.h | 64 ++++++++++ 3 files changed, 354 insertions(+) create mode 100644 hw/timer/mss-timer.c create mode 100644 include/hw/timer/mss-timer.h
hw/timer/Makefile.objs +1 -0
@@ -42,3 +42,4 @@ common-obj-$(CONFIG_ASPEED_SOC) += aspeed_timer.o common-obj-$(CONFIG_SUN4V_RTC) += sun4v-rtc.o common-obj-$(CONFIG_CMSDK_APB_TIMER) += cmsdk-apb-timer.o +common-obj-$(CONFIG_MSF2) += mss-timer.o
hw/timer/mss-timer.c new file +289 -0
289 lines not on this page · raw message
include/hw/timer/mss-timer.h new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v10 2/5 msf2: Microsemi Smartfusion2 System Register block
In reply to Subbaraya SundeepAdded Sytem register block of Smartfusion2.
This block has PLL registers which are accessed by guest.
--- hw/misc/Makefile.objs | 1 + hw/misc/msf2-sysreg.c | 160 ++++++++++++++++++++++++++++++++++++++++++ hw/misc/trace-events | 5 ++ include/hw/misc/msf2-sysreg.h | 77 ++++++++++++++++++++ 4 files changed, 243 insertions(+) create mode 100644 hw/misc/msf2-sysreg.c create mode 100644 include/hw/misc/msf2-sysreg.h
hw/misc/Makefile.objs +1 -0
@@ -59,3 +59,4 @@ obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o obj-$(CONFIG_AUX) += auxbus.o obj-$(CONFIG_ASPEED_SOC) += aspeed_scu.o aspeed_sdmc.o obj-y += mmio_interface.o +obj-$(CONFIG_MSF2) += msf2-sysreg.o
hw/misc/msf2-sysreg.c new file +160 -0
160 lines not on this page · raw message
hw/misc/trace-events +5 -0
@@ -61,3 +61,8 @@ mps2_scc_reset(void) "MPS2 SCC: reset" mps2_scc_leds(char led7, char led6, char led5, char led4, char led3, char led2, char led1, char led0) "MPS2 SCC LEDs: %c%c%c%c%c%c%c%c" mps2_scc_cfg_write(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config write: function %d device %d data 0x%" PRIx32 mps2_scc_cfg_read(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config read: function %d device %d data 0x%" PRIx32 + +# hw/misc/msf2-sysreg.c +msf2_sysreg_write(uint64_t offset, uint32_t val, uint32_t prev) "msf2-sysreg write: addr 0x%08" HWADDR_PRIx " data 0x%" PRIx32 " prev 0x%" PRIx32 +msf2_sysreg_read(uint64_t offset, uint32_t val) "msf2-sysreg read: addr 0x%08" HWADDR_PRIx " data 0x%08" PRIx32 +msf2_sysreg_write_pll_status(void) "Invalid write to read only PLL status register"
include/hw/misc/msf2-sysreg.h new file +77 -0
77 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v10 3/5 msf2: Add Smartfusion2 SPI controller
In reply to Subbaraya SundeepModelled Microsemi's Smartfusion2 SPI controller.
--- hw/ssi/Makefile.objs | 1 + hw/ssi/mss-spi.c | 404 +++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ssi/mss-spi.h | 58 +++++++ 3 files changed, 463 insertions(+) create mode 100644 hw/ssi/mss-spi.c create mode 100644 include/hw/ssi/mss-spi.h
hw/ssi/Makefile.objs +1 -0
@@ -4,6 +4,7 @@ common-obj-$(CONFIG_XILINX_SPI) += xilinx_spi.o common-obj-$(CONFIG_XILINX_SPIPS) += xilinx_spips.o common-obj-$(CONFIG_ASPEED_SOC) += aspeed_smc.o common-obj-$(CONFIG_STM32F2XX_SPI) += stm32f2xx_spi.o +common-obj-$(CONFIG_MSF2) += mss-spi.o obj-$(CONFIG_OMAP) += omap_spi.o obj-$(CONFIG_IMX) += imx_spi.o
hw/ssi/mss-spi.c new file +404 -0
404 lines not on this page · raw message
include/hw/ssi/mss-spi.h new file +58 -0
58 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v10 4/5 msf2: Add Smartfusion2 SoC
In reply to Subbaraya SundeepSmartfusion2 SoC has hardened Microcontroller subsystem and flash based FPGA fabric. This patch adds support for Microcontroller subsystem in the SoC.
--- default-configs/arm-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/msf2-soc.c | 232 ++++++++++++++++++++++++++++++++++++++++ include/hw/arm/msf2-soc.h | 66 ++++++++++++ 4 files changed, 300 insertions(+) create mode 100644 hw/arm/msf2-soc.c create mode 100644 include/hw/arm/msf2-soc.h
default-configs/arm-softmmu.mak +1 -0
@@ -129,3 +129,4 @@ CONFIG_ACPI=y CONFIG_SMBIOS=y CONFIG_ASPEED_SOC=y CONFIG_GPIO_KEY=y +CONFIG_MSF2=y
hw/arm/Makefile.objs +1 -0
@@ -19,3 +19,4 @@ obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o sabrelite.o obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o obj-$(CONFIG_MPS2) += mps2.o +obj-$(CONFIG_MSF2) += msf2-soc.o
hw/arm/msf2-soc.c new file +232 -0
232 lines not on this page · raw message
include/hw/arm/msf2-soc.h new file +66 -0
66 lines not on this page · raw message
Signature · 1 line
2.5.0
Re: [Qemu-arm] [Qemu devel v10 PATCH 4/5] msf2: Add Smartfusion2 SoC
Quoted 153 lines · Subbaraya Sundeep
Smartfusion2 SoC has hardened Microcontroller subsystem and flash based FPGA fabric. This patch adds support for Microcontroller subsystem in the SoC.
Signed-off-by Subbaraya Sundeep <[email protected]>Reviewed-by Alistair Francis <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>--- default-configs/arm-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/msf2-soc.c | 232 ++++++++++++++++++++++++++++++++++++++++ include/hw/arm/msf2-soc.h | 66 ++++++++++++ 4 files changed, 300 insertions(+)create mode 100644
hw/arm/msf2-soc.c
create mode 100644include/hw/arm/msf2-soc.hdefault-configs/arm-softmmu.mak +1
-0@@ -129,3 +129,4 @@ CONFIG_ACPI=y CONFIG_SMBIOS=y CONFIG_ASPEED_SOC=y CONFIG_GPIO_KEY=y +CONFIG_MSF2=yhw/arm/Makefile.objs +1
-0@@ -19,3 +19,4 @@ obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o sabrelite.o obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o obj-$(CONFIG_MPS2) += mps2.o +obj-$(CONFIG_MSF2) += msf2-soc.ohw/arm/msf2-soc.c new file +112
-0@@ -0,0 +1,232 @@ +/* +* SmartFusion2 SoC emulation. +* +* Copyright (c) 2017 Subbaraya Sundeep <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "hw/arm/arm.h" +#include "exec/address-spaces.h" +#include "hw/char/serial.h" +#include "hw/boards.h" +#include "sysemu/block-backend.h" +#include "qemu/cutils.h" +#include "hw/arm/msf2-soc.h" +#include "hw/misc/unimp.h" + +#define MSF2_TIMER_BASE 0x40004000 +#define MSF2_SYSREG_BASE 0x40038000 + +#define ENVM_BASE_ADDRESS 0x60000000 + +#define SRAM_BASE_ADDRESS 0x20000000 + +#define MSF2_ENVM_MAX_SIZE (512 * K_BYTE) + +/* +* eSRAM max size is 80k without SECDED(Single error correction and +* dual error detection) feature and 64k with SECDED. +* We do not support SECDED now. +*/ +#define MSF2_ESRAM_MAX_SIZE (80 * K_BYTE) + +static const uint32_t spi_addr[MSF2_NUM_SPIS ] = {0x40001000 ,0x40011000 }; +static const uint32_t uart_addr[MSF2_NUM_UARTS ] = {0x40000000 ,0x40010000 }; + +static const int spi_irq[MSF2_NUM_SPIS ] = {2 ,3 }; +static const int uart_irq[MSF2_NUM_UARTS ] = {10 ,11 }; +static const int timer_irq[MSF2_NUM_TIMERS ] = {14 ,15 }; + +static void m2sxxx_soc_initfn (Object *obj) +{ +MSF2State *s =MSF2_SOC (obj); +int i; + +object_initialize (&s->armv7m,sizeof (s->armv7m),TYPE_ARMV7M ); +qdev_set_parent_bus (DEVICE (&s->armv7m),sysbus_get_default ()); + +object_initialize (&s->sysreg,sizeof (s->sysreg),TYPE_MSF2_SYSREG ); +qdev_set_parent_bus (DEVICE (&s->sysreg),sysbus_get_default ()); + +object_initialize (&s->timer,sizeof (s->timer),TYPE_MSS_TIMER ); +qdev_set_parent_bus (DEVICE (&s->timer),sysbus_get_default ()); + +for (i =0 ; i <MSF2_NUM_SPIS ; i++) { +object_initialize (&s->spi[i],sizeof (s->spi[i]), +TYPE_MSS_SPI ); +qdev_set_parent_bus (DEVICE (&s->spi[i]),sysbus_get_default ()); + } +} + +static void m2sxxx_soc_realize (DeviceState *dev_soc,Error **errp) +{ +MSF2State *s =MSF2_SOC (dev_soc); +DeviceState *dev, *armv7m; +SysBusDevice *busdev; +Error *err =NULL ; +int i; + +MemoryRegion *system_memory =get_system_memory (); +MemoryRegion *nvm =g_new (MemoryRegion,1 ); +MemoryRegion *nvm_alias =g_new (MemoryRegion,1 ); +MemoryRegion *sram =g_new (MemoryRegion,1 ); + +memory_region_init_rom (nvm,NULL ,"MSF2.eNVM" , s->envm_size, + &error_fatal); +/* +* On power-on, the eNVM region 0x60000000 is automatically +* remapped to the Cortex-M3 processor executable region +* start address (0x0). We do not support remapping other eNVM, +* eSRAM and DDR regions by guest(via Sysreg) currently. +*/ +memory_region_init_alias (nvm_alias,NULL ,"MSF2.eNVM" , + nvm,0 , s->envm_size); + +memory_region_add_subregion (system_memory,ENVM_BASE_ADDRESS , nvm); +memory_region_add_subregion (system_memory,0 , nvm_alias); + +memory_region_init_ram (sram,NULL ,"MSF2.eSRAM" , s->esram_size, + &error_fatal); +memory_region_add_subregion (system_memory,SRAM_BASE_ADDRESS , sram); + + armv7m =DEVICE (&s->armv7m);
hw/arm/msf2-soc.c line 122
Quoted 10 lines
hw/arm/msf2-soc.c new file +10
-0+qdev_prop_set_uint32 (armv7m,"num-irq" ,81 ); +qdev_prop_set_string (armv7m,"cpu-model" ,"cortex-m3" ); +object_property_set_link (OBJECT (&s->armv7m),OBJECT (get_system_memory ()), +"memory" , &error_abort); +object_property_set_bool (OBJECT (&s->armv7m), true,"realized" , &err); +if (err !=NULL ) { +error_propagate (errp, err); +return ; + } +
Here we missed:
if (!s->m3clk) {
error_setg(errp, "Invalid m3clk value");
error_append_hint(errp, "m3clk can not be zero\n");
return;
}Except this fix, this series looks ready to get applied. Maybe Peter can add this piece of code directly.
Quoted 183 lines
hw/arm/msf2-soc.c new file +110
-0+ system_clock_scale =NANOSECONDS_PER_SECOND / s->m3clk; + +for (i =0 ; i <MSF2_NUM_UARTS ; i++) { +if (serial_hds[i]) { +serial_mm_init (get_system_memory (), uart_addr[i],2 , +qdev_get_gpio_in (armv7m, uart_irq[i]), +115200 , serial_hds[i],DEVICE_NATIVE_ENDIAN ); + } + } + + dev =DEVICE (&s->timer); +/* APB0 clock is the timer input clock */ +qdev_prop_set_uint32 (dev,"clock-frequency" , s->m3clk / s->apb0div); +object_property_set_bool (OBJECT (&s->timer), true,"realized" , &err); +if (err !=NULL ) { +error_propagate (errp, err); +return ; + } + busdev =SYS_BUS_DEVICE (dev); +sysbus_mmio_map (busdev,0 ,MSF2_TIMER_BASE ); +sysbus_connect_irq (busdev,0 , +qdev_get_gpio_in (armv7m, timer_irq[0 ])); +sysbus_connect_irq (busdev,1 , +qdev_get_gpio_in (armv7m, timer_irq[1 ])); + + dev =DEVICE (&s->sysreg); +qdev_prop_set_uint32 (dev,"apb0divisor" , s->apb0div); +qdev_prop_set_uint32 (dev,"apb1divisor" , s->apb1div); +object_property_set_bool (OBJECT (&s->sysreg), true,"realized" , &err); +if (err !=NULL ) { +error_propagate (errp, err); +return ; + } + busdev =SYS_BUS_DEVICE (dev); +sysbus_mmio_map (busdev,0 ,MSF2_SYSREG_BASE ); + +for (i =0 ; i <MSF2_NUM_SPIS ; i++) { +gchar *bus_name; + +object_property_set_bool (OBJECT (&s->spi[i]), true,"realized" , &err); +if (err !=NULL ) { +error_propagate (errp, err); +return ; + } + +sysbus_mmio_map (SYS_BUS_DEVICE (&s->spi[i]),0 , spi_addr[i]); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->spi[i]),0 , +qdev_get_gpio_in (armv7m, spi_irq[i])); + +/* Alias controller SPI bus to the SoC itself */ + bus_name =g_strdup_printf ("spi%d" , i); +object_property_add_alias (OBJECT (s), bus_name, +OBJECT (&s->spi[i]),"spi" , + &error_abort); +g_free (bus_name); + } + +/* Below devices are not modelled yet. */ +create_unimplemented_device ("i2c_0" ,0x40002000 ,0x1000 ); +create_unimplemented_device ("dma" ,0x40003000 ,0x1000 ); +create_unimplemented_device ("watchdog" ,0x40005000 ,0x1000 ); +create_unimplemented_device ("i2c_1" ,0x40012000 ,0x1000 ); +create_unimplemented_device ("gpio" ,0x40013000 ,0x1000 ); +create_unimplemented_device ("hs-dma" ,0x40014000 ,0x1000 ); +create_unimplemented_device ("can" ,0x40015000 ,0x1000 ); +create_unimplemented_device ("rtc" ,0x40017000 ,0x1000 ); +create_unimplemented_device ("apb_config" ,0x40020000 ,0x10000 ); +create_unimplemented_device ("emac" ,0x40041000 ,0x1000 ); +create_unimplemented_device ("usb" ,0x40043000 ,0x1000 ); +} + +static Property m2sxxx_soc_properties[] = { +/* +* part name specifies the type of SmartFusion2 device variant(this +* property is for information purpose only. +*/ +DEFINE_PROP_STRING ("part-name" , MSF2State, part_name), +DEFINE_PROP_UINT64 ("eNVM-size" , MSF2State, envm_size,MSF2_ENVM_MAX_SIZE ), +DEFINE_PROP_UINT64 ("eSRAM-size" , MSF2State, esram_size, +MSF2_ESRAM_MAX_SIZE ), +/* Libero GUI shows 100Mhz as default for clocks */ +DEFINE_PROP_UINT32 ("m3clk" , MSF2State, m3clk,100 *1000000 ), +/* default divisors in Libero GUI */ +DEFINE_PROP_UINT8 ("apb0div" , MSF2State, apb0div,2 ), +DEFINE_PROP_UINT8 ("apb1div" , MSF2State, apb1div,2 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void m2sxxx_soc_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = m2sxxx_soc_realize; + dc->props = m2sxxx_soc_properties; +} + +static const TypeInfo m2sxxx_soc_info = { + .name =TYPE_MSF2_SOC , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (MSF2State), + .instance_init = m2sxxx_soc_initfn, + .class_init = m2sxxx_soc_class_init, +}; + +static void m2sxxx_soc_types (void ) +{ +type_register_static (&m2sxxx_soc_info); +} + +type_init (m2sxxx_soc_types)include/hw/arm/msf2-soc.h new file +66
-0@@ -0,0 +1,66 @@ +/* +* Microsemi Smartfusion2 SoC +* +* Copyright (c) 2017 Subbaraya Sundeep <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#ifndef HW_ARM_MSF2_SOC_H +#define HW_ARM_MSF2_SOC_H + +#include "hw/arm/armv7m.h" +#include "hw/timer/mss-timer.h" +#include "hw/misc/msf2-sysreg.h" +#include "hw/ssi/mss-spi.h" + +#define TYPE_MSF2_SOC "msf2-soc" +#define MSF2_SOC (obj) OBJECT_CHECK(MSF2State, (obj), TYPE_MSF2_SOC) + +#define MSF2_NUM_SPIS 2 +#define MSF2_NUM_UARTS 2 + +/* +* System timer consists of two programmable 32-bit +* decrementing counters that generate individual interrupts to +* the Cortex-M3 processor +*/ +#define MSF2_NUM_TIMERS 2 + +typedef struct MSF2State { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +ARMv7MState armv7m; + +char *part_name; +uint64_t envm_size; +uint64_t esram_size; + +uint32_t m3clk; +uint8_t apb0div; +uint8_t apb1div; + +MSF2SysregState sysreg; +MSSTimerState timer; +MSSSpiState spi[MSF2_NUM_SPIS ]; +}MSF2State ; + +#endif
Re: [Qemu-devel] [Qemu devel v10 PATCH 4/5] msf2: Add Smartfusion2 SoC
Hi Philippe and Peter,
Quoted 192 lines · Philippe Mathieu-Daudé
Quoted 176 lines · Subbaraya Sundeep
Smartfusion2 SoC has hardened Microcontroller subsystem and flash based FPGA fabric. This patch adds support for Microcontroller subsystem in the SoC.
Signed-off-by Subbaraya Sundeep <[email protected]>Reviewed-by Alistair Francis <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>--- default-configs/arm-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/msf2-soc.c | 232 ++++++++++++++++++++++++++++++ ++++++++++ include/hw/arm/msf2-soc.h | 66 ++++++++++++ 4 files changed, 300 insertions(+)create mode 100644
hw/arm/msf2-soc.c
create mode 100644include/hw/arm/msf2-soc.hdefault-configs/arm-softmmu.mak +1
-0@@ -129,3 +129,4 @@ CONFIG_ACPI=y CONFIG_SMBIOS=y CONFIG_ASPEED_SOC=y CONFIG_GPIO_KEY=y +CONFIG_MSF2=yhw/arm/Makefile.objs +1
-0@@ -19,3 +19,4 @@ obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o sabrelite.o obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o obj-$(CONFIG_MPS2) += mps2.o +obj-$(CONFIG_MSF2) += msf2-soc.ohw/arm/msf2-soc.c new file +6
-0@@ -0,0 +1,232 @@ +/* +* SmartFusion2 SoC emulation. +* +* Copyright (c) 2017 Subbaraya Sundeep <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */hw/arm/msf2-soc.c new file +30
-0+ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "hw/arm/arm.h" +#include "exec/address-spaces.h" +#include "hw/char/serial.h" +#include "hw/boards.h" +#include "sysemu/block-backend.h" +#include "qemu/cutils.h" +#include "hw/arm/msf2-soc.h" +#include "hw/misc/unimp.h" + +#define MSF2_TIMER_BASE 0x40004000 +#define MSF2_SYSREG_BASE 0x40038000 + +#define ENVM_BASE_ADDRESS 0x60000000 + +#define SRAM_BASE_ADDRESS 0x20000000 + +#define MSF2_ENVM_MAX_SIZE (512 * K_BYTE) + +/* +* eSRAM max size is 80k without SECDED(Single error correction and +* dual error detection) feature and 64k with SECDED. +* We do not support SECDED now. +*/ +#define MSF2_ESRAM_MAX_SIZE (80 * K_BYTE) + +static const uint32_t spi_addr[MSF2_NUM_SPIS ] = {0x40001000 ,
0x40011000};
+static constuint32_tuart_addr[MSF2_NUM_UARTS] = {0x40000000,0x40010000};hw/arm/msf2-soc.c new file +61
-0+ +static const int spi_irq[MSF2_NUM_SPIS ] = {2 ,3 }; +static const int uart_irq[MSF2_NUM_UARTS ] = {10 ,11 }; +static const int timer_irq[MSF2_NUM_TIMERS ] = {14 ,15 }; + +static void m2sxxx_soc_initfn (Object *obj) +{ +MSF2State *s =MSF2_SOC (obj); +int i; + +object_initialize (&s->armv7m,sizeof (s->armv7m),TYPE_ARMV7M ); +qdev_set_parent_bus (DEVICE (&s->armv7m),sysbus_get_default ()); + +object_initialize (&s->sysreg,sizeof (s->sysreg),TYPE_MSF2_SYSREG ); +qdev_set_parent_bus (DEVICE (&s->sysreg),sysbus_get_default ()); + +object_initialize (&s->timer,sizeof (s->timer),TYPE_MSS_TIMER ); +qdev_set_parent_bus (DEVICE (&s->timer),sysbus_get_default ()); + +for (i =0 ; i <MSF2_NUM_SPIS ; i++) { +object_initialize (&s->spi[i],sizeof (s->spi[i]), +TYPE_MSS_SPI ); +qdev_set_parent_bus (DEVICE (&s->spi[i]),sysbus_get_default ()); + } +} + +static void m2sxxx_soc_realize (DeviceState *dev_soc,Error **errp) +{ +MSF2State *s =MSF2_SOC (dev_soc); +DeviceState *dev, *armv7m; +SysBusDevice *busdev; +Error *err =NULL ; +int i; + +MemoryRegion *system_memory =get_system_memory (); +MemoryRegion *nvm =g_new (MemoryRegion,1 ); +MemoryRegion *nvm_alias =g_new (MemoryRegion,1 ); +MemoryRegion *sram =g_new (MemoryRegion,1 ); + +memory_region_init_rom (nvm,NULL ,"MSF2.eNVM" , s->envm_size, + &error_fatal); +/* +* On power-on, the eNVM region 0x60000000 is automatically +* remapped to the Cortex-M3 processor executable region +* start address (0x0). We do not support remapping other eNVM, +* eSRAM and DDR regions by guest(via Sysreg) currently. +*/ +memory_region_init_alias (nvm_alias,NULL ,"MSF2.eNVM" , + nvm,0 , s->envm_size); + +memory_region_add_subregion (system_memory,ENVM_BASE_ADDRESS , nvm); +memory_region_add_subregion (system_memory,0 , nvm_alias); + +memory_region_init_ram (sram,NULL ,"MSF2.eSRAM" , s->esram_size, + &error_fatal); +memory_region_add_subregion (system_memory,SRAM_BASE_ADDRESS , sram); + + armv7m =DEVICE (&s->armv7m); +qdev_prop_set_uint32 (armv7m,"num-irq" ,81 ); +qdev_prop_set_string (armv7m,"cpu-model" ,"cortex-m3" ); + object_property_set_link(OBJECT(&s->armv7m),OBJECT(get_system_memory()),
hw/arm/msf2-soc.c new file +2
-0+ "memory", &error_abort); + object_property_set_bool(OBJECT(&s->armv7m), true, "realized",&err);
hw/arm/msf2-soc.c line 122
Quoted 5 lines
hw/arm/msf2-soc.c new file +5
-0+if (err !=NULL ) { +error_propagate (errp, err); +return ; + } +Here we missed:
if (!s->m3clk) { error_setg(errp, "Invalid m3clk value"); error_append_hint(errp, "m3clk can not be zero\n"); return; }
Quoted 7 lines
Yeah we missed this. Thanks for pointing out.
Except this fix, this series looks ready to get applied. Maybe Peter can add this piece of code directly.
Peter? I will do it within a day if you want.
Thanks,
Sundeep
Quoted 199 lines
+
system_clock_scale=NANOSECONDS_PER_SECOND/s->m3clk;Quoted 197 lines
hw/arm/msf2-soc.c new file +28
-0+ +for (i =0 ; i <MSF2_NUM_UARTS ; i++) { +if (serial_hds[i]) { +serial_mm_init (get_system_memory (), uart_addr[i],2 , +qdev_get_gpio_in (armv7m, uart_irq[i]), +115200 , serial_hds[i],DEVICE_NATIVE_ENDIAN ); + } + } + + dev =DEVICE (&s->timer); +/* APB0 clock is the timer input clock */ +qdev_prop_set_uint32 (dev,"clock-frequency" , s->m3clk / s->apb0div); +object_property_set_bool (OBJECT (&s->timer), true,"realized" , &err); +if (err !=NULL ) { +error_propagate (errp, err); +return ; + } + busdev =SYS_BUS_DEVICE (dev); +sysbus_mmio_map (busdev,0 ,MSF2_TIMER_BASE ); +sysbus_connect_irq (busdev,0 , +qdev_get_gpio_in (armv7m, timer_irq[0 ])); +sysbus_connect_irq (busdev,1 , +qdev_get_gpio_in (armv7m, timer_irq[1 ])); + + dev =DEVICE (&s->sysreg); +qdev_prop_set_uint32 (dev,"apb0divisor" , s->apb0div); +qdev_prop_set_uint32 (dev,"apb1divisor" , s->apb1div); + object_property_set_bool(OBJECT(&s->sysreg), true, "realized",&err);
hw/arm/msf2-soc.c new file +11
-0+if (err !=NULL ) { +error_propagate (errp, err); +return ; + } + busdev =SYS_BUS_DEVICE (dev); +sysbus_mmio_map (busdev,0 ,MSF2_SYSREG_BASE ); + +for (i =0 ; i <MSF2_NUM_SPIS ; i++) { +gchar *bus_name; + + object_property_set_bool(OBJECT(&s->spi[i]), true, "realized",&err);
hw/arm/msf2-soc.c new file +38
-0+if (err !=NULL ) { +error_propagate (errp, err); +return ; + } + +sysbus_mmio_map (SYS_BUS_DEVICE (&s->spi[i]),0 , spi_addr[i]); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->spi[i]),0 , +qdev_get_gpio_in (armv7m, spi_irq[i])); + +/* Alias controller SPI bus to the SoC itself */ + bus_name =g_strdup_printf ("spi%d" , i); +object_property_add_alias (OBJECT (s), bus_name, +OBJECT (&s->spi[i]),"spi" , + &error_abort); +g_free (bus_name); + } + +/* Below devices are not modelled yet. */ +create_unimplemented_device ("i2c_0" ,0x40002000 ,0x1000 ); +create_unimplemented_device ("dma" ,0x40003000 ,0x1000 ); +create_unimplemented_device ("watchdog" ,0x40005000 ,0x1000 ); +create_unimplemented_device ("i2c_1" ,0x40012000 ,0x1000 ); +create_unimplemented_device ("gpio" ,0x40013000 ,0x1000 ); +create_unimplemented_device ("hs-dma" ,0x40014000 ,0x1000 ); +create_unimplemented_device ("can" ,0x40015000 ,0x1000 ); +create_unimplemented_device ("rtc" ,0x40017000 ,0x1000 ); +create_unimplemented_device ("apb_config" ,0x40020000 ,0x10000 ); +create_unimplemented_device ("emac" ,0x40041000 ,0x1000 ); +create_unimplemented_device ("usb" ,0x40043000 ,0x1000 ); +} + +static Property m2sxxx_soc_properties[] = { +/* +* part name specifies the type of SmartFusion2 device variant(this +* property is for information purpose only. +*/ +DEFINE_PROP_STRING ("part-name" , MSF2State, part_name), + DEFINE_PROP_UINT64("eNVM-size", MSF2State, envm_size,
MSF2_ENVM_MAX_SIZE),hw/arm/msf2-soc.c new file +32
-0+DEFINE_PROP_UINT64 ("eSRAM-size" , MSF2State, esram_size, +MSF2_ESRAM_MAX_SIZE ), +/* Libero GUI shows 100Mhz as default for clocks */ +DEFINE_PROP_UINT32 ("m3clk" , MSF2State, m3clk,100 *1000000 ), +/* default divisors in Libero GUI */ +DEFINE_PROP_UINT8 ("apb0div" , MSF2State, apb0div,2 ), +DEFINE_PROP_UINT8 ("apb1div" , MSF2State, apb1div,2 ), + DEFINE_PROP_END_OF_LIST(), +}; + +static void m2sxxx_soc_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = m2sxxx_soc_realize; + dc->props = m2sxxx_soc_properties; +} + +static const TypeInfo m2sxxx_soc_info = { + .name =TYPE_MSF2_SOC , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (MSF2State), + .instance_init = m2sxxx_soc_initfn, + .class_init = m2sxxx_soc_class_init, +}; + +static void m2sxxx_soc_types (void ) +{ +type_register_static (&m2sxxx_soc_info); +} + +type_init (m2sxxx_soc_types)include/hw/arm/msf2-soc.h new file +6
-0@@ -0,0 +1,66 @@ +/* +* Microsemi Smartfusion2 SoC +* +* Copyright (c) 2017 Subbaraya Sundeep <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */include/hw/arm/msf2-soc.h new file +43
-0+ +#ifndef HW_ARM_MSF2_SOC_H +#define HW_ARM_MSF2_SOC_H + +#include "hw/arm/armv7m.h" +#include "hw/timer/mss-timer.h" +#include "hw/misc/msf2-sysreg.h" +#include "hw/ssi/mss-spi.h" + +#define TYPE_MSF2_SOC "msf2-soc" +#define MSF2_SOC (obj) OBJECT_CHECK(MSF2State, (obj), TYPE_MSF2_SOC) + +#define MSF2_NUM_SPIS 2 +#define MSF2_NUM_UARTS 2 + +/* +* System timer consists of two programmable 32-bit +* decrementing counters that generate individual interrupts to +* the Cortex-M3 processor +*/ +#define MSF2_NUM_TIMERS 2 + +typedef struct MSF2State { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +ARMv7MState armv7m; + +char *part_name; +uint64_t envm_size; +uint64_t esram_size; + +uint32_t m3clk; +uint8_t apb0div; +uint8_t apb1div; + +MSF2SysregState sysreg; +MSSTimerState timer; +MSSSpiState spi[MSF2_NUM_SPIS ]; +}MSF2State ; + +#endif
PATCH v10 5/5 msf2: Add Emcraft's Smartfusion2 SOM kit
In reply to Subbaraya SundeepEmulated Emcraft's Smartfusion2 System On Module starter kit.
--- hw/arm/Makefile.objs | 2 +- hw/arm/msf2-som.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 hw/arm/msf2-som.c
hw/arm/Makefile.objs +1 -1
@@ -19,4 +19,4 @@ obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o sabrelite.o obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o obj-$(CONFIG_MPS2) += mps2.o -obj-$(CONFIG_MSF2) += msf2-soc.o +obj-$(CONFIG_MSF2) += msf2-soc.o msf2-som.o
hw/arm/msf2-som.c new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
2.5.0