xrp_hw.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * Copyright (c) 2017 Cadence Design Systems, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sublicense, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included
  13. * in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Alternatively you can use and distribute this file under the terms of
  24. * the GNU General Public License version 2 or later.
  25. */
  26. /*!
  27. * \file xrp_hw.h
  28. * \brief Interface between generic and HW-specific kernel drivers.
  29. */
  30. #ifndef _XRP_HW
  31. #define _XRP_HW
  32. #include <linux/irqreturn.h>
  33. #include <linux/platform_device.h>
  34. #include <linux/types.h>
  35. struct xvp;
  36. /*!
  37. * Hardware-specific operation entry points.
  38. * Hardware-specific driver passes a pointer to this structure to xrp_init
  39. * at initialization time.
  40. */
  41. struct xrp_hw_ops {
  42. /*!
  43. * Enable power/clock, but keep the core stalled.
  44. * \param hw_arg: opaque parameter passed to xrp_init at initialization
  45. * time
  46. */
  47. int (*enable)(void *hw_arg);
  48. /*!
  49. * Diable power/clock.
  50. *
  51. * \param hw_arg: opaque parameter passed to xrp_init at initialization
  52. * time
  53. */
  54. void (*disable)(void *hw_arg);
  55. /*!
  56. * Reset the core.
  57. *
  58. * \param hw_arg: opaque parameter passed to xrp_init at initialization
  59. * time
  60. */
  61. void (*reset)(void *hw_arg);
  62. /*!
  63. * Unstall the core.
  64. *
  65. * \param hw_arg: opaque parameter passed to xrp_init at initialization
  66. * time
  67. */
  68. void (*release)(void *hw_arg);
  69. /*!
  70. * Stall the core.
  71. *
  72. * \param hw_arg: opaque parameter passed to xrp_init at initialization
  73. * time
  74. */
  75. void (*halt)(void *hw_arg);
  76. /*! Get HW-specific data to pass to the DSP on synchronization
  77. *
  78. * \param hw_arg: opaque parameter passed to xrp_init at initialization
  79. * time
  80. * \param sz: return size of sync data here
  81. * \return a buffer allocated with kmalloc that the caller will free
  82. */
  83. void *(*get_hw_sync_data)(void *hw_arg, size_t *sz);
  84. /*!
  85. * Send IRQ to the core.
  86. *
  87. * \param hw_arg: opaque parameter passed to xrp_init at initialization
  88. * time
  89. */
  90. void (*send_irq)(void *hw_arg);
  91. /*!
  92. * Check whether region of physical memory may be handled by
  93. * dma_sync_* operations
  94. *
  95. * \param hw_arg: opaque parameter passed to xrp_init at initialization
  96. * time
  97. */
  98. bool (*cacheable)(void *hw_arg, unsigned long pfn, unsigned long n_pages);
  99. /*!
  100. * Synchronize region of memory for DSP access.
  101. *
  102. * \param hw_arg: opaque parameter passed to xrp_init at initialization
  103. * time
  104. * \param flags: XRP_FLAG_{READ,WRITE,READWRITE}
  105. */
  106. void (*dma_sync_for_device)(void *hw_arg,
  107. void *vaddr, phys_addr_t paddr,
  108. unsigned long sz, unsigned flags);
  109. /*!
  110. * Synchronize region of memory for host access.
  111. *
  112. * \param hw_arg: opaque parameter passed to xrp_init at initialization
  113. * time
  114. * \param flags: XRP_FLAG_{READ,WRITE,READWRITE}
  115. */
  116. void (*dma_sync_for_cpu)(void *hw_arg,
  117. void *vaddr, phys_addr_t paddr,
  118. unsigned long sz, unsigned flags);
  119. /*!
  120. * memcpy data/code to device-specific memory.
  121. */
  122. void (*memcpy_tohw)(volatile void __iomem *dst, const void *src, size_t sz);
  123. /*!
  124. * memset device-specific memory.
  125. */
  126. void (*memset_hw)(volatile void __iomem *dst, int c, size_t sz);
  127. /*!
  128. * Check DSP status.
  129. *
  130. * \param hw_arg: opaque parameter passed to xrp_init at initialization
  131. * time
  132. * \return whether the core has crashed and needs to be restarted
  133. */
  134. bool (*panic_check)(void *hw_arg);
  135. phys_addr_t (*get_base_mimo)(void *hw_arg);
  136. void (*update_device_base)(void *hw_arg,phys_addr_t addr);
  137. void (*set_reset_vector)(void *hw_arg,u32 addr);
  138. void (*clear_hw)(void *hw_arg);
  139. };
  140. enum xrp_init_flags {
  141. /*! Use interrupts in DSP->host communication */
  142. XRP_INIT_USE_HOST_IRQ = 0x1,
  143. };
  144. /*!
  145. * Initialize generic XRP kernel driver from cdns,xrp-compatible device
  146. * tree node.
  147. *
  148. * \param pdev: pointer to platform device associated with the XRP device
  149. * instance
  150. * \param flags: initialization flags
  151. * \param hw: pointer to xrp_hw_ops structeure for this device
  152. * \param hw_arg: opaque pointer passed back to hw-specific functions
  153. * \return error code or pointer to struct xvp, use IS_ERR_VALUE and ERR_PTR
  154. */
  155. long xrp_init(struct platform_device *pdev, enum xrp_init_flags flags,
  156. const struct xrp_hw_ops *hw, void *hw_arg,int mem_idx);
  157. /*!
  158. * Initialize generic XRP kernel driver from cdns,xrp,v1-compatible device
  159. * tree node.
  160. *
  161. * \param pdev: pointer to platform device associated with the XRP device
  162. * instance
  163. * \param flags: initialization flags
  164. * \param hw: pointer to xrp_hw_ops structeure for this device
  165. * \param hw_arg: opaque pointer passed back to hw-specific functions
  166. * \return error code or pointer to struct xvp, use IS_ERR_VALUE and ERR_PTR
  167. */
  168. long xrp_init_v1(struct platform_device *pdev, enum xrp_init_flags flags,
  169. const struct xrp_hw_ops *hw, void *hw_arg,int mem_idx);
  170. /*!
  171. * Initialize generic XRP kernel driver from cdns,xrp,cma-compatible device
  172. * tree node.
  173. *
  174. * \param pdev: pointer to platform device associated with the XRP device
  175. * instance
  176. * \param flags: initialization flags
  177. * \param hw: pointer to xrp_hw_ops structeure for this device
  178. * \param hw_arg: opaque pointer passed back to hw-specific functions
  179. * \return error code or pointer to struct xvp, use IS_ERR_VALUE and ERR_PTR
  180. */
  181. long xrp_init_cma(struct platform_device *pdev, enum xrp_init_flags flags,
  182. const struct xrp_hw_ops *hw, void *hw_arg,int mem_idx);
  183. /*!
  184. * Deinitialize generic XRP kernel driver.
  185. *
  186. * \param pdev: pointer to platform device associated with the XRP device
  187. * instance
  188. * \return 0 on success, negative error code otherwise
  189. */
  190. int xrp_deinit(struct platform_device *pdev);
  191. /*!
  192. * Deinitialize generic XRP kernel driver.
  193. *
  194. * \param pdev: pointer to platform device associated with the XRP device
  195. * instance
  196. * \param hw_arg: optional pointer to opaque pointer where generic XRP driver
  197. * returns hw_arg that was associated with the pdev at xrp_init
  198. * time
  199. * \return 0 on success, negative error code otherwise
  200. */
  201. int xrp_deinit_hw(struct platform_device *pdev, void **hw_arg);
  202. /*!
  203. * Notify generic XRP driver of possible IRQ from the DSP.
  204. *
  205. * \param irq: IRQ number
  206. * \param xvp: pointer to struct xvp returned from xrp_init* call
  207. * \return whether IRQ was recognized and handled
  208. */
  209. irqreturn_t xrp_irq_handler(int irq, struct xvp *xvp);
  210. /*!
  211. * Resume generic XRP operation of the device dev.
  212. *
  213. * \param dev: device which operation shall be resumed
  214. * \return 0 on success, negative error code otherwise
  215. */
  216. int xrp_runtime_resume(struct device *dev);
  217. /*!
  218. * Suspend generic XRP operation of the device dev.
  219. *
  220. * \param dev: device which operation shall be suspended
  221. * \return 0 on success, negative error code otherwise
  222. */
  223. int xrp_runtime_suspend(struct device *dev);
  224. int xrp_set_reset_reg(int dsp_id);
  225. #endif