host1x.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. };
  27. struct host1x_client;
  28. struct host1x_client_ops {
  29. int (*init)(struct host1x_client *client);
  30. int (*exit)(struct host1x_client *client);
  31. };
  32. struct host1x_client {
  33. struct list_head list;
  34. struct device *parent;
  35. struct device *dev;
  36. const struct host1x_client_ops *ops;
  37. enum host1x_class class;
  38. struct host1x_channel *channel;
  39. struct host1x_syncpt **syncpts;
  40. unsigned int num_syncpts;
  41. };
  42. /*
  43. * host1x buffer objects
  44. */
  45. struct host1x_bo;
  46. struct sg_table;
  47. struct host1x_bo_ops {
  48. struct host1x_bo *(*get)(struct host1x_bo *bo);
  49. void (*put)(struct host1x_bo *bo);
  50. dma_addr_t (*pin)(struct host1x_bo *bo, struct sg_table **sgt);
  51. void (*unpin)(struct host1x_bo *bo, struct sg_table *sgt);
  52. void *(*mmap)(struct host1x_bo *bo);
  53. void (*munmap)(struct host1x_bo *bo, void *addr);
  54. void *(*kmap)(struct host1x_bo *bo, unsigned int pagenum);
  55. void (*kunmap)(struct host1x_bo *bo, unsigned int pagenum, void *addr);
  56. };
  57. struct host1x_bo {
  58. const struct host1x_bo_ops *ops;
  59. };
  60. static inline void host1x_bo_init(struct host1x_bo *bo,
  61. const struct host1x_bo_ops *ops)
  62. {
  63. bo->ops = ops;
  64. }
  65. static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
  66. {
  67. return bo->ops->get(bo);
  68. }
  69. static inline void host1x_bo_put(struct host1x_bo *bo)
  70. {
  71. bo->ops->put(bo);
  72. }
  73. static inline dma_addr_t host1x_bo_pin(struct host1x_bo *bo,
  74. struct sg_table **sgt)
  75. {
  76. return bo->ops->pin(bo, sgt);
  77. }
  78. static inline void host1x_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt)
  79. {
  80. bo->ops->unpin(bo, sgt);
  81. }
  82. static inline void *host1x_bo_mmap(struct host1x_bo *bo)
  83. {
  84. return bo->ops->mmap(bo);
  85. }
  86. static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
  87. {
  88. bo->ops->munmap(bo, addr);
  89. }
  90. static inline void *host1x_bo_kmap(struct host1x_bo *bo, unsigned int pagenum)
  91. {
  92. return bo->ops->kmap(bo, pagenum);
  93. }
  94. static inline void host1x_bo_kunmap(struct host1x_bo *bo,
  95. unsigned int pagenum, void *addr)
  96. {
  97. bo->ops->kunmap(bo, pagenum, addr);
  98. }
  99. /*
  100. * host1x syncpoints
  101. */
  102. struct host1x_syncpt;
  103. struct host1x;
  104. struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
  105. u32 host1x_syncpt_id(struct host1x_syncpt *sp);
  106. u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
  107. u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
  108. int host1x_syncpt_incr(struct host1x_syncpt *sp);
  109. int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
  110. u32 *value);
  111. struct host1x_syncpt *host1x_syncpt_request(struct device *dev,
  112. bool client_managed);
  113. void host1x_syncpt_free(struct host1x_syncpt *sp);
  114. /*
  115. * host1x channel
  116. */
  117. struct host1x_channel;
  118. struct host1x_job;
  119. struct host1x_channel *host1x_channel_request(struct device *dev);
  120. void host1x_channel_free(struct host1x_channel *channel);
  121. struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
  122. void host1x_channel_put(struct host1x_channel *channel);
  123. int host1x_job_submit(struct host1x_job *job);
  124. /*
  125. * host1x job
  126. */
  127. struct host1x_reloc {
  128. struct host1x_bo *cmdbuf;
  129. u32 cmdbuf_offset;
  130. struct host1x_bo *target;
  131. u32 target_offset;
  132. u32 shift;
  133. u32 pad;
  134. };
  135. struct host1x_job {
  136. /* When refcount goes to zero, job can be freed */
  137. struct kref ref;
  138. /* List entry */
  139. struct list_head list;
  140. /* Channel where job is submitted to */
  141. struct host1x_channel *channel;
  142. u32 client;
  143. /* Gathers and their memory */
  144. struct host1x_job_gather *gathers;
  145. unsigned int num_gathers;
  146. /* Wait checks to be processed at submit time */
  147. struct host1x_waitchk *waitchk;
  148. unsigned int num_waitchk;
  149. u32 waitchk_mask;
  150. /* Array of handles to be pinned & unpinned */
  151. struct host1x_reloc *relocarray;
  152. unsigned int num_relocs;
  153. struct host1x_job_unpin_data *unpins;
  154. unsigned int num_unpins;
  155. dma_addr_t *addr_phys;
  156. dma_addr_t *gather_addr_phys;
  157. dma_addr_t *reloc_addr_phys;
  158. /* Sync point id, number of increments and end related to the submit */
  159. u32 syncpt_id;
  160. u32 syncpt_incrs;
  161. u32 syncpt_end;
  162. /* Maximum time to wait for this job */
  163. unsigned int timeout;
  164. /* Index and number of slots used in the push buffer */
  165. unsigned int first_get;
  166. unsigned int num_slots;
  167. /* Copy of gathers */
  168. size_t gather_copy_size;
  169. dma_addr_t gather_copy;
  170. u8 *gather_copy_mapped;
  171. /* Check if register is marked as an address reg */
  172. int (*is_addr_reg)(struct device *dev, u32 reg, u32 class);
  173. /* Request a SETCLASS to this class */
  174. u32 class;
  175. /* Add a channel wait for previous ops to complete */
  176. bool serialize;
  177. };
  178. struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
  179. u32 num_cmdbufs, u32 num_relocs,
  180. u32 num_waitchks);
  181. void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *mem_id,
  182. u32 words, u32 offset);
  183. struct host1x_job *host1x_job_get(struct host1x_job *job);
  184. void host1x_job_put(struct host1x_job *job);
  185. int host1x_job_pin(struct host1x_job *job, struct device *dev);
  186. void host1x_job_unpin(struct host1x_job *job);
  187. /*
  188. * subdevice probe infrastructure
  189. */
  190. struct host1x_device;
  191. struct host1x_driver {
  192. const struct of_device_id *subdevs;
  193. struct list_head list;
  194. const char *name;
  195. int (*probe)(struct host1x_device *device);
  196. int (*remove)(struct host1x_device *device);
  197. };
  198. int host1x_driver_register(struct host1x_driver *driver);
  199. void host1x_driver_unregister(struct host1x_driver *driver);
  200. struct host1x_device {
  201. struct host1x_driver *driver;
  202. struct list_head list;
  203. struct device dev;
  204. struct mutex subdevs_lock;
  205. struct list_head subdevs;
  206. struct list_head active;
  207. struct mutex clients_lock;
  208. struct list_head clients;
  209. };
  210. static inline struct host1x_device *to_host1x_device(struct device *dev)
  211. {
  212. return container_of(dev, struct host1x_device, dev);
  213. }
  214. int host1x_device_init(struct host1x_device *device);
  215. int host1x_device_exit(struct host1x_device *device);
  216. int host1x_client_register(struct host1x_client *client);
  217. int host1x_client_unregister(struct host1x_client *client);
  218. #endif