Replace U(8|16) with u(8|16).
[platform/upstream/libdrm.git] / linux-core / xgi_drv.h
1
2 /****************************************************************************
3  * Copyright (C) 2003-2006 by XGI Technology, Taiwan.                   
4  *                                                                                                                                                      *
5  * All Rights Reserved.                                                                                                         *
6  *                                                                                                                                                      *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the      
9  * "Software"), to deal in the Software without restriction, including  
10  * without limitation on the rights to use, copy, modify, merge,        
11  * publish, distribute, sublicense, and/or sell copies of the Software, 
12  * and to permit persons to whom the Software is furnished to do so,    
13  * subject to the following conditions:                                 
14  *                                                                                                                                                      *
15  * The above copyright notice and this permission notice (including the 
16  * next paragraph) shall be included in all copies or substantial       
17  * portions of the Software.                                            
18  *                                                                                                                                                      *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,      
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF   
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND                
22  * NON-INFRINGEMENT.  IN NO EVENT SHALL XGI AND/OR                      
23  * ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,           
24  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,           
25  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER                        
26  * DEALINGS IN THE SOFTWARE.                                                                                            
27  ***************************************************************************/
28
29 #ifndef _XGI_DRV_H_
30 #define _XGI_DRV_H_
31
32 #define XGI_MAJOR_VERSION   0
33 #define XGI_MINOR_VERSION   7
34 #define XGI_PATCHLEVEL      5
35
36 #define XGI_DRV_VERSION     "0.7.5"
37
38 #ifndef XGI_DRV_NAME
39 #define XGI_DRV_NAME        "xgi"
40 #endif
41
42 /*
43  * xgi reserved major device number, Set this to 0 to
44  * request dynamic major number allocation.
45  */
46 #ifndef XGI_DEV_MAJOR
47 #define XGI_DEV_MAJOR   0
48 #endif
49
50 #ifndef XGI_MAX_DEVICES
51 #define XGI_MAX_DEVICES 1
52 #endif
53
54 /* Jong 06/06/2006 */
55 /* #define XGI_DEBUG */
56
57 #ifndef PCI_VENDOR_ID_XGI
58 /*
59 #define PCI_VENDOR_ID_XGI       0x1023
60 */
61 #define PCI_VENDOR_ID_XGI       0x18CA
62
63 #endif
64
65 #ifndef PCI_DEVICE_ID_XP5
66 #define PCI_DEVICE_ID_XP5       0x2200
67 #endif
68
69 #ifndef PCI_DEVICE_ID_XG47
70 #define PCI_DEVICE_ID_XG47      0x0047
71 #endif
72
73 /* Macros to make printk easier */
74 #define XGI_ERROR(fmt, arg...) \
75     printk(KERN_ERR "[" XGI_DRV_NAME ":%s] *ERROR* " fmt, __FUNCTION__, ##arg)
76
77 #define XGI_MEM_ERROR(area, fmt, arg...) \
78     printk(KERN_ERR "[" XGI_DRV_NAME ":%s] *ERROR* " fmt, __FUNCTION__, ##arg)
79
80 /* #define XGI_DEBUG */
81
82 #ifdef XGI_DEBUG
83 #define XGI_INFO(fmt, arg...) \
84     printk(KERN_ALERT "[" XGI_DRV_NAME ":%s] " fmt, __FUNCTION__, ##arg)
85 /*    printk(KERN_INFO "[" XGI_DRV_NAME ":%s] " fmt, __FUNCTION__, ##arg) */
86 #else
87 #define XGI_INFO(fmt, arg...)   do { } while (0)
88 #endif
89
90 /* device name length; must be atleast 8 */
91 #define XGI_DEVICE_NAME_LENGTH      40
92
93 /* need a fake device number for control device; just to flag it for msgs */
94 #define XGI_CONTROL_DEVICE_NUMBER   100
95
96 struct xgi_aperture {
97         U32 base;               // pcie base is different from fb base
98         U32 size;
99         u8 *vbase;
100 };
101
102 struct xgi_screen_info {
103         U32 scrn_start;
104         U32 scrn_xres;
105         U32 scrn_yres;
106         U32 scrn_bpp;
107         U32 scrn_pitch;
108 };
109
110 struct xgi_sarea_info {
111         U32 bus_addr;
112         U32 size;
113 };
114
115 struct xgi_info {
116         struct pci_dev *dev;
117         int flags;
118         int device_number;
119         int bus;                /* PCI config info */
120         int slot;
121         int vendor_id;
122         U32 device_id;
123         u8 revision_id;
124
125         /* physical characteristics */
126         struct xgi_aperture mmio;
127         struct xgi_aperture fb;
128         struct xgi_aperture pcie;
129         struct xgi_screen_info scrn_info;
130         struct xgi_sarea_info sarea_info;
131
132         /* look up table parameters */
133         U32 *lut_base;
134         U32 lutPageSize;
135         U32 lutPageOrder;
136         U32 isLUTInLFB;
137         U32 sdfbPageSize;
138
139         U32 pcie_config;
140         U32 pcie_status;
141         U32 irq;
142
143         atomic_t use_count;
144
145         /* keep track of any pending bottom halfes */
146         struct tasklet_struct tasklet;
147
148         spinlock_t info_lock;
149
150         struct semaphore info_sem;
151         struct semaphore fb_sem;
152         struct semaphore pcie_sem;
153 };
154
155 struct xgi_ioctl_post_vbios {
156         U32 bus;
157         U32 slot;
158 };
159
160 enum xgi_mem_location {
161         NON_LOCAL = 0,
162         LOCAL = 1,
163         INVALID = 0x7fffffff
164 };
165
166 enum PcieOwner {
167         PCIE_2D = 0,
168         /*
169            PCIE_3D should not begin with 1,
170            2D alloc pcie memory will use owner 1.
171          */
172         PCIE_3D = 11,           /*vetex buf */
173         PCIE_3D_CMDLIST = 12,
174         PCIE_3D_SCRATCHPAD = 13,
175         PCIE_3D_TEXTURE = 14,
176         PCIE_INVALID = 0x7fffffff
177 };
178
179 struct xgi_mem_req {
180         enum xgi_mem_location location;
181         unsigned long size;
182         unsigned long is_front;
183         enum PcieOwner owner;
184         unsigned long pid;
185 };
186
187 struct xgi_mem_alloc {
188         enum xgi_mem_location location;
189         unsigned long size;
190         unsigned long bus_addr;
191         unsigned long hw_addr;
192         unsigned long pid;
193 };
194
195 struct xgi_chip_info {
196         U32 device_id;
197         char device_name[32];
198         U32 vendor_id;
199         U32 curr_display_mode;  //Singe, DualView(Contained), MHS
200         U32 fb_size;
201         U32 sarea_bus_addr;
202         U32 sarea_size;
203 };
204
205 struct xgi_opengl_cmd {
206         U32 cmd;
207 };
208
209 struct xgi_mmio_info {
210         struct xgi_opengl_cmd cmd_head;
211         void *mmioBase;
212         int size;
213 };
214
215 typedef enum {
216         BTYPE_2D = 0,
217         BTYPE_3D = 1,
218         BTYPE_FLIP = 2,
219         BTYPE_CTRL = 3,
220         BTYPE_NONE = 0x7fffffff
221 } BATCH_TYPE;
222
223 struct xgi_cmd_info {
224         BATCH_TYPE _firstBeginType;
225         U32 _firstBeginAddr;
226         U32 _firstSize;
227         U32 _curDebugID;
228         U32 _lastBeginAddr;
229         U32 _beginCount;
230 };
231
232 struct xgi_state_info {
233         U32 _fromState;
234         U32 _toState;
235 };
236
237 struct cpu_info {
238         U32 _eax;
239         U32 _ebx;
240         U32 _ecx;
241         U32 _edx;
242 };
243
244 struct xgi_mem_pid {
245         struct list_head list;
246         enum xgi_mem_location location;
247         unsigned long bus_addr;
248         unsigned long pid;
249 };
250
251 /*
252  * Ioctl definitions
253  */
254
255 #define XGI_IOCTL_MAGIC             'x' /* use 'x' as magic number */
256
257 #define XGI_IOCTL_BASE              0
258 #define XGI_ESC_DEVICE_INFO         (XGI_IOCTL_BASE + 0)
259 #define XGI_ESC_POST_VBIOS          (XGI_IOCTL_BASE + 1)
260
261 #define XGI_ESC_FB_INIT             (XGI_IOCTL_BASE + 2)
262 #define XGI_ESC_FB_ALLOC            (XGI_IOCTL_BASE + 3)
263 #define XGI_ESC_FB_FREE             (XGI_IOCTL_BASE + 4)
264 #define XGI_ESC_PCIE_INIT           (XGI_IOCTL_BASE + 5)
265 #define XGI_ESC_PCIE_ALLOC          (XGI_IOCTL_BASE + 6)
266 #define XGI_ESC_PCIE_FREE           (XGI_IOCTL_BASE + 7)
267 #define XGI_ESC_SUBMIT_CMDLIST      (XGI_IOCTL_BASE + 8)
268 #define XGI_ESC_PUT_SCREEN_INFO     (XGI_IOCTL_BASE + 9)
269 #define XGI_ESC_GET_SCREEN_INFO     (XGI_IOCTL_BASE + 10)
270 #define XGI_ESC_GE_RESET            (XGI_IOCTL_BASE + 11)
271 #define XGI_ESC_SAREA_INFO          (XGI_IOCTL_BASE + 12)
272 #define XGI_ESC_DUMP_REGISTER       (XGI_IOCTL_BASE + 13)
273 #define XGI_ESC_DEBUG_INFO          (XGI_IOCTL_BASE + 14)
274 #define XGI_ESC_TEST_RWINKERNEL     (XGI_IOCTL_BASE + 16)
275 #define XGI_ESC_STATE_CHANGE        (XGI_IOCTL_BASE + 17)
276 #define XGI_ESC_MMIO_INFO           (XGI_IOCTL_BASE + 18)
277 #define XGI_ESC_PCIE_CHECK          (XGI_IOCTL_BASE + 19)
278 #define XGI_ESC_CPUID               (XGI_IOCTL_BASE + 20)
279 #define XGI_ESC_MEM_COLLECT          (XGI_IOCTL_BASE + 21)
280
281 #define XGI_IOCTL_DEVICE_INFO       _IOR(XGI_IOCTL_MAGIC, XGI_ESC_DEVICE_INFO, struct xgi_chip_info)
282 #define XGI_IOCTL_POST_VBIOS        _IO(XGI_IOCTL_MAGIC, XGI_ESC_POST_VBIOS)
283
284 #define XGI_IOCTL_FB_INIT           _IO(XGI_IOCTL_MAGIC, XGI_ESC_FB_INIT)
285 #define XGI_IOCTL_FB_ALLOC          _IOWR(XGI_IOCTL_MAGIC, XGI_ESC_FB_ALLOC, struct xgi_mem_req)
286 #define XGI_IOCTL_FB_FREE           _IOW(XGI_IOCTL_MAGIC, XGI_ESC_FB_FREE, unsigned long)
287
288 #define XGI_IOCTL_PCIE_INIT         _IO(XGI_IOCTL_MAGIC, XGI_ESC_PCIE_INIT)
289 #define XGI_IOCTL_PCIE_ALLOC        _IOWR(XGI_IOCTL_MAGIC, XGI_ESC_PCIE_ALLOC, struct xgi_mem_req)
290 #define XGI_IOCTL_PCIE_FREE         _IOW(XGI_IOCTL_MAGIC, XGI_ESC_PCIE_FREE, unsigned long)
291
292 #define XGI_IOCTL_PUT_SCREEN_INFO   _IOW(XGI_IOCTL_MAGIC, XGI_ESC_PUT_SCREEN_INFO, struct xgi_screen_info)
293 #define XGI_IOCTL_GET_SCREEN_INFO   _IOR(XGI_IOCTL_MAGIC, XGI_ESC_GET_SCREEN_INFO, struct xgi_screen_info)
294
295 #define XGI_IOCTL_GE_RESET          _IO(XGI_IOCTL_MAGIC, XGI_ESC_GE_RESET)
296 #define XGI_IOCTL_SAREA_INFO        _IOW(XGI_IOCTL_MAGIC, XGI_ESC_SAREA_INFO, struct xgi_sarea_info)
297 #define XGI_IOCTL_DUMP_REGISTER     _IO(XGI_IOCTL_MAGIC, XGI_ESC_DUMP_REGISTER)
298 #define XGI_IOCTL_DEBUG_INFO        _IO(XGI_IOCTL_MAGIC, XGI_ESC_DEBUG_INFO)
299 #define XGI_IOCTL_MMIO_INFO         _IOR(XGI_IOCTL_MAGIC, XGI_ESC_MMIO_INFO, struct xgi_mmio_info)
300
301 #define XGI_IOCTL_SUBMIT_CMDLIST        _IOWR(XGI_IOCTL_MAGIC, XGI_ESC_SUBMIT_CMDLIST, struct xgi_cmd_info)
302 #define XGI_IOCTL_TEST_RWINKERNEL       _IOWR(XGI_IOCTL_MAGIC, XGI_ESC_TEST_RWINKERNEL, unsigned long)
303 #define XGI_IOCTL_STATE_CHANGE      _IOWR(XGI_IOCTL_MAGIC, XGI_ESC_STATE_CHANGE, struct xgi_state_info)
304
305 #define XGI_IOCTL_PCIE_CHECK        _IO(XGI_IOCTL_MAGIC, XGI_ESC_PCIE_CHECK)
306 #define XGI_IOCTL_CPUID             _IOWR(XGI_IOCTL_MAGIC, XGI_ESC_CPUID, struct cpu_info)
307 #define XGI_IOCTL_MAXNR          30
308
309 /*
310  * flags
311  */
312 #define XGI_FLAG_OPEN            0x0001
313 #define XGI_FLAG_NEEDS_POSTING   0x0002
314 #define XGI_FLAG_WAS_POSTED      0x0004
315 #define XGI_FLAG_CONTROL         0x0010
316 #define XGI_FLAG_MAP_REGS_EARLY  0x0200
317
318 /* mmap(2) offsets */
319
320 #define IS_IO_OFFSET(info, offset, length) \
321             (((offset) >= (info)->mmio.base) \
322             && (((offset) + (length)) <= (info)->mmio.base + (info)->mmio.size))
323
324 /* Jong 06/14/2006 */
325 /* (info)->fb.base is a base address for physical (bus) address space */
326 /* what's the definition of offest? on  physical (bus) address space or HW address space */
327 /* Jong 06/15/2006; use HW address space */
328 #define IS_FB_OFFSET(info, offset, length) \
329             (((offset) >= 0) \
330             && (((offset) + (length)) <= (info)->fb.size))
331 #if 0
332 #define IS_FB_OFFSET(info, offset, length) \
333             (((offset) >= (info)->fb.base) \
334             && (((offset) + (length)) <= (info)->fb.base + (info)->fb.size))
335 #endif
336
337 #define IS_PCIE_OFFSET(info, offset, length) \
338             (((offset) >= (info)->pcie.base) \
339             && (((offset) + (length)) <= (info)->pcie.base + (info)->pcie.size))
340
341 extern int xgi_fb_heap_init(struct xgi_info * info);
342 extern void xgi_fb_heap_cleanup(struct xgi_info * info);
343
344 extern void xgi_fb_alloc(struct xgi_info * info, struct xgi_mem_req * req,
345                          struct xgi_mem_alloc * alloc);
346 extern void xgi_fb_free(struct xgi_info * info, unsigned long offset);
347 extern void xgi_mem_collect(struct xgi_info * info, unsigned int *pcnt);
348
349 extern int xgi_pcie_heap_init(struct xgi_info * info);
350 extern void xgi_pcie_heap_cleanup(struct xgi_info * info);
351
352 extern void xgi_pcie_alloc(struct xgi_info * info, unsigned long size,
353                            enum PcieOwner owner, struct xgi_mem_alloc * alloc);
354 extern void xgi_pcie_free(struct xgi_info * info, unsigned long offset);
355 extern void xgi_pcie_heap_check(void);
356 extern struct xgi_pcie_block *xgi_find_pcie_block(struct xgi_info * info,
357                                                     unsigned long address);
358 extern void *xgi_find_pcie_virt(struct xgi_info * info, unsigned long address);
359
360 extern void xgi_read_pcie_mem(struct xgi_info * info, struct xgi_mem_req * req);
361 extern void xgi_write_pcie_mem(struct xgi_info * info, struct xgi_mem_req * req);
362
363 extern void xgi_test_rwinkernel(struct xgi_info * info, unsigned long address);
364
365 #endif