Skip to content

Commit

Permalink
fix for latest sDDF with newly merged sddf blk
Browse files Browse the repository at this point in the history
  • Loading branch information
erichchan999 committed Jan 19, 2024
1 parent 3b3714c commit c2d6844
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 260 deletions.
33 changes: 17 additions & 16 deletions examples/virtio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ CLIENT_VM_1_DTB := $(BUILD_DIR)/client_vm_1.dtb
CLIENT_VM_2_DTB := $(BUILD_DIR)/client_vm_2.dtb

SDDF := sddf
SDDF_UTIL := $(SDDF)/util

SDDF_SERIAL_RINGBUFFER := $(SDDF)/serial/libserialsharedringbuffer
SDDF_SERIAL_COMPONENTS := $(SDDF)/serial/components
SDDF_SERIAL_DRIVER := $(SDDF)/drivers/serial/arm
SDDF_UTIL := $(SDDF)/util

SDDF_BLOCK_RINGBUFFER := $(SDDF)/block/libblocksharedringbuffer
SDDF_BLK_SHAREDQUEUE := $(SDDF)/blk/libblksharedqueue

# ELFS := blk_driver_vmm.elf client_vmm.elf serial_mux_tx.elf serial_mux_rx.elf uart_driver.elf
ELFS := client_vmm_1.elf client_vmm_2.elf serial_mux_tx.elf serial_mux_rx.elf uart_driver.elf test_blk.elf
Expand Down Expand Up @@ -140,8 +140,8 @@ CLIENT_VMM_1_OBJS := $(VMM_OBJS) \
console.o \
block.o \
mmio.o \
sddf_serial_shared_ringbuffer.o \
sddf_blk_shared_ringbuffer.o \
sddf_serial_sharedringbuffer.o \
sddf_blk_shared_queue.o \

CLIENT_VMM_2_OBJS := $(VMM_OBJS) \
client_images_2.o \
Expand All @@ -150,18 +150,18 @@ CLIENT_VMM_2_OBJS := $(VMM_OBJS) \
console.o \
block.o \
mmio.o \
sddf_serial_shared_ringbuffer.o \
sddf_blk_shared_ringbuffer.o \
sddf_serial_sharedringbuffer.o \
sddf_blk_shared_queue.o \

# BLK_DRIVER_VMM_OBJS := $(VMM_OBJS) \
# blk_driver_images.o \
# blk_driver_vmm.o \
TEST_BLK_OBJS := test_blk.o sddf_blk_shared_ringbuffer.o printf.o util.o
TEST_BLK_OBJS := test_blk.o sddf_blk_shared_queue.o printf.o util.o

SERIAL_MUX_TX_OBJS := mux_tx.o sddf_serial_shared_ringbuffer.o
SERIAL_MUX_RX_OBJS := mux_rx.o sddf_serial_shared_ringbuffer.o
SERIAL_DRIVER_OBJS := uart.o sddf_serial_shared_ringbuffer.o
SERIAL_MUX_TX_OBJS := mux_tx.o sddf_serial_sharedringbuffer.o
SERIAL_MUX_RX_OBJS := mux_rx.o sddf_serial_sharedringbuffer.o
SERIAL_DRIVER_OBJS := uart.o sddf_serial_sharedringbuffer.o

# Toolchain flags
# FIXME: For optimisation we should consider providing the flag -mcpu.
Expand All @@ -178,11 +178,10 @@ CFLAGS := -mstrict-align \
-Wno-unused-command-line-argument \
-Wall -Wno-unused-function -Werror \
-I$(VMM_SRC_DIR)/arch/aarch64 -I$(VMM_SRC_DIR) -I$(VMM_SRC_DIR)/util -I$(BOARD_DIR)/include \
-I$(SDDF_SERIAL_RINGBUFFER)/include \
-I$(SDDF_SERIAL_DRIVER)/include \
-I$(SDDF_BLOCK_RINGBUFFER)/include \
-I$(SDDF) \
-I$(SDDF)/include \
-I$(SDDF_UTIL)/include \
-DBOARD_$(BOARD) \
-DCONFIG_$(CONFIG) \
-target aarch64-none-elf
Expand Down Expand Up @@ -302,14 +301,16 @@ $(BUILD_DIR)/%.o: $(VMM_SRC_DIR)/virtio/%.c Makefile
$(BUILD_DIR)/%.o: $(SDDF_SERIAL_COMPONENTS)/%.c Makefile
$(CC) -c $(CFLAGS) -DSERIAL_NUM_CLIENTS=2 -DSERIAL_TRANSFER_WITH_COLOUR=1 $< -o $@

