Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / drivers / dri / mga / mga_xmesa.h
1 /*
2  * Copyright 2000-2001 VA Linux Systems, Inc.
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * on the rights to use, copy, modify, merge, publish, distribute, sub
9  * license, and/or sell copies of the Software, and to permit persons to whom
10  * the Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors:
25  *    Keith Whitwell <keith@tungstengraphics.com>
26  */
27
28 #ifndef _MGA_INIT_H_
29 #define _MGA_INIT_H_
30
31 #include <sys/time.h>
32 #include "dri_util.h"
33 #include "mga_drm.h"
34 #include "main/mtypes.h"
35 #include "mgaregs.h"
36 #include "xmlconfig.h"
37
38 typedef struct mga_screen_private_s {
39    /**
40     * Chipset "family" of this card.  Currently only \c MGA_CARD_TYPE_G200 and
41     * \c MGA_CARD_TYPE_G400 are possible.
42     */
43    int chipset;
44
45
46    /**
47     * Characters (bytes) per-pixel for both the front and back buffers.
48     * 
49     * \note
50     * This is also implicitly the bytes per-pixel for the depth-buffer.
51     */
52    int cpp;
53
54    GLint agpMode;
55    unsigned int irq;            /**< IRQ number (0 means none) */
56
57    unsigned int frontOffset;
58    unsigned int frontPitch;
59    unsigned int backOffset;
60    unsigned int backPitch;
61
62    unsigned int depthOffset;
63    unsigned int depthPitch;
64
65    unsigned int textureOffset[MGA_NR_TEX_HEAPS];
66    unsigned int textureSize[MGA_NR_TEX_HEAPS];
67    char *texVirtual[MGA_NR_TEX_HEAPS];
68
69
70    __DRIscreen *sPriv;
71    drmBufMapPtr  bufs;
72
73    drmRegion mmio;
74    drmRegion primary;
75    unsigned int sarea_priv_offset;
76
77    /** Configuration cache with default values for all contexts */
78    driOptionCache optionCache;
79 } mgaScreenPrivate;
80
81
82 /**
83  * mgaRenderbuffer, derived from Mesa's gl_renderbuffer
84  */
85 typedef struct {
86    struct gl_renderbuffer Base;
87    /* XXX per-window info should go here */
88    int foo, bar;
89 } mgaRenderbuffer;
90
91
92
93 #include "mgacontext.h"
94
95 extern void mgaGetLock( mgaContextPtr mmesa, GLuint flags );
96 extern void mgaEmitHwStateLocked( mgaContextPtr mmesa );
97 extern void mgaEmitScissorValues( mgaContextPtr mmesa, int box_nr, int emit );
98
99 #define GET_DISPATCH_AGE( mmesa ) mmesa->sarea->last_dispatch
100
101
102
103 /* Lock the hardware and validate our state.
104  */
105 #define LOCK_HARDWARE( mmesa )                                  \
106   do {                                                          \
107     char __ret=0;                                               \
108     DRM_CAS(mmesa->driHwLock, mmesa->hHWContext,                \
109             (DRM_LOCK_HELD|mmesa->hHWContext), __ret);          \
110     if (__ret)                                                  \
111         mgaGetLock( mmesa, 0 );                                 \
112   } while (0)
113
114
115 /*
116  */
117 #define LOCK_HARDWARE_QUIESCENT( mmesa ) do {                           \
118         LOCK_HARDWARE( mmesa );                                         \
119         UPDATE_LOCK( mmesa, DRM_LOCK_QUIESCENT | DRM_LOCK_FLUSH );      \
120 } while (0)
121
122
123 /* Unlock the hardware using the global current context
124  */
125 #define UNLOCK_HARDWARE(mmesa)                          \
126     DRM_UNLOCK(mmesa->driFd, mmesa->driHwLock, mmesa->hHWContext);
127
128
129 /* Freshen our snapshot of the drawables
130  */
131 #define REFRESH_DRAWABLE_INFO( mmesa )          \
132 do {                                            \
133    LOCK_HARDWARE( mmesa );                      \
134    mmesa->lastX = mmesa->drawX;                 \
135    mmesa->lastY = mmesa->drawY;                 \
136    UNLOCK_HARDWARE( mmesa );                    \
137 } while (0)
138
139
140 #define GET_DRAWABLE_LOCK( mmesa ) while(0)
141 #define RELEASE_DRAWABLE_LOCK( mmesa ) while(0)
142
143
144 /* The 2D driver macros are busted -- we can't use them here as they
145  * rely on the 2D driver data structures rather than taking an explicit
146  * base address.
147  */
148 #define MGA_BASE( reg )         ((unsigned long)(mmesa->mgaScreen->mmio.map))
149 #define MGA_ADDR( reg )         (MGA_BASE(reg) + reg)
150
151 #define MGA_DEREF( reg )        *(volatile uint32_t *)MGA_ADDR( reg )
152 #define MGA_READ( reg )         MGA_DEREF( reg )
153
154 #endif