source: mainline/uspace/drv/bus/usb/ohci/ohci_bus.c@ ed8575f

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

usbhost: made device_remove and endpoint_unregister noexcept

  • Property mode set to 100644
File size: 4.5 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
34 */
35
36#include <assert.h>
37#include <stdlib.h>
38#include <usb/host/utils/malloc32.h>
39#include <usb/host/bandwidth.h>
40
41#include "ohci_bus.h"
42#include "ohci_batch.h"
43#include "hc.h"
44
45/** Callback to reset toggle on ED.
46 *
47 * @param[in] hcd_ep hcd endpoint structure
48 * @param[in] toggle new value of toggle bit
49 */
50static void ohci_ep_toggle_reset(endpoint_t *ep)
51{
52 ohci_endpoint_t *instance = ohci_endpoint_get(ep);
53 assert(instance);
54 assert(instance->ed);
55 ep->toggle = 0;
56 ed_toggle_set(instance->ed, 0);
57}
58
59/** Creates new hcd endpoint representation.
60 */
61static endpoint_t *ohci_endpoint_create(device_t *dev, const usb_endpoint_descriptors_t *desc)
62{
63 assert(dev);
64
65 ohci_endpoint_t *ohci_ep = malloc(sizeof(ohci_endpoint_t));
66 if (ohci_ep == NULL)
67 return NULL;
68
69 endpoint_init(&ohci_ep->base, dev, desc);
70
71 ohci_ep->ed = malloc32(sizeof(ed_t));
72 if (ohci_ep->ed == NULL) {
73 free(ohci_ep);
74 return NULL;
75 }
76
77 ohci_ep->td = malloc32(sizeof(td_t));
78 if (ohci_ep->td == NULL) {
79 free32(ohci_ep->ed);
80 free(ohci_ep);
81 return NULL;
82 }
83
84 link_initialize(&ohci_ep->link);
85 return &ohci_ep->base;
86}
87
88/** Disposes hcd endpoint structure
89 *
90 * @param[in] hcd driver using this instance.
91 * @param[in] ep endpoint structure.
92 */
93static void ohci_endpoint_destroy(endpoint_t *ep)
94{
95 assert(ep);
96 ohci_endpoint_t *instance = ohci_endpoint_get(ep);
97
98 free32(instance->ed);
99 free32(instance->td);
100 free(instance);
101}
102
103
104static int ohci_register_ep(endpoint_t *ep)
105{
106 bus_t *bus_base = endpoint_get_bus(ep);
107 ohci_bus_t *bus = (ohci_bus_t *) bus_base;
108 ohci_endpoint_t *ohci_ep = ohci_endpoint_get(ep);
109
110 const int err = usb2_bus_ops.endpoint_register(ep);
111 if (err)
112 return err;
113
114 ed_init(ohci_ep->ed, ep, ohci_ep->td);
115 hc_enqueue_endpoint(bus->hc, ep);
116
117 return EOK;
118}
119
120static void ohci_unregister_ep(endpoint_t *ep)
121{
122 ohci_bus_t *bus = (ohci_bus_t *) endpoint_get_bus(ep);
123 assert(ep);
124
125 usb2_bus_ops.endpoint_unregister(ep);
126 hc_dequeue_endpoint(bus->hc, ep);
127}
128
129static usb_transfer_batch_t *ohci_create_batch(endpoint_t *ep)
130{
131 ohci_transfer_batch_t *batch = ohci_transfer_batch_create(ep);
132 return &batch->base;
133}
134
135static void ohci_destroy_batch(usb_transfer_batch_t *batch)
136{
137 ohci_transfer_batch_destroy(ohci_transfer_batch_get(batch));
138}
139
140static const bus_ops_t ohci_bus_ops = {
141 .parent = &usb2_bus_ops,
142
143 .interrupt = ohci_hc_interrupt,
144 .status = ohci_hc_status,
145
146 .endpoint_destroy = ohci_endpoint_destroy,
147 .endpoint_create = ohci_endpoint_create,
148 .endpoint_register = ohci_register_ep,
149 .endpoint_unregister = ohci_unregister_ep,
150 .endpoint_count_bw = bandwidth_count_usb11,
151 .endpoint_toggle_reset = ohci_ep_toggle_reset,
152 .batch_create = ohci_create_batch,
153 .batch_destroy = ohci_destroy_batch,
154 .batch_schedule = ohci_hc_schedule,
155};
156
157
158int ohci_bus_init(ohci_bus_t *bus, hc_t *hc)
159{
160 assert(hc);
161 assert(bus);
162
163 usb2_bus_t *usb2_bus = (usb2_bus_t *) bus;
164 bus_t *bus_base = (bus_t *) bus;
165
166 usb2_bus_init(usb2_bus, BANDWIDTH_AVAILABLE_USB11);
167 bus_base->ops = &ohci_bus_ops;
168
169 bus->hc = hc;
170
171 return EOK;
172}
173
174/**
175 * @}
176 */
Note: See TracBrowser for help on using the repository browser.