nv40_fb.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #include "drmP.h"
  2. #include "nouveau_drv.h"
  3. #include "nouveau_drm.h"
  4. void
  5. nv40_fb_set_tile_region(struct drm_device *dev, int i)
  6. {
  7. struct drm_nouveau_private *dev_priv = dev->dev_private;
  8. struct nouveau_tile_reg *tile = &dev_priv->tile.reg[i];
  9. switch (dev_priv->chipset) {
  10. case 0x40:
  11. nv_wr32(dev, NV10_PFB_TLIMIT(i), tile->limit);
  12. nv_wr32(dev, NV10_PFB_TSIZE(i), tile->pitch);
  13. nv_wr32(dev, NV10_PFB_TILE(i), tile->addr);
  14. break;
  15. default:
  16. nv_wr32(dev, NV40_PFB_TLIMIT(i), tile->limit);
  17. nv_wr32(dev, NV40_PFB_TSIZE(i), tile->pitch);
  18. nv_wr32(dev, NV40_PFB_TILE(i), tile->addr);
  19. break;
  20. }
  21. }
  22. static void
  23. nv40_fb_init_gart(struct drm_device *dev)
  24. {
  25. struct drm_nouveau_private *dev_priv = dev->dev_private;
  26. struct nouveau_gpuobj *gart = dev_priv->gart_info.sg_ctxdma;
  27. if (dev_priv->gart_info.type != NOUVEAU_GART_HW) {
  28. nv_wr32(dev, 0x100800, 0x00000001);
  29. return;
  30. }
  31. nv_wr32(dev, 0x100800, gart->pinst | 0x00000002);
  32. nv_mask(dev, 0x10008c, 0x00000100, 0x00000100);
  33. nv_wr32(dev, 0x100820, 0x00000000);
  34. }
  35. static void
  36. nv44_fb_init_gart(struct drm_device *dev)
  37. {
  38. struct drm_nouveau_private *dev_priv = dev->dev_private;
  39. struct nouveau_gpuobj *gart = dev_priv->gart_info.sg_ctxdma;
  40. u32 vinst;
  41. if (dev_priv->gart_info.type != NOUVEAU_GART_HW) {
  42. nv_wr32(dev, 0x100850, 0x80000000);
  43. nv_wr32(dev, 0x100800, 0x00000001);
  44. return;
  45. }
  46. /* calculate vram address of this PRAMIN block, object
  47. * must be allocated on 512KiB alignment, and not exceed
  48. * a total size of 512KiB for this to work correctly
  49. */
  50. vinst = nv_rd32(dev, 0x10020c);
  51. vinst -= ((gart->pinst >> 19) + 1) << 19;
  52. nv_wr32(dev, 0x100850, 0x80000000);
  53. nv_wr32(dev, 0x100818, dev_priv->gart_info.dummy.addr);
  54. nv_wr32(dev, 0x100804, dev_priv->gart_info.aper_size);
  55. nv_wr32(dev, 0x100850, 0x00008000);
  56. nv_mask(dev, 0x10008c, 0x00000200, 0x00000200);
  57. nv_wr32(dev, 0x100820, 0x00000000);
  58. nv_wr32(dev, 0x10082c, 0x00000001);
  59. nv_wr32(dev, 0x100800, vinst | 0x00000010);
  60. }
  61. int
  62. nv40_fb_vram_init(struct drm_device *dev)
  63. {
  64. struct drm_nouveau_private *dev_priv = dev->dev_private;
  65. /* 0x001218 is actually present on a few other NV4X I looked at,
  66. * and even contains sane values matching 0x100474. From looking
  67. * at various vbios images however, this isn't the case everywhere.
  68. * So, I chose to use the same regs I've seen NVIDIA reading around
  69. * the memory detection, hopefully that'll get us the right numbers
  70. */
  71. if (dev_priv->chipset == 0x40) {
  72. u32 pbus1218 = nv_rd32(dev, 0x001218);
  73. switch (pbus1218 & 0x00000300) {
  74. case 0x00000000: dev_priv->vram_type = NV_MEM_TYPE_SDRAM; break;
  75. case 0x00000100: dev_priv->vram_type = NV_MEM_TYPE_DDR1; break;
  76. case 0x00000200: dev_priv->vram_type = NV_MEM_TYPE_GDDR3; break;
  77. case 0x00000300: dev_priv->vram_type = NV_MEM_TYPE_DDR2; break;
  78. }
  79. } else
  80. if (dev_priv->chipset == 0x49 || dev_priv->chipset == 0x4b) {
  81. u32 pfb914 = nv_rd32(dev, 0x100914);
  82. switch (pfb914 & 0x00000003) {
  83. case 0x00000000: dev_priv->vram_type = NV_MEM_TYPE_DDR1; break;
  84. case 0x00000001: dev_priv->vram_type = NV_MEM_TYPE_DDR2; break;
  85. case 0x00000002: dev_priv->vram_type = NV_MEM_TYPE_GDDR3; break;
  86. case 0x00000003: break;
  87. }
  88. } else
  89. if (dev_priv->chipset != 0x4e) {
  90. u32 pfb474 = nv_rd32(dev, 0x100474);
  91. if (pfb474 & 0x00000004)
  92. dev_priv->vram_type = NV_MEM_TYPE_GDDR3;
  93. if (pfb474 & 0x00000002)
  94. dev_priv->vram_type = NV_MEM_TYPE_DDR2;
  95. if (pfb474 & 0x00000001)
  96. dev_priv->vram_type = NV_MEM_TYPE_DDR1;
  97. } else {
  98. dev_priv->vram_type = NV_MEM_TYPE_STOLEN;
  99. }
  100. dev_priv->vram_size = nv_rd32(dev, 0x10020c) & 0xff000000;
  101. return 0;
  102. }
  103. int
  104. nv40_fb_init(struct drm_device *dev)
  105. {
  106. struct drm_nouveau_private *dev_priv = dev->dev_private;
  107. struct nouveau_fb_engine *pfb = &dev_priv->engine.fb;
  108. uint32_t tmp;
  109. int i;
  110. if (dev_priv->chipset != 0x40 && dev_priv->chipset != 0x45) {
  111. if (nv44_graph_class(dev))
  112. nv44_fb_init_gart(dev);
  113. else
  114. nv40_fb_init_gart(dev);
  115. }
  116. switch (dev_priv->chipset) {
  117. case 0x40:
  118. case 0x45:
  119. tmp = nv_rd32(dev, NV10_PFB_CLOSE_PAGE2);
  120. nv_wr32(dev, NV10_PFB_CLOSE_PAGE2, tmp & ~(1 << 15));
  121. pfb->num_tiles = NV10_PFB_TILE__SIZE;
  122. break;
  123. case 0x46: /* G72 */
  124. case 0x47: /* G70 */
  125. case 0x49: /* G71 */
  126. case 0x4b: /* G73 */
  127. case 0x4c: /* C51 (G7X version) */
  128. pfb->num_tiles = NV40_PFB_TILE__SIZE_1;
  129. break;
  130. default:
  131. pfb->num_tiles = NV40_PFB_TILE__SIZE_0;
  132. break;
  133. }
  134. /* Turn all the tiling regions off. */
  135. for (i = 0; i < pfb->num_tiles; i++)
  136. pfb->set_tile_region(dev, i);
  137. return 0;
  138. }
  139. void
  140. nv40_fb_takedown(struct drm_device *dev)
  141. {
  142. }