sde_kms.h 22 KB

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