From f9c1841d7699ecc04f9ce4499f1c081ae50aa225 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Sat, 20 Jan 2024 10:29:01 +0800 Subject: [PATCH] Clear the interrupt after setting BL808_UART_INT_CLEAR (0x30002028) --- riscv_cpu.c | 11 ++++++----- virtio.c | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/riscv_cpu.c b/riscv_cpu.c index 4c69404..476baca 100644 --- a/riscv_cpu.c +++ b/riscv_cpu.c @@ -496,11 +496,12 @@ int target_write_slow(RISCVCPUState *s, target_ulong addr, print_console(NULL, buf, 1); break; } - // Console Input: Clear the interrupt after setting BL808_UART_INT_CLEAR (0x30002028) - // case 0x30002028: - // break; - + case 0x30002028: { + void virtio_ack_irq(void *device0); + virtio_ack_irq(NULL); + break; + } default: // Unknown Memory-Mapped I/O #ifdef DUMP_INVALID_MEM_ACCESS printf("target_write_slow: invalid physical address 0x"); @@ -1171,7 +1172,7 @@ static void raise_exception(RISCVCPUState *s, uint32_t cause) { printf("raise_exception: cause=%d\n", cause);//// #ifndef EMSCRIPTEN //// - printf("raise_exception: sleep\n"); sleep(4);//// + // printf("raise_exception: sleep\n"); sleep(4);//// #endif //// EMSCRIPTEN raise_exception2(s, cause, 0); } diff --git a/virtio.c b/virtio.c index a586cee..0e9c73a 100644 --- a/virtio.c +++ b/virtio.c @@ -158,6 +158,7 @@ static void virtio_mmio_write(void *opaque, uint32_t offset, static uint32_t virtio_pci_read(void *opaque, uint32_t offset, int size_log2); static void virtio_pci_write(void *opaque, uint32_t offset, uint32_t val, int size_log2); +void virtio_ack_irq(VIRTIODevice *device0); static void virtio_reset(VIRTIODevice *s) { @@ -293,6 +294,7 @@ static void virtio_init(VIRTIODevice *s, VIRTIOBusDef *bus, s->config_space_size = config_space_size; s->device_recv = device_recv; virtio_reset(s); + virtio_ack_irq(s); //// } static uint16_t virtio_read16(VIRTIODevice *s, virtio_phys_addr_t addr) @@ -1337,8 +1339,6 @@ int virtio_console_write_data(VIRTIODevice *s, const uint8_t *buf, int buf_len) s->int_status |= 1; set_irq(s->irq, 1); - // TODO: Clear the interrupt after reading keypress - // set_irq(s->irq, 0); #ifdef NOTUSED int queue_idx = 0; QueueState *qs = &s->queue[queue_idx]; @@ -2678,3 +2678,16 @@ VIRTIODevice *virtio_9p_init(VIRTIOBusDef *bus, FSDevice *fs, return (VIRTIODevice *)s; } +//// Begin Test: Acknowledge VirtIO Interrupt +void virtio_ack_irq(VIRTIODevice *device0) { + static VIRTIODevice *device = NULL; + if (device0 != NULL) { device = device0; return; } + if (device == NULL) { puts("virtio_ack_irq: Missing device"); } + + puts("virtio_ack_irq"); + // device->int_status &= ~val; + // if (device->int_status == 0) { + set_irq(device->irq, 0); + // } +} +//// End Test