source: mainline/uspace/drv/bus/usb/uhci/uhci_batch.h@ 3be9d10

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3be9d10 was ae3a941, checked in by Ondřej Hlavatý <aearsis@…>, 7 years ago

usb: cstyle

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2011 Jan Vesely
3 * Copyright (c) 2018 Ondrej Hlavaty
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 */
29
30/** @addtogroup drvusbuhcihc
31 * @{
32 */
33/** @file
34 * @brief UHCI driver USB tranfer helper functions
35 */
36
37#ifndef DRV_UHCI_BATCH_H
38#define DRV_UHCI_BATCH_H
39
40#include <adt/list.h>
41#include <assert.h>
42#include <errno.h>
43#include <stdbool.h>
44#include <stddef.h>
45#include <usb/host/usb_transfer_batch.h>
46#include <usb/host/endpoint.h>
47
48#include "hw_struct/queue_head.h"
49#include "hw_struct/transfer_descriptor.h"
50
51/** UHCI specific data required for USB transfer */
52typedef struct uhci_transfer_batch {
53 usb_transfer_batch_t base;
54
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;
64 /* Setup data */
65 char *setup_buffer;
66 /** Backing TDs + setup_buffer */
67 dma_buffer_t uhci_dma_buffer;
68 /** List element */
69 link_t link;
70} uhci_transfer_batch_t;
71
72uhci_transfer_batch_t *uhci_transfer_batch_create(endpoint_t *);
73int uhci_transfer_batch_prepare(uhci_transfer_batch_t *);
74bool uhci_transfer_batch_check_completed(uhci_transfer_batch_t *);
75void uhci_transfer_batch_destroy(uhci_transfer_batch_t *);
76
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 */
81static inline void *uhci_transfer_batch_setup_buffer(
82 const uhci_transfer_batch_t *uhci_batch)
83{
84 assert(uhci_batch);
85 return uhci_batch->uhci_dma_buffer.virt + sizeof(qh_t) +
86 uhci_batch->td_count * sizeof(td_t);
87}
88
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 */
93static inline void *uhci_transfer_batch_data_buffer(
94 const uhci_transfer_batch_t *uhci_batch)
95{
96 assert(uhci_batch);
97 return uhci_batch->base.dma_buffer.virt;
98}
99
100/** Linked list conversion wrapper.
101 * @param l Linked list link.
102 * @return Pointer to the uhci batch structure.
103 */
104static 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}
109
110static inline uhci_transfer_batch_t *uhci_transfer_batch_get(
111 usb_transfer_batch_t *b)
112{
113 assert(b);
114 return (uhci_transfer_batch_t *) b;
115}
116
117#endif
118
119/**
120 * @}
121 */
Note: See TracBrowser for help on using the repository browser.