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;
78 struct drm_file *filp;
82 * A structure of ipp context.
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.
93 struct exynos_drm_subdrv subdrv;
94 struct mutex ipp_lock;
95 struct mutex prop_lock;
98 struct workqueue_struct *event_workq;
99 struct workqueue_struct *cmd_workq;
102 static LIST_HEAD(exynos_drm_ippdrv_list);
103 static DEFINE_MUTEX(exynos_drm_ippdrv_lock);
104 static BLOCKING_NOTIFIER_HEAD(exynos_drm_ippnb_list);
106 int exynos_platform_device_ipp_register(void)
108 struct platform_device *pdev;
110 if (exynos_drm_ipp_pdev)
113 pdev = platform_device_register_simple("exynos-drm-ipp", -1, NULL, 0);
115 return PTR_ERR(pdev);
117 exynos_drm_ipp_pdev = pdev;
122 void exynos_platform_device_ipp_unregister(void)
124 if (exynos_drm_ipp_pdev) {
125 platform_device_unregister(exynos_drm_ipp_pdev);
126 exynos_drm_ipp_pdev = NULL;
130 int exynos_drm_ippdrv_register(struct exynos_drm_ippdrv *ippdrv)
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);
142 int exynos_drm_ippdrv_unregister(struct exynos_drm_ippdrv *ippdrv)
147 mutex_lock(&exynos_drm_ippdrv_lock);
148 list_del(&ippdrv->drv_list);
149 mutex_unlock(&exynos_drm_ippdrv_lock);
154 static int ipp_create_id(struct idr *id_idr, struct mutex *lock, void *obj,
159 /* do the allocation under our mutexlock */
161 ret = idr_alloc(id_idr, obj, 1, 0, GFP_KERNEL);
170 static void ipp_remove_id(struct idr *id_idr, struct mutex *lock, u32 id)
173 idr_remove(id_idr, id);
177 static void *ipp_find_obj(struct idr *id_idr, struct mutex *lock, u32 id)
181 DRM_DEBUG_KMS("id[%d]\n", id);
185 /* find object using handle */
186 obj = idr_find(id_idr, id);
188 DRM_ERROR("failed to find object.\n");
190 return ERR_PTR(-ENODEV);
198 static inline bool ipp_check_dedicated(struct exynos_drm_ippdrv *ippdrv,
199 enum drm_exynos_ipp_cmd cmd)
202 * check dedicated flag and WB, OUTPUT operation with
205 if (ippdrv->dedicated || (!ipp_is_m2m_cmd(cmd) &&
206 !pm_runtime_suspended(ippdrv->dev)))
212 static struct exynos_drm_ippdrv *ipp_find_driver(struct ipp_context *ctx,
213 struct drm_exynos_ipp_property *property)
215 struct exynos_drm_ippdrv *ippdrv;
216 u32 ipp_id = property->ipp_id;
218 DRM_DEBUG_KMS("ipp_id[%d]\n", ipp_id);
221 /* find ipp driver using idr */
222 ippdrv = ipp_find_obj(&ctx->ipp_idr, &ctx->ipp_lock,
224 if (IS_ERR(ippdrv)) {
225 DRM_ERROR("not found ipp%d driver.\n", ipp_id);
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.
234 if (ipp_check_dedicated(ippdrv, property->cmd)) {
235 DRM_ERROR("already used choose device.\n");
236 return ERR_PTR(-EBUSY);
240 * This is necessary to find correct device in ipp drivers.
241 * ipp drivers have different abilities,
242 * so need to check property.
244 if (ippdrv->check_property &&
245 ippdrv->check_property(ippdrv->dev, property)) {
246 DRM_ERROR("not support property.\n");
247 return ERR_PTR(-EINVAL);
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.
257 list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
258 if (ipp_check_dedicated(ippdrv, property->cmd)) {
259 DRM_DEBUG_KMS("used device.\n");
263 if (ippdrv->check_property &&
264 ippdrv->check_property(ippdrv->dev, property)) {
265 DRM_DEBUG_KMS("not support property.\n");
272 DRM_ERROR("not support ipp driver operations.\n");
275 return ERR_PTR(-ENODEV);
278 static struct exynos_drm_ippdrv *ipp_find_drv_by_handle(u32 prop_id)
280 struct exynos_drm_ippdrv *ippdrv;
281 struct drm_exynos_ipp_cmd_node *c_node;
284 DRM_DEBUG_KMS("prop_id[%d]\n", prop_id);
287 * This case is search ipp driver by prop_id handle.
288 * sometimes, ipp subsystem find driver by prop_id.
289 * e.g PAUSE state, queue buf, command control.
291 list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
292 DRM_DEBUG_KMS("count[%d]ippdrv[0x%x]\n", count++, (int)ippdrv);
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);
301 mutex_unlock(&ippdrv->cmd_lock);
304 return ERR_PTR(-ENODEV);
307 int exynos_drm_ipp_get_property(struct drm_device *drm_dev, void *data,
308 struct drm_file *file)
310 struct drm_exynos_file_private *file_priv = file->driver_priv;
311 struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
312 struct device *dev = priv->dev;
313 struct ipp_context *ctx = get_ipp_context(dev);
314 struct drm_exynos_ipp_prop_list *prop_list = data;
315 struct exynos_drm_ippdrv *ippdrv;
319 DRM_ERROR("invalid context.\n");
324 DRM_ERROR("invalid property parameter.\n");
328 DRM_DEBUG_KMS("ipp_id[%d]\n", prop_list->ipp_id);
330 if (!prop_list->ipp_id) {
331 list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list)
335 * Supports ippdrv list count for user application.
336 * First step user application getting ippdrv count.
337 * and second step getting ippdrv capability using ipp_id.
339 prop_list->count = count;
342 * Getting ippdrv capability by ipp_id.
343 * some device not supported wb, output interface.
344 * so, user application detect correct ipp driver
347 ippdrv = ipp_find_obj(&ctx->ipp_idr, &ctx->ipp_lock,
349 if (IS_ERR(ippdrv)) {
350 DRM_ERROR("not found ipp%d driver.\n",
352 return PTR_ERR(ippdrv);
355 *prop_list = ippdrv->prop_list;
361 static void ipp_print_property(struct drm_exynos_ipp_property *property,
364 struct drm_exynos_ipp_config *config = &property->config[idx];
365 struct drm_exynos_pos *pos = &config->pos;
366 struct drm_exynos_sz *sz = &config->sz;
368 DRM_DEBUG_KMS("prop_id[%d]ops[%s]fmt[0x%x]\n",
369 property->prop_id, idx ? "dst" : "src", config->fmt);
371 DRM_DEBUG_KMS("pos[%d %d %d %d]sz[%d %d]f[%d]r[%d]\n",
372 pos->x, pos->y, pos->w, pos->h,
373 sz->hsize, sz->vsize, config->flip, config->degree);
376 static int ipp_find_and_set_property(struct drm_exynos_ipp_property *property)
378 struct exynos_drm_ippdrv *ippdrv;
379 struct drm_exynos_ipp_cmd_node *c_node;
380 u32 prop_id = property->prop_id;
382 DRM_DEBUG_KMS("prop_id[%d]\n", prop_id);
384 ippdrv = ipp_find_drv_by_handle(prop_id);
385 if (IS_ERR(ippdrv)) {
386 DRM_ERROR("failed to get ipp driver.\n");
391 * Find command node using command list in ippdrv.
392 * when we find this command no using prop_id.
393 * return property information set in this command node.
395 mutex_lock(&ippdrv->cmd_lock);
396 list_for_each_entry(c_node, &ippdrv->cmd_list, list) {
397 if ((c_node->property.prop_id == prop_id) &&
398 (c_node->state == IPP_STATE_STOP)) {
399 mutex_unlock(&ippdrv->cmd_lock);
400 DRM_DEBUG_KMS("found cmd[%d]ippdrv[0x%x]\n",
401 property->cmd, (int)ippdrv);
403 c_node->property = *property;
407 mutex_unlock(&ippdrv->cmd_lock);
409 DRM_ERROR("failed to search property.\n");
414 static struct drm_exynos_ipp_cmd_work *ipp_create_cmd_work(void)
416 struct drm_exynos_ipp_cmd_work *cmd_work;
418 cmd_work = kzalloc(sizeof(*cmd_work), GFP_KERNEL);
420 return ERR_PTR(-ENOMEM);
422 INIT_WORK((struct work_struct *)cmd_work, ipp_sched_cmd);
427 static struct drm_exynos_ipp_event_work *ipp_create_event_work(void)
429 struct drm_exynos_ipp_event_work *event_work;
431 event_work = kzalloc(sizeof(*event_work), GFP_KERNEL);
433 return ERR_PTR(-ENOMEM);
435 INIT_WORK(&event_work->work, ipp_sched_event);
440 int exynos_drm_ipp_set_property(struct drm_device *drm_dev, void *data,
441 struct drm_file *file)
443 struct drm_exynos_file_private *file_priv = file->driver_priv;
444 struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
445 struct device *dev = priv->dev;
446 struct ipp_context *ctx = get_ipp_context(dev);
447 struct drm_exynos_ipp_property *property = data;
448 struct exynos_drm_ippdrv *ippdrv;
449 struct drm_exynos_ipp_cmd_node *c_node;
453 DRM_ERROR("invalid context.\n");
458 DRM_ERROR("invalid property parameter.\n");
463 * This is log print for user application property.
464 * user application set various property.
467 ipp_print_property(property, i);
470 * set property ioctl generated new prop_id.
471 * but in this case already asigned prop_id using old set property.
472 * e.g PAUSE state. this case supports find current prop_id and use it
473 * instead of allocation.
475 if (property->prop_id) {
476 DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id);
477 return ipp_find_and_set_property(property);
480 /* find ipp driver using ipp id */
481 ippdrv = ipp_find_driver(ctx, property);
482 if (IS_ERR(ippdrv)) {
483 DRM_ERROR("failed to get ipp driver.\n");
487 /* allocate command node */
488 c_node = kzalloc(sizeof(*c_node), GFP_KERNEL);
492 /* create property id */
493 ret = ipp_create_id(&ctx->prop_idr, &ctx->prop_lock, c_node,
496 DRM_ERROR("failed to create id.\n");
500 DRM_DEBUG_KMS("created prop_id[%d]cmd[%d]ippdrv[0x%x]\n",
501 property->prop_id, property->cmd, (int)ippdrv);
503 /* stored property information and ippdrv in private data */
505 c_node->property = *property;
506 c_node->state = IPP_STATE_IDLE;
508 c_node->start_work = ipp_create_cmd_work();
509 if (IS_ERR(c_node->start_work)) {
510 DRM_ERROR("failed to create start work.\n");
514 c_node->stop_work = ipp_create_cmd_work();
515 if (IS_ERR(c_node->stop_work)) {
516 DRM_ERROR("failed to create stop work.\n");
520 c_node->event_work = ipp_create_event_work();
521 if (IS_ERR(c_node->event_work)) {
522 DRM_ERROR("failed to create event work.\n");
526 mutex_init(&c_node->lock);
527 mutex_init(&c_node->mem_lock);
528 mutex_init(&c_node->event_lock);
530 init_completion(&c_node->start_complete);
531 init_completion(&c_node->stop_complete);
534 INIT_LIST_HEAD(&c_node->mem_list[i]);
536 INIT_LIST_HEAD(&c_node->event_list);
537 mutex_lock(&ippdrv->cmd_lock);
538 list_add_tail(&c_node->list, &ippdrv->cmd_list);
539 mutex_unlock(&ippdrv->cmd_lock);
541 /* make dedicated state without m2m */
542 if (!ipp_is_m2m_cmd(property->cmd))
543 ippdrv->dedicated = true;
548 kfree(c_node->stop_work);
550 kfree(c_node->start_work);
552 ipp_remove_id(&ctx->prop_idr, &ctx->prop_lock, property->prop_id);
558 static void ipp_clean_cmd_node(struct ipp_context *ctx,
559 struct drm_exynos_ipp_cmd_node *c_node)
562 list_del(&c_node->list);
564 ipp_remove_id(&ctx->prop_idr, &ctx->prop_lock,
565 c_node->property.prop_id);
568 mutex_destroy(&c_node->lock);
569 mutex_destroy(&c_node->mem_lock);
570 mutex_destroy(&c_node->event_lock);
572 /* free command node */
573 kfree(c_node->start_work);
574 kfree(c_node->stop_work);
575 kfree(c_node->event_work);
579 static int ipp_check_mem_list(struct drm_exynos_ipp_cmd_node *c_node)
581 struct drm_exynos_ipp_property *property = &c_node->property;
582 struct drm_exynos_ipp_mem_node *m_node;
583 struct list_head *head;
584 int ret, i, count[EXYNOS_DRM_OPS_MAX] = { 0, };
586 for_each_ipp_ops(i) {
587 /* source/destination memory list */
588 head = &c_node->mem_list[i];
590 /* find memory node entry */
591 list_for_each_entry(m_node, head, list) {
592 DRM_DEBUG_KMS("%s,count[%d]m_node[0x%x]\n",
593 i ? "dst" : "src", count[i], (int)m_node);
598 DRM_DEBUG_KMS("min[%d]max[%d]\n",
599 min(count[EXYNOS_DRM_OPS_SRC], count[EXYNOS_DRM_OPS_DST]),
600 max(count[EXYNOS_DRM_OPS_SRC], count[EXYNOS_DRM_OPS_DST]));
603 * M2M operations should be need paired memory address.
604 * so, need to check minimum count about src, dst.
605 * other case not use paired memory, so use maximum count
607 if (ipp_is_m2m_cmd(property->cmd))
608 ret = min(count[EXYNOS_DRM_OPS_SRC],
609 count[EXYNOS_DRM_OPS_DST]);
611 ret = max(count[EXYNOS_DRM_OPS_SRC],
612 count[EXYNOS_DRM_OPS_DST]);
617 static struct drm_exynos_ipp_mem_node
618 *ipp_find_mem_node(struct drm_exynos_ipp_cmd_node *c_node,
619 struct drm_exynos_ipp_queue_buf *qbuf)
621 struct drm_exynos_ipp_mem_node *m_node;
622 struct list_head *head;
625 DRM_DEBUG_KMS("buf_id[%d]\n", qbuf->buf_id);
627 /* source/destination memory list */
628 head = &c_node->mem_list[qbuf->ops_id];
630 /* find memory node from memory list */
631 list_for_each_entry(m_node, head, list) {
632 DRM_DEBUG_KMS("count[%d]m_node[0x%x]\n", count++, (int)m_node);
634 /* compare buffer id */
635 if (m_node->buf_id == qbuf->buf_id)
642 static int ipp_set_mem_node(struct exynos_drm_ippdrv *ippdrv,
643 struct drm_exynos_ipp_cmd_node *c_node,
644 struct drm_exynos_ipp_mem_node *m_node)
646 struct exynos_drm_ipp_ops *ops = NULL;
649 DRM_DEBUG_KMS("node[0x%x]\n", (int)m_node);
652 DRM_ERROR("invalid queue node.\n");
656 DRM_DEBUG_KMS("ops_id[%d]\n", m_node->ops_id);
658 /* get operations callback */
659 ops = ippdrv->ops[m_node->ops_id];
661 DRM_ERROR("not support ops.\n");
665 /* set address and enable irq */
667 ret = ops->set_addr(ippdrv->dev, &m_node->buf_info,
668 m_node->buf_id, IPP_BUF_ENQUEUE);
670 DRM_ERROR("failed to set addr.\n");
678 static struct drm_exynos_ipp_mem_node
679 *ipp_get_mem_node(struct drm_device *drm_dev,
680 struct drm_file *file,
681 struct drm_exynos_ipp_cmd_node *c_node,
682 struct drm_exynos_ipp_queue_buf *qbuf)
684 struct drm_exynos_ipp_mem_node *m_node;
685 struct drm_exynos_ipp_buf_info buf_info;
689 m_node = kzalloc(sizeof(*m_node), GFP_KERNEL);
691 return ERR_PTR(-ENOMEM);
693 /* clear base address for error handling */
694 memset(&buf_info, 0x0, sizeof(buf_info));
696 /* operations, buffer id */
697 m_node->ops_id = qbuf->ops_id;
698 m_node->prop_id = qbuf->prop_id;
699 m_node->buf_id = qbuf->buf_id;
701 DRM_DEBUG_KMS("m_node[0x%x]ops_id[%d]\n", (int)m_node, qbuf->ops_id);
702 DRM_DEBUG_KMS("prop_id[%d]buf_id[%d]\n", qbuf->prop_id, m_node->buf_id);
704 for_each_ipp_planar(i) {
705 DRM_DEBUG_KMS("i[%d]handle[0x%x]\n", i, qbuf->handle[i]);
707 /* get dma address by handle */
708 if (qbuf->handle[i]) {
709 addr = exynos_drm_gem_get_dma_addr(drm_dev,
710 qbuf->handle[i], file);
712 DRM_ERROR("failed to get addr.\n");
716 buf_info.handles[i] = qbuf->handle[i];
717 buf_info.base[i] = *(dma_addr_t *) addr;
718 DRM_DEBUG_KMS("i[%d]base[0x%x]hd[0x%x]\n",
719 i, buf_info.base[i], (int)buf_info.handles[i]);
724 m_node->buf_info = buf_info;
725 mutex_lock(&c_node->mem_lock);
726 list_add_tail(&m_node->list, &c_node->mem_list[qbuf->ops_id]);
727 mutex_unlock(&c_node->mem_lock);
733 return ERR_PTR(-EFAULT);
736 static int ipp_put_mem_node(struct drm_device *drm_dev,
737 struct drm_exynos_ipp_cmd_node *c_node,
738 struct drm_exynos_ipp_mem_node *m_node)
742 DRM_DEBUG_KMS("node[0x%x]\n", (int)m_node);
745 DRM_ERROR("invalid dequeue node.\n");
749 DRM_DEBUG_KMS("ops_id[%d]\n", m_node->ops_id);
752 for_each_ipp_planar(i) {
753 unsigned long handle = m_node->buf_info.handles[i];
755 exynos_drm_gem_put_dma_addr(drm_dev, handle,
759 /* delete list in queue */
760 list_del(&m_node->list);
766 static void ipp_free_event(struct drm_pending_event *event)
771 static int ipp_get_event(struct drm_device *drm_dev,
772 struct drm_file *file,
773 struct drm_exynos_ipp_cmd_node *c_node,
774 struct drm_exynos_ipp_queue_buf *qbuf)
776 struct drm_exynos_ipp_send_event *e;
779 DRM_DEBUG_KMS("ops_id[%d]buf_id[%d]\n", qbuf->ops_id, qbuf->buf_id);
781 e = kzalloc(sizeof(*e), GFP_KERNEL);
783 spin_lock_irqsave(&drm_dev->event_lock, flags);
784 file->event_space += sizeof(e->event);
785 spin_unlock_irqrestore(&drm_dev->event_lock, flags);
790 e->event.base.type = DRM_EXYNOS_IPP_EVENT;
791 e->event.base.length = sizeof(e->event);
792 e->event.user_data = qbuf->user_data;
793 e->event.prop_id = qbuf->prop_id;
794 e->event.buf_id[EXYNOS_DRM_OPS_DST] = qbuf->buf_id;
795 e->base.event = &e->event.base;
796 e->base.file_priv = file;
797 e->base.destroy = ipp_free_event;
798 mutex_lock(&c_node->event_lock);
799 list_add_tail(&e->base.link, &c_node->event_list);
800 mutex_unlock(&c_node->event_lock);
805 static void ipp_put_event(struct drm_exynos_ipp_cmd_node *c_node,
806 struct drm_exynos_ipp_queue_buf *qbuf)
808 struct drm_exynos_ipp_send_event *e, *te;
811 mutex_lock(&c_node->event_lock);
812 list_for_each_entry_safe(e, te, &c_node->event_list, base.link) {
813 DRM_DEBUG_KMS("count[%d]e[0x%x]\n", count++, (int)e);
816 * qbuf == NULL condition means all event deletion.
817 * stop operations want to delete all event list.
818 * another case delete only same buf id.
822 list_del(&e->base.link);
826 /* compare buffer id */
827 if (qbuf && (qbuf->buf_id ==
828 e->event.buf_id[EXYNOS_DRM_OPS_DST])) {
830 list_del(&e->base.link);
837 mutex_unlock(&c_node->event_lock);
841 static void ipp_handle_cmd_work(struct device *dev,
842 struct exynos_drm_ippdrv *ippdrv,
843 struct drm_exynos_ipp_cmd_work *cmd_work,
844 struct drm_exynos_ipp_cmd_node *c_node)
846 struct ipp_context *ctx = get_ipp_context(dev);
848 cmd_work->ippdrv = ippdrv;
849 cmd_work->c_node = c_node;
850 queue_work(ctx->cmd_workq, (struct work_struct *)cmd_work);
853 static int ipp_queue_buf_with_run(struct device *dev,
854 struct drm_exynos_ipp_cmd_node *c_node,
855 struct drm_exynos_ipp_mem_node *m_node,
856 struct drm_exynos_ipp_queue_buf *qbuf)
858 struct exynos_drm_ippdrv *ippdrv;
859 struct drm_exynos_ipp_property *property;
860 struct exynos_drm_ipp_ops *ops;
863 ippdrv = ipp_find_drv_by_handle(qbuf->prop_id);
864 if (IS_ERR(ippdrv)) {
865 DRM_ERROR("failed to get ipp driver.\n");
869 ops = ippdrv->ops[qbuf->ops_id];
871 DRM_ERROR("failed to get ops.\n");
875 property = &c_node->property;
877 if (c_node->state != IPP_STATE_START) {
878 DRM_DEBUG_KMS("bypass for invalid state.\n");
882 mutex_lock(&c_node->mem_lock);
883 if (!ipp_check_mem_list(c_node)) {
884 mutex_unlock(&c_node->mem_lock);
885 DRM_DEBUG_KMS("empty memory.\n");
890 * If set destination buffer and enabled clock,
891 * then m2m operations need start operations at queue_buf
893 if (ipp_is_m2m_cmd(property->cmd)) {
894 struct drm_exynos_ipp_cmd_work *cmd_work = c_node->start_work;
896 cmd_work->ctrl = IPP_CTRL_PLAY;
897 ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
899 ret = ipp_set_mem_node(ippdrv, c_node, m_node);
901 mutex_unlock(&c_node->mem_lock);
902 DRM_ERROR("failed to set m node.\n");
906 mutex_unlock(&c_node->mem_lock);
911 static void ipp_clean_queue_buf(struct drm_device *drm_dev,
912 struct drm_exynos_ipp_cmd_node *c_node,
913 struct drm_exynos_ipp_queue_buf *qbuf)
915 struct drm_exynos_ipp_mem_node *m_node, *tm_node;
918 mutex_lock(&c_node->mem_lock);
919 list_for_each_entry_safe(m_node, tm_node,
920 &c_node->mem_list[qbuf->ops_id], list) {
921 if (m_node->buf_id == qbuf->buf_id &&
922 m_node->ops_id == qbuf->ops_id)
923 ipp_put_mem_node(drm_dev, c_node, m_node);
925 mutex_unlock(&c_node->mem_lock);
928 int exynos_drm_ipp_queue_buf(struct drm_device *drm_dev, void *data,
929 struct drm_file *file)
931 struct drm_exynos_file_private *file_priv = file->driver_priv;
932 struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
933 struct device *dev = priv->dev;
934 struct ipp_context *ctx = get_ipp_context(dev);
935 struct drm_exynos_ipp_queue_buf *qbuf = data;
936 struct drm_exynos_ipp_cmd_node *c_node;
937 struct drm_exynos_ipp_mem_node *m_node;
941 DRM_ERROR("invalid buf parameter.\n");
945 if (qbuf->ops_id >= EXYNOS_DRM_OPS_MAX) {
946 DRM_ERROR("invalid ops parameter.\n");
950 DRM_DEBUG_KMS("prop_id[%d]ops_id[%s]buf_id[%d]buf_type[%d]\n",
951 qbuf->prop_id, qbuf->ops_id ? "dst" : "src",
952 qbuf->buf_id, qbuf->buf_type);
954 /* find command node */
955 c_node = ipp_find_obj(&ctx->prop_idr, &ctx->prop_lock,
957 if (IS_ERR(c_node)) {
958 DRM_ERROR("failed to get command node.\n");
959 return PTR_ERR(c_node);
963 switch (qbuf->buf_type) {
964 case IPP_BUF_ENQUEUE:
965 /* get memory node */
966 m_node = ipp_get_mem_node(drm_dev, file, c_node, qbuf);
967 if (IS_ERR(m_node)) {
968 DRM_ERROR("failed to get m_node.\n");
969 return PTR_ERR(m_node);
973 * first step get event for destination buffer.
974 * and second step when M2M case run with destination buffer
977 if (qbuf->ops_id == EXYNOS_DRM_OPS_DST) {
978 /* get event for destination buffer */
979 ret = ipp_get_event(drm_dev, file, c_node, qbuf);
981 DRM_ERROR("failed to get event.\n");
986 * M2M case run play control for streaming feature.
987 * other case set address and waiting.
989 ret = ipp_queue_buf_with_run(dev, c_node, m_node, qbuf);
991 DRM_ERROR("failed to run command.\n");
996 case IPP_BUF_DEQUEUE:
997 mutex_lock(&c_node->lock);
999 /* put event for destination buffer */
1000 if (qbuf->ops_id == EXYNOS_DRM_OPS_DST)
1001 ipp_put_event(c_node, qbuf);
1003 ipp_clean_queue_buf(drm_dev, c_node, qbuf);
1005 mutex_unlock(&c_node->lock);
1008 DRM_ERROR("invalid buffer control.\n");
1015 DRM_ERROR("clean memory nodes.\n");
1017 ipp_clean_queue_buf(drm_dev, c_node, qbuf);
1021 static bool exynos_drm_ipp_check_valid(struct device *dev,
1022 enum drm_exynos_ipp_ctrl ctrl, enum drm_exynos_ipp_state state)
1024 if (ctrl != IPP_CTRL_PLAY) {
1025 if (pm_runtime_suspended(dev)) {
1026 DRM_ERROR("pm:runtime_suspended.\n");
1033 if (state != IPP_STATE_IDLE)
1037 if (state == IPP_STATE_STOP)
1040 case IPP_CTRL_PAUSE:
1041 if (state != IPP_STATE_START)
1044 case IPP_CTRL_RESUME:
1045 if (state != IPP_STATE_STOP)
1049 DRM_ERROR("invalid state.\n");
1056 DRM_ERROR("invalid status:ctrl[%d]state[%d]\n", ctrl, state);
1060 int exynos_drm_ipp_cmd_ctrl(struct drm_device *drm_dev, void *data,
1061 struct drm_file *file)
1063 struct drm_exynos_file_private *file_priv = file->driver_priv;
1064 struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
1065 struct exynos_drm_ippdrv *ippdrv = NULL;
1066 struct device *dev = priv->dev;
1067 struct ipp_context *ctx = get_ipp_context(dev);
1068 struct drm_exynos_ipp_cmd_ctrl *cmd_ctrl = data;
1069 struct drm_exynos_ipp_cmd_work *cmd_work;
1070 struct drm_exynos_ipp_cmd_node *c_node;
1073 DRM_ERROR("invalid context.\n");
1078 DRM_ERROR("invalid control parameter.\n");
1082 DRM_DEBUG_KMS("ctrl[%d]prop_id[%d]\n",
1083 cmd_ctrl->ctrl, cmd_ctrl->prop_id);
1085 ippdrv = ipp_find_drv_by_handle(cmd_ctrl->prop_id);
1086 if (IS_ERR(ippdrv)) {
1087 DRM_ERROR("failed to get ipp driver.\n");
1088 return PTR_ERR(ippdrv);
1091 c_node = ipp_find_obj(&ctx->prop_idr, &ctx->prop_lock,
1093 if (IS_ERR(c_node)) {
1094 DRM_ERROR("invalid command node list.\n");
1095 return PTR_ERR(c_node);
1098 if (!exynos_drm_ipp_check_valid(ippdrv->dev, cmd_ctrl->ctrl,
1100 DRM_ERROR("invalid state.\n");
1104 switch (cmd_ctrl->ctrl) {
1106 if (pm_runtime_suspended(ippdrv->dev))
1107 pm_runtime_get_sync(ippdrv->dev);
1109 c_node->state = IPP_STATE_START;
1111 cmd_work = c_node->start_work;
1112 cmd_work->ctrl = cmd_ctrl->ctrl;
1113 ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
1116 cmd_work = c_node->stop_work;
1117 cmd_work->ctrl = cmd_ctrl->ctrl;
1118 ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
1120 if (!wait_for_completion_timeout(&c_node->stop_complete,
1121 msecs_to_jiffies(300))) {
1122 DRM_ERROR("timeout stop:prop_id[%d]\n",
1123 c_node->property.prop_id);
1126 c_node->state = IPP_STATE_STOP;
1127 ippdrv->dedicated = false;
1128 mutex_lock(&ippdrv->cmd_lock);
1129 ipp_clean_cmd_node(ctx, c_node);
1131 if (list_empty(&ippdrv->cmd_list))
1132 pm_runtime_put_sync(ippdrv->dev);
1133 mutex_unlock(&ippdrv->cmd_lock);
1135 case IPP_CTRL_PAUSE:
1136 cmd_work = c_node->stop_work;
1137 cmd_work->ctrl = cmd_ctrl->ctrl;
1138 ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
1140 if (!wait_for_completion_timeout(&c_node->stop_complete,
1141 msecs_to_jiffies(200))) {
1142 DRM_ERROR("timeout stop:prop_id[%d]\n",
1143 c_node->property.prop_id);
1146 c_node->state = IPP_STATE_STOP;
1148 case IPP_CTRL_RESUME:
1149 c_node->state = IPP_STATE_START;
1150 cmd_work = c_node->start_work;
1151 cmd_work->ctrl = cmd_ctrl->ctrl;
1152 ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node);
1155 DRM_ERROR("could not support this state currently.\n");
1159 DRM_DEBUG_KMS("done ctrl[%d]prop_id[%d]\n",
1160 cmd_ctrl->ctrl, cmd_ctrl->prop_id);
1165 int exynos_drm_ippnb_register(struct notifier_block *nb)
1167 return blocking_notifier_chain_register(
1168 &exynos_drm_ippnb_list, nb);
1171 int exynos_drm_ippnb_unregister(struct notifier_block *nb)
1173 return blocking_notifier_chain_unregister(
1174 &exynos_drm_ippnb_list, nb);
1177 int exynos_drm_ippnb_send_event(unsigned long val, void *v)
1179 return blocking_notifier_call_chain(
1180 &exynos_drm_ippnb_list, val, v);
1183 static int ipp_set_property(struct exynos_drm_ippdrv *ippdrv,
1184 struct drm_exynos_ipp_property *property)
1186 struct exynos_drm_ipp_ops *ops = NULL;
1191 DRM_ERROR("invalid property parameter.\n");
1195 DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id);
1197 /* reset h/w block */
1198 if (ippdrv->reset &&
1199 ippdrv->reset(ippdrv->dev)) {
1200 DRM_ERROR("failed to reset.\n");
1204 /* set source,destination operations */
1205 for_each_ipp_ops(i) {
1206 struct drm_exynos_ipp_config *config =
1207 &property->config[i];
1209 ops = ippdrv->ops[i];
1210 if (!ops || !config) {
1211 DRM_ERROR("not support ops and config.\n");
1217 ret = ops->set_fmt(ippdrv->dev, config->fmt);
1219 DRM_ERROR("not support format.\n");
1224 /* set transform for rotation, flip */
1225 if (ops->set_transf) {
1226 ret = ops->set_transf(ippdrv->dev, config->degree,
1227 config->flip, &swap);
1229 DRM_ERROR("not support tranf.\n");
1235 if (ops->set_size) {
1236 ret = ops->set_size(ippdrv->dev, swap, &config->pos,
1239 DRM_ERROR("not support size.\n");
1248 static int ipp_start_property(struct exynos_drm_ippdrv *ippdrv,
1249 struct drm_exynos_ipp_cmd_node *c_node)
1251 struct drm_exynos_ipp_mem_node *m_node;
1252 struct drm_exynos_ipp_property *property = &c_node->property;
1253 struct list_head *head;
1256 DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id);
1258 /* store command info in ippdrv */
1259 ippdrv->c_node = c_node;
1261 mutex_lock(&c_node->mem_lock);
1262 if (!ipp_check_mem_list(c_node)) {
1263 DRM_DEBUG_KMS("empty memory.\n");
1268 /* set current property in ippdrv */
1269 ret = ipp_set_property(ippdrv, property);
1271 DRM_ERROR("failed to set property.\n");
1272 ippdrv->c_node = NULL;
1277 switch (property->cmd) {
1279 for_each_ipp_ops(i) {
1280 /* source/destination memory list */
1281 head = &c_node->mem_list[i];
1283 m_node = list_first_entry(head,
1284 struct drm_exynos_ipp_mem_node, list);
1286 DRM_ERROR("failed to get node.\n");
1291 DRM_DEBUG_KMS("m_node[0x%x]\n", (int)m_node);
1293 ret = ipp_set_mem_node(ippdrv, c_node, m_node);
1295 DRM_ERROR("failed to set m node.\n");
1301 /* destination memory list */
1302 head = &c_node->mem_list[EXYNOS_DRM_OPS_DST];
1304 list_for_each_entry(m_node, head, list) {
1305 ret = ipp_set_mem_node(ippdrv, c_node, m_node);
1307 DRM_ERROR("failed to set m node.\n");
1312 case IPP_CMD_OUTPUT:
1313 /* source memory list */
1314 head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC];
1316 list_for_each_entry(m_node, head, list) {
1317 ret = ipp_set_mem_node(ippdrv, c_node, m_node);
1319 DRM_ERROR("failed to set m node.\n");
1325 DRM_ERROR("invalid operations.\n");
1329 mutex_unlock(&c_node->mem_lock);
1331 DRM_DEBUG_KMS("cmd[%d]\n", property->cmd);
1333 /* start operations */
1334 if (ippdrv->start) {
1335 ret = ippdrv->start(ippdrv->dev, property->cmd);
1337 DRM_ERROR("failed to start ops.\n");
1338 ippdrv->c_node = NULL;
1346 mutex_unlock(&c_node->mem_lock);
1347 ippdrv->c_node = NULL;
1351 static int ipp_stop_property(struct drm_device *drm_dev,
1352 struct exynos_drm_ippdrv *ippdrv,
1353 struct drm_exynos_ipp_cmd_node *c_node)
1355 struct drm_exynos_ipp_mem_node *m_node, *tm_node;
1356 struct drm_exynos_ipp_property *property = &c_node->property;
1357 struct list_head *head;
1360 DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id);
1363 ipp_put_event(c_node, NULL);
1365 mutex_lock(&c_node->mem_lock);
1368 switch (property->cmd) {
1370 for_each_ipp_ops(i) {
1371 /* source/destination memory list */
1372 head = &c_node->mem_list[i];
1374 list_for_each_entry_safe(m_node, tm_node,
1376 ret = ipp_put_mem_node(drm_dev, c_node,
1379 DRM_ERROR("failed to put m_node.\n");
1386 /* destination memory list */
1387 head = &c_node->mem_list[EXYNOS_DRM_OPS_DST];
1389 list_for_each_entry_safe(m_node, tm_node, head, list) {
1390 ret = ipp_put_mem_node(drm_dev, c_node, m_node);
1392 DRM_ERROR("failed to put m_node.\n");
1397 case IPP_CMD_OUTPUT:
1398 /* source memory list */
1399 head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC];
1401 list_for_each_entry_safe(m_node, tm_node, head, list) {
1402 ret = ipp_put_mem_node(drm_dev, c_node, m_node);
1404 DRM_ERROR("failed to put m_node.\n");
1410 DRM_ERROR("invalid operations.\n");
1416 mutex_unlock(&c_node->mem_lock);
1418 /* stop operations */
1420 ippdrv->stop(ippdrv->dev, property->cmd);
1425 void ipp_sched_cmd(struct work_struct *work)
1427 struct drm_exynos_ipp_cmd_work *cmd_work =
1428 (struct drm_exynos_ipp_cmd_work *)work;
1429 struct exynos_drm_ippdrv *ippdrv;
1430 struct drm_exynos_ipp_cmd_node *c_node;
1431 struct drm_exynos_ipp_property *property;
1434 ippdrv = cmd_work->ippdrv;
1436 DRM_ERROR("invalid ippdrv list.\n");
1440 c_node = cmd_work->c_node;
1442 DRM_ERROR("invalid command node list.\n");
1446 mutex_lock(&c_node->lock);
1448 property = &c_node->property;
1450 switch (cmd_work->ctrl) {
1452 case IPP_CTRL_RESUME:
1453 ret = ipp_start_property(ippdrv, c_node);
1455 DRM_ERROR("failed to start property:prop_id[%d]\n",
1456 c_node->property.prop_id);
1461 * M2M case supports wait_completion of transfer.
1462 * because M2M case supports single unit operation
1463 * with multiple queue.
1464 * M2M need to wait completion of data transfer.
1466 if (ipp_is_m2m_cmd(property->cmd)) {
1467 if (!wait_for_completion_timeout
1468 (&c_node->start_complete, msecs_to_jiffies(200))) {
1469 DRM_ERROR("timeout event:prop_id[%d]\n",
1470 c_node->property.prop_id);
1476 case IPP_CTRL_PAUSE:
1477 ret = ipp_stop_property(ippdrv->drm_dev, ippdrv,
1480 DRM_ERROR("failed to stop property.\n");
1484 complete(&c_node->stop_complete);
1487 DRM_ERROR("unknown control type\n");
1491 DRM_DEBUG_KMS("ctrl[%d] done.\n", cmd_work->ctrl);
1494 mutex_unlock(&c_node->lock);
1497 static int ipp_send_event(struct exynos_drm_ippdrv *ippdrv,
1498 struct drm_exynos_ipp_cmd_node *c_node, int *buf_id)
1500 struct drm_device *drm_dev = ippdrv->drm_dev;
1501 struct drm_exynos_ipp_property *property = &c_node->property;
1502 struct drm_exynos_ipp_mem_node *m_node;
1503 struct drm_exynos_ipp_queue_buf qbuf;
1504 struct drm_exynos_ipp_send_event *e;
1505 struct list_head *head;
1507 unsigned long flags;
1508 u32 tbuf_id[EXYNOS_DRM_OPS_MAX] = {0, };
1512 DRM_DEBUG_KMS("%s buf_id[%d]\n", i ? "dst" : "src", buf_id[i]);
1515 DRM_ERROR("failed to get drm_dev.\n");
1520 DRM_ERROR("failed to get property.\n");
1524 mutex_lock(&c_node->event_lock);
1525 if (list_empty(&c_node->event_list)) {
1526 DRM_DEBUG_KMS("event list is empty.\n");
1528 goto err_event_unlock;
1531 mutex_lock(&c_node->mem_lock);
1532 if (!ipp_check_mem_list(c_node)) {
1533 DRM_DEBUG_KMS("empty memory.\n");
1535 goto err_mem_unlock;
1539 switch (property->cmd) {
1541 for_each_ipp_ops(i) {
1542 /* source/destination memory list */
1543 head = &c_node->mem_list[i];
1545 m_node = list_first_entry(head,
1546 struct drm_exynos_ipp_mem_node, list);
1548 DRM_ERROR("empty memory node.\n");
1550 goto err_mem_unlock;
1553 tbuf_id[i] = m_node->buf_id;
1554 DRM_DEBUG_KMS("%s buf_id[%d]\n",
1555 i ? "dst" : "src", tbuf_id[i]);
1557 ret = ipp_put_mem_node(drm_dev, c_node, m_node);
1559 DRM_ERROR("failed to put m_node.\n");
1563 /* clear buf for finding */
1564 memset(&qbuf, 0x0, sizeof(qbuf));
1565 qbuf.ops_id = EXYNOS_DRM_OPS_DST;
1566 qbuf.buf_id = buf_id[EXYNOS_DRM_OPS_DST];
1568 /* get memory node entry */
1569 m_node = ipp_find_mem_node(c_node, &qbuf);
1571 DRM_ERROR("empty memory node.\n");
1573 goto err_mem_unlock;
1576 tbuf_id[EXYNOS_DRM_OPS_DST] = m_node->buf_id;
1578 ret = ipp_put_mem_node(drm_dev, c_node, m_node);
1580 DRM_ERROR("failed to put m_node.\n");
1582 case IPP_CMD_OUTPUT:
1583 /* source memory list */
1584 head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC];
1586 m_node = list_first_entry(head,
1587 struct drm_exynos_ipp_mem_node, list);
1589 DRM_ERROR("empty memory node.\n");
1591 goto err_mem_unlock;
1594 tbuf_id[EXYNOS_DRM_OPS_SRC] = m_node->buf_id;
1596 ret = ipp_put_mem_node(drm_dev, c_node, m_node);
1598 DRM_ERROR("failed to put m_node.\n");
1601 DRM_ERROR("invalid operations.\n");
1603 goto err_mem_unlock;
1605 mutex_unlock(&c_node->mem_lock);
1607 if (tbuf_id[EXYNOS_DRM_OPS_DST] != buf_id[EXYNOS_DRM_OPS_DST])
1608 DRM_ERROR("failed to match buf_id[%d %d]prop_id[%d]\n",
1609 tbuf_id[1], buf_id[1], property->prop_id);
1612 * command node have event list of destination buffer
1613 * If destination buffer enqueue to mem list,
1614 * then we make event and link to event list tail.
1615 * so, we get first event for first enqueued buffer.
1617 e = list_first_entry(&c_node->event_list,
1618 struct drm_exynos_ipp_send_event, base.link);
1620 do_gettimeofday(&now);
1621 DRM_DEBUG_KMS("tv_sec[%ld]tv_usec[%ld]\n", now.tv_sec, now.tv_usec);
1622 e->event.tv_sec = now.tv_sec;
1623 e->event.tv_usec = now.tv_usec;
1624 e->event.prop_id = property->prop_id;
1626 /* set buffer id about source destination */
1628 e->event.buf_id[i] = tbuf_id[i];
1630 spin_lock_irqsave(&drm_dev->event_lock, flags);
1631 list_move_tail(&e->base.link, &e->base.file_priv->event_list);
1632 wake_up_interruptible(&e->base.file_priv->event_wait);
1633 spin_unlock_irqrestore(&drm_dev->event_lock, flags);
1634 mutex_unlock(&c_node->event_lock);
1636 DRM_DEBUG_KMS("done cmd[%d]prop_id[%d]buf_id[%d]\n",
1637 property->cmd, property->prop_id, tbuf_id[EXYNOS_DRM_OPS_DST]);
1642 mutex_unlock(&c_node->mem_lock);
1644 mutex_unlock(&c_node->event_lock);
1648 void ipp_sched_event(struct work_struct *work)
1650 struct drm_exynos_ipp_event_work *event_work =
1651 (struct drm_exynos_ipp_event_work *)work;
1652 struct exynos_drm_ippdrv *ippdrv;
1653 struct drm_exynos_ipp_cmd_node *c_node;
1657 DRM_ERROR("failed to get event_work.\n");
1661 DRM_DEBUG_KMS("buf_id[%d]\n", event_work->buf_id[EXYNOS_DRM_OPS_DST]);
1663 ippdrv = event_work->ippdrv;
1665 DRM_ERROR("failed to get ipp driver.\n");
1669 c_node = ippdrv->c_node;
1671 DRM_ERROR("failed to get command node.\n");
1676 * IPP supports command thread, event thread synchronization.
1677 * If IPP close immediately from user land, then IPP make
1678 * synchronization with command thread, so make complete event.
1679 * or going out operations.
1681 if (c_node->state != IPP_STATE_START) {
1682 DRM_DEBUG_KMS("bypass state[%d]prop_id[%d]\n",
1683 c_node->state, c_node->property.prop_id);
1684 goto err_completion;
1687 ret = ipp_send_event(ippdrv, c_node, event_work->buf_id);
1689 DRM_ERROR("failed to send event.\n");
1690 goto err_completion;
1694 if (ipp_is_m2m_cmd(c_node->property.cmd))
1695 complete(&c_node->start_complete);
1698 static int ipp_subdrv_probe(struct drm_device *drm_dev, struct device *dev)
1700 struct ipp_context *ctx = get_ipp_context(dev);
1701 struct exynos_drm_ippdrv *ippdrv;
1704 /* get ipp driver entry */
1705 list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
1708 ippdrv->drm_dev = drm_dev;
1710 ret = ipp_create_id(&ctx->ipp_idr, &ctx->ipp_lock, ippdrv,
1712 if (ret || ipp_id == 0) {
1713 DRM_ERROR("failed to create id.\n");
1717 DRM_DEBUG_KMS("count[%d]ippdrv[0x%x]ipp_id[%d]\n",
1718 count++, (int)ippdrv, ipp_id);
1720 ippdrv->prop_list.ipp_id = ipp_id;
1722 /* store parent device for node */
1723 ippdrv->parent_dev = dev;
1725 /* store event work queue and handler */
1726 ippdrv->event_workq = ctx->event_workq;
1727 ippdrv->sched_event = ipp_sched_event;
1728 INIT_LIST_HEAD(&ippdrv->cmd_list);
1729 mutex_init(&ippdrv->cmd_lock);
1731 if (is_drm_iommu_supported(drm_dev)) {
1732 ret = drm_iommu_attach_device(drm_dev, ippdrv->dev);
1734 DRM_ERROR("failed to activate iommu\n");
1743 /* get ipp driver entry */
1744 list_for_each_entry_continue_reverse(ippdrv, &exynos_drm_ippdrv_list,
1746 if (is_drm_iommu_supported(drm_dev))
1747 drm_iommu_detach_device(drm_dev, ippdrv->dev);
1749 ipp_remove_id(&ctx->ipp_idr, &ctx->ipp_lock,
1750 ippdrv->prop_list.ipp_id);
1756 static void ipp_subdrv_remove(struct drm_device *drm_dev, struct device *dev)
1758 struct exynos_drm_ippdrv *ippdrv;
1759 struct ipp_context *ctx = get_ipp_context(dev);
1761 /* get ipp driver entry */
1762 list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
1763 if (is_drm_iommu_supported(drm_dev))
1764 drm_iommu_detach_device(drm_dev, ippdrv->dev);
1766 ipp_remove_id(&ctx->ipp_idr, &ctx->ipp_lock,
1767 ippdrv->prop_list.ipp_id);
1769 ippdrv->drm_dev = NULL;
1770 exynos_drm_ippdrv_unregister(ippdrv);
1774 static int ipp_subdrv_open(struct drm_device *drm_dev, struct device *dev,
1775 struct drm_file *file)
1777 struct drm_exynos_file_private *file_priv = file->driver_priv;
1778 struct exynos_drm_ipp_private *priv;
1780 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1784 file_priv->ipp_priv = priv;
1787 DRM_DEBUG_KMS("done priv[0x%x]\n", (int)priv);
1792 static void ipp_subdrv_close(struct drm_device *drm_dev, struct device *dev,
1793 struct drm_file *file)
1795 struct drm_exynos_file_private *file_priv = file->driver_priv;
1796 struct exynos_drm_ipp_private *priv = file_priv->ipp_priv;
1797 struct exynos_drm_ippdrv *ippdrv = NULL;
1798 struct ipp_context *ctx = get_ipp_context(dev);
1799 struct drm_exynos_ipp_cmd_node *c_node, *tc_node;
1802 DRM_DEBUG_KMS("for priv[0x%x]\n", (int)priv);
1804 list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) {
1805 mutex_lock(&ippdrv->cmd_lock);
1806 list_for_each_entry_safe(c_node, tc_node,
1807 &ippdrv->cmd_list, list) {
1808 DRM_DEBUG_KMS("count[%d]ippdrv[0x%x]\n",
1809 count++, (int)ippdrv);
1811 if (c_node->priv == priv) {
1813 * userland goto unnormal state. process killed.
1814 * and close the file.
1815 * so, IPP didn't called stop cmd ctrl.
1816 * so, we are make stop operation in this state.
1818 if (c_node->state == IPP_STATE_START) {
1819 ipp_stop_property(drm_dev, ippdrv,
1821 c_node->state = IPP_STATE_STOP;
1824 ippdrv->dedicated = false;
1825 ipp_clean_cmd_node(ctx, c_node);
1826 if (list_empty(&ippdrv->cmd_list))
1827 pm_runtime_put_sync(ippdrv->dev);
1830 mutex_unlock(&ippdrv->cmd_lock);
1837 static int ipp_probe(struct platform_device *pdev)
1839 struct device *dev = &pdev->dev;
1840 struct ipp_context *ctx;
1841 struct exynos_drm_subdrv *subdrv;
1844 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
1848 mutex_init(&ctx->ipp_lock);
1849 mutex_init(&ctx->prop_lock);
1851 idr_init(&ctx->ipp_idr);
1852 idr_init(&ctx->prop_idr);
1855 * create single thread for ipp event
1856 * IPP supports event thread for IPP drivers.
1857 * IPP driver send event_work to this thread.
1858 * and IPP event thread send event to user process.
1860 ctx->event_workq = create_singlethread_workqueue("ipp_event");
1861 if (!ctx->event_workq) {
1862 dev_err(dev, "failed to create event workqueue\n");
1867 * create single thread for ipp command
1868 * IPP supports command thread for user process.
1869 * user process make command node using set property ioctl.
1870 * and make start_work and send this work to command thread.
1871 * and then this command thread start property.
1873 ctx->cmd_workq = create_singlethread_workqueue("ipp_cmd");
1874 if (!ctx->cmd_workq) {
1875 dev_err(dev, "failed to create cmd workqueue\n");
1877 goto err_event_workq;
1880 /* set sub driver informations */
1881 subdrv = &ctx->subdrv;
1883 subdrv->probe = ipp_subdrv_probe;
1884 subdrv->remove = ipp_subdrv_remove;
1885 subdrv->open = ipp_subdrv_open;
1886 subdrv->close = ipp_subdrv_close;
1888 platform_set_drvdata(pdev, ctx);
1890 ret = exynos_drm_subdrv_register(subdrv);
1892 DRM_ERROR("failed to register drm ipp device.\n");
1896 dev_info(dev, "drm ipp registered successfully.\n");
1901 destroy_workqueue(ctx->cmd_workq);
1903 destroy_workqueue(ctx->event_workq);
1907 static int ipp_remove(struct platform_device *pdev)
1909 struct ipp_context *ctx = platform_get_drvdata(pdev);
1911 /* unregister sub driver */
1912 exynos_drm_subdrv_unregister(&ctx->subdrv);
1914 /* remove,destroy ipp idr */
1915 idr_destroy(&ctx->ipp_idr);
1916 idr_destroy(&ctx->prop_idr);
1918 mutex_destroy(&ctx->ipp_lock);
1919 mutex_destroy(&ctx->prop_lock);
1921 /* destroy command, event work queue */
1922 destroy_workqueue(ctx->cmd_workq);
1923 destroy_workqueue(ctx->event_workq);
1928 static int ipp_power_ctrl(struct ipp_context *ctx, bool enable)
1930 DRM_DEBUG_KMS("enable[%d]\n", enable);
1935 #ifdef CONFIG_PM_SLEEP
1936 static int ipp_suspend(struct device *dev)
1938 struct ipp_context *ctx = get_ipp_context(dev);
1940 if (pm_runtime_suspended(dev))
1943 return ipp_power_ctrl(ctx, false);
1946 static int ipp_resume(struct device *dev)
1948 struct ipp_context *ctx = get_ipp_context(dev);
1950 if (!pm_runtime_suspended(dev))
1951 return ipp_power_ctrl(ctx, true);
1957 #ifdef CONFIG_PM_RUNTIME
1958 static int ipp_runtime_suspend(struct device *dev)
1960 struct ipp_context *ctx = get_ipp_context(dev);
1962 return ipp_power_ctrl(ctx, false);
1965 static int ipp_runtime_resume(struct device *dev)
1967 struct ipp_context *ctx = get_ipp_context(dev);
1969 return ipp_power_ctrl(ctx, true);
1973 static const struct dev_pm_ops ipp_pm_ops = {
1974 SET_SYSTEM_SLEEP_PM_OPS(ipp_suspend, ipp_resume)
1975 SET_RUNTIME_PM_OPS(ipp_runtime_suspend, ipp_runtime_resume, NULL)
1978 struct platform_driver ipp_driver = {
1980 .remove = ipp_remove,
1982 .name = "exynos-drm-ipp",
1983 .owner = THIS_MODULE,