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

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

ehci: Make async schedule a loop.

Hw RR mechanism needs this.

  • Property mode set to 100644
File size: 5.3 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
72void endpoint_list_chain(endpoint_list_t *instance, const endpoint_list_t *next)
73{
74 assert(instance);
75 assert(next);
76 assert(instance->list_head);
77 assert(next->list_head);
78
79 instance->list_head->horizontal = LINK_POINTER_QH(next->list_head_pa);
80}
81
82/** Add endpoint to the end of the list and queue.
83 *
84 * @param[in] instance List to use.
85 * @param[in] endpoint Endpoint to add.
86 *
87 * The endpoint is added to the end of the list and queue.
88 */
89void endpoint_list_append_ep(endpoint_list_t *instance, ehci_endpoint_t *ep)
90{
91 assert(instance);
92 assert(ep);
93 assert(ep->qh);
94 usb_log_debug2("Queue %s: Append endpoint(%p).\n", instance->name, ep);
95
96 fibril_mutex_lock(&instance->guard);
97
98 qh_t *last_qh = NULL;
99 /* Add to the hardware queue. */
100 if (list_empty(&instance->endpoint_list)) {
101 /* There are no active EDs */
102 last_qh = instance->list_head;
103 } else {
104 /* There are active EDs, get the last one */
105 ehci_endpoint_t *last = ehci_endpoint_list_instance(
106 list_last(&instance->endpoint_list));
107 last_qh = last->qh;
108 }
109 assert(last_qh);
110 /* Keep link */
111 ep->qh->horizontal = last_qh->horizontal;
112 /* Make sure QH update is written to the memory */
113 write_barrier();
114
115 /* Add QH to the hw queue */
116 qh_append_qh(last_qh, ep->qh);
117 /* Make sure QH is updated */
118 write_barrier();
119 /* Add to the sw list */
120 list_append(&ep->link, &instance->endpoint_list);
121
122 ehci_endpoint_t *first = ehci_endpoint_list_instance(
123 list_first(&instance->endpoint_list));
124 usb_log_debug("HCD EP(%p) added to list %s, first is %p(%p).\n",
125 ep, instance->name, first, first->qh);
126 if (last_qh == instance->list_head) {
127 usb_log_debug2("%s head ED(%p-0x%0" PRIx32 "): %x:%x.\n",
128 instance->name, last_qh, instance->list_head_pa,
129 last_qh->status, last_qh->horizontal);
130 }
131 fibril_mutex_unlock(&instance->guard);
132}
133
134/** Remove endpoint from the list and queue.
135 *
136 * @param[in] instance List to use.
137 * @param[in] endpoint Endpoint to remove.
138 */
139void endpoint_list_remove_ep(endpoint_list_t *instance, ehci_endpoint_t *ep)
140{
141 assert(instance);
142 assert(instance->list_head);
143 assert(ep);
144 assert(ep->qh);
145
146 fibril_mutex_lock(&instance->guard);
147
148 usb_log_debug2("Queue %s: removing endpoint(%p).\n", instance->name, ep);
149
150 const char *qpos = NULL;
151 qh_t *prev_qh;
152 /* Remove from the hardware queue */
153 if (list_first(&instance->endpoint_list) == &ep->link) {
154 /* I'm the first one here */
155 prev_qh = instance->list_head;
156 qpos = "FIRST";
157 } else {
158 ehci_endpoint_t *prev =
159 list_get_instance(ep->link.prev, ehci_endpoint_t, link);
160 prev_qh = prev->qh;
161 qpos = "NOT FIRST";
162 }
163 assert(qh_next(prev_qh) == addr_to_phys(ep->qh));
164 prev_qh->next = ep->qh->next;
165 /* Make sure ED is updated */
166 write_barrier();
167
168 usb_log_debug("HCD EP(%p) removed (%s) from %s, next %x.\n",
169 ep, qpos, instance->name, ep->qh->next);
170
171 /* Remove from the endpoint list */
172 list_remove(&ep->link);
173 fibril_mutex_unlock(&instance->guard);
174}
175/**
176 * @}
177 */
178
Note: See TracBrowser for help on using the repository browser.