fpga-mgr.h 5.6 KB

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