exynos_drm_ipp.c 47 KB

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