2 * Copyright (C) 2017 Samsung Electronics Co.Ltd
6 * Exynos DRM Image Post Processing (IPP) related functions
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
19 #include <linux/uaccess.h>
21 #include <drm/drm_blend.h>
22 #include <drm/drm_file.h>
23 #include <drm/drm_fourcc.h>
24 #include <drm/drm_mode.h>
25 #include <drm/exynos_drm.h>
27 #include "exynos_drm_drv.h"
28 #include "exynos_drm_gem.h"
29 #include "exynos_drm_ipp.h"
32 static LIST_HEAD(ipp_list);
35 * exynos_drm_ipp_register - Register a new picture processor hardware module
37 * @ipp: ipp module to init
38 * @funcs: callbacks for the new ipp object
39 * @caps: bitmask of ipp capabilities (%DRM_EXYNOS_IPP_CAP_*)
40 * @formats: array of supported formats
41 * @num_formats: size of the supported formats array
42 * @name: name (for debugging purposes)
44 * Initializes a ipp module.
47 * Zero on success, error code on failure.
49 int exynos_drm_ipp_register(struct device *dev, struct exynos_drm_ipp *ipp,
50 const struct exynos_drm_ipp_funcs *funcs, unsigned int caps,
51 const struct exynos_drm_ipp_formats *formats,
52 unsigned int num_formats, const char *name)
57 WARN_ON(!num_formats);
59 spin_lock_init(&ipp->lock);
60 INIT_LIST_HEAD(&ipp->todo_list);
61 init_waitqueue_head(&ipp->done_wq);
64 ipp->capabilities = caps;
66 ipp->formats = formats;
67 ipp->num_formats = num_formats;
69 /* ipp_list modification is serialized by component framework */
70 list_add_tail(&ipp->head, &ipp_list);
73 DRM_DEV_DEBUG_DRIVER(dev, "Registered ipp %d\n", ipp->id);
79 * exynos_drm_ipp_unregister - Unregister the picture processor module
83 void exynos_drm_ipp_unregister(struct device *dev,
84 struct exynos_drm_ipp *ipp)
87 WARN_ON(!list_empty(&ipp->todo_list));
92 * exynos_drm_ipp_get_res_ioctl - enumerate all ipp modules
95 * @file_priv: DRM file info
97 * Construct a list of ipp ids.
99 * Called by the user via ioctl.
102 * Zero on success, negative errno on failure.
104 int exynos_drm_ipp_get_res_ioctl(struct drm_device *dev, void *data,
105 struct drm_file *file_priv)
107 struct drm_exynos_ioctl_ipp_get_res *resp = data;
108 struct exynos_drm_ipp *ipp;
109 uint32_t __user *ipp_ptr = (uint32_t __user *)
110 (unsigned long)resp->ipp_id_ptr;
111 unsigned int count = num_ipp, copied = 0;
114 * This ioctl is called twice, once to determine how much space is
115 * needed, and the 2nd time to fill it.
117 if (count && resp->count_ipps >= count) {
118 list_for_each_entry(ipp, &ipp_list, head) {
119 if (put_user(ipp->id, ipp_ptr + copied))
124 resp->count_ipps = count;
129 static inline struct exynos_drm_ipp *__ipp_get(uint32_t id)
131 struct exynos_drm_ipp *ipp;
133 list_for_each_entry(ipp, &ipp_list, head)
140 * exynos_drm_ipp_get_caps_ioctl - get ipp module capabilities and formats
143 * @file_priv: DRM file info
145 * Construct a structure describing ipp module capabilities.
147 * Called by the user via ioctl.
150 * Zero on success, negative errno on failure.
152 int exynos_drm_ipp_get_caps_ioctl(struct drm_device *dev, void *data,
153 struct drm_file *file_priv)
155 struct drm_exynos_ioctl_ipp_get_caps *resp = data;
156 void __user *ptr = (void __user *)(unsigned long)resp->formats_ptr;
157 struct exynos_drm_ipp *ipp;
160 ipp = __ipp_get(resp->ipp_id);
164 resp->ipp_id = ipp->id;
165 resp->capabilities = ipp->capabilities;
168 * This ioctl is called twice, once to determine how much space is
169 * needed, and the 2nd time to fill it.
171 if (resp->formats_count >= ipp->num_formats) {
172 for (i = 0; i < ipp->num_formats; i++) {
173 struct drm_exynos_ipp_format tmp = {
174 .fourcc = ipp->formats[i].fourcc,
175 .type = ipp->formats[i].type,
176 .modifier = ipp->formats[i].modifier,
179 if (copy_to_user(ptr, &tmp, sizeof(tmp)))
184 resp->formats_count = ipp->num_formats;
189 static inline const struct exynos_drm_ipp_formats *__ipp_format_get(
190 struct exynos_drm_ipp *ipp, uint32_t fourcc,
191 uint64_t mod, unsigned int type)
195 for (i = 0; i < ipp->num_formats; i++) {
196 if ((ipp->formats[i].type & type) &&
197 ipp->formats[i].fourcc == fourcc &&
198 ipp->formats[i].modifier == mod)
199 return &ipp->formats[i];
205 * exynos_drm_ipp_get_limits_ioctl - get ipp module limits
208 * @file_priv: DRM file info
210 * Construct a structure describing ipp module limitations for provided
213 * Called by the user via ioctl.
216 * Zero on success, negative errno on failure.
218 int exynos_drm_ipp_get_limits_ioctl(struct drm_device *dev, void *data,
219 struct drm_file *file_priv)
221 struct drm_exynos_ioctl_ipp_get_limits *resp = data;
222 void __user *ptr = (void __user *)(unsigned long)resp->limits_ptr;
223 const struct exynos_drm_ipp_formats *format;
224 struct exynos_drm_ipp *ipp;
226 if (resp->type != DRM_EXYNOS_IPP_FORMAT_SOURCE &&
227 resp->type != DRM_EXYNOS_IPP_FORMAT_DESTINATION)
230 ipp = __ipp_get(resp->ipp_id);
234 format = __ipp_format_get(ipp, resp->fourcc, resp->modifier,
240 * This ioctl is called twice, once to determine how much space is
241 * needed, and the 2nd time to fill it.
243 if (format->num_limits && resp->limits_count >= format->num_limits)
244 if (copy_to_user((void __user *)ptr, format->limits,
245 sizeof(*format->limits) * format->num_limits))
247 resp->limits_count = format->num_limits;
252 struct drm_pending_exynos_ipp_event {
253 struct drm_pending_event base;
254 struct drm_exynos_ipp_event event;
257 static inline struct exynos_drm_ipp_task *
258 exynos_drm_ipp_task_alloc(struct exynos_drm_ipp *ipp)
260 struct exynos_drm_ipp_task *task;
262 task = kzalloc(sizeof(*task), GFP_KERNEL);
266 task->dev = ipp->dev;
270 task->src.rect.w = task->dst.rect.w = UINT_MAX;
271 task->src.rect.h = task->dst.rect.h = UINT_MAX;
272 task->transform.rotation = DRM_MODE_ROTATE_0;
274 DRM_DEV_DEBUG_DRIVER(task->dev, "Allocated task %pK\n", task);
279 static const struct exynos_drm_param_map {
283 } exynos_drm_ipp_params_maps[] = {
285 DRM_EXYNOS_IPP_TASK_BUFFER | DRM_EXYNOS_IPP_TASK_TYPE_SOURCE,
286 sizeof(struct drm_exynos_ipp_task_buffer),
287 offsetof(struct exynos_drm_ipp_task, src.buf),
289 DRM_EXYNOS_IPP_TASK_BUFFER |
290 DRM_EXYNOS_IPP_TASK_TYPE_DESTINATION,
291 sizeof(struct drm_exynos_ipp_task_buffer),
292 offsetof(struct exynos_drm_ipp_task, dst.buf),
294 DRM_EXYNOS_IPP_TASK_RECTANGLE | DRM_EXYNOS_IPP_TASK_TYPE_SOURCE,
295 sizeof(struct drm_exynos_ipp_task_rect),
296 offsetof(struct exynos_drm_ipp_task, src.rect),
298 DRM_EXYNOS_IPP_TASK_RECTANGLE |
299 DRM_EXYNOS_IPP_TASK_TYPE_DESTINATION,
300 sizeof(struct drm_exynos_ipp_task_rect),
301 offsetof(struct exynos_drm_ipp_task, dst.rect),
303 DRM_EXYNOS_IPP_TASK_TRANSFORM,
304 sizeof(struct drm_exynos_ipp_task_transform),
305 offsetof(struct exynos_drm_ipp_task, transform),
307 DRM_EXYNOS_IPP_TASK_ALPHA,
308 sizeof(struct drm_exynos_ipp_task_alpha),
309 offsetof(struct exynos_drm_ipp_task, alpha),
313 static int exynos_drm_ipp_task_set(struct exynos_drm_ipp_task *task,
314 struct drm_exynos_ioctl_ipp_commit *arg)
316 const struct exynos_drm_param_map *map = exynos_drm_ipp_params_maps;
317 void __user *params = (void __user *)(unsigned long)arg->params_ptr;
318 unsigned int size = arg->params_size;
323 if (get_user(id, (uint32_t __user *)params))
326 for (i = 0; i < ARRAY_SIZE(exynos_drm_ipp_params_maps); i++)
329 if (i == ARRAY_SIZE(exynos_drm_ipp_params_maps) ||
333 if (copy_from_user((void *)task + map[i].offset, params,
337 params += map[i].size;
341 DRM_DEV_DEBUG_DRIVER(task->dev,
342 "Got task %pK configuration from userspace\n",
347 static int exynos_drm_ipp_task_setup_buffer(struct exynos_drm_ipp_buffer *buf,
348 struct drm_file *filp)
353 /* get GEM buffers and check their size */
354 for (i = 0; i < buf->format->num_planes; i++) {
355 unsigned int height = (i == 0) ? buf->buf.height :
356 DIV_ROUND_UP(buf->buf.height, buf->format->vsub);
357 unsigned long size = height * buf->buf.pitch[i];
358 struct exynos_drm_gem *gem = exynos_drm_gem_get(filp,
364 buf->exynos_gem[i] = gem;
366 if (size + buf->buf.offset[i] > buf->exynos_gem[i]->size) {
371 buf->dma_addr[i] = buf->exynos_gem[i]->dma_addr +
378 exynos_drm_gem_put(buf->exynos_gem[i]);
379 buf->exynos_gem[i] = NULL;
384 static void exynos_drm_ipp_task_release_buf(struct exynos_drm_ipp_buffer *buf)
388 if (!buf->exynos_gem[0])
390 for (i = 0; i < buf->format->num_planes; i++)
391 exynos_drm_gem_put(buf->exynos_gem[i]);
394 static void exynos_drm_ipp_task_free(struct exynos_drm_ipp *ipp,
395 struct exynos_drm_ipp_task *task)
397 DRM_DEV_DEBUG_DRIVER(task->dev, "Freeing task %pK\n", task);
399 exynos_drm_ipp_task_release_buf(&task->src);
400 exynos_drm_ipp_task_release_buf(&task->dst);
402 drm_event_cancel_free(ipp->drm_dev, &task->event->base);
406 struct drm_ipp_limit {
407 struct drm_exynos_ipp_limit_val h;
408 struct drm_exynos_ipp_limit_val v;
411 enum drm_ipp_size_id {
412 IPP_LIMIT_BUFFER, IPP_LIMIT_AREA, IPP_LIMIT_ROTATED, IPP_LIMIT_MAX
415 static const enum drm_exynos_ipp_limit_type limit_id_fallback[IPP_LIMIT_MAX][4] = {
416 [IPP_LIMIT_BUFFER] = { DRM_EXYNOS_IPP_LIMIT_SIZE_BUFFER },
417 [IPP_LIMIT_AREA] = { DRM_EXYNOS_IPP_LIMIT_SIZE_AREA,
418 DRM_EXYNOS_IPP_LIMIT_SIZE_BUFFER },
419 [IPP_LIMIT_ROTATED] = { DRM_EXYNOS_IPP_LIMIT_SIZE_ROTATED,
420 DRM_EXYNOS_IPP_LIMIT_SIZE_AREA,
421 DRM_EXYNOS_IPP_LIMIT_SIZE_BUFFER },
424 static inline void __limit_set_val(unsigned int *ptr, unsigned int val)
430 static void __get_size_limit(const struct drm_exynos_ipp_limit *limits,
431 unsigned int num_limits, enum drm_ipp_size_id id,
432 struct drm_ipp_limit *res)
434 const struct drm_exynos_ipp_limit *l = limits;
437 memset(res, 0, sizeof(*res));
438 for (i = 0; limit_id_fallback[id][i]; i++)
439 for (l = limits; l - limits < num_limits; l++) {
440 if (((l->type & DRM_EXYNOS_IPP_LIMIT_TYPE_MASK) !=
441 DRM_EXYNOS_IPP_LIMIT_TYPE_SIZE) ||
442 ((l->type & DRM_EXYNOS_IPP_LIMIT_SIZE_MASK) !=
443 limit_id_fallback[id][i]))
445 __limit_set_val(&res->h.min, l->h.min);
446 __limit_set_val(&res->h.max, l->h.max);
447 __limit_set_val(&res->h.align, l->h.align);
448 __limit_set_val(&res->v.min, l->v.min);
449 __limit_set_val(&res->v.max, l->v.max);
450 __limit_set_val(&res->v.align, l->v.align);
454 static inline bool __align_check(unsigned int val, unsigned int align)
456 if (align && (val & (align - 1))) {
457 DRM_DEBUG_DRIVER("Value %d exceeds HW limits (align %d)\n",
464 static inline bool __size_limit_check(unsigned int val,
465 struct drm_exynos_ipp_limit_val *l)
467 if ((l->min && val < l->min) || (l->max && val > l->max)) {
468 DRM_DEBUG_DRIVER("Value %d exceeds HW limits (min %d, max %d)\n",
469 val, l->min, l->max);
472 return __align_check(val, l->align);
475 static int exynos_drm_ipp_check_size_limits(struct exynos_drm_ipp_buffer *buf,
476 const struct drm_exynos_ipp_limit *limits, unsigned int num_limits,
477 bool rotate, bool swap)
479 enum drm_ipp_size_id id = rotate ? IPP_LIMIT_ROTATED : IPP_LIMIT_AREA;
480 struct drm_ipp_limit l;
481 struct drm_exynos_ipp_limit_val *lh = &l.h, *lv = &l.v;
482 int real_width = buf->buf.pitch[0] / buf->format->cpp[0];
487 __get_size_limit(limits, num_limits, IPP_LIMIT_BUFFER, &l);
488 if (!__size_limit_check(real_width, &l.h) ||
489 !__size_limit_check(buf->buf.height, &l.v))
496 __get_size_limit(limits, num_limits, id, &l);
497 if (!__size_limit_check(buf->rect.w, lh) ||
498 !__align_check(buf->rect.x, lh->align) ||
499 !__size_limit_check(buf->rect.h, lv) ||
500 !__align_check(buf->rect.y, lv->align))
506 static inline bool __scale_limit_check(unsigned int src, unsigned int dst,
507 unsigned int min, unsigned int max)
509 if ((max && (dst << 16) > src * max) ||
510 (min && (dst << 16) < src * min)) {
511 DRM_DEBUG_DRIVER("Scale from %d to %d exceeds HW limits (ratio min %d.%05d, max %d.%05d)\n",
513 min >> 16, 100000 * (min & 0xffff) / (1 << 16),
514 max >> 16, 100000 * (max & 0xffff) / (1 << 16));
520 static int exynos_drm_ipp_check_scale_limits(
521 struct drm_exynos_ipp_task_rect *src,
522 struct drm_exynos_ipp_task_rect *dst,
523 const struct drm_exynos_ipp_limit *limits,
524 unsigned int num_limits, bool swap)
526 const struct drm_exynos_ipp_limit_val *lh, *lv;
529 for (; num_limits; limits++, num_limits--)
530 if ((limits->type & DRM_EXYNOS_IPP_LIMIT_TYPE_MASK) ==
531 DRM_EXYNOS_IPP_LIMIT_TYPE_SCALE)
536 lh = (!swap) ? &limits->h : &limits->v;
537 lv = (!swap) ? &limits->v : &limits->h;
538 dw = (!swap) ? dst->w : dst->h;
539 dh = (!swap) ? dst->h : dst->w;
541 if (!__scale_limit_check(src->w, dw, lh->min, lh->max) ||
542 !__scale_limit_check(src->h, dh, lv->min, lv->max))
548 static int exynos_drm_ipp_check_format(struct exynos_drm_ipp_task *task,
549 struct exynos_drm_ipp_buffer *buf,
550 struct exynos_drm_ipp_buffer *src,
551 struct exynos_drm_ipp_buffer *dst,
552 bool rotate, bool swap)
554 const struct exynos_drm_ipp_formats *fmt;
557 fmt = __ipp_format_get(task->ipp, buf->buf.fourcc, buf->buf.modifier,
558 buf == src ? DRM_EXYNOS_IPP_FORMAT_SOURCE :
559 DRM_EXYNOS_IPP_FORMAT_DESTINATION);
561 DRM_DEV_DEBUG_DRIVER(task->dev,
562 "Task %pK: %s format not supported\n",
563 task, buf == src ? "src" : "dst");
568 if (buf->buf.width == 0 || buf->buf.height == 0)
571 buf->format = drm_format_info(buf->buf.fourcc);
572 for (i = 0; i < buf->format->num_planes; i++) {
573 unsigned int width = (i == 0) ? buf->buf.width :
574 DIV_ROUND_UP(buf->buf.width, buf->format->hsub);
576 if (buf->buf.pitch[i] == 0)
577 buf->buf.pitch[i] = width * buf->format->cpp[i];
578 if (buf->buf.pitch[i] < width * buf->format->cpp[i])
580 if (!buf->buf.gem_id[i])
584 /* pitch for additional planes must match */
585 if (buf->format->num_planes > 2 &&
586 buf->buf.pitch[1] != buf->buf.pitch[2])
589 /* check driver limits */
590 ret = exynos_drm_ipp_check_size_limits(buf, fmt->limits,
593 buf == dst ? swap : false);
596 ret = exynos_drm_ipp_check_scale_limits(&src->rect, &dst->rect,
598 fmt->num_limits, swap);
602 static int exynos_drm_ipp_task_check(struct exynos_drm_ipp_task *task)
604 struct exynos_drm_ipp *ipp = task->ipp;
605 struct exynos_drm_ipp_buffer *src = &task->src, *dst = &task->dst;
606 unsigned int rotation = task->transform.rotation;
608 bool swap = drm_rotation_90_or_270(rotation);
609 bool rotate = (rotation != DRM_MODE_ROTATE_0);
612 DRM_DEV_DEBUG_DRIVER(task->dev, "Checking task %pK\n", task);
614 if (src->rect.w == UINT_MAX)
615 src->rect.w = src->buf.width;
616 if (src->rect.h == UINT_MAX)
617 src->rect.h = src->buf.height;
618 if (dst->rect.w == UINT_MAX)
619 dst->rect.w = dst->buf.width;
620 if (dst->rect.h == UINT_MAX)
621 dst->rect.h = dst->buf.height;
623 if (src->rect.x + src->rect.w > (src->buf.width) ||
624 src->rect.y + src->rect.h > (src->buf.height) ||
625 dst->rect.x + dst->rect.w > (dst->buf.width) ||
626 dst->rect.y + dst->rect.h > (dst->buf.height)) {
627 DRM_DEV_DEBUG_DRIVER(task->dev,
628 "Task %pK: defined area is outside provided buffers\n",
633 if ((!swap && (src->rect.w != dst->rect.w ||
634 src->rect.h != dst->rect.h)) ||
635 (swap && (src->rect.w != dst->rect.h ||
636 src->rect.h != dst->rect.w)))
639 if ((!(ipp->capabilities & DRM_EXYNOS_IPP_CAP_CROP) &&
640 (src->rect.x || src->rect.y || dst->rect.x || dst->rect.y)) ||
641 (!(ipp->capabilities & DRM_EXYNOS_IPP_CAP_ROTATE) && rotate) ||
642 (!(ipp->capabilities & DRM_EXYNOS_IPP_CAP_SCALE) && scale) ||
643 (!(ipp->capabilities & DRM_EXYNOS_IPP_CAP_CONVERT) &&
644 src->buf.fourcc != dst->buf.fourcc)) {
645 DRM_DEV_DEBUG_DRIVER(task->dev, "Task %pK: hw capabilities exceeded\n",
650 ret = exynos_drm_ipp_check_format(task, src, src, dst, rotate, swap);
654 ret = exynos_drm_ipp_check_format(task, dst, src, dst, false, swap);
658 DRM_DEV_DEBUG_DRIVER(ipp->dev, "Task %pK: all checks done.\n",
664 static int exynos_drm_ipp_task_setup_buffers(struct exynos_drm_ipp_task *task,
665 struct drm_file *filp)
667 struct exynos_drm_ipp_buffer *src = &task->src, *dst = &task->dst;
670 DRM_DEV_DEBUG_DRIVER(task->dev, "Setting buffer for task %pK\n",
673 ret = exynos_drm_ipp_task_setup_buffer(src, filp);
675 DRM_DEV_DEBUG_DRIVER(task->dev,
676 "Task %pK: src buffer setup failed\n",
680 ret = exynos_drm_ipp_task_setup_buffer(dst, filp);
682 DRM_DEV_DEBUG_DRIVER(task->dev,
683 "Task %pK: dst buffer setup failed\n",
688 DRM_DEV_DEBUG_DRIVER(task->dev, "Task %pK: buffers prepared.\n",
695 static int exynos_drm_ipp_event_create(struct exynos_drm_ipp_task *task,
696 struct drm_file *file_priv, uint64_t user_data)
698 struct drm_pending_exynos_ipp_event *e = NULL;
701 e = kzalloc(sizeof(*e), GFP_KERNEL);
705 e->event.base.type = DRM_EXYNOS_IPP_EVENT;
706 e->event.base.length = sizeof(e->event);
707 e->event.user_data = user_data;
709 ret = drm_event_reserve_init(task->ipp->drm_dev, file_priv, &e->base,
721 static void exynos_drm_ipp_event_send(struct exynos_drm_ipp_task *task)
723 struct timespec64 now;
725 ktime_get_ts64(&now);
726 task->event->event.tv_sec = now.tv_sec;
727 task->event->event.tv_usec = now.tv_nsec / NSEC_PER_USEC;
728 task->event->event.sequence = atomic_inc_return(&task->ipp->sequence);
730 drm_send_event(task->ipp->drm_dev, &task->event->base);
733 static int exynos_drm_ipp_task_cleanup(struct exynos_drm_ipp_task *task)
737 if (ret == 0 && task->event) {
738 exynos_drm_ipp_event_send(task);
739 /* ensure event won't be canceled on task free */
743 exynos_drm_ipp_task_free(task->ipp, task);
747 static void exynos_drm_ipp_cleanup_work(struct work_struct *work)
749 struct exynos_drm_ipp_task *task = container_of(work,
750 struct exynos_drm_ipp_task, cleanup_work);
752 exynos_drm_ipp_task_cleanup(task);
755 static void exynos_drm_ipp_next_task(struct exynos_drm_ipp *ipp);
758 * exynos_drm_ipp_task_done - finish given task and set return code
759 * @task: ipp task to finish
760 * @ret: error code or 0 if operation has been performed successfully
762 void exynos_drm_ipp_task_done(struct exynos_drm_ipp_task *task, int ret)
764 struct exynos_drm_ipp *ipp = task->ipp;
767 DRM_DEV_DEBUG_DRIVER(task->dev, "ipp: %d, task %pK done: %d\n",
770 spin_lock_irqsave(&ipp->lock, flags);
771 if (ipp->task == task)
773 task->flags |= DRM_EXYNOS_IPP_TASK_DONE;
775 spin_unlock_irqrestore(&ipp->lock, flags);
777 exynos_drm_ipp_next_task(ipp);
778 wake_up(&ipp->done_wq);
780 if (task->flags & DRM_EXYNOS_IPP_TASK_ASYNC) {
781 INIT_WORK(&task->cleanup_work, exynos_drm_ipp_cleanup_work);
782 schedule_work(&task->cleanup_work);
786 static void exynos_drm_ipp_next_task(struct exynos_drm_ipp *ipp)
788 struct exynos_drm_ipp_task *task;
792 DRM_DEV_DEBUG_DRIVER(ipp->dev, "ipp: %d, try to run new task\n",
795 spin_lock_irqsave(&ipp->lock, flags);
797 if (ipp->task || list_empty(&ipp->todo_list)) {
798 spin_unlock_irqrestore(&ipp->lock, flags);
802 task = list_first_entry(&ipp->todo_list, struct exynos_drm_ipp_task,
804 list_del_init(&task->head);
807 spin_unlock_irqrestore(&ipp->lock, flags);
809 DRM_DEV_DEBUG_DRIVER(ipp->dev,
810 "ipp: %d, selected task %pK to run\n", ipp->id,
813 ret = ipp->funcs->commit(ipp, task);
815 exynos_drm_ipp_task_done(task, ret);
818 static void exynos_drm_ipp_schedule_task(struct exynos_drm_ipp *ipp,
819 struct exynos_drm_ipp_task *task)
823 spin_lock_irqsave(&ipp->lock, flags);
824 list_add(&task->head, &ipp->todo_list);
825 spin_unlock_irqrestore(&ipp->lock, flags);
827 exynos_drm_ipp_next_task(ipp);
830 static void exynos_drm_ipp_task_abort(struct exynos_drm_ipp *ipp,
831 struct exynos_drm_ipp_task *task)
835 spin_lock_irqsave(&ipp->lock, flags);
836 if (task->flags & DRM_EXYNOS_IPP_TASK_DONE) {
837 /* already completed task */
838 exynos_drm_ipp_task_cleanup(task);
839 } else if (ipp->task != task) {
840 /* task has not been scheduled for execution yet */
841 list_del_init(&task->head);
842 exynos_drm_ipp_task_cleanup(task);
845 * currently processed task, call abort() and perform
846 * cleanup with async worker
848 task->flags |= DRM_EXYNOS_IPP_TASK_ASYNC;
849 spin_unlock_irqrestore(&ipp->lock, flags);
850 if (ipp->funcs->abort)
851 ipp->funcs->abort(ipp, task);
854 spin_unlock_irqrestore(&ipp->lock, flags);
858 * exynos_drm_ipp_commit_ioctl - perform image processing operation
861 * @file_priv: DRM file info
863 * Construct a ipp task from the set of properties provided from the user
864 * and try to schedule it to framebuffer processor hardware.
866 * Called by the user via ioctl.
869 * Zero on success, negative errno on failure.
871 int exynos_drm_ipp_commit_ioctl(struct drm_device *dev, void *data,
872 struct drm_file *file_priv)
874 struct drm_exynos_ioctl_ipp_commit *arg = data;
875 struct exynos_drm_ipp *ipp;
876 struct exynos_drm_ipp_task *task;
879 if ((arg->flags & ~DRM_EXYNOS_IPP_FLAGS) || arg->reserved)
882 /* can't test and expect an event at the same time */
883 if ((arg->flags & DRM_EXYNOS_IPP_FLAG_TEST_ONLY) &&
884 (arg->flags & DRM_EXYNOS_IPP_FLAG_EVENT))
887 ipp = __ipp_get(arg->ipp_id);
891 task = exynos_drm_ipp_task_alloc(ipp);
895 ret = exynos_drm_ipp_task_set(task, arg);
899 ret = exynos_drm_ipp_task_check(task);
903 ret = exynos_drm_ipp_task_setup_buffers(task, file_priv);
904 if (ret || arg->flags & DRM_EXYNOS_IPP_FLAG_TEST_ONLY)
907 if (arg->flags & DRM_EXYNOS_IPP_FLAG_EVENT) {
908 ret = exynos_drm_ipp_event_create(task, file_priv,
915 * Queue task for processing on the hardware. task object will be
916 * then freed after exynos_drm_ipp_task_done()
918 if (arg->flags & DRM_EXYNOS_IPP_FLAG_NONBLOCK) {
919 DRM_DEV_DEBUG_DRIVER(ipp->dev,
920 "ipp: %d, nonblocking processing task %pK\n",
923 task->flags |= DRM_EXYNOS_IPP_TASK_ASYNC;
924 exynos_drm_ipp_schedule_task(task->ipp, task);
927 DRM_DEV_DEBUG_DRIVER(ipp->dev, "ipp: %d, processing task %pK\n",
929 exynos_drm_ipp_schedule_task(ipp, task);
930 ret = wait_event_interruptible(ipp->done_wq,
931 task->flags & DRM_EXYNOS_IPP_TASK_DONE);
933 exynos_drm_ipp_task_abort(ipp, task);
935 ret = exynos_drm_ipp_task_cleanup(task);
939 exynos_drm_ipp_task_free(ipp, task);