FreeBSD kernel usb device Code
usb_dev.h
Go to the documentation of this file.
1/* $FreeBSD$ */
2/*-
3 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 *
5 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#ifndef _USB_DEV_H_
30#define _USB_DEV_H_
31
32#ifndef USB_GLOBAL_INCLUDE_FILE
33#include <sys/file.h>
34#include <sys/selinfo.h>
35#include <sys/poll.h>
36#include <sys/signalvar.h>
37#include <sys/proc.h>
38#endif
39
40struct usb_fifo;
41struct usb_mbuf;
42
45 char src_path[32]; /* Source path - including terminating
46 * zero */
47 char dst_path[32]; /* Destination path - including
48 * terminating zero */
49 uint8_t src_len; /* String length */
50 uint8_t dst_len; /* String length */
51};
52
53/*
54 * Private per-device information.
55 */
57 struct usb_bus *bus;
60 int bus_index; /* bus index */
61 int dev_index; /* device index */
62 int ep_addr; /* endpoint address */
63 int fflags;
64 uint8_t fifo_index; /* FIFO index */
65};
66
67/*
68 * The following structure defines a minimum re-implementation of the
69 * ifqueue structure in the kernel.
70 */
74
77};
78
79/*
80 * Private per-device and per-thread reference information
81 */
85 uint8_t is_read; /* location has read access */
86 uint8_t is_write; /* location has write access */
87 uint8_t is_uref; /* USB refcount decr. needed */
88 uint8_t is_usbfs; /* USB-FS is active */
89 uint8_t do_unlock; /* USB enum unlock needed */
90};
91
96 int mode;
98 struct cdev *cdev;
99
101};
102
103/*
104 * Most of the fields in the "usb_fifo" structure are used by the
105 * generic USB access layer.
106 */
107struct usb_fifo {
111 struct cv cv_io;
112 struct cv cv_drain;
114 struct usb_symlink *symlink[2];/* our symlinks */
115 struct proc *async_p; /* process that wants SIGIO */
118 struct usb_xfer *xfer[2];
120 struct mtx *priv_mtx; /* client data */
121 /* set if FIFO is opened by a FILE: */
123 void *priv_sc0; /* client data */
124 void *priv_sc1; /* client data */
127 usb_timeout_t timeout; /* timeout in milliseconds */
128 usb_frlength_t bufsize; /* BULK and INTERRUPT buffer size */
129 usb_frcount_t nframes; /* for isochronous mode */
130 uint16_t dev_ep_index; /* our device endpoint index */
131 uint8_t flag_sleeping; /* set if FIFO is sleeping */
132 uint8_t flag_iscomplete; /* set if a USB transfer is complete */
133 uint8_t flag_iserror; /* set if FIFO error happened */
134 uint8_t flag_isselect; /* set if FIFO is selected */
135 uint8_t flag_flushing; /* set if FIFO is flushing data */
136 uint8_t flag_short; /* set if short_ok or force_short
137 * transfer flags should be set */
138 uint8_t flag_stall; /* set if clear stall should be run */
139 uint8_t flag_write_defrag; /* set to defrag written data */
140 uint8_t flag_have_fragment; /* set if defragging */
141 uint8_t iface_index; /* set to the interface we belong to */
142 uint8_t fifo_index; /* set to the FIFO index in "struct
143 * usb_device" */
144 uint8_t fs_ep_max;
145 uint8_t fifo_zlp; /* zero length packet count */
146 uint8_t refcount;
147#define USB_FIFO_REF_MAX 0xFF
148};
149
150extern struct cdevsw usb_devsw;
151
152int usb_fifo_wait(struct usb_fifo *fifo);
153void usb_fifo_signal(struct usb_fifo *fifo);
154uint8_t usb_fifo_opened(struct usb_fifo *fifo);
155struct usb_symlink *usb_alloc_symlink(const char *target);
157int usb_read_symlink(uint8_t *user_ptr, uint32_t startentry,
158 uint32_t user_len);
159
160#endif /* _USB_DEV_H_ */
struct usb_device * udev
Definition: usb_dev.h:58
struct usb_interface * iface
Definition: usb_dev.h:59
struct usb_bus * bus
Definition: usb_dev.h:57
uint8_t fifo_index
Definition: usb_dev.h:64
uint8_t is_usbfs
Definition: usb_dev.h:88
uint8_t is_read
Definition: usb_dev.h:85
struct usb_fifo * txfifo
Definition: usb_dev.h:84
uint8_t is_uref
Definition: usb_dev.h:87
uint8_t do_unlock
Definition: usb_dev.h:89
struct usb_fifo * rxfifo
Definition: usb_dev.h:83
uint8_t is_write
Definition: usb_dev.h:86
struct usb_ifqueue free_q
Definition: usb_dev.h:108
void * priv_sc0
Definition: usb_dev.h:123
uint8_t flag_flushing
Definition: usb_dev.h:135
uint8_t refcount
Definition: usb_dev.h:146
struct cv cv_io
Definition: usb_dev.h:111
usb_size_t fs_ep_sz
Definition: usb_dev.h:126
struct usb_fs_endpoint * fs_ep_ptr
Definition: usb_dev.h:116
uint8_t flag_sleeping
Definition: usb_dev.h:131
struct usb_device * udev
Definition: usb_dev.h:117
uint8_t flag_short
Definition: usb_dev.h:136
uint8_t flag_iscomplete
Definition: usb_dev.h:132
uint8_t flag_write_defrag
Definition: usb_dev.h:139
uint8_t flag_iserror
Definition: usb_dev.h:133
struct usb_ifqueue used_q
Definition: usb_dev.h:109
uint8_t fifo_index
Definition: usb_dev.h:142
uint8_t flag_isselect
Definition: usb_dev.h:134
uint16_t dev_ep_index
Definition: usb_dev.h:130
struct proc * async_p
Definition: usb_dev.h:115
void * queue_data
Definition: usb_dev.h:125
usb_frlength_t bufsize
Definition: usb_dev.h:128
uint8_t flag_stall
Definition: usb_dev.h:138
void * priv_sc1
Definition: usb_dev.h:124
uint8_t iface_index
Definition: usb_dev.h:141
struct mtx * priv_mtx
Definition: usb_dev.h:120
uint8_t flag_have_fragment
Definition: usb_dev.h:140
usb_timeout_t timeout
Definition: usb_dev.h:127
uint8_t fs_ep_max
Definition: usb_dev.h:144
struct usb_cdev_privdata * curr_cpd
Definition: usb_dev.h:122
struct cv cv_drain
Definition: usb_dev.h:112
struct usb_symlink * symlink[2]
Definition: usb_dev.h:114
struct usb_xfer ** fs_xfer
Definition: usb_dev.h:119
struct selinfo selinfo
Definition: usb_dev.h:110
uint8_t fifo_zlp
Definition: usb_dev.h:145
struct usb_fifo_methods * methods
Definition: usb_dev.h:113
struct usb_xfer * xfer[2]
Definition: usb_dev.h:118
usb_frcount_t nframes
Definition: usb_dev.h:129
struct cdev * cdev
Definition: usb_dev.h:98
int fifo_index
Definition: usb_dev.h:97
LIST_ENTRY(usb_fs_privdata) pd_next
struct usb_mbuf * ifq_tail
Definition: usb_dev.h:73
struct usb_mbuf * ifq_head
Definition: usb_dev.h:72
usb_size_t ifq_len
Definition: usb_dev.h:75
usb_size_t ifq_maxlen
Definition: usb_dev.h:76
uint8_t usb_fifo_opened(struct usb_fifo *fifo)
struct cdevsw usb_devsw
int usb_read_symlink(uint8_t *user_ptr, uint32_t startentry, uint32_t user_len)
struct usb_symlink * usb_alloc_symlink(const char *target)
void usb_free_symlink(struct usb_symlink *ps)
void usb_fifo_signal(struct usb_fifo *fifo)
int usb_fifo_wait(struct usb_fifo *fifo)
uint32_t usb_frlength_t
Definition: usb_freebsd.h:100
uint32_t usb_frcount_t
Definition: usb_freebsd.h:101
uint32_t usb_timeout_t
Definition: usb_freebsd.h:99
uint32_t usb_size_t
Definition: usb_freebsd.h:102