nouveau_bo0039.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 <[email protected]>
  26. * Ben Skeggs <[email protected]>
  27. * Jeremy Kolb <[email protected]>
  28. */
  29. #include "nouveau_bo.h"
  30. #include "nouveau_dma.h"
  31. #include "nouveau_drv.h"
  32. #include <nvif/push006c.h>
  33. #include <nvhw/class/cl0039.h>
  34. static inline uint32_t
  35. nouveau_bo_mem_ctxdma(struct ttm_buffer_object *bo,
  36. struct nouveau_channel *chan, struct ttm_resource *reg)
  37. {
  38. if (reg->mem_type == TTM_PL_TT)
  39. return NvDmaTT;
  40. return chan->vram.handle;
  41. }
  42. int
  43. nv04_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo,
  44. struct ttm_resource *old_reg, struct ttm_resource *new_reg)
  45. {
  46. struct nvif_push *push = chan->chan.push;
  47. u32 src_ctxdma = nouveau_bo_mem_ctxdma(bo, chan, old_reg);
  48. u32 src_offset = old_reg->start << PAGE_SHIFT;
  49. u32 dst_ctxdma = nouveau_bo_mem_ctxdma(bo, chan, new_reg);
  50. u32 dst_offset = new_reg->start << PAGE_SHIFT;
  51. u32 page_count = new_reg->num_pages;
  52. int ret;
  53. ret = PUSH_WAIT(push, 3);
  54. if (ret)
  55. return ret;
  56. PUSH_MTHD(push, NV039, SET_CONTEXT_DMA_BUFFER_IN, src_ctxdma,
  57. SET_CONTEXT_DMA_BUFFER_OUT, dst_ctxdma);
  58. page_count = new_reg->num_pages;
  59. while (page_count) {
  60. int line_count = (page_count > 2047) ? 2047 : page_count;
  61. ret = PUSH_WAIT(push, 11);
  62. if (ret)
  63. return ret;
  64. PUSH_MTHD(push, NV039, OFFSET_IN, src_offset,
  65. OFFSET_OUT, dst_offset,
  66. PITCH_IN, PAGE_SIZE,
  67. PITCH_OUT, PAGE_SIZE,
  68. LINE_LENGTH_IN, PAGE_SIZE,
  69. LINE_COUNT, line_count,
  70. FORMAT,
  71. NVVAL(NV039, FORMAT, IN, 1) |
  72. NVVAL(NV039, FORMAT, OUT, 1),
  73. BUFFER_NOTIFY, NV039_BUFFER_NOTIFY_WRITE_ONLY);
  74. PUSH_MTHD(push, NV039, NO_OPERATION, 0x00000000);
  75. page_count -= line_count;
  76. src_offset += (PAGE_SIZE * line_count);
  77. dst_offset += (PAGE_SIZE * line_count);
  78. }
  79. return 0;
  80. }
  81. int
  82. nv04_bo_move_init(struct nouveau_channel *chan, u32 handle)
  83. {
  84. struct nvif_push *push = chan->chan.push;
  85. int ret;
  86. ret = PUSH_WAIT(push, 4);
  87. if (ret)
  88. return ret;
  89. PUSH_MTHD(push, NV039, SET_OBJECT, handle);
  90. PUSH_MTHD(push, NV039, SET_CONTEXT_DMA_NOTIFIES, chan->drm->ntfy.handle);
  91. return 0;
  92. }