xref: /illumos-gate/usr/src/uts/i86pc/sys/xsvc.h (revision bc3489c0c3dc75477d8ebb93b7a202625bd8cbfd)
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 2009 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 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include <sys/avl.h>
35 #include <sys/types.h>
36 
37 /* xsvc ioctls */
38 #define	XSVCIOC		('Q'<< 8)
39 #define	XSVC_ALLOC_MEM	(XSVCIOC | 130)
40 #define	XSVC_FREE_MEM	(XSVCIOC | 131)
41 #define	XSVC_FLUSH_MEM	(XSVCIOC | 132)
42 
43 /* arg * struct for ioctls */
44 typedef struct _xsvc_mem_req {
45 	int		xsvc_mem_reqid; /* request ID */
46 	uint64_t	xsvc_mem_addr_lo; /* low DMA address range */
47 	uint64_t	xsvc_mem_addr_hi; /* high DMA address range */
48 	uint64_t	xsvc_mem_align; /* DMA address alignment */
49 	int		xsvc_mem_sgllen; /* s/g length */
50 	size_t		xsvc_mem_size; /* length of mem in bytes */
51 	void		*xsvc_sg_list; /* returned scatter gather list */
52 } xsvc_mem_req;
53 
54 /* xsvc_sg_list format */
55 typedef struct _xsvc_mloc {
56 	uint64_t	mloc_addr;
57 	size_t		mloc_size;
58 } xsvc_mloc;
59 
60 #ifdef _KERNEL
61 /* *** Driver Private Below *** */
62 
63 /* arg * struct for ioctls from 32-bit app in 64-bit kernel */
64 #pragma pack(1)
65 typedef struct _xsvc_mem_req_32 {
66 	int		xsvc_mem_reqid; /* request ID */
67 	uint64_t	xsvc_mem_addr_lo; /* low DMA address range */
68 	uint64_t	xsvc_mem_addr_hi; /* high DMA address range */
69 	uint64_t	xsvc_mem_align; /* DMA address alignment */
70 	int		xsvc_mem_sgllen; /* s/g length */
71 	uint32_t	xsvc_mem_size; /* length of mem in bytes */
72 	uint32_t	xsvc_sg_list; /* returned scatter gather list */
73 } xsvc_mem_req_32;
74 #pragma pack()
75 
76 /* xsvc_sg_list format */
77 #pragma pack(1)
78 typedef struct _xsvc_mloc_32 {
79 	uint64_t	mloc_addr;
80 	uint32_t	mloc_size;
81 } xsvc_mloc_32;
82 #pragma pack()
83 
84 /* avl node */
85 typedef struct xsvc_mnode_s {
86 	avl_node_t		mn_link;
87 	uint64_t		mn_key;
88 	struct xsvc_mem_s	*mn_home;
89 } xsvc_mnode_t;
90 
91 /* track memory allocs */
92 typedef struct xsvc_mem_s {
93 	xsvc_mnode_t		xm_mnode;
94 	size_t			xm_size;
95 	caddr_t			xm_addr;
96 	size_t			xm_real_length;
97 	ddi_dma_handle_t	xm_dma_handle;
98 	ddi_acc_handle_t	xm_mem_handle;
99 	ddi_dma_attr_t		xm_dma_attr;
100 	ddi_device_acc_attr_t	xm_device_attr;
101 	uint_t			xm_cookie_count;
102 	ddi_dma_cookie_t	xm_cookie;
103 } xsvc_mem_t;
104 
105 /* list of memory allocs */
106 typedef struct xsvc_mlist_s {
107 	kmutex_t	ml_mutex;
108 	avl_tree_t	ml_avl;
109 } xsvc_mlist_t;
110 
111 /* driver state */
112 typedef struct xsvc_state_s {
113 	dev_info_t	*xs_dip;
114 	int		xs_instance;
115 
116 	/*
117 	 * track total memory allocated, mutex only covers
118 	 * xs_currently_alloced
119 	 */
120 	kmutex_t	xs_mutex;
121 	uint64_t	xs_currently_alloced;
122 
123 	kmutex_t	xs_cookie_mutex;
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