1/* 2 * Copyright (c) 2007 NVIDIA, Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the 6 * "Software"), to deal in the Software without restriction, including 7 * without limitation the rights to use, copy, modify, merge, publish, 8 * distribute, sublicense, and/or sell copies of the Software, and to 9 * permit persons to whom the Software is furnished to do so, subject to 10 * the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included 13 * in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 24#ifdef HAVE_CONFIG_H 25#include "config.h" 26#endif 27 28#include <string.h> 29 30#include <cursorstr.h> 31 32#include "g80_type.h" 33#include "g80_cursor.h" 34#include "g80_display.h" 35 36#define CURSOR_PTR ((CARD32*)pNv->mem + pNv->videoRam * 256 - 0x1000) 37 38void G80SetCursorPosition(xf86CrtcPtr crtc, int x, int y) 39{ 40 G80Ptr pNv = G80PTR(crtc->scrn); 41 const int headOff = 0x1000*G80CrtcGetHead(crtc); 42 43 x &= 0xffff; 44 y &= 0xffff; 45 pNv->reg[(0x00647084 + headOff)/4] = y << 16 | x; 46 pNv->reg[(0x00647080 + headOff)/4] = 0; 47} 48 49void G80LoadCursorARGB(xf86CrtcPtr crtc, CARD32 *src) 50{ 51 G80Ptr pNv = G80PTR(crtc->scrn); 52 CARD32 *dst = CURSOR_PTR; 53 54 /* Assume cursor is 64x64 */ 55 memcpy(dst, src, 64 * 64 * 4); 56} 57 58Bool G80CursorAcquire(ScrnInfoPtr pScrn) 59{ 60 G80Ptr pNv = G80PTR(pScrn); 61 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); 62 int i; 63 64 if(!pNv->HWCursor) return TRUE; 65 66 /* Initialize the cursor on each head */ 67 for(i = 0; i < xf86_config->num_crtc; i++) { 68 const int headOff = 0x10 * G80CrtcGetHead(xf86_config->crtc[i]); 69 70 pNv->reg[(0x00610270+headOff)/4] = 0x2000; 71 while(pNv->reg[(0x00610270+headOff)/4] & 0x30000); 72 73 pNv->reg[(0x00610270+headOff)/4] = 1; 74 while((pNv->reg[(0x00610270+headOff)/4] & 0x30000) != 0x10000); 75 } 76 77 return TRUE; 78} 79 80void G80CursorRelease(ScrnInfoPtr pScrn) 81{ 82 G80Ptr pNv = G80PTR(pScrn); 83 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); 84 int i; 85 86 if(!pNv->HWCursor) return; 87 88 /* Release the cursor on each head */ 89 for(i = 0; i < xf86_config->num_crtc; i++) { 90 const int headOff = 0x10 * G80CrtcGetHead(xf86_config->crtc[i]); 91 92 pNv->reg[(0x00610270+headOff)/4] = 0; 93 while(pNv->reg[(0x00610270+headOff)/4] & 0x30000); 94 } 95} 96 97Bool G80CursorInit(ScreenPtr pScreen) 98{ 99 return xf86_cursors_init(pScreen, 64, 64, 100 HARDWARE_CURSOR_TRUECOLOR_AT_8BPP | 101 HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_32 | 102 HARDWARE_CURSOR_ARGB); 103} 104