Subversion Repositories Kolibri OS

Rev

Rev 2325 | Rev 5060 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2325 Serge 1
/*
2
 * AGPGART
3
 * Copyright (C) 2004 Silicon Graphics, Inc.
4
 * Copyright (C) 2002-2004 Dave Jones
5
 * Copyright (C) 1999 Jeff Hartmann
6
 * Copyright (C) 1999 Precision Insight, Inc.
7
 * Copyright (C) 1999 Xi Graphics, Inc.
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a
10
 * copy of this software and associated documentation files (the "Software"),
11
 * to deal in the Software without restriction, including without limitation
12
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13
 * and/or sell copies of the Software, and to permit persons to whom the
14
 * Software is furnished to do so, subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included
17
 * in all copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22
 * JEFF HARTMANN, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
23
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
 *
27
 */
28
 
29
#ifndef _AGP_BACKEND_PRIV_H
30
#define _AGP_BACKEND_PRIV_H 1
31
 
32
//#include 	/* for flush_agp_cache() */
33
 
34
 
35
enum chipset_type {
36
       NOT_SUPPORTED,
37
       SUPPORTED,
38
};
39
 
3031 serge 40
struct agp_memory;
2325 Serge 41
 
42
#define PFX "agpgart: "
43
 
44
//#define AGP_DEBUG 1
45
#ifdef AGP_DEBUG
46
#define DBG(x,y...) printk (KERN_DEBUG PFX "%s: " x "\n", __func__ , ## y)
47
#else
48
#define DBG(x,y...) do { } while (0)
49
#endif
50
 
51
extern struct agp_bridge_data *agp_bridge;
52
 
53
enum aper_size_type {
54
	U8_APER_SIZE,
55
	U16_APER_SIZE,
56
	U32_APER_SIZE,
57
	LVL2_APER_SIZE,
58
	FIXED_APER_SIZE
59
};
60
 
61
struct gatt_mask {
62
	unsigned long mask;
63
	u32 type;
64
	/* totally device specific, for integrated chipsets that
65
	 * might have different types of memory masks.  For other
66
	 * devices this will probably be ignored */
67
};
68
 
69
#define AGP_PAGE_DESTROY_UNMAP 1
70
#define AGP_PAGE_DESTROY_FREE 2
71
 
72
struct aper_size_info_8 {
73
	int size;
74
	int num_entries;
75
	int page_order;
76
	u8 size_value;
77
};
78
 
79
struct aper_size_info_16 {
80
	int size;
81
	int num_entries;
82
	int page_order;
83
	u16 size_value;
84
};
85
 
86
struct aper_size_info_32 {
87
	int size;
88
	int num_entries;
89
	int page_order;
90
	u32 size_value;
91
};
92
 
93
struct aper_size_info_lvl2 {
94
	int size;
95
	int num_entries;
96
	u32 size_value;
97
};
98
 
99
struct aper_size_info_fixed {
100
	int size;
101
	int num_entries;
102
	int page_order;
103
};
104
 
105
struct agp_bridge_driver {
106
	struct module *owner;
107
	const void *aperture_sizes;
108
	int num_aperture_sizes;
109
	enum aper_size_type size_type;
110
	bool cant_use_aperture;
111
	bool needs_scratch_page;
112
	const struct gatt_mask *masks;
113
	int (*fetch_size)(void);
114
	int (*configure)(void);
115
	void (*agp_enable)(struct agp_bridge_data *, u32);
116
	void (*cleanup)(void);
117
	void (*tlb_flush)(struct agp_memory *);
118
	unsigned long (*mask_memory)(struct agp_bridge_data *, dma_addr_t, int);
119
	void (*cache_flush)(void);
120
	int (*create_gatt_table)(struct agp_bridge_data *);
121
	int (*free_gatt_table)(struct agp_bridge_data *);
122
	int (*insert_memory)(struct agp_memory *, off_t, int);
123
	int (*remove_memory)(struct agp_memory *, off_t, int);
124
	struct agp_memory *(*alloc_by_type) (size_t, int);
125
	void (*free_by_type)(struct agp_memory *);
126
	struct page *(*agp_alloc_page)(struct agp_bridge_data *);
127
	int (*agp_alloc_pages)(struct agp_bridge_data *, struct agp_memory *, size_t);
128
	void (*agp_destroy_page)(struct page *, int flags);
129
	void (*agp_destroy_pages)(struct agp_memory *);
130
	int (*agp_type_to_mask_type) (struct agp_bridge_data *, int);
131
};
132
 
