nv04_instmem.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #include "drmP.h"
  2. #include "drm.h"
  3. #include "nouveau_drv.h"
  4. /* returns the size of fifo context */
  5. static int
  6. nouveau_fifo_ctx_size(struct drm_device *dev)
  7. {
  8. struct drm_nouveau_private *dev_priv = dev->dev_private;
  9. if (dev_priv->chipset >= 0x40)
  10. return 128;
  11. else
  12. if (dev_priv->chipset >= 0x17)
  13. return 64;
  14. return 32;
  15. }
  16. static void
  17. nv04_instmem_determine_amount(struct drm_device *dev)
  18. {
  19. struct drm_nouveau_private *dev_priv = dev->dev_private;
  20. int i;
  21. /* Figure out how much instance memory we need */
  22. if (dev_priv->card_type >= NV_40) {
  23. /* We'll want more instance memory than this on some NV4x cards.
  24. * There's a 16MB aperture to play with that maps onto the end
  25. * of vram. For now, only reserve a small piece until we know
  26. * more about what each chipset requires.
  27. */
  28. switch (dev_priv->chipset) {
  29. case 0x40:
  30. case 0x47:
  31. case 0x49:
  32. case 0x4b:
  33. dev_priv->ramin_rsvd_vram = (2 * 1024 * 1024);
  34. break;
  35. default:
  36. dev_priv->ramin_rsvd_vram = (1 * 1024 * 1024);
  37. break;
  38. }
  39. } else {
  40. /*XXX: what *are* the limits on <NV40 cards?
  41. */
  42. dev_priv->ramin_rsvd_vram = (512 * 1024);
  43. }
  44. NV_DEBUG(dev, "RAMIN size: %dKiB\n", dev_priv->ramin_rsvd_vram >> 10);
  45. /* Clear all of it, except the BIOS image that's in the first 64KiB */
  46. for (i = 64 * 1024; i < dev_priv->ramin_rsvd_vram; i += 4)
  47. nv_wi32(dev, i, 0x00000000);
  48. }
  49. static void
  50. nv04_instmem_configure_fixed_tables(struct drm_device *dev)
  51. {
  52. struct drm_nouveau_private *dev_priv = dev->dev_private;
  53. struct nouveau_engine *engine = &dev_priv->engine;
  54. /* FIFO hash table (RAMHT)
  55. * use 4k hash table at RAMIN+0x10000
  56. * TODO: extend the hash table
  57. */
  58. dev_priv->ramht_offset = 0x10000;
  59. dev_priv->ramht_bits = 9;
  60. dev_priv->ramht_size = (1 << dev_priv->ramht_bits); /* nr entries */
  61. dev_priv->ramht_size *= 8; /* 2 32-bit values per entry in RAMHT */
  62. NV_DEBUG(dev, "RAMHT offset=0x%x, size=%d\n", dev_priv->ramht_offset,
  63. dev_priv->ramht_size);
  64. /* FIFO runout table (RAMRO) - 512k at 0x11200 */
  65. dev_priv->ramro_offset = 0x11200;
  66. dev_priv->ramro_size = 512;
  67. NV_DEBUG(dev, "RAMRO offset=0x%x, size=%d\n", dev_priv->ramro_offset,
  68. dev_priv->ramro_size);
  69. /* FIFO context table (RAMFC)
  70. * NV40 : Not sure exactly how to position RAMFC on some cards,
  71. * 0x30002 seems to position it at RAMIN+0x20000 on these
  72. * cards. RAMFC is 4kb (32 fifos, 128byte entries).
  73. * Others: Position RAMFC at RAMIN+0x11400
  74. */
  75. dev_priv->ramfc_size = engine->fifo.channels *
  76. nouveau_fifo_ctx_size(dev);
  77. switch (dev_priv->card_type) {
  78. case NV_40:
  79. dev_priv->ramfc_offset = 0x20000;
  80. break;
  81. case NV_30:
  82. case NV_20:
  83. case NV_10:
  84. case NV_04:
  85. default:
  86. dev_priv->ramfc_offset = 0x11400;
  87. break;
  88. }
  89. NV_DEBUG(dev, "RAMFC offset=0x%x, size=%d\n", dev_priv->ramfc_offset,
  90. dev_priv->ramfc_size);
  91. }
  92. int nv04_instmem_init(struct drm_device *dev)
  93. {
  94. struct drm_nouveau_private *dev_priv = dev->dev_private;
  95. uint32_t offset;
  96. int ret;
  97. nv04_instmem_determine_amount(dev);
  98. nv04_instmem_configure_fixed_tables(dev);
  99. /* Create a heap to manage RAMIN allocations, we don't allocate
  100. * the space that was reserved for RAMHT/FC/RO.
  101. */
  102. offset = dev_priv->ramfc_offset + dev_priv->ramfc_size;
  103. /* It appears RAMRO (or something?) is controlled by 0x2220/0x2230
  104. * on certain NV4x chipsets as well as RAMFC. When 0x2230 == 0
  105. * ("new style" control) the upper 16-bits of 0x2220 points at this
  106. * other mysterious table that's clobbering important things.
  107. *
  108. * We're now pointing this at RAMIN+0x30000 to avoid RAMFC getting
  109. * smashed to pieces on us, so reserve 0x30000-0x40000 too..
  110. */
  111. if (dev_priv->card_type >= NV_40) {
  112. if (offset < 0x40000)
  113. offset = 0x40000;
  114. }
  115. ret = drm_mm_init(&dev_priv->ramin_heap, offset,
  116. dev_priv->ramin_rsvd_vram - offset);
  117. if (ret) {
  118. NV_ERROR(dev, "Failed to init RAMIN heap: %d\n", ret);
  119. return ret;
  120. }
  121. return 0;
  122. }
  123. void
  124. nv04_instmem_takedown(struct drm_device *dev)
  125. {
  126. }
  127. int
  128. nv04_instmem_populate(struct drm_device *dev, struct nouveau_gpuobj *gpuobj, uint32_t *sz)
  129. {
  130. if (gpuobj->im_backing)
  131. return -EINVAL;
  132. return 0;
  133. }
  134. void
  135. nv04_instmem_clear(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
  136. {
  137. struct drm_nouveau_private *dev_priv = dev->dev_private;
  138. if (gpuobj && gpuobj->im_backing) {
  139. if (gpuobj->im_bound)
  140. dev_priv->engine.instmem.unbind(dev, gpuobj);
  141. gpuobj->im_backing = NULL;
  142. }
  143. }
  144. int
  145. nv04_instmem_bind(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
  146. {
  147. if (!gpuobj->im_pramin || gpuobj->im_bound)
  148. return -EINVAL;
  149. gpuobj->im_bound = 1;
  150. return 0;
  151. }
  152. int
  153. nv04_instmem_unbind(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
  154. {
  155. if (gpuobj->im_bound == 0)
  156. return -EINVAL;
  157. gpuobj->im_bound = 0;
  158. return 0;
  159. }
  160. void
  161. nv04_instmem_flush(struct drm_device *dev)
  162. {
  163. }
  164. int
  165. nv04_instmem_suspend(struct drm_device *dev)
  166. {
  167. return 0;
  168. }
  169. void
  170. nv04_instmem_resume(struct drm_device *dev)
  171. {
  172. }