Changeset 741bcdeb in mainline for uspace/drv/bus/usb/ehci/ehci_bus.c
- Timestamp:
- 2017-10-13T09:21:22Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c0e4b5b2
- Parents:
- e6b9182
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ehci/ehci_bus.c
re6b9182 r741bcdeb 1 1 /* 2 * Copyright (c) 201 4Jan Vesely2 * Copyright (c) 2011 Jan Vesely 3 3 * All rights reserved. 4 4 * … … 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 /** @addtogroup drvusbehci 29 30 * @{ … … 35 36 #include <assert.h> 36 37 #include <stdlib.h> 38 #include <usb/host/utils/malloc32.h> 39 #include <usb/host/bandwidth.h> 37 40 #include <usb/debug.h> 38 #include <usb/host/utils/malloc32.h>39 41 40 #include "ehci_ endpoint.h"42 #include "ehci_bus.h" 41 43 #include "hc.h" 42 44 … … 46 48 * @param[in] toggle new value of toggle bit 47 49 */ 48 static void ehci_ep_toggle_set( void *ehci_ep, inttoggle)50 static void ehci_ep_toggle_set(endpoint_t *ep, bool toggle) 49 51 { 50 ehci_endpoint_t *instance = ehci_e p;52 ehci_endpoint_t *instance = ehci_endpoint_get(ep); 51 53 assert(instance); 52 54 assert(instance->qh); 55 ep->toggle = toggle; 53 56 if (qh_toggle_from_td(instance->qh)) 54 57 usb_log_warning("EP(%p): Setting toggle bit for transfer " … … 62 65 * @return Current value of toggle bit. 63 66 */ 64 static int ehci_ep_toggle_get(void *ehci_ep)67 static bool ehci_ep_toggle_get(endpoint_t *ep) 65 68 { 66 ehci_endpoint_t *instance = ehci_e p;69 ehci_endpoint_t *instance = ehci_endpoint_get(ep); 67 70 assert(instance); 68 71 assert(instance->qh); 72 69 73 if (qh_toggle_from_td(instance->qh)) 70 74 usb_log_warning("EP(%p): Reading useless toggle bit", instance); … … 73 77 74 78 /** Creates new hcd endpoint representation. 75 *76 * @param[in] ep USBD endpoint structure77 * @return Error code.78 79 */ 79 int ehci_endpoint_init(hcd_t *hcd, endpoint_t *ep)80 static endpoint_t *ehci_endpoint_create(bus_t *bus) 80 81 { 81 assert(ep); 82 hc_t *hc = hcd_get_driver_data(hcd); 82 assert(bus); 83 83 84 84 ehci_endpoint_t *ehci_ep = malloc(sizeof(ehci_endpoint_t)); 85 85 if (ehci_ep == NULL) 86 return ENOMEM; 86 return NULL; 87 88 endpoint_init(&ehci_ep->base, bus); 87 89 88 90 ehci_ep->qh = malloc32(sizeof(qh_t)); 89 91 if (ehci_ep->qh == NULL) { 90 92 free(ehci_ep); 91 return ENOMEM;93 return NULL; 92 94 } 93 95 94 usb_log_debug2("EP(%p): Creating for %p", ehci_ep, ep);95 96 link_initialize(&ehci_ep->link); 96 qh_init(ehci_ep->qh, ep);97 endpoint_set_hc_data(98 ep, ehci_ep, ehci_ep_toggle_get, ehci_ep_toggle_set);99 hc_enqueue_endpoint(hc, ep);100 97 return EOK; 101 98 } … … 106 103 * @param[in] ep endpoint structure. 107 104 */ 108 void ehci_endpoint_fini(hcd_t *hcd,endpoint_t *ep)105 static void ehci_endpoint_destroy(endpoint_t *ep) 109 106 { 110 assert(hcd);111 107 assert(ep); 112 hc_t *hc = hcd_get_driver_data(hcd);108 ehci_endpoint_t *instance = ehci_endpoint_get(ep); 113 109 114 ehci_endpoint_t *instance = ehci_endpoint_get(ep); 115 hc_dequeue_endpoint(hc, ep); 116 endpoint_clear_hc_data(ep); 117 usb_log_debug2("EP(%p): Destroying for %p", instance, ep); 118 if (instance) { 119 free32(instance->qh); 120 free(instance); 121 } 110 free32(instance->qh); 111 free(instance); 122 112 } 113 114 115 static int ehci_register_ep(bus_t *bus_base, endpoint_t *ep) 116 { 117 ehci_bus_t *bus = (ehci_bus_t *) bus_base; 118 ehci_endpoint_t *ehci_ep = ehci_endpoint_get(ep); 119 120 const int err = bus->parent_ops.register_endpoint(bus_base, ep); 121 if (err) 122 return err; 123 124 qh_init(ehci_ep->qh, ep); 125 hc_enqueue_endpoint(bus->hc, ep); 126 127 return EOK; 128 } 129 130 static int ehci_release_ep(bus_t *bus_base, endpoint_t *ep) 131 { 132 ehci_bus_t *bus = (ehci_bus_t *) bus_base; 133 assert(bus); 134 assert(ep); 135 136 const int err = bus->parent_ops.release_endpoint(bus_base, ep); 137 if (err) 138 return err; 139 140 hc_dequeue_endpoint(bus->hc, ep); 141 return EOK; 142 143 } 144 145 int ehci_bus_init(ehci_bus_t *bus, hc_t *hc) 146 { 147 assert(hc); 148 assert(bus); 149 150 // FIXME: Implement the USB2 bw counting. 151 usb2_bus_init(&bus->base, BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11); 152 153 bus_ops_t *ops = &bus->base.base.ops; 154 bus->parent_ops = *ops; 155 ops->create_endpoint = ehci_endpoint_create; 156 ops->destroy_endpoint = ehci_endpoint_destroy; 157 ops->endpoint_set_toggle = ehci_ep_toggle_set; 158 ops->endpoint_get_toggle = ehci_ep_toggle_get; 159 160 ops->register_endpoint = ehci_register_ep; 161 ops->release_endpoint = ehci_release_ep; 162 163 return EOK; 164 } 165 123 166 /** 124 167 * @} 125 168 */ 126
Note:
See TracChangeset
for help on using the changeset viewer.