[platform][qemu-riscv] add virtio to bring it up to par with arm virt machine
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
#define UART0_BASE 0x10000000
|
||||
#define VIRTIO_BASE 0x10001000
|
||||
#define DRAM_BASE 0x80000000
|
||||
#define NUM_VIRTIO_TRANSPORTS 8
|
||||
#define VIRTIO_STRIDE 0x1000
|
||||
|
||||
#if RISCV_XMODE_OFFSET == RISCV_MACH_OFFSET
|
||||
#define PLIC_HART_IDX(hart) (2 * (hart))
|
||||
|
||||
@@ -16,6 +16,11 @@
|
||||
#include <platform/virt.h>
|
||||
#include <sys/types.h>
|
||||
#include <libfdt.h>
|
||||
#include <dev/virtio.h>
|
||||
#include <dev/virtio/net.h>
|
||||
#if WITH_LIB_MINIP
|
||||
#include <lib/minip.h>
|
||||
#endif
|
||||
|
||||
#include "platform_p.h"
|
||||
|
||||
@@ -89,6 +94,35 @@ void platform_early_init(void) {
|
||||
void platform_init(void) {
|
||||
plic_init();
|
||||
uart_init();
|
||||
|
||||
/* detect any virtio devices */
|
||||
uint virtio_irqs[NUM_VIRTIO_TRANSPORTS];
|
||||
for (int i = 0; i < NUM_VIRTIO_TRANSPORTS; i++) {
|
||||
virtio_irqs[i] = IRQ_VIRTIO_BASE + i;
|
||||
}
|
||||
|
||||
virtio_mmio_detect((void *)VIRTIO_BASE, NUM_VIRTIO_TRANSPORTS, virtio_irqs, VIRTIO_STRIDE);
|
||||
|
||||
#if WITH_LIB_MINIP
|
||||
if (virtio_net_found() > 0) {
|
||||
uint8_t mac_addr[6];
|
||||
|
||||
virtio_net_get_mac_addr(mac_addr);
|
||||
|
||||
TRACEF("found virtio networking interface\n");
|
||||
|
||||
/* start minip */
|
||||
minip_set_macaddr(mac_addr);
|
||||
|
||||
__UNUSED uint32_t ip_addr = IPV4(192, 168, 0, 99);
|
||||
__UNUSED uint32_t ip_mask = IPV4(255, 255, 255, 0);
|
||||
__UNUSED uint32_t ip_gateway = IPV4_NONE;
|
||||
|
||||
//minip_init(virtio_net_send_minip_pkt, NULL, ip_addr, ip_mask, ip_gateway);
|
||||
minip_init_dhcp(virtio_net_send_minip_pkt, NULL);
|
||||
|
||||
virtio_net_start();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@ SMP_MAX_CPUS ?= 8
|
||||
|
||||
MODULE_DEPS += lib/cbuf
|
||||
MODULE_DEPS += lib/fdt
|
||||
MODULE_DEPS += dev/virtio/block
|
||||
MODULE_DEPS += dev/virtio/gpu
|
||||
MODULE_DEPS += dev/virtio/net
|
||||
|
||||
MODULE_SRCS += $(LOCAL_DIR)/platform.c
|
||||
MODULE_SRCS += $(LOCAL_DIR)/plic.c
|
||||
@@ -33,4 +36,11 @@ GLOBAL_DEFINES += ARCH_RISCV_MTIME_RATE=10000000
|
||||
# we're going to read the default memory map from a FDT
|
||||
GLOBAL_DEFINES += NOVM_DEFAULT_ARENA=0
|
||||
|
||||
# we can revert to a poll based uart spin routine
|
||||
GLOBAL_DEFINES += PLATFORM_SUPPORTS_PANIC_SHELL=1
|
||||
|
||||
# do not need to implement any cache ops
|
||||
# (for now, since there are no hw accellerated qemu machines)
|
||||
GLOBAL_DEFINES += RISCV_NO_CACHE_OPS=1
|
||||
|
||||
include make/module.mk
|
||||
|
||||
@@ -79,3 +79,12 @@ int platform_dgetc(char *c, bool wait) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* panic-time getc/putc */
|
||||
int platform_pgetc(char *c, bool wait) {
|
||||
if (uart_read_8(5) & (1<<0)) {
|
||||
*c = uart_read_8(0);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user