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