summaryrefslogtreecommitdiff
path: root/usr/src/man/man9e/usba_hcdi_cb_ops.9e
blob: bdd31bc57026ebaa8c62b2678494e3bd2bc663a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
.\"
.\" This file and its contents are supplied under the terms of the
.\" Common Development and Distribution License ("CDDL"), version 1.0.
.\" You may only use this file in accordance with the terms of version
.\" 1.0 of the CDDL.
.\"
.\" A full copy of the text of the CDDL should have accompanied this
.\" source.  A copy of the CDDL is also available via the Internet at
.\" http://www.illumos.org/license/CDDL.
.\"
.\"
.\" Copyright 2016 Joyent, Inc.
.\"
.Dd Dec 20, 2016
.Dt USBA_HCDI_CB_OPS 9E
.Os
.Sh NAME
.Nm usba_hcdi_cb_ops ,
.Nm usba_hcdi_cb_open ,
.Nm usba_hcdi_cb_ioctl ,
.Nm usba_hcdi_cb_close
.Nd USBA HCD Character Device character functions
.Sh SYNOPSIS
.In sys/types.h
.In sys/file.h
.In sys/errno.h
.In sys/open.h
.In sys/cred.h
.In sys/ddi.h
.In sys/sunddi.h
.Ft int
.Fo prefix_open
.Fa "dev_t *devp"
.Fa "int flag"
.Fa "int otyp"
.Fa "cred_t *credp"
.Fc
.Ft int
.Fo prefix_ioctl
.Fa "dev_t dev"
.Fa "int cmd"
.Fa "intptr_t arg"
.Fa "int mode"
.Fa "cred_t *cred_p"
.Fa "int *rval_p"
.Fc
.Ft int
.Fo prefix_close
.Fa "dev_t dev"
.Fa "int flag"
.Fa "int otyp"
.Fa "cred_t *cred_p"
.Fc
.Sh INTERFACE LEVEL
.Sy Volatile -
illumos USB HCD private function
.Pp
This describes private interfaces that are not part of the stable DDI.
This may be removed or changed at any time.
.Sh PARAMETERS
For parameter descriptions, see
.Xr open 9E ,
.Xr ioctl 9E ,
and
.Xr close 9E .
.Sh DESCRIPTION
The entry points listed here are the traditional character device
.Xr open 9E ,
.Xr ioctl 9E ,
and
.Xr close 9E
entry points.
As discussed in
.Xr usba_hcdi 9E
all HCD drivers are required to implement these functions and vector
them to
.Xr usba_hubdi_open 9F ,
.Xr usba_hubdi_ioctl 9F ,
and
.Xr usba_hubdi_close 9F
respectively.
For background information on these functions and how they interact in the
broader operating system, please see the general manual pages
.Xr open 9E ,
.Xr ioctl 9E ,
and
.Xr close 9E .
.Pp
The arguments between the two types of functions are slightly different.
The
.Sx EXAMPLES
section provides a sketch for how most HCD drivers should perform those
transformations.
.Pp
One important distinction from the traditional character routines is
that the USBA controls a bit more of the minor space.
Therefore, the driver needs to take extra care around the values encoded in the
.Sy dev_t
and it should not perform any cloning or renumbering in its
.Xr open 9E
entry point.
.Sh EXAMPLES
The following example is adapated from the
.Xr xhci 4D
driver which shows how an HCD driver might arrange things.
This assumes that a driver is following the recommendations in
.Xr usba_hcdi 9E
and has initialized a soft state structure through the
.Xr ddi_soft_state_init 9F
function.
This design also requires that the soft state structure contains a pointer to
the
.Sy dev_info_t
structure during its
.Xr attach 9E callback.
.Pp
This example does not stand alone, it will need to be adapted for a
driver:
.Bd -literal
#include <sys/types.h>
#include <sys/file.h>
#include <sys/errno.h>
#include <sys/open.h>
#include <sys/cred.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>

static void *prefix_soft_state;

/*
 * Per-instance structure
 */
typedef struct prefix {
	dev_info_t	*prefix_dev_info;
	...
} prefix_t;

static dev_info_t *
prefix_get_dip(dev_t dev)
{
	prefix_t *p;
	int instance = getminor(dev) & ~HUBD_IS_ROOT_HUB;

	p = ddi_get_soft_state(prefix_soft_state, instance);
	if (p != NULL)
		return (p->prefix_dip);
	return (NULL);
}

static int
prefix_open(dev_t *devp, int flags, int otyp, cred_t *credp)
{
	dev_info_t *dip = prefix_get_dip(*devp);

	return (usba_hubdi_open(dip, devp, flags, otyp, credp));
}

static int
prefix_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp,
    int *rvalp)
{
	dev_info_t *dip = prefix_get_dip(dev);

	/* Potentially handle private ioctls */

	return (usba_hubdi_ioctl(dip, dev, cmd, arg, mode, credp, rvalp));
}

static int
prefix_close(dev_t dev, int flag, int otyp, cred_t *credp)
{
	dev_info_t *dip = prefix_get_dip(dev);

	return (usba_hubdi_close(dip, dev, flag, otyp, credp));
}

static int
prefix_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
{
	int instance;
	prefix_t *p;

	/* Perform normal checking of cmd */

	instance = ddi_get_instance(dip);
	if (ddi_soft_state_zalloc(prefix_soft_state, inst) != 0)
		return (DDI_FAILURE);
	p = ddi_get_soft_state(prefix_soft_state, instance);
	p->prefix_dev_info = dip;

	/* Continue with normal attach(9E) initialization */
}

int
_init(void)
{
	int ret;

	if ((ret = ddi_soft_state_init(&prefx_soft_state, sizeof (prefx_t),
	    0)) != 0) {
		return (ret);
	}

	/* Perform normal module initialization here */

	return (ret);
}

int
_fini(void)
{

	/* Perform normal module teardown first */

	ddi_soft_state_fini(&prefix_soft_state);

	return (0);
}
.Ed
.Sh SEE ALSO
.Xr xhci 4D ,
.Xr attach 9E ,
.Xr close 9E ,
.Xr ioctl 9E ,
.Xr open 9E ,
.Xr usba_hcdi 9E ,
.Xr ddi_soft_state_init 9F ,
.Xr usba_hubdi_close 9F ,
.Xr usba_hubdi_ioctl 9F ,
.Xr usba_hubdi_open 9F