msm_drv.h 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  1. /*
  2. * Copyright (c) 2016-2019, 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/sizes.h>
  36. #include <linux/kthread.h>
  37. #include <drm/drmP.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/drm_gem.h>
  44. #include "sde_power_handle.h"
  45. #define GET_MAJOR_REV(rev) ((rev) >> 28)
  46. #define GET_MINOR_REV(rev) (((rev) >> 16) & 0xFFF)
  47. #define GET_STEP_REV(rev) ((rev) & 0xFFFF)
  48. struct msm_kms;
  49. struct msm_gpu;
  50. struct msm_mmu;
  51. struct msm_mdss;
  52. struct msm_rd_state;
  53. struct msm_perf_state;
  54. struct msm_gem_submit;
  55. struct msm_fence_context;
  56. struct msm_fence_cb;
  57. struct msm_gem_address_space;
  58. struct msm_gem_vma;
  59. #define NUM_DOMAINS 4 /* one for KMS, then one per gpu core (?) */
  60. #define MAX_CRTCS 16
  61. #define MAX_PLANES 20
  62. #define MAX_ENCODERS 16
  63. #define MAX_BRIDGES 16
  64. #define MAX_CONNECTORS 16
  65. #define TEARDOWN_DEADLOCK_RETRY_MAX 5
  66. struct msm_file_private {
  67. rwlock_t queuelock;
  68. struct list_head submitqueues;
  69. int queueid;
  70. /* update the refcount when user driver calls power_ctrl IOCTL */
  71. unsigned short enable_refcnt;
  72. /* protects enable_refcnt */
  73. struct mutex power_lock;
  74. };
  75. enum msm_mdp_plane_property {
  76. /* blob properties, always put these first */
  77. PLANE_PROP_CSC_V1,
  78. PLANE_PROP_CSC_DMA_V1,
  79. PLANE_PROP_INFO,
  80. PLANE_PROP_SCALER_LUT_ED,
  81. PLANE_PROP_SCALER_LUT_CIR,
  82. PLANE_PROP_SCALER_LUT_SEP,
  83. PLANE_PROP_SKIN_COLOR,
  84. PLANE_PROP_SKY_COLOR,
  85. PLANE_PROP_FOLIAGE_COLOR,
  86. PLANE_PROP_VIG_GAMUT,
  87. PLANE_PROP_VIG_IGC,
  88. PLANE_PROP_DMA_IGC,
  89. PLANE_PROP_DMA_GC,
  90. /* # of blob properties */
  91. PLANE_PROP_BLOBCOUNT,
  92. /* range properties */
  93. PLANE_PROP_ZPOS = PLANE_PROP_BLOBCOUNT,
  94. PLANE_PROP_ALPHA,
  95. PLANE_PROP_COLOR_FILL,
  96. PLANE_PROP_H_DECIMATE,
  97. PLANE_PROP_V_DECIMATE,
  98. PLANE_PROP_INPUT_FENCE,
  99. PLANE_PROP_HUE_ADJUST,
  100. PLANE_PROP_SATURATION_ADJUST,
  101. PLANE_PROP_VALUE_ADJUST,
  102. PLANE_PROP_CONTRAST_ADJUST,
  103. PLANE_PROP_EXCL_RECT_V1,
  104. PLANE_PROP_PREFILL_SIZE,
  105. PLANE_PROP_PREFILL_TIME,
  106. PLANE_PROP_SCALER_V1,
  107. PLANE_PROP_SCALER_V2,
  108. PLANE_PROP_INVERSE_PMA,
  109. /* enum/bitmask properties */
  110. PLANE_PROP_BLEND_OP,
  111. PLANE_PROP_SRC_CONFIG,
  112. PLANE_PROP_FB_TRANSLATION_MODE,
  113. PLANE_PROP_MULTIRECT_MODE,
  114. /* total # of properties */
  115. PLANE_PROP_COUNT
  116. };
  117. enum msm_mdp_crtc_property {
  118. CRTC_PROP_INFO,
  119. CRTC_PROP_DEST_SCALER_LUT_ED,
  120. CRTC_PROP_DEST_SCALER_LUT_CIR,
  121. CRTC_PROP_DEST_SCALER_LUT_SEP,
  122. /* # of blob properties */
  123. CRTC_PROP_BLOBCOUNT,
  124. /* range properties */
  125. CRTC_PROP_INPUT_FENCE_TIMEOUT = CRTC_PROP_BLOBCOUNT,
  126. CRTC_PROP_OUTPUT_FENCE,
  127. CRTC_PROP_OUTPUT_FENCE_OFFSET,
  128. CRTC_PROP_DIM_LAYER_V1,
  129. CRTC_PROP_CORE_CLK,
  130. CRTC_PROP_CORE_AB,
  131. CRTC_PROP_CORE_IB,
  132. CRTC_PROP_LLCC_AB,
  133. CRTC_PROP_LLCC_IB,
  134. CRTC_PROP_DRAM_AB,
  135. CRTC_PROP_DRAM_IB,
  136. CRTC_PROP_ROT_PREFILL_BW,
  137. CRTC_PROP_ROT_CLK,
  138. CRTC_PROP_ROI_V1,
  139. CRTC_PROP_SECURITY_LEVEL,
  140. CRTC_PROP_IDLE_TIMEOUT,
  141. CRTC_PROP_DEST_SCALER,
  142. CRTC_PROP_CAPTURE_OUTPUT,
  143. CRTC_PROP_IDLE_PC_STATE,
  144. /* total # of properties */
  145. CRTC_PROP_COUNT
  146. };
  147. enum msm_mdp_conn_property {
  148. /* blob properties, always put these first */
  149. CONNECTOR_PROP_SDE_INFO,
  150. CONNECTOR_PROP_MODE_INFO,
  151. CONNECTOR_PROP_HDR_INFO,
  152. CONNECTOR_PROP_EXT_HDR_INFO,
  153. CONNECTOR_PROP_PP_DITHER,
  154. CONNECTOR_PROP_HDR_METADATA,
  155. /* # of blob properties */
  156. CONNECTOR_PROP_BLOBCOUNT,
  157. /* range properties */
  158. CONNECTOR_PROP_OUT_FB = CONNECTOR_PROP_BLOBCOUNT,
  159. CONNECTOR_PROP_RETIRE_FENCE,
  160. CONNECTOR_PROP_DST_X,
  161. CONNECTOR_PROP_DST_Y,
  162. CONNECTOR_PROP_DST_W,
  163. CONNECTOR_PROP_DST_H,
  164. CONNECTOR_PROP_ROI_V1,
  165. CONNECTOR_PROP_BL_SCALE,
  166. CONNECTOR_PROP_SV_BL_SCALE,
  167. CONNECTOR_PROP_SUPPORTED_COLORSPACES,
  168. /* enum/bitmask properties */
  169. CONNECTOR_PROP_TOPOLOGY_NAME,
  170. CONNECTOR_PROP_TOPOLOGY_CONTROL,
  171. CONNECTOR_PROP_AUTOREFRESH,
  172. CONNECTOR_PROP_LP,
  173. CONNECTOR_PROP_FB_TRANSLATION_MODE,
  174. CONNECTOR_PROP_QSYNC_MODE,
  175. CONNECTOR_PROP_CMD_FRAME_TRIGGER_MODE,
  176. /* total # of properties */
  177. CONNECTOR_PROP_COUNT
  178. };
  179. #define MSM_GPU_MAX_RINGS 4
  180. #define MAX_H_TILES_PER_DISPLAY 2
  181. /**
  182. * enum msm_display_compression_type - compression method used for pixel stream
  183. * @MSM_DISPLAY_COMPRESSION_NONE: Pixel data is not compressed
  184. * @MSM_DISPLAY_COMPRESSION_DSC: DSC compresison is used
  185. */
  186. enum msm_display_compression_type {
  187. MSM_DISPLAY_COMPRESSION_NONE,
  188. MSM_DISPLAY_COMPRESSION_DSC,
  189. };
  190. /**
  191. * enum msm_display_compression_ratio - compression ratio
  192. * @MSM_DISPLAY_COMPRESSION_NONE: no compression
  193. * @MSM_DISPLAY_COMPRESSION_RATIO_2_TO_1: 2 to 1 compression
  194. * @MSM_DISPLAY_COMPRESSION_RATIO_3_TO_1: 3 to 1 compression
  195. */
  196. enum msm_display_compression_ratio {
  197. MSM_DISPLAY_COMPRESSION_RATIO_NONE,
  198. MSM_DISPLAY_COMPRESSION_RATIO_2_TO_1,
  199. MSM_DISPLAY_COMPRESSION_RATIO_3_TO_1,
  200. MSM_DISPLAY_COMPRESSION_RATIO_MAX,
  201. };
  202. /**
  203. * enum msm_display_caps - features/capabilities supported by displays
  204. * @MSM_DISPLAY_CAP_VID_MODE: Video or "active" mode supported
  205. * @MSM_DISPLAY_CAP_CMD_MODE: Command mode supported
  206. * @MSM_DISPLAY_CAP_HOT_PLUG: Hot plug detection supported
  207. * @MSM_DISPLAY_CAP_EDID: EDID supported
  208. * @MSM_DISPLAY_ESD_ENABLED: ESD feature enabled
  209. * @MSM_DISPLAY_CAP_MST_MODE: Display with MST support
  210. * @MSM_DISPLAY_SPLIT_LINK: Split Link enabled
  211. */
  212. enum msm_display_caps {
  213. MSM_DISPLAY_CAP_VID_MODE = BIT(0),
  214. MSM_DISPLAY_CAP_CMD_MODE = BIT(1),
  215. MSM_DISPLAY_CAP_HOT_PLUG = BIT(2),
  216. MSM_DISPLAY_CAP_EDID = BIT(3),
  217. MSM_DISPLAY_ESD_ENABLED = BIT(4),
  218. MSM_DISPLAY_CAP_MST_MODE = BIT(5),
  219. MSM_DISPLAY_SPLIT_LINK = BIT(6),
  220. };
  221. /**
  222. * enum panel_mode - panel operation mode
  223. * @MSM_DISPLAY_VIDEO_MODE: video mode panel
  224. * @MSM_DISPLAY_CMD_MODE: Command mode panel
  225. * @MODE_MAX:
  226. */
  227. enum panel_op_mode {
  228. MSM_DISPLAY_VIDEO_MODE = 0,
  229. MSM_DISPLAY_CMD_MODE,
  230. MSM_DISPLAY_MODE_MAX,
  231. };
  232. /**
  233. * enum msm_event_wait - type of HW events to wait for
  234. * @MSM_ENC_COMMIT_DONE - wait for the driver to flush the registers to HW
  235. * @MSM_ENC_TX_COMPLETE - wait for the HW to transfer the frame to panel
  236. * @MSM_ENC_VBLANK - wait for the HW VBLANK event (for driver-internal waiters)
  237. * @MSM_ENC_ACTIVE_REGION - wait for the TG to be in active pixel region
  238. */
  239. enum msm_event_wait {
  240. MSM_ENC_COMMIT_DONE = 0,
  241. MSM_ENC_TX_COMPLETE,
  242. MSM_ENC_VBLANK,
  243. MSM_ENC_ACTIVE_REGION,
  244. };
  245. /**
  246. * struct msm_roi_alignment - region of interest alignment restrictions
  247. * @xstart_pix_align: left x offset alignment restriction
  248. * @width_pix_align: width alignment restriction
  249. * @ystart_pix_align: top y offset alignment restriction
  250. * @height_pix_align: height alignment restriction
  251. * @min_width: minimum width restriction
  252. * @min_height: minimum height restriction
  253. */
  254. struct msm_roi_alignment {
  255. uint32_t xstart_pix_align;
  256. uint32_t width_pix_align;
  257. uint32_t ystart_pix_align;
  258. uint32_t height_pix_align;
  259. uint32_t min_width;
  260. uint32_t min_height;
  261. };
  262. /**
  263. * struct msm_roi_caps - display's region of interest capabilities
  264. * @enabled: true if some region of interest is supported
  265. * @merge_rois: merge rois before sending to display
  266. * @num_roi: maximum number of rois supported
  267. * @align: roi alignment restrictions
  268. */
  269. struct msm_roi_caps {
  270. bool enabled;
  271. bool merge_rois;
  272. uint32_t num_roi;
  273. struct msm_roi_alignment align;
  274. };
  275. /**
  276. * struct msm_display_dsc_info - defines dsc configuration
  277. * @version: DSC version.
  278. * @scr_rev: DSC revision.
  279. * @pic_height: Picture height in pixels.
  280. * @pic_width: Picture width in pixels.
  281. * @initial_lines: Number of initial lines stored in encoder.
  282. * @pkt_per_line: Number of packets per line.
  283. * @bytes_in_slice: Number of bytes in slice.
  284. * @eol_byte_num: Valid bytes at the end of line.
  285. * @pclk_per_line: Compressed width.
  286. * @full_frame_slices: Number of slice per interface.
  287. * @slice_height: Slice height in pixels.
  288. * @slice_width: Slice width in pixels.
  289. * @chunk_size: Chunk size in bytes for slice multiplexing.
  290. * @slice_last_group_size: Size of last group in pixels.
  291. * @bpp: Target bits per pixel.
  292. * @bpc: Number of bits per component.
  293. * @line_buf_depth: Line buffer bit depth.
  294. * @block_pred_enable: Block prediction enabled/disabled.
  295. * @vbr_enable: VBR mode.
  296. * @enable_422: Indicates if input uses 4:2:2 sampling.
  297. * @convert_rgb: DSC color space conversion.
  298. * @input_10_bits: 10 bit per component input.
  299. * @slice_per_pkt: Number of slices per packet.
  300. * @initial_dec_delay: Initial decoding delay.
  301. * @initial_xmit_delay: Initial transmission delay.
  302. * @initial_scale_value: Scale factor value at the beginning of a slice.
  303. * @scale_decrement_interval: Scale set up at the beginning of a slice.
  304. * @scale_increment_interval: Scale set up at the end of a slice.
  305. * @first_line_bpg_offset: Extra bits allocated on the first line of a slice.
  306. * @nfl_bpg_offset: Slice specific settings.
  307. * @slice_bpg_offset: Slice specific settings.
  308. * @initial_offset: Initial offset at the start of a slice.
  309. * @final_offset: Maximum end-of-slice value.
  310. * @rc_model_size: Number of bits in RC model.
  311. * @det_thresh_flatness: Flatness threshold.
  312. * @max_qp_flatness: Maximum QP for flatness adjustment.
  313. * @min_qp_flatness: Minimum QP for flatness adjustment.
  314. * @edge_factor: Ratio to detect presence of edge.
  315. * @quant_incr_limit0: QP threshold.
  316. * @quant_incr_limit1: QP threshold.
  317. * @tgt_offset_hi: Upper end of variability range.
  318. * @tgt_offset_lo: Lower end of variability range.
  319. * @buf_thresh: Thresholds in RC model
  320. * @range_min_qp: Min QP allowed.
  321. * @range_max_qp: Max QP allowed.
  322. * @range_bpg_offset: Bits per group adjustment.
  323. * @extra_width: Extra width required in timing calculations.
  324. * @pps_delay_ms: Post PPS command delay in milliseconds.
  325. */
  326. struct msm_display_dsc_info {
  327. u8 version;
  328. u8 scr_rev;
  329. int pic_height;
  330. int pic_width;
  331. int slice_height;
  332. int slice_width;
  333. int initial_lines;
  334. int pkt_per_line;
  335. int bytes_in_slice;
  336. int bytes_per_pkt;
  337. int eol_byte_num;
  338. int pclk_per_line;
  339. int full_frame_slices;
  340. int slice_last_group_size;
  341. int bpp;
  342. int bpc;
  343. int line_buf_depth;
  344. int slice_per_pkt;
  345. int chunk_size;
  346. bool block_pred_enable;
  347. int vbr_enable;
  348. int enable_422;
  349. int convert_rgb;
  350. int input_10_bits;
  351. int initial_dec_delay;
  352. int initial_xmit_delay;
  353. int initial_scale_value;
  354. int scale_decrement_interval;
  355. int scale_increment_interval;
  356. int first_line_bpg_offset;
  357. int nfl_bpg_offset;
  358. int slice_bpg_offset;
  359. int initial_offset;
  360. int final_offset;
  361. int rc_model_size;
  362. int det_thresh_flatness;
  363. int max_qp_flatness;
  364. int min_qp_flatness;
  365. int edge_factor;
  366. int quant_incr_limit0;
  367. int quant_incr_limit1;
  368. int tgt_offset_hi;
  369. int tgt_offset_lo;
  370. u32 *buf_thresh;
  371. char *range_min_qp;
  372. char *range_max_qp;
  373. char *range_bpg_offset;
  374. u32 extra_width;
  375. u32 pps_delay_ms;
  376. };
  377. /**
  378. * struct msm_compression_info - defined panel compression
  379. * @comp_type: type of compression supported
  380. * @comp_ratio: compression ratio
  381. * @dsc_info: dsc configuration if the compression
  382. * supported is DSC
  383. */
  384. struct msm_compression_info {
  385. enum msm_display_compression_type comp_type;
  386. enum msm_display_compression_ratio comp_ratio;
  387. union{
  388. struct msm_display_dsc_info dsc_info;
  389. };
  390. };
  391. /**
  392. * struct msm_display_topology - defines a display topology pipeline
  393. * @num_lm: number of layer mixers used
  394. * @num_enc: number of compression encoder blocks used
  395. * @num_intf: number of interfaces the panel is mounted on
  396. */
  397. struct msm_display_topology {
  398. u32 num_lm;
  399. u32 num_enc;
  400. u32 num_intf;
  401. };
  402. /**
  403. * struct msm_mode_info - defines all msm custom mode info
  404. * @frame_rate: frame_rate of the mode
  405. * @vtotal: vtotal calculated for the mode
  406. * @prefill_lines: prefill lines based on porches.
  407. * @jitter_numer: display panel jitter numerator configuration
  408. * @jitter_denom: display panel jitter denominator configuration
  409. * @clk_rate: DSI bit clock per lane in HZ.
  410. * @topology: supported topology for the mode
  411. * @comp_info: compression info supported
  412. * @roi_caps: panel roi capabilities
  413. * @wide_bus_en: wide-bus mode cfg for interface module
  414. * @mdp_transfer_time_us Specifies the mdp transfer time for command mode
  415. * panels in microseconds.
  416. */
  417. struct msm_mode_info {
  418. uint32_t frame_rate;
  419. uint32_t vtotal;
  420. uint32_t prefill_lines;
  421. uint32_t jitter_numer;
  422. uint32_t jitter_denom;
  423. uint64_t clk_rate;
  424. struct msm_display_topology topology;
  425. struct msm_compression_info comp_info;
  426. struct msm_roi_caps roi_caps;
  427. bool wide_bus_en;
  428. u32 mdp_transfer_time_us;
  429. };
  430. /**
  431. * struct msm_resource_caps_info - defines hw resources
  432. * @num_lm number of layer mixers available
  433. * @num_dsc number of dsc available
  434. * @num_ctl number of ctl available
  435. * @num_3dmux number of 3d mux available
  436. * @max_mixer_width: max width supported by layer mixer
  437. */
  438. struct msm_resource_caps_info {
  439. uint32_t num_lm;
  440. uint32_t num_dsc;
  441. uint32_t num_ctl;
  442. uint32_t num_3dmux;
  443. uint32_t max_mixer_width;
  444. };
  445. /**
  446. * struct msm_display_info - defines display properties
  447. * @intf_type: DRM_MODE_CONNECTOR_ display type
  448. * @capabilities: Bitmask of display flags
  449. * @num_of_h_tiles: Number of horizontal tiles in case of split interface
  450. * @h_tile_instance: Controller instance used per tile. Number of elements is
  451. * based on num_of_h_tiles
  452. * @is_connected: Set to true if display is connected
  453. * @width_mm: Physical width
  454. * @height_mm: Physical height
  455. * @max_width: Max width of display. In case of hot pluggable display
  456. * this is max width supported by controller
  457. * @max_height: Max height of display. In case of hot pluggable display
  458. * this is max height supported by controller
  459. * @clk_rate: DSI bit clock per lane in HZ.
  460. * @display_type: Enum for type of display
  461. * @is_te_using_watchdog_timer: Boolean to indicate watchdog TE is
  462. * used instead of panel TE in cmd mode panels
  463. * @roi_caps: Region of interest capability info
  464. * @qsync_min_fps Minimum fps supported by Qsync feature
  465. * @te_source vsync source pin information
  466. */
  467. struct msm_display_info {
  468. int intf_type;
  469. uint32_t capabilities;
  470. enum panel_op_mode curr_panel_mode;
  471. uint32_t num_of_h_tiles;
  472. uint32_t h_tile_instance[MAX_H_TILES_PER_DISPLAY];
  473. bool is_connected;
  474. unsigned int width_mm;
  475. unsigned int height_mm;
  476. uint32_t max_width;
  477. uint32_t max_height;
  478. uint64_t clk_rate;
  479. uint32_t display_type;
  480. bool is_te_using_watchdog_timer;
  481. struct msm_roi_caps roi_caps;
  482. uint32_t qsync_min_fps;
  483. uint32_t te_source;
  484. };
  485. #define MSM_MAX_ROI 4
  486. /**
  487. * struct msm_roi_list - list of regions of interest for a drm object
  488. * @num_rects: number of valid rectangles in the roi array
  489. * @roi: list of roi rectangles
  490. */
  491. struct msm_roi_list {
  492. uint32_t num_rects;
  493. struct drm_clip_rect roi[MSM_MAX_ROI];
  494. };
  495. /**
  496. * struct - msm_display_kickoff_params - info for display features at kickoff
  497. * @rois: Regions of interest structure for mapping CRTC to Connector output
  498. */
  499. struct msm_display_kickoff_params {
  500. struct msm_roi_list *rois;
  501. struct drm_msm_ext_hdr_metadata *hdr_meta;
  502. };
  503. /**
  504. * struct - msm_display_conn_params - info of dpu display features
  505. * @qsync_mode: Qsync mode, where 0: disabled 1: continuous mode 2: oneshot
  506. * @qsync_update: Qsync settings were changed/updated
  507. */
  508. struct msm_display_conn_params {
  509. uint32_t qsync_mode;
  510. bool qsync_update;
  511. };
  512. /**
  513. * struct msm_drm_event - defines custom event notification struct
  514. * @base: base object required for event notification by DRM framework.
  515. * @event: event object required for event notification by DRM framework.
  516. * @info: contains information of DRM object for which events has been
  517. * requested.
  518. * @data: memory location which contains response payload for event.
  519. */
  520. struct msm_drm_event {
  521. struct drm_pending_event base;
  522. struct drm_event event;
  523. struct drm_msm_event_req info;
  524. u8 data[];
  525. };
  526. /* Commit/Event thread specific structure */
  527. struct msm_drm_thread {
  528. struct drm_device *dev;
  529. struct task_struct *thread;
  530. unsigned int crtc_id;
  531. struct kthread_worker worker;
  532. };
  533. struct msm_drm_private {
  534. struct drm_device *dev;
  535. struct msm_kms *kms;
  536. struct sde_power_handle phandle;
  537. /* subordinate devices, if present: */
  538. struct platform_device *gpu_pdev;
  539. /* top level MDSS wrapper device (for MDP5 only) */
  540. struct msm_mdss *mdss;
  541. /* possibly this should be in the kms component, but it is
  542. * shared by both mdp4 and mdp5..
  543. */
  544. struct hdmi *hdmi;
  545. /* eDP is for mdp5 only, but kms has not been created
  546. * when edp_bind() and edp_init() are called. Here is the only
  547. * place to keep the edp instance.
  548. */
  549. struct msm_edp *edp;
  550. /* DSI is shared by mdp4 and mdp5 */
  551. struct msm_dsi *dsi[2];
  552. /* when we have more than one 'msm_gpu' these need to be an array: */
  553. struct msm_gpu *gpu;
  554. struct msm_file_private *lastctx;
  555. struct drm_fb_helper *fbdev;
  556. struct msm_rd_state *rd; /* debugfs to dump all submits */
  557. struct msm_rd_state *hangrd; /* debugfs to dump hanging submits */
  558. struct msm_perf_state *perf;
  559. /* list of GEM objects: */
  560. struct list_head inactive_list;
  561. struct workqueue_struct *wq;
  562. /* crtcs pending async atomic updates: */
  563. uint32_t pending_crtcs;
  564. uint32_t pending_planes;
  565. wait_queue_head_t pending_crtcs_event;
  566. unsigned int num_planes;
  567. struct drm_plane *planes[MAX_PLANES];
  568. unsigned int num_crtcs;
  569. struct drm_crtc *crtcs[MAX_CRTCS];
  570. struct msm_drm_thread disp_thread[MAX_CRTCS];
  571. struct msm_drm_thread event_thread[MAX_CRTCS];
  572. struct task_struct *pp_event_thread;
  573. struct kthread_worker pp_event_worker;
  574. unsigned int num_encoders;
  575. struct drm_encoder *encoders[MAX_ENCODERS];
  576. unsigned int num_bridges;
  577. struct drm_bridge *bridges[MAX_BRIDGES];
  578. unsigned int num_connectors;
  579. struct drm_connector *connectors[MAX_CONNECTORS];
  580. /* Properties */
  581. struct drm_property *plane_property[PLANE_PROP_COUNT];
  582. struct drm_property *crtc_property[CRTC_PROP_COUNT];
  583. struct drm_property *conn_property[CONNECTOR_PROP_COUNT];
  584. /* Color processing properties for the crtc */
  585. struct drm_property **cp_property;
  586. /* VRAM carveout, used when no IOMMU: */
  587. struct {
  588. unsigned long size;
  589. dma_addr_t paddr;
  590. /* NOTE: mm managed at the page level, size is in # of pages
  591. * and position mm_node->start is in # of pages:
  592. */
  593. struct drm_mm mm;
  594. spinlock_t lock; /* Protects drm_mm node allocation/removal */
  595. } vram;
  596. struct notifier_block vmap_notifier;
  597. struct shrinker shrinker;
  598. struct drm_atomic_state *pm_state;
  599. /* task holding struct_mutex.. currently only used in submit path
  600. * to detect and reject faults from copy_from_user() for submit
  601. * ioctl.
  602. */
  603. struct task_struct *struct_mutex_task;
  604. /* list of clients waiting for events */
  605. struct list_head client_event_list;
  606. /* whether registered and drm_dev_unregister should be called */
  607. bool registered;
  608. /* msm drv debug root node */
  609. struct dentry *debug_root;
  610. /* update the flag when msm driver receives shutdown notification */
  611. bool shutdown_in_progress;
  612. };
  613. /* get struct msm_kms * from drm_device * */
  614. #define ddev_to_msm_kms(D) ((D) && (D)->dev_private ? \
  615. ((struct msm_drm_private *)((D)->dev_private))->kms : NULL)
  616. struct msm_format {
  617. uint32_t pixel_format;
  618. };
  619. int msm_atomic_prepare_fb(struct drm_plane *plane,
  620. struct drm_plane_state *new_state);
  621. void msm_atomic_commit_tail(struct drm_atomic_state *state);
  622. int msm_atomic_commit(struct drm_device *dev,
  623. struct drm_atomic_state *state, bool nonblock);
  624. /* callback from wq once fence has passed: */
  625. struct msm_fence_cb {
  626. struct work_struct work;
  627. uint32_t fence;
  628. void (*func)(struct msm_fence_cb *cb);
  629. };
  630. void __msm_fence_worker(struct work_struct *work);
  631. #define INIT_FENCE_CB(_cb, _func) do { \
  632. INIT_WORK(&(_cb)->work, __msm_fence_worker); \
  633. (_cb)->func = _func; \
  634. } while (0)
  635. struct drm_atomic_state *msm_atomic_state_alloc(struct drm_device *dev);
  636. void msm_atomic_state_clear(struct drm_atomic_state *state);
  637. void msm_atomic_state_free(struct drm_atomic_state *state);
  638. int msm_gem_init_vma(struct msm_gem_address_space *aspace,
  639. struct msm_gem_vma *vma, int npages);
  640. void msm_gem_unmap_vma(struct msm_gem_address_space *aspace,
  641. struct msm_gem_vma *vma, struct sg_table *sgt,
  642. unsigned int flags);
  643. int msm_gem_map_vma(struct msm_gem_address_space *aspace,
  644. struct msm_gem_vma *vma, struct sg_table *sgt, int npages,
  645. unsigned int flags);
  646. struct device *msm_gem_get_aspace_device(struct msm_gem_address_space *aspace);
  647. void msm_gem_address_space_put(struct msm_gem_address_space *aspace);
  648. struct msm_gem_address_space *
  649. msm_gem_address_space_create(struct device *dev, struct iommu_domain *domain,
  650. const char *name);
  651. /* For SDE display */
  652. struct msm_gem_address_space *
  653. msm_gem_smmu_address_space_create(struct drm_device *dev, struct msm_mmu *mmu,
  654. const char *name);
  655. /**
  656. * msm_gem_add_obj_to_aspace_active_list: adds obj to active obj list in aspace
  657. */
  658. void msm_gem_add_obj_to_aspace_active_list(
  659. struct msm_gem_address_space *aspace,
  660. struct drm_gem_object *obj);
  661. /**
  662. * msm_gem_remove_obj_from_aspace_active_list: removes obj from active obj
  663. * list in aspace
  664. */
  665. void msm_gem_remove_obj_from_aspace_active_list(
  666. struct msm_gem_address_space *aspace,
  667. struct drm_gem_object *obj);
  668. /**
  669. * msm_gem_smmu_address_space_get: returns the aspace pointer for the requested
  670. * domain
  671. */
  672. struct msm_gem_address_space *
  673. msm_gem_smmu_address_space_get(struct drm_device *dev,
  674. unsigned int domain);
  675. int msm_register_mmu(struct drm_device *dev, struct msm_mmu *mmu);
  676. void msm_unregister_mmu(struct drm_device *dev, struct msm_mmu *mmu);
  677. /**
  678. * msm_gem_aspace_domain_attach_detach: function to inform the attach/detach
  679. * of the domain for this aspace
  680. */
  681. void msm_gem_aspace_domain_attach_detach_update(
  682. struct msm_gem_address_space *aspace,
  683. bool is_detach);
  684. /**
  685. * msm_gem_address_space_register_cb: function to register callback for attach
  686. * and detach of the domain
  687. */
  688. int msm_gem_address_space_register_cb(
  689. struct msm_gem_address_space *aspace,
  690. void (*cb)(void *, bool),
  691. void *cb_data);
  692. /**
  693. * msm_gem_address_space_register_cb: function to unregister callback
  694. */
  695. int msm_gem_address_space_unregister_cb(
  696. struct msm_gem_address_space *aspace,
  697. void (*cb)(void *, bool),
  698. void *cb_data);
  699. void msm_gem_submit_free(struct msm_gem_submit *submit);
  700. int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
  701. struct drm_file *file);
  702. void msm_gem_shrinker_init(struct drm_device *dev);
  703. void msm_gem_shrinker_cleanup(struct drm_device *dev);
  704. void msm_gem_sync(struct drm_gem_object *obj);
  705. int msm_gem_mmap_obj(struct drm_gem_object *obj,
  706. struct vm_area_struct *vma);
  707. int msm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  708. vm_fault_t msm_gem_fault(struct vm_fault *vmf);
  709. uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj);
  710. int msm_gem_get_iova(struct drm_gem_object *obj,
  711. struct msm_gem_address_space *aspace, uint64_t *iova);
  712. int msm_gem_get_and_pin_iova(struct drm_gem_object *obj,
  713. struct msm_gem_address_space *aspace, uint64_t *iova);
  714. uint64_t msm_gem_iova(struct drm_gem_object *obj,
  715. struct msm_gem_address_space *aspace);
  716. void msm_gem_unpin_iova(struct drm_gem_object *obj,
  717. struct msm_gem_address_space *aspace);
  718. struct page **msm_gem_get_pages(struct drm_gem_object *obj);
  719. void msm_gem_put_pages(struct drm_gem_object *obj);
  720. void msm_gem_put_iova(struct drm_gem_object *obj,
  721. struct msm_gem_address_space *aspace);
  722. dma_addr_t msm_gem_get_dma_addr(struct drm_gem_object *obj);
  723. int msm_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
  724. struct drm_mode_create_dumb *args);
  725. int msm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
  726. uint32_t handle, uint64_t *offset);
  727. struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj);
  728. void *msm_gem_prime_vmap(struct drm_gem_object *obj);
  729. void msm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
  730. int msm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
  731. struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev,
  732. struct dma_buf_attachment *attach, struct sg_table *sg);
  733. int msm_gem_prime_pin(struct drm_gem_object *obj);
  734. void msm_gem_prime_unpin(struct drm_gem_object *obj);
  735. struct drm_gem_object *msm_gem_prime_import(struct drm_device *dev,
  736. struct dma_buf *dma_buf);
  737. void *msm_gem_get_vaddr(struct drm_gem_object *obj);
  738. void *msm_gem_get_vaddr_active(struct drm_gem_object *obj);
  739. void msm_gem_put_vaddr(struct drm_gem_object *obj);
  740. int msm_gem_madvise(struct drm_gem_object *obj, unsigned madv);
  741. int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op, ktime_t *timeout);
  742. int msm_gem_cpu_fini(struct drm_gem_object *obj);
  743. void msm_gem_free_object(struct drm_gem_object *obj);
  744. int msm_gem_new_handle(struct drm_device *dev, struct drm_file *file,
  745. uint32_t size, uint32_t flags, uint32_t *handle, char *name);
  746. struct drm_gem_object *msm_gem_new(struct drm_device *dev,
  747. uint32_t size, uint32_t flags);
  748. struct drm_gem_object *msm_gem_new_locked(struct drm_device *dev,
  749. uint32_t size, uint32_t flags);
  750. void *msm_gem_kernel_new(struct drm_device *dev, uint32_t size,
  751. uint32_t flags, struct msm_gem_address_space *aspace,
  752. struct drm_gem_object **bo, uint64_t *iova);
  753. void *msm_gem_kernel_new_locked(struct drm_device *dev, uint32_t size,
  754. uint32_t flags, struct msm_gem_address_space *aspace,
  755. struct drm_gem_object **bo, uint64_t *iova);
  756. struct drm_gem_object *msm_gem_import(struct drm_device *dev,
  757. struct dma_buf *dmabuf, struct sg_table *sgt);
  758. __printf(2, 3)
  759. void msm_gem_object_set_name(struct drm_gem_object *bo, const char *fmt, ...);
  760. int msm_gem_delayed_import(struct drm_gem_object *obj);
  761. void msm_framebuffer_set_kmap(struct drm_framebuffer *fb, bool enable);
  762. void msm_framebuffer_set_keepattrs(struct drm_framebuffer *fb, bool enable);
  763. int msm_framebuffer_prepare(struct drm_framebuffer *fb,
  764. struct msm_gem_address_space *aspace);
  765. void msm_framebuffer_cleanup(struct drm_framebuffer *fb,
  766. struct msm_gem_address_space *aspace);
  767. uint32_t msm_framebuffer_iova(struct drm_framebuffer *fb,
  768. struct msm_gem_address_space *aspace, int plane);
  769. uint32_t msm_framebuffer_phys(struct drm_framebuffer *fb, int plane);
  770. struct drm_gem_object *msm_framebuffer_bo(struct drm_framebuffer *fb, int plane);
  771. const struct msm_format *msm_framebuffer_format(struct drm_framebuffer *fb);
  772. struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev,
  773. const struct drm_mode_fb_cmd2 *mode_cmd,
  774. struct drm_gem_object **bos);
  775. struct drm_framebuffer *msm_framebuffer_create(struct drm_device *dev,
  776. struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd);
  777. struct drm_framebuffer * msm_alloc_stolen_fb(struct drm_device *dev,
  778. int w, int h, int p, uint32_t format);
  779. struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev);
  780. void msm_fbdev_free(struct drm_device *dev);
  781. struct hdmi;
  782. #ifdef CONFIG_DRM_MSM_HDMI
  783. int msm_hdmi_modeset_init(struct hdmi *hdmi, struct drm_device *dev,
  784. struct drm_encoder *encoder);
  785. void __init msm_hdmi_register(void);
  786. void __exit msm_hdmi_unregister(void);
  787. #else
  788. static inline void __init msm_hdmi_register(void)
  789. {
  790. }
  791. static inline void __exit msm_hdmi_unregister(void)
  792. {
  793. }
  794. #endif
  795. struct msm_edp;
  796. #ifdef CONFIG_DRM_MSM_EDP
  797. void __init msm_edp_register(void);
  798. void __exit msm_edp_unregister(void);
  799. int msm_edp_modeset_init(struct msm_edp *edp, struct drm_device *dev,
  800. struct drm_encoder *encoder);
  801. #else
  802. static inline void __init msm_edp_register(void)
  803. {
  804. }
  805. static inline void __exit msm_edp_unregister(void)
  806. {
  807. }
  808. static inline int msm_edp_modeset_init(struct msm_edp *edp,
  809. struct drm_device *dev, struct drm_encoder *encoder)
  810. {
  811. return -EINVAL;
  812. }
  813. #endif
  814. struct msm_dsi;
  815. /* *
  816. * msm_mode_object_event_notify - notify user-space clients of drm object
  817. * events.
  818. * @obj: mode object (crtc/connector) that is generating the event.
  819. * @event: event that needs to be notified.
  820. * @payload: payload for the event.
  821. */
  822. void msm_mode_object_event_notify(struct drm_mode_object *obj,
  823. struct drm_device *dev, struct drm_event *event, u8 *payload);
  824. #ifndef CONFIG_DRM_MSM_DSI
  825. void __init msm_dsi_register(void);
  826. void __exit msm_dsi_unregister(void);
  827. int msm_dsi_modeset_init(struct msm_dsi *msm_dsi, struct drm_device *dev,
  828. struct drm_encoder *encoder);
  829. #else
  830. static inline void __init msm_dsi_register(void)
  831. {
  832. }
  833. static inline void __exit msm_dsi_unregister(void)
  834. {
  835. }
  836. static inline int msm_dsi_modeset_init(struct msm_dsi *msm_dsi,
  837. struct drm_device *dev,
  838. struct drm_encoder *encoder)
  839. {
  840. return -EINVAL;
  841. }
  842. #endif
  843. #ifdef CONFIG_DRM_MSM_MDP5
  844. void __init msm_mdp_register(void);
  845. void __exit msm_mdp_unregister(void);
  846. #else
  847. static inline void __init msm_mdp_register(void)
  848. {
  849. }
  850. static inline void __exit msm_mdp_unregister(void)
  851. {
  852. }
  853. #endif
  854. #ifdef CONFIG_DEBUG_FS
  855. void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m);
  856. void msm_gem_describe_objects(struct list_head *list, struct seq_file *m);
  857. void msm_framebuffer_describe(struct drm_framebuffer *fb, struct seq_file *m);
  858. int msm_debugfs_late_init(struct drm_device *dev);
  859. int msm_rd_debugfs_init(struct drm_minor *minor);
  860. void msm_rd_debugfs_cleanup(struct msm_drm_private *priv);
  861. __printf(3, 4)
  862. void msm_rd_dump_submit(struct msm_rd_state *rd, struct msm_gem_submit *submit,
  863. const char *fmt, ...);
  864. int msm_perf_debugfs_init(struct drm_minor *minor);
  865. void msm_perf_debugfs_cleanup(struct msm_drm_private *priv);
  866. #else
  867. static inline int msm_debugfs_late_init(struct drm_device *dev) { return 0; }
  868. __printf(3, 4)
  869. static inline void msm_rd_dump_submit(struct msm_rd_state *rd, struct msm_gem_submit *submit,
  870. const char *fmt, ...) {}
  871. static inline void msm_rd_debugfs_cleanup(struct msm_drm_private *priv) {}
  872. static inline void msm_perf_debugfs_cleanup(struct msm_drm_private *priv) {}
  873. #endif
  874. struct clk *msm_clk_get(struct platform_device *pdev, const char *name);
  875. int msm_clk_bulk_get(struct device *dev, struct clk_bulk_data **bulk);
  876. struct clk *msm_clk_bulk_get_clock(struct clk_bulk_data *bulk, int count,
  877. const char *name);
  878. void __iomem *msm_ioremap(struct platform_device *pdev, const char *name,
  879. const char *dbgname);
  880. unsigned long msm_iomap_size(struct platform_device *pdev, const char *name);
  881. void msm_iounmap(struct platform_device *dev, void __iomem *addr);
  882. void msm_writel(u32 data, void __iomem *addr);
  883. u32 msm_readl(const void __iomem *addr);
  884. #define DBG(fmt, ...) DRM_DEBUG_DRIVER(fmt"\n", ##__VA_ARGS__)
  885. #define VERB(fmt, ...) if (0) DRM_DEBUG_DRIVER(fmt"\n", ##__VA_ARGS__)
  886. static inline int align_pitch(int width, int bpp)
  887. {
  888. int bytespp = (bpp + 7) / 8;
  889. /* adreno needs pitch aligned to 32 pixels: */
  890. return bytespp * ALIGN(width, 32);
  891. }
  892. /* for the generated headers: */
  893. #define INVALID_IDX(idx) ({BUG(); 0;})
  894. #define fui(x) ({BUG(); 0;})
  895. #define util_float_to_half(x) ({BUG(); 0;})
  896. #define FIELD(val, name) (((val) & name ## __MASK) >> name ## __SHIFT)
  897. /* for conditionally setting boolean flag(s): */
  898. #define COND(bool, val) ((bool) ? (val) : 0)
  899. static inline unsigned long timeout_to_jiffies(const ktime_t *timeout)
  900. {
  901. ktime_t now = ktime_get();
  902. unsigned long remaining_jiffies;
  903. if (ktime_compare(*timeout, now) < 0) {
  904. remaining_jiffies = 0;
  905. } else {
  906. ktime_t rem = ktime_sub(*timeout, now);
  907. struct timespec ts = ktime_to_timespec(rem);
  908. remaining_jiffies = timespec_to_jiffies(&ts);
  909. }
  910. return remaining_jiffies;
  911. }
  912. int msm_get_mixer_count(struct msm_drm_private *priv,
  913. const struct drm_display_mode *mode,
  914. const struct msm_resource_caps_info *res, u32 *num_lm);
  915. #endif /* __MSM_DRV_H__ */