exynos_drm_ipp.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999
  1. /*
  2. * Copyright (C) 2012 Samsung Electronics Co.Ltd
  3. * Authors:
  4. * Eunchul Kim <chulspro.kim@samsung.com>
  5. * Jinyoung Jeon <jy0.jeon@samsung.com>
  6. * Sangmin Lee <lsmin.lee@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/types.h>
  18. #include <linux/clk.h>
  19. #include <linux/pm_runtime.h>
  20. #include <plat/map-base.h>
  21. #include <drm/drmP.h>
  22. #include <drm/exynos_drm.h>
  23. #include "exynos_drm_drv.h"
  24. #include "exynos_drm_gem.h"
  25. #include "exynos_drm_ipp.h"
  26. #include "exynos_drm_iommu.h"
  27. /*
  28. * IPP stands for Image Post Processing and
  29. * supports image scaler/rotator and input/output DMA operations.
  30. * using FIMC, GSC, Rotator, so on.
  31. * IPP is integration device driver of same attribute h/w
  32. */
  33. /*
  34. * TODO
  35. * 1. expand command control id.
  36. * 2. integrate property and config.
  37. * 3. removed send_event id check routine.
  38. * 4. compare send_event id if needed.
  39. * 5. free subdrv_remove notifier callback list if needed.
  40. * 6. need to check subdrv_open about multi-open.
  41. * 7. need to power_on implement power and sysmmu ctrl.
  42. */
  43. #define get_ipp_context(dev) platform_get_drvdata(to_platform_device(dev))
  44. #define ipp_is_m2m_cmd(c) (c == IPP_CMD_M2M)
  45. /* platform device pointer for ipp device. */
  46. static struct platform_device *exynos_drm_ipp_pdev;
  47. /*
  48. * A structure of event.
  49. *
  50. * @base: base of event.
  51. * @event: ipp event.
  52. */
  53. struct drm_exynos_ipp_send_event {
  54. struct drm_pending_event base;
  55. struct drm_exynos_ipp_event event;
  56. };
  57. /*
  58. * A structure of memory node.
  59. *
  60. * @list: list head to memory queue information.
  61. * @ops_id: id of operations.
  62. * @prop_id: id of property.
  63. * @buf_id: id of buffer.
  64. * @buf_info: gem objects and dma address, size.
  65. * @filp: a pointer to drm_file.
  66. */
  67. struct drm_exynos_ipp_mem_node {
  68. struct list_head list;
  69. enum drm_exynos_ops_id ops_id;
  70. u32 prop_id;
  71. u32 buf_id;
  72. struct drm_exynos_ipp_buf_info buf_info;
  73. struct drm_file *filp;
  74. };
  75. /*
  76. * A structure of ipp context.
  77. *
  78. * @subdrv: prepare initialization using subdrv.
  79. * @ipp_lock: lock for synchronization of access to ipp_idr.
  80. * @prop_lock: lock for synchronization of access to prop_idr.
  81. * @ipp_idr: ipp driver idr.
  82. * @prop_idr: property idr.
  83. * @event_workq: event work queue.
  84. * @cmd_workq: command work queue.
  85. */
  86. struct ipp_context {
  87. struct exynos_drm_subdrv subdrv;
  88. struct mutex ipp_lock;
  89. struct mutex prop_lock;
  90. struct idr ipp_idr;
  91. struct idr prop_idr;
  92. struct workqueue_struct *event_workq;
  93. struct workqueue_struct *cmd_workq;
  94. };
  95. static LIST_HEAD(exynos_drm_ippdrv_list);
  96. static DEFINE_MUTEX(exynos_drm_ippdrv_lock);
  97. static BLOCKING_NOTIFIER_HEAD(exynos_drm_ippnb_list);
  98. int exynos_platform_device_ipp_register(void)
  99. {
  100. struct platform_device *pdev;
  101. if (exynos_drm_ipp_pdev)
  102. return -EEXIST;
  103. pdev = platform_device_register_simple("exynos-drm-ipp", -1, NULL, 0);
  104. if (IS_ERR(pdev))
  105. return PTR_ERR(pdev);
  106. exynos_drm_ipp_pdev = pdev;
  107. return 0;
  108. }
  109. void exynos_platform_device_ipp_unregister(void)
  110. {
  111. if (exynos_drm_ipp_pdev) {
  112. platform_device_unregister(exynos_drm_ipp_pdev);
  113. exynos_drm_ipp_pdev = NULL;
  114. }
  115. }
  116. int exynos_drm_ippdrv_register(struct exynos_drm_ippdrv *ippdrv)
  117. {
  118. if (!ippdrv)
  119. return -EINVAL;
  120. mutex_lock(&exynos_drm_ippdrv_lock);
  121. list_add_tail(&ippdrv->drv_list, &exynos_drm_ippdrv_list);
  122. mutex_unlock(&exynos_drm_ippdrv_lock);
  123. return 0;
  124. }
  125. int exynos_drm_ippdrv_unregister(struct exynos_drm_ippdrv *ippdrv)
  126. {
  127. if (!ippdrv)
  128. return -EINVAL;
  129. mutex_lock(&exynos_drm_ippdrv_lock);
  130. list_del(&ippdrv->drv_list);
  131. mutex_unlock(&exynos_drm_ippdrv_lock);
  132. return 0;
  133. }
  134. static int ipp_create_id(struct idr *id_idr, struct mutex *lock, void *obj,
  135. u32 *idp)
  136. {
  137. int ret;
  138. /* do the allocation under our mutexlock */
  139. mutex_lock(lock);
  140. ret = idr_alloc(id_idr, obj, 1, 0, GFP_KERNEL);
  141. mutex_unlock(lock);
  142. if (ret < 0)
  143. return ret;
  144. *idp = ret;
  145. return 0;
  146. }
  147. static void *ipp_find_obj(struct idr *id_idr, struct mutex *lock, u32 id)
  148. {
  149. void *obj;
  150. DRM_DEBUG_KMS("id[%d]\n", id);
  151. mutex_lock(lock);
  152. /* find object using handle */
  153. obj = idr_find(id_idr, id);
  154. if (!obj) {
  155. DRM_ERROR("failed to find object.\n");
  156. mutex_unlock(lock);
  157. return ERR_PTR(-ENODEV);
  158. }
  159. mutex_unlock(lock);
  160. return obj;
  161. }
  162. static inline bool ipp_check_dedicated(struct exynos_drm_ippdrv *ippdrv,
  163. enum drm_exynos_ipp_cmd cmd)
  164. {
  165. /*
  166. * check dedicated flag and WB, OUTPUT operation with
  167. * power on state.
  168. */
  169. if (ippdrv->dedicated || (!ipp_is_m2m_cmd(cmd) &&
  170. !pm_runtime_suspended(ippdrv->dev)))
  171. return true;
  172. return false;
  173. }
  174. static struct exynos_drm_ippdrv *ipp_find_driver(struct ipp_context *ctx,
  175. struct drm_exynos_ipp_property *property)
  176. {
  177. struct exynos_drm_ippdrv *ippdrv;
  178. u32 ipp_id = property->ipp_id;
  179. DRM_DEBUG_KMS("ipp_id[%d]\n", ipp_id);
  180. if (ipp_id) {
  181. /* find ipp driver using idr */
  182. ippdrv = ipp_find_obj(&ctx->ipp_idr, &ctx->ipp_lock,
  183. ipp_id);
  184. if (IS_ERR(ippdrv)) {
  185. DRM_ERROR("not found ipp%d driver.\n", ipp_id);
  186. return ippdrv;
  187. }
  188. /*
  189. * WB, OUTPUT opertion not supported multi-operation.
  190. * so, make dedicated state at set property ioctl.
  191. * when ipp driver finished operations, clear dedicated flags.
  192. */
  193. if (ipp_check_dedicated(ippdrv, property->cmd)) {
  194. DRM_ERROR("already used choose device.\n");
  195. return ERR_PTR(-EBUSY);
  196. }
  197. /*
  198. * This is necessary to find correct device in ipp drivers.
  199. * ipp drivers have different abilities,
  200. * so need to check property.
  201. */
  202. if (ippdrv->check_property &&
  203. ippdrv->check_property(ippdrv->dev, property)) {
  204. DRM_ERROR("not support property.\n");
  205. return ERR_PTR(-EINVAL);
  206. }
  207. return ippdrv;
  208. } else {
  209. /*
  210. * This case is search all ipp driver for finding.
  211. * user application don't set ipp_id in this case,
  212. * so ipp subsystem search correct driver in driver list.
  213. */
  214. list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
  215. if (ipp_check_dedicated(ippdrv, property->cmd)) {
  216. DRM_DEBUG_KMS("used device.\n");
  217. continue;
  218. }
  219. if (ippdrv->check_property &&
  220. ippdrv->check_property(ippdrv->dev, property)) {
  221. DRM_DEBUG_KMS("not support property.\n");
  222. continue;
  223. }
  224. return ippdrv;
  225. }
  226. DRM_ERROR("not support ipp driver operations.\n");
  227. }
  228. return ERR_PTR(-ENODEV);
  229. }
  230. static struct exynos_drm_ippdrv *ipp_find_drv_by_handle(u32 prop_id)
  231. {
  232. struct exynos_drm_ippdrv *ippdrv;
  233. struct drm_exynos_ipp_cmd_node *c_node;
  234. int count = 0;
  235. DRM_DEBUG_KMS("prop_id[%d]\n", prop_id);
  236. if (list_empty(&exynos_drm_ippdrv_list)) {
  237. DRM_DEBUG_KMS("ippdrv_list is empty.\n");
  238. return ERR_PTR(-ENODEV);
  239. }
  240. /*
  241. * This case is search ipp driver by prop_id handle.
  242. * sometimes, ipp subsystem find driver by prop_id.
  243. * e.g PAUSE state, queue buf, command contro.
  244. */
  245. list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
  246. DRM_DEBUG_KMS("count[%d]ippdrv[0x%x]\n", count++, (int)ippdrv);
  247. if (!list_empty(&ippdrv->cmd_list)) {
  248. list_for_each_entry(c_node, &ippdrv->cmd_list, list)
  249. if (c_node->property.prop_id == prop_id)
  250. return ippdrv;
  251. }
  252. }
  253. return ERR_PTR(-ENODEV);
  254. }
  255. int exynos_drm_ipp_get_property(struct drm_device *drm_dev, void *data,
  256. struct drm_file *file)
  257. {
  258. struct drm_exynos_file_private *file_priv = file->driver_priv;
  259. struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
  260. struct device *dev = priv->dev;
  261. struct ipp_context *ctx = get_ipp_context(dev);
  262. struct drm_exynos_ipp_prop_list *prop_list = data;
  263. struct exynos_drm_ippdrv *ippdrv;
  264. int count = 0;
  265. if (!ctx) {
  266. DRM_ERROR("invalid context.\n");
  267. return -EINVAL;
  268. }
  269. if (!prop_list) {
  270. DRM_ERROR("invalid property parameter.\n");
  271. return -EINVAL;
  272. }
  273. DRM_DEBUG_KMS("ipp_id[%d]\n", prop_list->ipp_id);
  274. if (!prop_list->ipp_id) {
  275. list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list)
  276. count++;
  277. /*
  278. * Supports ippdrv list count for user application.
  279. * First step user application getting ippdrv count.
  280. * and second step getting ippdrv capability using ipp_id.
  281. */
  282. prop_list->count = count;
  283. } else {
  284. /*
  285. * Getting ippdrv capability by ipp_id.
  286. * some deivce not supported wb, output interface.
  287. * so, user application detect correct ipp driver
  288. * using this ioctl.
  289. */
  290. ippdrv = ipp_find_obj(&ctx->ipp_idr, &ctx->ipp_lock,
  291. prop_list->ipp_id);
  292. if (!ippdrv) {
  293. DRM_ERROR("not found ipp%d driver.\n",
  294. prop_list->ipp_id);
  295. return -EINVAL;
  296. }
  297. prop_list = ippdrv->prop_list;
  298. }
  299. return 0;
  300. }
  301. static void ipp_print_property(struct drm_exynos_ipp_property *property,
  302. int idx)
  303. {
  304. struct drm_exynos_ipp_config *config = &property->config[idx];
  305. struct drm_exynos_pos *pos = &config->pos;
  306. struct drm_exynos_sz *sz = &config->sz;
  307. DRM_DEBUG_KMS("prop_id[%d]ops[%s]fmt[0x%x]\n",
  308. property->prop_id, idx ? "dst" : "src", config->fmt);
  309. DRM_DEBUG_KMS("pos[%d %d %d %d]sz[%d %d]f[%d]r[%d]\n",
  310. pos->x, pos->y, pos->w, pos->h,
  311. sz->hsize, sz->vsize, config->flip, config->degree);
  312. }
  313. static int ipp_find_and_set_property(struct drm_exynos_ipp_property *property)
  314. {
  315. struct exynos_drm_ippdrv *ippdrv;
  316. struct drm_exynos_ipp_cmd_node *c_node;
  317. u32 prop_id = property->prop_id;
  318. DRM_DEBUG_KMS("prop_id[%d]\n", prop_id);
  319. ippdrv = ipp_find_drv_by_handle(prop_id);
  320. if (IS_ERR(ippdrv)) {
  321. DRM_ERROR("failed to get ipp driver.\n");
  322. return -EINVAL;
  323. }
  324. /*
  325. * Find command node using command list in ippdrv.
  326. * when we find this command no using prop_id.
  327. * return property information set in this command node.
  328. */
  329. list_for_each_entry(c_node, &ippdrv->cmd_list, list) {
  330. if ((c_node->property.prop_id == prop_id) &&
  331. (c_node->state == IPP_STATE_STOP)) {
  332. DRM_DEBUG_KMS("found cmd[%d]ippdrv[0x%x]\n",
  333. property->cmd, (int)ippdrv);
  334. c_node->property = *property;
  335. return 0;
  336. }
  337. }
  338. DRM_ERROR("failed to search property.\n");
  339. return -EINVAL;
  340. }
  341. static struct drm_exynos_ipp_cmd_work *ipp_create_cmd_work(void)
  342. {
  343. struct drm_exynos_ipp_cmd_work *cmd_work;
  344. cmd_work = kzalloc(sizeof(*cmd_work), GFP_KERNEL);
  345. if (!cmd_work) {
  346. DRM_ERROR("failed to alloc cmd_work.\n");
  347. return ERR_PTR(-ENOMEM);
  348. }
  349. INIT_WORK((struct work_struct *)cmd_work, ipp_sched_cmd);
  350. return cmd_work;
  351. }
  352. static struct drm_exynos_ipp_event_work *ipp_create_event_work(void)
  353. {
  354. struct drm_exynos_ipp_event_work *event_work;
  355. event_work = kzalloc(sizeof(*event_work), GFP_KERNEL);
  356. if (!event_work) {
  357. DRM_ERROR("failed to alloc event_work.\n");
  358. return ERR_PTR(-ENOMEM);
  359. }
  360. INIT_WORK((struct work_struct *)event_work, ipp_sched_event);
  361. return event_work;
  362. }
  363. int exynos_drm_ipp_set_property(struct drm_device *drm_dev, void *data,
  364. struct drm_file *file)
  365. {
  366. struct drm_exynos_file_private *file_priv = file->driver_priv;
  367. struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
  368. struct device *dev = priv->dev;
  369. struct ipp_context *ctx = get_ipp_context(dev);
  370. struct drm_exynos_ipp_property *property = data;
  371. struct exynos_drm_ippdrv *ippdrv;
  372. struct drm_exynos_ipp_cmd_node *c_node;
  373. int ret, i;
  374. if (!ctx) {
  375. DRM_ERROR("invalid context.\n");
  376. return -EINVAL;
  377. }
  378. if (!property) {
  379. DRM_ERROR("invalid property parameter.\n");
  380. return -EINVAL;
  381. }
  382. /*
  383. * This is log print for user application property.
  384. * user application set various property.
  385. */
  386. for_each_ipp_ops(i)
  387. ipp_print_property(property, i);
  388. /*
  389. * set property ioctl generated new prop_id.
  390. * but in this case already asigned prop_id using old set property.
  391. * e.g PAUSE state. this case supports find current prop_id and use it
  392. * instead of allocation.
  393. */
  394. if (property->prop_id) {
  395. DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id);
  396. return ipp_find_and_set_property(property);
  397. }
  398. /* find ipp driver using ipp id */
  399. ippdrv = ipp_find_driver(ctx, property);
  400. if (IS_ERR(ippdrv)) {
  401. DRM_ERROR("failed to get ipp driver.\n");
  402. return -EINVAL;
  403. }
  404. /* allocate command node */
  405. c_node = kzalloc(sizeof(*c_node), GFP_KERNEL);
  406. if (!c_node) {
  407. DRM_ERROR("failed to allocate map node.\n");
  408. return -ENOMEM;
  409. }
  410. /* create property id */
  411. ret = ipp_create_id(&ctx->prop_idr, &ctx->prop_lock, c_node,
  412. &property->prop_id);
  413. if (ret) {
  414. DRM_ERROR("failed to create id.\n");
  415. goto err_clear;
  416. }
  417. DRM_DEBUG_KMS("created prop_id[%d]cmd[%d]ippdrv[0x%x]\n",
  418. property->prop_id, property->cmd, (int)ippdrv);
  419. /* stored property information and ippdrv in private data */
  420. c_node->priv = priv;
  421. c_node->property = *property;
  422. c_node->state = IPP_STATE_IDLE;
  423. c_node->start_work = ipp_create_cmd_work();
  424. if (IS_ERR(c_node->start_work)) {
  425. DRM_ERROR("failed to create start work.\n");
  426. goto err_clear;
  427. }
  428. c_node->stop_work = ipp_create_cmd_work();
  429. if (IS_ERR(c_node->stop_work)) {
  430. DRM_ERROR("failed to create stop work.\n");
  431. goto err_free_start;
  432. }
  433. c_node->event_work = ipp_create_event_work();
  434. if (IS_ERR(c_node->event_work)) {
  435. DRM_ERROR("failed to create event work.\n");
  436. goto err_free_stop;
  437. }
  438. mutex_init(&c_node->cmd_lock);
  439. mutex_init(&c_node->mem_lock);
  440. mutex_init(&c_node->event_lock);
  441. init_completion(&c_node->start_complete);
  442. init_completion(&c_node->stop_complete);
  443. for_each_ipp_ops(i)
  444. INIT_LIST_HEAD(&c_node->mem_list[i]);
  445. INIT_LIST_HEAD(&c_node->event_list);
  446. list_splice_init(&priv->event_list, &c_node->event_list);
  447. list_add_tail(&c_node->list, &ippdrv->cmd_list);
  448. /* make dedicated state without m2m */
  449. if (!ipp_is_m2m_cmd(property->cmd))
  450. ippdrv->dedicated = true;
  451. return 0;
  452. err_free_stop:
  453. kfree(c_node->stop_work);
  454. err_free_start:
  455. kfree(c_node->start_work);
  456. err_clear:
  457. kfree(c_node);
  458. return ret;
  459. }
  460. static void ipp_clean_cmd_node(struct drm_exynos_ipp_cmd_node *c_node)
  461. {
  462. /* delete list */
  463. list_del(&c_node->list);
  464. /* destroy mutex */
  465. mutex_destroy(&c_node->cmd_lock);
  466. mutex_destroy(&c_node->mem_lock);
  467. mutex_destroy(&c_node->event_lock);
  468. /* free command node */
  469. kfree(c_node->start_work);
  470. kfree(c_node->stop_work);
  471. kfree(c_node->event_work);
  472. kfree(c_node);
  473. }
  474. static int ipp_check_mem_list(struct drm_exynos_ipp_cmd_node *c_node)
  475. {
  476. struct drm_exynos_ipp_property *property = &c_node->property;
  477. struct drm_exynos_ipp_mem_node *m_node;
  478. struct list_head *head;
  479. int ret, i, count[EXYNOS_DRM_OPS_MAX] = { 0, };
  480. mutex_lock(&c_node->mem_lock);
  481. for_each_ipp_ops(i) {
  482. /* source/destination memory list */
  483. head = &c_node->mem_list[i];
  484. if (list_empty(head)) {
  485. DRM_DEBUG_KMS("%s memory empty.\n", i ? "dst" : "src");
  486. continue;
  487. }
  488. /* find memory node entry */
  489. list_for_each_entry(m_node, head, list) {
  490. DRM_DEBUG_KMS("%s,count[%d]m_node[0x%x]\n",
  491. i ? "dst" : "src", count[i], (int)m_node);
  492. count[i]++;
  493. }
  494. }
  495. DRM_DEBUG_KMS("min[%d]max[%d]\n",
  496. min(count[EXYNOS_DRM_OPS_SRC], count[EXYNOS_DRM_OPS_DST]),
  497. max(count[EXYNOS_DRM_OPS_SRC], count[EXYNOS_DRM_OPS_DST]));
  498. /*
  499. * M2M operations should be need paired memory address.
  500. * so, need to check minimum count about src, dst.
  501. * other case not use paired memory, so use maximum count
  502. */
  503. if (ipp_is_m2m_cmd(property->cmd))
  504. ret = min(count[EXYNOS_DRM_OPS_SRC],
  505. count[EXYNOS_DRM_OPS_DST]);
  506. else
  507. ret = max(count[EXYNOS_DRM_OPS_SRC],
  508. count[EXYNOS_DRM_OPS_DST]);
  509. mutex_unlock(&c_node->mem_lock);
  510. return ret;
  511. }
  512. static struct drm_exynos_ipp_mem_node
  513. *ipp_find_mem_node(struct drm_exynos_ipp_cmd_node *c_node,
  514. struct drm_exynos_ipp_queue_buf *qbuf)
  515. {
  516. struct drm_exynos_ipp_mem_node *m_node;
  517. struct list_head *head;
  518. int count = 0;
  519. DRM_DEBUG_KMS("buf_id[%d]\n", qbuf->buf_id);
  520. /* source/destination memory list */
  521. head = &c_node->mem_list[qbuf->ops_id];
  522. /* find memory node from memory list */
  523. list_for_each_entry(m_node, head, list) {
  524. DRM_DEBUG_KMS("count[%d]m_node[0x%x]\n", count++, (int)m_node);
  525. /* compare buffer id */
  526. if (m_node->buf_id == qbuf->buf_id)
  527. return m_node;
  528. }
  529. return NULL;
  530. }
  531. static int ipp_set_mem_node(struct exynos_drm_ippdrv *ippdrv,
  532. struct drm_exynos_ipp_cmd_node *c_node,
  533. struct drm_exynos_ipp_mem_node *m_node)
  534. {
  535. struct exynos_drm_ipp_ops *ops = NULL;
  536. int ret = 0;
  537. DRM_DEBUG_KMS("node[0x%x]\n", (int)m_node);
  538. if (!m_node) {
  539. DRM_ERROR("invalid queue node.\n");
  540. return -EFAULT;
  541. }
  542. mutex_lock(&c_node->mem_lock);
  543. DRM_DEBUG_KMS("ops_id[%d]\n", m_node->ops_id);
  544. /* get operations callback */
  545. ops = ippdrv->ops[m_node->ops_id];
  546. if (!ops) {
  547. DRM_ERROR("not support ops.\n");
  548. ret = -EFAULT;
  549. goto err_unlock;
  550. }
  551. /* set address and enable irq */
  552. if (ops->set_addr) {
  553. ret = ops->set_addr(ippdrv->dev, &m_node->buf_info,
  554. m_node->buf_id, IPP_BUF_ENQUEUE);
  555. if (ret) {
  556. DRM_ERROR("failed to set addr.\n");
  557. goto err_unlock;
  558. }
  559. }
  560. err_unlock:
  561. mutex_unlock(&c_node->mem_lock);
  562. return ret;
  563. }
  564. static struct drm_exynos_ipp_mem_node
  565. *ipp_get_mem_node(struct drm_device *drm_dev,
  566. struct drm_file *file,
  567. struct drm_exynos_ipp_cmd_node *c_node,
  568. struct drm_exynos_ipp_queue_buf *qbuf)
  569. {
  570. struct drm_exynos_ipp_mem_node *m_node;
  571. struct drm_exynos_ipp_buf_info buf_info;
  572. void *addr;
  573. int i;
  574. mutex_lock(&c_node->mem_lock);
  575. m_node = kzalloc(sizeof(*m_node), GFP_KERNEL);
  576. if (!m_node) {
  577. DRM_ERROR("failed to allocate queue node.\n");
  578. goto err_unlock;
  579. }
  580. /* clear base address for error handling */
  581. memset(&buf_info, 0x0, sizeof(buf_info));
  582. /* operations, buffer id */
  583. m_node->ops_id = qbuf->ops_id;
  584. m_node->prop_id = qbuf->prop_id;
  585. m_node->buf_id = qbuf->buf_id;
  586. DRM_DEBUG_KMS("m_node[0x%x]ops_id[%d]\n", (int)m_node, qbuf->ops_id);
  587. DRM_DEBUG_KMS("prop_id[%d]buf_id[%d]\n", qbuf->prop_id, m_node->buf_id);
  588. for_each_ipp_planar(i) {
  589. DRM_DEBUG_KMS("i[%d]handle[0x%x]\n", i, qbuf->handle[i]);
  590. /* get dma address by handle */
  591. if (qbuf->handle[i]) {
  592. addr = exynos_drm_gem_get_dma_addr(drm_dev,
  593. qbuf->handle[i], file);
  594. if (IS_ERR(addr)) {
  595. DRM_ERROR("failed to get addr.\n");
  596. goto err_clear;
  597. }
  598. buf_info.handles[i] = qbuf->handle[i];
  599. buf_info.base[i] = *(dma_addr_t *) addr;
  600. DRM_DEBUG_KMS("i[%d]base[0x%x]hd[0x%x]\n",
  601. i, buf_info.base[i], (int)buf_info.handles[i]);
  602. }
  603. }
  604. m_node->filp = file;
  605. m_node->buf_info = buf_info;
  606. list_add_tail(&m_node->list, &c_node->mem_list[qbuf->ops_id]);
  607. mutex_unlock(&c_node->mem_lock);
  608. return m_node;
  609. err_clear:
  610. kfree(m_node);
  611. err_unlock:
  612. mutex_unlock(&c_node->mem_lock);
  613. return ERR_PTR(-EFAULT);
  614. }
  615. static int ipp_put_mem_node(struct drm_device *drm_dev,
  616. struct drm_exynos_ipp_cmd_node *c_node,
  617. struct drm_exynos_ipp_mem_node *m_node)
  618. {
  619. int i;
  620. DRM_DEBUG_KMS("node[0x%x]\n", (int)m_node);
  621. if (!m_node) {
  622. DRM_ERROR("invalid dequeue node.\n");
  623. return -EFAULT;
  624. }
  625. if (list_empty(&m_node->list)) {
  626. DRM_ERROR("empty memory node.\n");
  627. return -ENOMEM;
  628. }
  629. mutex_lock(&c_node->mem_lock);
  630. DRM_DEBUG_KMS("ops_id[%d]\n", m_node->ops_id);
  631. /* put gem buffer */
  632. for_each_ipp_planar(i) {
  633. unsigned long handle = m_node->buf_info.handles[i];
  634. if (handle)
  635. exynos_drm_gem_put_dma_addr(drm_dev, handle,
  636. m_node->filp);
  637. }
  638. /* delete list in queue */
  639. list_del(&m_node->list);
  640. kfree(m_node);
  641. mutex_unlock(&c_node->mem_lock);
  642. return 0;
  643. }
  644. static void ipp_free_event(struct drm_pending_event *event)
  645. {
  646. kfree(event);
  647. }
  648. static int ipp_get_event(struct drm_device *drm_dev,
  649. struct drm_file *file,
  650. struct drm_exynos_ipp_cmd_node *c_node,
  651. struct drm_exynos_ipp_queue_buf *qbuf)
  652. {
  653. struct drm_exynos_ipp_send_event *e;
  654. unsigned long flags;
  655. DRM_DEBUG_KMS("ops_id[%d]buf_id[%d]\n", qbuf->ops_id, qbuf->buf_id);
  656. e = kzalloc(sizeof(*e), GFP_KERNEL);
  657. if (!e) {
  658. DRM_ERROR("failed to allocate event.\n");
  659. spin_lock_irqsave(&drm_dev->event_lock, flags);
  660. file->event_space += sizeof(e->event);
  661. spin_unlock_irqrestore(&drm_dev->event_lock, flags);
  662. return -ENOMEM;
  663. }
  664. /* make event */
  665. e->event.base.type = DRM_EXYNOS_IPP_EVENT;
  666. e->event.base.length = sizeof(e->event);
  667. e->event.user_data = qbuf->user_data;
  668. e->event.prop_id = qbuf->prop_id;
  669. e->event.buf_id[EXYNOS_DRM_OPS_DST] = qbuf->buf_id;
  670. e->base.event = &e->event.base;
  671. e->base.file_priv = file;
  672. e->base.destroy = ipp_free_event;
  673. list_add_tail(&e->base.link, &c_node->event_list);
  674. return 0;
  675. }
  676. static void ipp_put_event(struct drm_exynos_ipp_cmd_node *c_node,
  677. struct drm_exynos_ipp_queue_buf *qbuf)
  678. {
  679. struct drm_exynos_ipp_send_event *e, *te;
  680. int count = 0;
  681. if (list_empty(&c_node->event_list)) {
  682. DRM_DEBUG_KMS("event_list is empty.\n");
  683. return;
  684. }
  685. list_for_each_entry_safe(e, te, &c_node->event_list, base.link) {
  686. DRM_DEBUG_KMS("count[%d]e[0x%x]\n", count++, (int)e);
  687. /*
  688. * quf == NULL condition means all event deletion.
  689. * stop operations want to delete all event list.
  690. * another case delete only same buf id.
  691. */
  692. if (!qbuf) {
  693. /* delete list */
  694. list_del(&e->base.link);
  695. kfree(e);
  696. }
  697. /* compare buffer id */
  698. if (qbuf && (qbuf->buf_id ==
  699. e->event.buf_id[EXYNOS_DRM_OPS_DST])) {
  700. /* delete list */
  701. list_del(&e->base.link);
  702. kfree(e);
  703. return;
  704. }
  705. }
  706. }
  707. static void ipp_handle_cmd_work(struct device *dev,
  708. struct exynos_drm_ippdrv *ippdrv,
  709. struct drm_exynos_ipp_cmd_work *cmd_work,
  710. struct drm_exynos_ipp_cmd_node *c_node)
  711. {
  712. struct ipp_context *ctx = get_ipp_context(dev);
  713. cmd_work->ippdrv = ippdrv;
  714. cmd_work->c_node = c_node;
  715. queue_work(ctx->cmd_workq, (struct work_struct *)cmd_work);
  716. }
  717. static int ipp_queue_buf_with_run(struct device *dev,
  718. struct drm_exynos_ipp_cmd_node *c_node,
  719. struct drm_exynos_ipp_mem_node *m_node,
  720. struct drm_exynos_ipp_queue_buf *qbuf)
  721. {
  722. struct exynos_drm_ippdrv *ippdrv;
  723. struct drm_exynos_ipp_property *property;
  724. struct exynos_drm_ipp_ops *ops;
  725. int ret;
  726. ippdrv = ipp_find_drv_by_handle(qbuf->prop_id);
  727. if (IS_ERR(ippdrv)) {
  728. DRM_ERROR("failed to get ipp driver.\n");
  729. return -EFAULT;
  730. }
  731. ops = ippdrv->ops[qbuf->ops_id];
  732. if (!ops) {
  733. DRM_ERROR("failed to get ops.\n");
  734. return -EFAULT;
  735. }
  736. property = &c_node->property;
  737. if (c_node->state != IPP_STATE_START) {
  738. DRM_DEBUG_KMS("bypass for invalid state.\n");
  739. return 0;
  740. }
  741. if (!ipp_check_mem_list(c_node)) {
  742. DRM_DEBUG_KMS("empty memory.\n");
  743. return 0;
  744. }
  745. /*
  746. * If set destination buffer and enabled clock,
  747. * then m2m operations need start operations at queue_buf
  748. */
  749. if (ipp_is_m2m_cmd(property->cmd)) {
  750. struct drm_exynos_ipp_cmd_work *cmd_work = c_node->start_work;
  751. cmd_work->ctrl = IPP_CTRL_PLAY;
  752. ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
  753. } else {
  754. ret = ipp_set_mem_node(ippdrv, c_node, m_node);
  755. if (ret) {
  756. DRM_ERROR("failed to set m node.\n");
  757. return ret;
  758. }
  759. }
  760. return 0;
  761. }
  762. static void ipp_clean_queue_buf(struct drm_device *drm_dev,
  763. struct drm_exynos_ipp_cmd_node *c_node,
  764. struct drm_exynos_ipp_queue_buf *qbuf)
  765. {
  766. struct drm_exynos_ipp_mem_node *m_node, *tm_node;
  767. if (!list_empty(&c_node->mem_list[qbuf->ops_id])) {
  768. /* delete list */
  769. list_for_each_entry_safe(m_node, tm_node,
  770. &c_node->mem_list[qbuf->ops_id], list) {
  771. if (m_node->buf_id == qbuf->buf_id &&
  772. m_node->ops_id == qbuf->ops_id)
  773. ipp_put_mem_node(drm_dev, c_node, m_node);
  774. }
  775. }
  776. }
  777. int exynos_drm_ipp_queue_buf(struct drm_device *drm_dev, void *data,
  778. struct drm_file *file)
  779. {
  780. struct drm_exynos_file_private *file_priv = file->driver_priv;
  781. struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
  782. struct device *dev = priv->dev;
  783. struct ipp_context *ctx = get_ipp_context(dev);
  784. struct drm_exynos_ipp_queue_buf *qbuf = data;
  785. struct drm_exynos_ipp_cmd_node *c_node;
  786. struct drm_exynos_ipp_mem_node *m_node;
  787. int ret;
  788. if (!qbuf) {
  789. DRM_ERROR("invalid buf parameter.\n");
  790. return -EINVAL;
  791. }
  792. if (qbuf->ops_id >= EXYNOS_DRM_OPS_MAX) {
  793. DRM_ERROR("invalid ops parameter.\n");
  794. return -EINVAL;
  795. }
  796. DRM_DEBUG_KMS("prop_id[%d]ops_id[%s]buf_id[%d]buf_type[%d]\n",
  797. qbuf->prop_id, qbuf->ops_id ? "dst" : "src",
  798. qbuf->buf_id, qbuf->buf_type);
  799. /* find command node */
  800. c_node = ipp_find_obj(&ctx->prop_idr, &ctx->prop_lock,
  801. qbuf->prop_id);
  802. if (!c_node) {
  803. DRM_ERROR("failed to get command node.\n");
  804. return -EFAULT;
  805. }
  806. /* buffer control */
  807. switch (qbuf->buf_type) {
  808. case IPP_BUF_ENQUEUE:
  809. /* get memory node */
  810. m_node = ipp_get_mem_node(drm_dev, file, c_node, qbuf);
  811. if (IS_ERR(m_node)) {
  812. DRM_ERROR("failed to get m_node.\n");
  813. return PTR_ERR(m_node);
  814. }
  815. /*
  816. * first step get event for destination buffer.
  817. * and second step when M2M case run with destination buffer
  818. * if needed.
  819. */
  820. if (qbuf->ops_id == EXYNOS_DRM_OPS_DST) {
  821. /* get event for destination buffer */
  822. ret = ipp_get_event(drm_dev, file, c_node, qbuf);
  823. if (ret) {
  824. DRM_ERROR("failed to get event.\n");
  825. goto err_clean_node;
  826. }
  827. /*
  828. * M2M case run play control for streaming feature.
  829. * other case set address and waiting.
  830. */
  831. ret = ipp_queue_buf_with_run(dev, c_node, m_node, qbuf);
  832. if (ret) {
  833. DRM_ERROR("failed to run command.\n");
  834. goto err_clean_node;
  835. }
  836. }
  837. break;
  838. case IPP_BUF_DEQUEUE:
  839. mutex_lock(&c_node->cmd_lock);
  840. /* put event for destination buffer */
  841. if (qbuf->ops_id == EXYNOS_DRM_OPS_DST)
  842. ipp_put_event(c_node, qbuf);
  843. ipp_clean_queue_buf(drm_dev, c_node, qbuf);
  844. mutex_unlock(&c_node->cmd_lock);
  845. break;
  846. default:
  847. DRM_ERROR("invalid buffer control.\n");
  848. return -EINVAL;
  849. }
  850. return 0;
  851. err_clean_node:
  852. DRM_ERROR("clean memory nodes.\n");
  853. ipp_clean_queue_buf(drm_dev, c_node, qbuf);
  854. return ret;
  855. }
  856. static bool exynos_drm_ipp_check_valid(struct device *dev,
  857. enum drm_exynos_ipp_ctrl ctrl, enum drm_exynos_ipp_state state)
  858. {
  859. if (ctrl != IPP_CTRL_PLAY) {
  860. if (pm_runtime_suspended(dev)) {
  861. DRM_ERROR("pm:runtime_suspended.\n");
  862. goto err_status;
  863. }
  864. }
  865. switch (ctrl) {
  866. case IPP_CTRL_PLAY:
  867. if (state != IPP_STATE_IDLE)
  868. goto err_status;
  869. break;
  870. case IPP_CTRL_STOP:
  871. if (state == IPP_STATE_STOP)
  872. goto err_status;
  873. break;
  874. case IPP_CTRL_PAUSE:
  875. if (state != IPP_STATE_START)
  876. goto err_status;
  877. break;
  878. case IPP_CTRL_RESUME:
  879. if (state != IPP_STATE_STOP)
  880. goto err_status;
  881. break;
  882. default:
  883. DRM_ERROR("invalid state.\n");
  884. goto err_status;
  885. }
  886. return true;
  887. err_status:
  888. DRM_ERROR("invalid status:ctrl[%d]state[%d]\n", ctrl, state);
  889. return false;
  890. }
  891. int exynos_drm_ipp_cmd_ctrl(struct drm_device *drm_dev, void *data,
  892. struct drm_file *file)
  893. {
  894. struct drm_exynos_file_private *file_priv = file->driver_priv;
  895. struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
  896. struct exynos_drm_ippdrv *ippdrv = NULL;
  897. struct device *dev = priv->dev;
  898. struct ipp_context *ctx = get_ipp_context(dev);
  899. struct drm_exynos_ipp_cmd_ctrl *cmd_ctrl = data;
  900. struct drm_exynos_ipp_cmd_work *cmd_work;
  901. struct drm_exynos_ipp_cmd_node *c_node;
  902. if (!ctx) {
  903. DRM_ERROR("invalid context.\n");
  904. return -EINVAL;
  905. }
  906. if (!cmd_ctrl) {
  907. DRM_ERROR("invalid control parameter.\n");
  908. return -EINVAL;
  909. }
  910. DRM_DEBUG_KMS("ctrl[%d]prop_id[%d]\n",
  911. cmd_ctrl->ctrl, cmd_ctrl->prop_id);
  912. ippdrv = ipp_find_drv_by_handle(cmd_ctrl->prop_id);
  913. if (IS_ERR(ippdrv)) {
  914. DRM_ERROR("failed to get ipp driver.\n");
  915. return PTR_ERR(ippdrv);
  916. }
  917. c_node = ipp_find_obj(&ctx->prop_idr, &ctx->prop_lock,
  918. cmd_ctrl->prop_id);
  919. if (!c_node) {
  920. DRM_ERROR("invalid command node list.\n");
  921. return -EINVAL;
  922. }
  923. if (!exynos_drm_ipp_check_valid(ippdrv->dev, cmd_ctrl->ctrl,
  924. c_node->state)) {
  925. DRM_ERROR("invalid state.\n");
  926. return -EINVAL;
  927. }
  928. switch (cmd_ctrl->ctrl) {
  929. case IPP_CTRL_PLAY:
  930. if (pm_runtime_suspended(ippdrv->dev))
  931. pm_runtime_get_sync(ippdrv->dev);
  932. c_node->state = IPP_STATE_START;
  933. cmd_work = c_node->start_work;
  934. cmd_work->ctrl = cmd_ctrl->ctrl;
  935. ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
  936. c_node->state = IPP_STATE_START;
  937. break;
  938. case IPP_CTRL_STOP:
  939. cmd_work = c_node->stop_work;
  940. cmd_work->ctrl = cmd_ctrl->ctrl;
  941. ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
  942. if (!wait_for_completion_timeout(&c_node->stop_complete,
  943. msecs_to_jiffies(300))) {
  944. DRM_ERROR("timeout stop:prop_id[%d]\n",
  945. c_node->property.prop_id);
  946. }
  947. c_node->state = IPP_STATE_STOP;
  948. ippdrv->dedicated = false;
  949. ipp_clean_cmd_node(c_node);
  950. if (list_empty(&ippdrv->cmd_list))
  951. pm_runtime_put_sync(ippdrv->dev);
  952. break;
  953. case IPP_CTRL_PAUSE:
  954. cmd_work = c_node->stop_work;
  955. cmd_work->ctrl = cmd_ctrl->ctrl;
  956. ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
  957. if (!wait_for_completion_timeout(&c_node->stop_complete,
  958. msecs_to_jiffies(200))) {
  959. DRM_ERROR("timeout stop:prop_id[%d]\n",
  960. c_node->property.prop_id);
  961. }
  962. c_node->state = IPP_STATE_STOP;
  963. break;
  964. case IPP_CTRL_RESUME:
  965. c_node->state = IPP_STATE_START;
  966. cmd_work = c_node->start_work;
  967. cmd_work->ctrl = cmd_ctrl->ctrl;
  968. ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
  969. break;
  970. default:
  971. DRM_ERROR("could not support this state currently.\n");
  972. return -EINVAL;
  973. }
  974. DRM_DEBUG_KMS("done ctrl[%d]prop_id[%d]\n",
  975. cmd_ctrl->ctrl, cmd_ctrl->prop_id);
  976. return 0;
  977. }
  978. int exynos_drm_ippnb_register(struct notifier_block *nb)
  979. {
  980. return blocking_notifier_chain_register(
  981. &exynos_drm_ippnb_list, nb);
  982. }
  983. int exynos_drm_ippnb_unregister(struct notifier_block *nb)
  984. {
  985. return blocking_notifier_chain_unregister(
  986. &exynos_drm_ippnb_list, nb);
  987. }
  988. int exynos_drm_ippnb_send_event(unsigned long val, void *v)
  989. {
  990. return blocking_notifier_call_chain(
  991. &exynos_drm_ippnb_list, val, v);
  992. }
  993. static int ipp_set_property(struct exynos_drm_ippdrv *ippdrv,
  994. struct drm_exynos_ipp_property *property)
  995. {
  996. struct exynos_drm_ipp_ops *ops = NULL;
  997. bool swap = false;
  998. int ret, i;
  999. if (!property) {
  1000. DRM_ERROR("invalid property parameter.\n");
  1001. return -EINVAL;
  1002. }
  1003. DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id);
  1004. /* reset h/w block */
  1005. if (ippdrv->reset &&
  1006. ippdrv->reset(ippdrv->dev)) {
  1007. DRM_ERROR("failed to reset.\n");
  1008. return -EINVAL;
  1009. }
  1010. /* set source,destination operations */
  1011. for_each_ipp_ops(i) {
  1012. struct drm_exynos_ipp_config *config =
  1013. &property->config[i];
  1014. ops = ippdrv->ops[i];
  1015. if (!ops || !config) {
  1016. DRM_ERROR("not support ops and config.\n");
  1017. return -EINVAL;
  1018. }
  1019. /* set format */
  1020. if (ops->set_fmt) {
  1021. ret = ops->set_fmt(ippdrv->dev, config->fmt);
  1022. if (ret) {
  1023. DRM_ERROR("not support format.\n");
  1024. return ret;
  1025. }
  1026. }
  1027. /* set transform for rotation, flip */
  1028. if (ops->set_transf) {
  1029. ret = ops->set_transf(ippdrv->dev, config->degree,
  1030. config->flip, &swap);
  1031. if (ret) {
  1032. DRM_ERROR("not support tranf.\n");
  1033. return -EINVAL;
  1034. }
  1035. }
  1036. /* set size */
  1037. if (ops->set_size) {
  1038. ret = ops->set_size(ippdrv->dev, swap, &config->pos,
  1039. &config->sz);
  1040. if (ret) {
  1041. DRM_ERROR("not support size.\n");
  1042. return ret;
  1043. }
  1044. }
  1045. }
  1046. return 0;
  1047. }
  1048. static int ipp_start_property(struct exynos_drm_ippdrv *ippdrv,
  1049. struct drm_exynos_ipp_cmd_node *c_node)
  1050. {
  1051. struct drm_exynos_ipp_mem_node *m_node;
  1052. struct drm_exynos_ipp_property *property = &c_node->property;
  1053. struct list_head *head;
  1054. int ret, i;
  1055. DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id);
  1056. /* store command info in ippdrv */
  1057. ippdrv->c_node = c_node;
  1058. if (!ipp_check_mem_list(c_node)) {
  1059. DRM_DEBUG_KMS("empty memory.\n");
  1060. return -ENOMEM;
  1061. }
  1062. /* set current property in ippdrv */
  1063. ret = ipp_set_property(ippdrv, property);
  1064. if (ret) {
  1065. DRM_ERROR("failed to set property.\n");
  1066. ippdrv->c_node = NULL;
  1067. return ret;
  1068. }
  1069. /* check command */
  1070. switch (property->cmd) {
  1071. case IPP_CMD_M2M:
  1072. for_each_ipp_ops(i) {
  1073. /* source/destination memory list */
  1074. head = &c_node->mem_list[i];
  1075. m_node = list_first_entry(head,
  1076. struct drm_exynos_ipp_mem_node, list);
  1077. if (!m_node) {
  1078. DRM_ERROR("failed to get node.\n");
  1079. ret = -EFAULT;
  1080. return ret;
  1081. }
  1082. DRM_DEBUG_KMS("m_node[0x%x]\n", (int)m_node);
  1083. ret = ipp_set_mem_node(ippdrv, c_node, m_node);
  1084. if (ret) {
  1085. DRM_ERROR("failed to set m node.\n");
  1086. return ret;
  1087. }
  1088. }
  1089. break;
  1090. case IPP_CMD_WB:
  1091. /* destination memory list */
  1092. head = &c_node->mem_list[EXYNOS_DRM_OPS_DST];
  1093. list_for_each_entry(m_node, head, list) {
  1094. ret = ipp_set_mem_node(ippdrv, c_node, m_node);
  1095. if (ret) {
  1096. DRM_ERROR("failed to set m node.\n");
  1097. return ret;
  1098. }
  1099. }
  1100. break;
  1101. case IPP_CMD_OUTPUT:
  1102. /* source memory list */
  1103. head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC];
  1104. list_for_each_entry(m_node, head, list) {
  1105. ret = ipp_set_mem_node(ippdrv, c_node, m_node);
  1106. if (ret) {
  1107. DRM_ERROR("failed to set m node.\n");
  1108. return ret;
  1109. }
  1110. }
  1111. break;
  1112. default:
  1113. DRM_ERROR("invalid operations.\n");
  1114. return -EINVAL;
  1115. }
  1116. DRM_DEBUG_KMS("cmd[%d]\n", property->cmd);
  1117. /* start operations */
  1118. if (ippdrv->start) {
  1119. ret = ippdrv->start(ippdrv->dev, property->cmd);
  1120. if (ret) {
  1121. DRM_ERROR("failed to start ops.\n");
  1122. return ret;
  1123. }
  1124. }
  1125. return 0;
  1126. }
  1127. static int ipp_stop_property(struct drm_device *drm_dev,
  1128. struct exynos_drm_ippdrv *ippdrv,
  1129. struct drm_exynos_ipp_cmd_node *c_node)
  1130. {
  1131. struct drm_exynos_ipp_mem_node *m_node, *tm_node;
  1132. struct drm_exynos_ipp_property *property = &c_node->property;
  1133. struct list_head *head;
  1134. int ret = 0, i;
  1135. DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id);
  1136. /* put event */
  1137. ipp_put_event(c_node, NULL);
  1138. /* check command */
  1139. switch (property->cmd) {
  1140. case IPP_CMD_M2M:
  1141. for_each_ipp_ops(i) {
  1142. /* source/destination memory list */
  1143. head = &c_node->mem_list[i];
  1144. if (list_empty(head)) {
  1145. DRM_DEBUG_KMS("mem_list is empty.\n");
  1146. break;
  1147. }
  1148. list_for_each_entry_safe(m_node, tm_node,
  1149. head, list) {
  1150. ret = ipp_put_mem_node(drm_dev, c_node,
  1151. m_node);
  1152. if (ret) {
  1153. DRM_ERROR("failed to put m_node.\n");
  1154. goto err_clear;
  1155. }
  1156. }
  1157. }
  1158. break;
  1159. case IPP_CMD_WB:
  1160. /* destination memory list */
  1161. head = &c_node->mem_list[EXYNOS_DRM_OPS_DST];
  1162. if (list_empty(head)) {
  1163. DRM_DEBUG_KMS("mem_list is empty.\n");
  1164. break;
  1165. }
  1166. list_for_each_entry_safe(m_node, tm_node, head, list) {
  1167. ret = ipp_put_mem_node(drm_dev, c_node, m_node);
  1168. if (ret) {
  1169. DRM_ERROR("failed to put m_node.\n");
  1170. goto err_clear;
  1171. }
  1172. }
  1173. break;
  1174. case IPP_CMD_OUTPUT:
  1175. /* source memory list */
  1176. head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC];
  1177. if (list_empty(head)) {
  1178. DRM_DEBUG_KMS("mem_list is empty.\n");
  1179. break;
  1180. }
  1181. list_for_each_entry_safe(m_node, tm_node, head, list) {
  1182. ret = ipp_put_mem_node(drm_dev, c_node, m_node);
  1183. if (ret) {
  1184. DRM_ERROR("failed to put m_node.\n");
  1185. goto err_clear;
  1186. }
  1187. }
  1188. break;
  1189. default:
  1190. DRM_ERROR("invalid operations.\n");
  1191. ret = -EINVAL;
  1192. goto err_clear;
  1193. }
  1194. err_clear:
  1195. /* stop operations */
  1196. if (ippdrv->stop)
  1197. ippdrv->stop(ippdrv->dev, property->cmd);
  1198. return ret;
  1199. }
  1200. void ipp_sched_cmd(struct work_struct *work)
  1201. {
  1202. struct drm_exynos_ipp_cmd_work *cmd_work =
  1203. (struct drm_exynos_ipp_cmd_work *)work;
  1204. struct exynos_drm_ippdrv *ippdrv;
  1205. struct drm_exynos_ipp_cmd_node *c_node;
  1206. struct drm_exynos_ipp_property *property;
  1207. int ret;
  1208. ippdrv = cmd_work->ippdrv;
  1209. if (!ippdrv) {
  1210. DRM_ERROR("invalid ippdrv list.\n");
  1211. return;
  1212. }
  1213. c_node = cmd_work->c_node;
  1214. if (!c_node) {
  1215. DRM_ERROR("invalid command node list.\n");
  1216. return;
  1217. }
  1218. mutex_lock(&c_node->cmd_lock);
  1219. property = &c_node->property;
  1220. switch (cmd_work->ctrl) {
  1221. case IPP_CTRL_PLAY:
  1222. case IPP_CTRL_RESUME:
  1223. ret = ipp_start_property(ippdrv, c_node);
  1224. if (ret) {
  1225. DRM_ERROR("failed to start property:prop_id[%d]\n",
  1226. c_node->property.prop_id);
  1227. goto err_unlock;
  1228. }
  1229. /*
  1230. * M2M case supports wait_completion of transfer.
  1231. * because M2M case supports single unit operation
  1232. * with multiple queue.
  1233. * M2M need to wait completion of data transfer.
  1234. */
  1235. if (ipp_is_m2m_cmd(property->cmd)) {
  1236. if (!wait_for_completion_timeout
  1237. (&c_node->start_complete, msecs_to_jiffies(200))) {
  1238. DRM_ERROR("timeout event:prop_id[%d]\n",
  1239. c_node->property.prop_id);
  1240. goto err_unlock;
  1241. }
  1242. }
  1243. break;
  1244. case IPP_CTRL_STOP:
  1245. case IPP_CTRL_PAUSE:
  1246. ret = ipp_stop_property(ippdrv->drm_dev, ippdrv,
  1247. c_node);
  1248. if (ret) {
  1249. DRM_ERROR("failed to stop property.\n");
  1250. goto err_unlock;
  1251. }
  1252. complete(&c_node->stop_complete);
  1253. break;
  1254. default:
  1255. DRM_ERROR("unknown control type\n");
  1256. break;
  1257. }
  1258. DRM_DEBUG_KMS("ctrl[%d] done.\n", cmd_work->ctrl);
  1259. err_unlock:
  1260. mutex_unlock(&c_node->cmd_lock);
  1261. }
  1262. static int ipp_send_event(struct exynos_drm_ippdrv *ippdrv,
  1263. struct drm_exynos_ipp_cmd_node *c_node, int *buf_id)
  1264. {
  1265. struct drm_device *drm_dev = ippdrv->drm_dev;
  1266. struct drm_exynos_ipp_property *property = &c_node->property;
  1267. struct drm_exynos_ipp_mem_node *m_node;
  1268. struct drm_exynos_ipp_queue_buf qbuf;
  1269. struct drm_exynos_ipp_send_event *e;
  1270. struct list_head *head;
  1271. struct timeval now;
  1272. unsigned long flags;
  1273. u32 tbuf_id[EXYNOS_DRM_OPS_MAX] = {0, };
  1274. int ret, i;
  1275. for_each_ipp_ops(i)
  1276. DRM_DEBUG_KMS("%s buf_id[%d]\n", i ? "dst" : "src", buf_id[i]);
  1277. if (!drm_dev) {
  1278. DRM_ERROR("failed to get drm_dev.\n");
  1279. return -EINVAL;
  1280. }
  1281. if (!property) {
  1282. DRM_ERROR("failed to get property.\n");
  1283. return -EINVAL;
  1284. }
  1285. if (list_empty(&c_node->event_list)) {
  1286. DRM_DEBUG_KMS("event list is empty.\n");
  1287. return 0;
  1288. }
  1289. if (!ipp_check_mem_list(c_node)) {
  1290. DRM_DEBUG_KMS("empty memory.\n");
  1291. return 0;
  1292. }
  1293. /* check command */
  1294. switch (property->cmd) {
  1295. case IPP_CMD_M2M:
  1296. for_each_ipp_ops(i) {
  1297. /* source/destination memory list */
  1298. head = &c_node->mem_list[i];
  1299. m_node = list_first_entry(head,
  1300. struct drm_exynos_ipp_mem_node, list);
  1301. if (!m_node) {
  1302. DRM_ERROR("empty memory node.\n");
  1303. return -ENOMEM;
  1304. }
  1305. tbuf_id[i] = m_node->buf_id;
  1306. DRM_DEBUG_KMS("%s buf_id[%d]\n",
  1307. i ? "dst" : "src", tbuf_id[i]);
  1308. ret = ipp_put_mem_node(drm_dev, c_node, m_node);
  1309. if (ret)
  1310. DRM_ERROR("failed to put m_node.\n");
  1311. }
  1312. break;
  1313. case IPP_CMD_WB:
  1314. /* clear buf for finding */
  1315. memset(&qbuf, 0x0, sizeof(qbuf));
  1316. qbuf.ops_id = EXYNOS_DRM_OPS_DST;
  1317. qbuf.buf_id = buf_id[EXYNOS_DRM_OPS_DST];
  1318. /* get memory node entry */
  1319. m_node = ipp_find_mem_node(c_node, &qbuf);
  1320. if (!m_node) {
  1321. DRM_ERROR("empty memory node.\n");
  1322. return -ENOMEM;
  1323. }
  1324. tbuf_id[EXYNOS_DRM_OPS_DST] = m_node->buf_id;
  1325. ret = ipp_put_mem_node(drm_dev, c_node, m_node);
  1326. if (ret)
  1327. DRM_ERROR("failed to put m_node.\n");
  1328. break;
  1329. case IPP_CMD_OUTPUT:
  1330. /* source memory list */
  1331. head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC];
  1332. m_node = list_first_entry(head,
  1333. struct drm_exynos_ipp_mem_node, list);
  1334. if (!m_node) {
  1335. DRM_ERROR("empty memory node.\n");
  1336. return -ENOMEM;
  1337. }
  1338. tbuf_id[EXYNOS_DRM_OPS_SRC] = m_node->buf_id;
  1339. ret = ipp_put_mem_node(drm_dev, c_node, m_node);
  1340. if (ret)
  1341. DRM_ERROR("failed to put m_node.\n");
  1342. break;
  1343. default:
  1344. DRM_ERROR("invalid operations.\n");
  1345. return -EINVAL;
  1346. }
  1347. if (tbuf_id[EXYNOS_DRM_OPS_DST] != buf_id[EXYNOS_DRM_OPS_DST])
  1348. DRM_ERROR("failed to match buf_id[%d %d]prop_id[%d]\n",
  1349. tbuf_id[1], buf_id[1], property->prop_id);
  1350. /*
  1351. * command node have event list of destination buffer
  1352. * If destination buffer enqueue to mem list,
  1353. * then we make event and link to event list tail.
  1354. * so, we get first event for first enqueued buffer.
  1355. */
  1356. e = list_first_entry(&c_node->event_list,
  1357. struct drm_exynos_ipp_send_event, base.link);
  1358. if (!e) {
  1359. DRM_ERROR("empty event.\n");
  1360. return -EINVAL;
  1361. }
  1362. do_gettimeofday(&now);
  1363. DRM_DEBUG_KMS("tv_sec[%ld]tv_usec[%ld]\n", now.tv_sec, now.tv_usec);
  1364. e->event.tv_sec = now.tv_sec;
  1365. e->event.tv_usec = now.tv_usec;
  1366. e->event.prop_id = property->prop_id;
  1367. /* set buffer id about source destination */
  1368. for_each_ipp_ops(i)
  1369. e->event.buf_id[i] = tbuf_id[i];
  1370. spin_lock_irqsave(&drm_dev->event_lock, flags);
  1371. list_move_tail(&e->base.link, &e->base.file_priv->event_list);
  1372. wake_up_interruptible(&e->base.file_priv->event_wait);
  1373. spin_unlock_irqrestore(&drm_dev->event_lock, flags);
  1374. DRM_DEBUG_KMS("done cmd[%d]prop_id[%d]buf_id[%d]\n",
  1375. property->cmd, property->prop_id, tbuf_id[EXYNOS_DRM_OPS_DST]);
  1376. return 0;
  1377. }
  1378. void ipp_sched_event(struct work_struct *work)
  1379. {
  1380. struct drm_exynos_ipp_event_work *event_work =
  1381. (struct drm_exynos_ipp_event_work *)work;
  1382. struct exynos_drm_ippdrv *ippdrv;
  1383. struct drm_exynos_ipp_cmd_node *c_node;
  1384. int ret;
  1385. if (!event_work) {
  1386. DRM_ERROR("failed to get event_work.\n");
  1387. return;
  1388. }
  1389. DRM_DEBUG_KMS("buf_id[%d]\n", event_work->buf_id[EXYNOS_DRM_OPS_DST]);
  1390. ippdrv = event_work->ippdrv;
  1391. if (!ippdrv) {
  1392. DRM_ERROR("failed to get ipp driver.\n");
  1393. return;
  1394. }
  1395. c_node = ippdrv->c_node;
  1396. if (!c_node) {
  1397. DRM_ERROR("failed to get command node.\n");
  1398. return;
  1399. }
  1400. /*
  1401. * IPP supports command thread, event thread synchronization.
  1402. * If IPP close immediately from user land, then IPP make
  1403. * synchronization with command thread, so make complete event.
  1404. * or going out operations.
  1405. */
  1406. if (c_node->state != IPP_STATE_START) {
  1407. DRM_DEBUG_KMS("bypass state[%d]prop_id[%d]\n",
  1408. c_node->state, c_node->property.prop_id);
  1409. goto err_completion;
  1410. }
  1411. mutex_lock(&c_node->event_lock);
  1412. ret = ipp_send_event(ippdrv, c_node, event_work->buf_id);
  1413. if (ret) {
  1414. DRM_ERROR("failed to send event.\n");
  1415. goto err_completion;
  1416. }
  1417. err_completion:
  1418. if (ipp_is_m2m_cmd(c_node->property.cmd))
  1419. complete(&c_node->start_complete);
  1420. mutex_unlock(&c_node->event_lock);
  1421. }
  1422. static int ipp_subdrv_probe(struct drm_device *drm_dev, struct device *dev)
  1423. {
  1424. struct ipp_context *ctx = get_ipp_context(dev);
  1425. struct exynos_drm_ippdrv *ippdrv;
  1426. int ret, count = 0;
  1427. /* get ipp driver entry */
  1428. list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
  1429. ippdrv->drm_dev = drm_dev;
  1430. ret = ipp_create_id(&ctx->ipp_idr, &ctx->ipp_lock, ippdrv,
  1431. &ippdrv->ipp_id);
  1432. if (ret) {
  1433. DRM_ERROR("failed to create id.\n");
  1434. goto err_idr;
  1435. }
  1436. DRM_DEBUG_KMS("count[%d]ippdrv[0x%x]ipp_id[%d]\n",
  1437. count++, (int)ippdrv, ippdrv->ipp_id);
  1438. if (ippdrv->ipp_id == 0) {
  1439. DRM_ERROR("failed to get ipp_id[%d]\n",
  1440. ippdrv->ipp_id);
  1441. goto err_idr;
  1442. }
  1443. /* store parent device for node */
  1444. ippdrv->parent_dev = dev;
  1445. /* store event work queue and handler */
  1446. ippdrv->event_workq = ctx->event_workq;
  1447. ippdrv->sched_event = ipp_sched_event;
  1448. INIT_LIST_HEAD(&ippdrv->cmd_list);
  1449. if (is_drm_iommu_supported(drm_dev)) {
  1450. ret = drm_iommu_attach_device(drm_dev, ippdrv->dev);
  1451. if (ret) {
  1452. DRM_ERROR("failed to activate iommu\n");
  1453. goto err_iommu;
  1454. }
  1455. }
  1456. }
  1457. return 0;
  1458. err_iommu:
  1459. /* get ipp driver entry */
  1460. list_for_each_entry_reverse(ippdrv, &exynos_drm_ippdrv_list, drv_list)
  1461. if (is_drm_iommu_supported(drm_dev))
  1462. drm_iommu_detach_device(drm_dev, ippdrv->dev);
  1463. err_idr:
  1464. idr_destroy(&ctx->ipp_idr);
  1465. idr_destroy(&ctx->prop_idr);
  1466. return ret;
  1467. }
  1468. static void ipp_subdrv_remove(struct drm_device *drm_dev, struct device *dev)
  1469. {
  1470. struct exynos_drm_ippdrv *ippdrv;
  1471. /* get ipp driver entry */
  1472. list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
  1473. if (is_drm_iommu_supported(drm_dev))
  1474. drm_iommu_detach_device(drm_dev, ippdrv->dev);
  1475. ippdrv->drm_dev = NULL;
  1476. exynos_drm_ippdrv_unregister(ippdrv);
  1477. }
  1478. }
  1479. static int ipp_subdrv_open(struct drm_device *drm_dev, struct device *dev,
  1480. struct drm_file *file)
  1481. {
  1482. struct drm_exynos_file_private *file_priv = file->driver_priv;
  1483. struct exynos_drm_ipp_private *priv;
  1484. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  1485. if (!priv) {
  1486. DRM_ERROR("failed to allocate priv.\n");
  1487. return -ENOMEM;
  1488. }
  1489. priv->dev = dev;
  1490. file_priv->ipp_priv = priv;
  1491. INIT_LIST_HEAD(&priv->event_list);
  1492. DRM_DEBUG_KMS("done priv[0x%x]\n", (int)priv);
  1493. return 0;
  1494. }
  1495. static void ipp_subdrv_close(struct drm_device *drm_dev, struct device *dev,
  1496. struct drm_file *file)
  1497. {
  1498. struct drm_exynos_file_private *file_priv = file->driver_priv;
  1499. struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
  1500. struct exynos_drm_ippdrv *ippdrv = NULL;
  1501. struct drm_exynos_ipp_cmd_node *c_node, *tc_node;
  1502. int count = 0;
  1503. DRM_DEBUG_KMS("for priv[0x%x]\n", (int)priv);
  1504. if (list_empty(&exynos_drm_ippdrv_list)) {
  1505. DRM_DEBUG_KMS("ippdrv_list is empty.\n");
  1506. goto err_clear;
  1507. }
  1508. list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
  1509. if (list_empty(&ippdrv->cmd_list))
  1510. continue;
  1511. list_for_each_entry_safe(c_node, tc_node,
  1512. &ippdrv->cmd_list, list) {
  1513. DRM_DEBUG_KMS("count[%d]ippdrv[0x%x]\n",
  1514. count++, (int)ippdrv);
  1515. if (c_node->priv == priv) {
  1516. /*
  1517. * userland goto unnormal state. process killed.
  1518. * and close the file.
  1519. * so, IPP didn't called stop cmd ctrl.
  1520. * so, we are make stop operation in this state.
  1521. */
  1522. if (c_node->state == IPP_STATE_START) {
  1523. ipp_stop_property(drm_dev, ippdrv,
  1524. c_node);
  1525. c_node->state = IPP_STATE_STOP;
  1526. }
  1527. ippdrv->dedicated = false;
  1528. ipp_clean_cmd_node(c_node);
  1529. if (list_empty(&ippdrv->cmd_list))
  1530. pm_runtime_put_sync(ippdrv->dev);
  1531. }
  1532. }
  1533. }
  1534. err_clear:
  1535. kfree(priv);
  1536. return;
  1537. }
  1538. static int ipp_probe(struct platform_device *pdev)
  1539. {
  1540. struct device *dev = &pdev->dev;
  1541. struct ipp_context *ctx;
  1542. struct exynos_drm_subdrv *subdrv;
  1543. int ret;
  1544. ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
  1545. if (!ctx)
  1546. return -ENOMEM;
  1547. mutex_init(&ctx->ipp_lock);
  1548. mutex_init(&ctx->prop_lock);
  1549. idr_init(&ctx->ipp_idr);
  1550. idr_init(&ctx->prop_idr);
  1551. /*
  1552. * create single thread for ipp event
  1553. * IPP supports event thread for IPP drivers.
  1554. * IPP driver send event_work to this thread.
  1555. * and IPP event thread send event to user process.
  1556. */
  1557. ctx->event_workq = create_singlethread_workqueue("ipp_event");
  1558. if (!ctx->event_workq) {
  1559. dev_err(dev, "failed to create event workqueue\n");
  1560. return -EINVAL;
  1561. }
  1562. /*
  1563. * create single thread for ipp command
  1564. * IPP supports command thread for user process.
  1565. * user process make command node using set property ioctl.
  1566. * and make start_work and send this work to command thread.
  1567. * and then this command thread start property.
  1568. */
  1569. ctx->cmd_workq = create_singlethread_workqueue("ipp_cmd");
  1570. if (!ctx->cmd_workq) {
  1571. dev_err(dev, "failed to create cmd workqueue\n");
  1572. ret = -EINVAL;
  1573. goto err_event_workq;
  1574. }
  1575. /* set sub driver informations */
  1576. subdrv = &ctx->subdrv;
  1577. subdrv->dev = dev;
  1578. subdrv->probe = ipp_subdrv_probe;
  1579. subdrv->remove = ipp_subdrv_remove;
  1580. subdrv->open = ipp_subdrv_open;
  1581. subdrv->close = ipp_subdrv_close;
  1582. platform_set_drvdata(pdev, ctx);
  1583. ret = exynos_drm_subdrv_register(subdrv);
  1584. if (ret < 0) {
  1585. DRM_ERROR("failed to register drm ipp device.\n");
  1586. goto err_cmd_workq;
  1587. }
  1588. dev_info(dev, "drm ipp registered successfully.\n");
  1589. return 0;
  1590. err_cmd_workq:
  1591. destroy_workqueue(ctx->cmd_workq);
  1592. err_event_workq:
  1593. destroy_workqueue(ctx->event_workq);
  1594. return ret;
  1595. }
  1596. static int ipp_remove(struct platform_device *pdev)
  1597. {
  1598. struct ipp_context *ctx = platform_get_drvdata(pdev);
  1599. /* unregister sub driver */
  1600. exynos_drm_subdrv_unregister(&ctx->subdrv);
  1601. /* remove,destroy ipp idr */
  1602. idr_destroy(&ctx->ipp_idr);
  1603. idr_destroy(&ctx->prop_idr);
  1604. mutex_destroy(&ctx->ipp_lock);
  1605. mutex_destroy(&ctx->prop_lock);
  1606. /* destroy command, event work queue */
  1607. destroy_workqueue(ctx->cmd_workq);
  1608. destroy_workqueue(ctx->event_workq);
  1609. return 0;
  1610. }
  1611. static int ipp_power_ctrl(struct ipp_context *ctx, bool enable)
  1612. {
  1613. DRM_DEBUG_KMS("enable[%d]\n", enable);
  1614. return 0;
  1615. }
  1616. #ifdef CONFIG_PM_SLEEP
  1617. static int ipp_suspend(struct device *dev)
  1618. {
  1619. struct ipp_context *ctx = get_ipp_context(dev);
  1620. if (pm_runtime_suspended(dev))
  1621. return 0;
  1622. return ipp_power_ctrl(ctx, false);
  1623. }
  1624. static int ipp_resume(struct device *dev)
  1625. {
  1626. struct ipp_context *ctx = get_ipp_context(dev);
  1627. if (!pm_runtime_suspended(dev))
  1628. return ipp_power_ctrl(ctx, true);
  1629. return 0;
  1630. }
  1631. #endif
  1632. #ifdef CONFIG_PM_RUNTIME
  1633. static int ipp_runtime_suspend(struct device *dev)
  1634. {
  1635. struct ipp_context *ctx = get_ipp_context(dev);
  1636. return ipp_power_ctrl(ctx, false);
  1637. }
  1638. static int ipp_runtime_resume(struct device *dev)
  1639. {
  1640. struct ipp_context *ctx = get_ipp_context(dev);
  1641. return ipp_power_ctrl(ctx, true);
  1642. }
  1643. #endif
  1644. static const struct dev_pm_ops ipp_pm_ops = {
  1645. SET_SYSTEM_SLEEP_PM_OPS(ipp_suspend, ipp_resume)
  1646. SET_RUNTIME_PM_OPS(ipp_runtime_suspend, ipp_runtime_resume, NULL)
  1647. };
  1648. struct platform_driver ipp_driver = {
  1649. .probe = ipp_probe,
  1650. .remove = ipp_remove,
  1651. .driver = {
  1652. .name = "exynos-drm-ipp",
  1653. .owner = THIS_MODULE,
  1654. .pm = &ipp_pm_ops,
  1655. },
  1656. };