dev.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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/irqreturn.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/reset.h>
  13. #include "cdma.h"
  14. #include "channel.h"
  15. #include "context.h"
  16. #include "intr.h"
  17. #include "job.h"
  18. #include "syncpt.h"
  19. struct host1x_syncpt;
  20. struct host1x_syncpt_base;
  21. struct host1x_channel;
  22. struct host1x_cdma;
  23. struct host1x_job;
  24. struct push_buffer;
  25. struct output;
  26. struct dentry;
  27. struct host1x_channel_ops {
  28. int (*init)(struct host1x_channel *channel, struct host1x *host,
  29. unsigned int id);
  30. int (*submit)(struct host1x_job *job);
  31. };
  32. struct host1x_cdma_ops {
  33. void (*start)(struct host1x_cdma *cdma);
  34. void (*stop)(struct host1x_cdma *cdma);
  35. void (*flush)(struct host1x_cdma *cdma);
  36. int (*timeout_init)(struct host1x_cdma *cdma);
  37. void (*timeout_destroy)(struct host1x_cdma *cdma);
  38. void (*freeze)(struct host1x_cdma *cdma);
  39. void (*resume)(struct host1x_cdma *cdma, u32 getptr);
  40. void (*timeout_cpu_incr)(struct host1x_cdma *cdma, u32 getptr,
  41. u32 syncpt_incrs, u32 syncval, u32 nr_slots);
  42. };
  43. struct host1x_pushbuffer_ops {
  44. void (*init)(struct push_buffer *pb);
  45. };
  46. struct host1x_debug_ops {
  47. void (*debug_init)(struct dentry *de);
  48. void (*show_channel_cdma)(struct host1x *host,
  49. struct host1x_channel *ch,
  50. struct output *o);
  51. void (*show_channel_fifo)(struct host1x *host,
  52. struct host1x_channel *ch,
  53. struct output *o);
  54. void (*show_mlocks)(struct host1x *host, struct output *output);
  55. };
  56. struct host1x_syncpt_ops {
  57. void (*restore)(struct host1x_syncpt *syncpt);
  58. void (*restore_wait_base)(struct host1x_syncpt *syncpt);
  59. void (*load_wait_base)(struct host1x_syncpt *syncpt);
  60. u32 (*load)(struct host1x_syncpt *syncpt);
  61. int (*cpu_incr)(struct host1x_syncpt *syncpt);
  62. void (*assign_to_channel)(struct host1x_syncpt *syncpt,
  63. struct host1x_channel *channel);
  64. void (*enable_protection)(struct host1x *host);
  65. };
  66. struct host1x_intr_ops {
  67. int (*init_host_sync)(struct host1x *host, u32 cpm);
  68. void (*set_syncpt_threshold)(
  69. struct host1x *host, unsigned int id, u32 thresh);
  70. void (*enable_syncpt_intr)(struct host1x *host, unsigned int id);
  71. void (*disable_syncpt_intr)(struct host1x *host, unsigned int id);
  72. void (*disable_all_syncpt_intrs)(struct host1x *host);
  73. int (*free_syncpt_irq)(struct host1x *host);
  74. irqreturn_t (*isr)(int irq, void *dev_id);
  75. };
  76. struct host1x_sid_entry {
  77. unsigned int base;
  78. unsigned int offset;
  79. unsigned int limit;
  80. };
  81. struct host1x_table_desc {
  82. unsigned int base;
  83. unsigned int count;
  84. };
  85. struct host1x_info {
  86. unsigned int nb_channels; /* host1x: number of channels supported */
  87. unsigned int nb_pts; /* host1x: number of syncpoints supported */
  88. unsigned int nb_bases; /* host1x: number of syncpoint bases supported */
  89. unsigned int nb_mlocks; /* host1x: number of mlocks supported */
  90. int (*init)(struct host1x *host1x); /* initialize per SoC ops */
  91. unsigned int sync_offset; /* offset of syncpoint registers */
  92. u64 dma_mask; /* mask of addressable memory */
  93. bool has_wide_gather; /* supports GATHER_W opcode */
  94. bool has_hypervisor; /* has hypervisor registers */
  95. bool has_common; /* has common registers separate from hypervisor */
  96. unsigned int num_sid_entries;
  97. const struct host1x_sid_entry *sid_table;
  98. struct host1x_table_desc streamid_vm_table;
  99. struct host1x_table_desc classid_vm_table;
  100. struct host1x_table_desc mmio_vm_table;
  101. /*
  102. * On T20-T148, the boot chain may setup DC to increment syncpoints
  103. * 26/27 on VBLANK. As such we cannot use these syncpoints until
  104. * the display driver disables VBLANK increments.
  105. */
  106. bool reserve_vblank_syncpts;
  107. /*
  108. * On Tegra186, secure world applications may require access to
  109. * host1x during suspend/resume. To allow this, we need to leave
  110. * host1x not in reset.
  111. */
  112. bool skip_reset_assert;
  113. };
  114. struct host1x {
  115. const struct host1x_info *info;
  116. void __iomem *regs;
  117. void __iomem *hv_regs; /* hypervisor region */
  118. void __iomem *common_regs;
  119. int syncpt_irqs[8];
  120. int num_syncpt_irqs;
  121. struct host1x_syncpt *syncpt;
  122. struct host1x_syncpt_base *bases;
  123. struct device *dev;
  124. struct clk *clk;
  125. struct reset_control_bulk_data resets[2];
  126. unsigned int nresets;
  127. struct iommu_group *group;
  128. struct iommu_domain *domain;
  129. struct iova_domain iova;
  130. dma_addr_t iova_end;
  131. struct mutex intr_mutex;
  132. const struct host1x_syncpt_ops *syncpt_op;
  133. const struct host1x_intr_ops *intr_op;
  134. const struct host1x_channel_ops *channel_op;
  135. const struct host1x_cdma_ops *cdma_op;
  136. const struct host1x_pushbuffer_ops *cdma_pb_op;
  137. const struct host1x_debug_ops *debug_op;
  138. struct host1x_syncpt *nop_sp;
  139. struct mutex syncpt_mutex;
  140. struct host1x_channel_list channel_list;
  141. struct host1x_memory_context_list context_list;
  142. struct dentry *debugfs;
  143. struct mutex devices_lock;
  144. struct list_head devices;
  145. struct list_head list;
  146. struct device_dma_parameters dma_parms;
  147. struct host1x_bo_cache cache;
  148. };
  149. void host1x_common_writel(struct host1x *host1x, u32 v, u32 r);
  150. void host1x_hypervisor_writel(struct host1x *host1x, u32 r, u32 v);
  151. u32 host1x_hypervisor_readl(struct host1x *host1x, u32 r);
  152. void host1x_sync_writel(struct host1x *host1x, u32 r, u32 v);
  153. u32 host1x_sync_readl(struct host1x *host1x, u32 r);
  154. void host1x_ch_writel(struct host1x_channel *ch, u32 r, u32 v);
  155. u32 host1x_ch_readl(struct host1x_channel *ch, u32 r);
  156. static inline void host1x_hw_syncpt_restore(struct host1x *host,
  157. struct host1x_syncpt *sp)
  158. {
  159. host->syncpt_op->restore(sp);
  160. }
  161. static inline void host1x_hw_syncpt_restore_wait_base(struct host1x *host,
  162. struct host1x_syncpt *sp)
  163. {
  164. host->syncpt_op->restore_wait_base(sp);
  165. }
  166. static inline void host1x_hw_syncpt_load_wait_base(struct host1x *host,
  167. struct host1x_syncpt *sp)
  168. {
  169. host->syncpt_op->load_wait_base(sp);
  170. }
  171. static inline u32 host1x_hw_syncpt_load(struct host1x *host,
  172. struct host1x_syncpt *sp)
  173. {
  174. return host->syncpt_op->load(sp);
  175. }
  176. static inline int host1x_hw_syncpt_cpu_incr(struct host1x *host,
  177. struct host1x_syncpt *sp)
  178. {
  179. return host->syncpt_op->cpu_incr(sp);
  180. }
  181. static inline void host1x_hw_syncpt_assign_to_channel(
  182. struct host1x *host, struct host1x_syncpt *sp,
  183. struct host1x_channel *ch)
  184. {
  185. return host->syncpt_op->assign_to_channel(sp, ch);
  186. }
  187. static inline void host1x_hw_syncpt_enable_protection(struct host1x *host)
  188. {
  189. return host->syncpt_op->enable_protection(host);
  190. }
  191. static inline int host1x_hw_intr_init_host_sync(struct host1x *host, u32 cpm)
  192. {
  193. return host->intr_op->init_host_sync(host, cpm);
  194. }
  195. static inline void host1x_hw_intr_set_syncpt_threshold(struct host1x *host,
  196. unsigned int id,
  197. u32 thresh)
  198. {
  199. host->intr_op->set_syncpt_threshold(host, id, thresh);
  200. }
  201. static inline void host1x_hw_intr_enable_syncpt_intr(struct host1x *host,
  202. unsigned int id)
  203. {
  204. host->intr_op->enable_syncpt_intr(host, id);
  205. }
  206. static inline void host1x_hw_intr_disable_syncpt_intr(struct host1x *host,
  207. unsigned int id)
  208. {
  209. host->intr_op->disable_syncpt_intr(host, id);
  210. }
  211. static inline void host1x_hw_intr_disable_all_syncpt_intrs(struct host1x *host)
  212. {
  213. host->intr_op->disable_all_syncpt_intrs(host);
  214. }
  215. static inline int host1x_hw_intr_free_syncpt_irq(struct host1x *host)
  216. {
  217. return host->intr_op->free_syncpt_irq(host);
  218. }
  219. static inline int host1x_hw_channel_init(struct host1x *host,
  220. struct host1x_channel *channel,
  221. unsigned int id)
  222. {
  223. return host->channel_op->init(channel, host, id);
  224. }
  225. static inline int host1x_hw_channel_submit(struct host1x *host,
  226. struct host1x_job *job)
  227. {
  228. return host->channel_op->submit(job);
  229. }
  230. static inline void host1x_hw_cdma_start(struct host1x *host,
  231. struct host1x_cdma *cdma)
  232. {
  233. host->cdma_op->start(cdma);
  234. }
  235. static inline void host1x_hw_cdma_stop(struct host1x *host,
  236. struct host1x_cdma *cdma)
  237. {
  238. host->cdma_op->stop(cdma);
  239. }
  240. static inline void host1x_hw_cdma_flush(struct host1x *host,
  241. struct host1x_cdma *cdma)
  242. {
  243. host->cdma_op->flush(cdma);
  244. }
  245. static inline int host1x_hw_cdma_timeout_init(struct host1x *host,
  246. struct host1x_cdma *cdma)
  247. {
  248. return host->cdma_op->timeout_init(cdma);
  249. }
  250. static inline void host1x_hw_cdma_timeout_destroy(struct host1x *host,
  251. struct host1x_cdma *cdma)
  252. {
  253. host->cdma_op->timeout_destroy(cdma);
  254. }
  255. static inline void host1x_hw_cdma_freeze(struct host1x *host,
  256. struct host1x_cdma *cdma)
  257. {
  258. host->cdma_op->freeze(cdma);
  259. }
  260. static inline void host1x_hw_cdma_resume(struct host1x *host,
  261. struct host1x_cdma *cdma, u32 getptr)
  262. {
  263. host->cdma_op->resume(cdma, getptr);
  264. }
  265. static inline void host1x_hw_cdma_timeout_cpu_incr(struct host1x *host,
  266. struct host1x_cdma *cdma,
  267. u32 getptr,
  268. u32 syncpt_incrs,
  269. u32 syncval, u32 nr_slots)
  270. {
  271. host->cdma_op->timeout_cpu_incr(cdma, getptr, syncpt_incrs, syncval,
  272. nr_slots);
  273. }
  274. static inline void host1x_hw_pushbuffer_init(struct host1x *host,
  275. struct push_buffer *pb)
  276. {
  277. host->cdma_pb_op->init(pb);
  278. }
  279. static inline void host1x_hw_debug_init(struct host1x *host, struct dentry *de)
  280. {
  281. if (host->debug_op && host->debug_op->debug_init)
  282. host->debug_op->debug_init(de);
  283. }
  284. static inline void host1x_hw_show_channel_cdma(struct host1x *host,
  285. struct host1x_channel *channel,
  286. struct output *o)
  287. {
  288. host->debug_op->show_channel_cdma(host, channel, o);
  289. }
  290. static inline void host1x_hw_show_channel_fifo(struct host1x *host,
  291. struct host1x_channel *channel,
  292. struct output *o)
  293. {
  294. host->debug_op->show_channel_fifo(host, channel, o);
  295. }
  296. static inline void host1x_hw_show_mlocks(struct host1x *host, struct output *o)
  297. {
  298. host->debug_op->show_mlocks(host, o);
  299. }
  300. extern struct platform_driver tegra_mipi_driver;
  301. #endif