]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/xserver.git/blob - hw/xfree86/ramdac/xf86RamDac.c
Imported Upstream version 1.11.4
[glsdk/xserver.git] / hw / xfree86 / ramdac / xf86RamDac.c
1 /*
2  * Copyright 1998 by Alan Hourihane, Wigan, England.
3  *
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.
13  *
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.
21  *
22  * Authors:  Alan Hourihane, <alanh@fairlite.demon.co.uk>
23  *
24  * Generic RAMDAC access routines.
25  */
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(void)
41 {
42     RamDacRecPtr infoRec;
44     infoRec = calloc(1, sizeof(RamDacRec));
46     return infoRec;
47 }
49 RamDacHelperRecPtr
50 RamDacHelperCreateInfoRec(void)
51 {
52     RamDacHelperRecPtr infoRec;
54     infoRec = calloc(1, sizeof(RamDacHelperRec));
56     return infoRec;
57 }
59 void
60 RamDacDestroyInfoRec(RamDacRecPtr infoRec)
61 {
62     free(infoRec);
63 }
65 void
66 RamDacHelperDestroyInfoRec(RamDacHelperRecPtr infoRec)
67 {
68     free(infoRec);
69 }
71 Bool
72 RamDacInit(ScrnInfoPtr pScrn, RamDacRecPtr ramdacPriv)
73 {
74     RamDacScreenRecPtr ramdacScrPtr;
76     /*
77      * make sure the RamDacRec is allocated
78      */
79     if (!RamDacGetRec(pScrn))
80         return FALSE;
81     ramdacScrPtr =
82         ((RamDacScreenRecPtr) (pScrn)->privates[RamDacGetScreenIndex()].ptr);
83     ramdacScrPtr->RamDacRec = ramdacPriv;
85     return TRUE;
86 }
88 void
89 RamDacGetRecPrivate(void)
90 {
91     if (RamDacHWPrivateIndex < 0)
92         RamDacHWPrivateIndex = xf86AllocateScrnInfoPrivateIndex();
93     if (RamDacScreenPrivateIndex < 0)
94         RamDacScreenPrivateIndex = xf86AllocateScrnInfoPrivateIndex();
95     return;
96 }
98 Bool
99 RamDacGetRec(ScrnInfoPtr scrp)
101     RamDacGetRecPrivate();
102     /*
103      * New privates are always set to NULL, so we can check if the allocation
104      * has already been done.
105      */
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);
115     
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);
134     
135     free(ramdacHWPtr);
136     ramdacHWPtr = NULL;
138     free(ramdacScrPtr);
139     ramdacScrPtr = NULL;
142 int
143 RamDacGetHWIndex(void)
145     return RamDacHWPrivateIndex;
148 int
149 RamDacGetScreenIndex(void)
151     return RamDacScreenPrivateIndex;