xref: /titanic_50/usr/src/uts/common/sys/sunldi_impl.h (revision fa9e4066f08beec538e775443c5be79dd423fcab)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_SUNLDI_IMPL_H
28 #define	_SYS_SUNLDI_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/dditypes.h>
37 #include <sys/vnode.h>
38 
39 /*
40  * NOTE
41  *
42  * The contents of this file are private to this implementation
43  * of Solaris and are subject to change at any time without notice.
44  *
45  * Applications and drivers using these interfaces will fail
46  * to run on future releases.
47  */
48 
49 /*
50  * LDI hash definitions
51  */
52 #define	LH_HASH_SZ	32
53 #define	LI_HASH_SZ	32
54 
55 /*
56  * LDI initialization function
57  */
58 void ldi_init(void);
59 
60 /*
61  * LDI streams linking interfaces
62  */
63 extern int ldi_mlink_lh(vnode_t *, int, intptr_t, cred_t *, int *);
64 extern void ldi_mlink_fp(struct stdata *, struct file *, int, int);
65 extern void ldi_munlink_fp(struct stdata *, struct file *, int);
66 
67 /*
68  * LDI module identifier
69  */
70 struct ldi_ident {
71 	/* protected by ldi_ident_hash_lock */
72 	struct ldi_ident		*li_next;
73 	uint_t				li_ref;
74 
75 	/* unique/static fields in the ident */
76 	char				li_modname[MODMAXNAMELEN];
77 	modid_t				li_modid;
78 	major_t				li_major;
79 	dev_info_t			*li_dip;
80 	dev_t				li_dev;
81 };
82 
83 /*
84  * LDI handle
85  */
86 struct ldi_handle {
87 	/* protected by ldi_handle_hash_lock */
88 	struct ldi_handle		*lh_next;
89 	uint_t				lh_ref;
90 
91 	/* unique/static fields in the handle */
92 	uint_t				lh_type;
93 	struct ldi_ident		*lh_ident;
94 	vnode_t				*lh_vp;
95 
96 	/* fields protected by lh_lock */
97 	kmutex_t			lh_lock[1];
98 	struct ldi_event		*lh_events;
99 };
100 
101 /*
102  * LDI event information
103  */
104 typedef struct ldi_event {
105 	/* fields protected by le_lhp->lh_lock */
106 	struct ldi_event	*le_next;
107 	struct ldi_event	*le_prev;
108 
109 	/* unique/static fields in the handle */
110 	struct ldi_handle	*le_lhp;
111 	void			(*le_handler)();
112 	void			*le_arg;
113 	ddi_callback_id_t	le_id;
114 } ldi_event_t;
115 
116 /*
117  * LDI device usage interfaces
118  *
119  * ldi_usage_count(), ldi_usage_walker(), and ldi_usage_t
120  *
121  * These functions are used by the devinfo driver and fuser to get a
122  * device usage information from the LDI. These functions along with
123  * the ldi_usage_t data structure allow these other subsystems to have
124  * no knowledge of how the LDI stores it's internal state.
125  *
126  * ldi_usage_count() provides an count of how many kernel
127  *	device clients currently exist.
128  *
129  * ldi_usage_walker() reports all kernel device usage information.
130  */
131 #define	LDI_USAGE_CONTINUE	0
132 #define	LDI_USAGE_TERMINATE	1
133 
134 typedef struct ldi_usage {
135 	/*
136 	 * information about the kernel subsystem that is accessing
137 	 * the target device
138 	 */
139 	modid_t		src_modid;
140 	char		*src_name;
141 	dev_info_t	*src_dip;
142 	dev_t		src_devt;
143 
144 	/*
145 	 * information about the target device that is open
146 	 */
147 	modid_t		tgt_modid;
148 	char		*tgt_name;
149 	dev_info_t	*tgt_dip;
150 	dev_t		tgt_devt;
151 	int		tgt_spec_type;
152 } ldi_usage_t;
153 
154 int ldi_usage_count();
155 void ldi_usage_walker(void *arg,
156     int (*callback)(const ldi_usage_t *ldi_usage, void *arg));
157 
158 #ifdef __cplusplus
159 }
160 #endif
161 
162 #endif	/* _SYS_SUNLDI_IMPL_H */
163