msm_drv.h 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527
  1. /*
  2. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (C) 2013 Red Hat
  5. * Author: Rob Clark <[email protected]>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __MSM_DRV_H__
  20. #define __MSM_DRV_H__
  21. #include <linux/kernel.h>
  22. #include <linux/clk.h>
  23. #include <linux/cpufreq.h>
  24. #include <linux/module.h>
  25. #include <linux/component.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/pm.h>
  28. #include <linux/pm_runtime.h>
  29. #include <linux/slab.h>
  30. #include <linux/list.h>
  31. #include <linux/iommu.h>
  32. #include <linux/types.h>
  33. #include <linux/of_graph.h>
  34. #include <linux/of_device.h>
  35. #include <linux/sde_io_util.h>
  36. #include <linux/sde_vm_event.h>
  37. #include <linux/sizes.h>
  38. #include <linux/kthread.h>
  39. #include <linux/version.h>
  40. #include <linux/delay.h>
  41. #include <drm/drm_atomic.h>
  42. #include <drm/drm_atomic_helper.h>
  43. #include <drm/drm_plane_helper.h>
  44. #include <drm/drm_fb_helper.h>
  45. #include <drm/msm_drm.h>
  46. #include <drm/sde_drm.h>
  47. #include <drm/drm_file.h>
  48. #include <drm/drm_gem.h>
  49. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0))
  50. #include <drm/display/drm_dsc.h>
  51. #else
  52. #include <drm/drm_dsc.h>
  53. #endif
  54. #include <drm/drm_bridge.h>
  55. #include <drm/drm_framebuffer.h>
  56. #include "sde_power_handle.h"
  57. #define GET_MAJOR_REV(rev) ((rev) >> 28)
  58. #define GET_MINOR_REV(rev) (((rev) >> 16) & 0xFFF)
  59. #define GET_STEP_REV(rev) ((rev) & 0xFFFF)
  60. struct msm_kms;
  61. struct msm_gpu;
  62. struct msm_mmu;
  63. struct msm_mdss;
  64. struct msm_rd_state;
  65. struct msm_perf_state;
  66. struct msm_gem_submit;
  67. struct msm_fence_context;
  68. struct msm_fence_cb;
  69. struct msm_gem_address_space;
  70. struct msm_gem_vma;
  71. #define NUM_DOMAINS 4 /* one for KMS, then one per gpu core (?) */
  72. #define MAX_CRTCS 16
  73. #define MAX_PLANES 20
  74. #define MAX_ENCODERS 16
  75. #define MAX_BRIDGES 16
  76. #define MAX_CONNECTORS 16
  77. #define MSM_RGB 0x0
  78. #define MSM_YUV 0x1
  79. #define MSM_CHROMA_444 0x0
  80. #define MSM_CHROMA_422 0x1
  81. #define MSM_CHROMA_420 0x2
  82. #define TEARDOWN_DEADLOCK_RETRY_MAX 5
  83. #define DISP_DEV_ERR(dev, fmt, ...) dev_err(dev, "[%s:%d] " fmt, __func__, __LINE__, ##__VA_ARGS__)
  84. struct msm_file_private {
  85. rwlock_t queuelock;
  86. struct list_head submitqueues;
  87. int queueid;
  88. /* update the refcount when user driver calls power_ctrl IOCTL */
  89. unsigned short enable_refcnt;
  90. /* protects enable_refcnt */
  91. struct mutex power_lock;
  92. };
  93. enum msm_mdp_plane_property {
  94. /* blob properties, always put these first */
  95. PLANE_PROP_CSC_V1,
  96. PLANE_PROP_CSC_DMA_V1,
  97. PLANE_PROP_INFO,
  98. PLANE_PROP_SCALER_LUT_ED,
  99. PLANE_PROP_SCALER_LUT_CIR,
  100. PLANE_PROP_SCALER_LUT_SEP,
  101. PLANE_PROP_SKIN_COLOR,
  102. PLANE_PROP_SKY_COLOR,
  103. PLANE_PROP_FOLIAGE_COLOR,
  104. PLANE_PROP_VIG_GAMUT,
  105. PLANE_PROP_VIG_IGC,
  106. PLANE_PROP_DMA_IGC,
  107. PLANE_PROP_DMA_GC,
  108. PLANE_PROP_FP16_GC,
  109. PLANE_PROP_FP16_CSC,
  110. PLANE_PROP_UBWC_STATS_ROI,
  111. /* # of blob properties */
  112. PLANE_PROP_BLOBCOUNT,
  113. /* range properties */
  114. PLANE_PROP_ZPOS = PLANE_PROP_BLOBCOUNT,
  115. PLANE_PROP_ALPHA,
  116. PLANE_PROP_COLOR_FILL,
  117. PLANE_PROP_H_DECIMATE,
  118. PLANE_PROP_V_DECIMATE,
  119. PLANE_PROP_INPUT_FENCE,
  120. PLANE_PROP_HUE_ADJUST,
  121. PLANE_PROP_SATURATION_ADJUST,
  122. PLANE_PROP_VALUE_ADJUST,
  123. PLANE_PROP_CONTRAST_ADJUST,
  124. PLANE_PROP_EXCL_RECT_V1,
  125. PLANE_PROP_PREFILL_SIZE,
  126. PLANE_PROP_PREFILL_TIME,
  127. PLANE_PROP_SCALER_V1,
  128. PLANE_PROP_SCALER_V2,
  129. PLANE_PROP_INVERSE_PMA,
  130. PLANE_PROP_FP16_IGC,
  131. PLANE_PROP_FP16_UNMULT,
  132. /* enum/bitmask properties */
  133. PLANE_PROP_BLEND_OP,
  134. PLANE_PROP_SRC_CONFIG,
  135. PLANE_PROP_FB_TRANSLATION_MODE,
  136. PLANE_PROP_MULTIRECT_MODE,
  137. /* total # of properties */
  138. PLANE_PROP_COUNT
  139. };
  140. enum msm_mdp_crtc_property {
  141. CRTC_PROP_INFO,
  142. CRTC_PROP_DEST_SCALER_LUT_ED,
  143. CRTC_PROP_DEST_SCALER_LUT_CIR,
  144. CRTC_PROP_DEST_SCALER_LUT_SEP,
  145. CRTC_PROP_DSPP_INFO,
  146. /* # of blob properties */
  147. CRTC_PROP_BLOBCOUNT,
  148. /* range properties */
  149. CRTC_PROP_INPUT_FENCE_TIMEOUT = CRTC_PROP_BLOBCOUNT,
  150. CRTC_PROP_OUTPUT_FENCE,
  151. CRTC_PROP_OUTPUT_FENCE_OFFSET,
  152. CRTC_PROP_DIM_LAYER_V1,
  153. CRTC_PROP_CORE_CLK,
  154. CRTC_PROP_CORE_AB,
  155. CRTC_PROP_CORE_IB,
  156. CRTC_PROP_LLCC_AB,
  157. CRTC_PROP_LLCC_IB,
  158. CRTC_PROP_DRAM_AB,
  159. CRTC_PROP_DRAM_IB,
  160. CRTC_PROP_ROT_PREFILL_BW,
  161. CRTC_PROP_ROT_CLK,
  162. CRTC_PROP_ROI_V1,
  163. CRTC_PROP_SECURITY_LEVEL,
  164. CRTC_PROP_DEST_SCALER,
  165. CRTC_PROP_CAPTURE_OUTPUT,
  166. CRTC_PROP_IDLE_PC_STATE,
  167. CRTC_PROP_CACHE_STATE,
  168. CRTC_PROP_VM_REQ_STATE,
  169. CRTC_PROP_NOISE_LAYER_V1,
  170. CRTC_PROP_FRAME_DATA_BUF,
  171. /* total # of properties */
  172. CRTC_PROP_COUNT
  173. };
  174. enum msm_mdp_conn_property {
  175. /* blob properties, always put these first */
  176. CONNECTOR_PROP_SDE_INFO,
  177. CONNECTOR_PROP_MODE_INFO,
  178. CONNECTOR_PROP_HDR_INFO,
  179. CONNECTOR_PROP_EXT_HDR_INFO,
  180. CONNECTOR_PROP_PP_DITHER,
  181. CONNECTOR_PROP_PP_CWB_DITHER,
  182. CONNECTOR_PROP_HDR_METADATA,
  183. CONNECTOR_PROP_DEMURA_PANEL_ID,
  184. CONNECTOR_PROP_DIMMING_BL_LUT,
  185. CONNECTOR_PROP_DNSC_BLUR,
  186. /* # of blob properties */
  187. CONNECTOR_PROP_BLOBCOUNT,
  188. /* range properties */
  189. CONNECTOR_PROP_OUT_FB = CONNECTOR_PROP_BLOBCOUNT,
  190. CONNECTOR_PROP_RETIRE_FENCE,
  191. CONN_PROP_RETIRE_FENCE_OFFSET,
  192. CONNECTOR_PROP_DST_X,
  193. CONNECTOR_PROP_DST_Y,
  194. CONNECTOR_PROP_DST_W,
  195. CONNECTOR_PROP_DST_H,
  196. CONNECTOR_PROP_ROI_V1,
  197. CONNECTOR_PROP_BL_SCALE,
  198. CONNECTOR_PROP_SV_BL_SCALE,
  199. CONNECTOR_PROP_SUPPORTED_COLORSPACES,
  200. CONNECTOR_PROP_DYN_BIT_CLK,
  201. CONNECTOR_PROP_DIMMING_CTRL,
  202. CONNECTOR_PROP_DIMMING_MIN_BL,
  203. CONNECTOR_PROP_EARLY_FENCE_LINE,
  204. CONNECTOR_PROP_DYN_TRANSFER_TIME,
  205. /* enum/bitmask properties */
  206. CONNECTOR_PROP_TOPOLOGY_NAME,
  207. CONNECTOR_PROP_TOPOLOGY_CONTROL,
  208. CONNECTOR_PROP_AUTOREFRESH,
  209. CONNECTOR_PROP_LP,
  210. CONNECTOR_PROP_FB_TRANSLATION_MODE,
  211. CONNECTOR_PROP_QSYNC_MODE,
  212. CONNECTOR_PROP_CMD_FRAME_TRIGGER_MODE,
  213. CONNECTOR_PROP_SET_PANEL_MODE,
  214. CONNECTOR_PROP_AVR_STEP,
  215. CONNECTOR_PROP_CACHE_STATE,
  216. CONNECTOR_PROP_DSC_MODE,
  217. CONNECTOR_PROP_WB_USAGE_TYPE,
  218. /* total # of properties */
  219. CONNECTOR_PROP_COUNT
  220. };
  221. #define MSM_GPU_MAX_RINGS 4
  222. #define MAX_H_TILES_PER_DISPLAY 2
  223. /**
  224. * enum msm_display_compression_type - compression method used for pixel stream
  225. * @MSM_DISPLAY_COMPRESSION_NONE: Pixel data is not compressed
  226. * @MSM_DISPLAY_COMPRESSION_DSC: DSC compresison is used
  227. * @MSM_DISPLAY_COMPRESSION_VDC: VDC compresison is used
  228. */
  229. enum msm_display_compression_type {
  230. MSM_DISPLAY_COMPRESSION_NONE,
  231. MSM_DISPLAY_COMPRESSION_DSC,
  232. MSM_DISPLAY_COMPRESSION_VDC
  233. };
  234. /**
  235. * enum msm_display_wd_jitter_type - Type of WD jitter used
  236. * @MSM_DISPLAY_WD_JITTER_NONE: No WD timer jitter enabled
  237. * @MSM_DISPLAY_WD_INSTANTANEOUS_JITTER: Instantaneous WD jitter enabled
  238. * @MSM_DISPLAY_WD_LTJ_JITTER: LTJ WD jitter enabled
  239. */
  240. enum msm_display_wd_jitter_type {
  241. MSM_DISPLAY_WD_JITTER_NONE = BIT(0),
  242. MSM_DISPLAY_WD_INSTANTANEOUS_JITTER = BIT(1),
  243. MSM_DISPLAY_WD_LTJ_JITTER = BIT(2),
  244. };
  245. #define MSM_DISPLAY_COMPRESSION_RATIO_NONE 1
  246. #define MSM_DISPLAY_COMPRESSION_RATIO_MAX 5
  247. /**
  248. * enum msm_display_spr_pack_type - sub pixel rendering pack patterns supported
  249. * @MSM_DISPLAY_SPR_TYPE_NONE: Bypass, no special packing
  250. * @MSM_DISPLAY_SPR_TYPE_PENTILE: pentile pack pattern
  251. * @MSM_DISPLAY_SPR_TYPE_RGBW: RGBW pack pattern
  252. * @MSM_DISPLAY_SPR_TYPE_YYGM: YYGM pack pattern
  253. * @MSM_DISPLAY_SPR_TYPE_YYGW: YYGW pack patterm
  254. * @MSM_DISPLAY_SPR_TYPE_MAX: max and invalid
  255. */
  256. enum msm_display_spr_pack_type {
  257. MSM_DISPLAY_SPR_TYPE_NONE,
  258. MSM_DISPLAY_SPR_TYPE_PENTILE,
  259. MSM_DISPLAY_SPR_TYPE_RGBW,
  260. MSM_DISPLAY_SPR_TYPE_YYGM,
  261. MSM_DISPLAY_SPR_TYPE_YYGW,
  262. MSM_DISPLAY_SPR_TYPE_MAX
  263. };
  264. static const char *msm_spr_pack_type_str[MSM_DISPLAY_SPR_TYPE_MAX] = {
  265. [MSM_DISPLAY_SPR_TYPE_NONE] = "",
  266. [MSM_DISPLAY_SPR_TYPE_PENTILE] = "pentile",
  267. [MSM_DISPLAY_SPR_TYPE_RGBW] = "rgbw",
  268. [MSM_DISPLAY_SPR_TYPE_YYGM] = "yygm",
  269. [MSM_DISPLAY_SPR_TYPE_YYGW] = "yygw",
  270. };
  271. /**
  272. * enum msm_display_caps - features/capabilities supported by displays
  273. * @MSM_DISPLAY_CAP_VID_MODE: Video or "active" mode supported
  274. * @MSM_DISPLAY_CAP_CMD_MODE: Command mode supported
  275. * @MSM_DISPLAY_CAP_HOT_PLUG: Hot plug detection supported
  276. * @MSM_DISPLAY_CAP_EDID: EDID supported
  277. * @MSM_DISPLAY_ESD_ENABLED: ESD feature enabled
  278. * @MSM_DISPLAY_CAP_MST_MODE: Display with MST support
  279. * @MSM_DISPLAY_SPLIT_LINK: Split Link enabled
  280. */
  281. enum msm_display_caps {
  282. MSM_DISPLAY_CAP_VID_MODE = BIT(0),
  283. MSM_DISPLAY_CAP_CMD_MODE = BIT(1),
  284. MSM_DISPLAY_CAP_HOT_PLUG = BIT(2),
  285. MSM_DISPLAY_CAP_EDID = BIT(3),
  286. MSM_DISPLAY_ESD_ENABLED = BIT(4),
  287. MSM_DISPLAY_CAP_MST_MODE = BIT(5),
  288. MSM_DISPLAY_SPLIT_LINK = BIT(6),
  289. };
  290. /**
  291. * enum panel_mode - panel operation mode
  292. * @MSM_DISPLAY_VIDEO_MODE: video mode panel
  293. * @MSM_DISPLAY_CMD_MODE: Command mode panel
  294. * @MODE_MAX:
  295. */
  296. enum panel_op_mode {
  297. MSM_DISPLAY_VIDEO_MODE = BIT(0),
  298. MSM_DISPLAY_CMD_MODE = BIT(1),
  299. MSM_DISPLAY_MODE_MAX = BIT(2)
  300. };
  301. /**
  302. * enum msm_display_dsc_mode - panel dsc mode
  303. * @MSM_DISPLAY_DSC_MODE_NONE: No operation
  304. * @MSM_DISPLAY_DSC_MODE_ENABLED: DSC is enabled
  305. * @MSM_DISPLAY_DSC_MODE_DISABLED: DSC is disabled
  306. */
  307. enum msm_display_dsc_mode {
  308. MSM_DISPLAY_DSC_MODE_NONE,
  309. MSM_DISPLAY_DSC_MODE_ENABLED,
  310. MSM_DISPLAY_DSC_MODE_DISABLED,
  311. };
  312. /**
  313. * struct msm_display_mode - wrapper for drm_display_mode
  314. * @base: drm_display_mode attached to this msm_mode
  315. * @private_flags: integer holding private driver mode flags
  316. * @private: pointer to private driver information
  317. */
  318. struct msm_display_mode {
  319. struct drm_display_mode *base;
  320. u32 private_flags;
  321. u32 *private;
  322. };
  323. /**
  324. * struct msm_sub_mode - msm display sub mode
  325. * @dsc_enabled: boolean used to indicate if dsc should be enabled
  326. */
  327. struct msm_sub_mode {
  328. enum msm_display_dsc_mode dsc_mode;
  329. };
  330. /**
  331. * struct msm_ratio - integer ratio
  332. * @numer: numerator
  333. * @denom: denominator
  334. */
  335. struct msm_ratio {
  336. uint32_t numer;
  337. uint32_t denom;
  338. };
  339. /**
  340. * enum msm_event_wait - type of HW events to wait for
  341. * @MSM_ENC_COMMIT_DONE - wait for the driver to flush the registers to HW
  342. * @MSM_ENC_TX_COMPLETE - wait for the HW to transfer the frame to panel
  343. * @MSM_ENC_VBLANK - wait for the HW VBLANK event (for driver-internal waiters)
  344. * @MSM_ENC_ACTIVE_REGION - wait for the TG to be in active pixel region
  345. */
  346. enum msm_event_wait {
  347. MSM_ENC_COMMIT_DONE = 0,
  348. MSM_ENC_TX_COMPLETE,
  349. MSM_ENC_VBLANK,
  350. MSM_ENC_ACTIVE_REGION,
  351. };
  352. /**
  353. * struct msm_roi_alignment - region of interest alignment restrictions
  354. * @xstart_pix_align: left x offset alignment restriction
  355. * @width_pix_align: width alignment restriction
  356. * @ystart_pix_align: top y offset alignment restriction
  357. * @height_pix_align: height alignment restriction
  358. * @min_width: minimum width restriction
  359. * @min_height: minimum height restriction
  360. */
  361. struct msm_roi_alignment {
  362. uint32_t xstart_pix_align;
  363. uint32_t width_pix_align;
  364. uint32_t ystart_pix_align;
  365. uint32_t height_pix_align;
  366. uint32_t min_width;
  367. uint32_t min_height;
  368. };
  369. /**
  370. * struct msm_roi_caps - display's region of interest capabilities
  371. * @enabled: true if some region of interest is supported
  372. * @merge_rois: merge rois before sending to display
  373. * @num_roi: maximum number of rois supported
  374. * @align: roi alignment restrictions
  375. */
  376. struct msm_roi_caps {
  377. bool enabled;
  378. bool merge_rois;
  379. uint32_t num_roi;
  380. struct msm_roi_alignment align;
  381. };
  382. /**
  383. * struct msm_display_dsc_info - defines dsc configuration
  384. * @config DSC encoder configuration
  385. * @scr_rev: DSC revision.
  386. * @initial_lines: Number of initial lines stored in encoder.
  387. * @pkt_per_line: Number of packets per line.
  388. * @bytes_in_slice: Number of bytes in slice.
  389. * @eol_byte_num: Valid bytes at the end of line.
  390. * @bytes_per_pkt Number of bytes in DSI packet
  391. * @pclk_per_line: Compressed width.
  392. * @slice_last_group_size: Size of last group in pixels.
  393. * @slice_per_pkt: Number of slices per packet.
  394. * @num_active_ss_per_enc: Number of active soft slices per encoder.
  395. * @source_color_space: Source color space of DSC encoder
  396. * @chroma_format: Chroma_format of DSC encoder.
  397. * @det_thresh_flatness: Flatness threshold.
  398. * @extra_width: Extra width required in timing calculations.
  399. * @pps_delay_ms: Post PPS command delay in milliseconds.
  400. * @dsc_4hsmerge_en: Using DSC 4HS merge topology
  401. * @dsc_4hsmerge_padding 4HS merge DSC pair padding value in bytes
  402. * @dsc_4hsmerge_alignment 4HS merge DSC alignment value in bytes
  403. * @half_panel_pu True for single and dual dsc encoders if partial
  404. * update sets the roi width to half of mode width
  405. * False in all other cases
  406. */
  407. struct msm_display_dsc_info {
  408. struct drm_dsc_config config;
  409. u8 scr_rev;
  410. int initial_lines;
  411. int pkt_per_line;
  412. int bytes_in_slice;
  413. int bytes_per_pkt;
  414. int eol_byte_num;
  415. int pclk_per_line;
  416. int slice_last_group_size;
  417. int slice_per_pkt;
  418. int num_active_ss_per_enc;
  419. int source_color_space;
  420. int chroma_format;
  421. int det_thresh_flatness;
  422. u32 extra_width;
  423. u32 pps_delay_ms;
  424. bool dsc_4hsmerge_en;
  425. u32 dsc_4hsmerge_padding;
  426. u32 dsc_4hsmerge_alignment;
  427. bool half_panel_pu;
  428. };
  429. /**
  430. * struct msm_display_vdc_info - defines vdc configuration
  431. * @version_major: major version number of VDC encoder.
  432. * @version_minor: minor version number of VDC encoder.
  433. * @source_color_space: source color space of VDC encoder
  434. * @chroma_format: chroma_format of VDC encoder.
  435. * @mppf_bpc_r_y: MPPF bpc for R/Y color component
  436. * @mppf_bpc_g_cb: MPPF bpc for G/Cb color component
  437. * @mppf_bpc_b_cr: MPPF bpc for B/Cr color component
  438. * @mppf_bpc_y: MPPF bpc for Y color component
  439. * @mppf_bpc_co: MPPF bpc for Co color component
  440. * @mppf_bpc_cg: MPPF bpc for Cg color component
  441. * @flatqp_vf_fbls: flatness qp very flat FBLs
  442. * @flatqp_vf_nbls: flatness qp very flat NBLs
  443. * @flatqp_sw_fbls: flatness qp somewhat flat FBLs
  444. * @flatqp_sw_nbls: flatness qp somewhat flat NBLs
  445. * @chroma_samples: number of chroma samples
  446. * @split_panel_enable: indicates whether split panel is enabled
  447. * @traffic_mode: indicates burst/non-burst mode
  448. * @flatness_qp_lut: LUT used to determine flatness QP
  449. * @max_qp_lut: LUT used to determine maximum QP
  450. * @tar_del_lut: LUT used to calculate RC target rate
  451. * @lbda_brate_lut: lambda bitrate LUT for encoder
  452. * @lbda_bf_lut: lambda buffer fullness lut for encoder
  453. * @lbda_brate_lut_interp: interpolated lambda bitrate LUT
  454. * @lbda_bf_lut_interp: interpolated lambda buffer fullness lut
  455. * @num_of_active_ss: number of active soft slices
  456. * @bits_per_component: number of bits per component.
  457. * @max_pixels_per_line: maximum pixels per line
  458. * @max_pixels_per_hs_line: maximum pixels per hs line
  459. * @max_lines_per_frame: maximum lines per frame
  460. * @max_lines_per_slice: maximum lines per slice
  461. * @chunk_size: chunk size for encoder
  462. * @chunk_size_bits: number of bits in the chunk
  463. * @avg_block_bits: average block bits
  464. * @per_chunk_pad_bits: number of bits per chunk pad
  465. * @tot_pad_bits: total padding bits
  466. * @rc_stuffing_bits: rate control stuffing bits
  467. * @chunk_adj_bits: number of adjacent bits in the chunk
  468. * @rc_buf_init_size_temp: temporary rate control buffer init size
  469. * @init_tx_delay_temp: initial tx delay
  470. * @rc_buffer_init_size: rate control buffer init size
  471. * @rc_init_tx_delay: rate control buffer init tx delay
  472. * @rc_init_tx_delay_px_times: rate control buffer init tx
  473. * delay times pixels
  474. * @rc_buffer_max_size: max size of rate control buffer
  475. * @rc_tar_rate_scale_temp_a: rate control target rate scale parameter
  476. * @rc_tar_rate_scale_temp_b: rate control target rate scale parameter
  477. * @rc_tar_rate_scale: rate control target rate scale
  478. * @block_max_bits: max bits in the block
  479. * @rc_lambda_bitrate_scale: rate control lambda bitrate scale
  480. * @rc_buffer_fullness_scale: rate control lambda fullness scale
  481. * @rc_fullness_offset_thresh: rate control lambda fullness threshold
  482. * @ramp_blocks: number of ramp blocks
  483. * @bits_per_pixel: number of bits per pixel.
  484. * @num_extra_mux_bits_init: initial value of number of extra mux bits
  485. * @extra_crop_bits: number of extra crop bits
  486. * @num_extra_mux_bits: value of number of extra mux bits
  487. * @mppf_bits_comp_0: mppf bits in color component 0
  488. * @mppf_bits_comp_1: mppf bits in color component 1
  489. * @mppf_bits_comp_2: mppf bits in color component 2
  490. * @min_block_bits: min number of block bits
  491. * @slice_height: slice height configuration of encoder.
  492. * @slice_width: slice width configuration of encoder.
  493. * @frame_width: frame width configuration of encoder
  494. * @frame_height: frame height configuration of encoder
  495. * @bytes_in_slice: Number of bytes in slice.
  496. * @bytes_per_pkt: Number of bytes in packet.
  497. * @eol_byte_num: Valid bytes at the end of line.
  498. * @pclk_per_line: Compressed width.
  499. * @slice_per_pkt: Number of slices per packet.
  500. * @pkt_per_line: Number of packets per line.
  501. * @min_ssm_delay: Min Sub-stream multiplexing delay
  502. * @max_ssm_delay: Max Sub-stream multiplexing delay
  503. * @input_ssm_out_latency: input Sub-stream multiplexing output latency
  504. * @input_ssm_out_latency_min: min input Sub-stream multiplexing output latency
  505. * @obuf_latency: Output buffer latency
  506. * @base_hs_latency: base hard-slice latency
  507. * @base_hs_latency_min: base hard-slice min latency
  508. * @base_hs_latency_pixels: base hard-slice latency pixels
  509. * @base_hs_latency_pixels_min: base hard-slice latency pixels(min)
  510. * @base_initial_lines: base initial lines
  511. * @base_top_up: base top up
  512. * @output_rate: output rate
  513. * @output_rate_ratio_100: output rate times 100
  514. * @burst_accum_pixels: burst accumulated pixels
  515. * @ss_initial_lines: soft-slice initial lines
  516. * @burst_initial_lines: burst mode initial lines
  517. * @initial_lines: initial lines
  518. * @obuf_base: output buffer base
  519. * @obuf_extra_ss0: output buffer extra ss0
  520. * @obuf_extra_ss1: output buffer extra ss1
  521. * @obuf_extra_burst: output buffer extra burst
  522. * @obuf_ss0: output buffer ss0
  523. * @obuf_ss1: output buffer ss1
  524. * @obuf_margin_words: output buffer margin words
  525. * @ob0_max_addr: output buffer 0 max address
  526. * @ob1_max_addr: output buffer 1 max address
  527. * @slice_width_orig: original slice width
  528. * @r2b0_max_addr: r2b0 max addr
  529. * @r2b1_max_addr: r1b1 max addr
  530. * @slice_num_px: number of pixels per slice
  531. * @rc_target_rate_threshold: rate control target rate threshold
  532. * @rc_fullness_offset_slope: rate control fullness offset slop
  533. * @pps_delay_ms: Post PPS command delay in milliseconds.
  534. * @version_release: release version of VDC encoder.
  535. * @slice_num_bits: number of bits per slice
  536. * @ramp_bits: number of ramp bits
  537. */
  538. struct msm_display_vdc_info {
  539. u8 version_major;
  540. u8 version_minor;
  541. u8 source_color_space;
  542. u8 chroma_format;
  543. u8 mppf_bpc_r_y;
  544. u8 mppf_bpc_g_cb;
  545. u8 mppf_bpc_b_cr;
  546. u8 mppf_bpc_y;
  547. u8 mppf_bpc_co;
  548. u8 mppf_bpc_cg;
  549. u8 flatqp_vf_fbls;
  550. u8 flatqp_vf_nbls;
  551. u8 flatqp_sw_fbls;
  552. u8 flatqp_sw_nbls;
  553. u8 chroma_samples;
  554. u8 split_panel_enable;
  555. u8 traffic_mode;
  556. u16 flatness_qp_lut[8];
  557. u16 max_qp_lut[8];
  558. u16 tar_del_lut[16];
  559. u16 lbda_brate_lut[16];
  560. u16 lbda_bf_lut[16];
  561. u16 lbda_brate_lut_interp[64];
  562. u16 lbda_bf_lut_interp[64];
  563. u8 num_of_active_ss;
  564. u8 bits_per_component;
  565. u16 max_pixels_per_line;
  566. u16 max_pixels_per_hs_line;
  567. u16 max_lines_per_frame;
  568. u16 max_lines_per_slice;
  569. u16 chunk_size;
  570. u16 chunk_size_bits;
  571. u16 avg_block_bits;
  572. u16 per_chunk_pad_bits;
  573. u16 tot_pad_bits;
  574. u16 rc_stuffing_bits;
  575. u16 chunk_adj_bits;
  576. u16 rc_buf_init_size_temp;
  577. u16 init_tx_delay_temp;
  578. u16 rc_buffer_init_size;
  579. u16 rc_init_tx_delay;
  580. u16 rc_init_tx_delay_px_times;
  581. u16 rc_buffer_max_size;
  582. u16 rc_tar_rate_scale_temp_a;
  583. u16 rc_tar_rate_scale_temp_b;
  584. u16 rc_tar_rate_scale;
  585. u16 block_max_bits;
  586. u16 rc_lambda_bitrate_scale;
  587. u16 rc_buffer_fullness_scale;
  588. u16 rc_fullness_offset_thresh;
  589. u16 ramp_blocks;
  590. u16 bits_per_pixel;
  591. u16 num_extra_mux_bits_init;
  592. u16 extra_crop_bits;
  593. u16 num_extra_mux_bits;
  594. u16 mppf_bits_comp_0;
  595. u16 mppf_bits_comp_1;
  596. u16 mppf_bits_comp_2;
  597. u16 min_block_bits;
  598. int slice_height;
  599. int slice_width;
  600. int frame_width;
  601. int frame_height;
  602. int bytes_in_slice;
  603. int bytes_per_pkt;
  604. int eol_byte_num;
  605. int pclk_per_line;
  606. int slice_per_pkt;
  607. int pkt_per_line;
  608. int min_ssm_delay;
  609. int max_ssm_delay;
  610. int input_ssm_out_latency;
  611. int input_ssm_out_latency_min;
  612. int obuf_latency;
  613. int base_hs_latency;
  614. int base_hs_latency_min;
  615. int base_hs_latency_pixels;
  616. int base_hs_latency_pixels_min;
  617. int base_initial_lines;
  618. int base_top_up;
  619. int output_rate;
  620. int output_rate_ratio_100;
  621. int burst_accum_pixels;
  622. int ss_initial_lines;
  623. int burst_initial_lines;
  624. int initial_lines;
  625. int obuf_base;
  626. int obuf_extra_ss0;
  627. int obuf_extra_ss1;
  628. int obuf_extra_burst;
  629. int obuf_ss0;
  630. int obuf_ss1;
  631. int obuf_margin_words;
  632. int ob0_max_addr;
  633. int ob1_max_addr;
  634. int slice_width_orig;
  635. int r2b0_max_addr;
  636. int r2b1_max_addr;
  637. u32 slice_num_px;
  638. u32 rc_target_rate_threshold;
  639. u32 rc_fullness_offset_slope;
  640. u32 pps_delay_ms;
  641. u32 version_release;
  642. u64 slice_num_bits;
  643. u64 ramp_bits;
  644. };
  645. /**
  646. * Bits/pixel target >> 4 (removing the fractional bits)
  647. * returns the integer bpp value from the drm_dsc_config struct
  648. */
  649. #define DSC_BPP(config) ((config).bits_per_pixel >> 4)
  650. /**
  651. * struct msm_compression_info - defined panel compression
  652. * @enabled: enabled/disabled
  653. * @comp_type: type of compression supported
  654. * @comp_ratio: compression ratio
  655. * @src_bpp: bits per pixel before compression
  656. * @tgt_bpp: bits per pixel after compression
  657. * @dsc_info: dsc configuration if the compression
  658. * supported is DSC
  659. * @vdc_info: vdc configuration if the compression
  660. * supported is VDC
  661. */
  662. struct msm_compression_info {
  663. bool enabled;
  664. enum msm_display_compression_type comp_type;
  665. u32 comp_ratio;
  666. u32 src_bpp;
  667. u32 tgt_bpp;
  668. union{
  669. struct msm_display_dsc_info dsc_info;
  670. struct msm_display_vdc_info vdc_info;
  671. };
  672. };
  673. /**
  674. * struct msm_display_topology - defines a display topology pipeline
  675. * @num_lm: number of layer mixers used
  676. * @num_enc: number of compression encoder blocks used
  677. * @num_intf: number of interfaces the panel is mounted on
  678. * @comp_type: type of compression supported
  679. */
  680. struct msm_display_topology {
  681. u32 num_lm;
  682. u32 num_enc;
  683. u32 num_intf;
  684. enum msm_display_compression_type comp_type;
  685. };
  686. /**
  687. * struct msm_dyn_clk_list - list of dynamic clock rates.
  688. * @count: number of supported clock rates
  689. * @rates: list of supported clock rates
  690. * @type: dynamic clock feature support type
  691. * @front_porches: list of clock rate matching porch compensation values
  692. * @pixel_clks_khz: list of clock rate matching pixel clock values
  693. */
  694. struct msm_dyn_clk_list {
  695. u32 count;
  696. u32 *rates;
  697. u32 type;
  698. u32 *front_porches;
  699. u32 *pixel_clks_khz;
  700. };
  701. /**
  702. * struct msm_display_wd_jitter_config - defines jitter properties for WD timer
  703. * @jitter_type: Type of WD jitter enabled.
  704. * @inst_jitter_numer: Instantaneous jitter numerator.
  705. * @inst_jitter_denom: Instantaneous jitter denominator.
  706. * @ltj_max_numer: LTJ max numerator.
  707. * @ltj_max_denom: LTJ max denominator.
  708. * @ltj_time_sec: LTJ time in seconds.
  709. */
  710. struct msm_display_wd_jitter_config {
  711. enum msm_display_wd_jitter_type jitter_type;
  712. u32 inst_jitter_numer;
  713. u32 inst_jitter_denom;
  714. u32 ltj_max_numer;
  715. u32 ltj_max_denom;
  716. u32 ltj_time_sec;
  717. };
  718. /**
  719. * struct msm_mode_info - defines all msm custom mode info
  720. * @frame_rate: frame_rate of the mode
  721. * @vtotal: vtotal calculated for the mode
  722. * @prefill_lines: prefill lines based on porches.
  723. * @jitter_numer: display panel jitter numerator configuration
  724. * @jitter_denom: display panel jitter denominator configuration
  725. * @clk_rate: DSI bit clock per lane in HZ.
  726. * @dfps_maxfps: max FPS of dynamic FPS
  727. * @topology: supported topology for the mode
  728. * @comp_info: compression info supported
  729. * @roi_caps: panel roi capabilities
  730. * @wide_bus_en: wide-bus mode cfg for interface module
  731. * @panel_mode_caps panel mode capabilities
  732. * @mdp_transfer_time_us Specifies the mdp transfer time for command mode
  733. * panels in microseconds.
  734. * @mdp_transfer_time_us_min Specifies the minimum possible mdp transfer time
  735. * for command mode panels in microseconds.
  736. * @mdp_transfer_time_us_max Specifies the maximum possible mdp transfer time
  737. * for command mode panels in microseconds.
  738. * @allowed_mode_switches: bit mask to indicate supported mode switch.
  739. * @disable_rsc_solver: Dynamically disable RSC solver for the timing mode due to lower bitclk rate.
  740. * @dyn_clk_list: List of dynamic clock rates for RFI.
  741. * @qsync_min_fps: qsync min fps rate
  742. * @wd_jitter: Info for WD jitter.
  743. * @vpadding: panel stacking height
  744. */
  745. struct msm_mode_info {
  746. uint32_t frame_rate;
  747. uint32_t vtotal;
  748. uint32_t prefill_lines;
  749. uint32_t jitter_numer;
  750. uint32_t jitter_denom;
  751. uint64_t clk_rate;
  752. uint32_t dfps_maxfps;
  753. struct msm_display_topology topology;
  754. struct msm_compression_info comp_info;
  755. struct msm_roi_caps roi_caps;
  756. bool wide_bus_en;
  757. u32 panel_mode_caps;
  758. u32 mdp_transfer_time_us;
  759. u32 mdp_transfer_time_us_min;
  760. u32 mdp_transfer_time_us_max;
  761. u32 allowed_mode_switches;
  762. bool disable_rsc_solver;
  763. struct msm_dyn_clk_list dyn_clk_list;
  764. u32 qsync_min_fps;
  765. struct msm_display_wd_jitter_config wd_jitter;
  766. u32 vpadding;
  767. };
  768. /**
  769. * struct msm_resource_caps_info - defines hw resources
  770. * @num_lm_in_use number of layer mixers allocated to a specified encoder
  771. * @num_lm number of layer mixers available
  772. * @num_dsc number of dsc available
  773. * @num_vdc number of vdc available
  774. * @num_ctl number of ctl available
  775. * @num_3dmux number of 3d mux available
  776. * @max_mixer_width: max width supported by layer mixer
  777. */
  778. struct msm_resource_caps_info {
  779. uint32_t num_lm_in_use;
  780. uint32_t num_lm;
  781. uint32_t num_dsc;
  782. uint32_t num_vdc;
  783. uint32_t num_ctl;
  784. uint32_t num_3dmux;
  785. uint32_t max_mixer_width;
  786. };
  787. /**
  788. * struct msm_display_info - defines display properties
  789. * @intf_type: DRM_MODE_CONNECTOR_ display type
  790. * @capabilities: Bitmask of display flags
  791. * @num_of_h_tiles: Number of horizontal tiles in case of split interface
  792. * @h_tile_instance: Controller instance used per tile. Number of elements is
  793. * based on num_of_h_tiles
  794. * @is_connected: Set to true if display is connected
  795. * @width_mm: Physical width
  796. * @height_mm: Physical height
  797. * @max_width: Max width of display. In case of hot pluggable display
  798. * this is max width supported by controller
  799. * @max_height: Max height of display. In case of hot pluggable display
  800. * this is max height supported by controller
  801. * @clk_rate: DSI bit clock per lane in HZ.
  802. * @display_type: Enum for type of display
  803. * @is_te_using_watchdog_timer: Boolean to indicate watchdog TE is
  804. * used instead of panel TE in cmd mode panels
  805. * @poms_align_vsync: poms with vsync aligned
  806. * @roi_caps: Region of interest capability info
  807. * @qsync_min_fps Minimum fps supported by Qsync feature
  808. * @has_qsync_min_fps_list True if dsi-supported-qsync-min-fps-list exits
  809. * @has_avr_step_req Panel has defined requirement for AVR steps
  810. * @te_source vsync source pin information
  811. * @dsc_count: max dsc hw blocks used by display (only available
  812. * for dsi display)
  813. * @lm_count: max layer mixer blocks used by display (only available
  814. * for dsi display)
  815. */
  816. struct msm_display_info {
  817. int intf_type;
  818. uint32_t capabilities;
  819. enum panel_op_mode curr_panel_mode;
  820. uint32_t num_of_h_tiles;
  821. uint32_t h_tile_instance[MAX_H_TILES_PER_DISPLAY];
  822. bool is_connected;
  823. unsigned int width_mm;
  824. unsigned int height_mm;
  825. uint32_t max_width;
  826. uint32_t max_height;
  827. uint64_t clk_rate;
  828. uint32_t display_type;
  829. bool is_te_using_watchdog_timer;
  830. bool poms_align_vsync;
  831. struct msm_roi_caps roi_caps;
  832. uint32_t qsync_min_fps;
  833. bool has_qsync_min_fps_list;
  834. bool has_avr_step_req;
  835. uint32_t te_source;
  836. uint32_t dsc_count;
  837. uint32_t lm_count;
  838. };
  839. #define MSM_MAX_ROI 4
  840. /**
  841. * struct msm_roi_list - list of regions of interest for a drm object
  842. * @num_rects: number of valid rectangles in the roi array
  843. * @roi: list of roi rectangles
  844. */
  845. struct msm_roi_list {
  846. uint32_t num_rects;
  847. struct drm_clip_rect roi[MSM_MAX_ROI];
  848. };
  849. /**
  850. * struct - msm_display_kickoff_params - info for display features at kickoff
  851. * @rois: Regions of interest structure for mapping CRTC to Connector output
  852. */
  853. struct msm_display_kickoff_params {
  854. struct msm_roi_list *rois;
  855. struct drm_msm_ext_hdr_metadata *hdr_meta;
  856. };
  857. /**
  858. * struct - msm_display_conn_params - info of dpu display features
  859. * @qsync_mode: Qsync mode, where 0: disabled 1: continuous mode 2: oneshot
  860. * @qsync_update: Qsync settings were changed/updated
  861. */
  862. struct msm_display_conn_params {
  863. uint32_t qsync_mode;
  864. bool qsync_update;
  865. };
  866. /**
  867. * struct msm_drm_event - defines custom event notification struct
  868. * @base: base object required for event notification by DRM framework.
  869. * @event: event object required for event notification by DRM framework.
  870. */
  871. struct msm_drm_event {
  872. struct drm_pending_event base;
  873. struct drm_msm_event_resp event;
  874. };
  875. /* Commit/Event thread specific structure */
  876. struct msm_drm_thread {
  877. struct drm_device *dev;
  878. struct task_struct *thread;
  879. unsigned int crtc_id;
  880. struct kthread_worker worker;
  881. };
  882. struct msm_drm_private {
  883. struct drm_device *dev;
  884. struct msm_kms *kms;
  885. struct sde_power_handle phandle;
  886. /* subordinate devices, if present: */
  887. struct platform_device *gpu_pdev;
  888. /* top level MDSS wrapper device (for MDP5 only) */
  889. struct msm_mdss *mdss;
  890. /* possibly this should be in the kms component, but it is
  891. * shared by both mdp4 and mdp5..
  892. */
  893. struct hdmi *hdmi;
  894. /* eDP is for mdp5 only, but kms has not been created
  895. * when edp_bind() and edp_init() are called. Here is the only
  896. * place to keep the edp instance.
  897. */
  898. struct msm_edp *edp;
  899. /* DSI is shared by mdp4 and mdp5 */
  900. struct msm_dsi *dsi[2];
  901. /* when we have more than one 'msm_gpu' these need to be an array: */
  902. struct msm_gpu *gpu;
  903. struct msm_file_private *lastctx;
  904. struct drm_fb_helper *fbdev;
  905. struct msm_rd_state *rd; /* debugfs to dump all submits */
  906. struct msm_rd_state *hangrd; /* debugfs to dump hanging submits */
  907. struct msm_perf_state *perf;
  908. /*
  909. * List of inactive GEM objects. Every bo is either in the inactive_list
  910. * or gpu->active_list (for the gpu it is active on[1])
  911. *
  912. * These lists are protected by mm_lock. If struct_mutex is involved, it
  913. * should be aquired prior to mm_lock. One should *not* hold mm_lock in
  914. * get_pages()/vmap()/etc paths, as they can trigger the shrinker.
  915. *
  916. * [1] if someone ever added support for the old 2d cores, there could be
  917. * more than one gpu object
  918. */
  919. struct list_head inactive_list;
  920. struct mutex mm_lock;
  921. struct workqueue_struct *wq;
  922. /* crtcs pending async atomic updates: */
  923. uint32_t pending_crtcs;
  924. uint32_t pending_planes;
  925. wait_queue_head_t pending_crtcs_event;
  926. unsigned int num_planes;
  927. struct drm_plane *planes[MAX_PLANES];
  928. unsigned int num_crtcs;
  929. struct drm_crtc *crtcs[MAX_CRTCS];
  930. struct msm_drm_thread disp_thread[MAX_CRTCS];
  931. struct msm_drm_thread event_thread[MAX_CRTCS];
  932. struct task_struct *pp_event_thread;
  933. struct kthread_worker pp_event_worker;
  934. struct kthread_work thread_priority_work;
  935. unsigned int num_encoders;
  936. struct drm_encoder *encoders[MAX_ENCODERS];
  937. unsigned int num_bridges;
  938. struct drm_bridge *bridges[MAX_BRIDGES];
  939. unsigned int num_connectors;
  940. struct drm_connector *connectors[MAX_CONNECTORS];
  941. /* Properties */
  942. struct drm_property *plane_property[PLANE_PROP_COUNT];
  943. struct drm_property *crtc_property[CRTC_PROP_COUNT];
  944. struct drm_property *conn_property[CONNECTOR_PROP_COUNT];
  945. /* Color processing properties for the crtc */
  946. struct drm_property **cp_property;
  947. /* VRAM carveout, used when no IOMMU: */
  948. struct {
  949. unsigned long size;
  950. dma_addr_t paddr;
  951. /* NOTE: mm managed at the page level, size is in # of pages
  952. * and position mm_node->start is in # of pages:
  953. */
  954. struct drm_mm mm;
  955. spinlock_t lock; /* Protects drm_mm node allocation/removal */
  956. } vram;
  957. struct notifier_block vmap_notifier;
  958. struct shrinker shrinker;
  959. struct drm_atomic_state *pm_state;
  960. /* task holding struct_mutex.. currently only used in submit path
  961. * to detect and reject faults from copy_from_user() for submit
  962. * ioctl.
  963. */
  964. struct task_struct *struct_mutex_task;
  965. /* list of clients waiting for events */
  966. struct list_head client_event_list;
  967. /* whether registered and drm_dev_unregister should be called */
  968. bool registered;
  969. /* msm drv debug root node */
  970. struct dentry *debug_root;
  971. /* update the flag when msm driver receives shutdown notification */
  972. bool shutdown_in_progress;
  973. struct mutex vm_client_lock;
  974. struct list_head vm_client_list;
  975. };
  976. /* get struct msm_kms * from drm_device * */
  977. #define ddev_to_msm_kms(D) ((D) && (D)->dev_private ? \
  978. ((struct msm_drm_private *)((D)->dev_private))->kms : NULL)
  979. struct msm_format {
  980. uint32_t pixel_format;
  981. };
  982. int msm_atomic_prepare_fb(struct drm_plane *plane,
  983. struct drm_plane_state *new_state);
  984. void msm_atomic_commit_tail(struct drm_atomic_state *state);
  985. int msm_atomic_commit(struct drm_device *dev,
  986. struct drm_atomic_state *state, bool nonblock);
  987. /* callback from wq once fence has passed: */
  988. struct msm_fence_cb {
  989. struct work_struct work;
  990. uint32_t fence;
  991. void (*func)(struct msm_fence_cb *cb);
  992. };
  993. void __msm_fence_worker(struct work_struct *work);
  994. #define INIT_FENCE_CB(_cb, _func) do { \
  995. INIT_WORK(&(_cb)->work, __msm_fence_worker); \
  996. (_cb)->func = _func; \
  997. } while (0)
  998. struct drm_atomic_state *msm_atomic_state_alloc(struct drm_device *dev);
  999. void msm_atomic_state_clear(struct drm_atomic_state *state);
  1000. void msm_atomic_state_free(struct drm_atomic_state *state);
  1001. void msm_atomic_flush_display_threads(struct msm_drm_private *priv);
  1002. int msm_gem_init_vma(struct msm_gem_address_space *aspace,
  1003. struct msm_gem_vma *vma, int npages);
  1004. void msm_gem_unmap_vma(struct msm_gem_address_space *aspace,
  1005. struct msm_gem_vma *vma, struct sg_table *sgt,
  1006. unsigned int flags);
  1007. int msm_gem_map_vma(struct msm_gem_address_space *aspace,
  1008. struct msm_gem_vma *vma, struct sg_table *sgt, int npages,
  1009. unsigned int flags);
  1010. struct device *msm_gem_get_aspace_device(struct msm_gem_address_space *aspace);
  1011. void msm_gem_address_space_put(struct msm_gem_address_space *aspace);
  1012. /* For SDE display */
  1013. struct msm_gem_address_space *
  1014. msm_gem_smmu_address_space_create(struct drm_device *dev, struct msm_mmu *mmu,
  1015. const char *name);
  1016. /**
  1017. * msm_gem_add_obj_to_aspace_active_list: adds obj to active obj list in aspace
  1018. */
  1019. void msm_gem_add_obj_to_aspace_active_list(
  1020. struct msm_gem_address_space *aspace,
  1021. struct drm_gem_object *obj);
  1022. /**
  1023. * msm_gem_remove_obj_from_aspace_active_list: removes obj from active obj
  1024. * list in aspace
  1025. */
  1026. void msm_gem_remove_obj_from_aspace_active_list(
  1027. struct msm_gem_address_space *aspace,
  1028. struct drm_gem_object *obj);
  1029. /**
  1030. * msm_gem_smmu_address_space_get: returns the aspace pointer for the requested
  1031. * domain
  1032. */
  1033. struct msm_gem_address_space *
  1034. msm_gem_smmu_address_space_get(struct drm_device *dev,
  1035. unsigned int domain);
  1036. int msm_register_mmu(struct drm_device *dev, struct msm_mmu *mmu);
  1037. void msm_unregister_mmu(struct drm_device *dev, struct msm_mmu *mmu);
  1038. /**
  1039. * msm_gem_aspace_domain_attach_detach: function to inform the attach/detach
  1040. * of the domain for this aspace
  1041. */
  1042. void msm_gem_aspace_domain_attach_detach_update(
  1043. struct msm_gem_address_space *aspace,
  1044. bool is_detach);
  1045. /**
  1046. * msm_gem_address_space_register_cb: function to register callback for attach
  1047. * and detach of the domain
  1048. */
  1049. int msm_gem_address_space_register_cb(
  1050. struct msm_gem_address_space *aspace,
  1051. void (*cb)(void *, bool),
  1052. void *cb_data);
  1053. /**
  1054. * msm_gem_address_space_register_cb: function to unregister callback
  1055. */
  1056. int msm_gem_address_space_unregister_cb(
  1057. struct msm_gem_address_space *aspace,
  1058. void (*cb)(void *, bool),
  1059. void *cb_data);
  1060. void msm_gem_submit_free(struct msm_gem_submit *submit);
  1061. int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
  1062. struct drm_file *file);
  1063. void msm_gem_shrinker_init(struct drm_device *dev);
  1064. void msm_gem_shrinker_cleanup(struct drm_device *dev);
  1065. void msm_gem_sync(struct drm_gem_object *obj);
  1066. int msm_gem_mmap_obj(struct drm_gem_object *obj,
  1067. struct vm_area_struct *vma);
  1068. int msm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  1069. uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj);
  1070. int msm_gem_get_iova(struct drm_gem_object *obj,
  1071. struct msm_gem_address_space *aspace, uint64_t *iova);
  1072. uint64_t msm_gem_iova(struct drm_gem_object *obj,
  1073. struct msm_gem_address_space *aspace);
  1074. void msm_gem_unpin_iova(struct drm_gem_object *obj,
  1075. struct msm_gem_address_space *aspace);
  1076. struct page **msm_gem_get_pages(struct drm_gem_object *obj);
  1077. void msm_gem_put_pages(struct drm_gem_object *obj);
  1078. void msm_gem_put_iova(struct drm_gem_object *obj,
  1079. struct msm_gem_address_space *aspace);
  1080. dma_addr_t msm_gem_get_dma_addr(struct drm_gem_object *obj);
  1081. int msm_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
  1082. struct drm_mode_create_dumb *args);
  1083. int msm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
  1084. uint32_t handle, uint64_t *offset);
  1085. struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj);
  1086. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0))
  1087. int msm_gem_prime_vmap(struct drm_gem_object *obj, struct iosys_map *map);
  1088. void msm_gem_prime_vunmap(struct drm_gem_object *obj, struct iosys_map *map);
  1089. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0))
  1090. int msm_gem_prime_vmap(struct drm_gem_object *obj, struct dma_buf_map *map);
  1091. void msm_gem_prime_vunmap(struct drm_gem_object *obj, struct dma_buf_map *map);
  1092. #else
  1093. void *msm_gem_prime_vmap(struct drm_gem_object *obj);
  1094. void msm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
  1095. vm_fault_t msm_gem_fault(struct vm_fault *vmf);
  1096. #endif
  1097. int msm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
  1098. struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev,
  1099. struct dma_buf_attachment *attach, struct sg_table *sg);
  1100. int msm_gem_prime_pin(struct drm_gem_object *obj);
  1101. void msm_gem_prime_unpin(struct drm_gem_object *obj);
  1102. struct drm_gem_object *msm_gem_prime_import(struct drm_device *dev,
  1103. struct dma_buf *dma_buf);
  1104. void *msm_gem_get_vaddr(struct drm_gem_object *obj);
  1105. void msm_gem_put_vaddr(struct drm_gem_object *obj);
  1106. int msm_gem_madvise(struct drm_gem_object *obj, unsigned madv);
  1107. int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op, ktime_t *timeout);
  1108. int msm_gem_cpu_fini(struct drm_gem_object *obj);
  1109. void msm_gem_free_object(struct drm_gem_object *obj);
  1110. int msm_gem_new_handle(struct drm_device *dev, struct drm_file *file,
  1111. uint32_t size, uint32_t flags, uint32_t *handle, char *name);
  1112. struct drm_gem_object *msm_gem_new(struct drm_device *dev,
  1113. uint32_t size, uint32_t flags);
  1114. struct drm_gem_object *msm_gem_import(struct drm_device *dev,
  1115. struct dma_buf *dmabuf, struct sg_table *sgt);
  1116. __printf(2, 3)
  1117. void msm_gem_object_set_name(struct drm_gem_object *bo, const char *fmt, ...);
  1118. int msm_gem_delayed_import(struct drm_gem_object *obj);
  1119. #define MSM_FB_CACHE_NONE 0x0
  1120. #define MSM_FB_CACHE_WRITE_EN 0x1
  1121. #define MSM_FB_CACHE_READ_EN 0x2
  1122. int msm_framebuffer_prepare(struct drm_framebuffer *fb,
  1123. struct msm_gem_address_space *aspace);
  1124. void msm_framebuffer_cleanup(struct drm_framebuffer *fb,
  1125. struct msm_gem_address_space *aspace);
  1126. uint32_t msm_framebuffer_iova(struct drm_framebuffer *fb,
  1127. struct msm_gem_address_space *aspace, int plane);
  1128. uint32_t msm_framebuffer_phys(struct drm_framebuffer *fb, int plane);
  1129. struct drm_gem_object *msm_framebuffer_bo(struct drm_framebuffer *fb, int plane);
  1130. const struct msm_format *msm_framebuffer_format(struct drm_framebuffer *fb);
  1131. struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev,
  1132. const struct drm_mode_fb_cmd2 *mode_cmd,
  1133. struct drm_gem_object **bos);
  1134. struct drm_framebuffer *msm_framebuffer_create(struct drm_device *dev,
  1135. struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd);
  1136. int msm_framebuffer_set_cache_hint(struct drm_framebuffer *fb,
  1137. u32 flags, u32 rd_type, u32 wr_type);
  1138. int msm_framebuffer_get_cache_hint(struct drm_framebuffer *fb,
  1139. u32 *flags, u32 *rd_type, u32 *wr_type);
  1140. struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev);
  1141. void msm_fbdev_free(struct drm_device *dev);
  1142. struct hdmi;
  1143. #if IS_ENABLED(CONFIG_DRM_MSM_HDMI)
  1144. int msm_hdmi_modeset_init(struct hdmi *hdmi, struct drm_device *dev,
  1145. struct drm_encoder *encoder);
  1146. void __init msm_hdmi_register(void);
  1147. void __exit msm_hdmi_unregister(void);
  1148. #else
  1149. static inline void __init msm_hdmi_register(void)
  1150. {
  1151. }
  1152. static inline void __exit msm_hdmi_unregister(void)
  1153. {
  1154. }
  1155. #endif /* CONFIG_DRM_MSM_HDMI */
  1156. struct msm_edp;
  1157. #if IS_ENABLED(CONFIG_DRM_MSM_EDP)
  1158. void __init msm_edp_register(void);
  1159. void __exit msm_edp_unregister(void);
  1160. int msm_edp_modeset_init(struct msm_edp *edp, struct drm_device *dev,
  1161. struct drm_encoder *encoder);
  1162. #else
  1163. static inline void __init msm_edp_register(void)
  1164. {
  1165. }
  1166. static inline void __exit msm_edp_unregister(void)
  1167. {
  1168. }
  1169. static inline int msm_edp_modeset_init(struct msm_edp *edp,
  1170. struct drm_device *dev, struct drm_encoder *encoder)
  1171. {
  1172. return -EINVAL;
  1173. }
  1174. #endif /* CONFIG_DRM_MSM_EDP */
  1175. struct msm_dsi;
  1176. /* *
  1177. * msm_mode_object_event_notify - notify user-space clients of drm object
  1178. * events.
  1179. * @obj: mode object (crtc/connector) that is generating the event.
  1180. * @event: event that needs to be notified.
  1181. * @payload: payload for the event.
  1182. */
  1183. void msm_mode_object_event_notify(struct drm_mode_object *obj,
  1184. struct drm_device *dev, struct drm_event *event, u8 *payload);
  1185. #if IS_ENABLED(CONFIG_DRM_MSM_DSI)
  1186. static inline void __init msm_dsi_register(void)
  1187. {
  1188. }
  1189. static inline void __exit msm_dsi_unregister(void)
  1190. {
  1191. }
  1192. static inline int msm_dsi_modeset_init(struct msm_dsi *msm_dsi,
  1193. struct drm_device *dev,
  1194. struct drm_encoder *encoder)
  1195. {
  1196. return -EINVAL;
  1197. }
  1198. #else
  1199. void __init msm_dsi_register(void);
  1200. void __exit msm_dsi_unregister(void);
  1201. int msm_dsi_modeset_init(struct msm_dsi *msm_dsi, struct drm_device *dev,
  1202. struct drm_encoder *encoder);
  1203. #endif /* CONFIG_DRM_MSM_DSI */
  1204. #if IS_ENABLED(CONFIG_DRM_MSM_MDP5)
  1205. void __init msm_mdp_register(void);
  1206. void __exit msm_mdp_unregister(void);
  1207. #else
  1208. static inline void __init msm_mdp_register(void)
  1209. {
  1210. }
  1211. static inline void __exit msm_mdp_unregister(void)
  1212. {
  1213. }
  1214. #endif /* CONFIG_DRM_MSM_MDP5 */
  1215. #if IS_ENABLED(CONFIG_DEBUG_FS)
  1216. int msm_debugfs_late_init(struct drm_device *dev);
  1217. int msm_rd_debugfs_init(struct drm_minor *minor);
  1218. void msm_rd_debugfs_cleanup(struct msm_drm_private *priv);
  1219. __printf(3, 4)
  1220. void msm_rd_dump_submit(struct msm_rd_state *rd, struct msm_gem_submit *submit,
  1221. const char *fmt, ...);
  1222. int msm_perf_debugfs_init(struct drm_minor *minor);
  1223. void msm_perf_debugfs_cleanup(struct msm_drm_private *priv);
  1224. #else
  1225. static inline int msm_debugfs_late_init(struct drm_device *dev) { return 0; }
  1226. __printf(3, 4)
  1227. static inline void msm_rd_dump_submit(struct msm_rd_state *rd, struct msm_gem_submit *submit,
  1228. const char *fmt, ...) {}
  1229. static inline void msm_rd_debugfs_cleanup(struct msm_drm_private *priv) {}
  1230. static inline void msm_perf_debugfs_cleanup(struct msm_drm_private *priv) {}
  1231. #endif /* CONFIG_DEBUG_FS */
  1232. #if IS_ENABLED(CONFIG_DRM_MSM_DSI)
  1233. void __init dsi_display_register(void);
  1234. void __exit dsi_display_unregister(void);
  1235. #else
  1236. static inline void __init dsi_display_register(void)
  1237. {
  1238. }
  1239. static inline void __exit dsi_display_unregister(void)
  1240. {
  1241. }
  1242. #endif /* CONFIG_DRM_MSM_DSI */
  1243. #if IS_ENABLED(CONFIG_HDCP_QSEECOM)
  1244. void __init msm_hdcp_register(void);
  1245. void __exit msm_hdcp_unregister(void);
  1246. #else
  1247. static inline void __init msm_hdcp_register(void)
  1248. {
  1249. }
  1250. static inline void __exit msm_hdcp_unregister(void)
  1251. {
  1252. }
  1253. #endif /* CONFIG_HDCP_QSEECOM */
  1254. #if IS_ENABLED(CONFIG_DRM_MSM_DP)
  1255. void __init dp_display_register(void);
  1256. void __exit dp_display_unregister(void);
  1257. #else
  1258. static inline void __init dp_display_register(void)
  1259. {
  1260. }
  1261. static inline void __exit dp_display_unregister(void)
  1262. {
  1263. }
  1264. #endif /* CONFIG_DRM_MSM_DP */
  1265. #if IS_ENABLED(CONFIG_DRM_SDE_RSC)
  1266. void __init sde_rsc_register(void);
  1267. void __exit sde_rsc_unregister(void);
  1268. void __init sde_rsc_rpmh_register(void);
  1269. #else
  1270. static inline void __init sde_rsc_register(void)
  1271. {
  1272. }
  1273. static inline void __exit sde_rsc_unregister(void)
  1274. {
  1275. }
  1276. static inline void __init sde_rsc_rpmh_register(void)
  1277. {
  1278. }
  1279. #endif /* CONFIG_DRM_SDE_RSC */
  1280. #if IS_ENABLED(CONFIG_DRM_SDE_WB)
  1281. void __init sde_wb_register(void);
  1282. void __exit sde_wb_unregister(void);
  1283. #else
  1284. static inline void __init sde_wb_register(void)
  1285. {
  1286. }
  1287. static inline void __exit sde_wb_unregister(void)
  1288. {
  1289. }
  1290. #endif /* CONFIG_DRM_SDE_WB */
  1291. #if IS_ENABLED(CONFIG_MSM_SDE_ROTATOR)
  1292. void sde_rotator_register(void);
  1293. void sde_rotator_unregister(void);
  1294. #else
  1295. static inline void sde_rotator_register(void)
  1296. {
  1297. }
  1298. static inline void sde_rotator_unregister(void)
  1299. {
  1300. }
  1301. #endif /* CONFIG_MSM_SDE_ROTATOR */
  1302. #if IS_ENABLED(CONFIG_MSM_SDE_ROTATOR)
  1303. void sde_rotator_smmu_driver_register(void);
  1304. void sde_rotator_smmu_driver_unregister(void);
  1305. #else
  1306. static inline void sde_rotator_smmu_driver_register(void)
  1307. {
  1308. }
  1309. static inline void sde_rotator_smmu_driver_unregister(void)
  1310. {
  1311. }
  1312. #endif /* CONFIG_MSM_SDE_ROTATOR */
  1313. struct clk *msm_clk_get(struct platform_device *pdev, const char *name);
  1314. int msm_clk_bulk_get(struct device *dev, struct clk_bulk_data **bulk);
  1315. struct clk *msm_clk_bulk_get_clock(struct clk_bulk_data *bulk, int count,
  1316. const char *name);
  1317. void __iomem *msm_ioremap(struct platform_device *pdev, const char *name,
  1318. const char *dbgname);
  1319. unsigned long msm_iomap_size(struct platform_device *pdev, const char *name);
  1320. unsigned long msm_get_phys_addr(struct platform_device *pdev, const char *name);
  1321. void msm_iounmap(struct platform_device *dev, void __iomem *addr);
  1322. void msm_writel(u32 data, void __iomem *addr);
  1323. u32 msm_readl(const void __iomem *addr);
  1324. #define DBG(fmt, ...) DRM_DEBUG_DRIVER(fmt"\n", ##__VA_ARGS__)
  1325. #define VERB(fmt, ...) if (0) DRM_DEBUG_DRIVER(fmt"\n", ##__VA_ARGS__)
  1326. static inline int align_pitch(int width, int bpp)
  1327. {
  1328. int bytespp = (bpp + 7) / 8;
  1329. /* adreno needs pitch aligned to 32 pixels: */
  1330. return bytespp * ALIGN(width, 32);
  1331. }
  1332. /* for the generated headers: */
  1333. #define INVALID_IDX(idx) ({BUG(); 0;})
  1334. #define fui(x) ({BUG(); 0;})
  1335. #define util_float_to_half(x) ({BUG(); 0;})
  1336. #define FIELD(val, name) (((val) & name ## __MASK) >> name ## __SHIFT)
  1337. /* for conditionally setting boolean flag(s): */
  1338. #define COND(bool, val) ((bool) ? (val) : 0)
  1339. static inline unsigned long timeout_to_jiffies(const ktime_t *timeout)
  1340. {
  1341. ktime_t now = ktime_get();
  1342. unsigned long remaining_jiffies;
  1343. if (ktime_compare(*timeout, now) < 0) {
  1344. remaining_jiffies = 0;
  1345. } else {
  1346. ktime_t rem = ktime_sub(*timeout, now);
  1347. remaining_jiffies = nsecs_to_jiffies(ktime_to_ns(rem));
  1348. }
  1349. return remaining_jiffies;
  1350. }
  1351. int msm_get_mixer_count(struct msm_drm_private *priv,
  1352. const struct drm_display_mode *mode,
  1353. const struct msm_resource_caps_info *res, u32 *num_lm);
  1354. int msm_get_dsc_count(struct msm_drm_private *priv,
  1355. u32 hdisplay, u32 *num_dsc);
  1356. int msm_get_src_bpc(int chroma_format, int bpc);
  1357. #endif /* __MSM_DRV_H__ */