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