xref: /titanic_41/usr/src/uts/common/sys/ddi_implfuncs.h (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_DDI_IMPLFUNCS_H
28 #define	_SYS_DDI_IMPLFUNCS_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/obpdefs.h>
37 #include <sys/vnode.h>
38 #include <sys/types.h>
39 #include <sys/task.h>
40 #include <sys/project.h>
41 
42 #ifdef	_KERNEL
43 
44 /*
45  * Declare implementation functions that sunddi functions can
46  * call in order to perform their required task. Each kernel
47  * architecture must provide them.
48  */
49 
50 int
51 i_ddi_bus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
52 	off_t offset, off_t len, caddr_t *vaddrp);
53 
54 int
55 i_ddi_apply_range(dev_info_t *dip, dev_info_t *rdip, struct regspec *rp);
56 
57 struct regspec *
58 i_ddi_rnumber_to_regspec(dev_info_t *dip, int rnumber);
59 
60 
61 int
62 i_ddi_map_fault(dev_info_t *dip, dev_info_t *rdip,
63 	struct hat *hat, struct seg *seg, caddr_t addr,
64 	struct devpage *dp, pfn_t pfn, uint_t prot, uint_t lock);
65 
66 ddi_regspec_t
67 i_ddi_get_regspec(dev_info_t *dip, dev_info_t *rdip, uint_t rnumber,
68 	off_t offset, off_t len);
69 
70 void
71 i_ddi_set_parent_private(dev_info_t *dip, caddr_t data);
72 
73 caddr_t
74 i_ddi_get_parent_private(dev_info_t *dip);
75 
76 /*
77  * Implementation specific memory allocation and de-allocation routines.
78  */
79 int
80 i_ddi_mem_alloc(dev_info_t *dip, ddi_dma_attr_t *attributes,
81 	size_t length, int cansleep, int streaming,
82 	ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp,
83 	size_t *real_length, ddi_acc_hdl_t *handlep);
84 
85 int
86 i_ddi_mem_alloc_lim(dev_info_t *dip, ddi_dma_lim_t *limits,
87 	size_t length, int cansleep, int streaming,
88 	ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp,
89 	uint_t *real_length, ddi_acc_hdl_t *handlep);
90 
91 void
92 i_ddi_mem_free(caddr_t kaddr, int streaming);
93 
94 int
95 i_ddi_devi_get_ppa(dev_info_t *dip);
96 
97 void
98 i_ddi_devi_set_ppa(dev_info_t *dip, int ppa);
99 
100 /*
101  * Access and DMA handle fault set/clear routines
102  */
103 void
104 i_ddi_acc_set_fault(ddi_acc_handle_t handle);
105 void
106 i_ddi_acc_clr_fault(ddi_acc_handle_t handle);
107 void
108 i_ddi_dma_set_fault(ddi_dma_handle_t handle);
109 void
110 i_ddi_dma_clr_fault(ddi_dma_handle_t handle);
111 
112 /*
113  *      Event-handling functions for rootnex
114  *      These provide the standard implementation of fault handling
115  */
116 void
117 i_ddi_rootnex_init_events(dev_info_t *dip);
118 
119 int
120 i_ddi_rootnex_get_eventcookie(dev_info_t *dip, dev_info_t *rdip,
121 	char *eventname, ddi_eventcookie_t *cookiep);
122 int
123 i_ddi_rootnex_add_eventcall(dev_info_t *dip, dev_info_t *rdip,
124 	ddi_eventcookie_t eventid, void (*handler)(dev_info_t *dip,
125 	ddi_eventcookie_t event, void *arg, void *impl_data), void *arg,
126 	ddi_callback_id_t *cb_id);
127 int
128 i_ddi_rootnex_remove_eventcall(dev_info_t *devi, ddi_callback_id_t cb_id);
129 
130 int
131 i_ddi_rootnex_post_event(dev_info_t *dip, dev_info_t *rdip,
132 	ddi_eventcookie_t eventid, void *impl_data);
133 
134 /*
135  * Clustering: Return the global devices path base, or
136  * the entire global devices path prefix.
137  */
138 const char *
139 i_ddi_get_dpath_base();
140 
141 const char *
142 i_ddi_get_dpath_prefix();
143 
144 /*
145  * Search and return properties from the PROM
146  */
147 int
148 impl_ddi_bus_prop_op(dev_t dev, dev_info_t *dip,
149 	dev_info_t *ch_dip, ddi_prop_op_t prop_op, int mod_flags,
150 	char *name, caddr_t valuep, int *lengthp);
151 
152 /*
153  * Copy an integer from PROM to native machine representation
154  */
155 int
156 impl_ddi_prop_int_from_prom(uchar_t *intp, int n);
157 
158 
159 extern int impl_ddi_sunbus_initchild(dev_info_t *);
160 extern void impl_ddi_sunbus_removechild(dev_info_t *);
161 
162 /*
163  * Implementation specific access handle allocator and init. routines
164  */
165 extern ddi_acc_handle_t impl_acc_hdl_alloc(int (*waitfp)(caddr_t),
166 	caddr_t arg);
167 extern void impl_acc_hdl_free(ddi_acc_handle_t handle);
168 
169 extern ddi_acc_hdl_t *impl_acc_hdl_get(ddi_acc_handle_t handle);
170 extern void impl_acc_hdl_init(ddi_acc_hdl_t *hp);
171 
172 /* access error handling support */
173 extern void impl_acc_err_init(ddi_acc_hdl_t *);
174 extern int i_ddi_ontrap(ddi_acc_handle_t);
175 extern void i_ddi_notrap(ddi_acc_handle_t);
176 extern int i_ddi_prot_trampoline();
177 extern int i_ddi_caut_trampoline();
178 
179 /*
180  * misc/bootdev entry points - these are private routines and subject
181  * to change.
182  */
183 extern int
184 i_devname_to_promname(char *dev_name, char *ret_buf, size_t);
185 
186 extern int
187 i_promname_to_devname(char *prom_name, char *ret_buf);
188 
189 extern char *
190 i_convert_boot_device_name(char *, char *, size_t *);
191 
192 /*
193  * Nodeid management ...
194  */
195 void impl_ddi_init_nodeid(void);
196 int impl_ddi_alloc_nodeid(int *nodeid);
197 int impl_ddi_take_nodeid(int nodeid, int kmflag);
198 void impl_ddi_free_nodeid(int nodeid);
199 
200 /*
201  * minorname/devtspectype conversions
202  */
203 extern char *
204 i_ddi_devtspectype_to_minorname(dev_info_t *dip, dev_t dev, int spec_type);
205 
206 extern int
207 i_ddi_minorname_to_devtspectype(dev_info_t *dip, char *minor_name,
208 	dev_t *devp, int *spectypep);
209 
210 
211 /*
212  * Helper functions
213  */
214 char *i_ddi_strdup(char *, uint_t);
215 void i_ddi_prop_list_delete(ddi_prop_t *);
216 ddi_prop_t *i_ddi_prop_list_dup(ddi_prop_t *, uint_t);
217 int i_ddi_load_drvconf(major_t);
218 int i_ddi_unload_drvconf(major_t);
219 ddi_node_state_t i_ddi_node_state(dev_info_t *);
220 
221 /*
222  * Routines in ddi_v9_asm.s
223  */
224 extern int do_peek(size_t, void *, void *);
225 extern int do_poke(size_t, void *, void *);
226 extern void peek_fault(void);
227 extern void poke_fault(void);
228 
229 extern int peekpoke_mem(ddi_ctl_enum_t, peekpoke_ctlops_t *);
230 
231 char *i_ddi_strdup(char *, uint_t);
232 void i_ddi_parse_name(char *, char **, char **, char **);
233 ddi_node_state_t i_ddi_node_state(dev_info_t *);
234 void i_ddi_set_node_state(dev_info_t *, ddi_node_state_t);
235 int i_ddi_detach_installed_driver(major_t, int);
236 int i_ddi_load_drvconf(major_t);
237 int i_ddi_unload_drvconf(major_t);
238 void i_ddi_set_binding_name(dev_info_t *, char *);
239 void i_ddi_bind_devs();
240 void i_ddi_unbind_devs(major_t);
241 ddi_prop_t *i_ddi_prop_list_dup(ddi_prop_t *, uint_t);
242 void i_ddi_prop_list_delete(ddi_prop_t *);
243 ddi_prop_list_t *i_ddi_prop_list_create(ddi_prop_t *);
244 struct devnames;
245 void i_ddi_prop_list_hold(ddi_prop_list_t *, struct devnames *);
246 void i_ddi_prop_list_rele(ddi_prop_list_t *, struct devnames *);
247 ddi_prop_t *i_ddi_prop_search(dev_t, char *, uint_t, ddi_prop_t **);
248 int resolve_pathname(char *, dev_info_t **, dev_t *, int *);
249 int i_ddi_prompath_to_devfspath(char *, char *);
250 int i_ddi_attach_node_hierarchy(dev_info_t *);
251 dev_info_t *i_ddi_attach_pseudo_node(char *);
252 int i_ddi_attach_hw_nodes(char *);
253 int i_ddi_devs_attached(major_t);
254 
255 /* non-DDI functions: wrapper around mod_hold/rele_dev_by_major() */
256 struct dev_ops *ddi_hold_driver(major_t);
257 void ddi_rele_driver(major_t);
258 
259 /*
260  * devid cache
261  */
262 void i_ddi_devices_init(void);
263 void i_ddi_read_devices_files(void);
264 
265 int i_ddi_devi_get_devid(dev_t, dev_info_t *, ddi_devid_t *);
266 
267 int e_ddi_devid_discovery(ddi_devid_t);
268 
269 int e_devid_cache_register(dev_info_t *, ddi_devid_t);
270 void e_devid_cache_unregister(dev_info_t *);
271 void e_devid_cache_cleanup(void);
272 
273 int e_devid_cache_to_devt_list(ddi_devid_t, char *, int *, dev_t **);
274 void e_devid_cache_free_devt_list(int, dev_t *);
275 
276 /*
277  * Resource control functions to lock down device memory.
278  */
279 extern int i_ddi_incr_locked_memory(proc_t *, task_t *, kproject_t *,
280 	zone_t *, rctl_qty_t);
281 extern void i_ddi_decr_locked_memory(proc_t *, task_t *, kproject_t *,
282 	zone_t *, rctl_qty_t);
283 
284 #endif	/* _KERNEL */
285 
286 #ifdef	__cplusplus
287 }
288 #endif
289 
290 #endif	/* _SYS_DDI_IMPLFUNCS_H */
291