2222#include <uapi/sound/sof-ipc.h>
2323#include <uapi/sound/sof-fw.h>
2424#include <uapi/sound/asoc.h>
25+ #include <uapi/sound/sof-virtio.h>
2526#include <sound/hdaudio.h>
2627#include <sound/compress_driver.h>
2728
5455#define SOF_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \
5556 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_FLOAT)
5657
58+ /* The maximum number of components a virtio guest vFE driver can use */
59+ #define SOF_VIRTIO_MAX_GOS_COMPS 1000
60+
61+ #define SOF_VIRTIO_COMP_ID_UNASSIGNED 0xffffffff
62+
5763struct snd_sof_dev ;
5864struct snd_sof_ipc_msg ;
5965struct snd_sof_ipc ;
@@ -62,6 +68,8 @@ struct snd_soc_tplg_ops;
6268struct snd_soc_component ;
6369struct sof_intel_hda_dev ;
6470struct snd_sof_pdata ;
71+ struct virtio_device ;
72+ struct virtqueue ;
6573
6674/*
6775 * SOF DSP HW abstraction operations.
@@ -290,6 +298,47 @@ struct snd_sof_dai {
290298 struct list_head list ; /* list in sdev dai list */
291299};
292300
301+ /*
302+ * in virtio iovec array:
303+ * iovec[0]: the ipc message data between vFE and vBE
304+ * iovec[1]: the ipc reply data between vFE and vBE
305+ */
306+ #define SOF_VIRTIO_IPC_MSG 0
307+ #define SOF_VIRTIO_IPC_REPLY 1
308+
309+ /* Virtio Frontend */
310+ struct sof_vfe {
311+ struct sof_virtio_priv * priv ;
312+ struct snd_sof_dev * sdev ;
313+
314+ /* IPC cmd from frontend to backend */
315+ struct virtqueue * ipc_cmd_tx_vq ;
316+
317+ /* IPC cmd reply from backend to frontend */
318+ struct virtqueue * ipc_cmd_rx_vq ;
319+
320+ /* IPC notification from backend to frontend */
321+ struct virtqueue * ipc_not_rx_vq ;
322+
323+ /* IPC notification reply from frontend to backend */
324+ struct virtqueue * ipc_not_tx_vq ;
325+
326+ /* position update work */
327+ struct work_struct posn_update_work ;
328+
329+ /* current pending cmd message */
330+ struct snd_sof_ipc_msg * msg ;
331+
332+ /* current and pending notification */
333+ struct snd_sof_ipc_msg * not ;
334+ struct sof_ipc_stream_posn * posn ;
335+ };
336+
337+ struct vbs_sof_posn {
338+ struct list_head list ;
339+ struct sof_ipc_stream_posn pos ;
340+ };
341+
293342/*
294343 * SOF Device Level.
295344 */
@@ -302,6 +351,7 @@ struct snd_sof_dev {
302351
303352 /* ASoC components */
304353 struct snd_soc_component_driver plat_drv ;
354+ struct snd_soc_card * card ;
305355
306356 /* DSP firmware boot */
307357 wait_queue_head_t boot_wait ;
@@ -358,6 +408,11 @@ struct snd_sof_dev {
358408 wait_queue_head_t waitq ;
359409 int code_loading ;
360410
411+ /* virtio for BE and FE */
412+ struct list_head vbe_list ;
413+ struct sof_vfe * vfe ;
414+ int is_vfe ;
415+
361416 /* DMA for Trace */
362417 struct snd_dma_buffer dmatb ;
363418 struct snd_dma_buffer dmatp ;
@@ -377,6 +432,29 @@ struct snd_sof_dev {
377432#define sof_to_bus (s ) (&(s)->hda->hbus.core)
378433#define sof_to_hbus (s ) (&(s)->hda->hbus)
379434
435+ #if IS_ENABLED (CONFIG_SND_SOC_SOF_VIRTIO_BE )
436+ int sof_virtio_miscdev_register (struct snd_sof_dev * sdev );
437+ int sof_virtio_miscdev_unregister (void );
438+ int sof_vbe_update_guest_posn (struct snd_sof_dev * sdev ,
439+ struct sof_ipc_stream_posn * posn );
440+ #else
441+ static inline int sof_virtio_miscdev_register (struct snd_sof_dev * sdev )
442+ {
443+ return 0 ;
444+ }
445+
446+ static inline int sof_virtio_miscdev_unregister (void )
447+ {
448+ return 0 ;
449+ }
450+
451+ static inline int sof_vbe_update_guest_posn (struct snd_sof_dev * sdev ,
452+ struct sof_ipc_stream_posn * posn )
453+ {
454+ return 0 ;
455+ }
456+ #endif
457+
380458/*
381459 * SOF platform private struct used as drvdata of
382460 * platform dev (e.g. pci/acpi/spi...) drvdata.
@@ -494,10 +572,26 @@ int snd_sof_get_status(struct snd_sof_dev *sdev, u32 panic_code,
494572 void * stack , size_t stack_size );
495573int snd_sof_init_trace_ipc (struct snd_sof_dev * sdev );
496574
575+ /*
576+ * VirtIO
577+ */
578+ int sof_virtio_submit_guest_ipc (struct snd_sof_dev * sdev , int vm_id ,
579+ void * ipc_buf , void * reply_buf ,
580+ size_t count , size_t reply_sz );
581+ int snd_sof_virtio_fs_init (struct snd_sof_dev * sdev );
582+ int snd_sof_virtio_fs_release (void );
583+ int sof_virtio_update_guest_posn (void * ctx , struct sof_ipc_stream_posn * posn );
584+ int sof_virtio_try_update_guest_posn (struct snd_sof_dev * sdev ,
585+ struct sof_ipc_stream_posn * posn );
586+ void sof_virtio_set_spcm_posn_offset (struct snd_sof_pcm * spcm , int direction );
587+ int sof_virtio_register_guest (void * ctx );
588+ int sof_virtio_release_guest (int id );
589+
497590/*
498591 * Platform specific ops.
499592 */
500593extern struct snd_compr_ops sof_compressed_ops ;
594+ extern struct snd_sof_dsp_ops snd_sof_virtio_fe_ops ;
501595
502596/*
503597 * Kcontrols.
0 commit comments