Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / nouveau / nouveau_bo5039.c
blob4c75c7b3804ca4cdc45fbbd483dff266cc73350b
1 /*
2 * Copyright 2007 Dave Airlied
3 * All Rights Reserved.
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
14 * Software.
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>
38 int
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;
49 int ret;
51 while (length) {
52 u32 amount, stride, height;
54 ret = PUSH_WAIT(push, 18 + 6 * (src_tiled + dst_tiled));
55 if (ret)
56 return ret;
58 amount = min(length, (u64)(4 * 1024 * 1024));
59 stride = 16 * 4;
60 height = amount / stride;
62 if (src_tiled) {
63 PUSH_MTHD(push, NV5039, SET_SRC_MEMORY_LAYOUT,
64 NVDEF(NV5039, SET_SRC_MEMORY_LAYOUT, V, BLOCKLINEAR),
66 SET_SRC_BLOCK_SIZE,
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,
73 SET_SRC_DEPTH, 1,
74 SET_SRC_LAYER, 0,
76 SET_SRC_ORIGIN,
77 NVVAL(NV5039, SET_SRC_ORIGIN, X, 0) |
78 NVVAL(NV5039, SET_SRC_ORIGIN, Y, 0));
79 } else {
80 PUSH_MTHD(push, NV5039, SET_SRC_MEMORY_LAYOUT,
81 NVDEF(NV5039, SET_SRC_MEMORY_LAYOUT, V, PITCH));
84 if (dst_tiled) {
85 PUSH_MTHD(push, NV5039, SET_DST_MEMORY_LAYOUT,
86 NVDEF(NV5039, SET_DST_MEMORY_LAYOUT, V, BLOCKLINEAR),
88 SET_DST_BLOCK_SIZE,
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,
95 SET_DST_DEPTH, 1,
96 SET_DST_LAYER, 0,
98 SET_DST_ORIGIN,
99 NVVAL(NV5039, SET_DST_ORIGIN, X, 0) |
100 NVVAL(NV5039, SET_DST_ORIGIN, Y, 0));
101 } else {
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)),
109 OFFSET_OUT_UPPER,
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),
114 PITCH_IN, stride,
115 PITCH_OUT, stride,
116 LINE_LENGTH_IN, stride,
117 LINE_COUNT, height,
119 FORMAT,
120 NVDEF(NV5039, FORMAT, IN, ONE) |
121 NVDEF(NV5039, FORMAT, OUT, ONE),
123 BUFFER_NOTIFY,
124 NVDEF(NV5039, BUFFER_NOTIFY, TYPE, WRITE_ONLY));
126 PUSH_MTHD(push, NV5039, NO_OPERATION, 0x00000000);
128 length -= amount;
129 src_offset += amount;
130 dst_offset += amount;
133 return 0;
137 nv50_bo_move_init(struct nouveau_channel *chan, u32 handle)
139 struct nvif_push *push = chan->chan.push;
140 int ret;
142 ret = PUSH_WAIT(push, 6);
143 if (ret)
144 return ret;
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);
150 return 0;