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