dev.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /*
  2. * Copyright (c) 2012-2013, 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 chlist_mutex;
  106. struct host1x_channel chlist;
  107. unsigned long allocated_channels;
  108. unsigned int num_allocated_channels;
  109. struct dentry *debugfs;
  110. struct mutex devices_lock;
  111. struct list_head devices;
  112. struct list_head list;
  113. };
  114. void host1x_sync_writel(struct host1x *host1x, u32 r, u32 v);
  115. u32 host1x_sync_readl(struct host1x *host1x, u32 r);
  116. void host1x_ch_writel(struct host1x_channel *ch, u32 r, u32 v);
  117. u32 host1x_ch_readl(struct host1x_channel *ch, u32 r);
  118. static inline void host1x_hw_syncpt_restore(struct host1x *host,
  119. struct host1x_syncpt *sp)
  120. {
  121. host->syncpt_op->restore(sp);
  122. }
  123. static inline void host1x_hw_syncpt_restore_wait_base(struct host1x *host,
  124. struct host1x_syncpt *sp)
  125. {
  126. host->syncpt_op->restore_wait_base(sp);
  127. }
  128. static inline void host1x_hw_syncpt_load_wait_base(struct host1x *host,
  129. struct host1x_syncpt *sp)
  130. {
  131. host->syncpt_op->load_wait_base(sp);
  132. }
  133. static inline u32 host1x_hw_syncpt_load(struct host1x *host,
  134. struct host1x_syncpt *sp)
  135. {
  136. return host->syncpt_op->load(sp);
  137. }
  138. static inline int host1x_hw_syncpt_cpu_incr(struct host1x *host,
  139. struct host1x_syncpt *sp)
  140. {
  141. return host->syncpt_op->cpu_incr(sp);
  142. }
  143. static inline int host1x_hw_syncpt_patch_wait(struct host1x *host,
  144. struct host1x_syncpt *sp,
  145. void *patch_addr)
  146. {
  147. return host->syncpt_op->patch_wait(sp, patch_addr);
  148. }
  149. static inline int host1x_hw_intr_init_host_sync(struct host1x *host, u32 cpm,
  150. void (*syncpt_thresh_work)(struct work_struct *))
  151. {
  152. return host->intr_op->init_host_sync(host, cpm, syncpt_thresh_work);
  153. }
  154. static inline void host1x_hw_intr_set_syncpt_threshold(struct host1x *host,
  155. unsigned int id,
  156. u32 thresh)
  157. {
  158. host->intr_op->set_syncpt_threshold(host, id, thresh);
  159. }
  160. static inline void host1x_hw_intr_enable_syncpt_intr(struct host1x *host,
  161. unsigned int id)
  162. {
  163. host->intr_op->enable_syncpt_intr(host, id);
  164. }
  165. static inline void host1x_hw_intr_disable_syncpt_intr(struct host1x *host,
  166. unsigned int id)
  167. {
  168. host->intr_op->disable_syncpt_intr(host, id);
  169. }
  170. static inline void host1x_hw_intr_disable_all_syncpt_intrs(struct host1x *host)
  171. {
  172. host->intr_op->disable_all_syncpt_intrs(host);
  173. }
  174. static inline int host1x_hw_intr_free_syncpt_irq(struct host1x *host)
  175. {
  176. return host->intr_op->free_syncpt_irq(host);
  177. }
  178. static inline int host1x_hw_channel_init(struct host1x *host,
  179. struct host1x_channel *channel,
  180. unsigned int id)
  181. {
  182. return host->channel_op->init(channel, host, id);
  183. }
  184. static inline int host1x_hw_channel_submit(struct host1x *host,
  185. struct host1x_job *job)
  186. {
  187. return host->channel_op->submit(job);
  188. }
  189. static inline void host1x_hw_cdma_start(struct host1x *host,
  190. struct host1x_cdma *cdma)
  191. {
  192. host->cdma_op->start(cdma);
  193. }
  194. static inline void host1x_hw_cdma_stop(struct host1x *host,
  195. struct host1x_cdma *cdma)
  196. {
  197. host->cdma_op->stop(cdma);
  198. }
  199. static inline void host1x_hw_cdma_flush(struct host1x *host,
  200. struct host1x_cdma *cdma)
  201. {
  202. host->cdma_op->flush(cdma);
  203. }
  204. static inline int host1x_hw_cdma_timeout_init(struct host1x *host,
  205. struct host1x_cdma *cdma,
  206. unsigned int syncpt)
  207. {
  208. return host->cdma_op->timeout_init(cdma, syncpt);
  209. }
  210. static inline void host1x_hw_cdma_timeout_destroy(struct host1x *host,
  211. struct host1x_cdma *cdma)
  212. {
  213. host->cdma_op->timeout_destroy(cdma);
  214. }
  215. static inline void host1x_hw_cdma_freeze(struct host1x *host,
  216. struct host1x_cdma *cdma)
  217. {
  218. host->cdma_op->freeze(cdma);
  219. }
  220. static inline void host1x_hw_cdma_resume(struct host1x *host,
  221. struct host1x_cdma *cdma, u32 getptr)
  222. {
  223. host->cdma_op->resume(cdma, getptr);
  224. }
  225. static inline void host1x_hw_cdma_timeout_cpu_incr(struct host1x *host,
  226. struct host1x_cdma *cdma,
  227. u32 getptr,
  228. u32 syncpt_incrs,
  229. u32 syncval, u32 nr_slots)
  230. {
  231. host->cdma_op->timeout_cpu_incr(cdma, getptr, syncpt_incrs, syncval,
  232. nr_slots);
  233. }
  234. static inline void host1x_hw_pushbuffer_init(struct host1x *host,
  235. struct push_buffer *pb)
  236. {
  237. host->cdma_pb_op->init(pb);
  238. }
  239. static inline void host1x_hw_debug_init(struct host1x *host, struct dentry *de)
  240. {
  241. if (host->debug_op && host->debug_op->debug_init)
  242. host->debug_op->debug_init(de);
  243. }
  244. static inline void host1x_hw_show_channel_cdma(struct host1x *host,
  245. struct host1x_channel *channel,
  246. struct output *o)
  247. {
  248. host->debug_op->show_channel_cdma(host, channel, o);
  249. }
  250. static inline void host1x_hw_show_channel_fifo(struct host1x *host,
  251. struct host1x_channel *channel,
  252. struct output *o)
  253. {
  254. host->debug_op->show_channel_fifo(host, channel, o);
  255. }
  256. static inline void host1x_hw_show_mlocks(struct host1x *host, struct output *o)
  257. {
  258. host->debug_op->show_mlocks(host, o);
  259. }
  260. extern struct platform_driver tegra_mipi_driver;
  261. #endif