162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * AGPGART 362306a36Sopenharmony_ci * Copyright (C) 2004 Silicon Graphics, Inc. 462306a36Sopenharmony_ci * Copyright (C) 2002-2004 Dave Jones 562306a36Sopenharmony_ci * Copyright (C) 1999 Jeff Hartmann 662306a36Sopenharmony_ci * Copyright (C) 1999 Precision Insight, Inc. 762306a36Sopenharmony_ci * Copyright (C) 1999 Xi Graphics, Inc. 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 1062306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 1162306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation 1262306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 1362306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 1462306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 1562306a36Sopenharmony_ci * 1662306a36Sopenharmony_ci * The above copyright notice and this permission notice shall be included 1762306a36Sopenharmony_ci * in all copies or substantial portions of the Software. 1862306a36Sopenharmony_ci * 1962306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 2062306a36Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2162306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 2262306a36Sopenharmony_ci * JEFF HARTMANN, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM, 2362306a36Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 2462306a36Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 2562306a36Sopenharmony_ci * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2662306a36Sopenharmony_ci * 2762306a36Sopenharmony_ci */ 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci#ifndef _AGP_BACKEND_PRIV_H 3062306a36Sopenharmony_ci#define _AGP_BACKEND_PRIV_H 1 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci#include <asm/agp.h> /* for flush_agp_cache() */ 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#define PFX "agpgart: " 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci//#define AGP_DEBUG 1 3762306a36Sopenharmony_ci#ifdef AGP_DEBUG 3862306a36Sopenharmony_ci#define DBG(x,y...) printk (KERN_DEBUG PFX "%s: " x "\n", __func__ , ## y) 3962306a36Sopenharmony_ci#else 4062306a36Sopenharmony_ci#define DBG(x,y...) do { } while (0) 4162306a36Sopenharmony_ci#endif 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ciextern struct agp_bridge_data *agp_bridge; 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_cienum aper_size_type { 4662306a36Sopenharmony_ci U8_APER_SIZE, 4762306a36Sopenharmony_ci U16_APER_SIZE, 4862306a36Sopenharmony_ci U32_APER_SIZE, 4962306a36Sopenharmony_ci LVL2_APER_SIZE, 5062306a36Sopenharmony_ci FIXED_APER_SIZE 5162306a36Sopenharmony_ci}; 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_cistruct gatt_mask { 5462306a36Sopenharmony_ci unsigned long mask; 5562306a36Sopenharmony_ci u32 type; 5662306a36Sopenharmony_ci /* totally device specific, for integrated chipsets that 5762306a36Sopenharmony_ci * might have different types of memory masks. For other 5862306a36Sopenharmony_ci * devices this will probably be ignored */ 5962306a36Sopenharmony_ci}; 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci#define AGP_PAGE_DESTROY_UNMAP 1 6262306a36Sopenharmony_ci#define AGP_PAGE_DESTROY_FREE 2 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_cistruct aper_size_info_8 { 6562306a36Sopenharmony_ci int size; 6662306a36Sopenharmony_ci int num_entries; 6762306a36Sopenharmony_ci int page_order; 6862306a36Sopenharmony_ci u8 size_value; 6962306a36Sopenharmony_ci}; 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_cistruct aper_size_info_16 { 7262306a36Sopenharmony_ci int size; 7362306a36Sopenharmony_ci int num_entries; 7462306a36Sopenharmony_ci int page_order; 7562306a36Sopenharmony_ci u16 size_value; 7662306a36Sopenharmony_ci}; 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_cistruct aper_size_info_32 { 7962306a36Sopenharmony_ci int size; 8062306a36Sopenharmony_ci int num_entries; 8162306a36Sopenharmony_ci int page_order; 8262306a36Sopenharmony_ci u32 size_value; 8362306a36Sopenharmony_ci}; 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_cistruct aper_size_info_lvl2 { 8662306a36Sopenharmony_ci int size; 8762306a36Sopenharmony_ci int num_entries; 8862306a36Sopenharmony_ci u32 size_value; 8962306a36Sopenharmony_ci}; 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_cistruct aper_size_info_fixed { 9262306a36Sopenharmony_ci int size; 9362306a36Sopenharmony_ci int num_entries; 9462306a36Sopenharmony_ci int page_order; 9562306a36Sopenharmony_ci}; 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_cistruct agp_bridge_driver { 9862306a36Sopenharmony_ci struct module *owner; 9962306a36Sopenharmony_ci const void *aperture_sizes; 10062306a36Sopenharmony_ci int num_aperture_sizes; 10162306a36Sopenharmony_ci enum aper_size_type size_type; 10262306a36Sopenharmony_ci bool cant_use_aperture; 10362306a36Sopenharmony_ci bool needs_scratch_page; 10462306a36Sopenharmony_ci const struct gatt_mask *masks; 10562306a36Sopenharmony_ci int (*fetch_size)(void); 10662306a36Sopenharmony_ci int (*configure)(void); 10762306a36Sopenharmony_ci void (*agp_enable)(struct agp_bridge_data *, u32); 10862306a36Sopenharmony_ci void (*cleanup)(void); 10962306a36Sopenharmony_ci void (*tlb_flush)(struct agp_memory *); 11062306a36Sopenharmony_ci unsigned long (*mask_memory)(struct agp_bridge_data *, dma_addr_t, int); 11162306a36Sopenharmony_ci void (*cache_flush)(void); 11262306a36Sopenharmony_ci int (*create_gatt_table)(struct agp_bridge_data *); 11362306a36Sopenharmony_ci int (*free_gatt_table)(struct agp_bridge_data *); 11462306a36Sopenharmony_ci int (*insert_memory)(struct agp_memory *, off_t, int); 11562306a36Sopenharmony_ci int (*remove_memory)(struct agp_memory *, off_t, int); 11662306a36Sopenharmony_ci struct agp_memory *(*alloc_by_type) (size_t, int); 11762306a36Sopenharmony_ci void (*free_by_type)(struct agp_memory *); 11862306a36Sopenharmony_ci struct page *(*agp_alloc_page)(struct agp_bridge_data *); 11962306a36Sopenharmony_ci int (*agp_alloc_pages)(struct agp_bridge_data *, struct agp_memory *, size_t); 12062306a36Sopenharmony_ci void (*agp_destroy_page)(struct page *, int flags); 12162306a36Sopenharmony_ci void (*agp_destroy_pages)(struct agp_memory *); 12262306a36Sopenharmony_ci int (*agp_type_to_mask_type) (struct agp_bridge_data *, int); 12362306a36Sopenharmony_ci}; 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_cistruct agp_bridge_data { 12662306a36Sopenharmony_ci const struct agp_version *version; 12762306a36Sopenharmony_ci const struct agp_bridge_driver *driver; 12862306a36Sopenharmony_ci const struct vm_operations_struct *vm_ops; 12962306a36Sopenharmony_ci void *previous_size; 13062306a36Sopenharmony_ci void *current_size; 13162306a36Sopenharmony_ci void *dev_private_data; 13262306a36Sopenharmony_ci struct pci_dev *dev; 13362306a36Sopenharmony_ci u32 __iomem *gatt_table; 13462306a36Sopenharmony_ci u32 *gatt_table_real; 13562306a36Sopenharmony_ci unsigned long scratch_page; 13662306a36Sopenharmony_ci struct page *scratch_page_page; 13762306a36Sopenharmony_ci dma_addr_t scratch_page_dma; 13862306a36Sopenharmony_ci unsigned long gart_bus_addr; 13962306a36Sopenharmony_ci unsigned long gatt_bus_addr; 14062306a36Sopenharmony_ci u32 mode; 14162306a36Sopenharmony_ci enum chipset_type type; 14262306a36Sopenharmony_ci unsigned long *key_list; 14362306a36Sopenharmony_ci atomic_t current_memory_agp; 14462306a36Sopenharmony_ci atomic_t agp_in_use; 14562306a36Sopenharmony_ci int max_memory_agp; /* in number of pages */ 14662306a36Sopenharmony_ci int aperture_size_idx; 14762306a36Sopenharmony_ci int capndx; 14862306a36Sopenharmony_ci int flags; 14962306a36Sopenharmony_ci char major_version; 15062306a36Sopenharmony_ci char minor_version; 15162306a36Sopenharmony_ci struct list_head list; 15262306a36Sopenharmony_ci u32 apbase_config; 15362306a36Sopenharmony_ci /* list of agp_memory mapped to the aperture */ 15462306a36Sopenharmony_ci struct list_head mapped_list; 15562306a36Sopenharmony_ci spinlock_t mapped_lock; 15662306a36Sopenharmony_ci}; 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ci#define KB(x) ((x) * 1024) 15962306a36Sopenharmony_ci#define MB(x) (KB (KB (x))) 16062306a36Sopenharmony_ci#define GB(x) (MB (KB (x))) 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci#define A_SIZE_8(x) ((struct aper_size_info_8 *) x) 16362306a36Sopenharmony_ci#define A_SIZE_16(x) ((struct aper_size_info_16 *) x) 16462306a36Sopenharmony_ci#define A_SIZE_32(x) ((struct aper_size_info_32 *) x) 16562306a36Sopenharmony_ci#define A_SIZE_LVL2(x) ((struct aper_size_info_lvl2 *) x) 16662306a36Sopenharmony_ci#define A_SIZE_FIX(x) ((struct aper_size_info_fixed *) x) 16762306a36Sopenharmony_ci#define A_IDX8(bridge) (A_SIZE_8((bridge)->driver->aperture_sizes) + i) 16862306a36Sopenharmony_ci#define A_IDX16(bridge) (A_SIZE_16((bridge)->driver->aperture_sizes) + i) 16962306a36Sopenharmony_ci#define A_IDX32(bridge) (A_SIZE_32((bridge)->driver->aperture_sizes) + i) 17062306a36Sopenharmony_ci#define MAXKEY (4096 * 32) 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_ci#define PGE_EMPTY(b, p) (!(p) || (p) == (unsigned long) (b)->scratch_page) 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_cistruct agp_device_ids { 17662306a36Sopenharmony_ci unsigned short device_id; /* first, to make table easier to read */ 17762306a36Sopenharmony_ci enum chipset_type chipset; 17862306a36Sopenharmony_ci const char *chipset_name; 17962306a36Sopenharmony_ci int (*chipset_setup) (struct pci_dev *pdev); /* used to override generic */ 18062306a36Sopenharmony_ci}; 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci/* Driver registration */ 18362306a36Sopenharmony_cistruct agp_bridge_data *agp_alloc_bridge(void); 18462306a36Sopenharmony_civoid agp_put_bridge(struct agp_bridge_data *bridge); 18562306a36Sopenharmony_ciint agp_add_bridge(struct agp_bridge_data *bridge); 18662306a36Sopenharmony_civoid agp_remove_bridge(struct agp_bridge_data *bridge); 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci/* Frontend routines. */ 18962306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY) 19062306a36Sopenharmony_ciint agp_frontend_initialize(void); 19162306a36Sopenharmony_civoid agp_frontend_cleanup(void); 19262306a36Sopenharmony_ci#else 19362306a36Sopenharmony_cistatic inline int agp_frontend_initialize(void) { return 0; } 19462306a36Sopenharmony_cistatic inline void agp_frontend_cleanup(void) {} 19562306a36Sopenharmony_ci#endif 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ci/* Generic routines. */ 19862306a36Sopenharmony_civoid agp_generic_enable(struct agp_bridge_data *bridge, u32 mode); 19962306a36Sopenharmony_ciint agp_generic_create_gatt_table(struct agp_bridge_data *bridge); 20062306a36Sopenharmony_ciint agp_generic_free_gatt_table(struct agp_bridge_data *bridge); 20162306a36Sopenharmony_cistruct agp_memory *agp_create_memory(int scratch_pages); 20262306a36Sopenharmony_ciint agp_generic_insert_memory(struct agp_memory *mem, off_t pg_start, int type); 20362306a36Sopenharmony_ciint agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type); 20462306a36Sopenharmony_cistruct agp_memory *agp_generic_alloc_by_type(size_t page_count, int type); 20562306a36Sopenharmony_civoid agp_generic_free_by_type(struct agp_memory *curr); 20662306a36Sopenharmony_cistruct page *agp_generic_alloc_page(struct agp_bridge_data *bridge); 20762306a36Sopenharmony_ciint agp_generic_alloc_pages(struct agp_bridge_data *agp_bridge, 20862306a36Sopenharmony_ci struct agp_memory *memory, size_t page_count); 20962306a36Sopenharmony_civoid agp_generic_destroy_page(struct page *page, int flags); 21062306a36Sopenharmony_civoid agp_generic_destroy_pages(struct agp_memory *memory); 21162306a36Sopenharmony_civoid agp_free_key(int key); 21262306a36Sopenharmony_ciint agp_num_entries(void); 21362306a36Sopenharmony_ciu32 agp_collect_device_status(struct agp_bridge_data *bridge, u32 mode, u32 command); 21462306a36Sopenharmony_civoid agp_device_command(u32 command, bool agp_v3); 21562306a36Sopenharmony_ciint agp_3_5_enable(struct agp_bridge_data *bridge); 21662306a36Sopenharmony_civoid global_cache_flush(void); 21762306a36Sopenharmony_civoid get_agp_version(struct agp_bridge_data *bridge); 21862306a36Sopenharmony_ciunsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge, 21962306a36Sopenharmony_ci dma_addr_t phys, int type); 22062306a36Sopenharmony_ciint agp_generic_type_to_mask_type(struct agp_bridge_data *bridge, 22162306a36Sopenharmony_ci int type); 22262306a36Sopenharmony_cistruct agp_bridge_data *agp_generic_find_bridge(struct pci_dev *pdev); 22362306a36Sopenharmony_ci 22462306a36Sopenharmony_ci/* generic functions for user-populated AGP memory types */ 22562306a36Sopenharmony_cistruct agp_memory *agp_generic_alloc_user(size_t page_count, int type); 22662306a36Sopenharmony_civoid agp_alloc_page_array(size_t size, struct agp_memory *mem); 22762306a36Sopenharmony_cistatic inline void agp_free_page_array(struct agp_memory *mem) 22862306a36Sopenharmony_ci{ 22962306a36Sopenharmony_ci kvfree(mem->pages); 23062306a36Sopenharmony_ci} 23162306a36Sopenharmony_ci 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ci/* generic routines for agp>=3 */ 23462306a36Sopenharmony_ciint agp3_generic_fetch_size(void); 23562306a36Sopenharmony_civoid agp3_generic_tlbflush(struct agp_memory *mem); 23662306a36Sopenharmony_ciint agp3_generic_configure(void); 23762306a36Sopenharmony_civoid agp3_generic_cleanup(void); 23862306a36Sopenharmony_ci 23962306a36Sopenharmony_ci/* GATT allocation. Returns/accepts GATT kernel virtual address. */ 24062306a36Sopenharmony_ci#define alloc_gatt_pages(order) \ 24162306a36Sopenharmony_ci ((char *)__get_free_pages(GFP_KERNEL, (order))) 24262306a36Sopenharmony_ci#define free_gatt_pages(table, order) \ 24362306a36Sopenharmony_ci free_pages((unsigned long)(table), (order)) 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_ci/* aperture sizes have been standardised since v3 */ 24662306a36Sopenharmony_ci#define AGP_GENERIC_SIZES_ENTRIES 11 24762306a36Sopenharmony_ciextern const struct aper_size_info_16 agp3_generic_sizes[]; 24862306a36Sopenharmony_ci 24962306a36Sopenharmony_ciextern int agp_off; 25062306a36Sopenharmony_ciextern int agp_try_unsupported_boot; 25162306a36Sopenharmony_ci 25262306a36Sopenharmony_cilong compat_agp_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ci/* Chipset independent registers (from AGP Spec) */ 25562306a36Sopenharmony_ci#define AGP_APBASE 0x10 25662306a36Sopenharmony_ci#define AGP_APERTURE_BAR 0 25762306a36Sopenharmony_ci 25862306a36Sopenharmony_ci#define AGPSTAT 0x4 25962306a36Sopenharmony_ci#define AGPCMD 0x8 26062306a36Sopenharmony_ci#define AGPNISTAT 0xc 26162306a36Sopenharmony_ci#define AGPCTRL 0x10 26262306a36Sopenharmony_ci#define AGPAPSIZE 0x14 26362306a36Sopenharmony_ci#define AGPNEPG 0x16 26462306a36Sopenharmony_ci#define AGPGARTLO 0x18 26562306a36Sopenharmony_ci#define AGPGARTHI 0x1c 26662306a36Sopenharmony_ci#define AGPNICMD 0x20 26762306a36Sopenharmony_ci 26862306a36Sopenharmony_ci#define AGP_MAJOR_VERSION_SHIFT (20) 26962306a36Sopenharmony_ci#define AGP_MINOR_VERSION_SHIFT (16) 27062306a36Sopenharmony_ci 27162306a36Sopenharmony_ci#define AGPSTAT_RQ_DEPTH (0xff000000) 27262306a36Sopenharmony_ci#define AGPSTAT_RQ_DEPTH_SHIFT 24 27362306a36Sopenharmony_ci 27462306a36Sopenharmony_ci#define AGPSTAT_CAL_MASK (1<<12|1<<11|1<<10) 27562306a36Sopenharmony_ci#define AGPSTAT_ARQSZ (1<<15|1<<14|1<<13) 27662306a36Sopenharmony_ci#define AGPSTAT_ARQSZ_SHIFT 13 27762306a36Sopenharmony_ci 27862306a36Sopenharmony_ci#define AGPSTAT_SBA (1<<9) 27962306a36Sopenharmony_ci#define AGPSTAT_AGP_ENABLE (1<<8) 28062306a36Sopenharmony_ci#define AGPSTAT_FW (1<<4) 28162306a36Sopenharmony_ci#define AGPSTAT_MODE_3_0 (1<<3) 28262306a36Sopenharmony_ci 28362306a36Sopenharmony_ci#define AGPSTAT2_1X (1<<0) 28462306a36Sopenharmony_ci#define AGPSTAT2_2X (1<<1) 28562306a36Sopenharmony_ci#define AGPSTAT2_4X (1<<2) 28662306a36Sopenharmony_ci 28762306a36Sopenharmony_ci#define AGPSTAT3_RSVD (1<<2) 28862306a36Sopenharmony_ci#define AGPSTAT3_8X (1<<1) 28962306a36Sopenharmony_ci#define AGPSTAT3_4X (1) 29062306a36Sopenharmony_ci 29162306a36Sopenharmony_ci#define AGPCTRL_APERENB (1<<8) 29262306a36Sopenharmony_ci#define AGPCTRL_GTLBEN (1<<7) 29362306a36Sopenharmony_ci 29462306a36Sopenharmony_ci#define AGP2_RESERVED_MASK 0x00fffcc8 29562306a36Sopenharmony_ci#define AGP3_RESERVED_MASK 0x00ff00c4 29662306a36Sopenharmony_ci 29762306a36Sopenharmony_ci#define AGP_ERRATA_FASTWRITES 1<<0 29862306a36Sopenharmony_ci#define AGP_ERRATA_SBA 1<<1 29962306a36Sopenharmony_ci#define AGP_ERRATA_1X 1<<2 30062306a36Sopenharmony_ci 30162306a36Sopenharmony_ci#endif /* _AGP_BACKEND_PRIV_H */ 302