ast2400: SMC controllers
Subsystems (2)
v2 cover ast2400: SMC controllers
Hello,
The following adds support for the AST2400 SMC controllers. The device model does not implement all the HW features, linear addressing mode is underway, but it should be complete enough for the OpenBMC distro.
Code is based on Andrew's SCU model :
https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg04420.html
Flash images can be grabbed here for testing :
https://openpower.xyz/job/openbmc-build/distro=ubuntu,target=palmetto/lastSuccessfulBuild/artifact/images/palmetto/flash-palmetto
https://openpower.xyz/job/openpower-op-build/distro=ubuntu,target=palmetto/lastSuccessfulBuild/artifact/images/palmetto.pnor
Changes Since v1:
- included Paolo's fix adding a "drive" property to the flash device model
- fixed drive definition in the test command line
Thanks,
C.
Cédric Le Goater (4):
ast2400: add SMC controllers (FMC and SPI)
ast2400: add SPI flash slave object
ast2400: create SPI flash slaves
tests: add a m25p80 test
Paolo Bonzini (1):
m25p80: qdev-ify drive property
hw/arm/ast2400.c | 31 +++ hw/arm/palmetto-bmc.c | 3 + hw/arm/xilinx_zynq.c | 8 +- hw/arm/xlnx-ep108.c | 9 +- hw/block/m25p80.c | 10 +- hw/microblaze/petalogix_ml605_mmu.c | 9 +- hw/ssi/Makefile.objs | 1 + hw/ssi/aspeed_smc.c | 460 ++++++++++++++++++++++++++++++++++++ include/hw/arm/ast2400.h | 3 + include/hw/ssi/aspeed_smc.h | 105 ++++++++ tests/Makefile.include | 2 + tests/m25p80-test.c | 242 +++++++++++++++++++ 12 files changed, 872 insertions(+), 11 deletions(-) create mode 100644 hw/ssi/aspeed_smc.c create mode 100644 include/hw/ssi/aspeed_smc.h create mode 100644 tests/m25p80-test.c
Signature · 1 line
2.1.4
PATCH v2 1/5 m25p80: qdev-ify drive property
From: Paolo Bonzini <[email protected]>
This allows specifying the property via -drive if=none and creating the flash device with -device.
--- hw/arm/xilinx_zynq.c | 8 +++++++- hw/arm/xlnx-ep108.c | 9 ++++++++- hw/block/m25p80.c | 10 ++-------- hw/microblaze/petalogix_ml605_mmu.c | 9 ++++++++- 4 files changed, 25 insertions(+), 11 deletions(-)
hw/arm/xilinx_zynq.c +7 -1
@@ -138,7 +138,13 @@ static inline void zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq, spi = (SSIBus *)qdev_get_child_bus (dev, bus_name);for (j =0 ; j < num_ss; ++j) { - flash_dev =ssi_create_slave (spi,"n25q128" ); +DriveInfo *dinfo =drive_get_next (IF_MTD ); + flash_dev =ssi_create_slave_no_init (spi,"n25q128" ); +if (dinfo) { +qdev_prop_set_drive (flash_dev,"drive" , +blk_by_legacy_dinfo (dinfo), &error_fatal); + } +qdev_init_nofail (flash_dev); cs_line =qdev_get_gpio_in_named (flash_dev,SSI_GPIO_CS ,0 );sysbus_connect_irq (busdev, i * num_ss + j +1 , cs_line);
hw/arm/xlnx-ep108.c +8 -1
@@ -88,12 +88,19 @@ static void xlnx_ep108_init(MachineState *machine)SSIBus *spi_bus;DeviceState *flash_dev;qemu_irq cs_line; +DriveInfo *dinfo =drive_get_next (IF_MTD );gchar *bus_name =g_strdup_printf ("spi%d" , i); spi_bus = (SSIBus *)qdev_get_child_bus (DEVICE (&s->soc), bus_name);g_free (bus_name); - flash_dev =ssi_create_slave (spi_bus,"sst25wf080" ); + flash_dev =ssi_create_slave_no_init (spi_bus,"sst25wf080" ); +if (dinfo) { +qdev_prop_set_drive (flash_dev,"drive" ,blk_by_legacy_dinfo (dinfo), + &error_fatal); + } +qdev_init_nofail (flash_dev); + cs_line =qdev_get_gpio_in_named (flash_dev,SSI_GPIO_CS ,0 );sysbus_connect_irq (SYS_BUS_DEVICE (&s->soc.spi[i]),1 , cs_line);
hw/block/m25p80.c +2 -8
@@ -881,7 +881,6 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx)static void m25p80_realize (SSISlave *ss,Error **errp) { -DriveInfo *dinfo;Flash *s =M25P80 (ss);M25P80Class *mc =M25P80_GET_CLASS (s);
@@ -890,14 +889,8 @@ static void m25p80_realize(SSISlave *ss, Error **errp) s->size = s->pi->sector_size * s->pi->n_sectors; s->dirty_page =-1 ; -/* FIXME use a qdev drive property instead of drive_get_next() */ - dinfo =drive_get_next (IF_MTD ); - -if (dinfo) { +if (s->blk) {DB_PRINT_L (0 ,"Binding to IF_MTD drive\n" ); - s->blk =blk_by_legacy_dinfo (dinfo); -blk_attach_dev_nofail (s->blk, s); - s->storage =blk_blockalign (s->blk, s->size);if (blk_pread (s->blk,0 , s->storage, s->size) != s->size) {
@@ -925,6 +918,7 @@ static void m25p80_pre_save(void *opaque)static Property m25p80_properties[] = {DEFINE_PROP_UINT32 ("nonvolatile-cfg" , Flash, nonvolatile_cfg,0x8FFF ), +DEFINE_PROP_DRIVE ("drive" , Flash, blk),DEFINE_PROP_END_OF_LIST (), };
hw/microblaze/petalogix_ml605_mmu.c +8 -1
@@ -191,9 +191,16 @@ petalogix_ml605_init(MachineState *machine) spi = (SSIBus *)qdev_get_child_bus (dev,"spi" );for (i =0 ; i <NUM_SPI_FLASHES ; i++) { +DriveInfo *dinfo =drive_get_next (IF_MTD );qemu_irq cs_line; - dev =ssi_create_slave (spi,"n25q128" ); + dev =ssi_create_slave_no_init (spi,"n25q128" ); +if (dinfo) { +qdev_prop_set_drive (dev,"drive" ,blk_by_legacy_dinfo (dinfo), + &error_fatal); + } +qdev_init_nofail (dev); + cs_line =qdev_get_gpio_in_named (dev,SSI_GPIO_CS ,0 );sysbus_connect_irq (busdev, i+1 , cs_line); }
Signature · 1 line
2.1.4
Re: [Qemu-arm] [PATCH v2 1/5] m25p80: qdev-ify drive property
Quoted 6 lines · Cédric Le Goater
From: Paolo Bonzini <[email protected]>
This allows specifying the property via -drive if=none and creating the flash device with -device.
Signed-off-by Paolo Bonzini <[email protected]>
You need to add your Signed-off-by line too. You should have used "git am -s" for that, but in this case just replace to my mail with the signoff and the maintainer will collect it.
Thanks for picking up the patch. :)
Paolo
Quoted 110 lines
--- hw/arm/xilinx_zynq.c | 8 +++++++- hw/arm/xlnx-ep108.c | 9 ++++++++- hw/block/m25p80.c | 10 ++-------- hw/microblaze/petalogix_ml605_mmu.c | 9 ++++++++- 4 files changed, 25 insertions(+), 11 deletions(-)hw/arm/xilinx_zynq.c +7
-1@@ -138,7 +138,13 @@ static inline void zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq, spi = (SSIBus *)qdev_get_child_bus (dev, bus_name);for (j =0 ; j < num_ss; ++j) { - flash_dev =ssi_create_slave (spi,"n25q128" ); +DriveInfo *dinfo =drive_get_next (IF_MTD ); + flash_dev =ssi_create_slave_no_init (spi,"n25q128" ); +if (dinfo) { +qdev_prop_set_drive (flash_dev,"drive" , +blk_by_legacy_dinfo (dinfo), &error_fatal); + } +qdev_init_nofail (flash_dev); cs_line =qdev_get_gpio_in_named (flash_dev,SSI_GPIO_CS ,0 );sysbus_connect_irq (busdev, i * num_ss + j +1 , cs_line);hw/arm/xlnx-ep108.c +8
-1@@ -88,12 +88,19 @@ static void xlnx_ep108_init(MachineState *machine)SSIBus *spi_bus;DeviceState *flash_dev;qemu_irq cs_line; +DriveInfo *dinfo =drive_get_next (IF_MTD );gchar *bus_name =g_strdup_printf ("spi%d" , i); spi_bus = (SSIBus *)qdev_get_child_bus (DEVICE (&s->soc), bus_name);g_free (bus_name); - flash_dev =ssi_create_slave (spi_bus,"sst25wf080" ); + flash_dev =ssi_create_slave_no_init (spi_bus,"sst25wf080" ); +if (dinfo) { +qdev_prop_set_drive (flash_dev,"drive" ,blk_by_legacy_dinfo (dinfo), + &error_fatal); + } +qdev_init_nofail (flash_dev); + cs_line =qdev_get_gpio_in_named (flash_dev,SSI_GPIO_CS ,0 );sysbus_connect_irq (SYS_BUS_DEVICE (&s->soc.spi[i]),1 , cs_line);hw/block/m25p80.c +2
-8@@ -881,7 +881,6 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx)static void m25p80_realize (SSISlave *ss,Error **errp) { -DriveInfo *dinfo;Flash *s =M25P80 (ss);M25P80Class *mc =M25P80_GET_CLASS (s);@@ -890,14 +889,8 @@ static void m25p80_realize(SSISlave *ss, Error **errp) s->size = s->pi->sector_size * s->pi->n_sectors; s->dirty_page =-1 ; -/* FIXME use a qdev drive property instead of drive_get_next() */ - dinfo =drive_get_next (IF_MTD ); - -if (dinfo) { +if (s->blk) {DB_PRINT_L (0 ,"Binding to IF_MTD drive\n" ); - s->blk =blk_by_legacy_dinfo (dinfo); -blk_attach_dev_nofail (s->blk, s); - s->storage =blk_blockalign (s->blk, s->size);if (blk_pread (s->blk,0 , s->storage, s->size) != s->size) {@@ -925,6 +918,7 @@ static void m25p80_pre_save(void *opaque)static Property m25p80_properties[] = {DEFINE_PROP_UINT32 ("nonvolatile-cfg" , Flash, nonvolatile_cfg,0x8FFF ), +DEFINE_PROP_DRIVE ("drive" , Flash, blk),DEFINE_PROP_END_OF_LIST (), };hw/microblaze/petalogix_ml605_mmu.c +8
-1@@ -191,9 +191,16 @@ petalogix_ml605_init(MachineState *machine) spi = (SSIBus *)qdev_get_child_bus (dev,"spi" );for (i =0 ; i <NUM_SPI_FLASHES ; i++) { +DriveInfo *dinfo =drive_get_next (IF_MTD );qemu_irq cs_line; - dev =ssi_create_slave (spi,"n25q128" ); + dev =ssi_create_slave_no_init (spi,"n25q128" ); +if (dinfo) { +qdev_prop_set_drive (dev,"drive" ,blk_by_legacy_dinfo (dinfo), + &error_fatal); + } +qdev_init_nofail (dev); + cs_line =qdev_get_gpio_in_named (dev,SSI_GPIO_CS ,0 );sysbus_connect_irq (busdev, i+1 , cs_line); }
Re: [Qemu-arm] [PATCH v2 1/5] m25p80: qdev-ify drive property
Quoted 11 lines · Paolo Bonzini
Quoted 6 lines · Cédric Le Goater
From: Paolo Bonzini <[email protected]>
This allows specifying the property via -drive if=none and creating the flash device with -device.
Signed-off-by Paolo Bonzini <[email protected]>You need to add your Signed-off-by line too.
Yes. Sorry about that :/
I will next round.
Quoted 5 lines
You should have used "git
am -s" for that, but in this case just replace to my mail with the signoff and the maintainer will collect it.Thanks for picking up the patch. :)
That was needed and it should help us for the next item we want to work on. We need more control on the flash storage as we should be mapping it in memory.
Thanks,
C.
Quoted 112 lines
Paolo
Quoted 110 lines
--- hw/arm/xilinx_zynq.c | 8 +++++++- hw/arm/xlnx-ep108.c | 9 ++++++++- hw/block/m25p80.c | 10 ++-------- hw/microblaze/petalogix_ml605_mmu.c | 9 ++++++++- 4 files changed, 25 insertions(+), 11 deletions(-)hw/arm/xilinx_zynq.c +7
-1@@ -138,7 +138,13 @@ static inline void zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq, spi = (SSIBus *)qdev_get_child_bus (dev, bus_name);for (j =0 ; j < num_ss; ++j) { - flash_dev =ssi_create_slave (spi,"n25q128" ); +DriveInfo *dinfo =drive_get_next (IF_MTD ); + flash_dev =ssi_create_slave_no_init (spi,"n25q128" ); +if (dinfo) { +qdev_prop_set_drive (flash_dev,"drive" , +blk_by_legacy_dinfo (dinfo), &error_fatal); + } +qdev_init_nofail (flash_dev); cs_line =qdev_get_gpio_in_named (flash_dev,SSI_GPIO_CS ,0 );sysbus_connect_irq (busdev, i * num_ss + j +1 , cs_line);hw/arm/xlnx-ep108.c +8
-1@@ -88,12 +88,19 @@ static void xlnx_ep108_init(MachineState *machine)SSIBus *spi_bus;DeviceState *flash_dev;qemu_irq cs_line; +DriveInfo *dinfo =drive_get_next (IF_MTD );gchar *bus_name =g_strdup_printf ("spi%d" , i); spi_bus = (SSIBus *)qdev_get_child_bus (DEVICE (&s->soc), bus_name);g_free (bus_name); - flash_dev =ssi_create_slave (spi_bus,"sst25wf080" ); + flash_dev =ssi_create_slave_no_init (spi_bus,"sst25wf080" ); +if (dinfo) { +qdev_prop_set_drive (flash_dev,"drive" ,blk_by_legacy_dinfo (dinfo), + &error_fatal); + } +qdev_init_nofail (flash_dev); + cs_line =qdev_get_gpio_in_named (flash_dev,SSI_GPIO_CS ,0 );sysbus_connect_irq (SYS_BUS_DEVICE (&s->soc.spi[i]),1 , cs_line);hw/block/m25p80.c +2
-8@@ -881,7 +881,6 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx)static void m25p80_realize (SSISlave *ss,Error **errp) { -DriveInfo *dinfo;Flash *s =M25P80 (ss);M25P80Class *mc =M25P80_GET_CLASS (s);@@ -890,14 +889,8 @@ static void m25p80_realize(SSISlave *ss, Error **errp) s->size = s->pi->sector_size * s->pi->n_sectors; s->dirty_page =-1 ; -/* FIXME use a qdev drive property instead of drive_get_next() */ - dinfo =drive_get_next (IF_MTD ); - -if (dinfo) { +if (s->blk) {DB_PRINT_L (0 ,"Binding to IF_MTD drive\n" ); - s->blk =blk_by_legacy_dinfo (dinfo); -blk_attach_dev_nofail (s->blk, s); - s->storage =blk_blockalign (s->blk, s->size);if (blk_pread (s->blk,0 , s->storage, s->size) != s->size) {@@ -925,6 +918,7 @@ static void m25p80_pre_save(void *opaque)static Property m25p80_properties[] = {DEFINE_PROP_UINT32 ("nonvolatile-cfg" , Flash, nonvolatile_cfg,0x8FFF ), +DEFINE_PROP_DRIVE ("drive" , Flash, blk),DEFINE_PROP_END_OF_LIST (), };hw/microblaze/petalogix_ml605_mmu.c +8
-1@@ -191,9 +191,16 @@ petalogix_ml605_init(MachineState *machine) spi = (SSIBus *)qdev_get_child_bus (dev,"spi" );for (i =0 ; i <NUM_SPI_FLASHES ; i++) { +DriveInfo *dinfo =drive_get_next (IF_MTD );qemu_irq cs_line; - dev =ssi_create_slave (spi,"n25q128" ); + dev =ssi_create_slave_no_init (spi,"n25q128" ); +if (dinfo) { +qdev_prop_set_drive (dev,"drive" ,blk_by_legacy_dinfo (dinfo), + &error_fatal); + } +qdev_init_nofail (dev); + cs_line =qdev_get_gpio_in_named (dev,SSI_GPIO_CS ,0 );sysbus_connect_irq (busdev, i+1 , cs_line); }
PATCH v2 2/5 ast2400: add SMC controllers (FMC and SPI)
In reply to Cédric Le GoaterThe Aspeed AST2400 soc includes a static memory controller for the BMC which supports NOR, NAND and SPI flash memory modules. This controller has two modes : the SMC for the legacy interface which supports only one module and the FMC for the new interface which supports up to five modules. The AST2400 also includes a SPI only controller used for the host firmware, commonly called BIOS on Intel. It can be used in three mode : a SPI master, SPI slave and SPI pass-through
Below is the initial framework for the SMC controller (FMC mode only) and the SPI controller: the sysbus object, MMIO for registers configuration and controls. Each controller has a SPI bus and a configurable number of CS lines for SPI flash slaves.
The differences between the controllers are small, so they are abstracted using indirections on the register numbers.
Only SPI flash modules are supported.
--- hw/arm/ast2400.c | 31 +++++ hw/ssi/Makefile.objs | 1 + hw/ssi/aspeed_smc.c | 300 ++++++++++++++++++++++++++++++++++++++++++++ include/hw/arm/ast2400.h | 3 + include/hw/ssi/aspeed_smc.h | 79 ++++++++++++ 5 files changed, 414 insertions(+) create mode 100644 hw/ssi/aspeed_smc.c create mode 100644 include/hw/ssi/aspeed_smc.h
hw/arm/ast2400.c +31 -0
@@ -23,6 +23,9 @@#define AST2400_UART_5_BASE 0x00184000#define AST2400_IOMEM_SIZE 0x00200000#define AST2400_IOMEM_BASE 0x1E600000 +#define AST2400_SMC_BASE AST2400_IOMEM_BASE/* Legacy SMC */ +#define AST2400_FMC_BASE 0X1E620000 +#define AST2400_SPI_BASE 0X1E630000#define AST2400_VIC_BASE 0x1E6C0000#define AST2400_SCU_BASE 0x1E6E2000#define AST2400_TIMER_BASE 0x1E782000
@@ -121,6 +124,14 @@ static void ast2400_init(Object *obj)qdev_prop_set_uint32 (DEVICE (&s->scu), propname, scu_reset[i].val);g_free (propname); } + +object_initialize (&s->smc,sizeof (s->smc),"aspeed.smc.fmc" ); +object_property_add_child (obj,"smc" ,OBJECT (&s->smc),NULL ); +qdev_set_parent_bus (DEVICE (&s->smc),sysbus_get_default ()); + +object_initialize (&s->spi,sizeof (s->spi),"aspeed.smc.spi" ); +object_property_add_child (obj,"spi" ,OBJECT (&s->spi),NULL ); +qdev_set_parent_bus (DEVICE (&s->spi),sysbus_get_default ()); }static void ast2400_realize (DeviceState *dev,Error **errp)
@@ -183,6 +194,26 @@ static void ast2400_realize(DeviceState *dev, Error **errp)sysbus_mmio_map (SYS_BUS_DEVICE (&s->i2c),0 ,AST2400_I2C_BASE );sysbus_connect_irq (SYS_BUS_DEVICE (&s->i2c),0 ,qdev_get_gpio_in (DEVICE (&s->vic),12 )); + +/* SMC */ +object_property_set_int (OBJECT (&s->smc),1 ,"num-cs" , &err); +object_property_set_bool (OBJECT (&s->smc), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->smc),0 ,AST2400_FMC_BASE ); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->smc),0 , +qdev_get_gpio_in (DEVICE (&s->vic),19 )); + +/* SPI */ +object_property_set_int (OBJECT (&s->spi),1 ,"num-cs" , &err); +object_property_set_bool (OBJECT (&s->spi), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->spi),0 ,AST2400_SPI_BASE ); }static void ast2400_class_init (ObjectClass *oc,void *data)
hw/ssi/Makefile.objs +1 -0
@@ -2,6 +2,7 @@ common-obj-$(CONFIG_PL022) += pl022.o common-obj-$(CONFIG_SSI) += ssi.o common-obj-$(CONFIG_XILINX_SPI) += xilinx_spi.o common-obj-$(CONFIG_XILINX_SPIPS) += xilinx_spips.o +common-obj-$(CONFIG_ASPEED_SOC) += aspeed_smc.o obj-$(CONFIG_OMAP) += omap_spi.o obj-$(CONFIG_IMX) += imx_spi.o
hw/ssi/aspeed_smc.c new file +300 -0
300 lines not on this page · raw message
include/hw/arm/ast2400.h +3 -0
@@ -17,6 +17,7 @@#include "hw/misc/aspeed_scu.h" #include "hw/timer/aspeed_timer.h" #include "hw/i2c/aspeed_i2c.h" +#include "hw/ssi/aspeed_smc.h" typedef struct AST2400State { /*< private >*/
@@ -29,6 +30,8 @@ typedef struct AST2400State {AspeedTimerCtrlState timerctrl;AspeedI2CState i2c;AspeedSCUState scu; +AspeedSMCState smc; +AspeedSMCState spi; } AST2400State;#define TYPE_AST2400 "ast2400"
include/hw/ssi/aspeed_smc.h new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v2 3/5 ast2400: add SPI flash slave object
In reply to Cédric Le GoaterEach SPI flash slave can operate in two modes: Command and User. When in User mode, accesses to the memory segment of the slaves are translated in SPI transfers. When in Command mode, the HW generates the SPI commands automatically and the memory segment is accessed as if doing a MMIO. Other SPI controllers call that mode linear addressing mode.
This object is a model proposal for a SPI flash module, gathering SPI slave properties and a MemoryRegion handling the memory accesses. Only the User mode is supported for now but we are preparing ground for the Command mode.
The framework below is sufficient to support Linux which only uses User Mode.
--- hw/ssi/aspeed_smc.c | 97 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/ssi/aspeed_smc.h | 16 ++++++++ 2 files changed, 113 insertions(+)
hw/ssi/aspeed_smc.c +97 -0
@@ -112,6 +112,21 @@ static bool aspeed_smc_is_ce_stop_active(AspeedSMCState *s, int cs)return s->regs[s->r_ctrl0 + cs] &CTRL_CE_STOP_ACTIVE ; } +static inline int aspeed_smc_flash_mode (AspeedSMCState *s,int cs) +{ +return s->regs[s->r_ctrl0 + cs] &CTRL_CMD_MODE_MASK ; +} + +static inline bool aspeed_smc_is_usermode (AspeedSMCState *s,int cs) +{ +return (aspeed_smc_flash_mode (s, cs) ==CTRL_USERMODE ); +} + +static inline bool aspeed_smc_is_writable (AspeedSMCState *s,int cs) +{ +return s->regs[s->r_conf] & (1 << (s->conf_enable_w0 + cs)); +} +static void aspeed_smc_update_cs (AspeedSMCState *s) {int i;
@@ -298,3 +313,85 @@ static void aspeed_smc_register_types(void) }type_init (aspeed_smc_register_types) + +static uint64_t aspeed_smc_flash_read(void *opaque, hwaddr addr, unsigned size) +{ +AspeedSMCFlashState *fl =ASPEED_SMC_FLASH (opaque); +AspeedSMCState *s = fl->controller; +uint64_t ret =0 ; +int i; + +if (aspeed_smc_is_usermode (s, fl->id)) { +for (i =0 ; i < size; i++) { + ret |=ssi_transfer (s->spi,0x0 ) << (8 * i); + } + }else { +error_report ("%s: flash not in usermode" , __func__); + ret =-1 ; + } + +return ret; +} + +static void aspeed_smc_flash_write (void *opaque,hwaddr addr,uint64_t data, +unsigned size) +{ +AspeedSMCFlashState *fl =ASPEED_SMC_FLASH (opaque); +AspeedSMCState *s = fl->controller; +int i; + +if (!aspeed_smc_is_writable (s, fl->id)) { +error_report ("%s: flash is not writable" , __func__); +return ; + } + +if (!aspeed_smc_is_usermode (s, fl->id)) { +error_report ("%s: flash not in usermode" , __func__); +return ; + } + +for (i =0 ; i < size; i++) { +ssi_transfer (s->spi, (data >> (8 * i)) &0xff ); + } +} + +static const MemoryRegionOps aspeed_smc_flash_ops = { + .read = aspeed_smc_flash_read, + .write = aspeed_smc_flash_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =1 , + .max_access_size =4 , + }, +}; + +static const VMStateDescription vmstate_aspeed_smc_flash = { + .name ="aspeed.smc_flash" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT8 (id, AspeedSMCFlashState), +VMSTATE_END_OF_LIST () + } +}; + +static void aspeed_smc_flash_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->vmsd = &vmstate_aspeed_smc_flash; +} + +static const TypeInfo aspeed_smc_flash_info = { + .name =TYPE_ASPEED_SMC_FLASH , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (AspeedSMCState), + .class_init = aspeed_smc_flash_class_init, +}; + +static void aspeed_smc_flash_register_types (void ) +{ +type_register_static (&aspeed_smc_flash_info); +} + +type_init (aspeed_smc_flash_register_types)
include/hw/ssi/aspeed_smc.h +16 -0
@@ -27,6 +27,22 @@#include "hw/ssi/ssi.h" +struct AspeedSMCState ; + +typedef struct AspeedSMCFlashState { +SysBusDevice parent_obj; + +MemoryRegion mmio; +uint8_t id; +size_t size; +struct AspeedSMCState *controller; +DeviceState *flash; +}AspeedSMCFlashState ; + +#define TYPE_ASPEED_SMC_FLASH "aspeed.smc.flash" +#define ASPEED_SMC_FLASH (obj) \ + OBJECT_CHECK(AspeedSMCFlashState, (obj), TYPE_ASPEED_SMC_FLASH) + typedef struct AspeedSMCController { const char *name; uint8_t r_conf;
Signature · 1 line
2.1.4
PATCH v2 4/5 ast2400: create SPI flash slaves
In reply to Cédric Le GoaterA set of SPI flash slaves is attached under the flash controllers of the palmetto platform. "n25q256a" flash modules are used for the BMC and "mx25l25635e" for the host. These types are common in the OpenPower ecosystem.
The segment addresses used for the memory mappings are the defaults provided by the specs. They can be changed with the Segment Address Register but this is not supported in the current implementation.
---
Changes since v1:
- use the "drive" property to define the flash backend
hw/arm/palmetto-bmc.c | 3 ++ hw/ssi/aspeed_smc.c | 69 +++++++++++++++++++++++++++++++++++++++++++-- include/hw/ssi/aspeed_smc.h | 10 +++++++ 3 files changed, 79 insertions(+), 3 deletions(-)
hw/arm/palmetto-bmc.c +3 -0
@@ -47,6 +47,9 @@ static void palmetto_bmc_init(MachineState *machine)object_property_set_bool (OBJECT (&bmc->soc), true,"realized" , &error_abort); +aspeed_smc_init_flashes (&bmc->soc.smc,"n25q256a" , &error_abort); +aspeed_smc_init_flashes (&bmc->soc.spi,"mx25l25635e" , &error_abort); + palmetto_bmc_binfo.kernel_filename = machine->kernel_filename; palmetto_bmc_binfo.initrd_filename = machine->initrd_filename; palmetto_bmc_binfo.kernel_cmdline = machine->kernel_cmdline;
hw/ssi/aspeed_smc.c +66 -3
94 lines not on this page · raw message
include/hw/ssi/aspeed_smc.h +10 -0
@@ -43,6 +43,11 @@ typedef struct AspeedSMCFlashState {#define ASPEED_SMC_FLASH (obj) \ OBJECT_CHECK(AspeedSMCFlashState, (obj), TYPE_ASPEED_SMC_FLASH) +typedef struct AspeedSegments { +hwaddr addr; +uint32_t size; +}AspeedSegments ; + typedef struct AspeedSMCController { const char *name; uint8_t r_conf;
@@ -51,6 +56,7 @@ typedef struct AspeedSMCController {uint8_t r_timings;uint8_t conf_enable_w0;uint8_t max_slaves; +const AspeedSegments *segments; } AspeedSMCController;#define TYPE_ASPEED_SMC "aspeed.smc"
@@ -90,6 +96,10 @@ typedef struct AspeedSMCState {uint8_t r_ctrl0;uint8_t r_timings;uint8_t conf_enable_w0; + + AspeedSMCFlashState **flashes; } AspeedSMCState; +extern void aspeed_smc_init_flashes (AspeedSMCState *s,const char *flashtype, +Error **errp);#endif /* ASPEED_SMC_H */
Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH v2 4/5] ast2400: create SPI flash slaves
Quoted 17 lines · Cédric Le Goater
A set of SPI flash slaves is attached under the flash controllers of the palmetto platform. "n25q256a" flash modules are used for the BMC and "mx25l25635e" for the host. These types are common in the OpenPower ecosystem.
The segment addresses used for the memory mappings are the defaults provided by the specs. They can be changed with the Segment Address Register but this is not supported in the current implementation.
Signed-off-by Cédric Le Goater <[email protected]>---
hw/ssi/aspeed_smc.c +0
-0
hw/ssi/aspeed_smc.c static void aspeed_smc_flash_register_types(void) · line 431
Quoted 10 lines
hw/ssi/aspeed_smc.c +10
-0+void aspeed_smc_init_flashes (AspeedSMCState *s,const char *flashtype, +Error **errp) +{ +int i ; +char name[32 ]; + +for (i =0 ; i < s->num_cs; ++i) { +Object *obj =object_new (TYPE_ASPEED_SMC_FLASH ); +AspeedSMCFlashState *fl =ASPEED_SMC_FLASH (obj); +DriveInfo *dinfo =drive_get_next (IF_MTD );
You don't want to be calling drive_get_next() in code in hw/ssi -- that should be done at the board level, and then the board creates the flash device and sets its drive property and connects the flash device up to the SSI controller.
thanks
-- PMM
Re: [Qemu-devel] [PATCH v2 4/5] ast2400: create SPI flash slaves
Quoted 18 lines · Peter Maydell
Quoted 16 lines · Cédric Le Goater
A set of SPI flash slaves is attached under the flash controllers of the palmetto platform. "n25q256a" flash modules are used for the BMC and "mx25l25635e" for the host. These types are common in the OpenPower ecosystem.
The segment addresses used for the memory mappings are the defaults provided by the specs. They can be changed with the Segment Address Register but this is not supported in the current implementation.
Signed-off-by Cédric Le Goater <[email protected]>---
hw/ssi/aspeed_smc.c +0
-0
Quoted 15 lines
hw/ssi/aspeed_smc.c static void aspeed_smc_flash_register_types(void) · line 431
Quoted 10 lines
hw/ssi/aspeed_smc.c +10
-0+void aspeed_smc_init_flashes (AspeedSMCState *s,const char *flashtype, +Error **errp) +{ +int i ; +char name[32 ]; + +for (i =0 ; i < s->num_cs; ++i) { +Object *obj =object_new (TYPE_ASPEED_SMC_FLASH ); +AspeedSMCFlashState *fl =ASPEED_SMC_FLASH (obj); +DriveInfo *dinfo =drive_get_next (IF_MTD );You don't want to be calling
drive_get_next()in code in hw/ssi -- that should be done at the board level, and then the board creates the flash device and sets its drive property and connects the flash device up to the SSI controller.
OK. I will rework that part.
Thanks,
C.
PATCH v2 5/5 tests: add a m25p80 test
In reply to Cédric Le GoaterThis test uses the palmetto platform and the AST2400 SPI controller to test the m25p80 flash module device model. The flash model is defined by the platform (n25q256a) and it would be nice to find way to control it, using a property probably.
---
Changes since v1:
- fixed guest args to use -drive and not -mtdblock
tests/Makefile.include | 2 + tests/m25p80-test.c | 242 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 244 insertions(+) create mode 100644 tests/m25p80-test.c
tests/Makefile.include +2 -0
@@ -252,6 +252,7 @@ gcov-files-sparc-y += hw/timer/m48t59.c gcov-files-sparc64-y += hw/timer/m48t59.c check-qtest-arm-y = tests/tmp105-test$(EXESUF) check-qtest-arm-y = tests/ds1338-test$(EXESUF) +check-qtest-arm-y = tests/m25p80-test$(EXESUF) gcov-files-arm-y += hw/misc/tmp105.c check-qtest-arm-y += tests/virtio-blk-test$(EXESUF) gcov-files-arm-y += arm-softmmu/hw/block/virtio-blk.c
@@ -562,6 +563,7 @@ tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o \ tests/pxe-test$(EXESUF): tests/pxe-test.o tests/boot-sector.o $(libqos-obj-y) tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y) tests/ds1338-test$(EXESUF): tests/ds1338-test.o $(libqos-imx-obj-y) +tests/m25p80-test$(EXESUF): tests/m25p80-test.o tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y) tests/q35-test$(EXESUF): tests/q35-test.o $(libqos-pc-obj-y) tests/fw_cfg-test$(EXESUF): tests/fw_cfg-test.o $(libqos-pc-obj-y)
tests/m25p80-test.c new file +242 -0
242 lines not on this page · raw message
Signature · 1 line
2.1.4