sde_kms.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. /*
  2. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  3. * Copyright (c) 2015-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 __SDE_KMS_H__
  20. #define __SDE_KMS_H__
  21. #include <linux/pm_domain.h>
  22. #include <linux/pm_qos.h>
  23. #include "msm_drv.h"
  24. #include "msm_kms.h"
  25. #include "msm_mmu.h"
  26. #include "msm_gem.h"
  27. #include "sde_dbg.h"
  28. #include "sde_hw_catalog.h"
  29. #include "sde_hw_ctl.h"
  30. #include "sde_hw_lm.h"
  31. #include "sde_hw_pingpong.h"
  32. #include "sde_hw_interrupts.h"
  33. #include "sde_hw_wb.h"
  34. #include "sde_hw_top.h"
  35. #include "sde_hw_uidle.h"
  36. #include "sde_hw_vbif.h"
  37. #include "sde_rm.h"
  38. #include "sde_power_handle.h"
  39. #include "sde_irq.h"
  40. #include "sde_core_perf.h"
  41. #define DRMID(x) ((x) ? (x)->base.id : -1)
  42. /**
  43. * SDE_DEBUG - macro for kms/plane/crtc/encoder/connector logs
  44. * @fmt: Pointer to format string
  45. */
  46. #define SDE_DEBUG(fmt, ...) \
  47. do { \
  48. if (drm_debug_enabled(DRM_UT_KMS)) \
  49. DRM_DEBUG(fmt, ##__VA_ARGS__); \
  50. else \
  51. pr_debug(fmt, ##__VA_ARGS__); \
  52. } while (0)
  53. /**
  54. * SDE_INFO - macro for kms/plane/crtc/encoder/connector logs
  55. * @fmt: Pointer to format string
  56. */
  57. #define SDE_INFO(fmt, ...) \
  58. do { \
  59. if (drm_debug_enabled(DRM_UT_KMS)) \
  60. DRM_INFO(fmt, ##__VA_ARGS__); \
  61. else \
  62. pr_info(fmt, ##__VA_ARGS__); \
  63. } while (0)
  64. /**
  65. * SDE_DEBUG_DRIVER - macro for hardware driver logging
  66. * @fmt: Pointer to format string
  67. */
  68. #define SDE_DEBUG_DRIVER(fmt, ...) \
  69. do { \
  70. if (drm_debug_enabled(DRM_UT_DRIVER)) \
  71. DRM_ERROR(fmt, ##__VA_ARGS__); \
  72. else \
  73. pr_debug(fmt, ##__VA_ARGS__); \
  74. } while (0)
  75. #define SDE_ERROR(fmt, ...) pr_err("[sde error]" fmt, ##__VA_ARGS__)
  76. #define POPULATE_RECT(rect, a, b, c, d, Q16_flag) \
  77. do { \
  78. (rect)->x = (Q16_flag) ? (a) >> 16 : (a); \
  79. (rect)->y = (Q16_flag) ? (b) >> 16 : (b); \
  80. (rect)->w = (Q16_flag) ? (c) >> 16 : (c); \
  81. (rect)->h = (Q16_flag) ? (d) >> 16 : (d); \
  82. } while (0)
  83. #define CHECK_LAYER_BOUNDS(offset, size, max_size) \
  84. (((size) > (max_size)) || ((offset) > ((max_size) - (size))))
  85. /**
  86. * ktime_compare_safe - compare two ktime structures
  87. * This macro is similar to the standard ktime_compare() function, but
  88. * attempts to also handle ktime overflows.
  89. * @A: First ktime value
  90. * @B: Second ktime value
  91. * Returns: -1 if A < B, 0 if A == B, 1 if A > B
  92. */
  93. #define ktime_compare_safe(A, B) \
  94. ktime_compare(ktime_sub((A), (B)), ktime_set(0, 0))
  95. #define SDE_NAME_SIZE 12
  96. #define DEFAULT_FPS 60
  97. /* timeout in frames waiting for frame done */
  98. #define SDE_FRAME_DONE_TIMEOUT 60
  99. /* max active secure client counts allowed */
  100. #define MAX_ALLOWED_SECURE_CLIENT_CNT 1
  101. /* max active crtc when secure client is active */
  102. #define MAX_ALLOWED_CRTC_CNT_DURING_SECURE 1
  103. /* max virtual encoders per secure crtc */
  104. #define MAX_ALLOWED_ENCODER_CNT_PER_SECURE_CRTC 1
  105. /* defines the operations required for secure state transition */
  106. #define SDE_KMS_OPS_SECURE_STATE_CHANGE BIT(0)
  107. #define SDE_KMS_OPS_WAIT_FOR_TX_DONE BIT(1)
  108. #define SDE_KMS_OPS_CLEANUP_PLANE_FB BIT(2)
  109. #define SDE_KMS_OPS_PREPARE_PLANE_FB BIT(3)
  110. /* ESD status check interval in miliseconds */
  111. #define STATUS_CHECK_INTERVAL_MS 5000
  112. /**
  113. * enum sde_kms_smmu_state: smmu state
  114. * @ATTACHED: all the context banks are attached.
  115. * @DETACHED: all the context banks are detached.
  116. * @DETACHED_SEC: secure context bank is detached.
  117. * @ATTACH_ALL_REQ: transient state of attaching context banks.
  118. * @DETACH_ALL_REQ: transient state of detaching context banks.
  119. * @DETACH_SEC_REQ: tranisent state of secure context bank is detached
  120. * @ATTACH_SEC_REQ: transient state of attaching secure context bank.
  121. */
  122. enum sde_kms_smmu_state {
  123. ATTACHED = 0,
  124. DETACHED,
  125. DETACHED_SEC,
  126. ATTACH_ALL_REQ,
  127. DETACH_ALL_REQ,
  128. DETACH_SEC_REQ,
  129. ATTACH_SEC_REQ,
  130. };
  131. /**
  132. * enum sde_kms_smmu_state_transition_type: state transition type
  133. * @NONE: no pending state transitions
  134. * @PRE_COMMIT: state transitions should be done before processing the commit
  135. * @POST_COMMIT: state transitions to be done after processing the commit.
  136. */
  137. enum sde_kms_smmu_state_transition_type {
  138. NONE,
  139. PRE_COMMIT,
  140. POST_COMMIT
  141. };
  142. /**
  143. * enum sde_kms_sui_misr_state: state request for enabling/disabling MISR
  144. * @NONE: no request
  145. * @ENABLE_SUI_MISR_REQ: request to enable sui MISR
  146. * @DISABLE_SUI_MISR_REQ: request to disable sui MISR
  147. */
  148. enum sde_kms_sui_misr_state {
  149. SUI_MISR_NONE,
  150. SUI_MISR_ENABLE_REQ,
  151. SUI_MISR_DISABLE_REQ
  152. };
  153. /*
  154. * @FRAME_DONE_WAIT_DEFAULT: waits for frame N pp_done interrupt before
  155. * triggering frame N+1.
  156. * @FRAME_DONE_WAIT_SERIALIZE: serialize pp_done and ctl_start irq for frame
  157. * N without next frame trigger wait.
  158. * @FRAME_DONE_WAIT_POSTED_START: Do not wait for pp_done interrupt for any
  159. * frame. Wait will trigger only for error case.
  160. */
  161. enum frame_trigger_mode_type {
  162. FRAME_DONE_WAIT_DEFAULT,
  163. FRAME_DONE_WAIT_SERIALIZE,
  164. FRAME_DONE_WAIT_POSTED_START,
  165. };
  166. /**
  167. * struct sde_kms_smmu_state_data: stores the smmu state and transition type
  168. * @state: current state of smmu context banks
  169. * @prev_state: previous state of smmu context banks
  170. * @secure_level: secure level cached from crtc
  171. * @prev_secure_level: previous secure level
  172. * @transition_type: transition request type
  173. * @transition_error: whether there is error while transitioning the state
  174. */
  175. struct sde_kms_smmu_state_data {
  176. uint32_t state;
  177. uint32_t prev_state;
  178. uint32_t secure_level;
  179. uint32_t prev_secure_level;
  180. uint32_t transition_type;
  181. uint32_t transition_error;
  182. uint32_t sui_misr_state;
  183. };
  184. /*
  185. * struct sde_irq_callback - IRQ callback handlers
  186. * @list: list to callback
  187. * @func: intr handler
  188. * @arg: argument for the handler
  189. */
  190. struct sde_irq_callback {
  191. struct list_head list;
  192. void (*func)(void *arg, int irq_idx);
  193. void *arg;
  194. };
  195. /**
  196. * struct sde_irq: IRQ structure contains callback registration info
  197. * @total_irq: total number of irq_idx obtained from HW interrupts mapping
  198. * @irq_cb_tbl: array of IRQ callbacks setting
  199. * @enable_counts array of IRQ enable counts
  200. * @cb_lock: callback lock
  201. * @debugfs_file: debugfs file for irq statistics
  202. */
  203. struct sde_irq {
  204. u32 total_irqs;
  205. struct list_head *irq_cb_tbl;
  206. atomic_t *enable_counts;
  207. atomic_t *irq_counts;
  208. spinlock_t cb_lock;
  209. struct dentry *debugfs_file;
  210. };
  211. /**
  212. * struct sde_kms_frame_event_cb_data : info of drm objects of a frame event
  213. * @crtc: pointer to drm crtc object registered for frame event
  214. * @connector: pointer to drm connector which is source of frame event
  215. */
  216. struct sde_kms_frame_event_cb_data {
  217. struct drm_crtc *crtc;
  218. struct drm_connector *connector;
  219. };
  220. struct sde_kms {
  221. struct msm_kms base;
  222. struct drm_device *dev;
  223. uint32_t core_rev;
  224. struct sde_mdss_cfg *catalog;
  225. struct generic_pm_domain genpd;
  226. bool genpd_init;
  227. struct msm_gem_address_space *aspace[MSM_SMMU_DOMAIN_MAX];
  228. struct sde_power_event *power_event;
  229. /* directory entry for debugfs */
  230. struct dentry *debugfs_vbif;
  231. /* io/register spaces: */
  232. void __iomem *mmio, *vbif[VBIF_MAX], *reg_dma, *sid;
  233. unsigned long mmio_len, vbif_len[VBIF_MAX], reg_dma_len, sid_len;
  234. unsigned long reg_dma_off;
  235. struct regulator *vdd;
  236. struct regulator *mmagic;
  237. struct regulator *venus;
  238. struct sde_irq_controller irq_controller;
  239. struct sde_hw_intr *hw_intr;
  240. struct sde_irq irq_obj;
  241. int irq_num; /* mdss irq number */
  242. bool irq_enabled;
  243. struct sde_core_perf perf;
  244. /* saved atomic state during system suspend */
  245. struct drm_atomic_state *suspend_state;
  246. bool suspend_block;
  247. struct sde_rm rm;
  248. bool rm_init;
  249. struct sde_splash_data splash_data;
  250. struct sde_vbif_clk_client vbif_clk_clients[SDE_CLK_CTRL_MAX];
  251. struct sde_hw_vbif *hw_vbif[VBIF_MAX];
  252. struct sde_hw_mdp *hw_mdp;
  253. struct sde_hw_uidle *hw_uidle;
  254. struct sde_hw_sid *hw_sid;
  255. int dsi_display_count;
  256. void **dsi_displays;
  257. int wb_display_count;
  258. void **wb_displays;
  259. int dp_display_count;
  260. void **dp_displays;
  261. int dp_stream_count;
  262. bool dsc_switch_support;
  263. bool has_danger_ctrl;
  264. struct sde_kms_smmu_state_data smmu_state;
  265. atomic_t detach_sec_cb;
  266. atomic_t detach_all_cb;
  267. struct mutex secure_transition_lock;
  268. bool first_kickoff;
  269. bool qdss_enabled;
  270. bool pm_suspend_clk_dump;
  271. cpumask_t irq_cpu_mask;
  272. atomic_t irq_vote_count;
  273. struct dev_pm_qos_request pm_qos_irq_req[NR_CPUS];
  274. struct irq_affinity_notify affinity_notify;
  275. struct sde_vm *vm;
  276. unsigned long ipcc_base_addr;
  277. u32 debugfs_hw_fence;
  278. };
  279. struct vsync_info {
  280. u32 frame_count;
  281. u32 line_count;
  282. };
  283. #define to_sde_kms(x) container_of(x, struct sde_kms, base)
  284. /**
  285. * sde_is_custom_client - whether or not to enable non-standard customizations
  286. *
  287. * Return: Whether or not the 'sdeclient' module parameter was set on boot up
  288. */
  289. bool sde_is_custom_client(void);
  290. /**
  291. * sde_kms_get_hw_version - get the hw revision - client is expected to
  292. * enable the power resources before making this call
  293. * @dev: Pointer to drm device
  294. */
  295. static inline u32 sde_kms_get_hw_version(struct drm_device *dev)
  296. {
  297. struct sde_kms *sde_kms;
  298. if (!ddev_to_msm_kms(dev))
  299. return 0;
  300. sde_kms = to_sde_kms(ddev_to_msm_kms(dev));
  301. return readl_relaxed(sde_kms->mmio + 0x0);
  302. }
  303. /**
  304. * sde_kms_power_resource_is_enabled - whether or not power resource is enabled
  305. * @dev: Pointer to drm device
  306. * Return: true if power resource is enabled; false otherwise
  307. */
  308. static inline bool sde_kms_power_resource_is_enabled(struct drm_device *dev)
  309. {
  310. if (!dev)
  311. return false;
  312. return pm_runtime_enabled(dev->dev);
  313. }
  314. /**
  315. * sde_kms_is_suspend_state - whether or not the system is pm suspended
  316. * @dev: Pointer to drm device
  317. * Return: Suspend status
  318. */
  319. static inline bool sde_kms_is_suspend_state(struct drm_device *dev)
  320. {
  321. if (!ddev_to_msm_kms(dev))
  322. return false;
  323. return to_sde_kms(ddev_to_msm_kms(dev))->suspend_state != NULL;
  324. }
  325. /**
  326. * sde_kms_is_suspend_blocked - whether or not commits are blocked due to pm
  327. * suspend status
  328. * @dev: Pointer to drm device
  329. * Return: True if commits should be rejected due to pm suspend
  330. */
  331. static inline bool sde_kms_is_suspend_blocked(struct drm_device *dev)
  332. {
  333. if (!sde_kms_is_suspend_state(dev))
  334. return false;
  335. return to_sde_kms(ddev_to_msm_kms(dev))->suspend_block;
  336. }
  337. /**
  338. * sde_kms_is_secure_session_inprogress - to indicate if secure-session is in
  339. * currently in-progress based on the current smmu_state
  340. *
  341. * @sde_kms: Pointer to sde_kms
  342. *
  343. * return: true if secure-session is in progress; false otherwise
  344. */
  345. static inline bool sde_kms_is_secure_session_inprogress(struct sde_kms *sde_kms)
  346. {
  347. bool ret = false;
  348. if (!sde_kms || !sde_kms->catalog)
  349. return false;
  350. mutex_lock(&sde_kms->secure_transition_lock);
  351. if (((test_bit(SDE_FEATURE_SUI_NS_ALLOWED, sde_kms->catalog->features)) &&
  352. (sde_kms->smmu_state.secure_level == SDE_DRM_SEC_ONLY) &&
  353. ((sde_kms->smmu_state.state == DETACHED_SEC) ||
  354. (sde_kms->smmu_state.state == DETACH_SEC_REQ) ||
  355. (sde_kms->smmu_state.state == ATTACH_SEC_REQ))) ||
  356. (((sde_kms->smmu_state.state == DETACHED) ||
  357. (sde_kms->smmu_state.state == DETACH_ALL_REQ) ||
  358. (sde_kms->smmu_state.state == ATTACH_ALL_REQ))))
  359. ret = true;
  360. mutex_unlock(&sde_kms->secure_transition_lock);
  361. return ret;
  362. }
  363. /**
  364. * sde_kms_is_vbif_operation_allowed - resticts the VBIF programming
  365. * during secure-ui, if the sec_ui_misr feature is enabled
  366. *
  367. * @sde_kms: Pointer to sde_kms
  368. *
  369. * return: false if secure-session is in progress; true otherwise
  370. */
  371. static inline bool sde_kms_is_vbif_operation_allowed(struct sde_kms *sde_kms)
  372. {
  373. if (!sde_kms)
  374. return false;
  375. if (!test_bit(SDE_FEATURE_SUI_MISR, sde_kms->catalog->features))
  376. return true;
  377. return !sde_kms_is_secure_session_inprogress(sde_kms);
  378. }
  379. /**
  380. * sde_kms_is_cp_operation_allowed - resticts the CP programming
  381. * during secure-ui, if the non-secure context banks are detached
  382. *
  383. * @sde_kms: Pointer to sde_kms
  384. */
  385. static inline bool sde_kms_is_cp_operation_allowed(struct sde_kms *sde_kms)
  386. {
  387. if (!sde_kms || !sde_kms->catalog)
  388. return false;
  389. if (test_bit(SDE_FEATURE_SUI_NS_ALLOWED, sde_kms->catalog->features))
  390. return true;
  391. return !sde_kms_is_secure_session_inprogress(sde_kms);
  392. }
  393. /**
  394. * Debugfs functions - extra helper functions for debugfs support
  395. *
  396. * Main debugfs documentation is located at,
  397. *
  398. * Documentation/filesystems/debugfs.txt
  399. *
  400. * @sde_debugfs_get_root: Get root dentry for SDE_KMS's debugfs node
  401. */
  402. /**
  403. * sde_debugfs_get_root - Return root directory entry for KMS's debugfs
  404. *
  405. * The return value should be passed as the 'parent' argument to subsequent
  406. * debugfs create calls.
  407. *
  408. * @sde_kms: Pointer to SDE's KMS structure
  409. *
  410. * Return: dentry pointer for SDE's debugfs location
  411. */
  412. void *sde_debugfs_get_root(struct sde_kms *sde_kms);
  413. /**
  414. * SDE info management functions
  415. * These functions/definitions allow for building up a 'sde_info' structure
  416. * containing one or more "key=value\n" entries.
  417. */
  418. #if IS_ENABLED(CONFIG_DRM_LOW_MSM_MEM_FOOTPRINT)
  419. #define SDE_KMS_INFO_MAX_SIZE (1 << 12)
  420. #else
  421. #define SDE_KMS_INFO_MAX_SIZE (1 << 14)
  422. #endif
  423. /**
  424. * struct sde_kms_info - connector information structure container
  425. * @data: Array of information character data
  426. * @len: Current length of information data
  427. * @staged_len: Temporary data buffer length, commit to
  428. * len using sde_kms_info_stop
  429. * @start: Whether or not a partial data entry was just started
  430. */
  431. struct sde_kms_info {
  432. char data[SDE_KMS_INFO_MAX_SIZE];
  433. uint32_t len;
  434. uint32_t staged_len;
  435. bool start;
  436. };
  437. /**
  438. * SDE_KMS_INFO_DATA - Macro for accessing sde_kms_info data bytes
  439. * @S: Pointer to sde_kms_info structure
  440. * Returns: Pointer to byte data
  441. */
  442. #define SDE_KMS_INFO_DATA(S) ((S) ? ((struct sde_kms_info *)(S))->data \
  443. : NULL)
  444. /**
  445. * SDE_KMS_INFO_DATALEN - Macro for accessing sde_kms_info data length
  446. * it adds an extra character length to count null.
  447. * @S: Pointer to sde_kms_info structure
  448. * Returns: Size of available byte data
  449. */
  450. #define SDE_KMS_INFO_DATALEN(S) ((S) ? ((struct sde_kms_info *)(S))->len + 1 \
  451. : 0)
  452. /**
  453. * sde_kms_info_reset - reset sde_kms_info structure
  454. * @info: Pointer to sde_kms_info structure
  455. */
  456. void sde_kms_info_reset(struct sde_kms_info *info);
  457. /**
  458. * sde_kms_info_add_keyint - add integer value to 'sde_kms_info'
  459. * @info: Pointer to sde_kms_info structure
  460. * @key: Pointer to key string
  461. * @value: Signed 64-bit integer value
  462. */
  463. void sde_kms_info_add_keyint(struct sde_kms_info *info,
  464. const char *key,
  465. int64_t value);
  466. /**
  467. * sde_kms_info_add_keystr - add string value to 'sde_kms_info'
  468. * @info: Pointer to sde_kms_info structure
  469. * @key: Pointer to key string
  470. * @value: Pointer to string value
  471. */
  472. void sde_kms_info_add_keystr(struct sde_kms_info *info,
  473. const char *key,
  474. const char *value);
  475. /**
  476. * sde_kms_info_start - begin adding key to 'sde_kms_info'
  477. * Usage:
  478. * sde_kms_info_start(key)
  479. * sde_kms_info_append(val_1)
  480. * ...
  481. * sde_kms_info_append(val_n)
  482. * sde_kms_info_stop
  483. * @info: Pointer to sde_kms_info structure
  484. * @key: Pointer to key string
  485. */
  486. void sde_kms_info_start(struct sde_kms_info *info,
  487. const char *key);
  488. /**
  489. * sde_kms_info_append - append value string to 'sde_kms_info'
  490. * Usage:
  491. * sde_kms_info_start(key)
  492. * sde_kms_info_append(val_1)
  493. * ...
  494. * sde_kms_info_append(val_n)
  495. * sde_kms_info_stop
  496. * @info: Pointer to sde_kms_info structure
  497. * @str: Pointer to partial value string
  498. */
  499. void sde_kms_info_append(struct sde_kms_info *info,
  500. const char *str);
  501. /**
  502. * sde_kms_info_append_format - append format code string to 'sde_kms_info'
  503. * Usage:
  504. * sde_kms_info_start(key)
  505. * sde_kms_info_append_format(fourcc, modifier)
  506. * ...
  507. * sde_kms_info_stop
  508. * @info: Pointer to sde_kms_info structure
  509. * @pixel_format: FOURCC format code
  510. * @modifier: 64-bit drm format modifier
  511. */
  512. void sde_kms_info_append_format(struct sde_kms_info *info,
  513. uint32_t pixel_format,
  514. uint64_t modifier);
  515. /**
  516. * sde_kms_info_append_dnsc_blur_filter_info - append dnsc_blur filters code to 'sde_kms_info'
  517. * Usage:
  518. * sde_kms_info_start(key)
  519. * sde_kms_info_append_dnsc_blur_filter_info(info, ratio)
  520. * ...
  521. * sde_kms_info_stop
  522. * @info: Pointer to sde_kms_info structure
  523. * @filter: Pointer to dnsc_blur filter info
  524. */
  525. void sde_kms_info_append_dnsc_blur_filter_info(struct sde_kms_info *info,
  526. struct sde_dnsc_blur_filter_info *filter);
  527. /**
  528. * sde_kms_info_stop - finish adding key to 'sde_kms_info'
  529. * Usage:
  530. * sde_kms_info_start(key)
  531. * sde_kms_info_append(val_1)
  532. * ...
  533. * sde_kms_info_append(val_n)
  534. * sde_kms_info_stop
  535. * @info: Pointer to sde_kms_info structure
  536. */
  537. void sde_kms_info_stop(struct sde_kms_info *info);
  538. /**
  539. * sde_kms_info_add_list - add a space separated list to 'sde_kms_info'
  540. * @info: Pointer to sde_kms_info structure
  541. * @key: Pointer to key string
  542. * @item: Pointer to array of integer values
  543. * @size: Number of integers to parse
  544. */
  545. void sde_kms_info_add_list(struct sde_kms_info *info,
  546. const char *key, uint32_t *item, size_t size);
  547. /**
  548. * sde_kms_rect_intersect - intersect two rectangles
  549. * @r1: first rectangle
  550. * @r2: scissor rectangle
  551. * @result: result rectangle, all 0's on no intersection found
  552. */
  553. void sde_kms_rect_intersect(const struct sde_rect *r1,
  554. const struct sde_rect *r2,
  555. struct sde_rect *result);
  556. /**
  557. * sde_kms_rect_merge_rectangles - merge a rectangle list into one rect
  558. * @rois: pointer to the list of rois
  559. * @result: output rectangle, all 0 on error
  560. */
  561. void sde_kms_rect_merge_rectangles(const struct msm_roi_list *rois,
  562. struct sde_rect *result);
  563. /**
  564. * sde_kms_rect_is_equal - compares two rects
  565. * @r1: rect value to compare
  566. * @r2: rect value to compare
  567. *
  568. * Returns 1 if the rects are same, 0 otherwise.
  569. */
  570. static inline bool sde_kms_rect_is_equal(struct sde_rect *r1,
  571. struct sde_rect *r2)
  572. {
  573. if ((!r1 && r2) || (r1 && !r2))
  574. return false;
  575. if (!r1 && !r2)
  576. return true;
  577. return r1->x == r2->x && r1->y == r2->y && r1->w == r2->w &&
  578. r1->h == r2->h;
  579. }
  580. /**
  581. * sde_kms_rect_is_null - returns true if the width or height of a rect is 0
  582. * @rect: rectangle to check for zero size
  583. * @Return: True if width or height of rectangle is 0
  584. */
  585. static inline bool sde_kms_rect_is_null(const struct sde_rect *r)
  586. {
  587. if (!r)
  588. return true;
  589. return (!r->w || !r->h);
  590. }
  591. /*
  592. * sde_in_trusted_vm - checks the executing VM
  593. * return: true, if the device driver is executing in the trusted VM
  594. * false, if the device driver is executing in the primary VM
  595. */
  596. static inline bool sde_in_trusted_vm(const struct sde_kms *sde_kms)
  597. {
  598. if (sde_kms && sde_kms->catalog)
  599. return sde_kms->catalog->trusted_vm_env;
  600. return false;
  601. }
  602. /**
  603. * Vblank enable/disable functions
  604. */
  605. int sde_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
  606. void sde_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
  607. /**
  608. * smmu attach/detach functions
  609. * @sde_kms: poiner to sde_kms structure
  610. * @secure_only: if true only secure contexts are attached/detached, else
  611. * all contexts are attached/detached/
  612. */
  613. int sde_kms_mmu_attach(struct sde_kms *sde_kms, bool secure_only);
  614. int sde_kms_mmu_detach(struct sde_kms *sde_kms, bool secure_only);
  615. /**
  616. * sde_kms_timeline_status - provides current timeline status
  617. * @dev: Pointer to drm device
  618. */
  619. void sde_kms_timeline_status(struct drm_device *dev);
  620. /**
  621. * sde_kms_handle_recovery - handler function for FIFO overflow issue
  622. * @encoder: pointer to drm encoder structure
  623. * return: 0 on success; error code otherwise
  624. */
  625. int sde_kms_handle_recovery(struct drm_encoder *encoder);
  626. /**
  627. * sde_kms_cpu_vote_for_irq() - API to keep pm_qos latency vote on cpu
  628. * where mdss_irq is scheduled
  629. * @sde_kms: pointer to sde_kms structure
  630. * @enable: true if enable request, false otherwise.
  631. */
  632. void sde_kms_cpu_vote_for_irq(struct sde_kms *sde_kms, bool enable);
  633. /**
  634. * sde_kms_get_io_resources() - reads associated register range
  635. * @kms: pointer to sde_kms structure
  636. * @io_res: pointer to msm_io_res struct to populate the ranges
  637. * Return: error code.
  638. */
  639. int sde_kms_get_io_resources(struct sde_kms *kms, struct msm_io_res *io_res);
  640. /**
  641. * sde_kms_vm_trusted_resource_init - reserve/initialize the HW/SW resources
  642. * @sde_kms: poiner to sde_kms structure
  643. * @state: current update atomic commit state
  644. * return: 0 on success; error code otherwise
  645. */
  646. int sde_kms_vm_trusted_resource_init(struct sde_kms *sde_kms,
  647. struct drm_atomic_state *state);
  648. /**
  649. * sde_kms_vm_trusted_resource_deinit - release the HW/SW resources
  650. * @sde_kms: poiner to sde_kms structure
  651. */
  652. void sde_kms_vm_trusted_resource_deinit(struct sde_kms *sde_kms);
  653. /**
  654. * sde_kms_vm_trusted_post_commit - function to prepare the VM after the
  655. * last commit before releasing the HW
  656. * resources from trusted VM
  657. * @sde_kms: pointer to sde_kms
  658. * @state: current frames atomic commit state
  659. */
  660. int sde_kms_vm_trusted_post_commit(struct sde_kms *sde_kms,
  661. struct drm_atomic_state *state);
  662. /**
  663. * sde_kms_vm_primary_post_commit - function to prepare the VM after the
  664. * last commit before assign the HW
  665. * resources from primary VM
  666. * @sde_kms: pointer to sde_kms
  667. * @state: current frames atomic commit state
  668. */
  669. int sde_kms_vm_primary_post_commit(struct sde_kms *sde_kms,
  670. struct drm_atomic_state *state);
  671. /**
  672. * sde_kms_vm_trusted_prepare_commit - function to prepare the VM before the
  673. * the first commit after the accepting
  674. * the HW resources in trusted VM.
  675. * @sde_kms: pointer to sde_kms
  676. * @state: current frame's atomic commit state
  677. */
  678. int sde_kms_vm_trusted_prepare_commit(struct sde_kms *sde_kms,
  679. struct drm_atomic_state *state);
  680. /**
  681. * sde_kms_vm_primary_prepare_commit - function to prepare the VM before the
  682. * the first commit after the reclaming
  683. * the HW resources in trusted VM.
  684. * @sde_kms: pointer to sde_kms
  685. * @state: current frame's atomic commit state
  686. */
  687. int sde_kms_vm_primary_prepare_commit(struct sde_kms *sde_kms,
  688. struct drm_atomic_state *state);
  689. void sde_kms_add_data_to_minidump_va(struct sde_kms *sde_kms);
  690. #endif /* __sde_kms_H__ */