Skip to content

Commit

Permalink
feat!: add VirtIO 9P device
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Jan 19, 2024
1 parent 56b64d6 commit 67442cf
Show file tree
Hide file tree
Showing 6 changed files with 2,481 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ INCS+= \
-I../third-party/mongoose-7.12 \
$(BOOST_INC)

# Use 64-bit offsets for file operations in POSIX APIs
DEFS+=-D_FILE_OFFSET_BITS=64

ifeq ($(dump),yes)
#DEFS+=-DDUMP_ILLEGAL_INSN_EXCEPTIONS
#DEFS+=-DDUMP_EXCEPTIONS
Expand Down Expand Up @@ -319,6 +322,7 @@ LIBCARTESI_OBJS:= \
virtio-factory.o \
virtio-device.o \
virtio-console.o \
virtio-p9fs.o \
dtb.o \
os.o \
htif.o \
Expand Down
10 changes: 10 additions & 0 deletions src/dtb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ void dtb_init(const machine_config &c, unsigned char *dtb_start, uint64_t dtb_le
fdt.prop_u32_list<2>("interrupts-extended", {PLIC_PHANDLE, plic_irq_id});
fdt.end_node();
}
if (c.htif.console_getchar) { // virtio 9p
const uint32_t virtio_idx = 1;
const uint64_t virtio_paddr = PMA_FIRST_VIRTIO_START + virtio_idx * PMA_VIRTIO_LENGTH;
const uint32_t plic_irq_id = virtio_idx + 1;
fdt.begin_node_num("virtio", virtio_paddr);
fdt.prop_string("compatible", "virtio,mmio");
fdt.prop_u64_list<2>("reg", {virtio_paddr, PMA_VIRTIO_LENGTH});
fdt.prop_u32_list<2>("interrupts-extended", {PLIC_PHANDLE, plic_irq_id});
fdt.end_node();
}
fdt.end_node();
}

Expand Down
8 changes: 8 additions & 0 deletions src/machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "unique-c-ptr.h"
#include "virtio-console.h"
#include "virtio-factory.h"
#include "virtio-p9fs.h"

/// \file
/// \brief Cartesi machine implementation
Expand Down Expand Up @@ -448,6 +449,13 @@ machine::machine(const machine_config &c, const machine_runtime_config &r) :
make_virtio_pma_entry(PMA_FIRST_VIRTIO_START + vdev_console->get_virtio_index() * PMA_VIRTIO_LENGTH,
PMA_VIRTIO_LENGTH, "VirtIO console device", &virtio_driver, vdev_console.get()));
m_vdevs.push_back(std::move(vdev_console));

// Register VirtIO Plan 9 filesystem device
auto vdev_p9fs = std::make_unique<virtio_p9fs_device>(m_vdevs.size(), "vfs0", "/tmp");
register_pma_entry(
make_virtio_pma_entry(PMA_FIRST_VIRTIO_START + vdev_p9fs->get_virtio_index() * PMA_VIRTIO_LENGTH,
PMA_VIRTIO_LENGTH, "VirtIO p9fs device", &virtio_driver, vdev_p9fs.get()));
m_vdevs.push_back(std::move(vdev_p9fs));
}

// Initialize DTB
Expand Down
Loading

0 comments on commit 67442cf

Please sign in to comment.