nv50_evo.c 8.7 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 24 25 26 27 28 29
/*
 * Copyright 2010 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
 */

#include "drmP.h"

#include "nouveau_drv.h"
#include "nouveau_dma.h"
#include "nouveau_ramht.h"
30
#include "nv50_display.h"
31 32

static void
33
nv50_evo_channel_del(struct nouveau_channel **pevo)
34
{
35
	struct nouveau_channel *evo = *pevo;
36

37
	if (!evo)
38
		return;
39
	*pevo = NULL;
40

41 42 43
	nouveau_gpuobj_channel_takedown(evo);
	nouveau_bo_unmap(evo->pushbuf_bo);
	nouveau_bo_ref(NULL, &evo->pushbuf_bo);
44

45 46 47 48
	if (evo->user)
		iounmap(evo->user);

	kfree(evo);
49 50 51 52
}

int
nv50_evo_dmaobj_new(struct nouveau_channel *evo, u32 class, u32 name,
53 54
		    u32 tile_flags, u32 magic_flags, u32 offset, u32 limit,
		    u32 flags5)
55 56
{
	struct drm_nouveau_private *dev_priv = evo->dev->dev_private;
57
	struct nv50_display *disp = nv50_display(evo->dev);
58 59 60
	struct nouveau_gpuobj *obj = NULL;
	int ret;

61
	ret = nouveau_gpuobj_new(evo->dev, disp->master, 6*4, 32, 0, &obj);
62 63 64 65 66 67 68 69 70
	if (ret)
		return ret;
	obj->engine = NVOBJ_ENGINE_DISPLAY;

	nv_wo32(obj,  0, (tile_flags << 22) | (magic_flags << 16) | class);
	nv_wo32(obj,  4, limit);
	nv_wo32(obj,  8, offset);
	nv_wo32(obj, 12, 0x00000000);
	nv_wo32(obj, 16, 0x00000000);
71
	nv_wo32(obj, 20, flags5);
72
	dev_priv->engine.instmem.flush(evo->dev);
73 74 75 76 77 78 79 80 81 82 83

	ret = nouveau_ramht_insert(evo, name, obj);
	nouveau_gpuobj_ref(NULL, &obj);
	if (ret) {
		return ret;
	}

	return 0;
}

static int
84 85
nv50_evo_channel_new(struct drm_device *dev, int chid,
		     struct nouveau_channel **pevo)
86
{
87
	struct nv50_display *disp = nv50_display(dev);
88
	struct nouveau_channel *evo;
89 90
	int ret;

91 92
	evo = kzalloc(sizeof(struct nouveau_channel), GFP_KERNEL);
	if (!evo)
93
		return -ENOMEM;
94
	*pevo = evo;
95

96
	evo->id = chid;
97 98 99
	evo->dev = dev;
	evo->user_get = 4;
	evo->user_put = 0;
100 101

	ret = nouveau_bo_new(dev, NULL, 4096, 0, TTM_PL_FLAG_VRAM, 0, 0,
102
			     false, true, &evo->pushbuf_bo);
103
	if (ret == 0)
104
		ret = nouveau_bo_pin(evo->pushbuf_bo, TTM_PL_FLAG_VRAM);
105 106
	if (ret) {
		NV_ERROR(dev, "Error creating EVO DMA push buffer: %d\n", ret);
107
		nv50_evo_channel_del(pevo);
108 109 110
		return ret;
	}

111
	ret = nouveau_bo_map(evo->pushbuf_bo);
112 113
	if (ret) {
		NV_ERROR(dev, "Error mapping EVO DMA push buffer: %d\n", ret);
114
		nv50_evo_channel_del(pevo);
115 116 117
		return ret;
	}

118 119 120
	evo->user = ioremap(pci_resource_start(dev->pdev, 0) +
			    NV50_PDISPLAY_USER(evo->id), PAGE_SIZE);
	if (!evo->user) {
121
		NV_ERROR(dev, "Error mapping EVO control regs.\n");
122
		nv50_evo_channel_del(pevo);
123 124 125
		return -ENOMEM;
	}

126
	/* bind primary evo channel's ramht to the channel */
127 128
	if (disp->master && evo != disp->master)
		nouveau_ramht_ref(disp->master->ramht, &evo->ramht, NULL);
129

130 131 132 133 134 135 136
	return 0;
}

