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