dev.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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, u32 syncpt_id);
  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, u32 id, u32 thresh);
  75. void (*enable_syncpt_intr)(struct host1x *host, u32 id);
  76. void (*disable_syncpt_intr)(struct host1x *host, u32 id);
  77. void (*disable_all_syncpt_intrs)(struct host1x *host);
  78. int (*free_syncpt_irq)(struct host1x *host);
  79. };
  80. struct host1x_info {
  81. int nb_channels; /* host1x: num channels supported */
  82. int nb_pts; /* host1x: num syncpoints supported */
  83. int nb_bases; /* host1x: num syncpoints supported */
  84. int nb_mlocks; /* host1x: number of mlocks */
  85. int (*init)(struct host1x *); /* initialize per SoC ops */
  86. int sync_offset;
  87. };
  88. struct host1x {
  89. const struct host1x_info *info;
  90. void __iomem *regs;
  91. struct host1x_syncpt *syncpt;
  92. struct host1x_syncpt_base *bases;
  93. struct device *dev;
  94. struct clk *clk;
  95. struct mutex intr_mutex;
  96. struct workqueue_struct *intr_wq;
  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. u32 id, u32 thresh)
  156. {
  157. host->intr_op->set_syncpt_threshold(host, id, thresh);
  158. }
  159. static inline void host1x_hw_intr_enable_syncpt_intr(struct host1x *host,
  160. u32 id)
  161. {
  162. host->intr_op->enable_syncpt_intr(host, id);
  163. }
  164. static inline void host1x_hw_intr_disable_syncpt_intr(struct host1x *host,
  165. u32 id)
  166. {
  167. host->intr_op->disable_syncpt_intr(host, id);
  168. }
  169. static inline void host1x_hw_intr_disable_all_syncpt_intrs(struct host1x *host)
  170. {
  171. host->intr_op->disable_all_syncpt_intrs(host);
  172. }
  173. static inline int host1x_hw_intr_free_syncpt_irq(struct host1x *host)
  174. {
  175. return host->intr_op->free_syncpt_irq(host);
  176. }
  177. static inline int host1x_hw_channel_init(struct host1x *host,
  178. struct host1x_channel *channel,
  179. int chid)
  180. {
  181. return host->channel_op->init(channel, host, chid);
  182. }
  183. static inline int host1x_hw_channel_submit(struct host1x *host,
  184. struct host1x_job *job)
  185. {
  186. return host->channel_op->submit(job);
  187. }
  188. static inline void host1x_hw_cdma_start(struct host1x *host,
  189. struct host1x_cdma *cdma)
  190. {
  191. host->cdma_op->start(cdma);
  192. }
  193. static inline void host1x_hw_cdma_stop(struct host1x *host,
  194. struct host1x_cdma *cdma)
  195. {
  196. host->cdma_op->stop(cdma);
  197. }
  198. static inline void host1x_hw_cdma_flush(struct host1x *host,
  199. struct host1x_cdma *cdma)
  200. {
  201. host->cdma_op->flush(cdma);
  202. }
  203. static inline int host1x_hw_cdma_timeout_init(struct host1x *host,
  204. struct host1x_cdma *cdma,
  205. u32 syncpt_id)
  206. {
  207. return host->cdma_op->timeout_init(cdma, syncpt_id);
  208. }
  209. static inline void host1x_hw_cdma_timeout_destroy(struct host1x *host,
  210. struct host1x_cdma *cdma)
  211. {
  212. host->cdma_op->timeout_destroy(cdma);
  213. }
  214. static inline void host1x_hw_cdma_freeze(struct host1x *host,
  215. struct host1x_cdma *cdma)
  216. {
  217. host->cdma_op->freeze(cdma);
  218. }
  219. static inline void host1x_hw_cdma_resume(struct host1x *host,
  220. struct host1x_cdma *cdma, u32 getptr)
  221. {
  222. host->cdma_op->resume(cdma, getptr);
  223. }
  224. static inline void host1x_hw_cdma_timeout_cpu_incr(struct host1x *host,
  225. struct host1x_cdma *cdma,
  226. u32 getptr,
  227. u32 syncpt_incrs,
  228. u32 syncval, u32 nr_slots)
  229. {
  230. host->cdma_op->timeout_cpu_incr(cdma, getptr, syncpt_incrs, syncval,
  231. nr_slots);
  232. }
  233. static inline void host1x_hw_pushbuffer_init(struct host1x *host,
  234. struct push_buffer *pb)
  235. {
  236. host->cdma_pb_op->init(pb);
  237. }
  238. static inline void host1x_hw_debug_init(struct host1x *host, struct dentry *de)
  239. {
  240. if (host->debug_op && host->debug_op->debug_init)
  241. host->debug_op->debug_init(de);
  242. }
  243. static inline void host1x_hw_show_channel_cdma(struct host1x *host,
  244. struct host1x_channel *channel,
  245. struct output *o)
  246. {
  247. host->debug_op->show_channel_cdma(host, channel, o);
  248. }
  249. static inline void host1x_hw_show_channel_fifo(struct host1x *host,
  250. struct host1x_channel *channel,
  251. struct output *o)
  252. {
  253. host->debug_op->show_channel_fifo(host, channel, o);
  254. }
  255. static inline void host1x_hw_show_mlocks(struct host1x *host, struct output *o)
  256. {
  257. host->debug_op->show_mlocks(host, o);
  258. }
  259. extern struct platform_driver tegra_mipi_driver;
  260. #endif