2 * Copyright (C) 2012 Samsung Electronics Co.Ltd
4 * Eunchul Kim <chulspro.kim@samsung.com>
5 * Jinyoung Jeon <jy0.jeon@samsung.com>
6 * Sangmin Lee <lsmin.lee@samsung.com>
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.
14 #include <linux/kernel.h>
15 #include <linux/platform_device.h>
16 #include <linux/types.h>
17 #include <linux/clk.h>
18 #include <linux/pm_runtime.h>
21 #include <drm/exynos_drm.h>
22 #include "exynos_drm_drv.h"
23 #include "exynos_drm_gem.h"
24 #include "exynos_drm_ipp.h"
25 #include "exynos_drm_iommu.h"
28 * IPP stands for Image Post Processing and
29 * supports image scaler/rotator and input/output DMA operations.
30 * using FIMC, GSC, Rotator, so on.
31 * IPP is integration device driver of same attribute h/w
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.
45 #define get_ipp_context(dev) platform_get_drvdata(to_platform_device(dev))
46 #define ipp_is_m2m_cmd(c) (c == IPP_CMD_M2M)
48 /* platform device pointer for ipp device. */
49 static struct platform_device
*exynos_drm_ipp_pdev
;
52 * A structure of event.
54 * @base: base of event.
57 struct drm_exynos_ipp_send_event
{
58 struct drm_pending_event base
;
59 struct drm_exynos_ipp_event event
;
63 * A structure of memory node.
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.
72 struct drm_exynos_ipp_mem_node
{
73 struct list_head list
;
74 enum drm_exynos_ops_id ops_id
;
77 struct drm_exynos_ipp_buf_info buf_info
;
81 * A structure of ipp context.
83 * @subdrv: prepare initialization using subdrv.
84 * @ipp_lock: lock for synchronization of access to ipp_idr.
85 * @prop_lock: lock for synchronization of access to prop_idr.
86 * @ipp_idr: ipp driver idr.
87 * @prop_idr: property idr.
88 * @event_workq: event work queue.
89 * @cmd_workq: command work queue.
92 struct exynos_drm_subdrv subdrv
;
93 struct mutex ipp_lock
;
94 struct mutex prop_lock
;
97 struct workqueue_struct
*event_workq
;
98 struct workqueue_struct
*cmd_workq
;
101 static LIST_HEAD(exynos_drm_ippdrv_list
);
102 static DEFINE_MUTEX(exynos_drm_ippdrv_lock
);
103 static BLOCKING_NOTIFIER_HEAD(exynos_drm_ippnb_list
);
105 int exynos_platform_device_ipp_register(void)
107 struct platform_device
*pdev
;
109 if (exynos_drm_ipp_pdev
)
112 pdev
= platform_device_register_simple("exynos-drm-ipp", -1, NULL
, 0);
114 return PTR_ERR(pdev
);
116 exynos_drm_ipp_pdev
= pdev
;
121 void exynos_platform_device_ipp_unregister(void)
123 if (exynos_drm_ipp_pdev
) {
124 platform_device_unregister(exynos_drm_ipp_pdev
);
125 exynos_drm_ipp_pdev
= NULL
;
129 int exynos_drm_ippdrv_register(struct exynos_drm_ippdrv
*ippdrv
)
131 mutex_lock(&exynos_drm_ippdrv_lock
);
132 list_add_tail(&ippdrv
->drv_list
, &exynos_drm_ippdrv_list
);
133 mutex_unlock(&exynos_drm_ippdrv_lock
);
138 int exynos_drm_ippdrv_unregister(struct exynos_drm_ippdrv
*ippdrv
)
140 mutex_lock(&exynos_drm_ippdrv_lock
);
141 list_del(&ippdrv
->drv_list
);
142 mutex_unlock(&exynos_drm_ippdrv_lock
);
147 static int ipp_create_id(struct idr
*id_idr
, struct mutex
*lock
, void *obj
)
152 ret
= idr_alloc(id_idr
, obj
, 1, 0, GFP_KERNEL
);
158 static void ipp_remove_id(struct idr
*id_idr
, struct mutex
*lock
, u32 id
)
161 idr_remove(id_idr
, id
);
165 static void *ipp_find_obj(struct idr
*id_idr
, struct mutex
*lock
, u32 id
)
170 obj
= idr_find(id_idr
, id
);
176 static int ipp_check_driver(struct exynos_drm_ippdrv
*ippdrv
,
177 struct drm_exynos_ipp_property
*property
)
179 if (ippdrv
->dedicated
|| (!ipp_is_m2m_cmd(property
->cmd
) &&
180 !pm_runtime_suspended(ippdrv
->dev
)))
183 if (ippdrv
->check_property
&&
184 ippdrv
->check_property(ippdrv
->dev
, property
))
190 static struct exynos_drm_ippdrv
*ipp_find_driver(struct ipp_context
*ctx
,
191 struct drm_exynos_ipp_property
*property
)
193 struct exynos_drm_ippdrv
*ippdrv
;
194 u32 ipp_id
= property
->ipp_id
;
198 ippdrv
= ipp_find_obj(&ctx
->ipp_idr
, &ctx
->ipp_lock
, ipp_id
);
200 DRM_DEBUG("ipp%d driver not found\n", ipp_id
);
201 return ERR_PTR(-ENODEV
);
204 ret
= ipp_check_driver(ippdrv
, property
);
206 DRM_DEBUG("ipp%d driver check error %d\n", ipp_id
, ret
);
212 list_for_each_entry(ippdrv
, &exynos_drm_ippdrv_list
, drv_list
) {
213 ret
= ipp_check_driver(ippdrv
, property
);
218 DRM_DEBUG("cannot find driver suitable for given property.\n");
221 return ERR_PTR(-ENODEV
);
224 static struct exynos_drm_ippdrv
*ipp_find_drv_by_handle(u32 prop_id
)
226 struct exynos_drm_ippdrv
*ippdrv
;
227 struct drm_exynos_ipp_cmd_node
*c_node
;
230 DRM_DEBUG_KMS("prop_id[%d]\n", prop_id
);
233 * This case is search ipp driver by prop_id handle.
234 * sometimes, ipp subsystem find driver by prop_id.
235 * e.g PAUSE state, queue buf, command control.
237 list_for_each_entry(ippdrv
, &exynos_drm_ippdrv_list
, drv_list
) {
238 DRM_DEBUG_KMS("count[%d]ippdrv[0x%x]\n", count
++, (int)ippdrv
);
240 mutex_lock(&ippdrv
->cmd_lock
);
241 list_for_each_entry(c_node
, &ippdrv
->cmd_list
, list
) {
242 if (c_node
->property
.prop_id
== prop_id
) {
243 mutex_unlock(&ippdrv
->cmd_lock
);
247 mutex_unlock(&ippdrv
->cmd_lock
);
250 return ERR_PTR(-ENODEV
);
253 int exynos_drm_ipp_get_property(struct drm_device
*drm_dev
, void *data
,
254 struct drm_file
*file
)
256 struct drm_exynos_file_private
*file_priv
= file
->driver_priv
;
257 struct device
*dev
= file_priv
->ipp_dev
;
258 struct ipp_context
*ctx
= get_ipp_context(dev
);
259 struct drm_exynos_ipp_prop_list
*prop_list
= data
;
260 struct exynos_drm_ippdrv
*ippdrv
;
264 DRM_ERROR("invalid context.\n");
269 DRM_ERROR("invalid property parameter.\n");
273 DRM_DEBUG_KMS("ipp_id[%d]\n", prop_list
->ipp_id
);
275 if (!prop_list
->ipp_id
) {
276 list_for_each_entry(ippdrv
, &exynos_drm_ippdrv_list
, drv_list
)
280 * Supports ippdrv list count for user application.
281 * First step user application getting ippdrv count.
282 * and second step getting ippdrv capability using ipp_id.
284 prop_list
->count
= count
;
287 * Getting ippdrv capability by ipp_id.
288 * some device not supported wb, output interface.
289 * so, user application detect correct ipp driver
292 ippdrv
= ipp_find_obj(&ctx
->ipp_idr
, &ctx
->ipp_lock
,
295 DRM_ERROR("not found ipp%d driver.\n",
300 *prop_list
= ippdrv
->prop_list
;
306 static void ipp_print_property(struct drm_exynos_ipp_property
*property
,
309 struct drm_exynos_ipp_config
*config
= &property
->config
[idx
];
310 struct drm_exynos_pos
*pos
= &config
->pos
;
311 struct drm_exynos_sz
*sz
= &config
->sz
;
313 DRM_DEBUG_KMS("prop_id[%d]ops[%s]fmt[0x%x]\n",
314 property
->prop_id
, idx
? "dst" : "src", config
->fmt
);
316 DRM_DEBUG_KMS("pos[%d %d %d %d]sz[%d %d]f[%d]r[%d]\n",
317 pos
->x
, pos
->y
, pos
->w
, pos
->h
,
318 sz
->hsize
, sz
->vsize
, config
->flip
, config
->degree
);
321 static int ipp_find_and_set_property(struct drm_exynos_ipp_property
*property
)
323 struct exynos_drm_ippdrv
*ippdrv
;
324 struct drm_exynos_ipp_cmd_node
*c_node
;
325 u32 prop_id
= property
->prop_id
;
327 DRM_DEBUG_KMS("prop_id[%d]\n", prop_id
);
329 ippdrv
= ipp_find_drv_by_handle(prop_id
);
330 if (IS_ERR(ippdrv
)) {
331 DRM_ERROR("failed to get ipp driver.\n");
336 * Find command node using command list in ippdrv.
337 * when we find this command no using prop_id.
338 * return property information set in this command node.
340 mutex_lock(&ippdrv
->cmd_lock
);
341 list_for_each_entry(c_node
, &ippdrv
->cmd_list
, list
) {
342 if ((c_node
->property
.prop_id
== prop_id
) &&
343 (c_node
->state
== IPP_STATE_STOP
)) {
344 mutex_unlock(&ippdrv
->cmd_lock
);
345 DRM_DEBUG_KMS("found cmd[%d]ippdrv[0x%x]\n",
346 property
->cmd
, (int)ippdrv
);
348 c_node
->property
= *property
;
352 mutex_unlock(&ippdrv
->cmd_lock
);
354 DRM_ERROR("failed to search property.\n");
359 static struct drm_exynos_ipp_cmd_work
*ipp_create_cmd_work(void)
361 struct drm_exynos_ipp_cmd_work
*cmd_work
;
363 cmd_work
= kzalloc(sizeof(*cmd_work
), GFP_KERNEL
);
365 return ERR_PTR(-ENOMEM
);
367 INIT_WORK((struct work_struct
*)cmd_work
, ipp_sched_cmd
);
372 static struct drm_exynos_ipp_event_work
*ipp_create_event_work(void)
374 struct drm_exynos_ipp_event_work
*event_work
;
376 event_work
= kzalloc(sizeof(*event_work
), GFP_KERNEL
);
378 return ERR_PTR(-ENOMEM
);
380 INIT_WORK(&event_work
->work
, ipp_sched_event
);
385 int exynos_drm_ipp_set_property(struct drm_device
*drm_dev
, void *data
,
386 struct drm_file
*file
)
388 struct drm_exynos_file_private
*file_priv
= file
->driver_priv
;
389 struct device
*dev
= file_priv
->ipp_dev
;
390 struct ipp_context
*ctx
= get_ipp_context(dev
);
391 struct drm_exynos_ipp_property
*property
= data
;
392 struct exynos_drm_ippdrv
*ippdrv
;
393 struct drm_exynos_ipp_cmd_node
*c_node
;
397 DRM_ERROR("invalid context.\n");
402 DRM_ERROR("invalid property parameter.\n");
407 * This is log print for user application property.
408 * user application set various property.
411 ipp_print_property(property
, i
);
414 * set property ioctl generated new prop_id.
415 * but in this case already asigned prop_id using old set property.
416 * e.g PAUSE state. this case supports find current prop_id and use it
417 * instead of allocation.
419 if (property
->prop_id
) {
420 DRM_DEBUG_KMS("prop_id[%d]\n", property
->prop_id
);
421 return ipp_find_and_set_property(property
);
424 /* find ipp driver using ipp id */
425 ippdrv
= ipp_find_driver(ctx
, property
);
426 if (IS_ERR(ippdrv
)) {
427 DRM_ERROR("failed to get ipp driver.\n");
431 /* allocate command node */
432 c_node
= kzalloc(sizeof(*c_node
), GFP_KERNEL
);
436 ret
= ipp_create_id(&ctx
->prop_idr
, &ctx
->prop_lock
, c_node
);
438 DRM_ERROR("failed to create id.\n");
441 property
->prop_id
= ret
;
443 DRM_DEBUG_KMS("created prop_id[%d]cmd[%d]ippdrv[0x%x]\n",
444 property
->prop_id
, property
->cmd
, (int)ippdrv
);
446 /* stored property information and ippdrv in private data */
447 c_node
->property
= *property
;
448 c_node
->state
= IPP_STATE_IDLE
;
451 c_node
->start_work
= ipp_create_cmd_work();
452 if (IS_ERR(c_node
->start_work
)) {
453 DRM_ERROR("failed to create start work.\n");
457 c_node
->stop_work
= ipp_create_cmd_work();
458 if (IS_ERR(c_node
->stop_work
)) {
459 DRM_ERROR("failed to create stop work.\n");
463 c_node
->event_work
= ipp_create_event_work();
464 if (IS_ERR(c_node
->event_work
)) {
465 DRM_ERROR("failed to create event work.\n");
469 mutex_init(&c_node
->lock
);
470 mutex_init(&c_node
->mem_lock
);
471 mutex_init(&c_node
->event_lock
);
473 init_completion(&c_node
->start_complete
);
474 init_completion(&c_node
->stop_complete
);
477 INIT_LIST_HEAD(&c_node
->mem_list
[i
]);
479 INIT_LIST_HEAD(&c_node
->event_list
);
480 mutex_lock(&ippdrv
->cmd_lock
);
481 list_add_tail(&c_node
->list
, &ippdrv
->cmd_list
);
482 mutex_unlock(&ippdrv
->cmd_lock
);
484 /* make dedicated state without m2m */
485 if (!ipp_is_m2m_cmd(property
->cmd
))
486 ippdrv
->dedicated
= true;
491 kfree(c_node
->stop_work
);
493 kfree(c_node
->start_work
);
495 ipp_remove_id(&ctx
->prop_idr
, &ctx
->prop_lock
, property
->prop_id
);
501 static int ipp_put_mem_node(struct drm_device
*drm_dev
,
502 struct drm_exynos_ipp_cmd_node
*c_node
,
503 struct drm_exynos_ipp_mem_node
*m_node
)
507 DRM_DEBUG_KMS("node[0x%x]\n", (int)m_node
);
510 DRM_ERROR("invalid dequeue node.\n");
514 DRM_DEBUG_KMS("ops_id[%d]\n", m_node
->ops_id
);
517 for_each_ipp_planar(i
) {
518 unsigned long handle
= m_node
->buf_info
.handles
[i
];
520 exynos_drm_gem_put_dma_addr(drm_dev
, handle
,
524 list_del(&m_node
->list
);
530 static struct drm_exynos_ipp_mem_node
531 *ipp_get_mem_node(struct drm_device
*drm_dev
,
532 struct drm_exynos_ipp_cmd_node
*c_node
,
533 struct drm_exynos_ipp_queue_buf
*qbuf
)
535 struct drm_exynos_ipp_mem_node
*m_node
;
536 struct drm_exynos_ipp_buf_info
*buf_info
;
539 m_node
= kzalloc(sizeof(*m_node
), GFP_KERNEL
);
541 return ERR_PTR(-ENOMEM
);
543 buf_info
= &m_node
->buf_info
;
545 /* operations, buffer id */
546 m_node
->ops_id
= qbuf
->ops_id
;
547 m_node
->prop_id
= qbuf
->prop_id
;
548 m_node
->buf_id
= qbuf
->buf_id
;
549 INIT_LIST_HEAD(&m_node
->list
);
551 DRM_DEBUG_KMS("m_node[0x%x]ops_id[%d]\n", (int)m_node
, qbuf
->ops_id
);
552 DRM_DEBUG_KMS("prop_id[%d]buf_id[%d]\n", qbuf
->prop_id
, m_node
->buf_id
);
554 for_each_ipp_planar(i
) {
555 DRM_DEBUG_KMS("i[%d]handle[0x%x]\n", i
, qbuf
->handle
[i
]);
557 /* get dma address by handle */
558 if (qbuf
->handle
[i
]) {
561 addr
= exynos_drm_gem_get_dma_addr(drm_dev
,
562 qbuf
->handle
[i
], c_node
->filp
);
564 DRM_ERROR("failed to get addr.\n");
565 ipp_put_mem_node(drm_dev
, c_node
, m_node
);
566 return ERR_PTR(-EFAULT
);
569 buf_info
->handles
[i
] = qbuf
->handle
[i
];
570 buf_info
->base
[i
] = *addr
;
571 DRM_DEBUG_KMS("i[%d]base[0x%x]hd[0x%lx]\n", i
,
572 buf_info
->base
[i
], buf_info
->handles
[i
]);
576 mutex_lock(&c_node
->mem_lock
);
577 list_add_tail(&m_node
->list
, &c_node
->mem_list
[qbuf
->ops_id
]);
578 mutex_unlock(&c_node
->mem_lock
);
583 static void ipp_clean_mem_nodes(struct drm_device
*drm_dev
,
584 struct drm_exynos_ipp_cmd_node
*c_node
, int ops
)
586 struct drm_exynos_ipp_mem_node
*m_node
, *tm_node
;
587 struct list_head
*head
= &c_node
->mem_list
[ops
];
589 mutex_lock(&c_node
->mem_lock
);
591 list_for_each_entry_safe(m_node
, tm_node
, head
, list
) {
594 ret
= ipp_put_mem_node(drm_dev
, c_node
, m_node
);
596 DRM_ERROR("failed to put m_node.\n");
599 mutex_unlock(&c_node
->mem_lock
);
602 static void ipp_free_event(struct drm_pending_event
*event
)
607 static int ipp_get_event(struct drm_device
*drm_dev
,
608 struct drm_exynos_ipp_cmd_node
*c_node
,
609 struct drm_exynos_ipp_queue_buf
*qbuf
)
611 struct drm_exynos_ipp_send_event
*e
;
614 DRM_DEBUG_KMS("ops_id[%d]buf_id[%d]\n", qbuf
->ops_id
, qbuf
->buf_id
);
616 e
= kzalloc(sizeof(*e
), GFP_KERNEL
);
618 spin_lock_irqsave(&drm_dev
->event_lock
, flags
);
619 c_node
->filp
->event_space
+= sizeof(e
->event
);
620 spin_unlock_irqrestore(&drm_dev
->event_lock
, flags
);
625 e
->event
.base
.type
= DRM_EXYNOS_IPP_EVENT
;
626 e
->event
.base
.length
= sizeof(e
->event
);
627 e
->event
.user_data
= qbuf
->user_data
;
628 e
->event
.prop_id
= qbuf
->prop_id
;
629 e
->event
.buf_id
[EXYNOS_DRM_OPS_DST
] = qbuf
->buf_id
;
630 e
->base
.event
= &e
->event
.base
;
631 e
->base
.file_priv
= c_node
->filp
;
632 e
->base
.destroy
= ipp_free_event
;
633 mutex_lock(&c_node
->event_lock
);
634 list_add_tail(&e
->base
.link
, &c_node
->event_list
);
635 mutex_unlock(&c_node
->event_lock
);
640 static void ipp_put_event(struct drm_exynos_ipp_cmd_node
*c_node
,
641 struct drm_exynos_ipp_queue_buf
*qbuf
)
643 struct drm_exynos_ipp_send_event
*e
, *te
;
646 mutex_lock(&c_node
->event_lock
);
647 list_for_each_entry_safe(e
, te
, &c_node
->event_list
, base
.link
) {
648 DRM_DEBUG_KMS("count[%d]e[0x%x]\n", count
++, (int)e
);
651 * qbuf == NULL condition means all event deletion.
652 * stop operations want to delete all event list.
653 * another case delete only same buf id.
657 list_del(&e
->base
.link
);
661 /* compare buffer id */
662 if (qbuf
&& (qbuf
->buf_id
==
663 e
->event
.buf_id
[EXYNOS_DRM_OPS_DST
])) {
665 list_del(&e
->base
.link
);
672 mutex_unlock(&c_node
->event_lock
);
676 static void ipp_clean_cmd_node(struct ipp_context
*ctx
,
677 struct drm_exynos_ipp_cmd_node
*c_node
)
682 cancel_work_sync(&c_node
->start_work
->work
);
683 cancel_work_sync(&c_node
->stop_work
->work
);
684 cancel_work_sync(&c_node
->event_work
->work
);
687 ipp_put_event(c_node
, NULL
);
690 ipp_clean_mem_nodes(ctx
->subdrv
.drm_dev
, c_node
, i
);
693 list_del(&c_node
->list
);
695 ipp_remove_id(&ctx
->prop_idr
, &ctx
->prop_lock
,
696 c_node
->property
.prop_id
);
699 mutex_destroy(&c_node
->lock
);
700 mutex_destroy(&c_node
->mem_lock
);
701 mutex_destroy(&c_node
->event_lock
);
703 /* free command node */
704 kfree(c_node
->start_work
);
705 kfree(c_node
->stop_work
);
706 kfree(c_node
->event_work
);
710 static bool ipp_check_mem_list(struct drm_exynos_ipp_cmd_node
*c_node
)
712 switch (c_node
->property
.cmd
) {
714 return !list_empty(&c_node
->mem_list
[EXYNOS_DRM_OPS_DST
]);
716 return !list_empty(&c_node
->mem_list
[EXYNOS_DRM_OPS_SRC
]);
719 return !list_empty(&c_node
->mem_list
[EXYNOS_DRM_OPS_SRC
]) &&
720 !list_empty(&c_node
->mem_list
[EXYNOS_DRM_OPS_DST
]);
724 static struct drm_exynos_ipp_mem_node
725 *ipp_find_mem_node(struct drm_exynos_ipp_cmd_node
*c_node
,
726 struct drm_exynos_ipp_queue_buf
*qbuf
)
728 struct drm_exynos_ipp_mem_node
*m_node
;
729 struct list_head
*head
;
732 DRM_DEBUG_KMS("buf_id[%d]\n", qbuf
->buf_id
);
734 /* source/destination memory list */
735 head
= &c_node
->mem_list
[qbuf
->ops_id
];
737 /* find memory node from memory list */
738 list_for_each_entry(m_node
, head
, list
) {
739 DRM_DEBUG_KMS("count[%d]m_node[0x%x]\n", count
++, (int)m_node
);
741 /* compare buffer id */
742 if (m_node
->buf_id
== qbuf
->buf_id
)
749 static int ipp_set_mem_node(struct exynos_drm_ippdrv
*ippdrv
,
750 struct drm_exynos_ipp_cmd_node
*c_node
,
751 struct drm_exynos_ipp_mem_node
*m_node
)
753 struct exynos_drm_ipp_ops
*ops
= NULL
;
756 DRM_DEBUG_KMS("node[0x%x]\n", (int)m_node
);
759 DRM_ERROR("invalid queue node.\n");
763 DRM_DEBUG_KMS("ops_id[%d]\n", m_node
->ops_id
);
765 /* get operations callback */
766 ops
= ippdrv
->ops
[m_node
->ops_id
];
768 DRM_ERROR("not support ops.\n");
772 /* set address and enable irq */
774 ret
= ops
->set_addr(ippdrv
->dev
, &m_node
->buf_info
,
775 m_node
->buf_id
, IPP_BUF_ENQUEUE
);
777 DRM_ERROR("failed to set addr.\n");
785 static void ipp_handle_cmd_work(struct device
*dev
,
786 struct exynos_drm_ippdrv
*ippdrv
,
787 struct drm_exynos_ipp_cmd_work
*cmd_work
,
788 struct drm_exynos_ipp_cmd_node
*c_node
)
790 struct ipp_context
*ctx
= get_ipp_context(dev
);
792 cmd_work
->ippdrv
= ippdrv
;
793 cmd_work
->c_node
= c_node
;
794 queue_work(ctx
->cmd_workq
, &cmd_work
->work
);
797 static int ipp_queue_buf_with_run(struct device
*dev
,
798 struct drm_exynos_ipp_cmd_node
*c_node
,
799 struct drm_exynos_ipp_mem_node
*m_node
,
800 struct drm_exynos_ipp_queue_buf
*qbuf
)
802 struct exynos_drm_ippdrv
*ippdrv
;
803 struct drm_exynos_ipp_property
*property
;
804 struct exynos_drm_ipp_ops
*ops
;
807 ippdrv
= ipp_find_drv_by_handle(qbuf
->prop_id
);
808 if (IS_ERR(ippdrv
)) {
809 DRM_ERROR("failed to get ipp driver.\n");
813 ops
= ippdrv
->ops
[qbuf
->ops_id
];
815 DRM_ERROR("failed to get ops.\n");
819 property
= &c_node
->property
;
821 if (c_node
->state
!= IPP_STATE_START
) {
822 DRM_DEBUG_KMS("bypass for invalid state.\n");
826 mutex_lock(&c_node
->mem_lock
);
827 if (!ipp_check_mem_list(c_node
)) {
828 mutex_unlock(&c_node
->mem_lock
);
829 DRM_DEBUG_KMS("empty memory.\n");
834 * If set destination buffer and enabled clock,
835 * then m2m operations need start operations at queue_buf
837 if (ipp_is_m2m_cmd(property
->cmd
)) {
838 struct drm_exynos_ipp_cmd_work
*cmd_work
= c_node
->start_work
;
840 cmd_work
->ctrl
= IPP_CTRL_PLAY
;
841 ipp_handle_cmd_work(dev
, ippdrv
, cmd_work
, c_node
);
843 ret
= ipp_set_mem_node(ippdrv
, c_node
, m_node
);
845 mutex_unlock(&c_node
->mem_lock
);
846 DRM_ERROR("failed to set m node.\n");
850 mutex_unlock(&c_node
->mem_lock
);
855 static void ipp_clean_queue_buf(struct drm_device
*drm_dev
,
856 struct drm_exynos_ipp_cmd_node
*c_node
,
857 struct drm_exynos_ipp_queue_buf
*qbuf
)
859 struct drm_exynos_ipp_mem_node
*m_node
, *tm_node
;
862 mutex_lock(&c_node
->mem_lock
);
863 list_for_each_entry_safe(m_node
, tm_node
,
864 &c_node
->mem_list
[qbuf
->ops_id
], list
) {
865 if (m_node
->buf_id
== qbuf
->buf_id
&&
866 m_node
->ops_id
== qbuf
->ops_id
)
867 ipp_put_mem_node(drm_dev
, c_node
, m_node
);
869 mutex_unlock(&c_node
->mem_lock
);
872 int exynos_drm_ipp_queue_buf(struct drm_device
*drm_dev
, void *data
,
873 struct drm_file
*file
)
875 struct drm_exynos_file_private
*file_priv
= file
->driver_priv
;
876 struct device
*dev
= file_priv
->ipp_dev
;
877 struct ipp_context
*ctx
= get_ipp_context(dev
);
878 struct drm_exynos_ipp_queue_buf
*qbuf
= data
;
879 struct drm_exynos_ipp_cmd_node
*c_node
;
880 struct drm_exynos_ipp_mem_node
*m_node
;
884 DRM_ERROR("invalid buf parameter.\n");
888 if (qbuf
->ops_id
>= EXYNOS_DRM_OPS_MAX
) {
889 DRM_ERROR("invalid ops parameter.\n");
893 DRM_DEBUG_KMS("prop_id[%d]ops_id[%s]buf_id[%d]buf_type[%d]\n",
894 qbuf
->prop_id
, qbuf
->ops_id
? "dst" : "src",
895 qbuf
->buf_id
, qbuf
->buf_type
);
897 /* find command node */
898 c_node
= ipp_find_obj(&ctx
->prop_idr
, &ctx
->prop_lock
,
901 DRM_ERROR("failed to get command node.\n");
906 switch (qbuf
->buf_type
) {
907 case IPP_BUF_ENQUEUE
:
908 /* get memory node */
909 m_node
= ipp_get_mem_node(drm_dev
, c_node
, qbuf
);
910 if (IS_ERR(m_node
)) {
911 DRM_ERROR("failed to get m_node.\n");
912 return PTR_ERR(m_node
);
916 * first step get event for destination buffer.
917 * and second step when M2M case run with destination buffer
920 if (qbuf
->ops_id
== EXYNOS_DRM_OPS_DST
) {
921 /* get event for destination buffer */
922 ret
= ipp_get_event(drm_dev
, c_node
, qbuf
);
924 DRM_ERROR("failed to get event.\n");
929 * M2M case run play control for streaming feature.
930 * other case set address and waiting.
932 ret
= ipp_queue_buf_with_run(dev
, c_node
, m_node
, qbuf
);
934 DRM_ERROR("failed to run command.\n");
939 case IPP_BUF_DEQUEUE
:
940 mutex_lock(&c_node
->lock
);
942 /* put event for destination buffer */
943 if (qbuf
->ops_id
== EXYNOS_DRM_OPS_DST
)
944 ipp_put_event(c_node
, qbuf
);
946 ipp_clean_queue_buf(drm_dev
, c_node
, qbuf
);
948 mutex_unlock(&c_node
->lock
);
951 DRM_ERROR("invalid buffer control.\n");
958 DRM_ERROR("clean memory nodes.\n");
960 ipp_clean_queue_buf(drm_dev
, c_node
, qbuf
);
964 static bool exynos_drm_ipp_check_valid(struct device
*dev
,
965 enum drm_exynos_ipp_ctrl ctrl
, enum drm_exynos_ipp_state state
)
967 if (ctrl
!= IPP_CTRL_PLAY
) {
968 if (pm_runtime_suspended(dev
)) {
969 DRM_ERROR("pm:runtime_suspended.\n");
976 if (state
!= IPP_STATE_IDLE
)
980 if (state
== IPP_STATE_STOP
)
984 if (state
!= IPP_STATE_START
)
987 case IPP_CTRL_RESUME
:
988 if (state
!= IPP_STATE_STOP
)
992 DRM_ERROR("invalid state.\n");
999 DRM_ERROR("invalid status:ctrl[%d]state[%d]\n", ctrl
, state
);
1003 int exynos_drm_ipp_cmd_ctrl(struct drm_device
*drm_dev
, void *data
,
1004 struct drm_file
*file
)
1006 struct drm_exynos_file_private
*file_priv
= file
->driver_priv
;
1007 struct exynos_drm_ippdrv
*ippdrv
= NULL
;
1008 struct device
*dev
= file_priv
->ipp_dev
;
1009 struct ipp_context
*ctx
= get_ipp_context(dev
);
1010 struct drm_exynos_ipp_cmd_ctrl
*cmd_ctrl
= data
;
1011 struct drm_exynos_ipp_cmd_work
*cmd_work
;
1012 struct drm_exynos_ipp_cmd_node
*c_node
;
1015 DRM_ERROR("invalid context.\n");
1020 DRM_ERROR("invalid control parameter.\n");
1024 DRM_DEBUG_KMS("ctrl[%d]prop_id[%d]\n",
1025 cmd_ctrl
->ctrl
, cmd_ctrl
->prop_id
);
1027 ippdrv
= ipp_find_drv_by_handle(cmd_ctrl
->prop_id
);
1028 if (IS_ERR(ippdrv
)) {
1029 DRM_ERROR("failed to get ipp driver.\n");
1030 return PTR_ERR(ippdrv
);
1033 c_node
= ipp_find_obj(&ctx
->prop_idr
, &ctx
->prop_lock
,
1036 DRM_ERROR("invalid command node list.\n");
1040 if (!exynos_drm_ipp_check_valid(ippdrv
->dev
, cmd_ctrl
->ctrl
,
1042 DRM_ERROR("invalid state.\n");
1046 switch (cmd_ctrl
->ctrl
) {
1048 if (pm_runtime_suspended(ippdrv
->dev
))
1049 pm_runtime_get_sync(ippdrv
->dev
);
1051 c_node
->state
= IPP_STATE_START
;
1053 cmd_work
= c_node
->start_work
;
1054 cmd_work
->ctrl
= cmd_ctrl
->ctrl
;
1055 ipp_handle_cmd_work(dev
, ippdrv
, cmd_work
, c_node
);
1058 cmd_work
= c_node
->stop_work
;
1059 cmd_work
->ctrl
= cmd_ctrl
->ctrl
;
1060 ipp_handle_cmd_work(dev
, ippdrv
, cmd_work
, c_node
);
1062 if (!wait_for_completion_timeout(&c_node
->stop_complete
,
1063 msecs_to_jiffies(300))) {
1064 DRM_ERROR("timeout stop:prop_id[%d]\n",
1065 c_node
->property
.prop_id
);
1068 c_node
->state
= IPP_STATE_STOP
;
1069 ippdrv
->dedicated
= false;
1070 mutex_lock(&ippdrv
->cmd_lock
);
1071 ipp_clean_cmd_node(ctx
, c_node
);
1073 if (list_empty(&ippdrv
->cmd_list
))
1074 pm_runtime_put_sync(ippdrv
->dev
);
1075 mutex_unlock(&ippdrv
->cmd_lock
);
1077 case IPP_CTRL_PAUSE
:
1078 cmd_work
= c_node
->stop_work
;
1079 cmd_work
->ctrl
= cmd_ctrl
->ctrl
;
1080 ipp_handle_cmd_work(dev
, ippdrv
, cmd_work
, c_node
);
1082 if (!wait_for_completion_timeout(&c_node
->stop_complete
,
1083 msecs_to_jiffies(200))) {
1084 DRM_ERROR("timeout stop:prop_id[%d]\n",
1085 c_node
->property
.prop_id
);
1088 c_node
->state
= IPP_STATE_STOP
;
1090 case IPP_CTRL_RESUME
:
1091 c_node
->state
= IPP_STATE_START
;
1092 cmd_work
= c_node
->start_work
;
1093 cmd_work
->ctrl
= cmd_ctrl
->ctrl
;
1094 ipp_handle_cmd_work(dev
, ippdrv
, cmd_work
, c_node
);
1097 DRM_ERROR("could not support this state currently.\n");
1101 DRM_DEBUG_KMS("done ctrl[%d]prop_id[%d]\n",
1102 cmd_ctrl
->ctrl
, cmd_ctrl
->prop_id
);
1107 int exynos_drm_ippnb_register(struct notifier_block
*nb
)
1109 return blocking_notifier_chain_register(
1110 &exynos_drm_ippnb_list
, nb
);
1113 int exynos_drm_ippnb_unregister(struct notifier_block
*nb
)
1115 return blocking_notifier_chain_unregister(
1116 &exynos_drm_ippnb_list
, nb
);
1119 int exynos_drm_ippnb_send_event(unsigned long val
, void *v
)
1121 return blocking_notifier_call_chain(
1122 &exynos_drm_ippnb_list
, val
, v
);
1125 static int ipp_set_property(struct exynos_drm_ippdrv
*ippdrv
,
1126 struct drm_exynos_ipp_property
*property
)
1128 struct exynos_drm_ipp_ops
*ops
= NULL
;
1133 DRM_ERROR("invalid property parameter.\n");
1137 DRM_DEBUG_KMS("prop_id[%d]\n", property
->prop_id
);
1139 /* reset h/w block */
1140 if (ippdrv
->reset
&&
1141 ippdrv
->reset(ippdrv
->dev
)) {
1145 /* set source,destination operations */
1146 for_each_ipp_ops(i
) {
1147 struct drm_exynos_ipp_config
*config
=
1148 &property
->config
[i
];
1150 ops
= ippdrv
->ops
[i
];
1151 if (!ops
|| !config
) {
1152 DRM_ERROR("not support ops and config.\n");
1158 ret
= ops
->set_fmt(ippdrv
->dev
, config
->fmt
);
1163 /* set transform for rotation, flip */
1164 if (ops
->set_transf
) {
1165 ret
= ops
->set_transf(ippdrv
->dev
, config
->degree
,
1166 config
->flip
, &swap
);
1172 if (ops
->set_size
) {
1173 ret
= ops
->set_size(ippdrv
->dev
, swap
, &config
->pos
,
1183 static int ipp_start_property(struct exynos_drm_ippdrv
*ippdrv
,
1184 struct drm_exynos_ipp_cmd_node
*c_node
)
1186 struct drm_exynos_ipp_mem_node
*m_node
;
1187 struct drm_exynos_ipp_property
*property
= &c_node
->property
;
1188 struct list_head
*head
;
1191 DRM_DEBUG_KMS("prop_id[%d]\n", property
->prop_id
);
1193 /* store command info in ippdrv */
1194 ippdrv
->c_node
= c_node
;
1196 mutex_lock(&c_node
->mem_lock
);
1197 if (!ipp_check_mem_list(c_node
)) {
1198 DRM_DEBUG_KMS("empty memory.\n");
1203 /* set current property in ippdrv */
1204 ret
= ipp_set_property(ippdrv
, property
);
1206 DRM_ERROR("failed to set property.\n");
1207 ippdrv
->c_node
= NULL
;
1212 switch (property
->cmd
) {
1214 for_each_ipp_ops(i
) {
1215 /* source/destination memory list */
1216 head
= &c_node
->mem_list
[i
];
1218 m_node
= list_first_entry(head
,
1219 struct drm_exynos_ipp_mem_node
, list
);
1221 DRM_DEBUG_KMS("m_node[0x%x]\n", (int)m_node
);
1223 ret
= ipp_set_mem_node(ippdrv
, c_node
, m_node
);
1225 DRM_ERROR("failed to set m node.\n");
1231 /* destination memory list */
1232 head
= &c_node
->mem_list
[EXYNOS_DRM_OPS_DST
];
1234 list_for_each_entry(m_node
, head
, list
) {
1235 ret
= ipp_set_mem_node(ippdrv
, c_node
, m_node
);
1237 DRM_ERROR("failed to set m node.\n");
1242 case IPP_CMD_OUTPUT
:
1243 /* source memory list */
1244 head
= &c_node
->mem_list
[EXYNOS_DRM_OPS_SRC
];
1246 list_for_each_entry(m_node
, head
, list
) {
1247 ret
= ipp_set_mem_node(ippdrv
, c_node
, m_node
);
1249 DRM_ERROR("failed to set m node.\n");
1255 DRM_ERROR("invalid operations.\n");
1259 mutex_unlock(&c_node
->mem_lock
);
1261 DRM_DEBUG_KMS("cmd[%d]\n", property
->cmd
);
1263 /* start operations */
1264 if (ippdrv
->start
) {
1265 ret
= ippdrv
->start(ippdrv
->dev
, property
->cmd
);
1267 DRM_ERROR("failed to start ops.\n");
1268 ippdrv
->c_node
= NULL
;
1276 mutex_unlock(&c_node
->mem_lock
);
1277 ippdrv
->c_node
= NULL
;
1281 static int ipp_stop_property(struct drm_device
*drm_dev
,
1282 struct exynos_drm_ippdrv
*ippdrv
,
1283 struct drm_exynos_ipp_cmd_node
*c_node
)
1285 struct drm_exynos_ipp_property
*property
= &c_node
->property
;
1288 DRM_DEBUG_KMS("prop_id[%d]\n", property
->prop_id
);
1290 /* stop operations */
1292 ippdrv
->stop(ippdrv
->dev
, property
->cmd
);
1295 switch (property
->cmd
) {
1298 ipp_clean_mem_nodes(drm_dev
, c_node
, i
);
1301 ipp_clean_mem_nodes(drm_dev
, c_node
, EXYNOS_DRM_OPS_DST
);
1303 case IPP_CMD_OUTPUT
:
1304 ipp_clean_mem_nodes(drm_dev
, c_node
, EXYNOS_DRM_OPS_SRC
);
1307 DRM_ERROR("invalid operations.\n");
1314 void ipp_sched_cmd(struct work_struct
*work
)
1316 struct drm_exynos_ipp_cmd_work
*cmd_work
=
1317 container_of(work
, struct drm_exynos_ipp_cmd_work
, work
);
1318 struct exynos_drm_ippdrv
*ippdrv
;
1319 struct drm_exynos_ipp_cmd_node
*c_node
;
1320 struct drm_exynos_ipp_property
*property
;
1323 ippdrv
= cmd_work
->ippdrv
;
1325 DRM_ERROR("invalid ippdrv list.\n");
1329 c_node
= cmd_work
->c_node
;
1331 DRM_ERROR("invalid command node list.\n");
1335 mutex_lock(&c_node
->lock
);
1337 property
= &c_node
->property
;
1339 switch (cmd_work
->ctrl
) {
1341 case IPP_CTRL_RESUME
:
1342 ret
= ipp_start_property(ippdrv
, c_node
);
1344 DRM_ERROR("failed to start property:prop_id[%d]\n",
1345 c_node
->property
.prop_id
);
1350 * M2M case supports wait_completion of transfer.
1351 * because M2M case supports single unit operation
1352 * with multiple queue.
1353 * M2M need to wait completion of data transfer.
1355 if (ipp_is_m2m_cmd(property
->cmd
)) {
1356 if (!wait_for_completion_timeout
1357 (&c_node
->start_complete
, msecs_to_jiffies(200))) {
1358 DRM_ERROR("timeout event:prop_id[%d]\n",
1359 c_node
->property
.prop_id
);
1365 case IPP_CTRL_PAUSE
:
1366 ret
= ipp_stop_property(ippdrv
->drm_dev
, ippdrv
,
1369 DRM_ERROR("failed to stop property.\n");
1373 complete(&c_node
->stop_complete
);
1376 DRM_ERROR("unknown control type\n");
1380 DRM_DEBUG_KMS("ctrl[%d] done.\n", cmd_work
->ctrl
);
1383 mutex_unlock(&c_node
->lock
);
1386 static int ipp_send_event(struct exynos_drm_ippdrv
*ippdrv
,
1387 struct drm_exynos_ipp_cmd_node
*c_node
, int *buf_id
)
1389 struct drm_device
*drm_dev
= ippdrv
->drm_dev
;
1390 struct drm_exynos_ipp_property
*property
= &c_node
->property
;
1391 struct drm_exynos_ipp_mem_node
*m_node
;
1392 struct drm_exynos_ipp_queue_buf qbuf
;
1393 struct drm_exynos_ipp_send_event
*e
;
1394 struct list_head
*head
;
1396 unsigned long flags
;
1397 u32 tbuf_id
[EXYNOS_DRM_OPS_MAX
] = {0, };
1401 DRM_DEBUG_KMS("%s buf_id[%d]\n", i
? "dst" : "src", buf_id
[i
]);
1404 DRM_ERROR("failed to get drm_dev.\n");
1409 DRM_ERROR("failed to get property.\n");
1413 mutex_lock(&c_node
->event_lock
);
1414 if (list_empty(&c_node
->event_list
)) {
1415 DRM_DEBUG_KMS("event list is empty.\n");
1417 goto err_event_unlock
;
1420 mutex_lock(&c_node
->mem_lock
);
1421 if (!ipp_check_mem_list(c_node
)) {
1422 DRM_DEBUG_KMS("empty memory.\n");
1424 goto err_mem_unlock
;
1428 switch (property
->cmd
) {
1430 for_each_ipp_ops(i
) {
1431 /* source/destination memory list */
1432 head
= &c_node
->mem_list
[i
];
1434 m_node
= list_first_entry(head
,
1435 struct drm_exynos_ipp_mem_node
, list
);
1437 tbuf_id
[i
] = m_node
->buf_id
;
1438 DRM_DEBUG_KMS("%s buf_id[%d]\n",
1439 i
? "dst" : "src", tbuf_id
[i
]);
1441 ret
= ipp_put_mem_node(drm_dev
, c_node
, m_node
);
1443 DRM_ERROR("failed to put m_node.\n");
1447 /* clear buf for finding */
1448 memset(&qbuf
, 0x0, sizeof(qbuf
));
1449 qbuf
.ops_id
= EXYNOS_DRM_OPS_DST
;
1450 qbuf
.buf_id
= buf_id
[EXYNOS_DRM_OPS_DST
];
1452 /* get memory node entry */
1453 m_node
= ipp_find_mem_node(c_node
, &qbuf
);
1455 DRM_ERROR("empty memory node.\n");
1457 goto err_mem_unlock
;
1460 tbuf_id
[EXYNOS_DRM_OPS_DST
] = m_node
->buf_id
;
1462 ret
= ipp_put_mem_node(drm_dev
, c_node
, m_node
);
1464 DRM_ERROR("failed to put m_node.\n");
1466 case IPP_CMD_OUTPUT
:
1467 /* source memory list */
1468 head
= &c_node
->mem_list
[EXYNOS_DRM_OPS_SRC
];
1470 m_node
= list_first_entry(head
,
1471 struct drm_exynos_ipp_mem_node
, list
);
1473 tbuf_id
[EXYNOS_DRM_OPS_SRC
] = m_node
->buf_id
;
1475 ret
= ipp_put_mem_node(drm_dev
, c_node
, m_node
);
1477 DRM_ERROR("failed to put m_node.\n");
1480 DRM_ERROR("invalid operations.\n");
1482 goto err_mem_unlock
;
1484 mutex_unlock(&c_node
->mem_lock
);
1486 if (tbuf_id
[EXYNOS_DRM_OPS_DST
] != buf_id
[EXYNOS_DRM_OPS_DST
])
1487 DRM_ERROR("failed to match buf_id[%d %d]prop_id[%d]\n",
1488 tbuf_id
[1], buf_id
[1], property
->prop_id
);
1491 * command node have event list of destination buffer
1492 * If destination buffer enqueue to mem list,
1493 * then we make event and link to event list tail.
1494 * so, we get first event for first enqueued buffer.
1496 e
= list_first_entry(&c_node
->event_list
,
1497 struct drm_exynos_ipp_send_event
, base
.link
);
1499 do_gettimeofday(&now
);
1500 DRM_DEBUG_KMS("tv_sec[%ld]tv_usec[%ld]\n", now
.tv_sec
, now
.tv_usec
);
1501 e
->event
.tv_sec
= now
.tv_sec
;
1502 e
->event
.tv_usec
= now
.tv_usec
;
1503 e
->event
.prop_id
= property
->prop_id
;
1505 /* set buffer id about source destination */
1507 e
->event
.buf_id
[i
] = tbuf_id
[i
];
1509 spin_lock_irqsave(&drm_dev
->event_lock
, flags
);
1510 list_move_tail(&e
->base
.link
, &e
->base
.file_priv
->event_list
);
1511 wake_up_interruptible(&e
->base
.file_priv
->event_wait
);
1512 spin_unlock_irqrestore(&drm_dev
->event_lock
, flags
);
1513 mutex_unlock(&c_node
->event_lock
);
1515 DRM_DEBUG_KMS("done cmd[%d]prop_id[%d]buf_id[%d]\n",
1516 property
->cmd
, property
->prop_id
, tbuf_id
[EXYNOS_DRM_OPS_DST
]);
1521 mutex_unlock(&c_node
->mem_lock
);
1523 mutex_unlock(&c_node
->event_lock
);
1527 void ipp_sched_event(struct work_struct
*work
)
1529 struct drm_exynos_ipp_event_work
*event_work
=
1530 container_of(work
, struct drm_exynos_ipp_event_work
, work
);
1531 struct exynos_drm_ippdrv
*ippdrv
;
1532 struct drm_exynos_ipp_cmd_node
*c_node
;
1536 DRM_ERROR("failed to get event_work.\n");
1540 DRM_DEBUG_KMS("buf_id[%d]\n", event_work
->buf_id
[EXYNOS_DRM_OPS_DST
]);
1542 ippdrv
= event_work
->ippdrv
;
1544 DRM_ERROR("failed to get ipp driver.\n");
1548 c_node
= ippdrv
->c_node
;
1550 DRM_ERROR("failed to get command node.\n");
1555 * IPP supports command thread, event thread synchronization.
1556 * If IPP close immediately from user land, then IPP make
1557 * synchronization with command thread, so make complete event.
1558 * or going out operations.
1560 if (c_node
->state
!= IPP_STATE_START
) {
1561 DRM_DEBUG_KMS("bypass state[%d]prop_id[%d]\n",
1562 c_node
->state
, c_node
->property
.prop_id
);
1563 goto err_completion
;
1566 ret
= ipp_send_event(ippdrv
, c_node
, event_work
->buf_id
);
1568 DRM_ERROR("failed to send event.\n");
1569 goto err_completion
;
1573 if (ipp_is_m2m_cmd(c_node
->property
.cmd
))
1574 complete(&c_node
->start_complete
);
1577 static int ipp_subdrv_probe(struct drm_device
*drm_dev
, struct device
*dev
)
1579 struct ipp_context
*ctx
= get_ipp_context(dev
);
1580 struct exynos_drm_ippdrv
*ippdrv
;
1583 /* get ipp driver entry */
1584 list_for_each_entry(ippdrv
, &exynos_drm_ippdrv_list
, drv_list
) {
1585 ippdrv
->drm_dev
= drm_dev
;
1587 ret
= ipp_create_id(&ctx
->ipp_idr
, &ctx
->ipp_lock
, ippdrv
);
1589 DRM_ERROR("failed to create id.\n");
1592 ippdrv
->prop_list
.ipp_id
= ret
;
1594 DRM_DEBUG_KMS("count[%d]ippdrv[0x%x]ipp_id[%d]\n",
1595 count
++, (int)ippdrv
, ret
);
1597 /* store parent device for node */
1598 ippdrv
->parent_dev
= dev
;
1600 /* store event work queue and handler */
1601 ippdrv
->event_workq
= ctx
->event_workq
;
1602 ippdrv
->sched_event
= ipp_sched_event
;
1603 INIT_LIST_HEAD(&ippdrv
->cmd_list
);
1604 mutex_init(&ippdrv
->cmd_lock
);
1606 if (is_drm_iommu_supported(drm_dev
)) {
1607 ret
= drm_iommu_attach_device(drm_dev
, ippdrv
->dev
);
1609 DRM_ERROR("failed to activate iommu\n");
1618 /* get ipp driver entry */
1619 list_for_each_entry_continue_reverse(ippdrv
, &exynos_drm_ippdrv_list
,
1621 if (is_drm_iommu_supported(drm_dev
))
1622 drm_iommu_detach_device(drm_dev
, ippdrv
->dev
);
1624 ipp_remove_id(&ctx
->ipp_idr
, &ctx
->ipp_lock
,
1625 ippdrv
->prop_list
.ipp_id
);
1631 static void ipp_subdrv_remove(struct drm_device
*drm_dev
, struct device
*dev
)
1633 struct exynos_drm_ippdrv
*ippdrv
;
1634 struct ipp_context
*ctx
= get_ipp_context(dev
);
1636 /* get ipp driver entry */
1637 list_for_each_entry(ippdrv
, &exynos_drm_ippdrv_list
, drv_list
) {
1638 if (is_drm_iommu_supported(drm_dev
))
1639 drm_iommu_detach_device(drm_dev
, ippdrv
->dev
);
1641 ipp_remove_id(&ctx
->ipp_idr
, &ctx
->ipp_lock
,
1642 ippdrv
->prop_list
.ipp_id
);
1644 ippdrv
->drm_dev
= NULL
;
1645 exynos_drm_ippdrv_unregister(ippdrv
);
1649 static int ipp_subdrv_open(struct drm_device
*drm_dev
, struct device
*dev
,
1650 struct drm_file
*file
)
1652 struct drm_exynos_file_private
*file_priv
= file
->driver_priv
;
1654 file_priv
->ipp_dev
= dev
;
1656 DRM_DEBUG_KMS("done priv[0x%x]\n", (int)dev
);
1661 static void ipp_subdrv_close(struct drm_device
*drm_dev
, struct device
*dev
,
1662 struct drm_file
*file
)
1664 struct exynos_drm_ippdrv
*ippdrv
= NULL
;
1665 struct ipp_context
*ctx
= get_ipp_context(dev
);
1666 struct drm_exynos_ipp_cmd_node
*c_node
, *tc_node
;
1669 list_for_each_entry(ippdrv
, &exynos_drm_ippdrv_list
, drv_list
) {
1670 mutex_lock(&ippdrv
->cmd_lock
);
1671 list_for_each_entry_safe(c_node
, tc_node
,
1672 &ippdrv
->cmd_list
, list
) {
1673 DRM_DEBUG_KMS("count[%d]ippdrv[0x%x]\n",
1674 count
++, (int)ippdrv
);
1676 if (c_node
->filp
== file
) {
1678 * userland goto unnormal state. process killed.
1679 * and close the file.
1680 * so, IPP didn't called stop cmd ctrl.
1681 * so, we are make stop operation in this state.
1683 if (c_node
->state
== IPP_STATE_START
) {
1684 ipp_stop_property(drm_dev
, ippdrv
,
1686 c_node
->state
= IPP_STATE_STOP
;
1689 ippdrv
->dedicated
= false;
1690 ipp_clean_cmd_node(ctx
, c_node
);
1691 if (list_empty(&ippdrv
->cmd_list
))
1692 pm_runtime_put_sync(ippdrv
->dev
);
1695 mutex_unlock(&ippdrv
->cmd_lock
);
1701 static int ipp_probe(struct platform_device
*pdev
)
1703 struct device
*dev
= &pdev
->dev
;
1704 struct ipp_context
*ctx
;
1705 struct exynos_drm_subdrv
*subdrv
;
1708 ctx
= devm_kzalloc(dev
, sizeof(*ctx
), GFP_KERNEL
);
1712 mutex_init(&ctx
->ipp_lock
);
1713 mutex_init(&ctx
->prop_lock
);
1715 idr_init(&ctx
->ipp_idr
);
1716 idr_init(&ctx
->prop_idr
);
1719 * create single thread for ipp event
1720 * IPP supports event thread for IPP drivers.
1721 * IPP driver send event_work to this thread.
1722 * and IPP event thread send event to user process.
1724 ctx
->event_workq
= create_singlethread_workqueue("ipp_event");
1725 if (!ctx
->event_workq
) {
1726 dev_err(dev
, "failed to create event workqueue\n");
1731 * create single thread for ipp command
1732 * IPP supports command thread for user process.
1733 * user process make command node using set property ioctl.
1734 * and make start_work and send this work to command thread.
1735 * and then this command thread start property.
1737 ctx
->cmd_workq
= create_singlethread_workqueue("ipp_cmd");
1738 if (!ctx
->cmd_workq
) {
1739 dev_err(dev
, "failed to create cmd workqueue\n");
1741 goto err_event_workq
;
1744 /* set sub driver informations */
1745 subdrv
= &ctx
->subdrv
;
1747 subdrv
->probe
= ipp_subdrv_probe
;
1748 subdrv
->remove
= ipp_subdrv_remove
;
1749 subdrv
->open
= ipp_subdrv_open
;
1750 subdrv
->close
= ipp_subdrv_close
;
1752 platform_set_drvdata(pdev
, ctx
);
1754 ret
= exynos_drm_subdrv_register(subdrv
);
1756 DRM_ERROR("failed to register drm ipp device.\n");
1760 dev_info(dev
, "drm ipp registered successfully.\n");
1765 destroy_workqueue(ctx
->cmd_workq
);
1767 destroy_workqueue(ctx
->event_workq
);
1771 static int ipp_remove(struct platform_device
*pdev
)
1773 struct ipp_context
*ctx
= platform_get_drvdata(pdev
);
1775 /* unregister sub driver */
1776 exynos_drm_subdrv_unregister(&ctx
->subdrv
);
1778 /* remove,destroy ipp idr */
1779 idr_destroy(&ctx
->ipp_idr
);
1780 idr_destroy(&ctx
->prop_idr
);
1782 mutex_destroy(&ctx
->ipp_lock
);
1783 mutex_destroy(&ctx
->prop_lock
);
1785 /* destroy command, event work queue */
1786 destroy_workqueue(ctx
->cmd_workq
);
1787 destroy_workqueue(ctx
->event_workq
);
1792 struct platform_driver ipp_driver
= {
1794 .remove
= ipp_remove
,
1796 .name
= "exynos-drm-ipp",
1797 .owner
= THIS_MODULE
,