1 /*
2  * AGPGART module version 0.99
3  * Copyright (C) 1999 Jeff Hartmann
4  * Copyright (C) 1999 Precision Insight, Inc.
5  * Copyright (C) 1999 Xi Graphics, Inc.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * JEFF HARTMANN, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
23  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  */
26 
27 #ifndef _AGP_BACKEND_H
28 #define _AGP_BACKEND_H 1
29 
30 #ifndef TRUE
31 #define TRUE 1
32 #endif
33 
34 #ifndef FALSE
35 #define FALSE 0
36 #endif
37 
38 #define AGPGART_VERSION_MAJOR 0
39 #define AGPGART_VERSION_MINOR 99
40 
41 enum chipset_type {
42 	NOT_SUPPORTED,
43 	INTEL_GENERIC,
44 	INTEL_LX,
45 	INTEL_BX,
46 	INTEL_GX,
47 	INTEL_I810,
48 	INTEL_I815,
49 	INTEL_I820,
50 	INTEL_I830_M,
51 	INTEL_I845_G,
52 	INTEL_I840,
53 	INTEL_I845,
54 	INTEL_I850,
55 	INTEL_I855_PM,
56 	INTEL_I860,
57 	INTEL_I865_G,
58 	INTEL_I915_G,
59 	INTEL_I915_GM,
60 	INTEL_I7205,
61 	INTEL_I7505,
62 	INTEL_460GX,
63 	VIA_GENERIC,
64 	VIA_VP3,
65 	VIA_MVP3,
66 	VIA_MVP4,
67 	VIA_APOLLO_PLE133,
68 	VIA_APOLLO_PRO,
69 	VIA_APOLLO_KX133,
70 	VIA_APOLLO_KT133,
71 	VIA_APOLLO_KM266,
72 	VIA_APOLLO_KT400,
73 	VIA_CLE266,
74 	VIA_APOLLO_P4M266,
75 	VIA_APOLLO_P4X400,
76 	SIS_GENERIC,
77 	AMD_GENERIC,
78 	AMD_IRONGATE,
79 	AMD_761,
80 	AMD_762,
81 	AMD_8151,
82 	ALI_M1541,
83 	ALI_M1621,
84 	ALI_M1631,
85 	ALI_M1632,
86 	ALI_M1641,
87 	ALI_M1644,
88 	ALI_M1647,
89 	ALI_M1651,
90 	ALI_M1671,
91 	ALI_GENERIC,
92 	SVWRKS_HE,
93 	SVWRKS_LE,
94 	SVWRKS_GENERIC,
95 	NVIDIA_NFORCE,
96 	NVIDIA_NFORCE2,
97 	NVIDIA_NFORCE3,
98 	NVIDIA_GENERIC,
99 	HP_ZX1,
100 	ATI_RS100,
101 	ATI_RS200,
102 	ATI_RS250,
103 	ATI_RS300_100,
104 	ATI_RS300_133,
105 	ATI_RS300_166,
106 	ATI_RS300_200
107 };
108 
109 typedef struct _agp_version {
110 	u16 major;
111 	u16 minor;
112 } agp_version;
113 
114 typedef struct _agp_kern_info {
115 	agp_version version;
116 	struct pci_dev *device;
117 	enum chipset_type chipset;
118 	unsigned long mode;
119 	off_t aper_base;
120 	size_t aper_size;
121 	int max_memory;		/* In pages */
122 	int current_memory;
123 	int cant_use_aperture;
124 	unsigned long page_mask;
125 } agp_kern_info;
126 
127 /*
128  * The agp_memory structure has information
129  * about the block of agp memory allocated.
130  * A caller may manipulate the next and prev
131  * pointers to link each allocated item into
132  * a list.  These pointers are ignored by the
133  * backend.  Everything else should never be
134  * written to, but the caller may read any of
135  * the items to detrimine the status of this
136  * block of agp memory.
137  *
138  */
139 
140 typedef struct _agp_memory {
141 	int key;
142 	struct _agp_memory *next;
143 	struct _agp_memory *prev;
144 	size_t page_count;
145 	int num_scratch_pages;
146 	unsigned long *memory;
147 	off_t pg_start;
148 	u32 type;
149 	u32 physical;
150 	u8 is_bound;
151 	u8 is_flushed;
152 } agp_memory;
153 
154 #define AGP_NORMAL_MEMORY 0
155 
156 extern void agp_free_memory(agp_memory *);
157 
158 /*
159  * agp_free_memory :
160  *
161  * This function frees memory associated with
162  * an agp_memory pointer.  It is the only function
163  * that can be called when the backend is not owned
164  * by the caller.  (So it can free memory on client
165  * death.)
166  *
167  * It takes an agp_memory pointer as an argument.
168  *
169  */
170 
171 extern agp_memory *agp_allocate_memory(size_t, u32);
172 
173 /*
174  * agp_allocate_memory :
175  *
176  * This function allocates a group of pages of
177  * a certain type.
178  *
179  * It takes a size_t argument of the number of pages, and
180  * an u32 argument of the type of memory to be allocated.
181  * Every agp bridge device will allow you to allocate
182  * AGP_NORMAL_MEMORY which maps to physical ram.  Any other
183  * type is device dependant.
184  *
185  * It returns NULL whenever memory is unavailable.
186  *
187  */
188 
189 extern int agp_copy_info(agp_kern_info *);
190 
191 /*
192  * agp_copy_info :
193  *
194  * This function copies information about the
195  * agp bridge device and the state of the agp
196  * backend into an agp_kern_info pointer.
197  *
198  * It takes an agp_kern_info pointer as an
199  * argument.  The caller should insure that
200  * this pointer is valid.
201  *
202  */
203 
204 extern int agp_bind_memory(agp_memory *, off_t);
205 
206 /*
207  * agp_bind_memory :
208  *
209  * This function binds an agp_memory structure
210  * into the graphics aperture translation table.
211  *
212  * It takes an agp_memory pointer and an offset into
213  * the graphics aperture translation table as arguments
214  *
215  * It returns -EINVAL if the pointer == NULL.
216  * It returns -EBUSY if the area of the table
217  * requested is already in use.
218  *
219  */
220 
221 extern int agp_unbind_memory(agp_memory *);
222 
223 /*
224  * agp_unbind_memory :
225  *
226  * This function removes an agp_memory structure
227  * from the graphics aperture translation table.
228  *
229  * It takes an agp_memory pointer as an argument.
230  *
231  * It returns -EINVAL if this piece of agp_memory
232  * is not currently bound to the graphics aperture
233  * translation table or if the agp_memory
234  * pointer == NULL
235  *
236  */
237 
238 extern void agp_enable(u32);
239 
240 /*
241  * agp_enable :
242  *
243  * This function initializes the agp point-to-point
244  * connection.
245  *
246  * It takes an agp mode register as an argument
247  *
248  */
249 
250 extern int agp_backend_acquire(void);
251 
252 /*
253  * agp_backend_acquire :
254  *
255  * This Function attempts to acquire the agp
256  * backend.
257  *
258  * returns -EBUSY if agp is in use,
259  * returns 0 if the caller owns the agp backend
260  */
261 
262 extern void agp_backend_release(void);
263 
264 /*
265  * agp_backend_release :
266  *
267  * This Function releases the lock on the agp
268  * backend.
269  *
270  * The caller must insure that the graphics
271  * aperture translation table is read for use
272  * by another entity.  (Ensure that all memory
273  * it bound is unbound.)
274  *
275  */
276 
277 typedef struct {
278 	void       (*free_memory)(agp_memory *);
279 	agp_memory *(*allocate_memory)(size_t, u32);
280 	int        (*bind_memory)(agp_memory *, off_t);
281 	int        (*unbind_memory)(agp_memory *);
282 	void       (*enable)(u32);
283 	int        (*acquire)(void);
284 	void       (*release)(void);
285 	int        (*copy_info)(agp_kern_info *);
286 } drm_agp_t;
287 
288 extern const drm_agp_t *drm_agp_p;
289 
290 /*
291  * Interface between drm and agp code.  When agp initializes, it makes
292  * the above structure available via inter_module_register(), drm might
293  * use it.  Keith Owens <kaos@ocs.com.au> 28 Oct 2000.
294  */
295 
296 #endif				/* _AGP_BACKEND_H */
297