xref: /illumos-gate/usr/src/uts/common/sys/ddi_implfuncs.h (revision 7655c6d53c36750b508636f48c73a2de57754e5a)
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 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 /*
27  * Copyright 2012 Garrett D'Amore <garrett@damore.org>.  All rights reserved.
28  * Copyright 2020 Joshua M. Clulow <josh@sysmgr.org>
29  * Copyright 2023 Oxide Computer Company
30  */
31 
32 #ifndef _SYS_DDI_IMPLFUNCS_H
33 #define	_SYS_DDI_IMPLFUNCS_H
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #include <sys/obpdefs.h>
40 #include <sys/vnode.h>
41 #include <sys/types.h>
42 #include <sys/task.h>
43 #include <sys/project.h>
44 
45 #ifdef	_KERNEL
46 
47 /*
48  * Declare implementation functions that sunddi functions can call in order to
49  * perform their required task.  Each kernel architecture must provide them.
50  */
51 extern int 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 extern int i_ddi_apply_range(dev_info_t *dip, dev_info_t *rdip,
54     struct regspec *rp);
55 extern struct regspec *i_ddi_rnumber_to_regspec(dev_info_t *dip, int rnumber);
56 extern int i_ddi_map_fault(dev_info_t *dip, dev_info_t *rdip,
57     struct hat *hat, struct seg *seg, caddr_t addr,
58     struct devpage *dp, pfn_t pfn, uint_t prot, uint_t lock);
59 
60 /*
61  * Implementation-specific memory allocation and de-allocation routines
62  */
63 extern int i_ddi_mem_alloc(dev_info_t *dip, ddi_dma_attr_t *attributes,
64     size_t length, int cansleep, int streaming,
65     const ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp,
66     size_t *real_length, ddi_acc_hdl_t *handlep);
67 extern void i_ddi_mem_free(caddr_t kaddr, ddi_acc_hdl_t *ap);
68 
69 extern int i_ddi_devi_get_ppa(dev_info_t *);
70 extern void i_ddi_devi_set_ppa(dev_info_t *, int);
71 
72 extern void i_ddi_devacc_to_hatacc(const ddi_device_acc_attr_t *devaccp,
73     uint_t *hataccp);
74 extern void i_ddi_cacheattr_to_hatacc(uint_t flags, uint_t *hataccp);
75 extern boolean_t i_ddi_check_cache_attr(uint_t flags);
76 
77 /*
78  * Access and DMA handle fault set/clear routines
79  */
80 extern void i_ddi_acc_set_fault(ddi_acc_handle_t handle);
81 extern void i_ddi_acc_clr_fault(ddi_acc_handle_t handle);
82 extern void i_ddi_dma_set_fault(ddi_dma_handle_t handle);
83 extern void i_ddi_dma_clr_fault(ddi_dma_handle_t handle);
84 
85 /*
86  * Event-handling functions for rootnex.
87  * These provide the standard implementation of fault handling.
88  */
89 extern void i_ddi_rootnex_init_events(dev_info_t *);
90 extern int i_ddi_rootnex_get_eventcookie(dev_info_t *, dev_info_t *, char *,
91     ddi_eventcookie_t *);
92 extern int i_ddi_rootnex_add_eventcall(dev_info_t *, dev_info_t *,
93     ddi_eventcookie_t, ddi_event_cb_f, void *, ddi_callback_id_t *);
94 extern int i_ddi_rootnex_remove_eventcall(dev_info_t *, ddi_callback_id_t);
95 extern int i_ddi_rootnex_post_event(dev_info_t *, dev_info_t *,
96     ddi_eventcookie_t, void *);
97 
98 /*
99  * Search and return properties from the PROM
100  */
101 extern int impl_ddi_bus_prop_op(dev_t, dev_info_t *, dev_info_t *,
102     ddi_prop_op_t, int, char *, caddr_t, int *);
103 
104 /*
105  * Copy an integer from PROM to native machine representation
106  */
107 extern int impl_ddi_prop_int_from_prom(uchar_t *intp, int n);
108 
109 extern int impl_ddi_sunbus_initchild(dev_info_t *);
110 extern void impl_ddi_sunbus_removechild(dev_info_t *);
111 
112 /*
113  * Implementation-specific access handle allocator and init. routines
114  */
115 extern ddi_acc_handle_t impl_acc_hdl_alloc(int (*waitfp)(caddr_t),
116     caddr_t arg);
117 extern void impl_acc_hdl_free(ddi_acc_handle_t handle);
118 extern ddi_acc_hdl_t *impl_acc_hdl_get(ddi_acc_handle_t handle);
119 extern void impl_acc_hdl_init(ddi_acc_hdl_t *hp);
120 
121 /*
122  * Access error handling support
123  */
124 extern void impl_acc_err_init(ddi_acc_hdl_t *);
125 extern int impl_dma_check(dev_info_t *, const void *, const void *,
126     const void *);
127 extern int i_ddi_ontrap(ddi_acc_handle_t);
128 extern void i_ddi_notrap(ddi_acc_handle_t);
129 extern int i_ddi_prot_trampoline(void);
130 extern int i_ddi_caut_trampoline(void);
131 
132 /*
133  * misc/bootdev entry points - these are private routines and subject
134  * to change
135  */
136 extern int i_devname_to_promname(char *dev_name, char *ret_buf, size_t);
137 extern int i_promname_to_devname(char *prom_name, char *ret_buf);
138 extern char *i_convert_boot_device_name(char *, char *, size_t *);
139 
140 /*
141  * Nodeid management
142  */
143 extern void impl_ddi_init_nodeid(void);
144 extern int impl_ddi_alloc_nodeid(int *);
145 extern int impl_ddi_take_nodeid(int, int);
146 extern void impl_ddi_free_nodeid(int);
147 
148 /*
149  * minorname/devtspectype conversions
150  */
151 extern char *i_ddi_devtspectype_to_minorname(dev_info_t *, dev_t, int);
152 extern int i_ddi_minorname_to_devtspectype(dev_info_t *, const char *, dev_t *,
153     int *);
154 
155 /*
156  * Routines in ddi_v9_asm.s
157  */
158 extern int do_peek(size_t, void *, void *);
159 extern int do_poke(size_t, void *, void *);
160 extern void peek_fault(void);
161 extern void poke_fault(void);
162 extern int peekpoke_mem(ddi_ctl_enum_t, peekpoke_ctlops_t *);
163 
164 /*
165  * Helper functions
166  */
167 extern char *i_ddi_strdup(const char *, uint_t);
168 extern void i_ddi_prop_list_delete(ddi_prop_t *);
169 extern ddi_prop_t *i_ddi_prop_list_dup(ddi_prop_t *, uint_t);
170 extern int i_ddi_load_drvconf(major_t);
171 extern int i_ddi_unload_drvconf(major_t);
172 extern ddi_node_state_t i_ddi_node_state(dev_info_t *);
173 extern int i_ddi_devi_attached(dev_info_t *);
174 extern void i_ddi_parse_name(char *, char **, char **, char **);
175 extern void i_ddi_set_node_state(dev_info_t *, ddi_node_state_t);
176 extern int i_ddi_detach_installed_driver(major_t, int);
177 extern void i_ddi_set_binding_name(dev_info_t *, char *);
178 extern void i_ddi_bind_devs(void);
179 extern int i_ddi_unbind_devs_by_alias(major_t, char *);
180 extern void i_ddi_unbind_devs(major_t);
181 extern ddi_prop_list_t *i_ddi_prop_list_create(ddi_prop_t *);
182 struct devnames;
183 extern void i_ddi_prop_list_hold(ddi_prop_list_t *, struct devnames *);
184 extern void i_ddi_prop_list_rele(ddi_prop_list_t *, struct devnames *);
185 extern ddi_prop_t *i_ddi_prop_search(dev_t, char *, uint_t, ddi_prop_t **);
186 extern int resolve_pathname(const char *, dev_info_t **, dev_t *, int *);
187 extern int i_ddi_prompath_to_devfspath(char *, char *);
188 extern int i_ddi_attach_node_hierarchy(dev_info_t *);
189 extern dev_info_t *i_ddi_attach_pseudo_node(char *);
190 extern int i_ddi_attach_hw_nodes(char *);
191 extern int i_ddi_devs_attached(major_t);
192 extern int i_ddi_minor_node_count(dev_info_t *, const char *);
193 extern int ddi_is_pci_dip(dev_info_t *dip);
194 
195 /*
196  * Non-DDI functions: wrapper around mod_hold/rele_dev_by_major()
197  */
198 extern struct dev_ops *ddi_hold_driver(major_t);
199 extern void ddi_rele_driver(major_t);
200 
201 /*
202  * /etc/devices cache files management
203  */
204 extern void i_ddi_devices_init(void);
205 extern void i_ddi_read_devices_files(void);
206 extern void i_ddi_clean_devices_files(void);
207 
208 /*
209  * devid cache
210  */
211 extern void devid_cache_init(void);
212 extern void devid_cache_read(void);
213 extern void devid_cache_cleanup(void);
214 extern int i_ddi_devi_get_devid(dev_t, dev_info_t *, ddi_devid_t *);
215 extern int e_ddi_devid_discovery(ddi_devid_t);
216 extern int e_devid_cache_register(dev_info_t *, ddi_devid_t);
217 extern void e_devid_cache_unregister(dev_info_t *);
218 extern int e_devid_cache_to_devt_list(ddi_devid_t, const char *, int *,
219     dev_t **);
220 extern void e_devid_cache_free_devt_list(int, dev_t *);
221 
222 /*
223  * I/O retire persistent store
224  */
225 extern void retire_store_init(void);
226 extern void retire_store_read(void);
227 extern int e_ddi_retire_persist(char *);
228 extern int e_ddi_retire_unpersist(char *);
229 extern int e_ddi_device_retired(char *);
230 
231 /*
232  * Resource control functions to lock down device memory
233  */
234 extern int i_ddi_incr_locked_memory(proc_t *, rctl_qty_t);
235 extern void i_ddi_decr_locked_memory(proc_t *, rctl_qty_t);
236 
237 /*
238  * Direct I/O support functions
239  */
240 extern void translate_devid(dev_info_t *dip);
241 
242 /*
243  * Support routine for file systems that need to scan block devices searching
244  * for a label as part of mounting the root file system.
245  */
246 extern void preroot_walk_block_devices(int (*)(const char *, void *), void *);
247 
248 #define	PREROOT_WALK_BLOCK_DEVICES_NEXT		1
249 #define	PREROOT_WALK_BLOCK_DEVICES_CANCEL	2
250 
251 
252 #endif	/* _KERNEL */
253 
254 #ifdef	__cplusplus
255 }
256 #endif
257 
258 #endif	/* _SYS_DDI_IMPLFUNCS_H */
259