virtio_config.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef _LINUX_VIRTIO_CONFIG_H
  2. #define _LINUX_VIRTIO_CONFIG_H
  3. /* Virtio devices use a standardized configuration space to define their
  4. * features and pass configuration information, but each implementation can
  5. * store and access that space differently. */
  6. #include <linux/types.h>
  7. /* Status byte for guest to report progress, and synchronize features. */
  8. /* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */
  9. #define VIRTIO_CONFIG_S_ACKNOWLEDGE 1
  10. /* We have found a driver for the device. */
  11. #define VIRTIO_CONFIG_S_DRIVER 2
  12. /* Driver has used its parts of the config, and is happy */
  13. #define VIRTIO_CONFIG_S_DRIVER_OK 4
  14. /* We've given up on this device. */
  15. #define VIRTIO_CONFIG_S_FAILED 0x80
  16. #ifdef __KERNEL__
  17. #include <linux/virtio.h>
  18. /**
  19. * virtio_config_ops - operations for configuring a virtio device
  20. * @feature: search for a feature in this config
  21. * vdev: the virtio_device
  22. * bit: the feature bit
  23. * Returns true if the feature is supported. Acknowledges the feature
  24. * so the host can see it.
  25. * @get: read the value of a configuration field
  26. * vdev: the virtio_device
  27. * offset: the offset of the configuration field
  28. * buf: the buffer to write the field value into.
  29. * len: the length of the buffer
  30. * @set: write the value of a configuration field
  31. * vdev: the virtio_device
  32. * offset: the offset of the configuration field
  33. * buf: the buffer to read the field value from.
  34. * len: the length of the buffer
  35. * @get_status: read the status byte
  36. * vdev: the virtio_device
  37. * Returns the status byte
  38. * @set_status: write the status byte
  39. * vdev: the virtio_device
  40. * status: the new status byte
  41. * @reset: reset the device
  42. * vdev: the virtio device
  43. * After this, status and feature negotiation must be done again
  44. * @find_vq: find a virtqueue and instantiate it.
  45. * vdev: the virtio_device
  46. * index: the 0-based virtqueue number in case there's more than one.
  47. * callback: the virqtueue callback
  48. * Returns the new virtqueue or ERR_PTR() (eg. -ENOENT).
  49. * @del_vq: free a virtqueue found by find_vq().
  50. */
  51. struct virtio_config_ops
  52. {
  53. bool (*feature)(struct virtio_device *vdev, unsigned bit);
  54. void (*get)(struct virtio_device *vdev, unsigned offset,
  55. void *buf, unsigned len);
  56. void (*set)(struct virtio_device *vdev, unsigned offset,
  57. const void *buf, unsigned len);
  58. u8 (*get_status)(struct virtio_device *vdev);
  59. void (*set_status)(struct virtio_device *vdev, u8 status);
  60. void (*reset)(struct virtio_device *vdev);
  61. struct virtqueue *(*find_vq)(struct virtio_device *vdev,
  62. unsigned index,
  63. void (*callback)(struct virtqueue *));
  64. void (*del_vq)(struct virtqueue *vq);
  65. };
  66. /**
  67. * virtio_config_val - look for a feature and get a virtio config entry.
  68. * @vdev: the virtio device
  69. * @fbit: the feature bit
  70. * @offset: the type to search for.
  71. * @val: a pointer to the value to fill in.
  72. *
  73. * The return value is -ENOENT if the feature doesn't exist. Otherwise
  74. * the config value is copied into whatever is pointed to by v. */
  75. #define virtio_config_val(vdev, fbit, offset, v) \
  76. virtio_config_buf((vdev), (fbit), (offset), (v), sizeof(v))
  77. static inline int virtio_config_buf(struct virtio_device *vdev,
  78. unsigned int fbit,
  79. unsigned int offset,
  80. void *buf, unsigned len)
  81. {
  82. if (!vdev->config->feature(vdev, fbit))
  83. return -ENOENT;
  84. vdev->config->get(vdev, offset, buf, len);
  85. return 0;
  86. }
  87. #endif /* __KERNEL__ */
  88. #endif /* _LINUX_VIRTIO_CONFIG_H */