xillybus.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * linux/drivers/misc/xillybus.h
  3. *
  4. * Copyright 2011 Xillybus Ltd, http://xillybus.com
  5. *
  6. * Header file for the Xillybus FPGA/host framework.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the smems of the GNU General Public License as published by
  10. * the Free Software Foundation; version 2 of the License.
  11. */
  12. #ifndef __XILLYBUS_H
  13. #define __XILLYBUS_H
  14. #include <linux/list.h>
  15. #include <linux/device.h>
  16. #include <linux/dma-mapping.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/sched.h>
  19. #include <linux/cdev.h>
  20. #include <linux/spinlock.h>
  21. #include <linux/mutex.h>
  22. #include <linux/workqueue.h>
  23. struct xilly_endpoint_hardware;
  24. struct xilly_buffer {
  25. void *addr;
  26. dma_addr_t dma_addr;
  27. int end_offset; /* Counting elements, not bytes */
  28. };
  29. struct xilly_idt_handle {
  30. unsigned char *chandesc;
  31. unsigned char *idt;
  32. int entries;
  33. };
  34. /*
  35. * Read-write confusion: wr_* and rd_* notation sticks to FPGA view, so
  36. * wr_* buffers are those consumed by read(), since the FPGA writes to them
  37. * and vice versa.
  38. */
  39. struct xilly_channel {
  40. struct xilly_endpoint *endpoint;
  41. int chan_num;
  42. int log2_element_size;
  43. int seekable;
  44. struct xilly_buffer **wr_buffers; /* FPGA writes, driver reads! */
  45. int num_wr_buffers;
  46. unsigned int wr_buf_size; /* In bytes */
  47. int wr_fpga_buf_idx;
  48. int wr_host_buf_idx;
  49. int wr_host_buf_pos;
  50. int wr_empty;
  51. int wr_ready; /* Significant only when wr_empty == 1 */
  52. int wr_sleepy;
  53. int wr_eof;
  54. int wr_hangup;
  55. spinlock_t wr_spinlock;
  56. struct mutex wr_mutex;
  57. wait_queue_head_t wr_wait;
  58. wait_queue_head_t wr_ready_wait;
  59. int wr_ref_count;
  60. int wr_synchronous;
  61. int wr_allow_partial;
  62. int wr_exclusive_open;
  63. int wr_supports_nonempty;
  64. struct xilly_buffer **rd_buffers; /* FPGA reads, driver writes! */
  65. int num_rd_buffers;
  66. unsigned int rd_buf_size; /* In bytes */
  67. int rd_fpga_buf_idx;
  68. int rd_host_buf_pos;
  69. int rd_host_buf_idx;
  70. int rd_full;
  71. spinlock_t rd_spinlock;
  72. struct mutex rd_mutex;
  73. wait_queue_head_t rd_wait;
  74. int rd_ref_count;
  75. int rd_allow_partial;
  76. int rd_synchronous;
  77. int rd_exclusive_open;
  78. struct delayed_work rd_workitem;
  79. unsigned char rd_leftovers[4];
  80. };
  81. struct xilly_endpoint {
  82. /*
  83. * One of pdev and dev is always NULL, and the other is a valid
  84. * pointer, depending on the type of device
  85. */
  86. struct pci_dev *pdev;
  87. struct device *dev;
  88. struct xilly_endpoint_hardware *ephw;
  89. struct list_head ep_list;
  90. int dma_using_dac; /* =1 if 64-bit DMA is used, =0 otherwise. */
  91. __iomem void *registers;
  92. int fatal_error;
  93. struct mutex register_mutex;
  94. wait_queue_head_t ep_wait;
  95. /* Channels and message handling */
  96. struct cdev cdev;
  97. int major;
  98. int lowest_minor; /* Highest minor = lowest_minor + num_channels - 1 */
  99. int num_channels; /* EXCLUDING message buffer */
  100. struct xilly_channel **channels;
  101. int msg_counter;
  102. int failed_messages;
  103. int idtlen;
  104. u32 *msgbuf_addr;
  105. dma_addr_t msgbuf_dma_addr;
  106. unsigned int msg_buf_size;
  107. };
  108. struct xilly_endpoint_hardware {
  109. struct module *owner;
  110. void (*hw_sync_sgl_for_cpu)(struct xilly_endpoint *,
  111. dma_addr_t,
  112. size_t,
  113. int);
  114. void (*hw_sync_sgl_for_device)(struct xilly_endpoint *,
  115. dma_addr_t,
  116. size_t,
  117. int);
  118. int (*map_single)(struct xilly_endpoint *,
  119. void *,
  120. size_t,
  121. int,
  122. dma_addr_t *);
  123. };
  124. struct xilly_mapping {
  125. void *device;
  126. dma_addr_t dma_addr;
  127. size_t size;
  128. int direction;
  129. };
  130. irqreturn_t xillybus_isr(int irq, void *data);
  131. struct xilly_endpoint *xillybus_init_endpoint(struct pci_dev *pdev,
  132. struct device *dev,
  133. struct xilly_endpoint_hardware
  134. *ephw);
  135. int xillybus_endpoint_discovery(struct xilly_endpoint *endpoint);
  136. void xillybus_endpoint_remove(struct xilly_endpoint *endpoint);
  137. #endif /* __XILLYBUS_H */