nv04.c 3.8 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 <engine/sw.h>
25 26 27 28 29 30 31
#include <engine/fifo.h>

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

static int
32
nv04_sw_set_ref(struct nvkm_object *object, u32 mthd, void *data, u32 size)
33
{
34 35
	struct nvkm_object *channel = (void *)nv_engctx(object->parent);
	struct nvkm_fifo_chan *fifo = (void *)channel->parent;
36 37 38 39 40
	atomic_set(&fifo->refcnt, *(u32*)data);
	return 0;
}

static int
41
nv04_sw_flip(struct nvkm_object *object, u32 mthd, void *args, u32 size)
42
{
B
Ben Skeggs 已提交
43 44 45
	struct nvkm_sw_chan *chan = (void *)nv_engctx(object->parent);
	if (chan->flip)
		return chan->flip(chan->flip_data);
46 47 48
	return -EINVAL;
}

49
static struct nvkm_omthds
50 51 52
nv04_sw_omthds[] = {
	{ 0x0150, 0x0150, nv04_sw_set_ref },
	{ 0x0500, 0x0500, nv04_sw_flip },
53 54 55
	{}
};

56
static struct nvkm_oclass
57
nv04_sw_sclass[] = {
58
	{ 0x006e, &nvkm_object_ofuncs, nv04_sw_omthds },
59 60 61 62 63 64 65 66
	{}
};

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

static int
67 68 69
nv04_sw_context_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
		     struct nvkm_oclass *oclass, void *data, u32 size,
		     struct nvkm_object **pobject)
70
{
B
Ben Skeggs 已提交
71
	struct nvkm_sw_chan *chan;
72 73
	int ret;

74
	ret = nvkm_sw_context_create(parent, engine, oclass, &chan);
75 76 77 78 79 80 81
	*pobject = nv_object(chan);
	if (ret)
		return ret;

	return 0;
}

82
static struct nvkm_oclass
83
nv04_sw_cclass = {
84
	.handle = NV_ENGCTX(SW, 0x04),
85
	.ofuncs = &(struct nvkm_ofuncs) {
86
		.ctor = nv04_sw_context_ctor,
87 88 89
		.dtor = _nvkm_sw_context_dtor,
		.init = _nvkm_sw_context_init,
		.fini = _nvkm_sw_context_fini,
90 91 92 93 94 95 96
	},
};

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

97
void
98
nv04_sw_intr(struct nvkm_subdev *subdev)
99 100 101 102
{
	nv_mask(subdev, 0x000100, 0x80000000, 0x00000000);
}

103
static int
104 105 106
nv04_sw_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
	     struct nvkm_oclass *oclass, void *data, u32 size,
	     struct nvkm_object **pobject)
107
{
B
Ben Skeggs 已提交
108
	struct nvkm_sw *sw;
109 110
	int ret;

B
Ben Skeggs 已提交
111 112
	ret = nvkm_sw_create(parent, engine, oclass, &sw);
	*pobject = nv_object(sw);
113 114 115
	if (ret)
		return ret;

B
Ben Skeggs 已提交
116 117 118
	nv_engine(sw)->cclass = &nv04_sw_cclass;
	nv_engine(sw)->sclass = nv04_sw_sclass;
	nv_subdev(sw)->intr = nv04_sw_intr;
119 120 121
	return 0;
}

122 123
struct nvkm_oclass *
nv04_sw_oclass = &(struct nvkm_oclass) {
124
	.handle = NV_ENGINE(SW, 0x04),
125
	.ofuncs = &(struct nvkm_ofuncs) {
126
		.ctor = nv04_sw_ctor,
127 128 129
		.dtor = _nvkm_sw_dtor,
		.init = _nvkm_sw_init,
		.fini = _nvkm_sw_fini,
130 131
	},
};