nvreg.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* $XConsortium: nvreg.h /main/2 1996/10/28 05:13:41 kaleb $ */
  2. /*
  3. * Copyright 1996-1997 David J. McKay
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * DAVID J. MCKAY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
  20. * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. /* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/nv/nvreg.h,v 3.2.2.1 1998/01/18 10:35:36 hohndel Exp $ */
  24. #ifndef __NVREG_H_
  25. #define __NVREG_H_
  26. /* Little macro to construct bitmask for contiguous ranges of bits */
  27. #define BITMASK(t,b) (((unsigned)(1U << (((t)-(b)+1)))-1) << (b))
  28. #define MASKEXPAND(mask) BITMASK(1?mask,0?mask)
  29. /* Macro to set specific bitfields (mask has to be a macro x:y) ! */
  30. #define SetBF(mask,value) ((value) << (0?mask))
  31. #define GetBF(var,mask) (((unsigned)((var) & MASKEXPAND(mask))) >> (0?mask) )
  32. #define MaskAndSetBF(var,mask,value) (var)=(((var)&(~MASKEXPAND(mask)) \
  33. | SetBF(mask,value)))
  34. #define DEVICE_BASE(device) (0?NV##_##device)
  35. #define DEVICE_SIZE(device) ((1?NV##_##device) - DEVICE_BASE(device)+1)
  36. /* This is where we will have to have conditional compilation */
  37. #define DEVICE_ACCESS(device,reg) \
  38. nvCONTROL[(NV_##device##_##reg)/4]
  39. #define DEVICE_WRITE(device,reg,value) DEVICE_ACCESS(device,reg)=(value)
  40. #define DEVICE_READ(device,reg) DEVICE_ACCESS(device,reg)
  41. #define DEVICE_PRINT(device,reg) \
  42. ErrorF("NV_"#device"_"#reg"=#%08lx\n",DEVICE_ACCESS(device,reg))
  43. #define DEVICE_DEF(device,mask,value) \
  44. SetBF(NV_##device##_##mask,NV_##device##_##mask##_##value)
  45. #define DEVICE_VALUE(device,mask,value) SetBF(NV_##device##_##mask,value)
  46. #define DEVICE_MASK(device,mask) MASKEXPAND(NV_##device##_##mask)
  47. #define PDAC_Write(reg,value) DEVICE_WRITE(PDAC,reg,value)
  48. #define PDAC_Read(reg) DEVICE_READ(PDAC,reg)
  49. #define PDAC_Print(reg) DEVICE_PRINT(PDAC,reg)
  50. #define PDAC_Def(mask,value) DEVICE_DEF(PDAC,mask,value)
  51. #define PDAC_Val(mask,value) DEVICE_VALUE(PDAC,mask,value)
  52. #define PDAC_Mask(mask) DEVICE_MASK(PDAC,mask)
  53. #define PFB_Write(reg,value) DEVICE_WRITE(PFB,reg,value)
  54. #define PFB_Read(reg) DEVICE_READ(PFB,reg)
  55. #define PFB_Print(reg) DEVICE_PRINT(PFB,reg)
  56. #define PFB_Def(mask,value) DEVICE_DEF(PFB,mask,value)
  57. #define PFB_Val(mask,value) DEVICE_VALUE(PFB,mask,value)
  58. #define PFB_Mask(mask) DEVICE_MASK(PFB,mask)
  59. #define PRM_Write(reg,value) DEVICE_WRITE(PRM,reg,value)
  60. #define PRM_Read(reg) DEVICE_READ(PRM,reg)
  61. #define PRM_Print(reg) DEVICE_PRINT(PRM,reg)
  62. #define PRM_Def(mask,value) DEVICE_DEF(PRM,mask,value)
  63. #define PRM_Val(mask,value) DEVICE_VALUE(PRM,mask,value)
  64. #define PRM_Mask(mask) DEVICE_MASK(PRM,mask)
  65. #define PGRAPH_Write(reg,value) DEVICE_WRITE(PGRAPH,reg,value)
  66. #define PGRAPH_Read(reg) DEVICE_READ(PGRAPH,reg)
  67. #define PGRAPH_Print(reg) DEVICE_PRINT(PGRAPH,reg)
  68. #define PGRAPH_Def(mask,value) DEVICE_DEF(PGRAPH,mask,value)
  69. #define PGRAPH_Val(mask,value) DEVICE_VALUE(PGRAPH,mask,value)
  70. #define PGRAPH_Mask(mask) DEVICE_MASK(PGRAPH,mask)
  71. #define PDMA_Write(reg,value) DEVICE_WRITE(PDMA,reg,value)
  72. #define PDMA_Read(reg) DEVICE_READ(PDMA,reg)
  73. #define PDMA_Print(reg) DEVICE_PRINT(PDMA,reg)
  74. #define PDMA_Def(mask,value) DEVICE_DEF(PDMA,mask,value)
  75. #define PDMA_Val(mask,value) DEVICE_VALUE(PDMA,mask,value)
  76. #define PDMA_Mask(mask) DEVICE_MASK(PDMA,mask)
  77. #define PTIMER_Write(reg,value) DEVICE_WRITE(PTIMER,reg,value)
  78. #define PTIMER_Read(reg) DEVICE_READ(PTIMER,reg)
  79. #define PTIMER_Print(reg) DEVICE_PRINT(PTIMER,reg)
  80. #define PTIMER_Def(mask,value) DEVICE_DEF(PTIMER,mask,value)
  81. #define PTIMER_Val(mask,value) DEVICE_VALUE(PTIEMR,mask,value)
  82. #define PTIMER_Mask(mask) DEVICE_MASK(PTIMER,mask)
  83. #define PEXTDEV_Write(reg,value) DEVICE_WRITE(PEXTDEV,reg,value)
  84. #define PEXTDEV_Read(reg) DEVICE_READ(PEXTDEV,reg)
  85. #define PEXTDEV_Print(reg) DEVICE_PRINT(PEXTDEV,reg)
  86. #define PEXTDEV_Def(mask,value) DEVICE_DEF(PEXTDEV,mask,value)
  87. #define PEXTDEV_Val(mask,value) DEVICE_VALUE(PEXTDEV,mask,value)
  88. #define PEXTDEV_Mask(mask) DEVICE_MASK(PEXTDEV,mask)
  89. #define PFIFO_Write(reg,value) DEVICE_WRITE(PFIFO,reg,value)
  90. #define PFIFO_Read(reg) DEVICE_READ(PFIFO,reg)
  91. #define PFIFO_Print(reg) DEVICE_PRINT(PFIFO,reg)
  92. #define PFIFO_Def(mask,value) DEVICE_DEF(PFIFO,mask,value)
  93. #define PFIFO_Val(mask,value) DEVICE_VALUE(PFIFO,mask,value)
  94. #define PFIFO_Mask(mask) DEVICE_MASK(PFIFO,mask)
  95. #define PRAM_Write(reg,value) DEVICE_WRITE(PRAM,reg,value)
  96. #define PRAM_Read(reg) DEVICE_READ(PRAM,reg)
  97. #define PRAM_Print(reg) DEVICE_PRINT(PRAM,reg)
  98. #define PRAM_Def(mask,value) DEVICE_DEF(PRAM,mask,value)
  99. #define PRAM_Val(mask,value) DEVICE_VALUE(PRAM,mask,value)
  100. #define PRAM_Mask(mask) DEVICE_MASK(PRAM,mask)
  101. #define PRAMFC_Write(reg,value) DEVICE_WRITE(PRAMFC,reg,value)
  102. #define PRAMFC_Read(reg) DEVICE_READ(PRAMFC,reg)
  103. #define PRAMFC_Print(reg) DEVICE_PRINT(PRAMFC,reg)
  104. #define PRAMFC_Def(mask,value) DEVICE_DEF(PRAMFC,mask,value)
  105. #define PRAMFC_Val(mask,value) DEVICE_VALUE(PRAMFC,mask,value)
  106. #define PRAMFC_Mask(mask) DEVICE_MASK(PRAMFC,mask)
  107. #define PMC_Write(reg,value) DEVICE_WRITE(PMC,reg,value)
  108. #define PMC_Read(reg) DEVICE_READ(PMC,reg)
  109. #define PMC_Print(reg) DEVICE_PRINT(PMC,reg)
  110. #define PMC_Def(mask,value) DEVICE_DEF(PMC,mask,value)
  111. #define PMC_Val(mask,value) DEVICE_VALUE(PMC,mask,value)
  112. #define PMC_Mask(mask) DEVICE_MASK(PMC,mask)
  113. #define PMC_Write(reg,value) DEVICE_WRITE(PMC,reg,value)
  114. #define PMC_Read(reg) DEVICE_READ(PMC,reg)
  115. #define PMC_Print(reg) DEVICE_PRINT(PMC,reg)
  116. #define PMC_Def(mask,value) DEVICE_DEF(PMC,mask,value)
  117. #define PMC_Val(mask,value) DEVICE_VALUE(PMC,mask,value)
  118. #define PMC_Mask(mask) DEVICE_MASK(PMC,mask)
  119. #define PBUS_Write(reg,value) DEVICE_WRITE(PBUS,reg,value)
  120. #define PBUS_Read(reg) DEVICE_READ(PBUS,reg)
  121. #define PBUS_Print(reg) DEVICE_PRINT(PBUS,reg)
  122. #define PBUS_Def(mask,value) DEVICE_DEF(PBUS,mask,value)
  123. #define PBUS_Val(mask,value) DEVICE_VALUE(PBUS,mask,value)
  124. #define PBUS_Mask(mask) DEVICE_MASK(PBUS,mask)
  125. #define PRAMDAC_Write(reg,value) DEVICE_WRITE(PRAMDAC,reg,value)
  126. #define PRAMDAC_Read(reg) DEVICE_READ(PRAMDAC,reg)
  127. #define PRAMDAC_Print(reg) DEVICE_PRINT(PRAMDAC,reg)
  128. #define PRAMDAC_Def(mask,value) DEVICE_DEF(PRAMDAC,mask,value)
  129. #define PRAMDAC_Val(mask,value) DEVICE_VALUE(PRAMDAC,mask,value)
  130. #define PRAMDAC_Mask(mask) DEVICE_MASK(PRAMDAC,mask)
  131. #define PDAC_ReadExt(reg) \
  132. ((PDAC_Write(INDEX_LO,(NV_PDAC_EXT_##reg) & 0xff)),\
  133. (PDAC_Write(INDEX_HI,((NV_PDAC_EXT_##reg) >> 8) & 0xff)),\
  134. (PDAC_Read(INDEX_DATA)))
  135. #define PDAC_WriteExt(reg,value)\
  136. ((PDAC_Write(INDEX_LO,(NV_PDAC_EXT_##reg) & 0xff)),\
  137. (PDAC_Write(INDEX_HI,((NV_PDAC_EXT_##reg) >> 8) & 0xff)),\
  138. (PDAC_Write(INDEX_DATA,(value))))
  139. #define CRTC_Write(index,value) outb((index), 0x3d4); outb(value, 0x3d5)
  140. #define CRTC_Read(index) (outb(index, 0x3d4),inb(0x3d5))
  141. #define PCRTC_Write(index,value) CRTC_Write(NV_PCRTC_##index,value)
  142. #define PCRTC_Read(index) CRTC_Read(NV_PCRTC_##index)
  143. #define PCRTC_Def(mask,value) DEVICE_DEF(PCRTC,mask,value)
  144. #define PCRTC_Val(mask,value) DEVICE_VALUE(PCRTC,mask,value)
  145. #define PCRTC_Mask(mask) DEVICE_MASK(PCRTC,mask)
  146. #define SR_Write(index,value) outb(0x3c4,(index));outb(0x3c5,value)
  147. #define SR_Read(index) (outb(0x3c4,index),inb(0x3c5))
  148. extern volatile unsigned *nvCONTROL;
  149. typedef enum {NV1,NV3,NV4,NumNVChips} NVChipType;
  150. NVChipType GetChipType(void);
  151. #endif