1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
/*
* Copyright 1996-1997 David J. McKay
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* DAVID J. MCKAY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/* Hacked together from mga driver and 3.3.4 NVIDIA driver by Jarno Paananen
<jpaana@s2.org> */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "riva_include.h"
/*
* Override VGA I/O routines.
*/
static void RivaWriteCrtc(vgaHWPtr pVga, CARD8 index, CARD8 value)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
VGA_WR08(pRiva->riva.PCIO, pVga->IOBase + VGA_CRTC_INDEX_OFFSET, index);
VGA_WR08(pRiva->riva.PCIO, pVga->IOBase + VGA_CRTC_DATA_OFFSET, value);
}
static CARD8 RivaReadCrtc(vgaHWPtr pVga, CARD8 index)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
VGA_WR08(pRiva->riva.PCIO, pVga->IOBase + VGA_CRTC_INDEX_OFFSET, index);
return (VGA_RD08(pRiva->riva.PCIO, pVga->IOBase + VGA_CRTC_DATA_OFFSET));
}
static void RivaWriteGr(vgaHWPtr pVga, CARD8 index, CARD8 value)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
VGA_WR08(pRiva->riva.PVIO, VGA_GRAPH_INDEX, index);
VGA_WR08(pRiva->riva.PVIO, VGA_GRAPH_DATA, value);
}
static CARD8 RivaReadGr(vgaHWPtr pVga, CARD8 index)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
VGA_WR08(pRiva->riva.PVIO, VGA_GRAPH_INDEX, index);
return (VGA_RD08(pRiva->riva.PVIO, VGA_GRAPH_DATA));
}
static void RivaWriteSeq(vgaHWPtr pVga, CARD8 index, CARD8 value)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
VGA_WR08(pRiva->riva.PVIO, VGA_SEQ_INDEX, index);
VGA_WR08(pRiva->riva.PVIO, VGA_SEQ_DATA, value);
}
static CARD8 RivaReadSeq(vgaHWPtr pVga, CARD8 index)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
VGA_WR08(pRiva->riva.PVIO, VGA_SEQ_INDEX, index);
return (VGA_RD08(pRiva->riva.PVIO, VGA_SEQ_DATA));
}
static void RivaWriteAttr(vgaHWPtr pVga, CARD8 index, CARD8 value)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
volatile CARD8 tmp;
tmp = VGA_RD08(pRiva->riva.PCIO, pVga->IOBase + VGA_IN_STAT_1_OFFSET);
if (pVga->paletteEnabled)
index &= ~0x20;
else
index |= 0x20;
VGA_WR08(pRiva->riva.PCIO, VGA_ATTR_INDEX, index);
VGA_WR08(pRiva->riva.PCIO, VGA_ATTR_DATA_W, value);
}
static CARD8 RivaReadAttr(vgaHWPtr pVga, CARD8 index)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
volatile CARD8 tmp;
tmp = VGA_RD08(pRiva->riva.PCIO, pVga->IOBase + VGA_IN_STAT_1_OFFSET);
if (pVga->paletteEnabled)
index &= ~0x20;
else
index |= 0x20;
VGA_WR08(pRiva->riva.PCIO, VGA_ATTR_INDEX, index);
return (VGA_RD08(pRiva->riva.PCIO, VGA_ATTR_DATA_R));
}
static void RivaWriteMiscOut(vgaHWPtr pVga, CARD8 value)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
VGA_WR08(pRiva->riva.PVIO, VGA_MISC_OUT_W, value);
}
static CARD8 RivaReadMiscOut(vgaHWPtr pVga)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
return (VGA_RD08(pRiva->riva.PVIO, VGA_MISC_OUT_R));
}
static void RivaEnablePalette(vgaHWPtr pVga)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
volatile CARD8 tmp;
tmp = VGA_RD08(pRiva->riva.PCIO, pVga->IOBase + VGA_IN_STAT_1_OFFSET);
VGA_WR08(pRiva->riva.PCIO, VGA_ATTR_INDEX, 0x00);
pVga->paletteEnabled = TRUE;
}
static void RivaDisablePalette(vgaHWPtr pVga)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
volatile CARD8 tmp;
tmp = VGA_RD08(pRiva->riva.PCIO, pVga->IOBase + VGA_IN_STAT_1_OFFSET);
VGA_WR08(pRiva->riva.PCIO, VGA_ATTR_INDEX, 0x20);
pVga->paletteEnabled = FALSE;
}
static void RivaWriteDacMask(vgaHWPtr pVga, CARD8 value)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
VGA_WR08(pRiva->riva.PDIO, VGA_DAC_MASK, value);
}
static CARD8 RivaReadDacMask(vgaHWPtr pVga)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
return (VGA_RD08(pRiva->riva.PDIO, VGA_DAC_MASK));
}
static void RivaWriteDacReadAddr(vgaHWPtr pVga, CARD8 value)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
VGA_WR08(pRiva->riva.PDIO, VGA_DAC_READ_ADDR, value);
}
static void RivaWriteDacWriteAddr(vgaHWPtr pVga, CARD8 value)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
VGA_WR08(pRiva->riva.PDIO, VGA_DAC_WRITE_ADDR, value);
}
static void RivaWriteDacData(vgaHWPtr pVga, CARD8 value)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
VGA_WR08(pRiva->riva.PDIO, VGA_DAC_DATA, value);
}
static CARD8 RivaReadDacData(vgaHWPtr pVga)
{
RivaPtr pRiva = (RivaPtr)pVga->MMIOBase;
return (VGA_RD08(pRiva->riva.PDIO, VGA_DAC_DATA));
}
static xf86MonPtr
RivaProbeDDC (ScrnInfoPtr pScrn)
{
RivaPtr pRiva = RivaPTR(pScrn);
xf86MonPtr MonInfo = NULL;
if(!pRiva->I2C) return NULL;
pRiva->DDCBase = 0x3e;
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Probing for EDID...\n");
#ifdef EDID_COMPLETE_RAWDATA
MonInfo = xf86DoEEDID(pScrn->scrnIndex, pNv->I2C, TRUE);
#else
MonInfo = xf86DoEDID_DDC2(pScrn->scrnIndex, pNv->I2C);
#endif
if (MonInfo) {
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
" ... found one\n");
xf86PrintEDID( MonInfo );
} else {
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
" ... none found\n");
}
return MonInfo;
}
void
Riva3Setup(ScrnInfoPtr pScrn)
{
RivaPtr pRiva = RivaPTR(pScrn);
vgaHWPtr pVga = VGAHWPTR(pScrn);
CARD32 regBase = pRiva->IOAddress;
CARD32 frameBase = pRiva->FbAddress;
xf86MonPtr monitor;
pRiva->Save = RivaDACSave;
pRiva->Restore = RivaDACRestore;
pRiva->ModeInit = RivaDACInit;
pRiva->Dac.LoadPalette = RivaDACLoadPalette;
/*
* Override VGA I/O routines.
*/
pVga->writeCrtc = RivaWriteCrtc;
pVga->readCrtc = RivaReadCrtc;
pVga->writeGr = RivaWriteGr;
pVga->readGr = RivaReadGr;
pVga->writeAttr = RivaWriteAttr;
pVga->readAttr = RivaReadAttr;
pVga->writeSeq = RivaWriteSeq;
pVga->readSeq = RivaReadSeq;
pVga->writeMiscOut = RivaWriteMiscOut;
pVga->readMiscOut = RivaReadMiscOut;
pVga->enablePalette = RivaEnablePalette;
pVga->disablePalette = RivaDisablePalette;
pVga->writeDacMask = RivaWriteDacMask;
pVga->readDacMask = RivaReadDacMask;
pVga->writeDacWriteAddr = RivaWriteDacWriteAddr;
pVga->writeDacReadAddr = RivaWriteDacReadAddr;
pVga->writeDacData = RivaWriteDacData;
pVga->readDacData = RivaReadDacData;
/*
* Note: There are different pointers to the CRTC/AR and GR/SEQ registers.
* Bastardize the intended uses of these to make it work.
*/
pVga->MMIOBase = (CARD8 *)pRiva;
pVga->MMIOOffset = 0;
/*
* No IRQ in use.
*/
pRiva->riva.EnableIRQ = 0;
pRiva->riva.IO = VGA_IOBASE_COLOR;
#if XSERVER_LIBPCIACCESS
#define MAP(ptr, offset, size) { \
void *tmp; \
pci_device_map_range(pRiva->PciInfo, (offset), (size), \
PCI_DEV_MAP_FLAG_WRITABLE, &tmp); \
pRiva->riva.ptr = tmp; \
}
#else
#define MAP(ptr, offset, size) \
pRiva->riva.ptr = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_MMIO | \
VIDMEM_READSIDEEFFECT, pRiva->PciTag, \
(offset), (size));
#endif
MAP(PRAMDAC, regBase + 0x00680000, 0x00003000);
MAP(PFB, regBase + 0x00100000, 0x00001000);
MAP(PFIFO, regBase + 0x00002000, 0x00002000);
MAP(PGRAPH, regBase + 0x00400000, 0x00002000);
MAP(PEXTDEV, regBase + 0x00101000, 0x00001000);
MAP(PTIMER, regBase + 0x00009000, 0x00001000);
MAP(PMC, regBase + 0x00000000, 0x00009000);
MAP(FIFO, regBase + 0x00800000, 0x00010000);
MAP(PRAMIN, frameBase+0x00C00000, 0x00008000);
/*
* These registers are read/write as 8 bit values. Probably have to map
* sparse on alpha.
*/
MAP(PCIO, regBase + 0x00601000, 0x00003000);
MAP(PDIO, regBase + 0x00681000, 0x00003000);
MAP(PVIO, regBase + 0x000C0000, 0x00001000);
#undef MAP
pRiva->riva.PCRTC = pRiva->riva.PGRAPH;
RivaGetConfig(pRiva);
pRiva->riva.LockUnlock(&pRiva->riva, 0);
RivaI2CInit(pScrn);
monitor = RivaProbeDDC(pScrn);
if(monitor)
xf86SetDDCproperties(pScrn, monitor);
pRiva->Dac.maxPixelClock = pRiva->riva.MaxVClockFreqKHz;
}
|