Skip to content

Commit

Permalink
start virtio-snd
Browse files Browse the repository at this point in the history
  • Loading branch information
cleverca22 committed May 16, 2024
1 parent e56e790 commit 95e10ea
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 9 deletions.
3 changes: 2 additions & 1 deletion mini-rv32ima/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mini-rv32ima : mini-rv32ima.c mini-rv32ima.h default64mbdtc.h

CFLAGS := -ffunction-sections -fdata-sections -Wall -Wstrict-prototypes -DCNFG_WINDOWS_DISABLE_BATCH
LIBS := -lfdt
SRCS := plic.c virtio.c full-rv32ima.c mmio.c pl011.c stdio.c
SRCS := plic.c virtio.c full-rv32ima.c mmio.c pl011.c stdio.c virtio-snd.c
ifeq ($(BLOCK),1)
SRCS += virtio-blk.c
CFLAGS += -DWITH_BLOCK
Expand Down Expand Up @@ -59,6 +59,7 @@ plic.o: plic.c plic.h
full-rv32ima.o: full-rv32ima.c default64mbdtc.h rawdraw_sf.h virtio.h plic.h mmio.h pl011.h stdio.h mini-rv32ima.h
pl011.o: pl011.c pl011.h plic.h mmio.h stdio.h
stdio.o: stdio.c stdio.h
virtio-snd.o: virtio-snd.c virtio.h plic.h

amalgamation.c: $(SRCS)
cat $(SRCS) > $@
Expand Down
6 changes: 6 additions & 0 deletions mini-rv32ima/full-rv32ima.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ void patch_dtb(uint32_t dtb_ptr, bool enable_gfx, void **fb_virt_ptr, bool enabl
mmio_add_handler(virtio_input_mouse->reg_base, virtio_input_mouse->reg_size, virtio_mmio_load, virtio_mmio_store, virtio_input_mouse, "virtio-input mouse");
}
#endif
{
uint32_t base = get_next_base(0x1000);
struct virtio_device *virtio_snd = virtio_snd_create(ram_image, base);
virtio_add_dtb(virtio_snd, v_fdt);
mmio_add_handler(virtio_snd->reg_base, virtio_snd->reg_size, virtio_mmio_load, virtio_mmio_store, virtio_snd, "virtio-snd");
}

int chosen = fdt_path_offset(v_fdt, "/chosen");
if (chosen < 0) {
Expand Down
2 changes: 1 addition & 1 deletion mini-rv32ima/virtio-blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static void virtio_blk_process_command(struct virtio_device *dev, struct virtio_
virtio_flag_completion(dev, queue, start_idx, written);
}

const virtio_device_type virtio_blk_type = {
static const virtio_device_type virtio_blk_type = {
.device_type = 2,
.queue_count = 1,
.config_load = virtio_blk_config_load,
Expand Down
2 changes: 1 addition & 1 deletion mini-rv32ima/virtio-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void HandleButton( int x, int y, int button, int bDown ) {
send_event(ctx, EV_SYN, 0, 0);
}

const virtio_device_type virtio_input_type = {
static const virtio_device_type virtio_input_type = {
.device_type = 18,
.queue_count = 2,
.config_load = virtio_input_config_load,
Expand Down
29 changes: 29 additions & 0 deletions mini-rv32ima/virtio-snd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
#include "virtio.h"
#include "plic.h"

static uint32_t virtio_snd_config_load(struct virtio_device *dev, uint32_t offset) {
uint32_t ret = 0;
printf("virtio_snd_config_load(%p, %d) == 0x%x\n", dev, offset, ret);
return ret;
}

static void virtio_snd_config_store(struct virtio_device *dev, uint32_t offset, uint32_t val) {
printf("virtio_snd_config_store(%p, %d, %d)\n", dev, offset, val);
}

static void virtio_snd_process_command(struct virtio_device *dev, struct virtio_desc_internal *chain, int chain_length, int queue, uint16_t start_idx) {
printf("virtio_snd_process_command(%p, %p, %d, %d, %d)\n", dev, chain, chain_length, queue, start_idx);
}

static const virtio_device_type virtio_snd_type = {
.device_type = 25,
.queue_count = 4,
.config_load = virtio_snd_config_load,
.config_store = virtio_snd_config_store,
.process_command = virtio_snd_process_command,
};

struct virtio_device *virtio_snd_create(void *ram_image, uint32_t base) {
return virtio_create(ram_image, &virtio_snd_type, base, 0x200, get_next_irq());
}
14 changes: 11 additions & 3 deletions mini-rv32ima/virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,16 @@ void virtio_mmio_store(void *state, uint32_t offset, uint32_t val) {
break;
case 0x30:
dev->QueueSel = val;
printf("QueueSel = %d\n", val);
printf("virtio%d QueueSel = %d\n", dev->index, val);
break;
case 0x38:
dev->queues[dev->QueueSel].QueueNum = val;
printf("QueueNum[%d.%d] = %d\n", dev->index, dev->QueueSel, val);
printf("virtio%d QueueNum[%d] = %d\n", dev->index, dev->QueueSel, val);
break;
case 0x44:
dev->queues[dev->QueueSel].QueueReady = val;
if (val == 1) {
printf("virtio%d_queue%d has become ready\n", dev->index, dev->QueueSel);
printf("virtio%d Queue[%d] has become ready\n", dev->index, dev->QueueSel);
}
break;
case 0x50: // QueueNotify
Expand Down Expand Up @@ -285,14 +285,22 @@ uint32_t virtio_mmio_load(void *state, uint32_t offset) {
}
break;
case 0x34: // QueueNumMax
// TODO, delegate this to the type
switch (dev->QueueSel) {
case 0:
ret = 4096;
break;
case 1:
ret = 64;
break;
case 2:
ret = 4096;
break;
case 3:
ret = 4096;
break;
}
printf("virtio%d QueueNumMax[%d] = %d\n", dev->index, dev->QueueSel, ret);
break;
case 0x44:
ret = dev->queues[dev->QueueSel].QueueReady;
Expand Down
4 changes: 1 addition & 3 deletions mini-rv32ima/virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,5 @@ void virtio_flag_completion(struct virtio_device *dev, int queue, uint16_t start
void virtio_config_changed(struct virtio_device *dev);
struct virtio_device *virtio_input_create(void *ram_image, uint32_t base, bool mouse);
struct virtio_device *virtio_blk_create(void *ram_image, uint32_t base);
struct virtio_device *virtio_snd_create(void *ram_image, uint32_t base);
void virtio_add_dtb(struct virtio_device*, void *v_fdt);

extern const virtio_device_type virtio_blk_type;
extern const virtio_device_type virtio_input_type;

0 comments on commit 95e10ea

Please sign in to comment.