nv50.c 6.6 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 "nv50.h"
25 26

#include <core/handle.h>
27
#include <core/namedb.h>
28
#include <engine/disp.h>
29
#include <subdev/bar.h>
30

31
#include <nvif/event.h>
32 33 34 35 36 37

/*******************************************************************************
 * software object classes
 ******************************************************************************/

static int
38 39
nv50_sw_mthd_dma_vblsem(struct nvkm_object *object, u32 mthd,
			void *args, u32 size)
40
{
41
	struct nv50_sw_chan *chan = (void *)nv_engctx(object->parent);
42 43
	struct nvkm_fifo_chan *fifo = (void *)nv_object(chan)->parent;
	struct nvkm_handle *handle;
44 45
	int ret = -EINVAL;

46
	handle = nvkm_namedb_get(nv_namedb(fifo), *(u32 *)args);
47 48 49 50
	if (!handle)
		return -ENOENT;

	if (nv_iclass(handle->object, NV_GPUOBJ_CLASS)) {
51
		struct nvkm_gpuobj *gpuobj = nv_gpuobj(handle->object);
52
		chan->vblank.ctxdma = gpuobj->node->offset >> 4;
53 54
		ret = 0;
	}
55
	nvkm_namedb_put(handle);
56 57 58 59
	return ret;
}

static int
60 61
nv50_sw_mthd_vblsem_offset(struct nvkm_object *object, u32 mthd,
			   void *args, u32 size)
62
{
63
	struct nv50_sw_chan *chan = (void *)nv_engctx(object->parent);
64
	chan->vblank.offset = *(u32 *)args;
65 66 67
	return 0;
}

68
int
69 70
nv50_sw_mthd_vblsem_value(struct nvkm_object *object, u32 mthd,
			  void *args, u32 size)
71
{
72
	struct nv50_sw_chan *chan = (void *)nv_engctx(object->parent);
73
	chan->vblank.value = *(u32 *)args;
74 75 76
	return 0;
}

77
int
78 79
nv50_sw_mthd_vblsem_release(struct nvkm_object *object, u32 mthd,
			    void *args, u32 size)
80
{
81
	struct nv50_sw_chan *chan = (void *)nv_engctx(object->parent);
82
	u32 head = *(u32 *)args;
83
	if (head >= nvkm_disp(chan)->vblank.index_nr)
84 85
		return -EINVAL;

86
	nvkm_notify_get(&chan->vblank.notify[head]);
87 88 89
	return 0;
}

90
int
91
nv50_sw_mthd_flip(struct nvkm_object *object, u32 mthd, void *args, u32 size)
92
{
93
	struct nv50_sw_chan *chan = (void *)nv_engctx(object->parent);
94 95 96 97 98
	if (chan->base.flip)
		return chan->base.flip(chan->base.flip_data);
	return -EINVAL;
}

99
static struct nvkm_omthds
100 101 102 103 104 105
nv50_sw_omthds[] = {
	{ 0x018c, 0x018c, nv50_sw_mthd_dma_vblsem },
	{ 0x0400, 0x0400, nv50_sw_mthd_vblsem_offset },
	{ 0x0404, 0x0404, nv50_sw_mthd_vblsem_value },
	{ 0x0408, 0x0408, nv50_sw_mthd_vblsem_release },
	{ 0x0500, 0x0500, nv50_sw_mthd_flip },
106 107 108
	{}
};

109
static struct nvkm_oclass
110
nv50_sw_sclass[] = {
111
	{ 0x506e, &nvkm_object_ofuncs, nv50_sw_omthds },
112 113 114 115 116 117 118
	{}
};

/*******************************************************************************
 * software context
 ******************************************************************************/

119
static int
120
nv50_sw_vblsem_release(struct nvkm_notify *notify)
121
{
122
	struct nv50_sw_chan *chan =
123
		container_of(notify, typeof(*chan), vblank.notify[notify->index]);
B
Ben Skeggs 已提交
124
	struct nvkm_sw *sw = (void *)nv_object(chan)->engine;
125 126
	struct nvkm_device *device = sw->engine.subdev.device;
	struct nvkm_bar *bar = device->bar;
127

128 129
	nvkm_wr32(device, 0x001704, chan->vblank.channel);
	nvkm_wr32(device, 0x001710, 0x80000000 | chan->vblank.ctxdma);
130 131
	bar->flush(bar);

B
Ben Skeggs 已提交
132
	if (nv_device(sw)->chipset == 0x50) {
133 134
		nvkm_wr32(device, 0x001570, chan->vblank.offset);
		nvkm_wr32(device, 0x001574, chan->vblank.value);
135
	} else {
136 137
		nvkm_wr32(device, 0x060010, chan->vblank.offset);
		nvkm_wr32(device, 0x060014, chan->vblank.value);
138 139
	}

140
	return NVKM_NOTIFY_DROP;
141 142
}

