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