fpga-mgr.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * FPGA Framework
  3. *
  4. * Copyright (C) 2013-2016 Altera Corporation
  5. * Copyright (C) 2017 Intel Corporation
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _LINUX_FPGA_MGR_H
  20. #define _LINUX_FPGA_MGR_H
  21. #include <linux/mutex.h>
  22. #include <linux/platform_device.h>
  23. struct fpga_manager;
  24. struct sg_table;
  25. /**
  26. * enum fpga_mgr_states - fpga framework states
  27. * @FPGA_MGR_STATE_UNKNOWN: can't determine state
  28. * @FPGA_MGR_STATE_POWER_OFF: FPGA power is off
  29. * @FPGA_MGR_STATE_POWER_UP: FPGA reports power is up
  30. * @FPGA_MGR_STATE_RESET: FPGA in reset state
  31. * @FPGA_MGR_STATE_FIRMWARE_REQ: firmware request in progress
  32. * @FPGA_MGR_STATE_FIRMWARE_REQ_ERR: firmware request failed
  33. * @FPGA_MGR_STATE_WRITE_INIT: preparing FPGA for programming
  34. * @FPGA_MGR_STATE_WRITE_INIT_ERR: Error during WRITE_INIT stage
  35. * @FPGA_MGR_STATE_WRITE: writing image to FPGA
  36. * @FPGA_MGR_STATE_WRITE_ERR: Error while writing FPGA
  37. * @FPGA_MGR_STATE_WRITE_COMPLETE: Doing post programming steps
  38. * @FPGA_MGR_STATE_WRITE_COMPLETE_ERR: Error during WRITE_COMPLETE
  39. * @FPGA_MGR_STATE_OPERATING: FPGA is programmed and operating
  40. */
  41. enum fpga_mgr_states {
  42. /* default FPGA states */
  43. FPGA_MGR_STATE_UNKNOWN,
  44. FPGA_MGR_STATE_POWER_OFF,
  45. FPGA_MGR_STATE_POWER_UP,
  46. FPGA_MGR_STATE_RESET,
  47. /* getting an image for loading */
  48. FPGA_MGR_STATE_FIRMWARE_REQ,
  49. FPGA_MGR_STATE_FIRMWARE_REQ_ERR,
  50. /* write sequence: init, write, complete */
  51. FPGA_MGR_STATE_WRITE_INIT,
  52. FPGA_MGR_STATE_WRITE_INIT_ERR,
  53. FPGA_MGR_STATE_WRITE,
  54. FPGA_MGR_STATE_WRITE_ERR,
  55. FPGA_MGR_STATE_WRITE_COMPLETE,
  56. FPGA_MGR_STATE_WRITE_COMPLETE_ERR,
  57. /* fpga is programmed and operating */
  58. FPGA_MGR_STATE_OPERATING,
  59. };
  60. /*
  61. * FPGA Manager flags
  62. * FPGA_MGR_PARTIAL_RECONFIG: do partial reconfiguration if supported
  63. * FPGA_MGR_EXTERNAL_CONFIG: FPGA has been configured prior to Linux booting
  64. * FPGA_MGR_BITSTREAM_LSB_FIRST: SPI bitstream bit order is LSB first
  65. * FPGA_MGR_COMPRESSED_BITSTREAM: FPGA bitstream is compressed
  66. */
  67. #define FPGA_MGR_PARTIAL_RECONFIG BIT(0)
  68. #define FPGA_MGR_EXTERNAL_CONFIG BIT(1)
  69. #define FPGA_MGR_ENCRYPTED_BITSTREAM BIT(2)
  70. #define FPGA_MGR_BITSTREAM_LSB_FIRST BIT(3)
  71. #define FPGA_MGR_COMPRESSED_BITSTREAM BIT(4)
  72. /**
  73. * struct fpga_image_info - information specific to a FPGA image
  74. * @flags: boolean flags as defined above
  75. * @enable_timeout_us: maximum time to enable traffic through bridge (uSec)
  76. * @disable_timeout_us: maximum time to disable traffic through bridge (uSec)
  77. * @config_complete_timeout_us: maximum time for FPGA to switch to operating
  78. * status in the write_complete op.
  79. * @firmware_name: name of FPGA image firmware file
  80. * @sgt: scatter/gather table containing FPGA image
  81. * @buf: contiguous buffer containing FPGA image
  82. * @count: size of buf
  83. * @dev: device that owns this
  84. */
  85. struct fpga_image_info {
  86. u32 flags;
  87. u32 enable_timeout_us;
  88. u32 disable_timeout_us;
  89. u32 config_complete_timeout_us;
  90. char *firmware_name;
  91. struct sg_table *sgt;
  92. const char *buf;
  93. size_t count;
  94. struct device *dev;
  95. };
  96. /**
  97. * struct fpga_manager_ops - ops for low level fpga manager drivers
  98. * @initial_header_size: Maximum number of bytes that should be passed into write_init
  99. * @state: returns an enum value of the FPGA's state
  100. * @write_init: prepare the FPGA to receive confuration data
  101. * @write: write count bytes of configuration data to the FPGA
  102. * @write_sg: write the scatter list of configuration data to the FPGA
  103. * @write_complete: set FPGA to operating state after writing is done
  104. * @fpga_remove: optional: Set FPGA into a specific state during driver remove
  105. *
  106. * fpga_manager_ops are the low level functions implemented by a specific
  107. * fpga manager driver. The optional ones are tested for NULL before being
  108. * called, so leaving them out is fine.
  109. */
  110. struct fpga_manager_ops {
  111. size_t initial_header_size;
  112. enum fpga_mgr_states (*state)(struct fpga_manager *mgr);
  113. int (*write_init)(struct fpga_manager *mgr,
  114. struct fpga_image_info *info,
  115. const char *buf, size_t count);
  116. int (*write)(struct fpga_manager *mgr, const char *buf, size_t count);
  117. int (*write_sg)(struct fpga_manager *mgr, struct sg_table *sgt);
  118. int (*write_complete)(struct fpga_manager *mgr,
  119. struct fpga_image_info *info);
  120. void (*fpga_remove)(struct fpga_manager *mgr);
  121. };
  122. /**
  123. * struct fpga_manager - fpga manager structure
  124. * @name: name of low level fpga manager
  125. * @dev: fpga manager device
  126. * @ref_mutex: only allows one reference to fpga manager
  127. * @state: state of fpga manager
  128. * @mops: pointer to struct of fpga manager ops
  129. * @priv: low level driver private date
  130. */
  131. struct fpga_manager {
  132. const char *name;
  133. struct device dev;
  134. struct mutex ref_mutex;
  135. enum fpga_mgr_states state;
  136. const struct fpga_manager_ops *mops;
  137. void *priv;
  138. };
  139. #define to_fpga_manager(d) container_of(d, struct fpga_manager, dev)
  140. struct fpga_image_info *fpga_image_info_alloc(struct device *dev);
  141. void fpga_image_info_free(struct fpga_image_info *info);
  142. int fpga_mgr_load(struct fpga_manager *mgr, struct fpga_image_info *info);
  143. struct fpga_manager *of_fpga_mgr_get(struct device_node *node);
  144. struct fpga_manager *fpga_mgr_get(struct device *dev);
  145. void fpga_mgr_put(struct fpga_manager *mgr);
  146. int fpga_mgr_register(struct device *dev, const char *name,
  147. const struct fpga_manager_ops *mops, void *priv);
  148. void fpga_mgr_unregister(struct device *dev);
  149. #endif /*_LINUX_FPGA_MGR_H */