host1x.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. u32 host1x_syncpt_read(struct host1x_syncpt *sp);
  113. int host1x_syncpt_incr(struct host1x_syncpt *sp);
  114. u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
  115. int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
  116. u32 *value);
  117. struct host1x_syncpt *host1x_syncpt_request(struct device *dev,
  118. unsigned long flags);
  119. void host1x_syncpt_free(struct host1x_syncpt *sp);
  120. struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
  121. u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
  122. /*
  123. * host1x channel
  124. */
  125. struct host1x_channel;
  126. struct host1x_job;
  127. struct host1x_channel *host1x_channel_request(struct device *dev);
  128. void host1x_channel_free(struct host1x_channel *channel);
  129. struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
  130. void host1x_channel_put(struct host1x_channel *channel);
  131. int host1x_job_submit(struct host1x_job *job);
  132. /*
  133. * host1x job
  134. */
  135. struct host1x_reloc {
  136. struct {
  137. struct host1x_bo *bo;
  138. unsigned long offset;
  139. } cmdbuf;
  140. struct {
  141. struct host1x_bo *bo;
  142. unsigned long offset;
  143. } target;
  144. unsigned long shift;
  145. };
  146. struct host1x_job {
  147. /* When refcount goes to zero, job can be freed */
  148. struct kref ref;
  149. /* List entry */
  150. struct list_head list;
  151. /* Channel where job is submitted to */
  152. struct host1x_channel *channel;
  153. u32 client;
  154. /* Gathers and their memory */
  155. struct host1x_job_gather *gathers;
  156. unsigned int num_gathers;
  157. /* Wait checks to be processed at submit time */
  158. struct host1x_waitchk *waitchk;
  159. unsigned int num_waitchk;
  160. u32 waitchk_mask;
  161. /* Array of handles to be pinned & unpinned */
  162. struct host1x_reloc *relocarray;
  163. unsigned int num_relocs;
  164. struct host1x_job_unpin_data *unpins;
  165. unsigned int num_unpins;
  166. dma_addr_t *addr_phys;
  167. dma_addr_t *gather_addr_phys;
  168. dma_addr_t *reloc_addr_phys;
  169. /* Sync point id, number of increments and end related to the submit */
  170. u32 syncpt_id;
  171. u32 syncpt_incrs;
  172. u32 syncpt_end;
  173. /* Maximum time to wait for this job */
  174. unsigned int timeout;
  175. /* Index and number of slots used in the push buffer */
  176. unsigned int first_get;
  177. unsigned int num_slots;
  178. /* Copy of gathers */
  179. size_t gather_copy_size;
  180. dma_addr_t gather_copy;
  181. u8 *gather_copy_mapped;
  182. /* Check if register is marked as an address reg */
  183. int (*is_addr_reg)(struct device *dev, u32 reg, u32 class);
  184. /* Request a SETCLASS to this class */
  185. u32 class;
  186. /* Add a channel wait for previous ops to complete */
  187. bool serialize;
  188. };
  189. struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
  190. u32 num_cmdbufs, u32 num_relocs,
  191. u32 num_waitchks);
  192. void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *mem_id,
  193. u32 words, u32 offset);
  194. struct host1x_job *host1x_job_get(struct host1x_job *job);
  195. void host1x_job_put(struct host1x_job *job);
  196. int host1x_job_pin(struct host1x_job *job, struct device *dev);
  197. void host1x_job_unpin(struct host1x_job *job);
  198. /*
  199. * subdevice probe infrastructure
  200. */
  201. struct host1x_device;
  202. struct host1x_driver {
  203. struct device_driver driver;
  204. const struct of_device_id *subdevs;
  205. struct list_head list;
  206. int (*probe)(struct host1x_device *device);
  207. int (*remove)(struct host1x_device *device);
  208. void (*shutdown)(struct host1x_device *device);
  209. };
  210. static inline struct host1x_driver *
  211. to_host1x_driver(struct device_driver *driver)
  212. {
  213. return container_of(driver, struct host1x_driver, driver);
  214. }
  215. int host1x_driver_register_full(struct host1x_driver *driver,
  216. struct module *owner);
  217. void host1x_driver_unregister(struct host1x_driver *driver);
  218. #define host1x_driver_register(driver) \
  219. host1x_driver_register_full(driver, THIS_MODULE)
  220. struct host1x_device {
  221. struct host1x_driver *driver;
  222. struct list_head list;
  223. struct device dev;
  224. struct mutex subdevs_lock;
  225. struct list_head subdevs;
  226. struct list_head active;
  227. struct mutex clients_lock;
  228. struct list_head clients;
  229. bool registered;
  230. };
  231. static inline struct host1x_device *to_host1x_device(struct device *dev)
  232. {
  233. return container_of(dev, struct host1x_device, dev);
  234. }
  235. int host1x_device_init(struct host1x_device *device);
  236. int host1x_device_exit(struct host1x_device *device);
  237. int host1x_client_register(struct host1x_client *client);
  238. int host1x_client_unregister(struct host1x_client *client);
  239. struct tegra_mipi_device;
  240. struct tegra_mipi_device *tegra_mipi_request(struct device *device);
  241. void tegra_mipi_free(struct tegra_mipi_device *device);
  242. int tegra_mipi_calibrate(struct tegra_mipi_device *device);
  243. #endif