2019-06-25 01:11:49 +03:00
|
|
|
/*
|
|
|
|
* QEMU RISC-V Boot Helper
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 SiFive, Inc.
|
|
|
|
* Copyright (c) 2019 Alistair Francis <alistair.francis@wdc.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2 or later, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RISCV_BOOT_H
|
|
|
|
#define RISCV_BOOT_H
|
|
|
|
|
2019-08-12 08:23:31 +03:00
|
|
|
#include "exec/cpu-defs.h"
|
2020-04-24 00:09:37 +03:00
|
|
|
#include "hw/loader.h"
|
2020-12-16 21:23:08 +03:00
|
|
|
#include "hw/riscv/riscv_hart.h"
|
2019-08-12 08:23:31 +03:00
|
|
|
|
2021-04-30 10:13:01 +03:00
|
|
|
#define RISCV32_BIOS_BIN "opensbi-riscv32-generic-fw_dynamic.bin"
|
|
|
|
#define RISCV64_BIOS_BIN "opensbi-riscv64-generic-fw_dynamic.bin"
|
|
|
|
|
2021-01-16 02:00:27 +03:00
|
|
|
bool riscv_is_32bit(RISCVHartArrayState *harts);
|
2020-10-14 03:17:30 +03:00
|
|
|
|
2021-10-22 09:01:30 +03:00
|
|
|
char *riscv_plic_hart_config_string(int hart_count);
|
|
|
|
|
2021-01-16 02:00:27 +03:00
|
|
|
target_ulong riscv_calc_kernel_start_addr(RISCVHartArrayState *harts,
|
2020-10-14 03:17:33 +03:00
|
|
|
target_ulong firmware_end_addr);
|
2020-10-14 03:17:28 +03:00
|
|
|
target_ulong riscv_find_and_load_firmware(MachineState *machine,
|
|
|
|
const char *default_machine_firmware,
|
|
|
|
hwaddr firmware_load_addr,
|
|
|
|
symbol_fn_t sym_cb);
|
2022-12-29 12:18:26 +03:00
|
|
|
const char *riscv_default_firmware_name(RISCVHartArrayState *harts);
|
2022-12-29 12:18:27 +03:00
|
|
|
char *riscv_find_firmware(const char *firmware_filename,
|
|
|
|
const char *default_machine_firmware);
|
2019-06-25 01:11:52 +03:00
|
|
|
target_ulong riscv_load_firmware(const char *firmware_filename,
|
2020-04-27 11:06:42 +03:00
|
|
|
hwaddr firmware_load_addr,
|
|
|
|
symbol_fn_t sym_cb);
|
2023-01-02 14:52:39 +03:00
|
|
|
target_ulong riscv_load_kernel(MachineState *machine,
|
2023-02-06 17:00:20 +03:00
|
|
|
RISCVHartArrayState *harts,
|
2020-10-14 03:17:33 +03:00
|
|
|
target_ulong firmware_end_addr,
|
2023-02-06 17:00:21 +03:00
|
|
|
bool load_initrd,
|
2019-11-19 09:21:09 +03:00
|
|
|
symbol_fn_t sym_cb);
|
2023-02-01 20:12:11 +03:00
|
|
|
uint64_t riscv_compute_fdt_addr(hwaddr dram_start, uint64_t dram_size,
|
hw/riscv: change riscv_compute_fdt_addr() semantics
As it is now, riscv_compute_fdt_addr() is receiving a dram_base, a
mem_size (which is defaulted to MachineState::ram_size in all boards)
and the FDT pointer. And it makes a very important assumption: the DRAM
interval dram_base + mem_size is contiguous. This is indeed the case for
most boards that use a FDT.
The Icicle Kit board works with 2 distinct RAM banks that are separated
by a gap. We have a lower bank with 1GiB size, a gap follows, then at
64GiB the high memory starts. MachineClass::default_ram_size for this
board is set to 1.5Gb, and machine_init() is enforcing it as minimal RAM
size, meaning that there we'll always have at least 512 MiB in the Hi
RAM area.
Using riscv_compute_fdt_addr() in this board is weird because not only
the board has sparse RAM, and it's calling it using the base address of
the Lo RAM area, but it's also using a mem_size that we have guarantees
that it will go up to the Hi RAM. All the function assumptions doesn't
work for this board.
In fact, what makes the function works at all in this case is a
coincidence. Commit 1a475d39ef54 introduced a 3GB boundary for the FDT,
down from 4Gb, that is enforced if dram_base is lower than 3072 MiB. For
the Icicle Kit board, memmap[MICROCHIP_PFSOC_DRAM_LO].base is 0x80000000
(2 Gb) and it has a 1Gb size, so it will fall in the conditions to put
the FDT under a 3Gb address, which happens to be exactly at the end of
DRAM_LO. If the base address of the Lo area started later than 3Gb this
function would be unusable by the board. Changing any assumptions inside
riscv_compute_fdt_addr() can also break it by accident as well.
Let's change riscv_compute_fdt_addr() semantics to be appropriate to the
Icicle Kit board and for future boards that might have sparse RAM
topologies to worry about:
- relieve the condition that the dram_base + mem_size area is contiguous,
since this is already not the case today;
- receive an extra 'dram_size' size attribute that refers to a contiguous
RAM block that the board wants the FDT to reside on.
Together with 'mem_size' and 'fdt', which are now now being consumed by a
MachineState pointer, we're able to make clear assumptions based on the
DRAM block and total mem_size available to ensure that the FDT will be put
in a valid RAM address.
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-Id: <20230201171212.1219375-4-dbarboza@ventanamicro.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2023-02-01 20:12:12 +03:00
|
|
|
MachineState *ms);
|
2023-02-01 20:12:11 +03:00
|
|
|
void riscv_load_fdt(hwaddr fdt_addr, void *fdt);
|
2021-01-16 02:00:27 +03:00
|
|
|
void riscv_setup_rom_reset_vec(MachineState *machine, RISCVHartArrayState *harts,
|
2020-12-16 21:23:08 +03:00
|
|
|
hwaddr saddr,
|
2020-12-16 21:22:37 +03:00
|
|
|
hwaddr rom_base, hwaddr rom_size,
|
|
|
|
uint64_t kernel_entry,
|
2022-07-28 21:19:26 +03:00
|
|
|
uint64_t fdt_load_addr);
|
2020-12-16 21:22:37 +03:00
|
|
|
void riscv_rom_copy_firmware_info(MachineState *machine, hwaddr rom_base,
|
|
|
|
hwaddr rom_size,
|
2020-07-01 21:39:48 +03:00
|
|
|
uint32_t reset_vec_size,
|
|
|
|
uint64_t kernel_entry);
|
2022-01-12 11:13:22 +03:00
|
|
|
void riscv_setup_direct_kernel(hwaddr kernel_addr, hwaddr fdt_addr);
|
2022-10-04 12:23:51 +03:00
|
|
|
void riscv_setup_firmware_boot(MachineState *machine);
|
2019-06-25 01:11:49 +03:00
|
|
|
|
|
|
|
#endif /* RISCV_BOOT_H */
|