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