xref: /onnv-gate/usr/src/uts/common/sys/agp/agpgart_impl.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*0Sstevel@tonic-gate  * Use is subject to license terms.
4*0Sstevel@tonic-gate  */
5*0Sstevel@tonic-gate 
6*0Sstevel@tonic-gate #ifndef	_SYS_AGPGART_IMPL_H
7*0Sstevel@tonic-gate #define	_SYS_AGPGART_IMPL_H
8*0Sstevel@tonic-gate 
9*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
10*0Sstevel@tonic-gate 
11*0Sstevel@tonic-gate #ifdef __cplusplus
12*0Sstevel@tonic-gate extern "C" {
13*0Sstevel@tonic-gate #endif
14*0Sstevel@tonic-gate 
15*0Sstevel@tonic-gate 
16*0Sstevel@tonic-gate #ifdef _KERNEL
17*0Sstevel@tonic-gate 
18*0Sstevel@tonic-gate #define	AGPGART_MAX_INSTANCES	1
19*0Sstevel@tonic-gate #define	AGP_MAXKEYS		256
20*0Sstevel@tonic-gate #define	AGPGART_DEVNODE		"agpgart"
21*0Sstevel@tonic-gate 
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * The values of type agp_arc_type_t are used as indexes into arc_name
24*0Sstevel@tonic-gate  * in agp_kstat.c.
25*0Sstevel@tonic-gate  * So if agp_arc_type_t's values are changed in the future, the content
26*0Sstevel@tonic-gate  * of arc_name must be changed accordingly.
27*0Sstevel@tonic-gate  */
28*0Sstevel@tonic-gate enum agp_arc_type {
29*0Sstevel@tonic-gate 	ARC_IGD810 = 0,
30*0Sstevel@tonic-gate 	ARC_IGD830 = 1,
31*0Sstevel@tonic-gate 	ARC_INTELAGP = 2,
32*0Sstevel@tonic-gate 	ARC_AMD64AGP = 3,
33*0Sstevel@tonic-gate 	ARC_AMD64NOAGP = 4, /* AMD64 cpu without agp bridge */
34*0Sstevel@tonic-gate 	ARC_UNKNOWN = 5
35*0Sstevel@tonic-gate };
36*0Sstevel@tonic-gate typedef enum agp_arc_type agp_arc_type_t;
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate /* linked list structure of multiple agp gart devices access handles */
39*0Sstevel@tonic-gate typedef struct	amd64_gart_dev_list {
40*0Sstevel@tonic-gate 	ldi_handle_t			gart_devhdl;
41*0Sstevel@tonic-gate 	struct	amd64_gart_dev_list	*next;
42*0Sstevel@tonic-gate } amd64_gart_dev_list_t;
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate typedef struct amd64_garts_dev {
45*0Sstevel@tonic-gate 	int			gart_device_num;
46*0Sstevel@tonic-gate 	amd64_gart_dev_list_t	*gart_dev_list_head;
47*0Sstevel@tonic-gate } amd64_garts_dev_t;
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate /*
50*0Sstevel@tonic-gate  * AGP target and master device register their config space access
51*0Sstevel@tonic-gate  * interface here.
52*0Sstevel@tonic-gate  * In AMD64, gart_device_num is the number of hostbridge (device(1100, 1022))
53*0Sstevel@tonic-gate  * refer to <<Bios and Kernel Developer's Guide for AMD athlon64 and operton>>
54*0Sstevel@tonic-gate  */
55*0Sstevel@tonic-gate typedef struct agp_registered_dev {
56*0Sstevel@tonic-gate 	amd64_garts_dev_t	agprd_cpugarts;
57*0Sstevel@tonic-gate 	ldi_handle_t		agprd_targethdl;
58*0Sstevel@tonic-gate 	ldi_handle_t		agprd_masterhdl;
59*0Sstevel@tonic-gate 	agp_arc_type_t		agprd_arctype; /* system types */
60*0Sstevel@tonic-gate } agp_registered_dev_t;
61*0Sstevel@tonic-gate 
62*0Sstevel@tonic-gate /*
63*0Sstevel@tonic-gate  * If the OS have direct mapping support for mapping physical page frames
64*0Sstevel@tonic-gate  * directly to user address, we use this struct for memory
65*0Sstevel@tonic-gate  * allocation.
66*0Sstevel@tonic-gate  */
67*0Sstevel@tonic-gate typedef struct agp_pmem_handle {
68*0Sstevel@tonic-gate 	devmap_pmem_cookie_t pmem_cookie;
69*0Sstevel@tonic-gate } agp_pmem_handle_t;
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate /*
72*0Sstevel@tonic-gate  * This struct is used for DDI-compliant memory allocations.
73*0Sstevel@tonic-gate  */
74*0Sstevel@tonic-gate typedef struct agp_kmem_handle {
75*0Sstevel@tonic-gate 	ddi_dma_handle_t	kmem_handle;
76*0Sstevel@tonic-gate 	ddi_dma_cookie_t	kmem_dcookie;
77*0Sstevel@tonic-gate 	uint32_t		kmem_cookies_num;
78*0Sstevel@tonic-gate 	caddr_t			kmem_kvaddr;
79*0Sstevel@tonic-gate 	size_t			kmem_reallen;
80*0Sstevel@tonic-gate 	ddi_acc_handle_t	kmem_acchdl;
81*0Sstevel@tonic-gate } agp_kmem_handle_t;
82*0Sstevel@tonic-gate 
83*0Sstevel@tonic-gate typedef struct keytable_ent {
84*0Sstevel@tonic-gate 	int		kte_type; 	/* agp memory type */
85*0Sstevel@tonic-gate 	int		kte_key;	/* memory key */
86*0Sstevel@tonic-gate 	uint32_t	kte_pgoff;	/* aperture offset bound in pages */
87*0Sstevel@tonic-gate 	pgcnt_t		kte_pages;	/* user-requested size in pages */
88*0Sstevel@tonic-gate 	int		kte_bound;	/* bound to gart table */
89*0Sstevel@tonic-gate 	void		*kte_memhdl;	/* agp_kmem or agp_pmem handle */
90*0Sstevel@tonic-gate 	pfn_t		*kte_pfnarray;	/* page frame numbers allocated */
91*0Sstevel@tonic-gate 	uint32_t	kte_refcnt;	/* reference count */
92*0Sstevel@tonic-gate } keytable_ent_t;
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate typedef struct key_list {
95*0Sstevel@tonic-gate 	int	key_idx;
96*0Sstevel@tonic-gate 	struct	key_list *next;
97*0Sstevel@tonic-gate } key_list_t;
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate /*
100*0Sstevel@tonic-gate  * for kstat
101*0Sstevel@tonic-gate  */
102*0Sstevel@tonic-gate typedef struct agp_kern_info {
103*0Sstevel@tonic-gate 	uint32_t	agpki_mdevid;
104*0Sstevel@tonic-gate 	agp_version_t	agpki_mver;
105*0Sstevel@tonic-gate 	uint32_t	agpki_mstatus;
106*0Sstevel@tonic-gate 	size_t		agpki_presize;	/* valid only for IGD, in KB */
107*0Sstevel@tonic-gate 	uint32_t	agpki_tdevid;
108*0Sstevel@tonic-gate 	agp_version_t	agpki_tver;
109*0Sstevel@tonic-gate 	uint32_t	agpki_tstatus;
110*0Sstevel@tonic-gate 	uint64_t	agpki_aperbase;
111*0Sstevel@tonic-gate 	uint32_t	agpki_apersize;	/* in MB */
112*0Sstevel@tonic-gate } agp_kern_info_t;
113*0Sstevel@tonic-gate 
114*0Sstevel@tonic-gate #ifdef	_MULTI_DATAMODEL
115*0Sstevel@tonic-gate typedef struct _agp_info32 {
116*0Sstevel@tonic-gate 	agp_version_t	agpi32_version;
117*0Sstevel@tonic-gate 	uint32_t	agpi32_devid; /* device VID + DID */
118*0Sstevel@tonic-gate 	uint32_t	agpi32_mode; /* mode of bridge */
119*0Sstevel@tonic-gate 	uint32_t	agpi32_aperbase; /* base of aperture */
120*0Sstevel@tonic-gate 	uint32_t	agpi32_apersize; /* in MB */
121*0Sstevel@tonic-gate 	uint32_t	agpi32_pgtotal;	/* max number of pages */
122*0Sstevel@tonic-gate 	uint32_t	agpi32_pgsystem; /* same as pg_total */
123*0Sstevel@tonic-gate 	uint32_t	agpi32_pgused; /* pages consumed */
124*0Sstevel@tonic-gate } agp_info32_t;
125*0Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */
126*0Sstevel@tonic-gate 
127*0Sstevel@tonic-gate typedef struct	agpgart_softstate {
128*0Sstevel@tonic-gate 	dev_info_t	*asoft_dip;
129*0Sstevel@tonic-gate 	kmutex_t	asoft_instmutex;
130*0Sstevel@tonic-gate 	agp_kern_info_t	asoft_info;
131*0Sstevel@tonic-gate 	int		asoft_opened;	/* 0 not opened, non-0 opened */
132*0Sstevel@tonic-gate 	int		asoft_acquired;	/* 0 released, 1 acquired */
133*0Sstevel@tonic-gate 	int		asoft_agpen;	/* 0 disbaled, 1 enabled */
134*0Sstevel@tonic-gate 	pid_t		asoft_curpid;	/* the process accquiring gart */
135*0Sstevel@tonic-gate 	uint32_t	asoft_mode;	/* agp mode be set */
136*0Sstevel@tonic-gate 	uint32_t	asoft_pgtotal;	/* total available pages */
137*0Sstevel@tonic-gate 	uint32_t	asoft_pgused;	/* pages already used */
138*0Sstevel@tonic-gate 	/* resource handles */
139*0Sstevel@tonic-gate 	ldi_ident_t	asoft_li;	/* for ldi ops */
140*0Sstevel@tonic-gate 	keytable_ent_t	*asoft_table;	/* key table for all allocated table */
141*0Sstevel@tonic-gate 	ddi_dma_handle_t	gart_dma_handle; 	/* for GATT table */
142*0Sstevel@tonic-gate 	ddi_acc_handle_t	gart_dma_acc_handle;	/* for GATT table */
143*0Sstevel@tonic-gate 
144*0Sstevel@tonic-gate 	/* gart table info */
145*0Sstevel@tonic-gate 	uint64_t	gart_pbase; /* gart table physical address */
146*0Sstevel@tonic-gate 	caddr_t		gart_vbase; /* kernel-vir addr for GATT table */
147*0Sstevel@tonic-gate 	size_t		gart_size;  /* the size of aperture in megabytes */
148*0Sstevel@tonic-gate 	/* all registered agp device in here */
149*0Sstevel@tonic-gate 	agp_registered_dev_t	asoft_devreg;
150*0Sstevel@tonic-gate 	kstat_t			*asoft_ksp;
151*0Sstevel@tonic-gate } agpgart_softstate_t;
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate typedef struct agpgart_ctx {
154*0Sstevel@tonic-gate 	offset_t	actx_off;
155*0Sstevel@tonic-gate 	agpgart_softstate_t *actx_sc;
156*0Sstevel@tonic-gate } agpgart_ctx_t;
157*0Sstevel@tonic-gate 
158*0Sstevel@tonic-gate #define	KMEMP(p)		((agp_kmem_handle_t *)p)
159*0Sstevel@tonic-gate #define	PMEMP(p)		((agp_pmem_handle_t *)p)
160*0Sstevel@tonic-gate 
161*0Sstevel@tonic-gate int agp_init_kstats(agpgart_softstate_t *);
162*0Sstevel@tonic-gate void agp_fini_kstats(agpgart_softstate_t *);
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate #endif /* _KERNEL */
165*0Sstevel@tonic-gate 
166*0Sstevel@tonic-gate #ifdef __cplusplus
167*0Sstevel@tonic-gate }
168*0Sstevel@tonic-gate #endif
169*0Sstevel@tonic-gate 
170*0Sstevel@tonic-gate #endif /* _SYS_AGPGART_IMPL_H */
171