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

Support for virtIO sound #37

Merged
merged 50 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
58bbc2f
virtio-snd: add virtIO device and UIO driver
alexandermbrown Dec 11, 2023
07b8454
virtio-snd: add virtIO support level to docs
alexandermbrown Apr 19, 2024
bdb5704
virtio-snd: virtIO refactor
alexandermbrown Apr 24, 2024
f357a25
virtio-snd: add minor sDDF sound improvements
alexandermbrown Apr 29, 2024
567560c
virtio-snd: use busy wait on init
alexandermbrown May 1, 2024
ebff47c
virtio-snd: remove q size from shared memory
alexandermbrown May 1, 2024
d59bb31
virtio-snd: switch back to freelist
alexandermbrown May 1, 2024
fbf355c
virtio-snd: improve buffer addressing
alexandermbrown May 6, 2024
4dfe615
virtio-snd: rename data_*addr to data_region_*addr
alexandermbrown May 6, 2024
2ed0362
virtio-snd: remove .clang-format
alexandermbrown May 6, 2024
715eefc
virtio-snd: label passthrough IRQs
alexandermbrown May 6, 2024
5e59718
virtio-snd: remove unused min function
alexandermbrown May 6, 2024
08478c5
virtio-snd: fix Makefile after rebase
alexandermbrown May 7, 2024
e4bb893
Update virtIO block library
alexandermbrown May 7, 2024
bae4331
Add 3rd serial client to examples/virtio
alexandermbrown May 7, 2024
80a334b
Concatenate rootfs instead of unpacking
alexandermbrown May 7, 2024
08ba443
virtio-snd: move uio_sound.h to tools
alexandermbrown May 8, 2024
3297a3a
virtio-snd: remove cantina & crav_rave
alexandermbrown May 8, 2024
6ba5745
virtio-snd: add comment to alsa config
alexandermbrown May 8, 2024
07974bf
virtio-snd: fix switch statement indentation
alexandermbrown May 9, 2024
403a563
virtio-snd: cleanup shell.nix
alexandermbrown May 9, 2024
d61f2b7
Make ialloc 32-bit and use in virtIO sound
alexandermbrown May 9, 2024
8237e0c
sound: minor style changes
Ivan-Velickovic May 9, 2024
134b8fa
virtio-snd: remove unused buffer.h
alexandermbrown May 9, 2024
f5170d1
Add back virtIO 1.2 comment
alexandermbrown May 9, 2024
6e8709f
virtio-snd: add QUEUE_BYTES comment
alexandermbrown May 9, 2024
f7f2577
virtio-snd: remove unused queue_name
alexandermbrown May 9, 2024
f3afba2
virtio-snd: rename SERIAL_MUX_*_CH
alexandermbrown May 9, 2024
ce2e337
virtio-snd: change sddf directory
alexandermbrown May 9, 2024
5c8773b
virtio-snd: remove vgic include
alexandermbrown May 9, 2024
4d5ff41
virtio-snd: remove poll.c
alexandermbrown May 9, 2024
3cc1bc2
virtio-snd: move SOUND.md to virtio-snd
alexandermbrown May 9, 2024
56f561b
virtio: add some comments to MMIO functions
Ivan-Velickovic May 9, 2024
4924b71
sound: fixup README for virtIO sound example
Ivan-Velickovic May 9, 2024
137b0ee
virtio-snd: restructure docs a bit
Ivan-Velickovic May 9, 2024
bcd7939
virtio-snd: use packrootfs
alexandermbrown May 9, 2024
c53fc49
virtio-snd: remove incorrect license
alexandermbrown May 9, 2024
d5e86e8
virtio-snd: comment out DEBUG_SOUND
alexandermbrown May 9, 2024
1fbd5e1
virtio-snd: remove rootfs_overlayed from gitignore
alexandermbrown May 9, 2024
0f25d90
virtio-snd: docs: use svg instead of png
alexandermbrown May 9, 2024
3a13e47
virtio-snd: remove @alexbr comments
alexandermbrown May 9, 2024
3761da2
examples/virtio: remove shell.nix
Ivan-Velickovic May 9, 2024
8ad6656
virtio-snd: coalesce userlevel programs
alexandermbrown May 9, 2024
9aa76a1
virtio-snd: remove pack.sh
alexandermbrown May 9, 2024
04a4191
Remove old sddf_handlers from mmio.h
alexandermbrown May 9, 2024
0cd0fca
examples/virtio-snd: remove whitespace
Ivan-Velickovic May 9, 2024
ae044b4
virtio-snd: docs: remove cantina.elf
alexandermbrown May 9, 2024
a779056
virtio-snd: docs: update startup to busy wait
alexandermbrown May 9, 2024
7efecfb
virtio: remove more whitespace
Ivan-Velickovic May 9, 2024
1d1ca93
virtio-snd: remove unecessary include
Ivan-Velickovic May 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ zig-cache/
*.pdf
*.dtb
rust/target/
.cache
compile_commands.json
300 changes: 300 additions & 0 deletions examples/virtio-snd/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
#
# Copyright 2021, Breakaway Consulting Pty. Ltd.
# Copyright 2022, UNSW (ABN 57 195 873 179)
#
# SPDX-License-Identifier: BSD-2-Clause
#

