2 * Copyright (C) 2017 Samsung Electronics Co.Ltd
4 * Marek Szyprowski <m.szyprowski@samsung.com>
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.
20 #include <drm/drm_mode.h>
21 #include <drm/exynos_drm.h>
23 #include "exynos_drm_drv.h"
24 #include "exynos_drm_gem.h"
25 #include "exynos_drm_ipp.h"
28 static LIST_HEAD(ipp_list);
31 * exynos_drm_ipp_register - Register a new picture processor hardware module
33 * @ipp: ipp module to init
34 * @funcs: callbacks for the new ipp object
35 * @caps: bitmask of ipp capabilities (%DRM_EXYNOS_IPP_CAP_*)
36 * @formats: array of supported formats
37 * @num_formats: size of the supported formats array
38 * @name: name (for debugging purposes)
40 * Initializes a ipp module.
43 * Zero on success, error code on failure.
45 int exynos_drm_ipp_register(struct device *dev, struct exynos_drm_ipp *ipp,
46 const struct exynos_drm_ipp_funcs *funcs, unsigned int caps,
47 const struct exynos_drm_ipp_formats *formats,
48 unsigned int num_formats, const char *name)
53 WARN_ON(!num_formats);
55 spin_lock_init(&ipp->lock);
56 INIT_LIST_HEAD(&ipp->todo_list);
57 init_waitqueue_head(&ipp->done_wq);
60 ipp->capabilities = caps;
62 ipp->formats = formats;
63 ipp->num_formats = num_formats;
65 /* ipp_list modification is serialized by component framework */
66 list_add_tail(&ipp->head, &ipp_list);
69 DRM_DEV_DEBUG_DRIVER(dev, "Registered ipp %d\n", ipp->id);
75 * exynos_drm_ipp_unregister - Unregister the picture processor module
79 void exynos_drm_ipp_unregister(struct device *dev,
80 struct exynos_drm_ipp *ipp)
83 WARN_ON(!list_empty(&ipp->todo_list));
88 * exynos_drm_ipp_ioctl_get_res_ioctl - enumerate all ipp modules
91 * @file_priv: DRM file info
93 * Construct a list of ipp ids.
95 * Called by the user via ioctl.
98 * Zero on success, negative errno on failure.
100 int exynos_drm_ipp_get_res_ioctl(struct drm_device *dev, void *data,
101 struct drm_file *file_priv)
103 struct drm_exynos_ioctl_ipp_get_res *resp = data;
104 struct exynos_drm_ipp *ipp;
105 uint32_t __user *ipp_ptr = (uint32_t __user *)
106 (unsigned long)resp->ipp_id_ptr;
107 unsigned int count = num_ipp, copied = 0;
110 * This ioctl is called twice, once to determine how much space is
111 * needed, and the 2nd time to fill it.
113 if (count && resp->count_ipps >= count) {
114 list_for_each_entry(ipp, &ipp_list, head) {
115 if (put_user(ipp->id, ipp_ptr + copied))
120 resp->count_ipps = count;
125 static inline struct exynos_drm_ipp *__ipp_get(uint32_t id)
127 struct exynos_drm_ipp *ipp;
129 list_for_each_entry(ipp, &ipp_list, head)
136 * exynos_drm_ipp_ioctl_get_caps - get ipp module capabilities and formats
139 * @file_priv: DRM file info
141 * Construct a structure describing ipp module capabilities.
143 * Called by the user via ioctl.
146 * Zero on success, negative errno on failure.
148 int exynos_drm_ipp_get_caps_ioctl(struct drm_device *dev, void *data,
149 struct drm_file *file_priv)
151 struct drm_exynos_ioctl_ipp_get_caps *resp = data;
152 void __user *ptr = (void __user *)(unsigned long)resp->formats_ptr;
153 struct exynos_drm_ipp *ipp;
156 ipp = __ipp_get(resp->ipp_id);
160 resp->ipp_id = ipp->id;
161 resp->capabilities = ipp->capabilities;
164 * This ioctl is called twice, once to determine how much space is
165 * needed, and the 2nd time to fill it.
167 if (resp->formats_count >= ipp->num_formats) {
168 for (i = 0; i < ipp->num_formats; i++) {
169 struct drm_exynos_ipp_format tmp = {
170 .fourcc = ipp->formats[i].fourcc,
171 .type = ipp->formats[i].type,
172 .modifier = ipp->formats[i].modifier,
175 if (copy_to_user(ptr, &tmp, sizeof(tmp)))
180 resp->formats_count = ipp->num_formats;
185 static inline const struct exynos_drm_ipp_formats *__ipp_format_get(
186 struct exynos_drm_ipp *ipp, uint32_t fourcc,
187 uint64_t mod, unsigned int type)
191 for (i = 0; i < ipp->num_formats; i++) {
192 if ((ipp->formats[i].type & type) &&
193 ipp->formats[i].fourcc == fourcc &&
194 ipp->formats[i].modifier == mod)
195 return &ipp->formats[i];
201 * exynos_drm_ipp_get_limits_ioctl - get ipp module limits
204 * @file_priv: DRM file info
206 * Construct a structure describing ipp module limitations for provided
209 * Called by the user via ioctl.
212 * Zero on success, negative errno on failure.
214 int exynos_drm_ipp_get_limits_ioctl(struct drm_device *dev, void *data,
215 struct drm_file *file_priv)
217 struct drm_exynos_ioctl_ipp_get_limits *resp = data;
218 void __user *ptr = (void __user *)(unsigned long)resp->limits_ptr;
219 const struct exynos_drm_ipp_formats *format;
220 struct exynos_drm_ipp *ipp;
222 if (resp->type != DRM_EXYNOS_IPP_FORMAT_SOURCE &&
223 resp->type != DRM_EXYNOS_IPP_FORMAT_DESTINATION)
226 ipp = __ipp_get(resp->ipp_id);
230 format = __ipp_format_get(ipp, resp->fourcc, resp->modifier,
236 * This ioctl is called twice, once to determine how much space is
237 * needed, and the 2nd time to fill it.
239 if (format->num_limits && resp->limits_count >= format->num_limits)
240 if (copy_to_user((void __user *)ptr, format->limits,
241 sizeof(*format->limits) * format->num_limits))
243 resp->limits_count = format->num_limits;
248 struct drm_pending_exynos_ipp_event {
249 struct drm_pending_event base;
250 struct drm_exynos_ipp_event event;
253 static inline struct exynos_drm_ipp_task *
254 exynos_drm_ipp_task_alloc(struct exynos_drm_ipp *ipp)
256 struct exynos_drm_ipp_task *task;
258 task = kzalloc(sizeof(*task), GFP_KERNEL);
262 task->dev = ipp->dev;
266 task->src.rect.w = task->dst.rect.w = UINT_MAX;
267 task->src.rect.h = task->dst.rect.h = UINT_MAX;
268 task->transform.rotation = DRM_MODE_ROTATE_0;
270 DRM_DEV_DEBUG_DRIVER(task->dev, "Allocated task %pK\n", task);
275 static const struct exynos_drm_param_map {
279 } exynos_drm_ipp_params_maps[] = {
281 DRM_EXYNOS_IPP_TASK_BUFFER | DRM_EXYNOS_IPP_TASK_TYPE_SOURCE,
282 sizeof(struct drm_exynos_ipp_task_buffer),
283 offsetof(struct exynos_drm_ipp_task, src.buf),
285 DRM_EXYNOS_IPP_TASK_BUFFER |
286 DRM_EXYNOS_IPP_TASK_TYPE_DESTINATION,
287 sizeof(struct drm_exynos_ipp_task_buffer),
288 offsetof(struct exynos_drm_ipp_task, dst.buf),
290 DRM_EXYNOS_IPP_TASK_RECTANGLE | DRM_EXYNOS_IPP_TASK_TYPE_SOURCE,
291 sizeof(struct drm_exynos_ipp_task_rect),
292 offsetof(struct exynos_drm_ipp_task, src.rect),
294 DRM_EXYNOS_IPP_TASK_RECTANGLE |
295 DRM_EXYNOS_IPP_TASK_TYPE_DESTINATION,
296 sizeof(struct drm_exynos_ipp_task_rect),
297 offsetof(struct exynos_drm_ipp_task, dst.rect),
299 DRM_EXYNOS_IPP_TASK_TRANSFORM,
300 sizeof(struct drm_exynos_ipp_task_transform),
301 offsetof(struct exynos_drm_ipp_task, transform),
303 DRM_EXYNOS_IPP_TASK_ALPHA,
304 sizeof(struct drm_exynos_ipp_task_alpha),
305 offsetof(struct exynos_drm_ipp_task, alpha),
309 static int exynos_drm_ipp_task_set(struct exynos_drm_ipp_task *task,
310 struct drm_exynos_ioctl_ipp_commit *arg)
312 const struct exynos_drm_param_map *map = exynos_drm_ipp_params_maps;
313 void __user *params = (void __user *)(unsigned long)arg->params_ptr;
314 unsigned int size = arg->params_size;
319 if (get_user(id, (uint32_t __user *)params))
322 for (i = 0; i < ARRAY_SIZE(exynos_drm_ipp_params_maps); i++)
325 if (i == ARRAY_SIZE(exynos_drm_ipp_params_maps) ||
329 if (copy_from_user((void *)task + map[i].offset, params,
333 params += map[i].size;
337 DRM_DEV_DEBUG_DRIVER(task->dev,
338 "Got task %pK configuration from userspace\n",
343 static int exynos_drm_ipp_task_setup_buffer(struct exynos_drm_ipp_buffer *buf,
344 struct drm_file *filp)
349 /* get GEM buffers and check their size */
350 for (i = 0; i < buf->format->num_planes; i++) {
351 unsigned int height = (i == 0) ? buf->buf.height :
352 DIV_ROUND_UP(buf->buf.height, buf->format->vsub);
353 unsigned long size = height * buf->buf.pitch[i];
354 struct exynos_drm_gem *gem = exynos_drm_gem_get(filp,
360 buf->exynos_gem[i] = gem;
362 if (size + buf->buf.offset[i] > buf->exynos_gem[i]->size) {
367 buf->dma_addr[i] = buf->exynos_gem[i]->dma_addr +
374 exynos_drm_gem_put(buf->exynos_gem[i]);
375 buf->exynos_gem[i] = NULL;
380 static void exynos_drm_ipp_task_release_buf(struct exynos_drm_ipp_buffer *buf)
384 if (!buf->exynos_gem[0])
386 for (i = 0; i < buf->format->num_planes; i++)
387 exynos_drm_gem_put(buf->exynos_gem[i]);
390 static void exynos_drm_ipp_task_free(struct exynos_drm_ipp *ipp,
391 struct exynos_drm_ipp_task *task)
393 DRM_DEV_DEBUG_DRIVER(task->dev, "Freeing task %pK\n", task);
395 exynos_drm_ipp_task_release_buf(&task->src);
396 exynos_drm_ipp_task_release_buf(&task->dst);
398 drm_event_cancel_free(ipp->drm_dev, &task->event->base);
402 struct drm_ipp_limit {
403 struct drm_exynos_ipp_limit_val h;
404 struct drm_exynos_ipp_limit_val v;
407 enum drm_ipp_size_id {
408 IPP_LIMIT_BUFFER, IPP_LIMIT_AREA, IPP_LIMIT_ROTATED, IPP_LIMIT_MAX
411 static const enum drm_exynos_ipp_limit_type limit_id_fallback[IPP_LIMIT_MAX][4] = {
412 [IPP_LIMIT_BUFFER] = { DRM_EXYNOS_IPP_LIMIT_SIZE_BUFFER },
413 [IPP_LIMIT_AREA] = { DRM_EXYNOS_IPP_LIMIT_SIZE_AREA,
414 DRM_EXYNOS_IPP_LIMIT_SIZE_BUFFER },
415 [IPP_LIMIT_ROTATED] = { DRM_EXYNOS_IPP_LIMIT_SIZE_ROTATED,
416 DRM_EXYNOS_IPP_LIMIT_SIZE_AREA,
417 DRM_EXYNOS_IPP_LIMIT_SIZE_BUFFER },
420 static inline void __limit_set_val(unsigned int *ptr, unsigned int val)
426 static void __get_size_limit(const struct drm_exynos_ipp_limit *limits,
427 unsigned int num_limits, enum drm_ipp_size_id id,
428 struct drm_ipp_limit *res)
430 const struct drm_exynos_ipp_limit *l = limits;
433 memset(res, 0, sizeof(*res));
434 for (i = 0; limit_id_fallback[id][i]; i++)
435 for (l = limits; l - limits < num_limits; l++) {
436 if (((l->type & DRM_EXYNOS_IPP_LIMIT_TYPE_MASK) !=
437 DRM_EXYNOS_IPP_LIMIT_TYPE_SIZE) ||
438 ((l->type & DRM_EXYNOS_IPP_LIMIT_SIZE_MASK) !=
439 limit_id_fallback[id][i]))
441 __limit_set_val(&res->h.min, l->h.min);
442 __limit_set_val(&res->h.max, l->h.max);
443 __limit_set_val(&res->h.align, l->h.align);
444 __limit_set_val(&res->v.min, l->v.min);
445 __limit_set_val(&res->v.max, l->v.max);
446 __limit_set_val(&res->v.align, l->v.align);
450 static inline bool __align_check(unsigned int val, unsigned int align)
452 if (align && (val & (align - 1))) {
453 DRM_DEBUG_DRIVER("Value %d exceeds HW limits (align %d)\n",
460 static inline bool __size_limit_check(unsigned int val,
461 struct drm_exynos_ipp_limit_val *l)
463 if ((l->min && val < l->min) || (l->max && val > l->max)) {
464 DRM_DEBUG_DRIVER("Value %d exceeds HW limits (min %d, max %d)\n",
465 val, l->min, l->max);
468 return __align_check(val, l->align);
471 static int exynos_drm_ipp_check_size_limits(struct exynos_drm_ipp_buffer *buf,
472 const struct drm_exynos_ipp_limit *limits, unsigned int num_limits,
473 bool rotate, bool swap)
475 enum drm_ipp_size_id id = rotate ? IPP_LIMIT_ROTATED : IPP_LIMIT_AREA;
476 struct drm_ipp_limit l;
477 struct drm_exynos_ipp_limit_val *lh = &l.h, *lv = &l.v;
478 int real_width = buf->buf.pitch[0] / buf->format->cpp[0];
483 __get_size_limit(limits, num_limits, IPP_LIMIT_BUFFER, &l);
484 if (!__size_limit_check(real_width, &l.h) ||
485 !__size_limit_check(buf->buf.height, &l.v))
492 __get_size_limit(limits, num_limits, id, &l);
493 if (!__size_limit_check(buf->rect.w, lh) ||
494 !__align_check(buf->rect.x, lh->align) ||
495 !__size_limit_check(buf->rect.h, lv) ||
496 !__align_check(buf->rect.y, lv->align))
502 static inline bool __scale_limit_check(unsigned int src, unsigned int dst,
503 unsigned int min, unsigned int max)
505 if ((max && (dst << 16) > src * max) ||
506 (min && (dst << 16) < src * min)) {
507 DRM_DEBUG_DRIVER("Scale from %d to %d exceeds HW limits (ratio min %d.%05d, max %d.%05d)\n",
509 min >> 16, 100000 * (min & 0xffff) / (1 << 16),
510 max >> 16, 100000 * (max & 0xffff) / (1 << 16));
516 static int exynos_drm_ipp_check_scale_limits(
517 struct drm_exynos_ipp_task_rect *src,
518 struct drm_exynos_ipp_task_rect *dst,
519 const struct drm_exynos_ipp_limit *limits,
520 unsigned int num_limits, bool swap)
522 const struct drm_exynos_ipp_limit_val *lh, *lv;
525 for (; num_limits; limits++, num_limits--)
526 if ((limits->type & DRM_EXYNOS_IPP_LIMIT_TYPE_MASK) ==
527 DRM_EXYNOS_IPP_LIMIT_TYPE_SCALE)
532 lh = (!swap) ? &limits->h : &limits->v;
533 lv = (!swap) ? &limits->v : &limits->h;
534 dw = (!swap) ? dst->w : dst->h;
535 dh = (!swap) ? dst->h : dst->w;
537 if (!__scale_limit_check(src->w, dw, lh->min, lh->max) ||
538 !__scale_limit_check(src->h, dh, lv->min, lv->max))
544 static int exynos_drm_ipp_check_format(struct exynos_drm_ipp_task *task,
545 struct exynos_drm_ipp_buffer *buf,
546 struct exynos_drm_ipp_buffer *src,
547 struct exynos_drm_ipp_buffer *dst,
548 bool rotate, bool swap)
550 const struct exynos_drm_ipp_formats *fmt;
553 fmt = __ipp_format_get(task->ipp, buf->buf.fourcc, buf->buf.modifier,
554 buf == src ? DRM_EXYNOS_IPP_FORMAT_SOURCE :
555 DRM_EXYNOS_IPP_FORMAT_DESTINATION);
557 DRM_DEV_DEBUG_DRIVER(task->dev,
558 "Task %pK: %s format not supported\n",
559 task, buf == src ? "src" : "dst");
564 if (buf->buf.width == 0 || buf->buf.height == 0)
567 buf->format = drm_format_info(buf->buf.fourcc);
568 for (i = 0; i < buf->format->num_planes; i++) {
569 unsigned int width = (i == 0) ? buf->buf.width :
570 DIV_ROUND_UP(buf->buf.width, buf->format->hsub);
572 if (buf->buf.pitch[i] == 0)
573 buf->buf.pitch[i] = width * buf->format->cpp[i];
574 if (buf->buf.pitch[i] < width * buf->format->cpp[i])
576 if (!buf->buf.gem_id[i])
580 /* pitch for additional planes must match */
581 if (buf->format->num_planes > 2 &&
582 buf->buf.pitch[1] != buf->buf.pitch[2])
585 /* check driver limits */
586 ret = exynos_drm_ipp_check_size_limits(buf, fmt->limits,
589 buf == dst ? swap : false);
592 ret = exynos_drm_ipp_check_scale_limits(&src->rect, &dst->rect,
594 fmt->num_limits, swap);
598 static int exynos_drm_ipp_task_check(struct exynos_drm_ipp_task *task)
600 struct exynos_drm_ipp *ipp = task->ipp;
601 struct exynos_drm_ipp_buffer *src = &task->src, *dst = &task->dst;
602 unsigned int rotation = task->transform.rotation;
604 bool swap = drm_rotation_90_or_270(rotation);
605 bool rotate = (rotation != DRM_MODE_ROTATE_0);
608 DRM_DEV_DEBUG_DRIVER(task->dev, "Checking task %pK\n", task);
610 if (src->rect.w == UINT_MAX)
611 src->rect.w = src->buf.width;
612 if (src->rect.h == UINT_MAX)
613 src->rect.h = src->buf.height;
614 if (dst->rect.w == UINT_MAX)
615 dst->rect.w = dst->buf.width;
616 if (dst->rect.h == UINT_MAX)
617 dst->rect.h = dst->buf.height;
619 if (src->rect.x + src->rect.w > (src->buf.width) ||
620 src->rect.y + src->rect.h > (src->buf.height) ||
621 dst->rect.x + dst->rect.w > (dst->buf.width) ||
622 dst->rect.y + dst->rect.h > (dst->buf.height)) {
623 DRM_DEV_DEBUG_DRIVER(task->dev,
624 "Task %pK: defined area is outside provided buffers\n",
629 if ((!swap && (src->rect.w != dst->rect.w ||
630 src->rect.h != dst->rect.h)) ||
631 (swap && (src->rect.w != dst->rect.h ||
632 src->rect.h != dst->rect.w)))
635 if ((!(ipp->capabilities & DRM_EXYNOS_IPP_CAP_CROP) &&
636 (src->rect.x || src->rect.y || dst->rect.x || dst->rect.y)) ||
637 (!(ipp->capabilities & DRM_EXYNOS_IPP_CAP_ROTATE) && rotate) ||
638 (!(ipp->capabilities & DRM_EXYNOS_IPP_CAP_SCALE) && scale) ||
639 (!(ipp->capabilities & DRM_EXYNOS_IPP_CAP_CONVERT) &&
640 src->buf.fourcc != dst->buf.fourcc)) {
641 DRM_DEV_DEBUG_DRIVER(task->dev, "Task %pK: hw capabilities exceeded\n",
646 ret = exynos_drm_ipp_check_format(task, src, src, dst, rotate, swap);
650 ret = exynos_drm_ipp_check_format(task, dst, src, dst, false, swap);
654 DRM_DEV_DEBUG_DRIVER(ipp->dev, "Task %pK: all checks done.\n",
660 static int exynos_drm_ipp_task_setup_buffers(struct exynos_drm_ipp_task *task,
661 struct drm_file *filp)
663 struct exynos_drm_ipp_buffer *src = &task->src, *dst = &task->dst;
666 DRM_DEV_DEBUG_DRIVER(task->dev, "Setting buffer for task %pK\n",
669 ret = exynos_drm_ipp_task_setup_buffer(src, filp);
671 DRM_DEV_DEBUG_DRIVER(task->dev,
672 "Task %pK: src buffer setup failed\n",
676 ret = exynos_drm_ipp_task_setup_buffer(dst, filp);
678 DRM_DEV_DEBUG_DRIVER(task->dev,
679 "Task %pK: dst buffer setup failed\n",
684 DRM_DEV_DEBUG_DRIVER(task->dev, "Task %pK: buffers prepared.\n",
691 static int exynos_drm_ipp_event_create(struct exynos_drm_ipp_task *task,
692 struct drm_file *file_priv, uint64_t user_data)
694 struct drm_pending_exynos_ipp_event *e = NULL;
697 e = kzalloc(sizeof(*e), GFP_KERNEL);
701 e->event.base.type = DRM_EXYNOS_IPP_EVENT;
702 e->event.base.length = sizeof(e->event);
703 e->event.user_data = user_data;
705 ret = drm_event_reserve_init(task->ipp->drm_dev, file_priv, &e->base,
717 static void exynos_drm_ipp_event_send(struct exynos_drm_ipp_task *task)
719 struct timespec64 now;
721 ktime_get_ts64(&now);
722 task->event->event.tv_sec = now.tv_sec;
723 task->event->event.tv_usec = now.tv_nsec / NSEC_PER_USEC;
724 task->event->event.sequence = atomic_inc_return(&task->ipp->sequence);
726 drm_send_event(task->ipp->drm_dev, &task->event->base);
729 static int exynos_drm_ipp_task_cleanup(struct exynos_drm_ipp_task *task)
733 if (ret == 0 && task->event) {
734 exynos_drm_ipp_event_send(task);
735 /* ensure event won't be canceled on task free */
739 exynos_drm_ipp_task_free(task->ipp, task);
743 static void exynos_drm_ipp_cleanup_work(struct work_struct *work)
745 struct exynos_drm_ipp_task *task = container_of(work,
746 struct exynos_drm_ipp_task, cleanup_work);
748 exynos_drm_ipp_task_cleanup(task);
751 static void exynos_drm_ipp_next_task(struct exynos_drm_ipp *ipp);
754 * exynos_drm_ipp_task_done - finish given task and set return code
755 * @task: ipp task to finish
756 * @ret: error code or 0 if operation has been performed successfully
758 void exynos_drm_ipp_task_done(struct exynos_drm_ipp_task *task, int ret)
760 struct exynos_drm_ipp *ipp = task->ipp;
763 DRM_DEV_DEBUG_DRIVER(task->dev, "ipp: %d, task %pK done: %d\n",
766 spin_lock_irqsave(&ipp->lock, flags);
767 if (ipp->task == task)
769 task->flags |= DRM_EXYNOS_IPP_TASK_DONE;
771 spin_unlock_irqrestore(&ipp->lock, flags);
773 exynos_drm_ipp_next_task(ipp);
774 wake_up(&ipp->done_wq);
776 if (task->flags & DRM_EXYNOS_IPP_TASK_ASYNC) {
777 INIT_WORK(&task->cleanup_work, exynos_drm_ipp_cleanup_work);
778 schedule_work(&task->cleanup_work);
782 static void exynos_drm_ipp_next_task(struct exynos_drm_ipp *ipp)
784 struct exynos_drm_ipp_task *task;
788 DRM_DEV_DEBUG_DRIVER(ipp->dev, "ipp: %d, try to run new task\n",
791 spin_lock_irqsave(&ipp->lock, flags);
793 if (ipp->task || list_empty(&ipp->todo_list)) {
794 spin_unlock_irqrestore(&ipp->lock, flags);
798 task = list_first_entry(&ipp->todo_list, struct exynos_drm_ipp_task,
800 list_del_init(&task->head);
803 spin_unlock_irqrestore(&ipp->lock, flags);
805 DRM_DEV_DEBUG_DRIVER(ipp->dev,
806 "ipp: %d, selected task %pK to run\n", ipp->id,
809 ret = ipp->funcs->commit(ipp, task);
811 exynos_drm_ipp_task_done(task, ret);
814 static void exynos_drm_ipp_schedule_task(struct exynos_drm_ipp *ipp,
815 struct exynos_drm_ipp_task *task)
819 spin_lock_irqsave(&ipp->lock, flags);
820 list_add(&task->head, &ipp->todo_list);
821 spin_unlock_irqrestore(&ipp->lock, flags);
823 exynos_drm_ipp_next_task(ipp);
826 static void exynos_drm_ipp_task_abort(struct exynos_drm_ipp *ipp,
827 struct exynos_drm_ipp_task *task)
831 spin_lock_irqsave(&ipp->lock, flags);
832 if (task->flags & DRM_EXYNOS_IPP_TASK_DONE) {
833 /* already completed task */
834 exynos_drm_ipp_task_cleanup(task);
835 } else if (ipp->task != task) {
836 /* task has not been scheduled for execution yet */
837 list_del_init(&task->head);
838 exynos_drm_ipp_task_cleanup(task);
841 * currently processed task, call abort() and perform
842 * cleanup with async worker
844 task->flags |= DRM_EXYNOS_IPP_TASK_ASYNC;
845 spin_unlock_irqrestore(&ipp->lock, flags);
846 if (ipp->funcs->abort)
847 ipp->funcs->abort(ipp, task);
850 spin_unlock_irqrestore(&ipp->lock, flags);
854 * exynos_drm_ipp_commit_ioctl - perform image processing operation
857 * @file_priv: DRM file info
859 * Construct a ipp task from the set of properties provided from the user
860 * and try to schedule it to framebuffer processor hardware.
862 * Called by the user via ioctl.
865 * Zero on success, negative errno on failure.
867 int exynos_drm_ipp_commit_ioctl(struct drm_device *dev, void *data,
868 struct drm_file *file_priv)
870 struct drm_exynos_ioctl_ipp_commit *arg = data;
871 struct exynos_drm_ipp *ipp;
872 struct exynos_drm_ipp_task *task;
875 if ((arg->flags & ~DRM_EXYNOS_IPP_FLAGS) || arg->reserved)
878 /* can't test and expect an event at the same time */
879 if ((arg->flags & DRM_EXYNOS_IPP_FLAG_TEST_ONLY) &&
880 (arg->flags & DRM_EXYNOS_IPP_FLAG_EVENT))
883 ipp = __ipp_get(arg->ipp_id);
887 task = exynos_drm_ipp_task_alloc(ipp);
891 ret = exynos_drm_ipp_task_set(task, arg);
895 ret = exynos_drm_ipp_task_check(task);
899 ret = exynos_drm_ipp_task_setup_buffers(task, file_priv);
900 if (ret || arg->flags & DRM_EXYNOS_IPP_FLAG_TEST_ONLY)
903 if (arg->flags & DRM_EXYNOS_IPP_FLAG_EVENT) {
904 ret = exynos_drm_ipp_event_create(task, file_priv,
911 * Queue task for processing on the hardware. task object will be
912 * then freed after exynos_drm_ipp_task_done()
914 if (arg->flags & DRM_EXYNOS_IPP_FLAG_NONBLOCK) {
915 DRM_DEV_DEBUG_DRIVER(ipp->dev,
916 "ipp: %d, nonblocking processing task %pK\n",
919 task->flags |= DRM_EXYNOS_IPP_TASK_ASYNC;
920 exynos_drm_ipp_schedule_task(task->ipp, task);
923 DRM_DEV_DEBUG_DRIVER(ipp->dev, "ipp: %d, processing task %pK\n",
925 exynos_drm_ipp_schedule_task(ipp, task);
926 ret = wait_event_interruptible(ipp->done_wq,
927 task->flags & DRM_EXYNOS_IPP_TASK_DONE);
929 exynos_drm_ipp_task_abort(ipp, task);
931 ret = exynos_drm_ipp_task_cleanup(task);
935 exynos_drm_ipp_task_free(ipp, task);