mdp-4-subdev.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #include <linux/msm_mdp.h>
  14. #include <linux/slab.h>
  15. #include <mach/iommu_domains.h>
  16. #include <media/videobuf2-core.h>
  17. #include "enc-subdev.h"
  18. #include "mdp-subdev.h"
  19. #include "wfd-util.h"
  20. struct mdp_instance {
  21. struct fb_info *mdp;
  22. u32 height;
  23. u32 width;
  24. bool secure;
  25. bool uses_iommu_split_domain;
  26. };
  27. int mdp_init(struct v4l2_subdev *sd, u32 val)
  28. {
  29. return 0;
  30. }
  31. int mdp_open(struct v4l2_subdev *sd, void *arg)
  32. {
  33. struct mdp_instance *inst = kzalloc(sizeof(struct mdp_instance),
  34. GFP_KERNEL);
  35. struct mdp_msg_ops *mops = arg;
  36. int rc = 0;
  37. struct fb_info *fbi = NULL;
  38. if (!inst) {
  39. WFD_MSG_ERR("Out of memory\n");
  40. rc = -ENOMEM;
  41. goto mdp_open_fail;
  42. } else if (!mops) {
  43. WFD_MSG_ERR("Invalid arguments\n");
  44. rc = -EINVAL;
  45. goto mdp_open_fail;
  46. }
  47. fbi = msm_fb_get_writeback_fb();
  48. if (!fbi) {
  49. WFD_MSG_ERR("Failed to acquire mdp instance\n");
  50. rc = -ENODEV;
  51. goto mdp_open_fail;
  52. }
  53. msm_fb_writeback_init(fbi);
  54. inst->mdp = fbi;
  55. inst->secure = mops->secure;
  56. inst->uses_iommu_split_domain = mops->iommu_split_domain;
  57. mops->cookie = inst;
  58. return rc;
  59. mdp_open_fail:
  60. kfree(inst);
  61. return rc;
  62. }
  63. int mdp_start(struct v4l2_subdev *sd, void *arg)
  64. {
  65. struct mdp_instance *inst = arg;
  66. int rc = 0;
  67. struct fb_info *fbi = NULL;
  68. if (inst) {
  69. rc = msm_fb_writeback_start(inst->mdp);
  70. if (rc) {
  71. WFD_MSG_ERR("Failed to start MDP mode\n");
  72. goto exit;
  73. }
  74. fbi = msm_fb_get_writeback_fb();
  75. if (!fbi) {
  76. WFD_MSG_ERR("Failed to acquire mdp instance\n");
  77. rc = -ENODEV;
  78. goto exit;
  79. }
  80. }
  81. exit:
  82. return rc;
  83. }
  84. int mdp_stop(struct v4l2_subdev *sd, void *arg)
  85. {
  86. struct mdp_instance *inst = arg;
  87. int rc = 0;
  88. struct fb_info *fbi = NULL;
  89. if (inst) {
  90. rc = msm_fb_writeback_stop(inst->mdp);
  91. if (rc) {
  92. WFD_MSG_ERR("Failed to stop writeback mode\n");
  93. return rc;
  94. }
  95. fbi = (struct fb_info *)inst->mdp;
  96. }
  97. return 0;
  98. }
  99. int mdp_close(struct v4l2_subdev *sd, void *arg)
  100. {
  101. struct mdp_instance *inst = arg;
  102. struct fb_info *fbi = NULL;
  103. if (inst) {
  104. fbi = (struct fb_info *)inst->mdp;
  105. msm_fb_writeback_terminate(fbi);
  106. kfree(inst);
  107. }
  108. return 0;
  109. }
  110. int mdp_q_buffer(struct v4l2_subdev *sd, void *arg)
  111. {
  112. int rc = 0;
  113. struct mdp_buf_info *binfo = arg;
  114. struct msmfb_data fbdata;
  115. struct mdp_instance *inst;
  116. if (!binfo || !binfo->inst || !binfo->cookie) {
  117. WFD_MSG_ERR("Invalid argument\n");
  118. return -EINVAL;
  119. }
  120. inst = binfo->inst;
  121. fbdata.offset = binfo->offset;
  122. fbdata.memory_id = binfo->fd;
  123. fbdata.iova = binfo->paddr;
  124. fbdata.id = 0;
  125. fbdata.flags = 0;
  126. fbdata.priv = (uint32_t)binfo->cookie;
  127. WFD_MSG_INFO("queue buffer to mdp with offset = %u, fd = %u, "\
  128. "priv = %p, iova = %p\n",
  129. fbdata.offset, fbdata.memory_id,
  130. (void *)fbdata.priv, (void *)fbdata.iova);
  131. rc = msm_fb_writeback_queue_buffer(inst->mdp, &fbdata);
  132. if (rc)
  133. WFD_MSG_ERR("Failed to queue buffer\n");
  134. return rc;
  135. }
  136. int mdp_dq_buffer(struct v4l2_subdev *sd, void *arg)
  137. {
  138. int rc = 0;
  139. struct mdp_buf_info *obuf = arg;
  140. struct msmfb_data fbdata;
  141. struct mdp_instance *inst;
  142. if (!arg) {
  143. WFD_MSG_ERR("Invalid argument\n");
  144. return -EINVAL;
  145. }
  146. inst = obuf->inst;
  147. fbdata.flags = MSMFB_WRITEBACK_DEQUEUE_BLOCKING;
  148. rc = msm_fb_writeback_dequeue_buffer(inst->mdp, &fbdata);
  149. if (rc) {
  150. WFD_MSG_ERR("Failed to dequeue buffer\n");
  151. return rc;
  152. }
  153. WFD_MSG_DBG("dequeue buf from mdp with priv = %u\n",
  154. fbdata.priv);
  155. obuf->cookie = (void *)fbdata.priv;
  156. return rc;
  157. }
  158. int mdp_set_prop(struct v4l2_subdev *sd, void *arg)
  159. {
  160. struct mdp_prop *prop = (struct mdp_prop *)arg;
  161. struct mdp_instance *inst = prop->inst;
  162. if (!prop || !inst) {
  163. WFD_MSG_ERR("Invalid arguments\n");
  164. return -EINVAL;
  165. }
  166. inst->height = prop->height;
  167. inst->width = prop->width;
  168. return 0;
  169. }
  170. int mdp_mmap(struct v4l2_subdev *sd, void *arg)
  171. {
  172. int rc = 0, domain = -1;
  173. struct mem_region_map *mmap = arg;
  174. struct mem_region *mregion;
  175. bool use_iommu = true;
  176. struct mdp_instance *inst = NULL;
  177. if (!mmap || !mmap->mregion || !mmap->cookie) {
  178. WFD_MSG_ERR("Invalid argument\n");
  179. return -EINVAL;
  180. }
  181. inst = mmap->cookie;
  182. mregion = mmap->mregion;
  183. if (mregion->size % SZ_4K != 0) {
  184. WFD_MSG_ERR("Memregion not aligned to %d\n", SZ_4K);
  185. return -EINVAL;
  186. }
  187. if (inst->uses_iommu_split_domain) {
  188. if (inst->secure)
  189. use_iommu = false;
  190. else
  191. domain = DISPLAY_WRITE_DOMAIN;
  192. } else {
  193. domain = DISPLAY_READ_DOMAIN;
  194. }
  195. if (use_iommu) {
  196. rc = ion_map_iommu(mmap->ion_client, mregion->ion_handle,
  197. domain, GEN_POOL, SZ_4K, 0,
  198. (unsigned long *)&mregion->paddr,
  199. (unsigned long *)&mregion->size,
  200. 0, 0);
  201. } else {
  202. rc = ion_phys(mmap->ion_client, mregion->ion_handle,
  203. (unsigned long *)&mregion->paddr,
  204. (size_t *)&mregion->size);
  205. }
  206. return rc;
  207. }
  208. int mdp_munmap(struct v4l2_subdev *sd, void *arg)
  209. {
  210. struct mem_region_map *mmap = arg;
  211. struct mem_region *mregion;
  212. bool use_iommu = false;
  213. int domain = -1;
  214. struct mdp_instance *inst = NULL;
  215. if (!mmap || !mmap->mregion || !mmap->cookie) {
  216. WFD_MSG_ERR("Invalid argument\n");
  217. return -EINVAL;
  218. }
  219. inst = mmap->cookie;
  220. mregion = mmap->mregion;
  221. if (inst->uses_iommu_split_domain) {
  222. if (inst->secure)
  223. use_iommu = false;
  224. else
  225. domain = DISPLAY_WRITE_DOMAIN;
  226. } else {
  227. domain = DISPLAY_READ_DOMAIN;
  228. }
  229. if (use_iommu)
  230. ion_unmap_iommu(mmap->ion_client,
  231. mregion->ion_handle,
  232. domain, GEN_POOL);
  233. return 0;
  234. }
  235. long mdp_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
  236. {
  237. int rc = 0;
  238. if (!sd) {
  239. WFD_MSG_ERR("Invalid arguments\n");
  240. return -EINVAL;
  241. }
  242. switch (cmd) {
  243. case MDP_Q_BUFFER:
  244. rc = mdp_q_buffer(sd, arg);
  245. break;
  246. case MDP_DQ_BUFFER:
  247. rc = mdp_dq_buffer(sd, arg);
  248. break;
  249. case MDP_OPEN:
  250. rc = mdp_open(sd, arg);
  251. break;
  252. case MDP_START:
  253. rc = mdp_start(sd, arg);
  254. break;
  255. case MDP_STOP:
  256. rc = mdp_stop(sd, arg);
  257. break;
  258. case MDP_SET_PROP:
  259. rc = mdp_set_prop(sd, arg);
  260. break;
  261. case MDP_CLOSE:
  262. rc = mdp_close(sd, arg);
  263. break;
  264. case MDP_MMAP:
  265. rc = mdp_mmap(sd, arg);
  266. break;
  267. case MDP_MUNMAP:
  268. rc = mdp_munmap(sd, arg);
  269. break;
  270. default:
  271. WFD_MSG_ERR("IOCTL: %u not supported\n", cmd);
  272. rc = -EINVAL;
  273. break;
  274. }
  275. return rc;
  276. }