1 | /* $FreeBSD$ */ |
---|
2 | /*- |
---|
3 | * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. |
---|
4 | * |
---|
5 | * Redistribution and use in source and binary forms, with or without |
---|
6 | * modification, are permitted provided that the following conditions |
---|
7 | * are met: |
---|
8 | * 1. Redistributions of source code must retain the above copyright |
---|
9 | * notice, this list of conditions and the following disclaimer. |
---|
10 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
11 | * notice, this list of conditions and the following disclaimer in the |
---|
12 | * documentation and/or other materials provided with the distribution. |
---|
13 | * |
---|
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
---|
15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
24 | * SUCH DAMAGE. |
---|
25 | */ |
---|
26 | |
---|
27 | #ifndef _USB_TRANSFER_H_ |
---|
28 | #define _USB_TRANSFER_H_ |
---|
29 | |
---|
30 | /* |
---|
31 | * The following structure defines the messages that is used to signal |
---|
32 | * the "done_p" USB process. |
---|
33 | */ |
---|
34 | struct usb_done_msg { |
---|
35 | struct usb_proc_msg hdr; |
---|
36 | struct usb_xfer_root *xroot; |
---|
37 | }; |
---|
38 | |
---|
39 | #define USB_DMATAG_TO_XROOT(dpt) \ |
---|
40 | ((struct usb_xfer_root *)( \ |
---|
41 | ((uint8_t *)(dpt)) - \ |
---|
42 | ((uint8_t *)&((struct usb_xfer_root *)0)->dma_parent_tag))) |
---|
43 | |
---|
44 | /* |
---|
45 | * The following structure is used to keep information about memory |
---|
46 | * that should be automatically freed at the moment all USB transfers |
---|
47 | * have been freed. |
---|
48 | */ |
---|
49 | struct usb_xfer_root { |
---|
50 | struct usb_dma_parent_tag dma_parent_tag; |
---|
51 | #if USB_HAVE_BUSDMA |
---|
52 | struct usb_xfer_queue dma_q; |
---|
53 | #endif |
---|
54 | struct usb_xfer_queue done_q; |
---|
55 | struct usb_done_msg done_m[2]; |
---|
56 | struct cv cv_drain; |
---|
57 | |
---|
58 | struct usb_process *done_p; /* pointer to callback process */ |
---|
59 | void *memory_base; |
---|
60 | struct mtx *xfer_mtx; /* cannot be changed during operation */ |
---|
61 | #if USB_HAVE_BUSDMA |
---|
62 | struct usb_page_cache *dma_page_cache_start; |
---|
63 | struct usb_page_cache *dma_page_cache_end; |
---|
64 | #endif |
---|
65 | struct usb_page_cache *xfer_page_cache_start; |
---|
66 | struct usb_page_cache *xfer_page_cache_end; |
---|
67 | struct usb_bus *bus; /* pointer to USB bus (cached) */ |
---|
68 | struct usb_device *udev; /* pointer to USB device */ |
---|
69 | |
---|
70 | usb_size_t memory_size; |
---|
71 | usb_size_t setup_refcount; |
---|
72 | #if USB_HAVE_BUSDMA |
---|
73 | usb_frcount_t dma_nframes; /* number of page caches to load */ |
---|
74 | usb_frcount_t dma_currframe; /* currect page cache number */ |
---|
75 | usb_frlength_t dma_frlength_0; /* length of page cache zero */ |
---|
76 | uint8_t dma_error; /* set if virtual memory could not be |
---|
77 | * loaded */ |
---|
78 | #endif |
---|
79 | uint8_t done_sleep; /* set if done thread is sleeping */ |
---|
80 | }; |
---|
81 | |
---|
82 | /* |
---|
83 | * The following structure is used when setting up an array of USB |
---|
84 | * transfers. |
---|
85 | */ |
---|
86 | struct usb_setup_params { |
---|
87 | struct usb_dma_tag *dma_tag_p; |
---|
88 | struct usb_page *dma_page_ptr; |
---|
89 | struct usb_page_cache *dma_page_cache_ptr; /* these will be |
---|
90 | * auto-freed */ |
---|
91 | struct usb_page_cache *xfer_page_cache_ptr; /* these will not be |
---|
92 | * auto-freed */ |
---|
93 | struct usb_device *udev; |
---|
94 | struct usb_xfer *curr_xfer; |
---|
95 | const struct usb_config *curr_setup; |
---|
96 | const struct usb_pipe_methods *methods; |
---|
97 | void *buf; |
---|
98 | usb_frlength_t *xfer_length_ptr; |
---|
99 | |
---|
100 | usb_size_t size[7]; |
---|
101 | usb_frlength_t bufsize; |
---|
102 | usb_frlength_t bufsize_max; |
---|
103 | |
---|
104 | uint32_t hc_max_frame_size; |
---|
105 | uint16_t hc_max_packet_size; |
---|
106 | uint8_t hc_max_packet_count; |
---|
107 | enum usb_dev_speed speed; |
---|
108 | uint8_t dma_tag_max; |
---|
109 | usb_error_t err; |
---|
110 | }; |
---|
111 | |
---|
112 | /* function prototypes */ |
---|
113 | |
---|
114 | uint8_t usbd_transfer_setup_sub_malloc(struct usb_setup_params *parm, |
---|
115 | struct usb_page_cache **ppc, usb_size_t size, usb_size_t align, |
---|
116 | usb_size_t count); |
---|
117 | void usb_dma_delay_done_cb(struct usb_xfer *); |
---|
118 | void usb_command_wrapper(struct usb_xfer_queue *pq, |
---|
119 | struct usb_xfer *xfer); |
---|
120 | void usbd_pipe_enter(struct usb_xfer *xfer); |
---|
121 | void usbd_pipe_start(struct usb_xfer_queue *pq); |
---|
122 | void usbd_transfer_dequeue(struct usb_xfer *xfer); |
---|
123 | void usbd_transfer_done(struct usb_xfer *xfer, usb_error_t error); |
---|
124 | void usbd_transfer_enqueue(struct usb_xfer_queue *pq, |
---|
125 | struct usb_xfer *xfer); |
---|
126 | void usbd_transfer_setup_sub(struct usb_setup_params *parm); |
---|
127 | void usbd_ctrl_transfer_setup(struct usb_device *udev); |
---|
128 | void usbd_clear_stall_locked(struct usb_device *udev, |
---|
129 | struct usb_endpoint *ep); |
---|
130 | void usbd_clear_data_toggle(struct usb_device *udev, |
---|
131 | struct usb_endpoint *ep); |
---|
132 | usb_callback_t usbd_do_request_callback; |
---|
133 | usb_callback_t usb_handle_request_callback; |
---|
134 | usb_callback_t usb_do_clear_stall_callback; |
---|
135 | void usbd_transfer_timeout_ms(struct usb_xfer *xfer, |
---|
136 | void (*cb) (void *arg), usb_timeout_t ms); |
---|
137 | usb_timeout_t usbd_get_dma_delay(struct usb_device *udev); |
---|
138 | void usbd_transfer_power_ref(struct usb_xfer *xfer, int val); |
---|
139 | |
---|
140 | #endif /* _USB_TRANSFER_H_ */ |
---|