Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Samsung Electronics Co.Ltd |
| 3 | * Authors: |
| 4 | * Eunchul Kim <chulspro.kim@samsung.com> |
| 5 | * Jinyoung Jeon <jy0.jeon@samsung.com> |
| 6 | * Sangmin Lee <lsmin.lee@samsung.com> |
| 7 | * |
| 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. |
| 12 | * |
| 13 | */ |
| 14 | #include <linux/kernel.h> |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/clk.h> |
| 18 | #include <linux/pm_runtime.h> |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 19 | |
| 20 | #include <drm/drmP.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" |
Eunchul Kim | c12e261 | 2012-12-14 17:58:54 +0900 | [diff] [blame] | 25 | #include "exynos_drm_iommu.h" |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 26 | |
| 27 | /* |
Eunchul Kim | 6fe891f | 2012-12-22 17:49:26 +0900 | [diff] [blame] | 28 | * IPP stands for Image Post Processing and |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 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 |
| 32 | */ |
| 33 | |
| 34 | /* |
| 35 | * TODO |
| 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. |
| 43 | */ |
| 44 | |
| 45 | #define get_ipp_context(dev) platform_get_drvdata(to_platform_device(dev)) |
| 46 | #define ipp_is_m2m_cmd(c) (c == IPP_CMD_M2M) |
| 47 | |
Seung-Woo Kim | 43f4190 | 2013-04-23 14:02:53 +0900 | [diff] [blame] | 48 | /* platform device pointer for ipp device. */ |
| 49 | static struct platform_device *exynos_drm_ipp_pdev; |
| 50 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 51 | /* |
| 52 | * A structure of event. |
| 53 | * |
| 54 | * @base: base of event. |
| 55 | * @event: ipp event. |
| 56 | */ |
| 57 | struct drm_exynos_ipp_send_event { |
| 58 | struct drm_pending_event base; |
| 59 | struct drm_exynos_ipp_event event; |
| 60 | }; |
| 61 | |
| 62 | /* |
| 63 | * A structure of memory node. |
| 64 | * |
| 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. |
| 71 | */ |
| 72 | struct drm_exynos_ipp_mem_node { |
| 73 | struct list_head list; |
| 74 | enum drm_exynos_ops_id ops_id; |
| 75 | u32 prop_id; |
| 76 | u32 buf_id; |
| 77 | struct drm_exynos_ipp_buf_info buf_info; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | /* |
| 81 | * A structure of ipp context. |
| 82 | * |
| 83 | * @subdrv: prepare initialization using subdrv. |
| 84 | * @ipp_lock: lock for synchronization of access to ipp_idr. |
| 85 | * @prop_lock: lock for synchronization of access to prop_idr. |
| 86 | * @ipp_idr: ipp driver idr. |
| 87 | * @prop_idr: property idr. |
| 88 | * @event_workq: event work queue. |
| 89 | * @cmd_workq: command work queue. |
| 90 | */ |
| 91 | struct ipp_context { |
| 92 | struct exynos_drm_subdrv subdrv; |
| 93 | struct mutex ipp_lock; |
| 94 | struct mutex prop_lock; |
| 95 | struct idr ipp_idr; |
| 96 | struct idr prop_idr; |
| 97 | struct workqueue_struct *event_workq; |
| 98 | struct workqueue_struct *cmd_workq; |
| 99 | }; |
| 100 | |
| 101 | static LIST_HEAD(exynos_drm_ippdrv_list); |
| 102 | static DEFINE_MUTEX(exynos_drm_ippdrv_lock); |
| 103 | static BLOCKING_NOTIFIER_HEAD(exynos_drm_ippnb_list); |
| 104 | |
Seung-Woo Kim | 43f4190 | 2013-04-23 14:02:53 +0900 | [diff] [blame] | 105 | int exynos_platform_device_ipp_register(void) |
| 106 | { |
| 107 | struct platform_device *pdev; |
| 108 | |
| 109 | if (exynos_drm_ipp_pdev) |
| 110 | return -EEXIST; |
| 111 | |
| 112 | pdev = platform_device_register_simple("exynos-drm-ipp", -1, NULL, 0); |
| 113 | if (IS_ERR(pdev)) |
| 114 | return PTR_ERR(pdev); |
| 115 | |
| 116 | exynos_drm_ipp_pdev = pdev; |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | void exynos_platform_device_ipp_unregister(void) |
| 122 | { |
| 123 | if (exynos_drm_ipp_pdev) { |
| 124 | platform_device_unregister(exynos_drm_ipp_pdev); |
| 125 | exynos_drm_ipp_pdev = NULL; |
| 126 | } |
| 127 | } |
| 128 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 129 | int exynos_drm_ippdrv_register(struct exynos_drm_ippdrv *ippdrv) |
| 130 | { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 131 | mutex_lock(&exynos_drm_ippdrv_lock); |
| 132 | list_add_tail(&ippdrv->drv_list, &exynos_drm_ippdrv_list); |
| 133 | mutex_unlock(&exynos_drm_ippdrv_lock); |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | int exynos_drm_ippdrv_unregister(struct exynos_drm_ippdrv *ippdrv) |
| 139 | { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 140 | mutex_lock(&exynos_drm_ippdrv_lock); |
| 141 | list_del(&ippdrv->drv_list); |
| 142 | mutex_unlock(&exynos_drm_ippdrv_lock); |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
Andrzej Hajda | 12ff54d | 2014-07-03 15:10:36 +0200 | [diff] [blame] | 147 | static int ipp_create_id(struct idr *id_idr, struct mutex *lock, void *obj) |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 148 | { |
| 149 | int ret; |
| 150 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 151 | mutex_lock(lock); |
Tejun Heo | 8550cb2 | 2013-02-27 17:04:09 -0800 | [diff] [blame] | 152 | ret = idr_alloc(id_idr, obj, 1, 0, GFP_KERNEL); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 153 | mutex_unlock(lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 154 | |
Andrzej Hajda | 12ff54d | 2014-07-03 15:10:36 +0200 | [diff] [blame] | 155 | return ret; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 156 | } |
| 157 | |
YoungJun Cho | 075436b | 2014-05-26 10:17:19 +0200 | [diff] [blame] | 158 | static void ipp_remove_id(struct idr *id_idr, struct mutex *lock, u32 id) |
| 159 | { |
| 160 | mutex_lock(lock); |
| 161 | idr_remove(id_idr, id); |
| 162 | mutex_unlock(lock); |
| 163 | } |
| 164 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 165 | static void *ipp_find_obj(struct idr *id_idr, struct mutex *lock, u32 id) |
| 166 | { |
| 167 | void *obj; |
| 168 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 169 | mutex_lock(lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 170 | obj = idr_find(id_idr, id); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 171 | mutex_unlock(lock); |
| 172 | |
| 173 | return obj; |
| 174 | } |
| 175 | |
Andrzej Hajda | 9cc7d85 | 2014-07-03 15:10:37 +0200 | [diff] [blame] | 176 | static int ipp_check_driver(struct exynos_drm_ippdrv *ippdrv, |
| 177 | struct drm_exynos_ipp_property *property) |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 178 | { |
Andrzej Hajda | 9cc7d85 | 2014-07-03 15:10:37 +0200 | [diff] [blame] | 179 | if (ippdrv->dedicated || (!ipp_is_m2m_cmd(property->cmd) && |
| 180 | !pm_runtime_suspended(ippdrv->dev))) |
| 181 | return -EBUSY; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 182 | |
Andrzej Hajda | 9cc7d85 | 2014-07-03 15:10:37 +0200 | [diff] [blame] | 183 | if (ippdrv->check_property && |
| 184 | ippdrv->check_property(ippdrv->dev, property)) |
| 185 | return -EINVAL; |
| 186 | |
| 187 | return 0; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static struct exynos_drm_ippdrv *ipp_find_driver(struct ipp_context *ctx, |
| 191 | struct drm_exynos_ipp_property *property) |
| 192 | { |
| 193 | struct exynos_drm_ippdrv *ippdrv; |
| 194 | u32 ipp_id = property->ipp_id; |
Andrzej Hajda | 9cc7d85 | 2014-07-03 15:10:37 +0200 | [diff] [blame] | 195 | int ret; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 196 | |
| 197 | if (ipp_id) { |
Andrzej Hajda | 9cc7d85 | 2014-07-03 15:10:37 +0200 | [diff] [blame] | 198 | ippdrv = ipp_find_obj(&ctx->ipp_idr, &ctx->ipp_lock, ipp_id); |
Andrzej Hajda | 134f0e9 | 2014-07-03 15:10:34 +0200 | [diff] [blame] | 199 | if (!ippdrv) { |
Andrzej Hajda | 9cc7d85 | 2014-07-03 15:10:37 +0200 | [diff] [blame] | 200 | DRM_DEBUG("ipp%d driver not found\n", ipp_id); |
Andrzej Hajda | 134f0e9 | 2014-07-03 15:10:34 +0200 | [diff] [blame] | 201 | return ERR_PTR(-ENODEV); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 202 | } |
| 203 | |
Andrzej Hajda | 9cc7d85 | 2014-07-03 15:10:37 +0200 | [diff] [blame] | 204 | ret = ipp_check_driver(ippdrv, property); |
| 205 | if (ret < 0) { |
| 206 | DRM_DEBUG("ipp%d driver check error %d\n", ipp_id, ret); |
| 207 | return ERR_PTR(ret); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | return ippdrv; |
| 211 | } else { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 212 | list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) { |
Andrzej Hajda | 9cc7d85 | 2014-07-03 15:10:37 +0200 | [diff] [blame] | 213 | ret = ipp_check_driver(ippdrv, property); |
| 214 | if (ret == 0) |
| 215 | return ippdrv; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 216 | } |
| 217 | |
Andrzej Hajda | 9cc7d85 | 2014-07-03 15:10:37 +0200 | [diff] [blame] | 218 | DRM_DEBUG("cannot find driver suitable for given property.\n"); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | return ERR_PTR(-ENODEV); |
| 222 | } |
| 223 | |
| 224 | static struct exynos_drm_ippdrv *ipp_find_drv_by_handle(u32 prop_id) |
| 225 | { |
| 226 | struct exynos_drm_ippdrv *ippdrv; |
| 227 | struct drm_exynos_ipp_cmd_node *c_node; |
| 228 | int count = 0; |
| 229 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 230 | DRM_DEBUG_KMS("prop_id[%d]\n", prop_id); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 231 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 232 | /* |
| 233 | * This case is search ipp driver by prop_id handle. |
| 234 | * sometimes, ipp subsystem find driver by prop_id. |
Geert Uytterhoeven | 9fca9ac | 2014-03-11 11:23:37 +0100 | [diff] [blame] | 235 | * e.g PAUSE state, queue buf, command control. |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 236 | */ |
| 237 | list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) { |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 238 | DRM_DEBUG_KMS("count[%d]ippdrv[0x%x]\n", count++, (int)ippdrv); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 239 | |
YoungJun Cho | 7f5af05 | 2014-05-26 10:17:18 +0200 | [diff] [blame] | 240 | mutex_lock(&ippdrv->cmd_lock); |
| 241 | list_for_each_entry(c_node, &ippdrv->cmd_list, list) { |
| 242 | if (c_node->property.prop_id == prop_id) { |
| 243 | mutex_unlock(&ippdrv->cmd_lock); |
YoungJun Cho | c66ce40 | 2014-05-26 10:17:15 +0200 | [diff] [blame] | 244 | return ippdrv; |
YoungJun Cho | 7f5af05 | 2014-05-26 10:17:18 +0200 | [diff] [blame] | 245 | } |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 246 | } |
YoungJun Cho | 7f5af05 | 2014-05-26 10:17:18 +0200 | [diff] [blame] | 247 | mutex_unlock(&ippdrv->cmd_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | return ERR_PTR(-ENODEV); |
| 251 | } |
| 252 | |
| 253 | int exynos_drm_ipp_get_property(struct drm_device *drm_dev, void *data, |
| 254 | struct drm_file *file) |
| 255 | { |
| 256 | struct drm_exynos_file_private *file_priv = file->driver_priv; |
Andrzej Hajda | 5c76c5b | 2014-07-03 15:10:28 +0200 | [diff] [blame] | 257 | struct device *dev = file_priv->ipp_dev; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 258 | struct ipp_context *ctx = get_ipp_context(dev); |
| 259 | struct drm_exynos_ipp_prop_list *prop_list = data; |
| 260 | struct exynos_drm_ippdrv *ippdrv; |
| 261 | int count = 0; |
| 262 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 263 | if (!ctx) { |
| 264 | DRM_ERROR("invalid context.\n"); |
| 265 | return -EINVAL; |
| 266 | } |
| 267 | |
| 268 | if (!prop_list) { |
| 269 | DRM_ERROR("invalid property parameter.\n"); |
| 270 | return -EINVAL; |
| 271 | } |
| 272 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 273 | DRM_DEBUG_KMS("ipp_id[%d]\n", prop_list->ipp_id); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 274 | |
| 275 | if (!prop_list->ipp_id) { |
| 276 | list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) |
| 277 | count++; |
YoungJun Cho | 7f5af05 | 2014-05-26 10:17:18 +0200 | [diff] [blame] | 278 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 279 | /* |
| 280 | * Supports ippdrv list count for user application. |
| 281 | * First step user application getting ippdrv count. |
| 282 | * and second step getting ippdrv capability using ipp_id. |
| 283 | */ |
| 284 | prop_list->count = count; |
| 285 | } else { |
| 286 | /* |
| 287 | * Getting ippdrv capability by ipp_id. |
Masanari Iida | c6b78bc | 2013-10-24 16:02:57 +0900 | [diff] [blame] | 288 | * some device not supported wb, output interface. |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 289 | * so, user application detect correct ipp driver |
| 290 | * using this ioctl. |
| 291 | */ |
| 292 | ippdrv = ipp_find_obj(&ctx->ipp_idr, &ctx->ipp_lock, |
| 293 | prop_list->ipp_id); |
Andrzej Hajda | 134f0e9 | 2014-07-03 15:10:34 +0200 | [diff] [blame] | 294 | if (!ippdrv) { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 295 | DRM_ERROR("not found ipp%d driver.\n", |
| 296 | prop_list->ipp_id); |
Andrzej Hajda | 134f0e9 | 2014-07-03 15:10:34 +0200 | [diff] [blame] | 297 | return -ENODEV; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 298 | } |
| 299 | |
Andrzej Hajda | 3164605 | 2014-05-19 12:54:05 +0200 | [diff] [blame] | 300 | *prop_list = ippdrv->prop_list; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | static void ipp_print_property(struct drm_exynos_ipp_property *property, |
| 307 | int idx) |
| 308 | { |
| 309 | struct drm_exynos_ipp_config *config = &property->config[idx]; |
| 310 | struct drm_exynos_pos *pos = &config->pos; |
| 311 | struct drm_exynos_sz *sz = &config->sz; |
| 312 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 313 | DRM_DEBUG_KMS("prop_id[%d]ops[%s]fmt[0x%x]\n", |
| 314 | property->prop_id, idx ? "dst" : "src", config->fmt); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 315 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 316 | DRM_DEBUG_KMS("pos[%d %d %d %d]sz[%d %d]f[%d]r[%d]\n", |
| 317 | pos->x, pos->y, pos->w, pos->h, |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 318 | sz->hsize, sz->vsize, config->flip, config->degree); |
| 319 | } |
| 320 | |
| 321 | static int ipp_find_and_set_property(struct drm_exynos_ipp_property *property) |
| 322 | { |
| 323 | struct exynos_drm_ippdrv *ippdrv; |
| 324 | struct drm_exynos_ipp_cmd_node *c_node; |
| 325 | u32 prop_id = property->prop_id; |
| 326 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 327 | DRM_DEBUG_KMS("prop_id[%d]\n", prop_id); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 328 | |
| 329 | ippdrv = ipp_find_drv_by_handle(prop_id); |
Sachin Kamat | f025045 | 2013-04-29 12:27:06 +0530 | [diff] [blame] | 330 | if (IS_ERR(ippdrv)) { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 331 | DRM_ERROR("failed to get ipp driver.\n"); |
| 332 | return -EINVAL; |
| 333 | } |
| 334 | |
| 335 | /* |
| 336 | * Find command node using command list in ippdrv. |
| 337 | * when we find this command no using prop_id. |
| 338 | * return property information set in this command node. |
| 339 | */ |
YoungJun Cho | 7f5af05 | 2014-05-26 10:17:18 +0200 | [diff] [blame] | 340 | mutex_lock(&ippdrv->cmd_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 341 | list_for_each_entry(c_node, &ippdrv->cmd_list, list) { |
| 342 | if ((c_node->property.prop_id == prop_id) && |
| 343 | (c_node->state == IPP_STATE_STOP)) { |
YoungJun Cho | 7f5af05 | 2014-05-26 10:17:18 +0200 | [diff] [blame] | 344 | mutex_unlock(&ippdrv->cmd_lock); |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 345 | DRM_DEBUG_KMS("found cmd[%d]ippdrv[0x%x]\n", |
| 346 | property->cmd, (int)ippdrv); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 347 | |
| 348 | c_node->property = *property; |
| 349 | return 0; |
| 350 | } |
| 351 | } |
YoungJun Cho | 7f5af05 | 2014-05-26 10:17:18 +0200 | [diff] [blame] | 352 | mutex_unlock(&ippdrv->cmd_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 353 | |
| 354 | DRM_ERROR("failed to search property.\n"); |
| 355 | |
| 356 | return -EINVAL; |
| 357 | } |
| 358 | |
| 359 | static struct drm_exynos_ipp_cmd_work *ipp_create_cmd_work(void) |
| 360 | { |
| 361 | struct drm_exynos_ipp_cmd_work *cmd_work; |
| 362 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 363 | cmd_work = kzalloc(sizeof(*cmd_work), GFP_KERNEL); |
Sachin Kamat | 38bb525 | 2013-08-19 19:04:55 +0900 | [diff] [blame] | 364 | if (!cmd_work) |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 365 | return ERR_PTR(-ENOMEM); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 366 | |
| 367 | INIT_WORK((struct work_struct *)cmd_work, ipp_sched_cmd); |
| 368 | |
| 369 | return cmd_work; |
| 370 | } |
| 371 | |
| 372 | static struct drm_exynos_ipp_event_work *ipp_create_event_work(void) |
| 373 | { |
| 374 | struct drm_exynos_ipp_event_work *event_work; |
| 375 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 376 | event_work = kzalloc(sizeof(*event_work), GFP_KERNEL); |
Sachin Kamat | 38bb525 | 2013-08-19 19:04:55 +0900 | [diff] [blame] | 377 | if (!event_work) |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 378 | return ERR_PTR(-ENOMEM); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 379 | |
Andrzej Hajda | 60b61c2 | 2014-07-03 15:10:26 +0200 | [diff] [blame] | 380 | INIT_WORK(&event_work->work, ipp_sched_event); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 381 | |
| 382 | return event_work; |
| 383 | } |
| 384 | |
| 385 | int exynos_drm_ipp_set_property(struct drm_device *drm_dev, void *data, |
| 386 | struct drm_file *file) |
| 387 | { |
| 388 | struct drm_exynos_file_private *file_priv = file->driver_priv; |
Andrzej Hajda | 5c76c5b | 2014-07-03 15:10:28 +0200 | [diff] [blame] | 389 | struct device *dev = file_priv->ipp_dev; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 390 | struct ipp_context *ctx = get_ipp_context(dev); |
| 391 | struct drm_exynos_ipp_property *property = data; |
| 392 | struct exynos_drm_ippdrv *ippdrv; |
| 393 | struct drm_exynos_ipp_cmd_node *c_node; |
| 394 | int ret, i; |
| 395 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 396 | if (!ctx) { |
| 397 | DRM_ERROR("invalid context.\n"); |
| 398 | return -EINVAL; |
| 399 | } |
| 400 | |
| 401 | if (!property) { |
| 402 | DRM_ERROR("invalid property parameter.\n"); |
| 403 | return -EINVAL; |
| 404 | } |
| 405 | |
| 406 | /* |
| 407 | * This is log print for user application property. |
| 408 | * user application set various property. |
| 409 | */ |
| 410 | for_each_ipp_ops(i) |
| 411 | ipp_print_property(property, i); |
| 412 | |
| 413 | /* |
| 414 | * set property ioctl generated new prop_id. |
| 415 | * but in this case already asigned prop_id using old set property. |
| 416 | * e.g PAUSE state. this case supports find current prop_id and use it |
| 417 | * instead of allocation. |
| 418 | */ |
| 419 | if (property->prop_id) { |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 420 | DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 421 | return ipp_find_and_set_property(property); |
| 422 | } |
| 423 | |
| 424 | /* find ipp driver using ipp id */ |
| 425 | ippdrv = ipp_find_driver(ctx, property); |
Sachin Kamat | f025045 | 2013-04-29 12:27:06 +0530 | [diff] [blame] | 426 | if (IS_ERR(ippdrv)) { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 427 | DRM_ERROR("failed to get ipp driver.\n"); |
| 428 | return -EINVAL; |
| 429 | } |
| 430 | |
| 431 | /* allocate command node */ |
| 432 | c_node = kzalloc(sizeof(*c_node), GFP_KERNEL); |
Sachin Kamat | 38bb525 | 2013-08-19 19:04:55 +0900 | [diff] [blame] | 433 | if (!c_node) |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 434 | return -ENOMEM; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 435 | |
Andrzej Hajda | 12ff54d | 2014-07-03 15:10:36 +0200 | [diff] [blame] | 436 | ret = ipp_create_id(&ctx->prop_idr, &ctx->prop_lock, c_node); |
| 437 | if (ret < 0) { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 438 | DRM_ERROR("failed to create id.\n"); |
| 439 | goto err_clear; |
| 440 | } |
Andrzej Hajda | 12ff54d | 2014-07-03 15:10:36 +0200 | [diff] [blame] | 441 | property->prop_id = ret; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 442 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 443 | DRM_DEBUG_KMS("created prop_id[%d]cmd[%d]ippdrv[0x%x]\n", |
| 444 | property->prop_id, property->cmd, (int)ippdrv); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 445 | |
| 446 | /* stored property information and ippdrv in private data */ |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 447 | c_node->property = *property; |
| 448 | c_node->state = IPP_STATE_IDLE; |
Andrzej Hajda | 945a0aa | 2014-08-28 11:07:27 +0200 | [diff] [blame] | 449 | c_node->filp = file; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 450 | |
| 451 | c_node->start_work = ipp_create_cmd_work(); |
Sachin Kamat | f025045 | 2013-04-29 12:27:06 +0530 | [diff] [blame] | 452 | if (IS_ERR(c_node->start_work)) { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 453 | DRM_ERROR("failed to create start work.\n"); |
YoungJun Cho | 075436b | 2014-05-26 10:17:19 +0200 | [diff] [blame] | 454 | goto err_remove_id; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | c_node->stop_work = ipp_create_cmd_work(); |
Sachin Kamat | f025045 | 2013-04-29 12:27:06 +0530 | [diff] [blame] | 458 | if (IS_ERR(c_node->stop_work)) { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 459 | DRM_ERROR("failed to create stop work.\n"); |
| 460 | goto err_free_start; |
| 461 | } |
| 462 | |
| 463 | c_node->event_work = ipp_create_event_work(); |
Sachin Kamat | f025045 | 2013-04-29 12:27:06 +0530 | [diff] [blame] | 464 | if (IS_ERR(c_node->event_work)) { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 465 | DRM_ERROR("failed to create event work.\n"); |
| 466 | goto err_free_stop; |
| 467 | } |
| 468 | |
YoungJun Cho | 4e4fe55 | 2014-05-26 10:17:17 +0200 | [diff] [blame] | 469 | mutex_init(&c_node->lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 470 | mutex_init(&c_node->mem_lock); |
| 471 | mutex_init(&c_node->event_lock); |
| 472 | |
| 473 | init_completion(&c_node->start_complete); |
| 474 | init_completion(&c_node->stop_complete); |
| 475 | |
| 476 | for_each_ipp_ops(i) |
| 477 | INIT_LIST_HEAD(&c_node->mem_list[i]); |
| 478 | |
| 479 | INIT_LIST_HEAD(&c_node->event_list); |
YoungJun Cho | 7f5af05 | 2014-05-26 10:17:18 +0200 | [diff] [blame] | 480 | mutex_lock(&ippdrv->cmd_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 481 | list_add_tail(&c_node->list, &ippdrv->cmd_list); |
YoungJun Cho | 7f5af05 | 2014-05-26 10:17:18 +0200 | [diff] [blame] | 482 | mutex_unlock(&ippdrv->cmd_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 483 | |
| 484 | /* make dedicated state without m2m */ |
| 485 | if (!ipp_is_m2m_cmd(property->cmd)) |
| 486 | ippdrv->dedicated = true; |
| 487 | |
| 488 | return 0; |
| 489 | |
| 490 | err_free_stop: |
| 491 | kfree(c_node->stop_work); |
| 492 | err_free_start: |
| 493 | kfree(c_node->start_work); |
YoungJun Cho | 075436b | 2014-05-26 10:17:19 +0200 | [diff] [blame] | 494 | err_remove_id: |
| 495 | ipp_remove_id(&ctx->prop_idr, &ctx->prop_lock, property->prop_id); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 496 | err_clear: |
| 497 | kfree(c_node); |
| 498 | return ret; |
| 499 | } |
| 500 | |
Andrzej Hajda | c4a856a | 2014-08-28 11:07:31 +0200 | [diff] [blame] | 501 | static int ipp_put_mem_node(struct drm_device *drm_dev, |
| 502 | struct drm_exynos_ipp_cmd_node *c_node, |
| 503 | struct drm_exynos_ipp_mem_node *m_node) |
| 504 | { |
| 505 | int i; |
| 506 | |
| 507 | DRM_DEBUG_KMS("node[0x%x]\n", (int)m_node); |
| 508 | |
| 509 | if (!m_node) { |
| 510 | DRM_ERROR("invalid dequeue node.\n"); |
| 511 | return -EFAULT; |
| 512 | } |
| 513 | |
| 514 | DRM_DEBUG_KMS("ops_id[%d]\n", m_node->ops_id); |
| 515 | |
| 516 | /* put gem buffer */ |
| 517 | for_each_ipp_planar(i) { |
| 518 | unsigned long handle = m_node->buf_info.handles[i]; |
| 519 | if (handle) |
| 520 | exynos_drm_gem_put_dma_addr(drm_dev, handle, |
| 521 | c_node->filp); |
| 522 | } |
| 523 | |
| 524 | list_del(&m_node->list); |
| 525 | kfree(m_node); |
| 526 | |
| 527 | return 0; |
| 528 | } |
| 529 | |
| 530 | static struct drm_exynos_ipp_mem_node |
| 531 | *ipp_get_mem_node(struct drm_device *drm_dev, |
| 532 | struct drm_file *file, |
| 533 | struct drm_exynos_ipp_cmd_node *c_node, |
| 534 | struct drm_exynos_ipp_queue_buf *qbuf) |
| 535 | { |
| 536 | struct drm_exynos_ipp_mem_node *m_node; |
| 537 | struct drm_exynos_ipp_buf_info *buf_info; |
| 538 | int i; |
| 539 | |
| 540 | m_node = kzalloc(sizeof(*m_node), GFP_KERNEL); |
| 541 | if (!m_node) |
| 542 | return ERR_PTR(-ENOMEM); |
| 543 | |
| 544 | buf_info = &m_node->buf_info; |
| 545 | |
| 546 | /* operations, buffer id */ |
| 547 | m_node->ops_id = qbuf->ops_id; |
| 548 | m_node->prop_id = qbuf->prop_id; |
| 549 | m_node->buf_id = qbuf->buf_id; |
| 550 | INIT_LIST_HEAD(&m_node->list); |
| 551 | |
| 552 | DRM_DEBUG_KMS("m_node[0x%x]ops_id[%d]\n", (int)m_node, qbuf->ops_id); |
| 553 | DRM_DEBUG_KMS("prop_id[%d]buf_id[%d]\n", qbuf->prop_id, m_node->buf_id); |
| 554 | |
| 555 | for_each_ipp_planar(i) { |
| 556 | DRM_DEBUG_KMS("i[%d]handle[0x%x]\n", i, qbuf->handle[i]); |
| 557 | |
| 558 | /* get dma address by handle */ |
| 559 | if (qbuf->handle[i]) { |
| 560 | dma_addr_t *addr; |
| 561 | |
| 562 | addr = exynos_drm_gem_get_dma_addr(drm_dev, |
| 563 | qbuf->handle[i], file); |
| 564 | if (IS_ERR(addr)) { |
| 565 | DRM_ERROR("failed to get addr.\n"); |
| 566 | ipp_put_mem_node(drm_dev, c_node, m_node); |
| 567 | return ERR_PTR(-EFAULT); |
| 568 | } |
| 569 | |
| 570 | buf_info->handles[i] = qbuf->handle[i]; |
| 571 | buf_info->base[i] = *addr; |
| 572 | DRM_DEBUG_KMS("i[%d]base[0x%x]hd[0x%lx]\n", i, |
| 573 | buf_info->base[i], buf_info->handles[i]); |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | mutex_lock(&c_node->mem_lock); |
| 578 | list_add_tail(&m_node->list, &c_node->mem_list[qbuf->ops_id]); |
| 579 | mutex_unlock(&c_node->mem_lock); |
| 580 | |
| 581 | return m_node; |
| 582 | } |
| 583 | |
| 584 | static void ipp_clean_mem_nodes(struct drm_device *drm_dev, |
| 585 | struct drm_exynos_ipp_cmd_node *c_node, int ops) |
| 586 | { |
| 587 | struct drm_exynos_ipp_mem_node *m_node, *tm_node; |
| 588 | struct list_head *head = &c_node->mem_list[ops]; |
| 589 | |
| 590 | mutex_lock(&c_node->mem_lock); |
| 591 | |
| 592 | list_for_each_entry_safe(m_node, tm_node, head, list) { |
| 593 | int ret; |
| 594 | |
| 595 | ret = ipp_put_mem_node(drm_dev, c_node, m_node); |
| 596 | if (ret) |
| 597 | DRM_ERROR("failed to put m_node.\n"); |
| 598 | } |
| 599 | |
| 600 | mutex_unlock(&c_node->mem_lock); |
| 601 | } |
| 602 | |
YoungJun Cho | 075436b | 2014-05-26 10:17:19 +0200 | [diff] [blame] | 603 | static void ipp_clean_cmd_node(struct ipp_context *ctx, |
| 604 | struct drm_exynos_ipp_cmd_node *c_node) |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 605 | { |
Andrzej Hajda | 22e816f | 2014-08-28 11:07:32 +0200 | [diff] [blame] | 606 | int i; |
| 607 | |
Andrzej Hajda | 6f7d48e | 2014-08-28 11:07:26 +0200 | [diff] [blame] | 608 | /* cancel works */ |
| 609 | cancel_work_sync(&c_node->start_work->work); |
| 610 | cancel_work_sync(&c_node->stop_work->work); |
| 611 | cancel_work_sync(&c_node->event_work->work); |
| 612 | |
Andrzej Hajda | 22e816f | 2014-08-28 11:07:32 +0200 | [diff] [blame] | 613 | for_each_ipp_ops(i) |
| 614 | ipp_clean_mem_nodes(ctx->subdrv.drm_dev, c_node, i); |
| 615 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 616 | /* delete list */ |
| 617 | list_del(&c_node->list); |
| 618 | |
YoungJun Cho | 075436b | 2014-05-26 10:17:19 +0200 | [diff] [blame] | 619 | ipp_remove_id(&ctx->prop_idr, &ctx->prop_lock, |
| 620 | c_node->property.prop_id); |
| 621 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 622 | /* destroy mutex */ |
YoungJun Cho | 4e4fe55 | 2014-05-26 10:17:17 +0200 | [diff] [blame] | 623 | mutex_destroy(&c_node->lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 624 | mutex_destroy(&c_node->mem_lock); |
| 625 | mutex_destroy(&c_node->event_lock); |
| 626 | |
| 627 | /* free command node */ |
| 628 | kfree(c_node->start_work); |
| 629 | kfree(c_node->stop_work); |
| 630 | kfree(c_node->event_work); |
| 631 | kfree(c_node); |
| 632 | } |
| 633 | |
Andrzej Hajda | fb5ee01 | 2014-07-03 15:10:32 +0200 | [diff] [blame] | 634 | static bool ipp_check_mem_list(struct drm_exynos_ipp_cmd_node *c_node) |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 635 | { |
Andrzej Hajda | fb5ee01 | 2014-07-03 15:10:32 +0200 | [diff] [blame] | 636 | switch (c_node->property.cmd) { |
| 637 | case IPP_CMD_WB: |
| 638 | return !list_empty(&c_node->mem_list[EXYNOS_DRM_OPS_DST]); |
| 639 | case IPP_CMD_OUTPUT: |
| 640 | return !list_empty(&c_node->mem_list[EXYNOS_DRM_OPS_SRC]); |
| 641 | case IPP_CMD_M2M: |
| 642 | default: |
| 643 | return !list_empty(&c_node->mem_list[EXYNOS_DRM_OPS_SRC]) && |
| 644 | !list_empty(&c_node->mem_list[EXYNOS_DRM_OPS_DST]); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 645 | } |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | static struct drm_exynos_ipp_mem_node |
| 649 | *ipp_find_mem_node(struct drm_exynos_ipp_cmd_node *c_node, |
| 650 | struct drm_exynos_ipp_queue_buf *qbuf) |
| 651 | { |
| 652 | struct drm_exynos_ipp_mem_node *m_node; |
| 653 | struct list_head *head; |
| 654 | int count = 0; |
| 655 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 656 | DRM_DEBUG_KMS("buf_id[%d]\n", qbuf->buf_id); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 657 | |
| 658 | /* source/destination memory list */ |
| 659 | head = &c_node->mem_list[qbuf->ops_id]; |
| 660 | |
| 661 | /* find memory node from memory list */ |
| 662 | list_for_each_entry(m_node, head, list) { |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 663 | DRM_DEBUG_KMS("count[%d]m_node[0x%x]\n", count++, (int)m_node); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 664 | |
| 665 | /* compare buffer id */ |
| 666 | if (m_node->buf_id == qbuf->buf_id) |
| 667 | return m_node; |
| 668 | } |
| 669 | |
| 670 | return NULL; |
| 671 | } |
| 672 | |
| 673 | static int ipp_set_mem_node(struct exynos_drm_ippdrv *ippdrv, |
| 674 | struct drm_exynos_ipp_cmd_node *c_node, |
| 675 | struct drm_exynos_ipp_mem_node *m_node) |
| 676 | { |
| 677 | struct exynos_drm_ipp_ops *ops = NULL; |
| 678 | int ret = 0; |
| 679 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 680 | DRM_DEBUG_KMS("node[0x%x]\n", (int)m_node); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 681 | |
| 682 | if (!m_node) { |
| 683 | DRM_ERROR("invalid queue node.\n"); |
| 684 | return -EFAULT; |
| 685 | } |
| 686 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 687 | DRM_DEBUG_KMS("ops_id[%d]\n", m_node->ops_id); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 688 | |
| 689 | /* get operations callback */ |
| 690 | ops = ippdrv->ops[m_node->ops_id]; |
| 691 | if (!ops) { |
| 692 | DRM_ERROR("not support ops.\n"); |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 693 | return -EFAULT; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | /* set address and enable irq */ |
| 697 | if (ops->set_addr) { |
| 698 | ret = ops->set_addr(ippdrv->dev, &m_node->buf_info, |
| 699 | m_node->buf_id, IPP_BUF_ENQUEUE); |
| 700 | if (ret) { |
| 701 | DRM_ERROR("failed to set addr.\n"); |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 702 | return ret; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 706 | return ret; |
| 707 | } |
| 708 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 709 | static void ipp_free_event(struct drm_pending_event *event) |
| 710 | { |
| 711 | kfree(event); |
| 712 | } |
| 713 | |
| 714 | static int ipp_get_event(struct drm_device *drm_dev, |
| 715 | struct drm_file *file, |
| 716 | struct drm_exynos_ipp_cmd_node *c_node, |
| 717 | struct drm_exynos_ipp_queue_buf *qbuf) |
| 718 | { |
| 719 | struct drm_exynos_ipp_send_event *e; |
| 720 | unsigned long flags; |
| 721 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 722 | DRM_DEBUG_KMS("ops_id[%d]buf_id[%d]\n", qbuf->ops_id, qbuf->buf_id); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 723 | |
| 724 | e = kzalloc(sizeof(*e), GFP_KERNEL); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 725 | if (!e) { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 726 | spin_lock_irqsave(&drm_dev->event_lock, flags); |
| 727 | file->event_space += sizeof(e->event); |
| 728 | spin_unlock_irqrestore(&drm_dev->event_lock, flags); |
| 729 | return -ENOMEM; |
| 730 | } |
| 731 | |
| 732 | /* make event */ |
| 733 | e->event.base.type = DRM_EXYNOS_IPP_EVENT; |
| 734 | e->event.base.length = sizeof(e->event); |
| 735 | e->event.user_data = qbuf->user_data; |
| 736 | e->event.prop_id = qbuf->prop_id; |
| 737 | e->event.buf_id[EXYNOS_DRM_OPS_DST] = qbuf->buf_id; |
| 738 | e->base.event = &e->event.base; |
| 739 | e->base.file_priv = file; |
| 740 | e->base.destroy = ipp_free_event; |
YoungJun Cho | 4d52076 | 2014-05-26 10:17:21 +0200 | [diff] [blame] | 741 | mutex_lock(&c_node->event_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 742 | list_add_tail(&e->base.link, &c_node->event_list); |
YoungJun Cho | 4d52076 | 2014-05-26 10:17:21 +0200 | [diff] [blame] | 743 | mutex_unlock(&c_node->event_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 744 | |
| 745 | return 0; |
| 746 | } |
| 747 | |
| 748 | static void ipp_put_event(struct drm_exynos_ipp_cmd_node *c_node, |
| 749 | struct drm_exynos_ipp_queue_buf *qbuf) |
| 750 | { |
| 751 | struct drm_exynos_ipp_send_event *e, *te; |
| 752 | int count = 0; |
| 753 | |
YoungJun Cho | 4d52076 | 2014-05-26 10:17:21 +0200 | [diff] [blame] | 754 | mutex_lock(&c_node->event_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 755 | list_for_each_entry_safe(e, te, &c_node->event_list, base.link) { |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 756 | DRM_DEBUG_KMS("count[%d]e[0x%x]\n", count++, (int)e); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 757 | |
| 758 | /* |
Sachin Kamat | 4fe25b8 | 2014-01-16 10:00:23 +0530 | [diff] [blame] | 759 | * qbuf == NULL condition means all event deletion. |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 760 | * stop operations want to delete all event list. |
| 761 | * another case delete only same buf id. |
| 762 | */ |
| 763 | if (!qbuf) { |
| 764 | /* delete list */ |
| 765 | list_del(&e->base.link); |
| 766 | kfree(e); |
| 767 | } |
| 768 | |
| 769 | /* compare buffer id */ |
| 770 | if (qbuf && (qbuf->buf_id == |
| 771 | e->event.buf_id[EXYNOS_DRM_OPS_DST])) { |
| 772 | /* delete list */ |
| 773 | list_del(&e->base.link); |
| 774 | kfree(e); |
YoungJun Cho | 4d52076 | 2014-05-26 10:17:21 +0200 | [diff] [blame] | 775 | goto out_unlock; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 776 | } |
| 777 | } |
YoungJun Cho | 4d52076 | 2014-05-26 10:17:21 +0200 | [diff] [blame] | 778 | |
| 779 | out_unlock: |
| 780 | mutex_unlock(&c_node->event_lock); |
| 781 | return; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 782 | } |
| 783 | |
Sachin Kamat | 0bc4a0a | 2013-01-14 12:29:10 +0530 | [diff] [blame] | 784 | static void ipp_handle_cmd_work(struct device *dev, |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 785 | struct exynos_drm_ippdrv *ippdrv, |
| 786 | struct drm_exynos_ipp_cmd_work *cmd_work, |
| 787 | struct drm_exynos_ipp_cmd_node *c_node) |
| 788 | { |
| 789 | struct ipp_context *ctx = get_ipp_context(dev); |
| 790 | |
| 791 | cmd_work->ippdrv = ippdrv; |
| 792 | cmd_work->c_node = c_node; |
Andrzej Hajda | 05afb1a | 2014-08-28 11:07:33 +0200 | [diff] [blame^] | 793 | queue_work(ctx->cmd_workq, &cmd_work->work); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | static int ipp_queue_buf_with_run(struct device *dev, |
| 797 | struct drm_exynos_ipp_cmd_node *c_node, |
| 798 | struct drm_exynos_ipp_mem_node *m_node, |
| 799 | struct drm_exynos_ipp_queue_buf *qbuf) |
| 800 | { |
| 801 | struct exynos_drm_ippdrv *ippdrv; |
| 802 | struct drm_exynos_ipp_property *property; |
| 803 | struct exynos_drm_ipp_ops *ops; |
| 804 | int ret; |
| 805 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 806 | ippdrv = ipp_find_drv_by_handle(qbuf->prop_id); |
Sachin Kamat | f025045 | 2013-04-29 12:27:06 +0530 | [diff] [blame] | 807 | if (IS_ERR(ippdrv)) { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 808 | DRM_ERROR("failed to get ipp driver.\n"); |
| 809 | return -EFAULT; |
| 810 | } |
| 811 | |
| 812 | ops = ippdrv->ops[qbuf->ops_id]; |
| 813 | if (!ops) { |
| 814 | DRM_ERROR("failed to get ops.\n"); |
| 815 | return -EFAULT; |
| 816 | } |
| 817 | |
| 818 | property = &c_node->property; |
| 819 | |
| 820 | if (c_node->state != IPP_STATE_START) { |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 821 | DRM_DEBUG_KMS("bypass for invalid state.\n"); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 822 | return 0; |
| 823 | } |
| 824 | |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 825 | mutex_lock(&c_node->mem_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 826 | if (!ipp_check_mem_list(c_node)) { |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 827 | mutex_unlock(&c_node->mem_lock); |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 828 | DRM_DEBUG_KMS("empty memory.\n"); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 829 | return 0; |
| 830 | } |
| 831 | |
| 832 | /* |
| 833 | * If set destination buffer and enabled clock, |
| 834 | * then m2m operations need start operations at queue_buf |
| 835 | */ |
| 836 | if (ipp_is_m2m_cmd(property->cmd)) { |
| 837 | struct drm_exynos_ipp_cmd_work *cmd_work = c_node->start_work; |
| 838 | |
| 839 | cmd_work->ctrl = IPP_CTRL_PLAY; |
| 840 | ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node); |
| 841 | } else { |
| 842 | ret = ipp_set_mem_node(ippdrv, c_node, m_node); |
| 843 | if (ret) { |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 844 | mutex_unlock(&c_node->mem_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 845 | DRM_ERROR("failed to set m node.\n"); |
| 846 | return ret; |
| 847 | } |
| 848 | } |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 849 | mutex_unlock(&c_node->mem_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 850 | |
| 851 | return 0; |
| 852 | } |
| 853 | |
| 854 | static void ipp_clean_queue_buf(struct drm_device *drm_dev, |
| 855 | struct drm_exynos_ipp_cmd_node *c_node, |
| 856 | struct drm_exynos_ipp_queue_buf *qbuf) |
| 857 | { |
| 858 | struct drm_exynos_ipp_mem_node *m_node, *tm_node; |
| 859 | |
YoungJun Cho | c66ce40 | 2014-05-26 10:17:15 +0200 | [diff] [blame] | 860 | /* delete list */ |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 861 | mutex_lock(&c_node->mem_lock); |
YoungJun Cho | c66ce40 | 2014-05-26 10:17:15 +0200 | [diff] [blame] | 862 | list_for_each_entry_safe(m_node, tm_node, |
| 863 | &c_node->mem_list[qbuf->ops_id], list) { |
| 864 | if (m_node->buf_id == qbuf->buf_id && |
| 865 | m_node->ops_id == qbuf->ops_id) |
| 866 | ipp_put_mem_node(drm_dev, c_node, m_node); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 867 | } |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 868 | mutex_unlock(&c_node->mem_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | int exynos_drm_ipp_queue_buf(struct drm_device *drm_dev, void *data, |
| 872 | struct drm_file *file) |
| 873 | { |
| 874 | struct drm_exynos_file_private *file_priv = file->driver_priv; |
Andrzej Hajda | 5c76c5b | 2014-07-03 15:10:28 +0200 | [diff] [blame] | 875 | struct device *dev = file_priv->ipp_dev; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 876 | struct ipp_context *ctx = get_ipp_context(dev); |
| 877 | struct drm_exynos_ipp_queue_buf *qbuf = data; |
| 878 | struct drm_exynos_ipp_cmd_node *c_node; |
| 879 | struct drm_exynos_ipp_mem_node *m_node; |
| 880 | int ret; |
| 881 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 882 | if (!qbuf) { |
| 883 | DRM_ERROR("invalid buf parameter.\n"); |
| 884 | return -EINVAL; |
| 885 | } |
| 886 | |
| 887 | if (qbuf->ops_id >= EXYNOS_DRM_OPS_MAX) { |
| 888 | DRM_ERROR("invalid ops parameter.\n"); |
| 889 | return -EINVAL; |
| 890 | } |
| 891 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 892 | DRM_DEBUG_KMS("prop_id[%d]ops_id[%s]buf_id[%d]buf_type[%d]\n", |
| 893 | qbuf->prop_id, qbuf->ops_id ? "dst" : "src", |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 894 | qbuf->buf_id, qbuf->buf_type); |
| 895 | |
| 896 | /* find command node */ |
| 897 | c_node = ipp_find_obj(&ctx->prop_idr, &ctx->prop_lock, |
| 898 | qbuf->prop_id); |
Andrzej Hajda | 134f0e9 | 2014-07-03 15:10:34 +0200 | [diff] [blame] | 899 | if (!c_node) { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 900 | DRM_ERROR("failed to get command node.\n"); |
Andrzej Hajda | 134f0e9 | 2014-07-03 15:10:34 +0200 | [diff] [blame] | 901 | return -ENODEV; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | /* buffer control */ |
| 905 | switch (qbuf->buf_type) { |
| 906 | case IPP_BUF_ENQUEUE: |
| 907 | /* get memory node */ |
| 908 | m_node = ipp_get_mem_node(drm_dev, file, c_node, qbuf); |
| 909 | if (IS_ERR(m_node)) { |
| 910 | DRM_ERROR("failed to get m_node.\n"); |
| 911 | return PTR_ERR(m_node); |
| 912 | } |
| 913 | |
| 914 | /* |
| 915 | * first step get event for destination buffer. |
| 916 | * and second step when M2M case run with destination buffer |
| 917 | * if needed. |
| 918 | */ |
| 919 | if (qbuf->ops_id == EXYNOS_DRM_OPS_DST) { |
| 920 | /* get event for destination buffer */ |
| 921 | ret = ipp_get_event(drm_dev, file, c_node, qbuf); |
| 922 | if (ret) { |
| 923 | DRM_ERROR("failed to get event.\n"); |
| 924 | goto err_clean_node; |
| 925 | } |
| 926 | |
| 927 | /* |
| 928 | * M2M case run play control for streaming feature. |
| 929 | * other case set address and waiting. |
| 930 | */ |
| 931 | ret = ipp_queue_buf_with_run(dev, c_node, m_node, qbuf); |
| 932 | if (ret) { |
| 933 | DRM_ERROR("failed to run command.\n"); |
| 934 | goto err_clean_node; |
| 935 | } |
| 936 | } |
| 937 | break; |
| 938 | case IPP_BUF_DEQUEUE: |
YoungJun Cho | 4e4fe55 | 2014-05-26 10:17:17 +0200 | [diff] [blame] | 939 | mutex_lock(&c_node->lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 940 | |
| 941 | /* put event for destination buffer */ |
| 942 | if (qbuf->ops_id == EXYNOS_DRM_OPS_DST) |
| 943 | ipp_put_event(c_node, qbuf); |
| 944 | |
| 945 | ipp_clean_queue_buf(drm_dev, c_node, qbuf); |
| 946 | |
YoungJun Cho | 4e4fe55 | 2014-05-26 10:17:17 +0200 | [diff] [blame] | 947 | mutex_unlock(&c_node->lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 948 | break; |
| 949 | default: |
| 950 | DRM_ERROR("invalid buffer control.\n"); |
| 951 | return -EINVAL; |
| 952 | } |
| 953 | |
| 954 | return 0; |
| 955 | |
| 956 | err_clean_node: |
| 957 | DRM_ERROR("clean memory nodes.\n"); |
| 958 | |
| 959 | ipp_clean_queue_buf(drm_dev, c_node, qbuf); |
| 960 | return ret; |
| 961 | } |
| 962 | |
| 963 | static bool exynos_drm_ipp_check_valid(struct device *dev, |
| 964 | enum drm_exynos_ipp_ctrl ctrl, enum drm_exynos_ipp_state state) |
| 965 | { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 966 | if (ctrl != IPP_CTRL_PLAY) { |
| 967 | if (pm_runtime_suspended(dev)) { |
| 968 | DRM_ERROR("pm:runtime_suspended.\n"); |
| 969 | goto err_status; |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | switch (ctrl) { |
| 974 | case IPP_CTRL_PLAY: |
| 975 | if (state != IPP_STATE_IDLE) |
| 976 | goto err_status; |
| 977 | break; |
| 978 | case IPP_CTRL_STOP: |
| 979 | if (state == IPP_STATE_STOP) |
| 980 | goto err_status; |
| 981 | break; |
| 982 | case IPP_CTRL_PAUSE: |
| 983 | if (state != IPP_STATE_START) |
| 984 | goto err_status; |
| 985 | break; |
| 986 | case IPP_CTRL_RESUME: |
| 987 | if (state != IPP_STATE_STOP) |
| 988 | goto err_status; |
| 989 | break; |
| 990 | default: |
| 991 | DRM_ERROR("invalid state.\n"); |
| 992 | goto err_status; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | return true; |
| 996 | |
| 997 | err_status: |
| 998 | DRM_ERROR("invalid status:ctrl[%d]state[%d]\n", ctrl, state); |
| 999 | return false; |
| 1000 | } |
| 1001 | |
| 1002 | int exynos_drm_ipp_cmd_ctrl(struct drm_device *drm_dev, void *data, |
| 1003 | struct drm_file *file) |
| 1004 | { |
| 1005 | struct drm_exynos_file_private *file_priv = file->driver_priv; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1006 | struct exynos_drm_ippdrv *ippdrv = NULL; |
Andrzej Hajda | 5c76c5b | 2014-07-03 15:10:28 +0200 | [diff] [blame] | 1007 | struct device *dev = file_priv->ipp_dev; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1008 | struct ipp_context *ctx = get_ipp_context(dev); |
| 1009 | struct drm_exynos_ipp_cmd_ctrl *cmd_ctrl = data; |
| 1010 | struct drm_exynos_ipp_cmd_work *cmd_work; |
| 1011 | struct drm_exynos_ipp_cmd_node *c_node; |
| 1012 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1013 | if (!ctx) { |
| 1014 | DRM_ERROR("invalid context.\n"); |
| 1015 | return -EINVAL; |
| 1016 | } |
| 1017 | |
| 1018 | if (!cmd_ctrl) { |
| 1019 | DRM_ERROR("invalid control parameter.\n"); |
| 1020 | return -EINVAL; |
| 1021 | } |
| 1022 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1023 | DRM_DEBUG_KMS("ctrl[%d]prop_id[%d]\n", |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1024 | cmd_ctrl->ctrl, cmd_ctrl->prop_id); |
| 1025 | |
| 1026 | ippdrv = ipp_find_drv_by_handle(cmd_ctrl->prop_id); |
| 1027 | if (IS_ERR(ippdrv)) { |
| 1028 | DRM_ERROR("failed to get ipp driver.\n"); |
| 1029 | return PTR_ERR(ippdrv); |
| 1030 | } |
| 1031 | |
| 1032 | c_node = ipp_find_obj(&ctx->prop_idr, &ctx->prop_lock, |
| 1033 | cmd_ctrl->prop_id); |
Andrzej Hajda | 134f0e9 | 2014-07-03 15:10:34 +0200 | [diff] [blame] | 1034 | if (!c_node) { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1035 | DRM_ERROR("invalid command node list.\n"); |
Andrzej Hajda | 134f0e9 | 2014-07-03 15:10:34 +0200 | [diff] [blame] | 1036 | return -ENODEV; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | if (!exynos_drm_ipp_check_valid(ippdrv->dev, cmd_ctrl->ctrl, |
| 1040 | c_node->state)) { |
| 1041 | DRM_ERROR("invalid state.\n"); |
| 1042 | return -EINVAL; |
| 1043 | } |
| 1044 | |
| 1045 | switch (cmd_ctrl->ctrl) { |
| 1046 | case IPP_CTRL_PLAY: |
| 1047 | if (pm_runtime_suspended(ippdrv->dev)) |
| 1048 | pm_runtime_get_sync(ippdrv->dev); |
YoungJun Cho | ebaf05c | 2014-05-26 10:17:16 +0200 | [diff] [blame] | 1049 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1050 | c_node->state = IPP_STATE_START; |
| 1051 | |
| 1052 | cmd_work = c_node->start_work; |
| 1053 | cmd_work->ctrl = cmd_ctrl->ctrl; |
| 1054 | ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1055 | break; |
| 1056 | case IPP_CTRL_STOP: |
| 1057 | cmd_work = c_node->stop_work; |
| 1058 | cmd_work->ctrl = cmd_ctrl->ctrl; |
| 1059 | ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node); |
| 1060 | |
| 1061 | if (!wait_for_completion_timeout(&c_node->stop_complete, |
| 1062 | msecs_to_jiffies(300))) { |
| 1063 | DRM_ERROR("timeout stop:prop_id[%d]\n", |
| 1064 | c_node->property.prop_id); |
| 1065 | } |
| 1066 | |
| 1067 | c_node->state = IPP_STATE_STOP; |
| 1068 | ippdrv->dedicated = false; |
YoungJun Cho | 7f5af05 | 2014-05-26 10:17:18 +0200 | [diff] [blame] | 1069 | mutex_lock(&ippdrv->cmd_lock); |
YoungJun Cho | 075436b | 2014-05-26 10:17:19 +0200 | [diff] [blame] | 1070 | ipp_clean_cmd_node(ctx, c_node); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1071 | |
| 1072 | if (list_empty(&ippdrv->cmd_list)) |
| 1073 | pm_runtime_put_sync(ippdrv->dev); |
YoungJun Cho | 7f5af05 | 2014-05-26 10:17:18 +0200 | [diff] [blame] | 1074 | mutex_unlock(&ippdrv->cmd_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1075 | break; |
| 1076 | case IPP_CTRL_PAUSE: |
| 1077 | cmd_work = c_node->stop_work; |
| 1078 | cmd_work->ctrl = cmd_ctrl->ctrl; |
| 1079 | ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node); |
| 1080 | |
| 1081 | if (!wait_for_completion_timeout(&c_node->stop_complete, |
| 1082 | msecs_to_jiffies(200))) { |
| 1083 | DRM_ERROR("timeout stop:prop_id[%d]\n", |
| 1084 | c_node->property.prop_id); |
| 1085 | } |
| 1086 | |
| 1087 | c_node->state = IPP_STATE_STOP; |
| 1088 | break; |
| 1089 | case IPP_CTRL_RESUME: |
| 1090 | c_node->state = IPP_STATE_START; |
| 1091 | cmd_work = c_node->start_work; |
| 1092 | cmd_work->ctrl = cmd_ctrl->ctrl; |
| 1093 | ipp_handle_cmd_work(dev, ippdrv, cmd_work, c_node); |
| 1094 | break; |
| 1095 | default: |
| 1096 | DRM_ERROR("could not support this state currently.\n"); |
| 1097 | return -EINVAL; |
| 1098 | } |
| 1099 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1100 | DRM_DEBUG_KMS("done ctrl[%d]prop_id[%d]\n", |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1101 | cmd_ctrl->ctrl, cmd_ctrl->prop_id); |
| 1102 | |
| 1103 | return 0; |
| 1104 | } |
| 1105 | |
| 1106 | int exynos_drm_ippnb_register(struct notifier_block *nb) |
| 1107 | { |
| 1108 | return blocking_notifier_chain_register( |
| 1109 | &exynos_drm_ippnb_list, nb); |
| 1110 | } |
| 1111 | |
| 1112 | int exynos_drm_ippnb_unregister(struct notifier_block *nb) |
| 1113 | { |
| 1114 | return blocking_notifier_chain_unregister( |
| 1115 | &exynos_drm_ippnb_list, nb); |
| 1116 | } |
| 1117 | |
| 1118 | int exynos_drm_ippnb_send_event(unsigned long val, void *v) |
| 1119 | { |
| 1120 | return blocking_notifier_call_chain( |
| 1121 | &exynos_drm_ippnb_list, val, v); |
| 1122 | } |
| 1123 | |
| 1124 | static int ipp_set_property(struct exynos_drm_ippdrv *ippdrv, |
| 1125 | struct drm_exynos_ipp_property *property) |
| 1126 | { |
| 1127 | struct exynos_drm_ipp_ops *ops = NULL; |
| 1128 | bool swap = false; |
| 1129 | int ret, i; |
| 1130 | |
| 1131 | if (!property) { |
| 1132 | DRM_ERROR("invalid property parameter.\n"); |
| 1133 | return -EINVAL; |
| 1134 | } |
| 1135 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1136 | DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1137 | |
| 1138 | /* reset h/w block */ |
| 1139 | if (ippdrv->reset && |
| 1140 | ippdrv->reset(ippdrv->dev)) { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1141 | return -EINVAL; |
| 1142 | } |
| 1143 | |
| 1144 | /* set source,destination operations */ |
| 1145 | for_each_ipp_ops(i) { |
| 1146 | struct drm_exynos_ipp_config *config = |
| 1147 | &property->config[i]; |
| 1148 | |
| 1149 | ops = ippdrv->ops[i]; |
| 1150 | if (!ops || !config) { |
| 1151 | DRM_ERROR("not support ops and config.\n"); |
| 1152 | return -EINVAL; |
| 1153 | } |
| 1154 | |
| 1155 | /* set format */ |
| 1156 | if (ops->set_fmt) { |
| 1157 | ret = ops->set_fmt(ippdrv->dev, config->fmt); |
Andrzej Hajda | 57ace33 | 2014-07-03 15:10:35 +0200 | [diff] [blame] | 1158 | if (ret) |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1159 | return ret; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | /* set transform for rotation, flip */ |
| 1163 | if (ops->set_transf) { |
| 1164 | ret = ops->set_transf(ippdrv->dev, config->degree, |
| 1165 | config->flip, &swap); |
Andrzej Hajda | 57ace33 | 2014-07-03 15:10:35 +0200 | [diff] [blame] | 1166 | if (ret) |
| 1167 | return ret; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | /* set size */ |
| 1171 | if (ops->set_size) { |
| 1172 | ret = ops->set_size(ippdrv->dev, swap, &config->pos, |
| 1173 | &config->sz); |
Andrzej Hajda | 57ace33 | 2014-07-03 15:10:35 +0200 | [diff] [blame] | 1174 | if (ret) |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1175 | return ret; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | return 0; |
| 1180 | } |
| 1181 | |
| 1182 | static int ipp_start_property(struct exynos_drm_ippdrv *ippdrv, |
| 1183 | struct drm_exynos_ipp_cmd_node *c_node) |
| 1184 | { |
| 1185 | struct drm_exynos_ipp_mem_node *m_node; |
| 1186 | struct drm_exynos_ipp_property *property = &c_node->property; |
| 1187 | struct list_head *head; |
| 1188 | int ret, i; |
| 1189 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1190 | DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1191 | |
| 1192 | /* store command info in ippdrv */ |
Eunchul Kim | 7259c3d | 2012-12-22 17:49:22 +0900 | [diff] [blame] | 1193 | ippdrv->c_node = c_node; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1194 | |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 1195 | mutex_lock(&c_node->mem_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1196 | if (!ipp_check_mem_list(c_node)) { |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1197 | DRM_DEBUG_KMS("empty memory.\n"); |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 1198 | ret = -ENOMEM; |
| 1199 | goto err_unlock; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | /* set current property in ippdrv */ |
| 1203 | ret = ipp_set_property(ippdrv, property); |
| 1204 | if (ret) { |
| 1205 | DRM_ERROR("failed to set property.\n"); |
Eunchul Kim | 7259c3d | 2012-12-22 17:49:22 +0900 | [diff] [blame] | 1206 | ippdrv->c_node = NULL; |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 1207 | goto err_unlock; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | /* check command */ |
| 1211 | switch (property->cmd) { |
| 1212 | case IPP_CMD_M2M: |
| 1213 | for_each_ipp_ops(i) { |
| 1214 | /* source/destination memory list */ |
| 1215 | head = &c_node->mem_list[i]; |
| 1216 | |
| 1217 | m_node = list_first_entry(head, |
| 1218 | struct drm_exynos_ipp_mem_node, list); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1219 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1220 | DRM_DEBUG_KMS("m_node[0x%x]\n", (int)m_node); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1221 | |
| 1222 | ret = ipp_set_mem_node(ippdrv, c_node, m_node); |
| 1223 | if (ret) { |
| 1224 | DRM_ERROR("failed to set m node.\n"); |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 1225 | goto err_unlock; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1226 | } |
| 1227 | } |
| 1228 | break; |
| 1229 | case IPP_CMD_WB: |
| 1230 | /* destination memory list */ |
| 1231 | head = &c_node->mem_list[EXYNOS_DRM_OPS_DST]; |
| 1232 | |
| 1233 | list_for_each_entry(m_node, head, list) { |
| 1234 | ret = ipp_set_mem_node(ippdrv, c_node, m_node); |
| 1235 | if (ret) { |
| 1236 | DRM_ERROR("failed to set m node.\n"); |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 1237 | goto err_unlock; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1238 | } |
| 1239 | } |
| 1240 | break; |
| 1241 | case IPP_CMD_OUTPUT: |
| 1242 | /* source memory list */ |
| 1243 | head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC]; |
| 1244 | |
| 1245 | list_for_each_entry(m_node, head, list) { |
| 1246 | ret = ipp_set_mem_node(ippdrv, c_node, m_node); |
| 1247 | if (ret) { |
| 1248 | DRM_ERROR("failed to set m node.\n"); |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 1249 | goto err_unlock; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1250 | } |
| 1251 | } |
| 1252 | break; |
| 1253 | default: |
| 1254 | DRM_ERROR("invalid operations.\n"); |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 1255 | ret = -EINVAL; |
| 1256 | goto err_unlock; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1257 | } |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 1258 | mutex_unlock(&c_node->mem_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1259 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1260 | DRM_DEBUG_KMS("cmd[%d]\n", property->cmd); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1261 | |
| 1262 | /* start operations */ |
| 1263 | if (ippdrv->start) { |
| 1264 | ret = ippdrv->start(ippdrv->dev, property->cmd); |
| 1265 | if (ret) { |
| 1266 | DRM_ERROR("failed to start ops.\n"); |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 1267 | ippdrv->c_node = NULL; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1268 | return ret; |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | return 0; |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 1273 | |
| 1274 | err_unlock: |
| 1275 | mutex_unlock(&c_node->mem_lock); |
| 1276 | ippdrv->c_node = NULL; |
| 1277 | return ret; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | static int ipp_stop_property(struct drm_device *drm_dev, |
| 1281 | struct exynos_drm_ippdrv *ippdrv, |
| 1282 | struct drm_exynos_ipp_cmd_node *c_node) |
| 1283 | { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1284 | struct drm_exynos_ipp_property *property = &c_node->property; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1285 | int ret = 0, i; |
| 1286 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1287 | DRM_DEBUG_KMS("prop_id[%d]\n", property->prop_id); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1288 | |
| 1289 | /* put event */ |
| 1290 | ipp_put_event(c_node, NULL); |
| 1291 | |
| 1292 | /* check command */ |
| 1293 | switch (property->cmd) { |
| 1294 | case IPP_CMD_M2M: |
Andrzej Hajda | c4a856a | 2014-08-28 11:07:31 +0200 | [diff] [blame] | 1295 | for_each_ipp_ops(i) |
| 1296 | ipp_clean_mem_nodes(drm_dev, c_node, i); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1297 | break; |
| 1298 | case IPP_CMD_WB: |
Andrzej Hajda | c4a856a | 2014-08-28 11:07:31 +0200 | [diff] [blame] | 1299 | ipp_clean_mem_nodes(drm_dev, c_node, EXYNOS_DRM_OPS_DST); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1300 | break; |
| 1301 | case IPP_CMD_OUTPUT: |
Andrzej Hajda | c4a856a | 2014-08-28 11:07:31 +0200 | [diff] [blame] | 1302 | ipp_clean_mem_nodes(drm_dev, c_node, EXYNOS_DRM_OPS_SRC); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1303 | break; |
| 1304 | default: |
| 1305 | DRM_ERROR("invalid operations.\n"); |
| 1306 | ret = -EINVAL; |
| 1307 | goto err_clear; |
| 1308 | } |
| 1309 | |
| 1310 | err_clear: |
| 1311 | /* stop operations */ |
| 1312 | if (ippdrv->stop) |
| 1313 | ippdrv->stop(ippdrv->dev, property->cmd); |
| 1314 | |
| 1315 | return ret; |
| 1316 | } |
| 1317 | |
| 1318 | void ipp_sched_cmd(struct work_struct *work) |
| 1319 | { |
| 1320 | struct drm_exynos_ipp_cmd_work *cmd_work = |
Andrzej Hajda | 05afb1a | 2014-08-28 11:07:33 +0200 | [diff] [blame^] | 1321 | container_of(work, struct drm_exynos_ipp_cmd_work, work); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1322 | struct exynos_drm_ippdrv *ippdrv; |
| 1323 | struct drm_exynos_ipp_cmd_node *c_node; |
| 1324 | struct drm_exynos_ipp_property *property; |
| 1325 | int ret; |
| 1326 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1327 | ippdrv = cmd_work->ippdrv; |
| 1328 | if (!ippdrv) { |
| 1329 | DRM_ERROR("invalid ippdrv list.\n"); |
| 1330 | return; |
| 1331 | } |
| 1332 | |
| 1333 | c_node = cmd_work->c_node; |
| 1334 | if (!c_node) { |
| 1335 | DRM_ERROR("invalid command node list.\n"); |
| 1336 | return; |
| 1337 | } |
| 1338 | |
YoungJun Cho | 4e4fe55 | 2014-05-26 10:17:17 +0200 | [diff] [blame] | 1339 | mutex_lock(&c_node->lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1340 | |
| 1341 | property = &c_node->property; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1342 | |
| 1343 | switch (cmd_work->ctrl) { |
| 1344 | case IPP_CTRL_PLAY: |
| 1345 | case IPP_CTRL_RESUME: |
| 1346 | ret = ipp_start_property(ippdrv, c_node); |
| 1347 | if (ret) { |
| 1348 | DRM_ERROR("failed to start property:prop_id[%d]\n", |
| 1349 | c_node->property.prop_id); |
| 1350 | goto err_unlock; |
| 1351 | } |
| 1352 | |
| 1353 | /* |
| 1354 | * M2M case supports wait_completion of transfer. |
| 1355 | * because M2M case supports single unit operation |
| 1356 | * with multiple queue. |
| 1357 | * M2M need to wait completion of data transfer. |
| 1358 | */ |
| 1359 | if (ipp_is_m2m_cmd(property->cmd)) { |
| 1360 | if (!wait_for_completion_timeout |
| 1361 | (&c_node->start_complete, msecs_to_jiffies(200))) { |
| 1362 | DRM_ERROR("timeout event:prop_id[%d]\n", |
| 1363 | c_node->property.prop_id); |
| 1364 | goto err_unlock; |
| 1365 | } |
| 1366 | } |
| 1367 | break; |
| 1368 | case IPP_CTRL_STOP: |
| 1369 | case IPP_CTRL_PAUSE: |
| 1370 | ret = ipp_stop_property(ippdrv->drm_dev, ippdrv, |
| 1371 | c_node); |
| 1372 | if (ret) { |
| 1373 | DRM_ERROR("failed to stop property.\n"); |
| 1374 | goto err_unlock; |
| 1375 | } |
| 1376 | |
| 1377 | complete(&c_node->stop_complete); |
| 1378 | break; |
| 1379 | default: |
| 1380 | DRM_ERROR("unknown control type\n"); |
| 1381 | break; |
| 1382 | } |
| 1383 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1384 | DRM_DEBUG_KMS("ctrl[%d] done.\n", cmd_work->ctrl); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1385 | |
| 1386 | err_unlock: |
YoungJun Cho | 4e4fe55 | 2014-05-26 10:17:17 +0200 | [diff] [blame] | 1387 | mutex_unlock(&c_node->lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | static int ipp_send_event(struct exynos_drm_ippdrv *ippdrv, |
| 1391 | struct drm_exynos_ipp_cmd_node *c_node, int *buf_id) |
| 1392 | { |
| 1393 | struct drm_device *drm_dev = ippdrv->drm_dev; |
| 1394 | struct drm_exynos_ipp_property *property = &c_node->property; |
| 1395 | struct drm_exynos_ipp_mem_node *m_node; |
| 1396 | struct drm_exynos_ipp_queue_buf qbuf; |
| 1397 | struct drm_exynos_ipp_send_event *e; |
| 1398 | struct list_head *head; |
| 1399 | struct timeval now; |
| 1400 | unsigned long flags; |
| 1401 | u32 tbuf_id[EXYNOS_DRM_OPS_MAX] = {0, }; |
| 1402 | int ret, i; |
| 1403 | |
| 1404 | for_each_ipp_ops(i) |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1405 | DRM_DEBUG_KMS("%s buf_id[%d]\n", i ? "dst" : "src", buf_id[i]); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1406 | |
| 1407 | if (!drm_dev) { |
| 1408 | DRM_ERROR("failed to get drm_dev.\n"); |
| 1409 | return -EINVAL; |
| 1410 | } |
| 1411 | |
| 1412 | if (!property) { |
| 1413 | DRM_ERROR("failed to get property.\n"); |
| 1414 | return -EINVAL; |
| 1415 | } |
| 1416 | |
YoungJun Cho | 4d52076 | 2014-05-26 10:17:21 +0200 | [diff] [blame] | 1417 | mutex_lock(&c_node->event_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1418 | if (list_empty(&c_node->event_list)) { |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1419 | DRM_DEBUG_KMS("event list is empty.\n"); |
YoungJun Cho | 4d52076 | 2014-05-26 10:17:21 +0200 | [diff] [blame] | 1420 | ret = 0; |
| 1421 | goto err_event_unlock; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1422 | } |
| 1423 | |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 1424 | mutex_lock(&c_node->mem_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1425 | if (!ipp_check_mem_list(c_node)) { |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1426 | DRM_DEBUG_KMS("empty memory.\n"); |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 1427 | ret = 0; |
| 1428 | goto err_mem_unlock; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | /* check command */ |
| 1432 | switch (property->cmd) { |
| 1433 | case IPP_CMD_M2M: |
| 1434 | for_each_ipp_ops(i) { |
| 1435 | /* source/destination memory list */ |
| 1436 | head = &c_node->mem_list[i]; |
| 1437 | |
| 1438 | m_node = list_first_entry(head, |
| 1439 | struct drm_exynos_ipp_mem_node, list); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1440 | |
| 1441 | tbuf_id[i] = m_node->buf_id; |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1442 | DRM_DEBUG_KMS("%s buf_id[%d]\n", |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1443 | i ? "dst" : "src", tbuf_id[i]); |
| 1444 | |
| 1445 | ret = ipp_put_mem_node(drm_dev, c_node, m_node); |
| 1446 | if (ret) |
| 1447 | DRM_ERROR("failed to put m_node.\n"); |
| 1448 | } |
| 1449 | break; |
| 1450 | case IPP_CMD_WB: |
| 1451 | /* clear buf for finding */ |
| 1452 | memset(&qbuf, 0x0, sizeof(qbuf)); |
| 1453 | qbuf.ops_id = EXYNOS_DRM_OPS_DST; |
| 1454 | qbuf.buf_id = buf_id[EXYNOS_DRM_OPS_DST]; |
| 1455 | |
| 1456 | /* get memory node entry */ |
| 1457 | m_node = ipp_find_mem_node(c_node, &qbuf); |
| 1458 | if (!m_node) { |
| 1459 | DRM_ERROR("empty memory node.\n"); |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 1460 | ret = -ENOMEM; |
| 1461 | goto err_mem_unlock; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | tbuf_id[EXYNOS_DRM_OPS_DST] = m_node->buf_id; |
| 1465 | |
| 1466 | ret = ipp_put_mem_node(drm_dev, c_node, m_node); |
| 1467 | if (ret) |
| 1468 | DRM_ERROR("failed to put m_node.\n"); |
| 1469 | break; |
| 1470 | case IPP_CMD_OUTPUT: |
| 1471 | /* source memory list */ |
| 1472 | head = &c_node->mem_list[EXYNOS_DRM_OPS_SRC]; |
| 1473 | |
| 1474 | m_node = list_first_entry(head, |
| 1475 | struct drm_exynos_ipp_mem_node, list); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1476 | |
| 1477 | tbuf_id[EXYNOS_DRM_OPS_SRC] = m_node->buf_id; |
| 1478 | |
| 1479 | ret = ipp_put_mem_node(drm_dev, c_node, m_node); |
| 1480 | if (ret) |
| 1481 | DRM_ERROR("failed to put m_node.\n"); |
| 1482 | break; |
| 1483 | default: |
| 1484 | DRM_ERROR("invalid operations.\n"); |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 1485 | ret = -EINVAL; |
| 1486 | goto err_mem_unlock; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1487 | } |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 1488 | mutex_unlock(&c_node->mem_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1489 | |
| 1490 | if (tbuf_id[EXYNOS_DRM_OPS_DST] != buf_id[EXYNOS_DRM_OPS_DST]) |
| 1491 | DRM_ERROR("failed to match buf_id[%d %d]prop_id[%d]\n", |
| 1492 | tbuf_id[1], buf_id[1], property->prop_id); |
| 1493 | |
| 1494 | /* |
| 1495 | * command node have event list of destination buffer |
| 1496 | * If destination buffer enqueue to mem list, |
| 1497 | * then we make event and link to event list tail. |
| 1498 | * so, we get first event for first enqueued buffer. |
| 1499 | */ |
| 1500 | e = list_first_entry(&c_node->event_list, |
| 1501 | struct drm_exynos_ipp_send_event, base.link); |
| 1502 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1503 | do_gettimeofday(&now); |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1504 | DRM_DEBUG_KMS("tv_sec[%ld]tv_usec[%ld]\n", now.tv_sec, now.tv_usec); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1505 | e->event.tv_sec = now.tv_sec; |
| 1506 | e->event.tv_usec = now.tv_usec; |
| 1507 | e->event.prop_id = property->prop_id; |
| 1508 | |
| 1509 | /* set buffer id about source destination */ |
| 1510 | for_each_ipp_ops(i) |
| 1511 | e->event.buf_id[i] = tbuf_id[i]; |
| 1512 | |
| 1513 | spin_lock_irqsave(&drm_dev->event_lock, flags); |
| 1514 | list_move_tail(&e->base.link, &e->base.file_priv->event_list); |
| 1515 | wake_up_interruptible(&e->base.file_priv->event_wait); |
| 1516 | spin_unlock_irqrestore(&drm_dev->event_lock, flags); |
YoungJun Cho | 4d52076 | 2014-05-26 10:17:21 +0200 | [diff] [blame] | 1517 | mutex_unlock(&c_node->event_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1518 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1519 | DRM_DEBUG_KMS("done cmd[%d]prop_id[%d]buf_id[%d]\n", |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1520 | property->cmd, property->prop_id, tbuf_id[EXYNOS_DRM_OPS_DST]); |
| 1521 | |
| 1522 | return 0; |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 1523 | |
| 1524 | err_mem_unlock: |
| 1525 | mutex_unlock(&c_node->mem_lock); |
YoungJun Cho | 4d52076 | 2014-05-26 10:17:21 +0200 | [diff] [blame] | 1526 | err_event_unlock: |
| 1527 | mutex_unlock(&c_node->event_lock); |
YoungJun Cho | 220db6f | 2014-05-26 10:17:20 +0200 | [diff] [blame] | 1528 | return ret; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | void ipp_sched_event(struct work_struct *work) |
| 1532 | { |
| 1533 | struct drm_exynos_ipp_event_work *event_work = |
Andrzej Hajda | 05afb1a | 2014-08-28 11:07:33 +0200 | [diff] [blame^] | 1534 | container_of(work, struct drm_exynos_ipp_event_work, work); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1535 | struct exynos_drm_ippdrv *ippdrv; |
| 1536 | struct drm_exynos_ipp_cmd_node *c_node; |
| 1537 | int ret; |
| 1538 | |
| 1539 | if (!event_work) { |
| 1540 | DRM_ERROR("failed to get event_work.\n"); |
| 1541 | return; |
| 1542 | } |
| 1543 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1544 | DRM_DEBUG_KMS("buf_id[%d]\n", event_work->buf_id[EXYNOS_DRM_OPS_DST]); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1545 | |
| 1546 | ippdrv = event_work->ippdrv; |
| 1547 | if (!ippdrv) { |
| 1548 | DRM_ERROR("failed to get ipp driver.\n"); |
| 1549 | return; |
| 1550 | } |
| 1551 | |
Eunchul Kim | 7259c3d | 2012-12-22 17:49:22 +0900 | [diff] [blame] | 1552 | c_node = ippdrv->c_node; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1553 | if (!c_node) { |
| 1554 | DRM_ERROR("failed to get command node.\n"); |
| 1555 | return; |
| 1556 | } |
| 1557 | |
| 1558 | /* |
| 1559 | * IPP supports command thread, event thread synchronization. |
| 1560 | * If IPP close immediately from user land, then IPP make |
| 1561 | * synchronization with command thread, so make complete event. |
| 1562 | * or going out operations. |
| 1563 | */ |
| 1564 | if (c_node->state != IPP_STATE_START) { |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1565 | DRM_DEBUG_KMS("bypass state[%d]prop_id[%d]\n", |
| 1566 | c_node->state, c_node->property.prop_id); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1567 | goto err_completion; |
| 1568 | } |
| 1569 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1570 | ret = ipp_send_event(ippdrv, c_node, event_work->buf_id); |
| 1571 | if (ret) { |
| 1572 | DRM_ERROR("failed to send event.\n"); |
| 1573 | goto err_completion; |
| 1574 | } |
| 1575 | |
| 1576 | err_completion: |
| 1577 | if (ipp_is_m2m_cmd(c_node->property.cmd)) |
| 1578 | complete(&c_node->start_complete); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | static int ipp_subdrv_probe(struct drm_device *drm_dev, struct device *dev) |
| 1582 | { |
| 1583 | struct ipp_context *ctx = get_ipp_context(dev); |
| 1584 | struct exynos_drm_ippdrv *ippdrv; |
| 1585 | int ret, count = 0; |
| 1586 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1587 | /* get ipp driver entry */ |
| 1588 | list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) { |
| 1589 | ippdrv->drm_dev = drm_dev; |
| 1590 | |
Andrzej Hajda | 12ff54d | 2014-07-03 15:10:36 +0200 | [diff] [blame] | 1591 | ret = ipp_create_id(&ctx->ipp_idr, &ctx->ipp_lock, ippdrv); |
| 1592 | if (ret < 0) { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1593 | DRM_ERROR("failed to create id.\n"); |
YoungJun Cho | 075436b | 2014-05-26 10:17:19 +0200 | [diff] [blame] | 1594 | goto err; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1595 | } |
Andrzej Hajda | 12ff54d | 2014-07-03 15:10:36 +0200 | [diff] [blame] | 1596 | ippdrv->prop_list.ipp_id = ret; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1597 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1598 | DRM_DEBUG_KMS("count[%d]ippdrv[0x%x]ipp_id[%d]\n", |
Andrzej Hajda | 12ff54d | 2014-07-03 15:10:36 +0200 | [diff] [blame] | 1599 | count++, (int)ippdrv, ret); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1600 | |
| 1601 | /* store parent device for node */ |
| 1602 | ippdrv->parent_dev = dev; |
| 1603 | |
| 1604 | /* store event work queue and handler */ |
| 1605 | ippdrv->event_workq = ctx->event_workq; |
| 1606 | ippdrv->sched_event = ipp_sched_event; |
| 1607 | INIT_LIST_HEAD(&ippdrv->cmd_list); |
YoungJun Cho | 7f5af05 | 2014-05-26 10:17:18 +0200 | [diff] [blame] | 1608 | mutex_init(&ippdrv->cmd_lock); |
Eunchul Kim | c12e261 | 2012-12-14 17:58:54 +0900 | [diff] [blame] | 1609 | |
| 1610 | if (is_drm_iommu_supported(drm_dev)) { |
| 1611 | ret = drm_iommu_attach_device(drm_dev, ippdrv->dev); |
| 1612 | if (ret) { |
| 1613 | DRM_ERROR("failed to activate iommu\n"); |
YoungJun Cho | 075436b | 2014-05-26 10:17:19 +0200 | [diff] [blame] | 1614 | goto err; |
Eunchul Kim | c12e261 | 2012-12-14 17:58:54 +0900 | [diff] [blame] | 1615 | } |
| 1616 | } |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | return 0; |
| 1620 | |
YoungJun Cho | 075436b | 2014-05-26 10:17:19 +0200 | [diff] [blame] | 1621 | err: |
Eunchul Kim | c12e261 | 2012-12-14 17:58:54 +0900 | [diff] [blame] | 1622 | /* get ipp driver entry */ |
YoungJun Cho | 075436b | 2014-05-26 10:17:19 +0200 | [diff] [blame] | 1623 | list_for_each_entry_continue_reverse(ippdrv, &exynos_drm_ippdrv_list, |
| 1624 | drv_list) { |
Eunchul Kim | c12e261 | 2012-12-14 17:58:54 +0900 | [diff] [blame] | 1625 | if (is_drm_iommu_supported(drm_dev)) |
| 1626 | drm_iommu_detach_device(drm_dev, ippdrv->dev); |
| 1627 | |
YoungJun Cho | 075436b | 2014-05-26 10:17:19 +0200 | [diff] [blame] | 1628 | ipp_remove_id(&ctx->ipp_idr, &ctx->ipp_lock, |
| 1629 | ippdrv->prop_list.ipp_id); |
| 1630 | } |
| 1631 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1632 | return ret; |
| 1633 | } |
| 1634 | |
| 1635 | static void ipp_subdrv_remove(struct drm_device *drm_dev, struct device *dev) |
| 1636 | { |
| 1637 | struct exynos_drm_ippdrv *ippdrv; |
YoungJun Cho | 075436b | 2014-05-26 10:17:19 +0200 | [diff] [blame] | 1638 | struct ipp_context *ctx = get_ipp_context(dev); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1639 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1640 | /* get ipp driver entry */ |
| 1641 | list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) { |
Eunchul Kim | c12e261 | 2012-12-14 17:58:54 +0900 | [diff] [blame] | 1642 | if (is_drm_iommu_supported(drm_dev)) |
| 1643 | drm_iommu_detach_device(drm_dev, ippdrv->dev); |
| 1644 | |
YoungJun Cho | 075436b | 2014-05-26 10:17:19 +0200 | [diff] [blame] | 1645 | ipp_remove_id(&ctx->ipp_idr, &ctx->ipp_lock, |
| 1646 | ippdrv->prop_list.ipp_id); |
| 1647 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1648 | ippdrv->drm_dev = NULL; |
| 1649 | exynos_drm_ippdrv_unregister(ippdrv); |
| 1650 | } |
| 1651 | } |
| 1652 | |
| 1653 | static int ipp_subdrv_open(struct drm_device *drm_dev, struct device *dev, |
| 1654 | struct drm_file *file) |
| 1655 | { |
| 1656 | struct drm_exynos_file_private *file_priv = file->driver_priv; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1657 | |
Andrzej Hajda | 5c76c5b | 2014-07-03 15:10:28 +0200 | [diff] [blame] | 1658 | file_priv->ipp_dev = dev; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1659 | |
Andrzej Hajda | 5c76c5b | 2014-07-03 15:10:28 +0200 | [diff] [blame] | 1660 | DRM_DEBUG_KMS("done priv[0x%x]\n", (int)dev); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1661 | |
| 1662 | return 0; |
| 1663 | } |
| 1664 | |
| 1665 | static void ipp_subdrv_close(struct drm_device *drm_dev, struct device *dev, |
| 1666 | struct drm_file *file) |
| 1667 | { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1668 | struct exynos_drm_ippdrv *ippdrv = NULL; |
YoungJun Cho | 075436b | 2014-05-26 10:17:19 +0200 | [diff] [blame] | 1669 | struct ipp_context *ctx = get_ipp_context(dev); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1670 | struct drm_exynos_ipp_cmd_node *c_node, *tc_node; |
| 1671 | int count = 0; |
| 1672 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1673 | list_for_each_entry(ippdrv, &exynos_drm_ippdrv_list, drv_list) { |
YoungJun Cho | 7f5af05 | 2014-05-26 10:17:18 +0200 | [diff] [blame] | 1674 | mutex_lock(&ippdrv->cmd_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1675 | list_for_each_entry_safe(c_node, tc_node, |
| 1676 | &ippdrv->cmd_list, list) { |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1677 | DRM_DEBUG_KMS("count[%d]ippdrv[0x%x]\n", |
| 1678 | count++, (int)ippdrv); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1679 | |
Andrzej Hajda | 21a825e | 2014-08-28 11:07:28 +0200 | [diff] [blame] | 1680 | if (c_node->filp == file) { |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1681 | /* |
| 1682 | * userland goto unnormal state. process killed. |
| 1683 | * and close the file. |
| 1684 | * so, IPP didn't called stop cmd ctrl. |
| 1685 | * so, we are make stop operation in this state. |
| 1686 | */ |
| 1687 | if (c_node->state == IPP_STATE_START) { |
| 1688 | ipp_stop_property(drm_dev, ippdrv, |
| 1689 | c_node); |
| 1690 | c_node->state = IPP_STATE_STOP; |
| 1691 | } |
| 1692 | |
| 1693 | ippdrv->dedicated = false; |
YoungJun Cho | 075436b | 2014-05-26 10:17:19 +0200 | [diff] [blame] | 1694 | ipp_clean_cmd_node(ctx, c_node); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1695 | if (list_empty(&ippdrv->cmd_list)) |
| 1696 | pm_runtime_put_sync(ippdrv->dev); |
| 1697 | } |
| 1698 | } |
YoungJun Cho | 7f5af05 | 2014-05-26 10:17:18 +0200 | [diff] [blame] | 1699 | mutex_unlock(&ippdrv->cmd_lock); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1700 | } |
| 1701 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1702 | return; |
| 1703 | } |
| 1704 | |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 1705 | static int ipp_probe(struct platform_device *pdev) |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1706 | { |
| 1707 | struct device *dev = &pdev->dev; |
| 1708 | struct ipp_context *ctx; |
| 1709 | struct exynos_drm_subdrv *subdrv; |
| 1710 | int ret; |
| 1711 | |
Seung-Woo Kim | d873ab9 | 2013-05-22 21:14:14 +0900 | [diff] [blame] | 1712 | ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1713 | if (!ctx) |
| 1714 | return -ENOMEM; |
| 1715 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1716 | mutex_init(&ctx->ipp_lock); |
| 1717 | mutex_init(&ctx->prop_lock); |
| 1718 | |
| 1719 | idr_init(&ctx->ipp_idr); |
| 1720 | idr_init(&ctx->prop_idr); |
| 1721 | |
| 1722 | /* |
| 1723 | * create single thread for ipp event |
| 1724 | * IPP supports event thread for IPP drivers. |
| 1725 | * IPP driver send event_work to this thread. |
| 1726 | * and IPP event thread send event to user process. |
| 1727 | */ |
| 1728 | ctx->event_workq = create_singlethread_workqueue("ipp_event"); |
| 1729 | if (!ctx->event_workq) { |
| 1730 | dev_err(dev, "failed to create event workqueue\n"); |
Sachin Kamat | bfb6ed2 | 2012-12-24 14:03:42 +0530 | [diff] [blame] | 1731 | return -EINVAL; |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | /* |
| 1735 | * create single thread for ipp command |
| 1736 | * IPP supports command thread for user process. |
| 1737 | * user process make command node using set property ioctl. |
| 1738 | * and make start_work and send this work to command thread. |
| 1739 | * and then this command thread start property. |
| 1740 | */ |
| 1741 | ctx->cmd_workq = create_singlethread_workqueue("ipp_cmd"); |
| 1742 | if (!ctx->cmd_workq) { |
| 1743 | dev_err(dev, "failed to create cmd workqueue\n"); |
| 1744 | ret = -EINVAL; |
| 1745 | goto err_event_workq; |
| 1746 | } |
| 1747 | |
| 1748 | /* set sub driver informations */ |
| 1749 | subdrv = &ctx->subdrv; |
| 1750 | subdrv->dev = dev; |
| 1751 | subdrv->probe = ipp_subdrv_probe; |
| 1752 | subdrv->remove = ipp_subdrv_remove; |
| 1753 | subdrv->open = ipp_subdrv_open; |
| 1754 | subdrv->close = ipp_subdrv_close; |
| 1755 | |
| 1756 | platform_set_drvdata(pdev, ctx); |
| 1757 | |
| 1758 | ret = exynos_drm_subdrv_register(subdrv); |
| 1759 | if (ret < 0) { |
| 1760 | DRM_ERROR("failed to register drm ipp device.\n"); |
| 1761 | goto err_cmd_workq; |
| 1762 | } |
| 1763 | |
Seung-Woo Kim | d873ab9 | 2013-05-22 21:14:14 +0900 | [diff] [blame] | 1764 | dev_info(dev, "drm ipp registered successfully.\n"); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1765 | |
| 1766 | return 0; |
| 1767 | |
| 1768 | err_cmd_workq: |
| 1769 | destroy_workqueue(ctx->cmd_workq); |
| 1770 | err_event_workq: |
| 1771 | destroy_workqueue(ctx->event_workq); |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1772 | return ret; |
| 1773 | } |
| 1774 | |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 1775 | static int ipp_remove(struct platform_device *pdev) |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1776 | { |
| 1777 | struct ipp_context *ctx = platform_get_drvdata(pdev); |
| 1778 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1779 | /* unregister sub driver */ |
| 1780 | exynos_drm_subdrv_unregister(&ctx->subdrv); |
| 1781 | |
| 1782 | /* remove,destroy ipp idr */ |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1783 | idr_destroy(&ctx->ipp_idr); |
| 1784 | idr_destroy(&ctx->prop_idr); |
| 1785 | |
| 1786 | mutex_destroy(&ctx->ipp_lock); |
| 1787 | mutex_destroy(&ctx->prop_lock); |
| 1788 | |
| 1789 | /* destroy command, event work queue */ |
| 1790 | destroy_workqueue(ctx->cmd_workq); |
| 1791 | destroy_workqueue(ctx->event_workq); |
| 1792 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1793 | return 0; |
| 1794 | } |
| 1795 | |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1796 | struct platform_driver ipp_driver = { |
| 1797 | .probe = ipp_probe, |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 1798 | .remove = ipp_remove, |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1799 | .driver = { |
| 1800 | .name = "exynos-drm-ipp", |
| 1801 | .owner = THIS_MODULE, |
Eunchul Kim | cb471f14 | 2012-12-14 18:10:31 +0900 | [diff] [blame] | 1802 | }, |
| 1803 | }; |
| 1804 | |