msm_drv.h 46 KB

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