exynos_drm_ipp.c 47 KB

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