fpga-mgr.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * FPGA Framework
  3. *
  4. * Copyright (C) 2013-2015 Altera Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/mutex.h>
  19. #include <linux/platform_device.h>
  20. #ifndef _LINUX_FPGA_MGR_H
  21. #define _LINUX_FPGA_MGR_H
  22. struct fpga_manager;
  23. /**
  24. * enum fpga_mgr_states - fpga framework states
  25. * @FPGA_MGR_STATE_UNKNOWN: can't determine state
  26. * @FPGA_MGR_STATE_POWER_OFF: FPGA power is off
  27. * @FPGA_MGR_STATE_POWER_UP: FPGA reports power is up
  28. * @FPGA_MGR_STATE_RESET: FPGA in reset state
  29. * @FPGA_MGR_STATE_FIRMWARE_REQ: firmware request in progress
  30. * @FPGA_MGR_STATE_FIRMWARE_REQ_ERR: firmware request failed
  31. * @FPGA_MGR_STATE_WRITE_INIT: preparing FPGA for programming
  32. * @FPGA_MGR_STATE_WRITE_INIT_ERR: Error during WRITE_INIT stage
  33. * @FPGA_MGR_STATE_WRITE: writing image to FPGA
  34. * @FPGA_MGR_STATE_WRITE_ERR: Error while writing FPGA
  35. * @FPGA_MGR_STATE_WRITE_COMPLETE: Doing post programming steps
  36. * @FPGA_MGR_STATE_WRITE_COMPLETE_ERR: Error during WRITE_COMPLETE
  37. * @FPGA_MGR_STATE_OPERATING: FPGA is programmed and operating
  38. */
  39. enum fpga_mgr_states {
  40. /* default FPGA states */
  41. FPGA_MGR_STATE_UNKNOWN,
  42. FPGA_MGR_STATE_POWER_OFF,
  43. FPGA_MGR_STATE_POWER_UP,
  44. FPGA_MGR_STATE_RESET,
  45. /* getting an image for loading */
  46. FPGA_MGR_STATE_FIRMWARE_REQ,
  47. FPGA_MGR_STATE_FIRMWARE_REQ_ERR,
  48. /* write sequence: init, write, complete */
  49. FPGA_MGR_STATE_WRITE_INIT,
  50. FPGA_MGR_STATE_WRITE_INIT_ERR,
  51. FPGA_MGR_STATE_WRITE,
  52. FPGA_MGR_STATE_WRITE_ERR,
  53. FPGA_MGR_STATE_WRITE_COMPLETE,
  54. FPGA_MGR_STATE_WRITE_COMPLETE_ERR,
  55. /* fpga is programmed and operating */
  56. FPGA_MGR_STATE_OPERATING,
  57. };
  58. /*
  59. * FPGA Manager flags
  60. * FPGA_MGR_PARTIAL_RECONFIG: do partial reconfiguration if supported
  61. */
  62. #define FPGA_MGR_PARTIAL_RECONFIG BIT(0)
  63. /**
  64. * struct fpga_manager_ops - ops for low level fpga manager drivers
  65. * @state: returns an enum value of the FPGA's state
  66. * @write_init: prepare the FPGA to receive confuration data
  67. * @write: write count bytes of configuration data to the FPGA
  68. * @write_complete: set FPGA to operating state after writing is done
  69. * @fpga_remove: optional: Set FPGA into a specific state during driver remove
  70. *
  71. * fpga_manager_ops are the low level functions implemented by a specific
  72. * fpga manager driver. The optional ones are tested for NULL before being
  73. * called, so leaving them out is fine.
  74. */
  75. struct fpga_manager_ops {
  76. enum fpga_mgr_states (*state)(struct fpga_manager *mgr);
  77. int (*write_init)(struct fpga_manager *mgr, u32 flags,
  78. const char *buf, size_t count);
  79. int (*write)(struct fpga_manager *mgr, const char *buf, size_t count);
  80. int (*write_complete)(struct fpga_manager *mgr, u32 flags);
  81. void (*fpga_remove)(struct fpga_manager *mgr);
  82. };
  83. /**
  84. * struct fpga_manager - fpga manager structure
  85. * @name: name of low level fpga manager
  86. * @dev: fpga manager device
  87. * @ref_mutex: only allows one reference to fpga manager
  88. * @state: state of fpga manager
  89. * @mops: pointer to struct of fpga manager ops
  90. * @priv: low level driver private date
  91. */
  92. struct fpga_manager {
  93. const char *name;
  94. struct device dev;
  95. struct mutex ref_mutex;
  96. enum fpga_mgr_states state;
  97. const struct fpga_manager_ops *mops;
  98. void *priv;
  99. };
  100. #define to_fpga_manager(d) container_of(d, struct fpga_manager, dev)
  101. int fpga_mgr_buf_load(struct fpga_manager *mgr, u32 flags,
  102. const char *buf, size_t count);
  103. int fpga_mgr_firmware_load(struct fpga_manager *mgr, u32 flags,
  104. const char *image_name);
  105. struct fpga_manager *of_fpga_mgr_get(struct device_node *node);
  106. void fpga_mgr_put(struct fpga_manager *mgr);
  107. int fpga_mgr_register(struct device *dev, const char *name,
  108. const struct fpga_manager_ops *mops, void *priv);
  109. void fpga_mgr_unregister(struct device *dev);
  110. #endif /*_LINUX_FPGA_MGR_H */