292 lines · c
1/*2 * AGPGART3 * Copyright (C) 2004 Silicon Graphics, Inc.4 * Copyright (C) 2002-2004 Dave Jones5 * Copyright (C) 1999 Jeff Hartmann6 * 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 a10 * copy of this software and associated documentation files (the "Software"),11 * to deal in the Software without restriction, including without limitation12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,13 * and/or sell copies of the Software, and to permit persons to whom the14 * Software is furnished to do so, subject to the following conditions:15 *16 * The above copyright notice and this permission notice shall be included17 * in all copies or substantial portions of the Software.18 *19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL22 * JEFF HARTMANN, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,23 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR24 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE25 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.26 *27 */28 29#ifndef _AGP_BACKEND_PRIV_H30#define _AGP_BACKEND_PRIV_H 131 32#include <asm/agp.h> /* for flush_agp_cache() */33 34#define PFX "agpgart: "35 36//#define AGP_DEBUG 137#ifdef AGP_DEBUG38#define DBG(x,y...) printk (KERN_DEBUG PFX "%s: " x "\n", __func__ , ## y)39#else40#define DBG(x,y...) do { } while (0)41#endif42 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_SIZE51};52 53struct gatt_mask {54 unsigned long mask;55 u32 type;56 /* totally device specific, for integrated chipsets that57 * might have different types of memory masks. For other58 * devices this will probably be ignored */59};60 61#define AGP_PAGE_DESTROY_UNMAP 162#define AGP_PAGE_DESTROY_FREE 263 64struct 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;99 const void *aperture_sizes;100 int num_aperture_sizes;101 enum aper_size_type size_type;102 bool cant_use_aperture;103 bool needs_scratch_page;104 const struct gatt_mask *masks;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 *);110 unsigned long (*mask_memory)(struct agp_bridge_data *, dma_addr_t, int);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 *);118 struct page *(*agp_alloc_page)(struct agp_bridge_data *);119 int (*agp_alloc_pages)(struct agp_bridge_data *, struct agp_memory *, size_t);120 void (*agp_destroy_page)(struct page *, int flags);121 void (*agp_destroy_pages)(struct agp_memory *);122 int (*agp_type_to_mask_type) (struct agp_bridge_data *, int);123};124 125struct agp_bridge_data {126 const struct agp_version *version;127 const struct agp_bridge_driver *driver;128 const struct vm_operations_struct *vm_ops;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;136 struct page *scratch_page_page;137 dma_addr_t scratch_page_dma;138 unsigned long gart_bus_addr;139 unsigned long gatt_bus_addr;140 u32 mode;141 unsigned long *key_list;142 atomic_t current_memory_agp;143 atomic_t agp_in_use;144 int max_memory_agp; /* in number of pages */145 int aperture_size_idx;146 int capndx;147 int flags;148 char major_version;149 char minor_version;150 struct list_head list;151 u32 apbase_config;152 /* list of agp_memory mapped to the aperture */153 struct list_head mapped_list;154 spinlock_t mapped_lock;155};156 157#define KB(x) ((x) * 1024)158#define MB(x) (KB (KB (x)))159#define GB(x) (MB (KB (x)))160 161#define A_SIZE_8(x) ((struct aper_size_info_8 *) x)162#define A_SIZE_16(x) ((struct aper_size_info_16 *) x)163#define A_SIZE_32(x) ((struct aper_size_info_32 *) x)164#define A_SIZE_LVL2(x) ((struct aper_size_info_lvl2 *) x)165#define A_SIZE_FIX(x) ((struct aper_size_info_fixed *) x)166#define A_IDX8(bridge) (A_SIZE_8((bridge)->driver->aperture_sizes) + i)167#define A_IDX16(bridge) (A_SIZE_16((bridge)->driver->aperture_sizes) + i)168#define A_IDX32(bridge) (A_SIZE_32((bridge)->driver->aperture_sizes) + i)169#define MAXKEY (4096 * 32)170 171#define PGE_EMPTY(b, p) (!(p) || (p) == (unsigned long) (b)->scratch_page)172 173 174struct agp_device_ids {175 unsigned short device_id; /* first, to make table easier to read */176 enum chipset_type chipset;177 const char *chipset_name;178 int (*chipset_setup) (struct pci_dev *pdev); /* used to override generic */179};180 181/* Driver registration */182struct agp_bridge_data *agp_alloc_bridge(void);183void agp_put_bridge(struct agp_bridge_data *bridge);184int agp_add_bridge(struct agp_bridge_data *bridge);185void agp_remove_bridge(struct agp_bridge_data *bridge);186 187/* Generic routines. */188void agp_generic_enable(struct agp_bridge_data *bridge, u32 mode);189int agp_generic_create_gatt_table(struct agp_bridge_data *bridge);190int agp_generic_free_gatt_table(struct agp_bridge_data *bridge);191struct agp_memory *agp_create_memory(int scratch_pages);192int agp_generic_insert_memory(struct agp_memory *mem, off_t pg_start, int type);193int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type);194struct agp_memory *agp_generic_alloc_by_type(size_t page_count, int type);195void agp_generic_free_by_type(struct agp_memory *curr);196struct page *agp_generic_alloc_page(struct agp_bridge_data *bridge);197int agp_generic_alloc_pages(struct agp_bridge_data *agp_bridge,198 struct agp_memory *memory, size_t page_count);199void agp_generic_destroy_page(struct page *page, int flags);200void agp_generic_destroy_pages(struct agp_memory *memory);201void agp_free_key(int key);202int agp_num_entries(void);203u32 agp_collect_device_status(struct agp_bridge_data *bridge, u32 mode, u32 command);204void agp_device_command(u32 command, bool agp_v3);205int agp_3_5_enable(struct agp_bridge_data *bridge);206void global_cache_flush(void);207void get_agp_version(struct agp_bridge_data *bridge);208unsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge,209 dma_addr_t phys, int type);210int agp_generic_type_to_mask_type(struct agp_bridge_data *bridge,211 int type);212struct agp_bridge_data *agp_generic_find_bridge(struct pci_dev *pdev);213 214/* generic functions for user-populated AGP memory types */215struct agp_memory *agp_generic_alloc_user(size_t page_count, int type);216void agp_alloc_page_array(size_t size, struct agp_memory *mem);217static inline void agp_free_page_array(struct agp_memory *mem)218{219 kvfree(mem->pages);220}221 222 223/* generic routines for agp>=3 */224int agp3_generic_fetch_size(void);225void agp3_generic_tlbflush(struct agp_memory *mem);226int agp3_generic_configure(void);227void agp3_generic_cleanup(void);228 229/* GATT allocation. Returns/accepts GATT kernel virtual address. */230#define alloc_gatt_pages(order) \231 ((char *)__get_free_pages(GFP_KERNEL, (order)))232#define free_gatt_pages(table, order) \233 free_pages((unsigned long)(table), (order))234 235/* aperture sizes have been standardised since v3 */236#define AGP_GENERIC_SIZES_ENTRIES 11237extern const struct aper_size_info_16 agp3_generic_sizes[];238 239extern int agp_off;240extern int agp_try_unsupported_boot;241 242long compat_agp_ioctl(struct file *file, unsigned int cmd, unsigned long arg);243 244/* Chipset independent registers (from AGP Spec) */245#define AGP_APBASE 0x10246#define AGP_APERTURE_BAR 0247 248#define AGPSTAT 0x4249#define AGPCMD 0x8250#define AGPNISTAT 0xc251#define AGPCTRL 0x10252#define AGPAPSIZE 0x14253#define AGPNEPG 0x16254#define AGPGARTLO 0x18255#define AGPGARTHI 0x1c256#define AGPNICMD 0x20257 258#define AGP_MAJOR_VERSION_SHIFT (20)259#define AGP_MINOR_VERSION_SHIFT (16)260 261#define AGPSTAT_RQ_DEPTH (0xff000000)262#define AGPSTAT_RQ_DEPTH_SHIFT 24263 264#define AGPSTAT_CAL_MASK (1<<12|1<<11|1<<10)265#define AGPSTAT_ARQSZ (1<<15|1<<14|1<<13)266#define AGPSTAT_ARQSZ_SHIFT 13267 268#define AGPSTAT_SBA (1<<9)269#define AGPSTAT_AGP_ENABLE (1<<8)270#define AGPSTAT_FW (1<<4)271#define AGPSTAT_MODE_3_0 (1<<3)272 273#define AGPSTAT2_1X (1<<0)274#define AGPSTAT2_2X (1<<1)275#define AGPSTAT2_4X (1<<2)276 277#define AGPSTAT3_RSVD (1<<2)278#define AGPSTAT3_8X (1<<1)279#define AGPSTAT3_4X (1)280 281#define AGPCTRL_APERENB (1<<8)282#define AGPCTRL_GTLBEN (1<<7)283 284#define AGP2_RESERVED_MASK 0x00fffcc8285#define AGP3_RESERVED_MASK 0x00ff00c4286 287#define AGP_ERRATA_FASTWRITES 1<<0288#define AGP_ERRATA_SBA 1<<1289#define AGP_ERRATA_1X 1<<2290 291#endif /* _AGP_BACKEND_PRIV_H */292