msm_drv.h 48 KB

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