Skip to content

Implement VirtIO GPU and input devices #34

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

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: |
brew install make dtc expect e2fsprogs
- name: default build
run: make
run: make ENABLE_SDL=0
shell: bash
- name: automated test
run: .ci/autorun.sh
Expand Down
59 changes: 59 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include mk/common.mk
CC ?= gcc
CFLAGS := -O2 -g -Wall -Wextra
CFLAGS += -include common.h
LDFLAGS :=

# clock frequency
CLOCK_FREQ ?= 65000000
Expand All @@ -13,6 +14,8 @@ OBJS_EXTRA :=
# command line option
OPTS :=

LDFLAGS += -lpthread

# virtio-blk
ENABLE_VIRTIOBLK ?= 1
$(call set-feature, VIRTIOBLK)
Expand Down Expand Up @@ -50,6 +53,62 @@ ifeq ($(call has, VIRTIONET), 1)
OBJS_EXTRA += netdev.o
endif

# virtio-input
ENABLE_VIRTIOINPUT ?= 1
ifneq ($(UNAME_S),Linux)
ENABLE_VIRTIOINPUT := 0
endif
$(call set-feature, VIRTIOINPUT)
ifeq ($(call has, VIRTIOINPUT), 1)
OBJS_EXTRA += virtio-input.o
endif

# virtio-gpu and virgl
ENABLE_VIRTIOGPU ?= 1
ENABLE_VIRGL ?= 1

# SDL2
ENABLE_SDL ?= 1
ifeq (, $(shell which sdl2-config))
$(warning No sdl2-config in $$PATH. Check SDL2 installation in advance)
override ENABLE_SDL := 0
endif
ifeq ($(ENABLE_SDL),1)
CFLAGS += $(shell sdl2-config --cflags)
LDFLAGS += $(shell sdl2-config --libs)
else
# Disable virtio-gpu and virgl if SDL is not set
override ENABLE_VIRTIOGPU := 0
override ENABLE_VIRGL := 0
endif

# virtio-gpu
ifneq ($(UNAME_S),Linux)
ENABLE_VIRTIOGPU := 0
endif
ifeq ($(ENABLE_VIRTIOGPU),1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you check ENABLE_SDL here?

OBJS_EXTRA += window-events.o
OBJS_EXTRA += virtio-gpu.o
else
override ENABLE_VIRGL := 0
endif

# VirGL
ifeq ($(ENABLE_VIRGL),1)
CFLAGS += $(shell pkg-config virglrenderer gl egl epoxy --cflags)
LDFLAGS += $(shell pkg-config virglrenderer gl egl epoxy --libs)
OBJS_EXTRA += virgl.o
OBJS_EXTRA += window-gl.o
else
ifeq ($(ENABLE_VIRTIOGPU),1)
OBJS_EXTRA += virtio-gpu-sw.o
OBJS_EXTRA += window-sw.o
endif
endif

$(call set-feature, VIRTIOGPU)
$(call set-feature, VIRGL)

BIN = semu
all: $(BIN) minimal.dtb

Expand Down
17 changes: 17 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#pragma once

#include <stddef.h>
#include <stdint.h>
#include <sys/uio.h>

#include "feature.h"

#define BITS_PER_CHAR 8
#define BITS_PER_LONG (BITS_PER_CHAR * sizeof(long))

#define unlikely(x) __builtin_expect((x), 0)
#define likely(x) __builtin_expect((x), 1)

Expand All @@ -17,6 +24,16 @@ static inline int ilog2(int x)
return 31 - __builtin_clz(x | 1);
}

static inline void set_bit(unsigned long bit, unsigned long *word)
{
*word |= (1 << bit);
}

static inline void bitmap_set_bit(unsigned long *map, unsigned long bit)
{
set_bit(bit % BITS_PER_LONG, &map[bit / BITS_PER_LONG]);
}

/* Range check
* For any variable range checking:
* if (x >= minx && x <= maxx) ...
Expand Down
Loading