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>
32 #include "xf86_OSproc.h"
34 #include "xf86RamDacPriv.h"
36 int RamDacHWPrivateIndex
= -1;
37 int RamDacScreenPrivateIndex
= -1;
40 RamDacCreateInfoRec(void)
44 infoRec
= calloc(1, sizeof(RamDacRec
));
50 RamDacHelperCreateInfoRec(void)
52 RamDacHelperRecPtr infoRec
;
54 infoRec
= calloc(1, sizeof(RamDacHelperRec
));
60 RamDacDestroyInfoRec(RamDacRecPtr infoRec
)
66 RamDacHelperDestroyInfoRec(RamDacHelperRecPtr infoRec
)
72 RamDacInit(ScrnInfoPtr pScrn
, RamDacRecPtr ramdacPriv
)
74 RamDacScreenRecPtr ramdacScrPtr
;
77 * make sure the RamDacRec is allocated
79 if (!RamDacGetRec(pScrn
))
82 ((RamDacScreenRecPtr
) (pScrn
)->privates
[RamDacGetScreenIndex()].ptr
);
83 ramdacScrPtr
->RamDacRec
= ramdacPriv
;
89 RamDacGetRecPrivate(void)
91 if (RamDacHWPrivateIndex
< 0)
92 RamDacHWPrivateIndex
= xf86AllocateScrnInfoPrivateIndex();
93 if (RamDacScreenPrivateIndex
< 0)
94 RamDacScreenPrivateIndex
= xf86AllocateScrnInfoPrivateIndex();
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
)
108 if (scrp
->privates
[RamDacScreenPrivateIndex
].ptr
!= NULL
)
111 scrp
->privates
[RamDacHWPrivateIndex
].ptr
=
112 xnfcalloc(sizeof(RamDacHWRec
), 1);
113 scrp
->privates
[RamDacScreenPrivateIndex
].ptr
=
114 xnfcalloc(sizeof(RamDacScreenRec
), 1);
120 RamDacFreeRec(ScrnInfoPtr pScrn
)
122 RamDacHWRecPtr ramdacHWPtr
;
123 RamDacScreenRecPtr ramdacScrPtr
;
125 if (RamDacHWPrivateIndex
< 0)
128 if (RamDacScreenPrivateIndex
< 0)
131 ramdacHWPtr
= RAMDACHWPTR(pScrn
);
132 ramdacScrPtr
= ((RamDacScreenRecPtr
)
133 (pScrn
)->privates
[RamDacGetScreenIndex()].ptr
);
143 RamDacGetHWIndex(void)
145 return RamDacHWPrivateIndex
;
149 RamDacGetScreenIndex(void)
151 return RamDacScreenPrivateIndex
;