nvc0_vm.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright 2010 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Ben Skeggs
  23. */
  24. #include "drmP.h"
  25. #include "nouveau_drv.h"
  26. #include "nouveau_vm.h"
  27. void
  28. nvc0_vm_map_pgt(struct nouveau_gpuobj *pgd, u32 index,
  29. struct nouveau_gpuobj *pgt[2])
  30. {
  31. u32 pde[2] = { 0, 0 };
  32. if (pgt[0])
  33. pde[1] = 0x00000001 | (pgt[0]->vinst >> 8);
  34. if (pgt[1])
  35. pde[0] = 0x00000001 | (pgt[1]->vinst >> 8);
  36. nv_wo32(pgd, (index * 8) + 0, pde[0]);
  37. nv_wo32(pgd, (index * 8) + 4, pde[1]);
  38. }
  39. static inline u64
  40. nvc0_vm_addr(struct nouveau_vma *vma, u64 phys, u32 memtype, u32 target)
  41. {
  42. phys >>= 8;
  43. phys |= 0x00000001; /* present */
  44. if (vma->access & NV_MEM_ACCESS_SYS)
  45. phys |= 0x00000002;
  46. phys |= ((u64)target << 32);
  47. phys |= ((u64)memtype << 36);
  48. return phys;
  49. }
  50. void
  51. nvc0_vm_map(struct nouveau_vma *vma, struct nouveau_gpuobj *pgt,
  52. struct nouveau_mem *mem, u32 pte, u32 cnt, u64 phys, u64 delta)
  53. {
  54. u32 next = 1 << (vma->node->type - 8);
  55. phys = nvc0_vm_addr(vma, phys, mem->memtype, 0);
  56. pte <<= 3;
  57. while (cnt--) {
  58. nv_wo32(pgt, pte + 0, lower_32_bits(phys));
  59. nv_wo32(pgt, pte + 4, upper_32_bits(phys));
  60. phys += next;
  61. pte += 8;
  62. }
  63. }
  64. void
  65. nvc0_vm_map_sg(struct nouveau_vma *vma, struct nouveau_gpuobj *pgt,
  66. struct nouveau_mem *mem, u32 pte, u32 cnt, dma_addr_t *list)
  67. {
  68. u32 target = (vma->access & NV_MEM_ACCESS_NOSNOOP) ? 7 : 5;
  69. pte <<= 3;
  70. while (cnt--) {
  71. u64 phys = nvc0_vm_addr(vma, *list++, mem->memtype, target);
  72. nv_wo32(pgt, pte + 0, lower_32_bits(phys));
  73. nv_wo32(pgt, pte + 4, upper_32_bits(phys));
  74. pte += 8;
  75. }
  76. }
  77. void
  78. nvc0_vm_unmap(struct nouveau_gpuobj *pgt, u32 pte, u32 cnt)
  79. {
  80. pte <<= 3;
  81. while (cnt--) {
  82. nv_wo32(pgt, pte + 0, 0x00000000);
  83. nv_wo32(pgt, pte + 4, 0x00000000);
  84. pte += 8;
  85. }
  86. }
  87. void
  88. nvc0_vm_flush(struct nouveau_vm *vm)
  89. {
  90. struct drm_nouveau_private *dev_priv = vm->dev->dev_private;
  91. struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem;
  92. struct drm_device *dev = vm->dev;
  93. struct nouveau_vm_pgd *vpgd;
  94. unsigned long flags;
  95. u32 engine;
  96. engine = 1;
  97. if (vm == dev_priv->bar1_vm || vm == dev_priv->bar3_vm)
  98. engine |= 4;
  99. pinstmem->flush(vm->dev);
  100. spin_lock_irqsave(&dev_priv->vm_lock, flags);
  101. list_for_each_entry(vpgd, &vm->pgd_list, head) {
  102. /* looks like maybe a "free flush slots" counter, the
  103. * faster you write to 0x100cbc to more it decreases
  104. */
  105. if (!nv_wait_ne(dev, 0x100c80, 0x00ff0000, 0x00000000)) {
  106. NV_ERROR(dev, "vm timeout 0: 0x%08x %d\n",
  107. nv_rd32(dev, 0x100c80), engine);
  108. }
  109. nv_wr32(dev, 0x100cb8, vpgd->obj->vinst >> 8);
  110. nv_wr32(dev, 0x100cbc, 0x80000000 | engine);
  111. /* wait for flush to be queued? */
  112. if (!nv_wait(dev, 0x100c80, 0x00008000, 0x00008000)) {
  113. NV_ERROR(dev, "vm timeout 1: 0x%08x %d\n",
  114. nv_rd32(dev, 0x100c80), engine);
  115. }
  116. }
  117. spin_unlock_irqrestore(&dev_priv->vm_lock, flags);
  118. }