hab_virtio.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __HAB_VIRTIO_H
  7. #define __HAB_VIRTIO_H
  8. #include "hab.h"
  9. enum {
  10. HAB_PCHAN_TX_VQ = 0, /* receive data from gvm */
  11. HAB_PCHAN_RX_VQ, /* send data to gvm */
  12. HAB_PCHAN_VQ_MAX,
  13. };
  14. /* cross link between probe and comm-dev-alloc */
  15. struct vq_pchan {
  16. uint32_t mmid;
  17. struct physical_channel *pchan;
  18. struct virtio_hab *vhab;
  19. unsigned int index[HAB_PCHAN_VQ_MAX]; /* vring index */
  20. struct virtqueue *vq[HAB_PCHAN_VQ_MAX];
  21. spinlock_t lock[HAB_PCHAN_VQ_MAX]; /* per pchan lock */
  22. wait_queue_head_t out_wq;
  23. struct tasklet_struct task; /* for rxq only */
  24. void *s_pool;
  25. struct list_head s_list; /* small buffer available out list */
  26. int s_cnt;
  27. void *m_pool;
  28. struct list_head m_list; /* medium buffer available out list */
  29. int m_cnt;
  30. void *l_pool;
  31. struct list_head l_list; /* large buffer available out list */
  32. int l_cnt;
  33. void *in_pool;
  34. struct list_head in_list; /* only used for init then stored in vqs */
  35. int in_cnt;
  36. void *read_data; /* recved buf should be one of the in bufs */
  37. size_t read_size;
  38. int read_offset;
  39. bool pchan_ready;
  40. };
  41. typedef void (*vq_callback)(struct virtqueue *);
  42. struct virtio_hab {
  43. struct virtio_device *vdev; /* the actual virtio device probed */
  44. uint32_t mmid_start; /* starting mmid for this virthab */
  45. int mmid_range; /* total mmid used in this virthab, it might cross mmid groups */
  46. /* in case vqs are not start from zero to support all the needs of one
  47. * virtio device, and it always starts after "other" vqs
  48. */
  49. int vqs_offset;
  50. struct virtqueue **vqs; /* holds total # of vqs for all the pchans. 2 vqs per pchan */
  51. vq_callback_t **cbs; /* each vqs callback */
  52. char **names; /* each vqs' names */
  53. struct vq_pchan *vqpchans; /* total # of pchans */
  54. spinlock_t mlock; /* master lock for all the pchans */
  55. bool ready; /* overall device ready flag */
  56. struct list_head node; /* list of all probed virtio hab */
  57. };
  58. /*
  59. * this commdev has two parts, the pchan for hab driver created in commdev alloc,
  60. * and, virtio dev and vqs created during virtio probe.
  61. * commdev might happen earlier than virtio probe
  62. * one kind of hab driver for one kind of virtio device. within this one pair
  63. * there is one list/array of pchans/commdevs
  64. */
  65. struct virtio_pchan_link {
  66. uint32_t mmid;
  67. struct physical_channel *pchan; /* link back to hab driver */
  68. struct vq_pchan *vpc; /* link back to the virtio probe result */
  69. struct virtio_hab *vhab; /* this is initialized during virtio probe */
  70. };
  71. #ifdef CONFIG_MSM_VIRTIO_HAB
  72. int virthab_queue_inbufs(struct virtio_hab *vh, int alloc);
  73. int virthab_alloc(struct virtio_device *vdev, struct virtio_hab **pvh,
  74. uint32_t mmid_start, int mmid_range);
  75. int virthab_init_vqs_pre(struct virtio_hab *vh);
  76. int virthab_init_vqs_post(struct virtio_hab *vh);
  77. struct virtio_device *virthab_get_vdev(int32_t mmid);
  78. #else
  79. int virthab_queue_inbufs(struct virtio_hab *vh, int alloc)
  80. {
  81. return -ENODEV;
  82. }
  83. int virthab_alloc(struct virtio_device *vdev, struct virtio_hab **pvh,
  84. uint32_t mmid_start, int mmid_range)
  85. {
  86. return -ENODEV;
  87. }
  88. int virthab_init_vqs_pre(struct virtio_hab *vh)
  89. {
  90. return -ENODEV;
  91. }
  92. int virthab_init_vqs_post(struct virtio_hab *vh)
  93. {
  94. return -ENODEV;
  95. }
  96. struct virtio_device *virthab_get_vdev(int32_t mmid)
  97. {
  98. return NULL;
  99. }
  100. #endif
  101. #endif /* __HAB_VIRTIO_H */