1706f2543Smrg/* 2706f2543Smrg * Copyright © 2006 Keith Packard 3706f2543Smrg * 4706f2543Smrg * Permission to use, copy, modify, distribute, and sell this software and its 5706f2543Smrg * documentation for any purpose is hereby granted without fee, provided that 6706f2543Smrg * the above copyright notice appear in all copies and that both that copyright 7706f2543Smrg * notice and this permission notice appear in supporting documentation, and 8706f2543Smrg * that the name of the copyright holders not be used in advertising or 9706f2543Smrg * publicity pertaining to distribution of the software without specific, 10706f2543Smrg * written prior permission. The copyright holders make no representations 11706f2543Smrg * about the suitability of this software for any purpose. It is provided "as 12706f2543Smrg * is" without express or implied warranty. 13706f2543Smrg * 14706f2543Smrg * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 15706f2543Smrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 16706f2543Smrg * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 17706f2543Smrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 18706f2543Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 19706f2543Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 20706f2543Smrg * OF THIS SOFTWARE. 21706f2543Smrg */ 22706f2543Smrg 23706f2543Smrg#ifdef HAVE_XORG_CONFIG_H 24706f2543Smrg#include <xorg-config.h> 25706f2543Smrg#else 26706f2543Smrg#ifdef HAVE_CONFIG_H 27706f2543Smrg#include <config.h> 28706f2543Smrg#endif 29706f2543Smrg#endif 30706f2543Smrg 31706f2543Smrg#include "xf86.h" 32706f2543Smrg#include "xf86DDC.h" 33706f2543Smrg#include "xf86_OSproc.h" 34706f2543Smrg#include "dgaproc.h" 35706f2543Smrg#include "xf86Crtc.h" 36706f2543Smrg#include "xf86Modes.h" 37706f2543Smrg#include "gcstruct.h" 38706f2543Smrg#include "scrnintstr.h" 39706f2543Smrg#include "windowstr.h" 40706f2543Smrg 41706f2543Smrgstatic Bool 42706f2543Smrgxf86_dga_get_modes (ScreenPtr pScreen) 43706f2543Smrg{ 44706f2543Smrg ScrnInfoPtr scrn = xf86Screens[pScreen->myNum]; 45706f2543Smrg xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); 46706f2543Smrg DGAModePtr modes, mode; 47706f2543Smrg DisplayModePtr display_mode; 48706f2543Smrg int bpp = scrn->bitsPerPixel >> 3; 49706f2543Smrg int num; 50706f2543Smrg 51706f2543Smrg num = 0; 52706f2543Smrg display_mode = scrn->modes; 53706f2543Smrg while (display_mode) 54706f2543Smrg { 55706f2543Smrg num++; 56706f2543Smrg display_mode = display_mode->next; 57706f2543Smrg if (display_mode == scrn->modes) 58706f2543Smrg break; 59706f2543Smrg } 60706f2543Smrg 61706f2543Smrg if (!num) 62706f2543Smrg return FALSE; 63706f2543Smrg 64706f2543Smrg modes = malloc(num * sizeof(DGAModeRec)); 65706f2543Smrg if (!modes) 66706f2543Smrg return FALSE; 67706f2543Smrg 68706f2543Smrg num = 0; 69706f2543Smrg display_mode = scrn->modes; 70706f2543Smrg while (display_mode) 71706f2543Smrg { 72706f2543Smrg mode = modes + num++; 73706f2543Smrg 74706f2543Smrg mode->mode = display_mode; 75706f2543Smrg mode->flags = DGA_CONCURRENT_ACCESS; 76706f2543Smrg if (display_mode->Flags & V_DBLSCAN) 77706f2543Smrg mode->flags |= DGA_DOUBLESCAN; 78706f2543Smrg if (display_mode->Flags & V_INTERLACE) 79706f2543Smrg mode->flags |= DGA_INTERLACED; 80706f2543Smrg mode->byteOrder = scrn->imageByteOrder; 81706f2543Smrg mode->depth = scrn->depth; 82706f2543Smrg mode->bitsPerPixel = scrn->bitsPerPixel; 83706f2543Smrg mode->red_mask = scrn->mask.red; 84706f2543Smrg mode->green_mask = scrn->mask.green; 85706f2543Smrg mode->blue_mask = scrn->mask.blue; 86706f2543Smrg mode->visualClass = (bpp == 1) ? PseudoColor : TrueColor; 87706f2543Smrg mode->viewportWidth = display_mode->HDisplay; 88706f2543Smrg mode->viewportHeight = display_mode->VDisplay; 89706f2543Smrg mode->xViewportStep = (bpp == 3) ? 2 : 1; 90706f2543Smrg mode->yViewportStep = 1; 91706f2543Smrg mode->viewportFlags = DGA_FLIP_RETRACE; 92706f2543Smrg mode->offset = 0; 93706f2543Smrg mode->address = 0; 94706f2543Smrg mode->imageWidth = mode->viewportWidth; 95706f2543Smrg mode->imageHeight = mode->viewportHeight; 96706f2543Smrg mode->bytesPerScanline = (mode->imageWidth * scrn->bitsPerPixel) >> 3; 97706f2543Smrg mode->pixmapWidth = mode->imageWidth; 98706f2543Smrg mode->pixmapHeight = mode->imageHeight; 99706f2543Smrg mode->maxViewportX = 0; 100706f2543Smrg mode->maxViewportY = 0; 101706f2543Smrg 102706f2543Smrg display_mode = display_mode->next; 103706f2543Smrg if (display_mode == scrn->modes) 104706f2543Smrg break; 105706f2543Smrg } 106706f2543Smrg free(xf86_config->dga_modes); 107706f2543Smrg xf86_config->dga_nmode = num; 108706f2543Smrg xf86_config->dga_modes = modes; 109706f2543Smrg return TRUE; 110706f2543Smrg} 111706f2543Smrg 112706f2543Smrgstatic Bool 113706f2543Smrgxf86_dga_set_mode(ScrnInfoPtr scrn, DGAModePtr display_mode) 114706f2543Smrg{ 115706f2543Smrg ScreenPtr pScreen = scrn->pScreen; 116706f2543Smrg xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); 117706f2543Smrg 118706f2543Smrg if (!display_mode) 119706f2543Smrg { 120706f2543Smrg if (xf86_config->dga_save_mode) 121706f2543Smrg { 122706f2543Smrg xf86SwitchMode(pScreen, xf86_config->dga_save_mode); 123706f2543Smrg xf86_config->dga_save_mode = NULL; 124706f2543Smrg } 125706f2543Smrg } 126706f2543Smrg else 127706f2543Smrg { 128706f2543Smrg if (!xf86_config->dga_save_mode) 129706f2543Smrg { 130706f2543Smrg xf86_config->dga_save_mode = scrn->currentMode; 131706f2543Smrg xf86SwitchMode(pScreen, display_mode->mode); 132706f2543Smrg } 133706f2543Smrg } 134706f2543Smrg return TRUE; 135706f2543Smrg} 136706f2543Smrg 137706f2543Smrgstatic int 138706f2543Smrgxf86_dga_get_viewport(ScrnInfoPtr scrn) 139706f2543Smrg{ 140706f2543Smrg return 0; 141706f2543Smrg} 142706f2543Smrg 143706f2543Smrgstatic void 144706f2543Smrgxf86_dga_set_viewport(ScrnInfoPtr scrn, int x, int y, int flags) 145706f2543Smrg{ 146706f2543Smrg scrn->AdjustFrame(scrn->pScreen->myNum, x, y, flags); 147706f2543Smrg} 148706f2543Smrg 149706f2543Smrgstatic Bool 150706f2543Smrgxf86_dga_open_framebuffer(ScrnInfoPtr scrn, 151706f2543Smrg char **name, 152706f2543Smrg unsigned char **mem, int *size, int *offset, int *flags) 153706f2543Smrg{ 154706f2543Smrg return FALSE; 155706f2543Smrg} 156706f2543Smrg 157706f2543Smrgstatic void 158706f2543Smrgxf86_dga_close_framebuffer(ScrnInfoPtr scrn) 159706f2543Smrg{ 160706f2543Smrg} 161706f2543Smrg 162706f2543Smrgstatic DGAFunctionRec xf86_dga_funcs = { 163706f2543Smrg xf86_dga_open_framebuffer, 164706f2543Smrg xf86_dga_close_framebuffer, 165706f2543Smrg xf86_dga_set_mode, 166706f2543Smrg xf86_dga_set_viewport, 167706f2543Smrg xf86_dga_get_viewport, 168706f2543Smrg NULL, 169706f2543Smrg NULL, 170706f2543Smrg NULL, 171706f2543Smrg NULL 172706f2543Smrg}; 173706f2543Smrg 174706f2543SmrgBool 175706f2543Smrgxf86DiDGAReInit (ScreenPtr pScreen) 176706f2543Smrg{ 177706f2543Smrg return TRUE; 178706f2543Smrg} 179706f2543Smrg 180706f2543SmrgBool 181706f2543Smrg_xf86_di_dga_reinit_internal (ScreenPtr pScreen) 182706f2543Smrg{ 183706f2543Smrg ScrnInfoPtr scrn = xf86Screens[pScreen->myNum]; 184706f2543Smrg xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); 185706f2543Smrg 186706f2543Smrg if (!DGAAvailable(pScreen->myNum)) 187706f2543Smrg return TRUE; 188706f2543Smrg 189706f2543Smrg if (!xf86_dga_get_modes (pScreen)) 190706f2543Smrg return FALSE; 191706f2543Smrg 192706f2543Smrg return DGAReInitModes (pScreen, xf86_config->dga_modes, xf86_config->dga_nmode); 193706f2543Smrg} 194706f2543Smrg 195706f2543SmrgBool 196706f2543Smrgxf86DiDGAInit (ScreenPtr pScreen, unsigned long dga_address) 197706f2543Smrg{ 198706f2543Smrg return TRUE; 199706f2543Smrg} 200706f2543Smrg 201706f2543SmrgBool 202706f2543Smrg_xf86_di_dga_init_internal (ScreenPtr pScreen) 203706f2543Smrg{ 204706f2543Smrg ScrnInfoPtr scrn = xf86Screens[pScreen->myNum]; 205706f2543Smrg xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); 206706f2543Smrg 207706f2543Smrg xf86_config->dga_flags = 0; 208706f2543Smrg xf86_config->dga_address = 0; 209706f2543Smrg xf86_config->dga_width = 0; 210706f2543Smrg xf86_config->dga_height = 0; 211706f2543Smrg xf86_config->dga_stride = 0; 212706f2543Smrg 213706f2543Smrg if (!xf86_dga_get_modes (pScreen)) 214706f2543Smrg return FALSE; 215706f2543Smrg 216706f2543Smrg return DGAInit(pScreen, &xf86_dga_funcs, xf86_config->dga_modes, xf86_config->dga_nmode); 217706f2543Smrg} 218