Annotation of sys/dev/usb/usbfvar.h, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: usbfvar.h,v 1.6 2007/06/15 11:41:48 mbalmer Exp $ */
2:
3: /*
4: * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org>
5: *
6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
9: *
10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17: */
18:
19: /*
20: * USB function driver interface
21: *
22: * This file is to be included only by the logical device driver and the
23: * USB device controller (DC) driver.
24: */
25:
26: /*** structures corresponding to USB protocol components ***/
27:
28: struct usbf_endpoint {
29: struct usbf_interface *iface;
30: usb_endpoint_descriptor_t *edesc;
31: int halted; /* UF_ENDPOINT_HALT set */
32: int refcnt;
33: SIMPLEQ_ENTRY(usbf_endpoint) next;
34: };
35:
36: struct usbf_interface {
37: struct usbf_config *config;
38: usb_interface_descriptor_t *idesc;
39: LIST_HEAD(, usbf_pipe) pipes;
40: SIMPLEQ_HEAD(, usbf_endpoint) endpoint_head;
41: SIMPLEQ_ENTRY(usbf_interface) next;
42: };
43:
44: struct usbf_config {
45: struct usbf_device *uc_device;
46: usb_config_descriptor_t *uc_cdesc;
47: size_t uc_cdesc_size;
48: int uc_closed;
49: SIMPLEQ_HEAD(, usbf_interface) iface_head;
50: SIMPLEQ_ENTRY(usbf_config) next;
51: };
52:
53: struct usbf_device {
54: struct device bdev; /* base device */
55: struct usbf_bus *bus; /* device controller */
56: struct usbf_function *function; /* function driver */
57: struct usbf_pipe *default_pipe; /* pipe 0 (device control) */
58: struct usbf_xfer *default_xfer; /* device request xfer */
59: struct usbf_xfer *data_xfer; /* request response xfer */
60: int address; /* assigned by host (or 0) */
61: usbf_config_handle config; /* set by host (or NULL) */
62: usb_status_t status; /* device status */
63: usb_device_request_t def_req; /* device request buffer */
64: struct usbf_endpoint def_ep; /* for pipe 0 */
65: usb_endpoint_descriptor_t def_ep_desc; /* for pipe 0 */
66: usb_device_descriptor_t ddesc; /* device descriptor */
67: usb_string_descriptor_t *sdesc; /* string descriptors */
68: size_t sdesc_size; /* size of ud_sdesc */
69: uByte string_id; /* next string id */
70: SIMPLEQ_HEAD(, usbf_config) configs;
71: };
72:
73: /*** software control structures ***/
74:
75: struct usbf_pipe_methods {
76: usbf_status (*transfer)(usbf_xfer_handle);
77: usbf_status (*start)(usbf_xfer_handle);
78: void (*abort)(usbf_xfer_handle);
79: void (*done)(usbf_xfer_handle);
80: void (*close)(usbf_pipe_handle);
81: };
82:
83: struct usbf_bus_methods {
84: usbf_status (*open_pipe)(struct usbf_pipe *);
85: void (*soft_intr)(void *);
86: usbf_status (*allocm)(struct usbf_bus *, usb_dma_t *, u_int32_t);
87: void (*freem)(struct usbf_bus *, usb_dma_t *);
88: struct usbf_xfer *(*allocx)(struct usbf_bus *);
89: void (*freex)(struct usbf_bus *, struct usbf_xfer *);
90: };
91:
92: struct usbf_softc;
93:
94: struct usbf_bus {
95: /* Filled by DC driver */
96: struct device bdev; /* base device */
97: struct usbf_bus_methods *methods;
98: size_t pipe_size; /* size of pipe struct */
99: u_int8_t ep0_maxp; /* packet size for EP0 */
100: int usbrev; /* as in struct usbd_bus */
101: /* Filled by usbf driver */
102: struct usbf_softc *usbfctl;
103: int intr_context;
104: #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
105: void *soft; /* soft interrupt cookie */
106: #endif
107: bus_dma_tag_t dmatag; /* DMA tag */
108: };
109:
110: struct usbf_port {
111: usb_port_status_t status;
112: u_int8_t portno;
113: struct usbf_device *device; /* connected function */
114: };
115:
116: struct usbf_pipe {
117: struct usbf_device *device;
118: struct usbf_interface *iface; /* unless default pipe */
119: struct usbf_endpoint *endpoint;
120: int refcnt;
121: int running;
122: int aborting;
123: SIMPLEQ_HEAD(, usbf_xfer) queue;
124: LIST_ENTRY(usbf_pipe) next;
125:
126: char repeat;
127: int interval;
128:
129: /* Filled by DC driver. */
130: struct usbf_pipe_methods *methods;
131: };
132:
133: struct usbf_xfer {
134: struct usbf_pipe *pipe;
135: usbf_private_handle priv;
136: void *buffer;
137: u_int32_t length;
138: u_int32_t actlen;
139: u_int16_t flags;
140: u_int32_t timeout;
141: usbf_status status;
142: usbf_callback callback;
143: SIMPLEQ_ENTRY(usbf_xfer) next;
144:
145: /* for memory management */
146: struct usbf_device *device;
147: int rqflags;
148: usb_dma_t dmabuf;
149:
150: struct timeout timeout_handle;
151: };
152:
153:
154: /* usbf.c */
155: void usbf_host_reset(usbf_bus_handle);
156: void usbf_do_request(usbf_xfer_handle, usbf_private_handle,
157: usbf_status);
158:
159: /* usbf_subr.c */
160: usbf_status usbf_new_device(struct device *, usbf_bus_handle, int, int, int,
161: struct usbf_port *);
162: usbf_status usbf_set_endpoint_feature(usbf_config_handle, u_int8_t,
163: u_int16_t);
164: usbf_status usbf_clear_endpoint_feature(usbf_config_handle, u_int8_t,
165: u_int16_t);
166: usbf_status usbf_insert_transfer(usbf_xfer_handle xfer);
167: void usbf_transfer_complete(usbf_xfer_handle xfer);
168: usbf_status usbf_allocmem(usbf_bus_handle, size_t, size_t, usb_dma_t *);
169: void usbf_freemem(usbf_bus_handle, usb_dma_t *);
170: usbf_status usbf_softintr_establish(struct usbf_bus *);
171: void usbf_schedsoftintr(struct usbf_bus *);
CVSweb