virtio.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-9-16 GuEe-GUI the first version
  9. */
  10. #ifndef VIRTIO_H__
  11. #define VIRTIO_H__
  12. #include <stdint.h>
  13. #define PAGE_SIZE 4096
  14. #define PAGE_SHIFT 12
  15. #define VIRTIO_STAT_ACKNOWLEDGE 1
  16. #define VIRTIO_STAT_DRIVER 2
  17. #define VIRTIO_STAT_DRIVER_OK 4
  18. #define VIRTIO_STAT_FEATURES_OK 8
  19. #define VIRTIO_STAT_NEEDS_RESET 64
  20. #define VIRTIO_STAT_FAILED 128
  21. #define QUEUE_SIZE 8
  22. struct virtq_desc
  23. {
  24. uint64_t addr;
  25. uint32_t len;
  26. uint16_t flags;
  27. uint16_t next;
  28. };
  29. #define VRING_DESC_F_NEXT 1 // chained with another descriptor
  30. #define VRING_DESC_F_WRITE 2 // device writes (vs read)
  31. struct virtq_avail
  32. {
  33. uint16_t flags; // always zero
  34. uint16_t idx; // driver will write ring[idx] next
  35. uint16_t ring[QUEUE_SIZE]; // descriptor numbers of chain heads
  36. uint16_t unused;
  37. };
  38. struct virtq_used_elem
  39. {
  40. uint32_t id; // index of start of completed descriptor chain
  41. uint32_t len;
  42. };
  43. struct virtq_used
  44. {
  45. uint16_t flags; // always zero
  46. uint16_t idx; // device increments when it adds a ring[] entry
  47. struct virtq_used_elem ring[QUEUE_SIZE];
  48. };
  49. #endif /* VIRTIO_H__ */