igs_driver.c revision c59a3c9d
1be1ef3d3Smacallan/* $OpenBSD: wsfb_driver.c,v 1.19 2003/04/27 16:42:32 matthieu Exp $ */
2c59a3c9dSmrg/* $NetBSD: igs_driver.c,v 1.5 2010/11/24 02:54:08 mrg Exp $ */
3be1ef3d3Smacallan/*
4be1ef3d3Smacallan * Copyright (c) 2001 Matthieu Herrb
5be1ef3d3Smacallan *		 2009 Michael Lorenz
6be1ef3d3Smacallan * All rights reserved.
7be1ef3d3Smacallan *
8be1ef3d3Smacallan * Redistribution and use in source and binary forms, with or without
9be1ef3d3Smacallan * modification, are permitted provided that the following conditions
10be1ef3d3Smacallan * are met:
11be1ef3d3Smacallan *
12be1ef3d3Smacallan *    - Redistributions of source code must retain the above copyright
13be1ef3d3Smacallan *      notice, this list of conditions and the following disclaimer.
14be1ef3d3Smacallan *    - Redistributions in binary form must reproduce the above
15be1ef3d3Smacallan *      copyright notice, this list of conditions and the following
16be1ef3d3Smacallan *      disclaimer in the documentation and/or other materials provided
17be1ef3d3Smacallan *      with the distribution.
18be1ef3d3Smacallan *
19be1ef3d3Smacallan * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20be1ef3d3Smacallan * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21be1ef3d3Smacallan * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22be1ef3d3Smacallan * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23be1ef3d3Smacallan * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24be1ef3d3Smacallan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25be1ef3d3Smacallan * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26be1ef3d3Smacallan * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27be1ef3d3Smacallan * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28be1ef3d3Smacallan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29be1ef3d3Smacallan * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30be1ef3d3Smacallan * POSSIBILITY OF SUCH DAMAGE.
31be1ef3d3Smacallan *
32be1ef3d3Smacallan */
33be1ef3d3Smacallan
34be1ef3d3Smacallan/*
35be1ef3d3Smacallan * Based on fbdev.c written by:
36be1ef3d3Smacallan *
37be1ef3d3Smacallan * Authors:  Alan Hourihane, <alanh@fairlite.demon.co.uk>
38be1ef3d3Smacallan *	     Michel Dänzer, <michdaen@iiic.ethz.ch>
39be1ef3d3Smacallan */
40be1ef3d3Smacallan
41be1ef3d3Smacallan /*
42be1ef3d3Smacallan  * a driver for IGS CyberPro 2010 graphics controllers
43be1ef3d3Smacallan  * adapted from wsfb
44be1ef3d3Smacallan  */
45be1ef3d3Smacallan
46be1ef3d3Smacallan#ifdef HAVE_CONFIG_H
47be1ef3d3Smacallan#include "config.h"
48be1ef3d3Smacallan#endif
49be1ef3d3Smacallan
50be1ef3d3Smacallan#include <fcntl.h>
51be1ef3d3Smacallan#include <sys/types.h>
52be1ef3d3Smacallan#include <sys/time.h>
53be1ef3d3Smacallan#include <errno.h>
54be1ef3d3Smacallan#include <dev/wscons/wsconsio.h>
55be1ef3d3Smacallan
56be1ef3d3Smacallan/* all driver need this */
57be1ef3d3Smacallan#include "xf86.h"
58be1ef3d3Smacallan#include "xf86_OSproc.h"
59be1ef3d3Smacallan
60be1ef3d3Smacallan#include "mipointer.h"
61be1ef3d3Smacallan#include "mibstore.h"
62be1ef3d3Smacallan#include "micmap.h"
63be1ef3d3Smacallan#include "colormapst.h"
64be1ef3d3Smacallan#include "xf86cmap.h"
65be1ef3d3Smacallan#include "shadow.h"
66be1ef3d3Smacallan#include "dgaproc.h"
67be1ef3d3Smacallan
68be1ef3d3Smacallan/* Everything using inb/outb, etc needs "compiler.h" */
69be1ef3d3Smacallan#include "compiler.h"
70be1ef3d3Smacallan
71be1ef3d3Smacallan/* for visuals */
72be1ef3d3Smacallan#include "fb.h"
73be1ef3d3Smacallan
74c59a3c9dSmrg#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 7
75be1ef3d3Smacallan#include "xf86Resources.h"
76be1ef3d3Smacallan#include "xf86RAC.h"
7722b24a26Smrg#endif
78be1ef3d3Smacallan
79be1ef3d3Smacallan#ifdef XvExtension
80be1ef3d3Smacallan#include "xf86xv.h"
81be1ef3d3Smacallan#endif
82be1ef3d3Smacallan
83be1ef3d3Smacallan#include "igs.h"
84be1ef3d3Smacallan
85be1ef3d3Smacallan#include <sys/mman.h>
86be1ef3d3Smacallan
87c59a3c9dSmrg#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) > 6
881b41fcf5Smrg#define xf86LoaderReqSymLists(...) do {} while (0)
891b41fcf5Smrg#define LoaderRefSymLists(...) do {} while (0)
901b41fcf5Smrg#endif
911b41fcf5Smrg
92be1ef3d3Smacallan#define DEBUG 0
93be1ef3d3Smacallan
94be1ef3d3Smacallan#if DEBUG
95be1ef3d3Smacallan# define TRACE_ENTER(str)       ErrorF("igs: " str " %d\n",pScrn->scrnIndex)
96be1ef3d3Smacallan# define TRACE_EXIT(str)        ErrorF("igs: " str " done\n")
97be1ef3d3Smacallan# define TRACE(str)             ErrorF("igs trace: " str "\n")
98be1ef3d3Smacallan#else
99be1ef3d3Smacallan# define TRACE_ENTER(str)
100be1ef3d3Smacallan# define TRACE_EXIT(str)
101be1ef3d3Smacallan# define TRACE(str)
102be1ef3d3Smacallan#endif
103be1ef3d3Smacallan
104be1ef3d3Smacallan#define IGS_DEFAULT_DEV "/dev/ttyE0"
105be1ef3d3Smacallan
106be1ef3d3Smacallan/* Prototypes */
107be1ef3d3Smacallan#ifdef XFree86LOADER
108be1ef3d3Smacallanstatic pointer IgsSetup(pointer, pointer, int *, int *);
109be1ef3d3Smacallan#endif
110be1ef3d3Smacallanstatic Bool IgsGetRec(ScrnInfoPtr);
111be1ef3d3Smacallanstatic void IgsFreeRec(ScrnInfoPtr);
112be1ef3d3Smacallanstatic const OptionInfoRec * IgsAvailableOptions(int, int);
113be1ef3d3Smacallanstatic void IgsIdentify(int);
114be1ef3d3Smacallanstatic Bool IgsProbe(DriverPtr, int);
115be1ef3d3Smacallanstatic Bool IgsPreInit(ScrnInfoPtr, int);
116be1ef3d3Smacallanstatic Bool IgsScreenInit(int, ScreenPtr, int, char **);
117be1ef3d3Smacallanstatic Bool IgsCloseScreen(int, ScreenPtr);
118be1ef3d3Smacallanstatic void *IgsWindowLinear(ScreenPtr, CARD32, CARD32, int, CARD32 *,
119be1ef3d3Smacallan			      void *);
120be1ef3d3Smacallanstatic Bool IgsEnterVT(int, int);
121be1ef3d3Smacallanstatic void IgsLeaveVT(int, int);
122be1ef3d3Smacallanstatic Bool IgsSwitchMode(int, DisplayModePtr, int);
123be1ef3d3Smacallanstatic int IgsValidMode(int, DisplayModePtr, Bool, int);
124be1ef3d3Smacallanstatic void IgsLoadPalette(ScrnInfoPtr, int, int *, LOCO *, VisualPtr);
125be1ef3d3Smacallanstatic Bool IgsSaveScreen(ScreenPtr, int);
126be1ef3d3Smacallanstatic void IgsSave(ScrnInfoPtr);
127be1ef3d3Smacallanstatic void IgsRestore(ScrnInfoPtr);
128be1ef3d3Smacallan
129be1ef3d3Smacallan/* dga stuff */
130be1ef3d3Smacallan#ifdef XFreeXDGA
131be1ef3d3Smacallanstatic Bool IgsDGAOpenFramebuffer(ScrnInfoPtr, char **, unsigned char **,
132be1ef3d3Smacallan				   int *, int *, int *);
133be1ef3d3Smacallanstatic Bool IgsDGASetMode(ScrnInfoPtr, DGAModePtr);
134be1ef3d3Smacallanstatic void IgsDGASetViewport(ScrnInfoPtr, int, int, int);
135be1ef3d3Smacallanstatic Bool IgsDGAInit(ScrnInfoPtr, ScreenPtr);
136be1ef3d3Smacallan#endif
137be1ef3d3Smacallanstatic Bool IgsDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op,
138be1ef3d3Smacallan				pointer ptr);
139be1ef3d3Smacallan
140be1ef3d3Smacallan/* helper functions */
141be1ef3d3Smacallanstatic pointer igs_mmap(size_t, off_t, int);
142be1ef3d3Smacallan
143be1ef3d3Smacallan/*
144be1ef3d3Smacallan * This is intentionally screen-independent.  It indicates the binding
145be1ef3d3Smacallan * choice made in the first PreInit.
146be1ef3d3Smacallan */
147be1ef3d3Smacallanstatic int pix24bpp = 0;
148be1ef3d3Smacallan
149be1ef3d3Smacallan#define IGS_VERSION 		4000
150be1ef3d3Smacallan#define IGS_NAME		"igs"
151be1ef3d3Smacallan#define IGS_DRIVER_NAME	"igs"
152be1ef3d3Smacallan
153be1ef3d3Smacallan_X_EXPORT DriverRec IGS = {
154be1ef3d3Smacallan	IGS_VERSION,
155be1ef3d3Smacallan	IGS_DRIVER_NAME,
156be1ef3d3Smacallan	IgsIdentify,
157be1ef3d3Smacallan	IgsProbe,
158be1ef3d3Smacallan	IgsAvailableOptions,
159be1ef3d3Smacallan	NULL,
160be1ef3d3Smacallan	0,
161be1ef3d3Smacallan	IgsDriverFunc
162be1ef3d3Smacallan};
163be1ef3d3Smacallan
164be1ef3d3Smacallan/* Supported "chipsets" */
165be1ef3d3Smacallanstatic SymTabRec IgsChipsets[] = {
166be1ef3d3Smacallan	{ 0, "CyberPro 2010" },
167be1ef3d3Smacallan	{ -1, NULL }
168be1ef3d3Smacallan};
169be1ef3d3Smacallan
170be1ef3d3Smacallan/* Supported options */
171be1ef3d3Smacallantypedef enum {
172be1ef3d3Smacallan	OPTION_NOACCEL,
173be1ef3d3Smacallan	OPTION_HW_CURSOR,
174be1ef3d3Smacallan	OPTION_SW_CURSOR
175be1ef3d3Smacallan} IgsOpts;
176be1ef3d3Smacallan
177be1ef3d3Smacallanstatic const OptionInfoRec IgsOptions[] = {
178be1ef3d3Smacallan	{ OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE},
179be1ef3d3Smacallan	{ -1, NULL, OPTV_NONE, {0}, FALSE}
180be1ef3d3Smacallan};
181be1ef3d3Smacallan
182be1ef3d3Smacallan/* Symbols needed from other modules */
183be1ef3d3Smacallanstatic const char *fbSymbols[] = {
184be1ef3d3Smacallan	"fbPictureInit",
185be1ef3d3Smacallan	"fbScreenInit",
186be1ef3d3Smacallan	NULL
187be1ef3d3Smacallan};
188be1ef3d3Smacallanstatic const char *shadowSymbols[] = {
189be1ef3d3Smacallan	"shadowAdd",
190be1ef3d3Smacallan	"shadowSetup",
191be1ef3d3Smacallan	"shadowUpdatePacked",
192be1ef3d3Smacallan	"shadowUpdatePackedWeak",
193be1ef3d3Smacallan	"shadowUpdateRotatePacked",
194be1ef3d3Smacallan	"shadowUpdateRotatePackedWeak",
195be1ef3d3Smacallan	NULL
196be1ef3d3Smacallan};
197be1ef3d3Smacallan
198be1ef3d3Smacallanstatic const char *ramdacSymbols[] = {
199be1ef3d3Smacallan	"xf86CreateCursorInfoRec",
200be1ef3d3Smacallan	"xf86DestroyCursorInfoRec",
201be1ef3d3Smacallan	"xf86InitCursor",
202be1ef3d3Smacallan	NULL
203be1ef3d3Smacallan};
204be1ef3d3Smacallan
205be1ef3d3Smacallan#ifdef XFree86LOADER
206be1ef3d3Smacallanstatic XF86ModuleVersionInfo IgsVersRec = {
207be1ef3d3Smacallan	"igs",
208be1ef3d3Smacallan	MODULEVENDORSTRING,
209be1ef3d3Smacallan	MODINFOSTRING1,
210be1ef3d3Smacallan	MODINFOSTRING2,
211be1ef3d3Smacallan	XORG_VERSION_CURRENT,
212be1ef3d3Smacallan	PACKAGE_VERSION_MAJOR,
213be1ef3d3Smacallan	PACKAGE_VERSION_MINOR,
214be1ef3d3Smacallan	PACKAGE_VERSION_PATCHLEVEL,
215be1ef3d3Smacallan	ABI_CLASS_VIDEODRV,
216be1ef3d3Smacallan	ABI_VIDEODRV_VERSION,
217be1ef3d3Smacallan	NULL,
218be1ef3d3Smacallan	{0, 0, 0, 0}
219be1ef3d3Smacallan};
220be1ef3d3Smacallan
221be1ef3d3Smacallan_X_EXPORT XF86ModuleData igsModuleData = { &IgsVersRec, IgsSetup, NULL };
222be1ef3d3Smacallan
223be1ef3d3Smacallanstatic pointer
224be1ef3d3SmacallanIgsSetup(pointer module, pointer opts, int *errmaj, int *errmin)
225be1ef3d3Smacallan{
226be1ef3d3Smacallan	static Bool setupDone = FALSE;
227be1ef3d3Smacallan	const char *osname;
228be1ef3d3Smacallan
229be1ef3d3Smacallan	/* Check that we're being loaded on a OpenBSD or NetBSD system */
230be1ef3d3Smacallan	LoaderGetOS(&osname, NULL, NULL, NULL);
231be1ef3d3Smacallan	if (!osname || (strcmp(osname, "openbsd") != 0 &&
232be1ef3d3Smacallan	                strcmp(osname, "netbsd") != 0)) {
233be1ef3d3Smacallan		if (errmaj)
234be1ef3d3Smacallan			*errmaj = LDR_BADOS;
235be1ef3d3Smacallan		if (errmin)
236be1ef3d3Smacallan			*errmin = 0;
237be1ef3d3Smacallan		return NULL;
238be1ef3d3Smacallan	}
239be1ef3d3Smacallan	if (!setupDone) {
240be1ef3d3Smacallan		setupDone = TRUE;
241be1ef3d3Smacallan		xf86AddDriver(&IGS, module, HaveDriverFuncs);
242be1ef3d3Smacallan		LoaderRefSymLists(fbSymbols, shadowSymbols, ramdacSymbols,
243be1ef3d3Smacallan		    NULL);
244be1ef3d3Smacallan		return (pointer)1;
245be1ef3d3Smacallan	} else {
246be1ef3d3Smacallan		if (errmaj != NULL)
247be1ef3d3Smacallan			*errmaj = LDR_ONCEONLY;
248be1ef3d3Smacallan		return NULL;
249be1ef3d3Smacallan	}
250be1ef3d3Smacallan}
251be1ef3d3Smacallan#endif /* XFree86LOADER */
252be1ef3d3Smacallan
253be1ef3d3Smacallanstatic Bool
254be1ef3d3SmacallanIgsGetRec(ScrnInfoPtr pScrn)
255be1ef3d3Smacallan{
256be1ef3d3Smacallan
257be1ef3d3Smacallan	if (pScrn->driverPrivate != NULL)
258be1ef3d3Smacallan		return TRUE;
259be1ef3d3Smacallan
260be1ef3d3Smacallan	pScrn->driverPrivate = xnfcalloc(sizeof(IgsRec), 1);
261be1ef3d3Smacallan	return TRUE;
262be1ef3d3Smacallan}
263be1ef3d3Smacallan
264be1ef3d3Smacallanstatic void
265be1ef3d3SmacallanIgsFreeRec(ScrnInfoPtr pScrn)
266be1ef3d3Smacallan{
267be1ef3d3Smacallan
268be1ef3d3Smacallan	if (pScrn->driverPrivate == NULL)
269be1ef3d3Smacallan		return;
270be1ef3d3Smacallan	xfree(pScrn->driverPrivate);
271be1ef3d3Smacallan	pScrn->driverPrivate = NULL;
272be1ef3d3Smacallan}
273be1ef3d3Smacallan
274be1ef3d3Smacallanstatic const OptionInfoRec *
275be1ef3d3SmacallanIgsAvailableOptions(int chipid, int busid)
276be1ef3d3Smacallan{
277be1ef3d3Smacallan	return IgsOptions;
278be1ef3d3Smacallan}
279be1ef3d3Smacallan
280be1ef3d3Smacallanstatic void
281be1ef3d3SmacallanIgsIdentify(int flags)
282be1ef3d3Smacallan{
283be1ef3d3Smacallan	xf86PrintChipsets(IGS_NAME, "driver for IGS CyberPro 2010",
284be1ef3d3Smacallan			  IgsChipsets);
285be1ef3d3Smacallan}
286be1ef3d3Smacallan
287be1ef3d3Smacallan#define priv_open_device(n)	open(n,O_RDWR|O_NONBLOCK|O_EXCL)
288be1ef3d3Smacallan
289be1ef3d3Smacallan/* Open the framebuffer device */
290be1ef3d3Smacallanstatic int
291be1ef3d3Smacallanigs_open(char *dev)
292be1ef3d3Smacallan{
293be1ef3d3Smacallan	int fd = -1;
294be1ef3d3Smacallan
295be1ef3d3Smacallan	/* try argument from XF86Config first */
296be1ef3d3Smacallan	if (dev == NULL || ((fd = priv_open_device(dev)) == -1)) {
297be1ef3d3Smacallan		/* second: environment variable */
298be1ef3d3Smacallan		dev = getenv("XDEVICE");
299be1ef3d3Smacallan		if (dev == NULL || ((fd = priv_open_device(dev)) == -1)) {
300be1ef3d3Smacallan			/* last try: default device */
301be1ef3d3Smacallan			dev = IGS_DEFAULT_DEV;
302be1ef3d3Smacallan			if ((fd = priv_open_device(dev)) == -1) {
303be1ef3d3Smacallan				return -1;
304be1ef3d3Smacallan			}
305be1ef3d3Smacallan		}
306be1ef3d3Smacallan	}
307be1ef3d3Smacallan	return fd;
308be1ef3d3Smacallan}
309be1ef3d3Smacallan/* Map the framebuffer's memory */
310be1ef3d3Smacallanstatic pointer
311be1ef3d3Smacallanigs_mmap(size_t len, off_t off, int fd)
312be1ef3d3Smacallan{
313be1ef3d3Smacallan	int pagemask, mapsize;
314be1ef3d3Smacallan	caddr_t addr;
315be1ef3d3Smacallan	pointer mapaddr;
316be1ef3d3Smacallan
317be1ef3d3Smacallan	pagemask = getpagesize() - 1;
318be1ef3d3Smacallan	mapsize = ((int) len + pagemask) & ~pagemask;
319be1ef3d3Smacallan	addr = 0;
320be1ef3d3Smacallan
321be1ef3d3Smacallan	/*
322be1ef3d3Smacallan	 * try and make it private first, that way once we get it, an
323be1ef3d3Smacallan	 * interloper, e.g. another server, can't get this frame buffer,
324be1ef3d3Smacallan	 * and if another server already has it, this one won't.
325be1ef3d3Smacallan	 */
326be1ef3d3Smacallan	mapaddr = (pointer) mmap(addr, mapsize,
327be1ef3d3Smacallan				 PROT_READ | PROT_WRITE, MAP_SHARED,
328be1ef3d3Smacallan				 fd, off);
329be1ef3d3Smacallan	if (mapaddr == MAP_FAILED) {
330be1ef3d3Smacallan		mapaddr = NULL;
331be1ef3d3Smacallan	}
332be1ef3d3Smacallan#if DEBUG
333be1ef3d3Smacallan	ErrorF("mmap returns: addr %p len 0x%x\n", mapaddr, mapsize);
334be1ef3d3Smacallan#endif
335be1ef3d3Smacallan	return mapaddr;
336be1ef3d3Smacallan}
337be1ef3d3Smacallan
338be1ef3d3Smacallanstatic int
339be1ef3d3SmacallanigsFindIsaDevice(GDevPtr dev)
340be1ef3d3Smacallan{
341be1ef3d3Smacallan	int found = -1;
342be1ef3d3Smacallan	uint8_t id0, id1, rev;
343be1ef3d3Smacallan
344be1ef3d3Smacallan	/* read chip ID from extended VGA registers */
345be1ef3d3Smacallan	id0 = igs_ext_read(IGS_EXT_CHIP_ID0);
346be1ef3d3Smacallan	id1 = igs_ext_read(IGS_EXT_CHIP_ID1);
347be1ef3d3Smacallan	rev = igs_ext_read(IGS_EXT_CHIP_REV);
348be1ef3d3Smacallan	xf86Msg(X_ERROR, "%s: %x %x %x\n", __func__, id0, id1, rev);
349be1ef3d3Smacallan	if ((id0 == 0xa4) && (id1 == 8))
350be1ef3d3Smacallan		found = 0;
351be1ef3d3Smacallan	return found;
352be1ef3d3Smacallan}
353be1ef3d3Smacallan
354be1ef3d3Smacallanstatic Bool
355be1ef3d3SmacallanIgsProbe(DriverPtr drv, int flags)
356be1ef3d3Smacallan{
357be1ef3d3Smacallan    ScrnInfoPtr pScrn = NULL;
358be1ef3d3Smacallan    IgsPtr cPtr;
359be1ef3d3Smacallan    Bool foundScreen = FALSE;
360be1ef3d3Smacallan    int numDevSections, numUsed;
361be1ef3d3Smacallan    GDevPtr *devSections;
362be1ef3d3Smacallan    int *usedChips;
363be1ef3d3Smacallan    int i, chipset, entity;
364be1ef3d3Smacallan
365be1ef3d3Smacallan    /*
366be1ef3d3Smacallan     * Find the config file Device sections that match this
367be1ef3d3Smacallan     * driver, and return if there are none.
368be1ef3d3Smacallan     */
369be1ef3d3Smacallan    if ((numDevSections = xf86MatchDevice(IGS_DRIVER_NAME,
370be1ef3d3Smacallan					  &devSections)) <= 0) {
371be1ef3d3Smacallan	return FALSE;
372be1ef3d3Smacallan    }
373be1ef3d3Smacallan
374be1ef3d3Smacallan    /* Isa Bus */
375be1ef3d3Smacallan    if ((numDevSections =
376be1ef3d3Smacallan      xf86MatchDevice(IGS_DRIVER_NAME, &devSections)) > 0) {
377be1ef3d3Smacallan	for (i = 0; i < numDevSections; i++) {
378be1ef3d3Smacallan	    if ((chipset = igsFindIsaDevice(devSections[i])) > -1) {
379be1ef3d3Smacallan		if ( xf86DoConfigure && xf86DoConfigurePass1 ) {
380be1ef3d3Smacallan		    xf86AddBusDeviceToConfigure(IGS_DRIVER_NAME, BUS_ISA,
381be1ef3d3Smacallan			  NULL, chipset);
382be1ef3d3Smacallan		}
383be1ef3d3Smacallan		if (flags & PROBE_DETECT) {
384be1ef3d3Smacallan		    return TRUE;
385be1ef3d3Smacallan		}
386be1ef3d3Smacallan		if (!xf86CheckStrOption(devSections[i]->options, "BusID",
387be1ef3d3Smacallan		  "ISA")) {
388be1ef3d3Smacallan		    continue;
389be1ef3d3Smacallan		}
390be1ef3d3Smacallan
391be1ef3d3Smacallan		pScrn = NULL;
392be1ef3d3Smacallan		entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE);
393be1ef3d3Smacallan	    	pScrn = xf86ConfigFbEntity(NULL, 0, entity, NULL, NULL,
394be1ef3d3Smacallan		  NULL, NULL);
395be1ef3d3Smacallan		pScrn->driverVersion = IGS_VERSION;
396be1ef3d3Smacallan		pScrn->driverName    = IGS_DRIVER_NAME;
397be1ef3d3Smacallan		pScrn->name          = IGS_NAME;
398be1ef3d3Smacallan		pScrn->Probe         = IgsProbe;
399be1ef3d3Smacallan		pScrn->PreInit       = IgsPreInit;
400be1ef3d3Smacallan		pScrn->ScreenInit    = IgsScreenInit;
401be1ef3d3Smacallan		pScrn->SwitchMode    = IgsSwitchMode;
402be1ef3d3Smacallan		pScrn->AdjustFrame   = NULL;
403be1ef3d3Smacallan		pScrn->EnterVT       = IgsEnterVT;
404be1ef3d3Smacallan		pScrn->LeaveVT       = IgsLeaveVT;
405be1ef3d3Smacallan		pScrn->ValidMode     = IgsValidMode;
406be1ef3d3Smacallan		if (!IgsGetRec(pScrn)) {
407be1ef3d3Smacallan		    return;
408be1ef3d3Smacallan		}
409be1ef3d3Smacallan		cPtr = IGSPTR(pScrn);
410be1ef3d3Smacallan		cPtr->Chipset = chipset;
411be1ef3d3Smacallan		cPtr->fb_paddr =
412be1ef3d3Smacallan		    ((uint32_t)igs_ext_read(IGS_EXT_LINA_HI)) << 24;
413be1ef3d3Smacallan		xf86Msg(X_ERROR, "Aperture at %08x\n", cPtr->fb_paddr);
414be1ef3d3Smacallan	    }
415be1ef3d3Smacallan	}
416be1ef3d3Smacallan    }
417be1ef3d3Smacallan
418be1ef3d3Smacallan    xfree(devSections);
419be1ef3d3Smacallan    return foundScreen;
420be1ef3d3Smacallan}
421be1ef3d3Smacallan
422be1ef3d3Smacallanstatic Bool
423be1ef3d3SmacallanIgsPreInit(ScrnInfoPtr pScrn, int flags)
424be1ef3d3Smacallan{
425be1ef3d3Smacallan	IgsPtr fPtr;
426727ce256Smacallan	int default_depth, vram_size = 2 * 1024 * 1024;
427be1ef3d3Smacallan	char *dev, *s;
428be1ef3d3Smacallan	char *mod = NULL;
429be1ef3d3Smacallan	const char *reqSym = NULL;
430be1ef3d3Smacallan	Gamma zeros = {0.0, 0.0, 0.0};
431be1ef3d3Smacallan	DisplayModePtr mode;
432be1ef3d3Smacallan	MessageType from;
433be1ef3d3Smacallan
434be1ef3d3Smacallan	if (flags & PROBE_DETECT) return FALSE;
435be1ef3d3Smacallan
436be1ef3d3Smacallan	TRACE_ENTER("PreInit");
437be1ef3d3Smacallan
438be1ef3d3Smacallan	if (pScrn->numEntities != 1) return FALSE;
439be1ef3d3Smacallan
440be1ef3d3Smacallan	pScrn->monitor = pScrn->confScreen->monitor;
441be1ef3d3Smacallan
442be1ef3d3Smacallan	IgsGetRec(pScrn);
443be1ef3d3Smacallan	fPtr = IGSPTR(pScrn);
444be1ef3d3Smacallan
445be1ef3d3Smacallan	fPtr->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
446be1ef3d3Smacallan
44722b24a26Smrg#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6
448be1ef3d3Smacallan	pScrn->racMemFlags = RAC_FB | RAC_COLORMAP | RAC_CURSOR | RAC_VIEWPORT;
449be1ef3d3Smacallan	pScrn->racIoFlags = pScrn->racMemFlags;
45022b24a26Smrg#endif
451be1ef3d3Smacallan
452be1ef3d3Smacallan	dev = xf86FindOptionValue(fPtr->pEnt->device->options, "device");
453be1ef3d3Smacallan	fPtr->fd = igs_open(dev);
454be1ef3d3Smacallan	if (fPtr->fd == -1) {
455be1ef3d3Smacallan		return FALSE;
456be1ef3d3Smacallan	}
457be1ef3d3Smacallan
458be1ef3d3Smacallan	if (ioctl(fPtr->fd, WSDISPLAYIO_GINFO, &fPtr->info) == -1) {
459be1ef3d3Smacallan		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
460be1ef3d3Smacallan			   "ioctl WSDISPLAY_GINFO: %s\n",
461be1ef3d3Smacallan			   strerror(errno));
462be1ef3d3Smacallan		return FALSE;
463be1ef3d3Smacallan	}
464be1ef3d3Smacallan
465be1ef3d3Smacallan	/* Handle depth */
466be1ef3d3Smacallan	default_depth = fPtr->info.depth <= 24 ? fPtr->info.depth : 24;
467be1ef3d3Smacallan	if (!xf86SetDepthBpp(pScrn, default_depth, default_depth,
468be1ef3d3Smacallan		fPtr->info.depth,
469be1ef3d3Smacallan		fPtr->info.depth >= 24 ? Support24bppFb|Support32bppFb : 0))
470be1ef3d3Smacallan		return FALSE;
471be1ef3d3Smacallan
472be1ef3d3Smacallan	/* Check consistency */
473be1ef3d3Smacallan	if (pScrn->bitsPerPixel != fPtr->info.depth) {
474be1ef3d3Smacallan		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
475be1ef3d3Smacallan		    "specified depth (%d) or bpp (%d) doesn't match "
476be1ef3d3Smacallan		    "framebuffer depth (%d)\n", pScrn->depth,
477be1ef3d3Smacallan		    pScrn->bitsPerPixel, fPtr->info.depth);
478be1ef3d3Smacallan		return FALSE;
479be1ef3d3Smacallan	}
480be1ef3d3Smacallan	xf86PrintDepthBpp(pScrn);
481be1ef3d3Smacallan
482be1ef3d3Smacallan	/* Get the depth24 pixmap format */
483be1ef3d3Smacallan	if (pScrn->depth == 24 && pix24bpp == 0)
484be1ef3d3Smacallan		pix24bpp = xf86GetBppFromDepth(pScrn, 24);
485be1ef3d3Smacallan
486be1ef3d3Smacallan	/* color weight */
487be1ef3d3Smacallan	if (pScrn->depth > 8) {
488be1ef3d3Smacallan		rgb zeros = { 0, 0, 0 }, masks;
489be1ef3d3Smacallan
490be1ef3d3Smacallan		masks.red = 0;
491be1ef3d3Smacallan		masks.green = 0;
492be1ef3d3Smacallan		masks.blue = 0;
493be1ef3d3Smacallan
494be1ef3d3Smacallan		if (!xf86SetWeight(pScrn, zeros, masks))
495be1ef3d3Smacallan			return FALSE;
496be1ef3d3Smacallan	}
497be1ef3d3Smacallan
498be1ef3d3Smacallan	/* visual init */
499be1ef3d3Smacallan	if (!xf86SetDefaultVisual(pScrn, -1))
500be1ef3d3Smacallan		return FALSE;
501be1ef3d3Smacallan
502be1ef3d3Smacallan	/* We don't currently support DirectColor at > 8bpp */
503be1ef3d3Smacallan	if (pScrn->depth > 8 && pScrn->defaultVisual != TrueColor) {
504be1ef3d3Smacallan		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Given default visual"
505be1ef3d3Smacallan			   " (%s) is not supported at depth %d\n",
506be1ef3d3Smacallan			   xf86GetVisualName(pScrn->defaultVisual),
507be1ef3d3Smacallan			   pScrn->depth);
508be1ef3d3Smacallan		return FALSE;
509be1ef3d3Smacallan	}
510be1ef3d3Smacallan
511be1ef3d3Smacallan	xf86SetGamma(pScrn,zeros);
512be1ef3d3Smacallan
513be1ef3d3Smacallan	pScrn->progClock = TRUE;
514be1ef3d3Smacallan	pScrn->rgbBits   = 8;
515be1ef3d3Smacallan	pScrn->chipset   = "igs";
516be1ef3d3Smacallan	pScrn->videoRam  = vram_size;
517be1ef3d3Smacallan
518be1ef3d3Smacallan	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Vidmem: %dk\n",
519be1ef3d3Smacallan		   pScrn->videoRam/1024);
520be1ef3d3Smacallan
521be1ef3d3Smacallan	/* handle options */
522be1ef3d3Smacallan	xf86CollectOptions(pScrn, NULL);
523be1ef3d3Smacallan	if (!(fPtr->Options = xalloc(sizeof(IgsOptions))))
524be1ef3d3Smacallan		return FALSE;
525be1ef3d3Smacallan	memcpy(fPtr->Options, IgsOptions, sizeof(IgsOptions));
526be1ef3d3Smacallan	xf86ProcessOptions(pScrn->scrnIndex, fPtr->pEnt->device->options,
527be1ef3d3Smacallan			   fPtr->Options);
528be1ef3d3Smacallan
529be1ef3d3Smacallan	/* fake video mode struct */
530be1ef3d3Smacallan	mode = (DisplayModePtr)xalloc(sizeof(DisplayModeRec));
531be1ef3d3Smacallan	mode->prev = mode;
532be1ef3d3Smacallan	mode->next = mode;
533be1ef3d3Smacallan	mode->name = "igs current mode";
534be1ef3d3Smacallan	mode->status = MODE_OK;
535be1ef3d3Smacallan	mode->type = M_T_BUILTIN;
536be1ef3d3Smacallan	mode->Clock = 0;
537be1ef3d3Smacallan	mode->HDisplay = fPtr->info.width;
538be1ef3d3Smacallan	mode->HSyncStart = 0;
539be1ef3d3Smacallan	mode->HSyncEnd = 0;
540be1ef3d3Smacallan	mode->HTotal = 0;
541be1ef3d3Smacallan	mode->HSkew = 0;
542be1ef3d3Smacallan	mode->VDisplay = fPtr->info.height;
543be1ef3d3Smacallan	mode->VSyncStart = 0;
544be1ef3d3Smacallan	mode->VSyncEnd = 0;
545be1ef3d3Smacallan	mode->VTotal = 0;
546be1ef3d3Smacallan	mode->VScan = 0;
547be1ef3d3Smacallan	mode->Flags = 0;
548be1ef3d3Smacallan	if (pScrn->modes != NULL) {
549be1ef3d3Smacallan		xf86DrvMsg(pScrn->scrnIndex, X_INFO,
550be1ef3d3Smacallan		   "Ignoring mode specification from screen section\n");
551be1ef3d3Smacallan	}
552be1ef3d3Smacallan	pScrn->currentMode = pScrn->modes = mode;
553be1ef3d3Smacallan	pScrn->virtualX = fPtr->info.width;
554be1ef3d3Smacallan	pScrn->virtualY = fPtr->info.height;
555be1ef3d3Smacallan	pScrn->displayWidth = pScrn->virtualX;
556be1ef3d3Smacallan
557be1ef3d3Smacallan	/* Set the display resolution */
558be1ef3d3Smacallan	xf86SetDpi(pScrn, 0, 0);
559be1ef3d3Smacallan
560be1ef3d3Smacallan	from = X_DEFAULT;
561be1ef3d3Smacallan	fPtr->HWCursor = TRUE;
562be1ef3d3Smacallan	if (xf86GetOptValBool(fPtr->Options, OPTION_HW_CURSOR, &fPtr->HWCursor))
563be1ef3d3Smacallan		from = X_CONFIG;
564be1ef3d3Smacallan	if (xf86ReturnOptValBool(fPtr->Options, OPTION_SW_CURSOR, FALSE)) {
565be1ef3d3Smacallan		from = X_CONFIG;
566be1ef3d3Smacallan		fPtr->HWCursor = FALSE;
567be1ef3d3Smacallan	}
568be1ef3d3Smacallan	xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n",
569be1ef3d3Smacallan		fPtr->HWCursor ? "HW" : "SW");
570be1ef3d3Smacallan
571be1ef3d3Smacallan	/* Load bpp-specific modules */
572be1ef3d3Smacallan	switch(pScrn->bitsPerPixel) {
573be1ef3d3Smacallan	default:
574be1ef3d3Smacallan		mod = "fb";
575be1ef3d3Smacallan		break;
576be1ef3d3Smacallan	}
577be1ef3d3Smacallan
578be1ef3d3Smacallan	if (mod && xf86LoadSubModule(pScrn, mod) == NULL) {
579be1ef3d3Smacallan		IgsFreeRec(pScrn);
580be1ef3d3Smacallan		return FALSE;
581be1ef3d3Smacallan	}
582be1ef3d3Smacallan
583be1ef3d3Smacallan	if (xf86LoadSubModule(pScrn, "ramdac") == NULL) {
584be1ef3d3Smacallan		IgsFreeRec(pScrn);
585be1ef3d3Smacallan		return FALSE;
586be1ef3d3Smacallan        }
587be1ef3d3Smacallan
588be1ef3d3Smacallan	if (mod) {
589be1ef3d3Smacallan		if (reqSym) {
590be1ef3d3Smacallan			xf86LoaderReqSymbols(reqSym, NULL);
591be1ef3d3Smacallan		} else {
592be1ef3d3Smacallan			xf86LoaderReqSymLists(fbSymbols, NULL);
593be1ef3d3Smacallan		}
594be1ef3d3Smacallan	}
595be1ef3d3Smacallan	TRACE_EXIT("PreInit");
596be1ef3d3Smacallan	return TRUE;
597be1ef3d3Smacallan}
598be1ef3d3Smacallan
599be1ef3d3Smacallanstatic Bool
600be1ef3d3SmacallanIgsCreateScreenResources(ScreenPtr pScreen)
601be1ef3d3Smacallan{
602be1ef3d3Smacallan	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
603be1ef3d3Smacallan	IgsPtr fPtr = IGSPTR(pScrn);
604be1ef3d3Smacallan	PixmapPtr pPixmap;
605be1ef3d3Smacallan	Bool ret;
606be1ef3d3Smacallan
607be1ef3d3Smacallan	pScreen->CreateScreenResources = fPtr->CreateScreenResources;
608be1ef3d3Smacallan	ret = pScreen->CreateScreenResources(pScreen);
609be1ef3d3Smacallan	pScreen->CreateScreenResources = IgsCreateScreenResources;
610be1ef3d3Smacallan
611be1ef3d3Smacallan	if (!ret)
612be1ef3d3Smacallan		return FALSE;
613be1ef3d3Smacallan
614be1ef3d3Smacallan	pPixmap = pScreen->GetScreenPixmap(pScreen);
615be1ef3d3Smacallan
616be1ef3d3Smacallan	if (!shadowAdd(pScreen, pPixmap, shadowUpdatePackedWeak(),
617be1ef3d3Smacallan		IgsWindowLinear, FALSE, NULL)) {
618be1ef3d3Smacallan		return FALSE;
619be1ef3d3Smacallan	}
620be1ef3d3Smacallan	return TRUE;
621be1ef3d3Smacallan}
622be1ef3d3Smacallan
623be1ef3d3Smacallan
624be1ef3d3Smacallanstatic Bool
625be1ef3d3SmacallanIgsShadowInit(ScreenPtr pScreen)
626be1ef3d3Smacallan{
627be1ef3d3Smacallan	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
628be1ef3d3Smacallan	IgsPtr fPtr = IGSPTR(pScrn);
629be1ef3d3Smacallan
630be1ef3d3Smacallan	if (!shadowSetup(pScreen))
631be1ef3d3Smacallan		return FALSE;
632be1ef3d3Smacallan	fPtr->CreateScreenResources = pScreen->CreateScreenResources;
633be1ef3d3Smacallan	pScreen->CreateScreenResources = IgsCreateScreenResources;
634be1ef3d3Smacallan
635be1ef3d3Smacallan	return TRUE;
636be1ef3d3Smacallan}
637be1ef3d3Smacallan
638be1ef3d3Smacallanstatic Bool
639be1ef3d3SmacallanIgsScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
640be1ef3d3Smacallan{
641be1ef3d3Smacallan	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
642be1ef3d3Smacallan	IgsPtr fPtr = IGSPTR(pScrn);
643be1ef3d3Smacallan	VisualPtr visual;
644be1ef3d3Smacallan	int ret, flags, ncolors;
645be1ef3d3Smacallan	int wsmode = WSDISPLAYIO_MODE_DUMBFB;
646be1ef3d3Smacallan	size_t len;
647be1ef3d3Smacallan
648be1ef3d3Smacallan	TRACE_ENTER("IgsScreenInit");
649be1ef3d3Smacallan#if DEBUG
650be1ef3d3Smacallan	ErrorF("\tbitsPerPixel=%d, depth=%d, defaultVisual=%s\n"
651be1ef3d3Smacallan	       "\tmask: %x,%x,%x, offset: %u,%u,%u\n",
652be1ef3d3Smacallan	       pScrn->bitsPerPixel,
653be1ef3d3Smacallan	       pScrn->depth,
654be1ef3d3Smacallan	       xf86GetVisualName(pScrn->defaultVisual),
655be1ef3d3Smacallan	       pScrn->mask.red,pScrn->mask.green,pScrn->mask.blue,
656be1ef3d3Smacallan	       pScrn->offset.red,pScrn->offset.green,pScrn->offset.blue);
657be1ef3d3Smacallan#endif
658be1ef3d3Smacallan	fPtr->linebytes = fPtr->info.width * (fPtr->info.depth >> 3);
659be1ef3d3Smacallan
660be1ef3d3Smacallan	/* Switch to graphics mode - required before mmap */
661be1ef3d3Smacallan	if (ioctl(fPtr->fd, WSDISPLAYIO_SMODE, &wsmode) == -1) {
662be1ef3d3Smacallan		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
663be1ef3d3Smacallan			   "ioctl WSDISPLAYIO_SMODE: %s\n",
664be1ef3d3Smacallan			   strerror(errno));
665be1ef3d3Smacallan		return FALSE;
666be1ef3d3Smacallan	}
667be1ef3d3Smacallan
668be1ef3d3Smacallan	/* find our aperturwe */
669be1ef3d3Smacallan
670be1ef3d3Smacallan	/* assume 2MB for now, until I add actual RAM size probing */
671be1ef3d3Smacallan	len = 2 * 1024 * 1024;
672be1ef3d3Smacallan	fPtr->fbmem = igs_mmap(len, fPtr->fb_paddr, fPtr->fd);
673be1ef3d3Smacallan
674be1ef3d3Smacallan	if (fPtr->fbmem == NULL) {
675be1ef3d3Smacallan		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
676be1ef3d3Smacallan			   "igs_mmap(fb): %s\n", strerror(errno));
677be1ef3d3Smacallan		return FALSE;
678be1ef3d3Smacallan	}
679be1ef3d3Smacallan	fPtr->fbmem_len = len - 1024; /* leave room for the hw cursor */
680be1ef3d3Smacallan
681be1ef3d3Smacallan	fPtr->reg = igs_mmap(4096,
682be1ef3d3Smacallan	    fPtr->fb_paddr + IGS_MEM_MMIO_SELECT + IGS_COP_BASE_B, fPtr->fd);
683be1ef3d3Smacallan	if (fPtr->reg == NULL) {
684be1ef3d3Smacallan		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
685be1ef3d3Smacallan			   "igs_mmap(registers): %s\n", strerror(errno));
686be1ef3d3Smacallan		return FALSE;
687be1ef3d3Smacallan	}
688be1ef3d3Smacallan	xf86Msg(X_ERROR, "0x10: %08x\n", *(uint32_t *)(fPtr->reg + 0x10));
689be1ef3d3Smacallan
690be1ef3d3Smacallan	IgsSave(pScrn);
691be1ef3d3Smacallan	pScrn->vtSema = TRUE;
692be1ef3d3Smacallan
693be1ef3d3Smacallan	/* mi layer */
694be1ef3d3Smacallan	miClearVisualTypes();
695be1ef3d3Smacallan	if (pScrn->bitsPerPixel > 8) {
696be1ef3d3Smacallan		if (!miSetVisualTypes(pScrn->depth, TrueColorMask,
697be1ef3d3Smacallan				      pScrn->rgbBits, TrueColor))
698be1ef3d3Smacallan			return FALSE;
699be1ef3d3Smacallan	} else {
700be1ef3d3Smacallan		if (!miSetVisualTypes(pScrn->depth,
701be1ef3d3Smacallan				      miGetDefaultVisualMask(pScrn->depth),
702be1ef3d3Smacallan				      pScrn->rgbBits, pScrn->defaultVisual))
703be1ef3d3Smacallan			return FALSE;
704be1ef3d3Smacallan	}
705be1ef3d3Smacallan	if (!miSetPixmapDepths())
706be1ef3d3Smacallan		return FALSE;
707be1ef3d3Smacallan
708be1ef3d3Smacallan	fPtr->fbstart = fPtr->fbmem;
709be1ef3d3Smacallan
710be1ef3d3Smacallan	switch (pScrn->bitsPerPixel) {
711be1ef3d3Smacallan	case 8:
712be1ef3d3Smacallan	case 16:
713be1ef3d3Smacallan	case 24:
714be1ef3d3Smacallan	case 32:
715be1ef3d3Smacallan		ret = fbScreenInit(pScreen,
716be1ef3d3Smacallan		    fPtr->fbstart,
717be1ef3d3Smacallan		    pScrn->virtualX, pScrn->virtualY,
718be1ef3d3Smacallan		    pScrn->xDpi, pScrn->yDpi,
719be1ef3d3Smacallan		    pScrn->displayWidth, pScrn->bitsPerPixel);
720be1ef3d3Smacallan		break;
721be1ef3d3Smacallan	default:
722be1ef3d3Smacallan		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
723be1ef3d3Smacallan			   "Unsupported bpp: %d", pScrn->bitsPerPixel);
724be1ef3d3Smacallan		return FALSE;
725be1ef3d3Smacallan	} /* case */
726be1ef3d3Smacallan
727be1ef3d3Smacallan	if (!ret)
728be1ef3d3Smacallan		return FALSE;
729be1ef3d3Smacallan
730be1ef3d3Smacallan	if (pScrn->bitsPerPixel > 8) {
731be1ef3d3Smacallan		/* Fixup RGB ordering */
732be1ef3d3Smacallan		visual = pScreen->visuals + pScreen->numVisuals;
733be1ef3d3Smacallan		while (--visual >= pScreen->visuals) {
734be1ef3d3Smacallan			if ((visual->class | DynamicClass) == DirectColor) {
735be1ef3d3Smacallan				visual->offsetRed   = pScrn->offset.red;
736be1ef3d3Smacallan				visual->offsetGreen = pScrn->offset.green;
737be1ef3d3Smacallan				visual->offsetBlue  = pScrn->offset.blue;
738be1ef3d3Smacallan				visual->redMask     = pScrn->mask.red;
739be1ef3d3Smacallan				visual->greenMask   = pScrn->mask.green;
740be1ef3d3Smacallan				visual->blueMask    = pScrn->mask.blue;
741be1ef3d3Smacallan			}
742be1ef3d3Smacallan		}
743be1ef3d3Smacallan	}
744be1ef3d3Smacallan
745be1ef3d3Smacallan	if (pScrn->bitsPerPixel >= 8) {
746be1ef3d3Smacallan		if (!fbPictureInit(pScreen, NULL, 0))
747be1ef3d3Smacallan			xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
748be1ef3d3Smacallan				   "RENDER extension initialisation failed.");
749be1ef3d3Smacallan	}
750be1ef3d3Smacallan
751be1ef3d3Smacallan#ifdef XFreeXDGA
752be1ef3d3Smacallan	IgsDGAInit(pScrn, pScreen);
753be1ef3d3Smacallan#endif
754be1ef3d3Smacallan
755be1ef3d3Smacallan	xf86SetBlackWhitePixels(pScreen);
756be1ef3d3Smacallan	miInitializeBackingStore(pScreen);
757be1ef3d3Smacallan	xf86SetBackingStore(pScreen);
758be1ef3d3Smacallan
759be1ef3d3Smacallan	/* setup acceleration */
760be1ef3d3Smacallan	if (1) {
761be1ef3d3Smacallan		XF86ModReqInfo req;
762be1ef3d3Smacallan		int errmaj, errmin;
763be1ef3d3Smacallan
764be1ef3d3Smacallan		memset(&req, 0, sizeof(XF86ModReqInfo));
765be1ef3d3Smacallan		req.majorversion = 2;
766be1ef3d3Smacallan		req.minorversion = 0;
767be1ef3d3Smacallan		if (!LoadSubModule(pScrn->module, "exa", NULL, NULL, NULL, &req,
768be1ef3d3Smacallan		    &errmaj, &errmin)) {
769be1ef3d3Smacallan			LoaderErrorMsg(NULL, "exa", errmaj, errmin);
770be1ef3d3Smacallan			return FALSE;
771be1ef3d3Smacallan		}
772be1ef3d3Smacallan		if (!IgsInitAccel(pScreen))
773be1ef3d3Smacallan			return FALSE;
774be1ef3d3Smacallan	}
775be1ef3d3Smacallan
776be1ef3d3Smacallan	/* software cursor */
777be1ef3d3Smacallan	miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
778be1ef3d3Smacallan
779be1ef3d3Smacallan	/* check for hardware cursor support */
780be1ef3d3Smacallan	if (fPtr->HWCursor)
781be1ef3d3Smacallan		IgsSetupCursor(pScreen);
782be1ef3d3Smacallan
783be1ef3d3Smacallan	/* colormap */
784be1ef3d3Smacallan	if (!miCreateDefColormap(pScreen))
785be1ef3d3Smacallan		return FALSE;
786be1ef3d3Smacallan	flags = CMAP_RELOAD_ON_MODE_SWITCH;
787be1ef3d3Smacallan	ncolors = fPtr->info.cmsize;
788be1ef3d3Smacallan	/* on StaticGray visuals, fake a 256 entries colormap */
789be1ef3d3Smacallan	if (ncolors == 0)
790be1ef3d3Smacallan		ncolors = 256;
791be1ef3d3Smacallan	if(!xf86HandleColormaps(pScreen, ncolors, 8, IgsLoadPalette,
792be1ef3d3Smacallan				NULL, flags))
793be1ef3d3Smacallan		return FALSE;
794be1ef3d3Smacallan
795be1ef3d3Smacallan	pScreen->SaveScreen = IgsSaveScreen;
796be1ef3d3Smacallan
797be1ef3d3Smacallan#ifdef XvExtension
798be1ef3d3Smacallan	{
799be1ef3d3Smacallan		XF86VideoAdaptorPtr *ptr;
800be1ef3d3Smacallan
801be1ef3d3Smacallan		int n = xf86XVListGenericAdaptors(pScrn,&ptr);
802be1ef3d3Smacallan		if (n) {
803be1ef3d3Smacallan			xf86XVScreenInit(pScreen,ptr,n);
804be1ef3d3Smacallan		}
805be1ef3d3Smacallan	}
806be1ef3d3Smacallan#endif
807be1ef3d3Smacallan
808be1ef3d3Smacallan	/* Wrap the current CloseScreen function */
809be1ef3d3Smacallan	fPtr->CloseScreen = pScreen->CloseScreen;
810be1ef3d3Smacallan	pScreen->CloseScreen = IgsCloseScreen;
811be1ef3d3Smacallan
812be1ef3d3Smacallan	TRACE_EXIT("IgsScreenInit");
813be1ef3d3Smacallan	return TRUE;
814be1ef3d3Smacallan}
815be1ef3d3Smacallan
816be1ef3d3Smacallanstatic Bool
817be1ef3d3SmacallanIgsCloseScreen(int scrnIndex, ScreenPtr pScreen)
818be1ef3d3Smacallan{
819be1ef3d3Smacallan	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
820be1ef3d3Smacallan	IgsPtr fPtr = IGSPTR(pScrn);
821be1ef3d3Smacallan
822be1ef3d3Smacallan	TRACE_ENTER("IgsCloseScreen");
823be1ef3d3Smacallan
824be1ef3d3Smacallan	if (pScrn->vtSema) {
825be1ef3d3Smacallan		IgsRestore(pScrn);
826be1ef3d3Smacallan		if (munmap(fPtr->fbmem, fPtr->fbmem_len) == -1) {
827be1ef3d3Smacallan			xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
828be1ef3d3Smacallan				   "munmap: %s\n", strerror(errno));
829be1ef3d3Smacallan		}
830be1ef3d3Smacallan
831be1ef3d3Smacallan		fPtr->fbmem = NULL;
832be1ef3d3Smacallan	}
833be1ef3d3Smacallan#ifdef XFreeXDGA
834be1ef3d3Smacallan	if (fPtr->pDGAMode) {
835be1ef3d3Smacallan		xfree(fPtr->pDGAMode);
836be1ef3d3Smacallan		fPtr->pDGAMode = NULL;
837be1ef3d3Smacallan		fPtr->nDGAMode = 0;
838be1ef3d3Smacallan	}
839be1ef3d3Smacallan#endif
840be1ef3d3Smacallan	pScrn->vtSema = FALSE;
841be1ef3d3Smacallan
842be1ef3d3Smacallan	/* unwrap CloseScreen */
843be1ef3d3Smacallan	pScreen->CloseScreen = fPtr->CloseScreen;
844be1ef3d3Smacallan	return (*pScreen->CloseScreen)(scrnIndex, pScreen);
845be1ef3d3Smacallan}
846be1ef3d3Smacallan
847be1ef3d3Smacallanstatic void *
848be1ef3d3SmacallanIgsWindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode,
849be1ef3d3Smacallan		CARD32 *size, void *closure)
850be1ef3d3Smacallan{
851be1ef3d3Smacallan	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
852be1ef3d3Smacallan	IgsPtr fPtr = IGSPTR(pScrn);
853be1ef3d3Smacallan
854be1ef3d3Smacallan	if (fPtr->linebytes)
855be1ef3d3Smacallan		*size = fPtr->linebytes;
856be1ef3d3Smacallan	else {
857be1ef3d3Smacallan		if (ioctl(fPtr->fd, WSDISPLAYIO_LINEBYTES, size) == -1)
858be1ef3d3Smacallan			return NULL;
859be1ef3d3Smacallan		fPtr->linebytes = *size;
860be1ef3d3Smacallan	}
861be1ef3d3Smacallan	return ((CARD8 *)fPtr->fbmem + row *fPtr->linebytes + offset);
862be1ef3d3Smacallan}
863be1ef3d3Smacallan
864be1ef3d3Smacallanstatic Bool
865be1ef3d3SmacallanIgsEnterVT(int scrnIndex, int flags)
866be1ef3d3Smacallan{
867be1ef3d3Smacallan	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
868be1ef3d3Smacallan
869be1ef3d3Smacallan	TRACE_ENTER("EnterVT");
870be1ef3d3Smacallan	pScrn->vtSema = TRUE;
871be1ef3d3Smacallan	return TRUE;
872be1ef3d3Smacallan}
873be1ef3d3Smacallan
874be1ef3d3Smacallanstatic void
875be1ef3d3SmacallanIgsLeaveVT(int scrnIndex, int flags)
876be1ef3d3Smacallan{
877be1ef3d3Smacallan#if DEBUG
878be1ef3d3Smacallan	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
879be1ef3d3Smacallan#endif
880be1ef3d3Smacallan
881be1ef3d3Smacallan	TRACE_ENTER("LeaveVT");
882be1ef3d3Smacallan}
883be1ef3d3Smacallan
884be1ef3d3Smacallanstatic Bool
885be1ef3d3SmacallanIgsSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
886be1ef3d3Smacallan{
887be1ef3d3Smacallan#if DEBUG
888be1ef3d3Smacallan	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
889be1ef3d3Smacallan#endif
890be1ef3d3Smacallan
891be1ef3d3Smacallan	TRACE_ENTER("SwitchMode");
892be1ef3d3Smacallan	/* Nothing else to do */
893be1ef3d3Smacallan	return TRUE;
894be1ef3d3Smacallan}
895be1ef3d3Smacallan
896be1ef3d3Smacallanstatic int
897be1ef3d3SmacallanIgsValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
898be1ef3d3Smacallan{
899be1ef3d3Smacallan#if DEBUG
900be1ef3d3Smacallan	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
901be1ef3d3Smacallan#endif
902be1ef3d3Smacallan
903be1ef3d3Smacallan	TRACE_ENTER("ValidMode");
904be1ef3d3Smacallan	return MODE_OK;
905be1ef3d3Smacallan}
906be1ef3d3Smacallan
907be1ef3d3Smacallanstatic void
908be1ef3d3SmacallanIgsLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
909be1ef3d3Smacallan	       LOCO *colors, VisualPtr pVisual)
910be1ef3d3Smacallan{
911be1ef3d3Smacallan	IgsPtr fPtr = IGSPTR(pScrn);
912be1ef3d3Smacallan	struct wsdisplay_cmap cmap;
913be1ef3d3Smacallan	unsigned char red[256],green[256],blue[256];
914be1ef3d3Smacallan	int i, indexMin=256, indexMax=0;
915be1ef3d3Smacallan
916be1ef3d3Smacallan	TRACE_ENTER("LoadPalette");
917be1ef3d3Smacallan
918be1ef3d3Smacallan	cmap.count   = 1;
919be1ef3d3Smacallan	cmap.red   = red;
920be1ef3d3Smacallan	cmap.green = green;
921be1ef3d3Smacallan	cmap.blue  = blue;
922be1ef3d3Smacallan
923be1ef3d3Smacallan	if (numColors == 1) {
924be1ef3d3Smacallan		/* Optimisation */
925be1ef3d3Smacallan		cmap.index = indices[0];
926be1ef3d3Smacallan		red[0]   = colors[indices[0]].red;
927be1ef3d3Smacallan		green[0] = colors[indices[0]].green;
928be1ef3d3Smacallan		blue[0]  = colors[indices[0]].blue;
929be1ef3d3Smacallan		if (ioctl(fPtr->fd,WSDISPLAYIO_PUTCMAP, &cmap) == -1)
930be1ef3d3Smacallan			ErrorF("ioctl FBIOPUTCMAP: %s\n", strerror(errno));
931be1ef3d3Smacallan	} else {
932be1ef3d3Smacallan		/* Change all colors in 2 syscalls */
933be1ef3d3Smacallan		/* and limit the data to be transfered */
934be1ef3d3Smacallan		for (i = 0; i < numColors; i++) {
935be1ef3d3Smacallan			if (indices[i] < indexMin)
936be1ef3d3Smacallan				indexMin = indices[i];
937be1ef3d3Smacallan			if (indices[i] > indexMax)
938be1ef3d3Smacallan				indexMax = indices[i];
939be1ef3d3Smacallan		}
940be1ef3d3Smacallan		cmap.index = indexMin;
941be1ef3d3Smacallan		cmap.count = indexMax - indexMin + 1;
942be1ef3d3Smacallan		cmap.red = &red[indexMin];
943be1ef3d3Smacallan		cmap.green = &green[indexMin];
944be1ef3d3Smacallan		cmap.blue = &blue[indexMin];
945be1ef3d3Smacallan		/* Get current map */
946be1ef3d3Smacallan		if (ioctl(fPtr->fd, WSDISPLAYIO_GETCMAP, &cmap) == -1)
947be1ef3d3Smacallan			ErrorF("ioctl FBIOGETCMAP: %s\n", strerror(errno));
948be1ef3d3Smacallan		/* Change the colors that require updating */
949be1ef3d3Smacallan		for (i = 0; i < numColors; i++) {
950be1ef3d3Smacallan			red[indices[i]]   = colors[indices[i]].red;
951be1ef3d3Smacallan			green[indices[i]] = colors[indices[i]].green;
952be1ef3d3Smacallan			blue[indices[i]]  = colors[indices[i]].blue;
953be1ef3d3Smacallan		}
954be1ef3d3Smacallan		/* Write the colormap back */
955be1ef3d3Smacallan		if (ioctl(fPtr->fd,WSDISPLAYIO_PUTCMAP, &cmap) == -1)
956be1ef3d3Smacallan			ErrorF("ioctl FBIOPUTCMAP: %s\n", strerror(errno));
957be1ef3d3Smacallan	}
958be1ef3d3Smacallan	TRACE_EXIT("LoadPalette");
959be1ef3d3Smacallan}
960be1ef3d3Smacallan
961be1ef3d3Smacallanstatic Bool
962be1ef3d3SmacallanIgsSaveScreen(ScreenPtr pScreen, int mode)
963be1ef3d3Smacallan{
964be1ef3d3Smacallan	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
965be1ef3d3Smacallan	IgsPtr fPtr = IGSPTR(pScrn);
966be1ef3d3Smacallan	int state;
967be1ef3d3Smacallan
968be1ef3d3Smacallan	TRACE_ENTER("SaveScreen");
969be1ef3d3Smacallan
970be1ef3d3Smacallan	if (!pScrn->vtSema)
971be1ef3d3Smacallan		return TRUE;
972be1ef3d3Smacallan
973be1ef3d3Smacallan	if (mode != SCREEN_SAVER_FORCER) {
974be1ef3d3Smacallan		state = xf86IsUnblank(mode)?WSDISPLAYIO_VIDEO_ON:
975be1ef3d3Smacallan		                            WSDISPLAYIO_VIDEO_OFF;
976be1ef3d3Smacallan		ioctl(fPtr->fd,
977be1ef3d3Smacallan		      WSDISPLAYIO_SVIDEO, &state);
978be1ef3d3Smacallan	}
979be1ef3d3Smacallan	return TRUE;
980be1ef3d3Smacallan}
981be1ef3d3Smacallan
982be1ef3d3Smacallan
983be1ef3d3Smacallanstatic void
984be1ef3d3SmacallanIgsSave(ScrnInfoPtr pScrn)
985be1ef3d3Smacallan{
986be1ef3d3Smacallan	IgsPtr fPtr = IGSPTR(pScrn);
987be1ef3d3Smacallan
988be1ef3d3Smacallan	TRACE_ENTER("IgsSave");
989be1ef3d3Smacallan
990be1ef3d3Smacallan	if (fPtr->info.cmsize == 0)
991be1ef3d3Smacallan		return;
992be1ef3d3Smacallan
993be1ef3d3Smacallan}
994be1ef3d3Smacallan
995be1ef3d3Smacallanstatic void
996be1ef3d3SmacallanIgsRestore(ScrnInfoPtr pScrn)
997be1ef3d3Smacallan{
998be1ef3d3Smacallan	IgsPtr fPtr = IGSPTR(pScrn);
999be1ef3d3Smacallan	int mode;
1000be1ef3d3Smacallan
1001be1ef3d3Smacallan	TRACE_ENTER("IgsRestore");
1002be1ef3d3Smacallan
1003be1ef3d3Smacallan	/* Clear the screen */
1004be1ef3d3Smacallan	memset(fPtr->fbmem, 0, fPtr->fbmem_len);
1005be1ef3d3Smacallan
1006be1ef3d3Smacallan	/* Restore the text mode */
1007be1ef3d3Smacallan	mode = WSDISPLAYIO_MODE_EMUL;
1008be1ef3d3Smacallan	if (ioctl(fPtr->fd, WSDISPLAYIO_SMODE, &mode) == -1) {
1009be1ef3d3Smacallan		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1010be1ef3d3Smacallan			   "error setting text mode %s\n", strerror(errno));
1011be1ef3d3Smacallan	}
1012be1ef3d3Smacallan	TRACE_EXIT("IgsRestore");
1013be1ef3d3Smacallan}
1014be1ef3d3Smacallan
1015be1ef3d3Smacallan#ifdef XFreeXDGA
1016be1ef3d3Smacallan/***********************************************************************
1017be1ef3d3Smacallan * DGA stuff
1018be1ef3d3Smacallan ***********************************************************************/
1019be1ef3d3Smacallan
1020be1ef3d3Smacallanstatic Bool
1021be1ef3d3SmacallanIgsDGAOpenFramebuffer(ScrnInfoPtr pScrn, char **DeviceName,
1022be1ef3d3Smacallan		       unsigned char **ApertureBase, int *ApertureSize,
1023be1ef3d3Smacallan		       int *ApertureOffset, int *flags)
1024be1ef3d3Smacallan{
1025be1ef3d3Smacallan	*DeviceName = NULL;		/* No special device */
1026be1ef3d3Smacallan	*ApertureBase = (unsigned char *)(pScrn->memPhysBase);
1027be1ef3d3Smacallan	*ApertureSize = pScrn->videoRam;
1028be1ef3d3Smacallan	*ApertureOffset = pScrn->fbOffset;
1029be1ef3d3Smacallan	*flags = 0;
1030be1ef3d3Smacallan
1031be1ef3d3Smacallan	return TRUE;
1032be1ef3d3Smacallan}
1033be1ef3d3Smacallan
1034be1ef3d3Smacallanstatic Bool
1035be1ef3d3SmacallanIgsDGASetMode(ScrnInfoPtr pScrn, DGAModePtr pDGAMode)
1036be1ef3d3Smacallan{
1037be1ef3d3Smacallan	DisplayModePtr pMode;
1038be1ef3d3Smacallan	int scrnIdx = pScrn->pScreen->myNum;
1039be1ef3d3Smacallan	int frameX0, frameY0;
1040be1ef3d3Smacallan
1041be1ef3d3Smacallan	if (pDGAMode) {
1042be1ef3d3Smacallan		pMode = pDGAMode->mode;
1043be1ef3d3Smacallan		frameX0 = frameY0 = 0;
1044be1ef3d3Smacallan	} else {
1045be1ef3d3Smacallan		if (!(pMode = pScrn->currentMode))
1046be1ef3d3Smacallan			return TRUE;
1047be1ef3d3Smacallan
1048be1ef3d3Smacallan		frameX0 = pScrn->frameX0;
1049be1ef3d3Smacallan		frameY0 = pScrn->frameY0;
1050be1ef3d3Smacallan	}
1051be1ef3d3Smacallan
1052be1ef3d3Smacallan	if (!(*pScrn->SwitchMode)(scrnIdx, pMode, 0))
1053be1ef3d3Smacallan		return FALSE;
1054be1ef3d3Smacallan	(*pScrn->AdjustFrame)(scrnIdx, frameX0, frameY0, 0);
1055be1ef3d3Smacallan
1056be1ef3d3Smacallan	return TRUE;
1057be1ef3d3Smacallan}
1058be1ef3d3Smacallan
1059be1ef3d3Smacallanstatic void
1060be1ef3d3SmacallanIgsDGASetViewport(ScrnInfoPtr pScrn, int x, int y, int flags)
1061be1ef3d3Smacallan{
1062be1ef3d3Smacallan	(*pScrn->AdjustFrame)(pScrn->pScreen->myNum, x, y, flags);
1063be1ef3d3Smacallan}
1064be1ef3d3Smacallan
1065be1ef3d3Smacallanstatic int
1066be1ef3d3SmacallanIgsDGAGetViewport(ScrnInfoPtr pScrn)
1067be1ef3d3Smacallan{
1068be1ef3d3Smacallan	return (0);
1069be1ef3d3Smacallan}
1070be1ef3d3Smacallan
1071be1ef3d3Smacallanstatic DGAFunctionRec IgsDGAFunctions =
1072be1ef3d3Smacallan{
1073be1ef3d3Smacallan	IgsDGAOpenFramebuffer,
1074be1ef3d3Smacallan	NULL,       /* CloseFramebuffer */
1075be1ef3d3Smacallan	IgsDGASetMode,
1076be1ef3d3Smacallan	IgsDGASetViewport,
1077be1ef3d3Smacallan	IgsDGAGetViewport,
1078be1ef3d3Smacallan	NULL,       /* Sync */
1079be1ef3d3Smacallan	NULL,       /* FillRect */
1080be1ef3d3Smacallan	NULL,       /* BlitRect */
1081be1ef3d3Smacallan	NULL,       /* BlitTransRect */
1082be1ef3d3Smacallan};
1083be1ef3d3Smacallan
1084be1ef3d3Smacallanstatic void
1085be1ef3d3SmacallanIgsDGAAddModes(ScrnInfoPtr pScrn)
1086be1ef3d3Smacallan{
1087be1ef3d3Smacallan	IgsPtr fPtr = IGSPTR(pScrn);
1088be1ef3d3Smacallan	DisplayModePtr pMode = pScrn->modes;
1089be1ef3d3Smacallan	DGAModePtr pDGAMode;
1090be1ef3d3Smacallan
1091be1ef3d3Smacallan	do {
1092be1ef3d3Smacallan		pDGAMode = xrealloc(fPtr->pDGAMode,
1093be1ef3d3Smacallan				    (fPtr->nDGAMode + 1) * sizeof(DGAModeRec));
1094be1ef3d3Smacallan		if (!pDGAMode)
1095be1ef3d3Smacallan			break;
1096be1ef3d3Smacallan
1097be1ef3d3Smacallan		fPtr->pDGAMode = pDGAMode;
1098be1ef3d3Smacallan		pDGAMode += fPtr->nDGAMode;
1099be1ef3d3Smacallan		(void)memset(pDGAMode, 0, sizeof(DGAModeRec));
1100be1ef3d3Smacallan
1101be1ef3d3Smacallan		++fPtr->nDGAMode;
1102be1ef3d3Smacallan		pDGAMode->mode = pMode;
1103be1ef3d3Smacallan		pDGAMode->flags = DGA_CONCURRENT_ACCESS | DGA_PIXMAP_AVAILABLE;
1104be1ef3d3Smacallan		pDGAMode->byteOrder = pScrn->imageByteOrder;
1105be1ef3d3Smacallan		pDGAMode->depth = pScrn->depth;
1106be1ef3d3Smacallan		pDGAMode->bitsPerPixel = pScrn->bitsPerPixel;
1107be1ef3d3Smacallan		pDGAMode->red_mask = pScrn->mask.red;
1108be1ef3d3Smacallan		pDGAMode->green_mask = pScrn->mask.green;
1109be1ef3d3Smacallan		pDGAMode->blue_mask = pScrn->mask.blue;
1110be1ef3d3Smacallan		pDGAMode->visualClass = pScrn->bitsPerPixel > 8 ?
1111be1ef3d3Smacallan			TrueColor : PseudoColor;
1112be1ef3d3Smacallan		pDGAMode->xViewportStep = 1;
1113be1ef3d3Smacallan		pDGAMode->yViewportStep = 1;
1114be1ef3d3Smacallan		pDGAMode->viewportWidth = pMode->HDisplay;
1115be1ef3d3Smacallan		pDGAMode->viewportHeight = pMode->VDisplay;
1116be1ef3d3Smacallan
1117be1ef3d3Smacallan		if (fPtr->linebytes)
1118be1ef3d3Smacallan			pDGAMode->bytesPerScanline = fPtr->linebytes;
1119be1ef3d3Smacallan		else {
1120be1ef3d3Smacallan			ioctl(fPtr->fd, WSDISPLAYIO_LINEBYTES,
1121be1ef3d3Smacallan			      &fPtr->linebytes);
1122be1ef3d3Smacallan			pDGAMode->bytesPerScanline = fPtr->linebytes;
1123be1ef3d3Smacallan		}
1124be1ef3d3Smacallan
1125be1ef3d3Smacallan		pDGAMode->imageWidth = pMode->HDisplay;
1126be1ef3d3Smacallan		pDGAMode->imageHeight =  pMode->VDisplay;
1127be1ef3d3Smacallan		pDGAMode->pixmapWidth = pDGAMode->imageWidth;
1128be1ef3d3Smacallan		pDGAMode->pixmapHeight = pDGAMode->imageHeight;
1129be1ef3d3Smacallan		pDGAMode->maxViewportX = pScrn->virtualX -
1130be1ef3d3Smacallan			pDGAMode->viewportWidth;
1131be1ef3d3Smacallan		pDGAMode->maxViewportY = pScrn->virtualY -
1132be1ef3d3Smacallan			pDGAMode->viewportHeight;
1133be1ef3d3Smacallan
1134be1ef3d3Smacallan		pDGAMode->address = fPtr->fbstart;
1135be1ef3d3Smacallan
1136be1ef3d3Smacallan		pMode = pMode->next;
1137be1ef3d3Smacallan	} while (pMode != pScrn->modes);
1138be1ef3d3Smacallan}
1139be1ef3d3Smacallan
1140be1ef3d3Smacallanstatic Bool
1141be1ef3d3SmacallanIgsDGAInit(ScrnInfoPtr pScrn, ScreenPtr pScreen)
1142be1ef3d3Smacallan{
1143be1ef3d3Smacallan	IgsPtr fPtr = IGSPTR(pScrn);
1144be1ef3d3Smacallan
1145be1ef3d3Smacallan	if (pScrn->depth < 8)
1146be1ef3d3Smacallan		return FALSE;
1147be1ef3d3Smacallan
1148be1ef3d3Smacallan	if (!fPtr->nDGAMode)
1149be1ef3d3Smacallan		IgsDGAAddModes(pScrn);
1150be1ef3d3Smacallan
1151be1ef3d3Smacallan	return (DGAInit(pScreen, &IgsDGAFunctions,
1152be1ef3d3Smacallan			fPtr->pDGAMode, fPtr->nDGAMode));
1153be1ef3d3Smacallan}
1154be1ef3d3Smacallan#endif
1155be1ef3d3Smacallan
1156be1ef3d3Smacallanstatic Bool
1157be1ef3d3SmacallanIgsDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op,
1158be1ef3d3Smacallan    pointer ptr)
1159be1ef3d3Smacallan{
1160be1ef3d3Smacallan	xorgHWFlags *flag;
1161be1ef3d3Smacallan
1162be1ef3d3Smacallan	switch (op) {
1163be1ef3d3Smacallan	case GET_REQUIRED_HW_INTERFACES:
1164be1ef3d3Smacallan		flag = (CARD32*)ptr;
1165be1ef3d3Smacallan		(*flag) = 0;
1166be1ef3d3Smacallan		return TRUE;
1167be1ef3d3Smacallan	default:
1168be1ef3d3Smacallan		return FALSE;
1169be1ef3d3Smacallan	}
1170be1ef3d3Smacallan}
1171be1ef3d3Smacallan
1172