Initial commit
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / ramdac / xf86RamDac.c
blob1dd3daf1b7fe1f5d981c426856f9d7d96303dd26
1 /*
2 * Copyright 1998 by Alan Hourihane, Wigan, England.
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Alan Hourihane not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Alan Hourihane makes no representations
11 * about the suitability of this software for any purpose. It is provided
12 * "as is" without express or implied warranty.
14 * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
22 * Authors: Alan Hourihane, <alanh@fairlite.demon.co.uk>
24 * Generic RAMDAC access routines.
27 #ifdef HAVE_XORG_CONFIG_H
28 #include <xorg-config.h>
29 #endif
31 #include "xf86.h"
32 #include "xf86_OSproc.h"
34 #include "xf86RamDacPriv.h"
36 int RamDacHWPrivateIndex = -1;
37 int RamDacScreenPrivateIndex = -1;
39 RamDacRecPtr
40 RamDacCreateInfoRec()
42 RamDacRecPtr infoRec;
44 infoRec = xcalloc(1, sizeof(RamDacRec));
46 return infoRec;
49 RamDacHelperRecPtr
50 RamDacHelperCreateInfoRec()
52 RamDacHelperRecPtr infoRec;
54 infoRec = xcalloc(1, sizeof(RamDacHelperRec));
56 return infoRec;
59 void
60 RamDacDestroyInfoRec(RamDacRecPtr infoRec)
62 xfree(infoRec);
65 void
66 RamDacHelperDestroyInfoRec(RamDacHelperRecPtr infoRec)
68 xfree(infoRec);
71 Bool
72 RamDacInit(ScrnInfoPtr pScrn, RamDacRecPtr ramdacPriv)
74 RamDacScreenRecPtr ramdacScrPtr;
77 * make sure the RamDacRec is allocated
79 if (!RamDacGetRec(pScrn))
80 return FALSE;
81 ramdacScrPtr =
82 ((RamDacScreenRecPtr) (pScrn)->privates[RamDacGetScreenIndex()].ptr);
83 ramdacScrPtr->RamDacRec = ramdacPriv;
85 return(TRUE);
88 void
89 RamDacGetRecPrivate()
91 if (RamDacHWPrivateIndex < 0)
92 RamDacHWPrivateIndex = xf86AllocateScrnInfoPrivateIndex();
93 if (RamDacScreenPrivateIndex < 0)
94 RamDacScreenPrivateIndex = xf86AllocateScrnInfoPrivateIndex();
95 return;
98 Bool
99 RamDacGetRec(ScrnInfoPtr scrp)
101 RamDacGetRecPrivate();
103 * New privates are always set to NULL, so we can check if the allocation
104 * has already been done.
106 if (scrp->privates[RamDacHWPrivateIndex].ptr != NULL)
107 return TRUE;
108 if (scrp->privates[RamDacScreenPrivateIndex].ptr != NULL)
109 return TRUE;
111 scrp->privates[RamDacHWPrivateIndex].ptr =
112 xnfcalloc(sizeof(RamDacHWRec), 1);
113 scrp->privates[RamDacScreenPrivateIndex].ptr =
114 xnfcalloc(sizeof(RamDacScreenRec), 1);
116 return TRUE;
119 void
120 RamDacFreeRec(ScrnInfoPtr pScrn)
122 RamDacHWRecPtr ramdacHWPtr;
123 RamDacScreenRecPtr ramdacScrPtr;
125 if (RamDacHWPrivateIndex < 0)
126 return;
128 if (RamDacScreenPrivateIndex < 0)
129 return;
131 ramdacHWPtr = RAMDACHWPTR(pScrn);
132 ramdacScrPtr = ((RamDacScreenRecPtr)
133 (pScrn)->privates[RamDacGetScreenIndex()].ptr);
135 if (ramdacHWPtr)
136 xfree(ramdacHWPtr);
137 ramdacHWPtr = NULL;
139 if (ramdacScrPtr)
140 xfree(ramdacScrPtr);
141 ramdacScrPtr = NULL;
145 RamDacGetHWIndex()
147 return RamDacHWPrivateIndex;
151 RamDacGetScreenIndex()
153 return RamDacScreenPrivateIndex;