blob: 870f12cfed93000e670423e9aac8afad892503cf [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Dave Jones6a92a4e2006-02-28 00:54:25 -050022 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 * 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 <asm/agp.h> /* for flush_agp_cache() */
33
34#define PFX "agpgart: "
35
36//#define AGP_DEBUG 1
37#ifdef AGP_DEBUG
Harvey Harrisonbf9d8922008-04-30 00:55:10 -070038#define DBG(x,y...) printk (KERN_DEBUG PFX "%s: " x "\n", __func__ , ## y)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#else
40#define DBG(x,y...) do { } while (0)
41#endif
42
43extern struct agp_bridge_data *agp_bridge;
44
45enum aper_size_type {
46 U8_APER_SIZE,
47 U16_APER_SIZE,
48 U32_APER_SIZE,
49 LVL2_APER_SIZE,
50 FIXED_APER_SIZE
51};
52
53struct gatt_mask {
54 unsigned long mask;
55 u32 type;
Dave Jones6a92a4e2006-02-28 00:54:25 -050056 /* totally device specific, for integrated chipsets that
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 * might have different types of memory masks. For other
58 * devices this will probably be ignored */
59};
60
Dave Airliea2721e92007-10-15 10:19:16 +100061#define AGP_PAGE_DESTROY_UNMAP 1
62#define AGP_PAGE_DESTROY_FREE 2
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064struct aper_size_info_8 {
65 int size;
66 int num_entries;
67 int page_order;
68 u8 size_value;
69};
70
71struct aper_size_info_16 {
72 int size;
73 int num_entries;
74 int page_order;
75 u16 size_value;
76};
77
78struct aper_size_info_32 {
79 int size;
80 int num_entries;
81 int page_order;
82 u32 size_value;
83};
84
85struct aper_size_info_lvl2 {
86 int size;
87 int num_entries;
88 u32 size_value;
89};
90
91struct aper_size_info_fixed {
92 int size;
93 int num_entries;
94 int page_order;
95};
96
97struct agp_bridge_driver {
98 struct module *owner;
Dave Jonese5524f32007-02-22 18:41:28 -050099 const void *aperture_sizes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 int num_aperture_sizes;
101 enum aper_size_type size_type;
Joe Perchesc7258012008-03-26 14:10:02 -0700102 bool cant_use_aperture;
103 bool needs_scratch_page;
Dave Jonese5524f32007-02-22 18:41:28 -0500104 const struct gatt_mask *masks;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 int (*fetch_size)(void);
106 int (*configure)(void);
107 void (*agp_enable)(struct agp_bridge_data *, u32);
108 void (*cleanup)(void);
109 void (*tlb_flush)(struct agp_memory *);
David Woodhouse2a4ceb62009-07-27 10:27:29 +0100110 unsigned long (*mask_memory)(struct agp_bridge_data *, dma_addr_t, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 void (*cache_flush)(void);
112 int (*create_gatt_table)(struct agp_bridge_data *);
113 int (*free_gatt_table)(struct agp_bridge_data *);
114 int (*insert_memory)(struct agp_memory *, off_t, int);
115 int (*remove_memory)(struct agp_memory *, off_t, int);
116 struct agp_memory *(*alloc_by_type) (size_t, int);
117 void (*free_by_type)(struct agp_memory *);
Dave Airlie07613ba2009-06-12 14:11:41 +1000118 struct page *(*agp_alloc_page)(struct agp_bridge_data *);
Shaohua Li37acee12008-08-21 10:46:11 +0800119 int (*agp_alloc_pages)(struct agp_bridge_data *, struct agp_memory *, size_t);
Dave Airlie07613ba2009-06-12 14:11:41 +1000120 void (*agp_destroy_page)(struct page *, int flags);
Shaohua Libd079282008-08-21 10:46:17 +0800121 void (*agp_destroy_pages)(struct agp_memory *);
Dave Airliea13af4b2007-10-29 15:14:03 +1000122 int (*agp_type_to_mask_type) (struct agp_bridge_data *, int);
123 void (*chipset_flush)(struct agp_bridge_data *);
Zhenyu Wangff663cf2009-07-23 17:25:49 +0100124
David Woodhousec2980d82009-07-29 08:39:26 +0100125 int (*agp_map_page)(struct page *page, dma_addr_t *ret);
126 void (*agp_unmap_page)(struct page *page, dma_addr_t dma);
Zhenyu Wangff663cf2009-07-23 17:25:49 +0100127 int (*agp_map_memory)(struct agp_memory *mem);
128 void (*agp_unmap_memory)(struct agp_memory *mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129};
130
131struct agp_bridge_data {
Alexey Dobriyan8eb79252006-08-20 18:48:13 +0400132 const struct agp_version *version;
Dave Jonese5524f32007-02-22 18:41:28 -0500133 const struct agp_bridge_driver *driver;
Alexey Dobriyanf0f37e22009-09-27 22:29:37 +0400134 const struct vm_operations_struct *vm_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 void *previous_size;
136 void *current_size;
137 void *dev_private_data;
138 struct pci_dev *dev;
139 u32 __iomem *gatt_table;
140 u32 *gatt_table_real;
141 unsigned long scratch_page;
David Woodhousec2980d82009-07-29 08:39:26 +0100142 struct page *scratch_page_page;
Zhenyu Wangff663cf2009-07-23 17:25:49 +0100143 dma_addr_t scratch_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 unsigned long gart_bus_addr;
145 unsigned long gatt_bus_addr;
146 u32 mode;
147 enum chipset_type type;
148 unsigned long *key_list;
149 atomic_t current_memory_agp;
150 atomic_t agp_in_use;
151 int max_memory_agp; /* in number of pages */
152 int aperture_size_idx;
153 int capndx;
154 int flags;
155 char major_version;
156 char minor_version;
157 struct list_head list;
Matthew Garrettb0825482005-07-29 14:03:39 -0700158 u32 apbase_config;
Keith Packarda8c84df2008-07-31 15:48:07 +1000159 /* list of agp_memory mapped to the aperture */
160 struct list_head mapped_list;
161 spinlock_t mapped_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162};
163
164#define KB(x) ((x) * 1024)
165#define MB(x) (KB (KB (x)))
166#define GB(x) (MB (KB (x)))
167
168#define A_SIZE_8(x) ((struct aper_size_info_8 *) x)
169#define A_SIZE_16(x) ((struct aper_size_info_16 *) x)
170#define A_SIZE_32(x) ((struct aper_size_info_32 *) x)
171#define A_SIZE_LVL2(x) ((struct aper_size_info_lvl2 *) x)
172#define A_SIZE_FIX(x) ((struct aper_size_info_fixed *) x)
173#define A_IDX8(bridge) (A_SIZE_8((bridge)->driver->aperture_sizes) + i)
174#define A_IDX16(bridge) (A_SIZE_16((bridge)->driver->aperture_sizes) + i)
175#define A_IDX32(bridge) (A_SIZE_32((bridge)->driver->aperture_sizes) + i)
176#define MAXKEY (4096 * 32)
177
178#define PGE_EMPTY(b, p) (!(p) || (p) == (unsigned long) (b)->scratch_page)
179
180
181/* Intel registers */
182#define INTEL_APSIZE 0xb4
183#define INTEL_ATTBASE 0xb8
184#define INTEL_AGPCTRL 0xb0
185#define INTEL_NBXCFG 0x50
186#define INTEL_ERRSTS 0x91
187
188/* Intel i830 registers */
189#define I830_GMCH_CTRL 0x52
190#define I830_GMCH_ENABLED 0x4
191#define I830_GMCH_MEM_MASK 0x1
192#define I830_GMCH_MEM_64M 0x1
193#define I830_GMCH_MEM_128M 0
Dave Airliee67aa272007-09-18 22:46:35 -0700194#define I830_GMCH_GMS_MASK 0x70
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195#define I830_GMCH_GMS_DISABLED 0x00
196#define I830_GMCH_GMS_LOCAL 0x10
197#define I830_GMCH_GMS_STOLEN_512 0x20
198#define I830_GMCH_GMS_STOLEN_1024 0x30
199#define I830_GMCH_GMS_STOLEN_8192 0x40
200#define I830_RDRAM_CHANNEL_TYPE 0x03010
201#define I830_RDRAM_ND(x) (((x) & 0x20) >> 5)
202#define I830_RDRAM_DDT(x) (((x) & 0x18) >> 3)
203
204/* This one is for I830MP w. an external graphic card */
205#define INTEL_I830_ERRSTS 0x92
206
207/* Intel 855GM/852GM registers */
Dave Airliee67aa272007-09-18 22:46:35 -0700208#define I855_GMCH_GMS_MASK 0xF0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209#define I855_GMCH_GMS_STOLEN_0M 0x0
210#define I855_GMCH_GMS_STOLEN_1M (0x1 << 4)
211#define I855_GMCH_GMS_STOLEN_4M (0x2 << 4)
212#define I855_GMCH_GMS_STOLEN_8M (0x3 << 4)
213#define I855_GMCH_GMS_STOLEN_16M (0x4 << 4)
214#define I855_GMCH_GMS_STOLEN_32M (0x5 << 4)
215#define I85X_CAPID 0x44
216#define I85X_VARIANT_MASK 0x7
217#define I85X_VARIANT_SHIFT 5
218#define I855_GME 0x0
219#define I855_GM 0x4
220#define I852_GME 0x2
221#define I852_GM 0x5
222
223/* Intel i845 registers */
224#define INTEL_I845_AGPM 0x51
225#define INTEL_I845_ERRSTS 0xc8
226
227/* Intel i860 registers */
228#define INTEL_I860_MCHCFG 0x50
229#define INTEL_I860_ERRSTS 0xc8
230
231/* Intel i810 registers */
232#define I810_GMADDR 0x10
233#define I810_MMADDR 0x14
234#define I810_PTE_BASE 0x10000
235#define I810_PTE_MAIN_UNCACHED 0x00000000
236#define I810_PTE_LOCAL 0x00000002
237#define I810_PTE_VALID 0x00000001
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100238#define I830_PTE_SYSTEM_CACHED 0x00000006
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239#define I810_SMRAM_MISCC 0x70
240#define I810_GFX_MEM_WIN_SIZE 0x00010000
241#define I810_GFX_MEM_WIN_32M 0x00010000
242#define I810_GMS 0x000000c0
243#define I810_GMS_DISABLE 0x00000000
244#define I810_PGETBL_CTL 0x2020
245#define I810_PGETBL_ENABLED 0x00000001
Eric Anholtc41e0de2006-12-19 12:57:24 -0800246#define I965_PGETBL_SIZE_MASK 0x0000000e
247#define I965_PGETBL_SIZE_512KB (0 << 1)
248#define I965_PGETBL_SIZE_256KB (1 << 1)
249#define I965_PGETBL_SIZE_128KB (2 << 1)
Zhenyu Wang4e8b6e22008-01-23 14:54:37 +1000250#define I965_PGETBL_SIZE_1MB (3 << 1)
251#define I965_PGETBL_SIZE_2MB (4 << 1)
252#define I965_PGETBL_SIZE_1_5MB (5 << 1)
Wang Zhenyu874808c62007-06-06 11:16:25 +0800253#define G33_PGETBL_SIZE_MASK (3 << 8)
254#define G33_PGETBL_SIZE_1M (1 << 8)
255#define G33_PGETBL_SIZE_2M (2 << 8)
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#define I810_DRAM_CTL 0x3000
258#define I810_DRAM_ROW_0 0x00000001
259#define I810_DRAM_ROW_0_SDRAM 0x00000001
260
261struct agp_device_ids {
262 unsigned short device_id; /* first, to make table easier to read */
263 enum chipset_type chipset;
264 const char *chipset_name;
265 int (*chipset_setup) (struct pci_dev *pdev); /* used to override generic */
266};
267
268/* Driver registration */
269struct agp_bridge_data *agp_alloc_bridge(void);
270void agp_put_bridge(struct agp_bridge_data *bridge);
271int agp_add_bridge(struct agp_bridge_data *bridge);
272void agp_remove_bridge(struct agp_bridge_data *bridge);
273
274/* Frontend routines. */
275int agp_frontend_initialize(void);
276void agp_frontend_cleanup(void);
277
278/* Generic routines. */
279void agp_generic_enable(struct agp_bridge_data *bridge, u32 mode);
280int agp_generic_create_gatt_table(struct agp_bridge_data *bridge);
281int agp_generic_free_gatt_table(struct agp_bridge_data *bridge);
282struct agp_memory *agp_create_memory(int scratch_pages);
283int agp_generic_insert_memory(struct agp_memory *mem, off_t pg_start, int type);
284int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type);
285struct agp_memory *agp_generic_alloc_by_type(size_t page_count, int type);
286void agp_generic_free_by_type(struct agp_memory *curr);
Dave Airlie07613ba2009-06-12 14:11:41 +1000287struct page *agp_generic_alloc_page(struct agp_bridge_data *bridge);
Shaohua Li37acee12008-08-21 10:46:11 +0800288int agp_generic_alloc_pages(struct agp_bridge_data *agp_bridge,
289 struct agp_memory *memory, size_t page_count);
Dave Airlie07613ba2009-06-12 14:11:41 +1000290void agp_generic_destroy_page(struct page *page, int flags);
Shaohua Libd079282008-08-21 10:46:17 +0800291void agp_generic_destroy_pages(struct agp_memory *memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292void agp_free_key(int key);
293int agp_num_entries(void);
294u32 agp_collect_device_status(struct agp_bridge_data *bridge, u32 mode, u32 command);
Joe Perchesc7258012008-03-26 14:10:02 -0700295void agp_device_command(u32 command, bool agp_v3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296int agp_3_5_enable(struct agp_bridge_data *bridge);
297void global_cache_flush(void);
298void get_agp_version(struct agp_bridge_data *bridge);
299unsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge,
David Woodhouse2a4ceb62009-07-27 10:27:29 +0100300 dma_addr_t phys, int type);
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100301int agp_generic_type_to_mask_type(struct agp_bridge_data *bridge,
302 int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303struct agp_bridge_data *agp_generic_find_bridge(struct pci_dev *pdev);
304
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100305/* generic functions for user-populated AGP memory types */
306struct agp_memory *agp_generic_alloc_user(size_t page_count, int type);
307void agp_alloc_page_array(size_t size, struct agp_memory *mem);
308void agp_free_page_array(struct agp_memory *mem);
309
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311/* generic routines for agp>=3 */
312int agp3_generic_fetch_size(void);
313void agp3_generic_tlbflush(struct agp_memory *mem);
314int agp3_generic_configure(void);
315void agp3_generic_cleanup(void);
316
317/* aperture sizes have been standardised since v3 */
318#define AGP_GENERIC_SIZES_ENTRIES 11
Dave Jonese5524f32007-02-22 18:41:28 -0500319extern const struct aper_size_info_16 agp3_generic_sizes[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321extern int agp_off;
322extern int agp_try_unsupported_boot;
323
Zwane Mwaikambo0316fe82007-01-29 21:20:31 -0800324long compat_agp_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326/* Chipset independant registers (from AGP Spec) */
327#define AGP_APBASE 0x10
328
329#define AGPSTAT 0x4
330#define AGPCMD 0x8
331#define AGPNISTAT 0xc
332#define AGPCTRL 0x10
333#define AGPAPSIZE 0x14
334#define AGPNEPG 0x16
335#define AGPGARTLO 0x18
336#define AGPGARTHI 0x1c
337#define AGPNICMD 0x20
338
339#define AGP_MAJOR_VERSION_SHIFT (20)
340#define AGP_MINOR_VERSION_SHIFT (16)
341
342#define AGPSTAT_RQ_DEPTH (0xff000000)
343#define AGPSTAT_RQ_DEPTH_SHIFT 24
344
345#define AGPSTAT_CAL_MASK (1<<12|1<<11|1<<10)
346#define AGPSTAT_ARQSZ (1<<15|1<<14|1<<13)
347#define AGPSTAT_ARQSZ_SHIFT 13
348
349#define AGPSTAT_SBA (1<<9)
350#define AGPSTAT_AGP_ENABLE (1<<8)
351#define AGPSTAT_FW (1<<4)
352#define AGPSTAT_MODE_3_0 (1<<3)
353
354#define AGPSTAT2_1X (1<<0)
355#define AGPSTAT2_2X (1<<1)
356#define AGPSTAT2_4X (1<<2)
357
358#define AGPSTAT3_RSVD (1<<2)
359#define AGPSTAT3_8X (1<<1)
360#define AGPSTAT3_4X (1)
361
362#define AGPCTRL_APERENB (1<<8)
363#define AGPCTRL_GTLBEN (1<<7)
364
365#define AGP2_RESERVED_MASK 0x00fffcc8
366#define AGP3_RESERVED_MASK 0x00ff00c4
367
368#define AGP_ERRATA_FASTWRITES 1<<0
369#define AGP_ERRATA_SBA 1<<1
370#define AGP_ERRATA_1X 1<<2
371
372#endif /* _AGP_BACKEND_PRIV_H */