2 * Copyright 2007 Ben Skeggs
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 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #include "nv_include.h"
26 NVAccelInitNullObject(ScrnInfoPtr pScrn)
28 NVPtr pNv = NVPTR(pScrn);
31 if (nouveau_grobj_alloc(pNv->chan, NvNullObject, NV01_NULL,
40 NVAccelInitDmaNotifier0(ScrnInfoPtr pScrn)
42 NVPtr pNv = NVPTR(pScrn);
45 if (nouveau_notifier_alloc(pNv->chan, NvDmaNotifier0, 1,
53 /* FLAGS_ROP_AND, DmaFB, DmaFB, 0 */
55 NVAccelInitContextSurfaces(ScrnInfoPtr pScrn)
57 NVPtr pNv = NVPTR(pScrn);
60 class = (pNv->Architecture >= NV_10) ? NV10_CONTEXT_SURFACES_2D :
61 NV04_CONTEXT_SURFACES_2D;
63 if (!pNv->NvContextSurfaces) {
64 if (nouveau_grobj_alloc(pNv->chan, NvContextSurfaces, class,
65 &pNv->NvContextSurfaces))
69 BEGIN_RING(NvContextSurfaces, NV04_CONTEXT_SURFACES_2D_DMA_NOTIFY, 1);
70 OUT_RING (pNv->NvNull->handle);
71 BEGIN_RING(NvContextSurfaces,
72 NV04_CONTEXT_SURFACES_2D_DMA_IMAGE_SOURCE, 2);
73 OUT_RING (pNv->chan->vram->handle);
74 OUT_RING (pNv->chan->vram->handle);
79 /* FLAGS_ROP_AND, DmaFB, DmaFB, 0 */
81 NVAccelInitContextBeta1(ScrnInfoPtr pScrn)
83 NVPtr pNv = NVPTR(pScrn);
88 if (!pNv->NvContextBeta1) {
89 if (nouveau_grobj_alloc(pNv->chan, NvContextBeta1, class,
90 &pNv->NvContextBeta1))
94 BEGIN_RING(NvContextBeta1, 0x300, 1); /*alpha factor*/
95 OUT_RING (0xff << 23);
102 NVAccelInitContextBeta4(ScrnInfoPtr pScrn)
104 NVPtr pNv = NVPTR(pScrn);
109 if (!pNv->NvContextBeta4) {
110 if (nouveau_grobj_alloc(pNv->chan, NvContextBeta4, class,
111 &pNv->NvContextBeta4))
115 BEGIN_RING(NvContextBeta4, 0x300, 1); /*RGBA factor*/
116 OUT_RING (0xffff0000);
121 NVAccelGetCtxSurf2DFormatFromPixmap(PixmapPtr pPix, int *fmt_ret)
123 switch (pPix->drawable.bitsPerPixel) {
125 *fmt_ret = NV04_CONTEXT_SURFACES_2D_FORMAT_A8R8G8B8;
128 *fmt_ret = NV04_CONTEXT_SURFACES_2D_FORMAT_X8R8G8B8_Z8R8G8B8;
131 *fmt_ret = NV04_CONTEXT_SURFACES_2D_FORMAT_R5G6B5;
134 *fmt_ret = NV04_CONTEXT_SURFACES_2D_FORMAT_Y8;
144 NVAccelGetCtxSurf2DFormatFromPicture(PicturePtr pPict, int *fmt_ret)
146 switch (pPict->format) {
148 *fmt_ret = NV04_CONTEXT_SURFACES_2D_FORMAT_A8R8G8B8;
151 *fmt_ret = NV04_CONTEXT_SURFACES_2D_FORMAT_X8R8G8B8_Z8R8G8B8;
154 *fmt_ret = NV04_CONTEXT_SURFACES_2D_FORMAT_R5G6B5;
157 *fmt_ret = NV04_CONTEXT_SURFACES_2D_FORMAT_Y8;
167 NVAccelInitImagePattern(ScrnInfoPtr pScrn)
169 NVPtr pNv = NVPTR(pScrn);
172 class = NV04_IMAGE_PATTERN;
174 if (!pNv->NvImagePattern) {
175 if (nouveau_grobj_alloc(pNv->chan, NvImagePattern, class,
176 &pNv->NvImagePattern))
180 BEGIN_RING(NvImagePattern, NV04_IMAGE_PATTERN_DMA_NOTIFY, 1);
181 OUT_RING (pNv->NvNull->handle);
182 BEGIN_RING(NvImagePattern, NV04_IMAGE_PATTERN_MONOCHROME_FORMAT, 3);
183 #if X_BYTE_ORDER == X_BIG_ENDIAN
184 OUT_RING (NV04_IMAGE_PATTERN_MONOCHROME_FORMAT_LE);
186 OUT_RING (NV04_IMAGE_PATTERN_MONOCHROME_FORMAT_CGA6);
188 OUT_RING (NV04_IMAGE_PATTERN_MONOCHROME_SHAPE_8X8);
189 OUT_RING (NV04_IMAGE_PATTERN_PATTERN_SELECT_MONO);
195 NVAccelInitRasterOp(ScrnInfoPtr pScrn)
197 NVPtr pNv = NVPTR(pScrn);
200 class = NV03_CONTEXT_ROP;
203 if (nouveau_grobj_alloc(pNv->chan, NvRop, class,
208 BEGIN_RING(NvRop, NV03_CONTEXT_ROP_DMA_NOTIFY, 1);
209 OUT_RING (pNv->NvNull->handle);
211 pNv->currentRop = ~0;
216 NVAccelInitRectangle(ScrnInfoPtr pScrn)
218 NVPtr pNv = NVPTR(pScrn);
221 class = NV04_GDI_RECTANGLE_TEXT;
223 if (!pNv->NvRectangle) {
224 if (nouveau_grobj_alloc(pNv->chan, NvRectangle, class,
229 BEGIN_RING(NvRectangle, NV04_GDI_RECTANGLE_TEXT_DMA_NOTIFY, 1);
230 OUT_RING (pNv->notify0->handle);
231 BEGIN_RING(NvRectangle, NV04_GDI_RECTANGLE_TEXT_DMA_FONTS, 1);
232 OUT_RING (pNv->NvNull->handle);
233 BEGIN_RING(NvRectangle, NV04_GDI_RECTANGLE_TEXT_SURFACE, 1);
234 OUT_RING (pNv->NvContextSurfaces->handle);
235 BEGIN_RING(NvRectangle, NV04_GDI_RECTANGLE_TEXT_ROP, 1);
236 OUT_RING (pNv->NvRop->handle);
237 BEGIN_RING(NvRectangle, NV04_GDI_RECTANGLE_TEXT_PATTERN, 1);
238 OUT_RING (pNv->NvImagePattern->handle);
239 BEGIN_RING(NvRectangle, NV04_GDI_RECTANGLE_TEXT_OPERATION, 1);
240 OUT_RING (NV04_GDI_RECTANGLE_TEXT_OPERATION_ROP_AND);
241 BEGIN_RING(NvRectangle, NV04_GDI_RECTANGLE_TEXT_MONOCHROME_FORMAT, 1);
242 /* XXX why putting 1 like renouveau dump, swap the text */
243 #if 1 || X_BYTE_ORDER == X_BIG_ENDIAN
244 OUT_RING (NV04_GDI_RECTANGLE_TEXT_MONOCHROME_FORMAT_LE);
246 OUT_RING (NV04_GDI_RECTANGLE_TEXT_MONOCHROME_FORMAT_CGA6);
253 NVAccelInitImageBlit(ScrnInfoPtr pScrn)
255 NVPtr pNv = NVPTR(pScrn);
258 class = (pNv->WaitVSyncPossible) ? NV12_IMAGE_BLIT : NV04_IMAGE_BLIT;
260 if (!pNv->NvImageBlit) {
261 if (nouveau_grobj_alloc(pNv->chan, NvImageBlit, class,
266 BEGIN_RING(NvImageBlit, NV04_IMAGE_BLIT_DMA_NOTIFY, 1);
267 OUT_RING (pNv->notify0->handle);
268 BEGIN_RING(NvImageBlit, NV04_IMAGE_BLIT_COLOR_KEY, 1);
269 OUT_RING (pNv->NvNull->handle);
270 BEGIN_RING(NvImageBlit, NV04_IMAGE_BLIT_SURFACE, 1);
271 OUT_RING (pNv->NvContextSurfaces->handle);
272 BEGIN_RING(NvImageBlit, NV04_IMAGE_BLIT_CLIP_RECTANGLE, 3);
273 OUT_RING (pNv->NvNull->handle);
274 OUT_RING (pNv->NvImagePattern->handle);
275 OUT_RING (pNv->NvRop->handle);
276 BEGIN_RING(NvImageBlit, NV04_IMAGE_BLIT_OPERATION, 1);
277 OUT_RING (NV04_IMAGE_BLIT_OPERATION_ROP_AND);
279 if (pNv->WaitVSyncPossible) {
280 BEGIN_RING(NvImageBlit, 0x0120, 3);
290 NVAccelInitScaledImage(ScrnInfoPtr pScrn)
292 NVPtr pNv = NVPTR(pScrn);
295 switch (pNv->Architecture) {
297 class = NV04_SCALED_IMAGE_FROM_MEMORY;
302 class = NV10_SCALED_IMAGE_FROM_MEMORY;
306 class = NV10_SCALED_IMAGE_FROM_MEMORY | 0x3000;
310 if (!pNv->NvScaledImage) {
311 if (nouveau_grobj_alloc(pNv->chan, NvScaledImage, class,
312 &pNv->NvScaledImage))
316 BEGIN_RING(NvScaledImage,
317 NV04_SCALED_IMAGE_FROM_MEMORY_DMA_NOTIFY, 7);
318 OUT_RING (pNv->notify0->handle);
319 OUT_RING (pNv->chan->vram->handle);
320 OUT_RING (pNv->NvNull->handle);
321 OUT_RING (pNv->NvNull->handle);
322 OUT_RING (pNv->NvContextBeta1->handle);
323 OUT_RING (pNv->NvContextBeta4->handle);
324 OUT_RING (pNv->NvContextSurfaces->handle);
325 if (pNv->Architecture>=NV_ARCH_10) {
326 BEGIN_RING(NvScaledImage,
327 NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION, 1);
328 OUT_RING (NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION_DITHER);
330 BEGIN_RING(NvScaledImage, NV04_SCALED_IMAGE_FROM_MEMORY_OPERATION, 1);
331 OUT_RING (NV04_SCALED_IMAGE_FROM_MEMORY_OPERATION_SRCCOPY);
337 NVAccelInitClipRectangle(ScrnInfoPtr pScrn)
339 NVPtr pNv = NVPTR(pScrn);
340 int class = NV01_CONTEXT_CLIP_RECTANGLE;
342 if (!pNv->NvClipRectangle) {
343 if (nouveau_grobj_alloc(pNv->chan, NvClipRectangle, class,
344 &pNv->NvClipRectangle))
348 BEGIN_RING(NvClipRectangle, NV01_CONTEXT_CLIP_RECTANGLE_DMA_NOTIFY, 1);
349 OUT_RING (pNv->NvNull->handle);
354 /* FLAGS_NONE, NvDmaFB, NvDmaAGP, NvDmaNotifier0 */
356 NVAccelInitMemFormat(ScrnInfoPtr pScrn)
358 NVPtr pNv = NVPTR(pScrn);
361 if (pNv->Architecture < NV_ARCH_50)
362 class = NV04_MEMORY_TO_MEMORY_FORMAT;
364 class = NV50_MEMORY_TO_MEMORY_FORMAT;
366 if (!pNv->NvMemFormat) {
367 if (nouveau_grobj_alloc(pNv->chan, NvMemFormat, class,
372 BEGIN_RING(NvMemFormat, NV04_MEMORY_TO_MEMORY_FORMAT_DMA_NOTIFY, 1);
373 OUT_RING (pNv->notify0->handle);
374 BEGIN_RING(NvMemFormat, NV04_MEMORY_TO_MEMORY_FORMAT_DMA_BUFFER_IN, 2);
375 OUT_RING (pNv->chan->vram->handle);
376 OUT_RING (pNv->chan->vram->handle);
382 NVAccelInitImageFromCpu(ScrnInfoPtr pScrn)
384 NVPtr pNv = NVPTR(pScrn);
387 switch (pNv->Architecture) {
389 class = NV04_IMAGE_FROM_CPU;
396 class = NV10_IMAGE_FROM_CPU;
400 if (!pNv->NvImageFromCpu) {
401 if (nouveau_grobj_alloc(pNv->chan, NvImageFromCpu, class,
402 &pNv->NvImageFromCpu))
406 BEGIN_RING(NvImageFromCpu, NV01_IMAGE_FROM_CPU_DMA_NOTIFY, 1);
407 OUT_RING (pNv->notify0->handle);
408 BEGIN_RING(NvImageFromCpu, NV01_IMAGE_FROM_CPU_CLIP_RECTANGLE, 1);
409 OUT_RING (pNv->NvNull->handle);
410 BEGIN_RING(NvImageFromCpu, NV01_IMAGE_FROM_CPU_PATTERN, 1);
411 OUT_RING (pNv->NvNull->handle);
412 BEGIN_RING(NvImageFromCpu, NV01_IMAGE_FROM_CPU_ROP, 1);
413 OUT_RING (pNv->NvNull->handle);
414 if (pNv->Architecture >= NV_ARCH_10)
416 BEGIN_RING(NvImageFromCpu, NV01_IMAGE_FROM_CPU_BETA1, 1);
417 OUT_RING (pNv->NvNull->handle);
418 BEGIN_RING(NvImageFromCpu, NV05_IMAGE_FROM_CPU_BETA4, 1);
419 OUT_RING (pNv->NvNull->handle);
421 BEGIN_RING(NvImageFromCpu, NV05_IMAGE_FROM_CPU_SURFACE, 1);
422 OUT_RING (pNv->NvContextSurfaces->handle);
423 BEGIN_RING(NvImageFromCpu, NV01_IMAGE_FROM_CPU_OPERATION, 1);
424 OUT_RING (NV01_IMAGE_FROM_CPU_OPERATION_SRCCOPY);
429 NVAccelInit2D_NV50(ScrnInfoPtr pScrn)
431 NVPtr pNv = NVPTR(pScrn);
434 if (nouveau_grobj_alloc(pNv->chan, Nv2D, 0x502d,
439 BEGIN_RING(Nv2D, 0x180, 3);
440 OUT_RING (pNv->notify0->handle);
441 OUT_RING (pNv->chan->vram->handle);
442 OUT_RING (pNv->chan->vram->handle);
444 /* Magics from nv, no clue what they do, but at least some
445 * of them are needed to avoid crashes.
447 BEGIN_RING(Nv2D, 0x260, 1);
449 BEGIN_RING(Nv2D, 0x290, 1);
451 BEGIN_RING(Nv2D, 0x29c, 1);
453 BEGIN_RING(Nv2D, 0x58c, 1);
456 pNv->currentRop = 0xfffffffa;
460 #define INIT_CONTEXT_OBJECT(name) do { \
461 ret = NVAccelInit##name(pScrn); \
463 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, \
464 "Failed to initialise context object: "#name \
471 NVAccelCommonInit(ScrnInfoPtr pScrn)
473 NVPtr pNv = NVPTR(pScrn);
475 if(pNv->NoAccel) return TRUE;
477 /* General engine objects */
478 INIT_CONTEXT_OBJECT(NullObject);
479 INIT_CONTEXT_OBJECT(DmaNotifier0);
482 if (pNv->Architecture < NV_ARCH_50) {
483 INIT_CONTEXT_OBJECT(ContextSurfaces);
484 INIT_CONTEXT_OBJECT(ContextBeta1);
485 INIT_CONTEXT_OBJECT(ContextBeta4);
486 INIT_CONTEXT_OBJECT(ImagePattern);
487 INIT_CONTEXT_OBJECT(RasterOp);
488 INIT_CONTEXT_OBJECT(Rectangle);
489 INIT_CONTEXT_OBJECT(ImageBlit);
490 INIT_CONTEXT_OBJECT(ScaledImage);
491 INIT_CONTEXT_OBJECT(ClipRectangle);
492 INIT_CONTEXT_OBJECT(ImageFromCpu);
494 INIT_CONTEXT_OBJECT(2D_NV50);
496 INIT_CONTEXT_OBJECT(MemFormat);
499 switch (pNv->Architecture) {
501 INIT_CONTEXT_OBJECT(NV40TCL);
504 INIT_CONTEXT_OBJECT(NV30TCL);
508 INIT_CONTEXT_OBJECT(NV10TCL);