exynos_drm_ipp.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000
  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. break;
  886. }
  887. return true;
  888. err_status:
  889. DRM_ERROR("invalid status:ctrl[%d]state[%d]\n", ctrl, state);
  890. return false;
  891. }
  892. int exynos_drm_ipp_cmd_ctrl(struct drm_device *drm_dev, void *data,
  893. struct drm_file *file)
  894. {
  895. struct drm_exynos_file_private *file_priv = file->driver_priv;
  896. struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
  897. struct exynos_drm_ippdrv *ippdrv = NULL;
  898. struct device *dev = priv->dev;
  899. struct ipp_context *ctx = get_ipp_context(dev);
  900. struct drm_exynos_ipp_cmd_ctrl *cmd_ctrl = data;
  901. struct drm_exynos_ipp_cmd_work *cmd_work;
  902. struct drm_exynos_ipp_cmd_node *c_node;
  903. if (!ctx) {
  904. DRM_ERROR("invalid context.\n");
  905. return -EINVAL;
  906. }
  907. if (!cmd_ctrl) {
  908. DRM_ERROR("invalid control parameter.\n");
  909. return -EINVAL;
  910. }
  911. DRM_DEBUG_KMS("ctrl[%d]prop_id[%d]\n",
  912. cmd_ctrl->ctrl, cmd_ctrl->prop_id);
  913. ippdrv = ipp_find_drv_by_handle(cmd_ctrl->prop_id);
  914. if (IS_ERR(ippdrv)) {
  915. DRM_ERROR("failed to get ipp driver.\n");
  916. return PTR_ERR(ippdrv);
  917. }
  918. c_node = ipp_find_obj(&ctx->prop_idr, &ctx->prop_lock,
  919. cmd_ctrl->prop_id);
  920. if (!c_node) {
  921. DRM_ERROR("invalid command node list.\n");
  922. return -EINVAL;
  923. }
  924. if (!exynos_drm_ipp_check_valid(ippdrv->dev, cmd_ctrl->ctrl,
  925. c_node->state)) {
  926. DRM_ERROR("invalid state.\n");
  927. return -EINVAL;
  928. }
  929. switch (cmd_ctrl->ctrl) {
  930. case IPP_CTRL_PLAY:
  931. if (pm_runtime_suspended(ippdrv->dev))
  932. pm_runtime_get_sync(ippdrv->dev);
  933. c_node->state = IPP_STATE_START;
  934. cmd_work = c_node->start_work;
  935. cmd_work->ctrl = cmd_ctrl->ctrl;
  936. ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
  937. c_node->state = IPP_STATE_START;
  938. break;
  939. case IPP_CTRL_STOP:
  940. cmd_work = c_node->stop_work;
  941. cmd_work->ctrl = cmd_ctrl->ctrl;
  942. ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
  943. if (!wait_for_completion_timeout(&c_node->stop_complete,
  944. msecs_to_jiffies(300))) {
  945. DRM_ERROR("timeout stop:prop_id[%d]\n",
  946. c_node->property.prop_id);
  947. }
  948. c_node->state = IPP_STATE_STOP;
  949. ippdrv->dedicated = false;
  950. ipp_clean_cmd_node(c_node);
  951. if (list_empty(&ippdrv->cmd_list))
  952. pm_runtime_put_sync(ippdrv->dev);
  953. break;
  954. case IPP_CTRL_PAUSE:
  955. cmd_work = c_node->stop_work;
  956. cmd_work->ctrl = cmd_ctrl->ctrl;
  957. ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
  958. if (!wait_for_completion_timeout(&c_node->stop_complete,
  959. msecs_to_jiffies(200))) {
  960. DRM_ERROR("timeout stop:prop_id[%d]\n",
  961. c_node->property.prop_id);
  962. }
  963. c_node->state = IPP_STATE_STOP;
  964. break;
  965. case IPP_CTRL_RESUME:
  966. c_node->state = IPP_STATE_START;
  967. cmd_work = c_node->start_work;
  968. cmd_work->ctrl = cmd_ctrl->ctrl;
  969. ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
  970. break;
  971. default:
  972. DRM_ERROR("could not support this state currently.\n");
  973. return -EINVAL;
  974. }
  975. DRM_DEBUG_KMS("done ctrl[%d]prop_id[%d]\n",
  976. cmd_ctrl->ctrl, cmd_ctrl->prop_id);
  977. return 0;
  978. }
  979. int exynos_drm_ippnb_register(struct notifier_block *nb)
  980. {
  981. return blocking_notifier_chain_register(
  982. &exynos_drm_ippnb_list, nb);
  983. }
  984. int exynos_drm_ippnb_unregister(struct notifier_block *nb)
  985. {
  986. return blocking_notifier_chain_unregister(
  987. &exynos_drm_ippnb_list, nb);
  988. }
  989. int exynos_drm_ippnb_send_event(unsigned long val, void *v)
  990. {
  991. return blocking_notifier_call_chain(
  992. &exynos_drm_ippnb_list, val, v);
  993. }
  994. static int ipp_set_property(struct exynos_drm_ippdrv *ippdrv,
  995. struct drm_exynos_ipp_property *property)
  996. {
  997. struct exynos_drm_ipp_ops *ops = NULL;
  998. bool swap = false;
  999. int ret, i;
  1000. if (!property) {
  1001. DRM_ERROR("invalid property parameter.\n");
  1002. return -EINVAL;
  1003. }
  1004. DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id);
  1005. /* reset h/w block */
  1006. if (ippdrv->reset &&
  1007. ippdrv->reset(ippdrv->dev)) {
  1008. DRM_ERROR("failed to reset.\n");
  1009. return -EINVAL;
  1010. }
  1011. /* set source,destination operations */
  1012. for_each_ipp_ops(i) {
  1013. struct drm_exynos_ipp_config *config =
  1014. &property->config[i];
  1015. ops = ippdrv->ops[i];
  1016. if (!ops || !config) {
  1017. DRM_ERROR("not support ops and config.\n");
  1018. return -EINVAL;
  1019. }
  1020. /* set format */
  1021. if (ops->set_fmt) {
  1022. ret = ops->set_fmt(ippdrv->dev, config->fmt);
  1023. if (ret) {
  1024. DRM_ERROR("not support format.\n");
  1025. return ret;
  1026. }
  1027. }
  1028. /* set transform for rotation, flip */
  1029. if (ops->set_transf) {
  1030. ret = ops->set_transf(ippdrv->dev, config->degree,
  1031. config->flip, &swap);
  1032. if (ret) {
  1033. DRM_ERROR("not support tranf.\n");
  1034. return -EINVAL;
  1035. }
  1036. }
  1037. /* set size */
  1038. if (ops->set_size) {
  1039. ret = ops->set_size(ippdrv->dev, swap, &config->pos,
  1040. &config->sz);
  1041. if (ret) {
  1042. DRM_ERROR("not support size.\n");
  1043. return ret;
  1044. }
  1045. }
  1046. }
  1047. return 0;
  1048. }
  1049. static int ipp_start_property(struct exynos_drm_ippdrv *ippdrv,
  1050. struct drm_exynos_ipp_cmd_node *c_node)
  1051. {
  1052. struct drm_exynos_ipp_mem_node *m_node;
  1053. struct drm_exynos_ipp_property *property = &c_node->property;
  1054. struct list_head *head;
  1055. int ret, i;
  1056. DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id);
  1057. /* store command info in ippdrv */
  1058. ippdrv->c_node = c_node;
  1059. if (!ipp_check_mem_list(c_node)) {
  1060. DRM_DEBUG_KMS("empty memory.\n");
  1061. return -ENOMEM;
  1062. }
  1063. /* set current property in ippdrv */
  1064. ret = ipp_set_property(ippdrv, property);
  1065. if (ret) {
  1066. DRM_ERROR("failed to set property.\n");
  1067. ippdrv->c_node = NULL;
  1068. return ret;
  1069. }
  1070. /* check command */
  1071. switch (property->cmd) {
  1072. case IPP_CMD_M2M:
  1073. for_each_ipp_ops(i) {
  1074. /* source/destination memory list */
  1075. head = &c_node->mem_list[i];
  1076. m_node = list_first_entry(head,
  1077. struct drm_exynos_ipp_mem_node, list);
  1078. if (!m_node) {
  1079. DRM_ERROR("failed to get node.\n");
  1080. ret = -EFAULT;
  1081. return ret;
  1082. }
  1083. DRM_DEBUG_KMS("m_node[0x%x]\n", (int)m_node);
  1084. ret = ipp_set_mem_node(ippdrv, c_node, m_node);
  1085. if (ret) {
  1086. DRM_ERROR("failed to set m node.\n");
  1087. return ret;
  1088. }
  1089. }
  1090. break;
  1091. case IPP_CMD_WB:
  1092. /* destination memory list */
  1093. head = &c_node->mem_list[EXYNOS_DRM_OPS_DST];
  1094. list_for_each_entry(m_node, head, list) {
  1095. ret = ipp_set_mem_node(ippdrv, c_node, m_node);
  1096. if (ret) {
  1097. DRM_ERROR("failed to set m node.\n");
  1098. return ret;
  1099. }
  1100. }
  1101. break;
  1102. case IPP_CMD_OUTPUT:
  1103. /* source memory list */
  1104. head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC];
  1105. list_for_each_entry(m_node, head, list) {
  1106. ret = ipp_set_mem_node(ippdrv, c_node, m_node);
  1107. if (ret) {
  1108. DRM_ERROR("failed to set m node.\n");
  1109. return ret;
  1110. }
  1111. }
  1112. break;
  1113. default:
  1114. DRM_ERROR("invalid operations.\n");
  1115. return -EINVAL;
  1116. }
  1117. DRM_DEBUG_KMS("cmd[%d]\n", property->cmd);
  1118. /* start operations */
  1119. if (ippdrv->start) {
  1120. ret = ippdrv->start(ippdrv->dev, property->cmd);
  1121. if (ret) {
  1122. DRM_ERROR("failed to start ops.\n");
  1123. return ret;
  1124. }
  1125. }
  1126. return 0;
  1127. }
  1128. static int ipp_stop_property(struct drm_device *drm_dev,
  1129. struct exynos_drm_ippdrv *ippdrv,
  1130. struct drm_exynos_ipp_cmd_node *c_node)
  1131. {
  1132. struct drm_exynos_ipp_mem_node *m_node, *tm_node;
  1133. struct drm_exynos_ipp_property *property = &c_node->property;
  1134. struct list_head *head;
  1135. int ret = 0, i;
  1136. DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id);
  1137. /* put event */
  1138. ipp_put_event(c_node, NULL);
  1139. /* check command */
  1140. switch (property->cmd) {
  1141. case IPP_CMD_M2M:
  1142. for_each_ipp_ops(i) {
  1143. /* source/destination memory list */
  1144. head = &c_node->mem_list[i];
  1145. if (list_empty(head)) {
  1146. DRM_DEBUG_KMS("mem_list is empty.\n");
  1147. break;
  1148. }
  1149. list_for_each_entry_safe(m_node, tm_node,
  1150. head, list) {
  1151. ret = ipp_put_mem_node(drm_dev, c_node,
  1152. m_node);
  1153. if (ret) {
  1154. DRM_ERROR("failed to put m_node.\n");
  1155. goto err_clear;
  1156. }
  1157. }
  1158. }
  1159. break;
  1160. case IPP_CMD_WB:
  1161. /* destination memory list */
  1162. head = &c_node->mem_list[EXYNOS_DRM_OPS_DST];
  1163. if (list_empty(head)) {
  1164. DRM_DEBUG_KMS("mem_list is empty.\n");
  1165. break;
  1166. }
  1167. list_for_each_entry_safe(m_node, tm_node, head, list) {
  1168. ret = ipp_put_mem_node(drm_dev, c_node, m_node);
  1169. if (ret) {
  1170. DRM_ERROR("failed to put m_node.\n");
  1171. goto err_clear;
  1172. }
  1173. }
  1174. break;
  1175. case IPP_CMD_OUTPUT:
  1176. /* source memory list */
  1177. head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC];
  1178. if (list_empty(head)) {
  1179. DRM_DEBUG_KMS("mem_list is empty.\n");
  1180. break;
  1181. }
  1182. list_for_each_entry_safe(m_node, tm_node, head, list) {
  1183. ret = ipp_put_mem_node(drm_dev, c_node, m_node);
  1184. if (ret) {
  1185. DRM_ERROR("failed to put m_node.\n");
  1186. goto err_clear;
  1187. }
  1188. }
  1189. break;
  1190. default:
  1191. DRM_ERROR("invalid operations.\n");
  1192. ret = -EINVAL;
  1193. goto err_clear;
  1194. }
  1195. err_clear:
  1196. /* stop operations */
  1197. if (ippdrv->stop)
  1198. ippdrv->stop(ippdrv->dev, property->cmd);
  1199. return ret;
  1200. }
  1201. void ipp_sched_cmd(struct work_struct *work)
  1202. {
  1203. struct drm_exynos_ipp_cmd_work *cmd_work =
  1204. (struct drm_exynos_ipp_cmd_work *)work;
  1205. struct exynos_drm_ippdrv *ippdrv;
  1206. struct drm_exynos_ipp_cmd_node *c_node;
  1207. struct drm_exynos_ipp_property *property;
  1208. int ret;
  1209. ippdrv = cmd_work->ippdrv;
  1210. if (!ippdrv) {
  1211. DRM_ERROR("invalid ippdrv list.\n");
  1212. return;
  1213. }
  1214. c_node = cmd_work->c_node;
  1215. if (!c_node) {
  1216. DRM_ERROR("invalid command node list.\n");
  1217. return;
  1218. }
  1219. mutex_lock(&c_node->cmd_lock);
  1220. property = &c_node->property;
  1221. switch (cmd_work->ctrl) {
  1222. case IPP_CTRL_PLAY:
  1223. case IPP_CTRL_RESUME:
  1224. ret = ipp_start_property(ippdrv, c_node);
  1225. if (ret) {
  1226. DRM_ERROR("failed to start property:prop_id[%d]\n",
  1227. c_node->property.prop_id);
  1228. goto err_unlock;
  1229. }
  1230. /*
  1231. * M2M case supports wait_completion of transfer.
  1232. * because M2M case supports single unit operation
  1233. * with multiple queue.
  1234. * M2M need to wait completion of data transfer.
  1235. */
  1236. if (ipp_is_m2m_cmd(property->cmd)) {
  1237. if (!wait_for_completion_timeout
  1238. (&c_node->start_complete, msecs_to_jiffies(200))) {
  1239. DRM_ERROR("timeout event:prop_id[%d]\n",
  1240. c_node->property.prop_id);
  1241. goto err_unlock;
  1242. }
  1243. }
  1244. break;
  1245. case IPP_CTRL_STOP:
  1246. case IPP_CTRL_PAUSE:
  1247. ret = ipp_stop_property(ippdrv->drm_dev, ippdrv,
  1248. c_node);
  1249. if (ret) {
  1250. DRM_ERROR("failed to stop property.\n");
  1251. goto err_unlock;
  1252. }
  1253. complete(&c_node->stop_complete);
  1254. break;
  1255. default:
  1256. DRM_ERROR("unknown control type\n");
  1257. break;
  1258. }
  1259. DRM_DEBUG_KMS("ctrl[%d] done.\n", cmd_work->ctrl);
  1260. err_unlock:
  1261. mutex_unlock(&c_node->cmd_lock);
  1262. }
  1263. static int ipp_send_event(struct exynos_drm_ippdrv *ippdrv,
  1264. struct drm_exynos_ipp_cmd_node *c_node, int *buf_id)
  1265. {
  1266. struct drm_device *drm_dev = ippdrv->drm_dev;
  1267. struct drm_exynos_ipp_property *property = &c_node->property;
  1268. struct drm_exynos_ipp_mem_node *m_node;
  1269. struct drm_exynos_ipp_queue_buf qbuf;
  1270. struct drm_exynos_ipp_send_event *e;
  1271. struct list_head *head;
  1272. struct timeval now;
  1273. unsigned long flags;
  1274. u32 tbuf_id[EXYNOS_DRM_OPS_MAX] = {0, };
  1275. int ret, i;
  1276. for_each_ipp_ops(i)
  1277. DRM_DEBUG_KMS("%s buf_id[%d]\n", i ? "dst" : "src", buf_id[i]);
  1278. if (!drm_dev) {
  1279. DRM_ERROR("failed to get drm_dev.\n");
  1280. return -EINVAL;
  1281. }
  1282. if (!property) {
  1283. DRM_ERROR("failed to get property.\n");
  1284. return -EINVAL;
  1285. }
  1286. if (list_empty(&c_node->event_list)) {
  1287. DRM_DEBUG_KMS("event list is empty.\n");
  1288. return 0;
  1289. }
  1290. if (!ipp_check_mem_list(c_node)) {
  1291. DRM_DEBUG_KMS("empty memory.\n");
  1292. return 0;
  1293. }
  1294. /* check command */
  1295. switch (property->cmd) {
  1296. case IPP_CMD_M2M:
  1297. for_each_ipp_ops(i) {
  1298. /* source/destination memory list */
  1299. head = &c_node->mem_list[i];
  1300. m_node = list_first_entry(head,
  1301. struct drm_exynos_ipp_mem_node, list);
  1302. if (!m_node) {
  1303. DRM_ERROR("empty memory node.\n");
  1304. return -ENOMEM;
  1305. }
  1306. tbuf_id[i] = m_node->buf_id;
  1307. DRM_DEBUG_KMS("%s buf_id[%d]\n",
  1308. i ? "dst" : "src", tbuf_id[i]);
  1309. ret = ipp_put_mem_node(drm_dev, c_node, m_node);
  1310. if (ret)
  1311. DRM_ERROR("failed to put m_node.\n");
  1312. }
  1313. break;
  1314. case IPP_CMD_WB:
  1315. /* clear buf for finding */
  1316. memset(&qbuf, 0x0, sizeof(qbuf));
  1317. qbuf.ops_id = EXYNOS_DRM_OPS_DST;
  1318. qbuf.buf_id = buf_id[EXYNOS_DRM_OPS_DST];
  1319. /* get memory node entry */
  1320. m_node = ipp_find_mem_node(c_node, &qbuf);
  1321. if (!m_node) {
  1322. DRM_ERROR("empty memory node.\n");
  1323. return -ENOMEM;
  1324. }
  1325. tbuf_id[EXYNOS_DRM_OPS_DST] = m_node->buf_id;
  1326. ret = ipp_put_mem_node(drm_dev, c_node, m_node);
  1327. if (ret)
  1328. DRM_ERROR("failed to put m_node.\n");
  1329. break;
  1330. case IPP_CMD_OUTPUT:
  1331. /* source memory list */
  1332. head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC];
  1333. m_node = list_first_entry(head,
  1334. struct drm_exynos_ipp_mem_node, list);
  1335. if (!m_node) {
  1336. DRM_ERROR("empty memory node.\n");
  1337. return -ENOMEM;
  1338. }
  1339. tbuf_id[EXYNOS_DRM_OPS_SRC] = m_node->buf_id;
  1340. ret = ipp_put_mem_node(drm_dev, c_node, m_node);
  1341. if (ret)
  1342. DRM_ERROR("failed to put m_node.\n");
  1343. break;
  1344. default:
  1345. DRM_ERROR("invalid operations.\n");
  1346. return -EINVAL;
  1347. }
  1348. if (tbuf_id[EXYNOS_DRM_OPS_DST] != buf_id[EXYNOS_DRM_OPS_DST])
  1349. DRM_ERROR("failed to match buf_id[%d %d]prop_id[%d]\n",
  1350. tbuf_id[1], buf_id[1], property->prop_id);
  1351. /*
  1352. * command node have event list of destination buffer
  1353. * If destination buffer enqueue to mem list,
  1354. * then we make event and link to event list tail.
  1355. * so, we get first event for first enqueued buffer.
  1356. */
  1357. e = list_first_entry(&c_node->event_list,
  1358. struct drm_exynos_ipp_send_event, base.link);
  1359. if (!e) {
  1360. DRM_ERROR("empty event.\n");
  1361. return -EINVAL;
  1362. }
  1363. do_gettimeofday(&now);
  1364. DRM_DEBUG_KMS("tv_sec[%ld]tv_usec[%ld]\n", now.tv_sec, now.tv_usec);
  1365. e->event.tv_sec = now.tv_sec;
  1366. e->event.tv_usec = now.tv_usec;
  1367. e->event.prop_id = property->prop_id;
  1368. /* set buffer id about source destination */
  1369. for_each_ipp_ops(i)
  1370. e->event.buf_id[i] = tbuf_id[i];
  1371. spin_lock_irqsave(&drm_dev->event_lock, flags);
  1372. list_move_tail(&e->base.link, &e->base.file_priv->event_list);
  1373. wake_up_interruptible(&e->base.file_priv->event_wait);
  1374. spin_unlock_irqrestore(&drm_dev->event_lock, flags);
  1375. DRM_DEBUG_KMS("done cmd[%d]prop_id[%d]buf_id[%d]\n",
  1376. property->cmd, property->prop_id, tbuf_id[EXYNOS_DRM_OPS_DST]);
  1377. return 0;
  1378. }
  1379. void ipp_sched_event(struct work_struct *work)
  1380. {
  1381. struct drm_exynos_ipp_event_work *event_work =
  1382. (struct drm_exynos_ipp_event_work *)work;
  1383. struct exynos_drm_ippdrv *ippdrv;
  1384. struct drm_exynos_ipp_cmd_node *c_node;
  1385. int ret;
  1386. if (!event_work) {
  1387. DRM_ERROR("failed to get event_work.\n");
  1388. return;
  1389. }
  1390. DRM_DEBUG_KMS("buf_id[%d]\n", event_work->buf_id[EXYNOS_DRM_OPS_DST]);
  1391. ippdrv = event_work->ippdrv;
  1392. if (!ippdrv) {
  1393. DRM_ERROR("failed to get ipp driver.\n");
  1394. return;
  1395. }
  1396. c_node = ippdrv->c_node;
  1397. if (!c_node) {
  1398. DRM_ERROR("failed to get command node.\n");
  1399. return;
  1400. }
  1401. /*
  1402. * IPP supports command thread, event thread synchronization.
  1403. * If IPP close immediately from user land, then IPP make
  1404. * synchronization with command thread, so make complete event.
  1405. * or going out operations.
  1406. */
  1407. if (c_node->state != IPP_STATE_START) {
  1408. DRM_DEBUG_KMS("bypass state[%d]prop_id[%d]\n",
  1409. c_node->state, c_node->property.prop_id);
  1410. goto err_completion;
  1411. }
  1412. mutex_lock(&c_node->event_lock);
  1413. ret = ipp_send_event(ippdrv, c_node, event_work->buf_id);
  1414. if (ret) {
  1415. DRM_ERROR("failed to send event.\n");
  1416. goto err_completion;
  1417. }
  1418. err_completion:
  1419. if (ipp_is_m2m_cmd(c_node->property.cmd))
  1420. complete(&c_node->start_complete);
  1421. mutex_unlock(&c_node->event_lock);
  1422. }
  1423. static int ipp_subdrv_probe(struct drm_device *drm_dev, struct device *dev)
  1424. {
  1425. struct ipp_context *ctx = get_ipp_context(dev);
  1426. struct exynos_drm_ippdrv *ippdrv;
  1427. int ret, count = 0;
  1428. /* get ipp driver entry */
  1429. list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
  1430. ippdrv->drm_dev = drm_dev;
  1431. ret = ipp_create_id(&ctx->ipp_idr, &ctx->ipp_lock, ippdrv,
  1432. &ippdrv->ipp_id);
  1433. if (ret) {
  1434. DRM_ERROR("failed to create id.\n");
  1435. goto err_idr;
  1436. }
  1437. DRM_DEBUG_KMS("count[%d]ippdrv[0x%x]ipp_id[%d]\n",
  1438. count++, (int)ippdrv, ippdrv->ipp_id);
  1439. if (ippdrv->ipp_id == 0) {
  1440. DRM_ERROR("failed to get ipp_id[%d]\n",
  1441. ippdrv->ipp_id);
  1442. goto err_idr;
  1443. }
  1444. /* store parent device for node */
  1445. ippdrv->parent_dev = dev;
  1446. /* store event work queue and handler */
  1447. ippdrv->event_workq = ctx->event_workq;
  1448. ippdrv->sched_event = ipp_sched_event;
  1449. INIT_LIST_HEAD(&ippdrv->cmd_list);
  1450. if (is_drm_iommu_supported(drm_dev)) {
  1451. ret = drm_iommu_attach_device(drm_dev, ippdrv->dev);
  1452. if (ret) {
  1453. DRM_ERROR("failed to activate iommu\n");
  1454. goto err_iommu;
  1455. }
  1456. }
  1457. }
  1458. return 0;
  1459. err_iommu:
  1460. /* get ipp driver entry */
  1461. list_for_each_entry_reverse(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. err_idr:
  1465. idr_destroy(&ctx->ipp_idr);
  1466. idr_destroy(&ctx->prop_idr);
  1467. return ret;
  1468. }
  1469. static void ipp_subdrv_remove(struct drm_device *drm_dev, struct device *dev)
  1470. {
  1471. struct exynos_drm_ippdrv *ippdrv;
  1472. /* get ipp driver entry */
  1473. list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
  1474. if (is_drm_iommu_supported(drm_dev))
  1475. drm_iommu_detach_device(drm_dev, ippdrv->dev);
  1476. ippdrv->drm_dev = NULL;
  1477. exynos_drm_ippdrv_unregister(ippdrv);
  1478. }
  1479. }
  1480. static int ipp_subdrv_open(struct drm_device *drm_dev, struct device *dev,
  1481. struct drm_file *file)
  1482. {
  1483. struct drm_exynos_file_private *file_priv = file->driver_priv;
  1484. struct exynos_drm_ipp_private *priv;
  1485. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  1486. if (!priv) {
  1487. DRM_ERROR("failed to allocate priv.\n");
  1488. return -ENOMEM;
  1489. }
  1490. priv->dev = dev;
  1491. file_priv->ipp_priv = priv;
  1492. INIT_LIST_HEAD(&priv->event_list);
  1493. DRM_DEBUG_KMS("done priv[0x%x]\n", (int)priv);
  1494. return 0;
  1495. }
  1496. static void ipp_subdrv_close(struct drm_device *drm_dev, struct device *dev,
  1497. struct drm_file *file)
  1498. {
  1499. struct drm_exynos_file_private *file_priv = file->driver_priv;
  1500. struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
  1501. struct exynos_drm_ippdrv *ippdrv = NULL;
  1502. struct drm_exynos_ipp_cmd_node *c_node, *tc_node;
  1503. int count = 0;
  1504. DRM_DEBUG_KMS("for priv[0x%x]\n", (int)priv);
  1505. if (list_empty(&exynos_drm_ippdrv_list)) {
  1506. DRM_DEBUG_KMS("ippdrv_list is empty.\n");
  1507. goto err_clear;
  1508. }
  1509. list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
  1510. if (list_empty(&ippdrv->cmd_list))
  1511. continue;
  1512. list_for_each_entry_safe(c_node, tc_node,
  1513. &ippdrv->cmd_list, list) {
  1514. DRM_DEBUG_KMS("count[%d]ippdrv[0x%x]\n",
  1515. count++, (int)ippdrv);
  1516. if (c_node->priv == priv) {
  1517. /*
  1518. * userland goto unnormal state. process killed.
  1519. * and close the file.
  1520. * so, IPP didn't called stop cmd ctrl.
  1521. * so, we are make stop operation in this state.
  1522. */
  1523. if (c_node->state == IPP_STATE_START) {
  1524. ipp_stop_property(drm_dev, ippdrv,
  1525. c_node);
  1526. c_node->state = IPP_STATE_STOP;
  1527. }
  1528. ippdrv->dedicated = false;
  1529. ipp_clean_cmd_node(c_node);
  1530. if (list_empty(&ippdrv->cmd_list))
  1531. pm_runtime_put_sync(ippdrv->dev);
  1532. }
  1533. }
  1534. }
  1535. err_clear:
  1536. kfree(priv);
  1537. return;
  1538. }
  1539. static int ipp_probe(struct platform_device *pdev)
  1540. {
  1541. struct device *dev = &pdev->dev;
  1542. struct ipp_context *ctx;
  1543. struct exynos_drm_subdrv *subdrv;
  1544. int ret;
  1545. ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
  1546. if (!ctx)
  1547. return -ENOMEM;
  1548. mutex_init(&ctx->ipp_lock);
  1549. mutex_init(&ctx->prop_lock);
  1550. idr_init(&ctx->ipp_idr);
  1551. idr_init(&ctx->prop_idr);
  1552. /*
  1553. * create single thread for ipp event
  1554. * IPP supports event thread for IPP drivers.
  1555. * IPP driver send event_work to this thread.
  1556. * and IPP event thread send event to user process.
  1557. */
  1558. ctx->event_workq = create_singlethread_workqueue("ipp_event");
  1559. if (!ctx->event_workq) {
  1560. dev_err(dev, "failed to create event workqueue\n");
  1561. return -EINVAL;
  1562. }
  1563. /*
  1564. * create single thread for ipp command
  1565. * IPP supports command thread for user process.
  1566. * user process make command node using set property ioctl.
  1567. * and make start_work and send this work to command thread.
  1568. * and then this command thread start property.
  1569. */
  1570. ctx->cmd_workq = create_singlethread_workqueue("ipp_cmd");
  1571. if (!ctx->cmd_workq) {
  1572. dev_err(dev, "failed to create cmd workqueue\n");
  1573. ret = -EINVAL;
  1574. goto err_event_workq;
  1575. }
  1576. /* set sub driver informations */
  1577. subdrv = &ctx->subdrv;
  1578. subdrv->dev = dev;
  1579. subdrv->probe = ipp_subdrv_probe;
  1580. subdrv->remove = ipp_subdrv_remove;
  1581. subdrv->open = ipp_subdrv_open;
  1582. subdrv->close = ipp_subdrv_close;
  1583. platform_set_drvdata(pdev, ctx);
  1584. ret = exynos_drm_subdrv_register(subdrv);
  1585. if (ret < 0) {
  1586. DRM_ERROR("failed to register drm ipp device.\n");
  1587. goto err_cmd_workq;
  1588. }
  1589. dev_info(dev, "drm ipp registered successfully.\n");
  1590. return 0;
  1591. err_cmd_workq:
  1592. destroy_workqueue(ctx->cmd_workq);
  1593. err_event_workq:
  1594. destroy_workqueue(ctx->event_workq);
  1595. return ret;
  1596. }
  1597. static int ipp_remove(struct platform_device *pdev)
  1598. {
  1599. struct ipp_context *ctx = platform_get_drvdata(pdev);
  1600. /* unregister sub driver */
  1601. exynos_drm_subdrv_unregister(&ctx->subdrv);
  1602. /* remove,destroy ipp idr */
  1603. idr_destroy(&ctx->ipp_idr);
  1604. idr_destroy(&ctx->prop_idr);
  1605. mutex_destroy(&ctx->ipp_lock);
  1606. mutex_destroy(&ctx->prop_lock);
  1607. /* destroy command, event work queue */
  1608. destroy_workqueue(ctx->cmd_workq);
  1609. destroy_workqueue(ctx->event_workq);
  1610. return 0;
  1611. }
  1612. static int ipp_power_ctrl(struct ipp_context *ctx, bool enable)
  1613. {
  1614. DRM_DEBUG_KMS("enable[%d]\n", enable);
  1615. return 0;
  1616. }
  1617. #ifdef CONFIG_PM_SLEEP
  1618. static int ipp_suspend(struct device *dev)
  1619. {
  1620. struct ipp_context *ctx = get_ipp_context(dev);
  1621. if (pm_runtime_suspended(dev))
  1622. return 0;
  1623. return ipp_power_ctrl(ctx, false);
  1624. }
  1625. static int ipp_resume(struct device *dev)
  1626. {
  1627. struct ipp_context *ctx = get_ipp_context(dev);
  1628. if (!pm_runtime_suspended(dev))
  1629. return ipp_power_ctrl(ctx, true);
  1630. return 0;
  1631. }
  1632. #endif
  1633. #ifdef CONFIG_PM_RUNTIME
  1634. static int ipp_runtime_suspend(struct device *dev)
  1635. {
  1636. struct ipp_context *ctx = get_ipp_context(dev);
  1637. return ipp_power_ctrl(ctx, false);
  1638. }
  1639. static int ipp_runtime_resume(struct device *dev)
  1640. {
  1641. struct ipp_context *ctx = get_ipp_context(dev);
  1642. return ipp_power_ctrl(ctx, true);
  1643. }
  1644. #endif
  1645. static const struct dev_pm_ops ipp_pm_ops = {
  1646. SET_SYSTEM_SLEEP_PM_OPS(ipp_suspend, ipp_resume)
  1647. SET_RUNTIME_PM_OPS(ipp_runtime_suspend, ipp_runtime_resume, NULL)
  1648. };
  1649. struct platform_driver ipp_driver = {
  1650. .probe = ipp_probe,
  1651. .remove = ipp_remove,
  1652. .driver = {
  1653. .name = "exynos-drm-ipp",
  1654. .owner = THIS_MODULE,
  1655. .pm = &ipp_pm_ops,
  1656. },
  1657. };