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.
21 #include <drm/drm_mode.h>
22 #include <uapi/drm/exynos_drm.h>
24 #include "exynos_drm_drv.h"
25 #include "exynos_drm_gem.h"
26 #include "exynos_drm_ipp.h"
29 static LIST_HEAD(ipp_list);
32 * exynos_drm_ipp_register - Register a new picture processor hardware module
34 * @ipp: ipp module to init
35 * @funcs: callbacks for the new ipp object
36 * @caps: bitmask of ipp capabilities (%DRM_EXYNOS_IPP_CAP_*)
37 * @formats: array of supported formats
38 * @num_formats: size of the supported formats array
39 * @name: name (for debugging purposes)
41 * Initializes a ipp module.
44 * Zero on success, error code on failure.
46 int exynos_drm_ipp_register(struct drm_device *dev, struct exynos_drm_ipp *ipp,
47 const struct exynos_drm_ipp_funcs *funcs, unsigned int caps,
48 const struct exynos_drm_ipp_formats *formats,
49 unsigned int num_formats, const char *name)
54 WARN_ON(!num_formats);
56 spin_lock_init(&ipp->lock);
57 INIT_LIST_HEAD(&ipp->todo_list);
58 init_waitqueue_head(&ipp->done_wq);
61 ipp->capabilities = caps;
63 ipp->formats = formats;
64 ipp->num_formats = num_formats;
66 /* ipp_list modification is serialized by component framework */
67 list_add_tail(&ipp->head, &ipp_list);
70 DRM_DEBUG_DRIVER("Registered ipp %d\n", ipp->id);
76 * exynos_drm_ipp_unregister - Unregister the picture processor module
80 void exynos_drm_ipp_unregister(struct drm_device *dev,
81 struct exynos_drm_ipp *ipp)
84 WARN_ON(!list_empty(&ipp->todo_list));
89 * exynos_drm_ipp_ioctl_get_res_ioctl - enumerate all ipp modules
92 * @file_priv: DRM file info
94 * Construct a list of ipp ids.
96 * Called by the user via ioctl.
99 * Zero on success, negative errno on failure.
101 int exynos_drm_ipp_get_res_ioctl(struct drm_device *dev, void *data,
102 struct drm_file *file_priv)
104 struct drm_exynos_ioctl_ipp_get_res *resp = data;
105 struct exynos_drm_ipp *ipp;
106 uint32_t __user *ipp_ptr = (uint32_t __user *)
107 (unsigned long)resp->ipp_id_ptr;
108 unsigned int count = num_ipp, copied = 0;
111 * This ioctl is called twice, once to determine how much space is
112 * needed, and the 2nd time to fill it.
114 if (count && resp->count_ipps >= count) {
115 list_for_each_entry(ipp, &ipp_list, head) {
116 if (put_user(ipp->id, ipp_ptr + copied))
121 resp->count_ipps = count;
126 static inline struct exynos_drm_ipp *__ipp_get(uint32_t id)
128 struct exynos_drm_ipp *ipp;
130 list_for_each_entry(ipp, &ipp_list, head)
137 * exynos_drm_ipp_ioctl_get_caps - get ipp module capabilities and formats
140 * @file_priv: DRM file info
142 * Construct a structure describing ipp module capabilities.
144 * Called by the user via ioctl.
147 * Zero on success, negative errno on failure.
149 int exynos_drm_ipp_get_caps_ioctl(struct drm_device *dev, void *data,
150 struct drm_file *file_priv)
152 struct drm_exynos_ioctl_ipp_get_caps *resp = data;
153 void __user *ptr = (void __user *)(unsigned long)resp->formats_ptr;
154 struct exynos_drm_ipp *ipp;
157 ipp = __ipp_get(resp->ipp_id);
161 resp->ipp_id = ipp->id;
162 resp->capabilities = ipp->capabilities;
165 * This ioctl is called twice, once to determine how much space is
166 * needed, and the 2nd time to fill it.
168 if (resp->formats_count >= ipp->num_formats) {
169 for (i = 0; i < ipp->num_formats; i++) {
170 struct drm_exynos_ipp_format tmp = {
171 .fourcc = ipp->formats[i].fourcc,
172 .type = ipp->formats[i].type,
173 .modifier = ipp->formats[i].modifier,
176 if (copy_to_user(ptr, &tmp, sizeof(tmp)))
181 resp->formats_count = ipp->num_formats;
186 static inline const struct exynos_drm_ipp_formats *__ipp_format_get(
187 struct exynos_drm_ipp *ipp, uint32_t fourcc,
188 uint64_t mod, unsigned int type)
192 for (i = 0; i < ipp->num_formats; i++) {
193 if ((ipp->formats[i].type & type) &&
194 ipp->formats[i].fourcc == fourcc &&
195 ipp->formats[i].modifier == mod)
196 return &ipp->formats[i];
202 * exynos_drm_ipp_get_limits_ioctl - get ipp module limits
205 * @file_priv: DRM file info
207 * Construct a structure describing ipp module limitations for provided
210 * Called by the user via ioctl.
213 * Zero on success, negative errno on failure.
215 int exynos_drm_ipp_get_limits_ioctl(struct drm_device *dev, void *data,
216 struct drm_file *file_priv)
218 struct drm_exynos_ioctl_ipp_get_limits *resp = data;
219 void __user *ptr = (void __user *)(unsigned long)resp->limits_ptr;
220 const struct exynos_drm_ipp_formats *format;
221 struct exynos_drm_ipp *ipp;
223 if (resp->type != DRM_EXYNOS_IPP_FORMAT_SOURCE &&
224 resp->type != DRM_EXYNOS_IPP_FORMAT_DESTINATION)
227 ipp = __ipp_get(resp->ipp_id);
231 format = __ipp_format_get(ipp, resp->fourcc, resp->modifier,
237 * This ioctl is called twice, once to determine how much space is
238 * needed, and the 2nd time to fill it.
240 if (format->num_limits && resp->limits_count >= format->num_limits)
241 if (copy_to_user((void __user *)ptr, format->limits,
242 sizeof(*format->limits) * format->num_limits))
244 resp->limits_count = format->num_limits;
249 struct drm_pending_exynos_ipp_event {
250 struct drm_pending_event base;
251 struct drm_exynos_ipp_event event;
254 static inline struct exynos_drm_ipp_task *
255 exynos_drm_ipp_task_alloc(struct exynos_drm_ipp *ipp)
257 struct exynos_drm_ipp_task *task;
259 task = kzalloc(sizeof(*task), GFP_KERNEL);
263 task->dev = ipp->dev;
267 task->src.rect.w = task->dst.rect.w = UINT_MAX;
268 task->src.rect.h = task->dst.rect.h = UINT_MAX;
269 task->transform.rotation = DRM_MODE_ROTATE_0;
271 DRM_DEBUG_DRIVER("Allocated task %pK\n", task);
276 static const struct exynos_drm_param_map {
280 } exynos_drm_ipp_params_maps[] = {
282 DRM_EXYNOS_IPP_TASK_BUFFER | DRM_EXYNOS_IPP_TASK_TYPE_SOURCE,
283 sizeof(struct drm_exynos_ipp_task_buffer),
284 offsetof(struct exynos_drm_ipp_task, src.buf),
286 DRM_EXYNOS_IPP_TASK_BUFFER |
287 DRM_EXYNOS_IPP_TASK_TYPE_DESTINATION,
288 sizeof(struct drm_exynos_ipp_task_buffer),
289 offsetof(struct exynos_drm_ipp_task, dst.buf),
291 DRM_EXYNOS_IPP_TASK_RECTANGLE | DRM_EXYNOS_IPP_TASK_TYPE_SOURCE,
292 sizeof(struct drm_exynos_ipp_task_rect),
293 offsetof(struct exynos_drm_ipp_task, src.rect),
295 DRM_EXYNOS_IPP_TASK_RECTANGLE |
296 DRM_EXYNOS_IPP_TASK_TYPE_DESTINATION,
297 sizeof(struct drm_exynos_ipp_task_rect),
298 offsetof(struct exynos_drm_ipp_task, dst.rect),
300 DRM_EXYNOS_IPP_TASK_TRANSFORM,
301 sizeof(struct drm_exynos_ipp_task_transform),
302 offsetof(struct exynos_drm_ipp_task, transform),
304 DRM_EXYNOS_IPP_TASK_ALPHA,
305 sizeof(struct drm_exynos_ipp_task_alpha),
306 offsetof(struct exynos_drm_ipp_task, alpha),
310 static int exynos_drm_ipp_task_set(struct exynos_drm_ipp_task *task,
311 struct drm_exynos_ioctl_ipp_commit *arg)
313 const struct exynos_drm_param_map *map = exynos_drm_ipp_params_maps;
314 void __user *params = (void __user *)(unsigned long)arg->params_ptr;
315 unsigned int size = arg->params_size;
320 if (get_user(id, (uint32_t __user *)params))
323 for (i = 0; i < ARRAY_SIZE(exynos_drm_ipp_params_maps); i++)
326 if (i == ARRAY_SIZE(exynos_drm_ipp_params_maps) ||
330 if (copy_from_user((void *)task + map[i].offset, params,
334 params += map[i].size;
338 DRM_DEBUG_DRIVER("Got task %pK configuration from userspace\n", task);
342 static int exynos_drm_ipp_task_setup_buffer(struct exynos_drm_ipp_buffer *buf,
343 struct drm_file *filp)
349 if (buf->buf.width == 0 || buf->buf.height == 0)
351 buf->format = drm_format_info(buf->buf.fourcc);
352 for (i = 0; i < buf->format->num_planes; i++) {
353 unsigned int width = (i == 0) ? buf->buf.width :
354 DIV_ROUND_UP(buf->buf.width, buf->format->hsub);
356 if (buf->buf.pitch[i] == 0)
357 buf->buf.pitch[i] = width * buf->format->cpp[i];
358 if (buf->buf.pitch[i] < width * buf->format->cpp[i])
360 if (!buf->buf.gem_id[i])
364 /* pitch for additional planes must match */
365 if (buf->format->num_planes > 2 &&
366 buf->buf.pitch[1] != buf->buf.pitch[2])
369 /* get GEM buffers and check their size */
370 for (i = 0; i < buf->format->num_planes; i++) {
371 unsigned int height = (i == 0) ? buf->buf.height :
372 DIV_ROUND_UP(buf->buf.height, buf->format->vsub);
373 unsigned long size = height * buf->buf.pitch[i];
374 struct drm_gem_object *obj = drm_gem_object_lookup(filp,
380 buf->exynos_gem[i] = to_exynos_gem(obj);
382 if (size + buf->buf.offset[i] > buf->exynos_gem[i]->size) {
387 buf->dma_addr[i] = buf->exynos_gem[i]->dma_addr +
394 drm_gem_object_put_unlocked(&buf->exynos_gem[i]->base);
395 buf->exynos_gem[i] = NULL;
400 static void exynos_drm_ipp_task_release_buf(struct exynos_drm_ipp_buffer *buf)
404 if (!buf->exynos_gem[0])
406 for (i = 0; i < buf->format->num_planes; i++)
407 drm_gem_object_put_unlocked(&buf->exynos_gem[i]->base);
410 static void exynos_drm_ipp_task_free(struct exynos_drm_ipp *ipp,
411 struct exynos_drm_ipp_task *task)
413 DRM_DEBUG_DRIVER("Freeing task %pK\n", task);
415 exynos_drm_ipp_task_release_buf(&task->src);
416 exynos_drm_ipp_task_release_buf(&task->dst);
418 drm_event_cancel_free(ipp->dev, &task->event->base);
422 struct drm_ipp_limit {
423 struct drm_exynos_ipp_limit_val h;
424 struct drm_exynos_ipp_limit_val v;
427 enum drm_ipp_size_id {
428 IPP_LIMIT_BUFFER, IPP_LIMIT_AREA, IPP_LIMIT_ROTATED, IPP_LIMIT_MAX
431 static const enum drm_ipp_size_id limit_id_fallback[IPP_LIMIT_MAX][4] = {
432 [IPP_LIMIT_BUFFER] = { DRM_EXYNOS_IPP_LIMIT_SIZE_BUFFER },
433 [IPP_LIMIT_AREA] = { DRM_EXYNOS_IPP_LIMIT_SIZE_AREA,
434 DRM_EXYNOS_IPP_LIMIT_SIZE_BUFFER },
435 [IPP_LIMIT_ROTATED] = { DRM_EXYNOS_IPP_LIMIT_SIZE_ROTATED,
436 DRM_EXYNOS_IPP_LIMIT_SIZE_AREA,
437 DRM_EXYNOS_IPP_LIMIT_SIZE_BUFFER },
440 static inline void __limit_set_val(unsigned int *ptr, unsigned int val)
446 static void __get_size_limit(const struct drm_exynos_ipp_limit *limits,
447 unsigned int num_limits, enum drm_ipp_size_id id,
448 struct drm_ipp_limit *res)
450 const struct drm_exynos_ipp_limit *l = limits;
453 memset(res, 0, sizeof(*res));
454 for (i = 0; limit_id_fallback[id][i]; i++)
455 for (l = limits; l - limits < num_limits; l++) {
456 if (((l->type & DRM_EXYNOS_IPP_LIMIT_TYPE_MASK) !=
457 DRM_EXYNOS_IPP_LIMIT_TYPE_SIZE) ||
458 ((l->type & DRM_EXYNOS_IPP_LIMIT_SIZE_MASK) !=
459 limit_id_fallback[id][i]))
461 __limit_set_val(&res->h.min, l->h.min);
462 __limit_set_val(&res->h.max, l->h.max);
463 __limit_set_val(&res->h.align, l->h.align);
464 __limit_set_val(&res->v.min, l->v.min);
465 __limit_set_val(&res->v.max, l->v.max);
466 __limit_set_val(&res->v.align, l->v.align);
470 static inline bool __align_check(unsigned int val, unsigned int align)
472 if (align && (val & (align - 1))) {
473 DRM_DEBUG_DRIVER("Value %d exceeds HW limits (align %d)\n",
480 static inline bool __size_limit_check(unsigned int val,
481 struct drm_exynos_ipp_limit_val *l)
483 if ((l->min && val < l->min) || (l->max && val > l->max)) {
484 DRM_DEBUG_DRIVER("Value %d exceeds HW limits (min %d, max %d)\n",
485 val, l->min, l->max);
488 return __align_check(val, l->align);
491 static int exynos_drm_ipp_check_size_limits(struct exynos_drm_ipp_buffer *buf,
492 const struct drm_exynos_ipp_limit *limits, unsigned int num_limits,
493 bool rotate, bool swap)
495 enum drm_ipp_size_id id = rotate ? IPP_LIMIT_ROTATED : IPP_LIMIT_AREA;
496 struct drm_ipp_limit l;
497 struct drm_exynos_ipp_limit_val *lh = &l.h, *lv = &l.v;
502 __get_size_limit(limits, num_limits, IPP_LIMIT_BUFFER, &l);
503 if (!__size_limit_check(buf->buf.width, &l.h) ||
504 !__size_limit_check(buf->buf.height, &l.v))
511 __get_size_limit(limits, num_limits, id, &l);
512 if (!__size_limit_check(buf->rect.w, lh) ||
513 !__align_check(buf->rect.x, lh->align) ||
514 !__size_limit_check(buf->rect.h, lv) ||
515 !__align_check(buf->rect.y, lv->align))
521 static inline bool __scale_limit_check(unsigned int src, unsigned int dst,
522 unsigned int min, unsigned int max)
524 if ((max && (dst << 16) > src * max) ||
525 (min && (dst << 16) < src * min)) {
526 DRM_DEBUG_DRIVER("Scale from %d to %d exceeds HW limits (ratio min %d.%05d, max %d.%05d)\n",
528 min >> 16, 100000 * (min & 0xffff) / (1 << 16),
529 max >> 16, 100000 * (max & 0xffff) / (1 << 16));
535 static int exynos_drm_ipp_check_scale_limits(
536 struct drm_exynos_ipp_task_rect *src,
537 struct drm_exynos_ipp_task_rect *dst,
538 const struct drm_exynos_ipp_limit *limits,
539 unsigned int num_limits, bool swap)
541 const struct drm_exynos_ipp_limit_val *lh, *lv;
544 for (; num_limits; limits++, num_limits--)
545 if ((limits->type & DRM_EXYNOS_IPP_LIMIT_TYPE_MASK) ==
546 DRM_EXYNOS_IPP_LIMIT_TYPE_SCALE)
551 lh = (!swap) ? &limits->h : &limits->v;
552 lv = (!swap) ? &limits->v : &limits->h;
553 dw = (!swap) ? dst->w : dst->h;
554 dh = (!swap) ? dst->h : dst->w;
556 if (!__scale_limit_check(src->w, dw, lh->min, lh->max) ||
557 !__scale_limit_check(src->h, dh, lv->min, lv->max))
563 static int exynos_drm_ipp_task_check(struct exynos_drm_ipp_task *task)
565 struct exynos_drm_ipp *ipp = task->ipp;
566 const struct exynos_drm_ipp_formats *src_fmt, *dst_fmt;
567 struct exynos_drm_ipp_buffer *src = &task->src, *dst = &task->dst;
568 unsigned int rotation = task->transform.rotation;
570 bool swap = drm_rotation_90_or_270(rotation);
571 bool rotate = (rotation != DRM_MODE_ROTATE_0);
574 DRM_DEBUG_DRIVER("Checking task %pK\n", task);
576 if (src->rect.w == UINT_MAX)
577 src->rect.w = src->buf.width;
578 if (src->rect.h == UINT_MAX)
579 src->rect.h = src->buf.height;
580 if (dst->rect.w == UINT_MAX)
581 dst->rect.w = dst->buf.width;
582 if (dst->rect.h == UINT_MAX)
583 dst->rect.h = dst->buf.height;
585 if (src->rect.x + src->rect.w > (src->buf.width) ||
586 src->rect.y + src->rect.h > (src->buf.height) ||
587 dst->rect.x + dst->rect.w > (dst->buf.width) ||
588 dst->rect.y + dst->rect.h > (dst->buf.height)) {
589 DRM_DEBUG_DRIVER("Task %pK: defined area is outside provided buffers\n",
594 if ((!swap && (src->rect.w != dst->rect.w ||
595 src->rect.h != dst->rect.h)) ||
596 (swap && (src->rect.w != dst->rect.h ||
597 src->rect.h != dst->rect.w)))
600 if ((!(ipp->capabilities & DRM_EXYNOS_IPP_CAP_CROP) &&
601 (src->rect.x || src->rect.y || dst->rect.x || dst->rect.y)) ||
602 (!(ipp->capabilities & DRM_EXYNOS_IPP_CAP_ROTATE) && rotate) ||
603 (!(ipp->capabilities & DRM_EXYNOS_IPP_CAP_SCALE) && scale) ||
604 (!(ipp->capabilities & DRM_EXYNOS_IPP_CAP_CONVERT) &&
605 src->buf.fourcc != dst->buf.fourcc)) {
606 DRM_DEBUG_DRIVER("Task %pK: hw capabilities exceeded\n", task);
610 src_fmt = __ipp_format_get(ipp, src->buf.fourcc, src->buf.modifier,
611 DRM_EXYNOS_IPP_FORMAT_SOURCE);
613 DRM_DEBUG_DRIVER("Task %pK: src format not supported\n", task);
616 ret = exynos_drm_ipp_check_size_limits(src, src_fmt->limits,
621 ret = exynos_drm_ipp_check_scale_limits(&src->rect, &dst->rect,
623 src_fmt->num_limits, swap);
627 dst_fmt = __ipp_format_get(ipp, dst->buf.fourcc, dst->buf.modifier,
628 DRM_EXYNOS_IPP_FORMAT_DESTINATION);
630 DRM_DEBUG_DRIVER("Task %pK: dst format not supported\n", task);
633 ret = exynos_drm_ipp_check_size_limits(dst, dst_fmt->limits,
638 ret = exynos_drm_ipp_check_scale_limits(&src->rect, &dst->rect,
640 dst_fmt->num_limits, swap);
644 DRM_DEBUG_DRIVER("Task %pK: all checks done.\n", task);
649 static int exynos_drm_ipp_task_setup_buffers(struct exynos_drm_ipp_task *task,
650 struct drm_file *filp)
652 struct exynos_drm_ipp_buffer *src = &task->src, *dst = &task->dst;
655 DRM_DEBUG_DRIVER("Setting buffer for task %pK\n", task);
657 ret = exynos_drm_ipp_task_setup_buffer(src, filp);
659 DRM_DEBUG_DRIVER("Task %pK: src buffer setup failed\n", task);
662 ret = exynos_drm_ipp_task_setup_buffer(dst, filp);
664 DRM_DEBUG_DRIVER("Task %pK: dst buffer setup failed\n", task);
668 DRM_DEBUG_DRIVER("Task %pK: buffers prepared.\n", task);
674 static int exynos_drm_ipp_event_create(struct exynos_drm_ipp_task *task,
675 struct drm_file *file_priv, uint64_t user_data)
677 struct drm_pending_exynos_ipp_event *e = NULL;
680 e = kzalloc(sizeof(*e), GFP_KERNEL);
684 e->event.base.type = DRM_EXYNOS_IPP_EVENT;
685 e->event.base.length = sizeof(e->event);
686 e->event.user_data = user_data;
688 ret = drm_event_reserve_init(task->dev, file_priv, &e->base,
700 static void exynos_drm_ipp_event_send(struct exynos_drm_ipp_task *task)
702 struct timespec64 now;
704 ktime_get_ts64(&now);
705 task->event->event.tv_sec = now.tv_sec;
706 task->event->event.tv_usec = now.tv_nsec / NSEC_PER_USEC;
707 task->event->event.sequence = atomic_inc_return(&task->ipp->sequence);
709 drm_send_event(task->dev, &task->event->base);
712 static int exynos_drm_ipp_task_cleanup(struct exynos_drm_ipp_task *task)
716 if (ret == 0 && task->event) {
717 exynos_drm_ipp_event_send(task);
718 /* ensure event won't be canceled on task free */
722 exynos_drm_ipp_task_free(task->ipp, task);
726 static void exynos_drm_ipp_cleanup_work(struct work_struct *work)
728 struct exynos_drm_ipp_task *task = container_of(work,
729 struct exynos_drm_ipp_task, cleanup_work);
731 exynos_drm_ipp_task_cleanup(task);
734 static void exynos_drm_ipp_next_task(struct exynos_drm_ipp *ipp);
737 * exynos_drm_ipp_task_done - finish given task and set return code
738 * @task: ipp task to finish
739 * @ret: error code or 0 if operation has been performed successfully
741 void exynos_drm_ipp_task_done(struct exynos_drm_ipp_task *task, int ret)
743 struct exynos_drm_ipp *ipp = task->ipp;
746 DRM_DEBUG_DRIVER("ipp: %d, task %pK done: %d\n", ipp->id, task, ret);
748 spin_lock_irqsave(&ipp->lock, flags);
749 if (ipp->task == task)
751 task->flags |= DRM_EXYNOS_IPP_TASK_DONE;
753 spin_unlock_irqrestore(&ipp->lock, flags);
755 exynos_drm_ipp_next_task(ipp);
756 wake_up(&ipp->done_wq);
758 if (task->flags & DRM_EXYNOS_IPP_TASK_ASYNC) {
759 INIT_WORK(&task->cleanup_work, exynos_drm_ipp_cleanup_work);
760 schedule_work(&task->cleanup_work);
764 static void exynos_drm_ipp_next_task(struct exynos_drm_ipp *ipp)
766 struct exynos_drm_ipp_task *task;
770 DRM_DEBUG_DRIVER("ipp: %d, try to run new task\n", ipp->id);
772 spin_lock_irqsave(&ipp->lock, flags);
774 if (ipp->task || list_empty(&ipp->todo_list)) {
775 spin_unlock_irqrestore(&ipp->lock, flags);
779 task = list_first_entry(&ipp->todo_list, struct exynos_drm_ipp_task,
781 list_del_init(&task->head);
784 spin_unlock_irqrestore(&ipp->lock, flags);
786 DRM_DEBUG_DRIVER("ipp: %d, selected task %pK to run\n", ipp->id, task);
788 ret = ipp->funcs->commit(ipp, task);
790 exynos_drm_ipp_task_done(task, ret);
793 static void exynos_drm_ipp_schedule_task(struct exynos_drm_ipp *ipp,
794 struct exynos_drm_ipp_task *task)
798 spin_lock_irqsave(&ipp->lock, flags);
799 list_add(&task->head, &ipp->todo_list);
800 spin_unlock_irqrestore(&ipp->lock, flags);
802 exynos_drm_ipp_next_task(ipp);
805 static void exynos_drm_ipp_task_abort(struct exynos_drm_ipp *ipp,
806 struct exynos_drm_ipp_task *task)
810 spin_lock_irqsave(&ipp->lock, flags);
811 if (task->flags & DRM_EXYNOS_IPP_TASK_DONE) {
812 /* already completed task */
813 exynos_drm_ipp_task_cleanup(task);
814 } else if (ipp->task != task) {
815 /* task has not been scheduled for execution yet */
816 list_del_init(&task->head);
817 exynos_drm_ipp_task_cleanup(task);
820 * currently processed task, call abort() and perform
821 * cleanup with async worker
823 task->flags |= DRM_EXYNOS_IPP_TASK_ASYNC;
824 spin_unlock_irqrestore(&ipp->lock, flags);
825 if (ipp->funcs->abort)
826 ipp->funcs->abort(ipp, task);
829 spin_unlock_irqrestore(&ipp->lock, flags);
833 * exynos_drm_ipp_commit_ioctl - perform image processing operation
836 * @file_priv: DRM file info
838 * Construct a ipp task from the set of properties provided from the user
839 * and try to schedule it to framebuffer processor hardware.
841 * Called by the user via ioctl.
844 * Zero on success, negative errno on failure.
846 int exynos_drm_ipp_commit_ioctl(struct drm_device *dev, void *data,
847 struct drm_file *file_priv)
849 struct drm_exynos_ioctl_ipp_commit *arg = data;
850 struct exynos_drm_ipp *ipp;
851 struct exynos_drm_ipp_task *task;
854 if ((arg->flags & ~DRM_EXYNOS_IPP_FLAGS) || arg->reserved)
857 /* can't test and expect an event at the same time */
858 if ((arg->flags & DRM_EXYNOS_IPP_FLAG_TEST_ONLY) &&
859 (arg->flags & DRM_EXYNOS_IPP_FLAG_EVENT))
862 ipp = __ipp_get(arg->ipp_id);
866 task = exynos_drm_ipp_task_alloc(ipp);
870 ret = exynos_drm_ipp_task_set(task, arg);
874 ret = exynos_drm_ipp_task_check(task);
878 ret = exynos_drm_ipp_task_setup_buffers(task, file_priv);
879 if (ret || arg->flags & DRM_EXYNOS_IPP_FLAG_TEST_ONLY)
882 if (arg->flags & DRM_EXYNOS_IPP_FLAG_EVENT) {
883 ret = exynos_drm_ipp_event_create(task, file_priv,
890 * Queue task for processing on the hardware. task object will be
891 * then freed after exynos_drm_ipp_task_done()
893 if (arg->flags & DRM_EXYNOS_IPP_FLAG_NONBLOCK) {
894 DRM_DEBUG_DRIVER("ipp: %d, nonblocking processing task %pK\n",
897 task->flags |= DRM_EXYNOS_IPP_TASK_ASYNC;
898 exynos_drm_ipp_schedule_task(task->ipp, task);
901 DRM_DEBUG_DRIVER("ipp: %d, processing task %pK\n", ipp->id,
903 exynos_drm_ipp_schedule_task(ipp, task);
904 ret = wait_event_interruptible(ipp->done_wq,
905 task->flags & DRM_EXYNOS_IPP_TASK_DONE);
907 exynos_drm_ipp_task_abort(ipp, task);
909 ret = exynos_drm_ipp_task_cleanup(task);
913 exynos_drm_ipp_task_free(ipp, task);