ifeq ($(strip $(MICROKIT_SDK)),)
$(error MICROKIT_SDK must be specified)
endif

ifeq ($(strip $(BOARD)),)
$(error BOARD must be specified)
endif

# Default build directory, pass BUILD_DIR=<dir> to override
BUILD_DIR ?= build
# Default config is a debug build, pass CONFIG=<debug/release/benchmark> to override
CONFIG ?= debug

# Specify that we use bash for all shell commands
SHELL=/bin/bash
# All dependencies needed to compile the VMM
QEMU := qemu-system-aarch64
QEMU_SND_BACKEND := coreaudio
QEMU_SND_FRONTEND := hda

DTC := dtc

CC := clang
CC_USERLEVEL := zig cc
LD := ld.lld
MICROKIT_TOOL ?= $(MICROKIT_SDK)/bin/microkit

BOARD_DIR := $(MICROKIT_SDK)/board/$(BOARD)/$(CONFIG)
VMM := ../../
VMM_TOOLS := $(VMM)/tools
VMM_SRC_DIR := $(VMM)/src
SYSTEM_DESCRIPTION := board/$(BOARD)/virtio-snd.system

CURRENT_DIR := $(shell pwd)

LINUX_DIR := $(VMM_TOOLS)/linux
LINUX_SND_DIR := $(LINUX_DIR)/snd
UIO_DRIVERS_DIR := $(LINUX_DIR)/uio_drivers

VM_USERLEVEL_DIR := userlevel/

SND_DRIVER_VM_DIR := board/$(BOARD)/snd_driver_vm
SND_DRIVER_VM_DTS_DIR := $(SND_DRIVER_VM_DIR)/dts
SND_DRIVER_VM_ROOTFS_TMP_DIR := $(BUILD_DIR)/snd_driver_vm_rootfs

CLIENT_VM_DIR := board/$(BOARD)/client_vm
CLIENT_VM_DTS_DIR := $(CLIENT_VM_DIR)/dts
CLIENT_VM_ROOTFS_TMP_DIR := $(BUILD_DIR)/client_vm_rootfs

SND_DRIVER_VM_LINUX := $(SND_DRIVER_VM_DIR)/linux
SND_DRIVER_VM_INITRD := $(SND_DRIVER_VM_DIR)/rootfs.cpio.gz
SND_DRIVER_VM_INITRD_OVERLAYED := $(BUILD_DIR)/snd_driver_rootfs.cpio.gz
SND_DRIVER_VM_BASE_DTS := $(SND_DRIVER_VM_DTS_DIR)/linux.dts
SND_DRIVER_VM_DTS_OVERLAYS := $(SND_DRIVER_VM_DTS_DIR)/init.dts \
$(SND_DRIVER_VM_DTS_DIR)/io.dts

CLIENT_VM_LINUX := $(CLIENT_VM_DIR)/linux
CLIENT_VM_INITRD := $(CLIENT_VM_DIR)/rootfs.cpio.gz
CLIENT_VM_INITRD_OVERLAYED := $(BUILD_DIR)/client_vm_rootfs.cpio.gz
CLIENT_VM_BASE_DTS := $(CLIENT_VM_DTS_DIR)/linux.dts
CLIENT_VM_DTS_OVERLAYS := $(CLIENT_VM_DTS_DIR)/init.dts \
$(CLIENT_VM_DTS_DIR)/io.dts

