nv10.c 5.7 KB
Newer Older
1
/*
2
 * Copyright 2012 Red Hat Inc.
3
 *
4 5 6 7 8 9
 * 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:
10
 *
11 12
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
13
 *
14 15 16 17 18 19 20
 * 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.
21
 *
22
 * Authors: Ben Skeggs
23
 */
24
#include "nv04.h"
25

26
#include <core/client.h>
27
#include <core/engctx.h>
28
#include <core/ramht.h>
29 30
#include <subdev/instmem/nv04.h>

31 32
#include <nvif/class.h>
#include <nvif/unpack.h>
33 34 35

static struct ramfc_desc
nv10_ramfc[] = {
36 37 38 39 40 41 42 43 44 45 46 47
	{ 32,  0, 0x00,  0, NV04_PFIFO_CACHE1_DMA_PUT },
	{ 32,  0, 0x04,  0, NV04_PFIFO_CACHE1_DMA_GET },
	{ 32,  0, 0x08,  0, NV10_PFIFO_CACHE1_REF_CNT },
	{ 16,  0, 0x0c,  0, NV04_PFIFO_CACHE1_DMA_INSTANCE },
	{ 16, 16, 0x0c,  0, NV04_PFIFO_CACHE1_DMA_DCOUNT },
	{ 32,  0, 0x10,  0, NV04_PFIFO_CACHE1_DMA_STATE },
	{ 32,  0, 0x14,  0, NV04_PFIFO_CACHE1_DMA_FETCH },
	{ 32,  0, 0x18,  0, NV04_PFIFO_CACHE1_ENGINE },
	{ 32,  0, 0x1c,  0, NV04_PFIFO_CACHE1_PULL1 },
	{}
};

48 49 50
/*******************************************************************************
 * FIFO channel objects
 ******************************************************************************/
51 52

static int
53 54 55 56
nv10_fifo_chan_ctor(struct nvkm_object *parent,
		    struct nvkm_object *engine,
		    struct nvkm_oclass *oclass, void *data, u32 size,
		    struct nvkm_object **pobject)
57
{
58 59 60
	union {
		struct nv03_channel_dma_v0 v0;
	} *args = data;
B
Ben Skeggs 已提交
61
	struct nv04_fifo *fifo = (void *)engine;
62
	struct nv04_fifo_chan *chan;
63 64
	int ret;

65
	nvif_ioctl(parent, "create channel dma size %d\n", size);
66
	if (nvif_unpack(args->v0, 0, 0, false)) {
67
		nvif_ioctl(parent, "create channel dma vers %d pushbuf %llx "
68
				   "offset %08x\n", args->v0.version,
69
			   args->v0.pushbuf, args->v0.offset);
70 71
	} else
		return ret;
72

73 74 75 76 77
	ret = nvkm_fifo_channel_create(parent, engine, oclass, 0, 0x800000,
				       0x10000, args->v0.pushbuf,
				       (1ULL << NVDEV_ENGINE_DMAOBJ) |
				       (1ULL << NVDEV_ENGINE_SW) |
				       (1ULL << NVDEV_ENGINE_GR), &chan);
78 79 80 81
	*pobject = nv_object(chan);
	if (ret)
		return ret;

82 83
	args->v0.chid = chan->base.chid;

84 85
	nv_parent(chan)->object_attach = nv04_fifo_object_attach;
	nv_parent(chan)->object_detach = nv04_fifo_object_detach;
86
	nv_parent(chan)->context_attach = nv04_fifo_context_attach;
87 88
	chan->ramfc = chan->base.chid * 32;

89 90 91 92 93
	nvkm_kmap(fifo->ramfc);
	nvkm_wo32(fifo->ramfc, chan->ramfc + 0x00, args->v0.offset);
	nvkm_wo32(fifo->ramfc, chan->ramfc + 0x04, args->v0.offset);
	nvkm_wo32(fifo->ramfc, chan->ramfc + 0x0c, chan->base.pushgpu->addr >> 4);
	nvkm_wo32(fifo->ramfc, chan->ramfc + 0x14,
94 95
			     NV_PFIFO_CACHE1_DMA_FETCH_TRIG_128_BYTES |
			     NV_PFIFO_CACHE1_DMA_FETCH_SIZE_128_BYTES |
96
#ifdef __BIG_ENDIAN
97
			     NV_PFIFO_CACHE1_BIG_ENDIAN |
98
#endif
99
			     NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_8);
100
	nvkm_done(fifo->ramfc);
101 102
	return 0;
}
103

