diff options
author | Keith Whitwell <keith@tungstengraphics.com> | 2004-04-14 12:39:58 +0000 |
---|---|---|
committer | Keith Whitwell <keith@tungstengraphics.com> | 2004-04-14 12:39:58 +0000 |
commit | 680ec7f85158eae58fd5ab56da8c66a645883cb0 (patch) | |
tree | 1680892e7edd243e5c49dd40c0ae9b9750066229 /src/mesa/drivers/dri/dri_client/imports | |
parent | 00e01091ceeb7f2d9e81962a7e0e57077e4d37f7 (diff) |
First pass at support for building DRI drivers in mesa tree.
Diffstat (limited to 'src/mesa/drivers/dri/dri_client/imports')
-rw-r--r-- | src/mesa/drivers/dri/dri_client/imports/glxclient.h | 1143 | ||||
-rw-r--r-- | src/mesa/drivers/dri/dri_client/imports/sarea.h | 94 | ||||
-rw-r--r-- | src/mesa/drivers/dri/dri_client/imports/xf86drm.h | 646 |
3 files changed, 1883 insertions, 0 deletions
diff --git a/src/mesa/drivers/dri/dri_client/imports/glxclient.h b/src/mesa/drivers/dri/dri_client/imports/glxclient.h new file mode 100644 index 0000000000..317ea01116 --- /dev/null +++ b/src/mesa/drivers/dri/dri_client/imports/glxclient.h @@ -0,0 +1,1143 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ +/* $XFree86: xc/lib/GL/glx/glxclient.h,v 1.15 2002/10/30 12:51:26 alanh Exp $ */ + +/** + * \file glxclient.h + * Direct rendering support added by Precision Insight, Inc. + * + * \author Kevin E. Martin <kevin@precisioninsight.com> + */ + +#ifndef _GLX_client_h_ +#define _GLX_client_h_ +#define NEED_REPLIES +#define NEED_EVENTS +#include <X11/Xproto.h> +#include <X11/Xlibint.h> +#define GLX_GLXEXT_PROTOTYPES +#include <GL/glx.h> +#include <GL/glxext.h> +#include <string.h> +#include <stdlib.h> +#include "GL/glxint.h" +#include "GL/glxproto.h" +#include "GL/internal/glcore.h" +#include "glapitable.h" +#ifdef NEED_GL_FUNCS_WRAPPED +#include "indirect.h" +#endif +#ifdef XTHREADS +#include "Xthreads.h" +#endif +#ifdef GLX_BUILT_IN_XMESA +#include "realglx.h" /* just silences prototype warnings */ +#endif + +#define GLX_MAJOR_VERSION 1 /* current version numbers */ +#define GLX_MINOR_VERSION 2 + +#define __GLX_MAX_TEXTURE_UNITS 32 + +typedef struct __GLXcontextRec __GLXcontext; +typedef struct __GLXdisplayPrivateRec __GLXdisplayPrivate; +typedef struct _glapi_table __GLapi; + +/************************************************************************/ + +#ifdef GLX_DIRECT_RENDERING + +/** + * \name DRI interface structures + * + * The following structures define the interface between the GLX client + * side library and the DRI (direct rendering infrastructure). + */ +/*@{*/ +typedef struct __DRIdisplayRec __DRIdisplay; +typedef struct __DRIscreenRec __DRIscreen; +typedef struct __DRIcontextRec __DRIcontext; +typedef struct __DRIdrawableRec __DRIdrawable; +typedef struct __DRIdriverRec __DRIdriver; +typedef struct __DRIframebufferRec __DRIframebuffer; +typedef struct __DRIversionRec __DRIversion; +/*@}*/ + +extern __DRIscreen *__glXFindDRIScreen(Display *dpy, int scrn); + +/** + * Stored version of some component (i.e., server-side DRI module, kernel-side + * DRM, etc.). + * + * \todo There are several data structures that explicitly store a major + * version, minor version, and patch level. These structures should + * be modified to have a \c __DRIversionRec instead. + */ +struct __DRIversionRec { + int major; /**< Major version number. */ + int minor; /**< Minor version number. */ + int patch; /**< Patch-level. */ +}; + +/** + * Framebuffer information record. Used by libGL to communicate information + * about the framebuffer to the driver's \c __DRIdisplayRec::createNewScreen + * function. + * + * In XFree86, most of this information is derrived from data returned by + * calling \c XF86DRIGetDeviceInfo. + * + * \sa XF86DRIGetDeviceInfo __DRIdisplayRec::createNewScreen + * __driUtilCreateNewScreen CallCreateNewScreen + * + * \bug This structure could be better named. + */ +struct __DRIframebufferRec { + unsigned char *base; /**< Framebuffer base address in the CPU's + * address space. This value is calculated by + * calling \c drmMap on the framebuffer handle + * returned by \c XF86DRIGetDeviceInfo (or a + * similar function). + */ + int size; /**< Framebuffer size, in bytes. */ + int stride; /**< Number of bytes from one line to the next. */ + int width; /**< Pixel width of the framebuffer. */ + int height; /**< Pixel height of the framebuffer. */ + int dev_priv_size; /**< Size of the driver's dev-priv structure. */ + void *dev_priv; /**< Pointer to the driver's dev-priv structure. */ +}; + +typedef void *(*CreateScreenFunc)(Display *dpy, int scrn, __DRIscreen *psc, + int numConfigs, __GLXvisualConfig *config); + +typedef void *(*CreateNewScreenFunc)(Display *dpy, int scrn, __DRIscreen *psc, + const __GLcontextModes * modes, const __DRIversion * ddx_version, + const __DRIversion * dri_version, const __DRIversion * drm_version, + const __DRIframebuffer * frame_buffer, void * pSAREA, + int fd, int internal_api_version, __GLcontextModes ** driver_modes); + +/** + * Display dependent methods. This structure is initialized during the + * \c driCreateDisplay call. + */ +struct __DRIdisplayRec { + /** + * Method to destroy the private DRI display data. + */ + void (*destroyDisplay)(Display *dpy, void *displayPrivate); + + /** + * Methods to create the private DRI screen data and initialize the + * screen dependent methods. + * This is an array [indexed by screen number] of function pointers. + * + * \deprecated This array of function pointers has been replaced by + * \c __DRIdisplayRec::createNewScreen. + * \sa __DRIdisplayRec::createNewScreen + */ + CreateScreenFunc * createScreen; + + /** + * Opaque pointer to private per display direct rendering data. + * \c NULL if direct rendering is not supported on this display. + */ + struct __DRIdisplayPrivateRec *private; + + /** + * Array of pointers to methods to create and initialize the private DRI + * screen data. + * + * \sa __DRIdisplayRec::createScreen + */ + CreateNewScreenFunc * createNewScreen; +}; + +/** + * Screen dependent methods. This structure is initialized during the + * \c __DRIdisplayRec::createScreen call. + */ +struct __DRIscreenRec { + /** + * Method to destroy the private DRI screen data. + */ + void (*destroyScreen)(Display *dpy, int scrn, void *screenPrivate); + + /** + * Method to create the private DRI context data and initialize the + * context dependent methods. + * + * \sa __DRIscreenRec::createNewContext driCreateContext + * driCreateNewContext + * \deprecated This function has been replaced by + * __DRIscreenRec::createNewContext. New drivers will + * continue to export this method, but it will eventually + * (in the next XFree86 major relearse) go away. + */ + void *(*createContext)(Display *dpy, XVisualInfo *vis, void *sharedPrivate, + __DRIcontext *pctx); + + /** + * Method to create the private DRI drawable data and initialize the + * drawable dependent methods. + */ + void *(*createNewDrawable)(Display *dpy, const __GLcontextModes *modes, + GLXDrawable draw, __DRIdrawable *pdraw, + int renderType, const int *attrs); + + /** + * Method to return a pointer to the DRI drawable data. + */ + __DRIdrawable *(*getDrawable)(Display *dpy, GLXDrawable draw, + void *drawablePrivate); + + /** + * Opaque pointer to private per screen direct rendering data. \c NULL + * if direct rendering is not supported on this screen. Never + * dereferenced in libGL. + */ + void *private; + + /** + * Get the number of vertical refreshes since some point in time before + * this function was first called (i.e., system start up). + * + * \since Internal API version 20030317. + */ + int (*getMSC)( void *screenPrivate, int64_t *msc ); + + /** + * Opaque pointer that points back to the containing + * \c __GLXscreenConfigs. This data structure is shared with DRI drivers + * but \c __GLXscreenConfigs is not. However, they are needed by some GLX + * functions called by DRI drivers. + * + * \since Internal API version 20030813. + */ + void *screenConfigs; + + /** + * Functions associated with MESA_allocate_memory. + * + * \since Internal API version 20030815. + */ + /*@{*/ + void *(*allocateMemory)(Display *dpy, int scrn, GLsizei size, + GLfloat readfreq, GLfloat writefreq, + GLfloat priority); + + void (*freeMemory)(Display *dpy, int scrn, GLvoid *pointer); + + GLuint (*memoryOffset)(Display *dpy, int scrn, const GLvoid *pointer); + /*@}*/ + + /** + * Method to create the private DRI context data and initialize the + * context dependent methods. + * + * \since Internal API version 20031201. + */ + void * (*createNewContext)(Display *dpy, const __GLcontextModes *modes, + int render_type, + void *sharedPrivate, __DRIcontext *pctx); +}; + +/** + * Context dependent methods. This structure is initialized during the + * \c __DRIscreenRec::createContext call. + */ +struct __DRIcontextRec { + /** + * Method to destroy the private DRI context data. + */ + void (*destroyContext)(Display *dpy, int scrn, void *contextPrivate); + + /** + * Method to bind a DRI drawable to a DRI graphics context. + */ + Bool (*bindContext)(Display *dpy, int scrn, GLXDrawable draw, + GLXContext gc); + + /** + * Method to unbind a DRI drawable to a DRI graphics context. + */ + Bool (*unbindContext)(Display *dpy, int scrn, GLXDrawable draw, + GLXContext gc, int will_rebind); + + /** + * Opaque pointer to private per context direct rendering data. + * \c NULL if direct rendering is not supported on the display or + * screen used to create this context. Never dereferenced in libGL. + */ + void *private; + + /** + * Method to bind a DRI drawable to a DRI graphics context. + * + * \since Internal API version 20030606. + */ + Bool (*bindContext2)(Display *dpy, int scrn, GLXDrawable draw, + GLXDrawable read, GLXContext gc); + + /** + * Method to unbind a DRI drawable to a DRI graphics context. + * + * \since Internal API version 20030606. + */ + Bool (*unbindContext2)(Display *dpy, int scrn, GLXDrawable draw, + GLXDrawable read, GLXContext gc); +}; + +/** + * Drawable dependent methods. This structure is initialized during the + * \c __DRIscreenRec::createDrawable call. \c createDrawable is not called + * by libGL at this time. It's currently used via the dri_util.c utility code + * instead. + */ +struct __DRIdrawableRec { + /** + * Method to destroy the private DRI drawable data. + */ + void (*destroyDrawable)(Display *dpy, void *drawablePrivate); + + /** + * Method to swap the front and back buffers. + */ + void (*swapBuffers)(Display *dpy, void *drawablePrivate); + + /** + * Opaque pointer to private per drawable direct rendering data. + * \c NULL if direct rendering is not supported on the display or + * screen used to create this drawable. Never dereferenced in libGL. + */ + void *private; + + /** + * Get the number of completed swap buffers for this drawable. + * + * \since Internal API version 20030317. + */ + int (*getSBC)(Display *dpy, void *drawablePrivate, int64_t *sbc ); + + /** + * Wait for the SBC to be greater than or equal target_sbc. + * + * \since Internal API version 20030317. + */ + int (*waitForSBC)( Display * dpy, void *drawablePriv, + int64_t target_sbc, + int64_t * msc, int64_t * sbc ); + + /** + * Wait for the MSC to equal target_msc, or, if that has already passed, + * the next time (MSC % divisor) is equal to remainder. If divisor is + * zero, the function will return as soon as MSC is greater than or equal + * to target_msc. + * + * \since Internal API version 20030317. + */ + int (*waitForMSC)( Display * dpy, void *drawablePriv, + int64_t target_msc, int64_t divisor, int64_t remainder, + int64_t * msc, int64_t * sbc ); + + /** + * Like \c swapBuffers, but does NOT have an implicit \c glFlush. Once + * rendering is complete, waits until MSC is equal to target_msc, or + * if that has already passed, waits until (MSC % divisor) is equal + * to remainder. If divisor is zero, the swap will happen as soon as + * MSC is greater than or equal to target_msc. + * + * \since Internal API version 20030317. + */ + int64_t (*swapBuffersMSC)(Display *dpy, void *drawablePrivate, + int64_t target_msc, + int64_t divisor, int64_t remainder); + + /** + * Enable or disable frame usage tracking. + * + * \since Internal API version 20030317. + */ + int (*frameTracking)(Display *dpy, void *drawablePrivate, Bool enable); + + /** + * Retrieve frame usage information. + * + * \since Internal API version 20030317. + */ + int (*queryFrameTracking)(Display *dpy, void *drawablePrivate, + int64_t * sbc, int64_t * missedFrames, + float * lastMissedUsage, float * usage ); + + /** + * Used by drivers that implement the GLX_SGI_swap_control or + * GLX_MESA_swap_control extension. + * + * \since Internal API version 20030317. + */ + unsigned swap_interval; +}; + + +/* +** We keep a linked list of these structures, one per DRI device driver. +*/ +struct __DRIdriverRec { + const char *name; + void *handle; + CreateScreenFunc createScreenFunc; + CreateNewScreenFunc createNewScreenFunc; + struct __DRIdriverRec *next; +}; + +/* +** Function to create and DRI display data and initialize the display +** dependent methods. +*/ +extern void *driCreateDisplay(Display *dpy, __DRIdisplay *pdisp); + +extern __DRIdriver *driGetDriver(Display *dpy, int scrNum); + +extern void DRI_glXUseXFont( Font font, int first, int count, int listbase ); + +/* +** Functions to obtain driver configuration information from a direct +** rendering client application +*/ +extern const char *glXGetScreenDriver (Display *dpy, int scrNum); + +extern const char *glXGetDriverConfig (const char *driverName); + +#endif + +/************************************************************************/ + +#define __GL_CLIENT_ATTRIB_STACK_DEPTH 16 + +typedef struct __GLXpixelStoreModeRec { + GLboolean swapEndian; + GLboolean lsbFirst; + GLuint rowLength; + GLuint imageHeight; + GLuint imageDepth; + GLuint skipRows; + GLuint skipPixels; + GLuint skipImages; + GLuint alignment; +} __GLXpixelStoreMode; + +/* The next 3 structures are deprecated. Client state is no longer tracked + * using them. They only remain to maintain the layout / structure offset of + * __GLXcontextRec. In XFree86 5.0 they will be removed altogether. + */ + +typedef struct __GLXvertexArrayPointerStateRecDEPRECATED { + GLboolean enable; + void (*proc)(const void *); + const GLubyte *ptr; + GLsizei skip; + GLint size; + GLenum type; + GLsizei stride; +} __GLXvertexArrayPointerStateDEPRECATED; + +typedef struct __GLXvertArrayStateRecDEPRECATED { + __GLXvertexArrayPointerStateDEPRECATED vertex; + __GLXvertexArrayPointerStateDEPRECATED normal; + __GLXvertexArrayPointerStateDEPRECATED color; + __GLXvertexArrayPointerStateDEPRECATED index; + __GLXvertexArrayPointerStateDEPRECATED texCoord[__GLX_MAX_TEXTURE_UNITS]; + __GLXvertexArrayPointerStateDEPRECATED edgeFlag; + GLint maxElementsVertices; + GLint maxElementsIndices; + GLint activeTexture; +} __GLXvertArrayStateDEPRECATED; + +typedef struct __GLXattributeRecDEPRECATED { + GLuint mask; + + /* + ** Pixel storage state. Most of the pixel store mode state is kept + ** here and used by the client code to manage the packing and + ** unpacking of data sent to/received from the server. + */ + __GLXpixelStoreMode storePack, storeUnpack; + + /* + ** Vertex Array storage state. The vertex array component + ** state is stored here and is used to manage the packing of + ** DrawArrays data sent to the server. + */ + __GLXvertArrayStateDEPRECATED vertArray; +} __GLXattributeDEPRECATED; + +typedef struct __GLXvertexArrayPointerStateRec { + void (*proc)(const void *); + void (*mtex_proc)(GLenum, const void *); + const GLubyte *ptr; + GLsizei skip; + GLint size; + GLenum type; + GLsizei stride; +} __GLXvertexArrayPointerState; + +/** + * Define which entries of \c __GLXvertArrayState::arrays match which + * vertex arrays in the client-state vector. These are only the one-of + * arrays. See the \c __GLXvertArrayState::arrays documentation for more + * details. + * + * \sa __GLXvertArrayState + */ +enum { + edgeFlag_ARRAY, /**< \c GL_EDGE_FLAG_ARRAY */ + index_ARRAY, /**< \c GL_INDEX_ARRAY */ + fogCoord_ARRAY, /**< \c GL_FOG_COORD_ARRAY */ + secondaryColor_ARRAY, /**< \c GL_SECONDARY_COLOR_ARRAY */ + color_ARRAY, /**< \c GL_COLOR_ARRAY */ + normal_ARRAY, /**< \c GL_NORMAL_ARRAY */ + + /** + * \c GL_VERTEX_ARRAY \b must be last! All of the code for emitting arrays + * and array elements is written based on the assumption that the vertex + * array is last. + */ + vertex_ARRAY, + + __GLX_MAX_ARRAYS /**< Place holder entry. */ +}; + +#define ENABLE_ARRAY(state,a) \ + do { (state)->vertArray.enables |= (1U << (a ## _ARRAY)); } while( 0 ) +#define DISABLE_ARRAY(state,a) \ + do { (state)->vertArray.enables &= ~(1U << (a ## _ARRAY)); } while( 0 ) +#define IS_ARRAY_ENABLED_BY_INDEX(state, i) \ + (((state)->vertArray.enables & (1U << (i))) != 0) +#define IS_ARRAY_ENABLED(state, a) \ + IS_ARRAY_ENABLED_BY_INDEX(state, a ## _ARRAY) + +#define ENABLE_TEXARRAY(state,a) \ + do { (state)->vertArray.texture_enables |= (1U << a); } while( 0 ) +#define DISABLE_TEXARRAY(state,a) \ + do { (state)->vertArray.texture_enables &= ~(1U << a); } while( 0 ) +#define IS_TEXARRAY_ENABLED(state, a) \ + (((state)->vertArray.texture_enables & (1U << a)) != 0) + +/** + * Client-side vertex array state. + */ +typedef struct __GLXvertArrayStateRec { + /** + * Which client-side arrays are enabled? These are the flag bits for + * all of the non-texture coordinate arrays. + */ + GLuint enables; + + /** + * Which of the texture coordinate arrays are enabled? + */ + GLuint texture_enables; + + /** + * State for "one-of" arrays. These are the arrays, such as + * GL_COLOR_ARRAY or GL_FOG_COORD_ARRAY for which there is only one + * array. There are also "many-of" arrays, such as + * GL_TEXTURE_COORD_ARRAY. + */ + __GLXvertexArrayPointerState arrays[__GLX_MAX_ARRAYS]; + + __GLXvertexArrayPointerState texCoord[__GLX_MAX_TEXTURE_UNITS]; + + GLint maxElementsVertices; + GLint maxElementsIndices; + GLint activeTexture; +} __GLXvertArrayState; + +typedef struct __GLXattributeRec { + GLuint mask; + + /* + ** Pixel storage state. Most of the pixel store mode state is kept + ** here and used by the client code to manage the packing and + ** unpacking of data sent to/received from the server. + */ + __GLXpixelStoreMode storePack, storeUnpack; + + /* + ** Vertex Array storage state. The vertex array component + ** state is stored here and is used to manage the packing of + ** DrawArrays data sent to the server. + */ + __GLXvertArrayState vertArray; + + /** + * Is EXT_vertex_array / GL 1.1 DrawArrays protocol specifically + * disabled? + */ + GLboolean NoDrawArraysProtocol; +} __GLXattribute; + +typedef struct __GLXattributeMachineRec { + __GLXattribute *stack[__GL_CLIENT_ATTRIB_STACK_DEPTH]; + __GLXattribute **stackPointer; +} __GLXattributeMachine; + +/** + * GLX state that needs to be kept on the client. One of these records + * exist for each context that has been made current by this client. + */ +struct __GLXcontextRec { + /** + * \name Drawing command buffer. + * + * Drawing commands are packed into this buffer before being sent as a + * single GLX protocol request. The buffer is sent when it overflows or + * is flushed by \c __glXFlushRenderBuffer. \c pc is the next location + * in the buffer to be filled. \c limit is described above in the buffer + * slop discussion. + * + * Commands that require large amounts of data to be transfered will + * also use this buffer to hold a header that describes the large + * command. + * + * These must be the first 6 fields since they are static initialized + * in the dummy context in glxext.c + */ + /*@{*/ + GLubyte *buf; + GLubyte *pc; + GLubyte *limit; + GLubyte *bufEnd; + GLint bufSize; + /*@}*/ + + /** + * The XID of this rendering context. When the context is created a + * new XID is allocated. This is set to None when the context is + * destroyed but is still current to some thread. In this case the + * context will be freed on next MakeCurrent. + */ + XID xid; + + /** + * The XID of the \c shareList context. + */ + XID share_xid; + + /** + * Visual id. + * + * \deprecated + * This filed has been largely been replaced by the \c mode field, but + * the work is not quite done. + */ + VisualID vid; + + /** + * Screen number. + */ + GLint screen; + + /** + * \c GL_TRUE if the context was created with ImportContext, which + * means the server-side context was created by another X client. + */ + GLboolean imported; + + /** + * The context tag returned by MakeCurrent when this context is made + * current. This tag is used to identify the context that a thread has + * current so that proper server context management can be done. It is + * used for all context specific commands (i.e., \c Render, \c RenderLarge, + * \c WaitX, \c WaitGL, \c UseXFont, and \c MakeCurrent (for the old + * context)). + */ + GLXContextTag currentContextTag; + + /** + * \name Rendering mode + * + * The rendering mode is kept on the client as well as the server. + * When \c glRenderMode is called, the buffer associated with the + * previous rendering mode (feedback or select) is filled. + */ + /*@{*/ + GLenum renderMode; + GLfloat *feedbackBuf; + GLuint *selectBuf; + /*@}*/ + + /** + * This is \c GL_TRUE if the pixel unpack modes are such that an image + * can be unpacked from the clients memory by just copying. It may + * still be true that the server will have to do some work. This + * just promises that a straight copy will fetch the correct bytes. + */ + GLboolean fastImageUnpack; + + /** + * Fill newImage with the unpacked form of \c oldImage getting it + * ready for transport to the server. + */ + void (*fillImage)(__GLXcontext*, GLint, GLint, GLint, GLint, GLenum, + GLenum, const GLvoid*, GLubyte*, GLubyte*); + + /** + * \name Client side attribs. + */ + /*@{*/ + __GLXattributeDEPRECATED stateDEPRECATED; + __GLXattributeMachine attributes; + /*@}*/ + + /** + * Client side error code. This is set when client side gl API + * routines need to set an error because of a bad enumerant or + * running out of memory, etc. + */ + GLenum error; + + /** + * Whether this context does direct rendering. + */ + Bool isDirect; + + /** + * \c dpy of current display for this context. Will be \c NULL if not + * current to any display, or if this is the "dummy context". + */ + Display *currentDpy; + + /** + * The current drawable for this context. Will be None if this + * context is not current to any drawable. currentReadable is below. + */ + GLXDrawable currentDrawable; + + /** + * \name GL Constant Strings + * + * Constant strings that describe the server implementation + * These pertain to GL attributes, not to be confused with + * GLX versioning attributes. + */ + /*@{*/ + GLubyte *vendor; + GLubyte *renderer; + GLubyte *version; + GLubyte *extensions; + /*@}*/ + + /** + * Record the dpy this context was created on for later freeing + */ + Display *createDpy; + + /** + * Maximum small render command size. This is the smaller of 64k and + * the size of the above buffer. + */ + GLint maxSmallRenderCommandSize; + + /** + * Major opcode for the extension. Copied here so a lookup isn't + * needed. + */ + GLint majorOpcode; + +#ifdef GLX_DIRECT_RENDERING + /** + * Per context direct rendering interface functions and data. + */ + __DRIcontext driContext; +#endif + + /** + * \c GLXFBConfigID used to create this context. May be \c None. This + * field has been replaced by the \c mode field. + * + * \since Internal API version 20030317. + * + * \deprecated + * This filed has been largely been replaced by the \c mode field, but + * the work is not quite done. + */ + GLXFBConfigID fbconfigID; + + /** + * The current read-drawable for this context. Will be None if this + * context is not current to any drawable. + * + * \since Internal API version 20030606. + */ + GLXDrawable currentReadable; + + /** + * Pointer to client-state data that is private to libGL. This is only + * used for indirect rendering contexts. + * + * No internal API version change was made for this change. Client-side + * drivers should NEVER use this data or even care that it exists. + */ + void * client_state_private; + +#ifdef GLX_DIRECT_RENDERING + /** + * Pointer to the mode used to create this context. This field replaces + * the \c vid and \c fbconfigID fields. + * + * \since Internal API version 20031201. + */ + const __GLcontextModes * mode; +#endif /* GLX_DIRECT_RENDERING */ +}; + +#define __glXSetError(gc,code) \ + if (!(gc)->error) { \ + (gc)->error = code; \ + } + +extern void __glFreeAttributeState(__GLXcontext *); + +/************************************************************************/ + +/** + * The size of the largest drawing command known to the implementation + * that will use the GLXRender GLX command. In this case it is + * \c glPolygonStipple. + */ +#define __GLX_MAX_SMALL_RENDER_CMD_SIZE 156 + +/** + * To keep the implementation fast, the code uses a "limit" pointer + * to determine when the drawing command buffer is too full to hold + * another fixed size command. This constant defines the amount of + * space that must always be available in the drawing command buffer + * at all times for the implementation to work. It is important that + * the number be just large enough, but not so large as to reduce the + * efficacy of the buffer. The "+32" is just to keep the code working + * in case somebody counts wrong. + */ +#define __GLX_BUFFER_LIMIT_SIZE (__GLX_MAX_SMALL_RENDER_CMD_SIZE + 32) + +/** + * This implementation uses a smaller threshold for switching + * to the RenderLarge protocol than the protcol requires so that + * large copies don't occur. + */ +#define __GLX_RENDER_CMD_SIZE_LIMIT 4096 + +/** + * One of these records exists per screen of the display. It contains + * a pointer to the config data for that screen (if the screen supports GL). + */ +typedef struct __GLXscreenConfigsRec { + /** + * GLX visuals formated as \c __GLXvisualConfig structures. + */ + /*@{*/ + __GLXvisualConfig * old_configs; + int numOldConfigs; + /*@}*/ + + /** + * GLX extension string reported by the X-server. + */ + const char *serverGLXexts; + + /** + * GLX extension string to be reported to applications. This is the + * set of extensions that the application can actually use. + */ + char *effectiveGLXexts; + +#ifdef GLX_DIRECT_RENDERING + /** + * Per screen direct rendering interface functions and data. + */ + __DRIscreen driScreen; +#endif + + /** + * Linked list of configurations for this screen. This is intended to + * be a superset of \c old_configs. + */ + __GLcontextModes *configs; + /** + * Per-screen dynamic GLX extension tracking. The \c direct_support + * field only contains enough bits for 64 extensions. Should libGL + * ever need to track more than 64 GLX extensions, we can safely grow + * this field. The \c __GLXscreenConfigs structure is not used outside + * libGL. + */ + /*@{*/ + unsigned char direct_support[8]; + GLboolean ext_list_first_time; + /*@}*/ + +} __GLXscreenConfigs; + +/** + * Per display private data. One of these records exists for each display + * that is using the OpenGL (GLX) extension. + */ +struct __GLXdisplayPrivateRec { + /** + * Back pointer to the display + */ + Display *dpy; + + /** + * The \c majorOpcode is common to all connections to the same server. + * It is also copied into the context structure. + */ + int majorOpcode; + + /** + * \name Server Version + * + * Major and minor version returned by the server during initialization. + */ + /*@{*/ + int majorVersion, minorVersion; + /*@}*/ + + /** + * \name Storage for the servers GLX vendor and versions strings. + * + * These are the same for all screens on this display. These fields will + * be filled in on demand. + */ + /*@{*/ + char *serverGLXvendor; + char *serverGLXversion; + /*@}*/ + + /** + * Configurations of visuals for all screens on this display. + * Also, per screen data which now includes the server \c GLX_EXTENSION + * string. + */ + __GLXscreenConfigs *screenConfigs; + +#ifdef GLX_DIRECT_RENDERING + /** + * Per display direct rendering interface functions and data. + */ + __DRIdisplay driDisplay; +#endif +}; + +void __glXFreeContext(__GLXcontext*); + +extern GLubyte *__glXFlushRenderBuffer(__GLXcontext*, GLubyte*); + +extern void __glXSendLargeChunk(__GLXcontext *gc, GLint requestNumber, + GLint totalRequests, + const GLvoid * data, GLint dataLen); + +extern void __glXSendLargeCommand(__GLXcontext *, const GLvoid *, GLint, + const GLvoid *, GLint); + +/* Initialize the GLX extension for dpy */ +extern __GLXdisplayPrivate *__glXInitialize(Display*); + +/************************************************************************/ + +extern int __glXDebug; + +/* This is per-thread storage in an MT environment */ +#if defined(GLX_DIRECT_RENDERING) && defined(XTHREADS) +extern __GLXcontext *__glXGetCurrentContext(void); +extern void __glXSetCurrentContext(__GLXcontext *c); +#else +extern __GLXcontext *__glXcurrentContext; +#define __glXGetCurrentContext() __glXcurrentContext +#define __glXSetCurrentContext(gc) __glXcurrentContext = gc +#endif + + +/* +** Global lock for all threads in this address space using the GLX +** extension +*/ +#if defined(GLX_DIRECT_RENDERING) && defined(XTHREADS) +extern xmutex_rec __glXmutex; +#define __glXLock() xmutex_lock(&__glXmutex) +#define __glXUnlock() xmutex_unlock(&__glXmutex) +#else +#define __glXLock() +#define __glXUnlock() +#endif + +/* +** Setup for a command. Initialize the extension for dpy if necessary. +*/ +extern CARD8 __glXSetupForCommand(Display *dpy); + +/************************************************************************/ + +/* +** Data conversion and packing support. +*/ + +/* Return the size, in bytes, of some pixel data */ +extern GLint __glImageSize(GLint, GLint, GLint, GLenum, GLenum); + +/* Return the number of elements per group of a specified format*/ +extern GLint __glElementsPerGroup(GLenum format, GLenum type); + +/* Return the number of bytes per element, based on the element type (other +** than GL_BITMAP). +*/ +extern GLint __glBytesPerElement(GLenum type); + +/* Return the k value for a given map target */ +extern GLint __glEvalComputeK(GLenum); + +/* +** Fill the transport buffer with the data from the users buffer, +** applying some of the pixel store modes (unpack modes) to the data +** first. As a side effect of this call, the "modes" field is +** updated to contain the modes needed by the server to decode the +** sent data. +*/ +extern void __glFillImage(__GLXcontext*, GLint, GLint, GLint, GLint, GLenum, + GLenum, const GLvoid*, GLubyte*, GLubyte*); + +/* Copy map data with a stride into a packed buffer */ +extern void __glFillMap1f(GLint, GLint, GLint, const GLfloat *, GLubyte *); +extern void __glFillMap1d(GLint, GLint, GLint, const GLdouble *, GLubyte *); +extern void __glFillMap2f(GLint, GLint, GLint, GLint, GLint, + const GLfloat *, GLfloat *); +extern void __glFillMap2d(GLint, GLint, GLint, GLint, GLint, + const GLdouble *, GLdouble *); + +/* +** Empty an image out of the reply buffer into the clients memory applying +** the pack modes to pack back into the clients requested format. +*/ +extern void __glEmptyImage(__GLXcontext*, GLint, GLint, GLint, GLint, GLenum, + GLenum, const GLubyte *, GLvoid *); + + +/* +** Allocate and Initialize Vertex Array client state +*/ +extern void __glXInitVertexArrayState(__GLXcontext*); + +/* +** Inform the Server of the major and minor numbers and of the client +** libraries extension string. +*/ +extern void __glXClientInfo ( Display *dpy, int opcode ); + +/************************************************************************/ + +/* +** Declarations that should be in Xlib +*/ +#ifdef __GL_USE_OUR_PROTOTYPES +extern void _XFlush(Display*); +extern Status _XReply(Display*, xReply*, int, Bool); +extern void _XRead(Display*, void*, long); +extern void _XSend(Display*, const void*, long); +#endif + + +/* +** GLX_BUILT_IN_XMESA controls whether libGL has a built-in verions of +** Mesa that can render to non-GLX displays. +*/ +#ifdef GLX_BUILT_IN_XMESA +#define GLX_PREFIX(function) _real_##function +#else +#define GLX_PREFIX(function) function +#endif + + +extern void __glXInitializeVisualConfigFromTags( __GLcontextModes *config, + int count, const INT32 *bp, Bool tagged_only, Bool fbconfig_style_tags ); + +extern char *__glXInternalQueryServerString( Display *dpy, int opcode, + int screen, int name ); + +extern char *__glXstrdup(const char *str); + + +extern const char __glXGLClientVersion[]; +extern const char __glXGLClientExtensions[]; +extern char *__glXCombineExtensionStrings( const char *cext_string, + const char *sext_string ); + +/* Determine the internal API version */ +extern int __glXGetInternalVersion(void); + +/** + * Type of a pointer to \c __glXGetInternalVersion, as returned by + * \c glXGetProcAddress. + * + * \sa __glXGetInternalVersion, glXGetProcAddress + */ +typedef int (* PFNGLXGETINTERNALVERSIONPROC) ( void ); + +/** + * Type of a pointer to \c __glXWindowExists, as returned by + * \c glXGetProcAddress. + * + * \sa __glXWindowExists, glXGetProcAddress + */ +typedef Bool (* PFNGLXWINDOWEXISTSPROC) (Display *dpy, GLXDrawable draw); + +/* Get the unadjusted system time */ +extern int __glXGetUST( int64_t * ust ); + +/** + * Type of a pointer to \c __glXGetUST, as returned by \c glXGetProcAddress. + * + * \sa __glXGetUST, glXGetProcAddress + */ +typedef int (* PFNGLXGETUSTPROC) ( int64_t * ust ); + + +/** + * Type of pointer to \c __glXCreateContextModes, as returned by + * \c glXGetProcAddress. + * + * \sa _gl_context_modes_create, glXGetProcAddress + */ + +typedef __GLcontextModes * (* PFNGLXCREATECONTEXTMODES) ( unsigned count, + size_t minimum_bytes_per_struct ); + +#endif /* !__GLX_client_h__ */ diff --git a/src/mesa/drivers/dri/dri_client/imports/sarea.h b/src/mesa/drivers/dri/dri_client/imports/sarea.h new file mode 100644 index 0000000000..d4d83df930 --- /dev/null +++ b/src/mesa/drivers/dri/dri_client/imports/sarea.h @@ -0,0 +1,94 @@ +/* $XFree86: xc/programs/Xserver/GL/dri/sarea.h,v 1.11 2002/10/30 12:52:03 alanh Exp $ */ +/** + * \file sarea.h + * SAREA definitions. + * + * \author Kevin E. Martin <kevin@precisioninsight.com> + * \author Jens Owen <jens@tungstengraphics.com> + * \author Rickard E. (Rik) Faith <faith@valinux.com> + */ + +/* + * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. + * Copyright 2000 VA Linux Systems, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* $XFree86: xc/programs/Xserver/GL/dri/sarea.h,v 1.11 2002/10/30 12:52:03 alanh Exp $ */ + +#ifndef _SAREA_H_ +#define _SAREA_H_ + +#include "xf86drm.h" + +/* SAREA area needs to be at least a page */ +#if defined(__alpha__) +#define SAREA_MAX 0x2000 +#elif defined(__ia64__) +#define SAREA_MAX 0x10000 /* 64kB */ +#else +/* Intel 830M driver needs at least 8k SAREA */ +#define SAREA_MAX 0x2000 +#endif + +#define SAREA_MAX_DRAWABLES 256 + +#define SAREA_DRAWABLE_CLAIMED_ENTRY 0x80000000 + +/** + * SAREA per drawable information. + * + * \sa _XF86DRISAREA. + */ +typedef struct _XF86DRISAREADrawable { + unsigned int stamp; + unsigned int flags; +} XF86DRISAREADrawableRec, *XF86DRISAREADrawablePtr; + +/** + * SAREA frame information. + * + * \sa _XF86DRISAREA. + */ +typedef struct _XF86DRISAREAFrame { + unsigned int x; + unsigned int y; + unsigned int width; + unsigned int height; + unsigned int fullscreen; +} XF86DRISAREAFrameRec, *XF86DRISAREAFramePtr; + +/** + * SAREA definition. + */ +typedef struct _XF86DRISAREA { + /** first thing is always the DRM locking structure */ + drmLock lock; + /** \todo Use readers/writer lock for drawable_lock */ + drmLock drawable_lock; + XF86DRISAREADrawableRec drawableTable[SAREA_MAX_DRAWABLES]; + XF86DRISAREAFrameRec frame; + drmContext dummy_context; +} XF86DRISAREARec, *XF86DRISAREAPtr; + +#endif diff --git a/src/mesa/drivers/dri/dri_client/imports/xf86drm.h b/src/mesa/drivers/dri/dri_client/imports/xf86drm.h new file mode 100644 index 0000000000..c9f1007498 --- /dev/null +++ b/src/mesa/drivers/dri/dri_client/imports/xf86drm.h @@ -0,0 +1,646 @@ +/** + * \file xf86drm.h + * OS-independent header for DRM user-level library interface. + * + * \author Rickard E. (Rik) Faith <faith@valinux.com> + */ + +/* + * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas. + * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ + +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86drm.h,v 1.26 2003/08/16 19:26:37 dawes Exp $ */ + +#ifndef _XF86DRM_H_ +#define _XF86DRM_H_ + + /* Defaults, if nothing set in xf86config */ +#define DRM_DEV_UID 0 +#define DRM_DEV_GID 0 +/* Default /dev/dri directory permissions 0755 */ +#define DRM_DEV_DIRMODE \ + (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) +#define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) + +#define DRM_DIR_NAME "/dev/dri" +#define DRM_DEV_NAME "%s/card%d" +#define DRM_PROC_NAME "/proc/dri/" /* For backward Linux compatibility */ + +#define DRM_ERR_NO_DEVICE (-1001) +#define DRM_ERR_NO_ACCESS (-1002) +#define DRM_ERR_NOT_ROOT (-1003) +#define DRM_ERR_INVALID (-1004) +#define DRM_ERR_NO_FD (-1005) + +#define DRM_AGP_NO_HANDLE 0 + +typedef unsigned long drmHandle, *drmHandlePtr; /**< To mapped regions */ +typedef unsigned int drmSize, *drmSizePtr; /**< For mapped regions */ +typedef void *drmAddress, **drmAddressPtr; /**< For mapped regions */ +typedef unsigned int drmContext, *drmContextPtr; /**< GLXContext handle */ +typedef unsigned int drmDrawable, *drmDrawablePtr; /**< Unused */ +typedef unsigned int drmMagic, *drmMagicPtr; /**< Magic for authentication */ + +/** + * Driver version information. + * + * \sa drmGetVersion() and drmSetVersion(). + */ +typedef struct _drmVersion { + int version_major; /**< Major version */ + int version_minor; /**< Minor version */ + int version_patchlevel; /**< Patch level */ + int name_len; /**< Length of name buffer */ + char *name; /**< Name of driver */ + int date_len; /**< Length of date buffer */ + char *date; /**< User-space buffer to hold date */ + int desc_len; /**< Length of desc buffer */ + char *desc; /**< User-space buffer to hold desc */ +} drmVersion, *drmVersionPtr; + +typedef struct _drmStats { + unsigned long count; /**< Number of data */ + struct { + unsigned long value; /**< Value from kernel */ + const char *long_format; /**< Suggested format for long_name */ + const char *long_name; /**< Long name for value */ + const char *rate_format; /**< Suggested format for rate_name */ + const char *rate_name; /**< Short name for value per second */ + int isvalue; /**< True if value (vs. counter) */ + const char *mult_names; /**< Multiplier names (e.g., "KGM") */ + int mult; /**< Multiplier value (e.g., 1024) */ + int verbose; /**< Suggest only in verbose output */ + } data[15]; +} drmStatsT; + + + /* All of these enums *MUST* match with the + kernel implementation -- so do *NOT* + change them! (The drmlib implementation + will just copy the flags instead of + translating them.) */ +typedef enum { + DRM_FRAME_BUFFER = 0, /**< WC, no caching, no core dump */ + DRM_REGISTERS = 1, /**< no caching, no core dump */ + DRM_SHM = 2, /**< shared, cached */ + DRM_AGP = 3, /**< AGP/GART */ + DRM_SCATTER_GATHER = 4 /**< PCI scatter/gather */ +} drmMapType; + +typedef enum { + DRM_RESTRICTED = 0x0001, /**< Cannot be mapped to client-virtual */ + DRM_READ_ONLY = 0x0002, /**< Read-only in client-virtual */ + DRM_LOCKED = 0x0004, /**< Physical pages locked */ + DRM_KERNEL = 0x0008, /**< Kernel requires access */ + DRM_WRITE_COMBINING = 0x0010, /**< Use write-combining, if available */ + DRM_CONTAINS_LOCK = 0x0020, /**< SHM page that contains lock */ + DRM_REMOVABLE = 0x0040 /**< Removable mapping */ +} drmMapFlags; + +/** + * \warning These values *MUST* match drm.h + */ +typedef enum { + /** \name Flags for DMA buffer dispatch */ + /*@{*/ + DRM_DMA_BLOCK = 0x01, /**< + * Block until buffer dispatched. + * + * \note the buffer may not yet have been + * processed by the hardware -- getting a + * hardware lock with the hardware quiescent + * will ensure that the buffer has been + * processed. + */ + DRM_DMA_WHILE_LOCKED = 0x02, /**< Dispatch while lock held */ + DRM_DMA_PRIORITY = 0x04, /**< High priority dispatch */ + /*@}*/ + + /** \name Flags for DMA buffer request */ + /*@{*/ + DRM_DMA_WAIT = 0x10, /**< Wait for free buffers */ + DRM_DMA_SMALLER_OK = 0x20, /**< Smaller-than-requested buffers OK */ + DRM_DMA_LARGER_OK = 0x40 /**< Larger-than-requested buffers OK */ + /*@}*/ +} drmDMAFlags; + +typedef enum { + DRM_PAGE_ALIGN = 0x01, + DRM_AGP_BUFFER = 0x02, + DRM_SG_BUFFER = 0x04 +} drmBufDescFlags; + +typedef enum { + DRM_LOCK_READY = 0x01, /**< Wait until hardware is ready for DMA */ + DRM_LOCK_QUIESCENT = 0x02, /**< Wait until hardware quiescent */ + DRM_LOCK_FLUSH = 0x04, /**< Flush this context's DMA queue first */ + DRM_LOCK_FLUSH_ALL = 0x08, /**< Flush all DMA queues first */ + /* These *HALT* flags aren't supported yet + -- they will be used to support the + full-screen DGA-like mode. */ + DRM_HALT_ALL_QUEUES = 0x10, /**< Halt all current and future queues */ + DRM_HALT_CUR_QUEUES = 0x20 /**< Halt all current queues */ +} drmLockFlags; + +typedef enum { + DRM_CONTEXT_PRESERVED = 0x01, /**< This context is preserved and + never swapped. */ + DRM_CONTEXT_2DONLY = 0x02 /**< This context is for 2D rendering only. */ +} drmContextFlags, *drmContextFlagsPtr; + +typedef struct _drmBufDesc { + int count; /**< Number of buffers of this size */ + int size; /**< Size in bytes */ + int low_mark; /**< Low water mark */ + int high_mark; /**< High water mark */ +} drmBufDesc, *drmBufDescPtr; + +typedef struct _drmBufInfo { + int count; /**< Number of buffers described in list */ + drmBufDescPtr list; /**< List of buffer descriptions */ +} drmBufInfo, *drmBufInfoPtr; + +typedef struct _drmBuf { + int idx; /**< Index into the master buffer list */ + int total; /**< Buffer size */ + int used; /**< Amount of buffer in use (for DMA) */ + drmAddress address; /**< Address */ +} drmBuf, *drmBufPtr; + +/** + * Buffer mapping information. + * + * Used by drmMapBufs() and drmUnmapBufs() to store information about the + * mapped buffers. + */ +typedef struct _drmBufMap { + int count; /**< Number of buffers mapped */ + drmBufPtr list; /**< Buffers */ +} drmBufMap, *drmBufMapPtr; + +typedef struct _drmLock { + volatile unsigned int lock; + char padding[60]; + /* This is big enough for most current (and future?) architectures: + DEC Alpha: 32 bytes + Intel Merced: ? + Intel P5/PPro/PII/PIII: 32 bytes + Intel StrongARM: 32 bytes + Intel i386/i486: 16 bytes + MIPS: 32 bytes (?) + Motorola 68k: 16 bytes + Motorola PowerPC: 32 bytes + Sun SPARC: 32 bytes + */ +} drmLock, *drmLockPtr; + +/** + * Indices here refer to the offset into + * list in drmBufInfo + */ +typedef struct _drmDMAReq { + drmContext context; /**< Context handle */ + int send_count; /**< Number of buffers to send */ + int *send_list; /**< List of handles to buffers */ + int *send_sizes; /**< Lengths of data to send, in bytes */ + drmDMAFlags flags; /**< Flags */ + int request_count; /**< Number of buffers requested */ + int request_size; /**< Desired size of buffers requested */ + int *request_list; /**< Buffer information */ + int *request_sizes; /**< Minimum acceptable sizes */ + int granted_count; /**< Number of buffers granted at this size */ +} drmDMAReq, *drmDMAReqPtr; + +typedef struct _drmRegion { + drmHandle handle; + unsigned int offset; + drmSize size; + drmAddress map; +} drmRegion, *drmRegionPtr; + +typedef struct _drmTextureRegion { + unsigned char next; + unsigned char prev; + unsigned char in_use; + unsigned char padding; /**< Explicitly pad this out */ + unsigned int age; +} drmTextureRegion, *drmTextureRegionPtr; + + +typedef struct _drmClipRect { + unsigned short x1; /* Upper left: inclusive */ + unsigned short y1; + unsigned short x2; /* Lower right: exclusive */ + unsigned short y2; +} drmClipRect, *drmClipRectPtr; + + +typedef enum { + DRM_VBLANK_ABSOLUTE = 0x0, /**< Wait for specific vblank sequence number */ + DRM_VBLANK_RELATIVE = 0x1, /**< Wait for given number of vblanks */ + DRM_VBLANK_SIGNAL = 0x40000000 /* Send signal instead of blocking */ +} drmVBlankSeqType; + +typedef struct _drmVBlankReq { + drmVBlankSeqType type; + unsigned int sequence; + unsigned long signal; +} drmVBlankReq, *drmVBlankReqPtr; + +typedef struct _drmVBlankReply { + drmVBlankSeqType type; + unsigned int sequence; + long tval_sec; + long tval_usec; +} drmVBlankReply, *drmVBlankReplyPtr; + +typedef union _drmVBlank { + drmVBlankReq request; + drmVBlankReply reply; +} drmVBlank, *drmVBlankPtr; + +typedef struct _drmSetVersion { + int drm_di_major; + int drm_di_minor; + int drm_dd_major; + int drm_dd_minor; +} drmSetVersion, *drmSetVersionPtr; + + +#define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock) + +#define DRM_LOCK_HELD 0x80000000 /**< Hardware lock is held */ +#define DRM_LOCK_CONT 0x40000000 /**< Hardware lock is contended */ + +#if defined(__GNUC__) && (__GNUC__ >= 2) +# if defined(__i386) || defined(__AMD64__) + /* Reflect changes here to drmP.h */ +#define DRM_CAS(lock,old,new,__ret) \ + do { \ + int __dummy; /* Can't mark eax as clobbered */ \ + __asm__ __volatile__( \ + "lock ; cmpxchg %4,%1\n\t" \ + "setnz %0" \ + : "=d" (__ret), \ + "=m" (__drm_dummy_lock(lock)), \ + "=a" (__dummy) \ + : "2" (old), \ + "r" (new)); \ + } while (0) + +#elif defined(__alpha__) + +#define DRM_CAS(lock, old, new, ret) \ + do { \ + int old32; \ + int cur32; \ + __asm__ __volatile__( \ + " mb\n" \ + " zap %4, 0xF0, %0\n" \ + " ldl_l %1, %2\n" \ + " zap %1, 0xF0, %1\n" \ + " cmpeq %0, %1, %1\n" \ + " beq %1, 1f\n" \ + " bis %5, %5, %1\n" \ + " stl_c %1, %2\n" \ + "1: xor %1, 1, %1\n" \ + " stl %1, %3" \ + : "+r" (old32), \ + "+&r" (cur32), \ + "=m" (__drm_dummy_lock(lock)),\ + "=m" (ret) \ + : "r" (old), \ + "r" (new)); \ + } while(0) + +#elif defined(__sparc__) + +#define DRM_CAS(lock,old,new,__ret) \ +do { register unsigned int __old __asm("o0"); \ + register unsigned int __new __asm("o1"); \ + register volatile unsigned int *__lock __asm("o2"); \ + __old = old; \ + __new = new; \ + __lock = (volatile unsigned int *)lock; \ + __asm__ __volatile__( \ + /*"cas [%2], %3, %0"*/ \ + ".word 0xd3e29008\n\t" \ + /*"membar #StoreStore | #StoreLoad"*/ \ + ".word 0x8143e00a" \ + : "=&r" (__new) \ + : "0" (__new), \ + "r" (__lock), \ + "r" (__old) \ + : "memory"); \ + __ret = (__new != __old); \ +} while(0) + +#elif defined(__ia64__) + +#ifdef __INTEL_COMPILER +/* this currently generates bad code (missing stop bits)... */ +#include <ia64intrin.h> + +#define DRM_CAS(lock,old,new,__ret) \ + do { \ + unsigned long __result, __old = (old) & 0xffffffff; \ + __mf(); \ + __result = _InterlockedCompareExchange_acq(&__drm_dummy_lock(lock), (new), __old);\ + __ret = (__result) != (__old); \ +/* __ret = (__sync_val_compare_and_swap(&__drm_dummy_lock(lock), \ + (old), (new)) \ + != (old)); */\ + } while (0) + +#else +#define DRM_CAS(lock,old,new,__ret) \ + do { \ + unsigned int __result, __old = (old); \ + __asm__ __volatile__( \ + "mf\n" \ + "mov ar.ccv=%2\n" \ + ";;\n" \ + "cmpxchg4.acq %0=%1,%3,ar.ccv" \ + : "=r" (__result), "=m" (__drm_dummy_lock(lock)) \ + : "r" ((unsigned long)__old), "r" (new) \ + : "memory"); \ + __ret = (__result) != (__old); \ + } while (0) + +#endif + +#elif defined(__powerpc__) + +#define DRM_CAS(lock,old,new,__ret) \ + do { \ + __asm__ __volatile__( \ + "sync;" \ + "0: lwarx %0,0,%1;" \ + " xor. %0,%3,%0;" \ + " bne 1f;" \ + " stwcx. %2,0,%1;" \ + " bne- 0b;" \ + "1: " \ + "sync;" \ + : "=&r"(__ret) \ + : "r"(lock), "r"(new), "r"(old) \ + : "cr0", "memory"); \ + } while (0) + +#endif /* architecture */ +#endif /* __GNUC__ >= 2 */ + +#ifndef DRM_CAS +#define DRM_CAS(lock,old,new,ret) do { ret=1; } while (0) /* FAST LOCK FAILS */ +#endif + +#if defined(__alpha__) || defined(__powerpc__) +#define DRM_CAS_RESULT(_result) int _result +#else +#define DRM_CAS_RESULT(_result) char _result +#endif + +#define DRM_LIGHT_LOCK(fd,lock,context) \ + do { \ + DRM_CAS_RESULT(__ret); \ + DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \ + if (__ret) drmGetLock(fd,context,0); \ + } while(0) + + /* This one counts fast locks -- for + benchmarking only. */ +#define DRM_LIGHT_LOCK_COUNT(fd,lock,context,count) \ + do { \ + DRM_CAS_RESULT(__ret); \ + DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \ + if (__ret) drmGetLock(fd,context,0); \ + else ++count; \ + } while(0) + +#define DRM_LOCK(fd,lock,context,flags) \ + do { \ + if (flags) drmGetLock(fd,context,flags); \ + else DRM_LIGHT_LOCK(fd,lock,context); \ + } while(0) + +#define DRM_UNLOCK(fd,lock,context) \ + do { \ + DRM_CAS_RESULT(__ret); \ + DRM_CAS(lock,DRM_LOCK_HELD|context,context,__ret); \ + if (__ret) drmUnlock(fd,context); \ + } while(0) + + /* Simple spin locks */ +#define DRM_SPINLOCK(spin,val) \ + do { \ + DRM_CAS_RESULT(__ret); \ + do { \ + DRM_CAS(spin,0,val,__ret); \ + if (__ret) while ((spin)->lock); \ + } while (__ret); \ + } while(0) + +#define DRM_SPINLOCK_TAKE(spin,val) \ + do { \ + DRM_CAS_RESULT(__ret); \ + int cur; \ + do { \ + cur = (*spin).lock; \ + DRM_CAS(spin,cur,val,__ret); \ + } while (__ret); \ + } while(0) + +#define DRM_SPINLOCK_COUNT(spin,val,count,__ret) \ + do { \ + int __i; \ + __ret = 1; \ + for (__i = 0; __ret && __i < count; __i++) { \ + DRM_CAS(spin,0,val,__ret); \ + if (__ret) for (;__i < count && (spin)->lock; __i++); \ + } \ + } while(0) + +#define DRM_SPINUNLOCK(spin,val) \ + do { \ + DRM_CAS_RESULT(__ret); \ + if ((*spin).lock == val) { /* else server stole lock */ \ + do { \ + DRM_CAS(spin,val,0,__ret); \ + } while (__ret); \ + } \ + } while(0) + +/* General user-level programmer's API: unprivileged */ +extern int drmAvailable(void); +extern int drmOpen(const char *name, const char *busid); +extern int drmClose(int fd); +extern drmVersionPtr drmGetVersion(int fd); +extern drmVersionPtr drmGetLibVersion(int fd); +extern void drmFreeVersion(drmVersionPtr); +extern int drmGetMagic(int fd, drmMagicPtr magic); +extern char *drmGetBusid(int fd); +extern int drmGetInterruptFromBusID(int fd, int busnum, int devnum, + int funcnum); +extern int drmGetMap(int fd, int idx, drmHandle *offset, + drmSize *size, drmMapType *type, + drmMapFlags *flags, drmHandle *handle, + int *mtrr); +extern int drmGetClient(int fd, int idx, int *auth, int *pid, + int *uid, unsigned long *magic, + unsigned long *iocs); +extern int drmGetStats(int fd, drmStatsT *stats); +extern int drmSetInterfaceVersion(int fd, drmSetVersion *version); +extern int drmCommandNone(int fd, unsigned long drmCommandIndex); +extern int drmCommandRead(int fd, unsigned long drmCommandIndex, + void *data, unsigned long size); +extern int drmCommandWrite(int fd, unsigned long drmCommandIndex, + void *data, unsigned long size); +extern int drmCommandWriteRead(int fd, unsigned long drmCommandIndex, + void *data, unsigned long size); + +/* General user-level programmer's API: X server (root) only */ +extern void drmFreeBusid(const char *busid); +extern int drmSetBusid(int fd, const char *busid); +extern int drmAuthMagic(int fd, drmMagic magic); +extern int drmAddMap(int fd, + drmHandle offset, + drmSize size, + drmMapType type, + drmMapFlags flags, + drmHandlePtr handle); +extern int drmRmMap(int fd, drmHandle handle); +extern int drmAddContextPrivateMapping(int fd, drmContext ctx_id, + drmHandle handle); + +extern int drmAddBufs(int fd, int count, int size, + drmBufDescFlags flags, + int agp_offset); +extern int drmMarkBufs(int fd, double low, double high); +extern int drmCreateContext(int fd, drmContextPtr handle); +extern int drmSetContextFlags(int fd, drmContext context, + drmContextFlags flags); +extern int drmGetContextFlags(int fd, drmContext context, + drmContextFlagsPtr flags); +extern int drmAddContextTag(int fd, drmContext context, void *tag); +extern int drmDelContextTag(int fd, drmContext context); +extern void *drmGetContextTag(int fd, drmContext context); +extern drmContextPtr drmGetReservedContextList(int fd, int *count); +extern void drmFreeReservedContextList(drmContextPtr); +extern int drmSwitchToContext(int fd, drmContext context); +extern int drmDestroyContext(int fd, drmContext handle); +extern int drmCreateDrawable(int fd, drmDrawablePtr handle); +extern int drmDestroyDrawable(int fd, drmDrawable handle); +extern int drmCtlInstHandler(int fd, int irq); +extern int drmCtlUninstHandler(int fd); +extern int drmInstallSIGIOHandler(int fd, + void (*f)(int fd, + void *oldctx, + void *newctx)); +extern int drmRemoveSIGIOHandler(int fd); + +/* General user-level programmer's API: authenticated client and/or X */ +extern int drmMap(int fd, + drmHandle handle, + drmSize size, + drmAddressPtr address); +extern int drmUnmap(drmAddress address, drmSize size); +extern drmBufInfoPtr drmGetBufInfo(int fd); +extern drmBufMapPtr drmMapBufs(int fd); +extern int drmUnmapBufs(drmBufMapPtr bufs); +extern int drmDMA(int fd, drmDMAReqPtr request); +extern int drmFreeBufs(int fd, int count, int *list); +extern int drmGetLock(int fd, + drmContext context, + drmLockFlags flags); +extern int drmUnlock(int fd, drmContext context); +extern int drmFinish(int fd, int context, drmLockFlags flags); +extern int drmGetContextPrivateMapping(int fd, drmContext ctx_id, + drmHandlePtr handle); + +/* AGP/GART support: X server (root) only */ +extern int drmAgpAcquire(int fd); +extern int drmAgpRelease(int fd); +extern int drmAgpEnable(int fd, unsigned long mode); +extern int drmAgpAlloc(int fd, unsigned long size, + unsigned long type, unsigned long *address, + unsigned long *handle); +extern int drmAgpFree(int fd, unsigned long handle); +extern int drmAgpBind(int fd, unsigned long handle, + unsigned long offset); +extern int drmAgpUnbind(int fd, unsigned long handle); + +/* AGP/GART info: authenticated client and/or X */ +extern int drmAgpVersionMajor(int fd); +extern int drmAgpVersionMinor(int fd); +extern unsigned long drmAgpGetMode(int fd); +extern unsigned long drmAgpBase(int fd); /* Physical location */ +extern unsigned long drmAgpSize(int fd); /* Bytes */ +extern unsigned long drmAgpMemoryUsed(int fd); +extern unsigned long drmAgpMemoryAvail(int fd); +extern unsigned int drmAgpVendorId(int fd); +extern unsigned int drmAgpDeviceId(int fd); + +/* PCI scatter/gather support: X server (root) only */ +extern int drmScatterGatherAlloc(int fd, unsigned long size, + unsigned long *handle); +extern int drmScatterGatherFree(int fd, unsigned long handle); + +extern int drmWaitVBlank(int fd, drmVBlankPtr vbl); + +/* Support routines */ +extern int drmError(int err, const char *label); +extern void *drmMalloc(int size); +extern void drmFree(void *pt); + +/* Hash table routines */ +extern void *drmHashCreate(void); +extern int drmHashDestroy(void *t); +extern int drmHashLookup(void *t, unsigned long key, void **value); +extern int drmHashInsert(void *t, unsigned long key, void *value); +extern int drmHashDelete(void *t, unsigned long key); +extern int drmHashFirst(void *t, unsigned long *key, void **value); +extern int drmHashNext(void *t, unsigned long *key, void **value); + +/* PRNG routines */ +extern void *drmRandomCreate(unsigned long seed); +extern int drmRandomDestroy(void *state); +extern unsigned long drmRandom(void *state); +extern double drmRandomDouble(void *state); + +/* Skip list routines */ + +extern void *drmSLCreate(void); +extern int drmSLDestroy(void *l); +extern int drmSLLookup(void *l, unsigned long key, void **value); +extern int drmSLInsert(void *l, unsigned long key, void *value); +extern int drmSLDelete(void *l, unsigned long key); +extern int drmSLNext(void *l, unsigned long *key, void **value); +extern int drmSLFirst(void *l, unsigned long *key, void **value); +extern void drmSLDump(void *l); +extern int drmSLLookupNeighbors(void *l, unsigned long key, + unsigned long *prev_key, void **prev_value, + unsigned long *next_key, void **next_value); + +#endif |