dev.h 8.8 KB

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