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 _USB2_TRANSFER_H_ 28#define _USB2_TRANSFER_H_ 29 30/* 31 * The following structure defines the messages that is used to signal 32 * the "done_p" USB process. 33 */ 34struct usb2_done_msg { 35 struct usb2_proc_msg hdr; 36 struct usb2_xfer_root *usb2_root; 37}; 38 39/* 40 * The following structure is used to keep information about memory 41 * that should be automatically freed at the moment all USB transfers 42 * have been freed. 43 */ 44struct usb2_xfer_root { 45 struct usb2_xfer_queue dma_q; 46 struct usb2_xfer_queue done_q; 47 struct usb2_done_msg done_m[2]; 48 struct cv cv_drain; 49 50 struct usb2_dma_parent_tag dma_parent_tag; 51 52 struct usb2_process done_p; 53 void *memory_base; 54 struct mtx *priv_mtx;
| 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 _USB2_TRANSFER_H_ 28#define _USB2_TRANSFER_H_ 29 30/* 31 * The following structure defines the messages that is used to signal 32 * the "done_p" USB process. 33 */ 34struct usb2_done_msg { 35 struct usb2_proc_msg hdr; 36 struct usb2_xfer_root *usb2_root; 37}; 38 39/* 40 * The following structure is used to keep information about memory 41 * that should be automatically freed at the moment all USB transfers 42 * have been freed. 43 */ 44struct usb2_xfer_root { 45 struct usb2_xfer_queue dma_q; 46 struct usb2_xfer_queue done_q; 47 struct usb2_done_msg done_m[2]; 48 struct cv cv_drain; 49 50 struct usb2_dma_parent_tag dma_parent_tag; 51 52 struct usb2_process done_p; 53 void *memory_base; 54 struct mtx *priv_mtx;
|
56 struct usb2_page_cache *dma_page_cache_start; 57 struct usb2_page_cache *dma_page_cache_end; 58 struct usb2_page_cache *xfer_page_cache_start; 59 struct usb2_page_cache *xfer_page_cache_end; 60 struct usb2_bus *bus; 61 62 uint32_t memory_size; 63 uint32_t setup_refcount; 64 uint32_t page_size; 65 uint32_t dma_nframes; /* number of page caches to load */ 66 uint32_t dma_currframe; /* currect page cache number */ 67 uint32_t dma_frlength_0; /* length of page cache zero */ 68 uint8_t dma_error; /* set if virtual memory could not be 69 * loaded */ 70 uint8_t done_sleep; /* set if done thread is sleeping */ 71}; 72 73/* 74 * The following structure is used when setting up an array of USB 75 * transfers. 76 */ 77struct usb2_setup_params { 78 struct usb2_dma_tag *dma_tag_p; 79 struct usb2_page *dma_page_ptr; 80 struct usb2_page_cache *dma_page_cache_ptr; /* these will be 81 * auto-freed */ 82 struct usb2_page_cache *xfer_page_cache_ptr; /* these will not be 83 * auto-freed */ 84 struct usb2_device *udev; 85 struct usb2_xfer *curr_xfer; 86 const struct usb2_config *curr_setup; 87 const struct usb2_config_sub *curr_setup_sub; 88 const struct usb2_pipe_methods *methods; 89 void *buf; 90 uint32_t *xfer_length_ptr; 91 92 uint32_t size[7]; 93 uint32_t bufsize; 94 uint32_t bufsize_max; 95 uint32_t hc_max_frame_size; 96 97 uint16_t hc_max_packet_size; 98 uint8_t hc_max_packet_count; 99 uint8_t speed; 100 uint8_t dma_tag_max; 101 usb2_error_t err; 102}; 103 104/* function prototypes */ 105 106uint8_t usb2_transfer_pending(struct usb2_xfer *xfer); 107uint8_t usb2_transfer_setup_sub_malloc(struct usb2_setup_params *parm, struct usb2_page_cache **ppc, uint32_t size, uint32_t align, uint32_t count); 108void usb2_command_wrapper(struct usb2_xfer_queue *pq, struct usb2_xfer *xfer); 109void usb2_pipe_enter(struct usb2_xfer *xfer); 110void usb2_pipe_start(struct usb2_xfer_queue *pq); 111void usb2_transfer_dequeue(struct usb2_xfer *xfer); 112void usb2_transfer_done(struct usb2_xfer *xfer, usb2_error_t error); 113void usb2_transfer_enqueue(struct usb2_xfer_queue *pq, struct usb2_xfer *xfer); 114void usb2_transfer_setup_sub(struct usb2_setup_params *parm); 115void usb2_default_transfer_setup(struct usb2_device *udev); 116void usb2_clear_data_toggle(struct usb2_device *udev, struct usb2_pipe *pipe); 117void usb2_do_poll(struct usb2_xfer **ppxfer, uint16_t max); 118usb2_callback_t usb2_do_request_callback; 119usb2_callback_t usb2_handle_request_callback; 120usb2_callback_t usb2_do_clear_stall_callback; 121void usb2_transfer_timeout_ms(struct usb2_xfer *xfer, void (*cb) (void *arg), uint32_t ms); 122 123#endif /* _USB2_TRANSFER_H_ */
| 55 struct usb2_page_cache *dma_page_cache_start; 56 struct usb2_page_cache *dma_page_cache_end; 57 struct usb2_page_cache *xfer_page_cache_start; 58 struct usb2_page_cache *xfer_page_cache_end; 59 struct usb2_bus *bus; 60 61 uint32_t memory_size; 62 uint32_t setup_refcount; 63 uint32_t page_size; 64 uint32_t dma_nframes; /* number of page caches to load */ 65 uint32_t dma_currframe; /* currect page cache number */ 66 uint32_t dma_frlength_0; /* length of page cache zero */ 67 uint8_t dma_error; /* set if virtual memory could not be 68 * loaded */ 69 uint8_t done_sleep; /* set if done thread is sleeping */ 70}; 71 72/* 73 * The following structure is used when setting up an array of USB 74 * transfers. 75 */ 76struct usb2_setup_params { 77 struct usb2_dma_tag *dma_tag_p; 78 struct usb2_page *dma_page_ptr; 79 struct usb2_page_cache *dma_page_cache_ptr; /* these will be 80 * auto-freed */ 81 struct usb2_page_cache *xfer_page_cache_ptr; /* these will not be 82 * auto-freed */ 83 struct usb2_device *udev; 84 struct usb2_xfer *curr_xfer; 85 const struct usb2_config *curr_setup; 86 const struct usb2_config_sub *curr_setup_sub; 87 const struct usb2_pipe_methods *methods; 88 void *buf; 89 uint32_t *xfer_length_ptr; 90 91 uint32_t size[7]; 92 uint32_t bufsize; 93 uint32_t bufsize_max; 94 uint32_t hc_max_frame_size; 95 96 uint16_t hc_max_packet_size; 97 uint8_t hc_max_packet_count; 98 uint8_t speed; 99 uint8_t dma_tag_max; 100 usb2_error_t err; 101}; 102 103/* function prototypes */ 104 105uint8_t usb2_transfer_pending(struct usb2_xfer *xfer); 106uint8_t usb2_transfer_setup_sub_malloc(struct usb2_setup_params *parm, struct usb2_page_cache **ppc, uint32_t size, uint32_t align, uint32_t count); 107void usb2_command_wrapper(struct usb2_xfer_queue *pq, struct usb2_xfer *xfer); 108void usb2_pipe_enter(struct usb2_xfer *xfer); 109void usb2_pipe_start(struct usb2_xfer_queue *pq); 110void usb2_transfer_dequeue(struct usb2_xfer *xfer); 111void usb2_transfer_done(struct usb2_xfer *xfer, usb2_error_t error); 112void usb2_transfer_enqueue(struct usb2_xfer_queue *pq, struct usb2_xfer *xfer); 113void usb2_transfer_setup_sub(struct usb2_setup_params *parm); 114void usb2_default_transfer_setup(struct usb2_device *udev); 115void usb2_clear_data_toggle(struct usb2_device *udev, struct usb2_pipe *pipe); 116void usb2_do_poll(struct usb2_xfer **ppxfer, uint16_t max); 117usb2_callback_t usb2_do_request_callback; 118usb2_callback_t usb2_handle_request_callback; 119usb2_callback_t usb2_do_clear_stall_callback; 120void usb2_transfer_timeout_ms(struct usb2_xfer *xfer, void (*cb) (void *arg), uint32_t ms); 121 122#endif /* _USB2_TRANSFER_H_ */
|