0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifndef _AGP_BACKEND_PRIV_H
0030 #define _AGP_BACKEND_PRIV_H 1
0031
0032 #include <asm/agp.h> /* for flush_agp_cache() */
0033
0034 #define PFX "agpgart: "
0035
0036
0037 #ifdef AGP_DEBUG
0038 #define DBG(x,y...) printk (KERN_DEBUG PFX "%s: " x "\n", __func__ , ## y)
0039 #else
0040 #define DBG(x,y...) do { } while (0)
0041 #endif
0042
0043 extern struct agp_bridge_data *agp_bridge;
0044
0045 enum aper_size_type {
0046 U8_APER_SIZE,
0047 U16_APER_SIZE,
0048 U32_APER_SIZE,
0049 LVL2_APER_SIZE,
0050 FIXED_APER_SIZE
0051 };
0052
0053 struct gatt_mask {
0054 unsigned long mask;
0055 u32 type;
0056
0057
0058
0059 };
0060
0061 #define AGP_PAGE_DESTROY_UNMAP 1
0062 #define AGP_PAGE_DESTROY_FREE 2
0063
0064 struct aper_size_info_8 {
0065 int size;
0066 int num_entries;
0067 int page_order;
0068 u8 size_value;
0069 };
0070
0071 struct aper_size_info_16 {
0072 int size;
0073 int num_entries;
0074 int page_order;
0075 u16 size_value;
0076 };
0077
0078 struct aper_size_info_32 {
0079 int size;
0080 int num_entries;
0081 int page_order;
0082 u32 size_value;
0083 };
0084
0085 struct aper_size_info_lvl2 {
0086 int size;
0087 int num_entries;
0088 u32 size_value;
0089 };
0090
0091 struct aper_size_info_fixed {
0092 int size;
0093 int num_entries;
0094 int page_order;
0095 };
0096
0097 struct agp_bridge_driver {
0098 struct module *owner;
0099 const void *aperture_sizes;
0100 int num_aperture_sizes;
0101 enum aper_size_type size_type;
0102 bool cant_use_aperture;
0103 bool needs_scratch_page;
0104 const struct gatt_mask *masks;
0105 int (*fetch_size)(void);
0106 int (*configure)(void);
0107 void (*agp_enable)(struct agp_bridge_data *, u32);
0108 void (*cleanup)(void);
0109 void (*tlb_flush)(struct agp_memory *);
0110 unsigned long (*mask_memory)(struct agp_bridge_data *, dma_addr_t, int);
0111 void (*cache_flush)(void);
0112 int (*create_gatt_table)(struct agp_bridge_data *);
0113 int (*free_gatt_table)(struct agp_bridge_data *);
0114 int (*insert_memory)(struct agp_memory *, off_t, int);
0115 int (*remove_memory)(struct agp_memory *, off_t, int);
0116 struct agp_memory *(*alloc_by_type) (size_t, int);
0117 void (*free_by_type)(struct agp_memory *);
0118 struct page *(*agp_alloc_page)(struct agp_bridge_data *);
0119 int (*agp_alloc_pages)(struct agp_bridge_data *, struct agp_memory *, size_t);
0120 void (*agp_destroy_page)(struct page *, int flags);
0121 void (*agp_destroy_pages)(struct agp_memory *);
0122 int (*agp_type_to_mask_type) (struct agp_bridge_data *, int);
0123 };
0124
0125 struct agp_bridge_data {
0126 const struct agp_version *version;
0127 const struct agp_bridge_driver *driver;
0128 const struct vm_operations_struct *vm_ops;
0129 void *previous_size;
0130 void *current_size;
0131 void *dev_private_data;
0132 struct pci_dev *dev;
0133 u32 __iomem *gatt_table;
0134 u32 *gatt_table_real;
0135 unsigned long scratch_page;
0136 struct page *scratch_page_page;
0137 dma_addr_t scratch_page_dma;
0138 unsigned long gart_bus_addr;
0139 unsigned long gatt_bus_addr;
0140 u32 mode;
0141 enum chipset_type type;
0142 unsigned long *key_list;
0143 atomic_t current_memory_agp;
0144 atomic_t agp_in_use;
0145 int max_memory_agp;
0146 int aperture_size_idx;
0147 int capndx;
0148 int flags;
0149 char major_version;
0150 char minor_version;
0151 struct list_head list;
0152 u32 apbase_config;
0153
0154 struct list_head mapped_list;
0155 spinlock_t mapped_lock;
0156 };
0157
0158 #define KB(x) ((x) * 1024)
0159 #define MB(x) (KB (KB (x)))
0160 #define GB(x) (MB (KB (x)))
0161
0162 #define A_SIZE_8(x) ((struct aper_size_info_8 *) x)
0163 #define A_SIZE_16(x) ((struct aper_size_info_16 *) x)
0164 #define A_SIZE_32(x) ((struct aper_size_info_32 *) x)
0165 #define A_SIZE_LVL2(x) ((struct aper_size_info_lvl2 *) x)
0166 #define A_SIZE_FIX(x) ((struct aper_size_info_fixed *) x)
0167 #define A_IDX8(bridge) (A_SIZE_8((bridge)->driver->aperture_sizes) + i)
0168 #define A_IDX16(bridge) (A_SIZE_16((bridge)->driver->aperture_sizes) + i)
0169 #define A_IDX32(bridge) (A_SIZE_32((bridge)->driver->aperture_sizes) + i)
0170 #define MAXKEY (4096 * 32)
0171
0172 #define PGE_EMPTY(b, p) (!(p) || (p) == (unsigned long) (b)->scratch_page)
0173
0174
0175 struct agp_device_ids {
0176 unsigned short device_id;
0177 enum chipset_type chipset;
0178 const char *chipset_name;
0179 int (*chipset_setup) (struct pci_dev *pdev);
0180 };
0181
0182
0183 struct agp_bridge_data *agp_alloc_bridge(void);
0184 void agp_put_bridge(struct agp_bridge_data *bridge);
0185 int agp_add_bridge(struct agp_bridge_data *bridge);
0186 void agp_remove_bridge(struct agp_bridge_data *bridge);
0187
0188
0189 #if IS_ENABLED(CONFIG_DRM_LEGACY)
0190 int agp_frontend_initialize(void);
0191 void agp_frontend_cleanup(void);
0192 #else
0193 static inline int agp_frontend_initialize(void) { return 0; }
0194 static inline void agp_frontend_cleanup(void) {}
0195 #endif
0196
0197
0198 void agp_generic_enable(struct agp_bridge_data *bridge, u32 mode);
0199 int agp_generic_create_gatt_table(struct agp_bridge_data *bridge);
0200 int agp_generic_free_gatt_table(struct agp_bridge_data *bridge);
0201 struct agp_memory *agp_create_memory(int scratch_pages);
0202 int agp_generic_insert_memory(struct agp_memory *mem, off_t pg_start, int type);
0203 int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type);
0204 struct agp_memory *agp_generic_alloc_by_type(size_t page_count, int type);
0205 void agp_generic_free_by_type(struct agp_memory *curr);
0206 struct page *agp_generic_alloc_page(struct agp_bridge_data *bridge);
0207 int agp_generic_alloc_pages(struct agp_bridge_data *agp_bridge,
0208 struct agp_memory *memory, size_t page_count);
0209 void agp_generic_destroy_page(struct page *page, int flags);
0210 void agp_generic_destroy_pages(struct agp_memory *memory);
0211 void agp_free_key(int key);
0212 int agp_num_entries(void);
0213 u32 agp_collect_device_status(struct agp_bridge_data *bridge, u32 mode, u32 command);
0214 void agp_device_command(u32 command, bool agp_v3);
0215 int agp_3_5_enable(struct agp_bridge_data *bridge);
0216 void global_cache_flush(void);
0217 void get_agp_version(struct agp_bridge_data *bridge);
0218 unsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge,
0219 dma_addr_t phys, int type);
0220 int agp_generic_type_to_mask_type(struct agp_bridge_data *bridge,
0221 int type);
0222 struct agp_bridge_data *agp_generic_find_bridge(struct pci_dev *pdev);
0223
0224
0225 struct agp_memory *agp_generic_alloc_user(size_t page_count, int type);
0226 void agp_alloc_page_array(size_t size, struct agp_memory *mem);
0227 static inline void agp_free_page_array(struct agp_memory *mem)
0228 {
0229 kvfree(mem->pages);
0230 }
0231
0232
0233
0234 int agp3_generic_fetch_size(void);
0235 void agp3_generic_tlbflush(struct agp_memory *mem);
0236 int agp3_generic_configure(void);
0237 void agp3_generic_cleanup(void);
0238
0239
0240 #define AGP_GENERIC_SIZES_ENTRIES 11
0241 extern const struct aper_size_info_16 agp3_generic_sizes[];
0242
0243 extern int agp_off;
0244 extern int agp_try_unsupported_boot;
0245
0246 long compat_agp_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
0247
0248
0249 #define AGP_APBASE 0x10
0250 #define AGP_APERTURE_BAR 0
0251
0252 #define AGPSTAT 0x4
0253 #define AGPCMD 0x8
0254 #define AGPNISTAT 0xc
0255 #define AGPCTRL 0x10
0256 #define AGPAPSIZE 0x14
0257 #define AGPNEPG 0x16
0258 #define AGPGARTLO 0x18
0259 #define AGPGARTHI 0x1c
0260 #define AGPNICMD 0x20
0261
0262 #define AGP_MAJOR_VERSION_SHIFT (20)
0263 #define AGP_MINOR_VERSION_SHIFT (16)
0264
0265 #define AGPSTAT_RQ_DEPTH (0xff000000)
0266 #define AGPSTAT_RQ_DEPTH_SHIFT 24
0267
0268 #define AGPSTAT_CAL_MASK (1<<12|1<<11|1<<10)
0269 #define AGPSTAT_ARQSZ (1<<15|1<<14|1<<13)
0270 #define AGPSTAT_ARQSZ_SHIFT 13
0271
0272 #define AGPSTAT_SBA (1<<9)
0273 #define AGPSTAT_AGP_ENABLE (1<<8)
0274 #define AGPSTAT_FW (1<<4)
0275 #define AGPSTAT_MODE_3_0 (1<<3)
0276
0277 #define AGPSTAT2_1X (1<<0)
0278 #define AGPSTAT2_2X (1<<1)
0279 #define AGPSTAT2_4X (1<<2)
0280
0281 #define AGPSTAT3_RSVD (1<<2)
0282 #define AGPSTAT3_8X (1<<1)
0283 #define AGPSTAT3_4X (1)
0284
0285 #define AGPCTRL_APERENB (1<<8)
0286 #define AGPCTRL_GTLBEN (1<<7)
0287
0288 #define AGP2_RESERVED_MASK 0x00fffcc8
0289 #define AGP3_RESERVED_MASK 0x00ff00c4
0290
0291 #define AGP_ERRATA_FASTWRITES 1<<0
0292 #define AGP_ERRATA_SBA 1<<1
0293 #define AGP_ERRATA_1X 1<<2
0294
0295 #endif