133
struct agp_bridge_data {
134
	const struct agp_version *version;
135
	const struct agp_bridge_driver *driver;
136
	const struct vm_operations_struct *vm_ops;
137
	void *previous_size;
138
	void *current_size;
139
	void *dev_private_data;
140
	struct pci_dev *dev;
141
	u32 __iomem *gatt_table;
142
	u32 *gatt_table_real;
143
	unsigned long scratch_page;
144
	struct page *scratch_page_page;
145
	dma_addr_t scratch_page_dma;
146
	unsigned long gart_bus_addr;
147
	unsigned long gatt_bus_addr;
148
	u32 mode;
149
	enum chipset_type type;
150
	unsigned long *key_list;
151
	atomic_t current_memory_agp;
152
	atomic_t agp_in_use;
153
	int max_memory_agp;	/* in number of pages */
154
	int aperture_size_idx;
155
	int capndx;
156
	int flags;
157
	char major_version;
158
	char minor_version;
159
	struct list_head list;
160
	u32 apbase_config;
161
	/* list of agp_memory mapped to the aperture */
162
	struct list_head mapped_list;
163
	spinlock_t mapped_lock;
164
};
165
 
166
#define KB(x)	((x) * 1024)
167
#define MB(x)	(KB (KB (x)))
168
#define GB(x)	(MB (KB (x)))
169
 
170
#define A_SIZE_8(x)	((struct aper_size_info_8 *) x)
171
#define A_SIZE_16(x)	((struct aper_size_info_16 *) x)
172
#define A_SIZE_32(x)	((struct aper_size_info_32 *) x)
173
#define A_SIZE_LVL2(x)	((struct aper_size_info_lvl2 *) x)
174
#define A_SIZE_FIX(x)	((struct aper_size_info_fixed *) x)
175
#define A_IDX8(bridge)	(A_SIZE_8((bridge)->driver->aperture_sizes) + i)
176
#define A_IDX16(bridge)	(A_SIZE_16((bridge)->driver->aperture_sizes) + i)
177
#define A_IDX32(bridge)	(A_SIZE_32((bridge)->driver->aperture_sizes) + i)
178
#define MAXKEY		(4096 * 32)
179
 
180
#define PGE_EMPTY(b, p)	(!(p) || (p) == (unsigned long) (b)->scratch_page)
181
 
182
 
183
struct agp_device_ids {
184
	unsigned short device_id; /* first, to make table easier to read */
185
	enum chipset_type chipset;
186
	const char *chipset_name;
187
	int (*chipset_setup) (struct pci_dev *pdev);	/* used to override generic */
188
};
189
 
190
/* Driver registration */
191
struct agp_bridge_data *agp_alloc_bridge(void);
192
void agp_put_bridge(struct agp_bridge_data *bridge);
193
int agp_add_bridge(struct agp_bridge_data *bridge);
194
void agp_remove_bridge(struct agp_bridge_data *bridge);
195
 
196
/* Frontend routines. */
197
int agp_frontend_initialize(void);
198
void agp_frontend_cleanup(void);
199
 
200
/* Generic routines. */
201
void agp_generic_enable(struct agp_bridge_data *bridge, u32 mode);
202
int agp_generic_create_gatt_table(struct agp_bridge_data *bridge);
203
int agp_generic_free_gatt_table(struct agp_bridge_data *bridge);
204
struct agp_memory *agp_create_memory(int scratch_pages);
205
int agp_generic_insert_memory(struct agp_memory *mem, off_t pg_start, int type);
206
int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type);
207
struct agp_memory *agp_generic_alloc_by_type(size_t page_count, int type);
208
void agp_generic_free_by_type(struct agp_memory *curr);
209
struct page *agp_generic_alloc_page(struct agp_bridge_data *bridge);
210
int agp_generic_alloc_pages(struct agp_bridge_data *agp_bridge,
211
			    struct agp_memory *memory, size_t page_count);
