2 * Copyright 2007 Dave Airlied
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:
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
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.
25 * Authors: Dave Airlied <airlied@linux.ie>
26 * Ben Skeggs <darktama@iinet.net.au>
27 * Jeremy Kolb <jkolb@brandeis.edu>
29 #include "nouveau_bo.h"
30 #include "nouveau_dma.h"
31 #include "nouveau_drv.h"
32 #include "nouveau_mem.h"
34 #include <nvif/push206e.h>
36 #include <nvhw/class/cl5039.h>
39 nv50_bo_move_m2mf(struct nouveau_channel
*chan
, struct ttm_buffer_object
*bo
,
40 struct ttm_resource
*old_reg
, struct ttm_resource
*new_reg
)
42 struct nouveau_mem
*mem
= nouveau_mem(old_reg
);
43 struct nvif_push
*push
= chan
->chan
.push
;
44 u64 length
= (new_reg
->num_pages
<< PAGE_SHIFT
);
45 u64 src_offset
= mem
->vma
[0].addr
;
46 u64 dst_offset
= mem
->vma
[1].addr
;
47 int src_tiled
= !!mem
->kind
;
48 int dst_tiled
= !!nouveau_mem(new_reg
)->kind
;
52 u32 amount
, stride
, height
;
54 ret
= PUSH_WAIT(push
, 18 + 6 * (src_tiled
+ dst_tiled
));
58 amount
= min(length
, (u64
)(4 * 1024 * 1024));
60 height
= amount
/ stride
;
63 PUSH_MTHD(push
, NV5039
, SET_SRC_MEMORY_LAYOUT
,
64 NVDEF(NV5039
, SET_SRC_MEMORY_LAYOUT
, V
, BLOCKLINEAR
),
67 NVDEF(NV5039
, SET_SRC_BLOCK_SIZE
, WIDTH
, ONE_GOB
) |
68 NVDEF(NV5039
, SET_SRC_BLOCK_SIZE
, HEIGHT
, ONE_GOB
) |
69 NVDEF(NV5039
, SET_SRC_BLOCK_SIZE
, DEPTH
, ONE_GOB
),
71 SET_SRC_WIDTH
, stride
,
72 SET_SRC_HEIGHT
, height
,
77 NVVAL(NV5039
, SET_SRC_ORIGIN
, X
, 0) |
78 NVVAL(NV5039
, SET_SRC_ORIGIN
, Y
, 0));
80 PUSH_MTHD(push
, NV5039
, SET_SRC_MEMORY_LAYOUT
,
81 NVDEF(NV5039
, SET_SRC_MEMORY_LAYOUT
, V
, PITCH
));
85 PUSH_MTHD(push
, NV5039
, SET_DST_MEMORY_LAYOUT
,
86 NVDEF(NV5039
, SET_DST_MEMORY_LAYOUT
, V
, BLOCKLINEAR
),
89 NVDEF(NV5039
, SET_DST_BLOCK_SIZE
, WIDTH
, ONE_GOB
) |
90 NVDEF(NV5039
, SET_DST_BLOCK_SIZE
, HEIGHT
, ONE_GOB
) |
91 NVDEF(NV5039
, SET_DST_BLOCK_SIZE
, DEPTH
, ONE_GOB
),
93 SET_DST_WIDTH
, stride
,
94 SET_DST_HEIGHT
, height
,
99 NVVAL(NV5039
, SET_DST_ORIGIN
, X
, 0) |
100 NVVAL(NV5039
, SET_DST_ORIGIN
, Y
, 0));
102 PUSH_MTHD(push
, NV5039
, SET_DST_MEMORY_LAYOUT
,
103 NVDEF(NV5039
, SET_DST_MEMORY_LAYOUT
, V
, PITCH
));
106 PUSH_MTHD(push
, NV5039
, OFFSET_IN_UPPER
,
107 NVVAL(NV5039
, OFFSET_IN_UPPER
, VALUE
, upper_32_bits(src_offset
)),
110 NVVAL(NV5039
, OFFSET_OUT_UPPER
, VALUE
, upper_32_bits(dst_offset
)));
112 PUSH_MTHD(push
, NV5039
, OFFSET_IN
, lower_32_bits(src_offset
),
113 OFFSET_OUT
, lower_32_bits(dst_offset
),
116 LINE_LENGTH_IN
, stride
,
120 NVDEF(NV5039
, FORMAT
, IN
, ONE
) |
121 NVDEF(NV5039
, FORMAT
, OUT
, ONE
),
124 NVDEF(NV5039
, BUFFER_NOTIFY
, TYPE
, WRITE_ONLY
));
126 PUSH_MTHD(push
, NV5039
, NO_OPERATION
, 0x00000000);
129 src_offset
+= amount
;
130 dst_offset
+= amount
;
137 nv50_bo_move_init(struct nouveau_channel
*chan
, u32 handle
)
139 struct nvif_push
*push
= chan
->chan
.push
;
142 ret
= PUSH_WAIT(push
, 6);
146 PUSH_MTHD(push
, NV5039
, SET_OBJECT
, handle
);
147 PUSH_MTHD(push
, NV5039
, SET_CONTEXT_DMA_NOTIFY
, chan
->drm
->ntfy
.handle
,
148 SET_CONTEXT_DMA_BUFFER_IN
, chan
->vram
.handle
,
149 SET_CONTEXT_DMA_BUFFER_OUT
, chan
->vram
.handle
);