/* mga_drm.h -- Public header for the Matrox g200/g400 driver -*- linux-c -*-1* Created: Tue Jan 25 01:50:01 1999 by [email protected]2*3* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.4* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.5* All rights reserved.6*7* Permission is hereby granted, free of charge, to any person obtaining a8* copy of this software and associated documentation files (the "Software"),9* to deal in the Software without restriction, including without limitation10* the rights to use, copy, modify, merge, publish, distribute, sublicense,11* and/or sell copies of the Software, and to permit persons to whom the12* Software is furnished to do so, subject to the following conditions:13*14* The above copyright notice and this permission notice (including the next15* paragraph) shall be included in all copies or substantial portions of the16* Software.17*18* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR19* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,20* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL21* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR22* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,23* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR24* OTHER DEALINGS IN THE SOFTWARE.25*26* Authors:27* Jeff Hartmann <[email protected]>28* Keith Whitwell <[email protected]>29*30* Rewritten by:31* Gareth Hughes <[email protected]>32*/3334#ifndef __MGA_DRM_H__35#define __MGA_DRM_H__3637#include "drm.h"3839/* WARNING: If you change any of these defines, make sure to change the40* defines in the Xserver file (mga_sarea.h)41*/4243#ifndef __MGA_SAREA_DEFINES__44#define __MGA_SAREA_DEFINES__4546/* WARP pipe flags47*/48#define MGA_F 0x1 /* fog */49#define MGA_A 0x2 /* alpha */50#define MGA_S 0x4 /* specular */51#define MGA_T2 0x8 /* multitexture */5253#define MGA_WARP_TGZ 054#define MGA_WARP_TGZF (MGA_F)55#define MGA_WARP_TGZA (MGA_A)56#define MGA_WARP_TGZAF (MGA_F|MGA_A)57#define MGA_WARP_TGZS (MGA_S)58#define MGA_WARP_TGZSF (MGA_S|MGA_F)59#define MGA_WARP_TGZSA (MGA_S|MGA_A)60#define MGA_WARP_TGZSAF (MGA_S|MGA_F|MGA_A)61#define MGA_WARP_T2GZ (MGA_T2)62#define MGA_WARP_T2GZF (MGA_T2|MGA_F)63#define MGA_WARP_T2GZA (MGA_T2|MGA_A)64#define MGA_WARP_T2GZAF (MGA_T2|MGA_A|MGA_F)65#define MGA_WARP_T2GZS (MGA_T2|MGA_S)66#define MGA_WARP_T2GZSF (MGA_T2|MGA_S|MGA_F)67#define MGA_WARP_T2GZSA (MGA_T2|MGA_S|MGA_A)68#define MGA_WARP_T2GZSAF (MGA_T2|MGA_S|MGA_F|MGA_A)6970#define MGA_MAX_G200_PIPES 8 /* no multitex */71#define MGA_MAX_G400_PIPES 1672#define MGA_MAX_WARP_PIPES MGA_MAX_G400_PIPES73#define MGA_WARP_UCODE_SIZE 32768 /* in bytes */7475#define MGA_CARD_TYPE_G200 176#define MGA_CARD_TYPE_G400 277#define MGA_CARD_TYPE_G450 3 /* not currently used */78#define MGA_CARD_TYPE_G550 47980#define MGA_FRONT 0x181#define MGA_BACK 0x282#define MGA_DEPTH 0x48384/* What needs to be changed for the current vertex dma buffer?85*/86#define MGA_UPLOAD_CONTEXT 0x187#define MGA_UPLOAD_TEX0 0x288#define MGA_UPLOAD_TEX1 0x489#define MGA_UPLOAD_PIPE 0x890#define MGA_UPLOAD_TEX0IMAGE 0x10 /* handled client-side */91#define MGA_UPLOAD_TEX1IMAGE 0x20 /* handled client-side */92#define MGA_UPLOAD_2D 0x4093#define MGA_WAIT_AGE 0x80 /* handled client-side */94#define MGA_UPLOAD_CLIPRECTS 0x100 /* handled client-side */95#if 096#define MGA_DMA_FLUSH 0x200 /* set when someone gets the lock97quiescent */98#endif99100/* 32 buffers of 64k each, total 2 meg.101*/102#define MGA_BUFFER_SIZE (1 << 16)103#define MGA_NUM_BUFFERS 128104105/* Keep these small for testing.106*/107#define MGA_NR_SAREA_CLIPRECTS 8108109/* 2 heaps (1 for card, 1 for agp), each divided into up to 128110* regions, subject to a minimum region size of (1<<16) == 64k.111*112* Clients may subdivide regions internally, but when sharing between113* clients, the region size is the minimum granularity.114*/115116#define MGA_CARD_HEAP 0117#define MGA_AGP_HEAP 1118#define MGA_NR_TEX_HEAPS 2119#define MGA_NR_TEX_REGIONS 16120#define MGA_LOG_MIN_TEX_REGION_SIZE 16121122#define DRM_MGA_IDLE_RETRY 2048123124#endif /* __MGA_SAREA_DEFINES__ */125126/* Setup registers for 3D context127*/128typedef struct {129unsigned int dstorg;130unsigned int maccess;131unsigned int plnwt;132unsigned int dwgctl;133unsigned int alphactrl;134unsigned int fogcolor;135unsigned int wflag;136unsigned int tdualstage0;137unsigned int tdualstage1;138unsigned int fcol;139unsigned int stencil;140unsigned int stencilctl;141} drm_mga_context_regs_t;142143/* Setup registers for 2D, X server144*/145typedef struct {146unsigned int pitch;147} drm_mga_server_regs_t;148149/* Setup registers for each texture unit150*/151typedef struct {152unsigned int texctl;153unsigned int texctl2;154unsigned int texfilter;155unsigned int texbordercol;156unsigned int texorg;157unsigned int texwidth;158unsigned int texheight;159unsigned int texorg1;160unsigned int texorg2;161unsigned int texorg3;162unsigned int texorg4;163} drm_mga_texture_regs_t;164165/* General aging mechanism166*/167typedef struct {168unsigned int head; /* Position of head pointer */169unsigned int wrap; /* Primary DMA wrap count */170} drm_mga_age_t;171172typedef struct _drm_mga_sarea {173/* The channel for communication of state information to the kernel174* on firing a vertex dma buffer.175*/176drm_mga_context_regs_t context_state;177drm_mga_server_regs_t server_state;178drm_mga_texture_regs_t tex_state[2];179unsigned int warp_pipe;180unsigned int dirty;181unsigned int vertsize;182183/* The current cliprects, or a subset thereof.184*/185struct drm_clip_rect boxes[MGA_NR_SAREA_CLIPRECTS];186unsigned int nbox;187188/* Information about the most recently used 3d drawable. The189* client fills in the req_* fields, the server fills in the190* exported_ fields and puts the cliprects into boxes, above.191*192* The client clears the exported_drawable field before193* clobbering the boxes data.194*/195unsigned int req_drawable; /* the X drawable id */196unsigned int req_draw_buffer; /* MGA_FRONT or MGA_BACK */197198unsigned int exported_drawable;199unsigned int exported_index;200unsigned int exported_stamp;201unsigned int exported_buffers;202unsigned int exported_nfront;203unsigned int exported_nback;204int exported_back_x, exported_front_x, exported_w;205int exported_back_y, exported_front_y, exported_h;206struct drm_clip_rect exported_boxes[MGA_NR_SAREA_CLIPRECTS];207208/* Counters for aging textures and for client-side throttling.209*/210unsigned int status[4];211unsigned int last_wrap;212213drm_mga_age_t last_frame;214unsigned int last_enqueue; /* last time a buffer was enqueued */215unsigned int last_dispatch; /* age of the most recently dispatched buffer */216unsigned int last_quiescent; /* */217218/* LRU lists for texture memory in agp space and on the card.219*/220struct drm_tex_region texList[MGA_NR_TEX_HEAPS][MGA_NR_TEX_REGIONS + 1];221unsigned int texAge[MGA_NR_TEX_HEAPS];222223/* Mechanism to validate card state.224*/225int ctxOwner;226} drm_mga_sarea_t;227228/* MGA specific ioctls229* The device specific ioctl range is 0x40 to 0x79.230*/231#define DRM_MGA_INIT 0x00232#define DRM_MGA_FLUSH 0x01233#define DRM_MGA_RESET 0x02234#define DRM_MGA_SWAP 0x03235#define DRM_MGA_CLEAR 0x04236#define DRM_MGA_VERTEX 0x05237#define DRM_MGA_INDICES 0x06238#define DRM_MGA_ILOAD 0x07239#define DRM_MGA_BLIT 0x08240#define DRM_MGA_GETPARAM 0x09241242/* 3.2:243* ioctls for operating on fences.244*/245#define DRM_MGA_SET_FENCE 0x0a246#define DRM_MGA_WAIT_FENCE 0x0b247#define DRM_MGA_DMA_BOOTSTRAP 0x0c248249#define DRM_IOCTL_MGA_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_INIT, drm_mga_init_t)250#define DRM_IOCTL_MGA_FLUSH DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_FLUSH, struct drm_lock)251#define DRM_IOCTL_MGA_RESET DRM_IO( DRM_COMMAND_BASE + DRM_MGA_RESET)252#define DRM_IOCTL_MGA_SWAP DRM_IO( DRM_COMMAND_BASE + DRM_MGA_SWAP)253#define DRM_IOCTL_MGA_CLEAR DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_CLEAR, drm_mga_clear_t)254#define DRM_IOCTL_MGA_VERTEX DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_VERTEX, drm_mga_vertex_t)255#define DRM_IOCTL_MGA_INDICES DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_INDICES, drm_mga_indices_t)256#define DRM_IOCTL_MGA_ILOAD DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_ILOAD, drm_mga_iload_t)257#define DRM_IOCTL_MGA_BLIT DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_BLIT, drm_mga_blit_t)258#define DRM_IOCTL_MGA_GETPARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_MGA_GETPARAM, drm_mga_getparam_t)259#define DRM_IOCTL_MGA_SET_FENCE DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_SET_FENCE, __u32)260#define DRM_IOCTL_MGA_WAIT_FENCE DRM_IOWR(DRM_COMMAND_BASE + DRM_MGA_WAIT_FENCE, __u32)261#define DRM_IOCTL_MGA_DMA_BOOTSTRAP DRM_IOWR(DRM_COMMAND_BASE + DRM_MGA_DMA_BOOTSTRAP, drm_mga_dma_bootstrap_t)262263typedef struct _drm_mga_warp_index {264int installed;265unsigned long phys_addr;266int size;267} drm_mga_warp_index_t;268269typedef struct drm_mga_init {270enum {271MGA_INIT_DMA = 0x01,272MGA_CLEANUP_DMA = 0x02273} func;274275unsigned long sarea_priv_offset;276277int chipset;278int sgram;279280unsigned int maccess;281282unsigned int fb_cpp;283unsigned int front_offset, front_pitch;284unsigned int back_offset, back_pitch;285286unsigned int depth_cpp;287unsigned int depth_offset, depth_pitch;288289unsigned int texture_offset[MGA_NR_TEX_HEAPS];290unsigned int texture_size[MGA_NR_TEX_HEAPS];291292unsigned long fb_offset;293unsigned long mmio_offset;294unsigned long status_offset;295unsigned long warp_offset;296unsigned long primary_offset;297unsigned long buffers_offset;298} drm_mga_init_t;299300typedef struct drm_mga_dma_bootstrap {301/**302* \name AGP texture region303*304* On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, these fields will305* be filled in with the actual AGP texture settings.306*307* \warning308* If these fields are non-zero, but dma_mga_dma_bootstrap::agp_mode309* is zero, it means that PCI memory (most likely through the use of310* an IOMMU) is being used for "AGP" textures.311*/312/*@{ */313unsigned long texture_handle; /**< Handle used to map AGP textures. */314__u32 texture_size; /**< Size of the AGP texture region. */315/*@} */316317/**318* Requested size of the primary DMA region.319*320* On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be321* filled in with the actual AGP mode. If AGP was not available322*/323__u32 primary_size;324325/**326* Requested number of secondary DMA buffers.327*328* On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be329* filled in with the actual number of secondary DMA buffers330* allocated. Particularly when PCI DMA is used, this may be331* (subtantially) less than the number requested.332*/333__u32 secondary_bin_count;334335/**336* Requested size of each secondary DMA buffer.337*338* While the kernel \b is free to reduce339* dma_mga_dma_bootstrap::secondary_bin_count, it is \b not allowed340* to reduce dma_mga_dma_bootstrap::secondary_bin_size.341*/342__u32 secondary_bin_size;343344/**345* Bit-wise mask of AGPSTAT2_* values. Currently only \c AGPSTAT2_1X,346* \c AGPSTAT2_2X, and \c AGPSTAT2_4X are supported. If this value is347* zero, it means that PCI DMA should be used, even if AGP is348* possible.349*350* On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be351* filled in with the actual AGP mode. If AGP was not available352* (i.e., PCI DMA was used), this value will be zero.353*/354__u32 agp_mode;355356/**357* Desired AGP GART size, measured in megabytes.358*/359__u8 agp_size;360} drm_mga_dma_bootstrap_t;361362typedef struct drm_mga_clear {363unsigned int flags;364unsigned int clear_color;365unsigned int clear_depth;366unsigned int color_mask;367unsigned int depth_mask;368} drm_mga_clear_t;369370typedef struct drm_mga_vertex {371int idx; /* buffer to queue */372int used; /* bytes in use */373int discard; /* client finished with buffer? */374} drm_mga_vertex_t;375376typedef struct drm_mga_indices {377int idx; /* buffer to queue */378unsigned int start;379unsigned int end;380int discard; /* client finished with buffer? */381} drm_mga_indices_t;382383typedef struct drm_mga_iload {384int idx;385unsigned int dstorg;386unsigned int length;387} drm_mga_iload_t;388389typedef struct _drm_mga_blit {390unsigned int planemask;391unsigned int srcorg;392unsigned int dstorg;393int src_pitch, dst_pitch;394int delta_sx, delta_sy;395int delta_dx, delta_dy;396int height, ydir; /* flip image vertically */397int source_pitch, dest_pitch;398} drm_mga_blit_t;399400/* 3.1: An ioctl to get parameters that aren't available to the 3d401* client any other way.402*/403#define MGA_PARAM_IRQ_NR 1404405/* 3.2: Query the actual card type. The DDX only distinguishes between406* G200 chips and non-G200 chips, which it calls G400. It turns out that407* there are some very sublte differences between the G4x0 chips and the G550408* chips. Using this parameter query, a client-side driver can detect the409* difference between a G4x0 and a G550.410*/411#define MGA_PARAM_CARD_TYPE 2412413typedef struct drm_mga_getparam {414int param;415void __user *value;416} drm_mga_getparam_t;417418#endif419420421