Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 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_drv.h" |
| 32 | #include "nouveau_mem.h" |
| 33 | |
Ben Skeggs | 01c43a6 | 2020-06-22 15:54:52 +1000 | [diff] [blame] | 34 | #include <nvif/push206e.h> |
| 35 | |
Ben Skeggs | e767835 | 2020-06-22 16:29:45 +1000 | [diff] [blame] | 36 | #include <nvhw/class/cl5039.h> |
| 37 | |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 38 | int |
| 39 | nv50_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo, |
Thomas Zimmermann | 534b1f9 | 2020-08-12 19:17:18 +0200 | [diff] [blame] | 40 | struct ttm_resource *old_reg, struct ttm_resource *new_reg) |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 41 | { |
| 42 | struct nouveau_mem *mem = nouveau_mem(old_reg); |
Ben Skeggs | fe4249a | 2020-06-22 16:20:32 +1000 | [diff] [blame] | 43 | struct nvif_push *push = chan->chan.push; |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 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; |
| 50 | |
| 51 | while (length) { |
| 52 | u32 amount, stride, height; |
| 53 | |
Ben Skeggs | fe4249a | 2020-06-22 16:20:32 +1000 | [diff] [blame] | 54 | ret = PUSH_WAIT(push, 18 + 6 * (src_tiled + dst_tiled)); |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 55 | if (ret) |
| 56 | return ret; |
| 57 | |
| 58 | amount = min(length, (u64)(4 * 1024 * 1024)); |
| 59 | stride = 16 * 4; |
| 60 | height = amount / stride; |
| 61 | |
| 62 | if (src_tiled) { |
Ben Skeggs | 6c75137 | 2020-06-22 17:07:31 +1000 | [diff] [blame] | 63 | PUSH_MTHD(push, NV5039, SET_SRC_MEMORY_LAYOUT, |
| 64 | NVDEF(NV5039, SET_SRC_MEMORY_LAYOUT, V, BLOCKLINEAR), |
| 65 | |
| 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), |
| 70 | |
| 71 | SET_SRC_WIDTH, stride, |
| 72 | SET_SRC_HEIGHT, height, |
| 73 | SET_SRC_DEPTH, 1, |
| 74 | SET_SRC_LAYER, 0, |
| 75 | |
| 76 | SET_SRC_ORIGIN, |
| 77 | NVVAL(NV5039, SET_SRC_ORIGIN, X, 0) | |
| 78 | NVVAL(NV5039, SET_SRC_ORIGIN, Y, 0)); |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 79 | } else { |
Ben Skeggs | 6c75137 | 2020-06-22 17:07:31 +1000 | [diff] [blame] | 80 | PUSH_MTHD(push, NV5039, SET_SRC_MEMORY_LAYOUT, |
| 81 | NVDEF(NV5039, SET_SRC_MEMORY_LAYOUT, V, PITCH)); |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 82 | } |
| 83 | |
Ben Skeggs | fe4249a | 2020-06-22 16:20:32 +1000 | [diff] [blame] | 84 | if (dst_tiled) { |
Ben Skeggs | 6c75137 | 2020-06-22 17:07:31 +1000 | [diff] [blame] | 85 | PUSH_MTHD(push, NV5039, SET_DST_MEMORY_LAYOUT, |
| 86 | NVDEF(NV5039, SET_DST_MEMORY_LAYOUT, V, BLOCKLINEAR), |
| 87 | |
| 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), |
| 92 | |
| 93 | SET_DST_WIDTH, stride, |
| 94 | SET_DST_HEIGHT, height, |
| 95 | SET_DST_DEPTH, 1, |
| 96 | SET_DST_LAYER, 0, |
| 97 | |
| 98 | SET_DST_ORIGIN, |
| 99 | NVVAL(NV5039, SET_DST_ORIGIN, X, 0) | |
| 100 | NVVAL(NV5039, SET_DST_ORIGIN, Y, 0)); |
Ben Skeggs | fe4249a | 2020-06-22 16:20:32 +1000 | [diff] [blame] | 101 | } else { |
Ben Skeggs | 6c75137 | 2020-06-22 17:07:31 +1000 | [diff] [blame] | 102 | PUSH_MTHD(push, NV5039, SET_DST_MEMORY_LAYOUT, |
| 103 | NVDEF(NV5039, SET_DST_MEMORY_LAYOUT, V, PITCH)); |
Ben Skeggs | fe4249a | 2020-06-22 16:20:32 +1000 | [diff] [blame] | 104 | } |
| 105 | |
Ben Skeggs | 6c75137 | 2020-06-22 17:07:31 +1000 | [diff] [blame] | 106 | PUSH_MTHD(push, NV5039, OFFSET_IN_UPPER, |
| 107 | NVVAL(NV5039, OFFSET_IN_UPPER, VALUE, upper_32_bits(src_offset)), |
| 108 | |
| 109 | OFFSET_OUT_UPPER, |
| 110 | NVVAL(NV5039, OFFSET_OUT_UPPER, VALUE, upper_32_bits(dst_offset))); |
| 111 | |
| 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, |
| 118 | |
| 119 | FORMAT, |
| 120 | NVDEF(NV5039, FORMAT, IN, ONE) | |
| 121 | NVDEF(NV5039, FORMAT, OUT, ONE), |
| 122 | |
| 123 | BUFFER_NOTIFY, |
| 124 | NVDEF(NV5039, BUFFER_NOTIFY, TYPE, WRITE_ONLY)); |
| 125 | |
| 126 | PUSH_MTHD(push, NV5039, NO_OPERATION, 0x00000000); |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 127 | |
| 128 | length -= amount; |
| 129 | src_offset += amount; |
| 130 | dst_offset += amount; |
| 131 | } |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | int |
| 137 | nv50_bo_move_init(struct nouveau_channel *chan, u32 handle) |
| 138 | { |
Ben Skeggs | 01c43a6 | 2020-06-22 15:54:52 +1000 | [diff] [blame] | 139 | struct nvif_push *push = chan->chan.push; |
| 140 | int ret; |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 141 | |
Ben Skeggs | 01c43a6 | 2020-06-22 15:54:52 +1000 | [diff] [blame] | 142 | ret = PUSH_WAIT(push, 6); |
| 143 | if (ret) |
| 144 | return ret; |
| 145 | |
Ben Skeggs | e767835 | 2020-06-22 16:29:45 +1000 | [diff] [blame] | 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); |
Ben Skeggs | 01c43a6 | 2020-06-22 15:54:52 +1000 | [diff] [blame] | 150 | return 0; |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 151 | } |