nv04_instmem.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 & 0xf0) {
  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. dev_priv->engine.instmem.prepare_access(dev, true);
  47. for (i = 64 * 1024; i < dev_priv->ramin_rsvd_vram; i += 4)
  48. nv_wi32(dev, i, 0x00000000);
  49. dev_priv->engine.instmem.finish_access(dev);
  50. }
  51. static void
  52. nv04_instmem_configure_fixed_tables(struct drm_device *dev)
  53. {
  54. struct drm_nouveau_private *dev_priv = dev->dev_private;
  55. struct nouveau_engine *engine = &dev_priv->engine;
  56. /* FIFO hash table (RAMHT)
  57. * use 4k hash table at RAMIN+0x10000
  58. * TODO: extend the hash table
  59. */
  60. dev_priv->ramht_offset = 0x10000;
  61. dev_priv->ramht_bits = 9;
  62. dev_priv->ramht_size = (1 << dev_priv->ramht_bits); /* nr entries */
  63. dev_priv->ramht_size *= 8; /* 2 32-bit values per entry in RAMHT */
  64. NV_DEBUG(dev, "RAMHT offset=0x%x, size=%d\n", dev_priv->ramht_offset,
  65. dev_priv->ramht_size);
  66. /* FIFO runout table (RAMRO) - 512k at 0x11200 */
  67. dev_priv->ramro_offset = 0x11200;
  68. dev_priv->ramro_size = 512;
  69. NV_DEBUG(dev, "RAMRO offset=0x%x, size=%d\n", dev_priv->ramro_offset,
  70. dev_priv->ramro_size);
  71. /* FIFO context table (RAMFC)
  72. * NV40 : Not sure exactly how to position RAMFC on some cards,
  73. * 0x30002 seems to position it at RAMIN+0x20000 on these
  74. * cards. RAMFC is 4kb (32 fifos, 128byte entries).
  75. * Others: Position RAMFC at RAMIN+0x11400
  76. */
  77. dev_priv->ramfc_size = engine->fifo.channels *
  78. nouveau_fifo_ctx_size(dev);
  79. switch (dev_priv->card_type) {
  80. case NV_40:
  81. dev_priv->ramfc_offset = 0x20000;
  82. break;
  83. case NV_30:
  84. case NV_20:
  85. case NV_10:
  86. case NV_04:
  87. default:
  88. dev_priv->ramfc_offset = 0x11400;
  89. break;
  90. }
  91. NV_DEBUG(dev, "RAMFC offset=0x%x, size=%d\n", dev_priv->ramfc_offset,
  92. dev_priv->ramfc_size);
  93. }
  94. int nv04_instmem_init(struct drm_device *dev)
  95. {
  96. struct drm_nouveau_private *dev_priv = dev->dev_private;
  97. uint32_t offset;
  98. int ret = 0;
  99. nv04_instmem_determine_amount(dev);
  100. nv04_instmem_configure_fixed_tables(dev);
  101. /* Create a heap to manage RAMIN allocations, we don't allocate
  102. * the space that was reserved for RAMHT/FC/RO.
  103. */
  104. offset = dev_priv->ramfc_offset + dev_priv->ramfc_size;
  105. /* It appears RAMRO (or something?) is controlled by 0x2220/0x2230
  106. * on certain NV4x chipsets as well as RAMFC. When 0x2230 == 0
  107. * ("new style" control) the upper 16-bits of 0x2220 points at this
  108. * other mysterious table that's clobbering important things.
  109. *
  110. * We're now pointing this at RAMIN+0x30000 to avoid RAMFC getting
  111. * smashed to pieces on us, so reserve 0x30000-0x40000 too..
  112. */
  113. if (dev_priv->card_type >= NV_40) {
  114. if (offset < 0x40000)
  115. offset = 0x40000;
  116. }
  117. ret = nouveau_mem_init_heap(&dev_priv->ramin_heap,
  118. offset, dev_priv->ramin_rsvd_vram - offset);
  119. if (ret) {
  120. dev_priv->ramin_heap = NULL;
  121. NV_ERROR(dev, "Failed to init RAMIN heap\n");
  122. }
  123. return ret;
  124. }
  125. void
  126. nv04_instmem_takedown(struct drm_device *dev)
  127. {
  128. }
  129. int
  130. nv04_instmem_populate(struct drm_device *dev, struct nouveau_gpuobj *gpuobj, uint32_t *sz)
  131. {
  132. if (gpuobj->im_backing)
  133. return -EINVAL;
  134. return 0;
  135. }
  136. void
  137. nv04_instmem_clear(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
  138. {
  139. struct drm_nouveau_private *dev_priv = dev->dev_private;
  140. if (gpuobj && gpuobj->im_backing) {
  141. if (gpuobj->im_bound)
  142. dev_priv->engine.instmem.unbind(dev, gpuobj);
  143. gpuobj->im_backing = NULL;
  144. }
  145. }
  146. int
  147. nv04_instmem_bind(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
  148. {
  149. if (!gpuobj->im_pramin || gpuobj->im_bound)
  150. return -EINVAL;
  151. gpuobj->im_bound = 1;
  152. return 0;
  153. }
  154. int
  155. nv04_instmem_unbind(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
  156. {
  157. if (gpuobj->im_bound == 0)
  158. return -EINVAL;
  159. gpuobj->im_bound = 0;
  160. return 0;
  161. }
  162. void
  163. nv04_instmem_prepare_access(struct drm_device *dev, bool write)
  164. {
  165. }
  166. void
  167. nv04_instmem_finish_access(struct drm_device *dev)
  168. {
  169. }
  170. int
  171. nv04_instmem_suspend(struct drm_device *dev)
  172. {
  173. return 0;
  174. }
  175. void
  176. nv04_instmem_resume(struct drm_device *dev)
  177. {
  178. }