nouveau_bo5039.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright 2007 Dave Airlied
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. /*
  25. * Authors: Dave Airlied <airlied@linux.ie>
  26. * Ben Skeggs <darktama@iinet.net.au>
  27. * Jeremy Kolb <jkolb@brandeis.edu>
  28. */
  29. #include "nouveau_bo.h"
  30. #include "nouveau_dma.h"
  31. #include "nouveau_drv.h"
  32. #include "nouveau_mem.h"
  33. #include <nvif/push206e.h>
  34. #include <nvhw/class/cl5039.h>
  35. int
  36. nv50_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo,
  37. struct ttm_resource *old_reg, struct ttm_resource *new_reg)
  38. {
  39. struct nouveau_mem *mem = nouveau_mem(old_reg);
  40. struct nvif_push *push = chan->chan.push;
  41. u64 length = (new_reg->num_pages << PAGE_SHIFT);
  42. u64 src_offset = mem->vma[0].addr;
  43. u64 dst_offset = mem->vma[1].addr;
  44. int src_tiled = !!mem->kind;
  45. int dst_tiled = !!nouveau_mem(new_reg)->kind;
  46. int ret;
  47. while (length) {
  48. u32 amount, stride, height;
  49. ret = PUSH_WAIT(push, 18 + 6 * (src_tiled + dst_tiled));
  50. if (ret)
  51. return ret;
  52. amount = min(length, (u64)(4 * 1024 * 1024));
  53. stride = 16 * 4;
  54. height = amount / stride;
  55. if (src_tiled) {
  56. PUSH_MTHD(push, NV5039, SET_SRC_MEMORY_LAYOUT,
  57. NVDEF(NV5039, SET_SRC_MEMORY_LAYOUT, V, BLOCKLINEAR),
  58. SET_SRC_BLOCK_SIZE,
  59. NVDEF(NV5039, SET_SRC_BLOCK_SIZE, WIDTH, ONE_GOB) |
  60. NVDEF(NV5039, SET_SRC_BLOCK_SIZE, HEIGHT, ONE_GOB) |
  61. NVDEF(NV5039, SET_SRC_BLOCK_SIZE, DEPTH, ONE_GOB),
  62. SET_SRC_WIDTH, stride,
  63. SET_SRC_HEIGHT, height,
  64. SET_SRC_DEPTH, 1,
  65. SET_SRC_LAYER, 0,
  66. SET_SRC_ORIGIN,
  67. NVVAL(NV5039, SET_SRC_ORIGIN, X, 0) |
  68. NVVAL(NV5039, SET_SRC_ORIGIN, Y, 0));
  69. } else {
  70. PUSH_MTHD(push, NV5039, SET_SRC_MEMORY_LAYOUT,
  71. NVDEF(NV5039, SET_SRC_MEMORY_LAYOUT, V, PITCH));
  72. }
  73. if (dst_tiled) {
  74. PUSH_MTHD(push, NV5039, SET_DST_MEMORY_LAYOUT,
  75. NVDEF(NV5039, SET_DST_MEMORY_LAYOUT, V, BLOCKLINEAR),
  76. SET_DST_BLOCK_SIZE,
  77. NVDEF(NV5039, SET_DST_BLOCK_SIZE, WIDTH, ONE_GOB) |
  78. NVDEF(NV5039, SET_DST_BLOCK_SIZE, HEIGHT, ONE_GOB) |
  79. NVDEF(NV5039, SET_DST_BLOCK_SIZE, DEPTH, ONE_GOB),
  80. SET_DST_WIDTH, stride,
  81. SET_DST_HEIGHT, height,
  82. SET_DST_DEPTH, 1,
  83. SET_DST_LAYER, 0,
  84. SET_DST_ORIGIN,
  85. NVVAL(NV5039, SET_DST_ORIGIN, X, 0) |
  86. NVVAL(NV5039, SET_DST_ORIGIN, Y, 0));
  87. } else {
  88. PUSH_MTHD(push, NV5039, SET_DST_MEMORY_LAYOUT,
  89. NVDEF(NV5039, SET_DST_MEMORY_LAYOUT, V, PITCH));
  90. }
  91. PUSH_MTHD(push, NV5039, OFFSET_IN_UPPER,
  92. NVVAL(NV5039, OFFSET_IN_UPPER, VALUE, upper_32_bits(src_offset)),
  93. OFFSET_OUT_UPPER,
  94. NVVAL(NV5039, OFFSET_OUT_UPPER, VALUE, upper_32_bits(dst_offset)));
  95. PUSH_MTHD(push, NV5039, OFFSET_IN, lower_32_bits(src_offset),
  96. OFFSET_OUT, lower_32_bits(dst_offset),
  97. PITCH_IN, stride,
  98. PITCH_OUT, stride,
  99. LINE_LENGTH_IN, stride,
  100. LINE_COUNT, height,
  101. FORMAT,
  102. NVDEF(NV5039, FORMAT, IN, ONE) |
  103. NVDEF(NV5039, FORMAT, OUT, ONE),
  104. BUFFER_NOTIFY,
  105. NVDEF(NV5039, BUFFER_NOTIFY, TYPE, WRITE_ONLY));
  106. PUSH_MTHD(push, NV5039, NO_OPERATION, 0x00000000);
  107. length -= amount;
  108. src_offset += amount;
  109. dst_offset += amount;
  110. }
  111. return 0;
  112. }
  113. int
  114. nv50_bo_move_init(struct nouveau_channel *chan, u32 handle)
  115. {
  116. struct nvif_push *push = chan->chan.push;
  117. int ret;
  118. ret = PUSH_WAIT(push, 6);
  119. if (ret)
  120. return ret;
  121. PUSH_MTHD(push, NV5039, SET_OBJECT, handle);
  122. PUSH_MTHD(push, NV5039, SET_CONTEXT_DMA_NOTIFY, chan->drm->ntfy.handle,
  123. SET_CONTEXT_DMA_BUFFER_IN, chan->vram.handle,
  124. SET_CONTEXT_DMA_BUFFER_OUT, chan->vram.handle);
  125. return 0;
  126. }