Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Dave Jones | 6a92a4e | 2006-02-28 00:54:25 -0500 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 <asm/agp.h> /* for flush_agp_cache() */ |
| 33 | |
| 34 | #define PFX "agpgart: " |
| 35 | |
| 36 | //#define AGP_DEBUG 1 |
| 37 | #ifdef AGP_DEBUG |
Harvey Harrison | bf9d892 | 2008-04-30 00:55:10 -0700 | [diff] [blame] | 38 | #define DBG(x,y...) printk (KERN_DEBUG PFX "%s: " x "\n", __func__ , ## y) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #else |
| 40 | #define DBG(x,y...) do { } while (0) |
| 41 | #endif |
| 42 | |
| 43 | extern struct agp_bridge_data *agp_bridge; |
| 44 | |
| 45 | enum 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 | |
| 53 | struct gatt_mask { |
| 54 | unsigned long mask; |
| 55 | u32 type; |
Dave Jones | 6a92a4e | 2006-02-28 00:54:25 -0500 | [diff] [blame] | 56 | /* totally device specific, for integrated chipsets that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | * might have different types of memory masks. For other |
| 58 | * devices this will probably be ignored */ |
| 59 | }; |
| 60 | |
Dave Airlie | a2721e9 | 2007-10-15 10:19:16 +1000 | [diff] [blame] | 61 | #define AGP_PAGE_DESTROY_UNMAP 1 |
| 62 | #define AGP_PAGE_DESTROY_FREE 2 |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | struct aper_size_info_8 { |
| 65 | int size; |
| 66 | int num_entries; |
| 67 | int page_order; |
| 68 | u8 size_value; |
| 69 | }; |
| 70 | |
| 71 | struct aper_size_info_16 { |
| 72 | int size; |
| 73 | int num_entries; |
| 74 | int page_order; |
| 75 | u16 size_value; |
| 76 | }; |
| 77 | |
| 78 | struct aper_size_info_32 { |
| 79 | int size; |
| 80 | int num_entries; |
| 81 | int page_order; |
| 82 | u32 size_value; |
| 83 | }; |
| 84 | |
| 85 | struct aper_size_info_lvl2 { |
| 86 | int size; |
| 87 | int num_entries; |
| 88 | u32 size_value; |
| 89 | }; |
| 90 | |
| 91 | struct aper_size_info_fixed { |
| 92 | int size; |
| 93 | int num_entries; |
| 94 | int page_order; |
| 95 | }; |
| 96 | |
| 97 | struct agp_bridge_driver { |
| 98 | struct module *owner; |
Dave Jones | e5524f3 | 2007-02-22 18:41:28 -0500 | [diff] [blame] | 99 | const void *aperture_sizes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | int num_aperture_sizes; |
| 101 | enum aper_size_type size_type; |
Joe Perches | c725801 | 2008-03-26 14:10:02 -0700 | [diff] [blame] | 102 | bool cant_use_aperture; |
| 103 | bool needs_scratch_page; |
Dave Jones | e5524f3 | 2007-02-22 18:41:28 -0500 | [diff] [blame] | 104 | const struct gatt_mask *masks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | 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 Woodhouse | 2a4ceb6 | 2009-07-27 10:27:29 +0100 | [diff] [blame] | 110 | unsigned long (*mask_memory)(struct agp_bridge_data *, dma_addr_t, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | 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 Airlie | 07613ba | 2009-06-12 14:11:41 +1000 | [diff] [blame] | 118 | struct page *(*agp_alloc_page)(struct agp_bridge_data *); |
Shaohua Li | 37acee1 | 2008-08-21 10:46:11 +0800 | [diff] [blame] | 119 | int (*agp_alloc_pages)(struct agp_bridge_data *, struct agp_memory *, size_t); |
Dave Airlie | 07613ba | 2009-06-12 14:11:41 +1000 | [diff] [blame] | 120 | void (*agp_destroy_page)(struct page *, int flags); |
Shaohua Li | bd07928 | 2008-08-21 10:46:17 +0800 | [diff] [blame] | 121 | void (*agp_destroy_pages)(struct agp_memory *); |
Dave Airlie | a13af4b | 2007-10-29 15:14:03 +1000 | [diff] [blame] | 122 | int (*agp_type_to_mask_type) (struct agp_bridge_data *, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | struct agp_bridge_data { |
Alexey Dobriyan | 8eb7925 | 2006-08-20 18:48:13 +0400 | [diff] [blame] | 126 | const struct agp_version *version; |
Dave Jones | e5524f3 | 2007-02-22 18:41:28 -0500 | [diff] [blame] | 127 | const struct agp_bridge_driver *driver; |
Alexey Dobriyan | f0f37e2 | 2009-09-27 22:29:37 +0400 | [diff] [blame] | 128 | const struct vm_operations_struct *vm_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | void *previous_size; |
| 130 | void *current_size; |
| 131 | void *dev_private_data; |
| 132 | struct pci_dev *dev; |
| 133 | u32 __iomem *gatt_table; |
| 134 | u32 *gatt_table_real; |
| 135 | unsigned long scratch_page; |
David Woodhouse | c2980d8 | 2009-07-29 08:39:26 +0100 | [diff] [blame] | 136 | struct page *scratch_page_page; |
Zhenyu Wang | ff663cf | 2009-07-23 17:25:49 +0100 | [diff] [blame] | 137 | dma_addr_t scratch_page_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | unsigned long gart_bus_addr; |
| 139 | unsigned long gatt_bus_addr; |
| 140 | u32 mode; |
| 141 | enum chipset_type type; |
| 142 | unsigned long *key_list; |
| 143 | atomic_t current_memory_agp; |
| 144 | atomic_t agp_in_use; |
| 145 | int max_memory_agp; /* in number of pages */ |
| 146 | int aperture_size_idx; |
| 147 | int capndx; |
| 148 | int flags; |
| 149 | char major_version; |
| 150 | char minor_version; |
| 151 | struct list_head list; |
Matthew Garrett | b082548 | 2005-07-29 14:03:39 -0700 | [diff] [blame] | 152 | u32 apbase_config; |
Keith Packard | a8c84df | 2008-07-31 15:48:07 +1000 | [diff] [blame] | 153 | /* list of agp_memory mapped to the aperture */ |
| 154 | struct list_head mapped_list; |
| 155 | spinlock_t mapped_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | #define KB(x) ((x) * 1024) |
| 159 | #define MB(x) (KB (KB (x))) |
| 160 | #define GB(x) (MB (KB (x))) |
| 161 | |
| 162 | #define A_SIZE_8(x) ((struct aper_size_info_8 *) x) |
| 163 | #define A_SIZE_16(x) ((struct aper_size_info_16 *) x) |
| 164 | #define A_SIZE_32(x) ((struct aper_size_info_32 *) x) |
| 165 | #define A_SIZE_LVL2(x) ((struct aper_size_info_lvl2 *) x) |
| 166 | #define A_SIZE_FIX(x) ((struct aper_size_info_fixed *) x) |
| 167 | #define A_IDX8(bridge) (A_SIZE_8((bridge)->driver->aperture_sizes) + i) |
| 168 | #define A_IDX16(bridge) (A_SIZE_16((bridge)->driver->aperture_sizes) + i) |
| 169 | #define A_IDX32(bridge) (A_SIZE_32((bridge)->driver->aperture_sizes) + i) |
| 170 | #define MAXKEY (4096 * 32) |
| 171 | |
| 172 | #define PGE_EMPTY(b, p) (!(p) || (p) == (unsigned long) (b)->scratch_page) |
| 173 | |
| 174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | struct agp_device_ids { |
| 176 | unsigned short device_id; /* first, to make table easier to read */ |
| 177 | enum chipset_type chipset; |
| 178 | const char *chipset_name; |
| 179 | int (*chipset_setup) (struct pci_dev *pdev); /* used to override generic */ |
| 180 | }; |
| 181 | |
| 182 | /* Driver registration */ |
| 183 | struct agp_bridge_data *agp_alloc_bridge(void); |
| 184 | void agp_put_bridge(struct agp_bridge_data *bridge); |
| 185 | int agp_add_bridge(struct agp_bridge_data *bridge); |
| 186 | void agp_remove_bridge(struct agp_bridge_data *bridge); |
| 187 | |
| 188 | /* Frontend routines. */ |
| 189 | int agp_frontend_initialize(void); |
| 190 | void agp_frontend_cleanup(void); |
| 191 | |
| 192 | /* Generic routines. */ |
| 193 | void agp_generic_enable(struct agp_bridge_data *bridge, u32 mode); |
| 194 | int agp_generic_create_gatt_table(struct agp_bridge_data *bridge); |
| 195 | int agp_generic_free_gatt_table(struct agp_bridge_data *bridge); |
| 196 | struct agp_memory *agp_create_memory(int scratch_pages); |
| 197 | int agp_generic_insert_memory(struct agp_memory *mem, off_t pg_start, int type); |
| 198 | int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type); |
| 199 | struct agp_memory *agp_generic_alloc_by_type(size_t page_count, int type); |
| 200 | void agp_generic_free_by_type(struct agp_memory *curr); |
Dave Airlie | 07613ba | 2009-06-12 14:11:41 +1000 | [diff] [blame] | 201 | struct page *agp_generic_alloc_page(struct agp_bridge_data *bridge); |
Shaohua Li | 37acee1 | 2008-08-21 10:46:11 +0800 | [diff] [blame] | 202 | int agp_generic_alloc_pages(struct agp_bridge_data *agp_bridge, |
| 203 | struct agp_memory *memory, size_t page_count); |
Dave Airlie | 07613ba | 2009-06-12 14:11:41 +1000 | [diff] [blame] | 204 | void agp_generic_destroy_page(struct page *page, int flags); |
Shaohua Li | bd07928 | 2008-08-21 10:46:17 +0800 | [diff] [blame] | 205 | void agp_generic_destroy_pages(struct agp_memory *memory); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | void agp_free_key(int key); |
| 207 | int agp_num_entries(void); |
| 208 | u32 agp_collect_device_status(struct agp_bridge_data *bridge, u32 mode, u32 command); |
Joe Perches | c725801 | 2008-03-26 14:10:02 -0700 | [diff] [blame] | 209 | void agp_device_command(u32 command, bool agp_v3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | int agp_3_5_enable(struct agp_bridge_data *bridge); |
| 211 | void global_cache_flush(void); |
| 212 | void get_agp_version(struct agp_bridge_data *bridge); |
| 213 | unsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge, |
David Woodhouse | 2a4ceb6 | 2009-07-27 10:27:29 +0100 | [diff] [blame] | 214 | dma_addr_t phys, int type); |
Thomas Hellstrom | a030ce4 | 2007-01-23 10:33:43 +0100 | [diff] [blame] | 215 | int agp_generic_type_to_mask_type(struct agp_bridge_data *bridge, |
| 216 | int type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | struct agp_bridge_data *agp_generic_find_bridge(struct pci_dev *pdev); |
| 218 | |
Thomas Hellstrom | a030ce4 | 2007-01-23 10:33:43 +0100 | [diff] [blame] | 219 | /* generic functions for user-populated AGP memory types */ |
| 220 | struct agp_memory *agp_generic_alloc_user(size_t page_count, int type); |
| 221 | void agp_alloc_page_array(size_t size, struct agp_memory *mem); |
Wang, Yalin | e410055 | 2015-01-28 13:57:34 +0800 | [diff] [blame] | 222 | static inline void agp_free_page_array(struct agp_memory *mem) |
| 223 | { |
| 224 | kvfree(mem->pages); |
| 225 | } |
Thomas Hellstrom | a030ce4 | 2007-01-23 10:33:43 +0100 | [diff] [blame] | 226 | |
| 227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | /* generic routines for agp>=3 */ |
| 229 | int agp3_generic_fetch_size(void); |
| 230 | void agp3_generic_tlbflush(struct agp_memory *mem); |
| 231 | int agp3_generic_configure(void); |
| 232 | void agp3_generic_cleanup(void); |
| 233 | |
| 234 | /* aperture sizes have been standardised since v3 */ |
| 235 | #define AGP_GENERIC_SIZES_ENTRIES 11 |
Dave Jones | e5524f3 | 2007-02-22 18:41:28 -0500 | [diff] [blame] | 236 | extern const struct aper_size_info_16 agp3_generic_sizes[]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | extern int agp_off; |
| 239 | extern int agp_try_unsupported_boot; |
| 240 | |
Zwane Mwaikambo | 0316fe8 | 2007-01-29 21:20:31 -0800 | [diff] [blame] | 241 | long compat_agp_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
| 242 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 243 | /* Chipset independent registers (from AGP Spec) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | #define AGP_APBASE 0x10 |
Bjorn Helgaas | e501b3d | 2014-01-03 18:26:58 -0700 | [diff] [blame] | 245 | #define AGP_APERTURE_BAR 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | #define AGPSTAT 0x4 |
| 248 | #define AGPCMD 0x8 |
| 249 | #define AGPNISTAT 0xc |
| 250 | #define AGPCTRL 0x10 |
| 251 | #define AGPAPSIZE 0x14 |
| 252 | #define AGPNEPG 0x16 |
| 253 | #define AGPGARTLO 0x18 |
| 254 | #define AGPGARTHI 0x1c |
| 255 | #define AGPNICMD 0x20 |
| 256 | |
| 257 | #define AGP_MAJOR_VERSION_SHIFT (20) |
| 258 | #define AGP_MINOR_VERSION_SHIFT (16) |
| 259 | |
| 260 | #define AGPSTAT_RQ_DEPTH (0xff000000) |
| 261 | #define AGPSTAT_RQ_DEPTH_SHIFT 24 |
| 262 | |
| 263 | #define AGPSTAT_CAL_MASK (1<<12|1<<11|1<<10) |
| 264 | #define AGPSTAT_ARQSZ (1<<15|1<<14|1<<13) |
| 265 | #define AGPSTAT_ARQSZ_SHIFT 13 |
| 266 | |
| 267 | #define AGPSTAT_SBA (1<<9) |
| 268 | #define AGPSTAT_AGP_ENABLE (1<<8) |
| 269 | #define AGPSTAT_FW (1<<4) |
| 270 | #define AGPSTAT_MODE_3_0 (1<<3) |
| 271 | |
| 272 | #define AGPSTAT2_1X (1<<0) |
| 273 | #define AGPSTAT2_2X (1<<1) |
| 274 | #define AGPSTAT2_4X (1<<2) |
| 275 | |
| 276 | #define AGPSTAT3_RSVD (1<<2) |
| 277 | #define AGPSTAT3_8X (1<<1) |
| 278 | #define AGPSTAT3_4X (1) |
| 279 | |
| 280 | #define AGPCTRL_APERENB (1<<8) |
| 281 | #define AGPCTRL_GTLBEN (1<<7) |
| 282 | |
| 283 | #define AGP2_RESERVED_MASK 0x00fffcc8 |
| 284 | #define AGP3_RESERVED_MASK 0x00ff00c4 |
| 285 | |
| 286 | #define AGP_ERRATA_FASTWRITES 1<<0 |
| 287 | #define AGP_ERRATA_SBA 1<<1 |
| 288 | #define AGP_ERRATA_1X 1<<2 |
| 289 | |
| 290 | #endif /* _AGP_BACKEND_PRIV_H */ |