2 * Copyright 2010 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
27 #include "nouveau_drv.h"
28 #include "nouveau_dma.h"
29 #include "nouveau_ramht.h"
30 #include "nv50_display.h"
33 nv50_evo_channel_del(struct nouveau_channel **pevo)
35 struct nouveau_channel *evo = *pevo;
36 struct nv50_display *disp;
42 disp = nv50_display(evo->dev);
43 disp->evo_alloc &= ~(1 << evo->id);
45 nouveau_gpuobj_channel_takedown(evo);
46 nouveau_bo_unmap(evo->pushbuf_bo);
47 nouveau_bo_ref(NULL, &evo->pushbuf_bo);
56 nv50_evo_dmaobj_new(struct nouveau_channel *evo, u32 class, u32 name,
57 u32 tile_flags, u32 magic_flags, u32 offset, u32 limit,
60 struct drm_nouveau_private *dev_priv = evo->dev->dev_private;
61 struct nv50_display *disp = nv50_display(evo->dev);
62 struct nouveau_gpuobj *obj = NULL;
65 ret = nouveau_gpuobj_new(evo->dev, disp->master, 6*4, 32, 0, &obj);
68 obj->engine = NVOBJ_ENGINE_DISPLAY;
70 nv_wo32(obj, 0, (tile_flags << 22) | (magic_flags << 16) | class);
71 nv_wo32(obj, 4, limit);
72 nv_wo32(obj, 8, offset);
73 nv_wo32(obj, 12, 0x00000000);
74 nv_wo32(obj, 16, 0x00000000);
75 nv_wo32(obj, 20, flags5);
76 dev_priv->engine.instmem.flush(evo->dev);
78 ret = nouveau_ramht_insert(evo, name, obj);
79 nouveau_gpuobj_ref(NULL, &obj);
88 nv50_evo_channel_new(struct drm_device *dev, struct nouveau_channel **pevo)
90 struct nv50_display *disp = nv50_display(dev);
91 struct nouveau_channel *evo;
94 evo = kzalloc(sizeof(struct nouveau_channel), GFP_KERNEL);
99 for (evo->id = 0; evo->id < 5; evo->id++) {
100 if (disp->evo_alloc & (1 << evo->id))
103 disp->evo_alloc |= (1 << evo->id);
116 ret = nouveau_bo_new(dev, NULL, 4096, 0, TTM_PL_FLAG_VRAM, 0, 0,
117 false, true, &evo->pushbuf_bo);
119 ret = nouveau_bo_pin(evo->pushbuf_bo, TTM_PL_FLAG_VRAM);
121 NV_ERROR(dev, "Error creating EVO DMA push buffer: %d\n", ret);
122 nv50_evo_channel_del(pevo);
126 ret = nouveau_bo_map(evo->pushbuf_bo);
128 NV_ERROR(dev, "Error mapping EVO DMA push buffer: %d\n", ret);
129 nv50_evo_channel_del(pevo);
133 evo->user = ioremap(pci_resource_start(dev->pdev, 0) +
134 NV50_PDISPLAY_USER(evo->id), PAGE_SIZE);
136 NV_ERROR(dev, "Error mapping EVO control regs.\n");
137 nv50_evo_channel_del(pevo);
141 /* bind primary evo channel's ramht to the channel */
142 if (disp->master && evo != disp->master)
143 nouveau_ramht_ref(disp->master->ramht, &evo->ramht, NULL);
149 nv50_evo_channel_init(struct nouveau_channel *evo)
151 struct drm_device *dev = evo->dev;
152 int id = evo->id, ret, i;
153 u64 pushbuf = evo->pushbuf_bo->bo.mem.start << PAGE_SHIFT;
156 tmp = nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id));
157 if ((tmp & 0x009f0000) == 0x00020000)
158 nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), tmp | 0x00800000);
160 tmp = nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id));
161 if ((tmp & 0x003f0000) == 0x00030000)
162 nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), tmp | 0x00600000);
164 /* initialise fifo */
165 nv_wr32(dev, NV50_PDISPLAY_EVO_DMA_CB(id), pushbuf >> 8 |
166 NV50_PDISPLAY_EVO_DMA_CB_LOCATION_VRAM |
167 NV50_PDISPLAY_EVO_DMA_CB_VALID);
168 nv_wr32(dev, NV50_PDISPLAY_EVO_UNK2(id), 0x00010000);
169 nv_wr32(dev, NV50_PDISPLAY_EVO_HASH_TAG(id), id);
170 nv_mask(dev, NV50_PDISPLAY_EVO_CTRL(id), NV50_PDISPLAY_EVO_CTRL_DMA,
171 NV50_PDISPLAY_EVO_CTRL_DMA_ENABLED);
173 nv_wr32(dev, NV50_PDISPLAY_USER_PUT(id), 0x00000000);
174 nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x01000003 |
175 NV50_PDISPLAY_EVO_CTRL_DMA_ENABLED);
176 if (!nv_wait(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x80000000, 0x00000000)) {
177 NV_ERROR(dev, "EvoCh %d init timeout: 0x%08x\n", id,
178 nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id)));
182 /* enable error reporting on the channel */
183 nv_mask(dev, 0x610028, 0x00000000, 0x00010001 << id);
185 evo->dma.max = (4096/4) - 2;
187 evo->dma.cur = evo->dma.put;
188 evo->dma.free = evo->dma.max - evo->dma.cur;
190 ret = RING_SPACE(evo, NOUVEAU_DMA_SKIPS);
194 for (i = 0; i < NOUVEAU_DMA_SKIPS; i++)
201 nv50_evo_channel_fini(struct nouveau_channel *evo)
203 struct drm_device *dev = evo->dev;
206 nv_mask(dev, 0x610028, 0x00010001 << id, 0x00000000);
207 nv_mask(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x00001010, 0x00001000);
208 nv_wr32(dev, NV50_PDISPLAY_INTR_0, (1 << id));
209 nv_mask(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x00000003, 0x00000000);
210 if (!nv_wait(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x001e0000, 0x00000000)) {
211 NV_ERROR(dev, "EvoCh %d takedown timeout: 0x%08x\n", id,
212 nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id)));
217 nv50_evo_create(struct drm_device *dev)
219 struct drm_nouveau_private *dev_priv = dev->dev_private;
220 struct nv50_display *disp = nv50_display(dev);
221 struct nouveau_gpuobj *ramht = NULL;
222 struct nouveau_channel *evo;
225 /* create primary evo channel, the one we use for modesetting
228 ret = nv50_evo_channel_new(dev, &disp->master);
233 /* setup object management on it, any other evo channel will
234 * use this also as there's no per-channel support on the
237 ret = nouveau_gpuobj_new(dev, NULL, 32768, 65536,
238 NVOBJ_FLAG_ZERO_ALLOC, &evo->ramin);
240 NV_ERROR(dev, "Error allocating EVO channel memory: %d\n", ret);
241 nv50_evo_channel_del(&disp->master);
245 ret = drm_mm_init(&evo->ramin_heap, 0, 32768);
247 NV_ERROR(dev, "Error initialising EVO PRAMIN heap: %d\n", ret);
248 nv50_evo_channel_del(&disp->master);
252 ret = nouveau_gpuobj_new(dev, evo, 4096, 16, 0, &ramht);
254 NV_ERROR(dev, "Unable to allocate EVO RAMHT: %d\n", ret);
255 nv50_evo_channel_del(&disp->master);
259 ret = nouveau_ramht_new(dev, ramht, &evo->ramht);
260 nouveau_gpuobj_ref(NULL, &ramht);
262 nv50_evo_channel_del(&disp->master);
266 /* create some default objects for the scanout memtypes we support */
267 if (dev_priv->card_type >= NV_C0) {
268 ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoFB32, 0xfe, 0x19,
269 0, 0xffffffff, 0x00000000);
271 nv50_evo_channel_del(&disp->master);
275 ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoVRAM, 0, 0x19,
276 0, dev_priv->vram_size, 0x00020000);
278 nv50_evo_channel_del(&disp->master);
282 ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoVRAM_LP, 0, 0x19,
283 0, dev_priv->vram_size, 0x00000000);
285 nv50_evo_channel_del(&disp->master);
289 ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoFB16, 0x70, 0x19,
290 0, 0xffffffff, 0x00010000);
292 nv50_evo_channel_del(&disp->master);
297 ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoFB32, 0x7a, 0x19,
298 0, 0xffffffff, 0x00010000);
300 nv50_evo_channel_del(&disp->master);
304 ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoVRAM, 0, 0x19,
305 0, dev_priv->vram_size, 0x00010000);
307 nv50_evo_channel_del(&disp->master);
311 ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoVRAM_LP, 0, 0x19,
312 0, dev_priv->vram_size, 0x00010000);
314 nv50_evo_channel_del(&disp->master);
323 nv50_evo_init(struct drm_device *dev)
325 struct nv50_display *disp = nv50_display(dev);
329 ret = nv50_evo_create(dev);
334 return nv50_evo_channel_init(disp->master);
338 nv50_evo_fini(struct drm_device *dev)
340 struct nv50_display *disp = nv50_display(dev);
343 nv50_evo_channel_fini(disp->master);
344 nv50_evo_channel_del(&disp->master);