Add support for Smartfusion2 SoC
v9 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
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
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 | 168 +++++++++++++++++ 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, 1462 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 v9 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
Re: [Qemu-arm] [Qemu devel v9 PATCH 1/5] msf2: Add Smartfusion2 System timer
Quoted 5 lines · Subbaraya Sundeep
Modelled System Timer in Microsemi's Smartfusion2 Soc. Timer has two 32bit down counters and two interrupts.
Signed-off-by Subbaraya Sundeep <[email protected]>Reviewed-by Alistair Francis <[email protected]>
PATCH v9 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 | 168 ++++++++++++++++++++++++++++++++++++++++++ hw/misc/trace-events | 5 ++ include/hw/misc/msf2-sysreg.h | 77 +++++++++++++++++++ 4 files changed, 251 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 +168 -0
168 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
Re: [Qemu-arm] [Qemu devel v9 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block
Hi Sundeep, Peter,
Quoted 63 lines · Subbaraya Sundeep
Added Sytem register block of Smartfusion2.
This block has PLL registers which are accessed by guest.Signed-off-by Subbaraya Sundeep <[email protected]>Reviewed-by Alistair Francis <[email protected]>--- hw/misc/Makefile.objs | 1 + hw/misc/msf2-sysreg.c | 168 ++++++++++++++++++++++++++++++++++++++++++ hw/misc/trace-events | 5 ++ include/hw/misc/msf2-sysreg.h | 77 +++++++++++++++++++ 4 files changed, 251 insertions(+)create mode 100644
hw/misc/msf2-sysreg.ccreate mode 100644include/hw/misc/msf2-sysreg.hhw/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.ohw/misc/msf2-sysreg.c new file +34
-0@@ -0,0 +1,168 @@ +/* +* System Register block model of Microsemi SmartFusion2. +* +* Copyright (c) 2017 Subbaraya Sundeep <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "hw/misc/msf2-sysreg.h" +#include "trace.h" + +static inline int msf2_divbits (uint32_t div) +{ +int ret =0 ; + +switch (div) { +case 1 : + ret =0 ; +break ; +case 2 : + ret =1 ; +break ; +case 4 : + ret =2 ; +break ; +case 8 :
hw/misc/msf2-sysreg.c line 44
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +10
-0+ ret =4 ; +break ; +case 16 : + ret =5 ; +break ; +case 32 : + ret =6 ; +break ; +default : +break ;
eh?
hw/misc/msf2-sysreg.c line 56
Quoted 12 lines
hw/misc/msf2-sysreg.c new file +12
-0+ } + +return ret; +} + +static void msf2_sysreg_reset (DeviceState *d) +{ +MSF2SysregState *s =MSF2_SYSREG (d); + + s->regs[MSSDDR_PLL_STATUS_LOW_CR ] =0x021A2358 ; + s->regs[MSSDDR_PLL_STATUS ] =0x3 ; + s->regs[MSSDDR_FACC1_CR] = msf2_divbits(s->apb0div) << 5 |
ctz32(s->apb0div) << 5 ...
Quoted 31 lines
hw/misc/msf2-sysreg.c new file +31
-0+msf2_divbits (s->apb1div) <<2 ; +} + +static uint64_t msf2_sysreg_read (void *opaque,hwaddr offset, +unsigned size) +{ +MSF2SysregState *s = opaque; +uint32_t ret =0 ; + + offset >>=2 ; +if (offset <ARRAY_SIZE (s->regs)) { + ret = s->regs[offset]; +trace_msf2_sysreg_read (offset <<2 , ret); + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Bad offset 0x%08" HWADDR_PRIx"\n" , __func__, + offset <<2 ); + } + +return ret; +} + +static void msf2_sysreg_write (void *opaque,hwaddr offset, +uint64_t val,unsigned size) +{ +MSF2SysregState *s = opaque; +uint32_t newval = val; + + offset >>=2 ; + +switch (offset) {
hw/misc/msf2-sysreg.c line 97
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +10
-0+case MSSDDR_PLL_STATUS : +trace_msf2_sysreg_write_pll_status (); +break ; + +case ESRAM_CR : +case DDR_CR : +case ENVM_REMAP_BASE_CR : +if (newval != s->regs[offset]) { +qemu_log_mask (LOG_UNIMP , +TYPE_MSF2_SYSREG ": remapping not supported\n" );
I'd rather exit here than continue with inconsistent cpu, Peter what do you recommend?
Quoted 35 lines
hw/misc/msf2-sysreg.c new file +35
-0+ } +break ; + +default : +if (offset <ARRAY_SIZE (s->regs)) { +trace_msf2_sysreg_write (offset <<2 , newval, s->regs[offset]); + s->regs[offset] = newval; + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Bad offset 0x%08" HWADDR_PRIx"\n" , __func__, + offset <<2 ); + } +break ; + } +} + +static const MemoryRegionOps sysreg_ops = { + .read = msf2_sysreg_read, + .write = msf2_sysreg_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static void msf2_sysreg_init (Object *obj) +{ +MSF2SysregState *s =MSF2_SYSREG (obj); + +memory_region_init_io (&s->iomem, obj, &sysreg_ops, s,TYPE_MSF2_SYSREG , +MSF2_SYSREG_MMIO_SIZE ); +sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->iomem); +} + +static const VMStateDescription vmstate_msf2_sysreg = { + .name =TYPE_MSF2_SYSREG , + .version_id =1 , + .minimum_version_id =1 ,
hw/misc/msf2-sysreg.c line 142
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +10
-0+ .fields = (VMStateField[]) { +VMSTATE_UINT32_ARRAY (regs, MSF2SysregState,MSF2_SYSREG_MMIO_SIZE /4 ), +VMSTATE_END_OF_LIST () + } +}; + +static Property msf2_sysreg_properties[] = { +/* default divisors in Libero GUI */ +DEFINE_PROP_UINT32 ("apb0divisor" , MSF2SysregState, apb0div,2 ), +DEFINE_PROP_UINT32 ("apb1divisor" , MSF2SysregState, apb1div,2 ),
DEFINE_PROP_UINT8() is enough for both.
Beware these divisors must be power of 2, and maximum 32.
This can be checked in msf2_sysreg_realize() ...
hw/misc/msf2-sysreg.c line 151
Quoted 9 lines
hw/misc/msf2-sysreg.c new file +9
-0+ DEFINE_PROP_END_OF_LIST(), +}; + +static void msf2_sysreg_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->vmsd = &vmstate_msf2_sysreg; + dc->reset = msf2_sysreg_reset;
... which would go here:
dc->realize = msf2_sysreg_realize;
Quoted 98 lines
hw/misc/msf2-sysreg.c new file +17
-0+ dc->props = msf2_sysreg_properties; +} + +static const TypeInfo msf2_sysreg_info = { + .name =TYPE_MSF2_SYSREG , + .parent =TYPE_SYS_BUS_DEVICE , + .class_init = msf2_sysreg_class_init, + .instance_size =sizeof (MSF2SysregState), + .instance_init = msf2_sysreg_init, +}; + +static void msf2_sysreg_register_types (void ) +{ +type_register_static (&msf2_sysreg_info); +} + +type_init (msf2_sysreg_register_types)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 +62
-0@@ -0,0 +1,77 @@ +/* +* Microsemi SmartFusion2 SYSREG +* +* 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_MSF2_SYSREG_H +#define HW_MSF2_SYSREG_H + +#include "hw/sysbus.h" + +enum { +ESRAM_CR =0x00 /4 , +ESRAM_MAX_LAT , +DDR_CR , +ENVM_CR , +ENVM_REMAP_BASE_CR , +ENVM_REMAP_FAB_CR , +CC_CR , +CC_REGION_CR , +CC_LOCK_BASE_ADDR_CR , +CC_FLUSH_INDX_CR , +DDRB_BUF_TIMER_CR , +DDRB_NB_ADDR_CR , +DDRB_NB_SIZE_CR , +DDRB_CR , + +SOFT_RESET_CR =0x48 /4 , +M3_CR , + +GPIO_SYSRESET_SEL_CR =0x58 /4 , + +MDDR_CR =0x60 /4 , + +MSSDDR_PLL_STATUS_LOW_CR =0x90 /4 , +MSSDDR_PLL_STATUS_HIGH_CR , +MSSDDR_FACC1_CR , +MSSDDR_FACC2_CR , + +MSSDDR_PLL_STATUS =0x150 /4 , +}; + +#define MSF2_SYSREG_MMIO_SIZE 0x300 +
include/hw/misc/msf2-sysreg.h line 72
Quoted 10 lines
include/hw/misc/msf2-sysreg.h new file +10
-0+#define TYPE_MSF2_SYSREG "msf2-sysreg" +#define MSF2_SYSREG (obj) OBJECT_CHECK(MSF2SysregState, (obj), TYPE_MSF2_SYSREG) + +typedef struct MSF2SysregState { + SysBusDevice parent_obj; + + MemoryRegion iomem; + + uint32_t apb0div; + uint32_t apb1div;
uint8_t for both
include/hw/misc/msf2-sysreg.h line 77
Quoted 6 lines
include/hw/misc/msf2-sysreg.h new file +5
-0+ + uint32_t regs[MSF2_SYSREG_MMIO_SIZE / 4]; +} MSF2SysregState; + +#endif /* HW_MSF2_SYSREG_H */
Re: [Qemu-devel] [Qemu devel v9 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block
Hi Philippe,
Quoted 85 lines · Philippe Mathieu-Daudé
Hi Sundeep, Peter,
Quoted 66 lines · Subbaraya Sundeep
Added Sytem register block of Smartfusion2.
This block has PLL registers which are accessed by guest.Signed-off-by Subbaraya Sundeep <[email protected]>Reviewed-by Alistair Francis <[email protected]>--- hw/misc/Makefile.objs | 1 + hw/misc/msf2-sysreg.c | 168 ++++++++++++++++++++++++++++++ ++++++++++++ hw/misc/trace-events | 5 ++ include/hw/misc/msf2-sysreg.h | 77 +++++++++++++++++++ 4 files changed, 251 insertions(+)create mode 100644
hw/misc/msf2-sysreg.ccreate mode 100644include/hw/misc/msf2-sysreg.hhw/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.ohw/misc/msf2-sysreg.c new file +11
-0@@ -0,0 +1,168 @@ +/* +* System Register block model of Microsemi SmartFusion2. +* +* Copyright (c) 2017 Subbaraya Sundeep <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +* +* You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */hw/misc/msf2-sysreg.c new file +21
-0+ +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "hw/misc/msf2-sysreg.h" +#include "trace.h" + +static inline int msf2_divbits (uint32_t div) +{ +int ret =0 ; + +switch (div) { +case 1 : + ret =0 ; +break ; +case 2 : + ret =1 ; +break ; +case 4 : + ret =2 ; +break ; +case 8 :hw/misc/msf2-sysreg.c line 44
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +10
-0+ ret =4 ; +break ; +case 16 : + ret =5 ; +break ; +case 32 : + ret =6 ; +break ; +default : +break ;eh?
+ }
Quoted 14 lines
hw/misc/msf2-sysreg.c line 56
Quoted 12 lines
hw/misc/msf2-sysreg.c new file +11
-0+ +return ret; +} + +static void msf2_sysreg_reset (DeviceState *d) +{ +MSF2SysregState *s =MSF2_SYSREG (d); + + s->regs[MSSDDR_PLL_STATUS_LOW_CR ] =0x021A2358 ; + s->regs[MSSDDR_PLL_STATUS ] =0x3 ; + s->regs[MSSDDR_FACC1_CR] = msf2_divbits(s->apb0div) << 5 |
ctz32(s->apb0div)<< 5 ...
I will modify like below:
div0 = s->apb0div < 8 ? ctz32(s->apb0div) : ctz32(s->apb0div) + 1; div1 = s->apb1div < 8 ? ctz32(s->apb1div) : ctz32(s->apb1div) + 1; s->regs[MSSDDR_FACC1_CR] = div0 << 5 | div1 << 2;
Quoted 101 lines
+
msf2_divbits(s->apb1div)<< 2;Quoted 31 lines
hw/misc/msf2-sysreg.c new file +30
-0+} + +static uint64_t msf2_sysreg_read (void *opaque,hwaddr offset, +unsigned size) +{ +MSF2SysregState *s = opaque; +uint32_t ret =0 ; + + offset >>=2 ; +if (offset <ARRAY_SIZE (s->regs)) { + ret = s->regs[offset]; +trace_msf2_sysreg_read (offset <<2 , ret); + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Bad offset 0x%08" HWADDR_PRIx"\n" , __func__, + offset <<2 ); + } + +return ret; +} + +static void msf2_sysreg_write (void *opaque,hwaddr offset, +uint64_t val,unsigned size) +{ +MSF2SysregState *s = opaque; +uint32_t newval = val; + + offset >>=2 ; + +switch (offset) {hw/misc/msf2-sysreg.c line 97
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +10
-0+case MSSDDR_PLL_STATUS : +trace_msf2_sysreg_write_pll_status (); +break ; + +case ESRAM_CR : +case DDR_CR : +case ENVM_REMAP_BASE_CR : +if (newval != s->regs[offset]) { +qemu_log_mask (LOG_UNIMP , +TYPE_MSF2_SYSREG ": remapping not supported\n" );I'd rather exit here than continue with inconsistent cpu, Peter what do you recommend?
+ }
Quoted 41 lines
hw/misc/msf2-sysreg.c new file +5
-0+break ; + +default : +if (offset <ARRAY_SIZE (s->regs)) { + trace_msf2_sysreg_write(offset << 2, newval,s->regs[offset]);
hw/misc/msf2-sysreg.c new file +4
-0+ s->regs[offset] = newval; + }else { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Bad offset 0x%08" HWADDR_PRIx "\n",
__func__,hw/misc/msf2-sysreg.c new file +17
-0+ offset << 2); + } +break ; + } +} + +static const MemoryRegionOps sysreg_ops = { + .read = msf2_sysreg_read, + .write = msf2_sysreg_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static void msf2_sysreg_init (Object *obj) +{ +MSF2SysregState *s =MSF2_SYSREG (obj); + + memory_region_init_io(&s->iomem, obj, &sysreg_ops, s,
TYPE_MSF2_SYSREG,hw/misc/msf2-sysreg.c new file +10
-0+ MSF2_SYSREG_MMIO_SIZE); +sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->iomem); +} + +static const VMStateDescription vmstate_msf2_sysreg = { + .name =TYPE_MSF2_SYSREG , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { + VMSTATE_UINT32_ARRAY(regs, MSF2SysregState,
MSF2_SYSREG_MMIO_SIZE/ 4),hw/misc/msf2-sysreg.c line 142
Quoted 8 lines
hw/misc/msf2-sysreg.c new file +8
-0+ VMSTATE_END_OF_LIST() + } +}; + +static Property msf2_sysreg_properties[] = { +/* default divisors in Libero GUI */ +DEFINE_PROP_UINT32 ("apb0divisor" , MSF2SysregState, apb0div,2 ), +DEFINE_PROP_UINT32 ("apb1divisor" , MSF2SysregState, apb1div,2 ),
DEFINE_PROP_UINT8()is enough for both.
Quoted 1 line
Beware these divisors must be power of 2, and maximum 32.
This can be checked in msf2_sysreg_realize() ...
Ok
Quoted 143 lines
+
DEFINE_PROP_END_OF_LIST(),hw/misc/msf2-sysreg.c line 151
Quoted 9 lines
hw/misc/msf2-sysreg.c new file +8
-0+}; + +static void msf2_sysreg_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->vmsd = &vmstate_msf2_sysreg; + dc->reset = msf2_sysreg_reset;... which would go here:
dc->realize = msf2_sysreg_realize;Ok.
+
dc->props=msf2_sysreg_properties;Quoted 122 lines
hw/misc/msf2-sysreg.c new file +16
-0+} + +static const TypeInfo msf2_sysreg_info = { + .name =TYPE_MSF2_SYSREG , + .parent =TYPE_SYS_BUS_DEVICE , + .class_init = msf2_sysreg_class_init, + .instance_size =sizeof (MSF2SysregState), + .instance_init = msf2_sysreg_init, +}; + +static void msf2_sysreg_register_types (void ) +{ +type_register_static (&msf2_sysreg_info); +} + +type_init (msf2_sysreg_register_types)hw/misc/trace-events +0
-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%" PRIx32hw/misc/trace-events +3
-0+ +# 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_tval) "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. renamed from include/hw/misc/msf2-sysreg.h +0
-0h
new file mode 100644
index 0000000..231f827include/hw/misc/msf2-sysreg.h new file +6
-0@@ -0,0 +1,77 @@ +/* +* Microsemi SmartFusion2 SYSREG +* +* 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/misc/msf2-sysreg.h new file +41
-0+ +#ifndef HW_MSF2_SYSREG_H +#define HW_MSF2_SYSREG_H + +#include "hw/sysbus.h" + +enum { +ESRAM_CR =0x00 /4 , +ESRAM_MAX_LAT , +DDR_CR , +ENVM_CR , +ENVM_REMAP_BASE_CR , +ENVM_REMAP_FAB_CR , +CC_CR , +CC_REGION_CR , +CC_LOCK_BASE_ADDR_CR , +CC_FLUSH_INDX_CR , +DDRB_BUF_TIMER_CR , +DDRB_NB_ADDR_CR , +DDRB_NB_SIZE_CR , +DDRB_CR , + +SOFT_RESET_CR =0x48 /4 , +M3_CR , + +GPIO_SYSRESET_SEL_CR =0x58 /4 , + +MDDR_CR =0x60 /4 , + +MSSDDR_PLL_STATUS_LOW_CR =0x90 /4 , +MSSDDR_PLL_STATUS_HIGH_CR , +MSSDDR_FACC1_CR , +MSSDDR_FACC2_CR , + +MSSDDR_PLL_STATUS =0x150 /4 , +}; + +#define MSF2_SYSREG_MMIO_SIZE 0x300 + +#define TYPE_MSF2_SYSREG "msf2-sysreg" +#define MSF2_SYSREG (obj) OBJECT_CHECK(MSF2SysregState, (obj),
TYPE_MSF2_SYSREG)include/hw/misc/msf2-sysreg.h new file +3
-0+ +typedef struct MSF2SysregState { + SysBusDevice parent_obj;
Quoted 8 lines
include/hw/misc/msf2-sysreg.h line 72
Quoted 6 lines
include/hw/misc/msf2-sysreg.h new file +5
-0+ +MemoryRegion iomem; + +uint32_t apb0div; +uint32_t apb1div;
uint8_tfor both
Ok.
Quoted 12 lines
+
include/hw/misc/msf2-sysreg.h line 77
Quoted 6 lines
include/hw/misc/msf2-sysreg.h new file +4
-0+ uint32_t regs[MSF2_SYSREG_MMIO_SIZE / 4]; +} MSF2SysregState; + +#endif /* HW_MSF2_SYSREG_H */
Thank you,
Sundeep
Re: [Qemu-arm] [Qemu devel v9 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block
Quoted 106 lines · sundeep subbaraya
Hi Philippe,
Quoted 85 lines · Philippe Mathieu-Daudé
Hi Sundeep, Peter,
Quoted 66 lines · Subbaraya Sundeep
Added Sytem register block of Smartfusion2.
This block has PLL registers which are accessed by guest.Signed-off-by Subbaraya Sundeep <[email protected]>Reviewed-by Alistair Francis <[email protected]>--- hw/misc/Makefile.objs | 1 + hw/misc/msf2-sysreg.c | 168 ++++++++++++++++++++++++++++++++++++++++++ hw/misc/trace-events | 5 ++ include/hw/misc/msf2-sysreg.h | 77 +++++++++++++++++++ 4 files changed, 251 insertions(+)create mode 100644
hw/misc/msf2-sysreg.ccreate mode 100644include/hw/misc/msf2-sysreg.hhw/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.ohw/misc/msf2-sysreg.c new file +11
-0@@ -0,0 +1,168 @@ +/* +* System Register block model of Microsemi SmartFusion2. +* +* Copyright (c) 2017 Subbaraya Sundeep <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +* +* You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */hw/misc/msf2-sysreg.c new file +21
-0+ +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "hw/misc/msf2-sysreg.h" +#include "trace.h" + +static inline int msf2_divbits (uint32_t div) +{ +int ret =0 ; + +switch (div) { +case 1 : + ret =0 ; +break ; +case 2 : + ret =1 ; +break ; +case 4 : + ret =2 ; +break ; +case 8 :hw/misc/msf2-sysreg.c line 44
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +10
-0+ ret =4 ; +break ; +case 16 : + ret =5 ; +break ; +case 32 : + ret =6 ; +break ; +default : +break ;eh?
Quoted 15 lines
hw/misc/msf2-sysreg.c line 56
Quoted 12 lines
hw/misc/msf2-sysreg.c new file +12
-0+ } + +return ret; +} + +static void msf2_sysreg_reset (DeviceState *d) +{ +MSF2SysregState *s =MSF2_SYSREG (d); + + s->regs[MSSDDR_PLL_STATUS_LOW_CR ] =0x021A2358 ; + s->regs[MSSDDR_PLL_STATUS ] =0x3 ; + s->regs[MSSDDR_FACC1_CR] = msf2_divbits(s->apb0div) << 5 |
ctz32(s->apb0div)<< 5 ...
Quoted 3 lines
I will modify like below:
div0 =s->apb0div< 8 ?ctz32(s->apb0div):ctz32(s->apb0div)+ 1; div1 =s->apb1div< 8 ?ctz32(s->apb1div):ctz32(s->apb1div)+ 1;
I think you should keep an msf2_divbits() function for that, even if it's only
static inline int msf2_divbits(uint32_t div)
{
int r = ctz32(div);
return (div < 8) ? r : r + 1;
}thanks
-- PMM
Re: [Qemu-arm] [Qemu devel v9 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block
H Peter,
Quoted 116 lines · Peter Maydell
Quoted 107 lines · sundeep subbaraya
Hi Philippe,
On Mon, Sep 18, 2017 at 6:31 AM, Philippe Mathieu-Daudé <[email protected]
Quoted 85 lines · wrote:
Hi Sundeep, Peter,
Quoted 66 lines · Subbaraya Sundeep
Added Sytem register block of Smartfusion2.
This block has PLL registers which are accessed by guest.Signed-off-by Subbaraya Sundeep <[email protected]>Reviewed-by Alistair Francis <[email protected]>--- hw/misc/Makefile.objs | 1 + hw/misc/msf2-sysreg.c | 168 ++++++++++++++++++++++++++++++++++++++++++ hw/misc/trace-events | 5 ++ include/hw/misc/msf2-sysreg.h | 77 +++++++++++++++++++ 4 files changed, 251 insertions(+)create mode 100644
hw/misc/msf2-sysreg.ccreate mode 100644include/hw/misc/msf2-sysreg.hhw/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.ohw/misc/msf2-sysreg.c new file +11
-0@@ -0,0 +1,168 @@ +/* +* System Register block model of Microsemi SmartFusion2. +* +* Copyright (c) 2017 Subbaraya Sundeep <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +* +* You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */hw/misc/msf2-sysreg.c new file +21
-0+ +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "hw/misc/msf2-sysreg.h" +#include "trace.h" + +static inline int msf2_divbits (uint32_t div) +{ +int ret =0 ; + +switch (div) { +case 1 : + ret =0 ; +break ; +case 2 : + ret =1 ; +break ; +case 4 : + ret =2 ; +break ; +case 8 :hw/misc/msf2-sysreg.c line 44
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +10
-0+ ret =4 ; +break ; +case 16 : + ret =5 ; +break ; +case 32 : + ret =6 ; +break ; +default : +break ;eh?
Quoted 15 lines
hw/misc/msf2-sysreg.c line 56
Quoted 12 lines
hw/misc/msf2-sysreg.c new file +12
-0+ } + +return ret; +} + +static void msf2_sysreg_reset (DeviceState *d) +{ +MSF2SysregState *s =MSF2_SYSREG (d); + + s->regs[MSSDDR_PLL_STATUS_LOW_CR ] =0x021A2358 ; + s->regs[MSSDDR_PLL_STATUS ] =0x3 ; + s->regs[MSSDDR_FACC1_CR] = msf2_divbits(s->apb0div) << 5 |
ctz32(s->apb0div)<< 5 ...Quoted 3 lines
I will modify like below:
div0 =s->apb0div< 8 ?ctz32(s->apb0div):ctz32(s->apb0div)+ 1; div1 =s->apb1div< 8 ?ctz32(s->apb1div):ctz32(s->apb1div)+ 1;I think you should keep an
msf2_divbits()function for that, even if it's only
Quoted 8 lines
static inline int
msf2_divbits(uint32_t div){ int r = ctz32(div); return (div < 8) ? r : r + 1; }Ok will change like this.
Thanks,
Sundeep
Quoted 3 lines
thanks
-- PMM
Re: [Qemu-arm] [Qemu devel v9 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block
In reply to sundeep subbarayaHi Peter,
Quoted 106 lines · sundeep subbaraya
Hi Philippe,
Quoted 85 lines · Philippe Mathieu-Daudé
Hi Sundeep, Peter,
Quoted 66 lines · Subbaraya Sundeep
Added Sytem register block of Smartfusion2.
This block has PLL registers which are accessed by guest.Signed-off-by Subbaraya Sundeep <[email protected]>Reviewed-by Alistair Francis <[email protected]>--- hw/misc/Makefile.objs | 1 + hw/misc/msf2-sysreg.c | 168 ++++++++++++++++++++++++++++++ ++++++++++++ hw/misc/trace-events | 5 ++ include/hw/misc/msf2-sysreg.h | 77 +++++++++++++++++++ 4 files changed, 251 insertions(+)create mode 100644
hw/misc/msf2-sysreg.ccreate mode 100644include/hw/misc/msf2-sysreg.hhw/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.ohw/misc/msf2-sysreg.c new file +11
-0@@ -0,0 +1,168 @@ +/* +* System Register block model of Microsemi SmartFusion2. +* +* Copyright (c) 2017 Subbaraya Sundeep <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +* +* You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */hw/misc/msf2-sysreg.c new file +21
-0+ +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "hw/misc/msf2-sysreg.h" +#include "trace.h" + +static inline int msf2_divbits (uint32_t div) +{ +int ret =0 ; + +switch (div) { +case 1 : + ret =0 ; +break ; +case 2 : + ret =1 ; +break ; +case 4 : + ret =2 ; +break ; +case 8 :hw/misc/msf2-sysreg.c line 44
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +10
-0+ ret =4 ; +break ; +case 16 : + ret =5 ; +break ; +case 32 : + ret =6 ; +break ; +default : +break ;eh?
+ }
Quoted 14 lines
hw/misc/msf2-sysreg.c line 56
Quoted 12 lines
hw/misc/msf2-sysreg.c new file +11
-0+ +return ret; +} + +static void msf2_sysreg_reset (DeviceState *d) +{ +MSF2SysregState *s =MSF2_SYSREG (d); + + s->regs[MSSDDR_PLL_STATUS_LOW_CR ] =0x021A2358 ; + s->regs[MSSDDR_PLL_STATUS ] =0x3 ; + s->regs[MSSDDR_FACC1_CR] = msf2_divbits(s->apb0div) << 5 |
ctz32(s->apb0div)<< 5 ...
Quoted 54 lines
I will modify like below:
div0 =s->apb0div< 8 ?ctz32(s->apb0div):ctz32(s->apb0div)+ 1; div1 =s->apb1div< 8 ?ctz32(s->apb1div):ctz32(s->apb1div)+ 1; s->regs[MSSDDR_FACC1_CR] = div0 << 5 | div1 << 2;Quoted 46 lines
+
msf2_divbits(s->apb1div)<< 2;Quoted 31 lines
hw/misc/msf2-sysreg.c new file +30
-0+} + +static uint64_t msf2_sysreg_read (void *opaque,hwaddr offset, +unsigned size) +{ +MSF2SysregState *s = opaque; +uint32_t ret =0 ; + + offset >>=2 ; +if (offset <ARRAY_SIZE (s->regs)) { + ret = s->regs[offset]; +trace_msf2_sysreg_read (offset <<2 , ret); + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Bad offset 0x%08" HWADDR_PRIx"\n" , __func__, + offset <<2 ); + } + +return ret; +} + +static void msf2_sysreg_write (void *opaque,hwaddr offset, +uint64_t val,unsigned size) +{ +MSF2SysregState *s = opaque; +uint32_t newval = val; + + offset >>=2 ; + +switch (offset) {hw/misc/msf2-sysreg.c line 97
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +10
-0+case MSSDDR_PLL_STATUS : +trace_msf2_sysreg_write_pll_status (); +break ; + +case ESRAM_CR : +case DDR_CR : +case ENVM_REMAP_BASE_CR : +if (newval != s->regs[offset]) { +qemu_log_mask (LOG_UNIMP , +TYPE_MSF2_SYSREG ": remapping not supported\n" );I'd rather exit here than continue with inconsistent cpu, Peter what do you recommend?
Could you please suggest.
Thanks,
Sundeep
Quoted 233 lines
Quoted 55 lines
+ }
Quoted 41 lines
hw/misc/msf2-sysreg.c new file +5
-0+break ; + +default : +if (offset <ARRAY_SIZE (s->regs)) { + trace_msf2_sysreg_write(offset << 2, newval,s->regs[offset]);
hw/misc/msf2-sysreg.c new file +4
-0+ s->regs[offset] = newval; + }else { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Bad offset 0x%08" HWADDR_PRIx "\n",
__func__,hw/misc/msf2-sysreg.c new file +17
-0+ offset << 2); + } +break ; + } +} + +static const MemoryRegionOps sysreg_ops = { + .read = msf2_sysreg_read, + .write = msf2_sysreg_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static void msf2_sysreg_init (Object *obj) +{ +MSF2SysregState *s =MSF2_SYSREG (obj); + + memory_region_init_io(&s->iomem, obj, &sysreg_ops, s,
TYPE_MSF2_SYSREG,hw/misc/msf2-sysreg.c new file +10
-0+ MSF2_SYSREG_MMIO_SIZE); +sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->iomem); +} + +static const VMStateDescription vmstate_msf2_sysreg = { + .name =TYPE_MSF2_SYSREG , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { + VMSTATE_UINT32_ARRAY(regs, MSF2SysregState,
MSF2_SYSREG_MMIO_SIZE/ 4),hw/misc/msf2-sysreg.c line 142
Quoted 8 lines
hw/misc/msf2-sysreg.c new file +8
-0+ VMSTATE_END_OF_LIST() + } +}; + +static Property msf2_sysreg_properties[] = { +/* default divisors in Libero GUI */ +DEFINE_PROP_UINT32 ("apb0divisor" , MSF2SysregState, apb0div,2 ), +DEFINE_PROP_UINT32 ("apb1divisor" , MSF2SysregState, apb1div,2 ),
DEFINE_PROP_UINT8()is enough for both.Quoted 1 line
Beware these divisors must be power of 2, and maximum 32.
This can be checked in
msf2_sysreg_realize()...Ok
Quoted 143 lines
+
DEFINE_PROP_END_OF_LIST(),hw/misc/msf2-sysreg.c line 151
Quoted 9 lines
hw/misc/msf2-sysreg.c new file +8
-0+}; + +static void msf2_sysreg_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->vmsd = &vmstate_msf2_sysreg; + dc->reset = msf2_sysreg_reset;... which would go here:
dc->realize = msf2_sysreg_realize;Ok.
+
dc->props=msf2_sysreg_properties;Quoted 122 lines
hw/misc/msf2-sysreg.c new file +16
-0+} + +static const TypeInfo msf2_sysreg_info = { + .name =TYPE_MSF2_SYSREG , + .parent =TYPE_SYS_BUS_DEVICE , + .class_init = msf2_sysreg_class_init, + .instance_size =sizeof (MSF2SysregState), + .instance_init = msf2_sysreg_init, +}; + +static void msf2_sysreg_register_types (void ) +{ +type_register_static (&msf2_sysreg_info); +} + +type_init (msf2_sysreg_register_types)hw/misc/trace-events +0
-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%" PRIx32hw/misc/trace-events +3
-0+ +# 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_tval) "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 +6
-0@@ -0,0 +1,77 @@ +/* +* Microsemi SmartFusion2 SYSREG +* +* 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/misc/msf2-sysreg.h new file +41
-0+ +#ifndef HW_MSF2_SYSREG_H +#define HW_MSF2_SYSREG_H + +#include "hw/sysbus.h" + +enum { +ESRAM_CR =0x00 /4 , +ESRAM_MAX_LAT , +DDR_CR , +ENVM_CR , +ENVM_REMAP_BASE_CR , +ENVM_REMAP_FAB_CR , +CC_CR , +CC_REGION_CR , +CC_LOCK_BASE_ADDR_CR , +CC_FLUSH_INDX_CR , +DDRB_BUF_TIMER_CR , +DDRB_NB_ADDR_CR , +DDRB_NB_SIZE_CR , +DDRB_CR , + +SOFT_RESET_CR =0x48 /4 , +M3_CR , + +GPIO_SYSRESET_SEL_CR =0x58 /4 , + +MDDR_CR =0x60 /4 , + +MSSDDR_PLL_STATUS_LOW_CR =0x90 /4 , +MSSDDR_PLL_STATUS_HIGH_CR , +MSSDDR_FACC1_CR , +MSSDDR_FACC2_CR , + +MSSDDR_PLL_STATUS =0x150 /4 , +}; + +#define MSF2_SYSREG_MMIO_SIZE 0x300 + +#define TYPE_MSF2_SYSREG "msf2-sysreg" +#define MSF2_SYSREG (obj) OBJECT_CHECK(MSF2SysregState, (obj),
TYPE_MSF2_SYSREG)include/hw/misc/msf2-sysreg.h new file +3
-0+ +typedef struct MSF2SysregState { + SysBusDevice parent_obj;Quoted 8 lines
include/hw/misc/msf2-sysreg.h line 72
Quoted 6 lines
include/hw/misc/msf2-sysreg.h new file +5
-0+ +MemoryRegion iomem; + +uint32_t apb0div; +uint32_t apb1div;
uint8_tfor bothOk.
Quoted 12 lines
+
include/hw/misc/msf2-sysreg.h line 77
Quoted 6 lines
include/hw/misc/msf2-sysreg.h new file +4
-0+ uint32_t regs[MSF2_SYSREG_MMIO_SIZE / 4]; +} MSF2SysregState; + +#endif /* HW_MSF2_SYSREG_H */ Thank you,
Sundeep
Re: [Qemu-devel] [Qemu devel v9 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block
Quoted 40 lines · sundeep subbaraya
Hi Peter,
Quoted 34 lines · sundeep subbaraya
Hi Philippe,
Quoted 29 lines · Philippe Mathieu-Daudé
Hi Sundeep, Peter,
Quoted 10 lines · Subbaraya Sundeep
hw/misc/msf2-sysreg.c new file +9
-0+static void msf2_sysreg_write (void *opaque,hwaddr offset, +uint64_t val,unsigned size) +{ +MSF2SysregState *s = opaque; +uint32_t newval = val; + + offset >>=2 ; + +switch (offset) {hw/misc/msf2-sysreg.c line 97
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +10
-0+case MSSDDR_PLL_STATUS : +trace_msf2_sysreg_write_pll_status (); +break ; + +case ESRAM_CR : +case DDR_CR : +case ENVM_REMAP_BASE_CR : +if (newval != s->regs[offset]) { +qemu_log_mask (LOG_UNIMP , +TYPE_MSF2_SYSREG ": remapping not supported\n" );I'd rather exit here than continue with inconsistent cpu, Peter what do you recommend?
Quoted 1 line
Could you please suggest.
We shouldn't exit QEMU for something the guest can provoke. If the functionality isn't implemented then just LOG_UNIMP it.
thanks
-- PMM
Re: [Qemu-devel] [Qemu devel v9 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block
Hi Peter,
Quoted 31 lines · Peter Maydell
Quoted 30 lines · sundeep subbaraya
Quoted 28 lines
Quoted 28 lines
Hi Sundeep, Peter,
Quoted 10 lines · Subbaraya Sundeep
hw/misc/msf2-sysreg.c new file +9
-0+static void msf2_sysreg_write (void *opaque,hwaddr offset, +uint64_t val,unsigned size) +{ +MSF2SysregState *s = opaque; +uint32_t newval = val; + + offset >>=2 ; + +switch (offset) {hw/misc/msf2-sysreg.c line 97
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +10
-0+case MSSDDR_PLL_STATUS : +trace_msf2_sysreg_write_pll_status (); +break ; + +case ESRAM_CR : +case DDR_CR : +case ENVM_REMAP_BASE_CR : +if (newval != s->regs[offset]) { +qemu_log_mask (LOG_UNIMP , +TYPE_MSF2_SYSREG ": remapping not supported\n" );I'd rather exit here than continue with inconsistent cpu, Peter what do you recommend?
Quoted 4 lines
Quoted 1 line
Could you please suggest.
We shouldn't exit QEMU for something the guest can provoke. If the functionality isn't implemented then just
LOG_UNIMPit.
This was commented here:
http://lists.nongnu.org/archive/html/qemu-devel/2017-05/msg02971.html
Guest remapping code is like non-return function. Hardware error here can not happen, so there is no more guest code after a remap request. Continuing running QEMU will lead to chaos, that's why I recommend aborting instead of just LOG_UNIMP it.
Regards,
Phil.
Re: [Qemu-arm] [Qemu devel v9 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block
Quoted 48 lines · Philippe Mathieu-Daudé
Hi Peter,
Quoted 38 lines · Peter Maydell
Quoted 35 lines · sundeep subbaraya
Quoted 32 lines
Quoted 32 lines
Hi Sundeep, Peter,
Quoted 21 lines · Subbaraya Sundeep
hw/misc/msf2-sysreg.c new file +19
-0+static void msf2_sysreg_write(void *opaque, hwaddr offset, + uint64_t val, unsigned size) +{ + MSF2SysregState *s = opaque; + uint32_t newval = val; + + offset >>= 2; + + switch (offset) { + case MSSDDR_PLL_STATUS: + trace_msf2_sysreg_write_pll_status(); + break; + + case ESRAM_CR: + case DDR_CR: + case ENVM_REMAP_BASE_CR: + if (newval != s->regs[offset]) { + qemu_log_mask(LOG_UNIMP, + TYPE_MSF2_SYSREG": remapping notQuoted 1 line
supported\n");
I'd rather exit here than continue with inconsistent cpu, Peter what do you recommend?
Quoted 5 lines
Quoted 1 line
Could you please suggest.
We shouldn't exit QEMU for something the guest can provoke. If the functionality isn't implemented then just
LOG_UNIMPit.
Quoted 7 lines
This was commented here:
http://lists.nongnu.org/archive/html/qemu-devel/2017-05/msg02971.htmlGuest remapping code is like non-return function. Hardware error here can not happen, so there is no more guest code after a remap request. Continuing running QEMU will lead to chaos, that's why I recommend aborting instead of just
LOG_UNIMPit.
There's lots of stuff that can cause the guest to go badly and confusingly wrong if unimplemented. If we print a useful message with LOG_UNIMP then there's an easy clue for what's gone wrong. The guest shouldn't be able to provoke QEMU to exit.
thanks
-- PMM
Re: [Qemu-arm] [Qemu devel v9 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block
Quoted 57 lines · Peter Maydell
Quoted 48 lines · Philippe Mathieu-Daudé
Hi Peter,
Quoted 38 lines · Peter Maydell
Quoted 35 lines · sundeep subbaraya
Quoted 32 lines
Quoted 32 lines
Hi Sundeep, Peter,
Quoted 21 lines · Subbaraya Sundeep
(quoted diff) +19
-0+static void msf2_sysreg_write(void *opaque, hwaddr offset, + uint64_t val, unsigned size) +{ + MSF2SysregState *s = opaque; + uint32_t newval = val; + + offset >>= 2; + + switch (offset) { + case MSSDDR_PLL_STATUS: + trace_msf2_sysreg_write_pll_status(); + break; + + case ESRAM_CR: + case DDR_CR: + case ENVM_REMAP_BASE_CR: + if (newval != s->regs[offset]) { + qemu_log_mask(LOG_UNIMP, + TYPE_MSF2_SYSREG": remapping notQuoted 1 line
supported\n");
I'd rather exit here than continue with inconsistent cpu, Peter what do you recommend?
Quoted 5 lines
Quoted 1 line
Could you please suggest.
We shouldn't exit QEMU for something the guest can provoke. If the functionality isn't implemented then just
LOG_UNIMPit.Quoted 7 lines
This was commented here:
http://lists.nongnu.org/archive/html/qemu-devel/2017-05/msg02971.htmlGuest remapping code is like non-return function. Hardware error here can not happen, so there is no more guest code after a remap request. Continuing running QEMU will lead to chaos, that's why I recommend aborting instead of just
LOG_UNIMPit.
Quoted 5 lines
There's lots of stuff that can cause the guest to go badly and confusingly wrong if unimplemented. If we print a useful message with
LOG_UNIMPthen there's an easy clue for what's gone wrong. The guest shouldn't be able to provoke QEMU to exit.
I understand. I'm worried about being PITA for an user to figure out what's happening here, that's why I'm wondering how this should be handled. Another idea I thought about was raising a PREFETCH or BKPT exception, but this would also be an incorrect model behavior.
Anyway I'd be happy enough if instead of using LOG_UNIMP/LOG_GUEST_ERROR we use an unconditional qemu_log("bus remap unimplemented, unpredictable behaviour!") warning. Fair enough?
Regards,
Phil.
Re: [Qemu-arm] [Qemu devel v9 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Peter Maydell
There's lots of stuff that can cause the guest to go badly and confusingly wrong if unimplemented. If we print a useful message with
LOG_UNIMPthen there's an easy clue for what's gone wrong. The guest shouldn't be able to provoke QEMU to exit.
Quoted 8 lines
I understand. I'm worried about being PITA for an user to figure out what's happening here, that's why I'm wondering how this should be handled. Another idea I thought about was raising a PREFETCH or BKPT exception, but this would also be an incorrect model behavior.
Anyway I'd be happy enough if instead of using LOG_UNIMP/LOG_GUEST_ERROR we use an unconditional
qemu_log("bus remap unimplemented, unpredictable behaviour!")warning. Fair enough?
I don't see any reason to handle this any differently to anything else.
thanks
-- PMM
PATCH v9 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
Re: [Qemu-arm] [Qemu devel v9 PATCH 3/5] msf2: Add Smartfusion2 SPI controller
Quoted 4 lines · Subbaraya Sundeep
Modelled Microsemi's Smartfusion2 SPI controller.
Signed-off-by Subbaraya Sundeep <[email protected]>Reviewed-by Alistair Francis <[email protected]>
PATCH v9 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 v9 PATCH 4/5] msf2: Add Smartfusion2 SoC
Quoted 211 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]>--- 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 +172
-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); +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 ; + } + + 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 */
hw/arm/msf2-soc.c line 182
Quoted 10 lines
hw/arm/msf2-soc.c new file +10
-0+ 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 ("pdma" ,0x40003000 ,0x1000 );
name it "dma" only.
hw/arm/msf2-soc.c line 186
Quoted 4 lines
hw/arm/msf2-soc.c new file +4
-0+create_unimplemented_device ("watchdog" ,0x40005000 ,0x1000 ); +create_unimplemented_device ("i2c_1" ,0x40012000 ,0x1000 ); +create_unimplemented_device ("gpio" ,0x40013000 ,0x1000 ); +create_unimplemented_device ("hpdma" ,0x40014000 ,0x1000 );
"hs-dma" ?
hw/arm/msf2-soc.c line 189
Quoted 3 lines
hw/arm/msf2-soc.c new file +3
-0+create_unimplemented_device ("can" ,0x40015000 ,0x1000 ); +create_unimplemented_device ("rtc" ,0x40017000 ,0x1000 ); +create_unimplemented_device ("apb_config" ,0x40020000 ,0x10000 );
hmm ok.
hw/arm/msf2-soc.c line 192
Quoted 3 lines
hw/arm/msf2-soc.c new file +3
-0+create_unimplemented_device ("emac" ,0x40041000 ,0x1000 ); +create_unimplemented_device ("usb" ,0x40043000 ,0x1000 ); +}
now the cpu memory tree looks:
(qemu) info mtree
address-space: cpu-memory
0000000000000000-ffffffffffffffff (prio 0, i/o): armv7m-container
0000000000000000-ffffffffffffffff (prio -1, i/o): system
0000000000000000-000000000003ffff (prio 0, i/o): alias MSF2.eNVM
@MSF2.eNVM 0000000000000000-000000000003ffff
0000000020000000-000000002000ffff (prio 0, ram): MSF2.eSRAM
0000000040000000-000000004000001f (prio 0, i/o): serial
0000000040001000-000000004000103f (prio 0, i/o): mss-spi
0000000040002000-0000000040002fff (prio -1000, i/o): i2c_0
0000000040003000-0000000040003fff (prio -1000, i/o): pdma
0000000040004000-000000004000402f (prio 0, i/o): mss-timer
0000000040005000-0000000040005fff (prio -1000, i/o): watchdog
0000000040011000-000000004001103f (prio 0, i/o): mss-spi
0000000040012000-0000000040012fff (prio -1000, i/o): i2c_1
0000000040013000-0000000040013fff (prio -1000, i/o): gpio
0000000040014000-0000000040014fff (prio -1000, i/o): hpdma
0000000040015000-0000000040015fff (prio -1000, i/o): can
0000000040017000-0000000040017fff (prio -1000, i/o): rtc
0000000040020000-000000004002ffff (prio -1000, i/o): apb_config
0000000040038000-00000000400382ff (prio 0, i/o): msf2-sysreg
0000000040041000-0000000040041fff (prio -1000, i/o): emac
0000000040043000-0000000040043fff (prio -1000, i/o): usb
0000000060000000-000000006003ffff (prio 0, rom): MSF2.eNVM
00000000a0000000-00000000a3ffffff (prio 0, ram): ddr-ram
0000000022000000-0000000023ffffff (prio 0, i/o): bitband
0000000042000000-0000000043ffffff (prio 0, i/o): bitband
00000000e000e000-00000000e000efff (prio 0, i/o): nvic
00000000e000e000-00000000e000efff (prio 0, i/o): nvic_sysregs
00000000e000e010-00000000e000e0ef (prio 1, i/o): systickQuoted 5 lines
hw/arm/msf2-soc.c new file +5
-0+ +static Property m2sxxx_soc_properties[] = { +/* +* part name specifies the type of SmartFusion2 device variant(this +* property is for information purpose only.
hw/arm/msf2-soc.c line 207
Quoted 10 lines
hw/arm/msf2-soc.c new file +10
-0+*/ +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_UINT32 ("apb0div" , MSF2State, apb0div,2 ), + DEFINE_PROP_UINT32("apb1div", MSF2State, apb1div, 2),
DEFINE_PROP_UINT8 ?
Quoted 80 lines
hw/arm/msf2-soc.c new file +25
-0+ 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 +49
-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 >*/
include/hw/arm/msf2-soc.h line 59
Quoted 10 lines
include/hw/arm/msf2-soc.h new file +10
-0+ +ARMv7MState armv7m; + +char *part_name; +uint64_t envm_size; +uint64_t esram_size; + +uint32_t m3clk; +uint32_t apb0div; +uint32_t apb1div;
uint8_t ?
include/hw/arm/msf2-soc.h line 66
Quoted 8 lines
include/hw/arm/msf2-soc.h new file +7
-0+ +MSF2SysregState sysreg; +MSSTimerState timer; + MSSSpiState spi[MSF2_NUM_SPIS]; +} MSF2State; + +#endif
Re: [Qemu-arm] [Qemu devel v9 PATCH 4/5] msf2: Add Smartfusion2 SoC
Hi Philippe,
Quoted 237 lines · Philippe Mathieu-Daudé
Quoted 235 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]>--- 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 new file +34
-0+if (err !=NULL ) { +error_propagate (errp, err); +return ; + } + + 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);
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 +15
-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);
Quoted 8 lines
hw/arm/msf2-soc.c line 182
Quoted 6 lines
hw/arm/msf2-soc.c new file +5
-0+ } + +/* Below devices are not modelled yet. */ +create_unimplemented_device ("i2c_0" ,0x40002000 ,0x1000 ); +create_unimplemented_device ("pdma" ,0x40003000 ,0x1000 );name it "dma" only.
Just named so that it matches documentation. No strong feelings regd. names. I will change to dma and hs-dma .
Quoted 9 lines
+
create_unimplemented_device("watchdog", 0x40005000, 0x1000);hw/arm/msf2-soc.c line 186
Quoted 4 lines
hw/arm/msf2-soc.c new file +3
-0+create_unimplemented_device ("i2c_1" ,0x40012000 ,0x1000 ); +create_unimplemented_device ("gpio" ,0x40013000 ,0x1000 ); +create_unimplemented_device ("hpdma" ,0x40014000 ,0x1000 );"hs-dma" ?
Ok
Quoted 167 lines
+
create_unimplemented_device("can", 0x40015000, 0x1000);hw/arm/msf2-soc.c line 189
Quoted 3 lines
hw/arm/msf2-soc.c new file +2
-0+create_unimplemented_device ("rtc" ,0x40017000 ,0x1000 ); +create_unimplemented_device ("apb_config" ,0x40020000 ,0x10000 );hmm ok.
+
create_unimplemented_device("emac", 0x40041000, 0x1000);hw/arm/msf2-soc.c
Quoted 3 lines
hw/arm/msf2-soc.c new file +2
-0+create_unimplemented_device ("usb" ,0x40043000 ,0x1000 ); +}now the cpu memory tree looks:
(qemu) info mtree
address-space: cpu-memory
0000000000000000-ffffffffffffffff (prio 0, i/o): armv7m-container0000000000000000-ffffffffffffffff (prio -1, i/o): system 0000000000000000-000000000003ffff (prio 0, i/o): alias MSF2.eNVM @MSF2.eNVM 0000000000000000-000000000003ffff 0000000020000000-000000002000ffff (prio 0, ram): MSF2.eSRAM 0000000040000000-000000004000001f (prio 0, i/o): serial 0000000040001000-000000004000103f (prio 0, i/o): mss-spi 0000000040002000-0000000040002fff (prio -1000, i/o): i2c_0 0000000040003000-0000000040003fff (prio -1000, i/o): pdma 0000000040004000-000000004000402f (prio 0, i/o): mss-timer 0000000040005000-0000000040005fff (prio -1000, i/o): watchdog 0000000040011000-000000004001103f (prio 0, i/o): mss-spi 0000000040012000-0000000040012fff (prio -1000, i/o): i2c_1 0000000040013000-0000000040013fff (prio -1000, i/o): gpio 0000000040014000-0000000040014fff (prio -1000, i/o): hpdma 0000000040015000-0000000040015fff (prio -1000, i/o): can 0000000040017000-0000000040017fff (prio -1000, i/o): rtc 0000000040020000-000000004002ffff (prio -1000, i/o): apb_config 0000000040038000-00000000400382ff (prio 0, i/o): msf2-sysreg 0000000040041000-0000000040041fff (prio -1000, i/o): emac 0000000040043000-0000000040043fff (prio -1000, i/o): usb 0000000060000000-000000006003ffff (prio 0, rom): MSF2.eNVM 00000000a0000000-00000000a3ffffff (prio 0, ram): ddr-ram 0000000022000000-0000000023ffffff (prio 0, i/o): bitband 0000000042000000-0000000043ffffff (prio 0, i/o): bitband 00000000e000e000-00000000e000efff (prio 0, i/o): nvic 00000000e000e000-00000000e000efff (prio 0, i/o): nvic_sysregs 00000000e000e010-00000000e000e0ef (prio 1, i/o): systick+
Quoted 9 lines
hw/arm/msf2-soc.c new file +7
-0+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 line 207
Quoted 7 lines
hw/arm/msf2-soc.c new file +7
-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_UINT32 ("apb0div" , MSF2State, apb0div,2 ), + DEFINE_PROP_UINT32("apb1div", MSF2State, apb1div, 2),
DEFINE_PROP_UINT8?Ok
+
DEFINE_PROP_END_OF_LIST(),Quoted 95 lines
hw/arm/msf2-soc.c new file +24
-0+}; + +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 +31
-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;
Quoted 8 lines
include/hw/arm/msf2-soc.h line 59
Quoted 6 lines
include/hw/arm/msf2-soc.h new file +5
-0+uint64_t esram_size; + +uint32_t m3clk; +uint32_t apb0div; +uint32_t apb1div;
uint8_t?
Ok
Quoted 14 lines
+
include/hw/arm/msf2-soc.h line 66
Quoted 8 lines
include/hw/arm/msf2-soc.h new file +6
-0+MSF2SysregState sysreg; +MSSTimerState timer; + MSSSpiState spi[MSF2_NUM_SPIS]; +} MSF2State; + +#endif Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Thank you,
Sundeep
PATCH v9 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
Re: [Qemu-arm] [Qemu devel v9 PATCH 5/5] msf2: Add Emcraft's Smartfusion2 SOM kit
Quoted 5 lines · Subbaraya Sundeep
Emulated Emcraft's Smartfusion2 System On Module starter kit.
Signed-off-by Subbaraya Sundeep <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Hi Sundeep,
Quoted 10 lines · Subbaraya Sundeep
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.
When a review tag is sent to the series cover, this means it can be added to all the patches from the series.
Quoted 14 lines
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=rawBinaries u-boot.bin and spi.bin are at:
https://github.com/Subbaraya-Sundeep/qemu-test-binaries.gitU-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
Quoted 5 lines
Linux is 4.5 linux with Smartfusion2 SoC dts and clocksource driver added by myself @
https://github.com/Subbaraya-Sundeep/linux.gitv9:
However if you made significant changes to v9, please drop the R-b that were left on v8 to make sure people re-review those changes. Functional changes directly reset Tested-by tags.
$ git backport-diff -r master..msf2_v9 -u msf2_v8 Key: [----] : patches are identical [####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively
001/5:[----] [--] 'msf2: Add Smartfusion2 System timer' 002/5:[0047] [FC] 'msf2: Microsemi Smartfusion2 System Register block' 003/5:[----] [--] 'msf2: Add Smartfusion2 SPI controller' 004/5:[0018] [FC] 'msf2: Add Smartfusion2 SoC'
005/5:[0001] [FC] 'msf2: Add Emcraft's Smartfusion2 SOM kit'
Quoted 4 lines
used trace instead of
DB_PRINTinmsf2-sysreg.cusedLOG_UNIMPfor non guest errors inmsf2-sysreg.cadded unimplemented devices inmsf2-soc.cremoved .alias suffix in alias memory region name for eNVM
you also removed "mc->ignore_memory_transaction_failures" use.
Quoted 7 lines
v8:
memory_region_init_ramtomemory_region_init_romin soc %s/emcraft_sf2_init/emcraft_sf2_s2s010_init/g in som Addedmc->ignore_memory_transaction_failures= true in som
as per latest commit.
Code simplifications as suggested by Alistair in sysreg and ssi.
FYI, testing outputs:
- U-Boot
CPU : SmartFusion2 SoC (Cortex-M3 Hard IP)
Freqs: CORTEX-M3=142MHz,PCLK0=71MHz,PCLK1=71MHz
Board: M2S-FG484-SOM Rev 1A, www.emcraft.comapb_config: unimplemented device write (size 4, value 0x0, offset 0x10)apb_config: unimplemented device write (size 4, value 0x118, offset 0x84)apb_config: unimplemented device write (size 4, value 0xc1, offset 0x18)apb_config: unimplemented device write (size 4, value 0x99f, offset 0x1c)apb_config: unimplemented device write (size 4, value 0x3333, offset 0x24)apb_config: unimplemented device write (size 4, value 0xffff, offset 0x28)apb_config: unimplemented device write (size 4, value 0x3300, offset 0x78)apb_config: unimplemented device write (size 4, value 0x7777, offset 0x2c)apb_config: unimplemented device write (size 4, value 0xfff, offset 0x30)apb_config: unimplemented device write (size 4, value 0x580, offset 0x8)apb_config: unimplemented device write (size 4, value 0x110, offset 0xc)apb_config: unimplemented device write (size 4, value 0x1c00, offset 0x38)apb_config: unimplemented device write (size 4, value 0x8, offset 0x3c)apb_config: unimplemented device write (size 4, value 0xd23, offset 0x6c)apb_config: unimplemented device write (size 4, value 0x240, offset 0x50)apb_config: unimplemented device write (size 4, value 0x2, offset 0x5c)apb_config: unimplemented device write (size 4, value 0x126, offset 0x60)apb_config: unimplemented device write (size 4, value 0x3, offset 0xbc)apb_config: unimplemented device write (size 4, value 0x23, offset 0x54)apb_config: unimplemented device write (size 4, value 0x33, offset 0x40)apb_config: unimplemented device write (size 4, value 0x20, offset 0x44)apb_config: unimplemented device write (size 4, value 0x33, offset 0x80)apb_config: unimplemented device write (size 4, value 0x8, offset 0x7c)apb_config: unimplemented device write (size 4, value 0x4000, offset 0x9c)apb_config: unimplemented device write (size 4, value 0x0, offset 0xb4)apb_config: unimplemented device write (size 4, value 0x107, offset 0x64)apb_config: unimplemented device write (size 4, value 0x104, offset 0x58)apb_config: unimplemented device write (size 4, value 0x11, offset 0x68)apb_config: unimplemented device write (size 4, value 0x80f8, offset 0xa0)apb_config: unimplemented device write (size 4, value 0x7, offset 0xa4)apb_config: unimplemented device write (size 4, value 0x80f8, offset 0xa8)apb_config: unimplemented device write (size 4, value 0x7, offset 0xac)apb_config: unimplemented device write (size 4, value 0x200, offset 0xb0)apb_config: unimplemented device write (size 4, value 0x0, offset 0x21c)apb_config: unimplemented device write (size 4, value 0x80, offset 0x224)apb_config: unimplemented device write (size 4, value 0xf, offset 0x230)apb_config: unimplemented device write (size 4, value 0xb, offset 0x248)apb_config: unimplemented device write (size 4, value 0x0, offset 0x25c)apb_config: unimplemented device write (size 4, value 0x0, offset 0x260)apb_config: unimplemented device write (size 4, value 0x0, offset 0x264)apb_config: unimplemented device write (size 4, value 0x0, offset 0x268)apb_config: unimplemented device write (size 4, value 0x1, offset 0x280)apb_config: unimplemented device write (size 4, value 0x40, offset 0x298)apb_config: unimplemented device write (size 4, value 0x401, offset 0x29c)apb_config: unimplemented device write (size 4, value 0x4010, offset 0x2a0)apb_config: unimplemented device write (size 4, value 0x40, offset 0x2d8)apb_config: unimplemented device write (size 4, value 0x401, offset 0x2dc)apb_config: unimplemented device write (size 4, value 0x4010, offset 0x2e0)apb_config: unimplemented device write (size 4, value 0x0, offset 0x2fc)apb_config: unimplemented device write (size 4, value 0x3, offset 0x304)apb_config: unimplemented device write (size 4, value 0x1, offset 0x308)apb_config: unimplemented device write (size 4, value 0x1, offset 0x30c)apb_config: unimplemented device write (size 4, value 0x9, offset 0x314)apb_config: unimplemented device write (size 4, value 0x0, offset 0x238)apb_config: unimplemented device write (size 4, value 0x0, offset 0x23c)apb_config: unimplemented device write (size 4, value 0x1, offset 0x31c)apb_config: unimplemented device write (size 4, value 0x1, offset 0x0)
DRAM: 64 MB
pdma: unimplemented device write (size 4, value 0x1a0, offset 0x20)
pdma: unimplemented device read (size 4, offset 0x20)
pdma: unimplemented device write (size 4, value 0x3c000, offset 0x20)
pdma: unimplemented device read (size 4, offset 0x20)
pdma: unimplemented device write (size 4, value 0x2000001, offset 0x20)
pdma: unimplemented device write (size 4, value 0x1a0, offset 0x40)
pdma: unimplemented device read (size 4, offset 0x40)
pdma: unimplemented device write (size 4, value 0x3c000, offset 0x40)
pdma: unimplemented device read (size 4, offset 0x40)
pdma: unimplemented device write (size 4, value 0x2800003, offset 0x40)
pdma: unimplemented device write (size 4, value 0x20, offset 0x20)
pdma: unimplemented device write (size 4, value 0x20, offset 0x40) *** Warning - bad CRC, using default environment
In: serial Out: serial Err: serial Net: M2S_MAC Hit any key to stop autoboot: 0 pdma: unimplemented device write (size 4, value 0x1a0, offset 0x20) pdma: unimplemented device read (size 4, offset 0x20) pdma: unimplemented device write (size 4, value 0x3c000, offset 0x20) pdma: unimplemented device read (size 4, offset 0x20) pdma: unimplemented device write (size 4, value 0x2000001, offset 0x20) pdma: unimplemented device write (size 4, value 0x1a0, offset 0x40) pdma: unimplemented device read (size 4, offset 0x40) pdma: unimplemented device write (size 4, value 0x3c000, offset 0x40) pdma: unimplemented device read (size 4, offset 0x40) pdma: unimplemented device write (size 4, value 0x2800003, offset 0x40) pdma: unimplemented device write (size 4, value 0x20, offset 0x20) pdma: unimplemented device write (size 4, value 0x20, offset 0x40)
16384 KiB S25FL128P_64K at 0:0 is now current device
pdma: unimplemented device write (size 4, value 0x1a0, offset 0x20)
pdma: unimplemented device read (size 4, offset 0x20)
pdma: unimplemented device write (size 4, value 0x3c000, offset 0x20)
pdma: unimplemented device read (size 4, offset 0x20)
pdma: unimplemented device write (size 4, value 0x2000001, offset 0x20)
pdma: unimplemented device write (size 4, value 0x1a0, offset 0x40)
pdma: unimplemented device read (size 4, offset 0x40)
pdma: unimplemented device write (size 4, value 0x3c000, offset 0x40)
pdma: unimplemented device read (size 4, offset 0x40)
pdma: unimplemented device write (size 4, value 0x2800003, offset 0x40)
pdma: unimplemented device write (size 4, value 0x20, offset 0x20)
pdma: unimplemented device write (size 4, value 0x20, offset 0x40)
- tftpboot
M2S-FG484-SOM> tftpboot
emac: unimplemented device write (size 4, value 0x7, offset 0x20)
emac: unimplemented device read (size 4, offset 0x0)
emac: unimplemented device write (size 4, value 0x80000000, offset 0x0)
emac: unimplemented device read (size 4, offset 0x0)
emac: unimplemented device write (size 4, value 0x0, offset 0x0)
emac: unimplemented device read (size 4, offset 0x0)
emac: unimplemented device write (size 4, value 0x0, offset 0x0)
emac: unimplemented device read (size 4, offset 0x0)
emac: unimplemented device write (size 4, value 0x0, offset 0x0)
emac: unimplemented device read (size 4, offset 0x0)
emac: unimplemented device write (size 4, value 0x0, offset 0x0)
emac: unimplemented device read (size 4, offset 0x0)
emac: unimplemented device write (size 4, value 0x0, offset 0x0)
emac: unimplemented device read (size 4, offset 0x38)
emac: unimplemented device write (size 4, value 0x0, offset 0x38)
emac: unimplemented device read (size 4, offset 0x48)
emac: unimplemented device write (size 4, value 0x0, offset 0x48)
emac: unimplemented device write (size 4, value 0x0, offset 0x0)
emac: unimplemented device read (size 4, offset 0x4)
emac: unimplemented device write (size 4, value 0x0, offset 0x4)
emac: unimplemented device read (size 4, offset 0x4)
emac: unimplemented device write (size 4, value 0x105, offset 0x4)
emac: unimplemented device write (size 4, value 0x600, offset 0x10)
emac: unimplemented device write (size 4, value 0xc0b13c83, offset 0x40)
emac: unimplemented device write (size 4, value 0x83830000, offset 0x44)
emac: unimplemented device write (size 4, value 0x200032e4, offset 0x190)
emac: unimplemented device write (size 4, value 0x1, offset 0x18c)
emac: unimplemented device read (size 4, offset 0x48)
emac: unimplemented device write (size 4, value 0x1f, offset 0x48)
emac: unimplemented device read (size 4, offset 0x48)
emac: unimplemented device write (size 4, value 0x0, offset 0x48)
emac: unimplemented device write (size 4, value 0xff00, offset 0x48)
emac: unimplemented device read (size 4, offset 0x48)
[...]
emac: unimplemented device read (size 4, offset 0x48)m2s_eth_init: FIFO initialization timeout
*** m2s_mac_dump_regs FIFO init:
emac: unimplemented device read (size 4, offset 0x180)
emac: unimplemented device read (size 4, offset 0x184)
emac: unimplemented device read (size 4, offset 0x188)
DMA TX CTRL=00000000;DESC=00000000;STAT=00000000
emac: unimplemented device read (size 4, offset 0x18c)
emac: unimplemented device read (size 4, offset 0x190)
emac: unimplemented device read (size 4, offset 0x194)
DMA RX CTRL=00000000;DESC=00000000;STAT=00000000
emac: unimplemented device read (size 4, offset 0x19c)
emac: unimplemented device read (size 4, offset 0x198)
DMA IRQ 00000000/00000000
emac: unimplemented device read (size 4, offset 0x0)
emac: unimplemented device read (size 4, offset 0x4)
emac: unimplemented device read (size 4, offset 0x8)
emac: unimplemented device read (size 4, offset 0xc)
emac: unimplemented device read (size 4, offset 0x10)
CFG1=00000000;CFG2=00000000;IFG=00000000;HD=00000000;MFL=00000000
emac: unimplemented device read (size 4, offset 0x38)
emac: unimplemented device read (size 4, offset 0x3c)
emac: unimplemented device read (size 4, offset 0x40)
emac: unimplemented device read (size 4, offset 0x44)
IFCTRL=00000000;IFSTAT=00000000;ADR1=00000000;ADR2=00000000 FIFO CFG emac: unimplemented device read (size 4, offset 0x48)
00000000/emac: unimplemented device read (size 4, offset 0x4c) 00000000/emac: unimplemented device read (size 4, offset 0x50) 00000000/emac: unimplemented device read (size 4, offset 0x54) 00000000/emac: unimplemented device read (size 4, offset 0x58) 00000000/emac: unimplemented device read (size 4, offset 0x5c) 00000000/
FIFO ACC emac: unimplemented device read (size 4, offset 0x60)
00000000/emac: unimplemented device read (size 4, offset 0x64) 00000000/emac: unimplemented device read (size 4, offset 0x68) 00000000/emac: unimplemented device read (size 4, offset 0x6c) 00000000/emac: unimplemented device read (size 4, offset 0x70) 00000000/emac: unimplemented device read (size 4, offset 0x74) 00000000/emac: unimplemented device read (size 4, offset 0x78) 00000000/emac: unimplemented device read (size 4, offset 0x7c) 00000000/
M2S-FG484-SOM>
- erase
M2S-FG484-SOM> sf erase 0 0x1000
Taking exception 4 [Data Abort]
...with CFSR.PRECISERR and BFAR 0x10
... as 3
UNHANDLED EXCEPTION: HARD FAULT
R0 = 00848cea R1 = 00000000
R2 = 00022ab0 R3 = 00000000
R12 = 00000004 LR = 00000a27
PC = 0000d418 PSR = 01000000
Good work :)
Regards,
Phil.