source: mainline/uspace/drv/bus/usb/ehci/endpoint_list.c@ e0a5d4c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e0a5d4c 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.6 KB
Line 
1/*
2 * Copyright (c) 2014 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 drvusbehci
31 * @{
32 */
33/** @file
34 * @brief EHCI driver transfer list implementation
35 */
36
37#include <assert.h>
38#include <errno.h>
39#include <libarch/barrier.h>
40
41#include <usb/debug.h>
42
43#include "endpoint_list.h"
44
45/** Initialize transfer list structures.
46 *
47 * @param[in] instance Memory place to use.
48 * @param[in] name Name of the new list.
49 * @return Error code
50 *
51 * Allocates memory for internal ed_t structure.
52 */
53errno_t endpoint_list_init(endpoint_list_t *instance, const char *name)
54{
55 assert(instance);
56 instance->name = name;
57 if (dma_buffer_alloc(&instance->dma_buffer, sizeof(qh_t))) {
58 usb_log_error("EPL(%p-%s): Failed to allocate list head.",
59 instance, name);
60 return ENOMEM;
61 }
62 instance->list_head = instance->dma_buffer.virt;
63 qh_init(instance->list_head, NULL);
64
65 list_initialize(&instance->endpoint_list);
66 fibril_mutex_initialize(&instance->guard);
67
68 usb_log_debug2("EPL(%p-%s): Transfer list setup with ED: %p(%"PRIxn").",
69 instance, name, instance->list_head,
70 addr_to_phys(instance->list_head));
71
72 return EOK;
73}
74
75void endpoint_list_chain(endpoint_list_t *instance, const endpoint_list_t *next)
76{
77 assert(instance);
78 assert(next);
79 assert(instance->list_head);
80 assert(next->list_head);
81
82 usb_log_debug2("EPL(%p-%s): Chained with EPL(%p-%s).",
83 instance, instance->name, next, next->name);
84
85 qh_append_qh(instance->list_head, next->list_head);
86}
87
88/** Add endpoint to the end of the list and queue.
89 *
90 * @param[in] instance List to use.
91 * @param[in] endpoint Endpoint to add.
92 *
93 * The endpoint is added to the end of the list and queue.
94 */
95void endpoint_list_append_ep(endpoint_list_t *instance, ehci_endpoint_t *ep)
96{
97 assert(instance);
98 assert(instance->list_head);
99 assert(ep);
100 assert(ep->qh);
101 usb_log_debug2("EPL(%p-%s): Append endpoint(%p).",
102 instance, instance->name, ep);
103
104 fibril_mutex_lock(&instance->guard);
105
106 qh_t *last_qh = NULL;
107 /* Add to the hardware queue. */
108 if (list_empty(&instance->endpoint_list)) {
109 /* There are no active EDs */
110 last_qh = instance->list_head;
111 } else {
112 /* There are active EDs, get the last one */
113 ehci_endpoint_t *last = ehci_endpoint_list_instance(
114 list_last(&instance->endpoint_list));
115 last_qh = last->qh;
116 }
117 assert(last_qh);
118 /* Keep link, this might point to the queue QH, or next chained queue */
119 ep->qh->horizontal = last_qh->horizontal;
120 /* Make sure QH update is written to the memory */
121 write_barrier();
122
123 /* Add QH to the hw queue */
124 qh_append_qh(last_qh, ep->qh);
125 /* Make sure QH is updated */
126 write_barrier();
127 /* Add to the sw list */
128 list_append(&ep->eplist_link, &instance->endpoint_list);
129
130 ehci_endpoint_t *first = ehci_endpoint_list_instance(
131 list_first(&instance->endpoint_list));
132 usb_log_debug("EPL(%p-%s): EP(%p) added to list, first is %p(%p).",
133 instance, instance->name, ep, first, first->qh);
134 if (last_qh == instance->list_head) {
135 usb_log_debug2("EPL(%p-%s): head EP(%p-%"PRIxn"): %x:%x.",
136 instance, instance->name, last_qh,
137 addr_to_phys(instance->list_head),
138 last_qh->status, last_qh->horizontal);
139 }
140 fibril_mutex_unlock(&instance->guard);
141}
142
143/** Remove endpoint from the list and queue.
144 *
145 * @param[in] instance List to use.
146 * @param[in] endpoint Endpoint to remove.
147 */
148void endpoint_list_remove_ep(endpoint_list_t *instance, ehci_endpoint_t *ep)
149{
150 assert(instance);
151 assert(instance->list_head);
152 assert(ep);
153 assert(ep->qh);
154
155 fibril_mutex_lock(&instance->guard);
156
157 usb_log_debug2("EPL(%p-%s): removing EP(%p).",
158 instance, instance->name, ep);
159
160 const char *qpos = NULL;
161 qh_t *prev_qh;
162 /* Remove from the hardware queue */
163 if (list_first(&instance->endpoint_list) == &ep->eplist_link) {
164 /* I'm the first one here */
165 prev_qh = instance->list_head;
166 qpos = "FIRST";
167 } else {
168 prev_qh = ehci_endpoint_list_instance(ep->eplist_link.prev)->qh;
169 qpos = "NOT FIRST";
170 }
171 assert(qh_next(prev_qh) == addr_to_phys(ep->qh));
172 prev_qh->horizontal = ep->qh->horizontal;
173 /* Make sure ED is updated */
174 write_barrier();
175
176 usb_log_debug("EPL(%p-%s): EP(%p) removed (%s), horizontal %x.",
177 instance, instance->name, ep, qpos, ep->qh->horizontal);
178
179 /* Remove from the endpoint list */
180 list_remove(&ep->eplist_link);
181 fibril_mutex_unlock(&instance->guard);
182}
183/**
184 * @}
185 */
186
Note: See TracBrowser for help on using the repository browser.