source: mainline/uspace/drv/bus/usb/xhci/endpoint.c@ c10daa8

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c10daa8 was c10daa8, checked in by Petr Manek <petr.manek@…>, 8 years ago

Refactored XHCI bus to hold devices instead of endpoints. Added middle layer to keep track of endpoints within devices.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * Copyright (c) 2017 Petr Manek
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 drvusbxhci
30 * @{
31 */
32/** @file
33 * @brief The host controller endpoint management.
34 */
35
36#include <usb/host/endpoint.h>
37
38#include <errno.h>
39
40#include "bus.h"
41#include "endpoint.h"
42
43int xhci_endpoint_init(xhci_endpoint_t *xhci_ep, xhci_bus_t *xhci_bus)
44{
45 assert(xhci_ep);
46 assert(xhci_bus);
47
48 bus_t *bus = &xhci_bus->base;
49 endpoint_t *ep = &xhci_ep->base;
50
51 endpoint_init(ep, bus);
52 xhci_ep->device = NULL;
53
54 usb_log_debug("XHCI Endpoint %d:%d initialized.", ep->target.address, ep->target.endpoint);
55
56 return EOK;
57}
58
59void xhci_endpoint_fini(xhci_endpoint_t *xhci_ep)
60{
61 assert(xhci_ep);
62
63 /* FIXME: Tear down TR's? */
64
65 endpoint_t *ep = &xhci_ep->base;
66
67 usb_log_debug("XHCI Endpoint %d:%d destroyed.", ep->target.address, ep->target.endpoint);
68}
69
70int xhci_device_init(xhci_device_t *dev, xhci_bus_t *bus)
71{
72 memset(&dev->endpoints, 0, sizeof(dev->endpoints));
73 dev->active_endpoint_count = 0;
74 return EOK;
75}
76
77void xhci_device_fini(xhci_device_t *dev)
78{
79 // TODO: Check that all endpoints are dead.
80}
81
82int xhci_device_add_endpoint(xhci_device_t *dev, xhci_endpoint_t *ep)
83{
84 assert(dev->address == ep->base.target.address);
85 assert(!dev->endpoints[ep->base.target.endpoint]);
86 assert(!ep->device);
87
88 ep->device = dev;
89 dev->endpoints[ep->base.target.endpoint] = ep;
90 ++dev->active_endpoint_count;
91 return EOK;
92}
93
94int xhci_device_remove_endpoint(xhci_device_t *dev, xhci_endpoint_t *ep)
95{
96 assert(dev->address == ep->base.target.address);
97 assert(dev->endpoints[ep->base.target.endpoint]);
98 assert(dev == ep->device);
99
100 ep->device = NULL;
101 dev->endpoints[ep->base.target.endpoint] = NULL;
102 --dev->active_endpoint_count;
103 return EOK;
104}
105
106xhci_endpoint_t * xhci_device_get_endpoint(xhci_device_t *dev, usb_endpoint_t ep)
107{
108 return dev->endpoints[ep];
109}
110
111/**
112 * @}
113 */
Note: See TracBrowser for help on using the repository browser.