Add support for Smartfusion2 SoC
v8 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 smartfusion2-som -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
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 | 218 ++++++++++++++++++++++ hw/arm/msf2-som.c | 95 ++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/msf2-sysreg.c | 195 +++++++++++++++++++ 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 | 78 ++++++++ include/hw/ssi/mss-spi.h | 58 ++++++ include/hw/timer/mss-timer.h | 64 +++++++ 14 files changed, 1472 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 v8 1/5 msf2: Add Smartfusion2 System timer
Modelled System Timer in Microsemi's Smartfusion2 Soc. Timer has two 32bit down counters and two interrupts.
--- hw/timer/Makefile.objs | 1 + hw/timer/mss-timer.c | 289 +++++++++++++++++++++++++++++++++++++++++++ include/hw/timer/mss-timer.h | 64 ++++++++++ 3 files changed, 354 insertions(+) create mode 100644 hw/timer/mss-timer.c create mode 100644 include/hw/timer/mss-timer.h
hw/timer/Makefile.objs +1 -0
@@ -42,3 +42,4 @@ common-obj-$(CONFIG_ASPEED_SOC) += aspeed_timer.o common-obj-$(CONFIG_SUN4V_RTC) += sun4v-rtc.o common-obj-$(CONFIG_CMSDK_APB_TIMER) += cmsdk-apb-timer.o +common-obj-$(CONFIG_MSF2) += mss-timer.o
hw/timer/mss-timer.c new file +289 -0
289 lines not on this page · raw message
include/hw/timer/mss-timer.h new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v8 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 | 195 ++++++++++++++++++++++++++++++++++++++++++ include/hw/misc/msf2-sysreg.h | 78 +++++++++++++++++ 3 files changed, 274 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 +195 -0
195 lines not on this page · raw message
include/hw/misc/msf2-sysreg.h new file +78 -0
78 lines not on this page · raw message
Signature · 1 line
2.5.0
Re: [Qemu-devel] [Qemu devel v8 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block
Hi Sundeep,
Quoted 49 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 | 195 ++++++++++++++++++++++++++++++++++++++++++ include/hw/misc/msf2-sysreg.h | 78 +++++++++++++++++ 3 files changed, 274 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 +21
-0@@ -0,0 +1,195 @@ +/* +* 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" + +#ifndef MSF2_SYSREG_ERR_DEBUG +#define MSF2_SYSREG_ERR_DEBUG 0 +#endif
hw/misc/msf2-sysreg.c line 31
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +10
-0+ +#define DB_PRINT_L(lvl, fmt, args...) do { \ + if (MSF2_SYSREG_ERR_DEBUG >= lvl) { \ + qemu_log("%s: " fmt "\n", __func__, ## args); \ + } \ +} while (0); + +#define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args) + +static inline int msf2_divbits (uint32_t div)
Please directly use ctz32() instead of msf2_divbits()
Quoted 39 lines
hw/misc/msf2-sysreg.c new file +39
-0+{ +int ret =0 ; + +switch (div) { +case 1 : + ret =0 ; +break ; +case 2 : + ret =1 ; +break ; +case 4 : + ret =2 ; +break ; +case 8 : + ret =4 ; +break ; +case 16 : + ret =5 ; +break ; +case 32 : + ret =6 ; +break ; +default : +break ; + } + +return ret; +} + +static void msf2_sysreg_reset (DeviceState *d) +{ +MSF2SysregState *s =MSF2_SYSREG (d); + +DB_PRINT ("RESET" ); + + s->regs[MSSDDR_PLL_STATUS_LOW_CR ] =0x021A2358 ; + s->regs[MSSDDR_PLL_STATUS ] =0x3 ; + s->regs[MSSDDR_FACC1_CR ] =msf2_divbits (s->apb0div) <<5 | +msf2_divbits (s->apb1div) <<2 ;
hw/misc/msf2-sysreg.c line 80
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +10
-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)) {
This comment is controversial, I'll let Peter nod.
The SYSREG behaves differently regarding which bus access it (CPU, AHB).
You are implementing CPU access to the SYSREG, the registers have different permissions when accessed by the CPU. (see the SmartFusion2 User Guide: Table 21-1 "Register Types" and Table 21-2 "Register Map").
I'd think of this stub:
switch(reg) {
case register_supported1:
case register_supported2:
case register_supported3:
ret = s->regs[offset];
trace_msf2_sysreg_read(offset, ret);
break;
case RO-U:
qemu_log_mask(LOG_GUEST_ERROR, "Illegal AHB access 0x%08"...
break;case W1P:
qemu_log_mask(LOG_GUEST_ERROR, "Illegal read access ... break;
case RW:
case RW-P:
case RO:
case RO-P:
default:
ret = s->regs[offset];
qemu_log_mask(LOG_UNIMP, "...
break;
}Anyway keep this comment for further improvements, it's probably not useful for your use case.
hw/misc/msf2-sysreg.c line 83
Quoted 3 lines
hw/misc/msf2-sysreg.c new file +3
-0+ ret = s->regs[offset]; +DB_PRINT ("addr: 0x%08" HWADDR_PRIx" data: 0x%08" PRIx32, + offset <<2 , ret);
Can you replace DB_PRINT by traces? such:
trace_msf2_sysreg_read(...);
Quoted 12 lines
hw/misc/msf2-sysreg.c new file +12
-0+ }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) +{
hw/misc/msf2-sysreg.c line 105
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +10
-0+MSF2SysregState *s = opaque; +uint32_t newval = val; + +DB_PRINT ("addr: 0x%08" HWADDR_PRIx" data: 0x%08" PRIx64, + offset, val); + + offset >>=2 ; + +switch (offset) { +case MSSDDR_PLL_STATUS :
trace_msf2_sysreg_write_pll_status();
hw/misc/msf2-sysreg.c line 110
Quoted 5 lines
hw/misc/msf2-sysreg.c new file +5
-0+break ; + +case ESRAM_CR : +if (newval != s->regs[ESRAM_CR ]) { + qemu_log_mask(LOG_GUEST_ERROR,
Since this isn't a guest error, use LOG_UNIMP instead.
hw/misc/msf2-sysreg.c line 117
Quoted 7 lines
hw/misc/msf2-sysreg.c new file +7
-0+ TYPE_MSF2_SYSREG": eSRAM remapping not supported\n"); + } +break ; + +case DDR_CR : +if (newval != s->regs[DDR_CR ]) { + qemu_log_mask(LOG_GUEST_ERROR,
LOG_UNIMP
hw/misc/msf2-sysreg.c line 124
Quoted 7 lines
hw/misc/msf2-sysreg.c new file +7
-0+ TYPE_MSF2_SYSREG": DDR remapping not supported\n"); + } +break ; + +case ENVM_REMAP_BASE_CR : +if (newval != s->regs[ENVM_REMAP_BASE_CR ]) { + qemu_log_mask(LOG_GUEST_ERROR,
LOG_UNIMP
hw/misc/msf2-sysreg.c line 128
Quoted 4 lines
hw/misc/msf2-sysreg.c new file +4
-0+ TYPE_MSF2_SYSREG": eNVM remapping not supported\n"); + } +break ; +
Or shorter:
case ESRAM_CR:
case DDR_CR:
case ENVM_REMAP_BASE_CR:
oldval = s->regs[offset];
if (oldval ^ newval) {
qemu_log_mask(LOG_UNIMP,
TYPE_MSF2_SYSREG": remapping not supported\n");
}
break;hw/misc/msf2-sysreg.c line 130
Quoted 2 lines
hw/misc/msf2-sysreg.c new file +2
-0+default : +if (offset <ARRAY_SIZE (s->regs)) {
trace_msf2_sysreg_write(offset, val, s->regs[offset]);
hw/misc/msf2-sysreg.c line 139
Quoted 9 lines
hw/misc/msf2-sysreg.c new file +9
-0+ s->regs[offset] = newval; + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Bad offset 0x%08" HWADDR_PRIx"\n" , __func__, + offset <<2 ); + } +break ; + } +}
Good work, almost there, next respin should be ready for Peter to take in arm-next :)
Regards,
Phil.
Re: [Qemu-arm] [Qemu devel v8 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block
Quoted 38 lines · Philippe Mathieu-Daudé
hw/misc/msf2-sysreg.c line 80
Quoted 8 lines · Subbaraya Sundeep
hw/misc/msf2-sysreg.c new file +8
-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)) {This comment is controversial, I'll let Peter nod.
The SYSREG behaves differently regarding which bus access it (CPU, AHB). You are implementing CPU access to the SYSREG, the registers have different permissions when accessed by the CPU. (see the SmartFusion2 User Guide:
Table 21-1 "Register Types" and Table 21-2 "Register Map").I'd think of this stub:
switch(reg) {
caseregister_supported1:
caseregister_supported2:
caseregister_supported3:ret = s->regs[offset]; trace_msf2_sysreg_read(offset, ret); break; case RO-U: qemu_log_mask(LOG_GUEST_ERROR, "Illegal AHB access 0x%08"... break;case W1P:
qemu_log_mask(LOG_GUEST_ERROR, "Illegal read access ... break;
case RW:
case RW-P:
case RO:
case RO-P:
default:
Quoted 4 lines
ret = s->regs[offset];
qemu_log_mask(LOG_UNIMP, "...
break;
}This doesn't look entirely right, since this is the read interface. Shouldn't we be allowing pretty much all of these register types except maybe W1P to do a read?
On the other hand, in the write function we should probably not allow writes to registers documented as read only.
thanks
-- PMM
Re: [Qemu-arm] [Qemu devel v8 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block
Hi Philippe,
Quoted 15 lines · Peter Maydell
Quoted 13 lines · Philippe Mathieu-Daudé
hw/misc/msf2-sysreg.c line 80
Quoted 8 lines · Subbaraya Sundeep
hw/misc/msf2-sysreg.c new file +8
-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)) {This comment is controversial, I'll let Peter nod.
Quoted 6 lines
Quoted 2 lines
The SYSREG behaves differently regarding which bus access it (CPU, AHB). You are implementing CPU access to the SYSREG, the registers have
different
Quoted 2 lines
permissions when accessed by the CPU. (see the SmartFusion2 User Guide:
Table 21-1 "Register Types" and Table 21-2 "Register Map").
CPU is also one of the bus masters in AHB matrix (Fig 6.1 in page 248).
Quoted 17 lines
Quoted 17 lines
I'd think of this stub:
switch(reg) {
caseregister_supported1:
caseregister_supported2:
caseregister_supported3:ret = s->regs[offset]; trace_msf2_sysreg_read(offset, ret); break; case RO-U: qemu_log_mask(LOG_GUEST_ERROR, "Illegal AHB access 0x%08"... break;case W1P:
qemu_log_mask(LOG_GUEST_ERROR, "Illegal read access ... break;
case RW:
Quoted 9 lines
Quoted 8 lines
case RW-P:
case RO:
case RO-P:
default:ret = s->regs[offset]; qemu_log_mask(LOG_UNIMP, "... break; }
This sounds good to me and will fix later by rearranging registers in enum sorted
based on type (RO, RW, etc.,) and use those ranges in switch case.
Quoted 5 lines
This doesn't look entirely right, since this is the read interface. Shouldn't we be allowing pretty much all of these register types except maybe W1P to do a read?
Peter, some of the registers are not allowed to access by CPU and are only set during
device programming. For those registers Philippe is suggesting to log "Illegal AHB access"
when guest is trying to read/write.
Thanks,
Sundeep
Quoted 7 lines
On the other hand, in the write function we should probably not allow writes to registers documented as read only.
thanks
-- PMM
Re: [Qemu-arm] [Qemu devel v8 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
hw/misc/msf2-sysreg.c line 80
Quoted 8 lines
hw/misc/msf2-sysreg.c new file +8
-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)) {This comment is controversial, I'll let Peter nod.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
The SYSREG behaves differently regarding which bus access it (CPU, AHB). You are implementing CPU access to the SYSREG, the registers have
different
Quoted 2 lines
permissions when accessed by the CPU. (see the SmartFusion2 User Guide:
Table 21-1 "Register Types" and Table 21-2 "Register Map").CPU is also one of the bus masters in AHB matrix (Fig 6.1 in page 248).
I was worried about Fabric access but Peter remembered me QEMU doesn't model it ;)
Quoted 26 lines
Quoted 16 lines
Quoted 16 lines
I'd think of this stub:
switch(reg) {
caseregister_supported1:
caseregister_supported2:
caseregister_supported3:ret = s->regs[offset]; trace_msf2_sysreg_read(offset, ret); break; case RO-U: qemu_log_mask(LOG_GUEST_ERROR, "Illegal AHB access 0x%08"... break;case W1P:
qemu_log_mask(LOG_GUEST_ERROR, "Illegal read access ... break;
case RW:Quoted 9 lines
Quoted 8 lines
case RW-P:
case RO:
case RO-P:
default:ret = s->regs[offset]; qemu_log_mask(LOG_UNIMP, "... break; }
Quoted 3 lines
This sounds good to me and will fix later by rearranging registers in enum sorted
based on type (RO, RW, etc.,) and use those ranges in switch case.
The Register API (hw/register.h) is helpful to check such properties but might turn your code harder to read.
Quoted 11 lines
Quoted 5 lines
This doesn't look entirely right, since this is the read interface. Shouldn't we be allowing pretty much all of these register types except maybe W1P to do a read?
Peter, some of the registers are not allowed to access by CPU and are only set during
device programming. For those registers Philippe is suggesting to log "Illegal AHB access"
when guest is trying to read/write.
I was worried about accessing those registers when the flash WriteProtect bit is set, however the eNVM flash library is not Open Source, it is unlikely a guest access those registers, and if it is the library then MicroSemi already tried it on real hardware. There is probably no need to worry about "Illegal AHB access" :)
Quoted 2 lines
Quoted 2 lines
On the other hand, in the write function we should probably not allow writes to registers documented as read only.
Surely.
trace_msf2_sysreg_write(offset, s->regs[offset], ret);
switch(reg) {
case register_supported1:
case register_supported2:
case register_supported3:
s->regs[offset] = ret;
break;case RO:
case RO-P:
case RO-U:
qemu_log_mask(LOG_GUEST_ERROR, "Illegal write access on RO... break;
default:
qemu_log_mask(LOG_UNIMP, "...
break;
}Re: [Qemu-arm] [Qemu devel v8 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block
In reply to Philippe Mathieu-DaudéHi Philippe,
Quoted 151 lines · Philippe Mathieu-Daudé
Hi Sundeep,
Quoted 52 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 | 195 ++++++++++++++++++++++++++++++ ++++++++++++ include/hw/misc/msf2-sysreg.h | 78 +++++++++++++++++ 3 files changed, 274 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,195 @@ +/* +* 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 +8
-0+ +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "hw/misc/msf2-sysreg.h" + +#ifndef MSF2_SYSREG_ERR_DEBUG +#define MSF2_SYSREG_ERR_DEBUG 0 +#endif hw/misc/msf2-sysreg.c line 31
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +10
-0+ +#define DB_PRINT_L(lvl, fmt, args...) do { \ + if (MSF2_SYSREG_ERR_DEBUG >= lvl) { \ + qemu_log("%s: " fmt "\n", __func__, ## args); \ + } \ +} while (0); + +#define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args) + +static inline int msf2_divbits (uint32_t div)Please directly use
ctz32()instead ofmsf2_divbits()
ctz32()will not work for input 8,16,32 so need to usemsf2_divbits().+{
Quoted 39 lines
hw/misc/msf2-sysreg.c new file +38
-0+int ret =0 ; + +switch (div) { +case 1 : + ret =0 ; +break ; +case 2 : + ret =1 ; +break ; +case 4 : + ret =2 ; +break ; +case 8 : + ret =4 ; +break ; +case 16 : + ret =5 ; +break ; +case 32 : + ret =6 ; +break ; +default : +break ; + } + +return ret; +} + +static void msf2_sysreg_reset (DeviceState *d) +{ +MSF2SysregState *s =MSF2_SYSREG (d); + +DB_PRINT ("RESET" ); + + s->regs[MSSDDR_PLL_STATUS_LOW_CR ] =0x021A2358 ; + s->regs[MSSDDR_PLL_STATUS ] =0x3 ; + s->regs[MSSDDR_FACC1_CR ] =msf2_divbits (s->apb0div) <<5 | +msf2_divbits (s->apb1div) <<2 ;hw/misc/msf2-sysreg.c line 80
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +10
-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)) {This comment is controversial, I'll let Peter nod.
The SYSREG behaves differently regarding which bus access it (CPU, AHB). You are implementing CPU access to the SYSREG, the registers have different permissions when accessed by the CPU. (see the SmartFusion2 User
Guide: Table 21-1 "Register Types" and Table 21-2 "Register Map").I'd think of this stub:
switch(reg) {
caseregister_supported1:
caseregister_supported2:
caseregister_supported3:ret = s->regs[offset]; trace_msf2_sysreg_read(offset, ret); break; case RO-U: qemu_log_mask(LOG_GUEST_ERROR, "Illegal AHB access 0x%08"... break;case W1P:
qemu_log_mask(LOG_GUEST_ERROR, "Illegal read access ... break;
case RW:
case RW-P:
case RO:
case RO-P:
default:
Quoted 7 lines
ret = s->regs[offset]; qemu_log_mask(LOG_UNIMP, "... break; }Anyway keep this comment for further improvements, it's probably not useful for your use case.
Sure will remember this comment and fix it later.
Quoted 10 lines
+ ret = s->regs[offset];
hw/misc/msf2-sysreg.c line 83
Quoted 3 lines
hw/misc/msf2-sysreg.c new file +2
-0+DB_PRINT ("addr: 0x%08" HWADDR_PRIx" data: 0x%08" PRIx32, + offset <<2 , ret);Can you replace
DB_PRINTby traces? such:trace_msf2_sysreg_read(...);
Ok
Quoted 105 lines
+ } else {
Quoted 12 lines
hw/misc/msf2-sysreg.c new file +11
-0+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) +{hw/misc/msf2-sysreg.c line 105
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +10
-0+MSF2SysregState *s = opaque; +uint32_t newval = val; + +DB_PRINT ("addr: 0x%08" HWADDR_PRIx" data: 0x%08" PRIx64, + offset, val); + + offset >>=2 ; + +switch (offset) { +case MSSDDR_PLL_STATUS :trace_msf2_sysreg_write_pll_status();+ break;
hw/misc/msf2-sysreg.c line 110
Quoted 5 lines
hw/misc/msf2-sysreg.c new file +4
-0+ +case ESRAM_CR : +if (newval != s->regs[ESRAM_CR ]) { + qemu_log_mask(LOG_GUEST_ERROR,Since this isn't a guest error, use
LOG_UNIMPinstead.Ok
+
TYPE_MSF2_SYSREG": eSRAM remapping nothw/misc/msf2-sysreg.c line 117
Quoted 8 lines
supported\n");
hw/misc/msf2-sysreg.c new file +6
-0+ } +break ; + +case DDR_CR : +if (newval != s->regs[DDR_CR ]) { + qemu_log_mask(LOG_GUEST_ERROR,
LOG_UNIMPOk
+
TYPE_MSF2_SYSREG": DDR remapping not supported\n");hw/misc/msf2-sysreg.c line 124
Quoted 7 lines
hw/misc/msf2-sysreg.c new file +6
-0+ } +break ; + +case ENVM_REMAP_BASE_CR : +if (newval != s->regs[ENVM_REMAP_BASE_CR ]) { + qemu_log_mask(LOG_GUEST_ERROR,
LOG_UNIMPOk
+
TYPE_MSF2_SYSREG": eNVM remapping nothw/misc/msf2-sysreg.c line 107
Quoted 5 lines
supported\n");
hw/misc/msf2-sysreg.c new file +3
-0+ } +break ; +Or shorter:
case ESRAM_CR: case DDR_CR: case ENVM_REMAP_BASE_CR: oldval = s->regs[offset]; if (oldval ^ newval) { qemu_log_mask(LOG_UNIMP, TYPE_MSF2_SYSREG": remapping not supported\n"); } break;Ok
+ default:
Quoted 2 lines
+ if (offset <
ARRAY_SIZE(s->regs)) {trace_msf2_sysreg_write(offset, val, s->regs[offset]);+ s->regs[offset] = newval;
hw/misc/msf2-sysreg.c line 119
Quoted 10 lines
hw/misc/msf2-sysreg.c new file +3
-0+ }else { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Bad offset 0x%08" HWADDR_PRIx "\n",
__func__,hw/misc/msf2-sysreg.c new file +5
-0+ offset << 2); + } +break ; + } +}
Quoted 4 lines
Good work, almost there, next respin should be ready for Peter to take in arm-next :)
Thank you,
Sundeep
Quoted 4 lines
Regards,
Phil.
Re: [Qemu-arm] [Qemu devel v8 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block
In reply to Philippe Mathieu-DaudéHi Sundeep,
Quoted 1 line · Philippe Mathieu-Daudé
On 09/07/2017 04:24 PM, Subbaraya Sundeep wrote:
[...]
Quoted 3 lines
Quoted 1 line
+static inline int
msf2_divbits(uint32_t div)Please directly use
ctz32()instead ofmsf2_divbits()
It seems you missed this review comment in your v9.
Quoted 29 lines
Quoted 29 lines
hw/misc/msf2-sysreg.c new file +28
-0+{ + int ret = 0; + + switch (div) { + case 1: + ret = 0; + break; + case 2: + ret = 1; + break; + case 4: + ret = 2; + break; + case 8: + ret = 4; + break; + case 16: + ret = 5; + break; + case 32: + ret = 6; + break; + default: + break; + } + + return ret; +}
Re: [Qemu-arm] [Qemu devel v8 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block
Hi Philippe,
Quoted 8 lines · Philippe Mathieu-Daudé
Hi Sundeep,
Quoted 2 lines · Philippe Mathieu-Daudé
On 09/07/2017 04:24 PM, Subbaraya Sundeep wrote:
[...]
Quoted 7 lines
Quoted 5 lines
+static inline int
msf2_divbits(uint32_t div)Quoted 1 line
Please directly use
ctz32()instead ofmsf2_divbits()It seems you missed this review comment in your v9.
ctz32(1) = 0
ctz32(2) = 1
ctz32(4) = 2
ctz32(8) = 3
ctz32(16) = 4
ctz32(32) = 5
but for inputs 8,16,32 output should be 4,5,6 so didn't use ctz32(). I replied to this comment in the same mail chain earlier. Please check.
Thanks,
Sundeep
Quoted 33 lines
Quoted 33 lines
+{
Quoted 28 lines
hw/misc/msf2-sysreg.c new file +27
-0+int ret =0 ; + +switch (div) { +case 1 : + ret =0 ; +break ; +case 2 : + ret =1 ; +break ; +case 4 : + ret =2 ; +break ; +case 8 : + ret =4 ; +break ; +case 16 : + ret =5 ; +break ; +case 32 : + ret =6 ; +break ; +default : +break ; + } + +return ret; +}
PATCH v8 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 v8 PATCH 3/5] msf2: Add Smartfusion2 SPI controller
Quoted 3 lines · Subbaraya Sundeep
Modelled Microsemi's Smartfusion2 SPI controller.
Signed-off-by Subbaraya Sundeep <[email protected]>
Thanks,
Alistair
Quoted 497 lines
--- 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.hhw/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.ohw/ssi/mss-spi.c new file +404
-0@@ -0,0 +1,404 @@ +/* +* Block model of SPI controller present in +* Microsemi's SmartFusion2 and SmartFusion SoCs. +* +* 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 "hw/ssi/mss-spi.h" +#include "qemu/log.h" + +#ifndef MSS_SPI_ERR_DEBUG +#define MSS_SPI_ERR_DEBUG 0 +#endif + +#define DB_PRINT_L(lvl, fmt, args...) do { \ + if (MSS_SPI_ERR_DEBUG >= lvl) { \ + qemu_log("%s: " fmt "\n", __func__, ## args); \ + } \ +} while (0); + +#define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args) + +#define FIFO_CAPACITY 32 + +#define R_SPI_CONTROL 0 +#define R_SPI_DFSIZE 1 +#define R_SPI_STATUS 2 +#define R_SPI_INTCLR 3 +#define R_SPI_RX 4 +#define R_SPI_TX 5 +#define R_SPI_CLKGEN 6 +#define R_SPI_SS 7 +#define R_SPI_MIS 8 +#define R_SPI_RIS 9 + +#define S_TXDONE (1 << 0) +#define S_RXRDY (1 << 1) +#define S_RXCHOVRF (1 << 2) +#define S_RXFIFOFUL (1 << 4) +#define S_RXFIFOFULNXT (1 << 5) +#define S_RXFIFOEMP (1 << 6) +#define S_RXFIFOEMPNXT (1 << 7) +#define S_TXFIFOFUL (1 << 8) +#define S_TXFIFOFULNXT (1 << 9) +#define S_TXFIFOEMP (1 << 10) +#define S_TXFIFOEMPNXT (1 << 11) +#define S_FRAMESTART (1 << 12) +#define S_SSEL (1 << 13) +#define S_ACTIVE (1 << 14) + +#define C_ENABLE (1 << 0) +#define C_MODE (1 << 1) +#define C_INTRXDATA (1 << 4) +#define C_INTTXDATA (1 << 5) +#define C_INTRXOVRFLO (1 << 6) +#define C_SPS (1 << 26) +#define C_BIGFIFO (1 << 29) +#define C_RESET (1 << 31) + +#define FRAMESZ_MASK 0x1F +#define FMCOUNT_MASK 0x00FFFF00 +#define FMCOUNT_SHIFT 8 + +static void txfifo_reset (MSSSpiState *s) +{ +fifo32_reset (&s->tx_fifo); + + s->regs[R_SPI_STATUS ] &= ~S_TXFIFOFUL ; + s->regs[R_SPI_STATUS ] |=S_TXFIFOEMP ; +} + +static void rxfifo_reset (MSSSpiState *s) +{ +fifo32_reset (&s->rx_fifo); + + s->regs[R_SPI_STATUS ] &= ~S_RXFIFOFUL ; + s->regs[R_SPI_STATUS ] |=S_RXFIFOEMP ; +} + +static void set_fifodepth (MSSSpiState *s) +{ +unsigned int size = s->regs[R_SPI_DFSIZE ] &FRAMESZ_MASK ; + +if (size <=8 ) { + s->fifo_depth =32 ; + }else if (size <=16 ) { + s->fifo_depth =16 ; + }else if (size <=32 ) { + s->fifo_depth =8 ; + }else { + s->fifo_depth =4 ; + } +} + +static void update_mis (MSSSpiState *s) +{ +uint32_t reg = s->regs[R_SPI_CONTROL ]; +uint32_t tmp; + +/* +* form the Control register interrupt enable bits +* same as RIS, MIS and Interrupt clear registers for simplicity +*/ + tmp = ((reg &C_INTRXOVRFLO ) >>4 ) | ((reg &C_INTRXDATA ) >>3 ) | + ((reg &C_INTTXDATA ) >>5 ); + s->regs[R_SPI_MIS ] |= tmp & s->regs[R_SPI_RIS ]; +} + +static void spi_update_irq (MSSSpiState *s) +{ +int irq; + +update_mis (s); + irq = !!(s->regs[R_SPI_MIS ]); + +qemu_set_irq (s->irq, irq); +} + +static void mss_spi_reset (DeviceState *d) +{ +MSSSpiState *s =MSS_SPI (d); + +memset (s->regs,0 ,sizeof s->regs); + s->regs[R_SPI_CONTROL ] =0x80000102 ; + s->regs[R_SPI_DFSIZE ] =0x4 ; + s->regs[R_SPI_STATUS ] =S_SSEL |S_TXFIFOEMP |S_RXFIFOEMP ; + s->regs[R_SPI_CLKGEN ] =0x7 ; + s->regs[R_SPI_RIS ] =0x0 ; + + s->fifo_depth =4 ; + s->frame_count =1 ; + s->enabled = false; + +rxfifo_reset (s); +txfifo_reset (s); +} + +static uint64_t +spi_read (void *opaque,hwaddr addr,unsigned int size) +{ +MSSSpiState *s = opaque; +uint32_t ret =0 ; + + addr >>=2 ; +switch (addr) { +case R_SPI_RX : + s->regs[R_SPI_STATUS ] &= ~S_RXFIFOFUL ; + s->regs[R_SPI_STATUS ] &= ~S_RXCHOVRF ; + ret =fifo32_pop (&s->rx_fifo); +if (fifo32_is_empty (&s->rx_fifo)) { + s->regs[R_SPI_STATUS ] |=S_RXFIFOEMP ; + } +break ; + +case R_SPI_MIS : +update_mis (s); + ret = s->regs[R_SPI_MIS ]; +break ; + +default : +if (addr <ARRAY_SIZE (s->regs)) { + ret = s->regs[addr]; + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Bad offset 0x%" HWADDR_PRIx"\n" , __func__, + addr *4 ); +return ret; + } +break ; + } + +DB_PRINT ("addr=0x%" HWADDR_PRIx" = 0x%" PRIx32, addr *4 , ret); +spi_update_irq (s); +return ret; +} + +static void assert_cs (MSSSpiState *s) +{ +qemu_set_irq (s->cs_line,0 ); +} + +static void deassert_cs (MSSSpiState *s) +{ +qemu_set_irq (s->cs_line,1 ); +} + +static void spi_flush_txfifo (MSSSpiState *s) +{ +uint32_t tx; +uint32_t rx; +bool sps = !!(s->regs[R_SPI_CONTROL ] &C_SPS ); + +/* +* Chip Select(CS) is automatically controlled by this controller. +* If SPS bit is set in Control register then CS is asserted +* until all the frames set in frame count of Control register are +* transferred. If SPS is not set then CS pulses between frames. +* Note that Slave Select register specifies which of the CS line +* has to be controlled automatically by controller. Bits SS[7:1] are for +* masters in FPGA fabric since we model only Microcontroller subsystem +* of Smartfusion2 we control only one CS(SS[0]) line. +*/ +while (!fifo32_is_empty (&s->tx_fifo) && s->frame_count) { +assert_cs (s); + + s->regs[R_SPI_STATUS ] &= ~(S_TXDONE |S_RXRDY ); + + tx =fifo32_pop (&s->tx_fifo); +DB_PRINT ("data tx:0x%" PRIx32, tx); + rx =ssi_transfer (s->spi, tx); +DB_PRINT ("data rx:0x%" PRIx32, rx); + +if (fifo32_num_used (&s->rx_fifo) == s->fifo_depth) { + s->regs[R_SPI_STATUS ] |=S_RXCHOVRF ; + s->regs[R_SPI_RIS ] |=S_RXCHOVRF ; + }else { +fifo32_push (&s->rx_fifo, rx); + s->regs[R_SPI_STATUS ] &= ~S_RXFIFOEMP ; +if (fifo32_num_used (&s->rx_fifo) == (s->fifo_depth -1 )) { + s->regs[R_SPI_STATUS ] |=S_RXFIFOFULNXT ; + }else if (fifo32_num_used (&s->rx_fifo) == s->fifo_depth) { + s->regs[R_SPI_STATUS ] |=S_RXFIFOFUL ; + } + } + s->frame_count--; +if (!sps) { +deassert_cs (s); + } + } + +if (!s->frame_count) { + s->frame_count = (s->regs[R_SPI_CONTROL ] &FMCOUNT_MASK ) >> +FMCOUNT_SHIFT ; +deassert_cs (s); + s->regs[R_SPI_RIS ] |=S_TXDONE |S_RXRDY ; + s->regs[R_SPI_STATUS ] |=S_TXDONE |S_RXRDY ; + } +} + +static void spi_write (void *opaque,hwaddr addr, +uint64_t val64,unsigned int size) +{ +MSSSpiState *s = opaque; +uint32_t value = val64; + +DB_PRINT ("addr=0x%" HWADDR_PRIx" =0x%" PRIx32, addr, value); + addr >>=2 ; + +switch (addr) { +case R_SPI_TX : +/* adding to already full FIFO */ +if (fifo32_num_used (&s->tx_fifo) == s->fifo_depth) { +break ; + } + s->regs[R_SPI_STATUS ] &= ~S_TXFIFOEMP ; +fifo32_push (&s->tx_fifo, value); +if (fifo32_num_used (&s->tx_fifo) == (s->fifo_depth -1 )) { + s->regs[R_SPI_STATUS ] |=S_TXFIFOFULNXT ; + }else if (fifo32_num_used (&s->tx_fifo) == s->fifo_depth) { + s->regs[R_SPI_STATUS ] |=S_TXFIFOFUL ; + } +if (s->enabled) { +spi_flush_txfifo (s); + } +break ; + +case R_SPI_CONTROL : + s->regs[R_SPI_CONTROL ] = value; +if (value &C_BIGFIFO ) { +set_fifodepth (s); + }else { + s->fifo_depth =4 ; + } + s->enabled = value &C_ENABLE ; + s->frame_count = (value &FMCOUNT_MASK ) >>FMCOUNT_SHIFT ; +if (value &C_RESET ) { +mss_spi_reset (DEVICE (s)); + } +break ; + +case R_SPI_DFSIZE : +if (s->enabled) { +break ; + } + s->regs[R_SPI_DFSIZE ] = value; +break ; + +case R_SPI_INTCLR : + s->regs[R_SPI_INTCLR ] = value; +if (value &S_TXDONE ) { + s->regs[R_SPI_RIS ] &= ~S_TXDONE ; + } +if (value &S_RXRDY ) { + s->regs[R_SPI_RIS ] &= ~S_RXRDY ; + } +if (value &S_RXCHOVRF ) { + s->regs[R_SPI_RIS ] &= ~S_RXCHOVRF ; + } +break ; + +case R_SPI_MIS : +case R_SPI_STATUS : +case R_SPI_RIS : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Write to read only register 0x%" HWADDR_PRIx"\n" , + __func__, addr *4 ); +break ; + +default : +if (addr <ARRAY_SIZE (s->regs)) { + s->regs[addr] = value; + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Bad offset 0x%" HWADDR_PRIx"\n" , __func__, + addr *4 ); + } +break ; + } + +spi_update_irq (s); +} + +static const MemoryRegionOps spi_ops = { + .read = spi_read, + .write = spi_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =1 , + .max_access_size =4 + } +}; + +static void mss_spi_realize (DeviceState *dev,Error **errp) +{ +MSSSpiState *s =MSS_SPI (dev); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); + + s->spi =ssi_create_bus (dev,"spi" ); + +sysbus_init_irq (sbd, &s->irq); +ssi_auto_connect_slaves (dev, &s->cs_line, s->spi); +sysbus_init_irq (sbd, &s->cs_line); + +memory_region_init_io (&s->mmio,OBJECT (s), &spi_ops, s, +TYPE_MSS_SPI ,R_SPI_MAX *4 ); +sysbus_init_mmio (sbd, &s->mmio); + +fifo32_create (&s->tx_fifo,FIFO_CAPACITY ); +fifo32_create (&s->rx_fifo,FIFO_CAPACITY ); +} + +static const VMStateDescription vmstate_mss_spi = { + .name =TYPE_MSS_SPI , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_FIFO32 (tx_fifo, MSSSpiState), +VMSTATE_FIFO32 (rx_fifo, MSSSpiState), +VMSTATE_UINT32_ARRAY (regs, MSSSpiState,R_SPI_MAX ), +VMSTATE_END_OF_LIST () + } +}; + +static void mss_spi_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = mss_spi_realize; + dc->reset = mss_spi_reset; + dc->vmsd = &vmstate_mss_spi; +} + +static const TypeInfo mss_spi_info = { + .name =TYPE_MSS_SPI , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (MSSSpiState), + .class_init = mss_spi_class_init, +}; + +static void mss_spi_register_types (void ) +{ +type_register_static (&mss_spi_info); +} + +type_init (mss_spi_register_types)include/hw/ssi/mss-spi.h new file +58
-1@@ -0,0 +1,58 @@ +/* +* Microsemi SmartFusion2 SPI +* +* 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_MSS_SPI_H +#define HW_MSS_SPI_H + +#include "hw/sysbus.h" +#include "hw/ssi/ssi.h" +#include "qemu/fifo32.h" + +#define TYPE_MSS_SPI "mss-spi" +#define MSS_SPI (obj) OBJECT_CHECK(MSSSpiState, (obj), TYPE_MSS_SPI) + +#define R_SPI_MAX 16 + +typedef struct MSSSpiState { +SysBusDevice parent_obj; + +MemoryRegion mmio; + +qemu_irq irq; + +qemu_irq cs_line; + +SSIBus *spi; + +Fifo32 rx_fifo; +Fifo32 tx_fifo; + +int fifo_depth; +uint32_t frame_count; +bool enabled; + +uint32_t regs[R_SPI_MAX ]; +}MSSSpiState ; + +#endif /* HW_MSS_SPI_H */ --2.5.0
Re: [Qemu-arm] [Qemu devel v8 PATCH 3/5] msf2: Add Smartfusion2 SPI controller
Hi Alistair,
Quoted 9 lines · Alistair Francis
Quoted 3 lines · Subbaraya Sundeep
Modelled Microsemi's Smartfusion2 SPI controller.
Signed-off-by Subbaraya Sundeep <[email protected]>Reviewed-by Alistair Francis <[email protected]>Thank you,
Sundeep
Quoted 529 lines
Thanks,
AlistairQuoted 3 lines
--- hw/ssi/Makefile.objs | 1 + hw/ssi/mss-spi.c | 404 +++++++++++++++++++++++++++++++++++++++++++++++
Quoted 23 lines
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.hhw/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.ohw/ssi/mss-spi.c new file +0
-0hw/ssi/mss-spi.c line 7
Quoted 7 lines
hw/ssi/mss-spi.c new file +7
-0@@ -0,0 +1,404 @@ +/* +* Block model of SPI controller present in +* Microsemi's SmartFusion2 and SmartFusion SoCs. +* +* Copyright (C) 2017 Subbaraya Sundeep <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy
hw/ssi/mss-spi.c line 8
Quoted 1 line
hw/ssi/mss-spi.c new file +1
-0+* of this software and associated documentation files (the "Software"), to deal
hw/ssi/mss-spi.c line 9
Quoted 1 line
hw/ssi/mss-spi.c new file +1
-0+* in the Software without restriction, including without limitation the rights
hw/ssi/mss-spi.c line 10
Quoted 1 line
hw/ssi/mss-spi.c new file +1
-0+* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hw/ssi/mss-spi.c
Quoted 4 lines
hw/ssi/mss-spi.c new file +4
-0+* 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
hw/ssi/mss-spi.c
Quoted 3 lines
hw/ssi/mss-spi.c new file +3
-0+* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hw/ssi/mss-spi.c line 18
Quoted 1 line
hw/ssi/mss-spi.c new file +1
-0+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hw/ssi/mss-spi.c line 19
Quoted 1 line
hw/ssi/mss-spi.c new file +1
-0+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
hw/ssi/mss-spi.c line 20
Quoted 1 line
hw/ssi/mss-spi.c new file +1
-0+* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hw/ssi/mss-spi.c line 21
Quoted 1 line
hw/ssi/mss-spi.c new file +1
-0+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hw/ssi/mss-spi.c line 22
Quoted 1 line
hw/ssi/mss-spi.c new file +1
-0+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Quoted 152 lines
hw/ssi/mss-spi.c new file +152
-0+* THE SOFTWARE. +*/ + +#include "qemu/osdep.h" +#include "hw/ssi/mss-spi.h" +#include "qemu/log.h" + +#ifndef MSS_SPI_ERR_DEBUG +#define MSS_SPI_ERR_DEBUG 0 +#endif + +#define DB_PRINT_L(lvl, fmt, args...) do { \ + if (MSS_SPI_ERR_DEBUG >= lvl) { \ + qemu_log("%s: " fmt "\n", __func__, ## args); \ + } \ +} while (0); + +#define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args) + +#define FIFO_CAPACITY 32 + +#define R_SPI_CONTROL 0 +#define R_SPI_DFSIZE 1 +#define R_SPI_STATUS 2 +#define R_SPI_INTCLR 3 +#define R_SPI_RX 4 +#define R_SPI_TX 5 +#define R_SPI_CLKGEN 6 +#define R_SPI_SS 7 +#define R_SPI_MIS 8 +#define R_SPI_RIS 9 + +#define S_TXDONE (1 << 0) +#define S_RXRDY (1 << 1) +#define S_RXCHOVRF (1 << 2) +#define S_RXFIFOFUL (1 << 4) +#define S_RXFIFOFULNXT (1 << 5) +#define S_RXFIFOEMP (1 << 6) +#define S_RXFIFOEMPNXT (1 << 7) +#define S_TXFIFOFUL (1 << 8) +#define S_TXFIFOFULNXT (1 << 9) +#define S_TXFIFOEMP (1 << 10) +#define S_TXFIFOEMPNXT (1 << 11) +#define S_FRAMESTART (1 << 12) +#define S_SSEL (1 << 13) +#define S_ACTIVE (1 << 14) + +#define C_ENABLE (1 << 0) +#define C_MODE (1 << 1) +#define C_INTRXDATA (1 << 4) +#define C_INTTXDATA (1 << 5) +#define C_INTRXOVRFLO (1 << 6) +#define C_SPS (1 << 26) +#define C_BIGFIFO (1 << 29) +#define C_RESET (1 << 31) + +#define FRAMESZ_MASK 0x1F +#define FMCOUNT_MASK 0x00FFFF00 +#define FMCOUNT_SHIFT 8 + +static void txfifo_reset (MSSSpiState *s) +{ +fifo32_reset (&s->tx_fifo); + + s->regs[R_SPI_STATUS ] &= ~S_TXFIFOFUL ; + s->regs[R_SPI_STATUS ] |=S_TXFIFOEMP ; +} + +static void rxfifo_reset (MSSSpiState *s) +{ +fifo32_reset (&s->rx_fifo); + + s->regs[R_SPI_STATUS ] &= ~S_RXFIFOFUL ; + s->regs[R_SPI_STATUS ] |=S_RXFIFOEMP ; +} + +static void set_fifodepth (MSSSpiState *s) +{ +unsigned int size = s->regs[R_SPI_DFSIZE ] &FRAMESZ_MASK ; + +if (size <=8 ) { + s->fifo_depth =32 ; + }else if (size <=16 ) { + s->fifo_depth =16 ; + }else if (size <=32 ) { + s->fifo_depth =8 ; + }else { + s->fifo_depth =4 ; + } +} + +static void update_mis (MSSSpiState *s) +{ +uint32_t reg = s->regs[R_SPI_CONTROL ]; +uint32_t tmp; + +/* +* form the Control register interrupt enable bits +* same as RIS, MIS and Interrupt clear registers for simplicity +*/ + tmp = ((reg &C_INTRXOVRFLO ) >>4 ) | ((reg &C_INTRXDATA ) >>3 ) | + ((reg &C_INTTXDATA ) >>5 ); + s->regs[R_SPI_MIS ] |= tmp & s->regs[R_SPI_RIS ]; +} + +static void spi_update_irq (MSSSpiState *s) +{ +int irq; + +update_mis (s); + irq = !!(s->regs[R_SPI_MIS ]); + +qemu_set_irq (s->irq, irq); +} + +static void mss_spi_reset (DeviceState *d) +{ +MSSSpiState *s =MSS_SPI (d); + +memset (s->regs,0 ,sizeof s->regs); + s->regs[R_SPI_CONTROL ] =0x80000102 ; + s->regs[R_SPI_DFSIZE ] =0x4 ; + s->regs[R_SPI_STATUS ] =S_SSEL |S_TXFIFOEMP |S_RXFIFOEMP ; + s->regs[R_SPI_CLKGEN ] =0x7 ; + s->regs[R_SPI_RIS ] =0x0 ; + + s->fifo_depth =4 ; + s->frame_count =1 ; + s->enabled = false; + +rxfifo_reset (s); +txfifo_reset (s); +} + +static uint64_t +spi_read (void *opaque,hwaddr addr,unsigned int size) +{ +MSSSpiState *s = opaque; +uint32_t ret =0 ; + + addr >>=2 ; +switch (addr) { +case R_SPI_RX : + s->regs[R_SPI_STATUS ] &= ~S_RXFIFOFUL ; + s->regs[R_SPI_STATUS ] &= ~S_RXCHOVRF ; + ret =fifo32_pop (&s->rx_fifo); +if (fifo32_is_empty (&s->rx_fifo)) { + s->regs[R_SPI_STATUS ] |=S_RXFIFOEMP ; + } +break ; + +case R_SPI_MIS :hw/ssi/mss-spi.c
Quoted 10 lines
hw/ssi/mss-spi.c new file +10
-0+update_mis (s); + ret = s->regs[R_SPI_MIS ]; +break ; + +default : +if (addr <ARRAY_SIZE (s->regs)) { + ret = s->regs[addr]; + }else { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Bad offset 0x%" HWADDR_PRIx "\n",
__func__,Quoted 24 lines
hw/ssi/mss-spi.c new file +24
-0+ addr * 4); +return ret; + } +break ; + } + +DB_PRINT ("addr=0x%" HWADDR_PRIx" = 0x%" PRIx32, addr *4 , ret); +spi_update_irq (s); +return ret; +} + +static void assert_cs (MSSSpiState *s) +{ +qemu_set_irq (s->cs_line,0 ); +} + +static void deassert_cs (MSSSpiState *s) +{ +qemu_set_irq (s->cs_line,1 ); +} + +static void spi_flush_txfifo (MSSSpiState *s) +{ +uint32_t tx;hw/ssi/mss-spi.c
Quoted 10 lines
hw/ssi/mss-spi.c new file +10
-0+uint32_t rx; +bool sps = !!(s->regs[R_SPI_CONTROL ] &C_SPS ); + +/* +* Chip Select(CS) is automatically controlled by this controller. +* If SPS bit is set in Control register then CS is asserted +* until all the frames set in frame count of Control register are +* transferred. If SPS is not set then CS pulses between frames. +* Note that Slave Select register specifies which of the CS line +* has to be controlled automatically by controller. Bits SS[7:1] are for
hw/ssi/mss-spi.c line 219
Quoted 1 line
hw/ssi/mss-spi.c new file +1
-0+* masters in FPGA fabric since we model only Microcontroller subsystem
Quoted 95 lines
hw/ssi/mss-spi.c new file +95
-0+* of Smartfusion2 we control only one CS(SS[0]) line. +*/ +while (!fifo32_is_empty (&s->tx_fifo) && s->frame_count) { +assert_cs (s); + + s->regs[R_SPI_STATUS ] &= ~(S_TXDONE |S_RXRDY ); + + tx =fifo32_pop (&s->tx_fifo); +DB_PRINT ("data tx:0x%" PRIx32, tx); + rx =ssi_transfer (s->spi, tx); +DB_PRINT ("data rx:0x%" PRIx32, rx); + +if (fifo32_num_used (&s->rx_fifo) == s->fifo_depth) { + s->regs[R_SPI_STATUS ] |=S_RXCHOVRF ; + s->regs[R_SPI_RIS ] |=S_RXCHOVRF ; + }else { +fifo32_push (&s->rx_fifo, rx); + s->regs[R_SPI_STATUS ] &= ~S_RXFIFOEMP ; +if (fifo32_num_used (&s->rx_fifo) == (s->fifo_depth -1 )) { + s->regs[R_SPI_STATUS ] |=S_RXFIFOFULNXT ; + }else if (fifo32_num_used (&s->rx_fifo) == s->fifo_depth) { + s->regs[R_SPI_STATUS ] |=S_RXFIFOFUL ; + } + } + s->frame_count--; +if (!sps) { +deassert_cs (s); + } + } + +if (!s->frame_count) { + s->frame_count = (s->regs[R_SPI_CONTROL ] &FMCOUNT_MASK ) >> +FMCOUNT_SHIFT ; +deassert_cs (s); + s->regs[R_SPI_RIS ] |=S_TXDONE |S_RXRDY ; + s->regs[R_SPI_STATUS ] |=S_TXDONE |S_RXRDY ; + } +} + +static void spi_write (void *opaque,hwaddr addr, +uint64_t val64,unsigned int size) +{ +MSSSpiState *s = opaque; +uint32_t value = val64; + +DB_PRINT ("addr=0x%" HWADDR_PRIx" =0x%" PRIx32, addr, value); + addr >>=2 ; + +switch (addr) { +case R_SPI_TX : +/* adding to already full FIFO */ +if (fifo32_num_used (&s->tx_fifo) == s->fifo_depth) { +break ; + } + s->regs[R_SPI_STATUS ] &= ~S_TXFIFOEMP ; +fifo32_push (&s->tx_fifo, value); +if (fifo32_num_used (&s->tx_fifo) == (s->fifo_depth -1 )) { + s->regs[R_SPI_STATUS ] |=S_TXFIFOFULNXT ; + }else if (fifo32_num_used (&s->tx_fifo) == s->fifo_depth) { + s->regs[R_SPI_STATUS ] |=S_TXFIFOFUL ; + } +if (s->enabled) { +spi_flush_txfifo (s); + } +break ; + +case R_SPI_CONTROL : + s->regs[R_SPI_CONTROL ] = value; +if (value &C_BIGFIFO ) { +set_fifodepth (s); + }else { + s->fifo_depth =4 ; + } + s->enabled = value &C_ENABLE ; + s->frame_count = (value &FMCOUNT_MASK ) >>FMCOUNT_SHIFT ; +if (value &C_RESET ) { +mss_spi_reset (DEVICE (s)); + } +break ; + +case R_SPI_DFSIZE : +if (s->enabled) { +break ; + } + s->regs[R_SPI_DFSIZE ] = value; +break ; + +case R_SPI_INTCLR : + s->regs[R_SPI_INTCLR ] = value; +if (value &S_TXDONE ) { + s->regs[R_SPI_RIS ] &= ~S_TXDONE ; + } +if (value &S_RXRDY ) { + s->regs[R_SPI_RIS ] &= ~S_RXRDY ; + }hw/ssi/mss-spi.c
Quoted 10 lines
hw/ssi/mss-spi.c new file +10
-0+if (value &S_RXCHOVRF ) { + s->regs[R_SPI_RIS ] &= ~S_RXCHOVRF ; + } +break ; + +case R_SPI_MIS : +case R_SPI_STATUS : +case R_SPI_RIS : +qemu_log_mask (LOG_GUEST_ERROR , + "%s: Write to read only register 0x%"
HWADDR_PRIx"\n",hw/ssi/mss-spi.c
Quoted 9 lines
hw/ssi/mss-spi.c new file +9
-0+ __func__, addr * 4); +break ; + +default : +if (addr <ARRAY_SIZE (s->regs)) { + s->regs[addr] = value; + }else { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Bad offset 0x%" HWADDR_PRIx "\n",
__func__,Quoted 77 lines
hw/ssi/mss-spi.c new file +71
-0+ addr * 4); + } +break ; + } + +spi_update_irq (s); +} + +static const MemoryRegionOps spi_ops = { + .read = spi_read, + .write = spi_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =1 , + .max_access_size =4 + } +}; + +static void mss_spi_realize (DeviceState *dev,Error **errp) +{ +MSSSpiState *s =MSS_SPI (dev); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); + + s->spi =ssi_create_bus (dev,"spi" ); + +sysbus_init_irq (sbd, &s->irq); +ssi_auto_connect_slaves (dev, &s->cs_line, s->spi); +sysbus_init_irq (sbd, &s->cs_line); + +memory_region_init_io (&s->mmio,OBJECT (s), &spi_ops, s, +TYPE_MSS_SPI ,R_SPI_MAX *4 ); +sysbus_init_mmio (sbd, &s->mmio); + +fifo32_create (&s->tx_fifo,FIFO_CAPACITY ); +fifo32_create (&s->rx_fifo,FIFO_CAPACITY ); +} + +static const VMStateDescription vmstate_mss_spi = { + .name =TYPE_MSS_SPI , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_FIFO32 (tx_fifo, MSSSpiState), +VMSTATE_FIFO32 (rx_fifo, MSSSpiState), +VMSTATE_UINT32_ARRAY (regs, MSSSpiState,R_SPI_MAX ), +VMSTATE_END_OF_LIST () + } +}; + +static void mss_spi_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = mss_spi_realize; + dc->reset = mss_spi_reset; + dc->vmsd = &vmstate_mss_spi; +} + +static const TypeInfo mss_spi_info = { + .name =TYPE_MSS_SPI , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (MSSSpiState), + .class_init = mss_spi_class_init, +}; + +static void mss_spi_register_types (void ) +{ +type_register_static (&mss_spi_info); +} + +type_init (mss_spi_register_types)include/hw/ssi/mss-spi.h new file +0
-0include/hw/ssi/mss-spi.h line 6
Quoted 6 lines
include/hw/ssi/mss-spi.h new file +6
-0@@ -0,0 +1,58 @@ +/* +* Microsemi SmartFusion2 SPI +* +* Copyright (c) 2017 Subbaraya Sundeep <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy
include/hw/ssi/mss-spi.h line 7
Quoted 1 line
include/hw/ssi/mss-spi.h new file +1
-0+* of this software and associated documentation files (the "Software"), to deal
include/hw/ssi/mss-spi.h line 8
Quoted 1 line
include/hw/ssi/mss-spi.h new file +1
-0+* in the Software without restriction, including without limitation the rights
include/hw/ssi/mss-spi.h line 9
Quoted 1 line
include/hw/ssi/mss-spi.h new file +1
-0+* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
include/hw/ssi/mss-spi.h line 13
Quoted 4 lines
include/hw/ssi/mss-spi.h new file +4
-0+* 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
include/hw/ssi/mss-spi.h line 16
Quoted 3 lines
include/hw/ssi/mss-spi.h new file +3
-0+* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
include/hw/ssi/mss-spi.h line 17
Quoted 1 line
include/hw/ssi/mss-spi.h new file +1
-0+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
include/hw/ssi/mss-spi.h line 18
Quoted 1 line
include/hw/ssi/mss-spi.h new file +1
-0+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
include/hw/ssi/mss-spi.h line 19
Quoted 1 line
include/hw/ssi/mss-spi.h new file +1
-0+* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
include/hw/ssi/mss-spi.h line 20
Quoted 1 line
include/hw/ssi/mss-spi.h new file +1
-0+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
include/hw/ssi/mss-spi.h line 21
Quoted 1 line
include/hw/ssi/mss-spi.h new file +1
-0+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Quoted 40 lines
include/hw/ssi/mss-spi.h new file +37
-1+* THE SOFTWARE. +*/ + +#ifndef HW_MSS_SPI_H +#define HW_MSS_SPI_H + +#include "hw/sysbus.h" +#include "hw/ssi/ssi.h" +#include "qemu/fifo32.h" + +#define TYPE_MSS_SPI "mss-spi" +#define MSS_SPI (obj) OBJECT_CHECK(MSSSpiState, (obj), TYPE_MSS_SPI) + +#define R_SPI_MAX 16 + +typedef struct MSSSpiState { +SysBusDevice parent_obj; + +MemoryRegion mmio; + +qemu_irq irq; + +qemu_irq cs_line; + +SSIBus *spi; + +Fifo32 rx_fifo; +Fifo32 tx_fifo; + +int fifo_depth; +uint32_t frame_count; +bool enabled; + +uint32_t regs[R_SPI_MAX ]; +}MSSSpiState ; + +#endif /* HW_MSS_SPI_H */ --2.5.0
PATCH v8 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 | 218 ++++++++++++++++++++++++++++++++++++++++ include/hw/arm/msf2-soc.h | 66 ++++++++++++ 4 files changed, 286 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 +218 -0
218 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 v8 PATCH 4/5] msf2: Add Smartfusion2 SoC
Quoted 130 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 | 218 ++++++++++++++++++++++++++++++++++++++++ include/hw/arm/msf2-soc.h | 66 ++++++++++++ 4 files changed, 286 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 +91
-0@@ -0,0 +1,218 @@ +/* +* 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" + +#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 );
hw/arm/msf2-soc.c line 101
Quoted 10 lines
hw/arm/msf2-soc.c new file +10
-0+ +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.alias",
you can drop the ".alias", this function already prepends "alias "
Quoted 190 lines
hw/arm/msf2-soc.c new file +117
-0+ 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 */ + 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); + } +} + +static Property m2sxxx_soc_properties[] = { +/* +* part name specifies the type of SmartFusion2 device variant(this +* property is for information purpose only. +*/ +DEFINE_PROP_STRING ("part-name" , MSF2State, part_name), +DEFINE_PROP_UINT64 ("eNVM-size" , MSF2State, envm_size,MSF2_ENVM_MAX_SIZE ), +DEFINE_PROP_UINT64 ("eSRAM-size" , MSF2State, esram_size, +MSF2_ESRAM_MAX_SIZE ), +/* Libero GUI shows 100Mhz as default for clocks */ +DEFINE_PROP_UINT32 ("m3clk" , MSF2State, m3clk,100 *1000000 ), +/* default divisors in Libero GUI */ +DEFINE_PROP_UINT32 ("apb0div" , MSF2State, apb0div,2 ), +DEFINE_PROP_UINT32 ("apb1div" , MSF2State, apb1div,2 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void m2sxxx_soc_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = m2sxxx_soc_realize; + dc->props = m2sxxx_soc_properties; +} + +static const TypeInfo m2sxxx_soc_info = { + .name =TYPE_MSF2_SOC , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (MSF2State), + .instance_init = m2sxxx_soc_initfn, + .class_init = m2sxxx_soc_class_init, +}; + +static void m2sxxx_soc_types (void ) +{ +type_register_static (&m2sxxx_soc_info); +} + +type_init (m2sxxx_soc_types)include/hw/arm/msf2-soc.h new file +66
-0@@ -0,0 +1,66 @@ +/* +* Microsemi Smartfusion2 SoC +* +* Copyright (c) 2017 Subbaraya Sundeep <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#ifndef HW_ARM_MSF2_SOC_H +#define HW_ARM_MSF2_SOC_H + +#include "hw/arm/armv7m.h" +#include "hw/timer/mss-timer.h" +#include "hw/misc/msf2-sysreg.h" +#include "hw/ssi/mss-spi.h" + +#define TYPE_MSF2_SOC "msf2-soc" +#define MSF2_SOC (obj) OBJECT_CHECK(MSF2State, (obj), TYPE_MSF2_SOC) + +#define MSF2_NUM_SPIS 2 +#define MSF2_NUM_UARTS 2 + +/* +* System timer consists of two programmable 32-bit +* decrementing counters that generate individual interrupts to +* the Cortex-M3 processor +*/ +#define MSF2_NUM_TIMERS 2 + +typedef struct MSF2State { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +ARMv7MState armv7m; + +char *part_name; +uint64_t envm_size; +uint64_t esram_size; + +uint32_t m3clk; +uint32_t apb0div; +uint32_t apb1div; + +MSF2SysregState sysreg; +MSSTimerState timer; +MSSSpiState spi[MSF2_NUM_SPIS ]; +}MSF2State ; + +#endif
Re: [Qemu-devel] [Qemu devel v8 PATCH 4/5] msf2: Add Smartfusion2 SoC
Hi Philippe,
Quoted 152 lines · Philippe Mathieu-Daudé
Quoted 150 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 | 218 ++++++++++++++++++++++++++++++ ++++++++++ include/hw/arm/msf2-soc.h | 66 ++++++++++++ 4 files changed, 286 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,218 @@ +/* +* 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 +29
-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" + +#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 +43
-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
Quoted 8 lines
hw/arm/msf2-soc.c line 101
Quoted 6 lines
hw/arm/msf2-soc.c new file +5
-0+* 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.alias",you can drop the ".alias", this function already prepends "alias "
.remap sounds good?
Thanks,
Sundeep
Quoted 209 lines
+ nvm, 0,
s->envm_size);Quoted 206 lines
hw/arm/msf2-soc.c new file +12
-0+ +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 +25
-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); + } +} + +static Property m2sxxx_soc_properties[] = { +/* +* part name specifies the type of SmartFusion2 device variant(this +* property is for information purpose only. +*/ +DEFINE_PROP_STRING ("part-name" , MSF2State, part_name), + DEFINE_PROP_UINT64("eNVM-size", MSF2State, envm_size,
MSF2_ENVM_MAX_SIZE),hw/arm/msf2-soc.c new file +32
-0+DEFINE_PROP_UINT64 ("eSRAM-size" , MSF2State, esram_size, +MSF2_ESRAM_MAX_SIZE ), +/* Libero GUI shows 100Mhz as default for clocks */ +DEFINE_PROP_UINT32 ("m3clk" , MSF2State, m3clk,100 *1000000 ), +/* default divisors in Libero GUI */ +DEFINE_PROP_UINT32 ("apb0div" , MSF2State, apb0div,2 ), +DEFINE_PROP_UINT32 ("apb1div" , MSF2State, apb1div,2 ), + DEFINE_PROP_END_OF_LIST(), +}; + +static void m2sxxx_soc_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = m2sxxx_soc_realize; + dc->props = m2sxxx_soc_properties; +} + +static const TypeInfo m2sxxx_soc_info = { + .name =TYPE_MSF2_SOC , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (MSF2State), + .instance_init = m2sxxx_soc_initfn, + .class_init = m2sxxx_soc_class_init, +}; + +static void m2sxxx_soc_types (void ) +{ +type_register_static (&m2sxxx_soc_info); +} + +type_init (m2sxxx_soc_types)include/hw/arm/msf2-soc.h new file +6
-0@@ -0,0 +1,66 @@ +/* +* Microsemi Smartfusion2 SoC +* +* Copyright (c) 2017 Subbaraya Sundeep <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */include/hw/arm/msf2-soc.h new file +43
-0+ +#ifndef HW_ARM_MSF2_SOC_H +#define HW_ARM_MSF2_SOC_H + +#include "hw/arm/armv7m.h" +#include "hw/timer/mss-timer.h" +#include "hw/misc/msf2-sysreg.h" +#include "hw/ssi/mss-spi.h" + +#define TYPE_MSF2_SOC "msf2-soc" +#define MSF2_SOC (obj) OBJECT_CHECK(MSF2State, (obj), TYPE_MSF2_SOC) + +#define MSF2_NUM_SPIS 2 +#define MSF2_NUM_UARTS 2 + +/* +* System timer consists of two programmable 32-bit +* decrementing counters that generate individual interrupts to +* the Cortex-M3 processor +*/ +#define MSF2_NUM_TIMERS 2 + +typedef struct MSF2State { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +ARMv7MState armv7m; + +char *part_name; +uint64_t envm_size; +uint64_t esram_size; + +uint32_t m3clk; +uint32_t apb0div; +uint32_t apb1div; + +MSF2SysregState sysreg; +MSSTimerState timer; +MSSSpiState spi[MSF2_NUM_SPIS ]; +}MSF2State ; + +#endif
Re: [Qemu-devel] [Qemu devel v8 PATCH 4/5] msf2: Add Smartfusion2 SoC
Hi Philippe,
All patches got Reviewed-by. Do you want me to change alias to remap and send
v9 or wait so that you get time to review?
Thanks,
Sundeep
Quoted 384 lines · sundeep subbaraya
Hi Philippe,
Quoted 152 lines · Philippe Mathieu-Daudé
Quoted 150 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 | 218 ++++++++++++++++++++++++++++++ ++++++++++ include/hw/arm/msf2-soc.h | 66 ++++++++++++ 4 files changed, 286 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,218 @@ +/* +* 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 +29
-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" + +#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 +43
-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 Quoted 8 lines
hw/arm/msf2-soc.c line 101
Quoted 6 lines
hw/arm/msf2-soc.c new file +5
-0+* 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.alias",you can drop the ".alias", this function already prepends "alias "
.remap sounds good?
Thanks,
SundeepQuoted 211 lines
+ nvm, 0,
s->envm_size);Quoted 208 lines
hw/arm/msf2-soc.c new file +7
-0+ +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);
hw/arm/msf2-soc.c new file +5
-0+ + 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 +19
-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);
hw/arm/msf2-soc.c new file +15
-0+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 +25
-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); + } +} + +static Property m2sxxx_soc_properties[] = { +/* +* part name specifies the type of SmartFusion2 device variant(this +* property is for information purpose only. +*/ +DEFINE_PROP_STRING ("part-name" , MSF2State, part_name), + DEFINE_PROP_UINT64("eNVM-size", MSF2State, envm_size,
MSF2_ENVM_MAX_SIZE),hw/arm/msf2-soc.c new file +32
-0+DEFINE_PROP_UINT64 ("eSRAM-size" , MSF2State, esram_size, +MSF2_ESRAM_MAX_SIZE ), +/* Libero GUI shows 100Mhz as default for clocks */ +DEFINE_PROP_UINT32 ("m3clk" , MSF2State, m3clk,100 *1000000 ), +/* default divisors in Libero GUI */ +DEFINE_PROP_UINT32 ("apb0div" , MSF2State, apb0div,2 ), +DEFINE_PROP_UINT32 ("apb1div" , MSF2State, apb1div,2 ), + DEFINE_PROP_END_OF_LIST(), +}; + +static void m2sxxx_soc_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = m2sxxx_soc_realize; + dc->props = m2sxxx_soc_properties; +} + +static const TypeInfo m2sxxx_soc_info = { + .name =TYPE_MSF2_SOC , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (MSF2State), + .instance_init = m2sxxx_soc_initfn, + .class_init = m2sxxx_soc_class_init, +}; + +static void m2sxxx_soc_types (void ) +{ +type_register_static (&m2sxxx_soc_info); +} + +type_init (m2sxxx_soc_types)include/hw/arm/msf2-soc.h new file +6
-0@@ -0,0 +1,66 @@ +/* +* Microsemi Smartfusion2 SoC +* +* Copyright (c) 2017 Subbaraya Sundeep <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */include/hw/arm/msf2-soc.h new file +43
-0+ +#ifndef HW_ARM_MSF2_SOC_H +#define HW_ARM_MSF2_SOC_H + +#include "hw/arm/armv7m.h" +#include "hw/timer/mss-timer.h" +#include "hw/misc/msf2-sysreg.h" +#include "hw/ssi/mss-spi.h" + +#define TYPE_MSF2_SOC "msf2-soc" +#define MSF2_SOC (obj) OBJECT_CHECK(MSF2State, (obj), TYPE_MSF2_SOC) + +#define MSF2_NUM_SPIS 2 +#define MSF2_NUM_UARTS 2 + +/* +* System timer consists of two programmable 32-bit +* decrementing counters that generate individual interrupts to +* the Cortex-M3 processor +*/ +#define MSF2_NUM_TIMERS 2 + +typedef struct MSF2State { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +ARMv7MState armv7m; + +char *part_name; +uint64_t envm_size; +uint64_t esram_size; + +uint32_t m3clk; +uint32_t apb0div; +uint32_t apb1div; + +MSF2SysregState sysreg; +MSSTimerState timer; +MSSSpiState spi[MSF2_NUM_SPIS ]; +}MSF2State ; + +#endif
Re: [Qemu-arm] [Qemu devel v8 PATCH 4/5] msf2: Add Smartfusion2 SoC
Hi Philippe,
Quoted 7 lines · sundeep subbaraya
Hi Philippe,
All patches got Reviewed-by. Do you want me to change alias to remap and send
v9 or wait so that you get time to review?Sorry. My bad, I overlooked your comment. I will just drop alias and send
v9.
Thanks,
Sundeep
Quoted 396 lines
Thanks,
SundeepOn Fri, Sep 8, 2017 at 12:56 PM, sundeep subbaraya <[email protected]
Quoted 391 lines
wrote:
Hi Philippe,
Quoted 153 lines · Philippe Mathieu-Daudé
Quoted 151 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 | 218 ++++++++++++++++++++++++++++++ ++++++++++ include/hw/arm/msf2-soc.h | 66 ++++++++++++ 4 files changed, 286 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,218 @@ +/* +* 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 +29
-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" + +#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 +43
-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 Quoted 8 lines
hw/arm/msf2-soc.c line 101
Quoted 6 lines
hw/arm/msf2-soc.c new file +5
-0+* 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.alias",you can drop the ".alias", this function already prepends "alias "
.remap sounds good?
Thanks,
SundeepQuoted 215 lines
+ nvm, 0,
s->envm_size);Quoted 212 lines
hw/arm/msf2-soc.c new file +2
-0+ + memory_region_add_subregion(system_memory, ENVM_BASE_ADDRESS,nvm);
hw/arm/msf2-soc.c new file +5
-0+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);
hw/arm/msf2-soc.c new file +5
-0+ + 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 +12
-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);hw/arm/msf2-soc.c new file +6
-0+ } + } + + 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);hw/arm/msf2-soc.c new file +15
-0+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 +25
-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); + } +} + +static Property m2sxxx_soc_properties[] = { +/* +* part name specifies the type of SmartFusion2 device variant(this +* property is for information purpose only. +*/ +DEFINE_PROP_STRING ("part-name" , MSF2State, part_name), + DEFINE_PROP_UINT64("eNVM-size", MSF2State, envm_size,
MSF2_ENVM_MAX_SIZE),hw/arm/msf2-soc.c new file +32
-0+DEFINE_PROP_UINT64 ("eSRAM-size" , MSF2State, esram_size, +MSF2_ESRAM_MAX_SIZE ), +/* Libero GUI shows 100Mhz as default for clocks */ +DEFINE_PROP_UINT32 ("m3clk" , MSF2State, m3clk,100 *1000000 ), +/* default divisors in Libero GUI */ +DEFINE_PROP_UINT32 ("apb0div" , MSF2State, apb0div,2 ), +DEFINE_PROP_UINT32 ("apb1div" , MSF2State, apb1div,2 ), + DEFINE_PROP_END_OF_LIST(), +}; + +static void m2sxxx_soc_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = m2sxxx_soc_realize; + dc->props = m2sxxx_soc_properties; +} + +static const TypeInfo m2sxxx_soc_info = { + .name =TYPE_MSF2_SOC , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (MSF2State), + .instance_init = m2sxxx_soc_initfn, + .class_init = m2sxxx_soc_class_init, +}; + +static void m2sxxx_soc_types (void ) +{ +type_register_static (&m2sxxx_soc_info); +} + +type_init (m2sxxx_soc_types)include/hw/arm/msf2-soc.h new file +6
-0@@ -0,0 +1,66 @@ +/* +* Microsemi Smartfusion2 SoC +* +* Copyright (c) 2017 Subbaraya Sundeep <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */include/hw/arm/msf2-soc.h new file +43
-0+ +#ifndef HW_ARM_MSF2_SOC_H +#define HW_ARM_MSF2_SOC_H + +#include "hw/arm/armv7m.h" +#include "hw/timer/mss-timer.h" +#include "hw/misc/msf2-sysreg.h" +#include "hw/ssi/mss-spi.h" + +#define TYPE_MSF2_SOC "msf2-soc" +#define MSF2_SOC (obj) OBJECT_CHECK(MSF2State, (obj), TYPE_MSF2_SOC) + +#define MSF2_NUM_SPIS 2 +#define MSF2_NUM_UARTS 2 + +/* +* System timer consists of two programmable 32-bit +* decrementing counters that generate individual interrupts to +* the Cortex-M3 processor +*/ +#define MSF2_NUM_TIMERS 2 + +typedef struct MSF2State { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +ARMv7MState armv7m; + +char *part_name; +uint64_t envm_size; +uint64_t esram_size; + +uint32_t m3clk; +uint32_t apb0div; +uint32_t apb1div; + +MSF2SysregState sysreg; +MSSTimerState timer; +MSSSpiState spi[MSF2_NUM_SPIS ]; +}MSF2State ; + +#endif
Re: [Qemu-arm] [Qemu devel v8 PATCH 4/5] msf2: Add Smartfusion2 SoC
In reply to sundeep subbarayaHi Sundeep,
Quoted 2 lines · sundeep subbaraya
All patches got Reviewed-by. Do you want me to change alias to remap and send
This is just cosmetic for the "alias MSF2.eNVM.alias":
(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.alias @MSF2.eNVM 0000000000000000-000000000003ffff
0000000020000000-000000002000ffff (prio 0, ram): MSF2.eSRAM
0000000060000000-000000006003ffff (prio 0, rom): MSF2.eNVM
00000000a0000000-00000000a3ffffff (prio 0, ram): ddr-ramQuoted 1 line
v9 or wait so that you get time to review?
I have a draft for your patch 2, I'll send within the day.
Regards,
Phil.
PATCH v8 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 | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 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 +95 -0
95 lines not on this page · raw message
Signature · 1 line
2.5.0
Re: [Qemu-arm] [Qemu devel v8 PATCH 5/5] msf2: Add Emcraft's Smartfusion2 SOM kit
hw/arm/msf2-som.c line 92
Quoted 7 lines · Subbaraya Sundeep
Emulated Emcraft's Smartfusion2 System On Module starter kit.
hw/arm/msf2-som.c new file +5
-0+static void emcraft_sf2_machine_init (MachineClass *mc) +{ + mc->desc ="SmartFusion2 SOM kit from Emcraft (M2S010)" ; + mc->init = emcraft_sf2_s2s010_init; + mc->ignore_memory_transaction_failures = true;
Please don't set ignore_memory_transaction_failures in new boards. This is a legacy-old-code-only flag.
New boards should define enough devices, either properly or using create_unimplemented_device(), to make whatever code they're being tested against run.
This is a firm requirement for this code to go into master, because once we let a board in with the flag set it's almost impossible to clear it because we don't know what guest code that previously worked on the board will now break.
thanks
-- PMM
Re: [Qemu-arm] [Qemu devel v8 PATCH 5/5] msf2: Add Emcraft's Smartfusion2 SOM kit
Quoted 11 lines · Peter Maydell
hw/arm/msf2-som.c line 92
Quoted 7 lines · Subbaraya Sundeep
Emulated Emcraft's Smartfusion2 System On Module starter kit.
hw/arm/msf2-som.c new file +5
-0+static void emcraft_sf2_machine_init (MachineClass *mc) +{ + mc->desc ="SmartFusion2 SOM kit from Emcraft (M2S010)" ; + mc->init = emcraft_sf2_s2s010_init; + mc->ignore_memory_transaction_failures = true;Please don't set
ignore_memory_transaction_failuresin new boards. This is a legacy-old-code-only flag.
What about adding a such check in scripts/checkpatch.pl ?
if ($line =~ /ignore_memory_transaction_failures\s+=/) {
ERROR("ignore_memory_transaction_failures() is a
legacy-old-code-only flag\n" . $herecurr);
}Quoted 13 lines
New boards should define enough devices, either properly or using
create_unimplemented_device(), to make whatever code they're being tested against run.This is a firm requirement for this code to go into master, because once we let a board in with the flag set it's almost impossible to clear it because we don't know what guest code that previously worked on the board will now break.
thanks
-- PMM
Re: [Qemu-arm] [Qemu devel v8 PATCH 5/5] msf2: Add Emcraft's Smartfusion2 SOM kit
In reply to Peter MaydellHi Peter,
Quoted 13 lines · Peter Maydell
hw/arm/msf2-som.c line 92
Quoted 7 lines · Subbaraya Sundeep
Emulated Emcraft's Smartfusion2 System On Module starter kit.
hw/arm/msf2-som.c new file +5
-0+static void emcraft_sf2_machine_init (MachineClass *mc) +{ + mc->desc ="SmartFusion2 SOM kit from Emcraft (M2S010)" ; + mc->init = emcraft_sf2_s2s010_init; + mc->ignore_memory_transaction_failures = true;Please don't set
ignore_memory_transaction_failuresin new boards. This is a legacy-old-code-only flag.
Quoted 9 lines
New boards should define enough devices, either properly or using
create_unimplemented_device(), to make whatever code they're being tested against run.This is a firm requirement for this code to go into master, because once we let a board in with the flag set it's almost impossible to clear it because we don't know what guest code that previously worked on the board will now break.
Ok. I am working on it and will send next spin with this fix.
Thanks,
Sundeep
Quoted 3 lines
thanks
-- PMM
Hi Subbaraya,
very good work!
Quoted 9 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.
Quoted 3 lines
Testing:
./arm-softmmu/qemu-system-arm -M smartfusion2-som -serial mon:stdio \
-kernel u-boot.bin -display none -drive file=spi.bin,if=mtd,format=raw
"-M emcraft-sf2" ;)
U-Boot 2010.03-00147-g7da5092 (Jul 03 2017 - 09:04:50)
CPU : SmartFusion2 SoC (Cortex-M3 Hard IP) Freqs: CORTEX-M3=142MHz,PCLK0=71MHz,PCLK1=71MHz Board: M2S-FG484-SOM Rev 1A, www.emcraft.com DRAM: 64 MB
*** Warning - bad CRC, using default environment
In: serial Out: serial Err: serial Net: M2S_MAC Hit any key to stop autoboot: 0 16384 KiB S25FL128P_64K at 0:0 is now current device ## Booting kernel from Legacy Image at a0007fc0 ... Image Name: dtskernel Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 2664224 Bytes = 2.5 MB
Load Address: a0008000
Entry Point: a0008001
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK
Starting kernel ...
NVIC: Bad read offset 0xd74
[ 0.000000] Booting Linux on physical CPU 0x0 [ 0.000000] Linux version 4.5.0-00001-g3aa90e8-dirty (sundeep@sundeep-Vostro-3458) (gcc version 5.4.0 (GCC) ) #102 PREEMPT Tue May 16 19:43:40 IST 2017 [ 0.000000] CPU: ARMv7-M [410fc231] revision 1 (ARMv7M), cr=00000000 [ 0.000000] CPU: unknown data cache, unknown instruction cache [ 0.000000] Machine model: Microsemi SmartFusion 2 development board [ 0.000000] Kernel command line: console=ttyS0,115200n8 panic=10 mem=64M@0xa0000000 earlyprintk [ 0.000000] Memory: 62204K/65536K available (1472K kernel code, 73K rwdata, 652K rodata, 400K init, 120K bss, 3332K reserved, 0K cma-reserved) [ 0.000000] NR_IRQS:16 nr_irqs:16 16 [ 0.001178] sched_clock: 32 bits at 83MHz, resolution 12ns, wraps every 25873297401ns [ 0.003085] clocksource: msf2_clocksource: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 23027234290 ns [ 0.009732] timer at 40004000, irq=16 [ 0.014475] Calibrating delay loop... 442.36 BogoMIPS (lpj=2211840) [ 0.653685] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled [ 0.690789] console [ttyS0] disabled [ 0.696659] 40000000.serial: ttyS0 at MMIO 0x40000000 (irq = 17, base_baud = 5187500) is a 16550 [ 0.702725] console [ttyS0] enabled [ 0.826251] Freeing unused kernel memory: 400K (a021c000 - a0280000)
init started: BusyBox v1.24.1 (2017-05-15 09:57:00 IST) ~ #
(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.alias @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
0000000040004000-000000004000402f (prio 0, i/o): mss-timer
0000000040011000-000000004001103f (prio 0, i/o): mss-spi
0000000040038000-00000000400382ff (prio 0, i/o): msf2-sysreg
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(qemu) info qtree
bus: main-system-bus
type System
dev: msf2-soc, id ""
part-name = "M2S010"
eNVM-size = 262144 (0x40000)
eSRAM-size = 65536 (0x10000)
m3clk = 142000000 (0x876bf80)
apb0div = 2 (0x2)
apb1div = 2 (0x2)
dev: mss-spi, id ""
gpio-out "sysbus-irq" 2
mmio 0000000040011000/0000000000000040
bus: spi
type SSI
dev: mss-spi, id ""
gpio-out "sysbus-irq" 2
mmio 0000000040001000/0000000000000040
bus: spi
type SSI
dev: s25sl12801, id ""
gpio-in "ssi-gpio-cs" 1
nonvolatile-cfg = 36863 (0x8fff)
spansion-cr1nv = 0 (0x0)
spansion-cr2nv = 1 (0x1)
spansion-cr3nv = 2 (0x2)
spansion-cr4nv = 16 (0x10)
drive = "mtd0"
dev: mss-timer, id ""
gpio-out "sysbus-irq" 2
clock-frequency = 71000000 (0x43b5fc0)
mmio 0000000040004000/0000000000000030
dev: msf2-sysreg, id ""
apb0divisor = 2 (0x2)
apb1divisor = 2 (0x2)
mmio 0000000040038000/0000000000000300So far:
Just some comments (no need to fix):
M2S-FG484-SOM> reset
resetting ...
M2S-FG484-SOM>
Hmm no reset, I was expecting some unimp/guest-error warning.
M2S-FG484-SOM> tftpbootm2s_eth_init: FIFO initialization timeout
*** m2s_mac_dump_regs FIFO init:
DMA TX CTRL=00000000;DESC=00000000;STAT=00000000
DMA RX CTRL=00000000;DESC=00000000;STAT=00000000
DMA IRQ 00000000/00000000 CFG1=00000000;CFG2=00000000;IFG=00000000;HD=00000000;MFL=00000000 IFCTRL=00000000;IFSTAT=00000000;ADR1=00000000;ADR2=00000000 FIFO CFG 00000000/00000000/00000000/00000000/00000000/00000000/ FIFO ACC
00000000/00000000/00000000/00000000/00000000/00000000/00000000/00000000/
(same unimp/guest-error warning)
M2S-FG484-SOM> sf erase 0 0x1000
UNHANDLED EXCEPTION: HARD FAULT
R0 = 00000072 R1 = 00000072
R2 = 09fa3af0 R3 = 004c8000
R12 = 00000004 LR = 00000a27
PC = 0000ec98 PSR = 01000000
[hang]
IN:0x0000029e: e7fe b.n 0x29e
Quoted 92 lines
Binaries 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.gitLinux is 4.5 linux with Smartfusion2 SoC dts and clocksource driver added by myself @
https://github.com/Subbaraya-Sundeep/linux.gitv8:
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.v7:
Removedvmstate_register_ram_globalas per latest commit Moved header files to C which are local to C source files Removedabort()frommsf2-sysreg.c
Added VMStateDescription inmss-timer.cv6:
Moved some defines from header files to source files Added properties m3clk, apb0div, apb0div1 properties to soc.
Added properties apb0divisor, apb1divisor to sysreg Updatesystem_clock_sourceinmsf2-soc.cChanged machine name smartfusion2-som->emcraft-sf2v5
As per Philippe comments:
Added abort in Sysreg if guest tries to remap memory other than default mapping.
Use ofCONFIG_MSF2inMakefileforsoc.c
Fixed incorrect logic in timer model.
Renamedmsf2-timer.c->mss-timer.c
msf2-spi.c->mss-spi.calso type names
Renamed functionmsf2_init->emcraft_sf2_initinmsf2-som.cAdded 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 sysregThanks,
SundeepSubbaraya 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 kitdefault-configs/arm-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/msf2-soc.c | 218 ++++++++++++++++++++++ hw/arm/msf2-som.c | 95 ++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/msf2-sysreg.c | 195 +++++++++++++++++++ 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 | 78 ++++++++ include/hw/ssi/mss-spi.h | 58 ++++++ include/hw/timer/mss-timer.h | 64 +++++++ 14 files changed, 1472 insertions(+)create mode 100644
hw/arm/msf2-soc.ccreate mode 100644hw/arm/msf2-som.ccreate mode 100644hw/misc/msf2-sysreg.ccreate mode 100644hw/ssi/mss-spi.ccreate mode 100644hw/timer/mss-timer.ccreate mode 100644include/hw/arm/msf2-soc.hcreate mode 100644include/hw/misc/msf2-sysreg.hcreate mode 100644include/hw/ssi/mss-spi.hcreate mode 100644include/hw/timer/mss-timer.h
Hi Phillipe,
Quoted 15 lines · Philippe Mathieu-Daudé
Hi Subbaraya,
very good work!
Quoted 9 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.
Quoted 7 lines
Quoted 4 lines
Testing:
./arm-softmmu/qemu-system-arm -M smartfusion2-som -serial mon:stdio \
-kernel u-boot.bin -display none -drive file=spi.bin,if=mtd,format=raw"-M emcraft-sf2" ;)
copy/paste error :)
Quoted 112 lines
U-Boot 2010.03-00147-g7da5092 (Jul 03 2017 - 09:04:50)
CPU : SmartFusion2 SoC (Cortex-M3 Hard IP) Freqs: CORTEX-M3=142MHz,PCLK0=71MHz,PCLK1=71MHz Board: M2S-FG484-SOM Rev 1A, www.emcraft.com DRAM: 64 MB*** Warning - bad CRC, using default environment
In: serial Out: serial Err: serial Net: M2S_MAC Hit any key to stop autoboot: 0 16384 KiB S25FL128P_64K at 0:0 is now current device ## Booting kernel from Legacy Image at a0007fc0 ... Image Name: dtskernel Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 2664224 Bytes = 2.5 MBLoad Address:
a0008000
Entry Point:a0008001
Verifying Checksum ... OK
Loading Kernel Image ... OK
OKStarting kernel ...
NVIC: Bad read offset
0xd74[ 0.000000] Booting Linux on physical CPU 0x0 [ 0.000000] Linux version 4.5.0-00001-g3aa90e8-dirty (sundeep@sundeep-Vostro-3458) (gcc version 5.4.0 (GCC) ) #102 PREEMPT Tue May 16 19:43:40 IST 2017 [ 0.000000] CPU: ARMv7-M [410fc231] revision 1 (ARMv7M), cr=00000000 [ 0.000000] CPU: unknown data cache, unknown instruction cache [ 0.000000] Machine model: Microsemi SmartFusion 2 development board [ 0.000000] Kernel command line: console=ttyS0,115200n8 panic=10 mem=64M@0xa0000000 earlyprintk [ 0.000000] Memory: 62204K/65536K available (1472K kernel code, 73K rwdata, 652K rodata, 400K init, 120K bss, 3332K reserved, 0K cma-reserved) [ 0.000000] NR_IRQS:16 nr_irqs:16 16 [ 0.001178] sched_clock: 32 bits at 83MHz, resolution 12ns, wraps every 25873297401ns [ 0.003085] clocksource: msf2_clocksource: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 23027234290 ns [ 0.009732] timer at 40004000, irq=16 [ 0.014475] Calibrating delay loop... 442.36 BogoMIPS (lpj=2211840) [ 0.653685] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled [ 0.690789] console [ttyS0] disabled [ 0.696659] 40000000.serial: ttyS0 at MMIO 0x40000000 (irq = 17, base_baud = 5187500) is a 16550 [ 0.702725] console [ttyS0] enabled [ 0.826251] Freeing unused kernel memory: 400K (a021c000 - a0280000)init started: BusyBox v1.24.1 (2017-05-15 09:57:00 IST) ~ #
(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.alias @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 0000000040004000-000000004000402f (prio 0, i/o): mss-timer 0000000040011000-000000004001103f (prio 0, i/o): mss-spi 0000000040038000-00000000400382ff (prio 0, i/o): msf2-sysreg 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(qemu) info qtree
bus: main-system-bus
type System
dev: msf2-soc, id ""part-name = "M2S010" eNVM-size = 262144 (0x40000) eSRAM-size = 65536 (0x10000) m3clk = 142000000 (0x876bf80) apb0div = 2 (0x2) apb1div = 2 (0x2) dev: mss-spi, id "" gpio-out "sysbus-irq" 2 mmio 0000000040011000/0000000000000040 bus: spi type SSI dev: mss-spi, id "" gpio-out "sysbus-irq" 2 mmio 0000000040001000/0000000000000040 bus: spi type SSI dev: s25sl12801, id "" gpio-in "ssi-gpio-cs" 1 nonvolatile-cfg = 36863 (0x8fff) spansion-cr1nv = 0 (0x0) spansion-cr2nv = 1 (0x1) spansion-cr3nv = 2 (0x2) spansion-cr4nv = 16 (0x10) drive = "mtd0" dev: mss-timer, id "" gpio-out "sysbus-irq" 2 clock-frequency = 71000000 (0x43b5fc0) mmio 0000000040004000/0000000000000030 dev: msf2-sysreg, id "" apb0divisor = 2 (0x2) apb1divisor = 2 (0x2) mmio 0000000040038000/0000000000000300
Quoted 3 lines
So far:
Thanks for testing.
Quoted 2 lines
Just some comments (no need to fix):
Thank you, I will look into these errors once the patchset gets into the tree.
Quoted 19 lines
M2S-FG484-SOM> reset
resetting ...
M2S-FG484-SOM>Hmm no reset, I was expecting some unimp/guest-error warning.
M2S-FG484-SOM> tftpboot
m2s_eth_init: FIFO initialization timeout
***m2s_mac_dump_regsFIFO init:
DMA TX CTRL=00000000;DESC=00000000;STAT=00000000
DMA RX CTRL=00000000;DESC=00000000;STAT=00000000
DMA IRQ 00000000/00000000 CFG1=00000000;CFG2=00000000;IFG=00000000;HD=00000000;MFL=00000000 IFCTRL=00000000;IFSTAT=00000000;ADR1=00000000;ADR2=00000000 FIFO CFG 00000000/00000000/00000000/00000000/00000000/00000000/ FIFO ACC 00000000/00000000/00000000/00000000/00000000/00000000/000000
00/00000000/
Quoted 2 lines
(same unimp/guest-error warning)
If device is not implemented how do I print warning when guest access that device?
Thanks,
Sundeep
Quoted 110 lines
M2S-FG484-SOM> sf erase 0
0x1000
UNHANDLED EXCEPTION: HARD FAULTR0 = 00000072 R1 = 00000072 R2 = 09fa3af0 R3 = 004c8000 R12 = 00000004 LR = 00000a27 PC = 0000ec98 PSR = 01000000[hang]
IN:0x0000029e: e7fe b.n0x29eQuoted 94 lines
Binaries 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.gitLinux is 4.5 linux with Smartfusion2 SoC dts and clocksource driver added by myself @
https://github.com/Subbaraya-Sundeep/linux.gitv8:
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.v7:
Removedvmstate_register_ram_globalas per latest commit Moved header files to C which are local to C source files Removedabort()frommsf2-sysreg.c
Added VMStateDescription inmss-timer.cv6:
Moved some defines from header files to source files Added properties m3clk, apb0div, apb0div1 properties to soc.
Added properties apb0divisor, apb1divisor to sysreg Updatesystem_clock_sourceinmsf2-soc.cChanged machine name smartfusion2-som->emcraft-sf2v5
As per Philippe comments:
Added abort in Sysreg if guest tries to remap memory other than default mapping.
Use ofCONFIG_MSF2inMakefileforsoc.c
Fixed incorrect logic in timer model.
Renamedmsf2-timer.c->mss-timer.c
msf2-spi.c->mss-spi.calso type names
Renamed functionmsf2_init->emcraft_sf2_initinmsf2-som.cAdded 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 sysregThanks,
SundeepSubbaraya 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 kitdefault-configs/arm-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/msf2-soc.c | 218 ++++++++++++++++++++++ hw/arm/msf2-som.c | 95 ++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/msf2-sysreg.c | 195 +++++++++++++++++++ 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 | 78 ++++++++ include/hw/ssi/mss-spi.h | 58 ++++++ include/hw/timer/mss-timer.h | 64 +++++++ 14 files changed, 1472 insertions(+)create mode 100644
hw/arm/msf2-soc.ccreate mode 100644hw/arm/msf2-som.ccreate mode 100644hw/misc/msf2-sysreg.ccreate mode 100644hw/ssi/mss-spi.ccreate mode 100644hw/timer/mss-timer.ccreate mode 100644include/hw/arm/msf2-soc.hcreate mode 100644include/hw/misc/msf2-sysreg.hcreate mode 100644include/hw/ssi/mss-spi.hcreate mode 100644include/hw/timer/mss-timer.h
Quoted 178 lines · sundeep subbaraya
Hi Phillipe,
On Fri, Sep 8, 2017 at 3:14 AM, Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
Hi Subbaraya,
very good work!
On 09/07/2017 04:24 PM, Subbaraya Sundeep wrote:
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 smartfusion2-som -serial mon:stdio \
-kernel u-boot.bin -display none -drive file=spi.bin,if=mtd,format=raw"-M emcraft-sf2" ;)
copy/paste error :)
U-Boot 2010.03-00147-g7da5092 (Jul 03 2017 - 09:04:50) CPU : SmartFusion2 SoC (Cortex-M3 Hard IP) Freqs: CORTEX-M3=142MHz,PCLK0=71MHz,PCLK1=71MHz Board: M2S-FG484-SOM Rev 1A, www.emcraft.com <http://www.emcraft.com> DRAM: 64 MB *** Warning - bad CRC, using default environment In: serial Out: serial Err: serial Net: M2S_MAC Hit any key to stop autoboot: 0 16384 KiB S25FL128P_64K at 0:0 is now current device ## Booting kernel from Legacy Image at a0007fc0 ... Image Name: dtskernel Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 2664224 Bytes = 2.5 MB Load Address: a0008000 Entry Point: a0008001 Verifying Checksum ... OK Loading Kernel Image ... OK OK Starting kernel ... NVIC: Bad read offset 0xd74 [ 0.000000] Booting Linux on physical CPU 0x0 [ 0.000000] Linux version 4.5.0-00001-g3aa90e8-dirty (sundeep@sundeep-Vostro-3458) (gcc version 5.4.0 (GCC) ) #102 PREEMPT Tue May 16 19:43:40 IST 2017 [ 0.000000] CPU: ARMv7-M [410fc231] revision 1 (ARMv7M), cr=00000000 [ 0.000000] CPU: unknown data cache, unknown instruction cache [ 0.000000] Machine model: Microsemi SmartFusion 2 development board [ 0.000000] Kernel command line: console=ttyS0,115200n8 panic=10 mem=64M@0xa0000000 earlyprintk [ 0.000000] Memory: 62204K/65536K available (1472K kernel code, 73K rwdata, 652K rodata, 400K init, 120K bss, 3332K reserved, 0K cma-reserved) [ 0.000000] NR_IRQS:16 nr_irqs:16 16 [ 0.001178] sched_clock: 32 bits at 83MHz, resolution 12ns, wraps every 25873297401ns [ 0.003085] clocksource: msf2_clocksource: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 23027234290 ns [ 0.009732] timer at 40004000, irq=16 [ 0.014475] Calibrating delay loop... 442.36 BogoMIPS (lpj=2211840) [ 0.653685] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled [ 0.690789] console [ttyS0] disabled [ 0.696659] 40000000.serial: ttyS0 at MMIO 0x40000000 (irq = 17, base_baud = 5187500) is a 16550 [ 0.702725] console [ttyS0] enabled [ 0.826251] Freeing unused kernel memory: 400K (a021c000 - a0280000) init started: BusyBox v1.24.1 (2017-05-15 09:57:00 IST) ~ # (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.alias @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 0000000040004000-000000004000402f (prio 0, i/o): mss-timer 0000000040011000-000000004001103f (prio 0, i/o): mss-spi 0000000040038000-00000000400382ff (prio 0, i/o): msf2-sysreg 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 (qemu) info qtree bus: main-system-bus type System dev: msf2-soc, id "" part-name = "M2S010" eNVM-size = 262144 (0x40000) eSRAM-size = 65536 (0x10000) m3clk = 142000000 (0x876bf80) apb0div = 2 (0x2) apb1div = 2 (0x2) dev: mss-spi, id "" gpio-out "sysbus-irq" 2 mmio 0000000040011000/0000000000000040 bus: spi type SSI dev: mss-spi, id "" gpio-out "sysbus-irq" 2 mmio 0000000040001000/0000000000000040 bus: spi type SSI dev: s25sl12801, id "" gpio-in "ssi-gpio-cs" 1 nonvolatile-cfg = 36863 (0x8fff) spansion-cr1nv = 0 (0x0) spansion-cr2nv = 1 (0x1) spansion-cr3nv = 2 (0x2) spansion-cr4nv = 16 (0x10) drive = "mtd0" dev: mss-timer, id "" gpio-out "sysbus-irq" 2 clock-frequency = 71000000 (0x43b5fc0) mmio 0000000040004000/0000000000000030 dev: msf2-sysreg, id "" apb0divisor = 2 (0x2) apb1divisor = 2 (0x2) mmio 0000000040038000/0000000000000300 So far: Tested-by: Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>>Thanks for testing.
Just some comments (no need to fix):
Thank you, I will look into these errors once the patchset gets into the tree.
M2S-FG484-SOM> reset resetting ... M2S-FG484-SOM> Hmm no reset, I was expecting some unimp/guest-error warning. M2S-FG484-SOM> tftpboot m2s_eth_init: FIFO initialization timeout *** m2s_mac_dump_regs FIFO init: DMA TX CTRL=00000000;DESC=00000000;STAT=00000000 DMA RX CTRL=00000000;DESC=00000000;STAT=00000000 DMA IRQ 00000000/00000000 CFG1=00000000;CFG2=00000000;IFG=00000000;HD=00000000;MFL=00000000 IFCTRL=00000000;IFSTAT=00000000;ADR1=00000000;ADR2=00000000 FIFO CFG 00000000/00000000/00000000/00000000/00000000/00000000/ FIFO ACC 00000000/00000000/00000000/00000000/00000000/00000000/00000000/00000000/ (same unimp/guest-error warning)
Quoted 1 line
If device is not implemented how do I print warning when guest access that device?
in hw/arm/msf2-soc.c:
create_unimplemented_device("emac", 0x40041000, 0x1000);and while here:
create_unimplemented_device("i2c_0", 0x40002000, 0x1000);
create_unimplemented_device("i2c_1", 0x40012000, 0x1000);
create_unimplemented_device("rtc", 0x40017000, 0x1000);
create_unimplemented_device("usb", 0x40043000, 0x1000);Then you'll see unimp access running "qemu-system-arm -d unimp"
This can be another patch although.
Regards,
Phil.
Quoted 119 lines
Thanks,
SundeepM2S-FG484-SOM> sf erase 0
0x1000
UNHANDLED EXCEPTION: HARD FAULT
R0 = 00000072 R1 = 00000072
R2 = 09fa3af0 R3 =004c8000
R12 = 00000004 LR =00000a27
PC = 0000ec98 PSR = 01000000
[hang]
IN:
0x0000029e: e7fe b.n 0x29eBinaries u-boot.bin and spi.bin are at:
https://github.com/Subbaraya-Sundeep/qemu-test-binaries.git
<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
<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
<https://github.com/Subbaraya-Sundeep/linux.git>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.v7:
Removedvmstate_register_ram_globalas per latest commit Moved header files to C which are local to C source files Removedabort()frommsf2-sysreg.c
Added VMStateDescription inmss-timer.cv6:
Moved some defines from header files to source files Added properties m3clk, apb0div, apb0div1 properties to soc.
Added properties apb0divisor, apb1divisor to sysreg Updatesystem_clock_sourceinmsf2-soc.cChanged machine name smartfusion2-som->emcraft-sf2v5
As per Philippe comments:
Added abort in Sysreg if guest tries to remap memory other than default mapping.
Use ofCONFIG_MSF2inMakefileforsoc.c
Fixed incorrect logic in timer model.
Renamedmsf2-timer.c->mss-timer.c
msf2-spi.c ->mss-spi.calso type names Renamed functionmsf2_init->emcraft_sf2_initinmsf2-som.cAdded 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 sysregThanks,
SundeepSubbaraya 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 kitdefault-configs/arm-softmmu.ma <http://arm-softmmu.ma>k | 1 + hw/arm/Makefile.objs | 1 + hw/arm/msf2-soc.c | 218 ++++++++++++++++++++++ hw/arm/msf2-som.c | 95 ++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/msf2-sysreg.c | 195 +++++++++++++++++++ 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 | 78 ++++++++ include/hw/ssi/mss-spi.h | 58 ++++++ include/hw/timer/mss-timer.h | 64 +++++++
14 files changed, 1472 insertions(+)
create mode 100644hw/arm/msf2-soc.c
create mode 100644hw/arm/msf2-som.c
create mode 100644hw/misc/msf2-sysreg.c
create mode 100644hw/ssi/mss-spi.c
create mode 100644hw/timer/mss-timer.c
create mode 100644include/hw/arm/msf2-soc.h
create mode 100644include/hw/misc/msf2-sysreg.hcreate mode 100644include/hw/ssi/mss-spi.h
create mode 100644include/hw/timer/mss-timer.h
Quoted 198 lines · Philippe Mathieu-Daudé
Quoted 183 lines · sundeep subbaraya
Hi Phillipe,
On Fri, Sep 8, 2017 at 3:14 AM, Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
Hi Subbaraya,
very good work!
On 09/07/2017 04:24 PM, Subbaraya Sundeep wrote:
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 smartfusion2-som -serial mon:stdio \
-kernel u-boot.bin -display none -drive file=spi.bin,if=mtd,format=raw"-M emcraft-sf2" ;)
copy/paste error :)
U-Boot 2010.03-00147-g7da5092 (Jul 03 2017 - 09:04:50) CPU : SmartFusion2 SoC (Cortex-M3 Hard IP) Freqs: CORTEX-M3=142MHz,PCLK0=71MHz,PCLK1=71MHz Board: M2S-FG484-SOM Rev 1A, www.emcraft.com <http://www.emcraft.com> DRAM: 64 MB *** Warning - bad CRC, using default environment In: serial Out: serial Err: serial Net: M2S_MAC Hit any key to stop autoboot: 0 16384 KiB S25FL128P_64K at 0:0 is now current device ## Booting kernel from Legacy Image at a0007fc0 ... Image Name: dtskernel Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 2664224 Bytes = 2.5 MB Load Address: a0008000 Entry Point: a0008001 Verifying Checksum ... OK Loading Kernel Image ... OK OK Starting kernel ... NVIC: Bad read offset 0xd74 [ 0.000000] Booting Linux on physical CPU 0x0 [ 0.000000] Linux version 4.5.0-00001-g3aa90e8-dirty (sundeep@sundeep-Vostro-3458) (gcc version 5.4.0 (GCC) ) #102 PREEMPT Tue May 16 19:43:40 IST 2017 [ 0.000000] CPU: ARMv7-M [410fc231] revision 1 (ARMv7M), cr=00000000 [ 0.000000] CPU: unknown data cache, unknown instruction cache [ 0.000000] Machine model: Microsemi SmartFusion 2 development board [ 0.000000] Kernel command line: console=ttyS0,115200n8 panic=10 mem=64M@0xa0000000 earlyprintk [ 0.000000] Memory: 62204K/65536K available (1472K kernel code, 73K rwdata, 652K rodata, 400K init, 120K bss, 3332K reserved, 0K cma-reserved) [ 0.000000] NR_IRQS:16 nr_irqs:16 16 [ 0.001178] sched_clock: 32 bits at 83MHz, resolution 12ns, wraps every 25873297401ns [ 0.003085] clocksource: msf2_clocksource: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 23027234290 ns [ 0.009732] timer at 40004000, irq=16 [ 0.014475] Calibrating delay loop... 442.36 BogoMIPS (lpj=2211840) [ 0.653685] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled [ 0.690789] console [ttyS0] disabled [ 0.696659] 40000000.serial: ttyS0 at MMIO 0x40000000 (irq = 17, base_baud = 5187500) is a 16550 [ 0.702725] console [ttyS0] enabled [ 0.826251] Freeing unused kernel memory: 400K (a021c000 - a0280000) init started: BusyBox v1.24.1 (2017-05-15 09:57:00 IST) ~ # (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.alias @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 0000000040004000-000000004000402f (prio 0, i/o): mss-timer 0000000040011000-000000004001103f (prio 0, i/o): mss-spi 0000000040038000-00000000400382ff (prio 0, i/o): msf2-sysreg 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 (qemu) info qtree bus: main-system-bus type System dev: msf2-soc, id "" part-name = "M2S010" eNVM-size = 262144 (0x40000) eSRAM-size = 65536 (0x10000) m3clk = 142000000 (0x876bf80) apb0div = 2 (0x2) apb1div = 2 (0x2) dev: mss-spi, id "" gpio-out "sysbus-irq" 2 mmio 0000000040011000/0000000000000040 bus: spi type SSI dev: mss-spi, id "" gpio-out "sysbus-irq" 2 mmio 0000000040001000/0000000000000040 bus: spi type SSI dev: s25sl12801, id "" gpio-in "ssi-gpio-cs" 1 nonvolatile-cfg = 36863 (0x8fff) spansion-cr1nv = 0 (0x0) spansion-cr2nv = 1 (0x1) spansion-cr3nv = 2 (0x2) spansion-cr4nv = 16 (0x10) drive = "mtd0" dev: mss-timer, id "" gpio-out "sysbus-irq" 2 clock-frequency = 71000000 (0x43b5fc0) mmio 0000000040004000/0000000000000030 dev: msf2-sysreg, id "" apb0divisor = 2 (0x2) apb1divisor = 2 (0x2) mmio 0000000040038000/0000000000000300 So far: Tested-by: Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>>Thanks for testing.
Just some comments (no need to fix):
Thank you, I will look into these errors once the patchset gets into the tree.
M2S-FG484-SOM> reset resetting ... M2S-FG484-SOM> Hmm no reset, I was expecting some unimp/guest-error warning. M2S-FG484-SOM> tftpboot m2s_eth_init: FIFO initialization timeout *** m2s_mac_dump_regs FIFO init: DMA TX CTRL=00000000;DESC=00000000;STAT=00000000 DMA RX CTRL=00000000;DESC=00000000;STAT=00000000 DMA IRQ 00000000/00000000 CFG1=00000000;CFG2=00000000;IFG=00000000;HD=00000000;MFL=00000000 IFCTRL=00000000;IFSTAT=00000000;ADR1=00000000;ADR2=00000000 FIFO CFG 00000000/00000000/00000000/00000000/00000000/00000000/ FIFO ACCQuoted 6 lines
00000000/00000000/00000000/00000000/00000000/00000000/00000000/00000000/
(same unimp/guest-error warning)
If device is not implemented how do I print warning when guest access that device?
in
hw/arm/msf2-soc.c:create_unimplemented_device("emac", 0x40041000, 0x1000);and while here:
Quoted 8 lines
create_unimplemented_device("i2c_0", 0x40002000, 0x1000); create_unimplemented_device("i2c_1", 0x40012000, 0x1000); create_unimplemented_device("rtc", 0x40017000, 0x1000); create_unimplemented_device("usb", 0x40043000, 0x1000);Then you'll see unimp access running "qemu-system-arm -d unimp"
This can be another patch although.
Once you have all the devices there you can enable bus access errors as well. That's a future patch set though.
Thanks,
Alistair
Quoted 4 lines
Regards,
Phil.
Quoted 2 lines · Alistair Francis
Once you have all the devices there you can enable bus access errors as well. That's a future patch set though.
Ah, I hadn't noticed this code was opting out of bus access errors; I don't want to permit new boards which do that, so we do need to fix that in this round. (I just sent an email to that effect in reply to patch 1.)
thanks
-- PMM