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