Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for pci network device #56

Merged
merged 8 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ qemu-system-riscv64
-initrd vmlinux_debug
-drive file=rootfs.ext2,format=raw,id=hd0,if=none
-device virtio-blk-pci,drive=hd0,iommu_platform=true,disable-legacy=on
-netdev user,id=n1
-device virtio-net-pci,netdev=n1,iommu_platform=true,disable-legacy=on
-append root=/dev/vda,rw,console=ttyS0
-device riscv-iommu-pci
-kernel
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ missing_docs = "warn"
[lints.rustdoc]
missing_crate_level_docs = "warn"


[features]
# for real device
embedded_host_dtb = []

[dependencies]
elf = { version = "0.7.2", default-features = false }
fdt = "0.1.5"
Expand Down
Binary file modified guest.dtb
Binary file not shown.
92 changes: 76 additions & 16 deletions guest_image/build_dtb.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,93 @@
#!/bin/bash

qemu_path="../../qemu_iommu/build/qemu-system-riscv64"

function help() {
echo "create: create dts from qemu dtb"
echo "build: build dtb from guest.dts"
echo "create [host/guest/all]: create host or guest dts from qemu dtb"
echo "build [host/guest/all]: build host or guest dtb from guest.dts"
}

function create_host() {
$qemu_path -S -gdb tcp::10000 \
-machine virt \
-bios none \
-m 256M \
-initrd ../vmlinux_debug \
-drive file=../rootfs.ext2,format=raw,id=hd0,if=none \
-device virtio-blk-device,drive=hd0 \
-netdev user,id=n1 \
-device virtio-net-pci,netdev=n1 \
-device riscv-iommu-pci \
-append "root=/dev/vda rw console=ttyS0" \
-kernel ../target/riscv64imac-unknown-none-elf/debug/hikami \
-machine dumpdtb=qemu.dtb
dtc -I dtb -O dts -o host.dts qemu.dtb
rm -f qemu.dtb
}

function create_guest() {
$qemu_path -S -gdb tcp::10000 \
-machine virt \
-bios none \
-m 256M \
-initrd ../vmlinux_debug \
-drive file=../rootfs.ext2,format=raw,id=hd0,if=none \
-device virtio-blk-device,drive=hd0 \
-netdev user,id=n1 \
-device virtio-net-pci,netdev=n1 \
-append "root=/dev/vda rw console=ttyS0" \
-kernel ../target/riscv64imac-unknown-none-elf/debug/hikami \
-machine dumpdtb=qemu.dtb
dtc -I dtb -O dts -o guest.dts qemu.dtb
rm -f qemu.dtb
}

if [ "$#" -eq 0 ]; then
help
fi

if [ "$#" -eq 1 ]; then
echo "specify target: host or guest or all"
help
fi

if [ "$#" -eq 2 ]; then
case "$1" in
"create")
qemu-system-riscv64 -S -gdb tcp::10000 \
-machine virt \
-bios none \
-m 256M \
-initrd ../vmlinux_debug \
-device riscv-iommu-pci \
-drive file=../rootfs.img,format=raw,id=hd0,if=none \
-device virtio-blk-device,drive=hd0 \
-append "root=/dev/vda rw console=ttyS0" \
-kernel ../target/riscv64imac-unknown-none-elf/debug/hikami \
-machine dumpdtb=qemu.dtb
dtc -I dtb -O dts -o guest.dts qemu.dtb
rm -f qemu.dtb
case "$2" in
"host")
create_host
;;
"guest")
create_guest
;;
"all")
create_host
create_guest
;;
*)
echo "specify target: host or guest or all"
help
;;
esac
;;
"build")
dtc -I dts -O dtb -o ../guest.dtb guest.dts
case "$2" in
"host")
dtc -I dts -O dtb -o ../host.dtb host.dts
;;
"guest")
dtc -I dts -O dtb -o ../guest.dtb guest.dts
;;
"all")
dtc -I dts -O dtb -o ../host.dtb host.dts
dtc -I dts -O dtb -o ../guest.dtb guest.dts
;;
*)
echo "specify target: host or guest or all"
help
;;
esac
;;
*)
echo "command not found"
Expand Down
32 changes: 10 additions & 22 deletions guest_image/guest.dts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
ranges = <0x00 0x00 0x4000000 0x2000000>;
#address-cells = <0x01>;
#size-cells = <0x01>;
compatible = "qemu,platform\0simple-bus";
compatible = "qemu,platform", "simple-bus";
};

