xref: /titanic_50/usr/src/uts/i86pc/sys/xsvc.h (revision bb121940c2fe627557326e0143391ace6e6b7372)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_XSVC_H
28 #define	_SYS_XSVC_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/avl.h>
37 #include <sys/types.h>
38 
39 /* xsvc ioctls */
40 #define	XSVCIOC		('Q'<< 8)
41 #define	XSVC_ALLOC_MEM	(XSVCIOC | 130)
42 #define	XSVC_FREE_MEM	(XSVCIOC | 131)
43 #define	XSVC_FLUSH_MEM	(XSVCIOC | 132)
44 
45 /* arg * struct for ioctls */
46 typedef struct _xsvc_mem_req {
47 	int		xsvc_mem_reqid; /* request ID */
48 	uint64_t	xsvc_mem_addr_lo; /* low DMA address range */
49 	uint64_t	xsvc_mem_addr_hi; /* high DMA address range */
50 	uint64_t	xsvc_mem_align; /* DMA address alignment */
51 	int		xsvc_mem_sgllen; /* s/g length */
52 	size_t		xsvc_mem_size; /* length of mem in bytes */
53 	void		*xsvc_sg_list; /* returned scatter gather list */
54 } xsvc_mem_req;
55 
56 /* xsvc_sg_list format */
57 typedef struct _xsvc_mloc {
58 	uint64_t	mloc_addr;
59 	size_t		mloc_size;
60 } xsvc_mloc;
61 
62 #ifdef _KERNEL
63 /* *** Driver Private Below *** */
64 
65 /* arg * struct for ioctls from 32-bit app in 64-bit kernel */
66 #pragma pack(1)
67 typedef struct _xsvc_mem_req_32 {
68 	int		xsvc_mem_reqid; /* request ID */
69 	uint64_t	xsvc_mem_addr_lo; /* low DMA address range */
70 	uint64_t	xsvc_mem_addr_hi; /* high DMA address range */
71 	uint64_t	xsvc_mem_align; /* DMA address alignment */
72 	int		xsvc_mem_sgllen; /* s/g length */
73 	uint32_t	xsvc_mem_size; /* length of mem in bytes */
74 	uint32_t	xsvc_sg_list; /* returned scatter gather list */
75 } xsvc_mem_req_32;
76 #pragma pack()
77 
78 /* xsvc_sg_list format */
79 #pragma pack(1)
80 typedef struct _xsvc_mloc_32 {
81 	uint64_t	mloc_addr;
82 	uint32_t	mloc_size;
83 } xsvc_mloc_32;
84 #pragma pack()
85 
86 /* avl node */
87 typedef struct xsvc_mnode_s {
88 	avl_node_t		mn_link;
89 	uint64_t		mn_key;
90 	struct xsvc_mem_s	*mn_home;
91 } xsvc_mnode_t;
92 
93 /* track memory allocs */
94 typedef struct xsvc_mem_s {
95 	xsvc_mnode_t		xm_mnode;
96 	size_t			xm_size;
97 	caddr_t			xm_addr;
98 	size_t			xm_real_length;
99 	ddi_dma_handle_t	xm_dma_handle;
100 	ddi_acc_handle_t	xm_mem_handle;
101 	ddi_dma_attr_t		xm_dma_attr;
102 	ddi_device_acc_attr_t	xm_device_attr;
103 	uint_t			xm_cookie_count;
104 	ddi_dma_cookie_t	xm_cookie;
105 } xsvc_mem_t;
106 
107 /* list of memory allocs */
108 typedef struct xsvc_mlist_s {
109 	kmutex_t	ml_mutex;
110 	avl_tree_t	ml_avl;
111 } xsvc_mlist_t;
112 
113 /* driver state */
114 typedef struct xsvc_state_s {
115 	dev_info_t	*xs_dip;
116 	int		xs_instance;
117 
118 	/*
119 	 * track total memory allocated, mutex only covers
120 	 * xs_currently_alloced
121 	 */
122 	kmutex_t	xs_mutex;
123 	uint64_t	xs_currently_alloced;
124 
125 	xsvc_mlist_t	xs_mlist;
126 } xsvc_state_t;
127 
128 #endif /* _KERNEL */
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
134 #endif /* _SYS_XSVC_H */
135