aticonfig.c revision 0b0ce0bf
1/*
2 * Copyright 2000 through 2004 by Marc Aurele La France (TSI @ UQV), tsi@xfree86.org
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 copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of Marc Aurele La France not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission.  Marc Aurele La France 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 * MARC AURELE LA FRANCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO
16 * EVENT SHALL MARC AURELE LA FRANCE 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 * DRI support by:
23 *    Leif Delgass <ldelgass@retinalburn.net>
24 */
25
26#ifdef HAVE_CONFIG_H
27#include "config.h"
28#endif
29
30#include <string.h>
31
32#include "ati.h"
33#include "atichip.h"
34#include "aticursor.h"
35#include "atioption.h"
36#include "atistruct.h"
37
38#include "mach64_common.h"
39
40#ifdef TV_OUT
41
42/*
43 * List of supported TV standard names
44 */
45const char *ATITVStandardNames[ATI_TV_STDS_MAX_VALID+1] = {
46    "NTSC",
47    "PAL",
48    "PAL-M",
49    "PAL-60",
50    "NTSC-J",
51    "PAL-CN",
52    "PAL-N",
53    "Reserved1",
54    "Reserved2",
55    "SCART-PAL",
56    "None",
57    "Invalid"
58};
59
60#endif /* TV_OUT */
61
62/*
63 * Recognised XF86Config options.
64 */
65static const OptionInfoRec ATIPublicOptions[] =
66{
67    {
68        ATI_OPTION_PROBE_SPARSE,
69        "probe_sparse",
70        OPTV_BOOLEAN,
71        {0, },
72        FALSE
73    },
74    {
75        ATI_OPTION_ACCEL,
76        "accel",
77        OPTV_BOOLEAN,
78        {0, },
79        FALSE
80    },
81    {
82        ATI_OPTION_CRT_DISPLAY,
83        "crt_display",
84        OPTV_BOOLEAN,
85        {0, },
86        FALSE
87    },
88    {
89        ATI_OPTION_CSYNC,
90        "composite_sync",
91        OPTV_BOOLEAN,
92        {0, },
93        FALSE
94    },
95    {
96        ATI_OPTION_HWCURSOR,
97        "hw_cursor",
98        OPTV_BOOLEAN,
99        {0, },
100        FALSE,
101    },
102
103#ifdef XF86DRI_DEVEL
104
105    {
106        ATI_OPTION_IS_PCI,
107        "force_pci_mode",
108        OPTV_BOOLEAN,
109        {0, },
110        FALSE,
111    },
112    {
113        ATI_OPTION_DMA_MODE,
114        "dma_mode",
115        OPTV_STRING,
116        {0, },
117        FALSE,
118    },
119    {
120        ATI_OPTION_AGP_MODE,
121        "agp_mode",
122        OPTV_INTEGER,
123        {0, },
124        FALSE,
125    },
126    {
127        ATI_OPTION_AGP_SIZE,
128        "agp_size",
129        OPTV_INTEGER,
130        {0, },
131        FALSE,
132    },
133    {
134        ATI_OPTION_LOCAL_TEXTURES,
135        "local_textures",
136        OPTV_BOOLEAN,
137        {0, },
138        FALSE,
139    },
140    {
141        ATI_OPTION_BUFFER_SIZE,
142        "buffer_size",
143        OPTV_INTEGER,
144        {0, },
145        FALSE,
146    },
147
148#endif /* XF86DRI_DEVEL */
149
150#ifdef TV_OUT
151    {
152        ATI_OPTION_TV_OUT,
153        "tv_out",
154        OPTV_BOOLEAN,
155        {0, },
156        FALSE
157    },
158    {
159        ATI_OPTION_TV_STD,
160        "tv_standard",
161        OPTV_STRING,
162        {0, },
163        FALSE
164    },
165
166#endif /* TV_OUT */
167
168    {
169        ATI_OPTION_MMIO_CACHE,
170        "mmio_cache",
171        OPTV_BOOLEAN,
172        {0, },
173        FALSE
174    },
175
176
177    {
178        ATI_OPTION_TEST_MMIO_CACHE,
179        "test_mmio_cache",
180        OPTV_BOOLEAN,
181        {0, },
182        FALSE
183    },
184    {
185        ATI_OPTION_PANEL_DISPLAY,
186        "panel_display",
187        OPTV_BOOLEAN,
188        {0, },
189        FALSE
190    },
191    {
192        ATI_OPTION_REFERENCE_CLOCK,
193        "reference_clock",
194        OPTV_FREQ,
195        {0, },
196        FALSE
197    },
198    {
199        ATI_OPTION_SHADOW_FB,
200        "shadow_fb",
201        OPTV_BOOLEAN,
202        {0, },
203        FALSE
204    },
205    {
206        ATI_OPTION_SWCURSOR,
207        "sw_cursor",
208        OPTV_BOOLEAN,
209        {0, },
210        FALSE,
211    },
212    {
213        ATI_OPTION_ACCELMETHOD,
214        "AccelMethod",
215        OPTV_STRING,
216        {0, },
217        FALSE
218    },
219    {
220        ATI_OPTION_RENDER_ACCEL,
221        "RenderAccel",
222        OPTV_BOOLEAN,
223        {0, },
224        FALSE
225    },
226    {
227        -1,
228        NULL,
229        OPTV_NONE,
230        {0, },
231        FALSE
232    }
233};
234
235static const unsigned long ATIPublicOptionSize = SizeOf(ATIPublicOptions);
236
237const OptionInfoRec *
238ATIOptionsWeak(void) { return ATIPublicOptions; }
239
240/*
241 * Non-publicised XF86Config options.
242 */
243typedef enum
244{
245    ATI_OPTION_BIOS_DISPLAY,    /* Allow BIOS interference */
246    ATI_OPTION_CRT_SCREEN,      /* Legacy negation of "PanelDisplay" */
247    ATI_OPTION_DEVEL,           /* Intentionally undocumented */
248    ATI_OPTION_BLEND,           /* Force horizontal blending of small modes */
249    ATI_OPTION_LCDSYNC          /* Use XF86Config panel mode porches */
250} ATIPrivateOptionType;
251
252/*
253 * ATIProcessOptions --
254 *
255 * This function extracts options from what was parsed out of the XF86Config
256 * file.
257 */
258void
259ATIProcessOptions
260(
261    ScrnInfoPtr pScreenInfo,
262    ATIPtr      pATI
263)
264{
265    OptionInfoPtr PublicOption = xnfalloc(ATIPublicOptionSize);
266    OptionInfoRec PrivateOption[] =
267    {
268        {                       /* ON:  Let BIOS change display(s) */
269            ATI_OPTION_BIOS_DISPLAY,    /* OFF:  Don't */
270            "biosdisplay",
271            OPTV_BOOLEAN,
272            {0, },
273            FALSE
274        },
275        {                       /* Negation of "PanelDisplay" public option */
276            ATI_OPTION_CRT_SCREEN,
277            "crtscreen",
278            OPTV_BOOLEAN,
279            {0, },
280            FALSE
281        },
282        {                       /* ON:   Ease exploration of loose ends */
283            ATI_OPTION_DEVEL,   /* OFF:  Fit for public consumption */
284            "tsi",
285            OPTV_BOOLEAN,
286            {0, },
287            FALSE
288        },
289        {                       /* ON:   Horizontally blend most modes */
290            ATI_OPTION_BLEND,   /* OFF:  Use pixel replication more often */
291            "lcdblend",
292            OPTV_BOOLEAN,
293            {0, },
294            FALSE
295        },
296        {                       /* ON:   Use XF86Config porch timings */
297            ATI_OPTION_LCDSYNC, /* OFF:  Use porches from mode on entry */
298            "lcdsync",
299            OPTV_BOOLEAN,
300            {0, },
301            FALSE
302        },
303        {
304            -1,
305            NULL,
306            OPTV_NONE,
307            {0, },
308            FALSE
309        }
310    };
311
312    (void)memcpy(PublicOption, ATIPublicOptions, ATIPublicOptionSize);
313
314#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 25
315# define boolean bool
316#endif
317
318#   define ProbeSparse   PublicOption[ATI_OPTION_PROBE_SPARSE].value.boolean
319#   define Accel         PublicOption[ATI_OPTION_ACCEL].value.boolean
320#   define BIOSDisplay   PrivateOption[ATI_OPTION_BIOS_DISPLAY].value.boolean
321#   define Blend         PrivateOption[ATI_OPTION_BLEND].value.boolean
322#   define CRTDisplay    PublicOption[ATI_OPTION_CRT_DISPLAY].value.boolean
323#   define CRTScreen     PrivateOption[ATI_OPTION_CRT_SCREEN].value.boolean
324#   define CSync         PublicOption[ATI_OPTION_CSYNC].value.boolean
325#   define Devel         PrivateOption[ATI_OPTION_DEVEL].value.boolean
326#   define HWCursor      PublicOption[ATI_OPTION_HWCURSOR].value.boolean
327
328#ifdef XF86DRI_DEVEL
329
330#   define IsPCI       PublicOption[ATI_OPTION_IS_PCI].value.boolean
331#   define DMAMode     PublicOption[ATI_OPTION_DMA_MODE].value.str
332#   define AGPMode     PublicOption[ATI_OPTION_AGP_MODE].value.num
333#   define AGPSize     PublicOption[ATI_OPTION_AGP_SIZE].value.num
334#   define LocalTex    PublicOption[ATI_OPTION_LOCAL_TEXTURES].value.boolean
335#   define BufferSize  PublicOption[ATI_OPTION_BUFFER_SIZE].value.num
336
337#endif /* XF86DRI_DEVEL */
338
339#ifdef TV_OUT
340
341#   define TvOut        PublicOption[ATI_OPTION_TV_OUT].value.boolean
342#   define TvStd        PublicOption[ATI_OPTION_TV_STD].value.str
343
344#endif /* TV_OUT */
345
346#   define CacheMMIO     PublicOption[ATI_OPTION_MMIO_CACHE].value.boolean
347#   define TestCacheMMIO PublicOption[ATI_OPTION_TEST_MMIO_CACHE].value.boolean
348#   define PanelDisplay  PublicOption[ATI_OPTION_PANEL_DISPLAY].value.boolean
349#   define ShadowFB      PublicOption[ATI_OPTION_SHADOW_FB].value.boolean
350#   define SWCursor      PublicOption[ATI_OPTION_SWCURSOR].value.boolean
351#   define AccelMethod   PublicOption[ATI_OPTION_ACCELMETHOD].value.str
352#   define RenderAccel   PublicOption[ATI_OPTION_RENDER_ACCEL].value.boolean
353#   define LCDSync       PrivateOption[ATI_OPTION_LCDSYNC].value.boolean
354
355#   define ReferenceClock \
356        PublicOption[ATI_OPTION_REFERENCE_CLOCK].value.freq.freq
357
358    /* Pick up XF86Config options */
359    xf86CollectOptions(pScreenInfo, NULL);
360
361    /* Set non-zero defaults */
362    Accel = CacheMMIO = HWCursor = TRUE;
363
364    ReferenceClock = ((double)157500000.0) / ((double)11.0);
365
366    ShadowFB = TRUE;
367
368    Blend = PanelDisplay = TRUE;
369
370#ifdef USE_EXA
371    RenderAccel = TRUE;
372#endif
373
374#ifdef XF86DRI_DEVEL
375    DMAMode = "async";
376#endif
377
378#ifdef TV_OUT
379    TvStd = "None";  /* No tv standard change requested */
380#endif
381
382    xf86ProcessOptions(pScreenInfo->scrnIndex, pScreenInfo->options,
383        PublicOption);
384    xf86ProcessOptions(pScreenInfo->scrnIndex, pScreenInfo->options,
385        PrivateOption);
386
387    /* Move option values into driver private structure */
388    pATI->OptionProbeSparse = ProbeSparse;
389    pATI->OptionAccel = Accel;
390    pATI->OptionBIOSDisplay = BIOSDisplay;
391    pATI->OptionBlend = Blend;
392    pATI->OptionCRTDisplay = CRTDisplay;
393    pATI->OptionCSync = CSync;
394    pATI->OptionDevel = Devel;
395
396#ifdef TV_OUT
397
398    if (TvOut && pATI->Chip < ATI_CHIP_264GT) {
399       /* Only allow this for 3D Rage (I) or greater chip ID
400	* AFAIK, no chips before this supported TV-Out
401	* mach64VT has support for TV tuner, but no TV-Out
402	*/
403	xf86DrvMsg(pScreenInfo->scrnIndex, X_WARNING,
404                "TV Out not supported for this chip.\n");
405    } else {
406	ATITVStandard std;
407	pATI->OptionTvOut = TvOut;
408	pATI->OptionTvStd = ATI_TV_STD_INVALID;
409	for (std = 0; std < ATI_TV_STDS_MAX_VALID; std++) {
410	    if (std != ATI_TV_STD_RESERVED1 && std != ATI_TV_STD_RESERVED2) {
411		if (strncasecmp(TvStd, ATITVStandardNames[std], ATI_TV_STDS_NAME_MAXLEN)==0) {
412		    pATI->OptionTvStd = std;
413		    break;
414		}
415	    }
416	}
417    }
418
419#endif /* TV_OUT */
420
421    pATI->OptionMMIOCache = CacheMMIO;
422    pATI->OptionTestMMIOCache = TestCacheMMIO;
423    pATI->OptionShadowFB = ShadowFB;
424    pATI->OptionLCDSync = LCDSync;
425
426    /* "CRTScreen" is now "NoPanelDisplay" */
427    if ((PanelDisplay != CRTScreen) ||
428        PublicOption[ATI_OPTION_PANEL_DISPLAY].found)
429        pATI->OptionPanelDisplay = PanelDisplay;
430    else
431        pATI->OptionPanelDisplay = !CRTScreen;
432
433#ifdef XF86DRI_DEVEL
434
435    pATI->OptionIsPCI = IsPCI;
436    pATI->OptionAGPMode = AGPMode;
437    pATI->OptionAGPSize = AGPSize;
438    pATI->OptionLocalTextures = LocalTex;
439    pATI->OptionBufferSize = BufferSize;
440
441    if (strcasecmp(DMAMode, "async")==0)
442        pATI->OptionDMAMode = MACH64_MODE_DMA_ASYNC;
443    else if (strcasecmp(DMAMode, "sync")==0)
444        pATI->OptionDMAMode = MACH64_MODE_DMA_SYNC;
445    else if (strcasecmp(DMAMode, "mmio")==0 )
446        pATI->OptionDMAMode = MACH64_MODE_MMIO;
447    else {
448        xf86DrvMsg(pScreenInfo->scrnIndex, X_WARNING,
449		   "Unknown dma_mode: '%s'\n", DMAMode);
450	xf86DrvMsg(pScreenInfo->scrnIndex, X_WARNING,
451		   "Valid dma_mode options are: 'async','sync','mmio'\n");
452        xf86DrvMsg(pScreenInfo->scrnIndex, X_WARNING,
453		   "Defaulting to async DMA mode\n");
454	pATI->OptionDMAMode = MACH64_MODE_DMA_ASYNC;
455    }
456
457#endif /* XF86DRI_DEVEL */
458
459    /* Validate and set cursor options */
460    pATI->Cursor = ATI_CURSOR_SOFTWARE;
461    if (SWCursor || !HWCursor)
462    {
463        if (HWCursor && PublicOption[ATI_OPTION_HWCURSOR].found)
464            xf86DrvMsg(pScreenInfo->scrnIndex, X_WARNING,
465                "Option \"sw_cursor\" overrides Option \"hw_cursor\".\n");
466    }
467    else if (pATI->Chip < ATI_CHIP_264CT)
468    {
469        if (HWCursor && PublicOption[ATI_OPTION_HWCURSOR].found)
470            xf86DrvMsg(pScreenInfo->scrnIndex, X_WARNING,
471                "Option \"hw_cursor\" not supported in this configuration.\n");
472    }
473    else
474    {
475        pATI->Cursor = ATI_CURSOR_HARDWARE;
476    }
477
478    pATI->refclk = (int)ReferenceClock;
479
480    pATI->useEXA = FALSE;
481    if (pATI->OptionAccel)
482    {
483        MessageType from = X_DEFAULT;
484#if defined(USE_EXA)
485#if defined(USE_XAA)
486        if (AccelMethod != NULL)
487        {
488            from = X_CONFIG;
489            if (xf86NameCmp(AccelMethod, "EXA") == 0)
490                pATI->useEXA = TRUE;
491        }
492#else /* USE_XAA */
493        pATI->useEXA = TRUE;
494#endif /* !USE_XAA */
495#endif /* USE_EXA */
496        xf86DrvMsg(pScreenInfo->scrnIndex, from,
497            "Using %s acceleration architecture\n",
498            pATI->useEXA ? "EXA" : "XAA");
499
500#if defined(USE_EXA)
501        if (pATI->useEXA && pATI->Chip >= ATI_CHIP_264GTPRO)
502            pATI->RenderAccelEnabled = TRUE;
503
504        if (pATI->useEXA && !RenderAccel)
505            pATI->RenderAccelEnabled = FALSE;
506#endif
507    }
508
509    free(PublicOption);
510}
511