memory@90000000 {
Expand All @@ -47,10 +47,10 @@
riscv,cbop-block-size = <0x40>;
riscv,cboz-block-size = <0x40>;
riscv,cbom-block-size = <0x40>;
riscv,isa-extensions = "i\0m\0a\0f\0d\0c\0h\0zic64b\0zicbom\0zicbop\0zicboz\0ziccamoa\0ziccif\0zicclsm\0ziccrse\0zicfiss\0zicntr\0zicsr\0zifencei\0zihintntl\0zihintpause\0zihpm\0zmmul\0za64rs\0zaamo\0zalrsc\0zawrs\0zfa\0zca\0zcd\0zba\0zbb\0zbc\0zbs\0ssccptr\0sscounterenw\0sstc\0sstvala\0sstvecd\0svadu";
riscv,isa-extensions = "i", "m", "a", "f", "d", "c", "h", "zic64b", "zicbom", "zicbop", "zicboz", "ziccamoa", "ziccif", "zicclsm", "ziccrse", "zicfiss", "zicntr", "zicsr", "zifencei", "zihintntl", "zihintpause", "zihpm", "zmmul", "za64rs", "zaamo", "zalrsc", "zawrs", "zfa", "zca", "zcd", "zba", "zbb", "zbc", "zbs", "ssccptr", "sscounterenw", "sstc", "sstvala", "sstvecd", "svadu";
riscv,isa-base = "rv64i";
riscv,isa = "rv64imafdch_zic64b_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_zicfiss_zicntr_zicsr_zifencei_zihintntl_zihintpause_zihpm_zmmul_za64rs_zaamo_zalrsc_zawrs_zfa_zca_zcd_zba_zbb_zbc_zbs_ssccptr_sscounterenw_sstc_sstvala_sstvecd_svadu";
mmu-type = "riscv,sv39";
mmu-type = "riscv,sv57";

interrupt-controller {
#interrupt-cells = <0x01>;
Expand Down Expand Up @@ -90,10 +90,10 @@

chosen {
bootargs = "root=/dev/vda rw console=ttyS0";
linux,initrd-end = <0x00 0x97f67ce0>;
linux,initrd-end = <0x00 0x9812b230>;
linux,initrd-start = <0x00 0x88000000>;
stdout-path = "/soc/serial@10000000";
rng-seed = <0xcaf53f7f 0x52fe6542 0xf3156947 0xa50b572d 0xc6f64192 0x47d6e429 0x1985224b 0xe8a94cc2>;
rng-seed = <0x2b05a034 0xe739bfb7 0x512d2025 0xf0ec97e8 0x69399e86 0x1f2de5a9 0xcacea4aa 0xafb54655>;
};

soc {
Expand All @@ -112,15 +112,15 @@
serial@10000000 {
interrupts = <0x0a>;
interrupt-parent = <0x03>;
clock-frequency = "\08@";
clock-frequency = "", "8@";
reg = <0x00 0x10000000 0x00 0x100>;
compatible = "ns16550a";
};

test@100000 {
phandle = <0x04>;
reg = <0x00 0x100000 0x00 0x1000>;
compatible = "sifive,test1\0sifive,test0\0syscon";
compatible = "sifive,test1", "sifive,test0", "syscon";
};

virtio_mmio@10008000 {
Expand Down Expand Up @@ -185,25 +185,21 @@
reg = <0x00 0xc000000 0x00 0x600000>;
interrupts-extended = <0x02 0x0b 0x02 0x09>;
interrupt-controller;
compatible = "sifive,plic-1.0.0\0riscv,plic0";
compatible = "sifive,plic-1.0.0", "riscv,plic0";
#address-cells = <0x00>;
#interrupt-cells = <0x01>;
};

clint@2000000 {
interrupts-extended = <0x02 0x03 0x02 0x07>;
reg = <0x00 0x2000000 0x00 0x10000>;
compatible = "sifive,clint0\0riscv,clint0";
compatible = "sifive,clint0", "riscv,clint0";
};

pci@30000000 {
interrupt-map-mask = <0x1800 0x00 0x00 0x07>;
interrupt-map = <0x00 0x00 0x00 0x01 0x03 0x20 0x00 0x00 0x00 0x02 0x03 0x21 0x00 0x00 0x00 0x03 0x03 0x22 0x00 0x00 0x00 0x04 0x03 0x23 0x800 0x00 0x00 0x01 0x03 0x21 0x800 0x00 0x00 0x02 0x03 0x22 0x800 0x00 0x00 0x03 0x03 0x23 0x800 0x00 0x00 0x04 0x03 0x20 0x1000 0x00 0x00 0x01 0x03 0x22 0x1000 0x00 0x00 0x02 0x03 0x23 0x1000 0x00 0x00 0x03 0x03 0x20 0x1000 0x00 0x00 0x04 0x03 0x21 0x1800 0x00 0x00 0x01 0x03 0x23 0x1800 0x00 0x00 0x02 0x03 0x20 0x1800 0x00 0x00 0x03 0x03 0x21 0x1800 0x00 0x00 0x04 0x03 0x22>;
// BUS_ADDRESS(3) CPU_PHYSICAL(2) SIZE(2)
ranges = <
0x1000000 0x00 0x00 0x00 0x3000000 0x00 0x10000
0x2000000 0x00 0x40000000 0x00 0x40000000 0x00 0x40000000
0x3000000 0x04 0x00 0x04 0x00 0x04 0x00>;
ranges = <0x1000000 0x00 0x00 0x00 0x3000000 0x00 0x10000 0x2000000 0x00 0x40000000 0x00 0x40000000 0x00 0x40000000 0x3000000 0x04 0x00 0x04 0x00 0x04 0x00>;
reg = <0x00 0x30000000 0x00 0x10000000>;
dma-coherent;
bus-range = <0x00 0xff>;
Expand All @@ -213,14 +209,6 @@
#size-cells = <0x02>;
#interrupt-cells = <0x01>;
#address-cells = <0x03>;
iommu-map = <0x00 0x8000 0x00 0x08 0x09 0x8000 0x09 0xfff7>;

iommu@8 {
reg = <0x800 0x00 0x00 0x00 0x00>;
phandle = <0x8000>;
#iommu-cells = <0x01>;
compatible = "riscv,pci-iommu";
};
};
};
};
Loading
Loading