exynos_drm_ipp.c 48 KB

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