1fa225cbcSrjs 2fa225cbcSrjs/************************************************************************** 3fa225cbcSrjs 4fa225cbcSrjsCopyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. 5fa225cbcSrjsAll Rights Reserved. 6fa225cbcSrjs 7fa225cbcSrjsPermission is hereby granted, free of charge, to any person obtaining a 8fa225cbcSrjscopy of this software and associated documentation files (the 9fa225cbcSrjs"Software"), to deal in the Software without restriction, including 10fa225cbcSrjswithout limitation the rights to use, copy, modify, merge, publish, 11fa225cbcSrjsdistribute, sub license, and/or sell copies of the Software, and to 12fa225cbcSrjspermit persons to whom the Software is furnished to do so, subject to 13fa225cbcSrjsthe following conditions: 14fa225cbcSrjs 15fa225cbcSrjsThe above copyright notice and this permission notice (including the 16fa225cbcSrjsnext paragraph) shall be included in all copies or substantial portions 17fa225cbcSrjsof the Software. 18fa225cbcSrjs 19fa225cbcSrjsTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20fa225cbcSrjsOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21fa225cbcSrjsMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 22fa225cbcSrjsIN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 23fa225cbcSrjsANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24fa225cbcSrjsTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25fa225cbcSrjsSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26fa225cbcSrjs 27fa225cbcSrjs**************************************************************************/ 28fa225cbcSrjs 29fa225cbcSrjs#ifdef HAVE_CONFIG_H 30fa225cbcSrjs#include "config.h" 31fa225cbcSrjs#endif 32fa225cbcSrjs 33fa225cbcSrjs/* 34fa225cbcSrjs * Authors: 35fa225cbcSrjs * Keith Whitwell <keith@tungstengraphics.com> 36fa225cbcSrjs * 37fa225cbcSrjs * Add ARGB HW cursor support: 38fa225cbcSrjs * Alan Hourihane <alanh@tungstengraphics.com> 39fa225cbcSrjs * 40fa225cbcSrjs */ 41fa225cbcSrjs 42fa225cbcSrjs#include "xf86.h" 43fa225cbcSrjs#include "xf86_OSproc.h" 44fa225cbcSrjs#include "compiler.h" 45fa225cbcSrjs 46fa225cbcSrjs#include "xf86fbman.h" 47fa225cbcSrjs 48fa225cbcSrjs#include "i810.h" 49fa225cbcSrjs 50fa225cbcSrjsstatic Bool I810UseHWCursorARGB(ScreenPtr pScreen, CursorPtr pCurs); 51fa225cbcSrjsstatic void I810LoadCursorARGB(ScrnInfoPtr pScrn, CursorPtr pCurs); 52fa225cbcSrjsstatic void I810LoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src); 53fa225cbcSrjsstatic void I810ShowCursor(ScrnInfoPtr pScrn); 54fa225cbcSrjsstatic void I810HideCursor(ScrnInfoPtr pScrn); 55fa225cbcSrjsstatic void I810SetCursorColors(ScrnInfoPtr pScrn, int bg, int fb); 56fa225cbcSrjsstatic void I810SetCursorPosition(ScrnInfoPtr pScrn, int x, int y); 57fa225cbcSrjsstatic Bool I810UseHWCursor(ScreenPtr pScrn, CursorPtr pCurs); 58fa225cbcSrjs 59fa225cbcSrjsBool 60fa225cbcSrjsI810CursorInit(ScreenPtr pScreen) 61fa225cbcSrjs{ 62fa225cbcSrjs ScrnInfoPtr pScrn; 63fa225cbcSrjs I810Ptr pI810; 64fa225cbcSrjs xf86CursorInfoPtr infoPtr; 65fa225cbcSrjs 66fa225cbcSrjs pScrn = xf86Screens[pScreen->myNum]; 67fa225cbcSrjs pI810 = I810PTR(pScrn); 68fa225cbcSrjs pI810->CursorInfoRec = infoPtr = xf86CreateCursorInfoRec(); 69fa225cbcSrjs if (!infoPtr) 70fa225cbcSrjs return FALSE; 71fa225cbcSrjs 72fa225cbcSrjs infoPtr->MaxWidth = 64; 73fa225cbcSrjs infoPtr->MaxHeight = 64; 74fa225cbcSrjs infoPtr->Flags = (HARDWARE_CURSOR_TRUECOLOR_AT_8BPP | 75fa225cbcSrjs HARDWARE_CURSOR_BIT_ORDER_MSBFIRST | 76fa225cbcSrjs HARDWARE_CURSOR_INVERT_MASK | 77fa225cbcSrjs HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK | 78fa225cbcSrjs HARDWARE_CURSOR_AND_SOURCE_WITH_MASK | 79fa225cbcSrjs HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 | 0); 80fa225cbcSrjs 81fa225cbcSrjs infoPtr->SetCursorColors = I810SetCursorColors; 82fa225cbcSrjs infoPtr->SetCursorPosition = I810SetCursorPosition; 83fa225cbcSrjs infoPtr->LoadCursorImage = I810LoadCursorImage; 84fa225cbcSrjs infoPtr->HideCursor = I810HideCursor; 85fa225cbcSrjs infoPtr->ShowCursor = I810ShowCursor; 86fa225cbcSrjs infoPtr->UseHWCursor = I810UseHWCursor; 87fa225cbcSrjs#ifdef ARGB_CURSOR 88fa225cbcSrjs pI810->CursorIsARGB = FALSE; 89fa225cbcSrjs 90fa225cbcSrjs if (!pI810->CursorARGBPhysical) { 91fa225cbcSrjs infoPtr->UseHWCursorARGB = I810UseHWCursorARGB; 92fa225cbcSrjs infoPtr->LoadCursorARGB = I810LoadCursorARGB; 93fa225cbcSrjs } 94fa225cbcSrjs#endif 95fa225cbcSrjs 96fa225cbcSrjs return xf86InitCursor(pScreen, infoPtr); 97fa225cbcSrjs} 98fa225cbcSrjs 99fa225cbcSrjs#ifdef ARGB_CURSOR 100fa225cbcSrjs#include "cursorstr.h" 101fa225cbcSrjs 102fa225cbcSrjsstatic Bool I810UseHWCursorARGB (ScreenPtr pScreen, CursorPtr pCurs) 103fa225cbcSrjs{ 104fa225cbcSrjs ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 105fa225cbcSrjs I810Ptr pI810 = I810PTR(pScrn); 106fa225cbcSrjs 107fa225cbcSrjs if (!pI810->CursorARGBPhysical) 108fa225cbcSrjs return FALSE; 109fa225cbcSrjs 110fa225cbcSrjs if (pCurs->bits->height <= 64 && pCurs->bits->width <= 64) 111fa225cbcSrjs return TRUE; 112fa225cbcSrjs 113fa225cbcSrjs return FALSE; 114fa225cbcSrjs} 115fa225cbcSrjs 116fa225cbcSrjsstatic void I810LoadCursorARGB (ScrnInfoPtr pScrn, CursorPtr pCurs) 117fa225cbcSrjs{ 118fa225cbcSrjs I810Ptr pI810 = I810PTR(pScrn); 119fa225cbcSrjs uint32_t *pcurs = (uint32_t *) (pI810->FbBase + pI810->CursorStart); 120fa225cbcSrjs uint32_t *image = (uint32_t *) pCurs->bits->argb; 121fa225cbcSrjs int x, y, w, h; 122fa225cbcSrjs 123fa225cbcSrjs#ifdef ARGB_CURSOR 124fa225cbcSrjs pI810->CursorIsARGB = TRUE; 125fa225cbcSrjs#endif 126fa225cbcSrjs 127fa225cbcSrjs w = pCurs->bits->width; 128fa225cbcSrjs h = pCurs->bits->height; 129fa225cbcSrjs 130fa225cbcSrjs for (y = 0; y < h; y++) 131fa225cbcSrjs { 132fa225cbcSrjs for (x = 0; x < w; x++) 133fa225cbcSrjs *pcurs++ = *image++; 134fa225cbcSrjs for (; x < 64; x++) 135fa225cbcSrjs *pcurs++ = 0; 136fa225cbcSrjs } 137fa225cbcSrjs 138fa225cbcSrjs for (; y < 64; y++) 139fa225cbcSrjs for (x = 0; x < 64; x++) 140fa225cbcSrjs *pcurs++ = 0; 141fa225cbcSrjs} 142fa225cbcSrjs#endif 143fa225cbcSrjs 144fa225cbcSrjsstatic Bool 145fa225cbcSrjsI810UseHWCursor(ScreenPtr pScreen, CursorPtr pCurs) 146fa225cbcSrjs{ 147fa225cbcSrjs ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 148fa225cbcSrjs I810Ptr pI810 = I810PTR(pScrn); 149fa225cbcSrjs 150fa225cbcSrjs if (!pI810->CursorPhysical) 151fa225cbcSrjs return FALSE; 152fa225cbcSrjs else 153fa225cbcSrjs return TRUE; 154fa225cbcSrjs} 155fa225cbcSrjs 156fa225cbcSrjsstatic void 157fa225cbcSrjsI810LoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src) 158fa225cbcSrjs{ 159fa225cbcSrjs I810Ptr pI810 = I810PTR(pScrn); 160fa225cbcSrjs uint8_t *pcurs = (uint8_t *) (pI810->FbBase + pI810->CursorStart); 161fa225cbcSrjs int x, y; 162fa225cbcSrjs 163fa225cbcSrjs#ifdef ARGB_CURSOR 164fa225cbcSrjs pI810->CursorIsARGB = FALSE; 165fa225cbcSrjs#endif 166fa225cbcSrjs 167fa225cbcSrjs for (y = 0; y < 64; y++) { 168fa225cbcSrjs for (x = 0; x < 64 / 4; x++) { 169fa225cbcSrjs *pcurs++ = *src++; 170fa225cbcSrjs } 171fa225cbcSrjs } 172fa225cbcSrjs} 173fa225cbcSrjs 174fa225cbcSrjsstatic void 175fa225cbcSrjsI810SetCursorPosition(ScrnInfoPtr pScrn, int x, int y) 176fa225cbcSrjs{ 177fa225cbcSrjs I810Ptr pI810 = I810PTR(pScrn); 178fa225cbcSrjs int flag; 179fa225cbcSrjs 180fa225cbcSrjs x += pI810->CursorOffset; 181fa225cbcSrjs 182fa225cbcSrjs if (x >= 0) 183fa225cbcSrjs flag = CURSOR_X_POS; 184fa225cbcSrjs else { 185fa225cbcSrjs flag = CURSOR_X_NEG; 186fa225cbcSrjs x = -x; 187fa225cbcSrjs } 188fa225cbcSrjs 189fa225cbcSrjs OUTREG8(CURSOR_X_LO, x & 0xFF); 190fa225cbcSrjs OUTREG8(CURSOR_X_HI, (((x >> 8) & 0x07) | flag)); 191fa225cbcSrjs 192fa225cbcSrjs if (y >= 0) 193fa225cbcSrjs flag = CURSOR_Y_POS; 194fa225cbcSrjs else { 195fa225cbcSrjs flag = CURSOR_Y_NEG; 196fa225cbcSrjs y = -y; 197fa225cbcSrjs } 198fa225cbcSrjs OUTREG8(CURSOR_Y_LO, y & 0xFF); 199fa225cbcSrjs OUTREG8(CURSOR_Y_HI, (((y >> 8) & 0x07) | flag)); 200fa225cbcSrjs 201fa225cbcSrjs if (pI810->CursorIsARGB) 202fa225cbcSrjs OUTREG(CURSOR_BASEADDR, pI810->CursorARGBPhysical); 203fa225cbcSrjs else 204fa225cbcSrjs OUTREG(CURSOR_BASEADDR, pI810->CursorPhysical); 205fa225cbcSrjs} 206fa225cbcSrjs 207fa225cbcSrjsstatic void 208fa225cbcSrjsI810ShowCursor(ScrnInfoPtr pScrn) 209fa225cbcSrjs{ 210fa225cbcSrjs I810Ptr pI810 = I810PTR(pScrn); 211fa225cbcSrjs unsigned char tmp; 212fa225cbcSrjs 213fa225cbcSrjs if (pI810->CursorIsARGB) { 214fa225cbcSrjs OUTREG(CURSOR_BASEADDR, pI810->CursorARGBPhysical); 215fa225cbcSrjs OUTREG8(CURSOR_CONTROL, CURSOR_ORIGIN_DISPLAY | CURSOR_MODE_64_ARGB_AX); 216fa225cbcSrjs } else { 217fa225cbcSrjs OUTREG(CURSOR_BASEADDR, pI810->CursorPhysical); 218fa225cbcSrjs OUTREG8(CURSOR_CONTROL, CURSOR_ORIGIN_DISPLAY | CURSOR_MODE_64_3C); 219fa225cbcSrjs } 220fa225cbcSrjs 221fa225cbcSrjs tmp = INREG8(PIXPIPE_CONFIG_0); 222fa225cbcSrjs tmp |= HW_CURSOR_ENABLE; 223fa225cbcSrjs OUTREG8(PIXPIPE_CONFIG_0, tmp); 224fa225cbcSrjs} 225fa225cbcSrjs 226fa225cbcSrjsstatic void 227fa225cbcSrjsI810HideCursor(ScrnInfoPtr pScrn) 228fa225cbcSrjs{ 229fa225cbcSrjs unsigned char tmp; 230fa225cbcSrjs I810Ptr pI810 = I810PTR(pScrn); 231fa225cbcSrjs 232fa225cbcSrjs tmp = INREG8(PIXPIPE_CONFIG_0); 233fa225cbcSrjs tmp &= ~HW_CURSOR_ENABLE; 234fa225cbcSrjs OUTREG8(PIXPIPE_CONFIG_0, tmp); 235fa225cbcSrjs} 236fa225cbcSrjs 237fa225cbcSrjsstatic void 238fa225cbcSrjsI810SetCursorColors(ScrnInfoPtr pScrn, int bg, int fg) 239fa225cbcSrjs{ 240fa225cbcSrjs int tmp; 241fa225cbcSrjs I810Ptr pI810 = I810PTR(pScrn); 242fa225cbcSrjs 243fa225cbcSrjs#ifdef ARGB_CURSOR 244fa225cbcSrjs if (pI810->CursorIsARGB) 245fa225cbcSrjs return; 246fa225cbcSrjs#endif 247fa225cbcSrjs 248fa225cbcSrjs tmp = INREG8(PIXPIPE_CONFIG_0); 249fa225cbcSrjs tmp |= EXTENDED_PALETTE; 250fa225cbcSrjs OUTREG8(PIXPIPE_CONFIG_0, tmp); 251fa225cbcSrjs 252fa225cbcSrjs pI810->writeStandard(pI810, DACMASK, 0xFF); 253fa225cbcSrjs pI810->writeStandard(pI810, DACWX, 0x04); 254fa225cbcSrjs 255fa225cbcSrjs pI810->writeStandard(pI810, DACDATA, (bg & 0x00FF0000) >> 16); 256fa225cbcSrjs pI810->writeStandard(pI810, DACDATA, (bg & 0x0000FF00) >> 8); 257fa225cbcSrjs pI810->writeStandard(pI810, DACDATA, (bg & 0x000000FF)); 258fa225cbcSrjs 259fa225cbcSrjs pI810->writeStandard(pI810, DACDATA, (fg & 0x00FF0000) >> 16); 260fa225cbcSrjs pI810->writeStandard(pI810, DACDATA, (fg & 0x0000FF00) >> 8); 261fa225cbcSrjs pI810->writeStandard(pI810, DACDATA, (fg & 0x000000FF)); 262fa225cbcSrjs 263fa225cbcSrjs tmp = INREG8(PIXPIPE_CONFIG_0); 264fa225cbcSrjs tmp &= ~EXTENDED_PALETTE; 265fa225cbcSrjs OUTREG8(PIXPIPE_CONFIG_0, tmp); 266fa225cbcSrjs} 267