You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

virtio-pci.h 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef _VIRTIO_PCI_H_
  2. # define _VIRTIO_PCI_H_
  3. /* A 32-bit r/o bitmask of the features supported by the host */
  4. #define VIRTIO_PCI_HOST_FEATURES 0
  5. /* A 32-bit r/w bitmask of features activated by the guest */
  6. #define VIRTIO_PCI_GUEST_FEATURES 4
  7. /* A 32-bit r/w PFN for the currently selected queue */
  8. #define VIRTIO_PCI_QUEUE_PFN 8
  9. /* A 16-bit r/o queue size for the currently selected queue */
  10. #define VIRTIO_PCI_QUEUE_NUM 12
  11. /* A 16-bit r/w queue selector */
  12. #define VIRTIO_PCI_QUEUE_SEL 14
  13. /* A 16-bit r/w queue notifier */
  14. #define VIRTIO_PCI_QUEUE_NOTIFY 16
  15. /* An 8-bit device status register. */
  16. #define VIRTIO_PCI_STATUS 18
  17. /* An 8-bit r/o interrupt status register. Reading the value will return the
  18. * current contents of the ISR and will also clear it. This is effectively
  19. * a read-and-acknowledge. */
  20. #define VIRTIO_PCI_ISR 19
  21. /* The bit of the ISR which indicates a device configuration change. */
  22. #define VIRTIO_PCI_ISR_CONFIG 0x2
  23. /* The remaining space is defined by each driver as the per-driver
  24. * configuration space */
  25. #define VIRTIO_PCI_CONFIG 20
  26. /* Virtio ABI version, this must match exactly */
  27. #define VIRTIO_PCI_ABI_VERSION 0
  28. static inline u32 vp_get_features(unsigned int ioaddr)
  29. {
  30. return inl(ioaddr + VIRTIO_PCI_HOST_FEATURES);
  31. }
  32. static inline void vp_set_features(unsigned int ioaddr, u32 features)
  33. {
  34. outl(features, ioaddr + VIRTIO_PCI_GUEST_FEATURES);
  35. }
  36. static inline void vp_get(unsigned int ioaddr, unsigned offset,
  37. void *buf, unsigned len)
  38. {
  39. u8 *ptr = buf;
  40. unsigned i;
  41. for (i = 0; i < len; i++)
  42. ptr[i] = inb(ioaddr + VIRTIO_PCI_CONFIG + offset + i);
  43. }
  44. static inline u8 vp_get_status(unsigned int ioaddr)
  45. {
  46. return inb(ioaddr + VIRTIO_PCI_STATUS);
  47. }
  48. static inline void vp_set_status(unsigned int ioaddr, u8 status)
  49. {
  50. if (status == 0) /* reset */
  51. return;
  52. outb(status, ioaddr + VIRTIO_PCI_STATUS);
  53. }
  54. static inline u8 vp_get_isr(unsigned int ioaddr)
  55. {
  56. return inb(ioaddr + VIRTIO_PCI_ISR);
  57. }
  58. static inline void vp_reset(unsigned int ioaddr)
  59. {
  60. outb(0, ioaddr + VIRTIO_PCI_STATUS);
  61. (void)inb(ioaddr + VIRTIO_PCI_ISR);
  62. }
  63. static inline void vp_notify(unsigned int ioaddr, int queue_index)
  64. {
  65. outw(queue_index, ioaddr + VIRTIO_PCI_QUEUE_NOTIFY);
  66. }
  67. static inline void vp_del_vq(unsigned int ioaddr, int queue_index)
  68. {
  69. /* select the queue */
  70. outw(queue_index, ioaddr + VIRTIO_PCI_QUEUE_SEL);
  71. /* deactivate the queue */
  72. outl(0, ioaddr + VIRTIO_PCI_QUEUE_PFN);
  73. }
  74. int vp_find_vq(unsigned int ioaddr, int queue_index,
  75. struct vring_virtqueue *vq);
  76. #endif /* _VIRTIO_PCI_H_ */