2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
5 Desc: vmware svga hardware functions
9 #define DEBUG 1 /* no SysBase */
10 #include <aros/debug.h>
14 #include "vmwaresvgahardware.h"
16 #include "vmwaresvgaclass.h"
18 ULONG
vmwareReadReg(struct HWData
*data
, ULONG reg
)
20 outl(reg
, data
->indexReg
);
21 return inl(data
->valueReg
);
24 void vmwareWriteReg(struct HWData
*data
, ULONG reg
, ULONG val
)
26 outl(reg
, data
->indexReg
);
27 outl(val
, data
->valueReg
);
31 extern struct ExecBase
*SysBase
;
33 ULONG
getVMWareSVGAID(struct HWData
*data
)
37 vmwareWriteReg(data
, SVGA_REG_ID
, SVGA_ID_2
);
38 id
= vmwareReadReg(data
, SVGA_REG_ID
);
41 vmwareWriteReg(data
, SVGA_REG_ID
, SVGA_ID_1
);
42 id
= vmwareReadReg(data
, SVGA_REG_ID
);
47 return SVGA_ID_INVALID
;
50 VOID
initVMWareSVGAFIFO(struct HWData
*data
)
55 vmwareWriteReg(data
, SVGA_REG_CONFIG_DONE
, 0); //Stop vmware from reading the fifo
57 fifo
= data
->mmiobase
= (APTR
)(IPTR
)vmwareReadReg(data
, SVGA_REG_MEM_START
);
58 data
->mmiosize
= vmwareReadReg(data
, SVGA_REG_MEM_SIZE
) & ~3;
60 if (data
->capabilities
& SVGA_CAP_EXTENDED_FIFO
)
61 fifomin
= vmwareReadReg(data
, SVGA_REG_MEM_REGS
);
65 fifo
[SVGA_FIFO_MIN
] = fifomin
* sizeof(ULONG
);
67 /* reduce size of FIFO queue to prevent VMWare from failing */
68 fifo
[SVGA_FIFO_MAX
] = (data
->mmiosize
> 65536) ? 65536 : data
->mmiosize
;
69 fifo
[SVGA_FIFO_NEXT_CMD
] = fifomin
* sizeof(ULONG
);
70 fifo
[SVGA_FIFO_STOP
] = fifomin
* sizeof(ULONG
);
72 vmwareWriteReg(data
, SVGA_REG_CONFIG_DONE
, 1);
75 VOID
syncVMWareSVGAFIFO(struct HWData
*data
)
77 vmwareWriteReg(data
, SVGA_REG_SYNC
, 1);
78 while (vmwareReadReg(data
, SVGA_REG_BUSY
) != 0);
79 /* FIXME: maybe wait (delay) some time */
82 VOID
writeVMWareSVGAFIFO(struct HWData
*data
, ULONG val
)
86 fifo
= data
->mmiobase
;
88 (fifo
[SVGA_FIFO_NEXT_CMD
]+4 == fifo
[SVGA_FIFO_STOP
]) ||
90 (fifo
[SVGA_FIFO_NEXT_CMD
] == (fifo
[SVGA_FIFO_MAX
]-4)) &&
91 (fifo
[SVGA_FIFO_STOP
] == fifo
[SVGA_FIFO_MIN
])
94 syncVMWareSVGAFIFO(data
);
96 fifo
[fifo
[SVGA_FIFO_NEXT_CMD
] / 4] = val
;
97 fifo
[SVGA_FIFO_NEXT_CMD
] += 4;
99 if (fifo
[SVGA_FIFO_NEXT_CMD
] == fifo
[SVGA_FIFO_MAX
])
100 fifo
[SVGA_FIFO_NEXT_CMD
] = fifo
[SVGA_FIFO_MIN
];
103 BOOL
initVMWareSVGAHW(struct HWData
*data
, OOP_Object
*device
)
107 id
= getVMWareSVGAID(data
);
108 if ((id
== SVGA_ID_0
) || (id
== SVGA_ID_INVALID
))
113 initVMWareSVGAFIFO(data
);
115 data
->capabilities
= vmwareReadReg(data
, SVGA_REG_CAPABILITIES
);
117 if (data
->capabilities
& SVGA_CAP_8BIT_EMULATION
)
119 data
->bitsperpixel
= vmwareReadReg(data
, SVGA_REG_HOST_BITS_PER_PIXEL
);
120 vmwareWriteReg(data
,SVGA_REG_BITS_PER_PIXEL
, data
->bitsperpixel
);
122 data
->bitsperpixel
= vmwareReadReg(data
, SVGA_REG_BITS_PER_PIXEL
);
124 data
->depth
= vmwareReadReg(data
, SVGA_REG_DEPTH
);
125 data
->maxwidth
= vmwareReadReg(data
, SVGA_REG_MAX_WIDTH
);
126 data
->maxheight
= vmwareReadReg(data
, SVGA_REG_MAX_HEIGHT
);
127 data
->redmask
= vmwareReadReg(data
, SVGA_REG_RED_MASK
);
128 data
->greenmask
= vmwareReadReg(data
, SVGA_REG_GREEN_MASK
);
129 data
->bluemask
= vmwareReadReg(data
, SVGA_REG_BLUE_MASK
);
130 data
->bytesperpixel
= 1;
133 data
->bytesperpixel
= 4;
134 else if (data
->depth
>8)
135 data
->bytesperpixel
= 2;
137 if (data
->capabilities
& SVGA_CAP_MULTIMON
)
139 data
->displaycount
= vmwareReadReg(data
, SVGA_REG_NUM_DISPLAYS
);
143 data
->displaycount
= 1;
146 data
->vramsize
= vmwareReadReg(data
, SVGA_REG_VRAM_SIZE
);
147 data
->vrambase
= (APTR
)(IPTR
)vmwareReadReg(data
, SVGA_REG_FB_START
);
148 data
->pseudocolor
= vmwareReadReg(data
, SVGA_REG_PSEUDOCOLOR
);
150 D(bug("[VMWareSVGA] Init: VRAM at 0x%08x size %d\n",data
->vrambase
, data
->vramsize
));
151 D(bug("[VMWareSVGA] Init: no.displays: %d\n",data
->displaycount
));
152 D(bug("[VMWareSVGA] Init: caps : 0x%08x\n",data
->capabilities
));
153 D(bug("[VMWareSVGA] Init: no.displays: %d\n",data
->displaycount
));
154 D(bug("[VMWareSVGA] Init: depth: %d\n",data
->depth
));
155 D(bug("[VMWareSVGA] Init: bpp : %d\n",data
->bitsperpixel
));
156 D(bug("[VMWareSVGA] Init: maxw: %d\n",data
->maxwidth
));
157 D(bug("[VMWareSVGA] Init: maxh: %d\n",data
->maxheight
));
162 VOID
setModeVMWareSVGA(struct HWData
*data
, ULONG width
, ULONG height
)
164 D(bug("[VMWareSVGA] SetMode: %dx%d\n",width
,height
));
165 vmwareWriteReg(data
, SVGA_REG_ENABLE
, 0);
166 vmwareWriteReg(data
, SVGA_REG_WIDTH
, width
);
167 vmwareWriteReg(data
, SVGA_REG_HEIGHT
, height
);
169 if (data
->capabilities
& SVGA_CAP_8BIT_EMULATION
)
170 vmwareWriteReg(data
, SVGA_REG_BITS_PER_PIXEL
,data
->bitsperpixel
);
172 vmwareWriteReg(data
, SVGA_REG_ENABLE
, 1);
174 data
->fboffset
= vmwareReadReg(data
, SVGA_REG_FB_OFFSET
);
175 data
->bytesperline
= vmwareReadReg(data
, SVGA_REG_BYTES_PER_LINE
);
176 data
->depth
= vmwareReadReg(data
, SVGA_REG_DEPTH
);
177 data
->redmask
= vmwareReadReg(data
, SVGA_REG_RED_MASK
);
178 data
->greenmask
= vmwareReadReg(data
, SVGA_REG_GREEN_MASK
);
179 data
->bluemask
= vmwareReadReg(data
, SVGA_REG_BLUE_MASK
);
180 data
->pseudocolor
= vmwareReadReg(data
, SVGA_REG_PSEUDOCOLOR
);
183 VOID
refreshAreaVMWareSVGA(struct HWData
*data
, struct Box
*box
)
185 writeVMWareSVGAFIFO(data
, SVGA_CMD_UPDATE
);
186 writeVMWareSVGAFIFO(data
, box
->x1
);
187 writeVMWareSVGAFIFO(data
, box
->y1
);
188 writeVMWareSVGAFIFO(data
, box
->x2
-box
->x1
+1);
189 writeVMWareSVGAFIFO(data
, box
->y2
-box
->y1
+1);
192 VOID
rectFillVMWareSVGA(struct HWData
*data
, ULONG color
, LONG x
, LONG y
, LONG width
, LONG height
)
194 writeVMWareSVGAFIFO(data
, SVGA_CMD_RECT_FILL
);
195 writeVMWareSVGAFIFO(data
, color
);
196 writeVMWareSVGAFIFO(data
, x
);
197 writeVMWareSVGAFIFO(data
, y
);
198 writeVMWareSVGAFIFO(data
, width
);
199 writeVMWareSVGAFIFO(data
, height
);
200 syncVMWareSVGAFIFO(data
);
203 VOID
ropFillVMWareSVGA(struct HWData
*data
, ULONG color
, LONG x
, LONG y
, LONG width
, LONG height
, ULONG mode
)
205 writeVMWareSVGAFIFO(data
, SVGA_CMD_RECT_ROP_FILL
);
206 writeVMWareSVGAFIFO(data
, color
);
207 writeVMWareSVGAFIFO(data
, x
);
208 writeVMWareSVGAFIFO(data
, y
);
209 writeVMWareSVGAFIFO(data
, width
);
210 writeVMWareSVGAFIFO(data
, height
);
211 writeVMWareSVGAFIFO(data
, mode
);
212 syncVMWareSVGAFIFO(data
);
215 VOID
ropCopyVMWareSVGA(struct HWData
*data
, LONG sx
, LONG sy
, LONG dx
, LONG dy
, ULONG width
, ULONG height
, ULONG mode
)
217 writeVMWareSVGAFIFO(data
, SVGA_CMD_RECT_ROP_COPY
);
218 writeVMWareSVGAFIFO(data
, sx
);
219 writeVMWareSVGAFIFO(data
, sy
);
220 writeVMWareSVGAFIFO(data
, dx
);
221 writeVMWareSVGAFIFO(data
, dy
);
222 writeVMWareSVGAFIFO(data
, width
);
223 writeVMWareSVGAFIFO(data
, height
);
224 writeVMWareSVGAFIFO(data
, mode
);
225 syncVMWareSVGAFIFO(data
);
228 VOID
defineCursorVMWareSVGA(struct HWData
*data
, struct MouseData
*mouse
)
231 ULONG
*cshape
= mouse
->shape
;
232 ULONG andmask
[SVGA_PIXMAP_SIZE(mouse
->width
, mouse
->height
, data
->bitsperpixel
)];
236 /* TODO: convert mouse shape to current depth */
237 writeVMWareSVGAFIFO(data
, SVGA_CMD_DEFINE_CURSOR
);
238 writeVMWareSVGAFIFO(data
, 1);
239 writeVMWareSVGAFIFO(data
, 0); /* hot x value */
240 writeVMWareSVGAFIFO(data
, 0); /* hot y value */
241 writeVMWareSVGAFIFO(data
, mouse
->width
); /* width */
242 writeVMWareSVGAFIFO(data
, mouse
->height
); /* height */
243 writeVMWareSVGAFIFO(data
, data
->bitsperpixel
); /* bits per pixel */
244 writeVMWareSVGAFIFO(data
, data
->bitsperpixel
); /* bits per pixel */
249 for (i
= 0; i
<(SVGA_PIXMAP_SIZE(mouse
->width
, mouse
->height
, data
->bitsperpixel
)*2);i
++)
257 for (i
= 0; i
<SVGA_PIXMAP_SIZE(mouse
->width
, mouse
->height
, data
->bitsperpixel
);i
++) {
258 writeVMWareSVGAFIFO(data
, *a
++);
260 for (i
= 0; i
<SVGA_PIXMAP_SIZE(mouse
->width
, mouse
->height
, data
->bitsperpixel
);i
++)
261 writeVMWareSVGAFIFO(data
, *cshape
++);
262 syncVMWareSVGAFIFO(data
);
265 VOID
displayCursorVMWareSVGA(struct HWData
*data
, LONG mode
)
268 writeVMWareSVGAFIFO(data
, SVGA_CMD_DISPLAY_CURSOR
);
269 writeVMWareSVGAFIFO(data
, 1);
270 writeVMWareSVGAFIFO(data
, mode
);
271 syncVMWareSVGAFIFO(data
);
273 vmwareWriteReg(data
, SVGA_REG_CURSOR_ID
, 1);
274 vmwareWriteReg(data
, SVGA_REG_CURSOR_ON
, mode
);
278 VOID
moveCursorVMWareSVGA(struct HWData
*data
, LONG x
, LONG y
)
281 writeVMWareSVGAFIFO(data
, SVGA_CMD_MOVE_CURSOR
);
282 writeVMWareSVGAFIFO(data
, x
);
283 writeVMWareSVGAFIFO(data
, y
);
284 syncVMWareSVGAFIFO(data
);
286 vmwareWriteReg(data
, SVGA_REG_CURSOR_ID
, 1);
287 vmwareWriteReg(data
, SVGA_REG_CURSOR_X
, x
);
288 vmwareWriteReg(data
, SVGA_REG_CURSOR_Y
, y
);
289 vmwareWriteReg(data
, SVGA_REG_CURSOR_ON
, 1);