Benjamin Chan | 59a0605 | 2017-01-12 18:06:03 -0500 | [diff] [blame] | 1 | /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #ifndef SDE_ROTATOR_CORE_H |
| 15 | #define SDE_ROTATOR_CORE_H |
| 16 | |
| 17 | #include <linux/list.h> |
| 18 | #include <linux/file.h> |
| 19 | #include <linux/ktime.h> |
| 20 | #include <linux/mutex.h> |
| 21 | #include <linux/types.h> |
| 22 | #include <linux/cdev.h> |
| 23 | #include <linux/pm_runtime.h> |
| 24 | |
| 25 | #include "sde_rotator_base.h" |
| 26 | #include "sde_rotator_util.h" |
| 27 | #include "sde_rotator_sync.h" |
| 28 | |
| 29 | /********************************************************************** |
| 30 | * Rotation request flag |
| 31 | **********************************************************************/ |
| 32 | /* no rotation flag */ |
| 33 | #define SDE_ROTATION_NOP 0x01 |
| 34 | |
| 35 | /* left/right flip */ |
| 36 | #define SDE_ROTATION_FLIP_LR 0x02 |
| 37 | |
| 38 | /* up/down flip */ |
| 39 | #define SDE_ROTATION_FLIP_UD 0x04 |
| 40 | |
| 41 | /* rotate 90 degree */ |
| 42 | #define SDE_ROTATION_90 0x08 |
| 43 | |
| 44 | /* rotate 180 degre */ |
| 45 | #define SDE_ROTATION_180 (SDE_ROTATION_FLIP_LR | SDE_ROTATION_FLIP_UD) |
| 46 | |
| 47 | /* rotate 270 degree */ |
| 48 | #define SDE_ROTATION_270 (SDE_ROTATION_90 | SDE_ROTATION_180) |
| 49 | |
| 50 | /* format is interlaced */ |
| 51 | #define SDE_ROTATION_DEINTERLACE 0x10 |
| 52 | |
| 53 | /* secure data */ |
| 54 | #define SDE_ROTATION_SECURE 0x80 |
| 55 | |
| 56 | /* verify input configuration only */ |
| 57 | #define SDE_ROTATION_VERIFY_INPUT_ONLY 0x10000 |
| 58 | |
| 59 | /* use client provided dma buf instead of ion fd */ |
| 60 | #define SDE_ROTATION_EXT_DMA_BUF 0x20000 |
| 61 | |
Abhijit Kulkarni | 298c823 | 2016-09-26 22:32:10 -0700 | [diff] [blame] | 62 | /* secure camera operation*/ |
| 63 | #define SDE_ROTATION_SECURE_CAMERA 0x40000 |
| 64 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame^] | 65 | /* use client mapped i/o virtual address */ |
| 66 | #define SDE_ROTATION_EXT_IOVA 0x80000 |
| 67 | |
Alan Kwong | a94684f | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 68 | /********************************************************************** |
| 69 | * configuration structures |
| 70 | **********************************************************************/ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 71 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 72 | /* |
| 73 | * struct sde_rotation_buf_info - input/output buffer configuration |
| 74 | * @width: width of buffer region to be processed |
| 75 | * @height: height of buffer region to be processed |
| 76 | * @format: pixel format of buffer |
| 77 | * @comp_ratio: compression ratio for the session |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame^] | 78 | * @sbuf: true if buffer is streaming buffer |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 79 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 80 | struct sde_rotation_buf_info { |
| 81 | uint32_t width; |
| 82 | uint32_t height; |
| 83 | uint32_t format; |
| 84 | struct sde_mult_factor comp_ratio; |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame^] | 85 | bool sbuf; |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 88 | /* |
| 89 | * struct sde_rotation_config - rotation configuration for given session |
| 90 | * @session_id: identifier of the given session |
| 91 | * @input: input buffer information |
| 92 | * @output: output buffer information |
| 93 | * @frame_rate: session frame rate in fps |
| 94 | * @flags: configuration flags, e.g. rotation angle, flip, etc... |
| 95 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 96 | struct sde_rotation_config { |
| 97 | uint32_t session_id; |
| 98 | struct sde_rotation_buf_info input; |
| 99 | struct sde_rotation_buf_info output; |
| 100 | uint32_t frame_rate; |
| 101 | uint32_t flags; |
| 102 | }; |
| 103 | |
| 104 | enum sde_rotator_ts { |
| 105 | SDE_ROTATOR_TS_SRCQB, /* enqueue source buffer */ |
| 106 | SDE_ROTATOR_TS_DSTQB, /* enqueue destination buffer */ |
| 107 | SDE_ROTATOR_TS_FENCE, /* wait for source buffer fence */ |
| 108 | SDE_ROTATOR_TS_QUEUE, /* wait for h/w resource */ |
| 109 | SDE_ROTATOR_TS_COMMIT, /* prepare h/w command */ |
| 110 | SDE_ROTATOR_TS_FLUSH, /* initiate h/w processing */ |
| 111 | SDE_ROTATOR_TS_DONE, /* receive h/w completion */ |
| 112 | SDE_ROTATOR_TS_RETIRE, /* signal destination buffer fence */ |
| 113 | SDE_ROTATOR_TS_SRCDQB, /* dequeue source buffer */ |
| 114 | SDE_ROTATOR_TS_DSTDQB, /* dequeue destination buffer */ |
| 115 | SDE_ROTATOR_TS_MAX |
| 116 | }; |
| 117 | |
Benjamin Chan | 77aed19 | 2016-10-17 17:49:41 -0400 | [diff] [blame] | 118 | enum sde_rotator_clk_type { |
| 119 | SDE_ROTATOR_CLK_MDSS_AHB, |
| 120 | SDE_ROTATOR_CLK_MDSS_AXI, |
| 121 | SDE_ROTATOR_CLK_ROT_CORE, |
| 122 | SDE_ROTATOR_CLK_MDSS_ROT, |
| 123 | SDE_ROTATOR_CLK_MNOC_AHB, |
Alan Kwong | e1947ab | 2016-11-26 13:32:25 -0800 | [diff] [blame] | 124 | SDE_ROTATOR_CLK_GCC_AHB, |
| 125 | SDE_ROTATOR_CLK_GCC_AXI, |
Benjamin Chan | 77aed19 | 2016-10-17 17:49:41 -0400 | [diff] [blame] | 126 | SDE_ROTATOR_CLK_MAX |
| 127 | }; |
| 128 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame^] | 129 | enum sde_rotator_trigger { |
| 130 | SDE_ROTATOR_TRIGGER_IMMEDIATE, |
| 131 | SDE_ROTATOR_TRIGGER_VIDEO, |
| 132 | SDE_ROTATOR_TRIGGER_COMMAND, |
| 133 | }; |
| 134 | |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 135 | struct sde_rotation_item { |
| 136 | /* rotation request flag */ |
| 137 | uint32_t flags; |
| 138 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame^] | 139 | /* rotation trigger mode */ |
| 140 | uint32_t trigger; |
| 141 | |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 142 | /* Source crop rectangle */ |
| 143 | struct sde_rect src_rect; |
| 144 | |
| 145 | /* Destination rectangle */ |
| 146 | struct sde_rect dst_rect; |
| 147 | |
| 148 | /* Input buffer for the request */ |
| 149 | struct sde_layer_buffer input; |
| 150 | |
| 151 | /* The output buffer for the request */ |
| 152 | struct sde_layer_buffer output; |
| 153 | |
Alan Kwong | a94684f | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 154 | /* |
| 155 | * DMA pipe selection for this request by client: |
| 156 | * 0: DMA pipe 0 |
| 157 | * 1: DMA pipe 1 |
| 158 | * or SDE_ROTATION_HW_ANY if client wants |
| 159 | * driver to allocate any that is available |
| 160 | * |
| 161 | * OR |
| 162 | * |
| 163 | * Reserved |
| 164 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 165 | uint32_t pipe_idx; |
| 166 | |
Alan Kwong | a94684f | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 167 | /* |
| 168 | * Write-back block selection for this request by client: |
| 169 | * 0: Write-back block 0 |
| 170 | * 1: Write-back block 1 |
| 171 | * or SDE_ROTATION_HW_ANY if client wants |
| 172 | * driver to allocate any that is available |
| 173 | * |
| 174 | * OR |
| 175 | * |
| 176 | * Priority selection for this request by client: |
| 177 | * 0: Highest |
| 178 | * 1..n: Limited by the lowest available priority |
| 179 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 180 | uint32_t wb_idx; |
| 181 | |
Alan Kwong | a94684f | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 182 | /* |
| 183 | * Sequence ID of this request within the session |
| 184 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 185 | uint32_t sequence_id; |
| 186 | |
| 187 | /* Which session ID is this request scheduled on */ |
| 188 | uint32_t session_id; |
| 189 | |
| 190 | /* Time stamp for profiling purposes */ |
| 191 | ktime_t *ts; |
| 192 | }; |
| 193 | |
| 194 | /* |
| 195 | * Defining characteristics about rotation work, that has corresponding |
| 196 | * fmt and roi checks in open session |
| 197 | */ |
| 198 | #define SDE_ROT_DEFINING_FLAG_BITS SDE_ROTATION_90 |
| 199 | |
| 200 | struct sde_rot_entry; |
| 201 | struct sde_rot_perf; |
| 202 | |
| 203 | struct sde_rot_clk { |
| 204 | struct clk *clk; |
| 205 | char clk_name[32]; |
| 206 | unsigned long rate; |
| 207 | }; |
| 208 | |
| 209 | struct sde_rot_hw_resource { |
| 210 | u32 wb_id; |
| 211 | u32 pending_count; |
| 212 | atomic_t num_active; |
| 213 | int max_active; |
| 214 | wait_queue_head_t wait_queue; |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 215 | }; |
| 216 | |
| 217 | struct sde_rot_queue { |
| 218 | struct workqueue_struct *rot_work_queue; |
| 219 | struct sde_rot_timeline *timeline; |
| 220 | struct sde_rot_hw_resource *hw; |
| 221 | }; |
| 222 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 223 | /* |
| 224 | * struct sde_rot_entry_container - rotation request |
| 225 | * @list: list of active requests managed by rotator manager |
| 226 | * @flags: reserved |
| 227 | * @count: size of rotation entries |
| 228 | * @pending_count: count of entries pending completion |
| 229 | * @failed_count: count of entries failed completion |
| 230 | * @finished: true if client is finished with the request |
| 231 | * @retireq: workqueue to post completion notification |
| 232 | * @retire_work: work for completion notification |
| 233 | * @entries: array of rotation entries |
| 234 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 235 | struct sde_rot_entry_container { |
| 236 | struct list_head list; |
| 237 | u32 flags; |
| 238 | u32 count; |
| 239 | atomic_t pending_count; |
| 240 | atomic_t failed_count; |
| 241 | struct workqueue_struct *retireq; |
| 242 | struct work_struct *retire_work; |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 243 | bool finished; |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 244 | struct sde_rot_entry *entries; |
| 245 | }; |
| 246 | |
| 247 | struct sde_rot_mgr; |
| 248 | struct sde_rot_file_private; |
| 249 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame^] | 250 | /* |
| 251 | * struct sde_rot_entry - rotation entry |
| 252 | * @item: rotation item |
| 253 | * @commit_work: work descriptor for commit handler |
| 254 | * @done_work: work descriptor for done handler |
| 255 | * @commitq: pointer to commit handler rotator queue |
| 256 | * @fenceq: pointer to fence signaling rotator queue |
| 257 | * @doneq: pointer to done handler rotator queue |
| 258 | * @request: pointer to containing request |
| 259 | * @src_buf: descriptor of source buffer |
| 260 | * @dst_buf: descriptor of destination buffer |
| 261 | * @input_fence: pointer to input fence for when input content is available |
| 262 | * @output_fence: pointer to output fence for when output content is available |
| 263 | * @output_signaled: true if output fence of this entry has been signaled |
| 264 | * @dnsc_factor_w: calculated width downscale factor for this entry |
| 265 | * @dnsc_factor_w: calculated height downscale factor for this entry |
| 266 | * @perf: pointer to performance configuration associated with this entry |
| 267 | * @work_assigned: true if this item is assigned to h/w queue/unit |
| 268 | * @private: pointer to controlling session context |
| 269 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 270 | struct sde_rot_entry { |
| 271 | struct sde_rotation_item item; |
| 272 | struct work_struct commit_work; |
| 273 | struct work_struct done_work; |
| 274 | struct sde_rot_queue *commitq; |
| 275 | struct sde_rot_queue *fenceq; |
| 276 | struct sde_rot_queue *doneq; |
| 277 | struct sde_rot_entry_container *request; |
| 278 | |
| 279 | struct sde_mdp_data src_buf; |
| 280 | struct sde_mdp_data dst_buf; |
| 281 | |
| 282 | struct sde_rot_sync_fence *input_fence; |
| 283 | |
| 284 | struct sde_rot_sync_fence *output_fence; |
| 285 | bool output_signaled; |
| 286 | |
| 287 | u32 dnsc_factor_w; |
| 288 | u32 dnsc_factor_h; |
| 289 | |
| 290 | struct sde_rot_perf *perf; |
| 291 | bool work_assigned; /* Used when cleaning up work_distribution */ |
| 292 | struct sde_rot_file_private *private; |
| 293 | }; |
| 294 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame^] | 295 | /* |
| 296 | * struct sde_rot_perf - rotator session performance configuration |
| 297 | * @list: list of performance configuration under one session |
| 298 | * @config: current rotation configuration |
| 299 | * @clk_rate: current clock rate in Hz |
| 300 | * @bw: current bandwidth in byte per second |
| 301 | * @work_dis_lock: serialization lock for updating work distribution (not used) |
| 302 | * @work_distribution: work distribution among multiple hardware queue/unit |
| 303 | * @last_wb_idx: last queue/unit index, used to account for pre-distributed work |
| 304 | * @rdot_limit: read OT limit of this session |
| 305 | * @wrot_limit: write OT limit of this session |
| 306 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 307 | struct sde_rot_perf { |
| 308 | struct list_head list; |
| 309 | struct sde_rotation_config config; |
| 310 | unsigned long clk_rate; |
| 311 | u64 bw; |
| 312 | struct mutex work_dis_lock; |
| 313 | u32 *work_distribution; |
| 314 | int last_wb_idx; /* last known wb index, used when above count is 0 */ |
Alan Kwong | effb5ee | 2016-03-12 19:47:45 -0500 | [diff] [blame] | 315 | u32 rdot_limit; |
| 316 | u32 wrot_limit; |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 317 | }; |
| 318 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame^] | 319 | /* |
| 320 | * struct sde_rot_file_private - rotator manager per session context |
| 321 | * @list: list of all session context |
| 322 | * @req_list: list of rotation request for this session |
| 323 | * @perf_list: list of performance configuration for this session (only one) |
| 324 | * @mgr: pointer to the controlling rotator manager |
| 325 | * @fenceq: pointer to rotator queue to signal when entry is done |
| 326 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 327 | struct sde_rot_file_private { |
| 328 | struct list_head list; |
| 329 | struct list_head req_list; |
| 330 | struct list_head perf_list; |
| 331 | struct sde_rot_mgr *mgr; |
| 332 | struct sde_rot_queue *fenceq; |
| 333 | }; |
| 334 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame^] | 335 | /* |
| 336 | * struct sde_rot_bus_data_type - rotator bus scaling configuration |
| 337 | * @bus_cale_pdata: pointer to bus scaling configuration table |
| 338 | * @bus_hdl: msm bus scaling handle |
| 339 | * @curr_bw_uc_idx; current usecase index into configuration table |
| 340 | * @curr_quota_val: current bandwidth request in byte per second |
| 341 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 342 | struct sde_rot_bus_data_type { |
| 343 | struct msm_bus_scale_pdata *bus_scale_pdata; |
| 344 | u32 bus_hdl; |
| 345 | u32 curr_bw_uc_idx; |
| 346 | u64 curr_quota_val; |
| 347 | }; |
| 348 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame^] | 349 | /* |
| 350 | * struct sde_rot_mgr - core rotator manager |
| 351 | * @lock: serialization lock to rotator manager functions |
| 352 | * @device_suspended: 0 if device is not suspended; non-zero suspended |
| 353 | * @pdev: pointer to controlling platform device |
| 354 | * @device: pointer to controlling device |
| 355 | * @queue_count: number of hardware queue/unit available |
| 356 | * @commitq: array of rotator commit queue corresponding to hardware queue |
| 357 | * @doneq: array of rotator done queue corresponding to hardware queue |
| 358 | * @file_list: list of all sessions managed by rotator manager |
| 359 | * @pending_close_bw_vote: bandwidth of closed sessions with pending work |
| 360 | * @data_bus: data bus configuration state |
| 361 | * @reg_bus: register bus configuration state |
| 362 | * @module_power: power/clock configuration state |
| 363 | * @regulator_enable: true if foot switch is enabled; false otherwise |
| 364 | * @res_ref_cnt: reference count of how many times resource is requested |
| 365 | * @rot_enable_clk_cnt: reference count of how many times clock is requested |
| 366 | * @rot_clk: array of rotator and periphery clocks |
| 367 | * @num_rot_clk: size of the rotator clock array |
| 368 | * @rdot_limit: current read OT limit |
| 369 | * @wrot_limit: current write OT limit |
| 370 | * @hwacquire_timeout: maximum wait time for hardware availability in msec |
| 371 | * @pixel_per_clk: rotator hardware performance in pixel for clock |
| 372 | * @fudge_factor: fudge factor for clock calculation |
| 373 | * @overhead: software overhead for offline rotation in msec |
| 374 | * @sbuf_ctx: pointer to sbuf session context |
| 375 | * @ops_xxx: function pointers of rotator HAL layer |
| 376 | * @hw_data: private handle of rotator HAL layer |
| 377 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 378 | struct sde_rot_mgr { |
| 379 | struct mutex lock; |
| 380 | atomic_t device_suspended; |
| 381 | struct platform_device *pdev; |
| 382 | struct device *device; |
| 383 | |
| 384 | /* |
| 385 | * Managing rotation queues, depends on |
| 386 | * how many hw pipes available on the system |
| 387 | */ |
| 388 | int queue_count; |
| 389 | struct sde_rot_queue *commitq; |
| 390 | struct sde_rot_queue *doneq; |
| 391 | |
| 392 | /* |
| 393 | * managing all the open file sessions to bw calculations, |
| 394 | * and resource clean up during suspend |
| 395 | */ |
| 396 | struct list_head file_list; |
| 397 | |
| 398 | u64 pending_close_bw_vote; |
| 399 | struct sde_rot_bus_data_type data_bus; |
| 400 | struct sde_rot_bus_data_type reg_bus; |
| 401 | |
| 402 | /* Module power is only used for regulator management */ |
| 403 | struct sde_module_power module_power; |
| 404 | bool regulator_enable; |
| 405 | |
| 406 | int res_ref_cnt; |
| 407 | int rot_enable_clk_cnt; |
| 408 | struct sde_rot_clk *rot_clk; |
| 409 | int num_rot_clk; |
Alan Kwong | effb5ee | 2016-03-12 19:47:45 -0500 | [diff] [blame] | 410 | u32 rdot_limit; |
| 411 | u32 wrot_limit; |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 412 | |
| 413 | u32 hwacquire_timeout; |
| 414 | struct sde_mult_factor pixel_per_clk; |
Benjamin Chan | dbe1311 | 2016-09-26 12:10:06 -0400 | [diff] [blame] | 415 | struct sde_mult_factor fudge_factor; |
| 416 | struct sde_mult_factor overhead; |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 417 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame^] | 418 | struct sde_rot_file_private *sbuf_ctx; |
| 419 | |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 420 | int (*ops_config_hw)(struct sde_rot_hw_resource *hw, |
| 421 | struct sde_rot_entry *entry); |
| 422 | int (*ops_kickoff_entry)(struct sde_rot_hw_resource *hw, |
| 423 | struct sde_rot_entry *entry); |
| 424 | int (*ops_wait_for_entry)(struct sde_rot_hw_resource *hw, |
| 425 | struct sde_rot_entry *entry); |
| 426 | struct sde_rot_hw_resource *(*ops_hw_alloc)(struct sde_rot_mgr *mgr, |
| 427 | u32 pipe_id, u32 wb_id); |
| 428 | void (*ops_hw_free)(struct sde_rot_mgr *mgr, |
| 429 | struct sde_rot_hw_resource *hw); |
| 430 | int (*ops_hw_init)(struct sde_rot_mgr *mgr); |
Benjamin Chan | 0f9e61d | 2016-09-16 16:01:09 -0400 | [diff] [blame] | 431 | void (*ops_hw_pre_pmevent)(struct sde_rot_mgr *mgr, bool pmon); |
| 432 | void (*ops_hw_post_pmevent)(struct sde_rot_mgr *mgr, bool pmon); |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 433 | void (*ops_hw_destroy)(struct sde_rot_mgr *mgr); |
| 434 | ssize_t (*ops_hw_show_caps)(struct sde_rot_mgr *mgr, |
| 435 | struct device_attribute *attr, char *buf, ssize_t len); |
| 436 | ssize_t (*ops_hw_show_state)(struct sde_rot_mgr *mgr, |
| 437 | struct device_attribute *attr, char *buf, ssize_t len); |
| 438 | int (*ops_hw_create_debugfs)(struct sde_rot_mgr *mgr, |
| 439 | struct dentry *debugfs_root); |
| 440 | int (*ops_hw_validate_entry)(struct sde_rot_mgr *mgr, |
| 441 | struct sde_rot_entry *entry); |
Alan Kwong | da16e44 | 2016-08-14 20:47:18 -0400 | [diff] [blame] | 442 | u32 (*ops_hw_get_pixfmt)(struct sde_rot_mgr *mgr, int index, |
| 443 | bool input); |
| 444 | int (*ops_hw_is_valid_pixfmt)(struct sde_rot_mgr *mgr, u32 pixfmt, |
| 445 | bool input); |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame^] | 446 | int (*ops_hw_get_downscale_caps)(struct sde_rot_mgr *mgr, char *caps, |
| 447 | int len); |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 448 | |
| 449 | void *hw_data; |
| 450 | }; |
| 451 | |
Alan Kwong | da16e44 | 2016-08-14 20:47:18 -0400 | [diff] [blame] | 452 | static inline int sde_rotator_is_valid_pixfmt(struct sde_rot_mgr *mgr, |
| 453 | u32 pixfmt, bool input) |
| 454 | { |
| 455 | if (mgr && mgr->ops_hw_is_valid_pixfmt) |
| 456 | return mgr->ops_hw_is_valid_pixfmt(mgr, pixfmt, input); |
| 457 | |
| 458 | return false; |
| 459 | } |
| 460 | |
| 461 | static inline u32 sde_rotator_get_pixfmt(struct sde_rot_mgr *mgr, |
| 462 | int index, bool input) |
| 463 | { |
| 464 | if (mgr && mgr->ops_hw_get_pixfmt) |
| 465 | return mgr->ops_hw_get_pixfmt(mgr, index, input); |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame^] | 470 | static inline int sde_rotator_get_downscale_caps(struct sde_rot_mgr *mgr, |
| 471 | char *caps, int len) |
| 472 | { |
| 473 | if (mgr && mgr->ops_hw_get_downscale_caps) |
| 474 | return mgr->ops_hw_get_downscale_caps(mgr, caps, len); |
| 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 479 | static inline int __compare_session_item_rect( |
| 480 | struct sde_rotation_buf_info *s_rect, |
| 481 | struct sde_rect *i_rect, uint32_t i_fmt, bool src) |
| 482 | { |
| 483 | if ((s_rect->width != i_rect->w) || (s_rect->height != i_rect->h) || |
| 484 | (s_rect->format != i_fmt)) { |
| 485 | SDEROT_DBG( |
| 486 | "%s: session{%u,%u}f:%u mismatch from item{%u,%u}f:%u\n", |
| 487 | (src ? "src":"dst"), s_rect->width, s_rect->height, |
| 488 | s_rect->format, i_rect->w, i_rect->h, i_fmt); |
| 489 | return -EINVAL; |
| 490 | } |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | /* |
| 495 | * Compare all important flag bits associated with rotation between session |
| 496 | * config and item request. Format and roi validation is done during open |
| 497 | * session and is based certain defining bits. If these defining bits are |
| 498 | * different in item request, there is a possibility that rotation item |
| 499 | * is not a valid configuration. |
| 500 | */ |
| 501 | static inline int __compare_session_rotations(uint32_t cfg_flag, |
| 502 | uint32_t item_flag) |
| 503 | { |
| 504 | cfg_flag &= SDE_ROT_DEFINING_FLAG_BITS; |
| 505 | item_flag &= SDE_ROT_DEFINING_FLAG_BITS; |
| 506 | if (cfg_flag != item_flag) { |
| 507 | SDEROT_DBG( |
| 508 | "Rotation degree request different from open session\n"); |
| 509 | return -EINVAL; |
| 510 | } |
| 511 | return 0; |
| 512 | } |
| 513 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 514 | /* |
| 515 | * sde_rotator_core_init - initialize rotator manager for the given platform |
| 516 | * device |
| 517 | * @pmgr: Pointer to pointer of the newly initialized rotator manager |
| 518 | * @pdev: Pointer to platform device |
| 519 | * return: 0 if success; error code otherwise |
| 520 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 521 | int sde_rotator_core_init(struct sde_rot_mgr **pmgr, |
| 522 | struct platform_device *pdev); |
| 523 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 524 | /* |
| 525 | * sde_rotator_core_destroy - destroy given rotator manager |
| 526 | * @mgr: Pointer to rotator manager |
| 527 | * return: none |
| 528 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 529 | void sde_rotator_core_destroy(struct sde_rot_mgr *mgr); |
| 530 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 531 | /* |
| 532 | * sde_rotator_session_open - open a new rotator per file session |
| 533 | * @mgr: Pointer to rotator manager |
| 534 | * @pprivate: Pointer to pointer of the newly initialized per file session |
| 535 | * @session_id: identifier of the newly created session |
| 536 | * @queue: Pointer to fence queue of the new session |
| 537 | * return: 0 if success; error code otherwise |
| 538 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 539 | int sde_rotator_session_open(struct sde_rot_mgr *mgr, |
| 540 | struct sde_rot_file_private **pprivate, int session_id, |
| 541 | struct sde_rot_queue *queue); |
| 542 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 543 | /* |
| 544 | * sde_rotator_session_close - close the given rotator per file session |
| 545 | * @mgr: Pointer to rotator manager |
| 546 | * @private: Pointer to per file session |
| 547 | * @session_id: identifier of the session |
| 548 | * return: none |
| 549 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 550 | void sde_rotator_session_close(struct sde_rot_mgr *mgr, |
| 551 | struct sde_rot_file_private *private, int session_id); |
| 552 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 553 | /* |
| 554 | * sde_rotator_session_config - configure the given rotator per file session |
| 555 | * @mgr: Pointer to rotator manager |
| 556 | * @private: Pointer to per file session |
| 557 | * @config: Pointer to rotator configuration |
| 558 | * return: 0 if success; error code otherwise |
| 559 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 560 | int sde_rotator_session_config(struct sde_rot_mgr *mgr, |
| 561 | struct sde_rot_file_private *private, |
| 562 | struct sde_rotation_config *config); |
| 563 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 564 | /* |
| 565 | * sde_rotator_req_init - allocate a new request and initialzie with given |
| 566 | * array of rotation items |
| 567 | * @rot_dev: Pointer to rotator device |
| 568 | * @private: Pointer to rotator manager per file context |
| 569 | * @items: Pointer to array of rotation item |
| 570 | * @count: size of rotation item array |
| 571 | * @flags: rotation request flags |
| 572 | * return: Pointer to new rotation request if success; ERR_PTR otherwise |
| 573 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 574 | struct sde_rot_entry_container *sde_rotator_req_init( |
| 575 | struct sde_rot_mgr *rot_dev, |
| 576 | struct sde_rot_file_private *private, |
| 577 | struct sde_rotation_item *items, |
| 578 | u32 count, u32 flags); |
| 579 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 580 | /* |
| 581 | * sde_rotator_req_finish - notify manager that client is finished with the |
| 582 | * given request and manager can release the request as required |
| 583 | * @rot_dev: Pointer to rotator device |
| 584 | * @private: Pointer to rotator manager per file context |
| 585 | * @req: Pointer to rotation request |
| 586 | * return: none |
| 587 | */ |
| 588 | void sde_rotator_req_finish(struct sde_rot_mgr *mgr, |
| 589 | struct sde_rot_file_private *private, |
| 590 | struct sde_rot_entry_container *req); |
| 591 | |
| 592 | /* |
| 593 | * sde_rotator_handle_request_common - add the given request to rotator |
| 594 | * manager and clean up completed requests |
| 595 | * @rot_dev: Pointer to rotator device |
| 596 | * @private: Pointer to rotator manager per file context |
| 597 | * @req: Pointer to rotation request |
| 598 | * return: 0 if success; error code otherwise |
| 599 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 600 | int sde_rotator_handle_request_common(struct sde_rot_mgr *rot_dev, |
| 601 | struct sde_rot_file_private *ctx, |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 602 | struct sde_rot_entry_container *req); |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 603 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 604 | /* |
| 605 | * sde_rotator_queue_request - queue/schedule the given request for h/w commit |
| 606 | * @rot_dev: Pointer to rotator device |
| 607 | * @private: Pointer to rotator manager per file context |
| 608 | * @req: Pointer to rotation request |
| 609 | * return: 0 if success; error code otherwise |
| 610 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 611 | void sde_rotator_queue_request(struct sde_rot_mgr *rot_dev, |
| 612 | struct sde_rot_file_private *ctx, |
| 613 | struct sde_rot_entry_container *req); |
| 614 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 615 | /* |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame^] | 616 | * sde_rotator_commit_request - queue/schedule the given request and wait |
| 617 | * until h/w commit |
| 618 | * @rot_dev: Pointer to rotator device |
| 619 | * @private: Pointer to rotator manager per file context |
| 620 | * @req: Pointer to rotation request |
| 621 | * return: 0 if success; error code otherwise |
| 622 | */ |
| 623 | void sde_rotator_commit_request(struct sde_rot_mgr *mgr, |
| 624 | struct sde_rot_file_private *ctx, |
| 625 | struct sde_rot_entry_container *req); |
| 626 | |
| 627 | /* |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 628 | * sde_rotator_verify_config_all - verify given rotation configuration |
| 629 | * @rot_dev: Pointer to rotator device |
| 630 | * @config: Pointer to rotator configuration |
| 631 | * return: 0 if success; error code otherwise |
| 632 | */ |
Benjamin Chan | 59a0605 | 2017-01-12 18:06:03 -0500 | [diff] [blame] | 633 | int sde_rotator_verify_config_all(struct sde_rot_mgr *rot_dev, |
| 634 | struct sde_rotation_config *config); |
| 635 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 636 | /* |
| 637 | * sde_rotator_verify_config_input - verify rotation input configuration |
| 638 | * @rot_dev: Pointer to rotator device |
| 639 | * @config: Pointer to rotator configuration |
| 640 | * return: 0 if success; error code otherwise |
| 641 | */ |
Benjamin Chan | 59a0605 | 2017-01-12 18:06:03 -0500 | [diff] [blame] | 642 | int sde_rotator_verify_config_input(struct sde_rot_mgr *rot_dev, |
| 643 | struct sde_rotation_config *config); |
| 644 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 645 | /* |
| 646 | * sde_rotator_verify_config_output - verify rotation output configuration |
| 647 | * @rot_dev: Pointer to rotator device |
| 648 | * @config: Pointer to rotator configuration |
| 649 | * return: 0 if success; error code otherwise |
| 650 | */ |
Benjamin Chan | 59a0605 | 2017-01-12 18:06:03 -0500 | [diff] [blame] | 651 | int sde_rotator_verify_config_output(struct sde_rot_mgr *rot_dev, |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 652 | struct sde_rotation_config *config); |
| 653 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 654 | /* |
| 655 | * sde_rotator_validate_request - validates given rotation request with |
| 656 | * previous rotator configuration |
| 657 | * @rot_dev: Pointer to rotator device |
| 658 | * @private: Pointer to rotator manager per file context |
| 659 | * @req: Pointer to rotation request |
| 660 | * return: 0 if success; error code otherwise |
| 661 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 662 | int sde_rotator_validate_request(struct sde_rot_mgr *rot_dev, |
| 663 | struct sde_rot_file_private *ctx, |
| 664 | struct sde_rot_entry_container *req); |
| 665 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 666 | /* |
| 667 | * sde_rotator_clk_ctrl - enable/disable rotator clock with reference counting |
| 668 | * @mgr: Pointer to rotator manager |
| 669 | * @enable: true to enable clock; false to disable clock |
| 670 | * return: 0 if success; error code otherwise |
| 671 | */ |
Benjamin Chan | 0f9e61d | 2016-09-16 16:01:09 -0400 | [diff] [blame] | 672 | int sde_rotator_clk_ctrl(struct sde_rot_mgr *mgr, int enable); |
| 673 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 674 | /* |
| 675 | * sde_rot_mgr_lock - serialization lock prior to rotator manager calls |
| 676 | * @mgr: Pointer to rotator manager |
| 677 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 678 | static inline void sde_rot_mgr_lock(struct sde_rot_mgr *mgr) |
| 679 | { |
| 680 | mutex_lock(&mgr->lock); |
| 681 | } |
| 682 | |
Alan Kwong | f94a255 | 2016-12-28 09:41:22 -0800 | [diff] [blame] | 683 | /* |
| 684 | * sde_rot_mgr_lock - serialization unlock after rotator manager calls |
| 685 | * @mgr: Pointer to rotator manager |
| 686 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 687 | static inline void sde_rot_mgr_unlock(struct sde_rot_mgr *mgr) |
| 688 | { |
| 689 | mutex_unlock(&mgr->lock); |
| 690 | } |
| 691 | |
Alan Kwong | 3428f67 | 2016-04-18 12:32:06 -0400 | [diff] [blame] | 692 | #if defined(CONFIG_PM) |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 693 | int sde_rotator_runtime_resume(struct device *dev); |
| 694 | int sde_rotator_runtime_suspend(struct device *dev); |
| 695 | int sde_rotator_runtime_idle(struct device *dev); |
| 696 | #endif |
| 697 | |
| 698 | #if defined(CONFIG_PM_SLEEP) |
| 699 | int sde_rotator_pm_suspend(struct device *dev); |
| 700 | int sde_rotator_pm_resume(struct device *dev); |
| 701 | #endif |
| 702 | |
| 703 | #if defined(CONFIG_PM) && !defined(CONFIG_PM_SLEEP) |
| 704 | int sde_rotator_suspend(struct platform_device *dev, pm_message_t state); |
| 705 | int sde_rotator_resume(struct platform_device *dev); |
| 706 | #else |
| 707 | #define sde_rotator_suspend NULL |
| 708 | #define sde_rotator_resume NULL |
| 709 | #endif |
| 710 | #endif /* __SDE_ROTATOR_CORE_H__ */ |