Changeset 741bcdeb in mainline
- Timestamp:
- 2017-10-13T09:21:22Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c0e4b5b2
- Parents:
- e6b9182
- Location:
- uspace/drv/bus/usb
- Files:
-
- 9 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ehci/Makefile
re6b9182 r741bcdeb 46 46 SOURCES = \ 47 47 ehci_batch.c \ 48 ehci_ endpoint.c \48 ehci_bus.c \ 49 49 ehci_rh.c \ 50 50 endpoint_list.c \ -
uspace/drv/bus/usb/ehci/ehci_batch.c
re6b9182 r741bcdeb 45 45 46 46 #include "ehci_batch.h" 47 #include "ehci_ endpoint.h"47 #include "ehci_bus.h" 48 48 49 49 /* The buffer pointer list in the qTD is long enough to support a maximum -
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 -
uspace/drv/bus/usb/ehci/ehci_bus.h
re6b9182 r741bcdeb 1 1 /* 2 2 * Copyright (c) 2011 Jan Vesely 3 * Copyright (c) 2017 Ondrej Hlavaty <aearsis@eideo.cz> 3 4 * All rights reserved. 4 5 * … … 32 33 * @brief EHCI driver 33 34 */ 34 #ifndef DRV_EHCI_HCD_ ENDPOINT_H35 #define DRV_EHCI_HCD_ ENDPOINT_H35 #ifndef DRV_EHCI_HCD_BUS_H 36 #define DRV_EHCI_HCD_BUS_H 36 37 37 38 #include <assert.h> 38 39 #include <adt/list.h> 40 #include <usb/host/usb2_bus.h> 39 41 #include <usb/host/endpoint.h> 40 #include <usb/host/hcd.h>41 42 42 43 #include "hw_struct/queue_head.h" 43 #include "hw_struct/transfer_descriptor.h"44 44 45 45 /** Connector structure linking ED to to prepared TD. */ 46 46 typedef struct ehci_endpoint { 47 /* Inheritance */ 48 endpoint_t base; 49 47 50 /** EHCI endpoint descriptor */ 48 51 qh_t *qh; … … 51 54 } ehci_endpoint_t; 52 55 53 int ehci_endpoint_init(hcd_t *hcd, endpoint_t *ep); 54 void ehci_endpoint_fini(hcd_t *hcd, endpoint_t *ep); 56 typedef struct hc hc_t; 57 58 typedef struct { 59 usb2_bus_t base; 60 hc_t *hc; 61 62 /* Stored original ops from base, they are called in our handlers */ 63 bus_ops_t parent_ops; 64 } ehci_bus_t; 65 66 int ehci_bus_init(ehci_bus_t *, hc_t *); 55 67 56 68 /** Get and convert assigned ehci_endpoint_t structure … … 61 73 { 62 74 assert(ep); 63 return ep->hc_data.data;75 return (ehci_endpoint_t *) ep; 64 76 } 65 77 … … 73 85 * @} 74 86 */ 75 -
uspace/drv/bus/usb/ehci/ehci_rh.c
re6b9182 r741bcdeb 144 144 assert(instance); 145 145 assert(batch); 146 const usb_target_t target = {{ 147 .address = batch->ep->address, 148 .endpoint = batch->ep->endpoint, 149 }}; 146 const usb_target_t target = batch->ep->target; 150 147 batch->error = virthub_base_request(&instance->base, target, 151 148 usb_transfer_batch_direction(batch), (void*)batch->setup_buffer, … … 183 180 instance, batch); 184 181 if (batch) { 185 const usb_target_t target = {{ 186 .address = batch->ep->address, 187 .endpoint = batch->ep->endpoint, 188 }}; 182 const usb_target_t target = batch->ep->target; 189 183 batch->error = virthub_base_request(&instance->base, target, 190 184 usb_transfer_batch_direction(batch), -
uspace/drv/bus/usb/ehci/endpoint_list.h
re6b9182 r741bcdeb 40 40 #include <usb/host/utils/malloc32.h> 41 41 42 #include "ehci_ endpoint.h"42 #include "ehci_bus.h" 43 43 #include "hw_struct/queue_head.h" 44 44 -
uspace/drv/bus/usb/ehci/hc.c
re6b9182 r741bcdeb 190 190 &instance->rh, instance->caps, instance->registers, "ehci rh"); 191 191 192 ehci_bus_init(&instance->bus, instance); 192 193 return EOK; 193 194 } … … 214 215 ehci_endpoint_t *ehci_ep = ehci_endpoint_get(ep); 215 216 usb_log_debug("HC(%p) enqueue EP(%d:%d:%s:%s)\n", instance, 216 ep-> address, ep->endpoint,217 ep->target.address, ep->target.endpoint, 217 218 usb_str_transfer_type_short(ep->transfer_type), 218 219 usb_str_direction(ep->direction)); … … 238 239 ehci_endpoint_t *ehci_ep = ehci_endpoint_get(ep); 239 240 usb_log_debug("HC(%p) dequeue EP(%d:%d:%s:%s)\n", instance, 240 ep-> address, ep->endpoint,241 ep->target.address, ep->target.endpoint, 241 242 usb_str_transfer_type_short(ep->transfer_type), 242 243 usb_str_direction(ep->direction)); … … 290 291 291 292 /* Check for root hub communication */ 292 if (batch->ep-> address == ehci_rh_get_address(&instance->rh)) {293 if (batch->ep->target.address == ehci_rh_get_address(&instance->rh)) { 293 294 usb_log_debug("HC(%p): Scheduling BATCH(%p) for RH(%p)", 294 295 instance, batch, &instance->rh); -
uspace/drv/bus/usb/ehci/hc.h
re6b9182 r741bcdeb 80 80 /** USB hub emulation structure */ 81 81 ehci_rh_t rh; 82 83 /** USB bookkeeping */ 84 ehci_bus_t bus; 82 85 } hc_t; 83 86 -
uspace/drv/bus/usb/ehci/hw_struct/queue_head.c
re6b9182 r741bcdeb 65 65 assert(ep->speed < ARRAY_SIZE(speed)); 66 66 EHCI_MEM32_WR(instance->ep_char, 67 QH_EP_CHAR_ADDR_SET(ep-> address) |68 QH_EP_CHAR_EP_SET(ep-> endpoint) |67 QH_EP_CHAR_ADDR_SET(ep->target.address) | 68 QH_EP_CHAR_EP_SET(ep->target.endpoint) | 69 69 speed[ep->speed] | 70 70 QH_EP_CHAR_MAX_LENGTH_SET(ep->max_packet_size) -
uspace/drv/bus/usb/ehci/main.c
re6b9182 r741bcdeb 48 48 #include "res.h" 49 49 #include "hc.h" 50 #include "ehci_endpoint.h"51 50 52 51 #define NAME "ehci" … … 67 66 .ops = { 68 67 .schedule = ehci_hc_schedule, 69 .ep_add_hook = ehci_endpoint_init,70 .ep_remove_hook = ehci_endpoint_fini,71 68 .irq_hook = ehci_hc_interrupt, 72 69 .status_hook = ehci_hc_status, … … 86 83 const int ret = hc_init(instance, res); 87 84 if (ret == EOK) { 88 hcd_set_implementation(hcd, instance, &ehci_hc_driver.ops );85 hcd_set_implementation(hcd, instance, &ehci_hc_driver.ops, &instance->bus.base.base); 89 86 } else { 90 87 free(instance); … … 116 113 117 114 free(hc); 118 hcd_set_implementation(hcd, NULL, NULL );115 hcd_set_implementation(hcd, NULL, NULL, NULL); 119 116 } 120 117 -
uspace/drv/bus/usb/ohci/ohci_bus.c
re6b9182 r741bcdeb 78 78 if (ohci_ep == NULL) 79 79 return NULL; 80 81 endpoint_init(&ohci_ep->base, bus); 80 82 81 83 ohci_ep->ed = malloc32(sizeof(ed_t));
Note:
See TracChangeset
for help on using the changeset viewer.