xref: /openbmc/qemu/hw/loongarch/fw_cfg.c (revision d804ad98)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * QEMU fw_cfg helpers (LoongArch specific)
4  *
5  * Copyright (C) 2021 Loongson Technology Corporation Limited
6  */
7 
8 #include "qemu/osdep.h"
9 #include "hw/loongarch/fw_cfg.h"
10 #include "hw/loongarch/virt.h"
11 #include "hw/nvram/fw_cfg.h"
12 #include "sysemu/sysemu.h"
13 
fw_cfg_boot_set(void * opaque,const char * boot_device,Error ** errp)14 static void fw_cfg_boot_set(void *opaque, const char *boot_device,
15                             Error **errp)
16 {
17     fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
18 }
19 
virt_fw_cfg_init(ram_addr_t ram_size,MachineState * ms)20 FWCfgState *virt_fw_cfg_init(ram_addr_t ram_size, MachineState *ms)
21 {
22     FWCfgState *fw_cfg;
23     int max_cpus = ms->smp.max_cpus;
24     int smp_cpus = ms->smp.cpus;
25 
26     fw_cfg = fw_cfg_init_mem_wide(VIRT_FWCFG_BASE + 8, VIRT_FWCFG_BASE, 8,
27                                   VIRT_FWCFG_BASE + 16, &address_space_memory);
28     fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
29     fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
30     fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
31 
32     qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
33     return fw_cfg;
34 }
35