xref: /illumos-gate/usr/src/uts/common/sys/esunddi.h (revision dc5e7685b131559c0b7c622baee25a9a0ae50ada)
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  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  * Copyright (c) 2016 by Delphix. All rights reserved.
25  */
26 
27 #ifndef	_SYS_ESUNDDI_H
28 #define	_SYS_ESUNDDI_H
29 #include <sys/sunddi.h>
30 #include <sys/proc.h>
31 #include <sys/autoconf.h>
32 #include <sys/ddi_impldefs.h>
33 #include <sys/epm.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #ifdef	_KERNEL
40 
41 /*
42  * esunddi.h:		Function prototypes for kernel ddi functions.
43  *	Note that drivers calling these functions are not
44  *	portable.
45  */
46 
47 int
48 e_ddi_prop_create(dev_t dev, dev_info_t *dip, int flag,
49 	char *name, caddr_t value, int length);
50 
51 int
52 e_ddi_prop_modify(dev_t dev, dev_info_t *dip, int flag,
53 	char *name, caddr_t value, int length);
54 
55 int
56 e_ddi_prop_update_int(dev_t match_dev, dev_info_t *dip,
57 	char *name, int data);
58 
59 int
60 e_ddi_prop_update_int64(dev_t match_dev, dev_info_t *dip,
61     char *name, int64_t data);
62 
63 int
64 e_ddi_prop_update_int_array(dev_t match_dev, dev_info_t *dip,
65     char *name, int *data, uint_t nelements);
66 
67 int
68 e_ddi_prop_update_int64_array(dev_t match_dev, dev_info_t *dip,
69     char *name, int64_t *data, uint_t nelements);
70 
71 int
72 e_ddi_prop_update_string(dev_t match_dev, dev_info_t *dip,
73 	char *name, char *data);
74 
75 int
76 e_ddi_prop_update_string_array(dev_t match_dev, dev_info_t *dip,
77     char *name, char **data, uint_t nelements);
78 
79 int
80 e_ddi_prop_update_byte_array(dev_t match_dev, dev_info_t *dip,
81     char *name, uchar_t *data, uint_t nelements);
82 
83 int
84 e_ddi_prop_remove(dev_t dev, dev_info_t *dip, char *name);
85 
86 void
87 e_ddi_prop_remove_all(dev_info_t *dip);
88 
89 int
90 e_ddi_prop_undefine(dev_t dev, dev_info_t *dip, int flag, char *name);
91 
92 int
93 e_ddi_getprop(dev_t dev, vtype_t type, char *name, int flags, int defaultval);
94 
95 int64_t
96 e_ddi_getprop_int64(dev_t dev, vtype_t type, char *name,
97 	int flags, int64_t defvalue);
98 
99 int
100 e_ddi_getproplen(dev_t dev, vtype_t type, char *name, int flags, int *lengthp);
101 
102 int
103 e_ddi_getlongprop(dev_t dev, vtype_t type, char *name, int flags,
104 	caddr_t valuep, int *lengthp);
105 
106 int
107 e_ddi_getlongprop_buf(dev_t dev, vtype_t type, char *name, int flags,
108 	caddr_t valuep, int *lengthp);
109 
110 int
111 e_ddi_parental_suspend_resume(dev_info_t *dip);
112 
113 int
114 e_ddi_resume(dev_info_t *dip, ddi_attach_cmd_t);
115 
116 int
117 e_ddi_suspend(dev_info_t *dip, ddi_detach_cmd_t cmd);
118 
119 void
120 pm_init(void);
121 
122 void
123 e_ddi_prop_list_delete(ddi_prop_t *proplist);
124 
125 int
126 e_ddi_copyfromdev(dev_info_t *, off_t, const void *, void *, size_t);
127 
128 int
129 e_ddi_copytodev(dev_info_t *, off_t, const void *, void *, size_t);
130 
131 /*
132  * return codes for devi_stillreferenced()
133  *
134  * DEVI_REFERENCED	- specfs has open minor device(s) for the devinfo
135  * DEVI_NOT_REFERENCED	- specfs has no open minor device for the devinfo
136  */
137 #define	DEVI_REFERENCED		1
138 #define	DEVI_NOT_REFERENCED	0
139 
140 int
141 devi_stillreferenced(dev_info_t *dip);
142 
143 extern int (*pm_platform_power)(power_req_t *);
144 
145 /*
146  * A consolidation private function which is essentially equivalent to
147  * ddi_umem_lock but with the addition of arguments ops_vector and procp.
148  * The procp argument can be eliminated eventually as part of proper
149  * dynamic reconfiguration callback implementation.
150  *
151  * The valid flag values are those used for ddi_umem_lock plus an
152  * additional flag (DDI_UMEMLOCK_LONGTERM) which must be set when the
153  * locking will be maintained for an indefinitely long period (essentially
154  * permanent), rather than for what would be required for a typical I/O
155  * completion.  When DDI_UMEMLOCK_LONGTERM is set, umem_lockmemory will
156  * return EFAULT if the memory pertains to a regular file which is
157  * mapped MAP_SHARED.  This is to prevent a deadlock in the pvn routines
158  * if a file truncation is attempted after the locking is done.
159  */
160 int
161 umem_lockmemory(caddr_t addr, size_t size, int flags,
162 		ddi_umem_cookie_t *cookie,
163 		struct umem_callback_ops *ops_vector,
164 		proc_t *procp);
165 
166 #define	DDI_UMEMLOCK_LONGTERM	0x04
167 
168 /*
169  * These are evolving forms of the ddi function ddi_hold_devi_by_instance.
170  * Like ddi_hold_devi_by_instance, the hold should be released with
171  * ddi_release_devi.
172  */
173 dev_info_t	*
174 e_ddi_hold_devi_by_dev(dev_t dev, int flags);
175 
176 dev_info_t	*
177 e_ddi_hold_devi_by_path(char *path, int flags);
178 
179 /* {e_}ddi_hold_devi{_by{instance|dev|path}} flags */
180 #define	E_DDI_HOLD_DEVI_NOATTACH	0x01
181 
182 void
183 e_ddi_hold_devi(dev_info_t *);
184 
185 /*
186  * Return the reference count on a devinfo node. The caller can determine,
187  * with knowledge of its own holds, if the devinfo node is still in use.
188  */
189 int
190 e_ddi_devi_holdcnt(dev_info_t *dip);
191 
192 /*
193  * Perform path reconstruction given a major and instance. Does not
194  * drive attach of the path.
195  */
196 int
197 e_ddi_majorinstance_to_path(major_t major, int instance, char *name);
198 
199 /*
200  * walk all devinfo nodes linked on the driver list
201  */
202 void
203 e_ddi_walk_driver(char *, int (*f)(dev_info_t *, void *), void *);
204 
205 /*
206  * Given the nodeid for a persistent node, find the corresponding
207  * devinfo node.
208  * NOTE: .conf nodeids are not valid arguments to this function.
209  */
210 dev_info_t *
211 e_ddi_nodeid_to_dip(pnode_t nodeid);
212 
213 /*
214  * Defines for DR interfaces
215  */
216 #define	DEVI_BRANCH_CHILD	0x01	/* Walk immediate children of root  */
217 #define	DEVI_BRANCH_CONFIGURE	0x02	/* Configure branch after create    */
218 #define	DEVI_BRANCH_DESTROY	0x04	/* Destroy branch after unconfigure */
219 #define	DEVI_BRANCH_EVENT	0x08	/* Post NDI event		    */
220 #define	DEVI_BRANCH_PROM	0x10	/* Branches derived from PROM nodes */
221 #define	DEVI_BRANCH_SID		0x20	/* SID node branches		    */
222 #define	DEVI_BRANCH_ROOT	0x40	/* Node is the root of a branch	    */
223 
224 typedef struct devi_branch {
225 	void		*arg;
226 	void		(*devi_branch_callback)(dev_info_t *, void *, uint_t);
227 	int		type;
228 	union {
229 		int	(*prom_branch_select)(pnode_t, void *, uint_t);
230 		int	(*sid_branch_create)(dev_info_t *, void *, uint_t);
231 	} create;
232 } devi_branch_t;
233 
234 extern int e_ddi_branch_create(dev_info_t *pdip, devi_branch_t *bp,
235     dev_info_t **dipp, uint_t flags);
236 extern int e_ddi_branch_configure(dev_info_t *rdip, dev_info_t **dipp,
237     uint_t flags);
238 extern int e_ddi_branch_unconfigure(dev_info_t *rdip, dev_info_t **dipp,
239     uint_t flags);
240 extern int e_ddi_branch_destroy(dev_info_t *rdip, dev_info_t **dipp,
241     uint_t flags);
242 extern void e_ddi_branch_hold(dev_info_t *rdip);
243 extern void e_ddi_branch_rele(dev_info_t *rdip);
244 extern int e_ddi_branch_held(dev_info_t *rdip);
245 extern int e_ddi_branch_referenced(dev_info_t *rdip,
246     int (*cb)(dev_info_t *dip, void *, uint_t), void *arg);
247 
248 /*
249  * Obsolete interfaces, no longer used, to be removed.
250  * Retained only for driver compatibility.
251  */
252 void
253 e_ddi_enter_driver_list(struct devnames *, int *);	/* obsolete */
254 
255 int
256 e_ddi_tryenter_driver_list(struct devnames *, int *);	/* obsolete */
257 
258 void
259 e_ddi_exit_driver_list(struct devnames *, int);		/* obsolete */
260 
261 
262 #endif	/* _KERNEL */
263 
264 #ifdef	__cplusplus
265 }
266 #endif
267 
268 #endif /* _SYS_ESUNDDI_H */
269