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