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