Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / drivers / dri / mga / mgaioctl.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  *    Gareth Hughes <gareth@valinux.com>
27  */
28
29 #ifndef MGA_IOCTL_H
30 #define MGA_IOCTL_H
31
32 #include "mgacontext.h"
33 #include "mga_xmesa.h"
34
35 void mgaCopyBuffer( __DRIdrawable *dPriv );
36 void mgaWaitForVBlank( mgaContextPtr mmesa );
37
38 void mgaGetILoadBufferLocked( mgaContextPtr mmesa );
39 void mgaFireILoadLocked( mgaContextPtr mmesa,
40                          GLuint offset, GLuint length );
41
42 void mgaWaitAgeLocked( mgaContextPtr mmesa, int age );
43
44 void mgaFlushVertices( mgaContextPtr mmesa );
45 void mgaFlushVerticesLocked( mgaContextPtr mmesa );
46 int mgaFlushDMA( int fd, drmLockFlags flags );
47
48 void mgaInitIoctlFuncs( struct dd_function_table *functions );
49
50 #define FLUSH_BATCH(mmesa) do {                                         \
51         if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL)                              \
52               fprintf(stderr, "FLUSH_BATCH in %s\n", __FUNCTION__);     \
53         if (mmesa->vertex_dma_buffer) mgaFlushVertices(mmesa);          \
54 } while (0)
55
56 #define MGA_STATECHANGE(mmesa, flag) do {       \
57    FLUSH_BATCH(mmesa);                          \
58    mmesa->dirty |= flag;                        \
59 } while (0)
60
61
62 extern drmBufPtr mga_get_buffer_ioctl( mgaContextPtr mmesa );
63
64 static INLINE
65 GLuint *mgaAllocDmaLow( mgaContextPtr mmesa, int bytes )
66 {
67    GLuint *head;
68
69    /* If there is no DMA buffer currently allocated or the currently
70     * allocated DMA buffer doesn't have enough room left for this request,
71     * a new buffer will need to be allocated.
72     */
73    if ( (mmesa->vertex_dma_buffer == NULL)
74         || ((mmesa->vertex_dma_buffer->used + bytes) 
75             > mmesa->vertex_dma_buffer->total) ) {
76       LOCK_HARDWARE( mmesa );
77
78       /* In the case where the existing buffer does not have enough room,
79        * we need to flush it out to the hardware.
80        */
81       if ( mmesa->vertex_dma_buffer != NULL ) {
82          mgaFlushVerticesLocked( mmesa );
83       }
84            
85       mmesa->vertex_dma_buffer = mga_get_buffer_ioctl( mmesa );
86       UNLOCK_HARDWARE( mmesa );
87    }
88
89    head = (GLuint *)((char *)mmesa->vertex_dma_buffer->address +
90                       mmesa->vertex_dma_buffer->used);
91
92    mmesa->vertex_dma_buffer->used += bytes;
93    return head;
94 }
95
96
97 #define UPDATE_LOCK( mmesa, flags )                                     \
98 do {                                                                    \
99    GLint ret = mgaFlushDMA( mmesa->driFd, flags );                      \
100    if ( ret < 0 ) {                                                     \
101       drmCommandNone( mmesa->driFd, DRM_MGA_RESET );                    \
102       UNLOCK_HARDWARE( mmesa );                                         \
103       fprintf( stderr, "%s: flush return = %s (%d), flags = 0x%08x\n",  \
104                __FUNCTION__, strerror( -ret ), -ret,                    \
105                (unsigned)(flags) );                                     \
106       exit( 1 );                                                        \
107    }                                                                    \
108 } while (0)
109
110 #endif