nouveau: update for drm interface changes (0.0.5)
[mesa.git] / src / mesa / drivers / dri / nouveau / nouveau_object.c
1
2 #include "nouveau_fifo.h"
3 #include "nouveau_object.h"
4 #include "nouveau_reg.h"
5
6
7 GLboolean nouveauCreateContextObject(nouveauContextPtr nmesa,
8 uint32_t handle, int class)
9 {
10 drm_nouveau_object_init_t cto;
11 int ret;
12
13 cto.channel = nmesa->fifo.channel;
14 cto.handle = handle;
15 cto.class = class;
16 ret = drmCommandWrite(nmesa->driFd, DRM_NOUVEAU_OBJECT_INIT, &cto, sizeof(cto));
17
18 return ret == 0;
19 }
20
21 GLboolean nouveauCreateDmaObject(nouveauContextPtr nmesa,
22 uint32_t handle,
23 int class,
24 uint32_t offset,
25 uint32_t size,
26 int target,
27 int access)
28 {
29 drm_nouveau_dma_object_init_t dma;
30 int ret;
31
32 dma.channel = nmesa->fifo.channel;
33 dma.class = class;
34 dma.handle = handle;
35 dma.target = target;
36 dma.access = access;
37 dma.offset = offset;
38 dma.size = size;
39 ret = drmCommandWriteRead(nmesa->driFd, DRM_NOUVEAU_DMA_OBJECT_INIT,
40 &dma, sizeof(dma));
41 return ret == 0;
42 }
43
44 GLboolean nouveauCreateDmaObjectFromMem(nouveauContextPtr nmesa,
45 uint32_t handle, int class,
46 nouveau_mem *mem,
47 int access)
48 {
49 uint32_t offset = mem->offset;
50 int target = mem->type & (NOUVEAU_MEM_FB | NOUVEAU_MEM_AGP);
51
52 if (!target)
53 return GL_FALSE;
54
55 if (target & NOUVEAU_MEM_FB)
56 offset -= nmesa->vram_phys;
57 else if (target & NOUVEAU_MEM_AGP)
58 offset -= nmesa->agp_phys;
59
60 return nouveauCreateDmaObject(nmesa, handle, class,
61 offset, mem->size,
62 target, access);
63 }
64
65 void nouveauObjectOnSubchannel(nouveauContextPtr nmesa, int subchannel, int handle)
66 {
67 BEGIN_RING_SIZE(subchannel, 0, 1);
68 OUT_RING(handle);
69 }
70
71 void nouveauObjectInit(nouveauContextPtr nmesa)
72 {
73 #ifdef NOUVEAU_RING_DEBUG
74 return;
75 #endif
76
77 /* We need to know vram size.. and AGP size (and even if the card is AGP..) */
78 nouveauCreateDmaObject( nmesa, NvDmaFB, NV_DMA_IN_MEMORY,
79 0, nmesa->vram_size,
80 NOUVEAU_MEM_FB,
81 NOUVEAU_MEM_ACCESS_RW);
82 nouveauCreateDmaObject( nmesa, NvDmaAGP, NV_DMA_IN_MEMORY,
83 0, nmesa->agp_size,
84 NOUVEAU_MEM_AGP,
85 NOUVEAU_MEM_ACCESS_RW);
86
87 nouveauCreateContextObject(nmesa, Nv3D, nmesa->screen->card->class_3d);
88 if (nmesa->screen->card->type>=NV_10) {
89 nouveauCreateContextObject(nmesa, NvCtxSurf2D, NV10_CONTEXT_SURFACES_2D);
90 nouveauCreateContextObject(nmesa, NvImageBlit, NV10_IMAGE_BLIT);
91 } else {
92 nouveauCreateContextObject(nmesa, NvCtxSurf2D, NV04_CONTEXT_SURFACES_2D);
93 nouveauCreateContextObject(nmesa, NvCtxSurf3D, NV04_CONTEXT_SURFACES_3D);
94 nouveauCreateContextObject(nmesa, NvImageBlit, NV_IMAGE_BLIT);
95 }
96 nouveauCreateContextObject(nmesa, NvMemFormat, NV_MEMORY_TO_MEMORY_FORMAT);
97
98 #ifdef ALLOW_MULTI_SUBCHANNEL
99 nouveauObjectOnSubchannel(nmesa, NvSubCtxSurf2D, NvCtxSurf2D);
100 BEGIN_RING_SIZE(NvSubCtxSurf2D, NV10_CONTEXT_SURFACES_2D_SET_DMA_IN_MEMORY0, 2);
101 OUT_RING(NvDmaFB);
102 OUT_RING(NvDmaFB);
103
104 nouveauObjectOnSubchannel(nmesa, NvSubImageBlit, NvImageBlit);
105 BEGIN_RING_SIZE(NvSubImageBlit, NV10_IMAGE_BLIT_SET_CONTEXT_SURFACES_2D, 1);
106 OUT_RING(NvCtxSurf2D);
107 BEGIN_RING_SIZE(NvSubImageBlit, NV10_IMAGE_BLIT_SET_OPERATION, 1);
108 OUT_RING(3); /* SRCCOPY */
109
110 nouveauObjectOnSubchannel(nmesa, NvSubMemFormat, NvMemFormat);
111 #endif
112
113 nouveauObjectOnSubchannel(nmesa, NvSub3D, Nv3D);
114 }
115
116
117