Eliminate several useless ioctls and associated cruft.
[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 #include "xgi_drm.h"
33
34 #define XGI_MAJOR_VERSION   0
35 #define XGI_MINOR_VERSION   7
36 #define XGI_PATCHLEVEL      5
37
38 #define XGI_DRV_VERSION     "0.7.5"
39
40 #ifndef XGI_DRV_NAME
41 #define XGI_DRV_NAME        "xgi"
42 #endif
43
44 /*
45  * xgi reserved major device number, Set this to 0 to
46  * request dynamic major number allocation.
47  */
48 #ifndef XGI_DEV_MAJOR
49 #define XGI_DEV_MAJOR   0
50 #endif
51
52 #ifndef XGI_MAX_DEVICES
53 #define XGI_MAX_DEVICES 1
54 #endif
55
56 /* Jong 06/06/2006 */
57 /* #define XGI_DEBUG */
58
59 #ifndef PCI_VENDOR_ID_XGI
60 /*
61 #define PCI_VENDOR_ID_XGI       0x1023
62 */
63 #define PCI_VENDOR_ID_XGI       0x18CA
64
65 #endif
66
67 #ifndef PCI_DEVICE_ID_XP5
68 #define PCI_DEVICE_ID_XP5       0x2200
69 #endif
70
71 #ifndef PCI_DEVICE_ID_XG47
72 #define PCI_DEVICE_ID_XG47      0x0047
73 #endif
74
75 /* Macros to make printk easier */
76 #define XGI_ERROR(fmt, arg...) \
77     printk(KERN_ERR "[" XGI_DRV_NAME ":%s] *ERROR* " fmt, __FUNCTION__, ##arg)
78
79 #define XGI_MEM_ERROR(area, fmt, arg...) \
80     printk(KERN_ERR "[" XGI_DRV_NAME ":%s] *ERROR* " fmt, __FUNCTION__, ##arg)
81
82 /* #define XGI_DEBUG */
83
84 #ifdef XGI_DEBUG
85 #define XGI_INFO(fmt, arg...) \
86     printk(KERN_ALERT "[" XGI_DRV_NAME ":%s] " fmt, __FUNCTION__, ##arg)
87 /*    printk(KERN_INFO "[" XGI_DRV_NAME ":%s] " fmt, __FUNCTION__, ##arg) */
88 #else
89 #define XGI_INFO(fmt, arg...)   do { } while (0)
90 #endif
91
92 /* device name length; must be atleast 8 */
93 #define XGI_DEVICE_NAME_LENGTH      40
94
95 /* need a fake device number for control device; just to flag it for msgs */
96 #define XGI_CONTROL_DEVICE_NUMBER   100
97
98 struct xgi_aperture {
99         unsigned long base;
100         unsigned int size;
101         void *vbase;
102 };
103
104 struct xgi_info {
105         struct pci_dev *dev;
106         int flags;
107         int device_number;
108
109         /* physical characteristics */
110         struct xgi_aperture mmio;
111         struct xgi_aperture fb;
112         struct xgi_aperture pcie;
113
114         /* look up table parameters */
115         u32 *lut_base;
116         unsigned int lutPageSize;
117         unsigned int lutPageOrder;
118         bool isLUTInLFB;
119         unsigned int sdfbPageSize;
120
121         u32 pcie_config;
122         u32 pcie_status;
123
124         atomic_t use_count;
125
126         /* keep track of any pending bottom halfes */
127         struct tasklet_struct tasklet;
128
129         spinlock_t info_lock;
130
131         struct semaphore info_sem;
132         struct semaphore fb_sem;
133         struct semaphore pcie_sem;
134 };
135
136 struct xgi_ioctl_post_vbios {
137         unsigned int bus;
138         unsigned int slot;
139 };
140
141 enum PcieOwner {
142         PCIE_2D = 0,
143         /*
144            PCIE_3D should not begin with 1,
145            2D alloc pcie memory will use owner 1.
146          */
147         PCIE_3D = 11,           /*vetex buf */
148         PCIE_3D_CMDLIST = 12,
149         PCIE_3D_SCRATCHPAD = 13,
150         PCIE_3D_TEXTURE = 14,
151         PCIE_INVALID = 0x7fffffff
152 };
153
154 struct xgi_mem_pid {
155         struct list_head list;
156         enum xgi_mem_location location;
157         unsigned long bus_addr;
158         unsigned long pid;
159 };
160
161
162 /*
163  * flags
164  */
165 #define XGI_FLAG_OPEN            0x0001
166 #define XGI_FLAG_NEEDS_POSTING   0x0002
167 #define XGI_FLAG_WAS_POSTED      0x0004
168 #define XGI_FLAG_CONTROL         0x0010
169 #define XGI_FLAG_MAP_REGS_EARLY  0x0200
170
171 /* mmap(2) offsets */
172
173 #define IS_IO_OFFSET(info, offset, length) \
174             (((offset) >= (info)->mmio.base) \
175             && (((offset) + (length)) <= (info)->mmio.base + (info)->mmio.size))
176
177 /* Jong 06/14/2006 */
178 /* (info)->fb.base is a base address for physical (bus) address space */
179 /* what's the definition of offest? on  physical (bus) address space or HW address space */
180 /* Jong 06/15/2006; use HW address space */
181 #define IS_FB_OFFSET(info, offset, length) \
182             (((offset) >= 0) \
183             && (((offset) + (length)) <= (info)->fb.size))
184 #if 0
185 #define IS_FB_OFFSET(info, offset, length) \
186             (((offset) >= (info)->fb.base) \
187             && (((offset) + (length)) <= (info)->fb.base + (info)->fb.size))
188 #endif
189
190 #define IS_PCIE_OFFSET(info, offset, length) \
191             (((offset) >= (info)->pcie.base) \
192             && (((offset) + (length)) <= (info)->pcie.base + (info)->pcie.size))
193
194 extern int xgi_fb_heap_init(struct xgi_info * info);
195 extern void xgi_fb_heap_cleanup(struct xgi_info * info);
196
197 extern void xgi_fb_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc,
198                          pid_t pid);
199 extern void xgi_fb_free(struct xgi_info * info, unsigned long offset);
200 extern void xgi_mem_collect(struct xgi_info * info, unsigned int *pcnt);
201
202 extern int xgi_pcie_heap_init(struct xgi_info * info);
203 extern void xgi_pcie_heap_cleanup(struct xgi_info * info);
204
205 extern void xgi_pcie_alloc(struct xgi_info * info, 
206                            struct xgi_mem_alloc * alloc, pid_t pid);
207 extern void xgi_pcie_free(struct xgi_info * info, unsigned long offset);
208 extern struct xgi_pcie_block *xgi_find_pcie_block(struct xgi_info * info,
209                                                     unsigned long address);
210 extern void *xgi_find_pcie_virt(struct xgi_info * info, unsigned long address);
211
212 extern void xgi_test_rwinkernel(struct xgi_info * info, unsigned long address);
213
214 #endif