xref: /onnv-gate/usr/src/uts/common/sys/agp/agpgart_impl.h (revision 11260:eb8c6f2097e8)
10Sstevel@tonic-gate /*
2*11260SMiao.Chen@Sun.COM  * Copyright (c) 2009, Intel Corporation.
3*11260SMiao.Chen@Sun.COM  * All Rights Reserved.
4*11260SMiao.Chen@Sun.COM  */
5*11260SMiao.Chen@Sun.COM 
6*11260SMiao.Chen@Sun.COM /*
7*11260SMiao.Chen@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
80Sstevel@tonic-gate  * Use is subject to license terms.
90Sstevel@tonic-gate  */
100Sstevel@tonic-gate 
110Sstevel@tonic-gate #ifndef	_SYS_AGPGART_IMPL_H
120Sstevel@tonic-gate #define	_SYS_AGPGART_IMPL_H
130Sstevel@tonic-gate 
140Sstevel@tonic-gate #ifdef __cplusplus
150Sstevel@tonic-gate extern "C" {
160Sstevel@tonic-gate #endif
170Sstevel@tonic-gate 
180Sstevel@tonic-gate 
190Sstevel@tonic-gate #ifdef _KERNEL
200Sstevel@tonic-gate 
210Sstevel@tonic-gate #define	AGPGART_MAX_INSTANCES	1
220Sstevel@tonic-gate #define	AGP_MAXKEYS		256
230Sstevel@tonic-gate #define	AGPGART_DEVNODE		"agpgart"
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*
260Sstevel@tonic-gate  * The values of type agp_arc_type_t are used as indexes into arc_name
270Sstevel@tonic-gate  * in agp_kstat.c.
280Sstevel@tonic-gate  * So if agp_arc_type_t's values are changed in the future, the content
290Sstevel@tonic-gate  * of arc_name must be changed accordingly.
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate enum agp_arc_type {
320Sstevel@tonic-gate 	ARC_IGD810 = 0,
330Sstevel@tonic-gate 	ARC_IGD830 = 1,
340Sstevel@tonic-gate 	ARC_INTELAGP = 2,
350Sstevel@tonic-gate 	ARC_AMD64AGP = 3,
360Sstevel@tonic-gate 	ARC_UNKNOWN = 5
370Sstevel@tonic-gate };
380Sstevel@tonic-gate typedef enum agp_arc_type agp_arc_type_t;
390Sstevel@tonic-gate 
400Sstevel@tonic-gate /* linked list structure of multiple agp gart devices access handles */
410Sstevel@tonic-gate typedef struct	amd64_gart_dev_list {
420Sstevel@tonic-gate 	ldi_handle_t			gart_devhdl;
430Sstevel@tonic-gate 	struct	amd64_gart_dev_list	*next;
440Sstevel@tonic-gate } amd64_gart_dev_list_t;
450Sstevel@tonic-gate 
460Sstevel@tonic-gate typedef struct amd64_garts_dev {
470Sstevel@tonic-gate 	int			gart_device_num;
480Sstevel@tonic-gate 	amd64_gart_dev_list_t	*gart_dev_list_head;
490Sstevel@tonic-gate } amd64_garts_dev_t;
500Sstevel@tonic-gate 
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate  * AGP target and master device register their config space access
530Sstevel@tonic-gate  * interface here.
540Sstevel@tonic-gate  * In AMD64, gart_device_num is the number of hostbridge (device(1100, 1022))
550Sstevel@tonic-gate  * refer to <<Bios and Kernel Developer's Guide for AMD athlon64 and operton>>
560Sstevel@tonic-gate  */
570Sstevel@tonic-gate typedef struct agp_registered_dev {
580Sstevel@tonic-gate 	amd64_garts_dev_t	agprd_cpugarts;
590Sstevel@tonic-gate 	ldi_handle_t		agprd_targethdl;
600Sstevel@tonic-gate 	ldi_handle_t		agprd_masterhdl;
610Sstevel@tonic-gate 	agp_arc_type_t		agprd_arctype; /* system types */
620Sstevel@tonic-gate } agp_registered_dev_t;
630Sstevel@tonic-gate 
640Sstevel@tonic-gate /*
650Sstevel@tonic-gate  * If the OS have direct mapping support for mapping physical page frames
660Sstevel@tonic-gate  * directly to user address, we use this struct for memory
670Sstevel@tonic-gate  * allocation.
680Sstevel@tonic-gate  */
690Sstevel@tonic-gate typedef struct agp_pmem_handle {
700Sstevel@tonic-gate 	devmap_pmem_cookie_t pmem_cookie;
710Sstevel@tonic-gate } agp_pmem_handle_t;
720Sstevel@tonic-gate 
730Sstevel@tonic-gate /*
740Sstevel@tonic-gate  * This struct is used for DDI-compliant memory allocations.
750Sstevel@tonic-gate  */
760Sstevel@tonic-gate typedef struct agp_kmem_handle {
770Sstevel@tonic-gate 	ddi_dma_handle_t	kmem_handle;
780Sstevel@tonic-gate 	ddi_dma_cookie_t	kmem_dcookie;
790Sstevel@tonic-gate 	uint32_t		kmem_cookies_num;
800Sstevel@tonic-gate 	caddr_t			kmem_kvaddr;
810Sstevel@tonic-gate 	size_t			kmem_reallen;
820Sstevel@tonic-gate 	ddi_acc_handle_t	kmem_acchdl;
830Sstevel@tonic-gate } agp_kmem_handle_t;
840Sstevel@tonic-gate 
850Sstevel@tonic-gate typedef struct keytable_ent {
860Sstevel@tonic-gate 	int		kte_type; 	/* agp memory type */
870Sstevel@tonic-gate 	int		kte_key;	/* memory key */
880Sstevel@tonic-gate 	uint32_t	kte_pgoff;	/* aperture offset bound in pages */
890Sstevel@tonic-gate 	pgcnt_t		kte_pages;	/* user-requested size in pages */
900Sstevel@tonic-gate 	int		kte_bound;	/* bound to gart table */
910Sstevel@tonic-gate 	void		*kte_memhdl;	/* agp_kmem or agp_pmem handle */
920Sstevel@tonic-gate 	pfn_t		*kte_pfnarray;	/* page frame numbers allocated */
937165Shh224818 	int	kte_refcnt;	/* reference count */
940Sstevel@tonic-gate } keytable_ent_t;
950Sstevel@tonic-gate 
960Sstevel@tonic-gate typedef struct key_list {
970Sstevel@tonic-gate 	int	key_idx;
980Sstevel@tonic-gate 	struct	key_list *next;
990Sstevel@tonic-gate } key_list_t;
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate /*
1020Sstevel@tonic-gate  * for kstat
1030Sstevel@tonic-gate  */
1040Sstevel@tonic-gate typedef struct agp_kern_info {
1050Sstevel@tonic-gate 	uint32_t	agpki_mdevid;
1060Sstevel@tonic-gate 	agp_version_t	agpki_mver;
1070Sstevel@tonic-gate 	uint32_t	agpki_mstatus;
1080Sstevel@tonic-gate 	size_t		agpki_presize;	/* valid only for IGD, in KB */
1090Sstevel@tonic-gate 	uint32_t	agpki_tdevid;
1100Sstevel@tonic-gate 	agp_version_t	agpki_tver;
1110Sstevel@tonic-gate 	uint32_t	agpki_tstatus;
1120Sstevel@tonic-gate 	uint64_t	agpki_aperbase;
1130Sstevel@tonic-gate 	uint32_t	agpki_apersize;	/* in MB */
1140Sstevel@tonic-gate } agp_kern_info_t;
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate #ifdef	_MULTI_DATAMODEL
1170Sstevel@tonic-gate typedef struct _agp_info32 {
1180Sstevel@tonic-gate 	agp_version_t	agpi32_version;
1190Sstevel@tonic-gate 	uint32_t	agpi32_devid; /* device VID + DID */
1200Sstevel@tonic-gate 	uint32_t	agpi32_mode; /* mode of bridge */
1210Sstevel@tonic-gate 	uint32_t	agpi32_aperbase; /* base of aperture */
1220Sstevel@tonic-gate 	uint32_t	agpi32_apersize; /* in MB */
1230Sstevel@tonic-gate 	uint32_t	agpi32_pgtotal;	/* max number of pages */
1240Sstevel@tonic-gate 	uint32_t	agpi32_pgsystem; /* same as pg_total */
1250Sstevel@tonic-gate 	uint32_t	agpi32_pgused; /* pages consumed */
1260Sstevel@tonic-gate } agp_info32_t;
1270Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */
1280Sstevel@tonic-gate 
129*11260SMiao.Chen@Sun.COM struct list_head {
130*11260SMiao.Chen@Sun.COM 	struct list_head *next, *prev;
131*11260SMiao.Chen@Sun.COM 	struct igd_gtt_seg  *gttseg;
132*11260SMiao.Chen@Sun.COM };
133*11260SMiao.Chen@Sun.COM 
134*11260SMiao.Chen@Sun.COM 
1350Sstevel@tonic-gate typedef struct	agpgart_softstate {
1360Sstevel@tonic-gate 	dev_info_t	*asoft_dip;
1370Sstevel@tonic-gate 	kmutex_t	asoft_instmutex;
1380Sstevel@tonic-gate 	agp_kern_info_t	asoft_info;
1390Sstevel@tonic-gate 	int		asoft_opened;	/* 0 not opened, non-0 opened */
1400Sstevel@tonic-gate 	int		asoft_acquired;	/* 0 released, 1 acquired */
1410Sstevel@tonic-gate 	int		asoft_agpen;	/* 0 disbaled, 1 enabled */
1420Sstevel@tonic-gate 	pid_t		asoft_curpid;	/* the process accquiring gart */
1430Sstevel@tonic-gate 	uint32_t	asoft_mode;	/* agp mode be set */
1440Sstevel@tonic-gate 	uint32_t	asoft_pgtotal;	/* total available pages */
1450Sstevel@tonic-gate 	uint32_t	asoft_pgused;	/* pages already used */
1460Sstevel@tonic-gate 	/* resource handles */
1470Sstevel@tonic-gate 	ldi_ident_t	asoft_li;	/* for ldi ops */
1480Sstevel@tonic-gate 	keytable_ent_t	*asoft_table;	/* key table for all allocated table */
1490Sstevel@tonic-gate 	ddi_dma_handle_t	gart_dma_handle; 	/* for GATT table */
1500Sstevel@tonic-gate 	ddi_acc_handle_t	gart_dma_acc_handle;	/* for GATT table */
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate 	/* gart table info */
1530Sstevel@tonic-gate 	uint64_t	gart_pbase; /* gart table physical address */
1540Sstevel@tonic-gate 	caddr_t		gart_vbase; /* kernel-vir addr for GATT table */
1550Sstevel@tonic-gate 	size_t		gart_size;  /* the size of aperture in megabytes */
1560Sstevel@tonic-gate 	/* all registered agp device in here */
1570Sstevel@tonic-gate 	agp_registered_dev_t	asoft_devreg;
1580Sstevel@tonic-gate 	kstat_t			*asoft_ksp;
159*11260SMiao.Chen@Sun.COM 	struct		list_head	mapped_list;
1600Sstevel@tonic-gate } agpgart_softstate_t;
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate typedef struct agpgart_ctx {
1630Sstevel@tonic-gate 	offset_t	actx_off;
1640Sstevel@tonic-gate 	agpgart_softstate_t *actx_sc;
1650Sstevel@tonic-gate } agpgart_ctx_t;
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate #define	KMEMP(p)		((agp_kmem_handle_t *)p)
1680Sstevel@tonic-gate #define	PMEMP(p)		((agp_pmem_handle_t *)p)
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate int agp_init_kstats(agpgart_softstate_t *);
1710Sstevel@tonic-gate void agp_fini_kstats(agpgart_softstate_t *);
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate #endif /* _KERNEL */
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate #ifdef __cplusplus
1760Sstevel@tonic-gate }
1770Sstevel@tonic-gate #endif
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate #endif /* _SYS_AGPGART_IMPL_H */
180