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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
|
/*
* Copyright 1997 through 2004 by Marc Aurele La France (TSI @ UQV), tsi@xfree86.org
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of Marc Aurele La France not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. Marc Aurele La France makes no representations
* about the suitability of this software for any purpose. It is provided
* "as-is" without express or implied warranty.
*
* MARC AURELE LA FRANCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
* EVENT SHALL MARC AURELE LA FRANCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <stdio.h>
#include "ati.h"
#include "atibus.h"
#include "atichip.h"
#include "atimach64io.h"
#include "atimodule.h"
#include "atiprobe.h"
#include "ativersion.h"
#include "atividmem.h"
#include "atiwonderio.h"
#ifndef AVOID_CPIO
/*
* ATIVGAWonderProbe --
*
* This function determines if ATI extended VGA registers can be accessed
* through the I/O port specified by pATI->CPIO_VGAWonder. If not, the
* function resets pATI->CPIO_VGAWonder to zero.
*/
static void
ATIVGAWonderProbe
(
pciVideoPtr pVideo,
ATIPtr pATI
)
{
CARD8 IOValue1, IOValue2, IOValue3, IOValue4, IOValue5, IOValue6;
if (!pATI->OptionProbeSparse)
{
xf86Msg(X_WARNING,
ATI_NAME ": Expected VGA Wonder capability at I/O port"
" 0x%04lX will not be probed\n"
"set option \"probe_sparse\" to force probing.\n",
pATI->CPIO_VGAWonder);
pATI->CPIO_VGAWonder = 0;
return;
}
if (pVideo && !xf86IsPrimaryPci(pVideo) &&
(pATI->Chip <= ATI_CHIP_88800GXD))
{
/* Set up extended VGA register addressing */
PutReg(GRAX, 0x50U, GetByte(pATI->CPIO_VGAWonder, 0));
PutReg(GRAX, 0x51U, GetByte(pATI->CPIO_VGAWonder, 1) | 0x80U);
}
/*
* Register 0xBB is used by the BIOS to keep track of various
* things (monitor type, etc.). Except for 18800-x's, register
* 0xBC must be zero and causes the adapter to enter a test mode
* when written to with a non-zero value.
*/
IOValue1 = inb(pATI->CPIO_VGAWonder);
IOValue2 = ATIGetExtReg(IOValue1);
IOValue3 = ATIGetExtReg(0xBBU);
ATIPutExtReg(0xBBU, IOValue3 ^ 0xAAU);
IOValue4 = ATIGetExtReg(0xBBU);
ATIPutExtReg(0xBBU, IOValue3 ^ 0x55U);
IOValue5 = ATIGetExtReg(0xBBU);
ATIPutExtReg(0xBBU, IOValue3);
IOValue6 = ATIGetExtReg(0xBCU);
ATIPutExtReg(IOValue1, IOValue2);
if ((IOValue4 == (IOValue3 ^ 0xAAU)) &&
(IOValue5 == (IOValue3 ^ 0x55U)) &&
(IOValue6 == 0))
{
xf86MsgVerb(X_INFO, 3,
ATI_NAME ": VGA Wonder at I/O port 0x%04lX detected.\n",
pATI->CPIO_VGAWonder);
}
else
{
xf86Msg(X_WARNING,
ATI_NAME ": Expected VGA Wonder capability at I/O port"
" 0x%04lX was not detected.\n", pATI->CPIO_VGAWonder);
pATI->CPIO_VGAWonder = 0;
}
}
#endif /* AVOID_CPIO */
/*
* ATIMach64Detect --
*
* This function determines if a Mach64 is detectable at a particular base
* address.
*/
static Bool
ATIMach64Detect
(
ATIPtr pATI,
const CARD16 ChipType,
const ATIChipType Chip
)
{
CARD32 IOValue, bus_cntl, gen_test_cntl;
Bool DetectSuccess = FALSE;
(void)ATIMapApertures(-1, pATI); /* Ignore errors */
#ifdef AVOID_CPIO
if (!pATI->pBlock[0])
{
ATIUnmapApertures(-1, pATI);
return FALSE;
}
#endif /* AVOID_CPIO */
/* Make sure any Mach64 is not in some weird state */
bus_cntl = inr(BUS_CNTL);
if (Chip < ATI_CHIP_264VTB)
outr(BUS_CNTL,
(bus_cntl & ~(BUS_HOST_ERR_INT_EN | BUS_FIFO_ERR_INT_EN)) |
(BUS_HOST_ERR_INT | BUS_FIFO_ERR_INT));
else if (Chip < ATI_CHIP_264VT4)
outr(BUS_CNTL, (bus_cntl & ~BUS_HOST_ERR_INT_EN) | BUS_HOST_ERR_INT);
gen_test_cntl = inr(GEN_TEST_CNTL);
IOValue = gen_test_cntl &
(GEN_OVR_OUTPUT_EN | GEN_OVR_POLARITY | GEN_CUR_EN | GEN_BLOCK_WR_EN);
outr(GEN_TEST_CNTL, IOValue | GEN_GUI_EN);
outr(GEN_TEST_CNTL, IOValue);
outr(GEN_TEST_CNTL, IOValue | GEN_GUI_EN);
/* See if a Mach64 answers */
IOValue = inr(SCRATCH_REG0);
/* Test odd bits */
outr(SCRATCH_REG0, 0x55555555U);
if (inr(SCRATCH_REG0) == 0x55555555U)
{
/* Test even bits */
outr(SCRATCH_REG0, 0xAAAAAAAAU);
if (inr(SCRATCH_REG0) == 0xAAAAAAAAU)
{
/*
* *Something* has a R/W 32-bit register at this address. Try to
* make sure it's a Mach64. The following assumes that ATI will
* not be producing any more adapters that do not register
* themselves in PCI configuration space.
*/
ATIMach64ChipID(pATI, ChipType);
if ((pATI->Chip != ATI_CHIP_Mach64) ||
(pATI->CPIODecoding == BLOCK_IO))
DetectSuccess = TRUE;
}
}
/* Restore clobbered register value */
outr(SCRATCH_REG0, IOValue);
/* If no Mach64 was detected, return now */
if (!DetectSuccess)
{
outr(GEN_TEST_CNTL, gen_test_cntl);
outr(BUS_CNTL, bus_cntl);
ATIUnmapApertures(-1, pATI);
return FALSE;
}
/* Determine legacy BIOS address */
pATI->BIOSBase = 0x000C0000U +
(GetBits(inr(SCRATCH_REG1), BIOS_BASE_SEGMENT) << 11);
ATIUnmapApertures(-1, pATI);
return TRUE;
}
#ifdef AVOID_CPIO
/*
* ATIMach64Probe --
*
* This function looks for a Mach64 at a particular MMIO address and returns an
* ATIRec if one is found.
*/
static ATIPtr
ATIMach64Probe
(
ATIPtr pATI,
pciVideoPtr pVideo,
const ATIChipType Chip
)
{
CARD16 ChipType = PCI_DEV_DEVICE_ID(pVideo);
pATI->MMIOInLinear = FALSE;
/*
* Probe through auxiliary MMIO aperture if one exists. Because such
* apertures can be enabled/disabled only through PCI, this probes no
* further.
*/
if ((PCI_REGION_SIZE(pVideo, 2) >= (1 << 12)) &&
(pATI->Block0Base = PCI_REGION_BASE(pVideo, 2, REGION_MEM)))
{
pATI->Block0Base += 0x00000400U;
if (ATIMach64Detect(pATI, ChipType, Chip))
return pATI;
return NULL;
}
/*
* Probe through the primary MMIO aperture that exists at the tail end
* of the linear aperture. Test for both 8MB and 4MB linear apertures.
*/
if ((PCI_REGION_SIZE(pVideo, 0) >= (1 << 22)) &&
(pATI->Block0Base = PCI_REGION_BASE(pVideo, 0, REGION_MEM)))
{
pATI->MMIOInLinear = TRUE;
pATI->Block0Base += 0x007FFC00U;
if ((PCI_REGION_SIZE(pVideo, 0) >= (1 << 23)) &&
ATIMach64Detect(pATI, ChipType, Chip))
return pATI;
pATI->Block0Base -= 0x00400000U;
if (ATIMach64Detect(pATI, ChipType, Chip))
return pATI;
}
return NULL;
}
#else /* AVOID_CPIO */
/*
* ATIMach64Probe --
*
* This function looks for a Mach64 at a particular PIO address and returns an
* ATIRec if one is found.
*/
static ATIPtr
ATIMach64Probe
(
ATIPtr pATI,
pciVideoPtr pVideo,
const ATIChipType Chip
)
{
CARD32 IOValue;
CARD16 ChipType = PCI_DEV_DEVICE_ID(pVideo);
if ((pATI->CPIODecoding == BLOCK_IO) &&
(PCI_REGION_SIZE(pVideo, 1) < (1 << 8)))
return NULL;
if (!ATIMach64Detect(pATI, ChipType, Chip))
{
return NULL;
}
/*
* Determine VGA capability. VGA can always be enabled on integrated
* controllers. For the GX/CX, it's a board strap.
*/
if (pATI->Chip >= ATI_CHIP_264CT)
{
pATI->VGAAdapter = TRUE;
}
else
{
IOValue = inr(CONFIG_STATUS64_0);
pATI->BusType = GetBits(IOValue, CFG_BUS_TYPE);
IOValue &= (CFG_VGA_EN | CFG_CHIP_EN);
if (pATI->Chip == ATI_CHIP_88800CX)
IOValue |= CFG_VGA_EN;
if (IOValue == (CFG_VGA_EN | CFG_CHIP_EN))
{
pATI->VGAAdapter = TRUE;
pATI->CPIO_VGAWonder = 0x01CEU;
}
}
return pATI;
}
static void
ATIAssignVGA
(
pciVideoPtr pVideo,
ATIPtr pATI
)
{
if (pATI->CPIO_VGAWonder)
{
ATIVGAWonderProbe(pVideo, pATI);
if (!pATI->CPIO_VGAWonder)
{
/*
* Some adapters are reputed to append ATI extended VGA registers
* to the VGA Graphics controller registers. In particular, 0x01CE
* cannot, in general, be used in a PCI environment due to routing
* of I/O through the bus tree.
*/
pATI->CPIO_VGAWonder = GRAX;
ATIVGAWonderProbe(pVideo, pATI);
}
}
}
/*
* ATIFindVGA --
*
* This function determines if a VGA associated with an ATI PCI adapter is
* shareable.
*/
static void
ATIFindVGA
(
pciVideoPtr pVideo,
ATIPtr pATI
)
{
/*
* An ATI PCI adapter has been detected at this point, and its VGA, if
* any, is shareable. Ensure the VGA isn't in sleep mode.
*/
outb(GENENA, 0x16U);
outb(GENVS, 0x01U);
outb(GENENA, 0x0EU);
ATIAssignVGA(pVideo, pATI);
}
#endif /* AVOID_CPIO */
/*
* ATIMach64ProbeIO --
*
* This function determines the IO method and IO base of the ATI PCI adapter.
*/
Bool
ATIMach64ProbeIO
(
pciVideoPtr pVideo,
ATIPtr pATI
)
{
Bool ProbeSuccess = FALSE;
#ifndef AVOID_CPIO
/* Next, look for sparse I/O Mach64's */
if (!PCI_REGION_SIZE(pVideo, 1))
{
static const IOADDRESS Mach64SparseIOBases[] = {
0x02ECU,
0x01CCU,
0x01C8U
};
uint32_t PciReg;
uint32_t j;
pciConfigPtr pPCI = pVideo->thisCard;
if (pPCI == NULL)
goto SkipSparse;
PCI_READ_LONG(pVideo, &PciReg, PCI_REG_USERCONFIG);
j = PciReg & 0x03U;
if (j == 0x03U)
{
xf86Msg(X_WARNING, ATI_NAME ": "
"PCI Mach64 in slot %d:%d:%d cannot be enabled\n"
"because it has neither a block, nor a sparse, I/O base.\n",
PCI_DEV_BUS(pVideo), PCI_DEV_DEV(pVideo), PCI_DEV_FUNC(pVideo));
goto SkipSparse;
}
/* FIXME:
* Should not probe at sparse I/O bases which have been registered to
* other PCI devices. The old ATIProbe() would scan the PCI space and
* build a list of registered I/O ports. If there was a conflict
* between a mach64 sparse I/O base and a registered I/0 port, probing
* that port was not allowed...
*
* We just add an option and let the user decide, this will not work
* with "X -configure" though...
*/
if (!pATI->OptionProbeSparse)
{
xf86Msg(X_WARNING, ATI_NAME ": "
"PCI Mach64 in slot %d:%d:%d will not be probed\n"
"set option \"probe_sparse\" to force sparse I/O probing.\n",
PCI_DEV_BUS(pVideo), PCI_DEV_DEV(pVideo), PCI_DEV_FUNC(pVideo));
goto SkipSparse;
}
/* Possibly fix block I/O indicator */
if (PciReg & 0x00000004U)
{
PciReg &= ~0x00000004U;
PCI_WRITE_LONG(pVideo, PciReg, PCI_REG_USERCONFIG);
}
pATI->CPIOBase = Mach64SparseIOBases[j];
pATI->CPIODecoding = SPARSE_IO;
pATI->PCIInfo = pVideo;
if (!ATIMach64Probe(pATI, pVideo, pATI->Chip))
{
xf86Msg(X_WARNING, ATI_NAME ": "
"PCI Mach64 in slot %d:%d:%d could not be detected!\n",
PCI_DEV_BUS(pVideo), PCI_DEV_DEV(pVideo), PCI_DEV_FUNC(pVideo));
}
else
{
ProbeSuccess = TRUE;
xf86Msg(X_INFO, ATI_NAME ": "
"Shared PCI Mach64 in slot %d:%d:%d with sparse PIO base"
" 0x%04lX detected.\n",
PCI_DEV_BUS(pVideo), PCI_DEV_DEV(pVideo), PCI_DEV_FUNC(pVideo),
Mach64SparseIOBases[j]);
if (pATI->VGAAdapter)
ATIFindVGA(pVideo, pATI);
}
}
SkipSparse:
#else /* AVOID_CPIO */
if (!PCI_REGION_SIZE(pVideo, 1))
{
/* The adapter's CPIO base is of little concern here */
pATI->CPIOBase = 0;
pATI->CPIODecoding = SPARSE_IO;
pATI->PCIInfo = pVideo;
if (ATIMach64Probe(pATI, pVideo, pATI->Chip))
{
ProbeSuccess = TRUE;
xf86Msg(X_INFO, ATI_NAME ": "
"Shared PCI Mach64 in slot %d:%d:%d with Block 0 base"
" 0x%08lX detected.\n",
PCI_DEV_BUS(pVideo), PCI_DEV_DEV(pVideo), PCI_DEV_FUNC(pVideo),
pATI->Block0Base);
}
else
{
xf86Msg(X_WARNING, ATI_NAME ": "
"PCI Mach64 in slot %d:%d:%d could not be detected!\n",
PCI_DEV_BUS(pVideo), PCI_DEV_DEV(pVideo), PCI_DEV_FUNC(pVideo));
}
}
#endif /* AVOID_CPIO */
/* Lastly, look for block I/O devices */
if (PCI_REGION_SIZE(pVideo, 1))
{
pATI->CPIOBase = PCI_REGION_BASE(pVideo, 1, REGION_IO);
pATI->CPIODecoding = BLOCK_IO;
pATI->PCIInfo = pVideo;
if (ATIMach64Probe(pATI, pVideo, pATI->Chip))
{
ProbeSuccess = TRUE;
xf86Msg(X_INFO, ATI_NAME ": "
"Shared PCI/AGP Mach64 in slot %d:%d:%d detected.\n",
PCI_DEV_BUS(pVideo), PCI_DEV_DEV(pVideo), PCI_DEV_FUNC(pVideo));
#ifndef AVOID_CPIO
if (pATI->VGAAdapter)
ATIFindVGA(pVideo, pATI);
#endif /* AVOID_CPIO */
}
else
{
xf86Msg(X_WARNING, ATI_NAME ": "
"PCI/AGP Mach64 in slot %d:%d:%d could not be detected!\n",
PCI_DEV_BUS(pVideo), PCI_DEV_DEV(pVideo), PCI_DEV_FUNC(pVideo));
}
}
return ProbeSuccess;
}
|