xref: /illumos-gate/usr/src/uts/common/sys/esunddi.h (revision 28ab0ca48b3e331cbbb231b1c8325f9f24f9af95)
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  * Copyright 2020 Oxide Computer Company
26  */
27 
28 #ifndef	_SYS_ESUNDDI_H
29 #define	_SYS_ESUNDDI_H
30 #include <sys/sunddi.h>
31 #include <sys/proc.h>
32 #include <sys/autoconf.h>
33 #include <sys/ddi_impldefs.h>
34 #include <sys/epm.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #ifdef	_KERNEL
41 
42 /*
43  * esunddi.h:		Function prototypes for kernel ddi functions.
44  *	Note that drivers calling these functions are not
45  *	portable.
46  */
47 
48 int
49 e_ddi_prop_create(dev_t dev, dev_info_t *dip, int flag,
50     char *name, caddr_t value, int length);
51 
52 int
53 e_ddi_prop_modify(dev_t dev, dev_info_t *dip, int flag,
54     char *name, caddr_t value, int length);
55 
56 int
57 e_ddi_prop_update_int(dev_t match_dev, dev_info_t *dip,
58     char *name, int data);
59 
60 int
61 e_ddi_prop_update_int64(dev_t match_dev, dev_info_t *dip,
62     char *name, int64_t data);
63 
64 int
65 e_ddi_prop_update_int_array(dev_t match_dev, dev_info_t *dip,
66     char *name, int *data, uint_t nelements);
67 
68 int
69 e_ddi_prop_update_int64_array(dev_t match_dev, dev_info_t *dip,
70     char *name, int64_t *data, uint_t nelements);
71 
72 int
73 e_ddi_prop_update_string(dev_t match_dev, dev_info_t *dip,
74     char *name, char *data);
75 
76 int
77 e_ddi_prop_update_string_array(dev_t match_dev, dev_info_t *dip,
78     char *name, char **data, uint_t nelements);
79 
80 int
81 e_ddi_prop_update_byte_array(dev_t match_dev, dev_info_t *dip,
82     char *name, uchar_t *data, uint_t nelements);
83 
84 int
85 e_ddi_prop_remove(dev_t dev, dev_info_t *dip, char *name);
86 
87 void
88 e_ddi_prop_remove_all(dev_info_t *dip);
89 
90 int
91 e_ddi_prop_undefine(dev_t dev, dev_info_t *dip, int flag, char *name);
92 
93 int
94 e_ddi_getprop(dev_t dev, vtype_t type, char *name, int flags, int defaultval);
95 
96 int64_t
97 e_ddi_getprop_int64(dev_t dev, vtype_t type, char *name,
98     int flags, int64_t defvalue);
99 
100 int
101 e_ddi_getproplen(dev_t dev, vtype_t type, char *name, int flags, int *lengthp);
102 
103 int
104 e_ddi_getlongprop(dev_t dev, vtype_t type, char *name, int flags,
105     caddr_t valuep, int *lengthp);
106 
107 int
108 e_ddi_getlongprop_buf(dev_t dev, vtype_t type, char *name, int flags,
109     caddr_t valuep, int *lengthp);
110 
111 int
112 e_ddi_parental_suspend_resume(dev_info_t *dip);
113 
114 int
115 e_ddi_resume(dev_info_t *dip, ddi_attach_cmd_t);
116 
117 int
118 e_ddi_suspend(dev_info_t *dip, ddi_detach_cmd_t cmd);
119 
120 void
121 pm_init(void);
122 
123 void
124 e_ddi_prop_list_delete(ddi_prop_t *proplist);
125 
126 int
127 e_ddi_copyfromdev(dev_info_t *, off_t, const void *, void *, size_t);
128 
129 int
130 e_ddi_copytodev(dev_info_t *, off_t, const void *, void *, size_t);
131 
132 /*
133  * return codes for devi_stillreferenced()
134  *
135  * DEVI_REFERENCED	- specfs has open minor device(s) for the devinfo
136  * DEVI_NOT_REFERENCED	- specfs has no open minor device for the devinfo
137  */
138 #define	DEVI_REFERENCED		1
139 #define	DEVI_NOT_REFERENCED	0
140 
141 int
142 devi_stillreferenced(dev_info_t *dip);
143 
144 extern int (*pm_platform_power)(power_req_t *);
145 
146 /*
147  * A consolidation private function which is essentially equivalent to
148  * ddi_umem_lock but with the addition of arguments ops_vector and procp.
149  * The procp argument can be eliminated eventually as part of proper
150  * dynamic reconfiguration callback implementation.
151  *
152  * The valid flag values are those used for ddi_umem_lock plus an
153  * additional flag (DDI_UMEMLOCK_LONGTERM) which must be set when the
154  * locking will be maintained for an indefinitely long period (essentially
155  * permanent), rather than for what would be required for a typical I/O
156  * completion.  When DDI_UMEMLOCK_LONGTERM is set, umem_lockmemory will
157  * return EFAULT if the memory pertains to a regular file which is
158  * mapped MAP_SHARED.  This is to prevent a deadlock in the pvn routines
159  * if a file truncation is attempted after the locking is done.
160  */
161 int
162 umem_lockmemory(caddr_t addr, size_t size, int flags,
163     ddi_umem_cookie_t *cookie, 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 e_ddi_enter_driver_list(struct devnames *, int *);		/* obsolete */
253 
254 int e_ddi_tryenter_driver_list(struct devnames *, int *);	/* obsolete */
255 
256 void e_ddi_exit_driver_list(struct devnames *, int);		/* obsolete */
257 
258 typedef struct ddi_unbind_callback {
259 	list_node_t ddiub_next;
260 	void (*ddiub_cb)(void *, dev_info_t *);
261 	void *ddiub_arg;
262 } ddi_unbind_callback_t;
263 
264 extern void e_ddi_register_unbind_callback(dev_info_t *,
265     ddi_unbind_callback_t *);
266 
267 #endif	/* _KERNEL */
268 
269 #ifdef	__cplusplus
270 }
271 #endif
272 
273 #endif /* _SYS_ESUNDDI_H */
274