nv40_fb.c 4.5 KB

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