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 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_DEV_DEBUG_DRIVER(dev, "Registered ipp %d\n", ipp->id);
76 * exynos_drm_ipp_unregister - Unregister the picture processor module
80 void exynos_drm_ipp_unregister(struct 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_DEV_DEBUG_DRIVER(task->dev, "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_DEV_DEBUG_DRIVER(task->dev,
339 "Got task %pK configuration from userspace\n",
344 static int exynos_drm_ipp_task_setup_buffer(struct exynos_drm_ipp_buffer *buf,
345 struct drm_file *filp)
350 /* get GEM buffers and check their size */
351 for (i = 0; i < buf->format->num_planes; i++) {
352 unsigned int height = (i == 0) ? buf->buf.height :
353 DIV_ROUND_UP(buf->buf.height, buf->format->vsub);
354 unsigned long size = height * buf->buf.pitch[i];
355 struct exynos_drm_gem *gem = exynos_drm_gem_get(filp,
361 buf->exynos_gem[i] = gem;
363 if (size + buf->buf.offset[i] > buf->exynos_gem[i]->size) {
368 buf->dma_addr[i] = buf->exynos_gem[i]->dma_addr +
375 exynos_drm_gem_put(buf->exynos_gem[i]);
376 buf->exynos_gem[i] = NULL;
381 static void exynos_drm_ipp_task_release_buf(struct exynos_drm_ipp_buffer *buf)
385 if (!buf->exynos_gem[0])
387 for (i = 0; i < buf->format->num_planes; i++)
388 exynos_drm_gem_put(buf->exynos_gem[i]);
391 static void exynos_drm_ipp_task_free(struct exynos_drm_ipp *ipp,
392 struct exynos_drm_ipp_task *task)
394 DRM_DEV_DEBUG_DRIVER(task->dev, "Freeing task %pK\n", task);
396 exynos_drm_ipp_task_release_buf(&task->src);
397 exynos_drm_ipp_task_release_buf(&task->dst);
399 drm_event_cancel_free(ipp->drm_dev, &task->event->base);
403 struct drm_ipp_limit {
404 struct drm_exynos_ipp_limit_val h;
405 struct drm_exynos_ipp_limit_val v;
408 enum drm_ipp_size_id {
409 IPP_LIMIT_BUFFER, IPP_LIMIT_AREA, IPP_LIMIT_ROTATED, IPP_LIMIT_MAX
412 static const enum drm_exynos_ipp_limit_type limit_id_fallback[IPP_LIMIT_MAX][4] = {
413 [IPP_LIMIT_BUFFER] = { DRM_EXYNOS_IPP_LIMIT_SIZE_BUFFER },
414 [IPP_LIMIT_AREA] = { DRM_EXYNOS_IPP_LIMIT_SIZE_AREA,
415 DRM_EXYNOS_IPP_LIMIT_SIZE_BUFFER },
416 [IPP_LIMIT_ROTATED] = { DRM_EXYNOS_IPP_LIMIT_SIZE_ROTATED,
417 DRM_EXYNOS_IPP_LIMIT_SIZE_AREA,
418 DRM_EXYNOS_IPP_LIMIT_SIZE_BUFFER },
421 static inline void __limit_set_val(unsigned int *ptr, unsigned int val)
427 static void __get_size_limit(const struct drm_exynos_ipp_limit *limits,
428 unsigned int num_limits, enum drm_ipp_size_id id,
429 struct drm_ipp_limit *res)
431 const struct drm_exynos_ipp_limit *l = limits;
434 memset(res, 0, sizeof(*res));
435 for (i = 0; limit_id_fallback[id][i]; i++)
436 for (l = limits; l - limits < num_limits; l++) {
437 if (((l->type & DRM_EXYNOS_IPP_LIMIT_TYPE_MASK) !=
438 DRM_EXYNOS_IPP_LIMIT_TYPE_SIZE) ||
439 ((l->type & DRM_EXYNOS_IPP_LIMIT_SIZE_MASK) !=
440 limit_id_fallback[id][i]))
442 __limit_set_val(&res->h.min, l->h.min);
443 __limit_set_val(&res->h.max, l->h.max);
444 __limit_set_val(&res->h.align, l->h.align);
445 __limit_set_val(&res->v.min, l->v.min);
446 __limit_set_val(&res->v.max, l->v.max);
447 __limit_set_val(&res->v.align, l->v.align);
451 static inline bool __align_check(unsigned int val, unsigned int align)
453 if (align && (val & (align - 1))) {
454 DRM_DEBUG_DRIVER("Value %d exceeds HW limits (align %d)\n",
461 static inline bool __size_limit_check(unsigned int val,
462 struct drm_exynos_ipp_limit_val *l)
464 if ((l->min && val < l->min) || (l->max && val > l->max)) {
465 DRM_DEBUG_DRIVER("Value %d exceeds HW limits (min %d, max %d)\n",
466 val, l->min, l->max);
469 return __align_check(val, l->align);
472 static int exynos_drm_ipp_check_size_limits(struct exynos_drm_ipp_buffer *buf,
473 const struct drm_exynos_ipp_limit *limits, unsigned int num_limits,
474 bool rotate, bool swap)
476 enum drm_ipp_size_id id = rotate ? IPP_LIMIT_ROTATED : IPP_LIMIT_AREA;
477 struct drm_ipp_limit l;
478 struct drm_exynos_ipp_limit_val *lh = &l.h, *lv = &l.v;
479 int real_width = buf->buf.pitch[0] / buf->format->cpp[0];
484 __get_size_limit(limits, num_limits, IPP_LIMIT_BUFFER, &l);
485 if (!__size_limit_check(real_width, &l.h) ||
486 !__size_limit_check(buf->buf.height, &l.v))
493 __get_size_limit(limits, num_limits, id, &l);
494 if (!__size_limit_check(buf->rect.w, lh) ||
495 !__align_check(buf->rect.x, lh->align) ||
496 !__size_limit_check(buf->rect.h, lv) ||
497 !__align_check(buf->rect.y, lv->align))
503 static inline bool __scale_limit_check(unsigned int src, unsigned int dst,
504 unsigned int min, unsigned int max)
506 if ((max && (dst << 16) > src * max) ||
507 (min && (dst << 16) < src * min)) {
508 DRM_DEBUG_DRIVER("Scale from %d to %d exceeds HW limits (ratio min %d.%05d, max %d.%05d)\n",
510 min >> 16, 100000 * (min & 0xffff) / (1 << 16),
511 max >> 16, 100000 * (max & 0xffff) / (1 << 16));
517 static int exynos_drm_ipp_check_scale_limits(
518 struct drm_exynos_ipp_task_rect *src,
519 struct drm_exynos_ipp_task_rect *dst,
520 const struct drm_exynos_ipp_limit *limits,
521 unsigned int num_limits, bool swap)
523 const struct drm_exynos_ipp_limit_val *lh, *lv;
526 for (; num_limits; limits++, num_limits--)
527 if ((limits->type & DRM_EXYNOS_IPP_LIMIT_TYPE_MASK) ==
528 DRM_EXYNOS_IPP_LIMIT_TYPE_SCALE)
533 lh = (!swap) ? &limits->h : &limits->v;
534 lv = (!swap) ? &limits->v : &limits->h;
535 dw = (!swap) ? dst->w : dst->h;
536 dh = (!swap) ? dst->h : dst->w;
538 if (!__scale_limit_check(src->w, dw, lh->min, lh->max) ||
539 !__scale_limit_check(src->h, dh, lv->min, lv->max))
545 static int exynos_drm_ipp_check_format(struct exynos_drm_ipp_task *task,
546 struct exynos_drm_ipp_buffer *buf,
547 struct exynos_drm_ipp_buffer *src,
548 struct exynos_drm_ipp_buffer *dst,
549 bool rotate, bool swap)
551 const struct exynos_drm_ipp_formats *fmt;
554 fmt = __ipp_format_get(task->ipp, buf->buf.fourcc, buf->buf.modifier,
555 buf == src ? DRM_EXYNOS_IPP_FORMAT_SOURCE :
556 DRM_EXYNOS_IPP_FORMAT_DESTINATION);
558 DRM_DEV_DEBUG_DRIVER(task->dev,
559 "Task %pK: %s format not supported\n",
560 task, buf == src ? "src" : "dst");
565 if (buf->buf.width == 0 || buf->buf.height == 0)
568 buf->format = drm_format_info(buf->buf.fourcc);
569 for (i = 0; i < buf->format->num_planes; i++) {
570 unsigned int width = (i == 0) ? buf->buf.width :
571 DIV_ROUND_UP(buf->buf.width, buf->format->hsub);
573 if (buf->buf.pitch[i] == 0)
574 buf->buf.pitch[i] = width * buf->format->cpp[i];
575 if (buf->buf.pitch[i] < width * buf->format->cpp[i])
577 if (!buf->buf.gem_id[i])
581 /* pitch for additional planes must match */
582 if (buf->format->num_planes > 2 &&
583 buf->buf.pitch[1] != buf->buf.pitch[2])
586 /* check driver limits */
587 ret = exynos_drm_ipp_check_size_limits(buf, fmt->limits,
590 buf == dst ? swap : false);
593 ret = exynos_drm_ipp_check_scale_limits(&src->rect, &dst->rect,
595 fmt->num_limits, swap);
599 static int exynos_drm_ipp_task_check(struct exynos_drm_ipp_task *task)
601 struct exynos_drm_ipp *ipp = task->ipp;
602 struct exynos_drm_ipp_buffer *src = &task->src, *dst = &task->dst;
603 unsigned int rotation = task->transform.rotation;
605 bool swap = drm_rotation_90_or_270(rotation);
606 bool rotate = (rotation != DRM_MODE_ROTATE_0);
609 DRM_DEV_DEBUG_DRIVER(task->dev, "Checking task %pK\n", task);
611 if (src->rect.w == UINT_MAX)
612 src->rect.w = src->buf.width;
613 if (src->rect.h == UINT_MAX)
614 src->rect.h = src->buf.height;
615 if (dst->rect.w == UINT_MAX)
616 dst->rect.w = dst->buf.width;
617 if (dst->rect.h == UINT_MAX)
618 dst->rect.h = dst->buf.height;
620 if (src->rect.x + src->rect.w > (src->buf.width) ||
621 src->rect.y + src->rect.h > (src->buf.height) ||
622 dst->rect.x + dst->rect.w > (dst->buf.width) ||
623 dst->rect.y + dst->rect.h > (dst->buf.height)) {
624 DRM_DEV_DEBUG_DRIVER(task->dev,
625 "Task %pK: defined area is outside provided buffers\n",
630 if ((!swap && (src->rect.w != dst->rect.w ||
631 src->rect.h != dst->rect.h)) ||
632 (swap && (src->rect.w != dst->rect.h ||
633 src->rect.h != dst->rect.w)))
636 if ((!(ipp->capabilities & DRM_EXYNOS_IPP_CAP_CROP) &&
637 (src->rect.x || src->rect.y || dst->rect.x || dst->rect.y)) ||
638 (!(ipp->capabilities & DRM_EXYNOS_IPP_CAP_ROTATE) && rotate) ||
639 (!(ipp->capabilities & DRM_EXYNOS_IPP_CAP_SCALE) && scale) ||
640 (!(ipp->capabilities & DRM_EXYNOS_IPP_CAP_CONVERT) &&
641 src->buf.fourcc != dst->buf.fourcc)) {
642 DRM_DEV_DEBUG_DRIVER(task->dev, "Task %pK: hw capabilities exceeded\n",
647 ret = exynos_drm_ipp_check_format(task, src, src, dst, rotate, swap);
651 ret = exynos_drm_ipp_check_format(task, dst, src, dst, false, swap);
655 DRM_DEV_DEBUG_DRIVER(ipp->dev, "Task %pK: all checks done.\n",
661 static int exynos_drm_ipp_task_setup_buffers(struct exynos_drm_ipp_task *task,
662 struct drm_file *filp)
664 struct exynos_drm_ipp_buffer *src = &task->src, *dst = &task->dst;
667 DRM_DEV_DEBUG_DRIVER(task->dev, "Setting buffer for task %pK\n",
670 ret = exynos_drm_ipp_task_setup_buffer(src, filp);
672 DRM_DEV_DEBUG_DRIVER(task->dev,
673 "Task %pK: src buffer setup failed\n",
677 ret = exynos_drm_ipp_task_setup_buffer(dst, filp);
679 DRM_DEV_DEBUG_DRIVER(task->dev,
680 "Task %pK: dst buffer setup failed\n",
685 DRM_DEV_DEBUG_DRIVER(task->dev, "Task %pK: buffers prepared.\n",
692 static int exynos_drm_ipp_event_create(struct exynos_drm_ipp_task *task,
693 struct drm_file *file_priv, uint64_t user_data)
695 struct drm_pending_exynos_ipp_event *e = NULL;
698 e = kzalloc(sizeof(*e), GFP_KERNEL);
702 e->event.base.type = DRM_EXYNOS_IPP_EVENT;
703 e->event.base.length = sizeof(e->event);
704 e->event.user_data = user_data;
706 ret = drm_event_reserve_init(task->ipp->drm_dev, file_priv, &e->base,
718 static void exynos_drm_ipp_event_send(struct exynos_drm_ipp_task *task)
720 struct timespec64 now;
722 ktime_get_ts64(&now);
723 task->event->event.tv_sec = now.tv_sec;
724 task->event->event.tv_usec = now.tv_nsec / NSEC_PER_USEC;
725 task->event->event.sequence = atomic_inc_return(&task->ipp->sequence);
727 drm_send_event(task->ipp->drm_dev, &task->event->base);
730 static int exynos_drm_ipp_task_cleanup(struct exynos_drm_ipp_task *task)
734 if (ret == 0 && task->event) {
735 exynos_drm_ipp_event_send(task);
736 /* ensure event won't be canceled on task free */
740 exynos_drm_ipp_task_free(task->ipp, task);
744 static void exynos_drm_ipp_cleanup_work(struct work_struct *work)
746 struct exynos_drm_ipp_task *task = container_of(work,
747 struct exynos_drm_ipp_task, cleanup_work);
749 exynos_drm_ipp_task_cleanup(task);
752 static void exynos_drm_ipp_next_task(struct exynos_drm_ipp *ipp);
755 * exynos_drm_ipp_task_done - finish given task and set return code
756 * @task: ipp task to finish
757 * @ret: error code or 0 if operation has been performed successfully
759 void exynos_drm_ipp_task_done(struct exynos_drm_ipp_task *task, int ret)
761 struct exynos_drm_ipp *ipp = task->ipp;
764 DRM_DEV_DEBUG_DRIVER(task->dev, "ipp: %d, task %pK done: %d\n",
767 spin_lock_irqsave(&ipp->lock, flags);
768 if (ipp->task == task)
770 task->flags |= DRM_EXYNOS_IPP_TASK_DONE;
772 spin_unlock_irqrestore(&ipp->lock, flags);
774 exynos_drm_ipp_next_task(ipp);
775 wake_up(&ipp->done_wq);
777 if (task->flags & DRM_EXYNOS_IPP_TASK_ASYNC) {
778 INIT_WORK(&task->cleanup_work, exynos_drm_ipp_cleanup_work);
779 schedule_work(&task->cleanup_work);
783 static void exynos_drm_ipp_next_task(struct exynos_drm_ipp *ipp)
785 struct exynos_drm_ipp_task *task;
789 DRM_DEV_DEBUG_DRIVER(ipp->dev, "ipp: %d, try to run new task\n",
792 spin_lock_irqsave(&ipp->lock, flags);
794 if (ipp->task || list_empty(&ipp->todo_list)) {
795 spin_unlock_irqrestore(&ipp->lock, flags);
799 task = list_first_entry(&ipp->todo_list, struct exynos_drm_ipp_task,
801 list_del_init(&task->head);
804 spin_unlock_irqrestore(&ipp->lock, flags);
806 DRM_DEV_DEBUG_DRIVER(ipp->dev,
807 "ipp: %d, selected task %pK to run\n", ipp->id,
810 ret = ipp->funcs->commit(ipp, task);
812 exynos_drm_ipp_task_done(task, ret);
815 static void exynos_drm_ipp_schedule_task(struct exynos_drm_ipp *ipp,
816 struct exynos_drm_ipp_task *task)
820 spin_lock_irqsave(&ipp->lock, flags);
821 list_add(&task->head, &ipp->todo_list);
822 spin_unlock_irqrestore(&ipp->lock, flags);
824 exynos_drm_ipp_next_task(ipp);
827 static void exynos_drm_ipp_task_abort(struct exynos_drm_ipp *ipp,
828 struct exynos_drm_ipp_task *task)
832 spin_lock_irqsave(&ipp->lock, flags);
833 if (task->flags & DRM_EXYNOS_IPP_TASK_DONE) {
834 /* already completed task */
835 exynos_drm_ipp_task_cleanup(task);
836 } else if (ipp->task != task) {
837 /* task has not been scheduled for execution yet */
838 list_del_init(&task->head);
839 exynos_drm_ipp_task_cleanup(task);
842 * currently processed task, call abort() and perform
843 * cleanup with async worker
845 task->flags |= DRM_EXYNOS_IPP_TASK_ASYNC;
846 spin_unlock_irqrestore(&ipp->lock, flags);
847 if (ipp->funcs->abort)
848 ipp->funcs->abort(ipp, task);
851 spin_unlock_irqrestore(&ipp->lock, flags);
855 * exynos_drm_ipp_commit_ioctl - perform image processing operation
858 * @file_priv: DRM file info
860 * Construct a ipp task from the set of properties provided from the user
861 * and try to schedule it to framebuffer processor hardware.
863 * Called by the user via ioctl.
866 * Zero on success, negative errno on failure.
868 int exynos_drm_ipp_commit_ioctl(struct drm_device *dev, void *data,
869 struct drm_file *file_priv)
871 struct drm_exynos_ioctl_ipp_commit *arg = data;
872 struct exynos_drm_ipp *ipp;
873 struct exynos_drm_ipp_task *task;
876 if ((arg->flags & ~DRM_EXYNOS_IPP_FLAGS) || arg->reserved)
879 /* can't test and expect an event at the same time */
880 if ((arg->flags & DRM_EXYNOS_IPP_FLAG_TEST_ONLY) &&
881 (arg->flags & DRM_EXYNOS_IPP_FLAG_EVENT))
884 ipp = __ipp_get(arg->ipp_id);
888 task = exynos_drm_ipp_task_alloc(ipp);
892 ret = exynos_drm_ipp_task_set(task, arg);
896 ret = exynos_drm_ipp_task_check(task);
900 ret = exynos_drm_ipp_task_setup_buffers(task, file_priv);
901 if (ret || arg->flags & DRM_EXYNOS_IPP_FLAG_TEST_ONLY)
904 if (arg->flags & DRM_EXYNOS_IPP_FLAG_EVENT) {
905 ret = exynos_drm_ipp_event_create(task, file_priv,
912 * Queue task for processing on the hardware. task object will be
913 * then freed after exynos_drm_ipp_task_done()
915 if (arg->flags & DRM_EXYNOS_IPP_FLAG_NONBLOCK) {
916 DRM_DEV_DEBUG_DRIVER(ipp->dev,
917 "ipp: %d, nonblocking processing task %pK\n",
920 task->flags |= DRM_EXYNOS_IPP_TASK_ASYNC;
921 exynos_drm_ipp_schedule_task(task->ipp, task);
924 DRM_DEV_DEBUG_DRIVER(ipp->dev, "ipp: %d, processing task %pK\n",
926 exynos_drm_ipp_schedule_task(ipp, task);
927 ret = wait_event_interruptible(ipp->done_wq,
928 task->flags & DRM_EXYNOS_IPP_TASK_DONE);
930 exynos_drm_ipp_task_abort(ipp, task);
932 ret = exynos_drm_ipp_task_cleanup(task);
936 exynos_drm_ipp_task_free(ipp, task);