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

Upstream virtio block, refactor libuio, and fix virtio block descriptor chain parsing #128

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
7 changes: 4 additions & 3 deletions examples/virtio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ Welcome to Buildroot
buildroot login:
```

Initially all input is defaulted to guest 1 in green. To switch to input into
the other guest (red), type in `@2`. The `@` symbol is used to switch between
clients of the serial system, in this case the red guest is client 2.
Initially all input is defaulted to guest 0 in red. To switch input into
the other guest 1 (green), type in `ctrl + \` followed by `1` and then `enter`.
To switch input to the block driver VM, type in `ctrl + \`, followed by `2` and `enter`.

### virtIO block

Expand All @@ -137,6 +137,7 @@ divided by the disk's logical size. Partitions that do not follow this restricti
are unsupported.

### QEMU set up

When running on QEMU, read and writes go to an emulated ramdisk instead of to your
local storage device. The ramdisk file supplied to QEMU is formatted during build
time to contain a FAT filesystem for both partitions.
Expand Down
47 changes: 34 additions & 13 deletions examples/virtio/blk_driver_vmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <stddef.h>
#include <stdint.h>
#include <microkit.h>
#include <blk_config.h>
#include <libvmm/arch/aarch64/fault.h>
#include <libvmm/arch/aarch64/linux.h>
#include <libvmm/guest.h>
#include <libvmm/virq.h>
#include <libvmm/uio/uio.h>
#include <libvmm/util/util.h>
#include <libvmm/virq.h>
#include <libvmm/virtio/virtio.h>
#include <libvmm/arch/aarch64/linux.h>
#include <libvmm/arch/aarch64/fault.h>
#include <microkit.h>
#include <sddf/serial/queue.h>
#include <serial_config.h>
#include <stddef.h>
#include <stdint.h>
#include <uio/blk.h>

#define GUEST_RAM_SIZE 0x6000000

Expand All @@ -39,6 +42,12 @@ extern char _guest_initrd_image_end[];
/* Microkit will set this variable to the start of the guest RAM memory region. */
uintptr_t guest_ram_vaddr;

/* Passing info from VMM to block uio driver */
driver_blk_vmm_info_passing_t *driver_blk_vmm_info_passing;
uintptr_t virt_blk_data;
uintptr_t client_vmm_1_blk_data;
uintptr_t client_vmm_2_blk_data;

/* sDDF block */
#define BLOCK_CH 1
#if defined(BOARD_odroidc4)
Expand All @@ -50,6 +59,11 @@ uintptr_t guest_ram_vaddr;
#define UIO_IRQ 50
#define UIO_CH 3

/* This global is kind of redundant, but for now it's needed to be passed
* through to the uio-vmm notify handler
*/
microkit_channel uio_ch = UIO_CH;

/* Serial */
#define SERIAL_VIRT_TX_CH 4
#define SERIAL_VIRT_RX_CH 5
Expand All @@ -66,11 +80,6 @@ char *serial_tx_data;

static struct virtio_console_device virtio_console;

void uio_ack(size_t vcpu_id, int irq, void *cookie)
{
microkit_notify(UIO_CH);
}

void init(void)
{
/* Initialise the VMM, the VCPU(s), and start the guest */
Expand Down Expand Up @@ -120,8 +129,20 @@ void init(void)
SERIAL_VIRT_TX_CH);
assert(success);

/* Register the UIO IRQ */
virq_register(GUEST_VCPU_ID, UIO_IRQ, uio_ack, NULL);
/* Register the block uio driver */
success = uio_register_driver(UIO_IRQ, &uio_ch, 0x80000000, 0x1000);
assert(success);

/* Populate vmm info passing to block uio driver */
driver_blk_vmm_info_passing->client_data_phys[0] = virt_blk_data;
driver_blk_vmm_info_passing->client_data_phys[1] = client_vmm_1_blk_data;
driver_blk_vmm_info_passing->client_data_phys[2] = client_vmm_2_blk_data;
driver_blk_vmm_info_passing->client_data_size[0] =
BLK_DATA_REGION_SIZE_DRIV;
driver_blk_vmm_info_passing->client_data_size[1] =
BLK_DATA_REGION_SIZE_CLI0;
driver_blk_vmm_info_passing->client_data_size[2] =
BLK_DATA_REGION_SIZE_CLI1;

#if defined(BOARD_odroidc4)
/* Register the SD card IRQ */
Expand Down
23 changes: 17 additions & 6 deletions examples/virtio/board/odroidc4/blk_driver_vm/dts/overlays/io.dts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,24 @@
uio0 {
compatible = "generic-uio\0uio";
reg = <
0x00 0x39800000 0x00 0x1000
0x00 0x40000000 0x00 0x1000
0x00 0x40200000 0x00 0x200000
0x00 0x40400000 0x00 0x200000
0x00 0x40800000 0x00 0x200000
0x00 0x79800000 0x00 0x1000
0x00 0x80000000 0x00 0x1000
0x00 0x80200000 0x00 0x1000
0x00 0x80400000 0x00 0x200000
0x00 0x80600000 0x00 0x200000
>;
interrupts = <0x00 18 0x04>;
// IRQ = 50
};
};

/* Second UIO device for blk, just need this for the 2 extra regions */
uio1 {
compatible = "generic-uio\0uio";
reg = <
0x00 0x80800000 0x00 0x200000
0x00 0x80a00000 0x00 0x200000
0x00 0x80c00000 0x00 0x200000
0x00 0x80e00000 0x00 0x200000
>;
};
};
208 changes: 110 additions & 98 deletions examples/virtio/board/odroidc4/virtio.system

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,24 @@
uio0 {
compatible = "generic-uio\0uio";
reg = <
0x00 0x29800000 0x00 0x1000
0x00 0x20000000 0x00 0x1000
0x00 0x20200000 0x00 0x200000
0x00 0x20400000 0x00 0x200000
0x00 0x20800000 0x00 0x200000
0x00 0x79800000 0x00 0x1000
0x00 0x80000000 0x00 0x1000
0x00 0x80200000 0x00 0X1000
0x00 0x80400000 0x00 0x200000
0x00 0x80600000 0x00 0x200000
>;
interrupts = <0x00 18 0x04>;
// IRQ = 50
};
};

/* Second UIO device for blk, just need this for the 2 extra regions */
uio1 {
compatible = "generic-uio\0uio";
reg = <
0x00 0x80800000 0x00 0x200000
0x00 0x80a00000 0x00 0x200000
0x00 0x80c00000 0x00 0x200000
0x00 0x80e00000 0x00 0x200000
>;
};
};
Loading
Loading