dev.h 9.4 KB

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