Annotation of sys/dev/usb/usbf.h, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: usbf.h,v 1.3 2007/06/19 11:52:07 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 data structures and subroutines
21: */
22:
23: #ifndef _USBF_H_
24: #define _USBF_H_
25:
26: typedef struct usbf_function *usbf_function_handle;
27: typedef struct usbf_bus *usbf_bus_handle;
28: typedef struct usbf_device *usbf_device_handle;
29: typedef struct usbf_config *usbf_config_handle;
30: typedef struct usbf_interface *usbf_interface_handle;
31: typedef struct usbf_endpoint *usbf_endpoint_handle;
32: typedef struct usbf_pipe *usbf_pipe_handle;
33: typedef struct usbf_xfer *usbf_xfer_handle;
34: typedef void *usbf_private_handle;
35:
36: /*
37: * Return codes for many of the function driver interface routines
38: */
39: typedef enum { /* keep in sync with USBF_ERROR_STRS */
40: USBF_NORMAL_COMPLETION = 0, /* must be 0 */
41: USBF_IN_PROGRESS, /* 1 */
42: /* errors */
43: USBF_NOT_STARTED, /* 2 */
44: USBF_INVAL, /* 3 */
45: USBF_NOMEM, /* 4 */
46: USBF_CANCELLED, /* 5 */
47: USBF_BAD_ADDRESS, /* 6 */
48: USBF_IOERROR, /* 7 */
49: USBF_TIMEOUT, /* 8 */
50: USBF_SHORT_XFER, /* 9 */
51: USBF_STALLED, /* 10 */
52: USBF_ERROR_MAX /* must be last */
53: } usbf_status;
54: #define USBF_ERROR_STRS { /* keep in sync with enum usbf_status */ \
55: "NORMAL_COMPLETION", /* 0 */ \
56: "IN_PROGRESS", /* 1 */ \
57: "NOT_STARTED", /* 2 */ \
58: "INVAL", /* 3 */ \
59: "NOMEM", /* 4 */ \
60: "CANCELLED", /* 5 */ \
61: "BAD_ADDRESS", /* 6 */ \
62: "IOERROR", /* 7 */ \
63: "TIMEOUT", /* 8 */ \
64: "SHORT_XFER", /* 9 */ \
65: "STALLED", /* 10 */ \
66: };
67:
68: typedef void (*usbf_callback)(usbf_xfer_handle, usbf_private_handle,
69: usbf_status);
70:
71: /*
72: * Attach USB function at the logical device.
73: */
74: struct usbf_attach_arg {
75: usbf_device_handle device;
76: };
77:
78: struct usbf_function_methods {
79: usbf_status (*set_config)(usbf_function_handle, usbf_config_handle);
80: usbf_status (*do_request)(usbf_function_handle,
81: usb_device_request_t *req, void **data);
82: };
83:
84: struct usbf_function {
85: struct device bdev; /* base device */
86: /* filled in by function driver */
87: struct usbf_function_methods *methods;
88: };
89:
90: #define USBF_EMPTY_STRING_ID (USB_LANGUAGE_TABLE+1)
91: #define USBF_STRING_ID_MIN (USB_LANGUAGE_TABLE+2)
92: #define USBF_STRING_ID_MAX 255
93:
94: /*
95: * USB function driver interface
96: */
97:
98: /* global */
99: const char *usbf_errstr(usbf_status);
100:
101: /* device */
102: void usbf_devinfo_setup(usbf_device_handle, u_int8_t, u_int8_t,
103: u_int8_t, u_int16_t, u_int16_t, u_int16_t, const char *,
104: const char *, const char *);
105: char *usbf_devinfo_alloc(usbf_device_handle);
106: void usbf_devinfo_free(char *);
107: usb_device_descriptor_t *usbf_device_descriptor(usbf_device_handle);
108: usb_string_descriptor_t *usbf_string_descriptor(usbf_device_handle, u_int8_t);
109: usb_config_descriptor_t *usbf_config_descriptor(usbf_device_handle, u_int8_t);
110:
111: /* configuration */
112: u_int8_t usbf_add_string(usbf_device_handle, const char *);
113: usbf_status usbf_add_config(usbf_device_handle, usbf_config_handle *);
114: usbf_status usbf_add_config_desc(usbf_config_handle, usb_descriptor_t *,
115: usb_descriptor_t **);
116: usbf_status usbf_add_interface(usbf_config_handle, u_int8_t, u_int8_t,
117: u_int8_t, const char *, usbf_interface_handle *);
118: usbf_status usbf_add_endpoint(usbf_interface_handle, u_int8_t,
119: u_int8_t, u_int16_t, u_int8_t, usbf_endpoint_handle *);
120: usbf_status usbf_end_config(usbf_config_handle);
121: usbf_endpoint_handle usbf_config_endpoint(usbf_config_handle, u_int8_t);
122:
123: /* interface */
124: int usbf_interface_number(usbf_interface_handle);
125: usbf_endpoint_handle usbf_iface_endpoint(usbf_interface_handle, u_int8_t);
126:
127: /* endpoint */
128: u_int8_t usbf_endpoint_address(usbf_endpoint_handle);
129: u_int8_t usbf_endpoint_attributes(usbf_endpoint_handle);
130: #define usbf_endpoint_index(e) UE_GET_ADDR(usbf_endpoint_address((e)))
131: #define usbf_endpoint_dir(e) UE_GET_DIR(usbf_endpoint_address((e)))
132: #define usbf_endpoint_type(e) UE_GET_XFERTYPE(usbf_endpoint_attributes((e)))
133:
134: /* pipe */
135: usbf_status usbf_open_pipe(usbf_interface_handle, u_int8_t,
136: usbf_pipe_handle *);
137: void usbf_abort_pipe(usbf_pipe_handle);
138: void usbf_close_pipe(usbf_pipe_handle);
139: void usbf_stall_pipe(usbf_pipe_handle);
140:
141: /* transfer */
142: usbf_xfer_handle usbf_alloc_xfer(usbf_device_handle);
143: void usbf_free_xfer(usbf_xfer_handle);
144: void *usbf_alloc_buffer(usbf_xfer_handle, u_int32_t);
145: void usbf_free_buffer(usbf_xfer_handle);
146: void usbf_setup_xfer(usbf_xfer_handle, usbf_pipe_handle,
147: usbf_private_handle, void *, u_int32_t, u_int16_t,
148: u_int32_t, usbf_callback);
149: void usbf_setup_default_xfer(usbf_xfer_handle, usbf_pipe_handle,
150: usbf_private_handle, usb_device_request_t *, u_int16_t,
151: u_int32_t, usbf_callback);
152: void usbf_get_xfer_status(usbf_xfer_handle, usbf_private_handle *,
153: void **, u_int32_t *, usbf_status *);
154: usbf_status usbf_transfer(usbf_xfer_handle);
155:
156: /*
157: * The usbf_task structure describes a task to be perfomed in process
158: * context, i.e. the USB device's task thread. This is normally used by
159: * USB function drivers that need to perform tasks in a process context.
160: */
161: struct usbf_task {
162: TAILQ_ENTRY(usbf_task) next;
163: void (*fun)(void *);
164: void *arg;
165: char onqueue;
166: };
167:
168: void usbf_add_task(usbf_device_handle, struct usbf_task *);
169: void usbf_rem_task(usbf_device_handle, struct usbf_task *);
170: #define usbf_init_task(t, f, a) ((t)->fun=(f), (t)->arg=(a), (t)->onqueue=0)
171:
172: #endif
CVSweb