exynos_drm_ipp.c 47 KB

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