xillybus.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * linux/drivers/misc/xillybus.h
  4. *
  5. * Copyright 2011 Xillybus Ltd, http://xillybus.com
  6. *
  7. * Header file for the Xillybus FPGA/host framework.
  8. */
  9. #ifndef __XILLYBUS_H
  10. #define __XILLYBUS_H
  11. #include <linux/list.h>
  12. #include <linux/device.h>
  13. #include <linux/dma-mapping.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/sched.h>
  16. #include <linux/cdev.h>
  17. #include <linux/spinlock.h>
  18. #include <linux/mutex.h>
  19. #include <linux/workqueue.h>
  20. struct xilly_endpoint_hardware;
  21. struct xilly_buffer {
  22. void *addr;
  23. dma_addr_t dma_addr;
  24. int end_offset; /* Counting elements, not bytes */
  25. };
  26. struct xilly_idt_handle {
  27. unsigned char *chandesc;
  28. unsigned char *names;
  29. int names_len;
  30. int entries;
  31. };
  32. /*
  33. * Read-write confusion: wr_* and rd_* notation sticks to FPGA view, so
  34. * wr_* buffers are those consumed by read(), since the FPGA writes to them
  35. * and vice versa.
  36. */
  37. struct xilly_channel {
  38. struct xilly_endpoint *endpoint;
  39. int chan_num;
  40. int log2_element_size;
  41. int seekable;
  42. struct xilly_buffer **wr_buffers; /* FPGA writes, driver reads! */
  43. int num_wr_buffers;
  44. unsigned int wr_buf_size; /* In bytes */
  45. int wr_fpga_buf_idx;
  46. int wr_host_buf_idx;
  47. int wr_host_buf_pos;
  48. int wr_empty;
  49. int wr_ready; /* Significant only when wr_empty == 1 */
  50. int wr_sleepy;
  51. int wr_eof;
  52. int wr_hangup;
  53. spinlock_t wr_spinlock;
  54. struct mutex wr_mutex;
  55. wait_queue_head_t wr_wait;
  56. wait_queue_head_t wr_ready_wait;
  57. int wr_ref_count;
  58. int wr_synchronous;
  59. int wr_allow_partial;
  60. int wr_exclusive_open;
  61. int wr_supports_nonempty;
  62. struct xilly_buffer **rd_buffers; /* FPGA reads, driver writes! */
  63. int num_rd_buffers;
  64. unsigned int rd_buf_size; /* In bytes */
  65. int rd_fpga_buf_idx;
  66. int rd_host_buf_pos;
  67. int rd_host_buf_idx;
  68. int rd_full;
  69. spinlock_t rd_spinlock;
  70. struct mutex rd_mutex;
  71. wait_queue_head_t rd_wait;
  72. int rd_ref_count;
  73. int rd_allow_partial;
  74. int rd_synchronous;
  75. int rd_exclusive_open;
  76. struct delayed_work rd_workitem;
  77. unsigned char rd_leftovers[4];
  78. };
  79. struct xilly_endpoint {
  80. struct device *dev;
  81. struct module *owner;
  82. int dma_using_dac; /* =1 if 64-bit DMA is used, =0 otherwise. */
  83. __iomem void *registers;
  84. int fatal_error;
  85. struct mutex register_mutex;
  86. wait_queue_head_t ep_wait;
  87. int num_channels; /* EXCLUDING message buffer */
  88. struct xilly_channel **channels;
  89. int msg_counter;
  90. int failed_messages;
  91. int idtlen;
  92. u32 *msgbuf_addr;
  93. dma_addr_t msgbuf_dma_addr;
  94. unsigned int msg_buf_size;
  95. };
  96. struct xilly_mapping {
  97. struct device *device;
  98. dma_addr_t dma_addr;
  99. size_t size;
  100. int direction;
  101. };
  102. irqreturn_t xillybus_isr(int irq, void *data);
  103. struct xilly_endpoint *xillybus_init_endpoint(struct device *dev);
  104. int xillybus_endpoint_discovery(struct xilly_endpoint *endpoint);
  105. void xillybus_endpoint_remove(struct xilly_endpoint *endpoint);
  106. #endif /* __XILLYBUS_H */