$(BUILD_DIR)/%.o: $(SDDF_SERIAL_RINGBUFFER)/%.c Makefile
$(CC) -c $(CFLAGS) $< -o $@
$(BUILD_DIR)/sddf_serial_sharedringbuffer.o: Makefile
$(MAKE) -C $(SDDF_SERIAL_RINGBUFFER) MICROKIT_INCLUDE=$(MICROKIT_SDK)
cp $(SDDF_SERIAL_RINGBUFFER)/sddf_serial_sharedringbuffer.o $(BUILD_DIR)/sddf_serial_sharedringbuffer.o

$(BUILD_DIR)/%.o: $(SDDF_SERIAL_DRIVER)/%.c Makefile
$(CC) -c $(CFLAGS) $< -o $@

$(BUILD_DIR)/%.o: $(SDDF_BLOCK_RINGBUFFER)/%.c Makefile
$(CC) -c $(CFLAGS) $< -o $@
$(BUILD_DIR)/sddf_blk_shared_queue.o: Makefile
$(MAKE) -C $(SDDF_BLK_SHAREDQUEUE) MICROKIT_INCLUDE=$(MICROKIT_SDK)
cp $(SDDF_BLK_SHAREDQUEUE)/sddf_blk_shared_queue.o $(BUILD_DIR)/sddf_blk_shared_queue.o

$(BUILD_DIR)/client_vmm_1.elf: $(addprefix $(BUILD_DIR)/, $(CLIENT_VMM_1_OBJS))
$(LD) $(LDFLAGS) $^ $(LIBS) -o $@
Expand Down
10 changes: 5 additions & 5 deletions examples/virtio/board/qemu_arm_virt/virtio.system
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
</protection_domain> -->
<protection_domain name="TEST_BLK" priority="200">
<program_image path="test_blk.elf" />
<map mr="cmd_blk_vmm_1" vaddr="0x103_800_000" perms="rw" cached="true" setvar_vaddr="blk_cmd_ring" />
<map mr="resp_blk_vmm_1" vaddr="0x103_a00_000" perms="rw" cached="true" setvar_vaddr="blk_resp_ring" />
<map mr="req_blk_vmm_1" vaddr="0x103_800_000" perms="rw" cached="true" setvar_vaddr="blk_req_queue" />
<map mr="resp_blk_vmm_1" vaddr="0x103_a00_000" perms="rw" cached="true" setvar_vaddr="blk_resp_queue" />
<map mr="data_blk_vmm_1" vaddr="0x8_c00_000" perms="rw" cached="true" />
</protection_domain>

Expand All @@ -42,8 +42,8 @@

<!-- sDDF related regions for virtIO block -->
<!-- shared memory for ring buffer mechanism -->
<map mr="cmd_blk_vmm_1" vaddr="0x103_800_000" perms="rw" cached="true" setvar_vaddr="blk_cmd_ring" />
<map mr="resp_blk_vmm_1" vaddr="0x103_a00_000" perms="rw" cached="true" setvar_vaddr="blk_resp_ring" />
<map mr="req_blk_vmm_1" vaddr="0x103_800_000" perms="rw" cached="true" setvar_vaddr="blk_req_queue" />
<map mr="resp_blk_vmm_1" vaddr="0x103_a00_000" perms="rw" cached="true" setvar_vaddr="blk_resp_queue" />
<!-- sDDF data region -->
<map mr="data_blk_vmm_1" vaddr="0x8_c00_000" perms="rw" cached="true" setvar_vaddr="blk_data" />

Expand Down Expand Up @@ -189,7 +189,7 @@
Regions for the shared ring buffers used by the multiplexor (not implemented yet, in this case its the driver vm) and the
client (in this case the client is the VMM)
-->
<memory_region name="cmd_blk_vmm_1" size="0x200_000" page_size="0x200_000"/>
<memory_region name="req_blk_vmm_1" size="0x200_000" page_size="0x200_000"/>
<memory_region name="resp_blk_vmm_1" size="0x200_000" page_size="0x200_000"/>

<!-- <channel>
Expand Down
80 changes: 41 additions & 39 deletions examples/virtio/client_vmm_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "virtio/virtio.h"
#include "virtio/console.h"
#include <sddf/serial/shared_ringbuffer.h>
#include "virtio/block.h"
#include <sddf/blk/shared_queue.h>

