vring.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Copyright 2012 Red Hat, Inc. and/or its affiliates
  2. * Copyright IBM, Corp. 2012
  3. *
  4. * Based on Linux 2.6.39 vhost code:
  5. * Copyright (C) 2009 Red Hat, Inc.
  6. * Copyright (C) 2006 Rusty Russell IBM Corporation
  7. *
  8. * Author: Michael S. Tsirkin <mst@redhat.com>
  9. * Stefan Hajnoczi <stefanha@redhat.com>
  10. *
  11. * Inspiration, some code, and most witty comments come from
  12. * Documentation/virtual/lguest/lguest.c, by Rusty Russell
  13. *
  14. * This work is licensed under the terms of the GNU GPL, version 2.
  15. */
  16. #ifndef VRING_H
  17. #define VRING_H
  18. #include <linux/virtio_ring.h>
  19. #include "qemu-common.h"
  20. #include "hw/dataplane/hostmem.h"
  21. #include "hw/virtio.h"
  22. typedef struct {
  23. HostMem hostmem; /* guest memory mapper */
  24. struct vring vr; /* virtqueue vring mapped to host memory */
  25. uint16_t last_avail_idx; /* last processed avail ring index */
  26. uint16_t last_used_idx; /* last processed used ring index */
  27. uint16_t signalled_used; /* EVENT_IDX state */
  28. bool signalled_used_valid;
  29. bool broken; /* was there a fatal error? */
  30. } Vring;
  31. static inline unsigned int vring_get_num(Vring *vring)
  32. {
  33. return vring->vr.num;
  34. }
  35. /* Are there more descriptors available? */
  36. static inline bool vring_more_avail(Vring *vring)
  37. {
  38. return vring->vr.avail->idx != vring->last_avail_idx;
  39. }
  40. /* Fail future vring_pop() and vring_push() calls until reset */
  41. static inline void vring_set_broken(Vring *vring)
  42. {
  43. vring->broken = true;
  44. }
  45. bool vring_setup(Vring *vring, VirtIODevice *vdev, int n);
  46. void vring_teardown(Vring *vring);
  47. void vring_disable_notification(VirtIODevice *vdev, Vring *vring);
  48. bool vring_enable_notification(VirtIODevice *vdev, Vring *vring);
  49. bool vring_should_notify(VirtIODevice *vdev, Vring *vring);
  50. int vring_pop(VirtIODevice *vdev, Vring *vring,
  51. struct iovec iov[], struct iovec *iov_end,
  52. unsigned int *out_num, unsigned int *in_num);
  53. void vring_push(Vring *vring, unsigned int head, int len);
  54. #endif /* VRING_H */