Benjamin Chan | 99eb63b | 2016-12-21 15:45:26 -0500 | [diff] [blame] | 1 | /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [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 | #define pr_fmt(fmt) "%s: " fmt, __func__ |
| 15 | |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/fs.h> |
| 19 | #include <linux/file.h> |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 20 | #include <linux/delay.h> |
| 21 | #include <linux/debugfs.h> |
| 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/dma-mapping.h> |
| 24 | #include <linux/dma-buf.h> |
| 25 | #include <linux/msm_ion.h> |
Alan Kwong | 6ce448d | 2016-11-24 18:45:20 -0800 | [diff] [blame] | 26 | #include <linux/clk.h> |
| 27 | #include <linux/clk/qcom.h> |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 28 | |
| 29 | #include "sde_rotator_core.h" |
| 30 | #include "sde_rotator_util.h" |
| 31 | #include "sde_rotator_smmu.h" |
| 32 | #include "sde_rotator_r3.h" |
| 33 | #include "sde_rotator_r3_internal.h" |
| 34 | #include "sde_rotator_r3_hwio.h" |
| 35 | #include "sde_rotator_r3_debug.h" |
| 36 | #include "sde_rotator_trace.h" |
Benjamin Chan | 53e3bce | 2016-08-31 14:43:29 -0400 | [diff] [blame] | 37 | #include "sde_rotator_debug.h" |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 38 | |
Benjamin Chan | 99eb63b | 2016-12-21 15:45:26 -0500 | [diff] [blame] | 39 | #define RES_UHD (3840*2160) |
| 40 | |
| 41 | /* traffic shaping clock ticks = finish_time x 19.2MHz */ |
| 42 | #define TRAFFIC_SHAPE_CLKTICK_14MS 268800 |
| 43 | #define TRAFFIC_SHAPE_CLKTICK_12MS 230400 |
Alan Kwong | 498d59f | 2017-02-11 18:56:34 -0800 | [diff] [blame] | 44 | #define TRAFFIC_SHAPE_VSYNC_CLK 19200000 |
Benjamin Chan | 99eb63b | 2016-12-21 15:45:26 -0500 | [diff] [blame] | 45 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 46 | /* XIN mapping */ |
| 47 | #define XIN_SSPP 0 |
| 48 | #define XIN_WRITEBACK 1 |
| 49 | |
| 50 | /* wait for at most 2 vsync for lowest refresh rate (24hz) */ |
Alan Kwong | babe3b0 | 2017-02-24 08:31:03 -0800 | [diff] [blame] | 51 | #define KOFF_TIMEOUT (84) |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 52 | |
| 53 | /* default stream buffer headroom in lines */ |
| 54 | #define DEFAULT_SBUF_HEADROOM 20 |
Clarence Ip | 37e013c | 2017-05-04 12:23:13 -0700 | [diff] [blame] | 55 | #define DEFAULT_UBWC_MALSIZE 0 |
| 56 | #define DEFAULT_UBWC_SWIZZLE 0 |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 57 | |
Alan Kwong | b6c049c | 2017-03-31 12:50:27 -0700 | [diff] [blame] | 58 | #define DEFAULT_MAXLINEWIDTH 4096 |
| 59 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 60 | /* Macro for constructing the REGDMA command */ |
| 61 | #define SDE_REGDMA_WRITE(p, off, data) \ |
| 62 | do { \ |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 63 | SDEROT_DBG("SDEREG.W:[%s:0x%X] <= 0x%X\n", #off, (off),\ |
| 64 | (u32)(data));\ |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 65 | *p++ = REGDMA_OP_REGWRITE | \ |
| 66 | ((off) & REGDMA_ADDR_OFFSET_MASK); \ |
| 67 | *p++ = (data); \ |
| 68 | } while (0) |
| 69 | |
| 70 | #define SDE_REGDMA_MODIFY(p, off, mask, data) \ |
| 71 | do { \ |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 72 | SDEROT_DBG("SDEREG.M:[%s:0x%X] <= 0x%X\n", #off, (off),\ |
| 73 | (u32)(data));\ |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 74 | *p++ = REGDMA_OP_REGMODIFY | \ |
| 75 | ((off) & REGDMA_ADDR_OFFSET_MASK); \ |
| 76 | *p++ = (mask); \ |
| 77 | *p++ = (data); \ |
| 78 | } while (0) |
| 79 | |
| 80 | #define SDE_REGDMA_BLKWRITE_INC(p, off, len) \ |
| 81 | do { \ |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 82 | SDEROT_DBG("SDEREG.B:[%s:0x%X:0x%X]\n", #off, (off),\ |
| 83 | (u32)(len));\ |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 84 | *p++ = REGDMA_OP_BLKWRITE_INC | \ |
| 85 | ((off) & REGDMA_ADDR_OFFSET_MASK); \ |
| 86 | *p++ = (len); \ |
| 87 | } while (0) |
| 88 | |
| 89 | #define SDE_REGDMA_BLKWRITE_DATA(p, data) \ |
| 90 | do { \ |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 91 | SDEROT_DBG("SDEREG.I:[:] <= 0x%X\n", (u32)(data));\ |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 92 | *(p) = (data); \ |
| 93 | (p)++; \ |
| 94 | } while (0) |
| 95 | |
| 96 | /* Macro for directly accessing mapped registers */ |
| 97 | #define SDE_ROTREG_WRITE(base, off, data) \ |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 98 | do { \ |
| 99 | SDEROT_DBG("SDEREG.D:[%s:0x%X] <= 0x%X\n", #off, (off)\ |
| 100 | , (u32)(data));\ |
| 101 | writel_relaxed(data, (base + (off))); \ |
| 102 | } while (0) |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 103 | |
| 104 | #define SDE_ROTREG_READ(base, off) \ |
| 105 | readl_relaxed(base + (off)) |
| 106 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 107 | static u32 sde_hw_rotator_v3_inpixfmts[] = { |
Alan Kwong | da16e44 | 2016-08-14 20:47:18 -0400 | [diff] [blame] | 108 | SDE_PIX_FMT_XRGB_8888, |
| 109 | SDE_PIX_FMT_ARGB_8888, |
| 110 | SDE_PIX_FMT_ABGR_8888, |
| 111 | SDE_PIX_FMT_RGBA_8888, |
| 112 | SDE_PIX_FMT_BGRA_8888, |
| 113 | SDE_PIX_FMT_RGBX_8888, |
| 114 | SDE_PIX_FMT_BGRX_8888, |
| 115 | SDE_PIX_FMT_XBGR_8888, |
| 116 | SDE_PIX_FMT_RGBA_5551, |
| 117 | SDE_PIX_FMT_ARGB_1555, |
| 118 | SDE_PIX_FMT_ABGR_1555, |
| 119 | SDE_PIX_FMT_BGRA_5551, |
| 120 | SDE_PIX_FMT_BGRX_5551, |
| 121 | SDE_PIX_FMT_RGBX_5551, |
| 122 | SDE_PIX_FMT_XBGR_1555, |
| 123 | SDE_PIX_FMT_XRGB_1555, |
| 124 | SDE_PIX_FMT_ARGB_4444, |
| 125 | SDE_PIX_FMT_RGBA_4444, |
| 126 | SDE_PIX_FMT_BGRA_4444, |
| 127 | SDE_PIX_FMT_ABGR_4444, |
| 128 | SDE_PIX_FMT_RGBX_4444, |
| 129 | SDE_PIX_FMT_XRGB_4444, |
| 130 | SDE_PIX_FMT_BGRX_4444, |
| 131 | SDE_PIX_FMT_XBGR_4444, |
| 132 | SDE_PIX_FMT_RGB_888, |
| 133 | SDE_PIX_FMT_BGR_888, |
| 134 | SDE_PIX_FMT_RGB_565, |
| 135 | SDE_PIX_FMT_BGR_565, |
| 136 | SDE_PIX_FMT_Y_CB_CR_H2V2, |
| 137 | SDE_PIX_FMT_Y_CR_CB_H2V2, |
| 138 | SDE_PIX_FMT_Y_CR_CB_GH2V2, |
| 139 | SDE_PIX_FMT_Y_CBCR_H2V2, |
| 140 | SDE_PIX_FMT_Y_CRCB_H2V2, |
| 141 | SDE_PIX_FMT_Y_CBCR_H1V2, |
| 142 | SDE_PIX_FMT_Y_CRCB_H1V2, |
| 143 | SDE_PIX_FMT_Y_CBCR_H2V1, |
| 144 | SDE_PIX_FMT_Y_CRCB_H2V1, |
| 145 | SDE_PIX_FMT_YCBYCR_H2V1, |
| 146 | SDE_PIX_FMT_Y_CBCR_H2V2_VENUS, |
| 147 | SDE_PIX_FMT_Y_CRCB_H2V2_VENUS, |
| 148 | SDE_PIX_FMT_RGBA_8888_UBWC, |
| 149 | SDE_PIX_FMT_RGBX_8888_UBWC, |
| 150 | SDE_PIX_FMT_RGB_565_UBWC, |
| 151 | SDE_PIX_FMT_Y_CBCR_H2V2_UBWC, |
| 152 | SDE_PIX_FMT_RGBA_1010102, |
| 153 | SDE_PIX_FMT_RGBX_1010102, |
| 154 | SDE_PIX_FMT_ARGB_2101010, |
| 155 | SDE_PIX_FMT_XRGB_2101010, |
| 156 | SDE_PIX_FMT_BGRA_1010102, |
| 157 | SDE_PIX_FMT_BGRX_1010102, |
| 158 | SDE_PIX_FMT_ABGR_2101010, |
| 159 | SDE_PIX_FMT_XBGR_2101010, |
| 160 | SDE_PIX_FMT_RGBA_1010102_UBWC, |
| 161 | SDE_PIX_FMT_RGBX_1010102_UBWC, |
| 162 | SDE_PIX_FMT_Y_CBCR_H2V2_P010, |
| 163 | SDE_PIX_FMT_Y_CBCR_H2V2_TP10, |
| 164 | SDE_PIX_FMT_Y_CBCR_H2V2_TP10_UBWC, |
| 165 | }; |
| 166 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 167 | static u32 sde_hw_rotator_v3_outpixfmts[] = { |
Alan Kwong | da16e44 | 2016-08-14 20:47:18 -0400 | [diff] [blame] | 168 | SDE_PIX_FMT_XRGB_8888, |
| 169 | SDE_PIX_FMT_ARGB_8888, |
| 170 | SDE_PIX_FMT_ABGR_8888, |
| 171 | SDE_PIX_FMT_RGBA_8888, |
| 172 | SDE_PIX_FMT_BGRA_8888, |
| 173 | SDE_PIX_FMT_RGBX_8888, |
| 174 | SDE_PIX_FMT_BGRX_8888, |
| 175 | SDE_PIX_FMT_XBGR_8888, |
| 176 | SDE_PIX_FMT_RGBA_5551, |
| 177 | SDE_PIX_FMT_ARGB_1555, |
| 178 | SDE_PIX_FMT_ABGR_1555, |
| 179 | SDE_PIX_FMT_BGRA_5551, |
| 180 | SDE_PIX_FMT_BGRX_5551, |
| 181 | SDE_PIX_FMT_RGBX_5551, |
| 182 | SDE_PIX_FMT_XBGR_1555, |
| 183 | SDE_PIX_FMT_XRGB_1555, |
| 184 | SDE_PIX_FMT_ARGB_4444, |
| 185 | SDE_PIX_FMT_RGBA_4444, |
| 186 | SDE_PIX_FMT_BGRA_4444, |
| 187 | SDE_PIX_FMT_ABGR_4444, |
| 188 | SDE_PIX_FMT_RGBX_4444, |
| 189 | SDE_PIX_FMT_XRGB_4444, |
| 190 | SDE_PIX_FMT_BGRX_4444, |
| 191 | SDE_PIX_FMT_XBGR_4444, |
| 192 | SDE_PIX_FMT_RGB_888, |
| 193 | SDE_PIX_FMT_BGR_888, |
| 194 | SDE_PIX_FMT_RGB_565, |
| 195 | SDE_PIX_FMT_BGR_565, |
| 196 | /* SDE_PIX_FMT_Y_CB_CR_H2V2 */ |
| 197 | /* SDE_PIX_FMT_Y_CR_CB_H2V2 */ |
| 198 | /* SDE_PIX_FMT_Y_CR_CB_GH2V2 */ |
| 199 | SDE_PIX_FMT_Y_CBCR_H2V2, |
| 200 | SDE_PIX_FMT_Y_CRCB_H2V2, |
| 201 | SDE_PIX_FMT_Y_CBCR_H1V2, |
| 202 | SDE_PIX_FMT_Y_CRCB_H1V2, |
| 203 | SDE_PIX_FMT_Y_CBCR_H2V1, |
| 204 | SDE_PIX_FMT_Y_CRCB_H2V1, |
| 205 | /* SDE_PIX_FMT_YCBYCR_H2V1 */ |
| 206 | SDE_PIX_FMT_Y_CBCR_H2V2_VENUS, |
| 207 | SDE_PIX_FMT_Y_CRCB_H2V2_VENUS, |
| 208 | SDE_PIX_FMT_RGBA_8888_UBWC, |
| 209 | SDE_PIX_FMT_RGBX_8888_UBWC, |
| 210 | SDE_PIX_FMT_RGB_565_UBWC, |
| 211 | SDE_PIX_FMT_Y_CBCR_H2V2_UBWC, |
| 212 | SDE_PIX_FMT_RGBA_1010102, |
| 213 | SDE_PIX_FMT_RGBX_1010102, |
| 214 | /* SDE_PIX_FMT_ARGB_2101010 */ |
| 215 | /* SDE_PIX_FMT_XRGB_2101010 */ |
| 216 | SDE_PIX_FMT_BGRA_1010102, |
| 217 | SDE_PIX_FMT_BGRX_1010102, |
| 218 | /* SDE_PIX_FMT_ABGR_2101010 */ |
| 219 | /* SDE_PIX_FMT_XBGR_2101010 */ |
| 220 | SDE_PIX_FMT_RGBA_1010102_UBWC, |
| 221 | SDE_PIX_FMT_RGBX_1010102_UBWC, |
| 222 | SDE_PIX_FMT_Y_CBCR_H2V2_P010, |
| 223 | SDE_PIX_FMT_Y_CBCR_H2V2_TP10, |
| 224 | SDE_PIX_FMT_Y_CBCR_H2V2_TP10_UBWC, |
| 225 | }; |
| 226 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 227 | static u32 sde_hw_rotator_v4_inpixfmts[] = { |
| 228 | SDE_PIX_FMT_XRGB_8888, |
| 229 | SDE_PIX_FMT_ARGB_8888, |
| 230 | SDE_PIX_FMT_ABGR_8888, |
| 231 | SDE_PIX_FMT_RGBA_8888, |
| 232 | SDE_PIX_FMT_BGRA_8888, |
| 233 | SDE_PIX_FMT_RGBX_8888, |
| 234 | SDE_PIX_FMT_BGRX_8888, |
| 235 | SDE_PIX_FMT_XBGR_8888, |
| 236 | SDE_PIX_FMT_RGBA_5551, |
| 237 | SDE_PIX_FMT_ARGB_1555, |
| 238 | SDE_PIX_FMT_ABGR_1555, |
| 239 | SDE_PIX_FMT_BGRA_5551, |
| 240 | SDE_PIX_FMT_BGRX_5551, |
| 241 | SDE_PIX_FMT_RGBX_5551, |
| 242 | SDE_PIX_FMT_XBGR_1555, |
| 243 | SDE_PIX_FMT_XRGB_1555, |
| 244 | SDE_PIX_FMT_ARGB_4444, |
| 245 | SDE_PIX_FMT_RGBA_4444, |
| 246 | SDE_PIX_FMT_BGRA_4444, |
| 247 | SDE_PIX_FMT_ABGR_4444, |
| 248 | SDE_PIX_FMT_RGBX_4444, |
| 249 | SDE_PIX_FMT_XRGB_4444, |
| 250 | SDE_PIX_FMT_BGRX_4444, |
| 251 | SDE_PIX_FMT_XBGR_4444, |
| 252 | SDE_PIX_FMT_RGB_888, |
| 253 | SDE_PIX_FMT_BGR_888, |
| 254 | SDE_PIX_FMT_RGB_565, |
| 255 | SDE_PIX_FMT_BGR_565, |
| 256 | SDE_PIX_FMT_Y_CB_CR_H2V2, |
| 257 | SDE_PIX_FMT_Y_CR_CB_H2V2, |
| 258 | SDE_PIX_FMT_Y_CR_CB_GH2V2, |
| 259 | SDE_PIX_FMT_Y_CBCR_H2V2, |
| 260 | SDE_PIX_FMT_Y_CRCB_H2V2, |
| 261 | SDE_PIX_FMT_Y_CBCR_H1V2, |
| 262 | SDE_PIX_FMT_Y_CRCB_H1V2, |
| 263 | SDE_PIX_FMT_Y_CBCR_H2V1, |
| 264 | SDE_PIX_FMT_Y_CRCB_H2V1, |
| 265 | SDE_PIX_FMT_YCBYCR_H2V1, |
| 266 | SDE_PIX_FMT_Y_CBCR_H2V2_VENUS, |
| 267 | SDE_PIX_FMT_Y_CRCB_H2V2_VENUS, |
| 268 | SDE_PIX_FMT_RGBA_8888_UBWC, |
| 269 | SDE_PIX_FMT_RGBX_8888_UBWC, |
| 270 | SDE_PIX_FMT_RGB_565_UBWC, |
| 271 | SDE_PIX_FMT_Y_CBCR_H2V2_UBWC, |
| 272 | SDE_PIX_FMT_RGBA_1010102, |
| 273 | SDE_PIX_FMT_RGBX_1010102, |
| 274 | SDE_PIX_FMT_ARGB_2101010, |
| 275 | SDE_PIX_FMT_XRGB_2101010, |
| 276 | SDE_PIX_FMT_BGRA_1010102, |
| 277 | SDE_PIX_FMT_BGRX_1010102, |
| 278 | SDE_PIX_FMT_ABGR_2101010, |
| 279 | SDE_PIX_FMT_XBGR_2101010, |
| 280 | SDE_PIX_FMT_RGBA_1010102_UBWC, |
| 281 | SDE_PIX_FMT_RGBX_1010102_UBWC, |
| 282 | SDE_PIX_FMT_Y_CBCR_H2V2_P010, |
| 283 | SDE_PIX_FMT_Y_CBCR_H2V2_TP10, |
| 284 | SDE_PIX_FMT_Y_CBCR_H2V2_TP10_UBWC, |
Alan Kwong | 2ad00bc | 2017-02-06 23:32:17 -0800 | [diff] [blame] | 285 | SDE_PIX_FMT_Y_CBCR_H2V2_P010_UBWC, |
| 286 | SDE_PIX_FMT_Y_CBCR_H2V2_P010_TILE, |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 287 | SDE_PIX_FMT_Y_CBCR_H2V2_TILE, |
| 288 | SDE_PIX_FMT_Y_CRCB_H2V2_TILE, |
| 289 | SDE_PIX_FMT_XRGB_8888_TILE, |
| 290 | SDE_PIX_FMT_ARGB_8888_TILE, |
| 291 | SDE_PIX_FMT_ABGR_8888_TILE, |
| 292 | SDE_PIX_FMT_XBGR_8888_TILE, |
| 293 | SDE_PIX_FMT_RGBA_8888_TILE, |
| 294 | SDE_PIX_FMT_BGRA_8888_TILE, |
| 295 | SDE_PIX_FMT_RGBX_8888_TILE, |
| 296 | SDE_PIX_FMT_BGRX_8888_TILE, |
| 297 | SDE_PIX_FMT_RGBA_1010102_TILE, |
| 298 | SDE_PIX_FMT_RGBX_1010102_TILE, |
| 299 | SDE_PIX_FMT_ARGB_2101010_TILE, |
| 300 | SDE_PIX_FMT_XRGB_2101010_TILE, |
| 301 | SDE_PIX_FMT_BGRA_1010102_TILE, |
| 302 | SDE_PIX_FMT_BGRX_1010102_TILE, |
| 303 | SDE_PIX_FMT_ABGR_2101010_TILE, |
| 304 | SDE_PIX_FMT_XBGR_2101010_TILE, |
| 305 | }; |
| 306 | |
| 307 | static u32 sde_hw_rotator_v4_outpixfmts[] = { |
| 308 | SDE_PIX_FMT_XRGB_8888, |
| 309 | SDE_PIX_FMT_ARGB_8888, |
| 310 | SDE_PIX_FMT_ABGR_8888, |
| 311 | SDE_PIX_FMT_RGBA_8888, |
| 312 | SDE_PIX_FMT_BGRA_8888, |
| 313 | SDE_PIX_FMT_RGBX_8888, |
| 314 | SDE_PIX_FMT_BGRX_8888, |
| 315 | SDE_PIX_FMT_XBGR_8888, |
| 316 | SDE_PIX_FMT_RGBA_5551, |
| 317 | SDE_PIX_FMT_ARGB_1555, |
| 318 | SDE_PIX_FMT_ABGR_1555, |
| 319 | SDE_PIX_FMT_BGRA_5551, |
| 320 | SDE_PIX_FMT_BGRX_5551, |
| 321 | SDE_PIX_FMT_RGBX_5551, |
| 322 | SDE_PIX_FMT_XBGR_1555, |
| 323 | SDE_PIX_FMT_XRGB_1555, |
| 324 | SDE_PIX_FMT_ARGB_4444, |
| 325 | SDE_PIX_FMT_RGBA_4444, |
| 326 | SDE_PIX_FMT_BGRA_4444, |
| 327 | SDE_PIX_FMT_ABGR_4444, |
| 328 | SDE_PIX_FMT_RGBX_4444, |
| 329 | SDE_PIX_FMT_XRGB_4444, |
| 330 | SDE_PIX_FMT_BGRX_4444, |
| 331 | SDE_PIX_FMT_XBGR_4444, |
| 332 | SDE_PIX_FMT_RGB_888, |
| 333 | SDE_PIX_FMT_BGR_888, |
| 334 | SDE_PIX_FMT_RGB_565, |
| 335 | SDE_PIX_FMT_BGR_565, |
| 336 | /* SDE_PIX_FMT_Y_CB_CR_H2V2 */ |
| 337 | /* SDE_PIX_FMT_Y_CR_CB_H2V2 */ |
| 338 | /* SDE_PIX_FMT_Y_CR_CB_GH2V2 */ |
| 339 | SDE_PIX_FMT_Y_CBCR_H2V2, |
| 340 | SDE_PIX_FMT_Y_CRCB_H2V2, |
| 341 | SDE_PIX_FMT_Y_CBCR_H1V2, |
| 342 | SDE_PIX_FMT_Y_CRCB_H1V2, |
| 343 | SDE_PIX_FMT_Y_CBCR_H2V1, |
| 344 | SDE_PIX_FMT_Y_CRCB_H2V1, |
| 345 | /* SDE_PIX_FMT_YCBYCR_H2V1 */ |
| 346 | SDE_PIX_FMT_Y_CBCR_H2V2_VENUS, |
| 347 | SDE_PIX_FMT_Y_CRCB_H2V2_VENUS, |
| 348 | SDE_PIX_FMT_RGBA_8888_UBWC, |
| 349 | SDE_PIX_FMT_RGBX_8888_UBWC, |
| 350 | SDE_PIX_FMT_RGB_565_UBWC, |
| 351 | SDE_PIX_FMT_Y_CBCR_H2V2_UBWC, |
| 352 | SDE_PIX_FMT_RGBA_1010102, |
| 353 | SDE_PIX_FMT_RGBX_1010102, |
| 354 | /* SDE_PIX_FMT_ARGB_2101010 */ |
| 355 | /* SDE_PIX_FMT_XRGB_2101010 */ |
| 356 | SDE_PIX_FMT_BGRA_1010102, |
| 357 | SDE_PIX_FMT_BGRX_1010102, |
| 358 | /* SDE_PIX_FMT_ABGR_2101010 */ |
| 359 | /* SDE_PIX_FMT_XBGR_2101010 */ |
| 360 | SDE_PIX_FMT_RGBA_1010102_UBWC, |
| 361 | SDE_PIX_FMT_RGBX_1010102_UBWC, |
| 362 | SDE_PIX_FMT_Y_CBCR_H2V2_P010, |
| 363 | SDE_PIX_FMT_Y_CBCR_H2V2_TP10, |
| 364 | SDE_PIX_FMT_Y_CBCR_H2V2_TP10_UBWC, |
Alan Kwong | 2ad00bc | 2017-02-06 23:32:17 -0800 | [diff] [blame] | 365 | SDE_PIX_FMT_Y_CBCR_H2V2_P010_UBWC, |
| 366 | SDE_PIX_FMT_Y_CBCR_H2V2_P010_TILE, |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 367 | SDE_PIX_FMT_Y_CBCR_H2V2_TILE, |
| 368 | SDE_PIX_FMT_Y_CRCB_H2V2_TILE, |
| 369 | SDE_PIX_FMT_XRGB_8888_TILE, |
| 370 | SDE_PIX_FMT_ARGB_8888_TILE, |
| 371 | SDE_PIX_FMT_ABGR_8888_TILE, |
| 372 | SDE_PIX_FMT_XBGR_8888_TILE, |
| 373 | SDE_PIX_FMT_RGBA_8888_TILE, |
| 374 | SDE_PIX_FMT_BGRA_8888_TILE, |
| 375 | SDE_PIX_FMT_RGBX_8888_TILE, |
| 376 | SDE_PIX_FMT_BGRX_8888_TILE, |
| 377 | SDE_PIX_FMT_RGBA_1010102_TILE, |
| 378 | SDE_PIX_FMT_RGBX_1010102_TILE, |
| 379 | SDE_PIX_FMT_ARGB_2101010_TILE, |
| 380 | SDE_PIX_FMT_XRGB_2101010_TILE, |
| 381 | SDE_PIX_FMT_BGRA_1010102_TILE, |
| 382 | SDE_PIX_FMT_BGRX_1010102_TILE, |
| 383 | SDE_PIX_FMT_ABGR_2101010_TILE, |
| 384 | SDE_PIX_FMT_XBGR_2101010_TILE, |
| 385 | }; |
| 386 | |
Benjamin Chan | 53e3bce | 2016-08-31 14:43:29 -0400 | [diff] [blame] | 387 | static struct sde_rot_vbif_debug_bus nrt_vbif_dbg_bus_r3[] = { |
Benjamin Chan | 2d6411a | 2017-03-28 18:01:53 -0400 | [diff] [blame] | 388 | {0x214, 0x21c, 16, 1, 0x200}, /* arb clients main */ |
Benjamin Chan | 53e3bce | 2016-08-31 14:43:29 -0400 | [diff] [blame] | 389 | {0x214, 0x21c, 0, 12, 0x13}, /* xin blocks - axi side */ |
| 390 | {0x21c, 0x214, 0, 12, 0xc}, /* xin blocks - clock side */ |
| 391 | }; |
| 392 | |
Benjamin Chan | 2d6411a | 2017-03-28 18:01:53 -0400 | [diff] [blame] | 393 | static struct sde_rot_debug_bus rot_dbgbus_r3[] = { |
| 394 | /* |
| 395 | * rottop - 0xA8850 |
| 396 | */ |
| 397 | /* REGDMA */ |
| 398 | { 0XA8850, 0, 0 }, |
| 399 | { 0XA8850, 0, 1 }, |
| 400 | { 0XA8850, 0, 2 }, |
| 401 | { 0XA8850, 0, 3 }, |
| 402 | { 0XA8850, 0, 4 }, |
| 403 | |
| 404 | /* ROT_WB */ |
| 405 | { 0XA8850, 1, 0 }, |
| 406 | { 0XA8850, 1, 1 }, |
| 407 | { 0XA8850, 1, 2 }, |
| 408 | { 0XA8850, 1, 3 }, |
| 409 | { 0XA8850, 1, 4 }, |
| 410 | { 0XA8850, 1, 5 }, |
| 411 | { 0XA8850, 1, 6 }, |
| 412 | { 0XA8850, 1, 7 }, |
| 413 | |
| 414 | /* UBWC_DEC */ |
| 415 | { 0XA8850, 2, 0 }, |
| 416 | |
| 417 | /* UBWC_ENC */ |
| 418 | { 0XA8850, 3, 0 }, |
| 419 | |
| 420 | /* ROT_FETCH_0 */ |
| 421 | { 0XA8850, 4, 0 }, |
| 422 | { 0XA8850, 4, 1 }, |
| 423 | { 0XA8850, 4, 2 }, |
| 424 | { 0XA8850, 4, 3 }, |
| 425 | { 0XA8850, 4, 4 }, |
| 426 | { 0XA8850, 4, 5 }, |
| 427 | { 0XA8850, 4, 6 }, |
| 428 | { 0XA8850, 4, 7 }, |
| 429 | |
| 430 | /* ROT_FETCH_1 */ |
| 431 | { 0XA8850, 5, 0 }, |
| 432 | { 0XA8850, 5, 1 }, |
| 433 | { 0XA8850, 5, 2 }, |
| 434 | { 0XA8850, 5, 3 }, |
| 435 | { 0XA8850, 5, 4 }, |
| 436 | { 0XA8850, 5, 5 }, |
| 437 | { 0XA8850, 5, 6 }, |
| 438 | { 0XA8850, 5, 7 }, |
| 439 | |
| 440 | /* ROT_FETCH_2 */ |
| 441 | { 0XA8850, 6, 0 }, |
| 442 | { 0XA8850, 6, 1 }, |
| 443 | { 0XA8850, 6, 2 }, |
| 444 | { 0XA8850, 6, 3 }, |
| 445 | { 0XA8850, 6, 4 }, |
| 446 | { 0XA8850, 6, 5 }, |
| 447 | { 0XA8850, 6, 6 }, |
| 448 | { 0XA8850, 6, 7 }, |
| 449 | |
| 450 | /* ROT_FETCH_3 */ |
| 451 | { 0XA8850, 7, 0 }, |
| 452 | { 0XA8850, 7, 1 }, |
| 453 | { 0XA8850, 7, 2 }, |
| 454 | { 0XA8850, 7, 3 }, |
| 455 | { 0XA8850, 7, 4 }, |
| 456 | { 0XA8850, 7, 5 }, |
| 457 | { 0XA8850, 7, 6 }, |
| 458 | { 0XA8850, 7, 7 }, |
| 459 | |
| 460 | /* ROT_FETCH_4 */ |
| 461 | { 0XA8850, 8, 0 }, |
| 462 | { 0XA8850, 8, 1 }, |
| 463 | { 0XA8850, 8, 2 }, |
| 464 | { 0XA8850, 8, 3 }, |
| 465 | { 0XA8850, 8, 4 }, |
| 466 | { 0XA8850, 8, 5 }, |
| 467 | { 0XA8850, 8, 6 }, |
| 468 | { 0XA8850, 8, 7 }, |
| 469 | |
| 470 | /* ROT_UNPACK_0*/ |
| 471 | { 0XA8850, 9, 0 }, |
| 472 | { 0XA8850, 9, 1 }, |
| 473 | { 0XA8850, 9, 2 }, |
| 474 | { 0XA8850, 9, 3 }, |
| 475 | }; |
| 476 | |
Benjamin Chan | 53e3bce | 2016-08-31 14:43:29 -0400 | [diff] [blame] | 477 | static struct sde_rot_regdump sde_rot_r3_regdump[] = { |
| 478 | { "SDEROT_ROTTOP", SDE_ROT_ROTTOP_OFFSET, 0x100, SDE_ROT_REGDUMP_READ }, |
| 479 | { "SDEROT_SSPP", SDE_ROT_SSPP_OFFSET, 0x200, SDE_ROT_REGDUMP_READ }, |
| 480 | { "SDEROT_WB", SDE_ROT_WB_OFFSET, 0x300, SDE_ROT_REGDUMP_READ }, |
| 481 | { "SDEROT_REGDMA_CSR", SDE_ROT_REGDMA_OFFSET, 0x100, |
| 482 | SDE_ROT_REGDUMP_READ }, |
| 483 | /* |
| 484 | * Need to perform a SW reset to REGDMA in order to access the |
| 485 | * REGDMA RAM especially if REGDMA is waiting for Rotator IDLE. |
| 486 | * REGDMA RAM should be dump at last. |
| 487 | */ |
| 488 | { "SDEROT_REGDMA_RESET", ROTTOP_SW_RESET_OVERRIDE, 1, |
| 489 | SDE_ROT_REGDUMP_WRITE }, |
| 490 | { "SDEROT_REGDMA_RAM", SDE_ROT_REGDMA_RAM_OFFSET, 0x2000, |
| 491 | SDE_ROT_REGDUMP_READ }, |
Benjamin Chan | 59a0605 | 2017-01-12 18:06:03 -0500 | [diff] [blame] | 492 | { "SDEROT_VBIF_NRT", SDE_ROT_VBIF_NRT_OFFSET, 0x590, |
| 493 | SDE_ROT_REGDUMP_VBIF }, |
Benjamin Chan | 53e3bce | 2016-08-31 14:43:29 -0400 | [diff] [blame] | 494 | }; |
| 495 | |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 496 | /* Invalid software timestamp value for initialization */ |
| 497 | #define SDE_REGDMA_SWTS_INVALID (~0) |
| 498 | |
| 499 | /** |
| 500 | * sde_hw_rotator_elapsed_swts - Find difference of 2 software timestamps |
| 501 | * @ts_curr: current software timestamp |
| 502 | * @ts_prev: previous software timestamp |
| 503 | * @return: the amount ts_curr is ahead of ts_prev |
| 504 | */ |
| 505 | static int sde_hw_rotator_elapsed_swts(u32 ts_curr, u32 ts_prev) |
| 506 | { |
| 507 | u32 diff = (ts_curr - ts_prev) & SDE_REGDMA_SWTS_MASK; |
| 508 | |
| 509 | return sign_extend32(diff, (SDE_REGDMA_SWTS_SHIFT - 1)); |
| 510 | } |
| 511 | |
| 512 | /** |
| 513 | * sde_hw_rotator_pending_swts - Check if the given context is still pending |
| 514 | * @rot: Pointer to hw rotator |
| 515 | * @ctx: Pointer to rotator context |
| 516 | * @pswts: Pointer to returned reference software timestamp, optional |
| 517 | * @return: true if context has pending requests |
| 518 | */ |
| 519 | static int sde_hw_rotator_pending_swts(struct sde_hw_rotator *rot, |
| 520 | struct sde_hw_rotator_context *ctx, u32 *pswts) |
| 521 | { |
| 522 | u32 swts; |
| 523 | int ts_diff; |
| 524 | bool pending; |
| 525 | |
| 526 | if (ctx->last_regdma_timestamp == SDE_REGDMA_SWTS_INVALID) |
| 527 | swts = SDE_ROTREG_READ(rot->mdss_base, REGDMA_TIMESTAMP_REG); |
| 528 | else |
| 529 | swts = ctx->last_regdma_timestamp; |
| 530 | |
| 531 | if (ctx->q_id == ROT_QUEUE_LOW_PRIORITY) |
| 532 | swts >>= SDE_REGDMA_SWTS_SHIFT; |
| 533 | |
| 534 | swts &= SDE_REGDMA_SWTS_MASK; |
| 535 | |
| 536 | ts_diff = sde_hw_rotator_elapsed_swts(ctx->timestamp, swts); |
| 537 | |
| 538 | if (pswts) |
| 539 | *pswts = swts; |
| 540 | |
| 541 | pending = (ts_diff > 0) ? true : false; |
| 542 | |
| 543 | SDEROT_DBG("ts:0x%x, queue_id:%d, swts:0x%x, pending:%d\n", |
| 544 | ctx->timestamp, ctx->q_id, swts, pending); |
Benjamin Chan | 0f9e61d | 2016-09-16 16:01:09 -0400 | [diff] [blame] | 545 | SDEROT_EVTLOG(ctx->timestamp, swts, ctx->q_id, ts_diff); |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 546 | return pending; |
| 547 | } |
| 548 | |
| 549 | /** |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 550 | * sde_hw_rotator_update_swts - update software timestamp with given value |
| 551 | * @rot: Pointer to hw rotator |
| 552 | * @ctx: Pointer to rotator contxt |
| 553 | * @swts: new software timestamp |
| 554 | * @return: new combined swts |
| 555 | */ |
| 556 | static u32 sde_hw_rotator_update_swts(struct sde_hw_rotator *rot, |
| 557 | struct sde_hw_rotator_context *ctx, u32 swts) |
| 558 | { |
| 559 | u32 mask = SDE_REGDMA_SWTS_MASK; |
| 560 | |
| 561 | swts &= SDE_REGDMA_SWTS_MASK; |
| 562 | if (ctx->q_id == ROT_QUEUE_LOW_PRIORITY) { |
| 563 | swts <<= SDE_REGDMA_SWTS_SHIFT; |
| 564 | mask <<= SDE_REGDMA_SWTS_SHIFT; |
| 565 | } |
| 566 | |
| 567 | swts |= (SDE_ROTREG_READ(rot->mdss_base, REGDMA_TIMESTAMP_REG) & ~mask); |
| 568 | SDE_ROTREG_WRITE(rot->mdss_base, REGDMA_TIMESTAMP_REG, swts); |
| 569 | |
| 570 | return swts; |
| 571 | } |
| 572 | |
| 573 | /** |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 574 | * sde_hw_rotator_enable_irq - Enable hw rotator interrupt with ref. count |
| 575 | * Also, clear rotator/regdma irq status. |
| 576 | * @rot: Pointer to hw rotator |
| 577 | */ |
| 578 | static void sde_hw_rotator_enable_irq(struct sde_hw_rotator *rot) |
| 579 | { |
| 580 | SDEROT_DBG("irq_num:%d enabled:%d\n", rot->irq_num, |
| 581 | atomic_read(&rot->irq_enabled)); |
| 582 | |
| 583 | if (!atomic_read(&rot->irq_enabled)) { |
| 584 | if (rot->mode == ROT_REGDMA_OFF) |
| 585 | SDE_ROTREG_WRITE(rot->mdss_base, ROTTOP_INTR_CLEAR, |
| 586 | ROT_DONE_MASK); |
| 587 | else |
| 588 | SDE_ROTREG_WRITE(rot->mdss_base, |
| 589 | REGDMA_CSR_REGDMA_INT_CLEAR, REGDMA_INT_MASK); |
| 590 | |
| 591 | enable_irq(rot->irq_num); |
| 592 | } |
| 593 | atomic_inc(&rot->irq_enabled); |
| 594 | } |
| 595 | |
| 596 | /** |
| 597 | * sde_hw_rotator_disable_irq - Disable hw rotator interrupt with ref. count |
| 598 | * Also, clear rotator/regdma irq enable masks. |
| 599 | * @rot: Pointer to hw rotator |
| 600 | */ |
| 601 | static void sde_hw_rotator_disable_irq(struct sde_hw_rotator *rot) |
| 602 | { |
| 603 | SDEROT_DBG("irq_num:%d enabled:%d\n", rot->irq_num, |
| 604 | atomic_read(&rot->irq_enabled)); |
| 605 | |
| 606 | if (!atomic_read(&rot->irq_enabled)) { |
| 607 | SDEROT_ERR("irq %d is already disabled\n", rot->irq_num); |
| 608 | return; |
| 609 | } |
| 610 | |
| 611 | if (!atomic_dec_return(&rot->irq_enabled)) { |
| 612 | if (rot->mode == ROT_REGDMA_OFF) |
| 613 | SDE_ROTREG_WRITE(rot->mdss_base, ROTTOP_INTR_EN, 0); |
| 614 | else |
| 615 | SDE_ROTREG_WRITE(rot->mdss_base, |
| 616 | REGDMA_CSR_REGDMA_INT_EN, 0); |
| 617 | /* disable irq after last pending irq is handled, if any */ |
| 618 | synchronize_irq(rot->irq_num); |
| 619 | disable_irq_nosync(rot->irq_num); |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | /** |
| 624 | * sde_hw_rotator_dump_status - Dump hw rotator status on error |
| 625 | * @rot: Pointer to hw rotator |
| 626 | */ |
| 627 | static void sde_hw_rotator_dump_status(struct sde_hw_rotator *rot) |
| 628 | { |
Benjamin Chan | 1b94f95 | 2017-01-23 17:42:30 -0500 | [diff] [blame] | 629 | struct sde_rot_data_type *mdata = sde_rot_get_mdata(); |
| 630 | |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 631 | SDEROT_ERR( |
| 632 | "op_mode = %x, int_en = %x, int_status = %x\n", |
| 633 | SDE_ROTREG_READ(rot->mdss_base, |
| 634 | REGDMA_CSR_REGDMA_OP_MODE), |
| 635 | SDE_ROTREG_READ(rot->mdss_base, |
| 636 | REGDMA_CSR_REGDMA_INT_EN), |
| 637 | SDE_ROTREG_READ(rot->mdss_base, |
| 638 | REGDMA_CSR_REGDMA_INT_STATUS)); |
| 639 | |
| 640 | SDEROT_ERR( |
| 641 | "ts = %x, q0_status = %x, q1_status = %x, block_status = %x\n", |
| 642 | SDE_ROTREG_READ(rot->mdss_base, |
| 643 | REGDMA_TIMESTAMP_REG), |
| 644 | SDE_ROTREG_READ(rot->mdss_base, |
| 645 | REGDMA_CSR_REGDMA_QUEUE_0_STATUS), |
| 646 | SDE_ROTREG_READ(rot->mdss_base, |
| 647 | REGDMA_CSR_REGDMA_QUEUE_1_STATUS), |
| 648 | SDE_ROTREG_READ(rot->mdss_base, |
| 649 | REGDMA_CSR_REGDMA_BLOCK_STATUS)); |
| 650 | |
| 651 | SDEROT_ERR( |
| 652 | "invalid_cmd_offset = %x, fsm_state = %x\n", |
| 653 | SDE_ROTREG_READ(rot->mdss_base, |
| 654 | REGDMA_CSR_REGDMA_INVALID_CMD_RAM_OFFSET), |
| 655 | SDE_ROTREG_READ(rot->mdss_base, |
| 656 | REGDMA_CSR_REGDMA_FSM_STATE)); |
Benjamin Chan | 59a0605 | 2017-01-12 18:06:03 -0500 | [diff] [blame] | 657 | |
| 658 | SDEROT_ERR( |
| 659 | "UBWC decode status = %x, UBWC encode status = %x\n", |
| 660 | SDE_ROTREG_READ(rot->mdss_base, ROT_SSPP_UBWC_ERROR_STATUS), |
| 661 | SDE_ROTREG_READ(rot->mdss_base, ROT_WB_UBWC_ERROR_STATUS)); |
Benjamin Chan | 1b94f95 | 2017-01-23 17:42:30 -0500 | [diff] [blame] | 662 | |
| 663 | SDEROT_ERR("VBIF XIN HALT status = %x VBIF AXI HALT status = %x\n", |
| 664 | SDE_VBIF_READ(mdata, MMSS_VBIF_XIN_HALT_CTRL1), |
| 665 | SDE_VBIF_READ(mdata, MMSS_VBIF_AXI_HALT_CTRL1)); |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 666 | |
| 667 | SDEROT_ERR( |
| 668 | "sbuf_status_plane0 = %x, sbuf_status_plane1 = %x\n", |
| 669 | SDE_ROTREG_READ(rot->mdss_base, |
| 670 | ROT_WB_SBUF_STATUS_PLANE0), |
| 671 | SDE_ROTREG_READ(rot->mdss_base, |
| 672 | ROT_WB_SBUF_STATUS_PLANE1)); |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 673 | } |
| 674 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 675 | /** |
| 676 | * sde_hw_rotator_get_ctx(): Retrieve rotator context from rotator HW based |
| 677 | * on provided session_id. Each rotator has a different session_id. |
| 678 | */ |
| 679 | static struct sde_hw_rotator_context *sde_hw_rotator_get_ctx( |
| 680 | struct sde_hw_rotator *rot, u32 session_id, |
| 681 | enum sde_rot_queue_prio q_id) |
| 682 | { |
| 683 | int i; |
| 684 | struct sde_hw_rotator_context *ctx = NULL; |
| 685 | |
| 686 | for (i = 0; i < SDE_HW_ROT_REGDMA_TOTAL_CTX; i++) { |
| 687 | ctx = rot->rotCtx[q_id][i]; |
| 688 | |
| 689 | if (ctx && (ctx->session_id == session_id)) { |
| 690 | SDEROT_DBG( |
| 691 | "rotCtx sloti[%d][%d] ==> ctx:%p | session-id:%d\n", |
| 692 | q_id, i, ctx, ctx->session_id); |
| 693 | return ctx; |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | return NULL; |
| 698 | } |
| 699 | |
| 700 | /* |
| 701 | * sde_hw_rotator_map_vaddr - map the debug buffer to kernel space |
| 702 | * @dbgbuf: Pointer to debug buffer |
| 703 | * @buf: Pointer to layer buffer structure |
| 704 | * @data: Pointer to h/w mapped buffer structure |
| 705 | */ |
| 706 | static void sde_hw_rotator_map_vaddr(struct sde_dbg_buf *dbgbuf, |
| 707 | struct sde_layer_buffer *buf, struct sde_mdp_data *data) |
| 708 | { |
| 709 | dbgbuf->dmabuf = data->p[0].srcp_dma_buf; |
| 710 | dbgbuf->buflen = data->p[0].srcp_dma_buf->size; |
| 711 | |
| 712 | dbgbuf->vaddr = NULL; |
| 713 | dbgbuf->width = buf->width; |
| 714 | dbgbuf->height = buf->height; |
| 715 | |
| 716 | if (dbgbuf->dmabuf && (dbgbuf->buflen > 0)) { |
Alan Kwong | 6ce448d | 2016-11-24 18:45:20 -0800 | [diff] [blame] | 717 | dma_buf_begin_cpu_access(dbgbuf->dmabuf, DMA_FROM_DEVICE); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 718 | dbgbuf->vaddr = dma_buf_kmap(dbgbuf->dmabuf, 0); |
| 719 | SDEROT_DBG("vaddr mapping: 0x%p/%ld w:%d/h:%d\n", |
| 720 | dbgbuf->vaddr, dbgbuf->buflen, |
| 721 | dbgbuf->width, dbgbuf->height); |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | /* |
| 726 | * sde_hw_rotator_unmap_vaddr - unmap the debug buffer from kernel space |
| 727 | * @dbgbuf: Pointer to debug buffer |
| 728 | */ |
| 729 | static void sde_hw_rotator_unmap_vaddr(struct sde_dbg_buf *dbgbuf) |
| 730 | { |
| 731 | if (dbgbuf->vaddr) { |
| 732 | dma_buf_kunmap(dbgbuf->dmabuf, 0, dbgbuf->vaddr); |
Alan Kwong | 6ce448d | 2016-11-24 18:45:20 -0800 | [diff] [blame] | 733 | dma_buf_end_cpu_access(dbgbuf->dmabuf, DMA_FROM_DEVICE); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | dbgbuf->vaddr = NULL; |
| 737 | dbgbuf->dmabuf = NULL; |
| 738 | dbgbuf->buflen = 0; |
| 739 | dbgbuf->width = 0; |
| 740 | dbgbuf->height = 0; |
| 741 | } |
| 742 | |
| 743 | /* |
| 744 | * sde_hw_rotator_setup_timestamp_packet - setup timestamp writeback command |
| 745 | * @ctx: Pointer to rotator context |
| 746 | * @mask: Bit mask location of the timestamp |
| 747 | * @swts: Software timestamp |
| 748 | */ |
| 749 | static void sde_hw_rotator_setup_timestamp_packet( |
| 750 | struct sde_hw_rotator_context *ctx, u32 mask, u32 swts) |
| 751 | { |
| 752 | u32 *wrptr; |
| 753 | |
| 754 | wrptr = sde_hw_rotator_get_regdma_segment(ctx); |
| 755 | |
| 756 | /* |
| 757 | * Create a dummy packet write out to 1 location for timestamp |
| 758 | * generation. |
| 759 | */ |
| 760 | SDE_REGDMA_BLKWRITE_INC(wrptr, ROT_SSPP_SRC_SIZE, 6); |
| 761 | SDE_REGDMA_BLKWRITE_DATA(wrptr, 0x00010001); |
| 762 | SDE_REGDMA_BLKWRITE_DATA(wrptr, 0); |
| 763 | SDE_REGDMA_BLKWRITE_DATA(wrptr, 0); |
| 764 | SDE_REGDMA_BLKWRITE_DATA(wrptr, 0x00010001); |
| 765 | SDE_REGDMA_BLKWRITE_DATA(wrptr, 0); |
| 766 | SDE_REGDMA_BLKWRITE_DATA(wrptr, ctx->ts_addr); |
| 767 | SDE_REGDMA_WRITE(wrptr, ROT_SSPP_SRC_YSTRIDE0, 4); |
| 768 | SDE_REGDMA_BLKWRITE_INC(wrptr, ROT_SSPP_SRC_FORMAT, 4); |
| 769 | SDE_REGDMA_BLKWRITE_DATA(wrptr, 0x004037FF); |
| 770 | SDE_REGDMA_BLKWRITE_DATA(wrptr, 0x03020100); |
| 771 | SDE_REGDMA_BLKWRITE_DATA(wrptr, 0x80000000); |
| 772 | SDE_REGDMA_BLKWRITE_DATA(wrptr, ctx->timestamp); |
Benjamin Chan | 15c93d8 | 2016-08-29 10:04:22 -0400 | [diff] [blame] | 773 | /* |
| 774 | * Must clear secure buffer setting for SW timestamp because |
| 775 | * SW timstamp buffer allocation is always non-secure region. |
| 776 | */ |
| 777 | if (ctx->is_secure) { |
| 778 | SDE_REGDMA_WRITE(wrptr, ROT_SSPP_SRC_ADDR_SW_STATUS, 0); |
| 779 | SDE_REGDMA_WRITE(wrptr, ROT_WB_DST_ADDR_SW_STATUS, 0); |
| 780 | } |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 781 | SDE_REGDMA_BLKWRITE_INC(wrptr, ROT_WB_DST_FORMAT, 4); |
| 782 | SDE_REGDMA_BLKWRITE_DATA(wrptr, 0x000037FF); |
| 783 | SDE_REGDMA_BLKWRITE_DATA(wrptr, 0); |
| 784 | SDE_REGDMA_BLKWRITE_DATA(wrptr, 0x03020100); |
| 785 | SDE_REGDMA_BLKWRITE_DATA(wrptr, ctx->ts_addr); |
| 786 | SDE_REGDMA_WRITE(wrptr, ROT_WB_DST_YSTRIDE0, 4); |
| 787 | SDE_REGDMA_WRITE(wrptr, ROT_WB_OUT_SIZE, 0x00010001); |
| 788 | SDE_REGDMA_WRITE(wrptr, ROT_WB_OUT_IMG_SIZE, 0x00010001); |
| 789 | SDE_REGDMA_WRITE(wrptr, ROT_WB_OUT_XY, 0); |
| 790 | SDE_REGDMA_WRITE(wrptr, ROTTOP_DNSC, 0); |
| 791 | SDE_REGDMA_WRITE(wrptr, ROTTOP_OP_MODE, 1); |
| 792 | SDE_REGDMA_MODIFY(wrptr, REGDMA_TIMESTAMP_REG, mask, swts); |
| 793 | SDE_REGDMA_WRITE(wrptr, ROTTOP_START_CTRL, 1); |
| 794 | |
| 795 | sde_hw_rotator_put_regdma_segment(ctx, wrptr); |
| 796 | } |
| 797 | |
| 798 | /* |
| 799 | * sde_hw_rotator_setup_fetchengine - setup fetch engine |
| 800 | * @ctx: Pointer to rotator context |
| 801 | * @queue_id: Priority queue identifier |
| 802 | * @cfg: Fetch configuration |
| 803 | * @danger_lut: real-time QoS LUT for danger setting (not used) |
| 804 | * @safe_lut: real-time QoS LUT for safe setting (not used) |
Benjamin Chan | fb6faa3 | 2016-08-16 17:21:01 -0400 | [diff] [blame] | 805 | * @dnsc_factor_w: downscale factor for width |
| 806 | * @dnsc_factor_h: downscale factor for height |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 807 | * @flags: Control flag |
| 808 | */ |
| 809 | static void sde_hw_rotator_setup_fetchengine(struct sde_hw_rotator_context *ctx, |
| 810 | enum sde_rot_queue_prio queue_id, |
| 811 | struct sde_hw_rot_sspp_cfg *cfg, u32 danger_lut, u32 safe_lut, |
Benjamin Chan | fb6faa3 | 2016-08-16 17:21:01 -0400 | [diff] [blame] | 812 | u32 dnsc_factor_w, u32 dnsc_factor_h, u32 flags) |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 813 | { |
| 814 | struct sde_hw_rotator *rot = ctx->rot; |
| 815 | struct sde_mdp_format_params *fmt; |
| 816 | struct sde_mdp_data *data; |
Benjamin Chan | fb6faa3 | 2016-08-16 17:21:01 -0400 | [diff] [blame] | 817 | struct sde_rot_data_type *mdata = sde_rot_get_mdata(); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 818 | u32 *wrptr; |
| 819 | u32 opmode = 0; |
| 820 | u32 chroma_samp = 0; |
| 821 | u32 src_format = 0; |
| 822 | u32 unpack = 0; |
| 823 | u32 width = cfg->img_width; |
| 824 | u32 height = cfg->img_height; |
| 825 | u32 fetch_blocksize = 0; |
| 826 | int i; |
| 827 | |
| 828 | if (ctx->rot->mode == ROT_REGDMA_ON) { |
| 829 | SDE_ROTREG_WRITE(rot->mdss_base, REGDMA_CSR_REGDMA_INT_EN, |
| 830 | REGDMA_INT_MASK); |
| 831 | SDE_ROTREG_WRITE(rot->mdss_base, REGDMA_CSR_REGDMA_OP_MODE, |
| 832 | REGDMA_EN); |
| 833 | } |
| 834 | |
| 835 | wrptr = sde_hw_rotator_get_regdma_segment(ctx); |
| 836 | |
Alan Kwong | 5b4d71b | 2017-02-10 20:52:59 -0800 | [diff] [blame] | 837 | /* |
| 838 | * initialize start control trigger selection first |
| 839 | */ |
| 840 | if (test_bit(SDE_CAPS_SBUF_1, mdata->sde_caps_map)) { |
| 841 | if (ctx->sbuf_mode) |
| 842 | SDE_REGDMA_WRITE(wrptr, ROTTOP_START_CTRL, |
| 843 | ctx->start_ctrl); |
| 844 | else |
| 845 | SDE_REGDMA_WRITE(wrptr, ROTTOP_START_CTRL, 0); |
| 846 | } |
| 847 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 848 | /* source image setup */ |
| 849 | if ((flags & SDE_ROT_FLAG_DEINTERLACE) |
| 850 | && !(flags & SDE_ROT_FLAG_SOURCE_ROTATED_90)) { |
| 851 | for (i = 0; i < cfg->src_plane.num_planes; i++) |
| 852 | cfg->src_plane.ystride[i] *= 2; |
| 853 | width *= 2; |
| 854 | height /= 2; |
| 855 | } |
| 856 | |
| 857 | /* |
| 858 | * REGDMA BLK write from SRC_SIZE to OP_MODE, total 15 registers |
| 859 | */ |
| 860 | SDE_REGDMA_BLKWRITE_INC(wrptr, ROT_SSPP_SRC_SIZE, 15); |
| 861 | |
| 862 | /* SRC_SIZE, SRC_IMG_SIZE, SRC_XY, OUT_SIZE, OUT_XY */ |
| 863 | SDE_REGDMA_BLKWRITE_DATA(wrptr, |
| 864 | cfg->src_rect->w | (cfg->src_rect->h << 16)); |
| 865 | SDE_REGDMA_BLKWRITE_DATA(wrptr, 0); /* SRC_IMG_SIZE unused */ |
| 866 | SDE_REGDMA_BLKWRITE_DATA(wrptr, |
| 867 | cfg->src_rect->x | (cfg->src_rect->y << 16)); |
| 868 | SDE_REGDMA_BLKWRITE_DATA(wrptr, |
| 869 | cfg->src_rect->w | (cfg->src_rect->h << 16)); |
| 870 | SDE_REGDMA_BLKWRITE_DATA(wrptr, |
| 871 | cfg->src_rect->x | (cfg->src_rect->y << 16)); |
| 872 | |
| 873 | /* SRC_ADDR [0-3], SRC_YSTRIDE [0-1] */ |
| 874 | data = cfg->data; |
| 875 | for (i = 0; i < SDE_ROT_MAX_PLANES; i++) |
| 876 | SDE_REGDMA_BLKWRITE_DATA(wrptr, data->p[i].addr); |
| 877 | SDE_REGDMA_BLKWRITE_DATA(wrptr, cfg->src_plane.ystride[0] | |
| 878 | (cfg->src_plane.ystride[1] << 16)); |
| 879 | SDE_REGDMA_BLKWRITE_DATA(wrptr, cfg->src_plane.ystride[2] | |
| 880 | (cfg->src_plane.ystride[3] << 16)); |
| 881 | |
| 882 | /* UNUSED, write 0 */ |
| 883 | SDE_REGDMA_BLKWRITE_DATA(wrptr, 0); |
| 884 | |
| 885 | /* setup source format */ |
| 886 | fmt = cfg->fmt; |
| 887 | |
| 888 | chroma_samp = fmt->chroma_sample; |
| 889 | if (flags & SDE_ROT_FLAG_SOURCE_ROTATED_90) { |
| 890 | if (chroma_samp == SDE_MDP_CHROMA_H2V1) |
| 891 | chroma_samp = SDE_MDP_CHROMA_H1V2; |
| 892 | else if (chroma_samp == SDE_MDP_CHROMA_H1V2) |
| 893 | chroma_samp = SDE_MDP_CHROMA_H2V1; |
| 894 | } |
| 895 | |
| 896 | src_format = (chroma_samp << 23) | |
| 897 | (fmt->fetch_planes << 19) | |
| 898 | (fmt->bits[C3_ALPHA] << 6) | |
| 899 | (fmt->bits[C2_R_Cr] << 4) | |
| 900 | (fmt->bits[C1_B_Cb] << 2) | |
| 901 | (fmt->bits[C0_G_Y] << 0); |
| 902 | |
| 903 | if (fmt->alpha_enable && |
| 904 | (fmt->fetch_planes == SDE_MDP_PLANE_INTERLEAVED)) |
| 905 | src_format |= BIT(8); /* SRCC3_EN */ |
| 906 | |
| 907 | src_format |= ((fmt->unpack_count - 1) << 12) | |
| 908 | (fmt->unpack_tight << 17) | |
| 909 | (fmt->unpack_align_msb << 18) | |
| 910 | ((fmt->bpp - 1) << 9) | |
| 911 | ((fmt->frame_format & 3) << 30); |
| 912 | |
| 913 | if (flags & SDE_ROT_FLAG_ROT_90) |
| 914 | src_format |= BIT(11); /* ROT90 */ |
| 915 | |
| 916 | if (sde_mdp_is_ubwc_format(fmt)) |
| 917 | opmode |= BIT(0); /* BWC_DEC_EN */ |
| 918 | |
| 919 | /* if this is YUV pixel format, enable CSC */ |
| 920 | if (sde_mdp_is_yuv_format(fmt)) |
| 921 | src_format |= BIT(15); /* SRC_COLOR_SPACE */ |
| 922 | |
| 923 | if (fmt->pixel_mode == SDE_MDP_PIXEL_10BIT) |
| 924 | src_format |= BIT(14); /* UNPACK_DX_FORMAT */ |
| 925 | |
Alan Kwong | 3bef26f | 2017-02-26 15:38:09 -0800 | [diff] [blame] | 926 | if (rot->solid_fill) |
| 927 | src_format |= BIT(22); /* SOLID_FILL */ |
| 928 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 929 | /* SRC_FORMAT */ |
| 930 | SDE_REGDMA_BLKWRITE_DATA(wrptr, src_format); |
| 931 | |
| 932 | /* setup source unpack pattern */ |
| 933 | unpack = (fmt->element[3] << 24) | (fmt->element[2] << 16) | |
| 934 | (fmt->element[1] << 8) | (fmt->element[0] << 0); |
| 935 | |
| 936 | /* SRC_UNPACK_PATTERN */ |
| 937 | SDE_REGDMA_BLKWRITE_DATA(wrptr, unpack); |
| 938 | |
| 939 | /* setup source op mode */ |
| 940 | if (flags & SDE_ROT_FLAG_FLIP_LR) |
| 941 | opmode |= BIT(13); /* FLIP_MODE L/R horizontal flip */ |
| 942 | if (flags & SDE_ROT_FLAG_FLIP_UD) |
| 943 | opmode |= BIT(14); /* FLIP_MODE U/D vertical flip */ |
| 944 | opmode |= BIT(31); /* MDSS_MDP_OP_PE_OVERRIDE */ |
| 945 | |
| 946 | /* SRC_OP_MODE */ |
| 947 | SDE_REGDMA_BLKWRITE_DATA(wrptr, opmode); |
| 948 | |
| 949 | /* setup source fetch config, TP10 uses different block size */ |
Benjamin Chan | fb6faa3 | 2016-08-16 17:21:01 -0400 | [diff] [blame] | 950 | if (test_bit(SDE_CAPS_R3_1P5_DOWNSCALE, mdata->sde_caps_map) && |
| 951 | (dnsc_factor_w == 1) && (dnsc_factor_h == 1)) { |
| 952 | if (sde_mdp_is_tp10_format(fmt)) |
| 953 | fetch_blocksize = SDE_ROT_SSPP_FETCH_BLOCKSIZE_144_EXT; |
| 954 | else |
| 955 | fetch_blocksize = SDE_ROT_SSPP_FETCH_BLOCKSIZE_192_EXT; |
| 956 | } else { |
| 957 | if (sde_mdp_is_tp10_format(fmt)) |
| 958 | fetch_blocksize = SDE_ROT_SSPP_FETCH_BLOCKSIZE_96; |
| 959 | else |
| 960 | fetch_blocksize = SDE_ROT_SSPP_FETCH_BLOCKSIZE_128; |
| 961 | } |
| 962 | |
Alan Kwong | 3bef26f | 2017-02-26 15:38:09 -0800 | [diff] [blame] | 963 | if (rot->solid_fill) |
| 964 | SDE_REGDMA_WRITE(wrptr, ROT_SSPP_SRC_CONSTANT_COLOR, |
| 965 | rot->constant_color); |
| 966 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 967 | SDE_REGDMA_WRITE(wrptr, ROT_SSPP_FETCH_CONFIG, |
| 968 | fetch_blocksize | |
| 969 | SDE_ROT_SSPP_FETCH_CONFIG_RESET_VALUE | |
| 970 | ((rot->highest_bank & 0x3) << 18)); |
| 971 | |
Alan Kwong | fb8eeb2 | 2017-02-06 15:00:03 -0800 | [diff] [blame] | 972 | if (test_bit(SDE_CAPS_UBWC_2, mdata->sde_caps_map)) |
| 973 | SDE_REGDMA_WRITE(wrptr, ROT_SSPP_UBWC_STATIC_CTRL, BIT(31) | |
| 974 | ((ctx->rot->ubwc_malsize & 0x3) << 8) | |
| 975 | ((ctx->rot->highest_bank & 0x3) << 4) | |
| 976 | ((ctx->rot->ubwc_swizzle & 0x1) << 0)); |
| 977 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 978 | /* setup source buffer plane security status */ |
Abhijit Kulkarni | 298c823 | 2016-09-26 22:32:10 -0700 | [diff] [blame] | 979 | if (flags & (SDE_ROT_FLAG_SECURE_OVERLAY_SESSION | |
| 980 | SDE_ROT_FLAG_SECURE_CAMERA_SESSION)) { |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 981 | SDE_REGDMA_WRITE(wrptr, ROT_SSPP_SRC_ADDR_SW_STATUS, 0xF); |
| 982 | ctx->is_secure = true; |
Benjamin Chan | 15c93d8 | 2016-08-29 10:04:22 -0400 | [diff] [blame] | 983 | } else { |
| 984 | SDE_REGDMA_WRITE(wrptr, ROT_SSPP_SRC_ADDR_SW_STATUS, 0); |
| 985 | ctx->is_secure = false; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 986 | } |
| 987 | |
Benjamin Chan | 99eb63b | 2016-12-21 15:45:26 -0500 | [diff] [blame] | 988 | /* |
| 989 | * Determine if traffic shaping is required. Only enable traffic |
| 990 | * shaping when content is 4k@30fps. The actual traffic shaping |
| 991 | * bandwidth calculation is done in output setup. |
| 992 | */ |
| 993 | if (((cfg->src_rect->w * cfg->src_rect->h) >= RES_UHD) && |
| 994 | (cfg->fps <= 30)) { |
| 995 | SDEROT_DBG("Enable Traffic Shaper\n"); |
| 996 | ctx->is_traffic_shaping = true; |
| 997 | } else { |
| 998 | SDEROT_DBG("Disable Traffic Shaper\n"); |
| 999 | ctx->is_traffic_shaping = false; |
| 1000 | } |
| 1001 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1002 | /* Update command queue write ptr */ |
| 1003 | sde_hw_rotator_put_regdma_segment(ctx, wrptr); |
| 1004 | } |
| 1005 | |
| 1006 | /* |
| 1007 | * sde_hw_rotator_setup_wbengine - setup writeback engine |
| 1008 | * @ctx: Pointer to rotator context |
| 1009 | * @queue_id: Priority queue identifier |
| 1010 | * @cfg: Writeback configuration |
| 1011 | * @flags: Control flag |
| 1012 | */ |
| 1013 | static void sde_hw_rotator_setup_wbengine(struct sde_hw_rotator_context *ctx, |
| 1014 | enum sde_rot_queue_prio queue_id, |
| 1015 | struct sde_hw_rot_wb_cfg *cfg, |
| 1016 | u32 flags) |
| 1017 | { |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1018 | struct sde_rot_data_type *mdata = sde_rot_get_mdata(); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1019 | struct sde_mdp_format_params *fmt; |
| 1020 | u32 *wrptr; |
| 1021 | u32 pack = 0; |
| 1022 | u32 dst_format = 0; |
| 1023 | int i; |
| 1024 | |
| 1025 | wrptr = sde_hw_rotator_get_regdma_segment(ctx); |
| 1026 | |
| 1027 | fmt = cfg->fmt; |
| 1028 | |
| 1029 | /* setup WB DST format */ |
| 1030 | dst_format |= (fmt->chroma_sample << 23) | |
| 1031 | (fmt->fetch_planes << 19) | |
| 1032 | (fmt->bits[C3_ALPHA] << 6) | |
| 1033 | (fmt->bits[C2_R_Cr] << 4) | |
| 1034 | (fmt->bits[C1_B_Cb] << 2) | |
| 1035 | (fmt->bits[C0_G_Y] << 0); |
| 1036 | |
| 1037 | /* alpha control */ |
| 1038 | if (fmt->bits[C3_ALPHA] || fmt->alpha_enable) { |
| 1039 | dst_format |= BIT(8); |
| 1040 | if (!fmt->alpha_enable) { |
| 1041 | dst_format |= BIT(14); |
| 1042 | SDE_REGDMA_WRITE(wrptr, ROT_WB_DST_ALPHA_X_VALUE, 0); |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | dst_format |= ((fmt->unpack_count - 1) << 12) | |
| 1047 | (fmt->unpack_tight << 17) | |
| 1048 | (fmt->unpack_align_msb << 18) | |
| 1049 | ((fmt->bpp - 1) << 9) | |
| 1050 | ((fmt->frame_format & 3) << 30); |
| 1051 | |
| 1052 | if (sde_mdp_is_yuv_format(fmt)) |
| 1053 | dst_format |= BIT(15); |
| 1054 | |
| 1055 | if (fmt->pixel_mode == SDE_MDP_PIXEL_10BIT) |
| 1056 | dst_format |= BIT(21); /* PACK_DX_FORMAT */ |
| 1057 | |
| 1058 | /* |
| 1059 | * REGDMA BLK write, from DST_FORMAT to DST_YSTRIDE 1, total 9 regs |
| 1060 | */ |
| 1061 | SDE_REGDMA_BLKWRITE_INC(wrptr, ROT_WB_DST_FORMAT, 9); |
| 1062 | |
| 1063 | /* DST_FORMAT */ |
| 1064 | SDE_REGDMA_BLKWRITE_DATA(wrptr, dst_format); |
| 1065 | |
| 1066 | /* DST_OP_MODE */ |
| 1067 | if (sde_mdp_is_ubwc_format(fmt)) |
| 1068 | SDE_REGDMA_BLKWRITE_DATA(wrptr, BIT(0)); |
| 1069 | else |
| 1070 | SDE_REGDMA_BLKWRITE_DATA(wrptr, 0); |
| 1071 | |
| 1072 | /* DST_PACK_PATTERN */ |
| 1073 | pack = (fmt->element[3] << 24) | (fmt->element[2] << 16) | |
| 1074 | (fmt->element[1] << 8) | (fmt->element[0] << 0); |
| 1075 | SDE_REGDMA_BLKWRITE_DATA(wrptr, pack); |
| 1076 | |
| 1077 | /* DST_ADDR [0-3], DST_YSTRIDE [0-1] */ |
| 1078 | for (i = 0; i < SDE_ROT_MAX_PLANES; i++) |
| 1079 | SDE_REGDMA_BLKWRITE_DATA(wrptr, cfg->data->p[i].addr); |
| 1080 | SDE_REGDMA_BLKWRITE_DATA(wrptr, cfg->dst_plane.ystride[0] | |
| 1081 | (cfg->dst_plane.ystride[1] << 16)); |
| 1082 | SDE_REGDMA_BLKWRITE_DATA(wrptr, cfg->dst_plane.ystride[2] | |
| 1083 | (cfg->dst_plane.ystride[3] << 16)); |
| 1084 | |
| 1085 | /* setup WB out image size and ROI */ |
| 1086 | SDE_REGDMA_WRITE(wrptr, ROT_WB_OUT_IMG_SIZE, |
| 1087 | cfg->img_width | (cfg->img_height << 16)); |
| 1088 | SDE_REGDMA_WRITE(wrptr, ROT_WB_OUT_SIZE, |
| 1089 | cfg->dst_rect->w | (cfg->dst_rect->h << 16)); |
| 1090 | SDE_REGDMA_WRITE(wrptr, ROT_WB_OUT_XY, |
| 1091 | cfg->dst_rect->x | (cfg->dst_rect->y << 16)); |
| 1092 | |
Abhijit Kulkarni | 298c823 | 2016-09-26 22:32:10 -0700 | [diff] [blame] | 1093 | if (flags & (SDE_ROT_FLAG_SECURE_OVERLAY_SESSION | |
| 1094 | SDE_ROT_FLAG_SECURE_CAMERA_SESSION)) |
Benjamin Chan | 15c93d8 | 2016-08-29 10:04:22 -0400 | [diff] [blame] | 1095 | SDE_REGDMA_WRITE(wrptr, ROT_WB_DST_ADDR_SW_STATUS, 0x1); |
| 1096 | else |
| 1097 | SDE_REGDMA_WRITE(wrptr, ROT_WB_DST_ADDR_SW_STATUS, 0); |
| 1098 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1099 | /* |
| 1100 | * setup Downscale factor |
| 1101 | */ |
| 1102 | SDE_REGDMA_WRITE(wrptr, ROTTOP_DNSC, |
| 1103 | cfg->v_downscale_factor | |
| 1104 | (cfg->h_downscale_factor << 16)); |
| 1105 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1106 | /* write config setup for bank configuration */ |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1107 | SDE_REGDMA_WRITE(wrptr, ROT_WB_DST_WRITE_CONFIG, |
| 1108 | (ctx->rot->highest_bank & 0x3) << 8); |
| 1109 | |
Alan Kwong | fb8eeb2 | 2017-02-06 15:00:03 -0800 | [diff] [blame] | 1110 | if (test_bit(SDE_CAPS_UBWC_2, mdata->sde_caps_map)) |
| 1111 | SDE_REGDMA_WRITE(wrptr, ROT_WB_UBWC_STATIC_CTRL, |
| 1112 | ((ctx->rot->ubwc_malsize & 0x3) << 8) | |
| 1113 | ((ctx->rot->highest_bank & 0x3) << 4) | |
| 1114 | ((ctx->rot->ubwc_swizzle & 0x1) << 0)); |
| 1115 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1116 | if (test_bit(SDE_CAPS_SBUF_1, mdata->sde_caps_map)) |
| 1117 | SDE_REGDMA_WRITE(wrptr, ROT_WB_SYS_CACHE_MODE, |
| 1118 | ctx->sys_cache_mode); |
| 1119 | |
| 1120 | SDE_REGDMA_WRITE(wrptr, ROTTOP_OP_MODE, ctx->op_mode | |
| 1121 | (flags & SDE_ROT_FLAG_ROT_90 ? BIT(1) : 0) | BIT(0)); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1122 | |
Alan Kwong | 498d59f | 2017-02-11 18:56:34 -0800 | [diff] [blame] | 1123 | /* setup traffic shaper for 4k 30fps content or if prefill_bw is set */ |
| 1124 | if (ctx->is_traffic_shaping || cfg->prefill_bw) { |
Benjamin Chan | 99eb63b | 2016-12-21 15:45:26 -0500 | [diff] [blame] | 1125 | u32 bw; |
| 1126 | |
| 1127 | /* |
| 1128 | * Target to finish in 12ms, and we need to set number of bytes |
| 1129 | * per clock tick for traffic shaping. |
| 1130 | * Each clock tick run @ 19.2MHz, so we need we know total of |
| 1131 | * clock ticks in 14ms, i.e. 12ms/(1/19.2MHz) ==> 23040 |
| 1132 | * Finally, calcualte the byte count per clock tick based on |
| 1133 | * resolution, bpp and compression ratio. |
| 1134 | */ |
| 1135 | bw = cfg->dst_rect->w * cfg->dst_rect->h; |
| 1136 | |
| 1137 | if (fmt->chroma_sample == SDE_MDP_CHROMA_420) |
| 1138 | bw = (bw * 3) / 2; |
| 1139 | else |
| 1140 | bw *= fmt->bpp; |
| 1141 | |
| 1142 | bw /= TRAFFIC_SHAPE_CLKTICK_12MS; |
Alan Kwong | 498d59f | 2017-02-11 18:56:34 -0800 | [diff] [blame] | 1143 | |
| 1144 | /* use prefill bandwidth instead if specified */ |
| 1145 | if (cfg->prefill_bw) |
| 1146 | bw = DIV_ROUND_UP(cfg->prefill_bw, |
| 1147 | TRAFFIC_SHAPE_VSYNC_CLK); |
| 1148 | |
Benjamin Chan | 99eb63b | 2016-12-21 15:45:26 -0500 | [diff] [blame] | 1149 | if (bw > 0xFF) |
| 1150 | bw = 0xFF; |
| 1151 | SDE_REGDMA_WRITE(wrptr, ROT_WB_TRAFFIC_SHAPER_WR_CLIENT, |
Alan Kwong | 498d59f | 2017-02-11 18:56:34 -0800 | [diff] [blame] | 1152 | BIT(31) | (cfg->prefill_bw ? BIT(27) : 0) | bw); |
Benjamin Chan | 99eb63b | 2016-12-21 15:45:26 -0500 | [diff] [blame] | 1153 | SDEROT_DBG("Enable ROT_WB Traffic Shaper:%d\n", bw); |
| 1154 | } else { |
| 1155 | SDE_REGDMA_WRITE(wrptr, ROT_WB_TRAFFIC_SHAPER_WR_CLIENT, 0); |
| 1156 | SDEROT_DBG("Disable ROT_WB Traffic Shaper\n"); |
| 1157 | } |
| 1158 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1159 | /* Update command queue write ptr */ |
| 1160 | sde_hw_rotator_put_regdma_segment(ctx, wrptr); |
| 1161 | } |
| 1162 | |
| 1163 | /* |
| 1164 | * sde_hw_rotator_start_no_regdma - start non-regdma operation |
| 1165 | * @ctx: Pointer to rotator context |
| 1166 | * @queue_id: Priority queue identifier |
| 1167 | */ |
| 1168 | static u32 sde_hw_rotator_start_no_regdma(struct sde_hw_rotator_context *ctx, |
| 1169 | enum sde_rot_queue_prio queue_id) |
| 1170 | { |
| 1171 | struct sde_hw_rotator *rot = ctx->rot; |
| 1172 | u32 *wrptr; |
| 1173 | u32 *rdptr; |
| 1174 | u8 *addr; |
| 1175 | u32 mask; |
| 1176 | u32 blksize; |
| 1177 | |
| 1178 | rdptr = sde_hw_rotator_get_regdma_segment_base(ctx); |
| 1179 | wrptr = sde_hw_rotator_get_regdma_segment(ctx); |
| 1180 | |
| 1181 | if (rot->irq_num >= 0) { |
| 1182 | SDE_REGDMA_WRITE(wrptr, ROTTOP_INTR_EN, 1); |
| 1183 | SDE_REGDMA_WRITE(wrptr, ROTTOP_INTR_CLEAR, 1); |
| 1184 | reinit_completion(&ctx->rot_comp); |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 1185 | sde_hw_rotator_enable_irq(rot); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1186 | } |
| 1187 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1188 | SDE_REGDMA_WRITE(wrptr, ROTTOP_START_CTRL, ctx->start_ctrl); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1189 | |
| 1190 | /* Update command queue write ptr */ |
| 1191 | sde_hw_rotator_put_regdma_segment(ctx, wrptr); |
| 1192 | |
| 1193 | SDEROT_DBG("BEGIN %d\n", ctx->timestamp); |
| 1194 | /* Write all command stream to Rotator blocks */ |
| 1195 | /* Rotator will start right away after command stream finish writing */ |
| 1196 | while (rdptr < wrptr) { |
| 1197 | u32 op = REGDMA_OP_MASK & *rdptr; |
| 1198 | |
| 1199 | switch (op) { |
| 1200 | case REGDMA_OP_NOP: |
| 1201 | SDEROT_DBG("NOP\n"); |
| 1202 | rdptr++; |
| 1203 | break; |
| 1204 | case REGDMA_OP_REGWRITE: |
| 1205 | SDEROT_DBG("REGW %6.6x %8.8x\n", |
| 1206 | rdptr[0] & REGDMA_ADDR_OFFSET_MASK, |
| 1207 | rdptr[1]); |
| 1208 | addr = rot->mdss_base + |
| 1209 | (*rdptr++ & REGDMA_ADDR_OFFSET_MASK); |
| 1210 | writel_relaxed(*rdptr++, addr); |
| 1211 | break; |
| 1212 | case REGDMA_OP_REGMODIFY: |
| 1213 | SDEROT_DBG("REGM %6.6x %8.8x %8.8x\n", |
| 1214 | rdptr[0] & REGDMA_ADDR_OFFSET_MASK, |
| 1215 | rdptr[1], rdptr[2]); |
| 1216 | addr = rot->mdss_base + |
| 1217 | (*rdptr++ & REGDMA_ADDR_OFFSET_MASK); |
| 1218 | mask = *rdptr++; |
| 1219 | writel_relaxed((readl_relaxed(addr) & mask) | *rdptr++, |
| 1220 | addr); |
| 1221 | break; |
| 1222 | case REGDMA_OP_BLKWRITE_SINGLE: |
| 1223 | SDEROT_DBG("BLKWS %6.6x %6.6x\n", |
| 1224 | rdptr[0] & REGDMA_ADDR_OFFSET_MASK, |
| 1225 | rdptr[1]); |
| 1226 | addr = rot->mdss_base + |
| 1227 | (*rdptr++ & REGDMA_ADDR_OFFSET_MASK); |
| 1228 | blksize = *rdptr++; |
| 1229 | while (blksize--) { |
| 1230 | SDEROT_DBG("DATA %8.8x\n", rdptr[0]); |
| 1231 | writel_relaxed(*rdptr++, addr); |
| 1232 | } |
| 1233 | break; |
| 1234 | case REGDMA_OP_BLKWRITE_INC: |
| 1235 | SDEROT_DBG("BLKWI %6.6x %6.6x\n", |
| 1236 | rdptr[0] & REGDMA_ADDR_OFFSET_MASK, |
| 1237 | rdptr[1]); |
| 1238 | addr = rot->mdss_base + |
| 1239 | (*rdptr++ & REGDMA_ADDR_OFFSET_MASK); |
| 1240 | blksize = *rdptr++; |
| 1241 | while (blksize--) { |
| 1242 | SDEROT_DBG("DATA %8.8x\n", rdptr[0]); |
| 1243 | writel_relaxed(*rdptr++, addr); |
| 1244 | addr += 4; |
| 1245 | } |
| 1246 | break; |
| 1247 | default: |
| 1248 | /* Other not supported OP mode |
| 1249 | * Skip data for now for unregonized OP mode |
| 1250 | */ |
| 1251 | SDEROT_DBG("UNDEFINED\n"); |
| 1252 | rdptr++; |
| 1253 | break; |
| 1254 | } |
| 1255 | } |
| 1256 | SDEROT_DBG("END %d\n", ctx->timestamp); |
| 1257 | |
| 1258 | return ctx->timestamp; |
| 1259 | } |
| 1260 | |
| 1261 | /* |
| 1262 | * sde_hw_rotator_start_regdma - start regdma operation |
| 1263 | * @ctx: Pointer to rotator context |
| 1264 | * @queue_id: Priority queue identifier |
| 1265 | */ |
| 1266 | static u32 sde_hw_rotator_start_regdma(struct sde_hw_rotator_context *ctx, |
| 1267 | enum sde_rot_queue_prio queue_id) |
| 1268 | { |
| 1269 | struct sde_hw_rotator *rot = ctx->rot; |
| 1270 | u32 *wrptr; |
| 1271 | u32 regdmaSlot; |
| 1272 | u32 offset; |
| 1273 | long length; |
| 1274 | long ts_length; |
| 1275 | u32 enableInt; |
| 1276 | u32 swts = 0; |
| 1277 | u32 mask = 0; |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1278 | u32 trig_sel; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1279 | |
| 1280 | wrptr = sde_hw_rotator_get_regdma_segment(ctx); |
| 1281 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1282 | /* |
| 1283 | * Last ROT command must be ROT_START before REGDMA start |
| 1284 | */ |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1285 | SDE_REGDMA_WRITE(wrptr, ROTTOP_START_CTRL, ctx->start_ctrl); |
| 1286 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1287 | sde_hw_rotator_put_regdma_segment(ctx, wrptr); |
| 1288 | |
| 1289 | /* |
| 1290 | * Start REGDMA with command offset and size |
| 1291 | */ |
| 1292 | regdmaSlot = sde_hw_rotator_get_regdma_ctxidx(ctx); |
| 1293 | length = ((long)wrptr - (long)ctx->regdma_base) / 4; |
| 1294 | offset = (u32)(ctx->regdma_base - (u32 *)(rot->mdss_base + |
| 1295 | REGDMA_RAM_REGDMA_CMD_RAM)); |
| 1296 | enableInt = ((ctx->timestamp & 1) + 1) << 30; |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1297 | trig_sel = ctx->sbuf_mode ? REGDMA_CMD_TRIG_SEL_MDP_FLUSH : |
| 1298 | REGDMA_CMD_TRIG_SEL_SW_START; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1299 | |
| 1300 | SDEROT_DBG( |
| 1301 | "regdma(%d)[%d] <== INT:0x%X|length:%ld|offset:0x%X, ts:%X\n", |
| 1302 | queue_id, regdmaSlot, enableInt, length, offset, |
| 1303 | ctx->timestamp); |
| 1304 | |
| 1305 | /* ensure the command packet is issued before the submit command */ |
| 1306 | wmb(); |
| 1307 | |
| 1308 | /* REGDMA submission for current context */ |
| 1309 | if (queue_id == ROT_QUEUE_HIGH_PRIORITY) { |
| 1310 | SDE_ROTREG_WRITE(rot->mdss_base, |
| 1311 | REGDMA_CSR_REGDMA_QUEUE_0_SUBMIT, |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1312 | (ctx->sbuf_mode ? enableInt : 0) | trig_sel | |
| 1313 | ((length & 0x3ff) << 14) | offset); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1314 | swts = ctx->timestamp; |
| 1315 | mask = ~SDE_REGDMA_SWTS_MASK; |
| 1316 | } else { |
| 1317 | SDE_ROTREG_WRITE(rot->mdss_base, |
| 1318 | REGDMA_CSR_REGDMA_QUEUE_1_SUBMIT, |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1319 | (ctx->sbuf_mode ? enableInt : 0) | trig_sel | |
| 1320 | ((length & 0x3ff) << 14) | offset); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1321 | swts = ctx->timestamp << SDE_REGDMA_SWTS_SHIFT; |
| 1322 | mask = ~(SDE_REGDMA_SWTS_MASK << SDE_REGDMA_SWTS_SHIFT); |
| 1323 | } |
| 1324 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1325 | /* timestamp update can only be used in offline multi-context mode */ |
| 1326 | if (!ctx->sbuf_mode) { |
| 1327 | /* Write timestamp after previous rotator job finished */ |
| 1328 | sde_hw_rotator_setup_timestamp_packet(ctx, mask, swts); |
| 1329 | offset += length; |
| 1330 | ts_length = sde_hw_rotator_get_regdma_segment(ctx) - wrptr; |
| 1331 | WARN_ON((length + ts_length) > SDE_HW_ROT_REGDMA_SEG_SIZE); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1332 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1333 | /* ensure command packet is issue before the submit command */ |
| 1334 | wmb(); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1335 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1336 | if (queue_id == ROT_QUEUE_HIGH_PRIORITY) { |
| 1337 | SDE_ROTREG_WRITE(rot->mdss_base, |
| 1338 | REGDMA_CSR_REGDMA_QUEUE_0_SUBMIT, |
| 1339 | enableInt | (ts_length << 14) | offset); |
| 1340 | } else { |
| 1341 | SDE_ROTREG_WRITE(rot->mdss_base, |
| 1342 | REGDMA_CSR_REGDMA_QUEUE_1_SUBMIT, |
| 1343 | enableInt | (ts_length << 14) | offset); |
| 1344 | } |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1345 | } |
| 1346 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1347 | /* Update command queue write ptr */ |
| 1348 | sde_hw_rotator_put_regdma_segment(ctx, wrptr); |
| 1349 | |
| 1350 | return ctx->timestamp; |
| 1351 | } |
| 1352 | |
| 1353 | /* |
| 1354 | * sde_hw_rotator_wait_done_no_regdma - wait for non-regdma completion |
| 1355 | * @ctx: Pointer to rotator context |
| 1356 | * @queue_id: Priority queue identifier |
| 1357 | * @flags: Option flag |
| 1358 | */ |
| 1359 | static u32 sde_hw_rotator_wait_done_no_regdma( |
| 1360 | struct sde_hw_rotator_context *ctx, |
| 1361 | enum sde_rot_queue_prio queue_id, u32 flag) |
| 1362 | { |
| 1363 | struct sde_hw_rotator *rot = ctx->rot; |
| 1364 | int rc = 0; |
| 1365 | u32 sts = 0; |
| 1366 | u32 status; |
| 1367 | unsigned long flags; |
| 1368 | |
| 1369 | if (rot->irq_num >= 0) { |
| 1370 | SDEROT_DBG("Wait for Rotator completion\n"); |
| 1371 | rc = wait_for_completion_timeout(&ctx->rot_comp, |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1372 | msecs_to_jiffies(rot->koff_timeout)); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1373 | |
| 1374 | spin_lock_irqsave(&rot->rotisr_lock, flags); |
| 1375 | status = SDE_ROTREG_READ(rot->mdss_base, ROTTOP_STATUS); |
| 1376 | if (rc == 0) { |
| 1377 | /* |
| 1378 | * Timeout, there might be error, |
| 1379 | * or rotator still busy |
| 1380 | */ |
| 1381 | if (status & ROT_BUSY_BIT) |
| 1382 | SDEROT_ERR( |
| 1383 | "Timeout waiting for rotator done\n"); |
| 1384 | else if (status & ROT_ERROR_BIT) |
| 1385 | SDEROT_ERR( |
| 1386 | "Rotator report error status\n"); |
| 1387 | else |
| 1388 | SDEROT_WARN( |
| 1389 | "Timeout waiting, but rotator job is done!!\n"); |
| 1390 | |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 1391 | sde_hw_rotator_disable_irq(rot); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1392 | } |
| 1393 | spin_unlock_irqrestore(&rot->rotisr_lock, flags); |
| 1394 | } else { |
| 1395 | int cnt = 200; |
| 1396 | |
| 1397 | do { |
| 1398 | udelay(500); |
| 1399 | status = SDE_ROTREG_READ(rot->mdss_base, ROTTOP_STATUS); |
| 1400 | cnt--; |
| 1401 | } while ((cnt > 0) && (status & ROT_BUSY_BIT) |
| 1402 | && ((status & ROT_ERROR_BIT) == 0)); |
| 1403 | |
| 1404 | if (status & ROT_ERROR_BIT) |
| 1405 | SDEROT_ERR("Rotator error\n"); |
| 1406 | else if (status & ROT_BUSY_BIT) |
| 1407 | SDEROT_ERR("Rotator busy\n"); |
| 1408 | |
| 1409 | SDE_ROTREG_WRITE(rot->mdss_base, ROTTOP_INTR_CLEAR, |
| 1410 | ROT_DONE_CLEAR); |
| 1411 | } |
| 1412 | |
| 1413 | sts = (status & ROT_ERROR_BIT) ? -ENODEV : 0; |
| 1414 | |
| 1415 | return sts; |
| 1416 | } |
| 1417 | |
| 1418 | /* |
| 1419 | * sde_hw_rotator_wait_done_regdma - wait for regdma completion |
| 1420 | * @ctx: Pointer to rotator context |
| 1421 | * @queue_id: Priority queue identifier |
| 1422 | * @flags: Option flag |
| 1423 | */ |
| 1424 | static u32 sde_hw_rotator_wait_done_regdma( |
| 1425 | struct sde_hw_rotator_context *ctx, |
| 1426 | enum sde_rot_queue_prio queue_id, u32 flag) |
| 1427 | { |
| 1428 | struct sde_hw_rotator *rot = ctx->rot; |
| 1429 | int rc = 0; |
| 1430 | u32 status; |
| 1431 | u32 last_isr; |
| 1432 | u32 last_ts; |
| 1433 | u32 int_id; |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 1434 | u32 swts; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1435 | u32 sts = 0; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1436 | unsigned long flags; |
| 1437 | |
| 1438 | if (rot->irq_num >= 0) { |
| 1439 | SDEROT_DBG("Wait for REGDMA completion, ctx:%p, ts:%X\n", |
| 1440 | ctx, ctx->timestamp); |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 1441 | rc = wait_event_timeout(ctx->regdma_waitq, |
| 1442 | !sde_hw_rotator_pending_swts(rot, ctx, &swts), |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1443 | msecs_to_jiffies(rot->koff_timeout)); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1444 | |
Benjamin Chan | e7ca72e | 2016-12-22 18:42:34 -0500 | [diff] [blame] | 1445 | ATRACE_INT("sde_rot_done", 0); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1446 | spin_lock_irqsave(&rot->rotisr_lock, flags); |
| 1447 | |
| 1448 | last_isr = ctx->last_regdma_isr_status; |
| 1449 | last_ts = ctx->last_regdma_timestamp; |
| 1450 | status = last_isr & REGDMA_INT_MASK; |
| 1451 | int_id = last_ts & 1; |
| 1452 | SDEROT_DBG("INT status:0x%X, INT id:%d, timestamp:0x%X\n", |
| 1453 | status, int_id, last_ts); |
| 1454 | |
| 1455 | if (rc == 0 || (status & REGDMA_INT_ERR_MASK)) { |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 1456 | bool pending; |
| 1457 | |
| 1458 | pending = sde_hw_rotator_pending_swts(rot, ctx, &swts); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1459 | SDEROT_ERR( |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 1460 | "Timeout wait for regdma interrupt status, ts:0x%X/0x%X pending:%d\n", |
| 1461 | ctx->timestamp, swts, pending); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1462 | |
| 1463 | if (status & REGDMA_WATCHDOG_INT) |
| 1464 | SDEROT_ERR("REGDMA watchdog interrupt\n"); |
| 1465 | else if (status & REGDMA_INVALID_DESCRIPTOR) |
| 1466 | SDEROT_ERR("REGDMA invalid descriptor\n"); |
| 1467 | else if (status & REGDMA_INCOMPLETE_CMD) |
| 1468 | SDEROT_ERR("REGDMA incomplete command\n"); |
| 1469 | else if (status & REGDMA_INVALID_CMD) |
| 1470 | SDEROT_ERR("REGDMA invalid command\n"); |
| 1471 | |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 1472 | sde_hw_rotator_dump_status(rot); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1473 | status = ROT_ERROR_BIT; |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 1474 | } else { |
| 1475 | if (rc == 1) |
| 1476 | SDEROT_WARN( |
| 1477 | "REGDMA done but no irq, ts:0x%X/0x%X\n", |
| 1478 | ctx->timestamp, swts); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1479 | status = 0; |
| 1480 | } |
| 1481 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1482 | spin_unlock_irqrestore(&rot->rotisr_lock, flags); |
| 1483 | } else { |
| 1484 | int cnt = 200; |
Alan Kwong | b067960 | 2016-11-27 17:04:13 -0800 | [diff] [blame] | 1485 | bool pending; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1486 | |
| 1487 | do { |
| 1488 | udelay(500); |
Alan Kwong | b067960 | 2016-11-27 17:04:13 -0800 | [diff] [blame] | 1489 | last_isr = SDE_ROTREG_READ(rot->mdss_base, |
| 1490 | REGDMA_CSR_REGDMA_INT_STATUS); |
| 1491 | pending = sde_hw_rotator_pending_swts(rot, ctx, &swts); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1492 | cnt--; |
Alan Kwong | b067960 | 2016-11-27 17:04:13 -0800 | [diff] [blame] | 1493 | } while ((cnt > 0) && pending && |
| 1494 | ((last_isr & REGDMA_INT_ERR_MASK) == 0)); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1495 | |
Alan Kwong | b067960 | 2016-11-27 17:04:13 -0800 | [diff] [blame] | 1496 | if (last_isr & REGDMA_INT_ERR_MASK) { |
| 1497 | SDEROT_ERR("Rotator error, ts:0x%X/0x%X status:%x\n", |
| 1498 | ctx->timestamp, swts, last_isr); |
| 1499 | sde_hw_rotator_dump_status(rot); |
| 1500 | status = ROT_ERROR_BIT; |
| 1501 | } else if (pending) { |
| 1502 | SDEROT_ERR("Rotator timeout, ts:0x%X/0x%X status:%x\n", |
| 1503 | ctx->timestamp, swts, last_isr); |
| 1504 | sde_hw_rotator_dump_status(rot); |
| 1505 | status = ROT_ERROR_BIT; |
| 1506 | } else { |
| 1507 | status = 0; |
| 1508 | } |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1509 | |
| 1510 | SDE_ROTREG_WRITE(rot->mdss_base, REGDMA_CSR_REGDMA_INT_CLEAR, |
Alan Kwong | b067960 | 2016-11-27 17:04:13 -0800 | [diff] [blame] | 1511 | last_isr); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | sts = (status & ROT_ERROR_BIT) ? -ENODEV : 0; |
| 1515 | |
Benjamin Chan | 4ec1f1d | 2016-09-15 22:49:49 -0400 | [diff] [blame] | 1516 | if (status & ROT_ERROR_BIT) |
Benjamin Chan | 2d6411a | 2017-03-28 18:01:53 -0400 | [diff] [blame] | 1517 | SDEROT_EVTLOG_TOUT_HANDLER("rot", "rot_dbg_bus", |
| 1518 | "vbif_dbg_bus", "panic"); |
Benjamin Chan | 4ec1f1d | 2016-09-15 22:49:49 -0400 | [diff] [blame] | 1519 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1520 | return sts; |
| 1521 | } |
| 1522 | |
| 1523 | /* |
| 1524 | * setup_rotator_ops - setup callback functions for the low-level HAL |
| 1525 | * @ops: Pointer to low-level ops callback |
| 1526 | * @mode: Operation mode (non-regdma or regdma) |
| 1527 | */ |
| 1528 | static void setup_rotator_ops(struct sde_hw_rotator_ops *ops, |
| 1529 | enum sde_rotator_regdma_mode mode) |
| 1530 | { |
| 1531 | ops->setup_rotator_fetchengine = sde_hw_rotator_setup_fetchengine; |
| 1532 | ops->setup_rotator_wbengine = sde_hw_rotator_setup_wbengine; |
| 1533 | if (mode == ROT_REGDMA_ON) { |
| 1534 | ops->start_rotator = sde_hw_rotator_start_regdma; |
| 1535 | ops->wait_rotator_done = sde_hw_rotator_wait_done_regdma; |
| 1536 | } else { |
| 1537 | ops->start_rotator = sde_hw_rotator_start_no_regdma; |
| 1538 | ops->wait_rotator_done = sde_hw_rotator_wait_done_no_regdma; |
| 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | /* |
| 1543 | * sde_hw_rotator_swts_create - create software timestamp buffer |
| 1544 | * @rot: Pointer to rotator hw |
| 1545 | * |
| 1546 | * This buffer is used by regdma to keep track of last completed command. |
| 1547 | */ |
| 1548 | static int sde_hw_rotator_swts_create(struct sde_hw_rotator *rot) |
| 1549 | { |
| 1550 | int rc = 0; |
| 1551 | struct ion_handle *handle; |
| 1552 | struct sde_mdp_img_data *data; |
Abhijit Kulkarni | 298c823 | 2016-09-26 22:32:10 -0700 | [diff] [blame] | 1553 | struct sde_rot_data_type *mdata = sde_rot_get_mdata(); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1554 | u32 bufsize = sizeof(int) * SDE_HW_ROT_REGDMA_TOTAL_CTX * 2; |
| 1555 | |
Abhijit Kulkarni | 298c823 | 2016-09-26 22:32:10 -0700 | [diff] [blame] | 1556 | rot->iclient = mdata->iclient; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1557 | |
| 1558 | handle = ion_alloc(rot->iclient, bufsize, SZ_4K, |
| 1559 | ION_HEAP(ION_SYSTEM_HEAP_ID), 0); |
| 1560 | if (IS_ERR_OR_NULL(handle)) { |
| 1561 | SDEROT_ERR("ion memory allocation failed\n"); |
| 1562 | return -ENOMEM; |
| 1563 | } |
| 1564 | |
| 1565 | data = &rot->swts_buf; |
| 1566 | data->len = bufsize; |
| 1567 | data->srcp_dma_buf = ion_share_dma_buf(rot->iclient, handle); |
| 1568 | if (IS_ERR(data->srcp_dma_buf)) { |
| 1569 | SDEROT_ERR("ion_dma_buf setup failed\n"); |
| 1570 | rc = -ENOMEM; |
| 1571 | goto imap_err; |
| 1572 | } |
| 1573 | |
| 1574 | sde_smmu_ctrl(1); |
| 1575 | |
| 1576 | data->srcp_attachment = sde_smmu_dma_buf_attach(data->srcp_dma_buf, |
| 1577 | &rot->pdev->dev, SDE_IOMMU_DOMAIN_ROT_UNSECURE); |
| 1578 | if (IS_ERR_OR_NULL(data->srcp_attachment)) { |
| 1579 | SDEROT_ERR("sde_smmu_dma_buf_attach error\n"); |
| 1580 | rc = -ENOMEM; |
| 1581 | goto err_put; |
| 1582 | } |
| 1583 | |
| 1584 | data->srcp_table = dma_buf_map_attachment(data->srcp_attachment, |
| 1585 | DMA_BIDIRECTIONAL); |
| 1586 | if (IS_ERR_OR_NULL(data->srcp_table)) { |
| 1587 | SDEROT_ERR("dma_buf_map_attachment error\n"); |
| 1588 | rc = -ENOMEM; |
| 1589 | goto err_detach; |
| 1590 | } |
| 1591 | |
| 1592 | rc = sde_smmu_map_dma_buf(data->srcp_dma_buf, data->srcp_table, |
| 1593 | SDE_IOMMU_DOMAIN_ROT_UNSECURE, &data->addr, |
| 1594 | &data->len, DMA_BIDIRECTIONAL); |
Alan Kwong | 6ce448d | 2016-11-24 18:45:20 -0800 | [diff] [blame] | 1595 | if (rc < 0) { |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1596 | SDEROT_ERR("smmu_map_dma_buf failed: (%d)\n", rc); |
| 1597 | goto err_unmap; |
| 1598 | } |
| 1599 | |
Alan Kwong | 6ce448d | 2016-11-24 18:45:20 -0800 | [diff] [blame] | 1600 | dma_buf_begin_cpu_access(data->srcp_dma_buf, DMA_FROM_DEVICE); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1601 | rot->swts_buffer = dma_buf_kmap(data->srcp_dma_buf, 0); |
| 1602 | if (IS_ERR_OR_NULL(rot->swts_buffer)) { |
| 1603 | SDEROT_ERR("ion kernel memory mapping failed\n"); |
| 1604 | rc = IS_ERR(rot->swts_buffer); |
| 1605 | goto kmap_err; |
| 1606 | } |
| 1607 | |
| 1608 | data->mapped = true; |
| 1609 | SDEROT_DBG("swts buffer mapped: %pad/%lx va:%p\n", &data->addr, |
| 1610 | data->len, rot->swts_buffer); |
| 1611 | |
| 1612 | ion_free(rot->iclient, handle); |
| 1613 | |
| 1614 | sde_smmu_ctrl(0); |
| 1615 | |
| 1616 | return rc; |
| 1617 | kmap_err: |
| 1618 | sde_smmu_unmap_dma_buf(data->srcp_table, SDE_IOMMU_DOMAIN_ROT_UNSECURE, |
| 1619 | DMA_FROM_DEVICE, data->srcp_dma_buf); |
| 1620 | err_unmap: |
| 1621 | dma_buf_unmap_attachment(data->srcp_attachment, data->srcp_table, |
| 1622 | DMA_FROM_DEVICE); |
| 1623 | err_detach: |
| 1624 | dma_buf_detach(data->srcp_dma_buf, data->srcp_attachment); |
| 1625 | err_put: |
| 1626 | dma_buf_put(data->srcp_dma_buf); |
| 1627 | data->srcp_dma_buf = NULL; |
| 1628 | imap_err: |
| 1629 | ion_free(rot->iclient, handle); |
| 1630 | |
| 1631 | return rc; |
| 1632 | } |
| 1633 | |
| 1634 | /* |
| 1635 | * sde_hw_rotator_swtc_destroy - destroy software timestamp buffer |
| 1636 | * @rot: Pointer to rotator hw |
| 1637 | */ |
| 1638 | static void sde_hw_rotator_swtc_destroy(struct sde_hw_rotator *rot) |
| 1639 | { |
| 1640 | struct sde_mdp_img_data *data; |
| 1641 | |
| 1642 | data = &rot->swts_buf; |
| 1643 | |
Alan Kwong | 6ce448d | 2016-11-24 18:45:20 -0800 | [diff] [blame] | 1644 | dma_buf_end_cpu_access(data->srcp_dma_buf, DMA_FROM_DEVICE); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1645 | dma_buf_kunmap(data->srcp_dma_buf, 0, rot->swts_buffer); |
| 1646 | |
| 1647 | sde_smmu_unmap_dma_buf(data->srcp_table, SDE_IOMMU_DOMAIN_ROT_UNSECURE, |
| 1648 | DMA_FROM_DEVICE, data->srcp_dma_buf); |
| 1649 | dma_buf_unmap_attachment(data->srcp_attachment, data->srcp_table, |
| 1650 | DMA_FROM_DEVICE); |
| 1651 | dma_buf_detach(data->srcp_dma_buf, data->srcp_attachment); |
| 1652 | dma_buf_put(data->srcp_dma_buf); |
| 1653 | data->srcp_dma_buf = NULL; |
| 1654 | } |
| 1655 | |
| 1656 | /* |
Benjamin Chan | 0f9e61d | 2016-09-16 16:01:09 -0400 | [diff] [blame] | 1657 | * sde_hw_rotator_pre_pmevent - SDE rotator core will call this before a |
| 1658 | * PM event occurs |
| 1659 | * @mgr: Pointer to rotator manager |
| 1660 | * @pmon: Boolean indicate an on/off power event |
| 1661 | */ |
| 1662 | void sde_hw_rotator_pre_pmevent(struct sde_rot_mgr *mgr, bool pmon) |
| 1663 | { |
| 1664 | struct sde_hw_rotator *rot; |
| 1665 | u32 l_ts, h_ts, swts, hwts; |
| 1666 | u32 rotsts, regdmasts; |
| 1667 | |
| 1668 | /* |
| 1669 | * Check last HW timestamp with SW timestamp before power off event. |
| 1670 | * If there is a mismatch, that will be quite possible the rotator HW |
| 1671 | * is either hang or not finishing last submitted job. In that case, |
| 1672 | * it is best to do a timeout eventlog to capture some good events |
| 1673 | * log data for analysis. |
| 1674 | */ |
| 1675 | if (!pmon && mgr && mgr->hw_data) { |
| 1676 | rot = mgr->hw_data; |
| 1677 | h_ts = atomic_read(&rot->timestamp[ROT_QUEUE_HIGH_PRIORITY]); |
| 1678 | l_ts = atomic_read(&rot->timestamp[ROT_QUEUE_LOW_PRIORITY]); |
| 1679 | |
| 1680 | /* contruct the combined timstamp */ |
| 1681 | swts = (h_ts & SDE_REGDMA_SWTS_MASK) | |
| 1682 | ((l_ts & SDE_REGDMA_SWTS_MASK) << |
| 1683 | SDE_REGDMA_SWTS_SHIFT); |
| 1684 | |
| 1685 | /* Need to turn on clock to access rotator register */ |
| 1686 | sde_rotator_clk_ctrl(mgr, true); |
| 1687 | hwts = SDE_ROTREG_READ(rot->mdss_base, REGDMA_TIMESTAMP_REG); |
| 1688 | regdmasts = SDE_ROTREG_READ(rot->mdss_base, |
| 1689 | REGDMA_CSR_REGDMA_BLOCK_STATUS); |
| 1690 | rotsts = SDE_ROTREG_READ(rot->mdss_base, ROTTOP_STATUS); |
| 1691 | |
| 1692 | SDEROT_DBG( |
| 1693 | "swts:0x%x, hwts:0x%x, regdma-sts:0x%x, rottop-sts:0x%x\n", |
| 1694 | swts, hwts, regdmasts, rotsts); |
| 1695 | SDEROT_EVTLOG(swts, hwts, regdmasts, rotsts); |
| 1696 | |
| 1697 | if ((swts != hwts) && ((regdmasts & REGDMA_BUSY) || |
| 1698 | (rotsts & ROT_STATUS_MASK))) { |
| 1699 | SDEROT_ERR( |
| 1700 | "Mismatch SWTS with HWTS: swts:0x%x, hwts:0x%x, regdma-sts:0x%x, rottop-sts:0x%x\n", |
| 1701 | swts, hwts, regdmasts, rotsts); |
Benjamin Chan | 2d6411a | 2017-03-28 18:01:53 -0400 | [diff] [blame] | 1702 | SDEROT_EVTLOG_TOUT_HANDLER("rot", "rot_dbg_bus", |
| 1703 | "vbif_dbg_bus", "panic"); |
Benjamin Chan | 0f9e61d | 2016-09-16 16:01:09 -0400 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | /* Turn off rotator clock after checking rotator registers */ |
| 1707 | sde_rotator_clk_ctrl(mgr, false); |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | /* |
| 1712 | * sde_hw_rotator_post_pmevent - SDE rotator core will call this after a |
| 1713 | * PM event occurs |
| 1714 | * @mgr: Pointer to rotator manager |
| 1715 | * @pmon: Boolean indicate an on/off power event |
| 1716 | */ |
| 1717 | void sde_hw_rotator_post_pmevent(struct sde_rot_mgr *mgr, bool pmon) |
| 1718 | { |
| 1719 | struct sde_hw_rotator *rot; |
| 1720 | u32 l_ts, h_ts, swts; |
| 1721 | |
| 1722 | /* |
| 1723 | * After a power on event, the rotator HW is reset to default setting. |
| 1724 | * It is necessary to synchronize the SW timestamp with the HW. |
| 1725 | */ |
| 1726 | if (pmon && mgr && mgr->hw_data) { |
| 1727 | rot = mgr->hw_data; |
| 1728 | h_ts = atomic_read(&rot->timestamp[ROT_QUEUE_HIGH_PRIORITY]); |
| 1729 | l_ts = atomic_read(&rot->timestamp[ROT_QUEUE_LOW_PRIORITY]); |
| 1730 | |
| 1731 | /* contruct the combined timstamp */ |
| 1732 | swts = (h_ts & SDE_REGDMA_SWTS_MASK) | |
| 1733 | ((l_ts & SDE_REGDMA_SWTS_MASK) << |
| 1734 | SDE_REGDMA_SWTS_SHIFT); |
| 1735 | |
| 1736 | SDEROT_DBG("swts:0x%x, h_ts:0x%x, l_ts;0x%x\n", |
| 1737 | swts, h_ts, l_ts); |
| 1738 | SDEROT_EVTLOG(swts, h_ts, l_ts); |
| 1739 | rot->reset_hw_ts = true; |
| 1740 | rot->last_hw_ts = swts; |
| 1741 | } |
| 1742 | } |
| 1743 | |
| 1744 | /* |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1745 | * sde_hw_rotator_destroy - Destroy hw rotator and free allocated resources |
| 1746 | * @mgr: Pointer to rotator manager |
| 1747 | */ |
| 1748 | static void sde_hw_rotator_destroy(struct sde_rot_mgr *mgr) |
| 1749 | { |
| 1750 | struct sde_rot_data_type *mdata = sde_rot_get_mdata(); |
| 1751 | struct sde_hw_rotator *rot; |
| 1752 | |
| 1753 | if (!mgr || !mgr->pdev || !mgr->hw_data) { |
| 1754 | SDEROT_ERR("null parameters\n"); |
| 1755 | return; |
| 1756 | } |
| 1757 | |
| 1758 | rot = mgr->hw_data; |
| 1759 | if (rot->irq_num >= 0) |
| 1760 | devm_free_irq(&mgr->pdev->dev, rot->irq_num, mdata); |
| 1761 | |
| 1762 | if (rot->mode == ROT_REGDMA_ON) |
| 1763 | sde_hw_rotator_swtc_destroy(rot); |
| 1764 | |
| 1765 | devm_kfree(&mgr->pdev->dev, mgr->hw_data); |
| 1766 | mgr->hw_data = NULL; |
| 1767 | } |
| 1768 | |
| 1769 | /* |
| 1770 | * sde_hw_rotator_alloc_ext - allocate rotator resource from rotator hw |
| 1771 | * @mgr: Pointer to rotator manager |
| 1772 | * @pipe_id: pipe identifier (not used) |
| 1773 | * @wb_id: writeback identifier/priority queue identifier |
| 1774 | * |
| 1775 | * This function allocates a new hw rotator resource for the given priority. |
| 1776 | */ |
| 1777 | static struct sde_rot_hw_resource *sde_hw_rotator_alloc_ext( |
| 1778 | struct sde_rot_mgr *mgr, u32 pipe_id, u32 wb_id) |
| 1779 | { |
| 1780 | struct sde_hw_rotator_resource_info *resinfo; |
| 1781 | |
| 1782 | if (!mgr || !mgr->hw_data) { |
| 1783 | SDEROT_ERR("null parameters\n"); |
| 1784 | return NULL; |
| 1785 | } |
| 1786 | |
| 1787 | /* |
| 1788 | * Allocate rotator resource info. Each allocation is per |
| 1789 | * HW priority queue |
| 1790 | */ |
| 1791 | resinfo = devm_kzalloc(&mgr->pdev->dev, sizeof(*resinfo), GFP_KERNEL); |
| 1792 | if (!resinfo) { |
| 1793 | SDEROT_ERR("Failed allocation HW rotator resource info\n"); |
| 1794 | return NULL; |
| 1795 | } |
| 1796 | |
| 1797 | resinfo->rot = mgr->hw_data; |
| 1798 | resinfo->hw.wb_id = wb_id; |
| 1799 | atomic_set(&resinfo->hw.num_active, 0); |
| 1800 | init_waitqueue_head(&resinfo->hw.wait_queue); |
| 1801 | |
| 1802 | /* For non-regdma, only support one active session */ |
| 1803 | if (resinfo->rot->mode == ROT_REGDMA_OFF) |
| 1804 | resinfo->hw.max_active = 1; |
| 1805 | else { |
| 1806 | resinfo->hw.max_active = SDE_HW_ROT_REGDMA_TOTAL_CTX - 1; |
| 1807 | |
| 1808 | if (resinfo->rot->iclient == NULL) |
| 1809 | sde_hw_rotator_swts_create(resinfo->rot); |
| 1810 | } |
| 1811 | |
Alan Kwong | f987ea3 | 2016-07-06 12:11:44 -0400 | [diff] [blame] | 1812 | if (resinfo->rot->irq_num >= 0) |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 1813 | sde_hw_rotator_enable_irq(resinfo->rot); |
Alan Kwong | f987ea3 | 2016-07-06 12:11:44 -0400 | [diff] [blame] | 1814 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1815 | SDEROT_DBG("New rotator resource:%p, priority:%d\n", |
| 1816 | resinfo, wb_id); |
| 1817 | |
| 1818 | return &resinfo->hw; |
| 1819 | } |
| 1820 | |
| 1821 | /* |
| 1822 | * sde_hw_rotator_free_ext - free the given rotator resource |
| 1823 | * @mgr: Pointer to rotator manager |
| 1824 | * @hw: Pointer to rotator resource |
| 1825 | */ |
| 1826 | static void sde_hw_rotator_free_ext(struct sde_rot_mgr *mgr, |
| 1827 | struct sde_rot_hw_resource *hw) |
| 1828 | { |
| 1829 | struct sde_hw_rotator_resource_info *resinfo; |
| 1830 | |
| 1831 | if (!mgr || !mgr->hw_data) |
| 1832 | return; |
| 1833 | |
| 1834 | resinfo = container_of(hw, struct sde_hw_rotator_resource_info, hw); |
| 1835 | |
| 1836 | SDEROT_DBG( |
| 1837 | "Free rotator resource:%p, priority:%d, active:%d, pending:%d\n", |
| 1838 | resinfo, hw->wb_id, atomic_read(&hw->num_active), |
| 1839 | hw->pending_count); |
| 1840 | |
Alan Kwong | f987ea3 | 2016-07-06 12:11:44 -0400 | [diff] [blame] | 1841 | if (resinfo->rot->irq_num >= 0) |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 1842 | sde_hw_rotator_disable_irq(resinfo->rot); |
Alan Kwong | f987ea3 | 2016-07-06 12:11:44 -0400 | [diff] [blame] | 1843 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1844 | devm_kfree(&mgr->pdev->dev, resinfo); |
| 1845 | } |
| 1846 | |
| 1847 | /* |
| 1848 | * sde_hw_rotator_alloc_rotctx - allocate rotator context |
| 1849 | * @rot: Pointer to rotator hw |
| 1850 | * @hw: Pointer to rotator resource |
| 1851 | * @session_id: Session identifier of this context |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1852 | * @sbuf_mode: true if stream buffer is requested |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1853 | * |
| 1854 | * This function allocates a new rotator context for the given session id. |
| 1855 | */ |
| 1856 | static struct sde_hw_rotator_context *sde_hw_rotator_alloc_rotctx( |
| 1857 | struct sde_hw_rotator *rot, |
| 1858 | struct sde_rot_hw_resource *hw, |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1859 | u32 session_id, |
| 1860 | bool sbuf_mode) |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1861 | { |
| 1862 | struct sde_hw_rotator_context *ctx; |
| 1863 | |
| 1864 | /* Allocate rotator context */ |
| 1865 | ctx = devm_kzalloc(&rot->pdev->dev, sizeof(*ctx), GFP_KERNEL); |
| 1866 | if (!ctx) { |
| 1867 | SDEROT_ERR("Failed allocation HW rotator context\n"); |
| 1868 | return NULL; |
| 1869 | } |
| 1870 | |
| 1871 | ctx->rot = rot; |
| 1872 | ctx->q_id = hw->wb_id; |
| 1873 | ctx->session_id = session_id; |
| 1874 | ctx->hwres = hw; |
| 1875 | ctx->timestamp = atomic_add_return(1, &rot->timestamp[ctx->q_id]); |
| 1876 | ctx->timestamp &= SDE_REGDMA_SWTS_MASK; |
| 1877 | ctx->is_secure = false; |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1878 | ctx->sbuf_mode = sbuf_mode; |
| 1879 | INIT_LIST_HEAD(&ctx->list); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1880 | |
| 1881 | ctx->regdma_base = rot->cmd_wr_ptr[ctx->q_id] |
| 1882 | [sde_hw_rotator_get_regdma_ctxidx(ctx)]; |
| 1883 | ctx->regdma_wrptr = ctx->regdma_base; |
| 1884 | ctx->ts_addr = (dma_addr_t)((u32 *)rot->swts_buf.addr + |
| 1885 | ctx->q_id * SDE_HW_ROT_REGDMA_TOTAL_CTX + |
| 1886 | sde_hw_rotator_get_regdma_ctxidx(ctx)); |
| 1887 | |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 1888 | ctx->last_regdma_timestamp = SDE_REGDMA_SWTS_INVALID; |
| 1889 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1890 | init_completion(&ctx->rot_comp); |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 1891 | init_waitqueue_head(&ctx->regdma_waitq); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1892 | |
| 1893 | /* Store rotator context for lookup purpose */ |
| 1894 | sde_hw_rotator_put_ctx(ctx); |
| 1895 | |
| 1896 | SDEROT_DBG( |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1897 | "New rot CTX:%p, ctxidx:%d, session-id:%d, prio:%d, timestamp:%X, active:%d sbuf:%d\n", |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1898 | ctx, sde_hw_rotator_get_regdma_ctxidx(ctx), ctx->session_id, |
| 1899 | ctx->q_id, ctx->timestamp, |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1900 | atomic_read(&ctx->hwres->num_active), |
| 1901 | ctx->sbuf_mode); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1902 | |
| 1903 | return ctx; |
| 1904 | } |
| 1905 | |
| 1906 | /* |
| 1907 | * sde_hw_rotator_free_rotctx - free the given rotator context |
| 1908 | * @rot: Pointer to rotator hw |
| 1909 | * @ctx: Pointer to rotator context |
| 1910 | */ |
| 1911 | static void sde_hw_rotator_free_rotctx(struct sde_hw_rotator *rot, |
| 1912 | struct sde_hw_rotator_context *ctx) |
| 1913 | { |
| 1914 | if (!rot || !ctx) |
| 1915 | return; |
| 1916 | |
| 1917 | SDEROT_DBG( |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1918 | "Free rot CTX:%p, ctxidx:%d, session-id:%d, prio:%d, timestamp:%X, active:%d sbuf:%d\n", |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1919 | ctx, sde_hw_rotator_get_regdma_ctxidx(ctx), ctx->session_id, |
| 1920 | ctx->q_id, ctx->timestamp, |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1921 | atomic_read(&ctx->hwres->num_active), |
| 1922 | ctx->sbuf_mode); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1923 | |
Benjamin Chan | c3e185f | 2016-11-08 21:48:21 -0500 | [diff] [blame] | 1924 | /* Clear rotator context from lookup purpose */ |
| 1925 | sde_hw_rotator_clr_ctx(ctx); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1926 | |
| 1927 | devm_kfree(&rot->pdev->dev, ctx); |
| 1928 | } |
| 1929 | |
| 1930 | /* |
| 1931 | * sde_hw_rotator_config - configure hw for the given rotation entry |
| 1932 | * @hw: Pointer to rotator resource |
| 1933 | * @entry: Pointer to rotation entry |
| 1934 | * |
| 1935 | * This function setup the fetch/writeback/rotator blocks, as well as VBIF |
| 1936 | * based on the given rotation entry. |
| 1937 | */ |
| 1938 | static int sde_hw_rotator_config(struct sde_rot_hw_resource *hw, |
| 1939 | struct sde_rot_entry *entry) |
| 1940 | { |
| 1941 | struct sde_rot_data_type *mdata = sde_rot_get_mdata(); |
| 1942 | struct sde_hw_rotator *rot; |
| 1943 | struct sde_hw_rotator_resource_info *resinfo; |
| 1944 | struct sde_hw_rotator_context *ctx; |
| 1945 | struct sde_hw_rot_sspp_cfg sspp_cfg; |
| 1946 | struct sde_hw_rot_wb_cfg wb_cfg; |
| 1947 | u32 danger_lut = 0; /* applicable for realtime client only */ |
| 1948 | u32 safe_lut = 0; /* applicable for realtime client only */ |
| 1949 | u32 flags = 0; |
Benjamin Chan | a9dd305 | 2017-02-14 17:39:32 -0500 | [diff] [blame] | 1950 | u32 rststs = 0; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1951 | struct sde_rotation_item *item; |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1952 | int ret; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1953 | |
| 1954 | if (!hw || !entry) { |
| 1955 | SDEROT_ERR("null hw resource/entry\n"); |
| 1956 | return -EINVAL; |
| 1957 | } |
| 1958 | |
| 1959 | resinfo = container_of(hw, struct sde_hw_rotator_resource_info, hw); |
| 1960 | rot = resinfo->rot; |
| 1961 | item = &entry->item; |
| 1962 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1963 | ctx = sde_hw_rotator_alloc_rotctx(rot, hw, item->session_id, |
| 1964 | item->output.sbuf); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 1965 | if (!ctx) { |
| 1966 | SDEROT_ERR("Failed allocating rotator context!!\n"); |
| 1967 | return -EINVAL; |
| 1968 | } |
| 1969 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 1970 | /* save entry for debugging purposes */ |
| 1971 | ctx->last_entry = entry; |
| 1972 | |
| 1973 | if (test_bit(SDE_CAPS_SBUF_1, mdata->sde_caps_map)) { |
| 1974 | if (entry->dst_buf.sbuf) { |
| 1975 | u32 op_mode; |
| 1976 | |
| 1977 | if (entry->item.trigger == |
| 1978 | SDE_ROTATOR_TRIGGER_COMMAND) |
| 1979 | ctx->start_ctrl = (rot->cmd_trigger << 4); |
| 1980 | else if (entry->item.trigger == |
| 1981 | SDE_ROTATOR_TRIGGER_VIDEO) |
| 1982 | ctx->start_ctrl = (rot->vid_trigger << 4); |
| 1983 | else |
| 1984 | ctx->start_ctrl = 0; |
| 1985 | |
| 1986 | ctx->sys_cache_mode = BIT(15) | |
| 1987 | ((item->output.scid & 0x1f) << 8) | |
| 1988 | (item->output.writeback ? 0x5 : 0); |
| 1989 | |
| 1990 | ctx->op_mode = BIT(4) | |
| 1991 | ((ctx->rot->sbuf_headroom & 0xff) << 8); |
| 1992 | |
| 1993 | /* detect transition to inline mode */ |
| 1994 | op_mode = (SDE_ROTREG_READ(rot->mdss_base, |
| 1995 | ROTTOP_OP_MODE) >> 4) & 0x3; |
| 1996 | if (!op_mode) { |
| 1997 | u32 status; |
| 1998 | |
| 1999 | status = SDE_ROTREG_READ(rot->mdss_base, |
| 2000 | ROTTOP_STATUS); |
| 2001 | if (status & BIT(0)) { |
| 2002 | SDEROT_ERR("rotator busy 0x%x\n", |
| 2003 | status); |
| 2004 | sde_hw_rotator_dump_status(rot); |
| 2005 | SDEROT_EVTLOG_TOUT_HANDLER("rot", |
| 2006 | "vbif_dbg_bus", |
| 2007 | "panic"); |
| 2008 | } |
| 2009 | } |
| 2010 | |
| 2011 | } else { |
| 2012 | ctx->start_ctrl = BIT(0); |
| 2013 | ctx->sys_cache_mode = 0; |
| 2014 | ctx->op_mode = 0; |
| 2015 | } |
| 2016 | } else { |
| 2017 | ctx->start_ctrl = BIT(0); |
| 2018 | } |
| 2019 | |
| 2020 | SDEROT_EVTLOG(ctx->start_ctrl, ctx->sys_cache_mode, ctx->op_mode); |
| 2021 | |
Benjamin Chan | a9dd305 | 2017-02-14 17:39:32 -0500 | [diff] [blame] | 2022 | /* |
| 2023 | * if Rotator HW is reset, but missing PM event notification, we |
| 2024 | * need to init the SW timestamp automatically. |
| 2025 | */ |
| 2026 | rststs = SDE_ROTREG_READ(rot->mdss_base, REGDMA_RESET_STATUS_REG); |
| 2027 | if (!rot->reset_hw_ts && rststs) { |
| 2028 | u32 l_ts, h_ts, swts; |
| 2029 | |
| 2030 | swts = SDE_ROTREG_READ(rot->mdss_base, REGDMA_TIMESTAMP_REG); |
| 2031 | h_ts = atomic_read(&rot->timestamp[ROT_QUEUE_HIGH_PRIORITY]); |
| 2032 | l_ts = atomic_read(&rot->timestamp[ROT_QUEUE_LOW_PRIORITY]); |
| 2033 | SDEROT_EVTLOG(0xbad0, rststs, swts, h_ts, l_ts); |
| 2034 | |
| 2035 | if (ctx->q_id == ROT_QUEUE_HIGH_PRIORITY) |
| 2036 | h_ts = (h_ts - 1) & SDE_REGDMA_SWTS_MASK; |
| 2037 | else |
| 2038 | l_ts = (l_ts - 1) & SDE_REGDMA_SWTS_MASK; |
| 2039 | |
| 2040 | /* construct the combined timstamp */ |
| 2041 | swts = (h_ts & SDE_REGDMA_SWTS_MASK) | |
| 2042 | ((l_ts & SDE_REGDMA_SWTS_MASK) << |
| 2043 | SDE_REGDMA_SWTS_SHIFT); |
| 2044 | |
| 2045 | SDEROT_DBG("swts:0x%x, h_ts:0x%x, l_ts;0x%x\n", |
| 2046 | swts, h_ts, l_ts); |
| 2047 | SDEROT_EVTLOG(0x900d, swts, h_ts, l_ts); |
| 2048 | rot->last_hw_ts = swts; |
| 2049 | |
| 2050 | SDE_ROTREG_WRITE(rot->mdss_base, REGDMA_TIMESTAMP_REG, |
| 2051 | rot->last_hw_ts); |
| 2052 | SDE_ROTREG_WRITE(rot->mdss_base, REGDMA_RESET_STATUS_REG, 0); |
| 2053 | /* ensure write is issued to the rotator HW */ |
| 2054 | wmb(); |
| 2055 | } |
| 2056 | |
Benjamin Chan | 0f9e61d | 2016-09-16 16:01:09 -0400 | [diff] [blame] | 2057 | if (rot->reset_hw_ts) { |
| 2058 | SDEROT_EVTLOG(rot->last_hw_ts); |
| 2059 | SDE_ROTREG_WRITE(rot->mdss_base, REGDMA_TIMESTAMP_REG, |
| 2060 | rot->last_hw_ts); |
Benjamin Chan | a9dd305 | 2017-02-14 17:39:32 -0500 | [diff] [blame] | 2061 | SDE_ROTREG_WRITE(rot->mdss_base, REGDMA_RESET_STATUS_REG, 0); |
Benjamin Chan | 0f9e61d | 2016-09-16 16:01:09 -0400 | [diff] [blame] | 2062 | /* ensure write is issued to the rotator HW */ |
| 2063 | wmb(); |
| 2064 | rot->reset_hw_ts = false; |
| 2065 | } |
| 2066 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2067 | flags = (item->flags & SDE_ROTATION_FLIP_LR) ? |
| 2068 | SDE_ROT_FLAG_FLIP_LR : 0; |
| 2069 | flags |= (item->flags & SDE_ROTATION_FLIP_UD) ? |
| 2070 | SDE_ROT_FLAG_FLIP_UD : 0; |
| 2071 | flags |= (item->flags & SDE_ROTATION_90) ? |
| 2072 | SDE_ROT_FLAG_ROT_90 : 0; |
| 2073 | flags |= (item->flags & SDE_ROTATION_DEINTERLACE) ? |
| 2074 | SDE_ROT_FLAG_DEINTERLACE : 0; |
| 2075 | flags |= (item->flags & SDE_ROTATION_SECURE) ? |
| 2076 | SDE_ROT_FLAG_SECURE_OVERLAY_SESSION : 0; |
Abhijit Kulkarni | 298c823 | 2016-09-26 22:32:10 -0700 | [diff] [blame] | 2077 | flags |= (item->flags & SDE_ROTATION_SECURE_CAMERA) ? |
| 2078 | SDE_ROT_FLAG_SECURE_CAMERA_SESSION : 0; |
| 2079 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2080 | |
| 2081 | sspp_cfg.img_width = item->input.width; |
| 2082 | sspp_cfg.img_height = item->input.height; |
Benjamin Chan | 99eb63b | 2016-12-21 15:45:26 -0500 | [diff] [blame] | 2083 | sspp_cfg.fps = entry->perf->config.frame_rate; |
| 2084 | sspp_cfg.bw = entry->perf->bw; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2085 | sspp_cfg.fmt = sde_get_format_params(item->input.format); |
| 2086 | if (!sspp_cfg.fmt) { |
| 2087 | SDEROT_ERR("null format\n"); |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 2088 | ret = -EINVAL; |
| 2089 | goto error; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2090 | } |
| 2091 | sspp_cfg.src_rect = &item->src_rect; |
| 2092 | sspp_cfg.data = &entry->src_buf; |
| 2093 | sde_mdp_get_plane_sizes(sspp_cfg.fmt, item->input.width, |
| 2094 | item->input.height, &sspp_cfg.src_plane, |
| 2095 | 0, /* No bwc_mode */ |
| 2096 | (flags & SDE_ROT_FLAG_SOURCE_ROTATED_90) ? |
| 2097 | true : false); |
| 2098 | |
| 2099 | rot->ops.setup_rotator_fetchengine(ctx, ctx->q_id, |
Benjamin Chan | fb6faa3 | 2016-08-16 17:21:01 -0400 | [diff] [blame] | 2100 | &sspp_cfg, danger_lut, safe_lut, |
| 2101 | entry->dnsc_factor_w, entry->dnsc_factor_h, flags); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2102 | |
| 2103 | wb_cfg.img_width = item->output.width; |
| 2104 | wb_cfg.img_height = item->output.height; |
Benjamin Chan | 99eb63b | 2016-12-21 15:45:26 -0500 | [diff] [blame] | 2105 | wb_cfg.fps = entry->perf->config.frame_rate; |
| 2106 | wb_cfg.bw = entry->perf->bw; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2107 | wb_cfg.fmt = sde_get_format_params(item->output.format); |
| 2108 | wb_cfg.dst_rect = &item->dst_rect; |
| 2109 | wb_cfg.data = &entry->dst_buf; |
| 2110 | sde_mdp_get_plane_sizes(wb_cfg.fmt, item->output.width, |
| 2111 | item->output.height, &wb_cfg.dst_plane, |
| 2112 | 0, /* No bwc_mode */ |
| 2113 | (flags & SDE_ROT_FLAG_ROT_90) ? true : false); |
| 2114 | |
| 2115 | wb_cfg.v_downscale_factor = entry->dnsc_factor_h; |
| 2116 | wb_cfg.h_downscale_factor = entry->dnsc_factor_w; |
Alan Kwong | 498d59f | 2017-02-11 18:56:34 -0800 | [diff] [blame] | 2117 | wb_cfg.prefill_bw = item->prefill_bw; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2118 | |
| 2119 | rot->ops.setup_rotator_wbengine(ctx, ctx->q_id, &wb_cfg, flags); |
| 2120 | |
| 2121 | /* setup VA mapping for debugfs */ |
| 2122 | if (rot->dbgmem) { |
| 2123 | sde_hw_rotator_map_vaddr(&ctx->src_dbgbuf, |
| 2124 | &item->input, |
| 2125 | &entry->src_buf); |
| 2126 | |
| 2127 | sde_hw_rotator_map_vaddr(&ctx->dst_dbgbuf, |
| 2128 | &item->output, |
| 2129 | &entry->dst_buf); |
| 2130 | } |
| 2131 | |
Benjamin Chan | 0f9e61d | 2016-09-16 16:01:09 -0400 | [diff] [blame] | 2132 | SDEROT_EVTLOG(ctx->timestamp, flags, |
| 2133 | item->input.width, item->input.height, |
Benjamin Chan | 53e3bce | 2016-08-31 14:43:29 -0400 | [diff] [blame] | 2134 | item->output.width, item->output.height, |
Benjamin Chan | 59a0605 | 2017-01-12 18:06:03 -0500 | [diff] [blame] | 2135 | entry->src_buf.p[0].addr, entry->dst_buf.p[0].addr, |
Benjamin Chan | 1b94f95 | 2017-01-23 17:42:30 -0500 | [diff] [blame] | 2136 | item->input.format, item->output.format, |
| 2137 | entry->perf->config.frame_rate); |
Benjamin Chan | 53e3bce | 2016-08-31 14:43:29 -0400 | [diff] [blame] | 2138 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2139 | if (mdata->default_ot_rd_limit) { |
| 2140 | struct sde_mdp_set_ot_params ot_params; |
| 2141 | |
| 2142 | memset(&ot_params, 0, sizeof(struct sde_mdp_set_ot_params)); |
| 2143 | ot_params.xin_id = XIN_SSPP; |
| 2144 | ot_params.num = 0; /* not used */ |
Alan Kwong | effb5ee | 2016-03-12 19:47:45 -0500 | [diff] [blame] | 2145 | ot_params.width = entry->perf->config.input.width; |
| 2146 | ot_params.height = entry->perf->config.input.height; |
| 2147 | ot_params.fps = entry->perf->config.frame_rate; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2148 | ot_params.reg_off_vbif_lim_conf = MMSS_VBIF_RD_LIM_CONF; |
| 2149 | ot_params.reg_off_mdp_clk_ctrl = |
| 2150 | MMSS_VBIF_NRT_VBIF_CLK_FORCE_CTRL0; |
| 2151 | ot_params.bit_off_mdp_clk_ctrl = |
| 2152 | MMSS_VBIF_NRT_VBIF_CLK_FORCE_CTRL0_XIN0; |
Benjamin Chan | 99eb63b | 2016-12-21 15:45:26 -0500 | [diff] [blame] | 2153 | ot_params.fmt = ctx->is_traffic_shaping ? |
| 2154 | SDE_PIX_FMT_ABGR_8888 : |
| 2155 | entry->perf->config.input.format; |
Benjamin Chan | 1b94f95 | 2017-01-23 17:42:30 -0500 | [diff] [blame] | 2156 | ot_params.rotsts_base = rot->mdss_base + ROTTOP_STATUS; |
| 2157 | ot_params.rotsts_busy_mask = ROT_BUSY_BIT; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2158 | sde_mdp_set_ot_limit(&ot_params); |
| 2159 | } |
| 2160 | |
| 2161 | if (mdata->default_ot_wr_limit) { |
| 2162 | struct sde_mdp_set_ot_params ot_params; |
| 2163 | |
| 2164 | memset(&ot_params, 0, sizeof(struct sde_mdp_set_ot_params)); |
| 2165 | ot_params.xin_id = XIN_WRITEBACK; |
| 2166 | ot_params.num = 0; /* not used */ |
Alan Kwong | effb5ee | 2016-03-12 19:47:45 -0500 | [diff] [blame] | 2167 | ot_params.width = entry->perf->config.input.width; |
| 2168 | ot_params.height = entry->perf->config.input.height; |
| 2169 | ot_params.fps = entry->perf->config.frame_rate; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2170 | ot_params.reg_off_vbif_lim_conf = MMSS_VBIF_WR_LIM_CONF; |
| 2171 | ot_params.reg_off_mdp_clk_ctrl = |
| 2172 | MMSS_VBIF_NRT_VBIF_CLK_FORCE_CTRL0; |
| 2173 | ot_params.bit_off_mdp_clk_ctrl = |
| 2174 | MMSS_VBIF_NRT_VBIF_CLK_FORCE_CTRL0_XIN1; |
Benjamin Chan | 99eb63b | 2016-12-21 15:45:26 -0500 | [diff] [blame] | 2175 | ot_params.fmt = ctx->is_traffic_shaping ? |
| 2176 | SDE_PIX_FMT_ABGR_8888 : |
| 2177 | entry->perf->config.input.format; |
Benjamin Chan | 1b94f95 | 2017-01-23 17:42:30 -0500 | [diff] [blame] | 2178 | ot_params.rotsts_base = rot->mdss_base + ROTTOP_STATUS; |
| 2179 | ot_params.rotsts_busy_mask = ROT_BUSY_BIT; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2180 | sde_mdp_set_ot_limit(&ot_params); |
| 2181 | } |
| 2182 | |
| 2183 | if (test_bit(SDE_QOS_PER_PIPE_LUT, mdata->sde_qos_map)) { |
| 2184 | u32 qos_lut = 0; /* low priority for nrt read client */ |
| 2185 | |
| 2186 | trace_rot_perf_set_qos_luts(XIN_SSPP, sspp_cfg.fmt->format, |
| 2187 | qos_lut, sde_mdp_is_linear_format(sspp_cfg.fmt)); |
| 2188 | |
| 2189 | SDE_ROTREG_WRITE(rot->mdss_base, ROT_SSPP_CREQ_LUT, qos_lut); |
| 2190 | } |
| 2191 | |
Jayant Shekhar | dee61a0 | 2017-02-08 11:59:00 +0530 | [diff] [blame] | 2192 | /* Set CDP control registers to 0 if CDP is disabled */ |
| 2193 | if (!test_bit(SDE_QOS_CDP, mdata->sde_qos_map)) { |
| 2194 | SDE_ROTREG_WRITE(rot->mdss_base, ROT_SSPP_CDP_CNTL, 0x0); |
| 2195 | SDE_ROTREG_WRITE(rot->mdss_base, ROT_WB_CDP_CNTL, 0x0); |
| 2196 | } |
| 2197 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2198 | if (mdata->npriority_lvl > 0) { |
| 2199 | u32 mask, reg_val, i, vbif_qos; |
| 2200 | |
| 2201 | for (i = 0; i < mdata->npriority_lvl; i++) { |
| 2202 | reg_val = SDE_VBIF_READ(mdata, |
| 2203 | MMSS_VBIF_NRT_VBIF_QOS_REMAP_00 + i*4); |
| 2204 | mask = 0x3 << (XIN_SSPP * 2); |
| 2205 | reg_val &= ~(mask); |
| 2206 | vbif_qos = mdata->vbif_nrt_qos[i]; |
| 2207 | reg_val |= vbif_qos << (XIN_SSPP * 2); |
| 2208 | /* ensure write is issued after the read operation */ |
| 2209 | mb(); |
| 2210 | SDE_VBIF_WRITE(mdata, |
| 2211 | MMSS_VBIF_NRT_VBIF_QOS_REMAP_00 + i*4, |
| 2212 | reg_val); |
| 2213 | } |
| 2214 | } |
| 2215 | |
| 2216 | /* Enable write gather for writeback to remove write gaps, which |
| 2217 | * may hang AXI/BIMC/SDE. |
| 2218 | */ |
| 2219 | SDE_VBIF_WRITE(mdata, MMSS_VBIF_NRT_VBIF_WRITE_GATHTER_EN, |
| 2220 | BIT(XIN_WRITEBACK)); |
| 2221 | |
Benjamin Chan | 2d6411a | 2017-03-28 18:01:53 -0400 | [diff] [blame] | 2222 | /* |
| 2223 | * For debug purpose, disable clock gating, i.e. Clocks always on |
| 2224 | */ |
| 2225 | if (mdata->clk_always_on) { |
| 2226 | SDE_VBIF_WRITE(mdata, MMSS_VBIF_CLKON, 0x3); |
| 2227 | SDE_VBIF_WRITE(mdata, MMSS_VBIF_NRT_VBIF_CLK_FORCE_CTRL0, 0x3); |
| 2228 | SDE_VBIF_WRITE(mdata, MMSS_VBIF_NRT_VBIF_CLK_FORCE_CTRL1, |
| 2229 | 0xFFFF); |
| 2230 | SDE_ROTREG_WRITE(rot->mdss_base, ROTTOP_CLK_CTRL, 1); |
| 2231 | } |
| 2232 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2233 | return 0; |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 2234 | |
| 2235 | error: |
| 2236 | sde_hw_rotator_free_rotctx(rot, ctx); |
| 2237 | return ret; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | /* |
| 2241 | * sde_hw_rotator_kickoff - kickoff processing on the given entry |
| 2242 | * @hw: Pointer to rotator resource |
| 2243 | * @entry: Pointer to rotation entry |
| 2244 | */ |
| 2245 | static int sde_hw_rotator_kickoff(struct sde_rot_hw_resource *hw, |
| 2246 | struct sde_rot_entry *entry) |
| 2247 | { |
| 2248 | struct sde_hw_rotator *rot; |
| 2249 | struct sde_hw_rotator_resource_info *resinfo; |
| 2250 | struct sde_hw_rotator_context *ctx; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2251 | |
| 2252 | if (!hw || !entry) { |
| 2253 | SDEROT_ERR("null hw resource/entry\n"); |
| 2254 | return -EINVAL; |
| 2255 | } |
| 2256 | |
| 2257 | resinfo = container_of(hw, struct sde_hw_rotator_resource_info, hw); |
| 2258 | rot = resinfo->rot; |
| 2259 | |
| 2260 | /* Lookup rotator context from session-id */ |
| 2261 | ctx = sde_hw_rotator_get_ctx(rot, entry->item.session_id, hw->wb_id); |
| 2262 | if (!ctx) { |
| 2263 | SDEROT_ERR("Cannot locate rotator ctx from sesison id:%d\n", |
| 2264 | entry->item.session_id); |
Benjamin Chan | 62b94ed | 2016-08-18 23:55:21 -0400 | [diff] [blame] | 2265 | return -EINVAL; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2266 | } |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2267 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2268 | rot->ops.start_rotator(ctx, ctx->q_id); |
| 2269 | |
| 2270 | return 0; |
| 2271 | } |
| 2272 | |
| 2273 | /* |
| 2274 | * sde_hw_rotator_wait4done - wait for completion notification |
| 2275 | * @hw: Pointer to rotator resource |
| 2276 | * @entry: Pointer to rotation entry |
| 2277 | * |
| 2278 | * This function blocks until the given entry is complete, error |
| 2279 | * is detected, or timeout. |
| 2280 | */ |
| 2281 | static int sde_hw_rotator_wait4done(struct sde_rot_hw_resource *hw, |
| 2282 | struct sde_rot_entry *entry) |
| 2283 | { |
| 2284 | struct sde_hw_rotator *rot; |
| 2285 | struct sde_hw_rotator_resource_info *resinfo; |
| 2286 | struct sde_hw_rotator_context *ctx; |
| 2287 | int ret; |
| 2288 | |
| 2289 | if (!hw || !entry) { |
| 2290 | SDEROT_ERR("null hw resource/entry\n"); |
| 2291 | return -EINVAL; |
| 2292 | } |
| 2293 | |
| 2294 | resinfo = container_of(hw, struct sde_hw_rotator_resource_info, hw); |
| 2295 | rot = resinfo->rot; |
| 2296 | |
| 2297 | /* Lookup rotator context from session-id */ |
| 2298 | ctx = sde_hw_rotator_get_ctx(rot, entry->item.session_id, hw->wb_id); |
| 2299 | if (!ctx) { |
| 2300 | SDEROT_ERR("Cannot locate rotator ctx from sesison id:%d\n", |
| 2301 | entry->item.session_id); |
Benjamin Chan | 62b94ed | 2016-08-18 23:55:21 -0400 | [diff] [blame] | 2302 | return -EINVAL; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2303 | } |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2304 | |
| 2305 | ret = rot->ops.wait_rotator_done(ctx, ctx->q_id, 0); |
| 2306 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2307 | if (rot->dbgmem) { |
| 2308 | sde_hw_rotator_unmap_vaddr(&ctx->src_dbgbuf); |
| 2309 | sde_hw_rotator_unmap_vaddr(&ctx->dst_dbgbuf); |
| 2310 | } |
| 2311 | |
| 2312 | /* Current rotator context job is finished, time to free up*/ |
| 2313 | sde_hw_rotator_free_rotctx(rot, ctx); |
| 2314 | |
| 2315 | return ret; |
| 2316 | } |
| 2317 | |
| 2318 | /* |
| 2319 | * sde_rotator_hw_rev_init - setup feature and/or capability bitmask |
| 2320 | * @rot: Pointer to hw rotator |
| 2321 | * |
| 2322 | * This function initializes feature and/or capability bitmask based on |
| 2323 | * h/w version read from the device. |
| 2324 | */ |
| 2325 | static int sde_rotator_hw_rev_init(struct sde_hw_rotator *rot) |
| 2326 | { |
| 2327 | struct sde_rot_data_type *mdata = sde_rot_get_mdata(); |
| 2328 | u32 hw_version; |
| 2329 | |
| 2330 | if (!mdata) { |
| 2331 | SDEROT_ERR("null rotator data\n"); |
| 2332 | return -EINVAL; |
| 2333 | } |
| 2334 | |
| 2335 | hw_version = SDE_ROTREG_READ(rot->mdss_base, ROTTOP_HW_VERSION); |
| 2336 | SDEROT_DBG("hw version %8.8x\n", hw_version); |
| 2337 | |
| 2338 | clear_bit(SDE_QOS_PER_PIPE_IB, mdata->sde_qos_map); |
| 2339 | set_bit(SDE_QOS_OVERHEAD_FACTOR, mdata->sde_qos_map); |
| 2340 | clear_bit(SDE_QOS_CDP, mdata->sde_qos_map); |
| 2341 | set_bit(SDE_QOS_OTLIM, mdata->sde_qos_map); |
| 2342 | set_bit(SDE_QOS_PER_PIPE_LUT, mdata->sde_qos_map); |
| 2343 | clear_bit(SDE_QOS_SIMPLIFIED_PREFILL, mdata->sde_qos_map); |
| 2344 | |
| 2345 | set_bit(SDE_CAPS_R3_WB, mdata->sde_caps_map); |
| 2346 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 2347 | /* features exposed via rotator top h/w version */ |
Benjamin Chan | fb6faa3 | 2016-08-16 17:21:01 -0400 | [diff] [blame] | 2348 | if (hw_version != SDE_ROT_TYPE_V1_0) { |
| 2349 | SDEROT_DBG("Supporting 1.5 downscale for SDE Rotator\n"); |
| 2350 | set_bit(SDE_CAPS_R3_1P5_DOWNSCALE, mdata->sde_caps_map); |
| 2351 | } |
| 2352 | |
Abhijit Kulkarni | 298c823 | 2016-09-26 22:32:10 -0700 | [diff] [blame] | 2353 | set_bit(SDE_CAPS_SEC_ATTACH_DETACH_SMMU, mdata->sde_caps_map); |
| 2354 | |
Benjamin Chan | 53e3bce | 2016-08-31 14:43:29 -0400 | [diff] [blame] | 2355 | mdata->nrt_vbif_dbg_bus = nrt_vbif_dbg_bus_r3; |
| 2356 | mdata->nrt_vbif_dbg_bus_size = |
| 2357 | ARRAY_SIZE(nrt_vbif_dbg_bus_r3); |
| 2358 | |
Benjamin Chan | 2d6411a | 2017-03-28 18:01:53 -0400 | [diff] [blame] | 2359 | mdata->rot_dbg_bus = rot_dbgbus_r3; |
| 2360 | mdata->rot_dbg_bus_size = ARRAY_SIZE(rot_dbgbus_r3); |
| 2361 | |
Benjamin Chan | 53e3bce | 2016-08-31 14:43:29 -0400 | [diff] [blame] | 2362 | mdata->regdump = sde_rot_r3_regdump; |
| 2363 | mdata->regdump_size = ARRAY_SIZE(sde_rot_r3_regdump); |
Benjamin Chan | 0f9e61d | 2016-09-16 16:01:09 -0400 | [diff] [blame] | 2364 | SDE_ROTREG_WRITE(rot->mdss_base, REGDMA_TIMESTAMP_REG, 0); |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 2365 | |
| 2366 | /* features exposed via mdss h/w version */ |
| 2367 | if (IS_SDE_MAJOR_MINOR_SAME(mdata->mdss_version, SDE_MDP_HW_REV_400)) { |
| 2368 | SDEROT_DBG("Supporting sys cache inline rotation\n"); |
| 2369 | set_bit(SDE_CAPS_SBUF_1, mdata->sde_caps_map); |
Alan Kwong | fb8eeb2 | 2017-02-06 15:00:03 -0800 | [diff] [blame] | 2370 | set_bit(SDE_CAPS_UBWC_2, mdata->sde_caps_map); |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 2371 | rot->inpixfmts = sde_hw_rotator_v4_inpixfmts; |
| 2372 | rot->num_inpixfmt = ARRAY_SIZE(sde_hw_rotator_v4_inpixfmts); |
| 2373 | rot->outpixfmts = sde_hw_rotator_v4_outpixfmts; |
| 2374 | rot->num_outpixfmt = ARRAY_SIZE(sde_hw_rotator_v4_outpixfmts); |
| 2375 | rot->downscale_caps = |
| 2376 | "LINEAR/1.5/2/4/8/16/32/64 TILE/1.5/2/4 TP10/1.5/2"; |
| 2377 | } else { |
| 2378 | rot->inpixfmts = sde_hw_rotator_v3_inpixfmts; |
| 2379 | rot->num_inpixfmt = ARRAY_SIZE(sde_hw_rotator_v3_inpixfmts); |
| 2380 | rot->outpixfmts = sde_hw_rotator_v3_outpixfmts; |
| 2381 | rot->num_outpixfmt = ARRAY_SIZE(sde_hw_rotator_v3_outpixfmts); |
| 2382 | rot->downscale_caps = (hw_version == SDE_ROT_TYPE_V1_0) ? |
| 2383 | "LINEAR/2/4/8/16/32/64 TILE/2/4 TP10/2" : |
| 2384 | "LINEAR/1.5/2/4/8/16/32/64 TILE/1.5/2/4 TP10/1.5/2"; |
| 2385 | } |
| 2386 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2387 | return 0; |
| 2388 | } |
| 2389 | |
| 2390 | /* |
| 2391 | * sde_hw_rotator_rotirq_handler - non-regdma interrupt handler |
| 2392 | * @irq: Interrupt number |
| 2393 | * @ptr: Pointer to private handle provided during registration |
| 2394 | * |
| 2395 | * This function services rotator interrupt and wakes up waiting client |
| 2396 | * with pending rotation requests already submitted to h/w. |
| 2397 | */ |
| 2398 | static irqreturn_t sde_hw_rotator_rotirq_handler(int irq, void *ptr) |
| 2399 | { |
| 2400 | struct sde_hw_rotator *rot = ptr; |
| 2401 | struct sde_hw_rotator_context *ctx; |
| 2402 | irqreturn_t ret = IRQ_NONE; |
| 2403 | u32 isr; |
| 2404 | |
| 2405 | isr = SDE_ROTREG_READ(rot->mdss_base, ROTTOP_INTR_STATUS); |
| 2406 | |
| 2407 | SDEROT_DBG("intr_status = %8.8x\n", isr); |
| 2408 | |
| 2409 | if (isr & ROT_DONE_MASK) { |
| 2410 | if (rot->irq_num >= 0) |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 2411 | sde_hw_rotator_disable_irq(rot); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2412 | SDEROT_DBG("Notify rotator complete\n"); |
| 2413 | |
| 2414 | /* Normal rotator only 1 session, no need to lookup */ |
| 2415 | ctx = rot->rotCtx[0][0]; |
| 2416 | WARN_ON(ctx == NULL); |
| 2417 | complete_all(&ctx->rot_comp); |
| 2418 | |
| 2419 | spin_lock(&rot->rotisr_lock); |
| 2420 | SDE_ROTREG_WRITE(rot->mdss_base, ROTTOP_INTR_CLEAR, |
| 2421 | ROT_DONE_CLEAR); |
| 2422 | spin_unlock(&rot->rotisr_lock); |
| 2423 | ret = IRQ_HANDLED; |
| 2424 | } |
| 2425 | |
| 2426 | return ret; |
| 2427 | } |
| 2428 | |
| 2429 | /* |
| 2430 | * sde_hw_rotator_regdmairq_handler - regdma interrupt handler |
| 2431 | * @irq: Interrupt number |
| 2432 | * @ptr: Pointer to private handle provided during registration |
| 2433 | * |
| 2434 | * This function services rotator interrupt, decoding the source of |
| 2435 | * events (high/low priority queue), and wakes up all waiting clients |
| 2436 | * with pending rotation requests already submitted to h/w. |
| 2437 | */ |
| 2438 | static irqreturn_t sde_hw_rotator_regdmairq_handler(int irq, void *ptr) |
| 2439 | { |
| 2440 | struct sde_hw_rotator *rot = ptr; |
| 2441 | struct sde_hw_rotator_context *ctx; |
| 2442 | irqreturn_t ret = IRQ_NONE; |
| 2443 | u32 isr; |
| 2444 | u32 ts; |
| 2445 | u32 q_id; |
| 2446 | |
| 2447 | isr = SDE_ROTREG_READ(rot->mdss_base, REGDMA_CSR_REGDMA_INT_STATUS); |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 2448 | /* acknowledge interrupt before reading latest timestamp */ |
| 2449 | SDE_ROTREG_WRITE(rot->mdss_base, REGDMA_CSR_REGDMA_INT_CLEAR, isr); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2450 | ts = SDE_ROTREG_READ(rot->mdss_base, REGDMA_TIMESTAMP_REG); |
| 2451 | |
| 2452 | SDEROT_DBG("intr_status = %8.8x, sw_TS:%X\n", isr, ts); |
| 2453 | |
| 2454 | /* Any REGDMA status, including error and watchdog timer, should |
| 2455 | * trigger and wake up waiting thread |
| 2456 | */ |
| 2457 | if (isr & (REGDMA_INT_HIGH_MASK | REGDMA_INT_LOW_MASK)) { |
| 2458 | spin_lock(&rot->rotisr_lock); |
| 2459 | |
| 2460 | /* |
| 2461 | * Obtain rotator context based on timestamp from regdma |
| 2462 | * and low/high interrupt status |
| 2463 | */ |
| 2464 | if (isr & REGDMA_INT_HIGH_MASK) { |
| 2465 | q_id = ROT_QUEUE_HIGH_PRIORITY; |
| 2466 | ts = ts & SDE_REGDMA_SWTS_MASK; |
| 2467 | } else if (isr & REGDMA_INT_LOW_MASK) { |
| 2468 | q_id = ROT_QUEUE_LOW_PRIORITY; |
| 2469 | ts = (ts >> SDE_REGDMA_SWTS_SHIFT) & |
| 2470 | SDE_REGDMA_SWTS_MASK; |
Benjamin Chan | 62b94ed | 2016-08-18 23:55:21 -0400 | [diff] [blame] | 2471 | } else { |
| 2472 | SDEROT_ERR("unknown ISR status: isr=0x%X\n", isr); |
| 2473 | goto done_isr_handle; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2474 | } |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 2475 | |
| 2476 | /* |
| 2477 | * Timestamp packet is not available in sbuf mode. |
| 2478 | * Simulate timestamp update in the handler instead. |
| 2479 | */ |
| 2480 | if (!list_empty(&rot->sbuf_ctx[q_id])) { |
| 2481 | ctx = list_first_entry_or_null(&rot->sbuf_ctx[q_id], |
| 2482 | struct sde_hw_rotator_context, list); |
| 2483 | if (ctx) { |
| 2484 | ts = ctx->timestamp; |
| 2485 | sde_hw_rotator_update_swts(rot, ctx, ts); |
| 2486 | SDEROT_DBG("update swts:0x%X\n", ts); |
| 2487 | } else { |
| 2488 | SDEROT_ERR("invalid swts ctx\n"); |
| 2489 | } |
| 2490 | } |
| 2491 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2492 | ctx = rot->rotCtx[q_id][ts & SDE_HW_ROT_REGDMA_SEG_MASK]; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2493 | |
| 2494 | /* |
| 2495 | * Wake up all waiting context from the current and previous |
| 2496 | * SW Timestamp. |
| 2497 | */ |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 2498 | while (ctx && |
| 2499 | sde_hw_rotator_elapsed_swts(ctx->timestamp, ts) >= 0) { |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2500 | ctx->last_regdma_isr_status = isr; |
| 2501 | ctx->last_regdma_timestamp = ts; |
| 2502 | SDEROT_DBG( |
Alan Kwong | f987ea3 | 2016-07-06 12:11:44 -0400 | [diff] [blame] | 2503 | "regdma complete: ctx:%p, ts:%X\n", ctx, ts); |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 2504 | wake_up_all(&ctx->regdma_waitq); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2505 | |
| 2506 | ts = (ts - 1) & SDE_REGDMA_SWTS_MASK; |
| 2507 | ctx = rot->rotCtx[q_id] |
| 2508 | [ts & SDE_HW_ROT_REGDMA_SEG_MASK]; |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 2509 | }; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2510 | |
Benjamin Chan | 62b94ed | 2016-08-18 23:55:21 -0400 | [diff] [blame] | 2511 | done_isr_handle: |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2512 | spin_unlock(&rot->rotisr_lock); |
| 2513 | ret = IRQ_HANDLED; |
| 2514 | } else if (isr & REGDMA_INT_ERR_MASK) { |
| 2515 | /* |
| 2516 | * For REGDMA Err, we save the isr info and wake up |
| 2517 | * all waiting contexts |
| 2518 | */ |
| 2519 | int i, j; |
| 2520 | |
| 2521 | SDEROT_ERR( |
| 2522 | "regdma err isr:%X, wake up all waiting contexts\n", |
| 2523 | isr); |
| 2524 | |
| 2525 | spin_lock(&rot->rotisr_lock); |
| 2526 | |
| 2527 | for (i = 0; i < ROT_QUEUE_MAX; i++) { |
| 2528 | for (j = 0; j < SDE_HW_ROT_REGDMA_TOTAL_CTX; j++) { |
| 2529 | ctx = rot->rotCtx[i][j]; |
| 2530 | if (ctx && ctx->last_regdma_isr_status == 0) { |
| 2531 | ctx->last_regdma_isr_status = isr; |
| 2532 | ctx->last_regdma_timestamp = ts; |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 2533 | wake_up_all(&ctx->regdma_waitq); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2534 | SDEROT_DBG("Wakeup rotctx[%d][%d]:%p\n", |
| 2535 | i, j, ctx); |
| 2536 | } |
| 2537 | } |
| 2538 | } |
| 2539 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2540 | spin_unlock(&rot->rotisr_lock); |
| 2541 | ret = IRQ_HANDLED; |
| 2542 | } |
| 2543 | |
| 2544 | return ret; |
| 2545 | } |
| 2546 | |
| 2547 | /* |
| 2548 | * sde_hw_rotator_validate_entry - validate rotation entry |
| 2549 | * @mgr: Pointer to rotator manager |
| 2550 | * @entry: Pointer to rotation entry |
| 2551 | * |
| 2552 | * This function validates the given rotation entry and provides possible |
| 2553 | * fixup (future improvement) if available. This function returns 0 if |
| 2554 | * the entry is valid, and returns error code otherwise. |
| 2555 | */ |
| 2556 | static int sde_hw_rotator_validate_entry(struct sde_rot_mgr *mgr, |
| 2557 | struct sde_rot_entry *entry) |
| 2558 | { |
Benjamin Chan | fb6faa3 | 2016-08-16 17:21:01 -0400 | [diff] [blame] | 2559 | struct sde_rot_data_type *mdata = sde_rot_get_mdata(); |
Alan Kwong | b6c049c | 2017-03-31 12:50:27 -0700 | [diff] [blame] | 2560 | struct sde_hw_rotator *hw_data; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2561 | int ret = 0; |
| 2562 | u16 src_w, src_h, dst_w, dst_h; |
| 2563 | struct sde_rotation_item *item = &entry->item; |
| 2564 | struct sde_mdp_format_params *fmt; |
| 2565 | |
Alan Kwong | b6c049c | 2017-03-31 12:50:27 -0700 | [diff] [blame] | 2566 | if (!mgr || !entry || !mgr->hw_data) { |
| 2567 | SDEROT_ERR("invalid parameters\n"); |
| 2568 | return -EINVAL; |
| 2569 | } |
| 2570 | |
| 2571 | hw_data = mgr->hw_data; |
| 2572 | |
| 2573 | if (hw_data->maxlinewidth < item->src_rect.w) { |
| 2574 | SDEROT_ERR("invalid src width %u\n", item->src_rect.w); |
| 2575 | return -EINVAL; |
| 2576 | } |
| 2577 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2578 | src_w = item->src_rect.w; |
| 2579 | src_h = item->src_rect.h; |
| 2580 | |
| 2581 | if (item->flags & SDE_ROTATION_90) { |
| 2582 | dst_w = item->dst_rect.h; |
| 2583 | dst_h = item->dst_rect.w; |
| 2584 | } else { |
| 2585 | dst_w = item->dst_rect.w; |
| 2586 | dst_h = item->dst_rect.h; |
| 2587 | } |
| 2588 | |
| 2589 | entry->dnsc_factor_w = 0; |
| 2590 | entry->dnsc_factor_h = 0; |
| 2591 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 2592 | if (item->output.sbuf && |
| 2593 | !test_bit(SDE_CAPS_SBUF_1, mdata->sde_caps_map)) { |
| 2594 | SDEROT_ERR("stream buffer not supported\n"); |
| 2595 | return -EINVAL; |
| 2596 | } |
| 2597 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2598 | if ((src_w != dst_w) || (src_h != dst_h)) { |
Clarence Ip | 4db1ea8 | 2017-05-01 12:18:55 -0700 | [diff] [blame] | 2599 | if (!dst_w || !dst_h) { |
| 2600 | SDEROT_DBG("zero output width/height not support\n"); |
| 2601 | ret = -EINVAL; |
| 2602 | goto dnsc_err; |
| 2603 | } |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2604 | if ((src_w % dst_w) || (src_h % dst_h)) { |
| 2605 | SDEROT_DBG("non integral scale not support\n"); |
| 2606 | ret = -EINVAL; |
Benjamin Chan | fb6faa3 | 2016-08-16 17:21:01 -0400 | [diff] [blame] | 2607 | goto dnsc_1p5_check; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2608 | } |
| 2609 | entry->dnsc_factor_w = src_w / dst_w; |
| 2610 | if ((entry->dnsc_factor_w & (entry->dnsc_factor_w - 1)) || |
| 2611 | (entry->dnsc_factor_w > 64)) { |
| 2612 | SDEROT_DBG("non power-of-2 w_scale not support\n"); |
| 2613 | ret = -EINVAL; |
| 2614 | goto dnsc_err; |
| 2615 | } |
| 2616 | entry->dnsc_factor_h = src_h / dst_h; |
| 2617 | if ((entry->dnsc_factor_h & (entry->dnsc_factor_h - 1)) || |
| 2618 | (entry->dnsc_factor_h > 64)) { |
| 2619 | SDEROT_DBG("non power-of-2 h_scale not support\n"); |
| 2620 | ret = -EINVAL; |
| 2621 | goto dnsc_err; |
| 2622 | } |
| 2623 | } |
| 2624 | |
Benjamin Chan | 0e96afd | 2017-01-17 16:49:12 -0500 | [diff] [blame] | 2625 | fmt = sde_get_format_params(item->output.format); |
Benjamin Chan | 886ff67 | 2016-11-07 15:23:17 -0500 | [diff] [blame] | 2626 | /* |
| 2627 | * Rotator downscale support max 4 times for UBWC format and |
| 2628 | * max 2 times for TP10/TP10_UBWC format |
| 2629 | */ |
| 2630 | if (sde_mdp_is_ubwc_format(fmt) && (entry->dnsc_factor_h > 4)) { |
| 2631 | SDEROT_DBG("max downscale for UBWC format is 4\n"); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2632 | ret = -EINVAL; |
| 2633 | goto dnsc_err; |
| 2634 | } |
Benjamin Chan | 886ff67 | 2016-11-07 15:23:17 -0500 | [diff] [blame] | 2635 | if (sde_mdp_is_tp10_format(fmt) && (entry->dnsc_factor_h > 2)) { |
| 2636 | SDEROT_DBG("downscale with TP10 cannot be more than 2\n"); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2637 | ret = -EINVAL; |
| 2638 | } |
Benjamin Chan | fb6faa3 | 2016-08-16 17:21:01 -0400 | [diff] [blame] | 2639 | goto dnsc_err; |
| 2640 | |
| 2641 | dnsc_1p5_check: |
| 2642 | /* Check for 1.5 downscale that only applies to V2 HW */ |
| 2643 | if (test_bit(SDE_CAPS_R3_1P5_DOWNSCALE, mdata->sde_caps_map)) { |
| 2644 | entry->dnsc_factor_w = src_w / dst_w; |
| 2645 | if ((entry->dnsc_factor_w != 1) || |
| 2646 | ((dst_w * 3) != (src_w * 2))) { |
| 2647 | SDEROT_DBG( |
| 2648 | "No supporting non 1.5 downscale width ratio, src_w:%d, dst_w:%d\n", |
| 2649 | src_w, dst_w); |
| 2650 | ret = -EINVAL; |
| 2651 | goto dnsc_err; |
| 2652 | } |
| 2653 | |
| 2654 | entry->dnsc_factor_h = src_h / dst_h; |
| 2655 | if ((entry->dnsc_factor_h != 1) || |
| 2656 | ((dst_h * 3) != (src_h * 2))) { |
| 2657 | SDEROT_DBG( |
| 2658 | "Not supporting non 1.5 downscale height ratio, src_h:%d, dst_h:%d\n", |
| 2659 | src_h, dst_h); |
| 2660 | ret = -EINVAL; |
| 2661 | goto dnsc_err; |
| 2662 | } |
| 2663 | ret = 0; |
| 2664 | } |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2665 | |
| 2666 | dnsc_err: |
| 2667 | /* Downscaler does not support asymmetrical dnsc */ |
| 2668 | if (entry->dnsc_factor_w != entry->dnsc_factor_h) { |
| 2669 | SDEROT_DBG("asymmetric downscale not support\n"); |
| 2670 | ret = -EINVAL; |
| 2671 | } |
| 2672 | |
| 2673 | if (ret) { |
| 2674 | entry->dnsc_factor_w = 0; |
| 2675 | entry->dnsc_factor_h = 0; |
| 2676 | } |
| 2677 | return ret; |
| 2678 | } |
| 2679 | |
| 2680 | /* |
| 2681 | * sde_hw_rotator_show_caps - output capability info to sysfs 'caps' file |
| 2682 | * @mgr: Pointer to rotator manager |
| 2683 | * @attr: Pointer to device attribute interface |
| 2684 | * @buf: Pointer to output buffer |
| 2685 | * @len: Length of output buffer |
| 2686 | */ |
| 2687 | static ssize_t sde_hw_rotator_show_caps(struct sde_rot_mgr *mgr, |
| 2688 | struct device_attribute *attr, char *buf, ssize_t len) |
| 2689 | { |
| 2690 | struct sde_hw_rotator *hw_data; |
Benjamin Chan | 886ff67 | 2016-11-07 15:23:17 -0500 | [diff] [blame] | 2691 | struct sde_rot_data_type *mdata = sde_rot_get_mdata(); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2692 | int cnt = 0; |
| 2693 | |
| 2694 | if (!mgr || !buf) |
| 2695 | return 0; |
| 2696 | |
| 2697 | hw_data = mgr->hw_data; |
| 2698 | |
| 2699 | #define SPRINT(fmt, ...) \ |
| 2700 | (cnt += scnprintf(buf + cnt, len - cnt, fmt, ##__VA_ARGS__)) |
| 2701 | |
| 2702 | /* insert capabilities here */ |
Benjamin Chan | 886ff67 | 2016-11-07 15:23:17 -0500 | [diff] [blame] | 2703 | if (test_bit(SDE_CAPS_R3_1P5_DOWNSCALE, mdata->sde_caps_map)) |
| 2704 | SPRINT("min_downscale=1.5\n"); |
| 2705 | else |
| 2706 | SPRINT("min_downscale=2.0\n"); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2707 | |
Benjamin Chan | 42db2c9 | 2016-11-22 22:50:01 -0500 | [diff] [blame] | 2708 | SPRINT("downscale_compression=1\n"); |
| 2709 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 2710 | if (hw_data->downscale_caps) |
| 2711 | SPRINT("downscale_ratios=%s\n", hw_data->downscale_caps); |
| 2712 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2713 | #undef SPRINT |
| 2714 | return cnt; |
| 2715 | } |
| 2716 | |
| 2717 | /* |
| 2718 | * sde_hw_rotator_show_state - output state info to sysfs 'state' file |
| 2719 | * @mgr: Pointer to rotator manager |
| 2720 | * @attr: Pointer to device attribute interface |
| 2721 | * @buf: Pointer to output buffer |
| 2722 | * @len: Length of output buffer |
| 2723 | */ |
| 2724 | static ssize_t sde_hw_rotator_show_state(struct sde_rot_mgr *mgr, |
| 2725 | struct device_attribute *attr, char *buf, ssize_t len) |
| 2726 | { |
| 2727 | struct sde_hw_rotator *rot; |
| 2728 | struct sde_hw_rotator_context *ctx; |
| 2729 | int cnt = 0; |
| 2730 | int num_active = 0; |
| 2731 | int i, j; |
| 2732 | |
| 2733 | if (!mgr || !buf) { |
| 2734 | SDEROT_ERR("null parameters\n"); |
| 2735 | return 0; |
| 2736 | } |
| 2737 | |
| 2738 | rot = mgr->hw_data; |
| 2739 | |
| 2740 | #define SPRINT(fmt, ...) \ |
| 2741 | (cnt += scnprintf(buf + cnt, len - cnt, fmt, ##__VA_ARGS__)) |
| 2742 | |
| 2743 | if (rot) { |
| 2744 | SPRINT("rot_mode=%d\n", rot->mode); |
| 2745 | SPRINT("irq_num=%d\n", rot->irq_num); |
| 2746 | |
| 2747 | if (rot->mode == ROT_REGDMA_OFF) { |
| 2748 | SPRINT("max_active=1\n"); |
| 2749 | SPRINT("num_active=%d\n", rot->rotCtx[0][0] ? 1 : 0); |
| 2750 | } else { |
| 2751 | for (i = 0; i < ROT_QUEUE_MAX; i++) { |
| 2752 | for (j = 0; j < SDE_HW_ROT_REGDMA_TOTAL_CTX; |
| 2753 | j++) { |
| 2754 | ctx = rot->rotCtx[i][j]; |
| 2755 | |
| 2756 | if (ctx) { |
| 2757 | SPRINT( |
| 2758 | "rotCtx[%d][%d]:%p\n", |
| 2759 | i, j, ctx); |
| 2760 | ++num_active; |
| 2761 | } |
| 2762 | } |
| 2763 | } |
| 2764 | |
| 2765 | SPRINT("max_active=%d\n", SDE_HW_ROT_REGDMA_TOTAL_CTX); |
| 2766 | SPRINT("num_active=%d\n", num_active); |
| 2767 | } |
| 2768 | } |
| 2769 | |
| 2770 | #undef SPRINT |
| 2771 | return cnt; |
| 2772 | } |
| 2773 | |
| 2774 | /* |
Alan Kwong | da16e44 | 2016-08-14 20:47:18 -0400 | [diff] [blame] | 2775 | * sde_hw_rotator_get_pixfmt - get the indexed pixel format |
| 2776 | * @mgr: Pointer to rotator manager |
| 2777 | * @index: index of pixel format |
| 2778 | * @input: true for input port; false for output port |
| 2779 | */ |
| 2780 | static u32 sde_hw_rotator_get_pixfmt(struct sde_rot_mgr *mgr, |
| 2781 | int index, bool input) |
| 2782 | { |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 2783 | struct sde_hw_rotator *rot; |
| 2784 | |
| 2785 | if (!mgr || !mgr->hw_data) { |
| 2786 | SDEROT_ERR("null parameters\n"); |
| 2787 | return 0; |
| 2788 | } |
| 2789 | |
| 2790 | rot = mgr->hw_data; |
| 2791 | |
Alan Kwong | da16e44 | 2016-08-14 20:47:18 -0400 | [diff] [blame] | 2792 | if (input) { |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 2793 | if ((index < rot->num_inpixfmt) && rot->inpixfmts) |
| 2794 | return rot->inpixfmts[index]; |
Alan Kwong | da16e44 | 2016-08-14 20:47:18 -0400 | [diff] [blame] | 2795 | else |
| 2796 | return 0; |
| 2797 | } else { |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 2798 | if ((index < rot->num_outpixfmt) && rot->outpixfmts) |
| 2799 | return rot->outpixfmts[index]; |
Alan Kwong | da16e44 | 2016-08-14 20:47:18 -0400 | [diff] [blame] | 2800 | else |
| 2801 | return 0; |
| 2802 | } |
| 2803 | } |
| 2804 | |
| 2805 | /* |
| 2806 | * sde_hw_rotator_is_valid_pixfmt - verify if the given pixel format is valid |
| 2807 | * @mgr: Pointer to rotator manager |
| 2808 | * @pixfmt: pixel format to be verified |
| 2809 | * @input: true for input port; false for output port |
| 2810 | */ |
| 2811 | static int sde_hw_rotator_is_valid_pixfmt(struct sde_rot_mgr *mgr, u32 pixfmt, |
| 2812 | bool input) |
| 2813 | { |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 2814 | struct sde_hw_rotator *rot; |
| 2815 | u32 *pixfmts; |
| 2816 | u32 num_pixfmt; |
Alan Kwong | da16e44 | 2016-08-14 20:47:18 -0400 | [diff] [blame] | 2817 | int i; |
| 2818 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 2819 | if (!mgr || !mgr->hw_data) { |
| 2820 | SDEROT_ERR("null parameters\n"); |
| 2821 | return false; |
Alan Kwong | da16e44 | 2016-08-14 20:47:18 -0400 | [diff] [blame] | 2822 | } |
| 2823 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 2824 | rot = mgr->hw_data; |
| 2825 | |
| 2826 | if (input) { |
| 2827 | pixfmts = rot->inpixfmts; |
| 2828 | num_pixfmt = rot->num_inpixfmt; |
| 2829 | } else { |
| 2830 | pixfmts = rot->outpixfmts; |
| 2831 | num_pixfmt = rot->num_outpixfmt; |
| 2832 | } |
| 2833 | |
| 2834 | if (!pixfmts || !num_pixfmt) { |
| 2835 | SDEROT_ERR("invalid pixel format tables\n"); |
| 2836 | return false; |
| 2837 | } |
| 2838 | |
| 2839 | for (i = 0; i < num_pixfmt; i++) |
| 2840 | if (pixfmts[i] == pixfmt) |
| 2841 | return true; |
| 2842 | |
Alan Kwong | da16e44 | 2016-08-14 20:47:18 -0400 | [diff] [blame] | 2843 | return false; |
| 2844 | } |
| 2845 | |
| 2846 | /* |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 2847 | * sde_hw_rotator_get_downscale_caps - get scaling capability string |
| 2848 | * @mgr: Pointer to rotator manager |
| 2849 | * @caps: Pointer to capability string buffer; NULL to return maximum length |
| 2850 | * @len: length of capability string buffer |
| 2851 | * return: length of capability string |
| 2852 | */ |
| 2853 | static int sde_hw_rotator_get_downscale_caps(struct sde_rot_mgr *mgr, |
| 2854 | char *caps, int len) |
| 2855 | { |
| 2856 | struct sde_hw_rotator *rot; |
| 2857 | int rc = 0; |
| 2858 | |
| 2859 | if (!mgr || !mgr->hw_data) { |
| 2860 | SDEROT_ERR("null parameters\n"); |
| 2861 | return -EINVAL; |
| 2862 | } |
| 2863 | |
| 2864 | rot = mgr->hw_data; |
| 2865 | |
| 2866 | if (rot->downscale_caps) { |
| 2867 | if (caps) |
| 2868 | rc = snprintf(caps, len, "%s", rot->downscale_caps); |
| 2869 | else |
| 2870 | rc = strlen(rot->downscale_caps); |
| 2871 | } |
| 2872 | |
| 2873 | return rc; |
| 2874 | } |
| 2875 | |
| 2876 | /* |
Alan Kwong | b6c049c | 2017-03-31 12:50:27 -0700 | [diff] [blame] | 2877 | * sde_hw_rotator_get_maxlinewidth - get maximum line width supported |
| 2878 | * @mgr: Pointer to rotator manager |
| 2879 | * return: maximum line width supported by hardware |
| 2880 | */ |
| 2881 | static int sde_hw_rotator_get_maxlinewidth(struct sde_rot_mgr *mgr) |
| 2882 | { |
| 2883 | struct sde_hw_rotator *rot; |
| 2884 | |
| 2885 | if (!mgr || !mgr->hw_data) { |
| 2886 | SDEROT_ERR("null parameters\n"); |
| 2887 | return -EINVAL; |
| 2888 | } |
| 2889 | |
| 2890 | rot = mgr->hw_data; |
| 2891 | |
| 2892 | return rot->maxlinewidth; |
| 2893 | } |
| 2894 | |
| 2895 | /* |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2896 | * sde_hw_rotator_parse_dt - parse r3 specific device tree settings |
| 2897 | * @hw_data: Pointer to rotator hw |
| 2898 | * @dev: Pointer to platform device |
| 2899 | */ |
| 2900 | static int sde_hw_rotator_parse_dt(struct sde_hw_rotator *hw_data, |
| 2901 | struct platform_device *dev) |
| 2902 | { |
| 2903 | int ret = 0; |
| 2904 | u32 data; |
| 2905 | |
| 2906 | if (!hw_data || !dev) |
| 2907 | return -EINVAL; |
| 2908 | |
| 2909 | ret = of_property_read_u32(dev->dev.of_node, "qcom,mdss-rot-mode", |
| 2910 | &data); |
| 2911 | if (ret) { |
| 2912 | SDEROT_DBG("default to regdma off\n"); |
| 2913 | ret = 0; |
| 2914 | hw_data->mode = ROT_REGDMA_OFF; |
| 2915 | } else if (data < ROT_REGDMA_MAX) { |
| 2916 | SDEROT_DBG("set to regdma mode %d\n", data); |
| 2917 | hw_data->mode = data; |
| 2918 | } else { |
| 2919 | SDEROT_ERR("regdma mode out of range. default to regdma off\n"); |
| 2920 | hw_data->mode = ROT_REGDMA_OFF; |
| 2921 | } |
| 2922 | |
| 2923 | ret = of_property_read_u32(dev->dev.of_node, |
| 2924 | "qcom,mdss-highest-bank-bit", &data); |
| 2925 | if (ret) { |
| 2926 | SDEROT_DBG("default to A5X bank\n"); |
| 2927 | ret = 0; |
| 2928 | hw_data->highest_bank = 2; |
| 2929 | } else { |
| 2930 | SDEROT_DBG("set highest bank bit to %d\n", data); |
| 2931 | hw_data->highest_bank = data; |
| 2932 | } |
| 2933 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 2934 | ret = of_property_read_u32(dev->dev.of_node, |
Alan Kwong | fb8eeb2 | 2017-02-06 15:00:03 -0800 | [diff] [blame] | 2935 | "qcom,sde-ubwc-malsize", &data); |
| 2936 | if (ret) { |
| 2937 | ret = 0; |
| 2938 | hw_data->ubwc_malsize = DEFAULT_UBWC_MALSIZE; |
| 2939 | } else { |
| 2940 | SDEROT_DBG("set ubwc malsize to %d\n", data); |
| 2941 | hw_data->ubwc_malsize = data; |
| 2942 | } |
| 2943 | |
| 2944 | ret = of_property_read_u32(dev->dev.of_node, |
| 2945 | "qcom,sde-ubwc_swizzle", &data); |
| 2946 | if (ret) { |
| 2947 | ret = 0; |
| 2948 | hw_data->ubwc_swizzle = DEFAULT_UBWC_SWIZZLE; |
| 2949 | } else { |
| 2950 | SDEROT_DBG("set ubwc swizzle to %d\n", data); |
| 2951 | hw_data->ubwc_swizzle = data; |
| 2952 | } |
| 2953 | |
| 2954 | ret = of_property_read_u32(dev->dev.of_node, |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 2955 | "qcom,mdss-sbuf-headroom", &data); |
| 2956 | if (ret) { |
| 2957 | ret = 0; |
| 2958 | hw_data->sbuf_headroom = DEFAULT_SBUF_HEADROOM; |
| 2959 | } else { |
| 2960 | SDEROT_DBG("set sbuf headroom to %d\n", data); |
| 2961 | hw_data->sbuf_headroom = data; |
| 2962 | } |
| 2963 | |
Alan Kwong | b6c049c | 2017-03-31 12:50:27 -0700 | [diff] [blame] | 2964 | ret = of_property_read_u32(dev->dev.of_node, |
| 2965 | "qcom,mdss-rot-linewidth", &data); |
| 2966 | if (ret) { |
| 2967 | ret = 0; |
| 2968 | hw_data->maxlinewidth = DEFAULT_MAXLINEWIDTH; |
| 2969 | } else { |
| 2970 | SDEROT_DBG("set mdss-rot-linewidth to %d\n", data); |
| 2971 | hw_data->maxlinewidth = data; |
| 2972 | } |
| 2973 | |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 2974 | return ret; |
| 2975 | } |
| 2976 | |
| 2977 | /* |
| 2978 | * sde_rotator_r3_init - initialize the r3 module |
| 2979 | * @mgr: Pointer to rotator manager |
| 2980 | * |
| 2981 | * This function setup r3 callback functions, parses r3 specific |
| 2982 | * device tree settings, installs r3 specific interrupt handler, |
| 2983 | * as well as initializes r3 internal data structure. |
| 2984 | */ |
| 2985 | int sde_rotator_r3_init(struct sde_rot_mgr *mgr) |
| 2986 | { |
| 2987 | struct sde_hw_rotator *rot; |
| 2988 | struct sde_rot_data_type *mdata = sde_rot_get_mdata(); |
| 2989 | int i; |
| 2990 | int ret; |
| 2991 | |
| 2992 | rot = devm_kzalloc(&mgr->pdev->dev, sizeof(*rot), GFP_KERNEL); |
| 2993 | if (!rot) |
| 2994 | return -ENOMEM; |
| 2995 | |
| 2996 | mgr->hw_data = rot; |
| 2997 | mgr->queue_count = ROT_QUEUE_MAX; |
| 2998 | |
| 2999 | rot->mdss_base = mdata->sde_io.base; |
| 3000 | rot->pdev = mgr->pdev; |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 3001 | rot->koff_timeout = KOFF_TIMEOUT; |
| 3002 | rot->vid_trigger = ROTTOP_START_CTRL_TRIG_SEL_MDP; |
| 3003 | rot->cmd_trigger = ROTTOP_START_CTRL_TRIG_SEL_MDP; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 3004 | |
| 3005 | /* Assign ops */ |
| 3006 | mgr->ops_hw_destroy = sde_hw_rotator_destroy; |
| 3007 | mgr->ops_hw_alloc = sde_hw_rotator_alloc_ext; |
| 3008 | mgr->ops_hw_free = sde_hw_rotator_free_ext; |
| 3009 | mgr->ops_config_hw = sde_hw_rotator_config; |
| 3010 | mgr->ops_kickoff_entry = sde_hw_rotator_kickoff; |
| 3011 | mgr->ops_wait_for_entry = sde_hw_rotator_wait4done; |
| 3012 | mgr->ops_hw_validate_entry = sde_hw_rotator_validate_entry; |
| 3013 | mgr->ops_hw_show_caps = sde_hw_rotator_show_caps; |
| 3014 | mgr->ops_hw_show_state = sde_hw_rotator_show_state; |
| 3015 | mgr->ops_hw_create_debugfs = sde_rotator_r3_create_debugfs; |
Alan Kwong | da16e44 | 2016-08-14 20:47:18 -0400 | [diff] [blame] | 3016 | mgr->ops_hw_get_pixfmt = sde_hw_rotator_get_pixfmt; |
| 3017 | mgr->ops_hw_is_valid_pixfmt = sde_hw_rotator_is_valid_pixfmt; |
Benjamin Chan | 0f9e61d | 2016-09-16 16:01:09 -0400 | [diff] [blame] | 3018 | mgr->ops_hw_pre_pmevent = sde_hw_rotator_pre_pmevent; |
| 3019 | mgr->ops_hw_post_pmevent = sde_hw_rotator_post_pmevent; |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 3020 | mgr->ops_hw_get_downscale_caps = sde_hw_rotator_get_downscale_caps; |
Alan Kwong | b6c049c | 2017-03-31 12:50:27 -0700 | [diff] [blame] | 3021 | mgr->ops_hw_get_maxlinewidth = sde_hw_rotator_get_maxlinewidth; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 3022 | |
| 3023 | ret = sde_hw_rotator_parse_dt(mgr->hw_data, mgr->pdev); |
| 3024 | if (ret) |
| 3025 | goto error_parse_dt; |
| 3026 | |
| 3027 | rot->irq_num = platform_get_irq(mgr->pdev, 0); |
| 3028 | if (rot->irq_num < 0) { |
| 3029 | SDEROT_ERR("fail to get rotator irq\n"); |
| 3030 | } else { |
| 3031 | if (rot->mode == ROT_REGDMA_OFF) |
| 3032 | ret = devm_request_threaded_irq(&mgr->pdev->dev, |
| 3033 | rot->irq_num, |
| 3034 | sde_hw_rotator_rotirq_handler, |
| 3035 | NULL, 0, "sde_rotator_r3", rot); |
| 3036 | else |
| 3037 | ret = devm_request_threaded_irq(&mgr->pdev->dev, |
| 3038 | rot->irq_num, |
| 3039 | sde_hw_rotator_regdmairq_handler, |
| 3040 | NULL, 0, "sde_rotator_r3", rot); |
| 3041 | if (ret) { |
| 3042 | SDEROT_ERR("fail to request irq r:%d\n", ret); |
| 3043 | rot->irq_num = -1; |
| 3044 | } else { |
| 3045 | disable_irq(rot->irq_num); |
| 3046 | } |
| 3047 | } |
Alan Kwong | 818b7fc | 2016-07-24 22:07:41 -0400 | [diff] [blame] | 3048 | atomic_set(&rot->irq_enabled, 0); |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 3049 | |
| 3050 | setup_rotator_ops(&rot->ops, rot->mode); |
| 3051 | |
| 3052 | spin_lock_init(&rot->rotctx_lock); |
| 3053 | spin_lock_init(&rot->rotisr_lock); |
| 3054 | |
| 3055 | /* REGDMA initialization */ |
| 3056 | if (rot->mode == ROT_REGDMA_OFF) { |
| 3057 | for (i = 0; i < SDE_HW_ROT_REGDMA_TOTAL_CTX; i++) |
| 3058 | rot->cmd_wr_ptr[0][i] = &rot->cmd_queue[ |
| 3059 | SDE_HW_ROT_REGDMA_SEG_SIZE * i]; |
| 3060 | } else { |
| 3061 | for (i = 0; i < SDE_HW_ROT_REGDMA_TOTAL_CTX; i++) |
| 3062 | rot->cmd_wr_ptr[ROT_QUEUE_HIGH_PRIORITY][i] = |
| 3063 | (u32 *)(rot->mdss_base + |
| 3064 | REGDMA_RAM_REGDMA_CMD_RAM + |
| 3065 | SDE_HW_ROT_REGDMA_SEG_SIZE * 4 * i); |
| 3066 | |
| 3067 | for (i = 0; i < SDE_HW_ROT_REGDMA_TOTAL_CTX; i++) |
| 3068 | rot->cmd_wr_ptr[ROT_QUEUE_LOW_PRIORITY][i] = |
| 3069 | (u32 *)(rot->mdss_base + |
| 3070 | REGDMA_RAM_REGDMA_CMD_RAM + |
| 3071 | SDE_HW_ROT_REGDMA_SEG_SIZE * 4 * |
| 3072 | (i + SDE_HW_ROT_REGDMA_TOTAL_CTX)); |
| 3073 | } |
| 3074 | |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 3075 | for (i = 0; i < ROT_QUEUE_MAX; i++) { |
| 3076 | atomic_set(&rot->timestamp[i], 0); |
| 3077 | INIT_LIST_HEAD(&rot->sbuf_ctx[i]); |
| 3078 | } |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 3079 | |
| 3080 | ret = sde_rotator_hw_rev_init(rot); |
| 3081 | if (ret) |
| 3082 | goto error_hw_rev_init; |
| 3083 | |
Alan Kwong | 315cd77 | 2016-08-03 22:29:42 -0400 | [diff] [blame] | 3084 | /* set rotator CBCR to shutoff memory/periphery on clock off.*/ |
Clarence Ip | 77c053d | 2017-04-24 19:26:37 -0700 | [diff] [blame] | 3085 | clk_set_flags(mgr->rot_clk[SDE_ROTATOR_CLK_MDSS_ROT].clk, |
Alan Kwong | 315cd77 | 2016-08-03 22:29:42 -0400 | [diff] [blame] | 3086 | CLKFLAG_NORETAIN_MEM); |
Clarence Ip | 77c053d | 2017-04-24 19:26:37 -0700 | [diff] [blame] | 3087 | clk_set_flags(mgr->rot_clk[SDE_ROTATOR_CLK_MDSS_ROT].clk, |
Alan Kwong | 315cd77 | 2016-08-03 22:29:42 -0400 | [diff] [blame] | 3088 | CLKFLAG_NORETAIN_PERIPH); |
| 3089 | |
Benjamin Chan | 53e3bce | 2016-08-31 14:43:29 -0400 | [diff] [blame] | 3090 | mdata->sde_rot_hw = rot; |
Alan Kwong | 9487de2 | 2016-01-16 22:06:36 -0500 | [diff] [blame] | 3091 | return 0; |
| 3092 | error_hw_rev_init: |
| 3093 | if (rot->irq_num >= 0) |
| 3094 | devm_free_irq(&mgr->pdev->dev, rot->irq_num, mdata); |
| 3095 | devm_kfree(&mgr->pdev->dev, mgr->hw_data); |
| 3096 | error_parse_dt: |
| 3097 | return ret; |
| 3098 | } |