static int
nv50_evo_channel_init(struct nouveau_channel *evo)
{
	struct drm_device *dev = evo->dev;
137
	int id = evo->id, ret, i;
138
	u64 pushbuf = evo->pushbuf_bo->bo.mem.start << PAGE_SHIFT;
139 140
	u32 tmp;

141 142 143
	tmp = nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id));
	if ((tmp & 0x009f0000) == 0x00020000)
		nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), tmp | 0x00800000);
144

145 146 147
	tmp = nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id));
	if ((tmp & 0x003f0000) == 0x00030000)
		nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), tmp | 0x00600000);
148 149

	/* initialise fifo */
150 151 152
	nv_wr32(dev, NV50_PDISPLAY_EVO_DMA_CB(id), pushbuf >> 8 |
		     NV50_PDISPLAY_EVO_DMA_CB_LOCATION_VRAM |
		     NV50_PDISPLAY_EVO_DMA_CB_VALID);
153 154
	nv_wr32(dev, NV50_PDISPLAY_EVO_UNK2(id), 0x00010000);
	nv_wr32(dev, NV50_PDISPLAY_EVO_HASH_TAG(id), id);
155 156 157 158 159 160
	nv_mask(dev, NV50_PDISPLAY_EVO_CTRL(id), NV50_PDISPLAY_EVO_CTRL_DMA,
		     NV50_PDISPLAY_EVO_CTRL_DMA_ENABLED);

	nv_wr32(dev, NV50_PDISPLAY_USER_PUT(id), 0x00000000);
	nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x01000003 |
		     NV50_PDISPLAY_EVO_CTRL_DMA_ENABLED);
161
	if (!nv_wait(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x80000000, 0x00000000)) {
162
		NV_ERROR(dev, "EvoCh %d init timeout: 0x%08x\n", id,
163
			 nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id)));
164 165 166 167
		return -EBUSY;
	}

	/* enable error reporting on the channel */
168
	nv_mask(dev, 0x610028, 0x00000000, 0x00010001 << id);
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188

	evo->dma.max = (4096/4) - 2;
	evo->dma.put = 0;
	evo->dma.cur = evo->dma.put;
	evo->dma.free = evo->dma.max - evo->dma.cur;

	ret = RING_SPACE(evo, NOUVEAU_DMA_SKIPS);
	if (ret)
		return ret;

	for (i = 0; i < NOUVEAU_DMA_SKIPS; i++)
		OUT_RING(evo, 0);

	return 0;
}

static void
nv50_evo_channel_fini(struct nouveau_channel *evo)
{
	struct drm_device *dev = evo->dev;
189 190 191 192 193 194 195 196 197
	int id = evo->id;

	nv_mask(dev, 0x610028, 0x00010001 << id, 0x00000000);
	nv_mask(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x00001010, 0x00001000);
	nv_wr32(dev, NV50_PDISPLAY_INTR_0, (1 << id));
	nv_mask(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x00000003, 0x00000000);
	if (!nv_wait(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x001e0000, 0x00000000)) {
		NV_ERROR(dev, "EvoCh %d takedown timeout: 0x%08x\n", id,
			 nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id)));
198 199 200 201 202 203 204
	}
}

static int
nv50_evo_create(struct drm_device *dev)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
205
	struct nv50_display *disp = nv50_display(dev);
206 207 208 209 210 211 212
	struct nouveau_gpuobj *ramht = NULL;
	struct nouveau_channel *evo;
	int ret;

	/* create primary evo channel, the one we use for modesetting
	 * purporses
	 */
213
	ret = nv50_evo_channel_new(dev, 0, &disp->master);
214 215
	if (ret)
		return ret;
