host1x.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*
  2. * Copyright (c) 2009-2013, NVIDIA Corporation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. */
  18. #ifndef __LINUX_HOST1X_H
  19. #define __LINUX_HOST1X_H
  20. #include <linux/device.h>
  21. #include <linux/types.h>
  22. enum host1x_class {
  23. HOST1X_CLASS_HOST1X = 0x1,
  24. HOST1X_CLASS_GR2D = 0x51,
  25. HOST1X_CLASS_GR2D_SB = 0x52,
  26. HOST1X_CLASS_GR3D = 0x60,
  27. };
  28. struct host1x_client;
  29. struct host1x_client_ops {
  30. int (*init)(struct host1x_client *client);
  31. int (*exit)(struct host1x_client *client);
  32. };
  33. struct host1x_client {
  34. struct list_head list;
  35. struct device *parent;
  36. struct device *dev;
  37. const struct host1x_client_ops *ops;
  38. enum host1x_class class;
  39. struct host1x_channel *channel;
  40. struct host1x_syncpt **syncpts;
  41. unsigned int num_syncpts;
  42. };
  43. /*
  44. * host1x buffer objects
  45. */
  46. struct host1x_bo;
  47. struct sg_table;
  48. struct host1x_bo_ops {
  49. struct host1x_bo *(*get)(struct host1x_bo *bo);
  50. void (*put)(struct host1x_bo *bo);
  51. dma_addr_t (*pin)(struct host1x_bo *bo, struct sg_table **sgt);
  52. void (*unpin)(struct host1x_bo *bo, struct sg_table *sgt);
  53. void *(*mmap)(struct host1x_bo *bo);
  54. void (*munmap)(struct host1x_bo *bo, void *addr);
  55. void *(*kmap)(struct host1x_bo *bo, unsigned int pagenum);
  56. void (*kunmap)(struct host1x_bo *bo, unsigned int pagenum, void *addr);
  57. };
  58. struct host1x_bo {
  59. const struct host1x_bo_ops *ops;
  60. };
  61. static inline void host1x_bo_init(struct host1x_bo *bo,
  62. const struct host1x_bo_ops *ops)
  63. {
  64. bo->ops = ops;
  65. }
  66. static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
  67. {
  68. return bo->ops->get(bo);
  69. }
  70. static inline void host1x_bo_put(struct host1x_bo *bo)
  71. {
  72. bo->ops->put(bo);
  73. }
  74. static inline dma_addr_t host1x_bo_pin(struct host1x_bo *bo,
  75. struct sg_table **sgt)
  76. {
  77. return bo->ops->pin(bo, sgt);
  78. }
  79. static inline void host1x_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt)
  80. {
  81. bo->ops->unpin(bo, sgt);
  82. }
  83. static inline void *host1x_bo_mmap(struct host1x_bo *bo)
  84. {
  85. return bo->ops->mmap(bo);
  86. }
  87. static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
  88. {
  89. bo->ops->munmap(bo, addr);
  90. }
  91. static inline void *host1x_bo_kmap(struct host1x_bo *bo, unsigned int pagenum)
  92. {
  93. return bo->ops->kmap(bo, pagenum);
  94. }
  95. static inline void host1x_bo_kunmap(struct host1x_bo *bo,
  96. unsigned int pagenum, void *addr)
  97. {
  98. bo->ops->kunmap(bo, pagenum, addr);
  99. }
  100. /*
  101. * host1x syncpoints
  102. */
  103. #define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
  104. #define HOST1X_SYNCPT_HAS_BASE (1 << 1)
  105. struct host1x_syncpt_base;
  106. struct host1x_syncpt;
  107. struct host1x;
  108. struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
  109. u32 host1x_syncpt_id(struct host1x_syncpt *sp);
  110. u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
  111. u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
  112. int host1x_syncpt_incr(struct host1x_syncpt *sp);
  113. u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
  114. int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
  115. u32 *value);
  116. struct host1x_syncpt *host1x_syncpt_request(struct device *dev,
  117. unsigned long flags);
  118. void host1x_syncpt_free(struct host1x_syncpt *sp);
  119. struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
  120. u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
  121. /*
  122. * host1x channel
  123. */
  124. struct host1x_channel;
  125. struct host1x_job;
  126. struct host1x_channel *host1x_channel_request(struct device *dev);
  127. void host1x_channel_free(struct host1x_channel *channel);
  128. struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
  129. void host1x_channel_put(struct host1x_channel *channel);
  130. int host1x_job_submit(struct host1x_job *job);
  131. /*
  132. * host1x job
  133. */
  134. struct host1x_reloc {
  135. struct {
  136. struct host1x_bo *bo;
  137. unsigned long offset;
  138. } cmdbuf;
  139. struct {
  140. struct host1x_bo *bo;
  141. unsigned long offset;
  142. } target;
  143. unsigned long shift;
  144. };
  145. struct host1x_job {
  146. /* When refcount goes to zero, job can be freed */
  147. struct kref ref;
  148. /* List entry */
  149. struct list_head list;
  150. /* Channel where job is submitted to */
  151. struct host1x_channel *channel;
  152. u32 client;
  153. /* Gathers and their memory */
  154. struct host1x_job_gather *gathers;
  155. unsigned int num_gathers;
  156. /* Wait checks to be processed at submit time */
  157. struct host1x_waitchk *waitchk;
  158. unsigned int num_waitchk;
  159. u32 waitchk_mask;
  160. /* Array of handles to be pinned & unpinned */
  161. struct host1x_reloc *relocarray;
  162. unsigned int num_relocs;
  163. struct host1x_job_unpin_data *unpins;
  164. unsigned int num_unpins;
  165. dma_addr_t *addr_phys;
  166. dma_addr_t *gather_addr_phys;
  167. dma_addr_t *reloc_addr_phys;
  168. /* Sync point id, number of increments and end related to the submit */
  169. u32 syncpt_id;
  170. u32 syncpt_incrs;
  171. u32 syncpt_end;
  172. /* Maximum time to wait for this job */
  173. unsigned int timeout;
  174. /* Index and number of slots used in the push buffer */
  175. unsigned int first_get;
  176. unsigned int num_slots;
  177. /* Copy of gathers */
  178. size_t gather_copy_size;
  179. dma_addr_t gather_copy;
  180. u8 *gather_copy_mapped;
  181. /* Check if register is marked as an address reg */
  182. int (*is_addr_reg)(struct device *dev, u32 reg, u32 class);
  183. /* Request a SETCLASS to this class */
  184. u32 class;
  185. /* Add a channel wait for previous ops to complete */
  186. bool serialize;
  187. };
  188. struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
  189. u32 num_cmdbufs, u32 num_relocs,
  190. u32 num_waitchks);
  191. void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *mem_id,
  192. u32 words, u32 offset);
  193. struct host1x_job *host1x_job_get(struct host1x_job *job);
  194. void host1x_job_put(struct host1x_job *job);
  195. int host1x_job_pin(struct host1x_job *job, struct device *dev);
  196. void host1x_job_unpin(struct host1x_job *job);
  197. /*
  198. * subdevice probe infrastructure
  199. */
  200. struct host1x_device;
  201. struct host1x_driver {
  202. struct device_driver driver;
  203. const struct of_device_id *subdevs;
  204. struct list_head list;
  205. int (*probe)(struct host1x_device *device);
  206. int (*remove)(struct host1x_device *device);
  207. void (*shutdown)(struct host1x_device *device);
  208. };
  209. static inline struct host1x_driver *
  210. to_host1x_driver(struct device_driver *driver)
  211. {
  212. return container_of(driver, struct host1x_driver, driver);
  213. }
  214. int host1x_driver_register_full(struct host1x_driver *driver,
  215. struct module *owner);
  216. void host1x_driver_unregister(struct host1x_driver *driver);
  217. #define host1x_driver_register(driver) \
  218. host1x_driver_register_full(driver, THIS_MODULE)
  219. struct host1x_device {
  220. struct host1x_driver *driver;
  221. struct list_head list;
  222. struct device dev;
  223. struct mutex subdevs_lock;
  224. struct list_head subdevs;
  225. struct list_head active;
  226. struct mutex clients_lock;
  227. struct list_head clients;
  228. bool registered;
  229. };
  230. static inline struct host1x_device *to_host1x_device(struct device *dev)
  231. {
  232. return container_of(dev, struct host1x_device, dev);
  233. }
  234. int host1x_device_init(struct host1x_device *device);
  235. int host1x_device_exit(struct host1x_device *device);
  236. int host1x_client_register(struct host1x_client *client);
  237. int host1x_client_unregister(struct host1x_client *client);
  238. struct tegra_mipi_device;
  239. struct tegra_mipi_device *tegra_mipi_request(struct device *device);
  240. void tegra_mipi_free(struct tegra_mipi_device *device);
  241. int tegra_mipi_calibrate(struct tegra_mipi_device *device);
  242. #endif