xref: /openbmc/linux/drivers/gpu/drm/nouveau/nouveau_bo5039.c (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
18b9d5d63SBen Skeggs /*
28b9d5d63SBen Skeggs  * Copyright 2007 Dave Airlied
38b9d5d63SBen Skeggs  * All Rights Reserved.
48b9d5d63SBen Skeggs  *
58b9d5d63SBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
68b9d5d63SBen Skeggs  * copy of this software and associated documentation files (the "Software"),
78b9d5d63SBen Skeggs  * to deal in the Software without restriction, including without limitation
88b9d5d63SBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
98b9d5d63SBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
108b9d5d63SBen Skeggs  * Software is furnished to do so, subject to the following conditions:
118b9d5d63SBen Skeggs  *
128b9d5d63SBen Skeggs  * The above copyright notice and this permission notice (including the next
138b9d5d63SBen Skeggs  * paragraph) shall be included in all copies or substantial portions of the
148b9d5d63SBen Skeggs  * Software.
158b9d5d63SBen Skeggs  *
168b9d5d63SBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
178b9d5d63SBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
188b9d5d63SBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
198b9d5d63SBen Skeggs  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
208b9d5d63SBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
218b9d5d63SBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
228b9d5d63SBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
238b9d5d63SBen Skeggs  */
248b9d5d63SBen Skeggs /*
258b9d5d63SBen Skeggs  * Authors: Dave Airlied <airlied@linux.ie>
268b9d5d63SBen Skeggs  *	    Ben Skeggs   <darktama@iinet.net.au>
278b9d5d63SBen Skeggs  *	    Jeremy Kolb  <jkolb@brandeis.edu>
288b9d5d63SBen Skeggs  */
298b9d5d63SBen Skeggs #include "nouveau_bo.h"
308b9d5d63SBen Skeggs #include "nouveau_dma.h"
318b9d5d63SBen Skeggs #include "nouveau_drv.h"
328b9d5d63SBen Skeggs #include "nouveau_mem.h"
338b9d5d63SBen Skeggs 
3401c43a66SBen Skeggs #include <nvif/push206e.h>
3501c43a66SBen Skeggs 
36e767835aSBen Skeggs #include <nvhw/class/cl5039.h>
37e767835aSBen Skeggs 
388b9d5d63SBen Skeggs int
nv50_bo_move_m2mf(struct nouveau_channel * chan,struct ttm_buffer_object * bo,struct ttm_resource * old_reg,struct ttm_resource * new_reg)398b9d5d63SBen Skeggs nv50_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo,
40534b1f90SThomas Zimmermann 		  struct ttm_resource *old_reg, struct ttm_resource *new_reg)
418b9d5d63SBen Skeggs {
428b9d5d63SBen Skeggs 	struct nouveau_mem *mem = nouveau_mem(old_reg);
43fe4249afSBen Skeggs 	struct nvif_push *push = chan->chan.push;
44*e3c92eb4SSomalapuram Amaranath 	u64 length = new_reg->size;
458b9d5d63SBen Skeggs 	u64 src_offset = mem->vma[0].addr;
468b9d5d63SBen Skeggs 	u64 dst_offset = mem->vma[1].addr;
478b9d5d63SBen Skeggs 	int src_tiled = !!mem->kind;
488b9d5d63SBen Skeggs 	int dst_tiled = !!nouveau_mem(new_reg)->kind;
498b9d5d63SBen Skeggs 	int ret;
508b9d5d63SBen Skeggs 
518b9d5d63SBen Skeggs 	while (length) {
528b9d5d63SBen Skeggs 		u32 amount, stride, height;
538b9d5d63SBen Skeggs 
54fe4249afSBen Skeggs 		ret = PUSH_WAIT(push, 18 + 6 * (src_tiled + dst_tiled));
558b9d5d63SBen Skeggs 		if (ret)
568b9d5d63SBen Skeggs 			return ret;
578b9d5d63SBen Skeggs 
588b9d5d63SBen Skeggs 		amount  = min(length, (u64)(4 * 1024 * 1024));
598b9d5d63SBen Skeggs 		stride  = 16 * 4;
608b9d5d63SBen Skeggs 		height  = amount / stride;
618b9d5d63SBen Skeggs 
628b9d5d63SBen Skeggs 		if (src_tiled) {
636c751372SBen Skeggs 			PUSH_MTHD(push, NV5039, SET_SRC_MEMORY_LAYOUT,
646c751372SBen Skeggs 				  NVDEF(NV5039, SET_SRC_MEMORY_LAYOUT, V, BLOCKLINEAR),
656c751372SBen Skeggs 
666c751372SBen Skeggs 						SET_SRC_BLOCK_SIZE,
676c751372SBen Skeggs 				  NVDEF(NV5039, SET_SRC_BLOCK_SIZE, WIDTH, ONE_GOB) |
686c751372SBen Skeggs 				  NVDEF(NV5039, SET_SRC_BLOCK_SIZE, HEIGHT, ONE_GOB) |
696c751372SBen Skeggs 				  NVDEF(NV5039, SET_SRC_BLOCK_SIZE, DEPTH, ONE_GOB),
706c751372SBen Skeggs 
716c751372SBen Skeggs 						SET_SRC_WIDTH, stride,
726c751372SBen Skeggs 						SET_SRC_HEIGHT, height,
736c751372SBen Skeggs 						SET_SRC_DEPTH, 1,
746c751372SBen Skeggs 						SET_SRC_LAYER, 0,
756c751372SBen Skeggs 
766c751372SBen Skeggs 						SET_SRC_ORIGIN,
776c751372SBen Skeggs 				  NVVAL(NV5039, SET_SRC_ORIGIN, X, 0) |
786c751372SBen Skeggs 				  NVVAL(NV5039, SET_SRC_ORIGIN, Y, 0));
798b9d5d63SBen Skeggs 		} else {
806c751372SBen Skeggs 			PUSH_MTHD(push, NV5039, SET_SRC_MEMORY_LAYOUT,
816c751372SBen Skeggs 				  NVDEF(NV5039, SET_SRC_MEMORY_LAYOUT, V, PITCH));
828b9d5d63SBen Skeggs 		}
838b9d5d63SBen Skeggs 
84fe4249afSBen Skeggs 		if (dst_tiled) {
856c751372SBen Skeggs 			PUSH_MTHD(push, NV5039, SET_DST_MEMORY_LAYOUT,
866c751372SBen Skeggs 				  NVDEF(NV5039, SET_DST_MEMORY_LAYOUT, V, BLOCKLINEAR),
876c751372SBen Skeggs 
886c751372SBen Skeggs 						SET_DST_BLOCK_SIZE,
896c751372SBen Skeggs 				  NVDEF(NV5039, SET_DST_BLOCK_SIZE, WIDTH, ONE_GOB) |
906c751372SBen Skeggs 				  NVDEF(NV5039, SET_DST_BLOCK_SIZE, HEIGHT, ONE_GOB) |
916c751372SBen Skeggs 				  NVDEF(NV5039, SET_DST_BLOCK_SIZE, DEPTH, ONE_GOB),
926c751372SBen Skeggs 
936c751372SBen Skeggs 						SET_DST_WIDTH, stride,
946c751372SBen Skeggs 						SET_DST_HEIGHT, height,
956c751372SBen Skeggs 						SET_DST_DEPTH, 1,
966c751372SBen Skeggs 						SET_DST_LAYER, 0,
976c751372SBen Skeggs 
986c751372SBen Skeggs 						SET_DST_ORIGIN,
996c751372SBen Skeggs 				  NVVAL(NV5039, SET_DST_ORIGIN, X, 0) |
1006c751372SBen Skeggs 				  NVVAL(NV5039, SET_DST_ORIGIN, Y, 0));
101fe4249afSBen Skeggs 		} else {
1026c751372SBen Skeggs 			PUSH_MTHD(push, NV5039, SET_DST_MEMORY_LAYOUT,
1036c751372SBen Skeggs 				  NVDEF(NV5039, SET_DST_MEMORY_LAYOUT, V, PITCH));
104fe4249afSBen Skeggs 		}
105fe4249afSBen Skeggs 
1066c751372SBen Skeggs 		PUSH_MTHD(push, NV5039, OFFSET_IN_UPPER,
1076c751372SBen Skeggs 			  NVVAL(NV5039, OFFSET_IN_UPPER, VALUE, upper_32_bits(src_offset)),
1086c751372SBen Skeggs 
1096c751372SBen Skeggs 					OFFSET_OUT_UPPER,
1106c751372SBen Skeggs 			  NVVAL(NV5039, OFFSET_OUT_UPPER, VALUE, upper_32_bits(dst_offset)));
1116c751372SBen Skeggs 
1126c751372SBen Skeggs 		PUSH_MTHD(push, NV5039, OFFSET_IN, lower_32_bits(src_offset),
1136c751372SBen Skeggs 					OFFSET_OUT, lower_32_bits(dst_offset),
1146c751372SBen Skeggs 					PITCH_IN, stride,
1156c751372SBen Skeggs 					PITCH_OUT, stride,
1166c751372SBen Skeggs 					LINE_LENGTH_IN, stride,
1176c751372SBen Skeggs 					LINE_COUNT, height,
1186c751372SBen Skeggs 
1196c751372SBen Skeggs 					FORMAT,
1206c751372SBen Skeggs 			  NVDEF(NV5039, FORMAT, IN, ONE) |
1216c751372SBen Skeggs 			  NVDEF(NV5039, FORMAT, OUT, ONE),
1226c751372SBen Skeggs 
1236c751372SBen Skeggs 					BUFFER_NOTIFY,
1246c751372SBen Skeggs 			  NVDEF(NV5039, BUFFER_NOTIFY, TYPE, WRITE_ONLY));
1256c751372SBen Skeggs 
1266c751372SBen Skeggs 		PUSH_MTHD(push, NV5039, NO_OPERATION, 0x00000000);
1278b9d5d63SBen Skeggs 
1288b9d5d63SBen Skeggs 		length -= amount;
1298b9d5d63SBen Skeggs 		src_offset += amount;
1308b9d5d63SBen Skeggs 		dst_offset += amount;
1318b9d5d63SBen Skeggs 	}
1328b9d5d63SBen Skeggs 
1338b9d5d63SBen Skeggs 	return 0;
1348b9d5d63SBen Skeggs }
1358b9d5d63SBen Skeggs 
1368b9d5d63SBen Skeggs int
nv50_bo_move_init(struct nouveau_channel * chan,u32 handle)1378b9d5d63SBen Skeggs nv50_bo_move_init(struct nouveau_channel *chan, u32 handle)
1388b9d5d63SBen Skeggs {
13901c43a66SBen Skeggs 	struct nvif_push *push = chan->chan.push;
14001c43a66SBen Skeggs 	int ret;
1418b9d5d63SBen Skeggs 
14201c43a66SBen Skeggs 	ret = PUSH_WAIT(push, 6);
14301c43a66SBen Skeggs 	if (ret)
1448b9d5d63SBen Skeggs 		return ret;
14501c43a66SBen Skeggs 
146e767835aSBen Skeggs 	PUSH_MTHD(push, NV5039, SET_OBJECT, handle);
147e767835aSBen Skeggs 	PUSH_MTHD(push, NV5039, SET_CONTEXT_DMA_NOTIFY, chan->drm->ntfy.handle,
148e767835aSBen Skeggs 				SET_CONTEXT_DMA_BUFFER_IN, chan->vram.handle,
149e767835aSBen Skeggs 				SET_CONTEXT_DMA_BUFFER_OUT, chan->vram.handle);
15001c43a66SBen Skeggs 	return 0;
1518b9d5d63SBen Skeggs }
152