sde_rotator_r3_internal.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _SDE_ROTATOR_R3_INTERNAL_H
  6. #define _SDE_ROTATOR_R3_INTERNAL_H
  7. #include "sde_rotator_core.h"
  8. struct sde_hw_rotator;
  9. struct sde_hw_rotator_context;
  10. /**
  11. * Flags
  12. */
  13. #define SDE_ROT_FLAG_SECURE_OVERLAY_SESSION 0x1
  14. #define SDE_ROT_FLAG_FLIP_LR 0x2
  15. #define SDE_ROT_FLAG_FLIP_UD 0x4
  16. #define SDE_ROT_FLAG_SOURCE_ROTATED_90 0x8
  17. #define SDE_ROT_FLAG_ROT_90 0x10
  18. #define SDE_ROT_FLAG_DEINTERLACE 0x20
  19. #define SDE_ROT_FLAG_SECURE_CAMERA_SESSION 0x40
  20. /**
  21. * General defines
  22. */
  23. #define SDE_HW_ROT_REGDMA_RAM_SIZE 1024
  24. #define SDE_HW_ROT_REGDMA_TOTAL_CTX 8
  25. #define SDE_HW_ROT_REGDMA_SEG_MASK (SDE_HW_ROT_REGDMA_TOTAL_CTX - 1)
  26. #define SDE_HW_ROT_REGDMA_SEG_SIZE \
  27. (SDE_HW_ROT_REGDMA_RAM_SIZE / SDE_HW_ROT_REGDMA_TOTAL_CTX)
  28. #define SDE_REGDMA_SWTS_MASK 0x00000FFF
  29. #define SDE_REGDMA_SWTS_SHIFT 12
  30. enum sde_rot_queue_prio {
  31. ROT_QUEUE_HIGH_PRIORITY,
  32. ROT_QUEUE_LOW_PRIORITY,
  33. ROT_QUEUE_MAX
  34. };
  35. enum sde_rot_angle {
  36. ROT_ANGLE_0,
  37. ROT_ANGLE_90,
  38. ROT_ANGEL_MAX
  39. };
  40. enum sde_rotator_regdma_mode {
  41. ROT_REGDMA_OFF,
  42. ROT_REGDMA_ON,
  43. ROT_REGDMA_MAX
  44. };
  45. /**
  46. * struct sde_hw_rot_sspp_cfg: Rotator SSPP Configration description
  47. * @src: source surface information
  48. * @src_rect: src ROI, caller takes into account the different operations
  49. * such as decimation, flip etc to program this field
  50. * @addr: source surface address
  51. */
  52. struct sde_hw_rot_sspp_cfg {
  53. struct sde_mdp_format_params *fmt;
  54. struct sde_mdp_plane_sizes src_plane;
  55. struct sde_rect *src_rect;
  56. struct sde_mdp_data *data;
  57. u32 img_width;
  58. u32 img_height;
  59. u32 fps;
  60. u64 bw;
  61. };
  62. /**
  63. * struct sde_hw_rot_wb_cfg: Rotator WB Configration description
  64. * @dest: destination surface information
  65. * @dest_rect: dest ROI, caller takes into account the different operations
  66. * such as decimation, flip etc to program this field
  67. * @addr: destination surface address
  68. * @prefill_bw: prefill bandwidth in Bps
  69. */
  70. struct sde_hw_rot_wb_cfg {
  71. struct sde_mdp_format_params *fmt;
  72. struct sde_mdp_plane_sizes dst_plane;
  73. struct sde_rect *dst_rect;
  74. struct sde_mdp_data *data;
  75. u32 img_width;
  76. u32 img_height;
  77. u32 v_downscale_factor;
  78. u32 h_downscale_factor;
  79. u32 fps;
  80. u64 bw;
  81. u64 prefill_bw;
  82. };
  83. /**
  84. *
  85. * struct sde_hw_rotator_ops: Interface to the Rotator Hw driver functions
  86. *
  87. * Pre-requsises:
  88. * - Caller must call the init function to get the rotator context
  89. * - These functions will be called after clocks are enabled
  90. */
  91. struct sde_hw_rotator_ops {
  92. /**
  93. * setup_rotator_fetchengine():
  94. * Setup Source format
  95. * Setup Source dimension/cropping rectangle (ROI)
  96. * Setup Source surface base address and stride
  97. * Setup fetch engine op mode (linear/tiled/compression/...)
  98. * @ctx: Rotator context created in sde_hw_rotator_config
  99. * @queue_id: Select either low / high priority queue
  100. * @cfg: Rotator Fetch engine configuration parameters
  101. * @danger_lut: Danger LUT setting
  102. * @safe_lut: Safe LUT setting
  103. * @dnsc_factor_w: Downscale factor for width
  104. * @dnsc_factor_h: Downscale factor for height
  105. * @flags: Specific config flag, see SDE_ROT_FLAG_ for details
  106. */
  107. void (*setup_rotator_fetchengine)(
  108. struct sde_hw_rotator_context *ctx,
  109. enum sde_rot_queue_prio queue_id,
  110. struct sde_hw_rot_sspp_cfg *cfg,
  111. u32 danger_lut,
  112. u32 safe_lut,
  113. u32 dnsc_factor_w,
  114. u32 dnsc_factor_h,
  115. u32 flags);
  116. /**
  117. * setup_rotator_wbengine():
  118. * Setup destination formats
  119. * Setup destination dimension/cropping rectangle (ROI)
  120. * Setup destination surface base address and strides
  121. * Setup writeback engine op mode (linear/tiled/compression)
  122. * @ctx: Rotator context created in sde_hw_rotator_config
  123. * @queue_id: Select either low / high priority queue
  124. * @cfg: Rotator WriteBack engine configuration parameters
  125. * @flags: Specific config flag, see SDE_ROT_FLAG_ for details
  126. */
  127. void (*setup_rotator_wbengine)(
  128. struct sde_hw_rotator_context *ctx,
  129. enum sde_rot_queue_prio queue_id,
  130. struct sde_hw_rot_wb_cfg *cfg,
  131. u32 flags);
  132. /**
  133. * start_rotator():
  134. * Kick start rotator operation based on cached setup parameters
  135. * REGDMA commands will get generated at this points
  136. * @ctx: Rotator context
  137. * @queue_id: Select either low / high priority queue
  138. * Returns: unique job timestamp per submit. Used for tracking
  139. * rotator finished job.
  140. */
  141. u32 (*start_rotator)(
  142. struct sde_hw_rotator_context *ctx,
  143. enum sde_rot_queue_prio queue_id);
  144. /**
  145. * wait_rotator_done():
  146. * Notify Rotator HAL layer previously submitted job finished.
  147. * A job timestamp will return to caller.
  148. * @ctx: Rotator context
  149. * @flags: Reserved
  150. * Returns: job timestamp for tracking purpose
  151. *
  152. */
  153. u32 (*wait_rotator_done)(
  154. struct sde_hw_rotator_context *ctx,
  155. enum sde_rot_queue_prio queue_id,
  156. u32 flags);
  157. /**
  158. * get_pending_ts():
  159. * Obtain current active timestamp from rotator hw
  160. * @rot: HW Rotator structure
  161. * @ctx: Rotator context
  162. * @ts: current timestamp return from rot hw
  163. * Returns: true if context has pending requests
  164. */
  165. int (*get_pending_ts)(
  166. struct sde_hw_rotator *rot,
  167. struct sde_hw_rotator_context *ctx,
  168. u32 *ts);
  169. /**
  170. * update_ts():
  171. * Update rotator timestmap with given value
  172. * @rot: HW Rotator structure
  173. * @q_id: rotator queue id
  174. * @ts: new timestamp for rotator
  175. */
  176. void (*update_ts)(
  177. struct sde_hw_rotator *rot,
  178. u32 q_id,
  179. u32 ts);
  180. };
  181. /**
  182. * struct sde_dbg_buf : Debug buffer used by debugfs
  183. * @vaddr: VA address mapped from dma buffer
  184. * @dmabuf: DMA buffer
  185. * @buflen: Length of DMA buffer
  186. * @width: pixel width of buffer
  187. * @height: pixel height of buffer
  188. */
  189. struct sde_dbg_buf {
  190. void *vaddr;
  191. struct dma_buf *dmabuf;
  192. unsigned long buflen;
  193. u32 width;
  194. u32 height;
  195. };
  196. /**
  197. * struct sde_hw_rotator_context : Each rotator context ties to each priority
  198. * queue. Max number of concurrent contexts in regdma is limited to regdma
  199. * ram segment size allocation. Each rotator context can be any priority. A
  200. * incremental timestamp is used to identify and assigned to each context.
  201. * @list: list of pending context
  202. * @sequence_id: unique sequence identifier for rotation request
  203. * @sbuf_mode: true if stream buffer is requested
  204. * @start_ctrl: start control register update value
  205. * @sys_cache_mode: sys cache mode register update value
  206. * @op_mode: rot top op mode selection
  207. * @last_entry: pointer to last configured entry (for debugging purposes)
  208. */
  209. struct sde_hw_rotator_context {
  210. struct list_head list;
  211. struct sde_hw_rotator *rot;
  212. struct sde_rot_hw_resource *hwres;
  213. enum sde_rot_queue_prio q_id;
  214. u32 session_id;
  215. u32 sequence_id;
  216. char __iomem *regdma_base;
  217. char __iomem *regdma_wrptr;
  218. u32 timestamp;
  219. struct completion rot_comp;
  220. wait_queue_head_t regdma_waitq;
  221. struct sde_dbg_buf src_dbgbuf;
  222. struct sde_dbg_buf dst_dbgbuf;
  223. u32 last_regdma_isr_status;
  224. u32 last_regdma_timestamp;
  225. dma_addr_t ts_addr;
  226. bool is_secure;
  227. bool is_traffic_shaping;
  228. bool sbuf_mode;
  229. bool abort;
  230. u32 start_ctrl;
  231. u32 sys_cache_mode;
  232. u32 op_mode;
  233. struct sde_rot_entry *last_entry;
  234. };
  235. /**
  236. * struct sde_hw_rotator_resource_info : Each rotator resource ties to each
  237. * priority queue
  238. */
  239. struct sde_hw_rotator_resource_info {
  240. struct sde_hw_rotator *rot;
  241. struct sde_rot_hw_resource hw;
  242. };
  243. /**
  244. * struct sde_hw_rotator : Rotator description
  245. * @hw: mdp register mapped offset
  246. * @ops: pointer to operations possible for the rotator HW
  247. * @highest_bank: highest bank size of memory
  248. * @ubwc_malsize: ubwc minimum allowable length
  249. * @ubwc_swizzle: ubwc swizzle enable
  250. * @sbuf_headroom: stream buffer headroom in lines
  251. * @solid_fill: true if solid fill is requested
  252. * @constant_color: solid fill constant color
  253. * @sbuf_ctx: list of active sbuf context in FIFO order
  254. * @vid_trigger: video mode trigger select
  255. * @cmd_trigger: command mode trigger select
  256. * @inpixfmts: array of supported input pixel formats fourcc per mode
  257. * @num_inpixfmt: size of the supported input pixel format array per mode
  258. * @outpixfmts: array of supported output pixel formats in fourcc per mode
  259. * @num_outpixfmt: size of the supported output pixel formats array per mode
  260. * @downscale_caps: capability string of scaling
  261. * @maxlinewidth: maximum line width supported
  262. */
  263. struct sde_hw_rotator {
  264. /* base */
  265. char __iomem *mdss_base;
  266. /* Platform device from upper manager */
  267. struct platform_device *pdev;
  268. /* Ops */
  269. struct sde_hw_rotator_ops ops;
  270. /* Cmd Queue */
  271. u32 cmd_queue[SDE_HW_ROT_REGDMA_RAM_SIZE];
  272. /* Cmd Queue Write Ptr */
  273. char __iomem *cmd_wr_ptr[ROT_QUEUE_MAX][SDE_HW_ROT_REGDMA_TOTAL_CTX];
  274. /* Rotator Context */
  275. struct sde_hw_rotator_context
  276. *rotCtx[ROT_QUEUE_MAX][SDE_HW_ROT_REGDMA_TOTAL_CTX];
  277. /* Cmd timestamp sequence for different priority*/
  278. atomic_t timestamp[ROT_QUEUE_MAX];
  279. /* regdma mode */
  280. enum sde_rotator_regdma_mode mode;
  281. /* logical interrupt number */
  282. int irq_num;
  283. atomic_t irq_enabled;
  284. /* internal ION memory for SW timestamp */
  285. struct ion_client *iclient;
  286. struct sde_mdp_img_data swts_buf;
  287. void *swts_buffer;
  288. u32 highest_bank;
  289. u32 ubwc_malsize;
  290. u32 ubwc_swizzle;
  291. u32 sbuf_headroom;
  292. u32 solid_fill;
  293. u32 constant_color;
  294. spinlock_t rotctx_lock;
  295. spinlock_t rotisr_lock;
  296. bool dbgmem;
  297. bool reset_hw_ts;
  298. u32 last_hwts[ROT_QUEUE_MAX];
  299. u32 koff_timeout;
  300. u32 vid_trigger;
  301. u32 cmd_trigger;
  302. struct list_head sbuf_ctx[ROT_QUEUE_MAX];
  303. const u32 *inpixfmts[SDE_ROTATOR_MODE_MAX];
  304. u32 num_inpixfmt[SDE_ROTATOR_MODE_MAX];
  305. const u32 *outpixfmts[SDE_ROTATOR_MODE_MAX];
  306. u32 num_outpixfmt[SDE_ROTATOR_MODE_MAX];
  307. const char *downscale_caps;
  308. u32 maxlinewidth;
  309. };
  310. /**
  311. * sde_hw_rotator_get_regdma_ctxidx(): regdma segment index is based on
  312. * timestamp. For non-regdma, just return 0 (i.e. first index)
  313. * @ctx: Rotator Context
  314. * return: regdma segment index
  315. */
  316. static inline u32 sde_hw_rotator_get_regdma_ctxidx(
  317. struct sde_hw_rotator_context *ctx)
  318. {
  319. if (ctx->rot->mode == ROT_REGDMA_OFF)
  320. return 0;
  321. else
  322. return ctx->timestamp & SDE_HW_ROT_REGDMA_SEG_MASK;
  323. }
  324. /**
  325. * sde_hw_rotator_get_regdma_segment_base: return the base pointe of current
  326. * regdma command buffer
  327. * @ctx: Rotator Context
  328. * return: base segment address
  329. */
  330. static inline char __iomem *sde_hw_rotator_get_regdma_segment_base(
  331. struct sde_hw_rotator_context *ctx)
  332. {
  333. SDEROT_DBG("regdma base @slot[%d]: %pK\n",
  334. sde_hw_rotator_get_regdma_ctxidx(ctx),
  335. ctx->regdma_base);
  336. return ctx->regdma_base;
  337. }
  338. /**
  339. * sde_hw_rotator_get_regdma_segment(): return current regdma command buffer
  340. * pointer for current regdma segment.
  341. * @ctx: Rotator Context
  342. * return: segment address
  343. */
  344. static inline char __iomem *sde_hw_rotator_get_regdma_segment(
  345. struct sde_hw_rotator_context *ctx)
  346. {
  347. u32 idx = sde_hw_rotator_get_regdma_ctxidx(ctx);
  348. char __iomem *addr = ctx->regdma_wrptr;
  349. SDEROT_DBG("regdma slot[%d] ==> %pK\n", idx, addr);
  350. return addr;
  351. }
  352. /**
  353. * sde_hw_rotator_put_regdma_segment(): update current regdma command buffer
  354. * pointer for current regdma segment
  355. * @ctx: Rotator Context
  356. * @wrptr: current regdma segment location
  357. */
  358. static inline void sde_hw_rotator_put_regdma_segment(
  359. struct sde_hw_rotator_context *ctx,
  360. char __iomem *wrptr)
  361. {
  362. u32 idx = sde_hw_rotator_get_regdma_ctxidx(ctx);
  363. ctx->regdma_wrptr = wrptr;
  364. SDEROT_DBG("regdma slot[%d] <== %pK\n", idx, wrptr);
  365. }
  366. /**
  367. * sde_hw_rotator_put_ctx(): Storing rotator context according to its
  368. * timestamp.
  369. */
  370. static inline void sde_hw_rotator_put_ctx(struct sde_hw_rotator_context *ctx)
  371. {
  372. struct sde_hw_rotator *rot = ctx->rot;
  373. u32 idx = sde_hw_rotator_get_regdma_ctxidx(ctx);
  374. unsigned long flags;
  375. spin_lock_irqsave(&rot->rotisr_lock, flags);
  376. rot->rotCtx[ctx->q_id][idx] = ctx;
  377. if (ctx->sbuf_mode)
  378. list_add_tail(&ctx->list, &rot->sbuf_ctx[ctx->q_id]);
  379. spin_unlock_irqrestore(&rot->rotisr_lock, flags);
  380. SDEROT_DBG("rotCtx[%d][%d] <== ctx:%pK | session-id:%d\n",
  381. ctx->q_id, idx, ctx, ctx->session_id);
  382. }
  383. /**
  384. * sde_hw_rotator_clr_ctx(): Clearing rotator context according to its
  385. * timestamp.
  386. */
  387. static inline void sde_hw_rotator_clr_ctx(struct sde_hw_rotator_context *ctx)
  388. {
  389. struct sde_hw_rotator *rot = ctx->rot;
  390. u32 idx = sde_hw_rotator_get_regdma_ctxidx(ctx);
  391. unsigned long flags;
  392. spin_lock_irqsave(&rot->rotisr_lock, flags);
  393. rot->rotCtx[ctx->q_id][idx] = NULL;
  394. if (ctx->sbuf_mode)
  395. list_del_init(&ctx->list);
  396. spin_unlock_irqrestore(&rot->rotisr_lock, flags);
  397. SDEROT_DBG("rotCtx[%d][%d] <== null | session-id:%d\n",
  398. ctx->q_id, idx, ctx->session_id);
  399. }
  400. #endif /*_SDE_ROTATOR_R3_INTERNAL_H */