Skip to content

Commit

Permalink
Update virtIO block library
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Brown <[email protected]>
  • Loading branch information
alexandermbrown committed May 7, 2024
1 parent 2898afa commit 8ad5f42
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 174 deletions.
2 changes: 0 additions & 2 deletions examples/virtio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ VMM_OBJS := printf.o \
CLIENT_VMM_1_OBJS := $(VMM_OBJS) \
client_images_1.o \
client_vmm.o \
virtio.o \
console.o \
block.o \
mmio.o \
Expand All @@ -183,7 +182,6 @@ CLIENT_VMM_1_OBJS := $(VMM_OBJS) \
CLIENT_VMM_2_OBJS := $(VMM_OBJS) \
client_images_2.o \
client_vmm.o \
virtio.o \
console.o \
block.o \
mmio.o \
Expand Down
89 changes: 39 additions & 50 deletions examples/virtio/client_vmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ uintptr_t serial_tx_active;
uintptr_t serial_rx_data;
uintptr_t serial_tx_data;

serial_queue_handle_t serial_rx_h;
serial_queue_handle_t serial_tx_h;
sddf_handler_t sddf_serial_handlers[SDDF_SERIAL_NUM_HANDLES];

static struct virtio_device virtio_console;
static struct virtio_console_device virtio_console;

/* Virtio Block */
#define BLK_CH 3
Expand All @@ -80,17 +76,16 @@ uintptr_t blk_resp_queue;
uintptr_t blk_data;
uintptr_t blk_config;

blk_queue_handle_t blk_queue_h;
sddf_handler_t sddf_blk_handlers[SDDF_BLK_NUM_HANDLES];

static struct virtio_device virtio_blk;
static struct virtio_blk_device virtio_blk;

