source: mainline/uspace/drv/bus/usb/ohci/endpoint_list.c@ 5da7199

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5da7199 was c0699467, checked in by Martin Decky <martin@…>, 14 years ago

do not provide general access to kernel headers from uspace, only allow specific headers to be accessed or shared
externalize headers which serve as kernel/uspace API/ABI into a special tree

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*
2 * Copyright (c) 2011 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 drvusbohci
30 * @{
31 */
32/** @file
33 * @brief OHCI driver transfer list implementation
34 */
35
36#include <errno.h>
37#include <usb/debug.h>
38#include <libarch/barrier.h>
39#include "endpoint_list.h"
40
41/** Initialize transfer list structures.
42 *
43 * @param[in] instance Memory place to use.
44 * @param[in] name Name of the new list.
45 * @return Error code
46 *
47 * Allocates memory for internal ed_t structure.
48 */
49int endpoint_list_init(endpoint_list_t *instance, const char *name)
50{
51 assert(instance);
52 instance->name = name;
53 instance->list_head = malloc32(sizeof(ed_t));
54 if (!instance->list_head) {
55 usb_log_error("Failed to allocate list head.\n");
56 return ENOMEM;
57 }
58 instance->list_head_pa = addr_to_phys(instance->list_head);
59 usb_log_debug2("Transfer list %s setup with ED: %p(0x%0" PRIx32 ")).\n",
60 name, instance->list_head, instance->list_head_pa);
61
62 ed_init(instance->list_head, NULL);
63 list_initialize(&instance->endpoint_list);
64 fibril_mutex_initialize(&instance->guard);
65 return EOK;
66}
67/*----------------------------------------------------------------------------*/
68/** Set the next list in transfer list chain.
69 *
70 * @param[in] instance List to lead.
71 * @param[in] next List to append.
72 *
73 * Does not check whether this replaces an existing list.
74 */
75void endpoint_list_set_next(endpoint_list_t *instance, endpoint_list_t *next)
76{
77 assert(instance);
78 assert(next);
79 ed_append_ed(instance->list_head, next->list_head);
80}
81/*----------------------------------------------------------------------------*/
82/** Add endpoint to 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_add_ep(endpoint_list_t *instance, hcd_endpoint_t *hcd_ep)
90{
91 assert(instance);
92 assert(hcd_ep);
93 usb_log_debug2("Queue %s: Adding endpoint(%p).\n",
94 instance->name, hcd_ep);
95
96 fibril_mutex_lock(&instance->guard);
97
98 ed_t *last_ed = NULL;
99 /* Add to the hardware queue. */
100 if (list_empty(&instance->endpoint_list)) {
101 /* There are no active EDs */
102 last_ed = instance->list_head;
103 } else {
104 /* There are active EDs, get the last one */
105 hcd_endpoint_t *last = list_get_instance(
106 list_last(&instance->endpoint_list), hcd_endpoint_t, link);
107 last_ed = last->ed;
108 }
109 /* Keep link */
110 hcd_ep->ed->next = last_ed->next;
111 /* Make sure ED is written to the memory */
112 write_barrier();
113
114 /* Add ed to the hw queue */
115 ed_append_ed(last_ed, hcd_ep->ed);
116 /* Make sure ED is updated */
117 write_barrier();
118
119 /* Add to the sw list */
120 list_append(&hcd_ep->link, &instance->endpoint_list);
121
122 hcd_endpoint_t *first = list_get_instance(
123 list_first(&instance->endpoint_list), hcd_endpoint_t, link);
124 usb_log_debug("HCD EP(%p) added to list %s, first is %p(%p).\n",
125 hcd_ep, instance->name, first, first->ed);
126 if (last_ed == instance->list_head) {
127 usb_log_debug2("%s head ED(%p-0x%0" PRIx32 "): %x:%x:%x:%x.\n",
128 instance->name, last_ed, instance->list_head_pa,
129 last_ed->status, last_ed->td_tail, last_ed->td_head,
130 last_ed->next);
131 }
132 fibril_mutex_unlock(&instance->guard);
133}
134/*----------------------------------------------------------------------------*/
135/** Remove endpoint from the list and queue.
136 *
137 * @param[in] instance List to use.
138 * @param[in] endpoint Endpoint to remove.
139 */
140void endpoint_list_remove_ep(endpoint_list_t *instance, hcd_endpoint_t *hcd_ep)
141{
142 assert(instance);
143 assert(instance->list_head);
144 assert(hcd_ep);
145 assert(hcd_ep->ed);
146
147 fibril_mutex_lock(&instance->guard);
148
149 usb_log_debug2(
150 "Queue %s: removing endpoint(%p).\n", instance->name, hcd_ep);
151
152 const char *qpos = NULL;
153 ed_t *prev_ed;
154 /* Remove from the hardware queue */
155 if (list_first(&instance->endpoint_list) == &hcd_ep->link) {
156 /* I'm the first one here */
157 prev_ed = instance->list_head;
158 qpos = "FIRST";
159 } else {
160 hcd_endpoint_t *prev =
161 list_get_instance(hcd_ep->link.prev, hcd_endpoint_t, link);
162 prev_ed = prev->ed;
163 qpos = "NOT FIRST";
164 }
165 assert((prev_ed->next & ED_NEXT_PTR_MASK) == addr_to_phys(hcd_ep->ed));
166 prev_ed->next = hcd_ep->ed->next;
167 /* Make sure ED is updated */
168 write_barrier();
169
170 usb_log_debug("HCD EP(%p) removed (%s) from %s, next %x.\n",
171 hcd_ep, qpos, instance->name, hcd_ep->ed->next);
172
173 /* Remove from the endpoint list */
174 list_remove(&hcd_ep->link);
175 fibril_mutex_unlock(&instance->guard);
176}
177/**
178 * @}
179 */
Note: See TracBrowser for help on using the repository browser.