msm_drv.h 31 KB

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