Eliminiate fields in xgi_info that are duplicates of fields in pci_dev.
[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         struct xgi_screen_info scrn_info;
114         struct xgi_sarea_info sarea_info;
115
116         /* look up table parameters */
117         U32 *lut_base;
118         unsigned int lutPageSize;
119         unsigned int lutPageOrder;
120         bool isLUTInLFB;
121         unsigned int sdfbPageSize;
122
123         u32 pcie_config;
124         u32 pcie_status;
125
126         atomic_t use_count;
127
128         /* keep track of any pending bottom halfes */
129         struct tasklet_struct tasklet;
130
131         spinlock_t info_lock;
132
133         struct semaphore info_sem;
134         struct semaphore fb_sem;
135         struct semaphore pcie_sem;
136 };
137
138 struct xgi_ioctl_post_vbios {
139         unsigned int bus;
140         unsigned int slot;
141 };
142
143 enum PcieOwner {
144         PCIE_2D = 0,
145         /*
146            PCIE_3D should not begin with 1,
147            2D alloc pcie memory will use owner 1.
148          */
149         PCIE_3D = 11,           /*vetex buf */
150         PCIE_3D_CMDLIST = 12,
151         PCIE_3D_SCRATCHPAD = 13,
152         PCIE_3D_TEXTURE = 14,
153         PCIE_INVALID = 0x7fffffff
154 };
155
156 struct xgi_mem_pid {
157         struct list_head list;
158         enum xgi_mem_location location;
159         unsigned long bus_addr;
160         unsigned long pid;
161 };
162
163
164 /*
165  * flags
166  */
167 #define XGI_FLAG_OPEN            0x0001
168 #define XGI_FLAG_NEEDS_POSTING   0x0002
169 #define XGI_FLAG_WAS_POSTED      0x0004
170 #define XGI_FLAG_CONTROL         0x0010
171 #define XGI_FLAG_MAP_REGS_EARLY  0x0200
172
173 /* mmap(2) offsets */
174
175 #define IS_IO_OFFSET(info, offset, length) \
176             (((offset) >= (info)->mmio.base) \
177             && (((offset) + (length)) <= (info)->mmio.base + (info)->mmio.size))
178
179 /* Jong 06/14/2006 */
180 /* (info)->fb.base is a base address for physical (bus) address space */
181 /* what's the definition of offest? on  physical (bus) address space or HW address space */
182 /* Jong 06/15/2006; use HW address space */
183 #define IS_FB_OFFSET(info, offset, length) \
184             (((offset) >= 0) \
185             && (((offset) + (length)) <= (info)->fb.size))
186 #if 0
187 #define IS_FB_OFFSET(info, offset, length) \
188             (((offset) >= (info)->fb.base) \
189             && (((offset) + (length)) <= (info)->fb.base + (info)->fb.size))
190 #endif
191
192 #define IS_PCIE_OFFSET(info, offset, length) \
193             (((offset) >= (info)->pcie.base) \
194             && (((offset) + (length)) <= (info)->pcie.base + (info)->pcie.size))
195
196 extern int xgi_fb_heap_init(struct xgi_info * info);
197 extern void xgi_fb_heap_cleanup(struct xgi_info * info);
198
199 extern void xgi_fb_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc,
200                          pid_t pid);
201 extern void xgi_fb_free(struct xgi_info * info, unsigned long offset);
202 extern void xgi_mem_collect(struct xgi_info * info, unsigned int *pcnt);
203
204 extern int xgi_pcie_heap_init(struct xgi_info * info);
205 extern void xgi_pcie_heap_cleanup(struct xgi_info * info);
206
207 extern void xgi_pcie_alloc(struct xgi_info * info, 
208                            struct xgi_mem_alloc * alloc, pid_t pid);
209 extern void xgi_pcie_free(struct xgi_info * info, unsigned long offset);
210 extern void xgi_pcie_heap_check(void);
211 extern struct xgi_pcie_block *xgi_find_pcie_block(struct xgi_info * info,
212                                                     unsigned long address);
213 extern void *xgi_find_pcie_virt(struct xgi_info * info, unsigned long address);
214
215 extern void xgi_test_rwinkernel(struct xgi_info * info, unsigned long address);
216
217 #endif