nv04.c 3.9 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
#include <engine/fifo.h>

27
struct nv04_sw_priv {
28
	struct nvkm_sw base;
29 30
};

31
struct nv04_sw_chan {
32
	struct nvkm_sw_chan base;
33 34 35 36 37 38 39
};

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

static int
40
nv04_sw_set_ref(struct nvkm_object *object, u32 mthd, void *data, u32 size)
41
{
42 43
	struct nvkm_object *channel = (void *)nv_engctx(object->parent);
	struct nvkm_fifo_chan *fifo = (void *)channel->parent;
44 45 46 47 48
	atomic_set(&fifo->refcnt, *(u32*)data);
	return 0;
}

static int
49
nv04_sw_flip(struct nvkm_object *object, u32 mthd, void *args, u32 size)
50
{
51
	struct nv04_sw_chan *chan = (void *)nv_engctx(object->parent);
52 53 54 55 56
	if (chan->base.flip)
		return chan->base.flip(chan->base.flip_data);
	return -EINVAL;
}

57
static struct nvkm_omthds
58 59 60
nv04_sw_omthds[] = {
	{ 0x0150, 0x0150, nv04_sw_set_ref },
	{ 0x0500, 0x0500, nv04_sw_flip },
61 62 63
	{}
};

64
static struct nvkm_oclass
65
nv04_sw_sclass[] = {
66
	{ 0x006e, &nvkm_object_ofuncs, nv04_sw_omthds },
67 68 69 70 71 72 73 74
	{}
};

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

static int
75 76 77
nv04_sw_context_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
		     struct nvkm_oclass *oclass, void *data, u32 size,
		     struct nvkm_object **pobject)
78
{
79
	struct nv04_sw_chan *chan;
80 81
	int ret;

82
	ret = nvkm_sw_context_create(parent, engine, oclass, &chan);
83 84 85 86 87 88 89
	*pobject = nv_object(chan);
	if (ret)
		return ret;

	return 0;
}

90
static struct nvkm_oclass
91
nv04_sw_cclass = {
92
	.handle = NV_ENGCTX(SW, 0x04),
93
	.ofuncs = &(struct nvkm_ofuncs) {
94
		.ctor = nv04_sw_context_ctor,
95 96 97
		.dtor = _nvkm_sw_context_dtor,
		.init = _nvkm_sw_context_init,
		.fini = _nvkm_sw_context_fini,
98 99 100 101 102 103 104
	},
};

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

105
void
106
nv04_sw_intr(struct nvkm_subdev *subdev)
107 108 109 110
{
	nv_mask(subdev, 0x000100, 0x80000000, 0x00000000);
}

111
static int
112 113 114
nv04_sw_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
	     struct nvkm_oclass *oclass, void *data, u32 size,
	     struct nvkm_object **pobject)
115
{
116
	struct nv04_sw_priv *priv;
117 118
	int ret;

119
	ret = nvkm_sw_create(parent, engine, oclass, &priv);
120 121 122 123
	*pobject = nv_object(priv);
	if (ret)
		return ret;

124 125 126
	nv_engine(priv)->cclass = &nv04_sw_cclass;
	nv_engine(priv)->sclass = nv04_sw_sclass;
	nv_subdev(priv)->intr = nv04_sw_intr;
127 128 129
	return 0;
}

130 131
struct nvkm_oclass *
nv04_sw_oclass = &(struct nvkm_oclass) {
132
	.handle = NV_ENGINE(SW, 0x04),
133
	.ofuncs = &(struct nvkm_ofuncs) {
134
		.ctor = nv04_sw_ctor,
135 136 137
		.dtor = _nvkm_sw_dtor,
		.init = _nvkm_sw_init,
		.fini = _nvkm_sw_fini,
138 139
	},
};