usergf100.c 4.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright 2012 Red Hat Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: Ben Skeggs
 */
24
#include "user.h"
25

26
#include <core/client.h>
27 28
#include <core/gpuobj.h>
#include <subdev/fb.h>
29

30 31
#include <nvif/class.h>
#include <nvif/unpack.h>
32

B
Ben Skeggs 已提交
33
struct gf100_dmaobj {
34
	struct nvkm_dmaobj base;
35 36 37 38
	u32 flags0;
	u32 flags5;
};

39
int
40
gf100_dmaobj_bind(struct nvkm_dmaobj *obj, struct nvkm_gpuobj *parent,
41
		  struct nvkm_gpuobj **pgpuobj)
42
{
B
Ben Skeggs 已提交
43
	struct gf100_dmaobj *dmaobj = container_of(obj, typeof(*dmaobj), base);
44
	struct nvkm_device *device = dmaobj->base.base.engine->subdev.device;
45
	int ret;
46

47
	ret = nvkm_gpuobj_new(device, 24, 32, false, parent, pgpuobj);
48
	if (ret == 0) {
49 50 51 52 53 54 55 56 57
		nvkm_kmap(*pgpuobj);
		nvkm_wo32(*pgpuobj, 0x00, dmaobj->flags0 | nv_mclass(dmaobj));
		nvkm_wo32(*pgpuobj, 0x04, lower_32_bits(dmaobj->base.limit));
		nvkm_wo32(*pgpuobj, 0x08, lower_32_bits(dmaobj->base.start));
		nvkm_wo32(*pgpuobj, 0x0c, upper_32_bits(dmaobj->base.limit) << 24 |
					  upper_32_bits(dmaobj->base.start));
		nvkm_wo32(*pgpuobj, 0x10, 0x00000000);
		nvkm_wo32(*pgpuobj, 0x14, dmaobj->flags5);
		nvkm_done(*pgpuobj);
58 59 60 61 62 63
	}

	return ret;
}

static int
64 65 66
gf100_dmaobj_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
		  struct nvkm_oclass *oclass, void *data, u32 size,
		  struct nvkm_object **pobject)
67
{
68
	struct nvkm_dma *dmaeng = (void *)engine;
69
	union {
70
		struct gf100_dma_v0 v0;
71
	} *args;
B
Ben Skeggs 已提交
72
	struct gf100_dmaobj *dmaobj;
73
	u32 kind, user, unkn;
74 75
	int ret;

B
Ben Skeggs 已提交
76 77
	ret = nvkm_dmaobj_create(parent, engine, oclass, &data, &size, &dmaobj);
	*pobject = nv_object(dmaobj);
78 79 80 81
	if (ret)
		return ret;
	args = data;

82
	nvif_ioctl(parent, "create gf100 dma size %d\n", size);
83
	if (nvif_unpack(args->v0, 0, 0, false)) {
84 85 86
		nvif_ioctl(parent,
			   "create gf100 dma vers %d priv %d kind %02x\n",
			   args->v0.version, args->v0.priv, args->v0.kind);
87 88 89 90 91
		kind = args->v0.kind;
		user = args->v0.priv;
		unkn = 0;
	} else
	if (size == 0) {
B
Ben Skeggs 已提交
92
		if (dmaobj->base.target != NV_MEM_TARGET_VM) {
93 94 95
			kind = GF100_DMA_V0_KIND_PITCH;
			user = GF100_DMA_V0_PRIV_US;
			unkn = 2;
96
		} else {
97 98 99
			kind = GF100_DMA_V0_KIND_VM;
			user = GF100_DMA_V0_PRIV_VM;
			unkn = 0;
100
		}
101 102
	} else
		return ret;
103

104 105
	if (user > 2)
		return -EINVAL;
B
Ben Skeggs 已提交
106 107
	dmaobj->flags0 |= (kind << 22) | (user << 20);
	dmaobj->flags5 |= (unkn << 16);
108

B
Ben Skeggs 已提交
109
	switch (dmaobj->base.target) {
110
	case NV_MEM_TARGET_VM:
B
Ben Skeggs 已提交
111
		dmaobj->flags0 |= 0x00000000;
112 113
		break;
	case NV_MEM_TARGET_VRAM:
B
Ben Skeggs 已提交
114
		dmaobj->flags0 |= 0x00010000;
115 116
		break;
	case NV_MEM_TARGET_PCI:
B
Ben Skeggs 已提交
117
		dmaobj->flags0 |= 0x00020000;
118 119
		break;
	case NV_MEM_TARGET_PCI_NOSNOOP:
B
Ben Skeggs 已提交
120
		dmaobj->flags0 |= 0x00030000;
121 122 123 124 125
		break;
	default:
		return -EINVAL;
	}

B
Ben Skeggs 已提交
126
	switch (dmaobj->base.access) {
127 128 129
	case NV_MEM_ACCESS_VM:
		break;
	case NV_MEM_ACCESS_RO:
B
Ben Skeggs 已提交
130
		dmaobj->flags0 |= 0x00040000;
131 132 133
		break;
	case NV_MEM_ACCESS_WO:
	case NV_MEM_ACCESS_RW:
B
Ben Skeggs 已提交
134
		dmaobj->flags0 |= 0x00080000;
135 136 137
		break;
	}

138
	return dmaeng->bind(&dmaobj->base, (void *)dmaobj, (void *)pobject);
139 140
}

141 142 143
static struct nvkm_ofuncs
gf100_dmaobj_ofuncs = {
	.ctor =  gf100_dmaobj_ctor,
144 145 146 147 148
	.dtor = _nvkm_dmaobj_dtor,
	.init = _nvkm_dmaobj_init,
	.fini = _nvkm_dmaobj_fini,
};

149
struct nvkm_oclass
150 151 152 153
gf100_dmaeng_sclass[] = {
	{ NV_DMA_FROM_MEMORY, &gf100_dmaobj_ofuncs },
	{ NV_DMA_TO_MEMORY, &gf100_dmaobj_ofuncs },
	{ NV_DMA_IN_MEMORY, &gf100_dmaobj_ofuncs },
154 155
	{}
};