Skip to content

Commit

Permalink
Adhering to style check
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Velickovic <[email protected]>
  • Loading branch information
Ivan-Velickovic committed Aug 21, 2024
1 parent 719fd18 commit e536750
Show file tree
Hide file tree
Showing 15 changed files with 470 additions and 366 deletions.
46 changes: 25 additions & 21 deletions examples/simple/vmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,33 @@ 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;

static void serial_ack(size_t vcpu_id, int irq, void *cookie) {
static void serial_ack(size_t vcpu_id, int irq, void *cookie)
{
/*
* For now we by default simply ack the serial IRQ, we have not
* come across a case yet where more than this needs to be done.
*/
microkit_irq_ack(SERIAL_IRQ_CH);
}

void init(void) {
void init(void)
{
/* Initialise the VMM, the VCPU(s), and start the guest */
LOG_VMM("starting \"%s\"\n", microkit_name);
/* Place all the binaries in the right locations before starting the guest */
size_t kernel_size = _guest_kernel_image_end - _guest_kernel_image;
size_t dtb_size = _guest_dtb_image_end - _guest_dtb_image;
size_t initrd_size = _guest_initrd_image_end - _guest_initrd_image;
uintptr_t kernel_pc = linux_setup_images(guest_ram_vaddr,
(uintptr_t) _guest_kernel_image,
kernel_size,
(uintptr_t) _guest_dtb_image,
GUEST_DTB_VADDR,
dtb_size,
(uintptr_t) _guest_initrd_image,
GUEST_INIT_RAM_DISK_VADDR,
initrd_size
);
(uintptr_t) _guest_kernel_image,
kernel_size,
(uintptr_t) _guest_dtb_image,
GUEST_DTB_VADDR,
dtb_size,
(uintptr_t) _guest_initrd_image,
GUEST_INIT_RAM_DISK_VADDR,
initrd_size
);
if (!kernel_pc) {
LOG_VMM_ERR("Failed to initialise guest images\n");
return;
Expand All @@ -118,17 +120,18 @@ void init(void) {
guest_start(kernel_pc, GUEST_DTB_VADDR, GUEST_INIT_RAM_DISK_VADDR);
}

void notified(microkit_channel ch) {
void notified(microkit_channel ch)
{
switch (ch) {
case SERIAL_IRQ_CH: {
bool success = virq_inject(SERIAL_IRQ);
if (!success) {
LOG_VMM_ERR("IRQ %d dropped\n", SERIAL_IRQ);
}
break;
case SERIAL_IRQ_CH: {
bool success = virq_inject(SERIAL_IRQ);
if (!success) {
LOG_VMM_ERR("IRQ %d dropped\n", SERIAL_IRQ);
}
default:
printf("Unexpected channel, ch: 0x%lx\n", ch);
break;
}
default:
printf("Unexpected channel, ch: 0x%lx\n", ch);
}
}

Expand All @@ -137,7 +140,8 @@ void notified(microkit_channel ch) {
* Whenever our guest causes an exception, it gets delivered to this entry point for
* the VMM to handle.
*/
seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo) {
seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo)
{
bool success = fault_handle(child, msginfo);
if (success) {
/* Now that we have handled the fault successfully, we reply to it so
Expand Down
78 changes: 41 additions & 37 deletions examples/virtio-snd/client_vmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,24 @@ static struct virtio_snd_device virtio_sound;

uintptr_t kernel_pc = 0;

void init(void) {
void init(void)
{
/* Initialise the VMM, the VCPU(s), and start the guest */
LOG_VMM("starting \"%s\"\n", microkit_name);
/* Place all the binaries in the right locations before starting the guest */
size_t kernel_size = _guest_kernel_image_end - _guest_kernel_image;
size_t dtb_size = _guest_dtb_image_end - _guest_dtb_image;
size_t initrd_size = _guest_initrd_image_end - _guest_initrd_image;
kernel_pc = linux_setup_images(guest_ram_vaddr,
(uintptr_t) _guest_kernel_image,
kernel_size,
(uintptr_t) _guest_dtb_image,
GUEST_DTB_VADDR,
dtb_size,
(uintptr_t) _guest_initrd_image,
GUEST_INIT_RAM_DISK_VADDR,
initrd_size
);
(uintptr_t) _guest_kernel_image,
kernel_size,
(uintptr_t) _guest_dtb_image,
GUEST_DTB_VADDR,
dtb_size,
(uintptr_t) _guest_initrd_image,
GUEST_INIT_RAM_DISK_VADDR,
initrd_size
);
if (!kernel_pc) {
LOG_VMM_ERR("Failed to initialise guest images\n");
return;
Expand All @@ -103,15 +104,16 @@ void init(void) {

/* Initialise our sDDF ring buffers for the serial device */
serial_queue_handle_t serial_rxq, serial_txq;
serial_cli_queue_init_sys(microkit_name, &serial_rxq, serial_rx_queue, serial_rx_data, &serial_txq, serial_tx_queue, serial_tx_data);
serial_cli_queue_init_sys(microkit_name, &serial_rxq, serial_rx_queue, serial_rx_data, &serial_txq, serial_tx_queue,
serial_tx_data);

/* Initialise virtIO console device */
success = virtio_mmio_console_init(&virtio_console,
VIRTIO_CONSOLE_BASE,
VIRTIO_CONSOLE_SIZE,
VIRTIO_CONSOLE_IRQ,
&serial_rxq, &serial_txq,
SERIAL_VIRT_TX_CH);
VIRTIO_CONSOLE_BASE,
VIRTIO_CONSOLE_SIZE,
VIRTIO_CONSOLE_IRQ,
&serial_rxq, &serial_txq,
SERIAL_VIRT_TX_CH);
assert(success);

assert(sound_cmd_req);
Expand All @@ -138,37 +140,39 @@ void init(void) {
while (!ATOMIC_LOAD(&shared_state->ready, __ATOMIC_ACQUIRE));

success = virtio_mmio_snd_init(&virtio_sound,
VIRTIO_SOUND_BASE,
VIRTIO_SOUND_SIZE,
VIRTIO_SOUND_IRQ,
shared_state,
&sound_queues,
sound_data,
SOUND_DRIVER_CH);
VIRTIO_SOUND_BASE,
VIRTIO_SOUND_SIZE,
VIRTIO_SOUND_IRQ,
shared_state,
&sound_queues,
sound_data,
SOUND_DRIVER_CH);
assert(success);

success = guest_start(GUEST_BOOT_VCPU_ID, kernel_pc, GUEST_DTB_VADDR, GUEST_INIT_RAM_DISK_VADDR);
assert(success);
}

void notified(microkit_channel ch) {
void notified(microkit_channel ch)
{
switch (ch) {
case SERIAL_VIRT_RX_CH: {
/* We have received an event from the serial virtualiser, so we
* call the virtIO console handling */
virtio_console_handle_rx(&virtio_console);
break;
}
case SOUND_DRIVER_CH: {
virtio_snd_notified(&virtio_sound);
break;
}
default:
printf("Unexpected channel, ch: 0x%lx\n", ch);
case SERIAL_VIRT_RX_CH: {
/* We have received an event from the serial virtualiser, so we
* call the virtIO console handling */
virtio_console_handle_rx(&virtio_console);
break;
}
case SOUND_DRIVER_CH: {
virtio_snd_notified(&virtio_sound);
break;
}
default:
printf("Unexpected channel, ch: 0x%lx\n", ch);
}
}

seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo) {
seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo)
{
bool success = fault_handle(child, msginfo);
if (success) {
/* Now that we have handled the fault successfully, we reply to it so
Expand Down
55 changes: 31 additions & 24 deletions examples/virtio-snd/snd_driver_vmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ uintptr_t sound_data_paddr;

static struct virtio_console_device virtio_console;

static void passthrough_device_ack(size_t vcpu_id, int irq, void *cookie) {
static void passthrough_device_ack(size_t vcpu_id, int irq, void *cookie)
{
microkit_channel irq_ch = (microkit_channel)(int64_t)cookie;
microkit_irq_ack(irq_ch);
}

static void register_passthrough_irq(int irq, microkit_channel irq_ch) {
static void register_passthrough_irq(int irq, microkit_channel irq_ch)
{
LOG_VMM("Register passthrough IRQ %d (channel: 0x%lx)\n", irq, irq_ch);
assert(irq_ch < MAX_IRQ_CH);
passthrough_irq_map[irq_ch] = irq;
Expand All @@ -90,17 +92,19 @@ static void register_passthrough_irq(int irq, microkit_channel irq_ch) {
}

static bool uio_sound_fault_handler(size_t vcpu_id,
size_t offset,
size_t fsr,
seL4_UserContext *regs,
void *data) {
size_t offset,
size_t fsr,
seL4_UserContext *regs,
void *data)
{
microkit_notify(SND_CLIENT_CH);
return true;
}

static void uio_sound_virq_ack(size_t vcpu_id, int irq, void *cookie) {}

void init(void) {
void init(void)
{
/* Initialise the VMM, the VCPU(s), and start the guest */
LOG_VMM("starting \"%s\"\n", microkit_name);
/* Place all the binaries in the right locations before starting the guest */
Expand All @@ -109,15 +113,15 @@ void init(void) {
size_t initrd_size = _guest_initrd_image_end - _guest_initrd_image;

uintptr_t kernel_pc = linux_setup_images(guest_ram_vaddr,
(uintptr_t) _guest_kernel_image,
kernel_size,
(uintptr_t) _guest_dtb_image,
GUEST_DTB_VADDR,
dtb_size,
(uintptr_t) _guest_initrd_image,
GUEST_INIT_RAM_DISK_VADDR,
initrd_size
);
(uintptr_t) _guest_kernel_image,
kernel_size,
(uintptr_t) _guest_dtb_image,
GUEST_DTB_VADDR,
dtb_size,
(uintptr_t) _guest_initrd_image,
GUEST_INIT_RAM_DISK_VADDR,
initrd_size
);
if (!kernel_pc) {
LOG_VMM_ERR("Failed to initialise guest images\n");
return;
Expand All @@ -137,15 +141,16 @@ void init(void) {

/* Initialise our sDDF ring buffers for the serial device */
serial_queue_handle_t serial_rxq, serial_txq;
serial_cli_queue_init_sys(microkit_name, &serial_rxq, serial_rx_queue, serial_rx_data, &serial_txq, serial_tx_queue, serial_tx_data);
serial_cli_queue_init_sys(microkit_name, &serial_rxq, serial_rx_queue, serial_rx_data, &serial_txq, serial_tx_queue,
serial_tx_data);

/* Initialise virtIO console device */
success = virtio_mmio_console_init(&virtio_console,
VIRTIO_CONSOLE_BASE,
VIRTIO_CONSOLE_SIZE,
VIRTIO_CONSOLE_IRQ,
&serial_rxq, &serial_txq,
SERIAL_TX_CH);
VIRTIO_CONSOLE_BASE,
VIRTIO_CONSOLE_SIZE,
VIRTIO_CONSOLE_IRQ,
&serial_rxq, &serial_txq,
SERIAL_TX_CH);
assert(success);

success = virq_register(GUEST_BOOT_VCPU_ID, UIO_SND_IRQ, &uio_sound_virq_ack, NULL);
Expand Down Expand Up @@ -175,7 +180,8 @@ void init(void) {
guest_start(GUEST_BOOT_VCPU_ID, kernel_pc, GUEST_DTB_VADDR, GUEST_INIT_RAM_DISK_VADDR);
}

void notified(microkit_channel ch) {
void notified(microkit_channel ch)
{
bool success;

switch (ch) {
Expand All @@ -202,7 +208,8 @@ void notified(microkit_channel ch) {
}
}

seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo) {
seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo)
{
bool success = fault_handle(child, msginfo);
if (success) {
/* Now that we have handled the fault successfully, we reply to it so
Expand Down
17 changes: 9 additions & 8 deletions examples/virtio/blk_driver_vmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,16 @@ void init(void)

/* Initialise our sDDF ring buffers for the serial device */
serial_queue_handle_t serial_rxq, serial_txq;
serial_cli_queue_init_sys(microkit_name, &serial_rxq, serial_rx_queue, serial_rx_data, &serial_txq, serial_tx_queue, serial_tx_data);

serial_cli_queue_init_sys(microkit_name, &serial_rxq, serial_rx_queue, serial_rx_data, &serial_txq, serial_tx_queue,
serial_tx_data);

/* Initialise virtIO console device */
success = virtio_mmio_console_init(&virtio_console,
VIRTIO_CONSOLE_BASE,
VIRTIO_CONSOLE_SIZE,
VIRTIO_CONSOLE_IRQ,
&serial_rxq, &serial_txq,
SERIAL_VIRT_TX_CH);
VIRTIO_CONSOLE_BASE,
VIRTIO_CONSOLE_SIZE,
VIRTIO_CONSOLE_IRQ,
&serial_rxq, &serial_txq,
SERIAL_VIRT_TX_CH);
assert(success);

/* Register the UIO IRQ */
Expand Down Expand Up @@ -162,7 +162,8 @@ void notified(microkit_channel ch)
}
}

seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo) {
seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo)
{
bool success = fault_handle(child, msginfo);
if (success) {
/* Now that we have handled the fault successfully, we reply to it so
Expand Down
Loading

0 comments on commit e536750

Please sign in to comment.