2022-07-14 16:24:38 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates. (http://www.meta.com)
|
|
|
|
*
|
|
|
|
* This code is licensed under the GPL version 2 or later. See the COPYING
|
|
|
|
* file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
2022-07-14 16:24:38 +02:00
|
|
|
#include "qemu/units.h"
|
|
|
|
#include "qapi/error.h"
|
|
|
|
#include "sysemu/sysemu.h"
|
2022-07-14 16:24:38 +02:00
|
|
|
#include "sysemu/block-backend.h"
|
2022-07-14 16:24:38 +02:00
|
|
|
#include "hw/boards.h"
|
2022-07-14 16:24:38 +02:00
|
|
|
#include "hw/arm/aspeed_soc.h"
|
2022-07-14 16:24:38 +02:00
|
|
|
|
|
|
|
#define TYPE_FBY35 MACHINE_TYPE_NAME("fby35")
|
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(Fby35State, FBY35);
|
|
|
|
|
|
|
|
struct Fby35State {
|
|
|
|
MachineState parent_obj;
|
2022-07-14 16:24:38 +02:00
|
|
|
|
|
|
|
MemoryRegion bmc_memory;
|
|
|
|
MemoryRegion bmc_dram;
|
|
|
|
MemoryRegion bmc_boot_rom;
|
|
|
|
|
|
|
|
AspeedSoCState bmc;
|
2022-07-14 16:24:38 +02:00
|
|
|
|
|
|
|
bool mmio_exec;
|
2022-07-14 16:24:38 +02:00
|
|
|
};
|
|
|
|
|
2022-07-14 16:24:38 +02:00
|
|
|
#define FBY35_BMC_RAM_SIZE (2 * GiB)
|
2022-07-14 16:24:38 +02:00
|
|
|
#define FBY35_BMC_FIRMWARE_ADDR 0x0
|
|
|
|
|
|
|
|
static void fby35_bmc_write_boot_rom(DriveInfo *dinfo, MemoryRegion *mr,
|
|
|
|
hwaddr offset, size_t rom_size,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
|
|
|
|
g_autofree void *storage = NULL;
|
|
|
|
int64_t size;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The block backend size should have already been 'validated' by
|
|
|
|
* the creation of the m25p80 object.
|
|
|
|
*/
|
|
|
|
size = blk_getlength(blk);
|
|
|
|
if (size <= 0) {
|
|
|
|
error_setg(errp, "failed to get flash size");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rom_size > size) {
|
|
|
|
rom_size = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
storage = g_malloc0(rom_size);
|
|
|
|
if (blk_pread(blk, 0, rom_size, storage, 0) < 0) {
|
|
|
|
error_setg(errp, "failed to read the initial flash content");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: find a better way to install the ROM */
|
|
|
|
memcpy(memory_region_get_ram_ptr(mr) + offset, storage, rom_size);
|
|
|
|
}
|
2022-07-14 16:24:38 +02:00
|
|
|
|
|
|
|
static void fby35_bmc_init(Fby35State *s)
|
|
|
|
{
|
2022-07-14 16:24:38 +02:00
|
|
|
DriveInfo *drive0 = drive_get(IF_MTD, 0, 0);
|
|
|
|
|
2022-07-14 16:24:38 +02:00
|
|
|
memory_region_init(&s->bmc_memory, OBJECT(s), "bmc-memory", UINT64_MAX);
|
|
|
|
memory_region_init_ram(&s->bmc_dram, OBJECT(s), "bmc-dram",
|
|
|
|
FBY35_BMC_RAM_SIZE, &error_abort);
|
|
|
|
|
|
|
|
object_initialize_child(OBJECT(s), "bmc", &s->bmc, "ast2600-a3");
|
|
|
|
object_property_set_int(OBJECT(&s->bmc), "ram-size", FBY35_BMC_RAM_SIZE,
|
|
|
|
&error_abort);
|
|
|
|
object_property_set_link(OBJECT(&s->bmc), "memory", OBJECT(&s->bmc_memory),
|
|
|
|
&error_abort);
|
|
|
|
object_property_set_link(OBJECT(&s->bmc), "dram", OBJECT(&s->bmc_dram),
|
|
|
|
&error_abort);
|
|
|
|
object_property_set_int(OBJECT(&s->bmc), "hw-strap1", 0x000000C0,
|
|
|
|
&error_abort);
|
|
|
|
object_property_set_int(OBJECT(&s->bmc), "hw-strap2", 0x00000003,
|
|
|
|
&error_abort);
|
|
|
|
aspeed_soc_uart_set_chr(&s->bmc, ASPEED_DEV_UART5, serial_hd(0));
|
|
|
|
qdev_realize(DEVICE(&s->bmc), NULL, &error_abort);
|
|
|
|
|
|
|
|
aspeed_board_init_flashes(&s->bmc.fmc, "n25q00", 2, 0);
|
2022-07-14 16:24:38 +02:00
|
|
|
|
|
|
|
/* Install first FMC flash content as a boot rom. */
|
|
|
|
if (drive0) {
|
|
|
|
AspeedSMCFlash *fl = &s->bmc.fmc.flashes[0];
|
|
|
|
MemoryRegion *boot_rom = g_new(MemoryRegion, 1);
|
|
|
|
uint64_t size = memory_region_size(&fl->mmio);
|
|
|
|
|
|
|
|
if (s->mmio_exec) {
|
|
|
|
memory_region_init_alias(boot_rom, NULL, "aspeed.boot_rom",
|
|
|
|
&fl->mmio, 0, size);
|
|
|
|
memory_region_add_subregion(&s->bmc_memory, FBY35_BMC_FIRMWARE_ADDR,
|
|
|
|
boot_rom);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
memory_region_init_rom(boot_rom, NULL, "aspeed.boot_rom",
|
|
|
|
size, &error_abort);
|
|
|
|
memory_region_add_subregion(&s->bmc_memory, FBY35_BMC_FIRMWARE_ADDR,
|
|
|
|
boot_rom);
|
|
|
|
fby35_bmc_write_boot_rom(drive0, boot_rom, FBY35_BMC_FIRMWARE_ADDR,
|
|
|
|
size, &error_abort);
|
|
|
|
}
|
|
|
|
}
|
2022-07-14 16:24:38 +02:00
|
|
|
}
|
|
|
|
|
2022-07-14 16:24:38 +02:00
|
|
|
static void fby35_init(MachineState *machine)
|
|
|
|
{
|
2022-07-14 16:24:38 +02:00
|
|
|
Fby35State *s = FBY35(machine);
|
|
|
|
|
|
|
|
fby35_bmc_init(s);
|
2022-07-14 16:24:38 +02:00
|
|
|
}
|
|
|
|
|
2022-07-14 16:24:38 +02:00
|
|
|
|
|
|
|
static bool fby35_get_mmio_exec(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
return FBY35(obj)->mmio_exec;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fby35_set_mmio_exec(Object *obj, bool value, Error **errp)
|
|
|
|
{
|
|
|
|
FBY35(obj)->mmio_exec = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fby35_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
FBY35(obj)->mmio_exec = false;
|
|
|
|
}
|
|
|
|
|
2022-07-14 16:24:38 +02:00
|
|
|
static void fby35_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
MachineClass *mc = MACHINE_CLASS(oc);
|
|
|
|
|
|
|
|
mc->desc = "Meta Platforms fby35";
|
|
|
|
mc->init = fby35_init;
|
2022-07-14 16:24:38 +02:00
|
|
|
mc->no_floppy = 1;
|
|
|
|
mc->no_cdrom = 1;
|
|
|
|
mc->min_cpus = mc->max_cpus = mc->default_cpus = 2;
|
2022-07-14 16:24:38 +02:00
|
|
|
|
|
|
|
object_class_property_add_bool(oc, "execute-in-place",
|
|
|
|
fby35_get_mmio_exec,
|
|
|
|
fby35_set_mmio_exec);
|
|
|
|
object_class_property_set_description(oc, "execute-in-place",
|
|
|
|
"boot directly from CE0 flash device");
|
2022-07-14 16:24:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo fby35_types[] = {
|
|
|
|
{
|
|
|
|
.name = MACHINE_TYPE_NAME("fby35"),
|
|
|
|
.parent = TYPE_MACHINE,
|
|
|
|
.class_init = fby35_class_init,
|
|
|
|
.instance_size = sizeof(Fby35State),
|
2022-07-14 16:24:38 +02:00
|
|
|
.instance_init = fby35_instance_init,
|
2022-07-14 16:24:38 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TYPES(fby35_types);
|