SND_DRIVER_VM_DTB := $(BUILD_DIR)/snd_driver_vm.dtb
CLIENT_VM_DTB := $(BUILD_DIR)/client_vm.dtb

SDDF := $(abspath ../../dep/sddf)

SDDF_SERIAL_COMPONENTS := $(SDDF)/serial/components
SDDF_SOUND_COMPONENTS := $(SDDF)/sound/components
SDDF_UTIL := $(SDDF)/util

SDDF_SERIAL_DRIVER_qemu_arm_virt := $(SDDF)/drivers/serial/arm
SDDF_SERIAL_DRIVER_odroidc4 := $(SDDF)/drivers/serial/meson
SDDF_SERIAL_DRIVER := ${SDDF_SERIAL_DRIVER_${BOARD}}

ELFS := client_vmm.elf \
serial_virt_tx.elf \
serial_virt_rx.elf \
uart_driver.elf \
sound_virt.elf \
snd_driver_vmm.elf

SND_DRIVER_VM_USERLEVEL_ELFS := control.elf pcm_min.elf user_sound.elf pcm.elf record.elf feedback.elf
CLIENT_VM_USERLEVEL_ELFS := control.elf pcm_min.elf pcm.elf record.elf feedback.elf

IMAGE_FILE = $(BUILD_DIR)/loader.img
REPORT_FILE = $(BUILD_DIR)/report.txt

# @ivanv: should only compile printf.o in debug
VMM_OBJS := printf.o \
virq.o \
linux.o \
guest.o \
psci.o \
smc.o \
fault.o \
util.o \
vgic.o \
vgic_v2.o \
tcb.o \
vcpu.o \

CLIENT_VMM_OBJS := $(VMM_OBJS) \
client_images.o \
client_vmm.o \
console.o \
sound.o \
mmio.o

SOUND_VIRT_OBJS := sound_virt.o \
sddf_printf.o \
sddf_putchar_debug.o \
sddf_cache.o

SND_DRIVER_VMM_OBJS := $(VMM_OBJS) \
snd_driver_images.o \
snd_driver_vmm.o \
console.o \
mmio.o \
sddf_cache.o

SERIAL_VIRT_TX_OBJS := virt_tx.o sddf_printf.o sddf_putchar_debug.o
SERIAL_VIRT_RX_OBJS := virt_rx.o sddf_printf.o sddf_putchar_debug.o
SERIAL_DRIVER_OBJS := uart.o sddf_printf.o sddf_putchar_debug.o

# Toolchain flags
# FIXME: For optimisation we should consider providing the flag -mcpu.
# FIXME: We should also consider whether -mgeneral-regs-only should be
# used to avoid the use of the FPU and therefore seL4 does not have to
# context switch the FPU.
# Note we only need -Wno-unused-command-line-argument because in Nix
# passes an extra `--gcc-toolchain` flag which we do not need.
CFLAGS := -mstrict-align \
-g3 \
-O3 \
-ffreestanding \
-fno-stack-protector \
-nostdlib \
-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_DRIVER)/include \
-I$(SDDF)/include \
-I$(LINUX_DIR)/include \
-DBOARD_$(BOARD) \
-DCONFIG_$(CONFIG) \
-target aarch64-none-elf

# TODO: currently all userlevel procs link asound. this should instead be done per-process.
CFLAGS_USERLEVEL := -g \
-Wno-unused-command-line-argument \
-Wall -Wno-unused-function -Werror \
-I$(SDDF) \
-I$(SDDF)/include \
-I$(VMM_SRC_DIR) \
-I$(LINUX_DIR)/include \
-DBOARD_$(BOARD) \
-lasound \
-lm \
-target aarch64-linux-gnu \
$(NIX_LDFLAGS) \
$(NIX_CFLAGS_COMPILE)

LDFLAGS := -L$(BOARD_DIR)/lib
LIBS := -lmicrokit -Tmicrokit.ld


.PHONY: all qemu clean

all: directories $(IMAGE_FILE)

qemu: all
# @ivanv: check that the amount of RAM given to QEMU is at least the number of RAM that QEMU is setup with for seL4.
if ! command -v $(QEMU) &> /dev/null; then echo "Could not find dependency: qemu-system-aarch64"; exit 1; fi
$(QEMU) -machine virt,virtualization=on,secure=off \
-cpu cortex-a53 \
-serial mon:stdio \
-device loader,file=$(IMAGE_FILE),addr=0x70000000,cpu-num=0 \
-audio driver=$(QEMU_SND_BACKEND),model=$(QEMU_SND_FRONTEND),id=$(QEMU_SND_BACKEND) \
-m size=2G \
-nographic

