xref: /titanic_52/usr/src/uts/common/sys/ddi_implfuncs.h (revision 03831d35f7499c87d51205817c93e9a8d42c4bae)
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 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, int streaming);
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 /*
95  * Access and DMA handle fault set/clear routines
96  */
97 void
98 i_ddi_acc_set_fault(ddi_acc_handle_t handle);
99 void
100 i_ddi_acc_clr_fault(ddi_acc_handle_t handle);
101 void
102 i_ddi_dma_set_fault(ddi_dma_handle_t handle);
103 void
104 i_ddi_dma_clr_fault(ddi_dma_handle_t handle);
105 
106 /*
107  *      Event-handling functions for rootnex
108  *      These provide the standard implementation of fault handling
109  */
110 void
111 i_ddi_rootnex_init_events(dev_info_t *dip);
112 
113 int
114 i_ddi_rootnex_get_eventcookie(dev_info_t *dip, dev_info_t *rdip,
115 	char *eventname, ddi_eventcookie_t *cookiep);
116 int
117 i_ddi_rootnex_add_eventcall(dev_info_t *dip, dev_info_t *rdip,
118 	ddi_eventcookie_t eventid, void (*handler)(dev_info_t *dip,
119 	ddi_eventcookie_t event, void *arg, void *impl_data), void *arg,
120 	ddi_callback_id_t *cb_id);
121 int
122 i_ddi_rootnex_remove_eventcall(dev_info_t *devi, ddi_callback_id_t cb_id);
123 
124 int
125 i_ddi_rootnex_post_event(dev_info_t *dip, dev_info_t *rdip,
126 	ddi_eventcookie_t eventid, void *impl_data);
127 
128 /*
129  * Clustering: Return the global devices path base, or
130  * the entire global devices path prefix.
131  */
132 const char *
133 i_ddi_get_dpath_base();
134 
135 const char *
136 i_ddi_get_dpath_prefix();
137 
138 /*
139  * Search and return properties from the PROM
140  */
141 int
142 impl_ddi_bus_prop_op(dev_t dev, dev_info_t *dip,
143 	dev_info_t *ch_dip, ddi_prop_op_t prop_op, int mod_flags,
144 	char *name, caddr_t valuep, int *lengthp);
145 
146 /*
147  * Copy an integer from PROM to native machine representation
148  */
149 int
150 impl_ddi_prop_int_from_prom(uchar_t *intp, int n);
151 
152 
153 extern int impl_ddi_sunbus_initchild(dev_info_t *);
154 extern void impl_ddi_sunbus_removechild(dev_info_t *);
155 
156 /*
157  * Implementation specific access handle allocator and init. routines
158  */
159 extern ddi_acc_handle_t impl_acc_hdl_alloc(int (*waitfp)(caddr_t),
160 	caddr_t arg);
161 extern void impl_acc_hdl_free(ddi_acc_handle_t handle);
162 
163 extern ddi_acc_hdl_t *impl_acc_hdl_get(ddi_acc_handle_t handle);
164 extern void impl_acc_hdl_init(ddi_acc_hdl_t *hp);
165 
166 /* access error handling support */
167 extern void impl_acc_err_init(ddi_acc_hdl_t *);
168 extern int i_ddi_ontrap(ddi_acc_handle_t);
169 extern void i_ddi_notrap(ddi_acc_handle_t);
170 extern int i_ddi_prot_trampoline();
171 extern int i_ddi_caut_trampoline();
172 
173 /*
174  * misc/bootdev entry points - these are private routines and subject
175  * to change.
176  */
177 extern int
178 i_devname_to_promname(char *dev_name, char *ret_buf, size_t);
179 
180 extern int
181 i_promname_to_devname(char *prom_name, char *ret_buf);
182 
183 extern char *
184 i_convert_boot_device_name(char *, char *, size_t *);
185 
186 /*
187  * Nodeid management ...
188  */
189 void impl_ddi_init_nodeid(void);
190 int impl_ddi_alloc_nodeid(int *nodeid);
191 int impl_ddi_take_nodeid(int nodeid, int kmflag);
192 void impl_ddi_free_nodeid(int nodeid);
193 
194 /*
195  * minorname/devtspectype conversions
196  */
197 extern char *
198 i_ddi_devtspectype_to_minorname(dev_info_t *dip, dev_t dev, int spec_type);
199 
200 extern int
201 i_ddi_minorname_to_devtspectype(dev_info_t *dip, char *minor_name,
202 	dev_t *devp, int *spectypep);
203 
204 /*
205  * Routines in ddi_v9_asm.s
206  */
207 extern int do_peek(size_t, void *, void *);
208 extern int do_poke(size_t, void *, void *);
209 extern void peek_fault(void);
210 extern void poke_fault(void);
211 extern int peekpoke_mem(ddi_ctl_enum_t, peekpoke_ctlops_t *);
212 
213 /*
214  * Helper functions
215  */
216 char *i_ddi_strdup(char *, uint_t);
217 void i_ddi_prop_list_delete(ddi_prop_t *);
218 ddi_prop_t *i_ddi_prop_list_dup(ddi_prop_t *, uint_t);
219 int i_ddi_load_drvconf(major_t);
220 int i_ddi_unload_drvconf(major_t);
221 ddi_node_state_t i_ddi_node_state(dev_info_t *);
222 int i_ddi_devi_attached(dev_info_t *);
223 void i_ddi_parse_name(char *, char **, char **, char **);
224 void i_ddi_set_node_state(dev_info_t *, ddi_node_state_t);
225 int i_ddi_detach_installed_driver(major_t, int);
226 void i_ddi_set_binding_name(dev_info_t *, char *);
227 void i_ddi_bind_devs();
228 void i_ddi_unbind_devs(major_t);
229 ddi_prop_list_t *i_ddi_prop_list_create(ddi_prop_t *);
230 struct devnames;
231 void i_ddi_prop_list_hold(ddi_prop_list_t *, struct devnames *);
232 void i_ddi_prop_list_rele(ddi_prop_list_t *, struct devnames *);
233 ddi_prop_t *i_ddi_prop_search(dev_t, char *, uint_t, ddi_prop_t **);
234 int resolve_pathname(char *, dev_info_t **, dev_t *, int *);
235 int i_ddi_prompath_to_devfspath(char *, char *);
236 int i_ddi_attach_node_hierarchy(dev_info_t *);
237 dev_info_t *i_ddi_attach_pseudo_node(char *);
238 int i_ddi_attach_hw_nodes(char *);
239 int i_ddi_devs_attached(major_t);
240 
241 /* non-DDI functions: wrapper around mod_hold/rele_dev_by_major() */
242 struct dev_ops *ddi_hold_driver(major_t);
243 void ddi_rele_driver(major_t);
244 
245 /*
246  * devid cache
247  */
248 void i_ddi_devices_init(void);
249 void i_ddi_read_devices_files(void);
250 void i_ddi_clean_devices_files(void);
251 
252 int i_ddi_devi_get_devid(dev_t, dev_info_t *, ddi_devid_t *);
253 
254 int e_ddi_devid_discovery(ddi_devid_t);
255 
256 int e_devid_cache_register(dev_info_t *, ddi_devid_t);
257 void e_devid_cache_unregister(dev_info_t *);
258 
259 int e_devid_cache_to_devt_list(ddi_devid_t, char *, int *, dev_t **);
260 void e_devid_cache_free_devt_list(int, dev_t *);
261 
262 /*
263  * Resource control functions to lock down device memory.
264  */
265 extern int i_ddi_incr_locked_memory(proc_t *, task_t *, kproject_t *,
266 	zone_t *, rctl_qty_t);
267 extern void i_ddi_decr_locked_memory(proc_t *, task_t *, kproject_t *,
268 	zone_t *, rctl_qty_t);
269 
270 #endif	/* _KERNEL */
271 
272 #ifdef	__cplusplus
273 }
274 #endif
275 
276 #endif	/* _SYS_DDI_IMPLFUNCS_H */
277