Home | History | Annotate | Line # | Download | only in src
      1  /*
      2   * (c) 2006-2008 Advanced Micro Devices, Inc.
      3   *
      4   * Permission is hereby granted, free of charge, to any person obtaining a
      5   * copy of this software and associated documentation files (the "Software"),
      6   * to deal in the Software without restriction, including without limitation
      7   * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      8   * and/or sell copies of the Software, and to permit persons to whom the
      9   * Software is furnished to do so, subject to the following conditions:
     10   *
     11   * The above copyright notice and this permission notice shall be included in
     12   * all copies or substantial portions of the Software.
     13   *
     14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     19   * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     20   * DEALINGS IN THE SOFTWARE.
     21   *
     22   * Neither the name of the Advanced Micro Devices, Inc. nor the names of its
     23   * contributors may be used to endorse or promote products derived from this
     24   * software without specific prior written permission.
     25   */
     26 
     27 #ifndef _GEODE_H_
     28 #define _GEODE_H_
     29 
     30 #ifdef HAVE_CONFIG_H
     31 #include "config.h"
     32 #endif
     33 #include "geode_pcirename.h"
     34 
     35 #ifdef HAVE_XAA_H
     36 #include "xaa.h"
     37 #endif
     38 #include "exa.h"
     39 #include "xf86Cursor.h"
     40 
     41 #include "vgaHW.h"
     42 #include "xf86int10.h"
     43 #include <X11/extensions/randr.h>
     44 #include "randrstr.h"
     45 
     46 #include "xf86xv.h"
     47 
     48 #include "compat-api.h"
     49 
     50 /* We only support EXA version >=2 */
     51 
     52 #if (EXA_VERSION_MAJOR >= 2)
     53 #ifndef XF86EXA
     54 #define XF86EXA 1
     55 #endif
     56 #else
     57 #undef XF86EXA
     58 #endif
     59 
     60 #ifdef HAVE_XAA_H
     61 #define XF86XAA 1
     62 #else
     63 #undef XF86XAA
     64 #endif
     65 
     66 #define CFB 0
     67 #define INT10_SUPPORT 1
     68 
     69 /* Existing Processor Models */
     70 #define GX1     0x01
     71 #define GX      0x10
     72 #define LX      0x20
     73 
     74 #define PCI_VENDOR_ID_CYRIX  0x1078
     75 #define PCI_VENDOR_ID_NS     0x100b
     76 #define PCI_VENDOR_ID_AMD    0x1022
     77 
     78 #define PCI_CHIP_5530     0x0104
     79 #define PCI_CHIP_SC1200   0x0504
     80 #define PCI_CHIP_SC1400   0x0104
     81 #define PCI_CHIP_GEODEGX  0x0030
     82 #define PCI_CHIP_GEODELX  0x2081
     83 
     84 #define GFX_CPU_GEODELX   4
     85 
     86 #if defined(HAVE_GX) && XF86XAA
     87 #define GX_FILL_RECT_SUPPORT 1
     88 #define GX_BRES_LINE_SUPPORT 1
     89 #define GX_DASH_LINE_SUPPORT 0  /* does not do dashed lines */
     90 #define GX_MONO_8X8_PAT_SUPPORT 1
     91 #define GX_CLREXP_8X8_PAT_SUPPORT 1
     92 #define GX_SCR2SCREXP_SUPPORT 1
     93 #define GX_SCR2SCRCPY_SUPPORT 1
     94 #define GX_CPU2SCREXP_SUPPORT 1
     95 #define GX_SCANLINE_SUPPORT 1
     96 #define GX_USE_OFFSCRN_MEM 0
     97 #define GX_ONE_LINE_AT_A_TIME 1
     98 #define GX_WRITE_PIXMAP_SUPPORT 1
     99 #endif
    100 
    101 #define GFX(func) gfx_##func
    102 #define GFX2(func) gfx2_##func
    103 
    104 #define GEODEPTR(p) ((GeodeRec *)((p)->driverPrivate))
    105 
    106 #define DEFAULT_EXA_SCRATCH_BFRSZ 0x40000
    107 
    108 /* the LX hardware (and Cimarron) require a cursor memory size of 48x64.. */
    109 #define LX_CURSOR_HW_WIDTH 48
    110 #define LX_CURSOR_HW_HEIGHT 64
    111 
    112 /* ...but xorg requires the cursor width to be a multiple of 32.  This is
    113 the size of the *actual* cursor. */
    114 #define LX_CURSOR_MAX_WIDTH 32
    115 #define LX_CURSOR_MAX_HEIGHT 32
    116 
    117 /* FIXME: Get rid of this from GX */
    118 
    119 #define DEBUGMSG(cond, drv_msg)
    120 
    121 #ifdef HAVE_LX
    122 extern unsigned char cim_inb(unsigned short port);
    123 extern void cim_outb(unsigned short port, unsigned char data);
    124 extern unsigned short cim_inw(unsigned short port);
    125 extern void cim_outw(unsigned short port, unsigned short data);
    126 extern unsigned long cim_ind(unsigned short port);
    127 extern void cim_outd(unsigned short port, unsigned long data);
    128 
    129 #include "cim_rtns.h"
    130 
    131 typedef struct _CIM_DISPLAYTIMING {
    132     unsigned short wPitch;
    133     unsigned short wBpp;
    134     VG_DISPLAY_MODE vgDisplayMode;
    135 } CIM_DISPLAYTIMING;
    136 
    137 #endif
    138 
    139 #ifdef HAVE_GX
    140 extern void gfx_write_reg32(int offset, int data);
    141 extern void gfx_write_reg16(int offset, short data);
    142 extern void gfx_write_reg8(int offset, char data);
    143 extern int gfx_read_reg32(int offset);
    144 extern short gfx_read_reg16(int offset);
    145 extern void gfx_write_vid32(int offset, int data);
    146 extern int gfx_read_vid32(int offset);
    147 extern unsigned char gfx_inb(unsigned short port);
    148 extern void gfx_outb(unsigned short port, unsigned char data);
    149 extern unsigned short gfx_inw(unsigned short port);
    150 extern void gfx_outw(unsigned short port, unsigned short data);
    151 extern unsigned long gfx_ind(unsigned short port);
    152 extern void gfx_outd(unsigned short port, unsigned long data);
    153 
    154 #define Q_WORD QQ_WORD
    155 #include "gfx_rtns.h"
    156 #undef Q_WORD
    157 #include "panel.h"
    158 
    159 typedef struct tag_GFX_DISPLAYTIMING {
    160     unsigned int dwDotClock;
    161     unsigned short wPitch;
    162     unsigned short wBpp;
    163     unsigned short wHTotal;
    164     unsigned short wHActive;
    165     unsigned short wHSyncStart;
    166     unsigned short wHSyncEnd;
    167     unsigned short wHBlankStart;
    168     unsigned short wHBlankEnd;
    169     unsigned short wVTotal;
    170     unsigned short wVActive;
    171     unsigned short wVSyncStart;
    172     unsigned short wVSyncEnd;
    173     unsigned short wVBlankStart;
    174     unsigned short wVBlankEnd;
    175     unsigned short wPolarity;
    176 } GFX_DISPLAYTIMING;
    177 
    178 #endif
    179 
    180 typedef struct _VESARec {
    181     xf86Int10InfoPtr pInt;
    182 } VESARec;
    183 
    184 typedef struct _GeodeMemRec {
    185     struct _GeodeMemRec *next;
    186     struct _GeodeMemRec *prev;
    187     unsigned int offset;
    188     int size;
    189 } GeodeMemRec, *GeodeMemPtr;
    190 
    191 #define OUTPUT_PANEL 0x01
    192 #define OUTPUT_CRT   0x02
    193 #define OUTPUT_TV    0x04
    194 #define OUTPUT_VOP   0x08
    195 #define OUTPUT_DCON  0x10
    196 
    197 typedef struct _geodeRec {
    198     /* Common for both GX and LX */
    199     int Output;                 /* Bitmask indicating the valid output options */
    200     Bool HWCursor;
    201     Bool NoAccel;
    202     Bool useVGA;
    203     Bool VGAActive;             /* Flag indicating if LX VGA is active */
    204     Bool Compression;
    205     Bool useEXA;
    206 
    207     int rotation;
    208     int displayWidth;
    209     Bool starting;
    210     Bool tryCompression;
    211     Bool tryHWCursor;
    212 
    213     int mm_width, mm_height;    /* physical display size */
    214 
    215     unsigned long CursorStartOffset;
    216 
    217     int Pitch;                  /* display FB pitch */
    218     int displaySize;            /* The size of the visible area */
    219 
    220     ExaOffscreenArea *shadowArea;
    221 
    222     /* Framebuffer memory */
    223 
    224     unsigned char *FBBase;
    225     unsigned int FBAvail;
    226 
    227     /* EXA structures */
    228 
    229     ExaDriverPtr pExa;
    230     unsigned int exaBfrOffset;
    231     unsigned int exaBfrSz;
    232 
    233     /* Other structures */
    234 
    235     EntityInfoPtr pEnt;
    236     ScreenBlockHandlerProcPtr BlockHandler;     /* needed for video */
    237     XF86VideoAdaptorPtr adaptor;
    238 
    239     /* State save structures */
    240     unsigned long FBDisplayOffset;
    241     unsigned long PrevDisplayOffset;
    242 
    243     VESARec *vesa;
    244 
    245     int FBCompressionEnable;
    246 
    247     VG_CURSOR_DATA FBCursor;
    248 
    249     /* Save the Cursor offset of the FB */
    250     unsigned long FBCursorOffset;
    251     unsigned char FBBIOSMode;
    252 
    253     /* Hooks */
    254 
    255     void (*PointerMoved) (POINTER_MOVED_ARGS_DECL);
    256     CloseScreenProcPtr CloseScreen;
    257     Bool (*CreateScreenResources) (ScreenPtr);
    258 
    259     /* ===== LX specific items ===== */
    260 
    261     /* Flags */
    262     Bool Scale;
    263 
    264     DisplayModePtr panelMode;   /* The mode for the panel (if attached) */
    265 
    266     /* Command buffer information */
    267     unsigned long CmdBfrOffset;
    268     unsigned long CmdBfrSize;
    269 
    270     /* Memory Management */
    271     GeodeMemPtr offscreenList;
    272     unsigned int offscreenStart;
    273     unsigned int offscreenSize;
    274 
    275     /* Save state */
    276     VG_COMPRESSION_DATA CBData;
    277     VG_COMPRESSION_DATA FBCBData;
    278     CIM_DISPLAYTIMING FBcimdisplaytiming;
    279 
    280     /* ===== GX specific items ===== */
    281 
    282     /* Flags */
    283     Bool Panel;
    284 
    285     int PanelX;
    286     int PanelY;
    287 
    288     int displayPitch;           /* The pitch of the visible area */
    289     int displayOffset;          /* The offset of the visible area */
    290 
    291     DisplayModePtr curMode;
    292 
    293     unsigned int shadowSize;
    294     unsigned int shadowOffset;
    295 
    296     int FBVGAActive;
    297 
    298     xf86CursorInfoPtr CursorInfo;
    299 
    300     /* XAA structures */
    301 
    302     unsigned int cpySrcOffset;
    303     int cpySrcPitch, cpySrcBpp;
    304     int cpyDx, cpyDy;
    305     unsigned int cmpSrcOffset;
    306     int cmpSrcPitch, cmpSrcBpp;
    307     unsigned int cmpSrcFmt, cmpDstFmt;
    308     int cmpOp;
    309 
    310     unsigned char **AccelImageWriteBuffers;
    311     int NoOfImgBuffers;
    312     unsigned char **AccelColorExpandBuffers;
    313     int NoOfColorExpandLines;
    314 #if XF86XAA
    315     XAAInfoRecPtr AccelInfoRec;
    316 #endif
    317 
    318     /* Save state */
    319     unsigned long FBCompressionOffset;
    320     unsigned short FBCompressionPitch;
    321     unsigned short FBCompressionSize;
    322     GFX_DISPLAYTIMING FBgfxdisplaytiming;
    323 
    324     /* Hooks */
    325     void (*WritePixmap) (ScrnInfoPtr pScrni, int x, int y, int w, int h,
    326                          unsigned char *src, int srcwidth, int rop,
    327                          unsigned int planemask, int trans, int bpp, int depth);
    328 
    329     /* Video information */
    330     int video_x;
    331     int video_y;
    332     short video_w;
    333     short video_h;
    334     short video_srcw;
    335     short video_srch;
    336     short video_dstw;
    337     short video_dsth;
    338     int video_id;
    339     int video_offset;
    340     ScrnInfoPtr video_scrnptr;
    341     BOOL OverlayON;
    342 } GeodeRec, *GeodePtr;
    343 
    344 /* option flags are self-explanatory */
    345 #ifdef HAVE_LX
    346 enum LX_GeodeOpts {
    347     LX_OPTION_SW_CURSOR,
    348     LX_OPTION_HW_CURSOR,
    349     LX_OPTION_NOCOMPRESSION,
    350     LX_OPTION_NOACCEL,
    351     LX_OPTION_EXA_SCRATCH_BFRSZ,
    352     LX_OPTION_TV_SUPPORT,
    353     LX_OPTION_TV_OUTPUT,
    354     LX_OPTION_TV_OVERSCAN,
    355     LX_OPTION_ROTATE,
    356     LX_OPTION_NOPANEL,
    357     LX_OPTION_FBSIZE,
    358     LX_OPTION_PANEL_MODE,
    359     LX_OPTION_DONT_PROGRAM
    360 };
    361 #endif
    362 
    363 #ifdef HAVE_GX
    364 enum GX_GeodeOpts {
    365     GX_OPTION_SW_CURSOR,
    366     GX_OPTION_HW_CURSOR,
    367     GX_OPTION_NOCOMPRESSION,
    368     GX_OPTION_NOACCEL,
    369     GX_OPTION_ACCEL_METHOD,
    370     GX_OPTION_EXA_SCRATCH_BFRSZ,
    371     GX_OPTION_TV_SUPPORT,
    372     GX_OPTION_TV_OUTPUT,
    373     GX_OPTION_TV_OVERSCAN,
    374     GX_OPTION_ROTATE,
    375     GX_OPTION_NOPANEL,
    376     GX_OPTION_OSM_IMG_BUFS,
    377     GX_OPTION_OSM_CLR_BUFS,
    378     GX_OPTION_FBSIZE,
    379     GX_OPTION_PANEL_GEOMETRY,
    380     GX_OPTION_DONT_PROGRAM
    381 };
    382 #endif
    383 
    384 /* geode_dcon.c */
    385 extern Bool dcon_init(ScrnInfoPtr pScrni);
    386 extern int DCONDPMSSet(ScrnInfoPtr pScrni, int mode);
    387 
    388 /* geode_common.c */
    389 
    390 void geode_memory_to_screen_blt(unsigned long, unsigned long,
    391                                 unsigned long, unsigned long, long, long, int);
    392 int GeodeGetRefreshRate(DisplayModePtr);
    393 void GeodeCopyGreyscale(unsigned char *, unsigned char *, int, int, int, int);
    394 int GeodeGetSizeFromFB(unsigned int *);
    395 
    396 /* gx_video.c */
    397 
    398 int
    399 
    400 
    401 GeodeQueryImageAttributes(ScrnInfoPtr, int id, unsigned short *w,
    402                           unsigned short *h, int *pitches, int *offsets);
    403 
    404 Bool RegionsEqual(RegionPtr A, RegionPtr B);
    405 
    406 /* gx_driver.c */
    407 
    408 void GeodeProbeDDC(ScrnInfoPtr pScrni, int index);
    409 xf86MonPtr GeodeDoDDC(ScrnInfoPtr pScrni, int index);
    410 Bool GeodeI2CInit(ScrnInfoPtr pScrni, I2CBusPtr * ptr, char *name);
    411 
    412 int GeodeGetFPGeometry(const char *str, int *width, int *height);
    413 void GeodePointerMoved(POINTER_MOVED_ARGS_DECL);
    414 void GeodeFreeScreen(FREE_SCREEN_ARGS_DECL);
    415 int GeodeCalculatePitchBytes(unsigned int width, unsigned int bpp);
    416 void GXSetupChipsetFPtr(ScrnInfoPtr pScrn);
    417 
    418 /* geode_msr.c */
    419 int GeodeReadMSR(unsigned long addr, unsigned long *lo, unsigned long *hi);
    420 int GeodeWriteMSR(unsigned long addr, unsigned long lo, unsigned long hi);
    421 
    422 /* gx_cursor.c */
    423 Bool GXHWCursorInit(ScreenPtr pScrn);
    424 void GXLoadCursorImage(ScrnInfoPtr pScrni, unsigned char *src);
    425 void GXHideCursor(ScrnInfoPtr pScrni);
    426 void GXShowCursor(ScrnInfoPtr pScrni);
    427 
    428 /* gx_randr.c */
    429 Rotation GXGetRotation(ScreenPtr pScreen);
    430 Bool GXRandRInit(ScreenPtr pScreen, int rotation);
    431 extern _X_EXPORT Bool GXRandRSetConfig(ScreenPtr pScreen, Rotation rotation,
    432                                        int rate, RRScreenSizePtr pSize);
    433 
    434 /* gx_rotate.c */
    435 Bool GXRotate(ScrnInfoPtr pScrni, DisplayModePtr mode);
    436 
    437 /* gx_accel.c */
    438 Bool GXAccelInit(ScreenPtr pScrn);
    439 void GXAccelSync(ScrnInfoPtr pScrni);
    440 
    441 /* gx_video.c */
    442 void GXInitVideo(ScreenPtr pScrn);
    443 
    444 /* lx_display.c */
    445 void lx_enable_dac_power(ScrnInfoPtr pScrni, int option);
    446 void lx_disable_dac_power(ScrnInfoPtr pScrni, int option);
    447 
    448 /* lx_driver.c */
    449 void LXSetupChipsetFPtr(ScrnInfoPtr pScrn);
    450 
    451 /* lx_cursor.c */
    452 Bool LXHWCursorInit(ScreenPtr pScrn);
    453 void LXLoadARGBCursorImage(ScrnInfoPtr pScrni, unsigned char *src);
    454 void LXHideCursor(ScrnInfoPtr pScrni);
    455 void LXShowCursor(ScrnInfoPtr pScrni);
    456 
    457 /* lx_exa.c */
    458 Bool LXExaInit(ScreenPtr pScreen);
    459 
    460 /* lx_video.c */
    461 void LXInitVideo(ScreenPtr pScrn);
    462 
    463 /* lx_output.c */
    464 void LXSetupOutput(ScrnInfoPtr);
    465 
    466 /* lx_panel.c */
    467 DisplayModePtr LXGetLegacyPanelMode(ScrnInfoPtr pScrni);
    468 DisplayModePtr LXGetManualPanelMode(const char *modestr);
    469 
    470 void LXAdjustFrame(ADJUST_FRAME_ARGS_DECL);
    471 
    472 /* lx_display.c */
    473 void LXSetupCrtc(ScrnInfoPtr pScrni);
    474 
    475 /* lx_memory.c */
    476 GeodeMemPtr GeodeAllocOffscreen(GeodeRec * pGeode, int size, int align);
    477 void GeodeFreeOffscreen(GeodeRec * pGeode, GeodeMemPtr ptr);
    478 void LXInitOffscreen(ScrnInfoPtr pScrni);
    479 void GeodeCloseOffscreen(ScrnInfoPtr pScrni);
    480 unsigned int GeodeOffscreenFreeSize(GeodeRec * pGeode);
    481 
    482 /* lx_cursor.c */
    483 Bool LXCursorInit(ScreenPtr pScrn);
    484 
    485 #endif
    486