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_mem.h"
32
33 #include <nvif/push906f.h>
34
35 #include <nvhw/class/cl9039.h>
36
37 int
nvc0_bo_move_m2mf(struct nouveau_channel * chan,struct ttm_buffer_object * bo,struct ttm_resource * old_reg,struct ttm_resource * new_reg)38 nvc0_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo,
39 struct ttm_resource *old_reg, struct ttm_resource *new_reg)
40 {
41 struct nvif_push *push = chan->chan.push;
42 struct nouveau_mem *mem = nouveau_mem(old_reg);
43 u64 src_offset = mem->vma[0].addr;
44 u64 dst_offset = mem->vma[1].addr;
45 u32 page_count = PFN_UP(new_reg->size);
46 int ret;
47
48 page_count = PFN_UP(new_reg->size);
49 while (page_count) {
50 int line_count = (page_count > 2047) ? 2047 : page_count;
51
52 ret = PUSH_WAIT(push, 12);
53 if (ret)
54 return ret;
55
56 PUSH_MTHD(push, NV9039, OFFSET_OUT_UPPER,
57 NVVAL(NV9039, OFFSET_OUT_UPPER, VALUE, upper_32_bits(dst_offset)),
58
59 OFFSET_OUT, lower_32_bits(dst_offset));
60
61 PUSH_MTHD(push, NV9039, OFFSET_IN_UPPER,
62 NVVAL(NV9039, OFFSET_IN_UPPER, VALUE, upper_32_bits(src_offset)),
63
64 OFFSET_IN, lower_32_bits(src_offset),
65 PITCH_IN, PAGE_SIZE,
66 PITCH_OUT, PAGE_SIZE,
67 LINE_LENGTH_IN, PAGE_SIZE,
68 LINE_COUNT, line_count);
69
70 PUSH_MTHD(push, NV9039, LAUNCH_DMA,
71 NVDEF(NV9039, LAUNCH_DMA, SRC_INLINE, FALSE) |
72 NVDEF(NV9039, LAUNCH_DMA, SRC_MEMORY_LAYOUT, PITCH) |
73 NVDEF(NV9039, LAUNCH_DMA, DST_MEMORY_LAYOUT, PITCH) |
74 NVDEF(NV9039, LAUNCH_DMA, COMPLETION_TYPE, FLUSH_DISABLE) |
75 NVDEF(NV9039, LAUNCH_DMA, INTERRUPT_TYPE, NONE) |
76 NVDEF(NV9039, LAUNCH_DMA, SEMAPHORE_STRUCT_SIZE, ONE_WORD));
77
78 page_count -= line_count;
79 src_offset += (PAGE_SIZE * line_count);
80 dst_offset += (PAGE_SIZE * line_count);
81 }
82
83 return 0;
84 }
85
86 int
nvc0_bo_move_init(struct nouveau_channel * chan,u32 handle)87 nvc0_bo_move_init(struct nouveau_channel *chan, u32 handle)
88 {
89 struct nvif_push *push = chan->chan.push;
90 int ret;
91
92 ret = PUSH_WAIT(push, 2);
93 if (ret)
94 return ret;
95
96 PUSH_MTHD(push, NV9039, SET_OBJECT, handle);
97 return 0;
98 }
99