virtio.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef LINUX_VIRTIO_H
  2. #define LINUX_VIRTIO_H
  3. #include <linux/scatterlist.h>
  4. #include <linux/kernel.h>
  5. /* TODO: empty stubs for now. Broken but enough for virtio_ring.c */
  6. #define list_add_tail(a, b) do {} while (0)
  7. #define list_del(a) do {} while (0)
  8. #define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
  9. #define BITS_PER_BYTE 8
  10. #define BITS_PER_LONG (sizeof(long) * BITS_PER_BYTE)
  11. #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
  12. /* TODO: Not atomic as it should be:
  13. * we don't use this for anything important. */
  14. static inline void clear_bit(int nr, volatile unsigned long *addr)
  15. {
  16. unsigned long mask = BIT_MASK(nr);
  17. unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
  18. *p &= ~mask;
  19. }
  20. static inline int test_bit(int nr, const volatile unsigned long *addr)
  21. {
  22. return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
  23. }
  24. /* end of stubs */
  25. struct virtio_device {
  26. void *dev;
  27. unsigned long features[1];
  28. };
  29. struct virtqueue {
  30. /* TODO: commented as list macros are empty stubs for now.
  31. * Broken but enough for virtio_ring.c
  32. * struct list_head list; */
  33. void (*callback)(struct virtqueue *vq);
  34. const char *name;
  35. struct virtio_device *vdev;
  36. unsigned int index;
  37. unsigned int num_free;
  38. void *priv;
  39. };
  40. #define MODULE_LICENSE(__MODULE_LICENSE_value) \
  41. const char *__MODULE_LICENSE_name = __MODULE_LICENSE_value
  42. /* Interfaces exported by virtio_ring. */
  43. int virtqueue_add_buf(struct virtqueue *vq,
  44. struct scatterlist sg[],
  45. unsigned int out_num,
  46. unsigned int in_num,
  47. void *data,
  48. gfp_t gfp);
  49. void virtqueue_kick(struct virtqueue *vq);
  50. void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len);
  51. void virtqueue_disable_cb(struct virtqueue *vq);
  52. bool virtqueue_enable_cb(struct virtqueue *vq);
  53. bool virtqueue_enable_cb_delayed(struct virtqueue *vq);
  54. void *virtqueue_detach_unused_buf(struct virtqueue *vq);
  55. struct virtqueue *vring_new_virtqueue(unsigned int index,
  56. unsigned int num,
  57. unsigned int vring_align,
  58. struct virtio_device *vdev,
  59. bool weak_barriers,
  60. void *pages,
  61. void (*notify)(struct virtqueue *vq),
  62. void (*callback)(struct virtqueue *vq),
  63. const char *name);
  64. void vring_del_virtqueue(struct virtqueue *vq);
  65. #endif