]>
Commit | Line | Data |
---|---|---|
715f6251 | 1 | /* |
2 | * This file is part of the SPL: Solaris Porting Layer. | |
3 | * | |
4 | * Copyright (c) 2008 Lawrence Livermore National Security, LLC. | |
5 | * Produced at Lawrence Livermore National Laboratory | |
6 | * Written by: | |
7 | * Brian Behlendorf <behlendorf1@llnl.gov>, | |
8 | * Herb Wartens <wartens2@llnl.gov>, | |
9 | * Jim Garlick <garlick@llnl.gov> | |
10 | * UCRL-CODE-235197 | |
11 | * | |
12 | * This is free software; you can redistribute it and/or modify it | |
13 | * under the terms of the GNU General Public License as published by | |
14 | * the Free Software Foundation; either version 2 of the License, or | |
15 | * (at your option) any later version. | |
16 | * | |
17 | * This is distributed in the hope that it will be useful, but WITHOUT | |
18 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
19 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
20 | * for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU General Public License along | |
23 | * with this program; if not, write to the Free Software Foundation, Inc., | |
24 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
25 | */ | |
26 | ||
23f28c4f | 27 | #ifndef _SPL_SUNDDI_H |
28 | #define _SPL_SUNDDI_H | |
29 | ||
4e62fd41 | 30 | #include <sys/cred.h> |
31 | #include <sys/uio.h> | |
32 | #include <sys/sunldi.h> | |
33 | #include <sys/mutex.h> | |
b53c565e | 34 | #include <sys/u8_textprep.h> |
4e62fd41 | 35 | #include <linux/kdev_t.h> |
36 | #include <linux/fs.h> | |
37 | #include <linux/cdev.h> | |
38 | #include <linux/list.h> | |
46c685d0 | 39 | #include <spl-device.h> |
4e62fd41 | 40 | |
41 | typedef int ddi_devid_t; | |
42 | ||
43 | typedef enum { | |
44 | DDI_INFO_DEVT2DEVINFO = 0, | |
45 | DDI_INFO_DEVT2INSTANCE = 1 | |
46 | } ddi_info_cmd_t; | |
47 | ||
48 | typedef enum { | |
49 | DDI_ATTACH = 0, | |
50 | DDI_RESUME = 1, | |
51 | DDI_PM_RESUME = 2 | |
52 | } ddi_attach_cmd_t; | |
53 | ||
54 | typedef enum { | |
55 | DDI_DETACH = 0, | |
56 | DDI_SUSPEND = 1, | |
57 | DDI_PM_SUSPEND = 2, | |
58 | DDI_HOTPLUG_DETACH = 3 | |
59 | } ddi_detach_cmd_t; | |
60 | ||
61 | typedef enum { | |
62 | DDI_RESET_FORCE = 0 | |
63 | } ddi_reset_cmd_t; | |
64 | ||
65 | typedef enum { | |
66 | PROP_LEN = 0, | |
67 | PROP_LEN_AND_VAL_BUF = 1, | |
68 | PROP_LEN_AND_VAL_ALLOC = 2, | |
69 | PROP_EXISTS = 3 | |
70 | } ddi_prop_op_t; | |
71 | ||
72 | typedef void *devmap_cookie_t; | |
73 | typedef struct as { | |
74 | uchar_t a_flags; | |
75 | } as_t; | |
76 | ||
77 | typedef struct pollhead { | |
78 | struct polldat *ph_list; | |
79 | } pollhead_t; | |
80 | ||
81 | typedef struct dev_info { | |
82 | kmutex_t di_lock; | |
83 | struct dev_ops *di_ops; | |
84 | struct cdev *di_cdev; | |
46c685d0 | 85 | spl_class *di_class; |
25557fd8 | 86 | spl_device *di_device; |
4e62fd41 | 87 | major_t di_major; |
88 | minor_t di_minor; | |
89 | dev_t di_dev; | |
90 | unsigned di_minors; | |
6a1c3d41 | 91 | int di_flags; |
4e62fd41 | 92 | struct list_head di_list; |
93 | } dev_info_t; | |
94 | ||
95 | typedef struct cb_ops { | |
96 | int (*cb_open)(dev_t *devp, int flag, int otyp, cred_t *credp); | |
97 | int (*cb_close)(dev_t dev, int flag, int otyp, cred_t *credp); | |
98 | int (*cb_strategy)(void *bp); | |
99 | int (*cb_print)(dev_t dev, char *str); | |
100 | int (*cb_dump)(dev_t dev, caddr_t addr, daddr_t blkno, int nblk); | |
101 | int (*cb_read)(dev_t dev, struct uio *uiop, cred_t *credp); | |
102 | int (*cb_write)(dev_t dev, struct uio *uiop, cred_t *credp); | |
103 | int (*cb_ioctl)(dev_t dev, int cmd, intptr_t arg, int mode, | |
104 | cred_t *credp, int *rvalp); | |
105 | int (*cb_devmap)(dev_t dev, devmap_cookie_t dhp, offset_t off, | |
106 | size_t len, size_t *maplen, uint_t model); | |
107 | int (*cb_mmap)(dev_t dev, off_t off, int prot); | |
108 | int (*cb_segmap)(dev_t dev, off_t off, struct as *asp, | |
109 | caddr_t *addrp, off_t len, unsigned int prot, | |
110 | unsigned int maxprot, unsigned int flags, | |
111 | cred_t *credp); | |
112 | int (*cb_chpoll)(dev_t dev, short events, int anyyet, | |
113 | short *reventsp, struct pollhead **phpp); | |
114 | int (*cb_prop_op)(dev_t dev, dev_info_t *dip, | |
115 | ddi_prop_op_t prop_op, int mod_flags, | |
116 | char *name, caddr_t valuep, int *length); | |
117 | struct streamtab *cb_str; | |
118 | int cb_flag; | |
119 | int cb_rev; | |
120 | int (*cb_aread)(dev_t dev, struct aio_req *aio, cred_t *credp); | |
121 | int (*cb_awrite)(dev_t dev, struct aio_req *aio, cred_t *credp); | |
122 | } cb_ops_t; | |
123 | ||
124 | typedef struct dev_ops { | |
125 | int devo_rev; | |
126 | int devo_refcnt; | |
127 | ||
128 | int (*devo_getinfo)(dev_info_t *dip, | |
129 | ddi_info_cmd_t infocmd, void *arg, void **result); | |
130 | int (*devo_identify)(dev_info_t *dip); | |
131 | int (*devo_probe)(dev_info_t *dip); | |
132 | int (*devo_attach)(dev_info_t *dip, ddi_attach_cmd_t cmd); | |
133 | int (*devo_detach)(dev_info_t *dip, ddi_detach_cmd_t cmd); | |
134 | int (*devo_reset)(dev_info_t *dip, ddi_reset_cmd_t cmd); | |
135 | ||
136 | struct cb_ops *devo_cb_ops; | |
137 | struct bus_ops *devo_bus_ops; | |
138 | int (*devo_power)(dev_info_t *dip, int component, int level); | |
139 | } dev_ops_t; | |
140 | ||
141 | typedef struct mod_ops { | |
142 | int (*modm_install)(void); | |
143 | int (*modm_remove)(void); | |
144 | int (*modm_info)(void); | |
145 | } mod_ops_t; | |
146 | ||
147 | typedef struct modldrv { | |
148 | struct mod_ops *drv_modops; | |
149 | char *drv_linkinfo; | |
150 | struct dev_ops *drv_dev_ops; | |
151 | struct dev_info *drv_dev_info; | |
152 | } modldrv_t; | |
153 | ||
154 | #define MODREV_1 1 | |
155 | ||
156 | #define D_NEW 0x000 | |
157 | #define D_MP 0x020 | |
158 | #define D_64BIT 0x200 | |
159 | ||
160 | #define DEVO_REV 3 | |
161 | #define CB_REV 1 | |
162 | ||
163 | #define DDI_SUCCESS 0 | |
164 | #define DDI_FAILURE -1 | |
165 | ||
166 | #define DDI_PSEUDO "ddi_pseudo" | |
167 | ||
168 | #define nodev NULL | |
169 | #define nochpoll NULL | |
170 | #define nulldev NULL | |
171 | #define mod_driverops NULL | |
172 | #define ddi_prop_op NULL | |
173 | ||
b831734a | 174 | #define getminor(x) (x) |
175 | #define getmajor(x) (x) | |
176 | #define ddi_driver_major(di) getmajor(di->di_dev) | |
4e62fd41 | 177 | |
6ab69573 | 178 | #define DDI_DEV_T_NONE ((dev_t)-1) |
179 | #define DDI_DEV_T_ANY ((dev_t)-2) | |
180 | #define DDI_MAJOR_T_UNKNOWN ((major_t)0) | |
181 | ||
182 | #define DDI_PROP_DONTPASS 0x0001 | |
183 | #define DDI_PROP_CANSLEEP 0x0002 | |
184 | ||
6a1c3d41 | 185 | #define GLOBAL_DEV 0x02 |
186 | #define NODEBOUND_DEV 0x04 | |
187 | #define NODESPECIFIC_DEV 0x06 | |
188 | #define ENUMERATED_DEV 0x08 | |
189 | ||
6ab69573 | 190 | #define ddi_prop_lookup_string(x1,x2,x3,x4,x5) (*x5 = NULL) |
191 | #define ddi_prop_free(x) (void)0 | |
192 | #define ddi_root_node() (void)0 | |
193 | ||
4e62fd41 | 194 | #define mod_install(x) 0 |
195 | #define mod_remove(x) 0 | |
196 | ||
197 | extern int __ddi_create_minor_node(dev_info_t *dip, char *name, int spec_type, | |
198 | minor_t minor_num, char *node_type, | |
6a1c3d41 | 199 | int flags, struct module *mod); |
4e62fd41 | 200 | extern void __ddi_remove_minor_node(dev_info_t *dip, char *name); |
201 | extern int __mod_install(struct modlinkage *modlp); | |
202 | extern int __mod_remove(struct modlinkage *modlp); | |
203 | ||
2ee63a54 BB |
204 | extern int ddi_strtoul(const char *, char **, int, unsigned long *); |
205 | extern int ddi_strtol(const char *, char **, int, long *); | |
206 | extern int ddi_strtoull(const char *, char **, int, unsigned long long *); | |
207 | extern int ddi_strtoll(const char *, char **, int, long long *); | |
208 | ||
4e62fd41 | 209 | static __inline__ void ddi_report_dev(dev_info_t *d) { } |
210 | static __inline__ void ddi_prop_remove_all(dev_info_t *dip) { } | |
211 | ||
6a1c3d41 | 212 | static __inline__ void |
213 | ddi_remove_minor_node(dev_info_t *di, char *name) | |
214 | { | |
215 | #ifdef HAVE_GPL_ONLY_SYMBOLS | |
216 | /* Cleanup udev (GPL-only symbols required). This is performed as | |
217 | * part of an inline function to ensure that these symbols are not | |
218 | * linked against the SPL which is GPL'ed. But instead they are | |
219 | * linked against the package building against the SPL to ensure | |
220 | * its license allows linking with GPL-only symbols. */ | |
221 | if (di->di_class) { | |
222 | spl_device_destroy(di->di_class, di->di_device, di->di_dev); | |
223 | spl_class_destroy(di->di_class); | |
224 | di->di_class = NULL; | |
225 | di->di_dev = 0; | |
226 | } | |
227 | #endif | |
228 | ||
229 | __ddi_remove_minor_node(di, name); | |
230 | } | |
231 | ||
4e62fd41 | 232 | static __inline__ int |
233 | ddi_create_minor_node(dev_info_t *di, char *name, int spec_type, | |
6a1c3d41 | 234 | minor_t minor_num, char *node_type, int flags) |
4e62fd41 | 235 | { |
6a1c3d41 | 236 | int rc; |
237 | ||
238 | rc = __ddi_create_minor_node(di, name, spec_type, minor_num, | |
239 | node_type, flags, THIS_MODULE); | |
240 | if (rc) | |
241 | return rc; | |
242 | ||
243 | #ifdef HAVE_GPL_ONLY_SYMBOLS | |
244 | /* Setup udev (GPL-only symbols required). This is performed as | |
245 | * part of an inline function to ensure that these symbols are not | |
246 | * linked against the SPL which is GPL'ed. But instead they are | |
247 | * linked against the package building against the SPL to ensure | |
248 | * its license allows linking with GPL-only symbols. */ | |
249 | di->di_class = spl_class_create(THIS_MODULE, name); | |
250 | if (IS_ERR(di->di_class)) { | |
251 | rc = PTR_ERR(di->di_class); | |
252 | di->di_class = NULL; | |
253 | ddi_remove_minor_node(di, name); | |
254 | CERROR("Error creating %s class, %d\n", name, rc); | |
255 | RETURN(DDI_FAILURE); | |
256 | } | |
257 | ||
258 | /* Do not append a 0 to devices with minor nums of 0 */ | |
259 | di->di_device = spl_device_create(di->di_class, NULL, di->di_dev, NULL, | |
260 | (di->di_minor == 0) ? "%s" : "%s%d", | |
261 | name, di->di_minor); | |
262 | #endif | |
263 | ||
264 | return rc; | |
4e62fd41 | 265 | } |
266 | ||
267 | #undef mod_install | |
268 | #undef mod_remove | |
269 | ||
4e62fd41 | 270 | #define mod_install __mod_install |
271 | #define mod_remove __mod_remove | |
272 | ||
23f28c4f | 273 | #endif /* SPL_SUNDDI_H */ |