@@ -100,6 +100,18 @@ static void emu_update_swi_interrupt(hart_t *hart)
100100 aclint_sswi_update_interrupts (hart , & data -> sswi );
101101}
102102
103+ #if SEMU_HAS (VIRTIOSND )
104+ static void emu_update_vsnd_interrupts (vm_t * vm )
105+ {
106+ emu_state_t * data = PRIV (vm -> hart [0 ]);
107+ if (data -> vsnd .InterruptStatus )
108+ data -> plic .active |= IRQ_VSND_BIT ;
109+ else
110+ data -> plic .active &= ~IRQ_VSND_BIT ;
111+ plic_update_interrupts (vm , & data -> plic );
112+ }
113+ #endif
114+
103115static void mem_load (hart_t * hart ,
104116 uint32_t addr ,
105117 uint8_t width ,
@@ -155,6 +167,13 @@ static void mem_load(hart_t *hart,
155167 emu_update_vrng_interrupts (hart -> vm );
156168 return ;
157169#endif
170+
171+ #if SEMU_HAS (VIRTIOSND )
172+ case 0x47 : /* virtio-snd */
173+ virtio_snd_read (hart , & data -> vsnd , addr & 0xFFFFF , width , value );
174+ emu_update_vsnd_interrupts (hart -> vm );
175+ return ;
176+ #endif
158177 }
159178 }
160179 vm_set_exception (hart , RV_EXC_LOAD_FAULT , hart -> exc_val );
@@ -209,12 +228,20 @@ static void mem_store(hart_t *hart,
209228 aclint_sswi_write (hart , & data -> sswi , addr & 0xFFFFF , width , value );
210229 aclint_sswi_update_interrupts (hart , & data -> sswi );
211230 return ;
231+
212232#if SEMU_HAS (VIRTIORNG )
213233 case 0x46 : /* virtio-rng */
214234 virtio_rng_write (hart , & data -> vrng , addr & 0xFFFFF , width , value );
215235 emu_update_vrng_interrupts (hart -> vm );
216236 return ;
217237#endif
238+
239+ #if SEMU_HAS (VIRTIOSND )
240+ case 0x47 : /* virtio-snd */
241+ virtio_snd_write (hart , & data -> vsnd , addr & 0xFFFFF , width , value );
242+ emu_update_vsnd_interrupts (hart -> vm );
243+ return ;
244+ #endif
218245 }
219246 }
220247 vm_set_exception (hart , RV_EXC_STORE_FAULT , hart -> exc_val );
@@ -651,6 +678,11 @@ static int semu_start(int argc, char **argv)
651678 emu .mtimer .mtimecmp = calloc (vm .n_hart , sizeof (uint64_t ));
652679 emu .mswi .msip = calloc (vm .n_hart , sizeof (uint32_t ));
653680 emu .sswi .ssip = calloc (vm .n_hart , sizeof (uint32_t ));
681+ #if SEMU_HAS (VIRTIOSND )
682+ if (!virtio_snd_init (& (emu .vsnd )))
683+ fprintf (stderr , "No virtio-snd functioned\n" );
684+ emu .vsnd .ram = emu .ram ;
685+ #endif
654686
655687 /* Emulate */
656688 uint32_t peripheral_update_ctr = 0 ;
@@ -676,6 +708,11 @@ static int semu_start(int argc, char **argv)
676708 if (emu .vblk .InterruptStatus )
677709 emu_update_vblk_interrupts (& vm );
678710#endif
711+
712+ #if SEMU_HAS (VIRTIOSND )
713+ if (emu .vsnd .InterruptStatus )
714+ emu_update_vsnd_interrupts (& vm );
715+ #endif
679716 }
680717
681718 emu_update_timer_interrupt (vm .hart [i ]);
0 commit comments