summaryrefslogtreecommitdiff
path: root/hw/kdrive/pm2/pm2.h
blob: e059033650d2585b75e2a71d637ba4b575a4bc5e (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
#ifndef _PM2_H_
#define _PM2_H_
#include <vesa.h>
#include "kxv.h"
#include "klinux.h"

#include "glint_regs.h"

typedef volatile CARD8	VOL8;
typedef volatile CARD16	VOL16;
typedef volatile CARD32	VOL32;

#define PM2_REG_BASE(c)		((c)->attr.address[0] & 0xFFFFC000)
#define PM2_REG_SIZE(c)		(0x10000)

typedef struct _PM2CardInfo {
    VesaCardPrivRec vesa;
    CARD8 *reg_base;

    int InFifoSpace;
    int	FIFOSize;

    int	pprod;
    int	bppalign;

    int	ClippingOn;

    int	ROP;

    int x;
    int	y;
    int	w;
    int	h;

    int	FrameBufferReadMode;
    int	BppShift;
    int	BltScanDirection;

    int	RasterizerSwap;
    int	PixelWidth;
    int	TexMapFormat;
    int	startxdom;
    int	startxsub;
    int	starty;
    int	count;
    int	dy;
    int	dxdom;

    int	planemask;
} PM2CardInfo;

#define getPM2CardInfo(kd)	((PM2CardInfo *) ((kd)->card->driver))
#define pmCardInfo(kd)	PM2CardInfo	*pm2c = getPM2CardInfo(kd)

typedef struct _PM2ScreenInfo {
    VesaScreenPrivRec vesa;
    CARD8 *cursor_base;
    CARD8 *screen;
    CARD8 *off_screen;
    int	 off_screen_size;
    KdVideoAdaptorPtr pAdaptor;
    KaaScreenInfoRec kaa;
} PM2ScreenInfo;

#define getPM2ScreenInfo(kd) ((PM2ScreenInfo *) ((kd)->screen->driver))
#define pmScreenInfo(kd)    PM2ScreenInfo *pm2s = getPM2ScreenInfo(kd)

Bool 
pmCardInit (KdCardInfo *card);

Bool 
pmScreenInit (KdScreenInfo *screen);

Bool        
pmDrawInit(ScreenPtr);

void
pmDrawEnable (ScreenPtr);

void
pmDrawDisable (ScreenPtr);

void
pmDrawFini (ScreenPtr);


extern KdCardFuncs  PM2Funcs;

#define MMIO_OUT32(base, offset, val) 				\
do { 								\
	*(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) = (val); \
} while (0)

#  define MMIO_IN32(base, offset) 				\
	*(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset))

#define GLINT_WRITE_REG(v,r) 					\
	MMIO_OUT32(mmio,(unsigned long)(r), (v))

#define GLINT_READ_REG(r) 					\
	MMIO_IN32(mmio,(unsigned long)(r))

#define GLINT_SLOW_WRITE_REG(v,r)				\
do{								\
	GLINT_WAIT(card->FIFOSize);		     		\
        GLINT_WRITE_REG(v,r);					\
}while(0)

#define REPLICATE(r)						\
{								\
	if (pScreenPriv->screen->fb[0].bitsPerPixel == 16) {	\
		r &= 0xFFFF;					\
		r |= (r<<16);					\
	} else							\
	if (pScreenPriv->screen->fb[0].bitsPerPixel == 8) { 	\
		r &= 0xFF;					\
		r |= (r<<8);					\
		r |= (r<<16);					\
	}							\
}

#define DO_PLANEMASK(planemask)					\
{ 								\
	if (planemask != card->planemask) {			\
		card->planemask = planemask;			\
		REPLICATE(planemask); 				\
		GLINT_WRITE_REG(planemask, FBHardwareWriteMask);\
	}							\
} 

#define LOADROP(rop)						\
{								\
	if (card->ROP != rop)	{				\
		GLINT_WRITE_REG(rop<<1|UNIT_ENABLE, LogicalOpMode);	\
		card->ROP = rop;				\
	}							\
}

#define GLINT_WAIT(n)						\
do{								\
	if (card->InFifoSpace>=(n))				\
	    card->InFifoSpace -= (n);				\
	else {							\
	    int tmp;						\
	    while((tmp=GLINT_READ_REG(InFIFOSpace))<(n));	\
	    /* Clamp value due to bugs in PM3 */		\
	    if (tmp > card->FIFOSize)				\
		tmp = card->FIFOSize;				\
	    card->InFifoSpace = tmp - (n);			\
	}							\
}while(0)

#define CHECKCLIPPING						\
{								\
	if (card->ClippingOn) {					\
		card->ClippingOn = FALSE;			\
		GLINT_WAIT(1);					\
		GLINT_WRITE_REG(0, ScissorMode);		\
	}							\
}

#endif /* _PM2_H_ */