source: mainline/uspace/drv/bus/usb/xhci/trb_ring.h@ 3692678

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

usb: update copyrights

The data was generated by a script, guided manually. If you feel your
name is missing somewhere, please add it!

The semi-automated process was roughly:

1) Changes per file and author (limited to our team) were counted
2) Trivial numbers were thrown away
3) Authors were sorted by lines added to file
4) All previous copyrights were replaced by the newly generated one
5) Hunks changing only year were discarded

It seems that a lot of my copyrights were added. It is due to me being
both sticking my nose everywhere and lazy to update the copyright right
away :)

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 * Copyright (c) 2018 Ondrej Hlavaty, Jan Hrach
3 * 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 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup drvusbxhci
30 * @{
31 */
32/** @file
33 * TRB Ring is a data structure for communication between HC and software.
34 *
35 * Despite this description, it is not used as an hardware structure - all but
36 * the Event ring is used as buffer of the TRBs itself, linked by Link TRB to
37 * form a (possibly multi-segment) circular buffer.
38 *
39 * This data structure abstracts this behavior.
40 */
41
42#ifndef XHCI_TRB_RING_H
43#define XHCI_TRB_RING_H
44
45#include <adt/list.h>
46#include <fibril_synch.h>
47#include <libarch/config.h>
48#include <usb/dma_buffer.h>
49
50typedef struct trb_segment trb_segment_t;
51typedef struct xhci_hc xhci_hc_t;
52typedef struct xhci_trb xhci_trb_t;
53typedef struct xhci_erst_entry xhci_erst_entry_t;
54
55/**
56 * A TRB ring of which the software is a producer - command / transfer.
57 */
58typedef struct xhci_trb_ring {
59 list_t segments; /* List of assigned segments */
60 int segment_count; /* Number of segments assigned */
61
62 /*
63 * As the link TRBs connect physical addresses, we need to keep track of
64 * active segment in virtual memory. The enqueue ptr should always belong
65 * to the enqueue segment.
66 */
67 trb_segment_t *enqueue_segment;
68 xhci_trb_t *enqueue_trb;
69
70 uintptr_t dequeue; /* Last reported position of the dequeue pointer */
71 bool pcs; /* Producer Cycle State: section 4.9.2 */
72
73 fibril_mutex_t guard;
74} xhci_trb_ring_t;
75
76extern errno_t xhci_trb_ring_init(xhci_trb_ring_t *, size_t);
77extern void xhci_trb_ring_fini(xhci_trb_ring_t *);
78extern errno_t xhci_trb_ring_enqueue(xhci_trb_ring_t *, xhci_trb_t *, uintptr_t *);
79extern errno_t xhci_trb_ring_enqueue_multiple(xhci_trb_ring_t *, xhci_trb_t *, size_t, uintptr_t *);
80extern size_t xhci_trb_ring_size(xhci_trb_ring_t *);
81
82extern void xhci_trb_ring_reset_dequeue_state(xhci_trb_ring_t *ring, uintptr_t *addr);
83
84/**
85 * When an event is received by the upper layer, it needs to update the dequeue
86 * pointer inside the ring. Otherwise, the ring will soon show up as full.
87 */
88static inline void xhci_trb_ring_update_dequeue(xhci_trb_ring_t *ring, uintptr_t phys)
89{
90 ring->dequeue = phys;
91}
92
93/**
94 * A TRB ring of which the software is a consumer (event rings).
95 */
96typedef struct xhci_event_ring {
97 list_t segments; /* List of assigned segments */
98 int segment_count; /* Number of segments assigned */
99
100 trb_segment_t *dequeue_segment; /* Current segment of the dequeue ptr */
101 xhci_trb_t *dequeue_trb; /* Next TRB to be processed */
102 uintptr_t dequeue_ptr; /* Physical address of the ERDP to be reported to the HC */
103
104 dma_buffer_t erst; /* ERST given to the HC */
105
106 bool ccs; /* Consumer Cycle State: section 4.9.2 */
107
108 fibril_mutex_t guard;
109} xhci_event_ring_t;
110
111extern errno_t xhci_event_ring_init(xhci_event_ring_t *, size_t);
112extern void xhci_event_ring_fini(xhci_event_ring_t *);
113extern void xhci_event_ring_reset(xhci_event_ring_t *);
114extern errno_t xhci_event_ring_dequeue(xhci_event_ring_t *, xhci_trb_t *);
115
116/**
117 * A TRB ring of which the software is both consumer and provider.
118 */
119typedef struct xhci_sw_ring {
120 xhci_trb_t *begin, *end;
121 xhci_trb_t *enqueue, *dequeue;
122
123 fibril_mutex_t guard;
124 fibril_condvar_t enqueued_cv, dequeued_cv;
125
126 bool running;
127} xhci_sw_ring_t;
128
129extern void xhci_sw_ring_init(xhci_sw_ring_t *, size_t);
130
131/* Both may block if the ring is full/empty. */
132extern errno_t xhci_sw_ring_enqueue(xhci_sw_ring_t *, xhci_trb_t *);
133extern errno_t xhci_sw_ring_dequeue(xhci_sw_ring_t *, xhci_trb_t *);
134
135extern void xhci_sw_ring_restart(xhci_sw_ring_t *);
136extern void xhci_sw_ring_stop(xhci_sw_ring_t *);
137extern void xhci_sw_ring_fini(xhci_sw_ring_t *);
138
139#endif
140
141/**
142 * @}
143 */
Note: See TracBrowser for help on using the repository browser.