summaryrefslogtreecommitdiff
path: root/src/rdc_2dtool.c
blob: 16d9e2672183c1dba31caf299268cc0c5c28e96f (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/* 
 * Copyright (C) 2009 RDC Semiconductor Co.,Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * For technical support : 
 *     <jason.lin@rdc.com.tw>
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "xf86.h"
#include "xf86_OSproc.h"
#include "xf86Resources.h"
#include "xf86RAC.h"
#include "xf86cmap.h"
#include "compiler.h"
#include "mibstore.h"
#include "vgaHW.h"
#include "mipointer.h"
#include "micmap.h"

#include "fb.h"
#include "regionstr.h"
#include "xf86xv.h"
#include <X11/extensions/Xv.h>
#include "vbe.h"

#include "xf86PciInfo.h"
#include "xf86Pci.h"

/* framebuffer offscreen manager */
#include "xf86fbman.h"

/* include xaa includes */
#include "xaa.h"
#include "xaarop.h"

/* H/W cursor support */
#include "xf86Cursor.h"

/* Driver specific headers */
#include "rdc.h"

#ifdef Accel_2D

/* Prototype type declaration */
Bool    bInitCMDQInfo(ScrnInfoPtr pScrn, RDCRecPtr pRDC);
Bool    bEnableCMDQ(ScrnInfoPtr pScrn, RDCRecPtr pRDC);
Bool    bEnable2D(ScrnInfoPtr pScrn, RDCRecPtr pRDC);
void    vDisable2D(ScrnInfoPtr pScrn, RDCRecPtr pRDC);
void    vWaitEngIdle(ScrnInfoPtr pScrn, RDCRecPtr pRDC);    
UCHAR   *pjRequestCMDQ(RDCRecPtr pRDC, ULONG   ulDataLen);

Bool
bInitCMDQInfo(ScrnInfoPtr pScrn, RDCRecPtr pRDC)
{

    ScreenPtr pScreen;
    
    xf86DrvMsgVerb(0, X_INFO, InternalLevel, "==Init CMDQ Info== \n");
    
    pRDC->CMDQInfo.pjCmdQBasePort    = pRDC->MMIOVirtualAddr+ 0x8044; 
    pRDC->CMDQInfo.pjWritePort       = pRDC->MMIOVirtualAddr+ 0x8048;
    pRDC->CMDQInfo.pjReadPort        = pRDC->MMIOVirtualAddr+ 0x804C;
    pRDC->CMDQInfo.pjEngStatePort    = pRDC->MMIOVirtualAddr+ 0x804C;

    /* CMDQ mode Init */
    if (!pRDC->MMIO2D) 
    {
        pRDC->CMDQInfo.ulCMDQType = VM_CMD_QUEUE;    
       
        pScreen = screenInfo.screens[pScrn->scrnIndex];
        
        pRDC->CMDQInfo.pjCMDQVirtualAddr = pRDC->FBVirtualAddr + pRDC->CMDQInfo.ulCMDQOffsetAddr;
        pRDC->CMDQInfo.ulCurCMDQueueLen = pRDC->CMDQInfo.ulCMDQSize - CMD_QUEUE_GUARD_BAND;
        pRDC->CMDQInfo.ulCMDQMask = pRDC->CMDQInfo.ulCMDQSize - 1 ; 
    }
    
    /* MMIO mode init */  
    if (pRDC->MMIO2D)
    {        
        pRDC->CMDQInfo.ulCMDQType = VM_CMD_MMIO;        
    }
       
    return (TRUE);    
}

Bool
bEnableCMDQ(ScrnInfoPtr pScrn, RDCRecPtr pRDC)
{
    ULONG ulVMCmdQBasePort = 0;
    
    xf86DrvMsgVerb(0, X_INFO, InternalLevel, "==Entry Enable CMDQ== \n");

    vWaitEngIdle(pScrn, pRDC);  

    /* set DBG Select Info */
    if (pRDC->DBGSelect)
    {
        *(ULONG *) (pRDC->MMIOVirtualAddr + 0x804C) = (ULONG) (pRDC->DBGSelect);                 
    }
    
    /* set CMDQ base */
    switch (pRDC->CMDQInfo.ulCMDQType)
    {
    case VM_CMD_QUEUE:
        ulVMCmdQBasePort  = pRDC->CMDQInfo.ulCMDQOffsetAddr >> 3;
 
        /* set CMDQ Threshold */
        ulVMCmdQBasePort |= 0xF0000000;               

        /* set CMDQ Size */
        switch (pRDC->CMDQInfo.ulCMDQSize)
        {
        case CMD_QUEUE_SIZE_256K:
            ulVMCmdQBasePort |= 0x00000000;   
            break;

        case CMD_QUEUE_SIZE_512K:
            ulVMCmdQBasePort |= 0x04000000;   
            break;
      
        case CMD_QUEUE_SIZE_1M:
            ulVMCmdQBasePort |= 0x08000000;       
            break;
            
        case CMD_QUEUE_SIZE_2M:
            ulVMCmdQBasePort |= 0x0C000000;       
            break;        
            
        default:
            return(FALSE);
            break;
        }     
                                 
        *(ULONG *) (pRDC->CMDQInfo.pjCmdQBasePort) = ulVMCmdQBasePort;         
        pRDC->CMDQInfo.ulWritePointer = *(ULONG *) (pRDC->CMDQInfo.pjWritePort) << 3;                 
        break;
        
    case VM_CMD_MMIO:
        /* set CMDQ Threshold */
        ulVMCmdQBasePort |= 0xF0000000;               
        ulVMCmdQBasePort |= 0x02000000;            /* MMIO mode */
        *(ULONG *) (pRDC->CMDQInfo.pjCmdQBasePort) = ulVMCmdQBasePort;                                
        break;
        
    default:
        return (FALSE);
        break;
    }

    return (TRUE);    
}

Bool
bEnable2D(ScrnInfoPtr pScrn, RDCRecPtr pRDC)
{

    xf86DrvMsgVerb(0, X_INFO, InternalLevel, "==Enable 2D== \n");
    
    SetIndexRegMask(CRTC_PORT, 0xA4, 0xFE, 0x01);        /* enable 2D */

    SetIndexRegMask(CRTC_PORT, 0xA3, ~0x20, 0x20);       /* enable flip */    
    *(ULONG *)MMIOREG_1ST_FLIP |=  0x80000000;

    if (!bInitCMDQInfo(pScrn, pRDC))
    {
        vDisable2D(pScrn, pRDC);      
        return (FALSE);
    }
        
    if (!bEnableCMDQ(pScrn, pRDC))
    {
        vDisable2D(pScrn, pRDC);      
        return (FALSE);
    }
            
    return (TRUE);    
}

void
vDisable2D(ScrnInfoPtr pScrn, RDCRecPtr pRDC)
{
   xf86DrvMsgVerb(0, X_INFO, InternalLevel, "==Engine Disable 2D== \n");

    vWaitEngIdle(pScrn, pRDC);
    vWaitEngIdle(pScrn, pRDC);
    SetIndexRegMask(CRTC_PORT, 0xA4, 0xFE, 0x00);

    SetIndexRegMask(CRTC_PORT, 0xA3, ~0x20, 0x00);       /* disable flip */
    *(ULONG *)MMIOREG_1ST_FLIP &=  ~0x80000000;
}


void
vWaitEngIdle(ScrnInfoPtr pScrn, RDCRecPtr pRDC)
{
    ULONG  ulEngState, ulEngState2;

    xf86DrvMsgVerb(0, X_INFO, 10, "==Entry Wait Idle== \n");

    do  /* wait engine idle */
    {
        ulEngState = *((volatile ULONG*)(pRDC->MMIOVirtualAddr + 0x804c));    
        ulEngState2 = *((volatile ULONG*)(pRDC->MMIOVirtualAddr + 0x8048));        
    } while ((ulEngState & 0x80000000) || 
            ((ulEngState&0x3ffff) != (ulEngState2&0x3ffff)));
            
    xf86DrvMsgVerb(0, X_INFO, 10, "==Exit Wait Idle== \n");
}    

/* ULONG ulGetCMDQLength() */
__inline ULONG ulGetCMDQLength(RDCRecPtr pRDC, ULONG ulWritePointer, ULONG ulCMDQMask)
{
    ULONG ulReadPointer, ulReadPointer2;

    do {
        ulReadPointer  = *((volatile ULONG *)(pRDC->CMDQInfo.pjReadPort)) & 0x0003FFFF;        
        ulReadPointer2 = *((volatile ULONG *)(pRDC->CMDQInfo.pjReadPort)) & 0x0003FFFF;
        ulReadPointer2 = *((volatile ULONG *)(pRDC->CMDQInfo.pjReadPort)) & 0x0003FFFF;
        ulReadPointer2 = *((volatile ULONG *)(pRDC->CMDQInfo.pjReadPort)) & 0x0003FFFF;
        ulReadPointer2 = *((volatile ULONG *)(pRDC->CMDQInfo.pjReadPort)) & 0x0003FFFF;
        ulReadPointer2 = *((volatile ULONG *)(pRDC->CMDQInfo.pjReadPort)) & 0x0003FFFF;        
     } while (ulReadPointer != ulReadPointer2);

    return ((ulReadPointer << 3) - ulWritePointer - CMD_QUEUE_GUARD_BAND) & ulCMDQMask;
}

UCHAR *pjRequestCMDQ(
RDCRecPtr pRDC, ULONG   ulDataLen)
{
    UCHAR   *pjBuffer;
    ULONG   i, ulWritePointer, ulCMDQMask, ulCurCMDQLen, ulContinueCMDQLen;

    ulWritePointer = pRDC->CMDQInfo.ulWritePointer;
    ulContinueCMDQLen = pRDC->CMDQInfo.ulCMDQSize - ulWritePointer;
    ulCMDQMask = pRDC->CMDQInfo.ulCMDQMask;        
    
    if (ulContinueCMDQLen >= ulDataLen)
    {
        /* Get CMDQ Buffer */                
        if (pRDC->CMDQInfo.ulCurCMDQueueLen < ulDataLen)
        {
            do
            {
                ulCurCMDQLen = ulGetCMDQLength(pRDC, ulWritePointer, ulCMDQMask);
            } while (ulCurCMDQLen < ulDataLen);
            
            pRDC->CMDQInfo.ulCurCMDQueueLen = ulCurCMDQLen;
        }
        
        pjBuffer = pRDC->CMDQInfo.pjCMDQVirtualAddr + ulWritePointer;
        pRDC->CMDQInfo.ulCurCMDQueueLen -= ulDataLen;            
        pRDC->CMDQInfo.ulWritePointer = (ulWritePointer + ulDataLen) & ulCMDQMask;
        return pjBuffer;            
    }
    else
    {   

        /* Fill NULL CMD to the last of the CMDQ */
        if (pRDC->CMDQInfo.ulCurCMDQueueLen < ulContinueCMDQLen)
        {
            do
            {
                ulCurCMDQLen = ulGetCMDQLength(pRDC, ulWritePointer, ulCMDQMask);
            } while (ulCurCMDQLen < ulContinueCMDQLen);
            
            pRDC->CMDQInfo.ulCurCMDQueueLen = ulCurCMDQLen;
        }
    
        pjBuffer = pRDC->CMDQInfo.pjCMDQVirtualAddr + ulWritePointer;
        
        for (i = 0; i<ulContinueCMDQLen/8; i++, pjBuffer+=8)
        {
            *(ULONG *)pjBuffer = (ULONG) PKT_NULL_CMD;
            *(ULONG *) (pjBuffer+4) = 0;
        }
        
        pRDC->CMDQInfo.ulCurCMDQueueLen -= ulContinueCMDQLen;
        pRDC->CMDQInfo.ulWritePointer = ulWritePointer = 0;
            
        /* Get CMDQ Buffer */    
        if (pRDC->CMDQInfo.ulCurCMDQueueLen < ulDataLen)
        {
            do
            {
                ulCurCMDQLen = ulGetCMDQLength(pRDC, ulWritePointer, ulCMDQMask);
            } while (ulCurCMDQLen < ulDataLen);

            pRDC->CMDQInfo.ulCurCMDQueueLen = ulCurCMDQLen;
        }

        pRDC->CMDQInfo.ulCurCMDQueueLen -= ulDataLen;
        pjBuffer = pRDC->CMDQInfo.pjCMDQVirtualAddr + ulWritePointer;
        pRDC->CMDQInfo.ulWritePointer = (ulWritePointer + ulDataLen) & ulCMDQMask;
        return pjBuffer;            
    }
   
} /* end of pjRequestCmdQ() */

#endif    /* end of Accel_2D */