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 | |
Ben Skeggs | 01c43a6 | 2020-06-22 15:54:52 +1000 | [diff] [blame] | 33 | #include <nvif/push006c.h> |
| 34 | |
Ben Skeggs | e767835 | 2020-06-22 16:29:45 +1000 | [diff] [blame] | 35 | #include <nvhw/class/cl0039.h> |
| 36 | |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 37 | static inline uint32_t |
| 38 | nouveau_bo_mem_ctxdma(struct ttm_buffer_object *bo, |
Thomas Zimmermann | 534b1f9 | 2020-08-12 19:17:18 +0200 | [diff] [blame] | 39 | struct nouveau_channel *chan, struct ttm_resource *reg) |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 40 | { |
| 41 | if (reg->mem_type == TTM_PL_TT) |
| 42 | return NvDmaTT; |
| 43 | return chan->vram.handle; |
| 44 | } |
| 45 | |
| 46 | int |
| 47 | nv04_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo, |
Thomas Zimmermann | 534b1f9 | 2020-08-12 19:17:18 +0200 | [diff] [blame] | 48 | struct ttm_resource *old_reg, struct ttm_resource *new_reg) |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 49 | { |
Ben Skeggs | 0df26c0 | 2024-07-26 14:38:26 +1000 | [diff] [blame] | 50 | struct nvif_push *push = &chan->chan.push; |
Ben Skeggs | 6c75137 | 2020-06-22 17:07:31 +1000 | [diff] [blame] | 51 | u32 src_ctxdma = nouveau_bo_mem_ctxdma(bo, chan, old_reg); |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 52 | u32 src_offset = old_reg->start << PAGE_SHIFT; |
Ben Skeggs | 6c75137 | 2020-06-22 17:07:31 +1000 | [diff] [blame] | 53 | u32 dst_ctxdma = nouveau_bo_mem_ctxdma(bo, chan, new_reg); |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 54 | u32 dst_offset = new_reg->start << PAGE_SHIFT; |
Somalapuram Amaranath | e3c92eb | 2022-10-27 14:42:37 +0530 | [diff] [blame] | 55 | u32 page_count = PFN_UP(new_reg->size); |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 56 | int ret; |
| 57 | |
Ben Skeggs | fe4249a | 2020-06-22 16:20:32 +1000 | [diff] [blame] | 58 | ret = PUSH_WAIT(push, 3); |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 59 | if (ret) |
| 60 | return ret; |
| 61 | |
Ben Skeggs | 6c75137 | 2020-06-22 17:07:31 +1000 | [diff] [blame] | 62 | PUSH_MTHD(push, NV039, SET_CONTEXT_DMA_BUFFER_IN, src_ctxdma, |
| 63 | SET_CONTEXT_DMA_BUFFER_OUT, dst_ctxdma); |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 64 | |
Somalapuram Amaranath | e3c92eb | 2022-10-27 14:42:37 +0530 | [diff] [blame] | 65 | page_count = PFN_UP(new_reg->size); |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 66 | while (page_count) { |
| 67 | int line_count = (page_count > 2047) ? 2047 : page_count; |
| 68 | |
Ben Skeggs | fe4249a | 2020-06-22 16:20:32 +1000 | [diff] [blame] | 69 | ret = PUSH_WAIT(push, 11); |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 70 | if (ret) |
| 71 | return ret; |
| 72 | |
Ben Skeggs | 6c75137 | 2020-06-22 17:07:31 +1000 | [diff] [blame] | 73 | PUSH_MTHD(push, NV039, OFFSET_IN, src_offset, |
| 74 | OFFSET_OUT, dst_offset, |
| 75 | PITCH_IN, PAGE_SIZE, |
| 76 | PITCH_OUT, PAGE_SIZE, |
| 77 | LINE_LENGTH_IN, PAGE_SIZE, |
| 78 | LINE_COUNT, line_count, |
| 79 | |
| 80 | FORMAT, |
| 81 | NVVAL(NV039, FORMAT, IN, 1) | |
| 82 | NVVAL(NV039, FORMAT, OUT, 1), |
| 83 | |
| 84 | BUFFER_NOTIFY, NV039_BUFFER_NOTIFY_WRITE_ONLY); |
| 85 | |
| 86 | PUSH_MTHD(push, NV039, NO_OPERATION, 0x00000000); |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 87 | |
| 88 | page_count -= line_count; |
| 89 | src_offset += (PAGE_SIZE * line_count); |
| 90 | dst_offset += (PAGE_SIZE * line_count); |
| 91 | } |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | int |
| 97 | nv04_bo_move_init(struct nouveau_channel *chan, u32 handle) |
| 98 | { |
Ben Skeggs | 0df26c0 | 2024-07-26 14:38:26 +1000 | [diff] [blame] | 99 | struct nvif_push *push = &chan->chan.push; |
Ben Skeggs | 01c43a6 | 2020-06-22 15:54:52 +1000 | [diff] [blame] | 100 | int ret; |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 101 | |
Ben Skeggs | 01c43a6 | 2020-06-22 15:54:52 +1000 | [diff] [blame] | 102 | ret = PUSH_WAIT(push, 4); |
| 103 | if (ret) |
| 104 | return ret; |
| 105 | |
Ben Skeggs | e767835 | 2020-06-22 16:29:45 +1000 | [diff] [blame] | 106 | PUSH_MTHD(push, NV039, SET_OBJECT, handle); |
Ben Skeggs | 3543e84 | 2024-07-26 14:38:24 +1000 | [diff] [blame] | 107 | PUSH_MTHD(push, NV039, SET_CONTEXT_DMA_NOTIFIES, chan->cli->drm->ntfy.handle); |
Ben Skeggs | 01c43a6 | 2020-06-22 15:54:52 +1000 | [diff] [blame] | 108 | return 0; |
Ben Skeggs | 8b9d5d6 | 2020-06-22 15:37:19 +1000 | [diff] [blame] | 109 | } |