From 5ecb77ec9f6f1cfb02b23cdb9a1eb2eca905b12e Mon Sep 17 00:00:00 2001 From: tjin Date: Tue, 2 Apr 2019 14:48:25 +0800 Subject: [PATCH] adds a virtio_net netcard for mips boston board Adds a network card for boston to make it convenient for users who are verifying network related functionalities on this board. As the linux kernel has already supported virtio_net, now add a virtio netcard for boston, to make virtio work properly, please: 1. set virtio net options in linux kernel, saying CONFIG_VIRTIO && CONFIG_VIRTIO_PCI && CONFIG_VIRTIO_NET 2. specify model=virtio when you start boston in qemu. Signed-off-by: tjin --- hw/mips/boston.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/hw/mips/boston.c b/hw/mips/boston.c index e5bab3c..97c1728 100644 --- a/hw/mips/boston.c +++ b/hw/mips/boston.c @@ -32,6 +32,7 @@ #include "hw/mips/cps.h" #include "hw/mips/cpudevs.h" #include "hw/pci-host/xilinx-pcie.h" +#include "hw/virtio/virtio-pci.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/log.h" @@ -422,6 +423,23 @@ xilinx_pcie_init(MemoryRegion *sys_mem, uint32_t bus_nr, return XILINX_PCIE_HOST(dev); } +/* Plug network card in pcie slot.*/ +static void network_init(PCIBus *bus) +{ + NICInfo *nd = &nd_table[0]; + PCIDevice *eth; + + /* Please set CONFIG_VIRTIO && CONFIG_VIRTIO_PCI && CONFIG_VIRTIO_NET */ + /* of Linux kernel. */ + if (nd->model && strcmp(nd->model, "virtio") == 0) { + eth = pci_create(bus, + PCI_DEVFN(0, 1), "virtio-net-pci"); + + qdev_set_nic_properties(ð->qdev, &nd_table[0]); + qdev_init_nofail(ð->qdev); + } +} + static void boston_mach_init(MachineState *machine) { DeviceState *dev; @@ -545,6 +563,9 @@ static void boston_mach_init(MachineState *machine) error_printf("Please provide either a -kernel or -bios argument\n"); exit(1); } + + /* Network card */ + network_init(&PCI_BRIDGE(&pcie2->root)->sec_bus); } static void boston_mach_class_init(MachineClass *mc) -- 2.7.4