104
static struct nvkm_ofuncs
105 106 107 108 109
nv10_fifo_ofuncs = {
	.ctor = nv10_fifo_chan_ctor,
	.dtor = nv04_fifo_chan_dtor,
	.init = nv04_fifo_chan_init,
	.fini = nv04_fifo_chan_fini,
110 111 112 113
	.map  = _nvkm_fifo_channel_map,
	.rd32 = _nvkm_fifo_channel_rd32,
	.wr32 = _nvkm_fifo_channel_wr32,
	.ntfy = _nvkm_fifo_channel_ntfy
114
};
115

116
static struct nvkm_oclass
117
nv10_fifo_sclass[] = {
118
	{ NV10_CHANNEL_DMA, &nv10_fifo_ofuncs },
119 120 121 122 123 124 125
	{}
};

/*******************************************************************************
 * FIFO context - basically just the instmem reserved for the channel
 ******************************************************************************/

126
static struct nvkm_oclass
127 128
nv10_fifo_cclass = {
	.handle = NV_ENGCTX(FIFO, 0x10),
129
	.ofuncs = &(struct nvkm_ofuncs) {
130
		.ctor = nv04_fifo_context_ctor,
131 132 133 134 135
		.dtor = _nvkm_fifo_context_dtor,
		.init = _nvkm_fifo_context_init,
		.fini = _nvkm_fifo_context_fini,
		.rd32 = _nvkm_fifo_context_rd32,
		.wr32 = _nvkm_fifo_context_wr32,
136 137 138 139 140 141
	},
};

/*******************************************************************************
 * PFIFO engine
 ******************************************************************************/
142

143
static int
144 145 146
nv10_fifo_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
	       struct nvkm_oclass *oclass, void *data, u32 size,
	       struct nvkm_object **pobject)
147
{
B
Ben Skeggs 已提交
148
	struct nv04_instmem *imem = nv04_instmem(parent);
B
Ben Skeggs 已提交
149
	struct nv04_fifo *fifo;
150
	int ret;
151

B
Ben Skeggs 已提交
152 153
	ret = nvkm_fifo_create(parent, engine, oclass, 0, 31, &fifo);
	*pobject = nv_object(fifo);
154 155 156
	if (ret)
		return ret;

B
Ben Skeggs 已提交
157 158 159 160 161 162 163 164 165 166 167
	nvkm_ramht_ref(imem->ramht, &fifo->ramht);
	nvkm_gpuobj_ref(imem->ramro, &fifo->ramro);
	nvkm_gpuobj_ref(imem->ramfc, &fifo->ramfc);

	nv_subdev(fifo)->unit = 0x00000100;
	nv_subdev(fifo)->intr = nv04_fifo_intr;
	nv_engine(fifo)->cclass = &nv10_fifo_cclass;
	nv_engine(fifo)->sclass = nv10_fifo_sclass;
	fifo->base.pause = nv04_fifo_pause;
	fifo->base.start = nv04_fifo_start;
	fifo->ramfc_desc = nv10_ramfc;
168 169
	return 0;
}
170

171 172
struct nvkm_oclass *
nv10_fifo_oclass = &(struct nvkm_oclass) {
173
	.handle = NV_ENGINE(FIFO, 0x10),
174
	.ofuncs = &(struct nvkm_ofuncs) {
175 176 177
		.ctor = nv10_fifo_ctor,
		.dtor = nv04_fifo_dtor,
		.init = nv04_fifo_init,
178
		.fini = _nvkm_fifo_fini,
179 180
	},
};