選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

virtio-pci.h 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 void vp_reset(unsigned int ioaddr)
  55. {
  56. outb(0, ioaddr + VIRTIO_PCI_STATUS);
  57. (void)inb(ioaddr + VIRTIO_PCI_ISR);
  58. }
  59. static inline void vp_notify(unsigned int ioaddr, int queue_index)
  60. {
  61. outw(queue_index, ioaddr + VIRTIO_PCI_QUEUE_NOTIFY);
  62. }
  63. static inline void vp_del_vq(unsigned int ioaddr, int queue_index)
  64. {
  65. /* select the queue */
  66. outw(queue_index, ioaddr + VIRTIO_PCI_QUEUE_SEL);
  67. /* deactivate the queue */
  68. outl(0, ioaddr + VIRTIO_PCI_QUEUE_PFN);
  69. }
  70. int vp_find_vq(unsigned int ioaddr, int queue_index,
  71. struct vring_virtqueue *vq);
  72. #endif /* _VIRTIO_PCI_H_ */