r128.h revision a0e1ef58
1c582b7e3Smrg/*
2c582b7e3Smrg * Copyright 1999, 2000 ATI Technologies Inc., Markham, Ontario,
3c582b7e3Smrg *                      Precision Insight, Inc., Cedar Park, Texas, and
4c582b7e3Smrg *                      VA Linux Systems Inc., Fremont, California.
5c582b7e3Smrg *
6c582b7e3Smrg * All Rights Reserved.
7c582b7e3Smrg *
8c582b7e3Smrg * Permission is hereby granted, free of charge, to any person obtaining
9c582b7e3Smrg * a copy of this software and associated documentation files (the
10c582b7e3Smrg * "Software"), to deal in the Software without restriction, including
11c582b7e3Smrg * without limitation on the rights to use, copy, modify, merge,
12c582b7e3Smrg * publish, distribute, sublicense, and/or sell copies of the Software,
13c582b7e3Smrg * and to permit persons to whom the Software is furnished to do so,
14c582b7e3Smrg * subject to the following conditions:
15c582b7e3Smrg *
16c582b7e3Smrg * The above copyright notice and this permission notice (including the
17c582b7e3Smrg * next paragraph) shall be included in all copies or substantial
18c582b7e3Smrg * portions of the Software.
19c582b7e3Smrg *
20c582b7e3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21c582b7e3Smrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22c582b7e3Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23c582b7e3Smrg * NON-INFRINGEMENT.  IN NO EVENT SHALL ATI, PRECISION INSIGHT, VA LINUX
24c582b7e3Smrg * SYSTEMS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25c582b7e3Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26c582b7e3Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27c582b7e3Smrg * OTHER DEALINGS IN THE SOFTWARE.
28c582b7e3Smrg */
29c582b7e3Smrg
30c582b7e3Smrg/*
31c582b7e3Smrg * Authors:
32c582b7e3Smrg *   Rickard E. Faith <faith@valinux.com>
33c582b7e3Smrg *   Kevin E. Martin <martin@valinux.com>
34c582b7e3Smrg *
35c582b7e3Smrg */
36c582b7e3Smrg
37c582b7e3Smrg#ifndef _R128_H_
38c582b7e3Smrg#define _R128_H_
39c582b7e3Smrg
40c582b7e3Smrg#include <unistd.h>
41c582b7e3Smrg#include "xf86str.h"
42c582b7e3Smrg
43c582b7e3Smrg				/* PCI support */
44c582b7e3Smrg#include "xf86Pci.h"
45c582b7e3Smrg
4684354367Smrg				/* EXA support */
4784354367Smrg#ifdef USE_EXA
4884354367Smrg#include "exa.h"
4984354367Smrg#endif
5084354367Smrg
51c582b7e3Smrg				/* XAA and Cursor Support */
5284354367Smrg#ifdef HAVE_XAA_H
53c582b7e3Smrg#include "xaa.h"
5484354367Smrg#endif
5584354367Smrg#include "xf86fbman.h"
56c582b7e3Smrg#include "xf86Cursor.h"
57c582b7e3Smrg
58c582b7e3Smrg				/* DDC support */
59c582b7e3Smrg#include "xf86DDC.h"
60c582b7e3Smrg
61c582b7e3Smrg				/* Xv support */
62c582b7e3Smrg#include "xf86xv.h"
63c582b7e3Smrg
64c582b7e3Smrg				/* DRI support */
6584354367Smrg#ifndef XF86DRI
6684354367Smrg#undef R128DRI
6784354367Smrg#endif
6884354367Smrg
6984354367Smrg#if R128DRI
70c582b7e3Smrg#define _XF86DRI_SERVER_
71c582b7e3Smrg#include "r128_dripriv.h"
72c582b7e3Smrg#include "dri.h"
73c582b7e3Smrg#include "GL/glxint.h"
74c582b7e3Smrg#endif
75c582b7e3Smrg
7684354367Smrg#include "fb.h"
7784354367Smrg
7884354367Smrg#include "compat-api.h"
79c582b7e3Smrg#include "atipcirename.h"
80c582b7e3Smrg
8184354367Smrg#include "r128_probe.h"
8284354367Smrg
8384354367Smrg#if HAVE_BYTESWAP_H
8484354367Smrg#include <byteswap.h>
8584354367Smrg#elif defined(USE_SYS_ENDIAN_H)
8684354367Smrg#include <sys/endian.h>
8784354367Smrg#else
8884354367Smrg#define bswap_16(value)  \
8984354367Smrg        ((((value) & 0xff) << 8) | ((value) >> 8))
9084354367Smrg
9184354367Smrg#define bswap_32(value) \
9284354367Smrg        (((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
9384354367Smrg        (uint32_t)bswap_16((uint16_t)((value) >> 16)))
9484354367Smrg
9584354367Smrg#define bswap_64(value) \
9684354367Smrg        (((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
9784354367Smrg            << 32) | \
9884354367Smrg        (uint64_t)bswap_32((uint32_t)((value) >> 32)))
9984354367Smrg#endif
10084354367Smrg
10184354367Smrg#if X_BYTE_ORDER == X_BIG_ENDIAN
10284354367Smrg#define le32_to_cpu(x) bswap_32(x)
10384354367Smrg#define le16_to_cpu(x) bswap_16(x)
10484354367Smrg#define cpu_to_le32(x) bswap_32(x)
10584354367Smrg#define cpu_to_le16(x) bswap_16(x)
10684354367Smrg#else
10784354367Smrg#define le32_to_cpu(x) (x)
10884354367Smrg#define le16_to_cpu(x) (x)
10984354367Smrg#define cpu_to_le32(x) (x)
11084354367Smrg#define cpu_to_le16(x) (x)
11184354367Smrg#endif
11284354367Smrg
113c582b7e3Smrg#define R128_DEBUG          0   /* Turn off debugging output               */
114c582b7e3Smrg#define R128_IDLE_RETRY    32   /* Fall out of idle loops after this count */
115c582b7e3Smrg#define R128_TIMEOUT  2000000   /* Fall out of wait loops after this count */
116c582b7e3Smrg#define R128_MMIOSIZE  0x4000
117c582b7e3Smrg
118c582b7e3Smrg#define R128_VBIOS_SIZE 0x00010000
1199e881af1Smacallan#define R128_NAME "R128"
120c582b7e3Smrg
121c582b7e3Smrg#if R128_DEBUG
12284354367Smrg#include "r128_version.h"
12384354367Smrg
124c582b7e3Smrg#define R128TRACE(x)                                          \
125c582b7e3Smrg    do {                                                      \
126c582b7e3Smrg	ErrorF("(**) %s(%d): ", R128_NAME, pScrn->scrnIndex); \
127c582b7e3Smrg	ErrorF x;                                             \
128c582b7e3Smrg    } while (0);
129c582b7e3Smrg#else
130c582b7e3Smrg#define R128TRACE(x)
131c582b7e3Smrg#endif
132c582b7e3Smrg
133c582b7e3Smrg
134c582b7e3Smrg/* Other macros */
135c582b7e3Smrg#define R128_ARRAY_SIZE(x)  (sizeof(x)/sizeof(x[0]))
136c582b7e3Smrg#define R128_ALIGN(x,bytes) (((x) + ((bytes) - 1)) & ~((bytes) - 1))
137c582b7e3Smrg#define R128PTR(pScrn) ((R128InfoPtr)(pScrn)->driverPrivate)
138c582b7e3Smrg
139c582b7e3Smrgtypedef struct {        /* All values in XCLKS    */
140c582b7e3Smrg    int  ML;            /* Memory Read Latency    */
141c582b7e3Smrg    int  MB;            /* Memory Burst Length    */
142c582b7e3Smrg    int  Trcd;          /* RAS to CAS delay       */
143c582b7e3Smrg    int  Trp;           /* RAS percentage         */
144c582b7e3Smrg    int  Twr;           /* Write Recovery         */
145c582b7e3Smrg    int  CL;            /* CAS Latency            */
146c582b7e3Smrg    int  Tr2w;          /* Read to Write Delay    */
147c582b7e3Smrg    int  Rloop;         /* Loop Latency           */
148c582b7e3Smrg    int  Rloop_fudge;   /* Add to ML to get Rloop */
149c582b7e3Smrg    char *name;
150c582b7e3Smrg} R128RAMRec, *R128RAMPtr;
151c582b7e3Smrg
152c582b7e3Smrgtypedef struct {
153c582b7e3Smrg				/* Common registers */
154c582b7e3Smrg    CARD32     ovr_clr;
155c582b7e3Smrg    CARD32     ovr_wid_left_right;
156c582b7e3Smrg    CARD32     ovr_wid_top_bottom;
157c582b7e3Smrg    CARD32     ov0_scale_cntl;
158c582b7e3Smrg    CARD32     mpp_tb_config;
159c582b7e3Smrg    CARD32     mpp_gp_config;
160c582b7e3Smrg    CARD32     subpic_cntl;
161c582b7e3Smrg    CARD32     viph_control;
162c582b7e3Smrg    CARD32     i2c_cntl_1;
163c582b7e3Smrg    CARD32     gen_int_cntl;
164c582b7e3Smrg    CARD32     cap0_trig_cntl;
165c582b7e3Smrg    CARD32     cap1_trig_cntl;
166c582b7e3Smrg    CARD32     bus_cntl;
167c582b7e3Smrg    CARD32     config_cntl;
168c582b7e3Smrg
169c582b7e3Smrg				/* Other registers to save for VT switches */
170c582b7e3Smrg    CARD32     dp_datatype;
171c582b7e3Smrg    CARD32     gen_reset_cntl;
172c582b7e3Smrg    CARD32     clock_cntl_index;
173c582b7e3Smrg    CARD32     amcgpio_en_reg;
174c582b7e3Smrg    CARD32     amcgpio_mask;
175c582b7e3Smrg
176c582b7e3Smrg				/* CRTC registers */
177c582b7e3Smrg    CARD32     crtc_gen_cntl;
178c582b7e3Smrg    CARD32     crtc_ext_cntl;
179c582b7e3Smrg    CARD32     dac_cntl;
180c582b7e3Smrg    CARD32     crtc_h_total_disp;
181c582b7e3Smrg    CARD32     crtc_h_sync_strt_wid;
182c582b7e3Smrg    CARD32     crtc_v_total_disp;
183c582b7e3Smrg    CARD32     crtc_v_sync_strt_wid;
184c582b7e3Smrg    CARD32     crtc_offset;
185c582b7e3Smrg    CARD32     crtc_offset_cntl;
186c582b7e3Smrg    CARD32     crtc_pitch;
187c582b7e3Smrg
188c582b7e3Smrg				/* CRTC2 registers */
189c582b7e3Smrg    CARD32     crtc2_gen_cntl;
190c582b7e3Smrg    CARD32     crtc2_h_total_disp;
191c582b7e3Smrg    CARD32     crtc2_h_sync_strt_wid;
192c582b7e3Smrg    CARD32     crtc2_v_total_disp;
193c582b7e3Smrg    CARD32     crtc2_v_sync_strt_wid;
194c582b7e3Smrg    CARD32     crtc2_offset;
195c582b7e3Smrg    CARD32     crtc2_offset_cntl;
196c582b7e3Smrg    CARD32     crtc2_pitch;
197c582b7e3Smrg
198c582b7e3Smrg				/* Flat panel registers */
199c582b7e3Smrg    CARD32     fp_crtc_h_total_disp;
200c582b7e3Smrg    CARD32     fp_crtc_v_total_disp;
201c582b7e3Smrg    CARD32     fp_gen_cntl;
202c582b7e3Smrg    CARD32     fp_h_sync_strt_wid;
203c582b7e3Smrg    CARD32     fp_horz_stretch;
204c582b7e3Smrg    CARD32     fp_panel_cntl;
205c582b7e3Smrg    CARD32     fp_v_sync_strt_wid;
206c582b7e3Smrg    CARD32     fp_vert_stretch;
207c582b7e3Smrg    CARD32     lvds_gen_cntl;
208c582b7e3Smrg    CARD32     tmds_crc;
209c582b7e3Smrg    CARD32     tmds_transmitter_cntl;
210c582b7e3Smrg
211c582b7e3Smrg				/* Computed values for PLL */
212c582b7e3Smrg    CARD32     dot_clock_freq;
213c582b7e3Smrg    CARD32     pll_output_freq;
214c582b7e3Smrg    int        feedback_div;
215c582b7e3Smrg    int        post_div;
216c582b7e3Smrg
217c582b7e3Smrg				/* PLL registers */
218c582b7e3Smrg    CARD32     ppll_ref_div;
219c582b7e3Smrg    CARD32     ppll_div_3;
2209e881af1Smacallan    CARD32     ppll_div_0;
221c582b7e3Smrg    CARD32     htotal_cntl;
222c582b7e3Smrg
223c582b7e3Smrg				/* Computed values for PLL2 */
224c582b7e3Smrg    CARD32     dot_clock_freq_2;
225c582b7e3Smrg    CARD32     pll_output_freq_2;
226c582b7e3Smrg    int        feedback_div_2;
227c582b7e3Smrg    int        post_div_2;
228c582b7e3Smrg
229c582b7e3Smrg				/* PLL2 registers */
230c582b7e3Smrg    CARD32     p2pll_ref_div;
231c582b7e3Smrg    CARD32     p2pll_div_0;
232c582b7e3Smrg    CARD32     htotal_cntl2;
233c582b7e3Smrg
234c582b7e3Smrg				/* DDA register */
235c582b7e3Smrg    CARD32     dda_config;
236c582b7e3Smrg    CARD32     dda_on_off;
237c582b7e3Smrg
238c582b7e3Smrg				/* DDA2 register */
239c582b7e3Smrg    CARD32     dda2_config;
240c582b7e3Smrg    CARD32     dda2_on_off;
241c582b7e3Smrg
242c582b7e3Smrg				/* Pallet */
243c582b7e3Smrg    Bool       palette_valid;
244c582b7e3Smrg    CARD32     palette[256];
245c582b7e3Smrg    CARD32     palette2[256];
246c582b7e3Smrg} R128SaveRec, *R128SavePtr;
247c582b7e3Smrg
248c582b7e3Smrgtypedef struct {
249c582b7e3Smrg    CARD16        reference_freq;
250c582b7e3Smrg    CARD16        reference_div;
251c582b7e3Smrg    unsigned      min_pll_freq;
252c582b7e3Smrg    unsigned      max_pll_freq;
253c582b7e3Smrg    CARD16        xclk;
254c582b7e3Smrg} R128PLLRec, *R128PLLPtr;
255c582b7e3Smrg
256c582b7e3Smrgtypedef struct {
257c582b7e3Smrg    int                bitsPerPixel;
258c582b7e3Smrg    int                depth;
259c582b7e3Smrg    int                displayWidth;
260c582b7e3Smrg    int                pixel_code;
261c582b7e3Smrg    int                pixel_bytes;
262c582b7e3Smrg    DisplayModePtr     mode;
263c582b7e3Smrg} R128FBLayout;
264c582b7e3Smrg
265c582b7e3Smrgtypedef enum
266c582b7e3Smrg{
267c582b7e3Smrg    MT_NONE,
268c582b7e3Smrg    MT_CRT,
269c582b7e3Smrg    MT_LCD,
270c582b7e3Smrg    MT_DFP,
271c582b7e3Smrg    MT_CTV,
272c582b7e3Smrg    MT_STV
273c582b7e3Smrg} R128MonitorType;
274c582b7e3Smrg
27584354367Smrg#ifdef USE_EXA
27684354367Smrgstruct r128_2d_state {
27784354367Smrg    Bool in_use;
27884354367Smrg    Bool composite_setup;
27984354367Smrg    uint32_t dst_pitch_offset;
28084354367Smrg    uint32_t src_pitch_offset;
28184354367Smrg    uint32_t dp_gui_master_cntl;
28284354367Smrg    uint32_t dp_cntl;
28384354367Smrg    uint32_t dp_write_mask;
28484354367Smrg    uint32_t dp_brush_frgd_clr;
28584354367Smrg    uint32_t dp_brush_bkgd_clr;
28684354367Smrg    uint32_t dp_src_frgd_clr;
28784354367Smrg    uint32_t dp_src_bkgd_clr;
28884354367Smrg    uint32_t default_sc_bottom_right;
28984354367Smrg#if defined(R128DRI) && defined(RENDER)
29084354367Smrg    Bool has_mask;
29184354367Smrg    int x_offset;
29284354367Smrg    int y_offset;
29384354367Smrg    int widths[2];
29484354367Smrg    int heights[2];
29584354367Smrg    Bool is_transform[2];
29684354367Smrg    PictTransform *transform[2];
29784354367Smrg    PixmapPtr src_pix;
29884354367Smrg    PixmapPtr msk_pix;
29984354367Smrg#endif
30084354367Smrg};
30184354367Smrg#endif
30284354367Smrg
303c582b7e3Smrgtypedef struct {
304c582b7e3Smrg    EntityInfoPtr     pEnt;
305c582b7e3Smrg    pciVideoPtr       PciInfo;
306c582b7e3Smrg    PCITAG            PciTag;
307c582b7e3Smrg    int               Chipset;
308c582b7e3Smrg    Bool              Primary;
309c582b7e3Smrg
31079e5230eSmacallan#ifndef AVOID_FBDEV
311c582b7e3Smrg    Bool              FBDev;
31279e5230eSmacallan#endif
313c582b7e3Smrg
314c582b7e3Smrg    unsigned long     LinearAddr;   /* Frame buffer physical address         */
315c582b7e3Smrg    unsigned long     MMIOAddr;     /* MMIO region physical address          */
316c582b7e3Smrg    unsigned long     BIOSAddr;     /* BIOS physical address                 */
317c582b7e3Smrg
318c582b7e3Smrg    void              *MMIO;        /* Map of MMIO region                    */
319c582b7e3Smrg    void              *FB;          /* Map of frame buffer                   */
320c582b7e3Smrg
321c582b7e3Smrg    CARD32            MemCntl;
322c582b7e3Smrg    CARD32            BusCntl;
323c582b7e3Smrg    unsigned long     FbMapSize;    /* Size of frame buffer, in bytes        */
324c582b7e3Smrg    int               Flags;        /* Saved copy of mode flags              */
325c582b7e3Smrg
326c582b7e3Smrg    CARD8             BIOSDisplay;  /* Device the BIOS is set to display to  */
327c582b7e3Smrg
328c582b7e3Smrg    Bool              HasPanelRegs; /* Current chip can connect to a FP      */
329c582b7e3Smrg    CARD8             *VBIOS;       /* Video BIOS for mode validation on FPs */
330c582b7e3Smrg    int               FPBIOSstart;  /* Start of the flat panel info          */
331c582b7e3Smrg
332c582b7e3Smrg				/* Computed values for FPs */
333c582b7e3Smrg    int               PanelXRes;
334c582b7e3Smrg    int               PanelYRes;
335c582b7e3Smrg    int               HOverPlus;
336c582b7e3Smrg    int               HSyncWidth;
337c582b7e3Smrg    int               HBlank;
338c582b7e3Smrg    int               VOverPlus;
339c582b7e3Smrg    int               VSyncWidth;
340c582b7e3Smrg    int               VBlank;
341c582b7e3Smrg    int               PanelPwrDly;
342c582b7e3Smrg
343c582b7e3Smrg    R128PLLRec        pll;
344c582b7e3Smrg    R128RAMPtr        ram;
345c582b7e3Smrg
346c582b7e3Smrg    R128SaveRec       SavedReg;     /* Original (text) mode                  */
347c582b7e3Smrg    R128SaveRec       ModeReg;      /* Current mode                          */
34884354367Smrg    Bool              (*CloseScreen)(CLOSE_SCREEN_ARGS_DECL);
34984354367Smrg    void              (*BlockHandler)(BLOCKHANDLER_ARGS_DECL);
350c582b7e3Smrg
351c582b7e3Smrg    Bool              PaletteSavedOnVT; /* Palette saved on last VT switch   */
352c582b7e3Smrg
35384354367Smrg#ifdef HAVE_XAA_H
354c582b7e3Smrg    XAAInfoRecPtr     accel;
35584354367Smrg#endif
356c582b7e3Smrg    Bool              accelOn;
35784354367Smrg
35884354367Smrg    Bool	      useEXA;
35984354367Smrg    Bool	      RenderAccel;
36084354367Smrg#ifdef USE_EXA
36184354367Smrg    ExaDriverPtr      ExaDriver;
36284354367Smrg    XF86ModReqInfo    exaReq;
36384354367Smrg    struct r128_2d_state state_2d;
36484354367Smrg#endif
36584354367Smrg
366c582b7e3Smrg    xf86CursorInfoPtr cursor;
367c582b7e3Smrg    unsigned long     cursor_start;
368c582b7e3Smrg    unsigned long     cursor_end;
369c582b7e3Smrg
370c582b7e3Smrg    /*
371c582b7e3Smrg     * XAAForceTransBlit is used to change the behavior of the XAA
372c582b7e3Smrg     * SetupForScreenToScreenCopy function, to make it DGA-friendly.
373c582b7e3Smrg     */
374c582b7e3Smrg    Bool              XAAForceTransBlit;
375c582b7e3Smrg
376c582b7e3Smrg    int               fifo_slots;   /* Free slots in the FIFO (64 max)       */
377c582b7e3Smrg    int               pix24bpp;     /* Depth of pixmap for 24bpp framebuffer */
378c582b7e3Smrg    Bool              dac6bits;     /* Use 6 bit DAC?                        */
379c582b7e3Smrg
380c582b7e3Smrg				/* Computed values for Rage 128 */
381c582b7e3Smrg    int               pitch;
382c582b7e3Smrg    int               datatype;
383c582b7e3Smrg    CARD32            dp_gui_master_cntl;
384c582b7e3Smrg
385c582b7e3Smrg				/* Saved values for ScreenToScreenCopy */
386c582b7e3Smrg    int               xdir;
387c582b7e3Smrg    int               ydir;
388c582b7e3Smrg
389c582b7e3Smrg				/* ScanlineScreenToScreenColorExpand support */
390c582b7e3Smrg    unsigned char     *scratch_buffer[1];
391c582b7e3Smrg    unsigned char     *scratch_save;
392c582b7e3Smrg    int               scanline_x;
393c582b7e3Smrg    int               scanline_y;
394c582b7e3Smrg    int               scanline_w;
395c582b7e3Smrg    int               scanline_h;
39684354367Smrg#ifdef R128DRI
397c582b7e3Smrg    int               scanline_hpass;
398c582b7e3Smrg    int               scanline_x1clip;
399c582b7e3Smrg    int               scanline_x2clip;
400c582b7e3Smrg    int               scanline_rop;
401c582b7e3Smrg    int               scanline_fg;
402c582b7e3Smrg    int               scanline_bg;
40384354367Smrg#endif /* R128DRI */
404c582b7e3Smrg    int               scanline_words;
405c582b7e3Smrg    int               scanline_direct;
406c582b7e3Smrg    int               scanline_bpp; /* Only used for ImageWrite */
407c582b7e3Smrg
408c582b7e3Smrg    DGAModePtr        DGAModes;
409c582b7e3Smrg    int               numDGAModes;
410c582b7e3Smrg    Bool              DGAactive;
411c582b7e3Smrg    int               DGAViewportStatus;
412c582b7e3Smrg    DGAFunctionRec    DGAFuncs;
413c582b7e3Smrg
414c582b7e3Smrg    R128FBLayout      CurrentLayout;
41584354367Smrg#ifdef R128DRI
416c582b7e3Smrg    Bool              directRenderingEnabled;
417c582b7e3Smrg    DRIInfoPtr        pDRIInfo;
418c582b7e3Smrg    int               drmFD;
419c582b7e3Smrg    drm_context_t        drmCtx;
420c582b7e3Smrg    int               numVisualConfigs;
421c582b7e3Smrg    __GLXvisualConfig *pVisualConfigs;
422c582b7e3Smrg    R128ConfigPrivPtr pVisualConfigsPriv;
423c582b7e3Smrg
424c582b7e3Smrg    drm_handle_t         fbHandle;
425c582b7e3Smrg
426c582b7e3Smrg    drmSize           registerSize;
427c582b7e3Smrg    drm_handle_t         registerHandle;
428c582b7e3Smrg
429c582b7e3Smrg    Bool              IsPCI;            /* Current card is a PCI card */
430c582b7e3Smrg    drmSize           pciSize;
431c582b7e3Smrg    drm_handle_t         pciMemHandle;
432c582b7e3Smrg    drmAddress        PCI;              /* Map */
433c582b7e3Smrg
434c582b7e3Smrg    Bool              allowPageFlip;    /* Enable 3d page flipping */
435c582b7e3Smrg    Bool              have3DWindows;    /* Are there any 3d clients? */
436c582b7e3Smrg    int               drmMinor;
437c582b7e3Smrg
438c582b7e3Smrg    drmSize           agpSize;
439c582b7e3Smrg    drm_handle_t         agpMemHandle;     /* Handle from drmAgpAlloc */
440c582b7e3Smrg    unsigned long     agpOffset;
441c582b7e3Smrg    drmAddress        AGP;              /* Map */
442c582b7e3Smrg    int               agpMode;
443c582b7e3Smrg
444c582b7e3Smrg    Bool              CCEInUse;         /* CCE is currently active */
445c582b7e3Smrg    int               CCEMode;          /* CCE mode that server/clients use */
446c582b7e3Smrg    int               CCEFifoSize;      /* Size of the CCE command FIFO */
447c582b7e3Smrg    Bool              CCESecure;        /* CCE security enabled */
448c582b7e3Smrg    int               CCEusecTimeout;   /* CCE timeout in usecs */
449c582b7e3Smrg
450c582b7e3Smrg				/* CCE ring buffer data */
451c582b7e3Smrg    unsigned long     ringStart;        /* Offset into AGP space */
452c582b7e3Smrg    drm_handle_t         ringHandle;       /* Handle from drmAddMap */
453c582b7e3Smrg    drmSize           ringMapSize;      /* Size of map */
454c582b7e3Smrg    int               ringSize;         /* Size of ring (in MB) */
455c582b7e3Smrg    drmAddress        ring;             /* Map */
456c582b7e3Smrg    int               ringSizeLog2QW;
457c582b7e3Smrg
458c582b7e3Smrg    unsigned long     ringReadOffset;   /* Offset into AGP space */
459c582b7e3Smrg    drm_handle_t         ringReadPtrHandle; /* Handle from drmAddMap */
460c582b7e3Smrg    drmSize           ringReadMapSize;  /* Size of map */
461c582b7e3Smrg    drmAddress        ringReadPtr;      /* Map */
462c582b7e3Smrg
463c582b7e3Smrg				/* CCE vertex/indirect buffer data */
464c582b7e3Smrg    unsigned long     bufStart;        /* Offset into AGP space */
465c582b7e3Smrg    drm_handle_t         bufHandle;       /* Handle from drmAddMap */
466c582b7e3Smrg    drmSize           bufMapSize;      /* Size of map */
467c582b7e3Smrg    int               bufSize;         /* Size of buffers (in MB) */
468c582b7e3Smrg    drmAddress        buf;             /* Map */
469c582b7e3Smrg    int               bufNumBufs;      /* Number of buffers */
470c582b7e3Smrg    drmBufMapPtr      buffers;         /* Buffer map */
471c582b7e3Smrg
472c582b7e3Smrg				/* CCE AGP Texture data */
473c582b7e3Smrg    unsigned long     agpTexStart;      /* Offset into AGP space */
474c582b7e3Smrg    drm_handle_t         agpTexHandle;     /* Handle from drmAddMap */
475c582b7e3Smrg    drmSize           agpTexMapSize;    /* Size of map */
476c582b7e3Smrg    int               agpTexSize;       /* Size of AGP tex space (in MB) */
477c582b7e3Smrg    drmAddress        agpTex;           /* Map */
478c582b7e3Smrg    int               log2AGPTexGran;
479c582b7e3Smrg
480c582b7e3Smrg				/* CCE 2D accleration */
481c582b7e3Smrg    drmBufPtr         indirectBuffer;
482c582b7e3Smrg    int               indirectStart;
483c582b7e3Smrg
484c582b7e3Smrg				/* DRI screen private data */
485c582b7e3Smrg    int               fbX;
486c582b7e3Smrg    int               fbY;
487c582b7e3Smrg    int               backX;
488c582b7e3Smrg    int               backY;
489c582b7e3Smrg    int               depthX;
490c582b7e3Smrg    int               depthY;
491c582b7e3Smrg
492c582b7e3Smrg    int               frontOffset;
493c582b7e3Smrg    int               frontPitch;
494c582b7e3Smrg    int               backOffset;
495c582b7e3Smrg    int               backPitch;
496c582b7e3Smrg    int               depthOffset;
497c582b7e3Smrg    int               depthPitch;
498c582b7e3Smrg    int               spanOffset;
499c582b7e3Smrg    int               textureOffset;
500c582b7e3Smrg    int               textureSize;
501c582b7e3Smrg    int               log2TexGran;
502c582b7e3Smrg
503c582b7e3Smrg				/* Saved scissor values */
504c582b7e3Smrg    CARD32            sc_left;
505c582b7e3Smrg    CARD32            sc_right;
506c582b7e3Smrg    CARD32            sc_top;
507c582b7e3Smrg    CARD32            sc_bottom;
508c582b7e3Smrg
509c582b7e3Smrg    CARD32            re_top_left;
510c582b7e3Smrg    CARD32            re_width_height;
511c582b7e3Smrg
512c582b7e3Smrg    CARD32            aux_sc_cntl;
513c582b7e3Smrg
514c582b7e3Smrg    int               irq;
515c582b7e3Smrg    CARD32            gen_int_cntl;
516c582b7e3Smrg
517c582b7e3Smrg    Bool              DMAForXv;
518c582b7e3Smrg#endif
519c582b7e3Smrg
520c582b7e3Smrg    XF86VideoAdaptorPtr adaptor;
521c582b7e3Smrg    void              (*VideoTimerCallback)(ScrnInfoPtr, Time);
522c582b7e3Smrg    int               videoKey;
523c582b7e3Smrg    Bool              showCache;
524c582b7e3Smrg    OptionInfoPtr     Options;
525c582b7e3Smrg
526c582b7e3Smrg    Bool              isDFP;
527c582b7e3Smrg    Bool              isPro2;
528c582b7e3Smrg    I2CBusPtr         pI2CBus;
529c582b7e3Smrg    CARD32            DDCReg;
530c582b7e3Smrg
531c582b7e3Smrg    Bool              VGAAccess;
532c582b7e3Smrg
533c582b7e3Smrg    /****** Added for dualhead support *******************/
534c582b7e3Smrg    BOOL              HasCRTC2;     /* M3/M4 */
535c582b7e3Smrg    BOOL              IsSecondary;  /* second Screen */
536c582b7e3Smrg    BOOL	      IsPrimary;    /* primary Screen */
537c582b7e3Smrg    BOOL              UseCRT;       /* force use CRT port as primary */
538c582b7e3Smrg    BOOL              SwitchingMode;
539c582b7e3Smrg    R128MonitorType DisplayType;  /* Monitor connected on*/
540c582b7e3Smrg
541c582b7e3Smrg} R128InfoRec, *R128InfoPtr;
542c582b7e3Smrg
543c582b7e3Smrg#define R128WaitForFifo(pScrn, entries)                                      \
544c582b7e3Smrgdo {                                                                         \
545c582b7e3Smrg    if (info->fifo_slots < entries) R128WaitForFifoFunction(pScrn, entries); \
546c582b7e3Smrg    info->fifo_slots -= entries;                                             \
547c582b7e3Smrg} while (0)
548c582b7e3Smrg
549c582b7e3Smrgextern R128EntPtr R128EntPriv(ScrnInfoPtr pScrn);
550c582b7e3Smrgextern void        R128WaitForFifoFunction(ScrnInfoPtr pScrn, int entries);
551c582b7e3Smrgextern void        R128WaitForIdle(ScrnInfoPtr pScrn);
552c582b7e3Smrgextern void        R128EngineReset(ScrnInfoPtr pScrn);
553c582b7e3Smrgextern void        R128EngineFlush(ScrnInfoPtr pScrn);
554c582b7e3Smrg
555c582b7e3Smrgextern unsigned    R128INPLL(ScrnInfoPtr pScrn, int addr);
556c582b7e3Smrgextern void        R128WaitForVerticalSync(ScrnInfoPtr pScrn);
557c582b7e3Smrg
558c582b7e3Smrgextern Bool        R128AccelInit(ScreenPtr pScreen);
559c582b7e3Smrgextern void        R128EngineInit(ScrnInfoPtr pScrn);
560c582b7e3Smrgextern Bool        R128CursorInit(ScreenPtr pScreen);
561c582b7e3Smrgextern Bool        R128DGAInit(ScreenPtr pScreen);
562c582b7e3Smrg
563c582b7e3Smrgextern int         R128MinBits(int val);
564c582b7e3Smrg
565c582b7e3Smrgextern void        R128InitVideo(ScreenPtr pScreen);
566c582b7e3Smrg
56784354367Smrg#ifdef R128DRI
568c582b7e3Smrgextern Bool        R128DRIScreenInit(ScreenPtr pScreen);
569c582b7e3Smrgextern void        R128DRICloseScreen(ScreenPtr pScreen);
570c582b7e3Smrgextern Bool        R128DRIFinishScreenInit(ScreenPtr pScreen);
571c582b7e3Smrg
572c582b7e3Smrg#define R128CCE_START(pScrn, info)					\
573c582b7e3Smrgdo {									\
574c582b7e3Smrg    int _ret = drmCommandNone(info->drmFD, DRM_R128_CCE_START);		\
575c582b7e3Smrg    if (_ret) {								\
576c582b7e3Smrg	xf86DrvMsg(pScrn->scrnIndex, X_ERROR,				\
577c582b7e3Smrg		   "%s: CCE start %d\n", __FUNCTION__, _ret);		\
578c582b7e3Smrg    }									\
579c582b7e3Smrg} while (0)
580c582b7e3Smrg
581c582b7e3Smrg#define R128CCE_STOP(pScrn, info)					\
582c582b7e3Smrgdo {									\
583c582b7e3Smrg    int _ret = R128CCEStop(pScrn);					\
584c582b7e3Smrg    if (_ret) {								\
585c582b7e3Smrg	xf86DrvMsg(pScrn->scrnIndex, X_ERROR,				\
586c582b7e3Smrg		   "%s: CCE stop %d\n", __FUNCTION__, _ret);		\
587c582b7e3Smrg    }									\
588c582b7e3Smrg} while (0)
589c582b7e3Smrg
590c582b7e3Smrg#define R128CCE_RESET(pScrn, info)					\
591c582b7e3Smrgdo {									\
592c582b7e3Smrg    if (info->directRenderingEnabled					\
593c582b7e3Smrg	&& R128CCE_USE_RING_BUFFER(info->CCEMode)) {			\
594c582b7e3Smrg	int _ret = drmCommandNone(info->drmFD, DRM_R128_CCE_RESET);	\
595c582b7e3Smrg	if (_ret) {							\
596c582b7e3Smrg	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,			\
597c582b7e3Smrg		       "%s: CCE reset %d\n", __FUNCTION__, _ret);	\
598c582b7e3Smrg	}								\
599c582b7e3Smrg    }									\
600c582b7e3Smrg} while (0)
601c582b7e3Smrg
602c582b7e3Smrgextern drmBufPtr   R128CCEGetBuffer(ScrnInfoPtr pScrn);
603c582b7e3Smrg#endif
604c582b7e3Smrg
605c582b7e3Smrgextern void        R128CCEFlushIndirect(ScrnInfoPtr pScrn, int discard);
606c582b7e3Smrgextern void        R128CCEReleaseIndirect(ScrnInfoPtr pScrn);
607c582b7e3Smrgextern void        R128CCEWaitForIdle(ScrnInfoPtr pScrn);
608c582b7e3Smrgextern int         R128CCEStop(ScrnInfoPtr pScrn);
609a0e1ef58Smrgextern void	   R128CopySwap(uint8_t *dst, uint8_t *src, unsigned int size, int swap);
610c582b7e3Smrg
61184354367Smrg#ifdef USE_EXA
61284354367Smrgextern Bool	   R128EXAInit(ScreenPtr pScreen);
61384354367Smrgextern Bool	   R128GetDatatypeBpp(int bpp, uint32_t *type);
61484354367Smrgextern Bool	   R128GetPixmapOffsetPitch(PixmapPtr pPix, uint32_t *pitch_offset);
61584354367Smrgextern void	   R128DoPrepareCopy(ScrnInfoPtr pScrn, uint32_t src_pitch_offset,
61684354367Smrg				    uint32_t dst_pitch_offset, uint32_t datatype, int alu, Pixel planemask);
61784354367Smrg#endif
61884354367Smrg
619c582b7e3Smrg
620c582b7e3Smrg#define CCE_PACKET0( reg, n )						\
621c582b7e3Smrg	(R128_CCE_PACKET0 | ((n) << 16) | ((reg) >> 2))
622c582b7e3Smrg#define CCE_PACKET1( reg0, reg1 )					\
623c582b7e3Smrg	(R128_CCE_PACKET1 | (((reg1) >> 2) << 11) | ((reg0) >> 2))
624c582b7e3Smrg#define CCE_PACKET2()							\
625c582b7e3Smrg	(R128_CCE_PACKET2)
626c582b7e3Smrg#define CCE_PACKET3( pkt, n )						\
627c582b7e3Smrg	(R128_CCE_PACKET3 | (pkt) | ((n) << 16))
628c582b7e3Smrg
629c582b7e3Smrg
630c582b7e3Smrg#define R128_VERBOSE	0
631c582b7e3Smrg
632c582b7e3Smrg#define RING_LOCALS	CARD32 *__head; int __count;
633c582b7e3Smrg
634c582b7e3Smrg#define R128CCE_REFRESH(pScrn, info)					\
635c582b7e3Smrgdo {									\
636c582b7e3Smrg   if ( R128_VERBOSE ) {						\
637c582b7e3Smrg      xf86DrvMsg( pScrn->scrnIndex, X_INFO, "REFRESH( %d ) in %s\n",	\
638c582b7e3Smrg		  !info->CCEInUse , __FUNCTION__ );			\
639c582b7e3Smrg   }									\
640c582b7e3Smrg   if ( !info->CCEInUse ) {						\
641c582b7e3Smrg      R128CCEWaitForIdle(pScrn);					\
642c582b7e3Smrg      BEGIN_RING( 6 );							\
643c582b7e3Smrg      OUT_RING_REG( R128_RE_TOP_LEFT,     info->re_top_left );		\
644c582b7e3Smrg      OUT_RING_REG( R128_RE_WIDTH_HEIGHT, info->re_width_height );	\
645c582b7e3Smrg      OUT_RING_REG( R128_AUX_SC_CNTL,     info->aux_sc_cntl );		\
646c582b7e3Smrg      ADVANCE_RING();							\
647c582b7e3Smrg      info->CCEInUse = TRUE;						\
648c582b7e3Smrg   }									\
649c582b7e3Smrg} while (0)
650c582b7e3Smrg
651c582b7e3Smrg#define BEGIN_RING( n ) do {						\
652c582b7e3Smrg   if ( R128_VERBOSE ) {						\
653c582b7e3Smrg      xf86DrvMsg( pScrn->scrnIndex, X_INFO,				\
654c582b7e3Smrg		  "BEGIN_RING( %d ) in %s\n", n, __FUNCTION__ );	\
655c582b7e3Smrg   }									\
656c582b7e3Smrg   if ( !info->indirectBuffer ) {					\
657c582b7e3Smrg      info->indirectBuffer = R128CCEGetBuffer( pScrn );			\
658c582b7e3Smrg      info->indirectStart = 0;						\
659c582b7e3Smrg   } else if ( (info->indirectBuffer->used + 4*(n)) >			\
660c582b7e3Smrg                info->indirectBuffer->total ) {				\
661c582b7e3Smrg      R128CCEFlushIndirect( pScrn, 1 );					\
662c582b7e3Smrg   }									\
663c582b7e3Smrg   __head = (pointer)((char *)info->indirectBuffer->address +		\
664c582b7e3Smrg		       info->indirectBuffer->used);			\
665c582b7e3Smrg   __count = 0;								\
666c582b7e3Smrg} while (0)
667c582b7e3Smrg
668c582b7e3Smrg#define ADVANCE_RING() do {						\
669c582b7e3Smrg   if ( R128_VERBOSE ) {						\
670c582b7e3Smrg      xf86DrvMsg( pScrn->scrnIndex, X_INFO,				\
671c582b7e3Smrg		  "ADVANCE_RING() used: %d+%d=%d/%d\n",			\
672c582b7e3Smrg		  info->indirectBuffer->used - info->indirectStart,	\
673c582b7e3Smrg		  __count * (int)sizeof(CARD32),			\
674c582b7e3Smrg		  info->indirectBuffer->used - info->indirectStart +	\
675c582b7e3Smrg		  __count * (int)sizeof(CARD32),			\
676c582b7e3Smrg		  info->indirectBuffer->total - info->indirectStart );	\
677c582b7e3Smrg   }									\
678c582b7e3Smrg   info->indirectBuffer->used += __count * (int)sizeof(CARD32);		\
679c582b7e3Smrg} while (0)
680c582b7e3Smrg
681c582b7e3Smrg#define OUT_RING( x ) do {						\
682c582b7e3Smrg   if ( R128_VERBOSE ) {						\
683c582b7e3Smrg      xf86DrvMsg( pScrn->scrnIndex, X_INFO,				\
684c582b7e3Smrg		  "   OUT_RING( 0x%08x )\n", (unsigned int)(x) );	\
685c582b7e3Smrg   }									\
686c582b7e3Smrg   MMIO_OUT32(&__head[__count++], 0, (x));				\
687c582b7e3Smrg} while (0)
688c582b7e3Smrg
689c582b7e3Smrg#define OUT_RING_REG( reg, val )					\
690c582b7e3Smrgdo {									\
691c582b7e3Smrg   OUT_RING( CCE_PACKET0( reg, 0 ) );					\
692c582b7e3Smrg   OUT_RING( val );							\
693c582b7e3Smrg} while (0)
694c582b7e3Smrg
695c582b7e3Smrg#define FLUSH_RING()							\
696c582b7e3Smrgdo {									\
697c582b7e3Smrg   if ( R128_VERBOSE )							\
698c582b7e3Smrg      xf86DrvMsg( pScrn->scrnIndex, X_INFO,				\
699c582b7e3Smrg		  "FLUSH_RING in %s\n", __FUNCTION__ );			\
700c582b7e3Smrg   if ( info->indirectBuffer ) {					\
701c582b7e3Smrg      R128CCEFlushIndirect( pScrn, 0 );					\
702c582b7e3Smrg   }									\
703c582b7e3Smrg} while (0)
704c582b7e3Smrg
705c582b7e3Smrg#endif
706