dev.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /*
  2. * Copyright (c) 2012-2015, NVIDIA Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef HOST1X_DEV_H
  17. #define HOST1X_DEV_H
  18. #include <linux/platform_device.h>
  19. #include <linux/device.h>
  20. #include "channel.h"
  21. #include "syncpt.h"
  22. #include "intr.h"
  23. #include "cdma.h"
  24. #include "job.h"
  25. struct host1x_syncpt;
  26. struct host1x_syncpt_base;
  27. struct host1x_channel;
  28. struct host1x_cdma;
  29. struct host1x_job;
  30. struct push_buffer;
  31. struct output;
  32. struct dentry;
  33. struct host1x_channel_ops {
  34. int (*init)(struct host1x_channel *channel, struct host1x *host,
  35. unsigned int id);
  36. int (*submit)(struct host1x_job *job);
  37. };
  38. struct host1x_cdma_ops {
  39. void (*start)(struct host1x_cdma *cdma);
  40. void (*stop)(struct host1x_cdma *cdma);
  41. void (*flush)(struct host1x_cdma *cdma);
  42. int (*timeout_init)(struct host1x_cdma *cdma, unsigned int syncpt);
  43. void (*timeout_destroy)(struct host1x_cdma *cdma);
  44. void (*freeze)(struct host1x_cdma *cdma);
  45. void (*resume)(struct host1x_cdma *cdma, u32 getptr);
  46. void (*timeout_cpu_incr)(struct host1x_cdma *cdma, u32 getptr,
  47. u32 syncpt_incrs, u32 syncval, u32 nr_slots);
  48. };
  49. struct host1x_pushbuffer_ops {
  50. void (*init)(struct push_buffer *pb);
  51. };
  52. struct host1x_debug_ops {
  53. void (*debug_init)(struct dentry *de);
  54. void (*show_channel_cdma)(struct host1x *host,
  55. struct host1x_channel *ch,
  56. struct output *o);
  57. void (*show_channel_fifo)(struct host1x *host,
  58. struct host1x_channel *ch,
  59. struct output *o);
  60. void (*show_mlocks)(struct host1x *host, struct output *output);
  61. };
  62. struct host1x_syncpt_ops {
  63. void (*restore)(struct host1x_syncpt *syncpt);
  64. void (*restore_wait_base)(struct host1x_syncpt *syncpt);
  65. void (*load_wait_base)(struct host1x_syncpt *syncpt);
  66. u32 (*load)(struct host1x_syncpt *syncpt);
  67. int (*cpu_incr)(struct host1x_syncpt *syncpt);
  68. int (*patch_wait)(struct host1x_syncpt *syncpt, void *patch_addr);
  69. };
  70. struct host1x_intr_ops {
  71. int (*init_host_sync)(struct host1x *host, u32 cpm,
  72. void (*syncpt_thresh_work)(struct work_struct *work));
  73. void (*set_syncpt_threshold)(
  74. struct host1x *host, unsigned int id, u32 thresh);
  75. void (*enable_syncpt_intr)(struct host1x *host, unsigned int id);
  76. void (*disable_syncpt_intr)(struct host1x *host, unsigned int id);
  77. void (*disable_all_syncpt_intrs)(struct host1x *host);
  78. int (*free_syncpt_irq)(struct host1x *host);
  79. };
  80. struct host1x_info {
  81. unsigned int nb_channels; /* host1x: number of channels supported */
  82. unsigned int nb_pts; /* host1x: number of syncpoints supported */
  83. unsigned int nb_bases; /* host1x: number of syncpoint bases supported */
  84. unsigned int nb_mlocks; /* host1x: number of mlocks supported */
  85. int (*init)(struct host1x *host1x); /* initialize per SoC ops */
  86. unsigned int sync_offset; /* offset of syncpoint registers */
  87. u64 dma_mask; /* mask of addressable memory */
  88. };
  89. struct host1x {
  90. const struct host1x_info *info;
  91. void __iomem *regs;
  92. struct host1x_syncpt *syncpt;
  93. struct host1x_syncpt_base *bases;
  94. struct device *dev;
  95. struct clk *clk;
  96. struct mutex intr_mutex;
  97. int intr_syncpt_irq;
  98. const struct host1x_syncpt_ops *syncpt_op;
  99. const struct host1x_intr_ops *intr_op;
  100. const struct host1x_channel_ops *channel_op;
  101. const struct host1x_cdma_ops *cdma_op;
  102. const struct host1x_pushbuffer_ops *cdma_pb_op;
  103. const struct host1x_debug_ops *debug_op;
  104. struct host1x_syncpt *nop_sp;
  105. struct mutex syncpt_mutex;
  106. struct mutex chlist_mutex;
  107. struct host1x_channel chlist;
  108. unsigned long allocated_channels;
  109. unsigned int num_allocated_channels;
  110. struct dentry *debugfs;
  111. struct mutex devices_lock;
  112. struct list_head devices;
  113. struct list_head list;
  114. };
  115. void host1x_sync_writel(struct host1x *host1x, u32 r, u32 v);
  116. u32 host1x_sync_readl(struct host1x *host1x, u32 r);
  117. void host1x_ch_writel(struct host1x_channel *ch, u32 r, u32 v);
  118. u32 host1x_ch_readl(struct host1x_channel *ch, u32 r);
  119. static inline void host1x_hw_syncpt_restore(struct host1x *host,
  120. struct host1x_syncpt *sp)
  121. {
  122. host->syncpt_op->restore(sp);
  123. }
  124. static inline void host1x_hw_syncpt_restore_wait_base(struct host1x *host,
  125. struct host1x_syncpt *sp)
  126. {
  127. host->syncpt_op->restore_wait_base(sp);
  128. }
  129. static inline void host1x_hw_syncpt_load_wait_base(struct host1x *host,
  130. struct host1x_syncpt *sp)
  131. {
  132. host->syncpt_op->load_wait_base(sp);
  133. }
  134. static inline u32 host1x_hw_syncpt_load(struct host1x *host,
  135. struct host1x_syncpt *sp)
  136. {
  137. return host->syncpt_op->load(sp);
  138. }
  139. static inline int host1x_hw_syncpt_cpu_incr(struct host1x *host,
  140. struct host1x_syncpt *sp)
  141. {
  142. return host->syncpt_op->cpu_incr(sp);
  143. }
  144. static inline int host1x_hw_syncpt_patch_wait(struct host1x *host,
  145. struct host1x_syncpt *sp,
  146. void *patch_addr)
  147. {
  148. return host->syncpt_op->patch_wait(sp, patch_addr);
  149. }
  150. static inline int host1x_hw_intr_init_host_sync(struct host1x *host, u32 cpm,
  151. void (*syncpt_thresh_work)(struct work_struct *))
  152. {
  153. return host->intr_op->init_host_sync(host, cpm, syncpt_thresh_work);
  154. }
  155. static inline void host1x_hw_intr_set_syncpt_threshold(struct host1x *host,
  156. unsigned int id,
  157. u32 thresh)
  158. {
  159. host->intr_op->set_syncpt_threshold(host, id, thresh);
  160. }
  161. static inline void host1x_hw_intr_enable_syncpt_intr(struct host1x *host,
  162. unsigned int id)
  163. {
  164. host->intr_op->enable_syncpt_intr(host, id);
  165. }
  166. static inline void host1x_hw_intr_disable_syncpt_intr(struct host1x *host,
  167. unsigned int id)
  168. {
  169. host->intr_op->disable_syncpt_intr(host, id);
  170. }
  171. static inline void host1x_hw_intr_disable_all_syncpt_intrs(struct host1x *host)
  172. {
  173. host->intr_op->disable_all_syncpt_intrs(host);
  174. }
  175. static inline int host1x_hw_intr_free_syncpt_irq(struct host1x *host)
  176. {
  177. return host->intr_op->free_syncpt_irq(host);
  178. }
  179. static inline int host1x_hw_channel_init(struct host1x *host,
  180. struct host1x_channel *channel,
  181. unsigned int id)
  182. {
  183. return host->channel_op->init(channel, host, id);
  184. }
  185. static inline int host1x_hw_channel_submit(struct host1x *host,
  186. struct host1x_job *job)
  187. {
  188. return host->channel_op->submit(job);
  189. }
  190. static inline void host1x_hw_cdma_start(struct host1x *host,
  191. struct host1x_cdma *cdma)
  192. {
  193. host->cdma_op->start(cdma);
  194. }
  195. static inline void host1x_hw_cdma_stop(struct host1x *host,
  196. struct host1x_cdma *cdma)
  197. {
  198. host->cdma_op->stop(cdma);
  199. }
  200. static inline void host1x_hw_cdma_flush(struct host1x *host,
  201. struct host1x_cdma *cdma)
  202. {
  203. host->cdma_op->flush(cdma);
  204. }
  205. static inline int host1x_hw_cdma_timeout_init(struct host1x *host,
  206. struct host1x_cdma *cdma,
  207. unsigned int syncpt)
  208. {
  209. return host->cdma_op->timeout_init(cdma, syncpt);
  210. }
  211. static inline void host1x_hw_cdma_timeout_destroy(struct host1x *host,
  212. struct host1x_cdma *cdma)
  213. {
  214. host->cdma_op->timeout_destroy(cdma);
  215. }
  216. static inline void host1x_hw_cdma_freeze(struct host1x *host,
  217. struct host1x_cdma *cdma)
  218. {
  219. host->cdma_op->freeze(cdma);
  220. }
  221. static inline void host1x_hw_cdma_resume(struct host1x *host,
  222. struct host1x_cdma *cdma, u32 getptr)
  223. {
  224. host->cdma_op->resume(cdma, getptr);
  225. }
  226. static inline void host1x_hw_cdma_timeout_cpu_incr(struct host1x *host,
  227. struct host1x_cdma *cdma,
  228. u32 getptr,
  229. u32 syncpt_incrs,
  230. u32 syncval, u32 nr_slots)
  231. {
  232. host->cdma_op->timeout_cpu_incr(cdma, getptr, syncpt_incrs, syncval,
  233. nr_slots);
  234. }
  235. static inline void host1x_hw_pushbuffer_init(struct host1x *host,
  236. struct push_buffer *pb)
  237. {
  238. host->cdma_pb_op->init(pb);
  239. }
  240. static inline void host1x_hw_debug_init(struct host1x *host, struct dentry *de)
  241. {
  242. if (host->debug_op && host->debug_op->debug_init)
  243. host->debug_op->debug_init(de);
  244. }
  245. static inline void host1x_hw_show_channel_cdma(struct host1x *host,
  246. struct host1x_channel *channel,
  247. struct output *o)
  248. {
  249. host->debug_op->show_channel_cdma(host, channel, o);
  250. }
  251. static inline void host1x_hw_show_channel_fifo(struct host1x *host,
  252. struct host1x_channel *channel,
  253. struct output *o)
  254. {
  255. host->debug_op->show_channel_fifo(host, channel, o);
  256. }
  257. static inline void host1x_hw_show_mlocks(struct host1x *host, struct output *o)
  258. {
  259. host->debug_op->show_mlocks(host, o);
  260. }
  261. extern struct platform_driver tegra_mipi_driver;
  262. #endif