file mga_drm.h was initially added on branch mga-0-0-2-branch.
[platform/upstream/libdrm.git] / linux / mga_dma.h
1 #ifndef MGA_DMA_H
2 #define MGA_DMA_H
3
4 #include "mga_drm_public.h"
5
6
7 /* Isn't this fun.  This has to be fixed asap by emitting primary
8  * dma commands in the 'do_dma' ioctl.
9  */
10 typedef struct {
11         int dma_type;
12
13         unsigned int ContextState[MGA_CTX_SETUP_SIZE];
14         unsigned int ServerState[MGA_2D_SETUP_SIZE];
15         unsigned int TexState[2][MGA_TEX_SETUP_SIZE];
16         unsigned int WarpPipe;
17         unsigned int dirty;
18
19         unsigned int nbox;
20         xf86drmClipRectRec boxes[MGA_NR_SAREA_CLIPRECTS];
21 } drm_mga_buf_priv_t;
22
23
24 #define MGA_DMA_GENERAL 0
25 #define MGA_DMA_VERTEX  1
26 #define MGA_DMA_SETUP   2
27 #define MGA_DMA_ILOAD   3
28
29
30 #define DWGREG0         0x1c00
31 #define DWGREG0_END     0x1dff
32 #define DWGREG1         0x2c00
33 #define DWGREG1_END     0x2dff
34
35 #define ISREG0(r)       (r >= DWGREG0 && r <= DWGREG0_END)
36 #define ADRINDEX0(r)    (u8)((r - DWGREG0) >> 2)
37 #define ADRINDEX1(r)    (u8)(((r - DWGREG1) >> 2) | 0x80)
38 #define ADRINDEX(r)     (ISREG0(r) ? ADRINDEX0(r) : ADRINDEX1(r)) 
39
40
41 /* Macros for inserting commands into a secondary dma buffer.
42  */
43
44 #define DMALOCALS       u8 tempIndex[4]; u32 *dma_ptr; \
45                         int outcount, num_dwords;
46
47 #define DMAGETPTR(buf) do {                     \
48   dma_ptr = (u32 *)((u8 *)buf->address + buf->used);    \
49   outcount = 0;                                 \
50   num_dwords = buf->used / 4;                   \
51 } while(0)
52
53 #define DMAADVANCE(buf) do {                    \
54   buf->used = num_dwords * 4;                   \
55 } while(0)
56
57 #define DMAOUTREG(reg, val) do {                \
58   tempIndex[outcount]=ADRINDEX(reg);            \
59   dma_ptr[++outcount] = val;                    \
60   if (outcount == 4) {                          \
61      outcount = 0;                              \
62      dma_ptr[0] = *(u32 *)tempIndex;            \
63      dma_ptr+=5;                                \
64      num_dwords += 5;                           \
65   }                                             \
66 }while (0)
67
68
69
70 #define VERBO 0
71
72
73 /* Primary buffer versions of above -- pretty similar really.
74  */
75 #define PRIMLOCALS      u8 tempIndex[4]; u32 *dma_ptr; u32 phys_head; \
76                         int outcount, num_dwords
77
78 #define PRIMRESET(dev_priv) do {                                \
79         dev_priv->prim_num_dwords = 0;                          \
80         dev_priv->current_dma_ptr = dev_priv->prim_head;        \
81 } while (0)
82         
83 #define PRIMGETPTR(dev_priv) do {               \
84         dma_ptr = dev_priv->current_dma_ptr;    \
85         phys_head = dev_priv->prim_phys_head;   \
86         num_dwords = dev_priv->prim_num_dwords; \
87         outcount = 0;                           \
88 } while (0)
89
90 #define PRIMADVANCE(dev_priv)   do {            \
91         dev_priv->prim_num_dwords = num_dwords; \
92         dev_priv->current_dma_ptr = dma_ptr;    \
93 } while (0)
94
95 #define PRIMOUTREG(reg, val) do {                                       \
96         tempIndex[outcount]=ADRINDEX(reg);                              \
97         dma_ptr[1+outcount] = val;                                      \
98         if( ++outcount == 4) {                                          \
99                 outcount = 0;                                           \
100                 dma_ptr[0] = *(u32 *)tempIndex;                         \
101                 dma_ptr+=5;                                             \
102                 num_dwords += 5;                                        \
103         }                                                               \
104         if (VERBO)                                                      \
105                 printk(KERN_INFO                                        \
106                        "OUT %x val %x dma_ptr %p nr_dwords %d\n",       \
107                        outcount, ADRINDEX(reg), dma_ptr,                \
108                        num_dwords);                                     \
109 }while (0)
110
111
112 #endif