vop_bus.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Intel MIC Platform Software Stack (MPSS)
  3. *
  4. * Copyright(c) 2016 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License, version 2, as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * The full GNU General Public License is included in this distribution in
  16. * the file called "COPYING".
  17. *
  18. * Intel Virtio over PCIe Bus driver.
  19. */
  20. #ifndef _VOP_BUS_H_
  21. #define _VOP_BUS_H_
  22. /*
  23. * Everything a vop driver needs to work with any particular vop
  24. * implementation.
  25. */
  26. #include <linux/dmaengine.h>
  27. #include <linux/interrupt.h>
  28. #include "../common/mic_dev.h"
  29. struct vop_device_id {
  30. u32 device;
  31. u32 vendor;
  32. };
  33. #define VOP_DEV_TRNSP 1
  34. #define VOP_DEV_ANY_ID 0xffffffff
  35. /*
  36. * Size of the internal buffer used during DMA's as an intermediate buffer
  37. * for copy to/from user. Must be an integral number of pages.
  38. */
  39. #define VOP_INT_DMA_BUF_SIZE PAGE_ALIGN(64 * 1024ULL)
  40. /**
  41. * vop_device - representation of a device using vop
  42. * @hw_ops: the hardware ops supported by this device.
  43. * @id: the device type identification (used to match it with a driver).
  44. * @dev: underlying device.
  45. * @dnode - The destination node which this device will communicate with.
  46. * @aper: Aperture memory window
  47. * @dma_ch - DMA channel
  48. * @index: unique position on the vop bus
  49. */
  50. struct vop_device {
  51. struct vop_hw_ops *hw_ops;
  52. struct vop_device_id id;
  53. struct device dev;
  54. u8 dnode;
  55. struct mic_mw *aper;
  56. struct dma_chan *dma_ch;
  57. int index;
  58. };
  59. /**
  60. * vop_driver - operations for a vop I/O driver
  61. * @driver: underlying device driver (populate name and owner).
  62. * @id_table: the ids serviced by this driver.
  63. * @probe: the function to call when a device is found. Returns 0 or -errno.
  64. * @remove: the function to call when a device is removed.
  65. */
  66. struct vop_driver {
  67. struct device_driver driver;
  68. const struct vop_device_id *id_table;
  69. int (*probe)(struct vop_device *dev);
  70. void (*remove)(struct vop_device *dev);
  71. };
  72. /**
  73. * vop_hw_ops - Hardware operations for accessing a VOP device on the VOP bus.
  74. *
  75. * @next_db: Obtain the next available doorbell.
  76. * @request_irq: Request an interrupt on a particular doorbell.
  77. * @free_irq: Free an interrupt requested previously.
  78. * @ack_interrupt: acknowledge an interrupt in the ISR.
  79. * @get_remote_dp: Get access to the virtio device page used by the remote
  80. * node to add/remove/configure virtio devices.
  81. * @get_dp: Get access to the virtio device page used by the self
  82. * node to add/remove/configure virtio devices.
  83. * @send_intr: Send an interrupt to the peer node on a specified doorbell.
  84. * @ioremap: Map a buffer with the specified DMA address and length.
  85. * @iounmap: Unmap a buffer previously mapped.
  86. * @dma_filter: The DMA filter function to use for obtaining access to
  87. * a DMA channel on the peer node.
  88. */
  89. struct vop_hw_ops {
  90. int (*next_db)(struct vop_device *vpdev);
  91. struct mic_irq *(*request_irq)(struct vop_device *vpdev,
  92. irqreturn_t (*func)(int irq, void *data),
  93. const char *name, void *data,
  94. int intr_src);
  95. void (*free_irq)(struct vop_device *vpdev,
  96. struct mic_irq *cookie, void *data);
  97. void (*ack_interrupt)(struct vop_device *vpdev, int num);
  98. void __iomem * (*get_remote_dp)(struct vop_device *vpdev);
  99. void * (*get_dp)(struct vop_device *vpdev);
  100. void (*send_intr)(struct vop_device *vpdev, int db);
  101. void __iomem * (*ioremap)(struct vop_device *vpdev,
  102. dma_addr_t pa, size_t len);
  103. void (*iounmap)(struct vop_device *vpdev, void __iomem *va);
  104. };
  105. struct vop_device *
  106. vop_register_device(struct device *pdev, int id,
  107. const struct dma_map_ops *dma_ops,
  108. struct vop_hw_ops *hw_ops, u8 dnode, struct mic_mw *aper,
  109. struct dma_chan *chan);
  110. void vop_unregister_device(struct vop_device *dev);
  111. int vop_register_driver(struct vop_driver *drv);
  112. void vop_unregister_driver(struct vop_driver *drv);
  113. /*
  114. * module_vop_driver() - Helper macro for drivers that don't do
  115. * anything special in module init/exit. This eliminates a lot of
  116. * boilerplate. Each module may only use this macro once, and
  117. * calling it replaces module_init() and module_exit()
  118. */
  119. #define module_vop_driver(__vop_driver) \
  120. module_driver(__vop_driver, vop_register_driver, \
  121. vop_unregister_driver)
  122. static inline struct vop_device *dev_to_vop(struct device *dev)
  123. {
  124. return container_of(dev, struct vop_device, dev);
  125. }
  126. static inline struct vop_driver *drv_to_vop(struct device_driver *drv)
  127. {
  128. return container_of(drv, struct vop_driver, driver);
  129. }
  130. #endif /* _VOP_BUS_H */