216
	evo = disp->master;
217 218 219 220 221

	/* setup object management on it, any other evo channel will
	 * use this also as there's no per-channel support on the
	 * hardware
	 */
B
Ben Skeggs 已提交
222
	ret = nouveau_gpuobj_new(dev, NULL, 32768, 65536,
223 224 225
				 NVOBJ_FLAG_ZERO_ALLOC, &evo->ramin);
	if (ret) {
		NV_ERROR(dev, "Error allocating EVO channel memory: %d\n", ret);
226
		nv50_evo_channel_del(&disp->master);
227 228 229 230 231 232
		return ret;
	}

	ret = drm_mm_init(&evo->ramin_heap, 0, 32768);
	if (ret) {
		NV_ERROR(dev, "Error initialising EVO PRAMIN heap: %d\n", ret);
233
		nv50_evo_channel_del(&disp->master);
234 235 236 237 238 239
		return ret;
	}

	ret = nouveau_gpuobj_new(dev, evo, 4096, 16, 0, &ramht);
	if (ret) {
		NV_ERROR(dev, "Unable to allocate EVO RAMHT: %d\n", ret);
240
		nv50_evo_channel_del(&disp->master);
241 242 243 244 245 246
		return ret;
	}

	ret = nouveau_ramht_new(dev, ramht, &evo->ramht);
	nouveau_gpuobj_ref(NULL, &ramht);
	if (ret) {
247
		nv50_evo_channel_del(&disp->master);
248 249 250 251
		return ret;
	}

	/* create some default objects for the scanout memtypes we support */
252 253 254 255
	if (dev_priv->card_type >= NV_C0) {
		ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoFB32, 0xfe, 0x19,
					  0, 0xffffffff, 0x00000000);
		if (ret) {
256
			nv50_evo_channel_del(&disp->master);
257 258 259 260 261 262
			return ret;
		}

		ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoVRAM, 0, 0x19,
					  0, dev_priv->vram_size, 0x00020000);
		if (ret) {
263
			nv50_evo_channel_del(&disp->master);
264 265 266 267 268 269
			return ret;
		}

		ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoVRAM_LP, 0, 0x19,
					  0, dev_priv->vram_size, 0x00000000);
		if (ret) {
270
			nv50_evo_channel_del(&disp->master);
271 272
			return ret;
		}
B
Ben Skeggs 已提交
273
	} else {
274
		ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoFB16, 0x70, 0x19,
275
					  0, 0xffffffff, 0x00010000);
276
		if (ret) {
277
			nv50_evo_channel_del(&disp->master);
278 279 280 281 282
			return ret;
		}


		ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoFB32, 0x7a, 0x19,
283
					  0, 0xffffffff, 0x00010000);
284
		if (ret) {
285
			nv50_evo_channel_del(&disp->master);
286 287 288
			return ret;
		}

289 290 291
		ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoVRAM, 0, 0x19,
					  0, dev_priv->vram_size, 0x00010000);
		if (ret) {
292
			nv50_evo_channel_del(&disp->master);
293 294 295 296 297 298
			return ret;
		}

		ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoVRAM_LP, 0, 0x19,
					  0, dev_priv->vram_size, 0x00010000);
		if (ret) {
299
			nv50_evo_channel_del(&disp->master);
300 301
			return ret;
		}
302
	}
303 304

	return 0;
305 306 307 308 309
}

int
nv50_evo_init(struct drm_device *dev)
{
310
	struct nv50_display *disp = nv50_display(dev);
311 312
	int ret;

313
	if (!disp->master) {
314
		ret = nv50_evo_create(dev);
315 316 317 318
		if (ret)
			return ret;
	}

319
	return nv50_evo_channel_init(disp->master);
320 321 322 323 324
}

void
nv50_evo_fini(struct drm_device *dev)
{
325
	struct nv50_display *disp = nv50_display(dev);
326

327 328 329
	if (disp->master) {
		nv50_evo_channel_fini(disp->master);
		nv50_evo_channel_del(&disp->master);
330 331
	}
}