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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 296fcce was 296fcce, checked in by Jan Vesely <jano.vesely@…>, 12 years ago

ehci: Don't use prepend in async list.

Hw uses RR anyway.

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 * Copyright (c) 2014 Jan Vesely
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 drvusbehci
30 * @{
31 */
32/** @file
33 * @brief EHCI driver transfer list implementation
34 */
35
36#include <assert.h>
37#include <errno.h>
38#include <libarch/barrier.h>
39
40#include <usb/debug.h>
41
42#include "utils/malloc32.h"
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 */
53int endpoint_list_init(endpoint_list_t *instance, const char *name)
54{
55 assert(instance);
56 instance->name = name;
57 instance->list_head = malloc32(sizeof(qh_t));
58 if (!instance->list_head) {
59 usb_log_error("Failed to allocate list head.\n");
60 return ENOMEM;
61 }
62 instance->list_head_pa = addr_to_phys(instance->list_head);
63 usb_log_debug2("Transfer list %s setup with ED: %p(0x%0" PRIx32 ")).\n",
64 name, instance->list_head, instance->list_head_pa);
65
66 qh_init(instance->list_head, NULL);
67 list_initialize(&instance->endpoint_list);
68 fibril_mutex_initialize(&instance->guard);
69 return EOK;
70}
71
72/** Add endpoint to the end of the list and queue.
73 *
74 * @param[in] instance List to use.
75 * @param[in] endpoint Endpoint to add.
76 *
77 * The endpoint is added to the end of the list and queue.
78 */
79void endpoint_list_append_ep(endpoint_list_t *instance, ehci_endpoint_t *ep)
80{
81 assert(instance);
82 assert(ep);
83 assert(ep->qh);
84 usb_log_debug2("Queue %s: Append endpoint(%p).\n", instance->name, ep);
85
86 fibril_mutex_lock(&instance->guard);
87
88 qh_t *last_qh = NULL;
89 /* Add to the hardware queue. */
90 if (list_empty(&instance->endpoint_list)) {
91 /* There are no active EDs */
92 last_qh = instance->list_head;
93 } else {
94 /* There are active EDs, get the last one */
95 ehci_endpoint_t *last = ehci_endpoint_list_instance(
96 list_last(&instance->endpoint_list));
97 last_qh = last->qh;
98 }
99 assert(last_qh);
100 /* Keep link */
101 ep->qh->horizontal = last_qh->horizontal;
102 /* Make sure QH update is written to the memory */
103 write_barrier();
104
105 /* Add QH to the hw queue */
106 qh_append_qh(last_qh, ep->qh);
107 /* Make sure QH is updated */
108 write_barrier();
109 /* Add to the sw list */
110 list_append(&ep->link, &instance->endpoint_list);
111
112 ehci_endpoint_t *first = ehci_endpoint_list_instance(
113 list_first(&instance->endpoint_list));
114 usb_log_debug("HCD EP(%p) added to list %s, first is %p(%p).\n",
115 ep, instance->name, first, first->qh);
116 if (last_qh == instance->list_head) {
117 usb_log_debug2("%s head ED(%p-0x%0" PRIx32 "): %x:%x.\n",
118 instance->name, last_qh, instance->list_head_pa,
119 last_qh->status, last_qh->horizontal);
120 }
121 fibril_mutex_unlock(&instance->guard);
122}
123
124/** Remove endpoint from the list and queue.
125 *
126 * @param[in] instance List to use.
127 * @param[in] endpoint Endpoint to remove.
128 */
129void endpoint_list_remove_ep(endpoint_list_t *instance, ehci_endpoint_t *ep)
130{
131 assert(instance);
132 assert(instance->list_head);
133 assert(ep);
134 assert(ep->qh);
135
136 fibril_mutex_lock(&instance->guard);
137
138 usb_log_debug2("Queue %s: removing endpoint(%p).\n", instance->name, ep);
139
140 const char *qpos = NULL;
141 qh_t *prev_qh;
142 /* Remove from the hardware queue */
143 if (list_first(&instance->endpoint_list) == &ep->link) {
144 /* I'm the first one here */
145 prev_qh = instance->list_head;
146 qpos = "FIRST";
147 } else {
148 ehci_endpoint_t *prev =
149 list_get_instance(ep->link.prev, ehci_endpoint_t, link);
150 prev_qh = prev->qh;
151 qpos = "NOT FIRST";
152 }
153 assert(qh_next(prev_qh) == addr_to_phys(ep->qh));
154 prev_qh->next = ep->qh->next;
155 /* Make sure ED is updated */
156 write_barrier();
157
158 usb_log_debug("HCD EP(%p) removed (%s) from %s, next %x.\n",
159 ep, qpos, instance->name, ep->qh->next);
160
161 /* Remove from the endpoint list */
162 list_remove(&ep->link);
163 fibril_mutex_unlock(&instance->guard);
164}
165/**
166 * @}
167 */
168
Note: See TracBrowser for help on using the repository browser.