crc.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* SPDX-License-Identifier: MIT */
  2. #ifndef __NV50_CRC_H__
  3. #define __NV50_CRC_H__
  4. #include <linux/mutex.h>
  5. #include <drm/drm_crtc.h>
  6. #include <drm/drm_vblank_work.h>
  7. #include <nvif/mem.h>
  8. #include <nvkm/subdev/bios.h>
  9. #include "nouveau_encoder.h"
  10. struct nv50_atom;
  11. struct nv50_disp;
  12. struct nv50_head;
  13. #if IS_ENABLED(CONFIG_DEBUG_FS)
  14. enum nv50_crc_source {
  15. NV50_CRC_SOURCE_NONE = 0,
  16. NV50_CRC_SOURCE_AUTO,
  17. NV50_CRC_SOURCE_RG,
  18. NV50_CRC_SOURCE_OUTP_ACTIVE,
  19. NV50_CRC_SOURCE_OUTP_COMPLETE,
  20. NV50_CRC_SOURCE_OUTP_INACTIVE,
  21. };
  22. /* RG -> SF (DP only)
  23. * -> SOR
  24. * -> PIOR
  25. * -> DAC
  26. */
  27. enum nv50_crc_source_type {
  28. NV50_CRC_SOURCE_TYPE_NONE = 0,
  29. NV50_CRC_SOURCE_TYPE_SOR,
  30. NV50_CRC_SOURCE_TYPE_PIOR,
  31. NV50_CRC_SOURCE_TYPE_DAC,
  32. NV50_CRC_SOURCE_TYPE_RG,
  33. NV50_CRC_SOURCE_TYPE_SF,
  34. };
  35. struct nv50_crc_notifier_ctx {
  36. struct nvif_mem mem;
  37. struct nvif_object ntfy;
  38. };
  39. struct nv50_crc_atom {
  40. enum nv50_crc_source src;
  41. };
  42. struct nv50_crc_func {
  43. int (*set_src)(struct nv50_head *, int or, enum nv50_crc_source_type type,
  44. struct nv50_crc_notifier_ctx *ctx);
  45. int (*set_ctx)(struct nv50_head *, struct nv50_crc_notifier_ctx *);
  46. u32 (*get_entry)(struct nv50_head *, struct nv50_crc_notifier_ctx *,
  47. enum nv50_crc_source, int idx);
  48. bool (*ctx_finished)(struct nv50_head *,
  49. struct nv50_crc_notifier_ctx *);
  50. short flip_threshold;
  51. short num_entries;
  52. size_t notifier_len;
  53. };
  54. struct nv50_crc {
  55. spinlock_t lock;
  56. struct nv50_crc_notifier_ctx ctx[2];
  57. struct drm_vblank_work flip_work;
  58. enum nv50_crc_source src;
  59. u64 frame;
  60. short entry_idx;
  61. short flip_threshold;
  62. u8 ctx_idx : 1;
  63. bool ctx_changed : 1;
  64. };
  65. void nv50_crc_init(struct drm_device *dev);
  66. int nv50_head_crc_late_register(struct nv50_head *);
  67. void nv50_crc_handle_vblank(struct nv50_head *head);
  68. int nv50_crc_verify_source(struct drm_crtc *, const char *, size_t *);
  69. const char *const *nv50_crc_get_sources(struct drm_crtc *, size_t *);
  70. int nv50_crc_set_source(struct drm_crtc *, const char *);
  71. int nv50_crc_atomic_check_head(struct nv50_head *, struct nv50_head_atom *,
  72. struct nv50_head_atom *);
  73. void nv50_crc_atomic_check_outp(struct nv50_atom *atom);
  74. void nv50_crc_atomic_stop_reporting(struct drm_atomic_state *);
  75. void nv50_crc_atomic_init_notifier_contexts(struct drm_atomic_state *);
  76. void nv50_crc_atomic_release_notifier_contexts(struct drm_atomic_state *);
  77. void nv50_crc_atomic_start_reporting(struct drm_atomic_state *);
  78. void nv50_crc_atomic_set(struct nv50_head *, struct nv50_head_atom *);
  79. void nv50_crc_atomic_clr(struct nv50_head *);
  80. extern const struct nv50_crc_func crc907d;
  81. extern const struct nv50_crc_func crcc37d;
  82. extern const struct nv50_crc_func crcc57d;
  83. #else /* IS_ENABLED(CONFIG_DEBUG_FS) */
  84. struct nv50_crc {};
  85. struct nv50_crc_func {};
  86. struct nv50_crc_atom {};
  87. #define nv50_crc_verify_source NULL
  88. #define nv50_crc_get_sources NULL
  89. #define nv50_crc_set_source NULL
  90. static inline void nv50_crc_init(struct drm_device *dev) {}
  91. static inline int
  92. nv50_head_crc_late_register(struct nv50_head *head) { return 0; }
  93. static inline void nv50_crc_handle_vblank(struct nv50_head *head) {}
  94. static inline int
  95. nv50_crc_atomic_check_head(struct nv50_head *head,
  96. struct nv50_head_atom *asyh,
  97. struct nv50_head_atom *armh) { return 0; }
  98. static inline void nv50_crc_atomic_check_outp(struct nv50_atom *atom) {}
  99. static inline void
  100. nv50_crc_atomic_stop_reporting(struct drm_atomic_state *state) {}
  101. static inline void
  102. nv50_crc_atomic_init_notifier_contexts(struct drm_atomic_state *state) {}
  103. static inline void
  104. nv50_crc_atomic_release_notifier_contexts(struct drm_atomic_state *state) {}
  105. static inline void
  106. nv50_crc_atomic_start_reporting(struct drm_atomic_state *state) {}
  107. static inline void
  108. nv50_crc_atomic_set(struct nv50_head *head, struct nv50_head_atom *state) {}
  109. static inline void
  110. nv50_crc_atomic_clr(struct nv50_head *head) {}
  111. #endif /* IS_ENABLED(CONFIG_DEBUG_FS) */
  112. #endif /* !__NV50_CRC_H__ */