directories:
$(shell mkdir -p $(BUILD_DIR))

SND_DRIVER_VM_USERLEVEL_INIT := $(LINUX_SND_DIR)/sound
SND_DRIVER_VM_ETC := $(LINUX_SND_DIR)/board/$(BOARD)/asound.conf

$(SND_DRIVER_VM_INITRD_OVERLAYED): $(addprefix $(BUILD_DIR)/, $(SND_DRIVER_VM_USERLEVEL_ELFS)) \
$(SND_DRIVER_VM_USERLEVEL_INIT) \
$(SND_DRIVER_VM_ETC)
$(VMM_TOOLS)/packrootfs $(SND_DRIVER_VM_INITRD) $(SND_DRIVER_VM_ROOTFS_TMP_DIR) -o $(SND_DRIVER_VM_INITRD_OVERLAYED) \
--startup $(SND_DRIVER_VM_USERLEVEL_INIT) \
--home $(addprefix $(BUILD_DIR)/, $(SND_DRIVER_VM_USERLEVEL_ELFS)) \
--etc $(SND_DRIVER_VM_ETC)

$(CLIENT_VM_INITRD_OVERLAYED): $(addprefix $(BUILD_DIR)/, $(CLIENT_VM_USERLEVEL_ELFS)) \
$(addprefix $(BUILD_DIR)/, $(CLIENT_VM_USERLEVEL_INIT))
$(VMM_TOOLS)/packrootfs $(CLIENT_VM_INITRD) $(CLIENT_VM_ROOTFS_TMP_DIR) -o $(CLIENT_VM_INITRD_OVERLAYED) \
--home $(addprefix $(BUILD_DIR)/, $(CLIENT_VM_USERLEVEL_ELFS))


$(SND_DRIVER_VM_DTB): $(SND_DRIVER_VM_BASE_DTS) $(SND_DRIVER_VM_DTS_OVERLAYS)
sh ../../tools/dtscat $^ > $(BUILD_DIR)/snd_driver_vm.dts
$(DTC) -q -I dts -O dtb $(BUILD_DIR)/snd_driver_vm.dts > $@

$(BUILD_DIR)/snd_driver_images.o: $(VMM_TOOLS)/package_guest_images.S $(SND_DRIVER_VM_LINUX) $(SND_DRIVER_VM_DTB) $(SND_DRIVER_VM_INITRD_OVERLAYED)
$(CC) -c -g3 -x assembler-with-cpp \
-DGUEST_KERNEL_IMAGE_PATH=\"$(SND_DRIVER_VM_LINUX)\" \
-DGUEST_DTB_IMAGE_PATH=\"$(SND_DRIVER_VM_DTB)\" \
-DGUEST_INITRD_IMAGE_PATH=\"$(SND_DRIVER_VM_INITRD_OVERLAYED)\" \
-target aarch64-none-elf \
$< -o $@

$(CLIENT_VM_DTB): $(CLIENT_VM_BASE_DTS) $(CLIENT_VM_DTS_OVERLAYS)
sh ../../tools/dtscat $^ > $(BUILD_DIR)/client_vm.dts
$(DTC) -q -I dts -O dtb $(BUILD_DIR)/client_vm.dts > $@

$(BUILD_DIR)/client_images.o: $(VMM_TOOLS)/package_guest_images.S $(CLIENT_VM_LINUX) $(CLIENT_VM_DTB) $(CLIENT_VM_INITRD_OVERLAYED)
$(CC) -c -g3 -x assembler-with-cpp \
-DGUEST_KERNEL_IMAGE_PATH=\"$(CLIENT_VM_LINUX)\" \
-DGUEST_DTB_IMAGE_PATH=\"$(CLIENT_VM_DTB)\" \
-DGUEST_INITRD_IMAGE_PATH=\"$(CLIENT_VM_INITRD_OVERLAYED)\" \
-target aarch64-none-elf \
$< -o $@