212
void agp_generic_destroy_page(struct page *page, int flags);
213
void agp_generic_destroy_pages(struct agp_memory *memory);
214
void agp_free_key(int key);
215
int agp_num_entries(void);
216
u32 agp_collect_device_status(struct agp_bridge_data *bridge, u32 mode, u32 command);
217
void agp_device_command(u32 command, bool agp_v3);
218
int agp_3_5_enable(struct agp_bridge_data *bridge);
219
void global_cache_flush(void);
220
void get_agp_version(struct agp_bridge_data *bridge);
221
unsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge,
222
				      dma_addr_t phys, int type);
223
int agp_generic_type_to_mask_type(struct agp_bridge_data *bridge,
224
				  int type);
225
struct agp_bridge_data *agp_generic_find_bridge(struct pci_dev *pdev);
226
 
227
/* generic functions for user-populated AGP memory types */
228
struct agp_memory *agp_generic_alloc_user(size_t page_count, int type);
229
void agp_alloc_page_array(size_t size, struct agp_memory *mem);
230
void agp_free_page_array(struct agp_memory *mem);
231
 
232
 
233
/* generic routines for agp>=3 */
234
int agp3_generic_fetch_size(void);
235
void agp3_generic_tlbflush(struct agp_memory *mem);
236
int agp3_generic_configure(void);
237
void agp3_generic_cleanup(void);
238
 
239
/* aperture sizes have been standardised since v3 */
240
#define AGP_GENERIC_SIZES_ENTRIES 11
241
extern const struct aper_size_info_16 agp3_generic_sizes[];
242
 
243
extern int agp_off;
244
extern int agp_try_unsupported_boot;
245
 
246
long compat_agp_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
247
 
248
/* Chipset independent registers (from AGP Spec) */
249
#define AGP_APBASE	0x10
250
 
251
#define AGPSTAT		0x4
252
#define AGPCMD		0x8
253
#define AGPNISTAT	0xc
254
#define AGPCTRL		0x10
255
#define AGPAPSIZE	0x14
256
#define AGPNEPG		0x16
257
#define AGPGARTLO	0x18
258
#define AGPGARTHI	0x1c
259
#define AGPNICMD	0x20
260
 
261
#define AGP_MAJOR_VERSION_SHIFT	(20)
262
#define AGP_MINOR_VERSION_SHIFT	(16)
263
 
264
#define AGPSTAT_RQ_DEPTH	(0xff000000)
265
#define AGPSTAT_RQ_DEPTH_SHIFT	24
266
 
267
#define AGPSTAT_CAL_MASK	(1<<12|1<<11|1<<10)
268
#define AGPSTAT_ARQSZ		(1<<15|1<<14|1<<13)
269
#define AGPSTAT_ARQSZ_SHIFT	13
270
 
271
#define AGPSTAT_SBA		(1<<9)
272
#define AGPSTAT_AGP_ENABLE	(1<<8)
273
#define AGPSTAT_FW		(1<<4)
274
#define AGPSTAT_MODE_3_0	(1<<3)
275
 
276
#define AGPSTAT2_1X		(1<<0)
277
#define AGPSTAT2_2X		(1<<1)
278
#define AGPSTAT2_4X		(1<<2)
279
 
280
#define AGPSTAT3_RSVD		(1<<2)
281
#define AGPSTAT3_8X		(1<<1)
282
#define AGPSTAT3_4X		(1)
283
 
284
#define AGPCTRL_APERENB		(1<<8)
285
#define AGPCTRL_GTLBEN		(1<<7)
286
 
287
#define AGP2_RESERVED_MASK 0x00fffcc8
288
#define AGP3_RESERVED_MASK 0x00ff00c4
289
 
290
#define AGP_ERRATA_FASTWRITES 1<<0
291
#define AGP_ERRATA_SBA	 1<<1
292
#define AGP_ERRATA_1X 1<<2
293
 
294
#endif	/* _AGP_BACKEND_PRIV_H */