[4192d3d6] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Jan Vesely
|
---|
[e0a5d4c] | 3 | * Copyright (c) 2018 Ondrej Hlavaty
|
---|
[4192d3d6] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - 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 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
[58563585] | 29 |
|
---|
[17ceb72] | 30 | /** @addtogroup drvusbuhcihc
|
---|
[4192d3d6] | 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
[f706355] | 34 | * @brief UHCI driver USB tranfer helper functions
|
---|
[4192d3d6] | 35 | */
|
---|
[58563585] | 36 |
|
---|
[83c439c] | 37 | #ifndef DRV_UHCI_BATCH_H
|
---|
| 38 | #define DRV_UHCI_BATCH_H
|
---|
[4192d3d6] | 39 |
|
---|
[b991d37] | 40 | #include <adt/list.h>
|
---|
[8064c2f6] | 41 | #include <assert.h>
|
---|
| 42 | #include <errno.h>
|
---|
| 43 | #include <stdbool.h>
|
---|
[8d2dd7f2] | 44 | #include <stddef.h>
|
---|
[8064c2f6] | 45 | #include <usb/host/usb_transfer_batch.h>
|
---|
[5fd9c30] | 46 | #include <usb/host/endpoint.h>
|
---|
[4192d3d6] | 47 |
|
---|
[87644b4] | 48 | #include "hw_struct/queue_head.h"
|
---|
[b991d37] | 49 | #include "hw_struct/transfer_descriptor.h"
|
---|
| 50 |
|
---|
| 51 | /** UHCI specific data required for USB transfer */
|
---|
| 52 | typedef struct uhci_transfer_batch {
|
---|
[5fd9c30] | 53 | usb_transfer_batch_t base;
|
---|
| 54 |
|
---|
[b991d37] | 55 | /** Queue head
|
---|
| 56 | * This QH is used to maintain UHCI schedule structure and the element
|
---|
| 57 | * pointer points to the first TD of this batch.
|
---|
| 58 | */
|
---|
| 59 | qh_t *qh;
|
---|
| 60 | /** List of TDs needed for the transfer */
|
---|
| 61 | td_t *tds;
|
---|
| 62 | /** Number of TDs used by the transfer */
|
---|
| 63 | size_t td_count;
|
---|
[c21e6a5] | 64 | /* Setup data */
|
---|
| 65 | char *setup_buffer;
|
---|
| 66 | /** Backing TDs + setup_buffer */
|
---|
| 67 | dma_buffer_t uhci_dma_buffer;
|
---|
[b991d37] | 68 | /** List element */
|
---|
| 69 | link_t link;
|
---|
| 70 | } uhci_transfer_batch_t;
|
---|
| 71 |
|
---|
[ae3a941] | 72 | uhci_transfer_batch_t *uhci_transfer_batch_create(endpoint_t *);
|
---|
[a312d8f] | 73 | int uhci_transfer_batch_prepare(uhci_transfer_batch_t *);
|
---|
| 74 | bool uhci_transfer_batch_check_completed(uhci_transfer_batch_t *);
|
---|
| 75 | void uhci_transfer_batch_destroy(uhci_transfer_batch_t *);
|
---|
[b991d37] | 76 |
|
---|
[f7ac3f3] | 77 | /** Get offset to setup buffer accessible to the HC hw.
|
---|
| 78 | * @param uhci_batch UHCI batch structure.
|
---|
| 79 | * @return Pointer to the setup buffer.
|
---|
| 80 | */
|
---|
[ae3a941] | 81 | static inline void *uhci_transfer_batch_setup_buffer(
|
---|
[5d915b7] | 82 | const uhci_transfer_batch_t *uhci_batch)
|
---|
[b991d37] | 83 | {
|
---|
| 84 | assert(uhci_batch);
|
---|
[c21e6a5] | 85 | return uhci_batch->uhci_dma_buffer.virt + sizeof(qh_t) +
|
---|
[5d915b7] | 86 | uhci_batch->td_count * sizeof(td_t);
|
---|
[b991d37] | 87 | }
|
---|
[76fbd9a] | 88 |
|
---|
[f7ac3f3] | 89 | /** Get offset to data buffer accessible to the HC hw.
|
---|
| 90 | * @param uhci_batch UHCI batch structure.
|
---|
| 91 | * @return Pointer to the data buffer.
|
---|
| 92 | */
|
---|
[ae3a941] | 93 | static inline void *uhci_transfer_batch_data_buffer(
|
---|
[5d915b7] | 94 | const uhci_transfer_batch_t *uhci_batch)
|
---|
[b991d37] | 95 | {
|
---|
| 96 | assert(uhci_batch);
|
---|
[c21e6a5] | 97 | return uhci_batch->base.dma_buffer.virt;
|
---|
[b991d37] | 98 | }
|
---|
[76fbd9a] | 99 |
|
---|
[f7ac3f3] | 100 | /** Linked list conversion wrapper.
|
---|
| 101 | * @param l Linked list link.
|
---|
| 102 | * @return Pointer to the uhci batch structure.
|
---|
| 103 | */
|
---|
[b991d37] | 104 | static inline uhci_transfer_batch_t *uhci_transfer_batch_from_link(link_t *l)
|
---|
| 105 | {
|
---|
| 106 | assert(l);
|
---|
| 107 | return list_get_instance(l, uhci_transfer_batch_t, link);
|
---|
| 108 | }
|
---|
[4192d3d6] | 109 |
|
---|
[ae3a941] | 110 | static inline uhci_transfer_batch_t *uhci_transfer_batch_get(
|
---|
| 111 | usb_transfer_batch_t *b)
|
---|
[5fd9c30] | 112 | {
|
---|
| 113 | assert(b);
|
---|
| 114 | return (uhci_transfer_batch_t *) b;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
[4192d3d6] | 117 | #endif
|
---|
[58563585] | 118 |
|
---|
[4192d3d6] | 119 | /**
|
---|
| 120 | * @}
|
---|
| 121 | */
|
---|