1/* 2 * SiS hardware cursor handling 3 * Definitions 4 * 5 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1) Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2) Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3) The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 * Author: Thomas Winischhofer <thomas@winischhofer.net> 30 * 31 * Idea based on code by Can-Ru Yeou, SiS Inc. 32 * 33 */ 34 35#define CS(x) (0x8500 + (x << 2)) 36 37/* 300 series, CRT1 */ 38 39/* 80000000 = RGB(1) - MONO(0) 40 * 40000000 = enable(1) - disable(0) 41 * 20000000 = 32(1) / 16(1) bit RGB 42 * 10000000 = "ghost"(1) - [other effect](0) 43 */ 44 45#define sis300GetCursorStatus \ 46 SIS_MMIO_IN32(pSiS->IOBase, CS(0)) & 0x40000000; 47 48#define sis300SetCursorStatus(status) \ 49 { \ 50 ULong temp; \ 51 temp = SIS_MMIO_IN32(pSiS->IOBase, CS(0)); \ 52 temp &= 0xbfffffff; \ 53 temp |= status; \ 54 SIS_MMIO_OUT32(pSiS->IOBase, CS(0), temp); \ 55 } 56 57#define sis300EnableHWCursor() \ 58 { \ 59 ULong temp; \ 60 temp = SIS_MMIO_IN32(pSiS->IOBase, CS(0)); \ 61 temp &= 0x0fffffff; \ 62 temp |= 0x40000000; \ 63 SIS_MMIO_OUT32(pSiS->IOBase, CS(0), temp); \ 64 } 65 66#define sis300EnableHWARGBCursor() \ 67 { \ 68 ULong temp; \ 69 temp = SIS_MMIO_IN32(pSiS->IOBase, CS(0)); \ 70 temp |= 0xF0000000; \ 71 SIS_MMIO_OUT32(pSiS->IOBase, CS(0), temp); \ 72 } 73 74#define sis300EnableHWARGB16Cursor() \ 75 { \ 76 ULong temp; \ 77 temp = SIS_MMIO_IN32(pSiS->IOBase, CS(0)); \ 78 temp &= 0x0fffffff; \ 79 temp |= 0xD0000000; \ 80 SIS_MMIO_OUT32(pSiS->IOBase, CS(0), temp); \ 81 } 82 83#define sis300SwitchToMONOCursor() \ 84 { \ 85 ULong temp; \ 86 temp = SIS_MMIO_IN32(pSiS->IOBase, CS(0)); \ 87 temp &= 0x4fffffff; \ 88 SIS_MMIO_OUT32(pSiS->IOBase, CS(0), temp); \ 89 } 90 91#define sis300SwitchToRGBCursor() \ 92 { \ 93 ULong temp; \ 94 temp = SIS_MMIO_IN32(pSiS->IOBase, CS(0)); \ 95 temp |= 0xB0000000; \ 96 SIS_MMIO_OUT32(pSiS->IOBase, CS(0), temp); \ 97 } 98 99#define sis300DisableHWCursor()\ 100 { \ 101 ULong temp; \ 102 temp = SIS_MMIO_IN32(pSiS->IOBase, CS(0)); \ 103 temp &= 0xbFFFFFFF; \ 104 SIS_MMIO_OUT32(pSiS->IOBase, CS(0), temp); \ 105 } 106 107#define sis300SetCursorBGColor(color)\ 108 SIS_MMIO_OUT32(pSiS->IOBase, CS(1), (color)); 109#define sis300SetCursorFGColor(color)\ 110 SIS_MMIO_OUT32(pSiS->IOBase, CS(2), (color)); 111 112#define sis300SetCursorPositionX(x,preset)\ 113 SIS_MMIO_OUT32(pSiS->IOBase, CS(3), ((x) | ((preset) << 16))); 114#define sis300SetCursorPositionY(y,preset)\ 115 SIS_MMIO_OUT32(pSiS->IOBase, CS(4), ((y) | ((preset) << 16))); 116 117#define sis300SetCursorAddress(address)\ 118 { \ 119 ULong temp; \ 120 temp = SIS_MMIO_IN32(pSiS->IOBase, CS(0)); \ 121 temp &= 0xF0FF0000; \ 122 temp |= address; \ 123 SIS_MMIO_OUT32(pSiS->IOBase,CS(0),temp); \ 124 } 125 126/* 300 series, CRT2 */ 127 128/* 80000000 = RGB(1) - MONO(0) 129 * 40000000 = enable(1) - disable(0) 130 * 20000000 = 32(1) / 16(1) bit RGB 131 * 10000000 = unused (always "ghosting") 132 */ 133 134#define sis301GetCursorStatus \ 135 SIS_MMIO_IN32(pSiS->IOBase, CS(8)) & 0x40000000; 136 137#define sis301SetCursorStatus(status) \ 138 { \ 139 ULong temp; \ 140 temp = SIS_MMIO_IN32(pSiS->IOBase, CS(8)); \ 141 temp &= 0xbfffffff; \ 142 temp |= status; \ 143 SIS_MMIO_OUT32(pSiS->IOBase, CS(8), temp); \ 144 } 145 146#define sis301EnableHWCursor()\ 147 { \ 148 ULong temp; \ 149 temp = SIS_MMIO_IN32(pSiS->IOBase, CS(8)); \ 150 temp &= 0x0fffffff; \ 151 temp |= 0x40000000; \ 152 SIS_MMIO_OUT32(pSiS->IOBase, CS(8), temp); \ 153 } 154 155#define sis301EnableHWARGBCursor()\ 156 { \ 157 ULong temp; \ 158 temp = SIS_MMIO_IN32(pSiS->IOBase, CS(8)); \ 159 temp |= 0xF0000000; \ 160 SIS_MMIO_OUT32(pSiS->IOBase, CS(8), temp); \ 161 } 162 163#define sis301EnableHWARGB16Cursor()\ 164 { \ 165 ULong temp; \ 166 temp = SIS_MMIO_IN32(pSiS->IOBase, CS(8)); \ 167 temp &= 0x0FFFFFFF; \ 168 temp |= 0xD0000000; \ 169 SIS_MMIO_OUT32(pSiS->IOBase, CS(8), temp); \ 170 } 171 172#define sis301SwitchToRGBCursor() \ 173 { \ 174 ULong temp; \ 175 temp = SIS_MMIO_IN32(pSiS->IOBase, CS(8)); \ 176 temp |= 0xB0000000; \ 177 SIS_MMIO_OUT32(pSiS->IOBase, CS(8), temp); \ 178 } 179 180#define sis301SwitchToMONOCursor() \ 181 { \ 182 ULong temp; \ 183 temp = SIS_MMIO_IN32(pSiS->IOBase, CS(8)); \ 184 temp &= 0x4fffffff; \ 185 SIS_MMIO_OUT32(pSiS->IOBase, CS(8), temp); \ 186 } 187 188#define sis301DisableHWCursor()\ 189 { \ 190 ULong temp; \ 191 temp = SIS_MMIO_IN32(pSiS->IOBase, CS(8)); \ 192 temp &= 0xbFFFFFFF; \ 193 SIS_MMIO_OUT32(pSiS->IOBase, CS(8), temp); \ 194 } 195 196#define sis301SetCursorBGColor(color)\ 197 SIS_MMIO_OUT32(pSiS->IOBase, CS(9), (color)); 198#define sis301SetCursorFGColor(color)\ 199 SIS_MMIO_OUT32(pSiS->IOBase, CS(10), (color)); 200 201#define sis301SetCursorPositionX(x,preset)\ 202 SIS_MMIO_OUT32(pSiS->IOBase, CS(11), ((x) | ((preset) << 16))); 203#define sis301SetCursorPositionY(y,preset)\ 204 SIS_MMIO_OUT32(pSiS->IOBase, CS(12), ((y) | ((preset) << 16))); 205 206#define sis301SetCursorAddress(address)\ 207 { \ 208 ULong temp; \ 209 temp = SIS_MMIO_IN32(pSiS->IOBase, CS(8)); \ 210 temp &= 0xF0FF0000; \ 211 temp |= address; \ 212 SIS_MMIO_OUT32(pSiS->IOBase,CS(8),temp); \ 213 } 214 215/* 315/330 series CRT1 */ 216 217/* 80000000 = RGB(1) - MONO(0) 218 * 40000000 = enable(1) - disable(0) 219 * 20000000 = 32(1) / 16(1) bit RGB 220 * 10000000 = "ghost"(1) - Alpha Blend(0) 221 */ 222 223#define sis310GetCursorStatus \ 224 SIS_MMIO_IN32(pSiS->IOBase, CS(0)) & 0x40000000; 225 226#define sis310SetCursorStatus(status) \ 227 pSiS->HWCursorBackup[0] &= 0xbfffffff; \ 228 pSiS->HWCursorBackup[0] |= status; \ 229 SIS_MMIO_OUT32(pSiS->IOBase, CS(0), pSiS->HWCursorBackup[0]); \ 230 SIS_MMIO_OUT32(pSiS->IOBase, CS(3), pSiS->HWCursorBackup[3]); \ 231 SIS_MMIO_OUT32(pSiS->IOBase, CS(4), pSiS->HWCursorBackup[4]); 232 233#define sis310EnableHWCursor()\ 234 pSiS->HWCursorBackup[0] &= 0x0fffffff; \ 235 pSiS->HWCursorBackup[0] |= 0x40000000; \ 236 SIS_MMIO_OUT32(pSiS->IOBase, CS(0), pSiS->HWCursorBackup[0]); \ 237 SIS_MMIO_OUT32(pSiS->IOBase, CS(3), pSiS->HWCursorBackup[3]); \ 238 SIS_MMIO_OUT32(pSiS->IOBase, CS(4), pSiS->HWCursorBackup[4]); 239 240#define sis310EnableHWARGBCursor()\ 241 pSiS->HWCursorBackup[0] &= 0x0FFFFFFF; \ 242 pSiS->HWCursorBackup[0] |= 0xE0000000; \ 243 SIS_MMIO_OUT32(pSiS->IOBase, CS(0), pSiS->HWCursorBackup[0]); \ 244 SIS_MMIO_OUT32(pSiS->IOBase, CS(3), pSiS->HWCursorBackup[3]); \ 245 SIS_MMIO_OUT32(pSiS->IOBase, CS(4), pSiS->HWCursorBackup[4]); 246 247#define sis310SwitchToMONOCursor() \ 248 pSiS->HWCursorBackup[0] &= 0x4fffffff; \ 249 SIS_MMIO_OUT32(pSiS->IOBase, CS(0), pSiS->HWCursorBackup[0]); \ 250 SIS_MMIO_OUT32(pSiS->IOBase, CS(3), pSiS->HWCursorBackup[3]); \ 251 SIS_MMIO_OUT32(pSiS->IOBase, CS(4), pSiS->HWCursorBackup[4]); 252 253#define sis310SwitchToRGBCursor() \ 254 pSiS->HWCursorBackup[0] &= 0xBFFFFFFF; \ 255 pSiS->HWCursorBackup[0] |= 0xA0000000; \ 256 SIS_MMIO_OUT32(pSiS->IOBase, CS(0), pSiS->HWCursorBackup[0]); \ 257 SIS_MMIO_OUT32(pSiS->IOBase, CS(3), pSiS->HWCursorBackup[3]); \ 258 SIS_MMIO_OUT32(pSiS->IOBase, CS(4), pSiS->HWCursorBackup[4]); 259 260#define sis310DisableHWCursor()\ 261 pSiS->HWCursorBackup[0] &= 0xBFFFFFFF; \ 262 SIS_MMIO_OUT32(pSiS->IOBase, CS(0), pSiS->HWCursorBackup[0]); \ 263 SIS_MMIO_OUT32(pSiS->IOBase, CS(3), pSiS->HWCursorBackup[3]); \ 264 SIS_MMIO_OUT32(pSiS->IOBase, CS(4), pSiS->HWCursorBackup[4]); 265 266#define sis310SetCursorBGColor(color) \ 267 SIS_MMIO_OUT32(pSiS->IOBase, CS(1), (color)); \ 268 pSiS->HWCursorBackup[1] = color; 269 270#define sis310SetCursorFGColor(color)\ 271 SIS_MMIO_OUT32(pSiS->IOBase, CS(2), (color)); \ 272 pSiS->HWCursorBackup[2] = color; 273 274#define sis310SetCursorPositionX(x,preset) \ 275 pSiS->HWCursorBackup[3] = ((x) | ((preset) << 16)); \ 276 SIS_MMIO_OUT32(pSiS->IOBase, CS(3), pSiS->HWCursorBackup[3]); 277 278#define sis310SetCursorPositionY(y,preset) \ 279 pSiS->HWCursorBackup[4] = ((y) | ((preset) << 16)); \ 280 SIS_MMIO_OUT32(pSiS->IOBase, CS(4), pSiS->HWCursorBackup[4]); 281 282#define sis310SetCursorAddress(address)\ 283 pSiS->HWCursorBackup[0] &= 0xF0F00000; \ 284 pSiS->HWCursorBackup[0] |= address; \ 285 SIS_MMIO_OUT32(pSiS->IOBase, CS(0), pSiS->HWCursorBackup[0]); \ 286 SIS_MMIO_OUT32(pSiS->IOBase, CS(1), pSiS->HWCursorBackup[1]); \ 287 SIS_MMIO_OUT32(pSiS->IOBase, CS(2), pSiS->HWCursorBackup[2]); \ 288 SIS_MMIO_OUT32(pSiS->IOBase, CS(3), pSiS->HWCursorBackup[3]); \ 289 SIS_MMIO_OUT32(pSiS->IOBase, CS(4), pSiS->HWCursorBackup[4]); 290 291/* 315 series CRT2 */ 292 293/* 80000000 = RGB(1) - MONO(0) 294 * 40000000 = enable(1) - disable(0) 295 * 20000000 = 32(1) / 16(1) bit RGB 296 * 10000000 = "ghost"(1) - Alpha Blend(0) ? 297 */ 298 299#define sis301GetCursorStatus310 \ 300 SIS_MMIO_IN32(pSiS->IOBase, CS(8)) & 0x40000000; 301 302#define sis301SetCursorStatus310(status) \ 303 pSiS->HWCursorBackup[8] &= 0xbfffffff; \ 304 pSiS->HWCursorBackup[8] |= status; \ 305 SIS_MMIO_OUT32(pSiS->IOBase, CS(8), pSiS->HWCursorBackup[8]); \ 306 SIS_MMIO_OUT32(pSiS->IOBase, CS(11), pSiS->HWCursorBackup[11]); \ 307 SIS_MMIO_OUT32(pSiS->IOBase, CS(12), pSiS->HWCursorBackup[12]); 308 309#define sis301EnableHWCursor310()\ 310 pSiS->HWCursorBackup[8] &= 0x0fffffff; \ 311 pSiS->HWCursorBackup[8] |= 0x40000000; \ 312 SIS_MMIO_OUT32(pSiS->IOBase, CS(8), pSiS->HWCursorBackup[8]); \ 313 SIS_MMIO_OUT32(pSiS->IOBase, CS(11), pSiS->HWCursorBackup[11]); \ 314 SIS_MMIO_OUT32(pSiS->IOBase, CS(12), pSiS->HWCursorBackup[12]); 315 316#define sis301EnableHWARGBCursor310()\ 317 pSiS->HWCursorBackup[8] &= 0x0FFFFFFF; \ 318 pSiS->HWCursorBackup[8] |= 0xE0000000; \ 319 SIS_MMIO_OUT32(pSiS->IOBase, CS(8), pSiS->HWCursorBackup[8]); \ 320 SIS_MMIO_OUT32(pSiS->IOBase, CS(11), pSiS->HWCursorBackup[11]); \ 321 SIS_MMIO_OUT32(pSiS->IOBase, CS(12), pSiS->HWCursorBackup[12]); 322 323#define sis301SwitchToRGBCursor310() \ 324 pSiS->HWCursorBackup[8] &= 0xBFFFFFFF; \ 325 pSiS->HWCursorBackup[8] |= 0xA0000000; \ 326 SIS_MMIO_OUT32(pSiS->IOBase, CS(8), pSiS->HWCursorBackup[8]); \ 327 SIS_MMIO_OUT32(pSiS->IOBase, CS(11), pSiS->HWCursorBackup[11]); \ 328 SIS_MMIO_OUT32(pSiS->IOBase, CS(12), pSiS->HWCursorBackup[12]); 329 330#define sis301SwitchToMONOCursor310() \ 331 pSiS->HWCursorBackup[8] &= 0x4fffffff; \ 332 SIS_MMIO_OUT32(pSiS->IOBase, CS(8), pSiS->HWCursorBackup[8]); \ 333 SIS_MMIO_OUT32(pSiS->IOBase, CS(11), pSiS->HWCursorBackup[11]); \ 334 SIS_MMIO_OUT32(pSiS->IOBase, CS(12), pSiS->HWCursorBackup[12]); 335 336#define sis301DisableHWCursor310()\ 337 pSiS->HWCursorBackup[8] &= 0xBFFFFFFF; \ 338 SIS_MMIO_OUT32(pSiS->IOBase, CS(8), pSiS->HWCursorBackup[8]); \ 339 SIS_MMIO_OUT32(pSiS->IOBase, CS(11), pSiS->HWCursorBackup[11]); \ 340 SIS_MMIO_OUT32(pSiS->IOBase, CS(12), pSiS->HWCursorBackup[12]); 341 342#define sis301SetCursorBGColor310(color) \ 343 SIS_MMIO_OUT32(pSiS->IOBase, CS(9), (color)); \ 344 pSiS->HWCursorBackup[9] = color; 345 346#define sis301SetCursorFGColor310(color) \ 347 SIS_MMIO_OUT32(pSiS->IOBase, CS(10), (color)); \ 348 pSiS->HWCursorBackup[10] = color; 349 350#define sis301SetCursorPositionX310(x,preset) \ 351 pSiS->HWCursorBackup[11] = ((x) | ((preset) << 16)); \ 352 SIS_MMIO_OUT32(pSiS->IOBase, CS(11), pSiS->HWCursorBackup[11]); 353 354#define sis301SetCursorPositionY310(y,preset) \ 355 pSiS->HWCursorBackup[12] = ((y) | ((preset) << 16)); \ 356 SIS_MMIO_OUT32(pSiS->IOBase, CS(12), pSiS->HWCursorBackup[12]); 357 358#define sis301SetCursorAddress310(address) \ 359 if(pSiS->ChipType == SIS_315H) { \ 360 if(address & 0x10000) { \ 361 address &= ~0x10000; \ 362 orSISIDXREG(SISSR, 0x37, 0x80); \ 363 } else { \ 364 andSISIDXREG(SISSR, 0x37, 0x7f); \ 365 } \ 366 } \ 367 pSiS->HWCursorBackup[8] &= 0xF0F00000; \ 368 pSiS->HWCursorBackup[8] |= address; \ 369 SIS_MMIO_OUT32(pSiS->IOBase, CS(8), pSiS->HWCursorBackup[8]); \ 370 SIS_MMIO_OUT32(pSiS->IOBase, CS(9), pSiS->HWCursorBackup[9]); \ 371 SIS_MMIO_OUT32(pSiS->IOBase, CS(10), pSiS->HWCursorBackup[10]); \ 372 SIS_MMIO_OUT32(pSiS->IOBase, CS(11), pSiS->HWCursorBackup[11]); \ 373 SIS_MMIO_OUT32(pSiS->IOBase, CS(12), pSiS->HWCursorBackup[12]); 374 375/* 330 series CRT2 */ 376 377/* Mono cursor engine for CRT2 on SiS330 (Xabre) has bugs 378 * and cannot be used! Will hang engine. 379 */ 380 381/* 80000000 = RGB(1) - MONO(0) 382 * 40000000 = enable(1) - disable(0) 383 * 20000000 = 32(1) / 16(1) bit RGB 384 * 10000000 = "ghost"(1) - Alpha Blend(0) ? 385 */ 386 387#define sis301EnableHWCursor330() \ 388 /* andSISIDXREG(SISCR,0x5b,~0x10); */ \ 389 pSiS->HWCursorBackup[8] &= 0x0fffffff; \ 390 pSiS->HWCursorBackup[8] |= 0xE0000000; \ 391 SIS_MMIO_OUT32(pSiS->IOBase, CS(8), pSiS->HWCursorBackup[8]); \ 392 SIS_MMIO_OUT32(pSiS->IOBase, CS(11), pSiS->HWCursorBackup[11]); \ 393 SIS_MMIO_OUT32(pSiS->IOBase, CS(12), pSiS->HWCursorBackup[12]); \ 394 /* orSISIDXREG(SISCR,0x5b,0x10); */ 395 396 397 398