void init(void)
{
blk_storage_info_t *storage_info = (blk_storage_info_t *)blk_config;

/* Busy wait until blk device is ready
Need to put an empty assembly line to prevent compiler from optimising out the busy wait */
LOG_VMM("begin busy wait\n");
while (!((blk_storage_info_t *)blk_config)->ready) {
while (!storage_info->ready) {
asm("");
}
LOG_VMM("done busy waiting\n");
Expand Down Expand Up @@ -123,77 +118,71 @@ void init(void)
return;
}

/* virtIO console */
sddf_serial_handlers[SDDF_SERIAL_RX_HANDLE].queue_h = &serial_rx_h;
sddf_serial_handlers[SDDF_SERIAL_RX_HANDLE].config = NULL;
sddf_serial_handlers[SDDF_SERIAL_RX_HANDLE].data = (uintptr_t)serial_rx_data;
sddf_serial_handlers[SDDF_SERIAL_RX_HANDLE].data_size = 0; /* Unused */
sddf_serial_handlers[SDDF_SERIAL_RX_HANDLE].ch = SERIAL_VIRT_RX_CH;

sddf_serial_handlers[SDDF_SERIAL_TX_HANDLE].queue_h = &serial_tx_h;
sddf_serial_handlers[SDDF_SERIAL_TX_HANDLE].config = NULL;
sddf_serial_handlers[SDDF_SERIAL_TX_HANDLE].data = (uintptr_t)serial_tx_data;
sddf_serial_handlers[SDDF_SERIAL_TX_HANDLE].data_size = 0; /* Unusued */
sddf_serial_handlers[SDDF_SERIAL_TX_HANDLE].ch = SERIAL_VIRT_TX_CH;

/* Initialise our sDDF queues for the serial device */
serial_queue_init(sddf_serial_handlers[SDDF_SERIAL_RX_HANDLE].queue_h,
/* Initialise our sDDF ring buffers for the serial device */
serial_queue_handle_t rxq, txq;
serial_queue_init(&rxq,
(serial_queue_t *)serial_rx_free,
(serial_queue_t *)serial_rx_active,
true,
NUM_ENTRIES,
NUM_ENTRIES);
for (int i = 0; i < NUM_ENTRIES - 1; i++) {
int ret = serial_enqueue_free(sddf_serial_handlers[SDDF_SERIAL_RX_HANDLE].queue_h, serial_rx_data + (i * BUFFER_SIZE),
BUFFER_SIZE);
int ret = serial_enqueue_free(&rxq,
serial_rx_data + (i * BUFFER_SIZE),
BUFFER_SIZE);
if (ret != 0) {
microkit_dbg_puts(microkit_name);
microkit_dbg_puts(": server rx buffer population, unable to enqueue\n");
microkit_dbg_puts(": server rx buffer population, unable to enqueue buffer\n");
}
}
/* Neither ring should be plugged and hence all buffers we send should actually end up at the driver. */
assert(!serial_queue_plugged(((serial_queue_handle_t *)sddf_serial_handlers[SDDF_SERIAL_RX_HANDLE].queue_h)->free));
assert(!serial_queue_plugged(((serial_queue_handle_t *)sddf_serial_handlers[SDDF_SERIAL_RX_HANDLE].queue_h)->active));

serial_queue_init(sddf_serial_handlers[SDDF_SERIAL_TX_HANDLE].queue_h,
serial_queue_init(&txq,
(serial_queue_t *)serial_tx_free,
(serial_queue_t *)serial_tx_active,
true,
NUM_ENTRIES,
NUM_ENTRIES);
for (int i = 0; i < NUM_ENTRIES - 1; i++) {
int ret = serial_enqueue_free(sddf_serial_handlers[SDDF_SERIAL_TX_HANDLE].queue_h, serial_tx_data + (i * BUFFER_SIZE),
BUFFER_SIZE);
// Have to start at the memory region left of by the rx ring
int ret = serial_enqueue_free(&txq,
serial_tx_data + ((i + NUM_ENTRIES) * BUFFER_SIZE),
BUFFER_SIZE);
assert(ret == 0);
if (ret != 0) {
microkit_dbg_puts(microkit_name);
microkit_dbg_puts(": server tx buffer population, unable to enqueue\n");
microkit_dbg_puts(": server tx buffer population, unable to enqueue buffer\n");
}
}
assert(!serial_queue_plugged(((serial_queue_handle_t *)sddf_serial_handlers[SDDF_SERIAL_RX_HANDLE].queue_h)->free));
assert(!serial_queue_plugged(((serial_queue_handle_t *)sddf_serial_handlers[SDDF_SERIAL_RX_HANDLE].queue_h)->active));

/* Neither ring should be plugged and hence all buffers we send should actually end up at the driver. */
assert(!serial_queue_plugged(rxq.free));
assert(!serial_queue_plugged(rxq.active));
assert(!serial_queue_plugged(txq.free));
assert(!serial_queue_plugged(txq.active));

/* Initialise virtIO console device */
success = virtio_mmio_device_init(&virtio_console, CONSOLE, VIRTIO_CONSOLE_BASE, VIRTIO_CONSOLE_SIZE,
VIRTIO_CONSOLE_IRQ, sddf_serial_handlers);
assert(success);
success = virtio_mmio_console_init(&virtio_console,
VIRTIO_CONSOLE_BASE,
VIRTIO_CONSOLE_SIZE,
VIRTIO_CONSOLE_IRQ,
&rxq, &txq,
SERIAL_VIRT_TX_CH);

/* virtIO block */
sddf_blk_handlers[SDDF_BLK_DEFAULT_HANDLE].queue_h = &blk_queue_h;
sddf_blk_handlers[SDDF_BLK_DEFAULT_HANDLE].config = (void *)blk_config;
sddf_blk_handlers[SDDF_BLK_DEFAULT_HANDLE].data = (uintptr_t)blk_data;
sddf_blk_handlers[SDDF_BLK_DEFAULT_HANDLE].data_size = BLK_DATA_SIZE;
sddf_blk_handlers[SDDF_BLK_DEFAULT_HANDLE].ch = BLK_CH;

/* Initialise our sDDF queues for the block device */
blk_queue_init(sddf_blk_handlers[SDDF_BLK_DEFAULT_HANDLE].queue_h,
blk_queue_handle_t blk_queue_h;
blk_queue_init(&blk_queue_h,
(blk_req_queue_t *)blk_req_queue,
(blk_resp_queue_t *)blk_resp_queue,
BLK_QUEUE_SIZE);

/* Initialise virtIO block device */
success = virtio_mmio_device_init(&virtio_blk, BLOCK, VIRTIO_BLK_BASE, VIRTIO_BLK_SIZE, VIRTIO_BLK_IRQ,
sddf_blk_handlers);
success = virtio_mmio_blk_init(&virtio_blk,
VIRTIO_BLK_BASE, VIRTIO_BLK_SIZE, VIRTIO_BLK_IRQ,
blk_data,
BLK_DATA_SIZE,
storage_info,
&blk_queue_h,
BLK_CH);
assert(success);

/* Finally start the guest */
Expand Down
Loading

0 comments on commit 8ad5f42

Please sign in to comment.