nouveau_hwsq.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright 2010 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Ben Skeggs
  23. */
  24. #ifndef __NOUVEAU_HWSQ_H__
  25. #define __NOUVEAU_HWSQ_H__
  26. struct hwsq_ucode {
  27. u8 data[0x200];
  28. union {
  29. u8 *u08;
  30. u16 *u16;
  31. u32 *u32;
  32. } ptr;
  33. u16 len;
  34. u32 reg;
  35. u32 val;
  36. };
  37. static inline void
  38. hwsq_init(struct hwsq_ucode *hwsq)
  39. {
  40. hwsq->ptr.u08 = hwsq->data;
  41. hwsq->reg = 0xffffffff;
  42. hwsq->val = 0xffffffff;
  43. }
  44. static inline void
  45. hwsq_fini(struct hwsq_ucode *hwsq)
  46. {
  47. do {
  48. *hwsq->ptr.u08++ = 0x7f;
  49. hwsq->len = hwsq->ptr.u08 - hwsq->data;
  50. } while (hwsq->len & 3);
  51. hwsq->ptr.u08 = hwsq->data;
  52. }
  53. static inline void
  54. hwsq_usec(struct hwsq_ucode *hwsq, u8 usec)
  55. {
  56. u32 shift = 0;
  57. while (usec & ~3) {
  58. usec >>= 2;
  59. shift++;
  60. }
  61. *hwsq->ptr.u08++ = (shift << 2) | usec;
  62. }
  63. static inline void
  64. hwsq_setf(struct hwsq_ucode *hwsq, u8 flag, int val)
  65. {
  66. flag += 0x80;
  67. if (val >= 0)
  68. flag += 0x20;
  69. if (val >= 1)
  70. flag += 0x20;
  71. *hwsq->ptr.u08++ = flag;
  72. }
  73. static inline void
  74. hwsq_op5f(struct hwsq_ucode *hwsq, u8 v0, u8 v1)
  75. {
  76. *hwsq->ptr.u08++ = 0x5f;
  77. *hwsq->ptr.u08++ = v0;
  78. *hwsq->ptr.u08++ = v1;
  79. }
  80. static inline void
  81. hwsq_wr32(struct hwsq_ucode *hwsq, u32 reg, u32 val)
  82. {
  83. if (val != hwsq->val) {
  84. if ((val & 0xffff0000) == (hwsq->val & 0xffff0000)) {
  85. *hwsq->ptr.u08++ = 0x42;
  86. *hwsq->ptr.u16++ = (val & 0x0000ffff);
  87. } else {
  88. *hwsq->ptr.u08++ = 0xe2;
  89. *hwsq->ptr.u32++ = val;
  90. }
  91. hwsq->val = val;
  92. }
  93. if ((reg & 0xffff0000) == (hwsq->reg & 0xffff0000)) {
  94. *hwsq->ptr.u08++ = 0x40;
  95. *hwsq->ptr.u16++ = (reg & 0x0000ffff);
  96. } else {
  97. *hwsq->ptr.u08++ = 0xe0;
  98. *hwsq->ptr.u32++ = reg;
  99. }
  100. hwsq->reg = reg;
  101. }
  102. #endif