dev.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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_channel;
  27. struct host1x_cdma;
  28. struct host1x_job;
  29. struct push_buffer;
  30. struct output;
  31. struct dentry;
  32. struct host1x_channel_ops {
  33. int (*init)(struct host1x_channel *channel, struct host1x *host,
  34. unsigned int id);
  35. int (*submit)(struct host1x_job *job);
  36. };
  37. struct host1x_cdma_ops {
  38. void (*start)(struct host1x_cdma *cdma);
  39. void (*stop)(struct host1x_cdma *cdma);
  40. void (*flush)(struct host1x_cdma *cdma);
  41. int (*timeout_init)(struct host1x_cdma *cdma, u32 syncpt_id);
  42. void (*timeout_destroy)(struct host1x_cdma *cdma);
  43. void (*freeze)(struct host1x_cdma *cdma);
  44. void (*resume)(struct host1x_cdma *cdma, u32 getptr);
  45. void (*timeout_cpu_incr)(struct host1x_cdma *cdma, u32 getptr,
  46. u32 syncpt_incrs, u32 syncval, u32 nr_slots);
  47. };
  48. struct host1x_pushbuffer_ops {
  49. void (*init)(struct push_buffer *pb);
  50. };
  51. struct host1x_debug_ops {
  52. void (*debug_init)(struct dentry *de);
  53. void (*show_channel_cdma)(struct host1x *host,
  54. struct host1x_channel *ch,
  55. struct output *o);
  56. void (*show_channel_fifo)(struct host1x *host,
  57. struct host1x_channel *ch,
  58. struct output *o);
  59. void (*show_mlocks)(struct host1x *host, struct output *output);
  60. };
  61. struct host1x_syncpt_ops {
  62. void (*restore)(struct host1x_syncpt *syncpt);
  63. void (*restore_wait_base)(struct host1x_syncpt *syncpt);
  64. void (*load_wait_base)(struct host1x_syncpt *syncpt);
  65. u32 (*load)(struct host1x_syncpt *syncpt);
  66. int (*cpu_incr)(struct host1x_syncpt *syncpt);
  67. int (*patch_wait)(struct host1x_syncpt *syncpt, void *patch_addr);
  68. };
  69. struct host1x_intr_ops {
  70. int (*init_host_sync)(struct host1x *host, u32 cpm,
  71. void (*syncpt_thresh_work)(struct work_struct *work));
  72. void (*set_syncpt_threshold)(
  73. struct host1x *host, u32 id, u32 thresh);
  74. void (*enable_syncpt_intr)(struct host1x *host, u32 id);
  75. void (*disable_syncpt_intr)(struct host1x *host, u32 id);
  76. void (*disable_all_syncpt_intrs)(struct host1x *host);
  77. int (*free_syncpt_irq)(struct host1x *host);
  78. };
  79. struct host1x_info {
  80. int nb_channels; /* host1x: num channels supported */
  81. int nb_pts; /* host1x: num syncpoints supported */
  82. int nb_bases; /* host1x: num syncpoints supported */
  83. int nb_mlocks; /* host1x: number of mlocks */
  84. int (*init)(struct host1x *); /* initialize per SoC ops */
  85. int sync_offset;
  86. };
  87. struct host1x {
  88. const struct host1x_info *info;
  89. void __iomem *regs;
  90. struct host1x_syncpt *syncpt;
  91. struct device *dev;
  92. struct clk *clk;
  93. struct mutex intr_mutex;
  94. struct workqueue_struct *intr_wq;
  95. int intr_syncpt_irq;
  96. const struct host1x_syncpt_ops *syncpt_op;
  97. const struct host1x_intr_ops *intr_op;
  98. const struct host1x_channel_ops *channel_op;
  99. const struct host1x_cdma_ops *cdma_op;
  100. const struct host1x_pushbuffer_ops *cdma_pb_op;
  101. const struct host1x_debug_ops *debug_op;
  102. struct host1x_syncpt *nop_sp;
  103. struct mutex chlist_mutex;
  104. struct host1x_channel chlist;
  105. unsigned long allocated_channels;
  106. unsigned int num_allocated_channels;
  107. struct dentry *debugfs;
  108. struct mutex devices_lock;
  109. struct list_head devices;
  110. struct list_head list;
  111. };
  112. void host1x_sync_writel(struct host1x *host1x, u32 r, u32 v);
  113. u32 host1x_sync_readl(struct host1x *host1x, u32 r);
  114. void host1x_ch_writel(struct host1x_channel *ch, u32 r, u32 v);
  115. u32 host1x_ch_readl(struct host1x_channel *ch, u32 r);
  116. static inline void host1x_hw_syncpt_restore(struct host1x *host,
  117. struct host1x_syncpt *sp)
  118. {
  119. host->syncpt_op->restore(sp);
  120. }
  121. static inline void host1x_hw_syncpt_restore_wait_base(struct host1x *host,
  122. struct host1x_syncpt *sp)
  123. {
  124. host->syncpt_op->restore_wait_base(sp);
  125. }
  126. static inline void host1x_hw_syncpt_load_wait_base(struct host1x *host,
  127. struct host1x_syncpt *sp)
  128. {
  129. host->syncpt_op->load_wait_base(sp);
  130. }
  131. static inline u32 host1x_hw_syncpt_load(struct host1x *host,
  132. struct host1x_syncpt *sp)
  133. {
  134. return host->syncpt_op->load(sp);
  135. }
  136. static inline int host1x_hw_syncpt_cpu_incr(struct host1x *host,
  137. struct host1x_syncpt *sp)
  138. {
  139. return host->syncpt_op->cpu_incr(sp);
  140. }
  141. static inline int host1x_hw_syncpt_patch_wait(struct host1x *host,
  142. struct host1x_syncpt *sp,
  143. void *patch_addr)
  144. {
  145. return host->syncpt_op->patch_wait(sp, patch_addr);
  146. }
  147. static inline int host1x_hw_intr_init_host_sync(struct host1x *host, u32 cpm,
  148. void (*syncpt_thresh_work)(struct work_struct *))
  149. {
  150. return host->intr_op->init_host_sync(host, cpm, syncpt_thresh_work);
  151. }
  152. static inline void host1x_hw_intr_set_syncpt_threshold(struct host1x *host,
  153. u32 id, u32 thresh)
  154. {
  155. host->intr_op->set_syncpt_threshold(host, id, thresh);
  156. }
  157. static inline void host1x_hw_intr_enable_syncpt_intr(struct host1x *host,
  158. u32 id)
  159. {
  160. host->intr_op->enable_syncpt_intr(host, id);
  161. }
  162. static inline void host1x_hw_intr_disable_syncpt_intr(struct host1x *host,
  163. u32 id)
  164. {
  165. host->intr_op->disable_syncpt_intr(host, id);
  166. }
  167. static inline void host1x_hw_intr_disable_all_syncpt_intrs(struct host1x *host)
  168. {
  169. host->intr_op->disable_all_syncpt_intrs(host);
  170. }
  171. static inline int host1x_hw_intr_free_syncpt_irq(struct host1x *host)
  172. {
  173. return host->intr_op->free_syncpt_irq(host);
  174. }
  175. static inline int host1x_hw_channel_init(struct host1x *host,
  176. struct host1x_channel *channel,
  177. int chid)
  178. {
  179. return host->channel_op->init(channel, host, chid);
  180. }
  181. static inline int host1x_hw_channel_submit(struct host1x *host,
  182. struct host1x_job *job)
  183. {
  184. return host->channel_op->submit(job);
  185. }
  186. static inline void host1x_hw_cdma_start(struct host1x *host,
  187. struct host1x_cdma *cdma)
  188. {
  189. host->cdma_op->start(cdma);
  190. }
  191. static inline void host1x_hw_cdma_stop(struct host1x *host,
  192. struct host1x_cdma *cdma)
  193. {
  194. host->cdma_op->stop(cdma);
  195. }
  196. static inline void host1x_hw_cdma_flush(struct host1x *host,
  197. struct host1x_cdma *cdma)
  198. {
  199. host->cdma_op->flush(cdma);
  200. }
  201. static inline int host1x_hw_cdma_timeout_init(struct host1x *host,
  202. struct host1x_cdma *cdma,
  203. u32 syncpt_id)
  204. {
  205. return host->cdma_op->timeout_init(cdma, syncpt_id);
  206. }
  207. static inline void host1x_hw_cdma_timeout_destroy(struct host1x *host,
  208. struct host1x_cdma *cdma)
  209. {
  210. host->cdma_op->timeout_destroy(cdma);
  211. }
  212. static inline void host1x_hw_cdma_freeze(struct host1x *host,
  213. struct host1x_cdma *cdma)
  214. {
  215. host->cdma_op->freeze(cdma);
  216. }
  217. static inline void host1x_hw_cdma_resume(struct host1x *host,
  218. struct host1x_cdma *cdma, u32 getptr)
  219. {
  220. host->cdma_op->resume(cdma, getptr);
  221. }
  222. static inline void host1x_hw_cdma_timeout_cpu_incr(struct host1x *host,
  223. struct host1x_cdma *cdma,
  224. u32 getptr,
  225. u32 syncpt_incrs,
  226. u32 syncval, u32 nr_slots)
  227. {
  228. host->cdma_op->timeout_cpu_incr(cdma, getptr, syncpt_incrs, syncval,
  229. nr_slots);
  230. }
  231. static inline void host1x_hw_pushbuffer_init(struct host1x *host,
  232. struct push_buffer *pb)
  233. {
  234. host->cdma_pb_op->init(pb);
  235. }
  236. static inline void host1x_hw_debug_init(struct host1x *host, struct dentry *de)
  237. {
  238. if (host->debug_op && host->debug_op->debug_init)
  239. host->debug_op->debug_init(de);
  240. }
  241. static inline void host1x_hw_show_channel_cdma(struct host1x *host,
  242. struct host1x_channel *channel,
  243. struct output *o)
  244. {
  245. host->debug_op->show_channel_cdma(host, channel, o);
  246. }
  247. static inline void host1x_hw_show_channel_fifo(struct host1x *host,
  248. struct host1x_channel *channel,
  249. struct output *o)
  250. {
  251. host->debug_op->show_channel_fifo(host, channel, o);
  252. }
  253. static inline void host1x_hw_show_mlocks(struct host1x *host, struct output *o)
  254. {
  255. host->debug_op->show_mlocks(host, o);
  256. }
  257. #endif