xref: /kernel/linux/linux-5.10/drivers/char/agp/agp.h (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * AGPGART
38c2ecf20Sopenharmony_ci * Copyright (C) 2004 Silicon Graphics, Inc.
48c2ecf20Sopenharmony_ci * Copyright (C) 2002-2004 Dave Jones
58c2ecf20Sopenharmony_ci * Copyright (C) 1999 Jeff Hartmann
68c2ecf20Sopenharmony_ci * Copyright (C) 1999 Precision Insight, Inc.
78c2ecf20Sopenharmony_ci * Copyright (C) 1999 Xi Graphics, Inc.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
108c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
118c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
128c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
138c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
148c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
158c2ecf20Sopenharmony_ci *
168c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included
178c2ecf20Sopenharmony_ci * in all copies or substantial portions of the Software.
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
208c2ecf20Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
218c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
228c2ecf20Sopenharmony_ci * JEFF HARTMANN, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
238c2ecf20Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
248c2ecf20Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
258c2ecf20Sopenharmony_ci * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#ifndef _AGP_BACKEND_PRIV_H
308c2ecf20Sopenharmony_ci#define _AGP_BACKEND_PRIV_H 1
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#include <asm/agp.h>	/* for flush_agp_cache() */
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define PFX "agpgart: "
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci//#define AGP_DEBUG 1
378c2ecf20Sopenharmony_ci#ifdef AGP_DEBUG
388c2ecf20Sopenharmony_ci#define DBG(x,y...) printk (KERN_DEBUG PFX "%s: " x "\n", __func__ , ## y)
398c2ecf20Sopenharmony_ci#else
408c2ecf20Sopenharmony_ci#define DBG(x,y...) do { } while (0)
418c2ecf20Sopenharmony_ci#endif
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciextern struct agp_bridge_data *agp_bridge;
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cienum aper_size_type {
468c2ecf20Sopenharmony_ci	U8_APER_SIZE,
478c2ecf20Sopenharmony_ci	U16_APER_SIZE,
488c2ecf20Sopenharmony_ci	U32_APER_SIZE,
498c2ecf20Sopenharmony_ci	LVL2_APER_SIZE,
508c2ecf20Sopenharmony_ci	FIXED_APER_SIZE
518c2ecf20Sopenharmony_ci};
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistruct gatt_mask {
548c2ecf20Sopenharmony_ci	unsigned long mask;
558c2ecf20Sopenharmony_ci	u32 type;
568c2ecf20Sopenharmony_ci	/* totally device specific, for integrated chipsets that
578c2ecf20Sopenharmony_ci	 * might have different types of memory masks.  For other
588c2ecf20Sopenharmony_ci	 * devices this will probably be ignored */
598c2ecf20Sopenharmony_ci};
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci#define AGP_PAGE_DESTROY_UNMAP 1
628c2ecf20Sopenharmony_ci#define AGP_PAGE_DESTROY_FREE 2
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistruct aper_size_info_8 {
658c2ecf20Sopenharmony_ci	int size;
668c2ecf20Sopenharmony_ci	int num_entries;
678c2ecf20Sopenharmony_ci	int page_order;
688c2ecf20Sopenharmony_ci	u8 size_value;
698c2ecf20Sopenharmony_ci};
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_cistruct aper_size_info_16 {
728c2ecf20Sopenharmony_ci	int size;
738c2ecf20Sopenharmony_ci	int num_entries;
748c2ecf20Sopenharmony_ci	int page_order;
758c2ecf20Sopenharmony_ci	u16 size_value;
768c2ecf20Sopenharmony_ci};
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_cistruct aper_size_info_32 {
798c2ecf20Sopenharmony_ci	int size;
808c2ecf20Sopenharmony_ci	int num_entries;
818c2ecf20Sopenharmony_ci	int page_order;
828c2ecf20Sopenharmony_ci	u32 size_value;
838c2ecf20Sopenharmony_ci};
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistruct aper_size_info_lvl2 {
868c2ecf20Sopenharmony_ci	int size;
878c2ecf20Sopenharmony_ci	int num_entries;
888c2ecf20Sopenharmony_ci	u32 size_value;
898c2ecf20Sopenharmony_ci};
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_cistruct aper_size_info_fixed {
928c2ecf20Sopenharmony_ci	int size;
938c2ecf20Sopenharmony_ci	int num_entries;
948c2ecf20Sopenharmony_ci	int page_order;
958c2ecf20Sopenharmony_ci};
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_cistruct agp_bridge_driver {
988c2ecf20Sopenharmony_ci	struct module *owner;
998c2ecf20Sopenharmony_ci	const void *aperture_sizes;
1008c2ecf20Sopenharmony_ci	int num_aperture_sizes;
1018c2ecf20Sopenharmony_ci	enum aper_size_type size_type;
1028c2ecf20Sopenharmony_ci	bool cant_use_aperture;
1038c2ecf20Sopenharmony_ci	bool needs_scratch_page;
1048c2ecf20Sopenharmony_ci	const struct gatt_mask *masks;
1058c2ecf20Sopenharmony_ci	int (*fetch_size)(void);
1068c2ecf20Sopenharmony_ci	int (*configure)(void);
1078c2ecf20Sopenharmony_ci	void (*agp_enable)(struct agp_bridge_data *, u32);
1088c2ecf20Sopenharmony_ci	void (*cleanup)(void);
1098c2ecf20Sopenharmony_ci	void (*tlb_flush)(struct agp_memory *);
1108c2ecf20Sopenharmony_ci	unsigned long (*mask_memory)(struct agp_bridge_data *, dma_addr_t, int);
1118c2ecf20Sopenharmony_ci	void (*cache_flush)(void);
1128c2ecf20Sopenharmony_ci	int (*create_gatt_table)(struct agp_bridge_data *);
1138c2ecf20Sopenharmony_ci	int (*free_gatt_table)(struct agp_bridge_data *);
1148c2ecf20Sopenharmony_ci	int (*insert_memory)(struct agp_memory *, off_t, int);
1158c2ecf20Sopenharmony_ci	int (*remove_memory)(struct agp_memory *, off_t, int);
1168c2ecf20Sopenharmony_ci	struct agp_memory *(*alloc_by_type) (size_t, int);
1178c2ecf20Sopenharmony_ci	void (*free_by_type)(struct agp_memory *);
1188c2ecf20Sopenharmony_ci	struct page *(*agp_alloc_page)(struct agp_bridge_data *);
1198c2ecf20Sopenharmony_ci	int (*agp_alloc_pages)(struct agp_bridge_data *, struct agp_memory *, size_t);
1208c2ecf20Sopenharmony_ci	void (*agp_destroy_page)(struct page *, int flags);
1218c2ecf20Sopenharmony_ci	void (*agp_destroy_pages)(struct agp_memory *);
1228c2ecf20Sopenharmony_ci	int (*agp_type_to_mask_type) (struct agp_bridge_data *, int);
1238c2ecf20Sopenharmony_ci};
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_cistruct agp_bridge_data {
1268c2ecf20Sopenharmony_ci	const struct agp_version *version;
1278c2ecf20Sopenharmony_ci	const struct agp_bridge_driver *driver;
1288c2ecf20Sopenharmony_ci	const struct vm_operations_struct *vm_ops;
1298c2ecf20Sopenharmony_ci	void *previous_size;
1308c2ecf20Sopenharmony_ci	void *current_size;
1318c2ecf20Sopenharmony_ci	void *dev_private_data;
1328c2ecf20Sopenharmony_ci	struct pci_dev *dev;
1338c2ecf20Sopenharmony_ci	u32 __iomem *gatt_table;
1348c2ecf20Sopenharmony_ci	u32 *gatt_table_real;
1358c2ecf20Sopenharmony_ci	unsigned long scratch_page;
1368c2ecf20Sopenharmony_ci	struct page *scratch_page_page;
1378c2ecf20Sopenharmony_ci	dma_addr_t scratch_page_dma;
1388c2ecf20Sopenharmony_ci	unsigned long gart_bus_addr;
1398c2ecf20Sopenharmony_ci	unsigned long gatt_bus_addr;
1408c2ecf20Sopenharmony_ci	u32 mode;
1418c2ecf20Sopenharmony_ci	enum chipset_type type;
1428c2ecf20Sopenharmony_ci	unsigned long *key_list;
1438c2ecf20Sopenharmony_ci	atomic_t current_memory_agp;
1448c2ecf20Sopenharmony_ci	atomic_t agp_in_use;
1458c2ecf20Sopenharmony_ci	int max_memory_agp;	/* in number of pages */
1468c2ecf20Sopenharmony_ci	int aperture_size_idx;
1478c2ecf20Sopenharmony_ci	int capndx;
1488c2ecf20Sopenharmony_ci	int flags;
1498c2ecf20Sopenharmony_ci	char major_version;
1508c2ecf20Sopenharmony_ci	char minor_version;
1518c2ecf20Sopenharmony_ci	struct list_head list;
1528c2ecf20Sopenharmony_ci	u32 apbase_config;
1538c2ecf20Sopenharmony_ci	/* list of agp_memory mapped to the aperture */
1548c2ecf20Sopenharmony_ci	struct list_head mapped_list;
1558c2ecf20Sopenharmony_ci	spinlock_t mapped_lock;
1568c2ecf20Sopenharmony_ci};
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci#define KB(x)	((x) * 1024)
1598c2ecf20Sopenharmony_ci#define MB(x)	(KB (KB (x)))
1608c2ecf20Sopenharmony_ci#define GB(x)	(MB (KB (x)))
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci#define A_SIZE_8(x)	((struct aper_size_info_8 *) x)
1638c2ecf20Sopenharmony_ci#define A_SIZE_16(x)	((struct aper_size_info_16 *) x)
1648c2ecf20Sopenharmony_ci#define A_SIZE_32(x)	((struct aper_size_info_32 *) x)
1658c2ecf20Sopenharmony_ci#define A_SIZE_LVL2(x)	((struct aper_size_info_lvl2 *) x)
1668c2ecf20Sopenharmony_ci#define A_SIZE_FIX(x)	((struct aper_size_info_fixed *) x)
1678c2ecf20Sopenharmony_ci#define A_IDX8(bridge)	(A_SIZE_8((bridge)->driver->aperture_sizes) + i)
1688c2ecf20Sopenharmony_ci#define A_IDX16(bridge)	(A_SIZE_16((bridge)->driver->aperture_sizes) + i)
1698c2ecf20Sopenharmony_ci#define A_IDX32(bridge)	(A_SIZE_32((bridge)->driver->aperture_sizes) + i)
1708c2ecf20Sopenharmony_ci#define MAXKEY		(4096 * 32)
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci#define PGE_EMPTY(b, p)	(!(p) || (p) == (unsigned long) (b)->scratch_page)
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_cistruct agp_device_ids {
1768c2ecf20Sopenharmony_ci	unsigned short device_id; /* first, to make table easier to read */
1778c2ecf20Sopenharmony_ci	enum chipset_type chipset;
1788c2ecf20Sopenharmony_ci	const char *chipset_name;
1798c2ecf20Sopenharmony_ci	int (*chipset_setup) (struct pci_dev *pdev);	/* used to override generic */
1808c2ecf20Sopenharmony_ci};
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci/* Driver registration */
1838c2ecf20Sopenharmony_cistruct agp_bridge_data *agp_alloc_bridge(void);
1848c2ecf20Sopenharmony_civoid agp_put_bridge(struct agp_bridge_data *bridge);
1858c2ecf20Sopenharmony_ciint agp_add_bridge(struct agp_bridge_data *bridge);
1868c2ecf20Sopenharmony_civoid agp_remove_bridge(struct agp_bridge_data *bridge);
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci/* Frontend routines. */
1898c2ecf20Sopenharmony_ciint agp_frontend_initialize(void);
1908c2ecf20Sopenharmony_civoid agp_frontend_cleanup(void);
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci/* Generic routines. */
1938c2ecf20Sopenharmony_civoid agp_generic_enable(struct agp_bridge_data *bridge, u32 mode);
1948c2ecf20Sopenharmony_ciint agp_generic_create_gatt_table(struct agp_bridge_data *bridge);
1958c2ecf20Sopenharmony_ciint agp_generic_free_gatt_table(struct agp_bridge_data *bridge);
1968c2ecf20Sopenharmony_cistruct agp_memory *agp_create_memory(int scratch_pages);
1978c2ecf20Sopenharmony_ciint agp_generic_insert_memory(struct agp_memory *mem, off_t pg_start, int type);
1988c2ecf20Sopenharmony_ciint agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type);
1998c2ecf20Sopenharmony_cistruct agp_memory *agp_generic_alloc_by_type(size_t page_count, int type);
2008c2ecf20Sopenharmony_civoid agp_generic_free_by_type(struct agp_memory *curr);
2018c2ecf20Sopenharmony_cistruct page *agp_generic_alloc_page(struct agp_bridge_data *bridge);
2028c2ecf20Sopenharmony_ciint agp_generic_alloc_pages(struct agp_bridge_data *agp_bridge,
2038c2ecf20Sopenharmony_ci			    struct agp_memory *memory, size_t page_count);
2048c2ecf20Sopenharmony_civoid agp_generic_destroy_page(struct page *page, int flags);
2058c2ecf20Sopenharmony_civoid agp_generic_destroy_pages(struct agp_memory *memory);
2068c2ecf20Sopenharmony_civoid agp_free_key(int key);
2078c2ecf20Sopenharmony_ciint agp_num_entries(void);
2088c2ecf20Sopenharmony_ciu32 agp_collect_device_status(struct agp_bridge_data *bridge, u32 mode, u32 command);
2098c2ecf20Sopenharmony_civoid agp_device_command(u32 command, bool agp_v3);
2108c2ecf20Sopenharmony_ciint agp_3_5_enable(struct agp_bridge_data *bridge);
2118c2ecf20Sopenharmony_civoid global_cache_flush(void);
2128c2ecf20Sopenharmony_civoid get_agp_version(struct agp_bridge_data *bridge);
2138c2ecf20Sopenharmony_ciunsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge,
2148c2ecf20Sopenharmony_ci				      dma_addr_t phys, int type);
2158c2ecf20Sopenharmony_ciint agp_generic_type_to_mask_type(struct agp_bridge_data *bridge,
2168c2ecf20Sopenharmony_ci				  int type);
2178c2ecf20Sopenharmony_cistruct agp_bridge_data *agp_generic_find_bridge(struct pci_dev *pdev);
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci/* generic functions for user-populated AGP memory types */
2208c2ecf20Sopenharmony_cistruct agp_memory *agp_generic_alloc_user(size_t page_count, int type);
2218c2ecf20Sopenharmony_civoid agp_alloc_page_array(size_t size, struct agp_memory *mem);
2228c2ecf20Sopenharmony_cistatic inline void agp_free_page_array(struct agp_memory *mem)
2238c2ecf20Sopenharmony_ci{
2248c2ecf20Sopenharmony_ci	kvfree(mem->pages);
2258c2ecf20Sopenharmony_ci}
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci/* generic routines for agp>=3 */
2298c2ecf20Sopenharmony_ciint agp3_generic_fetch_size(void);
2308c2ecf20Sopenharmony_civoid agp3_generic_tlbflush(struct agp_memory *mem);
2318c2ecf20Sopenharmony_ciint agp3_generic_configure(void);
2328c2ecf20Sopenharmony_civoid agp3_generic_cleanup(void);
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci/* aperture sizes have been standardised since v3 */
2358c2ecf20Sopenharmony_ci#define AGP_GENERIC_SIZES_ENTRIES 11
2368c2ecf20Sopenharmony_ciextern const struct aper_size_info_16 agp3_generic_sizes[];
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ciextern int agp_off;
2398c2ecf20Sopenharmony_ciextern int agp_try_unsupported_boot;
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_cilong compat_agp_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci/* Chipset independent registers (from AGP Spec) */
2448c2ecf20Sopenharmony_ci#define AGP_APBASE	0x10
2458c2ecf20Sopenharmony_ci#define AGP_APERTURE_BAR	0
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci#define AGPSTAT		0x4
2488c2ecf20Sopenharmony_ci#define AGPCMD		0x8
2498c2ecf20Sopenharmony_ci#define AGPNISTAT	0xc
2508c2ecf20Sopenharmony_ci#define AGPCTRL		0x10
2518c2ecf20Sopenharmony_ci#define AGPAPSIZE	0x14
2528c2ecf20Sopenharmony_ci#define AGPNEPG		0x16
2538c2ecf20Sopenharmony_ci#define AGPGARTLO	0x18
2548c2ecf20Sopenharmony_ci#define AGPGARTHI	0x1c
2558c2ecf20Sopenharmony_ci#define AGPNICMD	0x20
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci#define AGP_MAJOR_VERSION_SHIFT	(20)
2588c2ecf20Sopenharmony_ci#define AGP_MINOR_VERSION_SHIFT	(16)
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci#define AGPSTAT_RQ_DEPTH	(0xff000000)
2618c2ecf20Sopenharmony_ci#define AGPSTAT_RQ_DEPTH_SHIFT	24
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci#define AGPSTAT_CAL_MASK	(1<<12|1<<11|1<<10)
2648c2ecf20Sopenharmony_ci#define AGPSTAT_ARQSZ		(1<<15|1<<14|1<<13)
2658c2ecf20Sopenharmony_ci#define AGPSTAT_ARQSZ_SHIFT	13
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci#define AGPSTAT_SBA		(1<<9)
2688c2ecf20Sopenharmony_ci#define AGPSTAT_AGP_ENABLE	(1<<8)
2698c2ecf20Sopenharmony_ci#define AGPSTAT_FW		(1<<4)
2708c2ecf20Sopenharmony_ci#define AGPSTAT_MODE_3_0	(1<<3)
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci#define AGPSTAT2_1X		(1<<0)
2738c2ecf20Sopenharmony_ci#define AGPSTAT2_2X		(1<<1)
2748c2ecf20Sopenharmony_ci#define AGPSTAT2_4X		(1<<2)
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci#define AGPSTAT3_RSVD		(1<<2)
2778c2ecf20Sopenharmony_ci#define AGPSTAT3_8X		(1<<1)
2788c2ecf20Sopenharmony_ci#define AGPSTAT3_4X		(1)
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci#define AGPCTRL_APERENB		(1<<8)
2818c2ecf20Sopenharmony_ci#define AGPCTRL_GTLBEN		(1<<7)
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci#define AGP2_RESERVED_MASK 0x00fffcc8
2848c2ecf20Sopenharmony_ci#define AGP3_RESERVED_MASK 0x00ff00c4
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci#define AGP_ERRATA_FASTWRITES 1<<0
2878c2ecf20Sopenharmony_ci#define AGP_ERRATA_SBA	 1<<1
2888c2ecf20Sopenharmony_ci#define AGP_ERRATA_1X 1<<2
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci#endif	/* _AGP_BACKEND_PRIV_H */
291