xref: /onnv-gate/usr/src/uts/common/sys/ddi_implfuncs.h (revision 1900:7657500f392a)
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 /*
23  * Copyright 2006 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 /*
71  * Implementation specific memory allocation and de-allocation routines.
72  */
73 int
74 i_ddi_mem_alloc(dev_info_t *dip, ddi_dma_attr_t *attributes,
75 	size_t length, int cansleep, int streaming,
76 	ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp,
77 	size_t *real_length, ddi_acc_hdl_t *handlep);
78 
79 int
80 i_ddi_mem_alloc_lim(dev_info_t *dip, ddi_dma_lim_t *limits,
81 	size_t length, int cansleep, int streaming,
82 	ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp,
83 	uint_t *real_length, ddi_acc_hdl_t *handlep);
84 
85 void
86 i_ddi_mem_free(caddr_t kaddr, ddi_acc_hdl_t *ap);
87 
88 int
89 i_ddi_devi_get_ppa(dev_info_t *dip);
90 
91 void
92 i_ddi_devi_set_ppa(dev_info_t *dip, int ppa);
93 
94 boolean_t
95 i_ddi_check_endian_attr(ddi_device_acc_attr_t *devaccp);
96 
97 void
98 i_ddi_devacc_to_hatacc(ddi_device_acc_attr_t *devaccp, uint_t *hataccp);
99 
100 void
101 i_ddi_cacheattr_to_hatacc(uint_t flags, uint_t *hataccp);
102 
103 boolean_t
104 i_ddi_check_cache_attr(uint_t flags);
105 
106 /*
107  * Access and DMA handle fault set/clear routines
108  */
109 void
110 i_ddi_acc_set_fault(ddi_acc_handle_t handle);
111 void
112 i_ddi_acc_clr_fault(ddi_acc_handle_t handle);
113 void
114 i_ddi_dma_set_fault(ddi_dma_handle_t handle);
115 void
116 i_ddi_dma_clr_fault(ddi_dma_handle_t handle);
117 
118 /*
119  *      Event-handling functions for rootnex
120  *      These provide the standard implementation of fault handling
121  */
122 void
123 i_ddi_rootnex_init_events(dev_info_t *dip);
124 
125 int
126 i_ddi_rootnex_get_eventcookie(dev_info_t *dip, dev_info_t *rdip,
127 	char *eventname, ddi_eventcookie_t *cookiep);
128 int
129 i_ddi_rootnex_add_eventcall(dev_info_t *dip, dev_info_t *rdip,
130 	ddi_eventcookie_t eventid, void (*handler)(dev_info_t *dip,
131 	ddi_eventcookie_t event, void *arg, void *impl_data), void *arg,
132 	ddi_callback_id_t *cb_id);
133 int
134 i_ddi_rootnex_remove_eventcall(dev_info_t *devi, ddi_callback_id_t cb_id);
135 
136 int
137 i_ddi_rootnex_post_event(dev_info_t *dip, dev_info_t *rdip,
138 	ddi_eventcookie_t eventid, void *impl_data);
139 
140 /*
141  * Clustering: Return the global devices path base, or
142  * the entire global devices path prefix.
143  */
144 const char *
145 i_ddi_get_dpath_base();
146 
147 const char *
148 i_ddi_get_dpath_prefix();
149 
150 /*
151  * Search and return properties from the PROM
152  */
153 int
154 impl_ddi_bus_prop_op(dev_t dev, dev_info_t *dip,
155 	dev_info_t *ch_dip, ddi_prop_op_t prop_op, int mod_flags,
156 	char *name, caddr_t valuep, int *lengthp);
157 
158 /*
159  * Copy an integer from PROM to native machine representation
160  */
161 int
162 impl_ddi_prop_int_from_prom(uchar_t *intp, int n);
163 
164 
165 extern int impl_ddi_sunbus_initchild(dev_info_t *);
166 extern void impl_ddi_sunbus_removechild(dev_info_t *);
167 
168 /*
169  * Implementation specific access handle allocator and init. routines
170  */
171 extern ddi_acc_handle_t impl_acc_hdl_alloc(int (*waitfp)(caddr_t),
172 	caddr_t arg);
173 extern void impl_acc_hdl_free(ddi_acc_handle_t handle);
174 
175 extern ddi_acc_hdl_t *impl_acc_hdl_get(ddi_acc_handle_t handle);
176 extern void impl_acc_hdl_init(ddi_acc_hdl_t *hp);
177 
178 /* access error handling support */
179 extern void impl_acc_err_init(ddi_acc_hdl_t *);
180 extern int impl_dma_check(dev_info_t *, const void *, const void *,
181     const void *);
182 extern int i_ddi_ontrap(ddi_acc_handle_t);
183 extern void i_ddi_notrap(ddi_acc_handle_t);
184 extern int i_ddi_prot_trampoline();
185 extern int i_ddi_caut_trampoline();
186 
187 /*
188  * misc/bootdev entry points - these are private routines and subject
189  * to change.
190  */
191 extern int
192 i_devname_to_promname(char *dev_name, char *ret_buf, size_t);
193 
194 extern int
195 i_promname_to_devname(char *prom_name, char *ret_buf);
196 
197 extern char *
198 i_convert_boot_device_name(char *, char *, size_t *);
199 
200 /*
201  * Nodeid management ...
202  */
203 void impl_ddi_init_nodeid(void);
204 int impl_ddi_alloc_nodeid(int *nodeid);
205 int impl_ddi_take_nodeid(int nodeid, int kmflag);
206 void impl_ddi_free_nodeid(int nodeid);
207 
208 /*
209  * minorname/devtspectype conversions
210  */
211 extern char *
212 i_ddi_devtspectype_to_minorname(dev_info_t *dip, dev_t dev, int spec_type);
213 
214 extern int
215 i_ddi_minorname_to_devtspectype(dev_info_t *dip, char *minor_name,
216 	dev_t *devp, int *spectypep);
217 
218 /*
219  * Routines in ddi_v9_asm.s
220  */
221 extern int do_peek(size_t, void *, void *);
222 extern int do_poke(size_t, void *, void *);
223 extern void peek_fault(void);
224 extern void poke_fault(void);
225 extern int peekpoke_mem(ddi_ctl_enum_t, peekpoke_ctlops_t *);
226 
227 /*
228  * Helper functions
229  */
230 char *i_ddi_strdup(char *, uint_t);
231 void i_ddi_prop_list_delete(ddi_prop_t *);
232 ddi_prop_t *i_ddi_prop_list_dup(ddi_prop_t *, uint_t);
233 int i_ddi_load_drvconf(major_t);
234 int i_ddi_unload_drvconf(major_t);
235 ddi_node_state_t i_ddi_node_state(dev_info_t *);
236 int i_ddi_devi_attached(dev_info_t *);
237 void i_ddi_parse_name(char *, char **, char **, char **);
238 void i_ddi_set_node_state(dev_info_t *, ddi_node_state_t);
239 int i_ddi_detach_installed_driver(major_t, int);
240 void i_ddi_set_binding_name(dev_info_t *, char *);
241 void i_ddi_bind_devs();
242 void i_ddi_unbind_devs(major_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 void i_ddi_clean_devices_files(void);
265 
266 int i_ddi_devi_get_devid(dev_t, dev_info_t *, ddi_devid_t *);
267 
268 int e_ddi_devid_discovery(ddi_devid_t);
269 
270 int e_devid_cache_register(dev_info_t *, ddi_devid_t);
271 void e_devid_cache_unregister(dev_info_t *);
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