/*
* As this is just an example, for simplicity we just make the size of the
Expand Down Expand Up @@ -60,10 +62,10 @@ uintptr_t serial_tx_used;
uintptr_t serial_rx_data;
uintptr_t serial_tx_data;

sddf_serial_ring_handle_t serial_rx_ring_handle;
sddf_serial_ring_handle_t serial_tx_ring_handle;
ring_handle_t serial_rx_ring_handle;
ring_handle_t serial_tx_ring_handle;

static sddf_serial_ring_handle_t *serial_ring_handles[SDDF_SERIAL_NUM_RING_HANDLES];
static ring_handle_t *serial_ring_handles[NUM_RING_HANDLES];

static struct virtio_device virtio_console;

Expand All @@ -74,16 +76,16 @@ static struct virtio_device virtio_console;
#define VIRTIO_BLK_BASE (0x150000)
#define VIRTIO_BLK_SIZE (0x1000)

uintptr_t blk_cmd_ring;
uintptr_t blk_resp_ring;
uintptr_t blk_req_queue;
uintptr_t blk_resp_queue;
uintptr_t blk_data;
sddf_blk_ring_handle_t blk_ring_handle;
static sddf_blk_ring_handle_t *blk_ring_handles[SDDF_BLK_NUM_RING_HANDLES];
blk_queue_handle_t blk_queue_handle;
static blk_queue_handle_t *blk_queue_handles[BLK_NUM_QUEUES];

blk_data_region_t blk_data_region;
bitarray_t blk_data_region_avail_bitarr;
word_t blk_data_region_avail_bitarr_words[roundup_bits2words64(SDDF_BLK_NUM_DATA_BUFFERS)];
static blk_data_region_t *blk_data_region_handles[SDDF_BLK_NUM_RING_HANDLES];
word_t blk_data_region_avail_bitarr_words[roundup_bits2words64(BLK_NUM_DATA_BUFFERS)];
static blk_data_region_t *blk_data_region_handlers[BLK_NUM_QUEUES];

static struct virtio_device virtio_blk;

Expand Down Expand Up @@ -117,68 +119,68 @@ void init(void) {
}

/* Initialise our sDDF ring buffers for the serial device */
sddf_serial_ring_init(&serial_rx_ring_handle,
(sddf_serial_ring_buffer_t *)serial_rx_free,
(sddf_serial_ring_buffer_t *)serial_rx_used,
ring_init(&serial_rx_ring_handle,
(ring_buffer_t *)serial_rx_free,
(ring_buffer_t *)serial_rx_used,
true,
SDDF_SERIAL_NUM_BUFFERS,
SDDF_SERIAL_NUM_BUFFERS);
for (int i = 0; i < SDDF_SERIAL_NUM_BUFFERS - 1; i++) {
int ret = sddf_serial_enqueue_free(&serial_rx_ring_handle, serial_rx_data + (i * SDDF_SERIAL_BUFFER_SIZE), SDDF_SERIAL_BUFFER_SIZE, NULL);
NUM_BUFFERS,
NUM_BUFFERS);
for (int i = 0; i < NUM_BUFFERS - 1; i++) {
int ret = enqueue_free(&serial_rx_ring_handle, serial_rx_data + (i * BUFFER_SIZE), BUFFER_SIZE, NULL);
if (ret != 0) {
microkit_dbg_puts(microkit_name);
microkit_dbg_puts(": server rx buffer population, unable to enqueue buffer\n");
}
}
sddf_serial_ring_init(&serial_tx_ring_handle,
(sddf_serial_ring_buffer_t *)serial_tx_free,
(sddf_serial_ring_buffer_t *)serial_tx_used,
ring_init(&serial_tx_ring_handle,
(ring_buffer_t *)serial_tx_free,
(ring_buffer_t *)serial_tx_used,
true,
SDDF_SERIAL_NUM_BUFFERS,
SDDF_SERIAL_NUM_BUFFERS);
for (int i = 0; i < SDDF_SERIAL_NUM_BUFFERS - 1; i++) {
NUM_BUFFERS,
NUM_BUFFERS);
for (int i = 0; i < NUM_BUFFERS - 1; i++) {
// Have to start at the memory region left of by the rx ring
int ret = sddf_serial_enqueue_free(&serial_tx_ring_handle, serial_tx_data + ((i + SDDF_SERIAL_NUM_BUFFERS) * SDDF_SERIAL_BUFFER_SIZE), SDDF_SERIAL_BUFFER_SIZE, NULL);
int ret = enqueue_free(&serial_tx_ring_handle, serial_tx_data + ((i + NUM_BUFFERS) * BUFFER_SIZE), BUFFER_SIZE, NULL);
assert(ret == 0);
if (ret != 0) {
microkit_dbg_puts(microkit_name);
microkit_dbg_puts(": server tx buffer population, unable to enqueue buffer\n");
}
}
serial_ring_handles[SDDF_SERIAL_RX_RING] = &serial_rx_ring_handle;
serial_ring_handles[SDDF_SERIAL_TX_RING] = &serial_tx_ring_handle;
serial_ring_handles[RX_RING] = &serial_rx_ring_handle;
serial_ring_handles[TX_RING] = &serial_tx_ring_handle;
/* Neither ring should be plugged and hence all buffers we send should actually end up at the driver. */
assert(!sddf_serial_ring_plugged(serial_tx_ring_handle.free_ring));
assert(!sddf_serial_ring_plugged(serial_tx_ring_handle.used_ring));
assert(!ring_plugged(serial_tx_ring_handle.free_ring));
assert(!ring_plugged(serial_tx_ring_handle.used_ring));
/* Initialise virtIO console device */
success = virtio_mmio_device_init(&virtio_console, CONSOLE, VIRTIO_CONSOLE_BASE, VIRTIO_CONSOLE_SIZE, VIRTIO_CONSOLE_IRQ,
NULL, (void **)serial_ring_handles, SERIAL_MUX_TX_CH);
assert(success);

/* Initialise our sDDF ring buffers for the block device */
sddf_blk_ring_init(&blk_ring_handle,
(sddf_blk_cmd_ring_buffer_t *)blk_cmd_ring,
(sddf_blk_resp_ring_buffer_t *)blk_resp_ring,
blk_queue_init(&blk_queue_handle,
(blk_req_queue_t *)blk_req_queue,
(blk_resp_queue_t *)blk_resp_queue,
true,
SDDF_BLK_NUM_CMD_BUFFERS,
SDDF_BLK_NUM_RESP_BUFFERS);
blk_ring_handles[SDDF_BLK_DEFAULT_RING] = &blk_ring_handle;
BLK_REQ_QUEUE_SIZE,
BLK_RESP_QUEUE_SIZE);
blk_queue_handles[BLK_DEFAULT_QUEUE] = &blk_queue_handle;
/* Command ring should be plugged and hence all buffers we send should actually end up at the driver VM. */
assert(!sddf_blk_cmd_ring_plugged(&blk_ring_handle));
assert(!blk_req_queue_plugged(&blk_queue_handle));
/* Initialise bit array*/
bitarray_init(&blk_data_region_avail_bitarr, blk_data_region_avail_bitarr_words, roundup_bits2words64(SDDF_BLK_NUM_DATA_BUFFERS));
bitarray_init(&blk_data_region_avail_bitarr, blk_data_region_avail_bitarr_words, roundup_bits2words64(BLK_NUM_DATA_BUFFERS));
/* Data struct that handles allocation and freeing of data buffers in sDDF shared memory region */
blk_data_region.avail_bitpos = 0; /* bit position of next avail buffer */
blk_data_region.avail_bitarr = &blk_data_region_avail_bitarr; /* bit array representing avail data buffers */
blk_data_region.num_buffers = SDDF_BLK_NUM_DATA_BUFFERS; /* number of buffers in data region */
blk_data_region.num_buffers = BLK_NUM_DATA_BUFFERS; /* number of buffers in data region */
blk_data_region.addr = blk_data; /* encoded base address of data region */
/* Set all available bits to 1 to indicate it is available */
bitarray_set_region(&blk_data_region_avail_bitarr, 0, SDDF_BLK_NUM_DATA_BUFFERS);
blk_data_region_handles[SDDF_BLK_DEFAULT_RING] = &blk_data_region;
bitarray_set_region(&blk_data_region_avail_bitarr, 0, BLK_NUM_DATA_BUFFERS);
blk_data_region_handlers[BLK_DEFAULT_QUEUE] = &blk_data_region;

/* Initialise virtIO block device */
success = virtio_mmio_device_init(&virtio_blk, BLK, VIRTIO_BLK_BASE, VIRTIO_BLK_SIZE, VIRTIO_BLK_IRQ,
(void **)blk_data_region_handles, (void **)blk_ring_handles, BLK_CH);
(void **)blk_data_region_handlers, (void **)blk_queue_handles, BLK_CH);
assert(success);

/* Finally start the guest */
Expand Down
44 changes: 22 additions & 22 deletions examples/virtio/client_vmm_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "virtio/virtio.h"
#include "virtio/console.h"
#include "virtio/block.h"
#include "serial/libserialsharedringbuffer/include/sddf_serial_shared_ringbuffer.h"
#include <sddf/serial/shared_ringbuffer.h>

/*
* As this is just an example, for simplicity we just make the size of the
Expand Down Expand Up @@ -61,10 +61,10 @@ uintptr_t serial_tx_used;
uintptr_t serial_rx_data;
uintptr_t serial_tx_data;

sddf_serial_ring_handle_t serial_rx_ring_handle;
sddf_serial_ring_handle_t serial_tx_ring_handle;
ring_handle_t serial_rx_ring_handle;
ring_handle_t serial_tx_ring_handle;

static sddf_serial_ring_handle_t *serial_ring_handles[SDDF_SERIAL_NUM_RING_HANDLES];
static ring_handle_t *serial_ring_handles[NUM_RING_HANDLES];

static struct virtio_device virtio_console;

Expand Down Expand Up @@ -98,39 +98,39 @@ void init(void) {
}

/* Initialise our sDDF ring buffers for the serial device */
sddf_serial_ring_init(&serial_rx_ring_handle,
(sddf_serial_ring_buffer_t *)serial_rx_free,
(sddf_serial_ring_buffer_t *)serial_rx_used,
ring_init(&serial_rx_ring_handle,
(ring_buffer_t *)serial_rx_free,
(ring_buffer_t *)serial_rx_used,
true,
SDDF_SERIAL_NUM_BUFFERS,
SDDF_SERIAL_NUM_BUFFERS);
for (int i = 0; i < SDDF_SERIAL_NUM_BUFFERS - 1; i++) {
int ret = sddf_serial_enqueue_free(&serial_rx_ring_handle, serial_rx_data + (i * SDDF_SERIAL_BUFFER_SIZE), SDDF_SERIAL_BUFFER_SIZE, NULL);
NUM_BUFFERS,
NUM_BUFFERS);
for (int i = 0; i < NUM_BUFFERS - 1; i++) {
int ret = enqueue_free(&serial_rx_ring_handle, serial_rx_data + (i * BUFFER_SIZE), BUFFER_SIZE, NULL);
if (ret != 0) {
microkit_dbg_puts(microkit_name);
microkit_dbg_puts(": server rx buffer population, unable to enqueue buffer\n");
}
}
sddf_serial_ring_init(&serial_tx_ring_handle,
(sddf_serial_ring_buffer_t *)serial_tx_free,
(sddf_serial_ring_buffer_t *)serial_tx_used,
ring_init(&serial_tx_ring_handle,
(ring_buffer_t *)serial_tx_free,
(ring_buffer_t *)serial_tx_used,
true,
SDDF_SERIAL_NUM_BUFFERS,
SDDF_SERIAL_NUM_BUFFERS);
for (int i = 0; i < SDDF_SERIAL_NUM_BUFFERS - 1; i++) {
NUM_BUFFERS,
NUM_BUFFERS);
for (int i = 0; i < NUM_BUFFERS - 1; i++) {
// Have to start at the memory region left of by the rx ring
int ret = sddf_serial_enqueue_free(&serial_tx_ring_handle, serial_tx_data + ((i + SDDF_SERIAL_NUM_BUFFERS) * SDDF_SERIAL_BUFFER_SIZE), SDDF_SERIAL_BUFFER_SIZE, NULL);
int ret = enqueue_free(&serial_tx_ring_handle, serial_tx_data + ((i + NUM_BUFFERS) * BUFFER_SIZE), BUFFER_SIZE, NULL);
assert(ret == 0);
if (ret != 0) {
microkit_dbg_puts(microkit_name);
microkit_dbg_puts(": server tx buffer population, unable to enqueue buffer\n");
}
}
serial_ring_handles[SDDF_SERIAL_RX_RING] = &serial_rx_ring_handle;
serial_ring_handles[SDDF_SERIAL_TX_RING] = &serial_tx_ring_handle;
serial_ring_handles[RX_RING] = &serial_rx_ring_handle;
serial_ring_handles[TX_RING] = &serial_tx_ring_handle;
/* Neither ring should be plugged and hence all buffers we send should actually end up at the driver. */
assert(!sddf_serial_ring_plugged(serial_tx_ring_handle.free_ring));
assert(!sddf_serial_ring_plugged(serial_tx_ring_handle.used_ring));
assert(!ring_plugged(serial_tx_ring_handle.free_ring));
assert(!ring_plugged(serial_tx_ring_handle.used_ring));
/* Initialise virtIO console device */
success = virtio_mmio_device_init(&virtio_console, CONSOLE, VIRTIO_CONSOLE_BASE, VIRTIO_CONSOLE_SIZE, VIRTIO_CONSOLE_IRQ,
NULL, (void **)serial_ring_handles, SERIAL_MUX_TX_CH);
Expand Down
2 changes: 1 addition & 1 deletion examples/virtio/sddf
Submodule sddf updated from 91685a to bbd044
Loading

0 comments on commit c2d6844

Please sign in to comment.