Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1029 serge 1
/*
2
 * Copyright 2007-2008  Luc Verhaegen 
3
 * Copyright 2007-2008  Matthias Hopf 
4
 * Copyright 2007-2008  Egbert Eich   
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
 * and/or sell copies of the Software, and to permit persons to whom the
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
 * OTHER DEALINGS IN THE SOFTWARE.
23
 */
24
 
25
#ifdef HAVE_CONFIG_H
26
#include "config.h"
27
#endif
28
 
29
#include "xf86.h"
30
#if HAVE_XF86_ANSIC_H
31
# include "xf86_ansic.h"
32
#endif
33
 
34
#include "rhd.h"
35
#include "rhd_vga.h"
36
#include "rhd_regs.h"
37
#include "rhd_mc.h"
38
 
39
struct rhdVGA {
40
    Bool Stored;
41
 
42
    CARD32 FBOffset;
43
    CARD8 *FB;
44
    int FBSize; /* 256kB */
45
 
46
    CARD32 Render_Control;
47
    CARD32 Mode_Control;
48
    CARD32 HDP_Control;
49
    CARD32 D1_Control;
50
    CARD32 D2_Control;
51
};
52
 
53
/*
54
 *
55
 */
56
void
57
RHDVGAInit(RHDPtr rhdPtr)
58
{
59
    struct rhdVGA *VGA;
60
 
61
    RHDFUNC(rhdPtr);
62
 
63
  /* Check whether one of our VGA bits is set */
64
  if (!(_RHDRegRead(rhdPtr, VGA_RENDER_CONTROL) & 0x00030000) &&
65
       (_RHDRegRead(rhdPtr, VGA_HDP_CONTROL) & 0x00000010) &&
66
      !(_RHDRegRead(rhdPtr, D1VGA_CONTROL) & 0x00000001) &&
67
      !(_RHDRegRead(rhdPtr, D2VGA_CONTROL) & 0x00000001))
68
	return;
69
 
70
    xf86DrvMsg(rhdPtr->scrnIndex, X_INFO, "Detected VGA mode.\n");
71
 
72
    VGA = xnfcalloc(sizeof(struct rhdVGA), 1);
73
    VGA->Stored = FALSE;
74
 
75
    rhdPtr->VGA = VGA;
76
}
77
 
78
#if 0
79
/*
80
 *
81
 */
82
static CARD32
83
rhdVGAFBOffsetGet(RHDPtr rhdPtr)
84
{
85
    CARD32 FBSize, VGAFBOffset, VGAFBSize = 256 * 1024;
86
    CARD64 FBAddress = RHDMCGetFBLocation(rhdPtr, &FBSize);
87
    CARD64 VGAFBAddress = RHDRegRead(rhdPtr, VGA_MEMORY_BASE_ADDRESS);
88
 
89
    if (VGAFBAddress < FBAddress)
90
	return 0xFFFFFFFF;
91
 
92
    if ((VGAFBAddress + VGAFBSize) > (FBAddress + FBSize))
93
	return 0xFFFFFFFF;
94
 
95
    VGAFBOffset = VGAFBAddress - FBAddress; /* < FBSize, so 32bit */
96
 
97
    if ((VGAFBOffset + VGAFBSize) >= rhdPtr->FbMapSize)
98
	return 0xFFFFFFFF;
99
 
100
    return VGAFBOffset;
101
}
102
 
103
/*
104
 * This is (usually) ok, as VGASave is called after the memory has been mapped,
105
 * but before the MC is set up. So the use of RHDMCGetFBLocation is correct in
106
 * rhdVGAFBOffsetGet.
107
 */
108
static void
109
rhdVGASaveFB(RHDPtr rhdPtr)
110
{
111
    struct rhdVGA *VGA = rhdPtr->VGA;
112
 
113
    ASSERT(rhdPtr->FbBase);
114
 
115
    RHDFUNC(rhdPtr);
116
 
117
    VGA->FBOffset = rhdVGAFBOffsetGet(rhdPtr);
118
 
119
    if (VGA->FBOffset == 0xFFFFFFFF) {
120
	xf86DrvMsg(rhdPtr->scrnIndex, X_WARNING, "%s: Unable to access the VGA "
121
		   "framebuffer (0x%08X)\n", __func__,
122
		   (unsigned int) RHDRegRead(rhdPtr, VGA_MEMORY_BASE_ADDRESS));
123
	if (VGA->FB)
124
	    xfree(VGA->FB);
125
	VGA->FB = NULL;
126
	VGA->FBSize = 0;
127
	return;
128
    }
129
 
130
    VGA->FBSize = 256 * 1024;
131
 
132
    RHDDebug(rhdPtr->scrnIndex, "%s: VGA FB Offset 0x%08X [0x%08X]\n",
133
	     __func__, VGA->FBOffset, VGA->FBSize);
134
 
135
    if (!VGA->FB)
136
	VGA->FB = xcalloc(VGA->FBSize, 1);
137
 
138
	if (VGA->FB)
139
	    memcpy(VGA->FB, ((CARD8 *) rhdPtr->FbBase) + VGA->FBOffset,
140
		   VGA->FBSize);
141
	else {
142
	xf86DrvMsg(rhdPtr->scrnIndex, X_WARNING, "%s: Failed to allocate"
143
                " space for storing the VGA framebuffer.\n", __func__);
144
	VGA->FBOffset = 0xFFFFFFFF;
145
	VGA->FBSize = 0;
146
    }
147
}
148
 
