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