host1x.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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_VIC = 0x5D,
  27. HOST1X_CLASS_GR3D = 0x60,
  28. };
  29. struct host1x_client;
  30. /**
  31. * struct host1x_client_ops - host1x client operations
  32. * @init: host1x client initialization code
  33. * @exit: host1x client tear down code
  34. */
  35. struct host1x_client_ops {
  36. int (*init)(struct host1x_client *client);
  37. int (*exit)(struct host1x_client *client);
  38. };
  39. /**
  40. * struct host1x_client - host1x client structure
  41. * @list: list node for the host1x client
  42. * @parent: pointer to struct device representing the host1x controller
  43. * @dev: pointer to struct device backing this host1x client
  44. * @ops: host1x client operations
  45. * @class: host1x class represented by this client
  46. * @channel: host1x channel associated with this client
  47. * @syncpts: array of syncpoints requested for this client
  48. * @num_syncpts: number of syncpoints requested for this client
  49. */
  50. struct host1x_client {
  51. struct list_head list;
  52. struct device *parent;
  53. struct device *dev;
  54. const struct host1x_client_ops *ops;
  55. enum host1x_class class;
  56. struct host1x_channel *channel;
  57. struct host1x_syncpt **syncpts;
  58. unsigned int num_syncpts;
  59. };
  60. /*
  61. * host1x buffer objects
  62. */
  63. struct host1x_bo;
  64. struct sg_table;
  65. struct host1x_bo_ops {
  66. struct host1x_bo *(*get)(struct host1x_bo *bo);
  67. void (*put)(struct host1x_bo *bo);
  68. dma_addr_t (*pin)(struct host1x_bo *bo, struct sg_table **sgt);
  69. void (*unpin)(struct host1x_bo *bo, struct sg_table *sgt);
  70. void *(*mmap)(struct host1x_bo *bo);
  71. void (*munmap)(struct host1x_bo *bo, void *addr);
  72. void *(*kmap)(struct host1x_bo *bo, unsigned int pagenum);
  73. void (*kunmap)(struct host1x_bo *bo, unsigned int pagenum, void *addr);
  74. };
  75. struct host1x_bo {
  76. const struct host1x_bo_ops *ops;
  77. };
  78. static inline void host1x_bo_init(struct host1x_bo *bo,
  79. const struct host1x_bo_ops *ops)
  80. {
  81. bo->ops = ops;
  82. }
  83. static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
  84. {
  85. return bo->ops->get(bo);
  86. }
  87. static inline void host1x_bo_put(struct host1x_bo *bo)
  88. {
  89. bo->ops->put(bo);
  90. }
  91. static inline dma_addr_t host1x_bo_pin(struct host1x_bo *bo,
  92. struct sg_table **sgt)
  93. {
  94. return bo->ops->pin(bo, sgt);
  95. }
  96. static inline void host1x_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt)
  97. {
  98. bo->ops->unpin(bo, sgt);
  99. }
  100. static inline void *host1x_bo_mmap(struct host1x_bo *bo)
  101. {
  102. return bo->ops->mmap(bo);
  103. }
  104. static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
  105. {
  106. bo->ops->munmap(bo, addr);
  107. }
  108. static inline void *host1x_bo_kmap(struct host1x_bo *bo, unsigned int pagenum)
  109. {
  110. return bo->ops->kmap(bo, pagenum);
  111. }
  112. static inline void host1x_bo_kunmap(struct host1x_bo *bo,
  113. unsigned int pagenum, void *addr)
  114. {
  115. bo->ops->kunmap(bo, pagenum, addr);
  116. }
  117. /*
  118. * host1x syncpoints
  119. */
  120. #define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
  121. #define HOST1X_SYNCPT_HAS_BASE (1 << 1)
  122. struct host1x_syncpt_base;
  123. struct host1x_syncpt;
  124. struct host1x;
  125. struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
  126. u32 host1x_syncpt_id(struct host1x_syncpt *sp);
  127. u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
  128. u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
  129. u32 host1x_syncpt_read(struct host1x_syncpt *sp);
  130. int host1x_syncpt_incr(struct host1x_syncpt *sp);
  131. u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
  132. int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
  133. u32 *value);
  134. struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client,
  135. unsigned long flags);
  136. void host1x_syncpt_free(struct host1x_syncpt *sp);
  137. struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
  138. u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
  139. /*
  140. * host1x channel
  141. */
  142. struct host1x_channel;
  143. struct host1x_job;
  144. struct host1x_channel *host1x_channel_request(struct device *dev);
  145. struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
  146. void host1x_channel_put(struct host1x_channel *channel);
  147. int host1x_job_submit(struct host1x_job *job);
  148. /*
  149. * host1x job
  150. */
  151. struct host1x_reloc {
  152. struct {
  153. struct host1x_bo *bo;
  154. unsigned long offset;
  155. } cmdbuf;
  156. struct {
  157. struct host1x_bo *bo;
  158. unsigned long offset;
  159. } target;
  160. unsigned long shift;
  161. };
  162. struct host1x_job {
  163. /* When refcount goes to zero, job can be freed */
  164. struct kref ref;
  165. /* List entry */
  166. struct list_head list;
  167. /* Channel where job is submitted to */
  168. struct host1x_channel *channel;
  169. /* client where the job originated */
  170. struct host1x_client *client;
  171. /* Gathers and their memory */
  172. struct host1x_job_gather *gathers;
  173. unsigned int num_gathers;
  174. /* Array of handles to be pinned & unpinned */
  175. struct host1x_reloc *relocs;
  176. unsigned int num_relocs;
  177. struct host1x_job_unpin_data *unpins;
  178. unsigned int num_unpins;
  179. dma_addr_t *addr_phys;
  180. dma_addr_t *gather_addr_phys;
  181. dma_addr_t *reloc_addr_phys;
  182. /* Sync point id, number of increments and end related to the submit */
  183. u32 syncpt_id;
  184. u32 syncpt_incrs;
  185. u32 syncpt_end;
  186. /* Maximum time to wait for this job */
  187. unsigned int timeout;
  188. /* Index and number of slots used in the push buffer */
  189. unsigned int first_get;
  190. unsigned int num_slots;
  191. /* Copy of gathers */
  192. size_t gather_copy_size;
  193. dma_addr_t gather_copy;
  194. u8 *gather_copy_mapped;
  195. /* Check if register is marked as an address reg */
  196. int (*is_addr_reg)(struct device *dev, u32 class, u32 reg);
  197. /* Check if class belongs to the unit */
  198. int (*is_valid_class)(u32 class);
  199. /* Request a SETCLASS to this class */
  200. u32 class;
  201. /* Add a channel wait for previous ops to complete */
  202. bool serialize;
  203. };
  204. struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
  205. u32 num_cmdbufs, u32 num_relocs);
  206. void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *bo,
  207. unsigned int words, unsigned int offset);
  208. struct host1x_job *host1x_job_get(struct host1x_job *job);
  209. void host1x_job_put(struct host1x_job *job);
  210. int host1x_job_pin(struct host1x_job *job, struct device *dev);
  211. void host1x_job_unpin(struct host1x_job *job);
  212. /*
  213. * subdevice probe infrastructure
  214. */
  215. struct host1x_device;
  216. /**
  217. * struct host1x_driver - host1x logical device driver
  218. * @driver: core driver
  219. * @subdevs: table of OF device IDs matching subdevices for this driver
  220. * @list: list node for the driver
  221. * @probe: called when the host1x logical device is probed
  222. * @remove: called when the host1x logical device is removed
  223. * @shutdown: called when the host1x logical device is shut down
  224. */
  225. struct host1x_driver {
  226. struct device_driver driver;
  227. const struct of_device_id *subdevs;
  228. struct list_head list;
  229. int (*probe)(struct host1x_device *device);
  230. int (*remove)(struct host1x_device *device);
  231. void (*shutdown)(struct host1x_device *device);
  232. };
  233. static inline struct host1x_driver *
  234. to_host1x_driver(struct device_driver *driver)
  235. {
  236. return container_of(driver, struct host1x_driver, driver);
  237. }
  238. int host1x_driver_register_full(struct host1x_driver *driver,
  239. struct module *owner);
  240. void host1x_driver_unregister(struct host1x_driver *driver);
  241. #define host1x_driver_register(driver) \
  242. host1x_driver_register_full(driver, THIS_MODULE)
  243. struct host1x_device {
  244. struct host1x_driver *driver;
  245. struct list_head list;
  246. struct device dev;
  247. struct mutex subdevs_lock;
  248. struct list_head subdevs;
  249. struct list_head active;
  250. struct mutex clients_lock;
  251. struct list_head clients;
  252. bool registered;
  253. struct device_dma_parameters dma_parms;
  254. };
  255. static inline struct host1x_device *to_host1x_device(struct device *dev)
  256. {
  257. return container_of(dev, struct host1x_device, dev);
  258. }
  259. int host1x_device_init(struct host1x_device *device);
  260. int host1x_device_exit(struct host1x_device *device);
  261. int host1x_client_register(struct host1x_client *client);
  262. int host1x_client_unregister(struct host1x_client *client);
  263. struct tegra_mipi_device;
  264. struct tegra_mipi_device *tegra_mipi_request(struct device *device);
  265. void tegra_mipi_free(struct tegra_mipi_device *device);
  266. int tegra_mipi_enable(struct tegra_mipi_device *device);
  267. int tegra_mipi_disable(struct tegra_mipi_device *device);
  268. int tegra_mipi_calibrate(struct tegra_mipi_device *device);
  269. #endif