xref: /illumos-gate/usr/src/uts/common/sys/sunldi.h (revision 5f61829ae051c3c632fdee24571c7e9eb5dcce8b)
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  * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef	_SYS_SUNLDI_H
26 #define	_SYS_SUNLDI_H
27 
28 #include <sys/modctl.h>
29 #include <sys/stream.h>
30 #include <sys/open.h>
31 
32 /*
33  * DDI interfaces for Layered driver support.
34  */
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #ifdef	_KERNEL
41 
42 
43 /*
44  * Opaque layered driver data structures.
45  *
46  * The contents of these data structures are private to this
47  * implementation of Solaris and are subject to change at any
48  * time without notice.
49  *
50  * Applications and drivers accessing the contents of these structures
51  * directly will fail to run on future releases.
52  */
53 typedef struct __ldi_ident		*ldi_ident_t;
54 
55 typedef struct __ldi_handle		*ldi_handle_t;
56 
57 typedef struct __ldi_callback_id	*ldi_callback_id_t;
58 
59 typedef struct __ldi_ev_cookie		*ldi_ev_cookie_t;
60 
61 /*
62  * LDI event interface related
63  */
64 #define	LDI_EV_SUCCESS	0
65 #define	LDI_EV_FAILURE	(-1)
66 #define	LDI_EV_NONE	(-2)	/* no matching callbacks registered */
67 #define	LDI_EV_OFFLINE	"LDI:EVENT:OFFLINE"
68 #define	LDI_EV_DEGRADE	"LDI:EVENT:DEGRADE"
69 #define	LDI_EV_DEVICE_REMOVE	"LDI:EVENT:DEVICE_REMOVE"
70 
71 #define	LDI_EV_CB_VERS_1	1
72 #define	LDI_EV_CB_VERS		LDI_EV_CB_VERS_1
73 
74 typedef struct ldi_ev_callback {
75 	uint_t cb_vers;
76 	int (*cb_notify)(ldi_handle_t, ldi_ev_cookie_t, void *, void *);
77 	void (*cb_finalize)(ldi_handle_t, ldi_ev_cookie_t, int, void *, void *);
78 } ldi_ev_callback_t;
79 
80 /*
81  * LDI Ident manipulation functions
82  */
83 extern ldi_ident_t ldi_ident_from_anon(void);
84 
85 extern int ldi_ident_from_mod(struct modlinkage *, ldi_ident_t *);
86 extern int ldi_ident_from_major(major_t major, ldi_ident_t *);
87 extern int ldi_ident_from_dip(dev_info_t *dip, ldi_ident_t *);
88 extern int ldi_ident_from_dev(dev_t, ldi_ident_t *);
89 extern int ldi_ident_from_stream(struct queue *, ldi_ident_t *);
90 extern void ldi_ident_release(ldi_ident_t);
91 
92 
93 /*
94  * LDI Handle manipulation functions
95  */
96 extern int ldi_open_by_dev(dev_t *, int, int, cred_t *,
97     ldi_handle_t *, ldi_ident_t);
98 extern int ldi_open_by_name(const char *, int, cred_t *,
99     ldi_handle_t *, ldi_ident_t);
100 extern int ldi_open_by_devid(ddi_devid_t, const char *, int, cred_t *,
101     ldi_handle_t *, ldi_ident_t);
102 extern int ldi_vp_from_name(const char *, vnode_t **);
103 extern int ldi_vp_from_devid(ddi_devid_t, const char *, vnode_t **);
104 
105 extern int ldi_close(ldi_handle_t, int flag, cred_t *);
106 
107 extern int ldi_read(ldi_handle_t, struct uio *, cred_t *);
108 extern int ldi_write(ldi_handle_t, struct uio *, cred_t *);
109 extern int ldi_ioctl(ldi_handle_t, int, intptr_t, int, cred_t *, int *);
110 extern int ldi_poll(ldi_handle_t, short, int, short *, struct pollhead **);
111 extern int ldi_get_size(ldi_handle_t, uint64_t *);
112 extern int ldi_prop_op(ldi_handle_t, ddi_prop_op_t, int,
113     char *, caddr_t, int *);
114 
115 extern int ldi_strategy(ldi_handle_t, struct buf *);
116 extern int ldi_dump(ldi_handle_t, caddr_t, daddr_t, int);
117 extern int ldi_devmap(ldi_handle_t, devmap_cookie_t, offset_t,
118     size_t, size_t *, uint_t);
119 extern int ldi_aread(ldi_handle_t, struct aio_req *, cred_t *);
120 extern int ldi_awrite(ldi_handle_t, struct aio_req *, cred_t *);
121 
122 extern int ldi_putmsg(ldi_handle_t, mblk_t *);
123 extern int ldi_getmsg(ldi_handle_t, mblk_t **, timestruc_t *);
124 
125 extern int ldi_prop_lookup_int_array(ldi_handle_t lh,
126     uint_t flags, char *name, int **data, uint_t *nelements);
127 extern int ldi_prop_lookup_int64_array(ldi_handle_t lh,
128     uint_t flags, char *name, int64_t **data, uint_t *nelements);
129 extern int ldi_prop_lookup_string_array(ldi_handle_t lh,
130     uint_t flags, char *name, char ***data, uint_t *nelements);
131 extern int ldi_prop_lookup_string(ldi_handle_t lh,
132     uint_t flags, char *name, char **data);
133 extern int ldi_prop_lookup_byte_array(ldi_handle_t lh,
134     uint_t flags, char *name, uchar_t **data, uint_t *nelements);
135 extern int ldi_prop_get_int(ldi_handle_t lh,
136     uint_t flags, char *name, int defvalue);
137 extern int64_t ldi_prop_get_int64(ldi_handle_t lh,
138     uint_t flags, char *name, int64_t defvalue);
139 extern int ldi_prop_exists(ldi_handle_t lh,
140     uint_t flags, char *name);
141 
142 extern int ldi_get_dev(ldi_handle_t, dev_t *);
143 extern int ldi_get_otyp(ldi_handle_t, int *);
144 extern int ldi_get_devid(ldi_handle_t, ddi_devid_t *);
145 extern int ldi_get_minor_name(ldi_handle_t, char **);
146 
147 /*
148  * LDI events related declarations
149  */
150 extern int ldi_ev_get_cookie(ldi_handle_t lh, char *evname,
151     ldi_ev_cookie_t *cookiep);
152 extern char *ldi_ev_get_type(ldi_ev_cookie_t cookie);
153 extern int ldi_ev_register_callbacks(ldi_handle_t lh,
154     ldi_ev_cookie_t cookie, ldi_ev_callback_t *callb,
155     void *arg, ldi_callback_id_t *id);
156 extern int ldi_ev_notify(dev_info_t *dip, minor_t minor, int spec_type,
157     ldi_ev_cookie_t cookie, void *ev_data);
158 extern void ldi_ev_finalize(dev_info_t *dip, minor_t minor, int spec_type,
159     int ldi_result, ldi_ev_cookie_t cookie, void *ev_data);
160 extern int ldi_ev_remove_callbacks(ldi_callback_id_t id);
161 
162 #endif	/* _KERNEL */
163 
164 #ifdef	__cplusplus
165 }
166 #endif
167 
168 #endif	/* _SYS_SUNLDI_H */
169