Initial code release
[adaptation/xorg-x11-drv-intel.git] / src / common.h
1
2 /**************************************************************************
3
4 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
5 Copyright © 2002 David Dawes
6
7 All Rights Reserved.
8
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sub license, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial portions
19 of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29 **************************************************************************/
30
31 /*
32  * Authors:
33  *   Keith Whitwell <keith@tungstengraphics.com>
34  *   David Dawes <dawes@xfree86.org>
35  *
36  */
37
38 #ifndef _INTEL_COMMON_H_
39 #define _INTEL_COMMON_H_
40
41 /* Provide substitutes for gcc's __FUNCTION__ on other compilers */
42 #if !defined(__GNUC__) && !defined(__FUNCTION__)
43 # if defined(__STDC__) && (__STDC_VERSION__>=199901L) /* C99 */
44 #  define __FUNCTION__ __func__
45 # else
46 #  define __FUNCTION__ ""
47 # endif
48 #endif
49
50
51 #define PFX __FILE__,__LINE__,__FUNCTION__
52 #define FUNCTION_NAME __FUNCTION__
53
54 #ifdef I830DEBUG
55 #define MARKER() ErrorF("\n### %s:%d: >>> %s <<< ###\n\n", \
56                          __FILE__, __LINE__,__FUNCTION__)
57 #define DPRINTF I830DPRINTF
58 #else /* #ifdef I830DEBUG */
59 #define MARKER()
60 #define DPRINTF I830DPRINTF_stub
61 static inline void
62 I830DPRINTF_stub(const char *filename, int line, const char *function,
63                  const char *fmt, ...)
64 {
65 }
66 #endif /* #ifdef I830DEBUG */
67
68 #define KB(x) ((x) * 1024)
69 #define MB(x) ((x) * KB(1024))
70
71 /* Using usleep() makes things noticably slow. */
72 #if 0
73 #define DELAY(x) usleep(x)
74 #else
75 #define DELAY(x) do {;} while (0)
76 #endif
77
78 /* I830 hooks for the I810 driver setup/probe. */
79 extern const OptionInfoRec *I830AvailableOptions(int chipid, int busid);
80 extern void intel_init_scrn(ScrnInfoPtr scrn);
81
82 /* Symbol lists shared by the i810 and i830 parts. */
83 extern int I830EntityIndex;
84
85 extern void I830DPRINTF_stub(const char *filename, int line,
86                              const char *function, const char *fmt, ...);
87
88 #ifdef _I830_H_
89 #define PrintErrorState i830_dump_error_state
90 #define WaitRingFunc I830WaitLpRing
91 #define RecPtr intel
92 #else
93 #define PrintErrorState I810PrintErrorState
94 #define WaitRingFunc I810WaitLpRing
95 #define RecPtr pI810
96 #endif
97
98 static inline void memset_volatile(volatile void *b, int c, size_t len)
99 {
100     int i;
101     
102     for (i = 0; i < len; i++)
103         ((volatile char *)b)[i] = c;
104 }
105
106 static inline void memcpy_volatile(volatile void *dst, const void *src,
107                                    size_t len)
108 {
109     int i;
110     
111     for (i = 0; i < len; i++)
112         ((volatile char *)dst)[i] = ((volatile char *)src)[i];
113 }
114
115 /* Memory mapped register access macros */
116 #define INREG8(addr)        *(volatile uint8_t *)(RecPtr->MMIOBase + (addr))
117 #define INREG16(addr)       *(volatile uint16_t *)(RecPtr->MMIOBase + (addr))
118 #define INREG(addr)         *(volatile uint32_t *)(RecPtr->MMIOBase + (addr))
119 #define INGTT(addr)         *(volatile uint32_t *)(RecPtr->GTTBase + (addr))
120 #define POSTING_READ(addr)  (void)INREG(addr)
121
122 #define OUTREG8(addr, val) do {                                         \
123    *(volatile uint8_t *)(RecPtr->MMIOBase  + (addr)) = (val);           \
124    if (I810_DEBUG&DEBUG_VERBOSE_OUTREG) {                               \
125       ErrorF("OUTREG8(0x%lx, 0x%lx) in %s\n", (unsigned long)(addr),    \
126                 (unsigned long)(val), FUNCTION_NAME);                   \
127    }                                                                    \
128 } while (0)
129
130 #define OUTREG16(addr, val) do {                                        \
131    *(volatile uint16_t *)(RecPtr->MMIOBase + (addr)) = (val);           \
132    if (I810_DEBUG&DEBUG_VERBOSE_OUTREG) {                               \
133       ErrorF("OUTREG16(0x%lx, 0x%lx) in %s\n", (unsigned long)(addr),   \
134                 (unsigned long)(val), FUNCTION_NAME);                   \
135    }                                                                    \
136 } while (0)
137
138 #define OUTREG(addr, val) do {                                          \
139    *(volatile uint32_t *)(RecPtr->MMIOBase + (addr)) = (val);           \
140    if (I810_DEBUG&DEBUG_VERBOSE_OUTREG) {                               \
141       ErrorF("OUTREG(0x%lx, 0x%lx) in %s\n", (unsigned long)(addr),     \
142                 (unsigned long)(val), FUNCTION_NAME);                   \
143    }                                                                    \
144 } while (0)
145
146
147 #define DEBUG_VERBOSE_ACCEL  0x1
148 #define DEBUG_VERBOSE_SYNC   0x2
149 #define DEBUG_VERBOSE_VGA    0x4
150 #define DEBUG_VERBOSE_RING   0x8
151 #define DEBUG_VERBOSE_OUTREG 0x10
152 #define DEBUG_VERBOSE_MEMORY 0x20
153 #define DEBUG_VERBOSE_CURSOR 0x40
154 #define DEBUG_ALWAYS_SYNC    0x80
155 #define DEBUG_VERBOSE_DRI    0x100
156 #define DEBUG_VERBOSE_BIOS   0x200
157
158 /* Size of the mmio region.
159  */
160 #define I810_REG_SIZE 0x80000
161
162 #define GTT_PAGE_SIZE                   KB(4)
163 #define PRIMARY_RINGBUFFER_SIZE         KB(128)
164 #define MIN_SCRATCH_BUFFER_SIZE         KB(16)
165 #define MAX_SCRATCH_BUFFER_SIZE         KB(64)
166 #define HWCURSOR_SIZE                   GTT_PAGE_SIZE
167 #define HWCURSOR_SIZE_ARGB              GTT_PAGE_SIZE * 4
168
169 /* Use a 64x64 HW cursor */
170 #define I810_CURSOR_X                   64
171 #define I810_CURSOR_Y                   I810_CURSOR_X
172
173 #define PIPE_NAME(n)                    ('A' + (n))
174
175 struct pci_device *
176 intel_host_bridge (void);
177
178 /**
179  * Hints to CreatePixmap to tell the driver how the pixmap is going to be
180  * used.
181  *
182  * Compare to CREATE_PIXMAP_USAGE_* in the server.
183  */
184 enum {
185         INTEL_CREATE_PIXMAP_TILING_X    = 0x10000000,
186         INTEL_CREATE_PIXMAP_TILING_Y    = 0x20000000,
187         INTEL_CREATE_PIXMAP_TILING_NONE = 0x40000000,
188         INTEL_CREATE_PIXMAP_DRI2        = 0x80000000,
189 };
190
191 #endif /* _INTEL_COMMON_H_ */