Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / nouveau / nouveau_bo9039.c
blob776b04976cdfa6f48461c47b5ccc1cd53f0d9f37
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_mem.h"
33 #include <nvif/push906f.h>
35 #include <nvhw/class/cl9039.h>
37 int
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)
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 = new_reg->num_pages;
46 int ret;
48 page_count = new_reg->num_pages;
49 while (page_count) {
50 int line_count = (page_count > 2047) ? 2047 : page_count;
52 ret = PUSH_WAIT(push, 12);
53 if (ret)
54 return ret;
56 PUSH_MTHD(push, NV9039, OFFSET_OUT_UPPER,
57 NVVAL(NV9039, OFFSET_OUT_UPPER, VALUE, upper_32_bits(dst_offset)),
59 OFFSET_OUT, lower_32_bits(dst_offset));
61 PUSH_MTHD(push, NV9039, OFFSET_IN_UPPER,
62 NVVAL(NV9039, OFFSET_IN_UPPER, VALUE, upper_32_bits(src_offset)),
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);
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));
78 page_count -= line_count;
79 src_offset += (PAGE_SIZE * line_count);
80 dst_offset += (PAGE_SIZE * line_count);
83 return 0;
86 int
87 nvc0_bo_move_init(struct nouveau_channel *chan, u32 handle)
89 struct nvif_push *push = chan->chan.push;
90 int ret;
92 ret = PUSH_WAIT(push, 2);
93 if (ret)
94 return ret;
96 PUSH_MTHD(push, NV9039, SET_OBJECT, handle);
97 return 0;