143
void
144
nv50_sw_context_dtor(struct nvkm_object *object)
145
{
146
	struct nv50_sw_chan *chan = (void *)object;
147 148
	int i;

149 150
	for (i = 0; i < ARRAY_SIZE(chan->vblank.notify); i++)
		nvkm_notify_fini(&chan->vblank.notify[i]);
151

152
	nvkm_sw_context_destroy(&chan->base);
153 154
}

155
int
156 157 158
nv50_sw_context_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
		     struct nvkm_oclass *oclass, void *data, u32 size,
		     struct nvkm_object **pobject)
159
{
B
Ben Skeggs 已提交
160
	struct nvkm_disp *disp = nvkm_disp(parent);
161 162
	struct nv50_sw_cclass *pclass = (void *)oclass;
	struct nv50_sw_chan *chan;
163
	int ret, i;
164

165
	ret = nvkm_sw_context_create(parent, engine, oclass, &chan);
166 167 168 169
	*pobject = nv_object(chan);
	if (ret)
		return ret;

B
Ben Skeggs 已提交
170 171
	for (i = 0; disp && i < disp->vblank.index_nr; i++) {
		ret = nvkm_notify_init(NULL, &disp->vblank, pclass->vblank,
172
				       false,
173 174 175 176 177 178
				       &(struct nvif_notify_head_req_v0) {
					.head = i,
				       },
				       sizeof(struct nvif_notify_head_req_v0),
				       sizeof(struct nvif_notify_head_rep_v0),
				       &chan->vblank.notify[i]);
179 180 181 182
		if (ret)
			return ret;
	}

183
	chan->vblank.channel = nv_gpuobj(parent->parent)->addr >> 12;
184 185 186
	return 0;
}

187 188
static struct nv50_sw_cclass
nv50_sw_cclass = {
189
	.base.handle = NV_ENGCTX(SW, 0x50),
190
	.base.ofuncs = &(struct nvkm_ofuncs) {
191 192
		.ctor = nv50_sw_context_ctor,
		.dtor = nv50_sw_context_dtor,
193 194
		.init = _nvkm_sw_context_init,
		.fini = _nvkm_sw_context_fini,
195
	},
196
	.vblank = nv50_sw_vblsem_release,
197 198 199 200 201 202
};

/*******************************************************************************
 * software engine/subdev functions
 ******************************************************************************/

203
int
204 205 206
nv50_sw_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
	     struct nvkm_oclass *oclass, void *data, u32 size,
	     struct nvkm_object **pobject)
207
{
208
	struct nv50_sw_oclass *pclass = (void *)oclass;
B
Ben Skeggs 已提交
209
	struct nvkm_sw *sw;
210 211
	int ret;

B
Ben Skeggs 已提交
212 213
	ret = nvkm_sw_create(parent, engine, oclass, &sw);
	*pobject = nv_object(sw);
214 215 216
	if (ret)
		return ret;

B
Ben Skeggs 已提交
217 218 219
	nv_engine(sw)->cclass = pclass->cclass;
	nv_engine(sw)->sclass = pclass->sclass;
	nv_subdev(sw)->intr = nv04_sw_intr;
220 221 222
	return 0;
}

223
struct nvkm_oclass *
224
nv50_sw_oclass = &(struct nv50_sw_oclass) {
225
	.base.handle = NV_ENGINE(SW, 0x50),
226
	.base.ofuncs = &(struct nvkm_ofuncs) {
227
		.ctor = nv50_sw_ctor,
228 229 230
		.dtor = _nvkm_sw_dtor,
		.init = _nvkm_sw_init,
		.fini = _nvkm_sw_fini,
231
	},
232 233
	.cclass = &nv50_sw_cclass.base,
	.sclass =  nv50_sw_sclass,
234
}.base;