$(BUILD_DIR)/user_sound/%.o: $(UIO_DRIVERS_DIR)/snd/%.c
mkdir -p $(BUILD_DIR)/user_sound
$(CC_USERLEVEL) -c $(CFLAGS_USERLEVEL) $^ -o $@

$(BUILD_DIR)/user_sound.elf: $(BUILD_DIR)/user_sound/main.o $(BUILD_DIR)/user_sound/stream.o $(BUILD_DIR)/user_sound/queue.o $(BUILD_DIR)/user_sound/convert.o
$(CC_USERLEVEL) $(CFLAGS_USERLEVEL) $^ -o $@
patchelf --set-interpreter /lib64/ld-linux-aarch64.so.1 $@

$(BUILD_DIR)/%.elf: $(VM_USERLEVEL_DIR)/%.c
$(CC_USERLEVEL) $(CFLAGS_USERLEVEL) $^ -o $@
patchelf --set-interpreter /lib64/ld-linux-aarch64.so.1 $@

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

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

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

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

$(BUILD_DIR)/%.o: $(VMM_SRC_DIR)/arch/aarch64/vgic/%.c Makefile
$(CC) -c $(CFLAGS) $< -o $@

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

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

$(BUILD_DIR)/%.o: $(SDDF_SERIAL_COMPONENTS)/%.c Makefile
$(CC) -c $(CFLAGS) -DSERIAL_NUM_CLIENTS=3 -DSERIAL_TRANSFER_WITH_COLOUR=1 $< -o $@

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

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

$(BUILD_DIR)/client_vmm.elf: $(addprefix $(BUILD_DIR)/, $(CLIENT_VMM_OBJS))
$(LD) $(LDFLAGS) $^ $(LIBS) -o $@

$(BUILD_DIR)/sound_virt.elf: $(addprefix $(BUILD_DIR)/, $(SOUND_VIRT_OBJS))
$(LD) $(LDFLAGS) $^ $(LIBS) -o $@

$(BUILD_DIR)/snd_driver_vmm.elf: $(addprefix $(BUILD_DIR)/, $(SND_DRIVER_VMM_OBJS))
$(LD) $(LDFLAGS) $^ $(LIBS) -o $@

$(BUILD_DIR)/serial_virt_tx.elf: $(addprefix $(BUILD_DIR)/, $(SERIAL_VIRT_TX_OBJS))
$(LD) $(LDFLAGS) $^ $(LIBS) -o $@

$(BUILD_DIR)/serial_virt_rx.elf: $(addprefix $(BUILD_DIR)/, $(SERIAL_VIRT_RX_OBJS))
$(LD) $(LDFLAGS) $^ $(LIBS) -o $@

$(BUILD_DIR)/uart_driver.elf: $(addprefix $(BUILD_DIR)/, $(SERIAL_DRIVER_OBJS))
$(LD) $(LDFLAGS) $^ $(LIBS) -o $@


$(IMAGE_FILE) $(REPORT_FILE): $(addprefix $(BUILD_DIR)/, $(ELFS)) $(SYSTEM_DESCRIPTION) $(SND_DRIVER_VM_DIR) $(CLIENT_VM_DIR)
$(MICROKIT_TOOL) $(SYSTEM_DESCRIPTION) --search-path $(BUILD_DIR) $(SND_DRIVER_VM_DIR) $(CLIENT_VM_DIR) --board $(BOARD) --config $(CONFIG) -o $(IMAGE_FILE) -r $(REPORT_FILE)

clean:
rm -rf build
21 changes: 21 additions & 0 deletions examples/virtio-snd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# virtIO sound example

This example shows off the virtIO sound support that libvmm provides using the
[seL4 Device Driver Framework](https://github.com/au-ts/sddf) to virtualise
the hardware.

We do not have a native driver for sound, but instead leverage a Linux VM that
contains a driver and have a user-level program to convert sDDF requests/responses
into Linux calls into the ALSA library.

Currently this example is not integrated with the [virtIO example](../virtio)
due to issues with using multiple driver VMs in the same system. Therefore, temporarily,
we have a separate virtIO example for the emulating the sound device. You can find more
information [in this GitHub issue](https://github.com/au-ts/libvmm/issues/60).

The example currently works on the following platforms:
* QEMU ARM virt
* HardKernel Odroid-C4

For details on the internals of the example and instructions on building and running it,
see [docs/SOUND.md](docs/SOUND.md).
Loading
Loading