2017-09-20 22:17:37 +02:00
|
|
|
/*
|
|
|
|
* SmartFusion2 SOM starter kit(from Emcraft) emulation.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Subbaraya Sundeep <sundeep.lkml@gmail.com>
|
|
|
|
*
|
|
|
|
* 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"
|
2018-06-25 14:41:58 +02:00
|
|
|
#include "qemu/units.h"
|
2017-09-20 22:17:37 +02:00
|
|
|
#include "qapi/error.h"
|
|
|
|
#include "qemu/error-report.h"
|
|
|
|
#include "hw/boards.h"
|
2019-08-12 07:23:51 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2019-05-23 15:47:43 +02:00
|
|
|
#include "hw/arm/boot.h"
|
2021-08-12 11:33:50 +02:00
|
|
|
#include "hw/qdev-clock.h"
|
2017-09-20 22:17:37 +02:00
|
|
|
#include "exec/address-spaces.h"
|
|
|
|
#include "hw/arm/msf2-soc.h"
|
|
|
|
|
|
|
|
#define DDR_BASE_ADDRESS 0xA0000000
|
2018-06-25 14:41:57 +02:00
|
|
|
#define DDR_SIZE (64 * MiB)
|
2017-09-20 22:17:37 +02:00
|
|
|
|
2018-06-25 14:41:57 +02:00
|
|
|
#define M2S010_ENVM_SIZE (256 * KiB)
|
|
|
|
#define M2S010_ESRAM_SIZE (64 * KiB)
|
2017-09-20 22:17:37 +02:00
|
|
|
|
|
|
|
static void emcraft_sf2_s2s010_init(MachineState *machine)
|
|
|
|
{
|
|
|
|
DeviceState *dev;
|
|
|
|
DeviceState *spi_flash;
|
|
|
|
MSF2State *soc;
|
|
|
|
MachineClass *mc = MACHINE_GET_CLASS(machine);
|
2021-11-17 17:33:58 +01:00
|
|
|
DriveInfo *dinfo = drive_get(IF_MTD, 0, 0);
|
2017-09-20 22:17:37 +02:00
|
|
|
qemu_irq cs_line;
|
ssi: Convert uses of ssi_create_slave_no_init() with Coccinelle
Replace
dev = ssi_create_slave_no_init(bus, type_name);
...
qdev_init_nofail(dev);
by
dev = qdev_new(type_name);
...
qdev_realize_and_unref(dev, bus, &error_fatal);
Recent commit "qdev: New qdev_new(), qdev_realize(), etc." explains
why.
@@
type SSIBus;
identifier bus;
expression dev, qbus, expr;
expression list args;
@@
- bus = (SSIBus *)qbus;
+ bus = qbus; // TODO fix up decl
...
- dev = ssi_create_slave_no_init(bus, args);
+ dev = qdev_new(args);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = ssi_create_slave_no_init(bus, args);
+ dev = qdev_new(args);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, BUS(bus), &error_fatal);
Bus declarations fixed up manually.
Cc: Alistair Francis <alistair@alistair23.me>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-24-armbru@redhat.com>
2020-06-10 07:32:12 +02:00
|
|
|
BusState *spi_bus;
|
2017-09-20 22:17:37 +02:00
|
|
|
MemoryRegion *sysmem = get_system_memory();
|
|
|
|
MemoryRegion *ddr = g_new(MemoryRegion, 1);
|
2021-08-12 11:33:50 +02:00
|
|
|
Clock *m3clk;
|
2017-09-20 22:17:37 +02:00
|
|
|
|
|
|
|
if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) {
|
|
|
|
error_report("This board can only be used with CPU %s",
|
|
|
|
mc->default_cpu_type);
|
2019-07-01 18:26:14 +02:00
|
|
|
exit(1);
|
2017-09-20 22:17:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
memory_region_init_ram(ddr, NULL, "ddr-ram", DDR_SIZE,
|
|
|
|
&error_fatal);
|
|
|
|
memory_region_add_subregion(sysmem, DDR_BASE_ADDRESS, ddr);
|
|
|
|
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:31:58 +02:00
|
|
|
dev = qdev_new(TYPE_MSF2_SOC);
|
2017-09-20 22:17:37 +02:00
|
|
|
qdev_prop_set_string(dev, "part-name", "M2S010");
|
|
|
|
qdev_prop_set_string(dev, "cpu-type", mc->default_cpu_type);
|
|
|
|
|
|
|
|
qdev_prop_set_uint64(dev, "eNVM-size", M2S010_ENVM_SIZE);
|
|
|
|
qdev_prop_set_uint64(dev, "eSRAM-size", M2S010_ESRAM_SIZE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CPU clock and peripheral clocks(APB0, APB1)are configurable
|
|
|
|
* in Libero. CPU clock is divided by APB0 and APB1 divisors for
|
|
|
|
* peripherals. Emcraft's SoM kit comes with these settings by default.
|
|
|
|
*/
|
2021-08-12 11:33:50 +02:00
|
|
|
/* This clock doesn't need migration because it is fixed-frequency */
|
|
|
|
m3clk = clock_new(OBJECT(machine), "m3clk");
|
|
|
|
clock_set_hz(m3clk, 142 * 1000000);
|
|
|
|
qdev_connect_clock_in(dev, "m3clk", m3clk);
|
2017-09-20 22:17:37 +02:00
|
|
|
qdev_prop_set_uint32(dev, "apb0div", 2);
|
|
|
|
qdev_prop_set_uint32(dev, "apb1div", 2);
|
|
|
|
|
sysbus: Convert to sysbus_realize() etc. with Coccinelle
Convert from qdev_realize(), qdev_realize_and_unref() with null @bus
argument to sysbus_realize(), sysbus_realize_and_unref().
Coccinelle script:
@@
expression dev, errp;
@@
- qdev_realize(DEVICE(dev), NULL, errp);
+ sysbus_realize(SYS_BUS_DEVICE(dev), errp);
@@
expression sysbus_dev, dev, errp;
@@
+ sysbus_dev = SYS_BUS_DEVICE(dev);
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
- sysbus_dev = SYS_BUS_DEVICE(dev);
@@
expression sysbus_dev, dev, errp;
expression expr;
@@
sysbus_dev = SYS_BUS_DEVICE(dev);
... when != dev = expr;
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(DEVICE(dev), NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
Whitespace changes minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-46-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:32:34 +02:00
|
|
|
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
|
2017-09-20 22:17:37 +02:00
|
|
|
|
|
|
|
soc = MSF2_SOC(dev);
|
|
|
|
|
|
|
|
/* Attach SPI flash to SPI0 controller */
|
ssi: Convert uses of ssi_create_slave_no_init() with Coccinelle
Replace
dev = ssi_create_slave_no_init(bus, type_name);
...
qdev_init_nofail(dev);
by
dev = qdev_new(type_name);
...
qdev_realize_and_unref(dev, bus, &error_fatal);
Recent commit "qdev: New qdev_new(), qdev_realize(), etc." explains
why.
@@
type SSIBus;
identifier bus;
expression dev, qbus, expr;
expression list args;
@@
- bus = (SSIBus *)qbus;
+ bus = qbus; // TODO fix up decl
...
- dev = ssi_create_slave_no_init(bus, args);
+ dev = qdev_new(args);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = ssi_create_slave_no_init(bus, args);
+ dev = qdev_new(args);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, BUS(bus), &error_fatal);
Bus declarations fixed up manually.
Cc: Alistair Francis <alistair@alistair23.me>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-24-armbru@redhat.com>
2020-06-10 07:32:12 +02:00
|
|
|
spi_bus = qdev_get_child_bus(dev, "spi0");
|
|
|
|
spi_flash = qdev_new("s25sl12801");
|
2017-09-20 22:17:37 +02:00
|
|
|
qdev_prop_set_uint8(spi_flash, "spansion-cr2nv", 1);
|
|
|
|
if (dinfo) {
|
qdev: Make qdev_prop_set_drive() match the other helpers
qdev_prop_set_drive() can fail. None of the other qdev_prop_set_FOO()
can; they abort on error.
To clean up this inconsistency, rename qdev_prop_set_drive() to
qdev_prop_set_drive_err(), and create a qdev_prop_set_drive() that
aborts on error.
Coccinelle script to update callers:
@ depends on !(file in "hw/core/qdev-properties-system.c")@
expression dev, name, value;
symbol error_abort;
@@
- qdev_prop_set_drive(dev, name, value, &error_abort);
+ qdev_prop_set_drive(dev, name, value);
@@
expression dev, name, value, errp;
@@
- qdev_prop_set_drive(dev, name, value, errp);
+ qdev_prop_set_drive_err(dev, name, value, errp);
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200622094227.1271650-14-armbru@redhat.com>
2020-06-22 11:42:24 +02:00
|
|
|
qdev_prop_set_drive_err(spi_flash, "drive",
|
|
|
|
blk_by_legacy_dinfo(dinfo), &error_fatal);
|
2017-09-20 22:17:37 +02:00
|
|
|
}
|
ssi: Convert uses of ssi_create_slave_no_init() with Coccinelle
Replace
dev = ssi_create_slave_no_init(bus, type_name);
...
qdev_init_nofail(dev);
by
dev = qdev_new(type_name);
...
qdev_realize_and_unref(dev, bus, &error_fatal);
Recent commit "qdev: New qdev_new(), qdev_realize(), etc." explains
why.
@@
type SSIBus;
identifier bus;
expression dev, qbus, expr;
expression list args;
@@
- bus = (SSIBus *)qbus;
+ bus = qbus; // TODO fix up decl
...
- dev = ssi_create_slave_no_init(bus, args);
+ dev = qdev_new(args);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = ssi_create_slave_no_init(bus, args);
+ dev = qdev_new(args);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, BUS(bus), &error_fatal);
Bus declarations fixed up manually.
Cc: Alistair Francis <alistair@alistair23.me>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-24-armbru@redhat.com>
2020-06-10 07:32:12 +02:00
|
|
|
qdev_realize_and_unref(spi_flash, spi_bus, &error_fatal);
|
2017-09-20 22:17:37 +02:00
|
|
|
cs_line = qdev_get_gpio_in_named(spi_flash, SSI_GPIO_CS, 0);
|
|
|
|
sysbus_connect_irq(SYS_BUS_DEVICE(&soc->spi[0]), 1, cs_line);
|
|
|
|
|
|
|
|
armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,
|
|
|
|
soc->envm_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void emcraft_sf2_machine_init(MachineClass *mc)
|
|
|
|
{
|
|
|
|
mc->desc = "SmartFusion2 SOM kit from Emcraft (M2S010)";
|
|
|
|
mc->init = emcraft_sf2_s2s010_init;
|
|
|
|
mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m3");
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_MACHINE("emcraft-sf2", emcraft_sf2_machine_init)
|