source: mainline/uspace/drv/bus/usb/ehci/ehci_endpoint.c@ b8191cc

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

ehci: Implement dequeue.

Includes async list doorbell interrupt handling

  • Property mode set to 100644
File size: 3.4 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/** @addtogroup drvusbehci
29 * @{
30 */
31/** @file
32 * @brief EHCI driver
33 */
34
35#include <assert.h>
36#include <stdlib.h>
37#include <usb/debug.h>
38
39#include "utils/malloc32.h"
40#include "ehci_endpoint.h"
41#include "hc.h"
42
43/** Callback to set toggle on ED.
44 *
45 * @param[in] hcd_ep hcd endpoint structure
46 * @param[in] toggle new value of toggle bit
47 */
48static void ehci_ep_toggle_set(void *ehci_ep, int toggle)
49{
50 ehci_endpoint_t *instance = ehci_ep;
51 assert(instance);
52 assert(instance->qh);
53 if (qh_toggle_from_td(instance->qh))
54 usb_log_warning("Setting toggle bit for transfer directed EP\n");
55 qh_toggle_set(instance->qh, toggle);
56}
57
58/** Callback to get value of toggle bit.
59 *
60 * @param[in] hcd_ep hcd endpoint structure
61 * @return Current value of toggle bit.
62 */
63static int ehci_ep_toggle_get(void *ehci_ep)
64{
65 ehci_endpoint_t *instance = ehci_ep;
66 assert(instance);
67 assert(instance->qh);
68 if (qh_toggle_from_td(instance->qh))
69 usb_log_warning("Reading useless toggle bit\n");
70 return qh_toggle_get(instance->qh);
71}
72
73/** Creates new hcd endpoint representation.
74 *
75 * @param[in] ep USBD endpoint structure
76 * @return Error code.
77 */
78int ehci_endpoint_init(hcd_t *hcd, endpoint_t *ep)
79{
80 assert(ep);
81 ehci_endpoint_t *ehci_ep = malloc(sizeof(ehci_endpoint_t));
82 if (ehci_ep == NULL)
83 return ENOMEM;
84
85 ehci_ep->qh = malloc32(sizeof(qh_t));
86 if (ehci_ep->qh == NULL) {
87 free(ehci_ep);
88 return ENOMEM;
89 }
90
91 qh_init(ehci_ep->qh, ep);
92 endpoint_set_hc_data(
93 ep, ehci_ep, ehci_ep_toggle_get, ehci_ep_toggle_set);
94 hc_enqueue_endpoint(hcd->driver.data, ep);
95 return EOK;
96}
97
98/** Disposes hcd endpoint structure
99 *
100 * @param[in] hcd driver using this instance.
101 * @param[in] ep endpoint structure.
102 */
103void ehci_endpoint_fini(hcd_t *hcd, endpoint_t *ep)
104{
105 assert(hcd);
106 assert(ep);
107 ehci_endpoint_t *instance = ehci_endpoint_get(ep);
108 hc_dequeue_endpoint(hcd->driver.data, ep);
109 endpoint_clear_hc_data(ep);
110 if (instance) {
111 free32(instance->qh);
112 free(instance);
113 }
114}
115/**
116 * @}
117 */
118
Note: See TracBrowser for help on using the repository browser.