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 struct drm_exynos_ipp_cmd_work *ipp_create_cmd_work(void)
323 struct drm_exynos_ipp_cmd_work *cmd_work;
325 cmd_work = kzalloc(sizeof(*cmd_work), GFP_KERNEL);
327 return ERR_PTR(-ENOMEM);
329 INIT_WORK((struct work_struct *)cmd_work, ipp_sched_cmd);
334 static struct drm_exynos_ipp_event_work *ipp_create_event_work(void)
336 struct drm_exynos_ipp_event_work *event_work;
338 event_work = kzalloc(sizeof(*event_work), GFP_KERNEL);
340 return ERR_PTR(-ENOMEM);
342 INIT_WORK(&event_work->work, ipp_sched_event);
347 int exynos_drm_ipp_set_property(struct drm_device *drm_dev, void *data,
348 struct drm_file *file)
350 struct drm_exynos_file_private *file_priv = file->driver_priv;
351 struct device *dev = file_priv->ipp_dev;
352 struct ipp_context *ctx = get_ipp_context(dev);
353 struct drm_exynos_ipp_property *property = data;
354 struct exynos_drm_ippdrv *ippdrv;
355 struct drm_exynos_ipp_cmd_node *c_node;
360 DRM_ERROR("invalid context.\n");
365 DRM_ERROR("invalid property parameter.\n");
369 prop_id = property->prop_id;
372 * This is log print for user application property.
373 * user application set various property.
376 ipp_print_property(property, i);
379 * In case prop_id is not zero try to set existing property.
382 c_node = ipp_find_obj(&ctx->prop_idr, &ctx->prop_lock, prop_id);
384 if (!c_node || c_node->filp != file) {
385 DRM_DEBUG_KMS("prop_id[%d] not found\n", prop_id);
389 if (c_node->state != IPP_STATE_STOP) {
390 DRM_DEBUG_KMS("prop_id[%d] not stopped\n", prop_id);
394 c_node->property = *property;
399 /* find ipp driver using ipp id */
400 ippdrv = ipp_find_driver(ctx, property);
401 if (IS_ERR(ippdrv)) {
402 DRM_ERROR("failed to get ipp driver.\n");
406 /* allocate command node */
407 c_node = kzalloc(sizeof(*c_node), GFP_KERNEL);
411 ret = ipp_create_id(&ctx->prop_idr, &ctx->prop_lock, c_node);
413 DRM_ERROR("failed to create id.\n");
416 property->prop_id = ret;
418 DRM_DEBUG_KMS("created prop_id[%d]cmd[%d]ippdrv[0x%x]\n",
419 property->prop_id, property->cmd, (int)ippdrv);
421 /* stored property information and ippdrv in private data */
422 c_node->property = *property;
423 c_node->state = IPP_STATE_IDLE;
426 c_node->start_work = ipp_create_cmd_work();
427 if (IS_ERR(c_node->start_work)) {
428 DRM_ERROR("failed to create start work.\n");
429 ret = PTR_ERR(c_node->start_work);
433 c_node->stop_work = ipp_create_cmd_work();
434 if (IS_ERR(c_node->stop_work)) {
435 DRM_ERROR("failed to create stop work.\n");
436 ret = PTR_ERR(c_node->stop_work);
440 c_node->event_work = ipp_create_event_work();
441 if (IS_ERR(c_node->event_work)) {
442 DRM_ERROR("failed to create event work.\n");
443 ret = PTR_ERR(c_node->event_work);
447 mutex_init(&c_node->lock);
448 mutex_init(&c_node->mem_lock);
449 mutex_init(&c_node->event_lock);
451 init_completion(&c_node->start_complete);
452 init_completion(&c_node->stop_complete);
455 INIT_LIST_HEAD(&c_node->mem_list[i]);
457 INIT_LIST_HEAD(&c_node->event_list);
458 mutex_lock(&ippdrv->cmd_lock);
459 list_add_tail(&c_node->list, &ippdrv->cmd_list);
460 mutex_unlock(&ippdrv->cmd_lock);
462 /* make dedicated state without m2m */
463 if (!ipp_is_m2m_cmd(property->cmd))
464 ippdrv->dedicated = true;
469 kfree(c_node->stop_work);
471 kfree(c_node->start_work);
473 ipp_remove_id(&ctx->prop_idr, &ctx->prop_lock, property->prop_id);
479 static int ipp_put_mem_node(struct drm_device *drm_dev,
480 struct drm_exynos_ipp_cmd_node *c_node,
481 struct drm_exynos_ipp_mem_node *m_node)
485 DRM_DEBUG_KMS("node[0x%x]\n", (int)m_node);
488 DRM_ERROR("invalid dequeue node.\n");
492 DRM_DEBUG_KMS("ops_id[%d]\n", m_node->ops_id);
495 for_each_ipp_planar(i) {
496 unsigned long handle = m_node->buf_info.handles[i];
498 exynos_drm_gem_put_dma_addr(drm_dev, handle,
502 list_del(&m_node->list);
508 static struct drm_exynos_ipp_mem_node
509 *ipp_get_mem_node(struct drm_device *drm_dev,
510 struct drm_exynos_ipp_cmd_node *c_node,
511 struct drm_exynos_ipp_queue_buf *qbuf)
513 struct drm_exynos_ipp_mem_node *m_node;
514 struct drm_exynos_ipp_buf_info *buf_info;
517 m_node = kzalloc(sizeof(*m_node), GFP_KERNEL);
519 return ERR_PTR(-ENOMEM);
521 buf_info = &m_node->buf_info;
523 /* operations, buffer id */
524 m_node->ops_id = qbuf->ops_id;
525 m_node->prop_id = qbuf->prop_id;
526 m_node->buf_id = qbuf->buf_id;
527 INIT_LIST_HEAD(&m_node->list);
529 DRM_DEBUG_KMS("m_node[0x%x]ops_id[%d]\n", (int)m_node, qbuf->ops_id);
530 DRM_DEBUG_KMS("prop_id[%d]buf_id[%d]\n", qbuf->prop_id, m_node->buf_id);
532 for_each_ipp_planar(i) {
533 DRM_DEBUG_KMS("i[%d]handle[0x%x]\n", i, qbuf->handle[i]);
535 /* get dma address by handle */
536 if (qbuf->handle[i]) {
539 addr = exynos_drm_gem_get_dma_addr(drm_dev,
540 qbuf->handle[i], c_node->filp);
542 DRM_ERROR("failed to get addr.\n");
543 ipp_put_mem_node(drm_dev, c_node, m_node);
544 return ERR_PTR(-EFAULT);
547 buf_info->handles[i] = qbuf->handle[i];
548 buf_info->base[i] = *addr;
549 DRM_DEBUG_KMS("i[%d]base[0x%x]hd[0x%lx]\n", i,
550 buf_info->base[i], buf_info->handles[i]);
554 mutex_lock(&c_node->mem_lock);
555 list_add_tail(&m_node->list, &c_node->mem_list[qbuf->ops_id]);
556 mutex_unlock(&c_node->mem_lock);
561 static void ipp_clean_mem_nodes(struct drm_device *drm_dev,
562 struct drm_exynos_ipp_cmd_node *c_node, int ops)
564 struct drm_exynos_ipp_mem_node *m_node, *tm_node;
565 struct list_head *head = &c_node->mem_list[ops];
567 mutex_lock(&c_node->mem_lock);
569 list_for_each_entry_safe(m_node, tm_node, head, list) {
572 ret = ipp_put_mem_node(drm_dev, c_node, m_node);
574 DRM_ERROR("failed to put m_node.\n");
577 mutex_unlock(&c_node->mem_lock);
580 static void ipp_free_event(struct drm_pending_event *event)
585 static int ipp_get_event(struct drm_device *drm_dev,
586 struct drm_exynos_ipp_cmd_node *c_node,
587 struct drm_exynos_ipp_queue_buf *qbuf)
589 struct drm_exynos_ipp_send_event *e;
592 DRM_DEBUG_KMS("ops_id[%d]buf_id[%d]\n", qbuf->ops_id, qbuf->buf_id);
594 e = kzalloc(sizeof(*e), GFP_KERNEL);
596 spin_lock_irqsave(&drm_dev->event_lock, flags);
597 c_node->filp->event_space += sizeof(e->event);
598 spin_unlock_irqrestore(&drm_dev->event_lock, flags);
603 e->event.base.type = DRM_EXYNOS_IPP_EVENT;
604 e->event.base.length = sizeof(e->event);
605 e->event.user_data = qbuf->user_data;
606 e->event.prop_id = qbuf->prop_id;
607 e->event.buf_id[EXYNOS_DRM_OPS_DST] = qbuf->buf_id;
608 e->base.event = &e->event.base;
609 e->base.file_priv = c_node->filp;
610 e->base.destroy = ipp_free_event;
611 mutex_lock(&c_node->event_lock);
612 list_add_tail(&e->base.link, &c_node->event_list);
613 mutex_unlock(&c_node->event_lock);
618 static void ipp_put_event(struct drm_exynos_ipp_cmd_node *c_node,
619 struct drm_exynos_ipp_queue_buf *qbuf)
621 struct drm_exynos_ipp_send_event *e, *te;
624 mutex_lock(&c_node->event_lock);
625 list_for_each_entry_safe(e, te, &c_node->event_list, base.link) {
626 DRM_DEBUG_KMS("count[%d]e[0x%x]\n", count++, (int)e);
629 * qbuf == NULL condition means all event deletion.
630 * stop operations want to delete all event list.
631 * another case delete only same buf id.
635 list_del(&e->base.link);
639 /* compare buffer id */
640 if (qbuf && (qbuf->buf_id ==
641 e->event.buf_id[EXYNOS_DRM_OPS_DST])) {
643 list_del(&e->base.link);
650 mutex_unlock(&c_node->event_lock);
654 static void ipp_clean_cmd_node(struct ipp_context *ctx,
655 struct drm_exynos_ipp_cmd_node *c_node)
660 cancel_work_sync(&c_node->start_work->work);
661 cancel_work_sync(&c_node->stop_work->work);
662 cancel_work_sync(&c_node->event_work->work);
665 ipp_put_event(c_node, NULL);
668 ipp_clean_mem_nodes(ctx->subdrv.drm_dev, c_node, i);
671 list_del(&c_node->list);
673 ipp_remove_id(&ctx->prop_idr, &ctx->prop_lock,
674 c_node->property.prop_id);
677 mutex_destroy(&c_node->lock);
678 mutex_destroy(&c_node->mem_lock);
679 mutex_destroy(&c_node->event_lock);
681 /* free command node */
682 kfree(c_node->start_work);
683 kfree(c_node->stop_work);
684 kfree(c_node->event_work);
688 static bool ipp_check_mem_list(struct drm_exynos_ipp_cmd_node *c_node)
690 switch (c_node->property.cmd) {
692 return !list_empty(&c_node->mem_list[EXYNOS_DRM_OPS_DST]);
694 return !list_empty(&c_node->mem_list[EXYNOS_DRM_OPS_SRC]);
697 return !list_empty(&c_node->mem_list[EXYNOS_DRM_OPS_SRC]) &&
698 !list_empty(&c_node->mem_list[EXYNOS_DRM_OPS_DST]);
702 static struct drm_exynos_ipp_mem_node
703 *ipp_find_mem_node(struct drm_exynos_ipp_cmd_node *c_node,
704 struct drm_exynos_ipp_queue_buf *qbuf)
706 struct drm_exynos_ipp_mem_node *m_node;
707 struct list_head *head;
710 DRM_DEBUG_KMS("buf_id[%d]\n", qbuf->buf_id);
712 /* source/destination memory list */
713 head = &c_node->mem_list[qbuf->ops_id];
715 /* find memory node from memory list */
716 list_for_each_entry(m_node, head, list) {
717 DRM_DEBUG_KMS("count[%d]m_node[0x%x]\n", count++, (int)m_node);
719 /* compare buffer id */
720 if (m_node->buf_id == qbuf->buf_id)
727 static int ipp_set_mem_node(struct exynos_drm_ippdrv *ippdrv,
728 struct drm_exynos_ipp_cmd_node *c_node,
729 struct drm_exynos_ipp_mem_node *m_node)
731 struct exynos_drm_ipp_ops *ops = NULL;
734 DRM_DEBUG_KMS("node[0x%x]\n", (int)m_node);
737 DRM_ERROR("invalid queue node.\n");
741 DRM_DEBUG_KMS("ops_id[%d]\n", m_node->ops_id);
743 /* get operations callback */
744 ops = ippdrv->ops[m_node->ops_id];
746 DRM_ERROR("not support ops.\n");
750 /* set address and enable irq */
752 ret = ops->set_addr(ippdrv->dev, &m_node->buf_info,
753 m_node->buf_id, IPP_BUF_ENQUEUE);
755 DRM_ERROR("failed to set addr.\n");
763 static void ipp_handle_cmd_work(struct device *dev,
764 struct exynos_drm_ippdrv *ippdrv,
765 struct drm_exynos_ipp_cmd_work *cmd_work,
766 struct drm_exynos_ipp_cmd_node *c_node)
768 struct ipp_context *ctx = get_ipp_context(dev);
770 cmd_work->ippdrv = ippdrv;
771 cmd_work->c_node = c_node;
772 queue_work(ctx->cmd_workq, &cmd_work->work);
775 static int ipp_queue_buf_with_run(struct device *dev,
776 struct drm_exynos_ipp_cmd_node *c_node,
777 struct drm_exynos_ipp_mem_node *m_node,
778 struct drm_exynos_ipp_queue_buf *qbuf)
780 struct exynos_drm_ippdrv *ippdrv;
781 struct drm_exynos_ipp_property *property;
782 struct exynos_drm_ipp_ops *ops;
785 ippdrv = ipp_find_drv_by_handle(qbuf->prop_id);
786 if (IS_ERR(ippdrv)) {
787 DRM_ERROR("failed to get ipp driver.\n");
791 ops = ippdrv->ops[qbuf->ops_id];
793 DRM_ERROR("failed to get ops.\n");
797 property = &c_node->property;
799 if (c_node->state != IPP_STATE_START) {
800 DRM_DEBUG_KMS("bypass for invalid state.\n");
804 mutex_lock(&c_node->mem_lock);
805 if (!ipp_check_mem_list(c_node)) {
806 mutex_unlock(&c_node->mem_lock);
807 DRM_DEBUG_KMS("empty memory.\n");
812 * If set destination buffer and enabled clock,
813 * then m2m operations need start operations at queue_buf
815 if (ipp_is_m2m_cmd(property->cmd)) {
816 struct drm_exynos_ipp_cmd_work *cmd_work = c_node->start_work;
818 cmd_work->ctrl = IPP_CTRL_PLAY;
819 ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
821 ret = ipp_set_mem_node(ippdrv, c_node, m_node);
823 mutex_unlock(&c_node->mem_lock);
824 DRM_ERROR("failed to set m node.\n");
828 mutex_unlock(&c_node->mem_lock);
833 static void ipp_clean_queue_buf(struct drm_device *drm_dev,
834 struct drm_exynos_ipp_cmd_node *c_node,
835 struct drm_exynos_ipp_queue_buf *qbuf)
837 struct drm_exynos_ipp_mem_node *m_node, *tm_node;
840 mutex_lock(&c_node->mem_lock);
841 list_for_each_entry_safe(m_node, tm_node,
842 &c_node->mem_list[qbuf->ops_id], list) {
843 if (m_node->buf_id == qbuf->buf_id &&
844 m_node->ops_id == qbuf->ops_id)
845 ipp_put_mem_node(drm_dev, c_node, m_node);
847 mutex_unlock(&c_node->mem_lock);
850 int exynos_drm_ipp_queue_buf(struct drm_device *drm_dev, void *data,
851 struct drm_file *file)
853 struct drm_exynos_file_private *file_priv = file->driver_priv;
854 struct device *dev = file_priv->ipp_dev;
855 struct ipp_context *ctx = get_ipp_context(dev);
856 struct drm_exynos_ipp_queue_buf *qbuf = data;
857 struct drm_exynos_ipp_cmd_node *c_node;
858 struct drm_exynos_ipp_mem_node *m_node;
862 DRM_ERROR("invalid buf parameter.\n");
866 if (qbuf->ops_id >= EXYNOS_DRM_OPS_MAX) {
867 DRM_ERROR("invalid ops parameter.\n");
871 DRM_DEBUG_KMS("prop_id[%d]ops_id[%s]buf_id[%d]buf_type[%d]\n",
872 qbuf->prop_id, qbuf->ops_id ? "dst" : "src",
873 qbuf->buf_id, qbuf->buf_type);
875 /* find command node */
876 c_node = ipp_find_obj(&ctx->prop_idr, &ctx->prop_lock,
878 if (!c_node || c_node->filp != file) {
879 DRM_ERROR("failed to get command node.\n");
884 switch (qbuf->buf_type) {
885 case IPP_BUF_ENQUEUE:
886 /* get memory node */
887 m_node = ipp_get_mem_node(drm_dev, c_node, qbuf);
888 if (IS_ERR(m_node)) {
889 DRM_ERROR("failed to get m_node.\n");
890 return PTR_ERR(m_node);
894 * first step get event for destination buffer.
895 * and second step when M2M case run with destination buffer
898 if (qbuf->ops_id == EXYNOS_DRM_OPS_DST) {
899 /* get event for destination buffer */
900 ret = ipp_get_event(drm_dev, c_node, qbuf);
902 DRM_ERROR("failed to get event.\n");
907 * M2M case run play control for streaming feature.
908 * other case set address and waiting.
910 ret = ipp_queue_buf_with_run(dev, c_node, m_node, qbuf);
912 DRM_ERROR("failed to run command.\n");
917 case IPP_BUF_DEQUEUE:
918 mutex_lock(&c_node->lock);
920 /* put event for destination buffer */
921 if (qbuf->ops_id == EXYNOS_DRM_OPS_DST)
922 ipp_put_event(c_node, qbuf);
924 ipp_clean_queue_buf(drm_dev, c_node, qbuf);
926 mutex_unlock(&c_node->lock);
929 DRM_ERROR("invalid buffer control.\n");
936 DRM_ERROR("clean memory nodes.\n");
938 ipp_clean_queue_buf(drm_dev, c_node, qbuf);
942 static bool exynos_drm_ipp_check_valid(struct device *dev,
943 enum drm_exynos_ipp_ctrl ctrl, enum drm_exynos_ipp_state state)
945 if (ctrl != IPP_CTRL_PLAY) {
946 if (pm_runtime_suspended(dev)) {
947 DRM_ERROR("pm:runtime_suspended.\n");
954 if (state != IPP_STATE_IDLE)
958 if (state == IPP_STATE_STOP)
962 if (state != IPP_STATE_START)
965 case IPP_CTRL_RESUME:
966 if (state != IPP_STATE_STOP)
970 DRM_ERROR("invalid state.\n");
977 DRM_ERROR("invalid status:ctrl[%d]state[%d]\n", ctrl, state);
981 int exynos_drm_ipp_cmd_ctrl(struct drm_device *drm_dev, void *data,
982 struct drm_file *file)
984 struct drm_exynos_file_private *file_priv = file->driver_priv;
985 struct exynos_drm_ippdrv *ippdrv = NULL;
986 struct device *dev = file_priv->ipp_dev;
987 struct ipp_context *ctx = get_ipp_context(dev);
988 struct drm_exynos_ipp_cmd_ctrl *cmd_ctrl = data;
989 struct drm_exynos_ipp_cmd_work *cmd_work;
990 struct drm_exynos_ipp_cmd_node *c_node;
993 DRM_ERROR("invalid context.\n");
998 DRM_ERROR("invalid control parameter.\n");
1002 DRM_DEBUG_KMS("ctrl[%d]prop_id[%d]\n",
1003 cmd_ctrl->ctrl, cmd_ctrl->prop_id);
1005 ippdrv = ipp_find_drv_by_handle(cmd_ctrl->prop_id);
1006 if (IS_ERR(ippdrv)) {
1007 DRM_ERROR("failed to get ipp driver.\n");
1008 return PTR_ERR(ippdrv);
1011 c_node = ipp_find_obj(&ctx->prop_idr, &ctx->prop_lock,
1013 if (!c_node || c_node->filp != file) {
1014 DRM_ERROR("invalid command node list.\n");
1018 if (!exynos_drm_ipp_check_valid(ippdrv->dev, cmd_ctrl->ctrl,
1020 DRM_ERROR("invalid state.\n");
1024 switch (cmd_ctrl->ctrl) {
1026 if (pm_runtime_suspended(ippdrv->dev))
1027 pm_runtime_get_sync(ippdrv->dev);
1029 c_node->state = IPP_STATE_START;
1031 cmd_work = c_node->start_work;
1032 cmd_work->ctrl = cmd_ctrl->ctrl;
1033 ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
1036 cmd_work = c_node->stop_work;
1037 cmd_work->ctrl = cmd_ctrl->ctrl;
1038 ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
1040 if (!wait_for_completion_timeout(&c_node->stop_complete,
1041 msecs_to_jiffies(300))) {
1042 DRM_ERROR("timeout stop:prop_id[%d]\n",
1043 c_node->property.prop_id);
1046 c_node->state = IPP_STATE_STOP;
1047 ippdrv->dedicated = false;
1048 mutex_lock(&ippdrv->cmd_lock);
1049 ipp_clean_cmd_node(ctx, c_node);
1051 if (list_empty(&ippdrv->cmd_list))
1052 pm_runtime_put_sync(ippdrv->dev);
1053 mutex_unlock(&ippdrv->cmd_lock);
1055 case IPP_CTRL_PAUSE:
1056 cmd_work = c_node->stop_work;
1057 cmd_work->ctrl = cmd_ctrl->ctrl;
1058 ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
1060 if (!wait_for_completion_timeout(&c_node->stop_complete,
1061 msecs_to_jiffies(200))) {
1062 DRM_ERROR("timeout stop:prop_id[%d]\n",
1063 c_node->property.prop_id);
1066 c_node->state = IPP_STATE_STOP;
1068 case IPP_CTRL_RESUME:
1069 c_node->state = IPP_STATE_START;
1070 cmd_work = c_node->start_work;
1071 cmd_work->ctrl = cmd_ctrl->ctrl;
1072 ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
1075 DRM_ERROR("could not support this state currently.\n");
1079 DRM_DEBUG_KMS("done ctrl[%d]prop_id[%d]\n",
1080 cmd_ctrl->ctrl, cmd_ctrl->prop_id);
1085 int exynos_drm_ippnb_register(struct notifier_block *nb)
1087 return blocking_notifier_chain_register(
1088 &exynos_drm_ippnb_list, nb);
1091 int exynos_drm_ippnb_unregister(struct notifier_block *nb)
1093 return blocking_notifier_chain_unregister(
1094 &exynos_drm_ippnb_list, nb);
1097 int exynos_drm_ippnb_send_event(unsigned long val, void *v)
1099 return blocking_notifier_call_chain(
1100 &exynos_drm_ippnb_list, val, v);
1103 static int ipp_set_property(struct exynos_drm_ippdrv *ippdrv,
1104 struct drm_exynos_ipp_property *property)
1106 struct exynos_drm_ipp_ops *ops = NULL;
1111 DRM_ERROR("invalid property parameter.\n");
1115 DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id);
1117 /* reset h/w block */
1118 if (ippdrv->reset &&
1119 ippdrv->reset(ippdrv->dev)) {
1123 /* set source,destination operations */
1124 for_each_ipp_ops(i) {
1125 struct drm_exynos_ipp_config *config =
1126 &property->config[i];
1128 ops = ippdrv->ops[i];
1129 if (!ops || !config) {
1130 DRM_ERROR("not support ops and config.\n");
1136 ret = ops->set_fmt(ippdrv->dev, config->fmt);
1141 /* set transform for rotation, flip */
1142 if (ops->set_transf) {
1143 ret = ops->set_transf(ippdrv->dev, config->degree,
1144 config->flip, &swap);
1150 if (ops->set_size) {
1151 ret = ops->set_size(ippdrv->dev, swap, &config->pos,
1161 static int ipp_start_property(struct exynos_drm_ippdrv *ippdrv,
1162 struct drm_exynos_ipp_cmd_node *c_node)
1164 struct drm_exynos_ipp_mem_node *m_node;
1165 struct drm_exynos_ipp_property *property = &c_node->property;
1166 struct list_head *head;
1169 DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id);
1171 /* store command info in ippdrv */
1172 ippdrv->c_node = c_node;
1174 mutex_lock(&c_node->mem_lock);
1175 if (!ipp_check_mem_list(c_node)) {
1176 DRM_DEBUG_KMS("empty memory.\n");
1181 /* set current property in ippdrv */
1182 ret = ipp_set_property(ippdrv, property);
1184 DRM_ERROR("failed to set property.\n");
1185 ippdrv->c_node = NULL;
1190 switch (property->cmd) {
1192 for_each_ipp_ops(i) {
1193 /* source/destination memory list */
1194 head = &c_node->mem_list[i];
1196 m_node = list_first_entry(head,
1197 struct drm_exynos_ipp_mem_node, list);
1199 DRM_DEBUG_KMS("m_node[0x%x]\n", (int)m_node);
1201 ret = ipp_set_mem_node(ippdrv, c_node, m_node);
1203 DRM_ERROR("failed to set m node.\n");
1209 /* destination memory list */
1210 head = &c_node->mem_list[EXYNOS_DRM_OPS_DST];
1212 list_for_each_entry(m_node, head, list) {
1213 ret = ipp_set_mem_node(ippdrv, c_node, m_node);
1215 DRM_ERROR("failed to set m node.\n");
1220 case IPP_CMD_OUTPUT:
1221 /* source memory list */
1222 head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC];
1224 list_for_each_entry(m_node, head, list) {
1225 ret = ipp_set_mem_node(ippdrv, c_node, m_node);
1227 DRM_ERROR("failed to set m node.\n");
1233 DRM_ERROR("invalid operations.\n");
1237 mutex_unlock(&c_node->mem_lock);
1239 DRM_DEBUG_KMS("cmd[%d]\n", property->cmd);
1241 /* start operations */
1242 if (ippdrv->start) {
1243 ret = ippdrv->start(ippdrv->dev, property->cmd);
1245 DRM_ERROR("failed to start ops.\n");
1246 ippdrv->c_node = NULL;
1254 mutex_unlock(&c_node->mem_lock);
1255 ippdrv->c_node = NULL;
1259 static int ipp_stop_property(struct drm_device *drm_dev,
1260 struct exynos_drm_ippdrv *ippdrv,
1261 struct drm_exynos_ipp_cmd_node *c_node)
1263 struct drm_exynos_ipp_property *property = &c_node->property;
1266 DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id);
1268 /* stop operations */
1270 ippdrv->stop(ippdrv->dev, property->cmd);
1273 switch (property->cmd) {
1276 ipp_clean_mem_nodes(drm_dev, c_node, i);
1279 ipp_clean_mem_nodes(drm_dev, c_node, EXYNOS_DRM_OPS_DST);
1281 case IPP_CMD_OUTPUT:
1282 ipp_clean_mem_nodes(drm_dev, c_node, EXYNOS_DRM_OPS_SRC);
1285 DRM_ERROR("invalid operations.\n");
1292 void ipp_sched_cmd(struct work_struct *work)
1294 struct drm_exynos_ipp_cmd_work *cmd_work =
1295 container_of(work, struct drm_exynos_ipp_cmd_work, work);
1296 struct exynos_drm_ippdrv *ippdrv;
1297 struct drm_exynos_ipp_cmd_node *c_node;
1298 struct drm_exynos_ipp_property *property;
1301 ippdrv = cmd_work->ippdrv;
1303 DRM_ERROR("invalid ippdrv list.\n");
1307 c_node = cmd_work->c_node;
1309 DRM_ERROR("invalid command node list.\n");
1313 mutex_lock(&c_node->lock);
1315 property = &c_node->property;
1317 switch (cmd_work->ctrl) {
1319 case IPP_CTRL_RESUME:
1320 ret = ipp_start_property(ippdrv, c_node);
1322 DRM_ERROR("failed to start property:prop_id[%d]\n",
1323 c_node->property.prop_id);
1328 * M2M case supports wait_completion of transfer.
1329 * because M2M case supports single unit operation
1330 * with multiple queue.
1331 * M2M need to wait completion of data transfer.
1333 if (ipp_is_m2m_cmd(property->cmd)) {
1334 if (!wait_for_completion_timeout
1335 (&c_node->start_complete, msecs_to_jiffies(200))) {
1336 DRM_ERROR("timeout event:prop_id[%d]\n",
1337 c_node->property.prop_id);
1343 case IPP_CTRL_PAUSE:
1344 ret = ipp_stop_property(ippdrv->drm_dev, ippdrv,
1347 DRM_ERROR("failed to stop property.\n");
1351 complete(&c_node->stop_complete);
1354 DRM_ERROR("unknown control type\n");
1358 DRM_DEBUG_KMS("ctrl[%d] done.\n", cmd_work->ctrl);
1361 mutex_unlock(&c_node->lock);
1364 static int ipp_send_event(struct exynos_drm_ippdrv *ippdrv,
1365 struct drm_exynos_ipp_cmd_node *c_node, int *buf_id)
1367 struct drm_device *drm_dev = ippdrv->drm_dev;
1368 struct drm_exynos_ipp_property *property = &c_node->property;
1369 struct drm_exynos_ipp_mem_node *m_node;
1370 struct drm_exynos_ipp_queue_buf qbuf;
1371 struct drm_exynos_ipp_send_event *e;
1372 struct list_head *head;
1374 unsigned long flags;
1375 u32 tbuf_id[EXYNOS_DRM_OPS_MAX] = {0, };
1379 DRM_DEBUG_KMS("%s buf_id[%d]\n", i ? "dst" : "src", buf_id[i]);
1382 DRM_ERROR("failed to get drm_dev.\n");
1387 DRM_ERROR("failed to get property.\n");
1391 mutex_lock(&c_node->event_lock);
1392 if (list_empty(&c_node->event_list)) {
1393 DRM_DEBUG_KMS("event list is empty.\n");
1395 goto err_event_unlock;
1398 mutex_lock(&c_node->mem_lock);
1399 if (!ipp_check_mem_list(c_node)) {
1400 DRM_DEBUG_KMS("empty memory.\n");
1402 goto err_mem_unlock;
1406 switch (property->cmd) {
1408 for_each_ipp_ops(i) {
1409 /* source/destination memory list */
1410 head = &c_node->mem_list[i];
1412 m_node = list_first_entry(head,
1413 struct drm_exynos_ipp_mem_node, list);
1415 tbuf_id[i] = m_node->buf_id;
1416 DRM_DEBUG_KMS("%s buf_id[%d]\n",
1417 i ? "dst" : "src", tbuf_id[i]);
1419 ret = ipp_put_mem_node(drm_dev, c_node, m_node);
1421 DRM_ERROR("failed to put m_node.\n");
1425 /* clear buf for finding */
1426 memset(&qbuf, 0x0, sizeof(qbuf));
1427 qbuf.ops_id = EXYNOS_DRM_OPS_DST;
1428 qbuf.buf_id = buf_id[EXYNOS_DRM_OPS_DST];
1430 /* get memory node entry */
1431 m_node = ipp_find_mem_node(c_node, &qbuf);
1433 DRM_ERROR("empty memory node.\n");
1435 goto err_mem_unlock;
1438 tbuf_id[EXYNOS_DRM_OPS_DST] = m_node->buf_id;
1440 ret = ipp_put_mem_node(drm_dev, c_node, m_node);
1442 DRM_ERROR("failed to put m_node.\n");
1444 case IPP_CMD_OUTPUT:
1445 /* source memory list */
1446 head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC];
1448 m_node = list_first_entry(head,
1449 struct drm_exynos_ipp_mem_node, list);
1451 tbuf_id[EXYNOS_DRM_OPS_SRC] = m_node->buf_id;
1453 ret = ipp_put_mem_node(drm_dev, c_node, m_node);
1455 DRM_ERROR("failed to put m_node.\n");
1458 DRM_ERROR("invalid operations.\n");
1460 goto err_mem_unlock;
1462 mutex_unlock(&c_node->mem_lock);
1464 if (tbuf_id[EXYNOS_DRM_OPS_DST] != buf_id[EXYNOS_DRM_OPS_DST])
1465 DRM_ERROR("failed to match buf_id[%d %d]prop_id[%d]\n",
1466 tbuf_id[1], buf_id[1], property->prop_id);
1469 * command node have event list of destination buffer
1470 * If destination buffer enqueue to mem list,
1471 * then we make event and link to event list tail.
1472 * so, we get first event for first enqueued buffer.
1474 e = list_first_entry(&c_node->event_list,
1475 struct drm_exynos_ipp_send_event, base.link);
1477 do_gettimeofday(&now);
1478 DRM_DEBUG_KMS("tv_sec[%ld]tv_usec[%ld]\n", now.tv_sec, now.tv_usec);
1479 e->event.tv_sec = now.tv_sec;
1480 e->event.tv_usec = now.tv_usec;
1481 e->event.prop_id = property->prop_id;
1483 /* set buffer id about source destination */
1485 e->event.buf_id[i] = tbuf_id[i];
1487 spin_lock_irqsave(&drm_dev->event_lock, flags);
1488 list_move_tail(&e->base.link, &e->base.file_priv->event_list);
1489 wake_up_interruptible(&e->base.file_priv->event_wait);
1490 spin_unlock_irqrestore(&drm_dev->event_lock, flags);
1491 mutex_unlock(&c_node->event_lock);
1493 DRM_DEBUG_KMS("done cmd[%d]prop_id[%d]buf_id[%d]\n",
1494 property->cmd, property->prop_id, tbuf_id[EXYNOS_DRM_OPS_DST]);
1499 mutex_unlock(&c_node->mem_lock);
1501 mutex_unlock(&c_node->event_lock);
1505 void ipp_sched_event(struct work_struct *work)
1507 struct drm_exynos_ipp_event_work *event_work =
1508 container_of(work, struct drm_exynos_ipp_event_work, work);
1509 struct exynos_drm_ippdrv *ippdrv;
1510 struct drm_exynos_ipp_cmd_node *c_node;
1514 DRM_ERROR("failed to get event_work.\n");
1518 DRM_DEBUG_KMS("buf_id[%d]\n", event_work->buf_id[EXYNOS_DRM_OPS_DST]);
1520 ippdrv = event_work->ippdrv;
1522 DRM_ERROR("failed to get ipp driver.\n");
1526 c_node = ippdrv->c_node;
1528 DRM_ERROR("failed to get command node.\n");
1533 * IPP supports command thread, event thread synchronization.
1534 * If IPP close immediately from user land, then IPP make
1535 * synchronization with command thread, so make complete event.
1536 * or going out operations.
1538 if (c_node->state != IPP_STATE_START) {
1539 DRM_DEBUG_KMS("bypass state[%d]prop_id[%d]\n",
1540 c_node->state, c_node->property.prop_id);
1541 goto err_completion;
1544 ret = ipp_send_event(ippdrv, c_node, event_work->buf_id);
1546 DRM_ERROR("failed to send event.\n");
1547 goto err_completion;
1551 if (ipp_is_m2m_cmd(c_node->property.cmd))
1552 complete(&c_node->start_complete);
1555 static int ipp_subdrv_probe(struct drm_device *drm_dev, struct device *dev)
1557 struct ipp_context *ctx = get_ipp_context(dev);
1558 struct exynos_drm_ippdrv *ippdrv;
1561 /* get ipp driver entry */
1562 list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
1563 ippdrv->drm_dev = drm_dev;
1565 ret = ipp_create_id(&ctx->ipp_idr, &ctx->ipp_lock, ippdrv);
1567 DRM_ERROR("failed to create id.\n");
1570 ippdrv->prop_list.ipp_id = ret;
1572 DRM_DEBUG_KMS("count[%d]ippdrv[0x%x]ipp_id[%d]\n",
1573 count++, (int)ippdrv, ret);
1575 /* store parent device for node */
1576 ippdrv->parent_dev = dev;
1578 /* store event work queue and handler */
1579 ippdrv->event_workq = ctx->event_workq;
1580 ippdrv->sched_event = ipp_sched_event;
1581 INIT_LIST_HEAD(&ippdrv->cmd_list);
1582 mutex_init(&ippdrv->cmd_lock);
1584 if (is_drm_iommu_supported(drm_dev)) {
1585 ret = drm_iommu_attach_device(drm_dev, ippdrv->dev);
1587 DRM_ERROR("failed to activate iommu\n");
1596 /* get ipp driver entry */
1597 list_for_each_entry_continue_reverse(ippdrv, &exynos_drm_ippdrv_list,
1599 if (is_drm_iommu_supported(drm_dev))
1600 drm_iommu_detach_device(drm_dev, ippdrv->dev);
1602 ipp_remove_id(&ctx->ipp_idr, &ctx->ipp_lock,
1603 ippdrv->prop_list.ipp_id);
1609 static void ipp_subdrv_remove(struct drm_device *drm_dev, struct device *dev)
1611 struct exynos_drm_ippdrv *ippdrv, *t;
1612 struct ipp_context *ctx = get_ipp_context(dev);
1614 /* get ipp driver entry */
1615 list_for_each_entry_safe(ippdrv, t, &exynos_drm_ippdrv_list, drv_list) {
1616 if (is_drm_iommu_supported(drm_dev))
1617 drm_iommu_detach_device(drm_dev, ippdrv->dev);
1619 ipp_remove_id(&ctx->ipp_idr, &ctx->ipp_lock,
1620 ippdrv->prop_list.ipp_id);
1622 ippdrv->drm_dev = NULL;
1623 exynos_drm_ippdrv_unregister(ippdrv);
1627 static int ipp_subdrv_open(struct drm_device *drm_dev, struct device *dev,
1628 struct drm_file *file)
1630 struct drm_exynos_file_private *file_priv = file->driver_priv;
1632 file_priv->ipp_dev = dev;
1634 DRM_DEBUG_KMS("done priv[0x%x]\n", (int)dev);
1639 static void ipp_subdrv_close(struct drm_device *drm_dev, struct device *dev,
1640 struct drm_file *file)
1642 struct exynos_drm_ippdrv *ippdrv = NULL;
1643 struct ipp_context *ctx = get_ipp_context(dev);
1644 struct drm_exynos_ipp_cmd_node *c_node, *tc_node;
1647 list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
1648 mutex_lock(&ippdrv->cmd_lock);
1649 list_for_each_entry_safe(c_node, tc_node,
1650 &ippdrv->cmd_list, list) {
1651 DRM_DEBUG_KMS("count[%d]ippdrv[0x%x]\n",
1652 count++, (int)ippdrv);
1654 if (c_node->filp == file) {
1656 * userland goto unnormal state. process killed.
1657 * and close the file.
1658 * so, IPP didn't called stop cmd ctrl.
1659 * so, we are make stop operation in this state.
1661 if (c_node->state == IPP_STATE_START) {
1662 ipp_stop_property(drm_dev, ippdrv,
1664 c_node->state = IPP_STATE_STOP;
1667 ippdrv->dedicated = false;
1668 ipp_clean_cmd_node(ctx, c_node);
1669 if (list_empty(&ippdrv->cmd_list))
1670 pm_runtime_put_sync(ippdrv->dev);
1673 mutex_unlock(&ippdrv->cmd_lock);
1679 static int ipp_probe(struct platform_device *pdev)
1681 struct device *dev = &pdev->dev;
1682 struct ipp_context *ctx;
1683 struct exynos_drm_subdrv *subdrv;
1686 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
1690 mutex_init(&ctx->ipp_lock);
1691 mutex_init(&ctx->prop_lock);
1693 idr_init(&ctx->ipp_idr);
1694 idr_init(&ctx->prop_idr);
1697 * create single thread for ipp event
1698 * IPP supports event thread for IPP drivers.
1699 * IPP driver send event_work to this thread.
1700 * and IPP event thread send event to user process.
1702 ctx->event_workq = create_singlethread_workqueue("ipp_event");
1703 if (!ctx->event_workq) {
1704 dev_err(dev, "failed to create event workqueue\n");
1709 * create single thread for ipp command
1710 * IPP supports command thread for user process.
1711 * user process make command node using set property ioctl.
1712 * and make start_work and send this work to command thread.
1713 * and then this command thread start property.
1715 ctx->cmd_workq = create_singlethread_workqueue("ipp_cmd");
1716 if (!ctx->cmd_workq) {
1717 dev_err(dev, "failed to create cmd workqueue\n");
1719 goto err_event_workq;
1722 /* set sub driver informations */
1723 subdrv = &ctx->subdrv;
1725 subdrv->probe = ipp_subdrv_probe;
1726 subdrv->remove = ipp_subdrv_remove;
1727 subdrv->open = ipp_subdrv_open;
1728 subdrv->close = ipp_subdrv_close;
1730 platform_set_drvdata(pdev, ctx);
1732 ret = exynos_drm_subdrv_register(subdrv);
1734 DRM_ERROR("failed to register drm ipp device.\n");
1738 dev_info(dev, "drm ipp registered successfully.\n");
1743 destroy_workqueue(ctx->cmd_workq);
1745 destroy_workqueue(ctx->event_workq);
1749 static int ipp_remove(struct platform_device *pdev)
1751 struct ipp_context *ctx = platform_get_drvdata(pdev);
1753 /* unregister sub driver */
1754 exynos_drm_subdrv_unregister(&ctx->subdrv);
1756 /* remove,destroy ipp idr */
1757 idr_destroy(&ctx->ipp_idr);
1758 idr_destroy(&ctx->prop_idr);
1760 mutex_destroy(&ctx->ipp_lock);
1761 mutex_destroy(&ctx->prop_lock);
1763 /* destroy command, event work queue */
1764 destroy_workqueue(ctx->cmd_workq);
1765 destroy_workqueue(ctx->event_workq);
1770 struct platform_driver ipp_driver = {
1772 .remove = ipp_remove,
1774 .name = "exynos-drm-ipp",
1775 .owner = THIS_MODULE,