nouveau_grctx.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #ifndef __NOUVEAU_GRCTX_H__
  2. #define __NOUVEAU_GRCTX_H__
  3. struct nouveau_grctx {
  4. struct drm_device *dev;
  5. enum {
  6. NOUVEAU_GRCTX_PROG,
  7. NOUVEAU_GRCTX_VALS
  8. } mode;
  9. void *data;
  10. uint32_t ctxprog_max;
  11. uint32_t ctxprog_len;
  12. uint32_t ctxprog_reg;
  13. int ctxprog_label[32];
  14. uint32_t ctxvals_pos;
  15. uint32_t ctxvals_base;
  16. };
  17. static inline void
  18. cp_out(struct nouveau_grctx *ctx, uint32_t inst)
  19. {
  20. uint32_t *ctxprog = ctx->data;
  21. if (ctx->mode != NOUVEAU_GRCTX_PROG)
  22. return;
  23. BUG_ON(ctx->ctxprog_len == ctx->ctxprog_max);
  24. ctxprog[ctx->ctxprog_len++] = inst;
  25. }
  26. static inline void
  27. cp_lsr(struct nouveau_grctx *ctx, uint32_t val)
  28. {
  29. cp_out(ctx, CP_LOAD_SR | val);
  30. }
  31. static inline void
  32. cp_ctx(struct nouveau_grctx *ctx, uint32_t reg, uint32_t length)
  33. {
  34. ctx->ctxprog_reg = (reg - 0x00400000) >> 2;
  35. ctx->ctxvals_base = ctx->ctxvals_pos;
  36. ctx->ctxvals_pos = ctx->ctxvals_base + length;
  37. if (length > (CP_CTX_COUNT >> CP_CTX_COUNT_SHIFT)) {
  38. cp_lsr(ctx, length);
  39. length = 0;
  40. }
  41. cp_out(ctx, CP_CTX | (length << CP_CTX_COUNT_SHIFT) | ctx->ctxprog_reg);
  42. }
  43. static inline void
  44. cp_name(struct nouveau_grctx *ctx, int name)
  45. {
  46. uint32_t *ctxprog = ctx->data;
  47. int i;
  48. if (ctx->mode != NOUVEAU_GRCTX_PROG)
  49. return;
  50. ctx->ctxprog_label[name] = ctx->ctxprog_len;
  51. for (i = 0; i < ctx->ctxprog_len; i++) {
  52. if ((ctxprog[i] & 0xfff00000) != 0xff400000)
  53. continue;
  54. if ((ctxprog[i] & CP_BRA_IP) != ((name) << CP_BRA_IP_SHIFT))
  55. continue;
  56. ctxprog[i] = (ctxprog[i] & 0x00ff00ff) |
  57. (ctx->ctxprog_len << CP_BRA_IP_SHIFT);
  58. }
  59. }
  60. static inline void
  61. _cp_bra(struct nouveau_grctx *ctx, u32 mod, int flag, int state, int name)
  62. {
  63. int ip = 0;
  64. if (mod != 2) {
  65. ip = ctx->ctxprog_label[name] << CP_BRA_IP_SHIFT;
  66. if (ip == 0)
  67. ip = 0xff000000 | (name << CP_BRA_IP_SHIFT);
  68. }
  69. cp_out(ctx, CP_BRA | (mod << 18) | ip | flag |
  70. (state ? 0 : CP_BRA_IF_CLEAR));
  71. }
  72. #define cp_bra(c, f, s, n) _cp_bra((c), 0, CP_FLAG_##f, CP_FLAG_##f##_##s, n)
  73. #define cp_cal(c, f, s, n) _cp_bra((c), 1, CP_FLAG_##f, CP_FLAG_##f##_##s, n)
  74. #define cp_ret(c, f, s) _cp_bra((c), 2, CP_FLAG_##f, CP_FLAG_##f##_##s, 0)
  75. static inline void
  76. _cp_wait(struct nouveau_grctx *ctx, int flag, int state)
  77. {
  78. cp_out(ctx, CP_WAIT | flag | (state ? CP_WAIT_SET : 0));
  79. }
  80. #define cp_wait(c, f, s) _cp_wait((c), CP_FLAG_##f, CP_FLAG_##f##_##s)
  81. static inline void
  82. _cp_set(struct nouveau_grctx *ctx, int flag, int state)
  83. {
  84. cp_out(ctx, CP_SET | flag | (state ? CP_SET_1 : 0));
  85. }
  86. #define cp_set(c, f, s) _cp_set((c), CP_FLAG_##f, CP_FLAG_##f##_##s)
  87. static inline void
  88. cp_pos(struct nouveau_grctx *ctx, int offset)
  89. {
  90. ctx->ctxvals_pos = offset;
  91. ctx->ctxvals_base = ctx->ctxvals_pos;
  92. cp_lsr(ctx, ctx->ctxvals_pos);
  93. cp_out(ctx, CP_SET_CONTEXT_POINTER);
  94. }
  95. static inline void
  96. gr_def(struct nouveau_grctx *ctx, uint32_t reg, uint32_t val)
  97. {
  98. if (ctx->mode != NOUVEAU_GRCTX_VALS)
  99. return;
  100. reg = (reg - 0x00400000) / 4;
  101. reg = (reg - ctx->ctxprog_reg) + ctx->ctxvals_base;
  102. nv_wo32(ctx->data, reg * 4, val);
  103. }
  104. #endif