149
/*
150
 *
151
 */
152
void
153
RHDVGASave(RHDPtr rhdPtr)
154
{
155
    struct rhdVGA *VGA = rhdPtr->VGA;
156
 
157
    RHDFUNC(rhdPtr);
158
 
159
    if (!VGA)
160
	return; /* We don't need to warn , this is intended use */
161
 
162
    VGA->Render_Control = RHDRegRead(rhdPtr, VGA_RENDER_CONTROL);
163
    VGA->Mode_Control = RHDRegRead(rhdPtr, VGA_MODE_CONTROL);
164
    VGA->HDP_Control = RHDRegRead(rhdPtr, VGA_HDP_CONTROL);
165
    VGA->D1_Control = RHDRegRead(rhdPtr, D1VGA_CONTROL);
166
    VGA->D2_Control = RHDRegRead(rhdPtr, D2VGA_CONTROL);
167
 
168
    rhdVGASaveFB(rhdPtr);
169
    VGA->Stored = TRUE;
170
}
171
 
172
/*
173
 *
174
 */
175
void
176
RHDVGARestore(RHDPtr rhdPtr)
177
{
178
    struct rhdVGA *VGA = rhdPtr->VGA;
179
 
180
    RHDFUNC(rhdPtr);
181
 
182
    if (!VGA)
183
	return; /* We don't need to warn , this is intended use */
184
 
185
    if (!VGA->Stored) {
186
	xf86DrvMsg(rhdPtr->scrnIndex, X_ERROR,
187
		   "%s: trying to restore uninitialized values.\n", __func__);
188
	return;
189
    }
190
 
191
    if (VGA->FB)
192
	memcpy(((CARD8 *) rhdPtr->FbBase) + VGA->FBOffset, VGA->FB,
193
	       VGA->FBSize);
194
 
195
    RHDRegWrite(rhdPtr, VGA_RENDER_CONTROL, VGA->Render_Control);
196
    RHDRegWrite(rhdPtr, VGA_MODE_CONTROL, VGA->Mode_Control);
197
    RHDRegWrite(rhdPtr, VGA_HDP_CONTROL, VGA->HDP_Control);
198
    RHDRegWrite(rhdPtr, D1VGA_CONTROL, VGA->D1_Control);
199
    RHDRegWrite(rhdPtr, D2VGA_CONTROL, VGA->D2_Control);
200
    RHD_UNSETDEBUGFLAG(rhdPtr, VGA_SETUP);
201
}
202
#endif
203
/*
204
 *
205
 */
206
void
207
RHDVGADisable(RHDPtr rhdPtr)
208
{
209
    RHDFUNC(rhdPtr);
210
 
211
    _RHDRegMask(rhdPtr, VGA_RENDER_CONTROL, 0, 0x00030000);
212
    _RHDRegMask(rhdPtr, VGA_MODE_CONTROL, 0, 0x00000030);
213
    _RHDRegMask(rhdPtr, VGA_HDP_CONTROL, 0x00010010, 0x00010010);
214
    RHDRegMask(rhdPtr, D1VGA_CONTROL, 0, D1VGA_MODE_ENABLE);
215
    RHDRegMask(rhdPtr, D2VGA_CONTROL, 0, D2VGA_MODE_ENABLE);
216
}
217
 
218
/*
219
 *
220
 */
221
void
222
RHDVGADestroy(RHDPtr rhdPtr)
223
{
224
    struct rhdVGA *VGA = rhdPtr->VGA;
225
 
226
    RHDFUNC(rhdPtr);
227
 
228
    if (!VGA)
229
      return; /* We don't need to warn , this is intended use */
230
 
231
    if (VGA->FB)
232
	xfree(VGA->FB);
233
    xfree(VGA);
234
}
235