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