Changeset 867b375 in mainline for uspace/drv/bus/usb/xhci
- Timestamp:
- 2017-10-15T02:04:10Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 20eaa82
- Parents:
- d7869d7e
- Location:
- uspace/drv/bus/usb/xhci
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/main.c
rd7869d7e r867b375 42 42 43 43 #include "hc.h" 44 #include "rh.h" 44 45 #include "endpoint.h" 45 46 … … 50 51 static int hcd_claim(hcd_t *, ddf_dev_t *); 51 52 static int hcd_start(hcd_t *, bool); 53 static int hcd_setup_root_hub(hcd_t *, ddf_dev_t *); 52 54 static int hcd_status(hcd_t *, uint32_t *); 53 55 static void hcd_interrupt(hcd_t *, uint32_t); 54 56 static int hcd_schedule(hcd_t *, usb_transfer_batch_t *); 57 static int hcd_address_device(hcd_t *, usb_speed_t, usb_tt_address_t, usb_address_t *); 55 58 static void hc_driver_fini(hcd_t *); 56 59 … … 62 65 .claim = hcd_claim, 63 66 .start = hcd_start, 67 .setup_root_hub = hcd_setup_root_hub, 64 68 .fini = hc_driver_fini, 65 69 .ops = { … … 67 71 .irq_hook = hcd_interrupt, 68 72 .status_hook = hcd_status, 73 .address_device = hcd_address_device, 69 74 } 70 75 }; … … 116 121 } 117 122 123 static int hcd_setup_root_hub(hcd_t *hcd, ddf_dev_t *dev) 124 { 125 xhci_hc_t *hc = hcd_get_driver_data(hcd); 126 assert(hc); 127 128 hc->rh.hcd_rh = hcd_roothub_create(hcd, dev, USB_SPEED_SUPER); 129 return hc->rh.hcd_rh ? EOK : ENOMEM; 130 } 131 118 132 static int hcd_schedule(hcd_t *hcd, usb_transfer_batch_t *batch) 119 133 { … … 139 153 140 154 hc_interrupt(hc, status); 155 } 156 157 static int hcd_address_device(hcd_t *hcd, usb_speed_t speed, usb_tt_address_t tt, usb_address_t *address) 158 { 159 xhci_hc_t *hc = hcd_get_driver_data(hcd); 160 assert(hc); 161 162 return xhci_rh_address_device(&hc->rh, speed, tt, address); 141 163 } 142 164 -
uspace/drv/bus/usb/xhci/rh.c
rd7869d7e r867b375 38 38 #include <usb/debug.h> 39 39 #include <usb/host/utils/malloc32.h> 40 #include <usb/host/ddf_helpers.h> 41 40 42 #include "debug.h" 41 43 #include "commands.h" … … 69 71 // TODO: Check device deallocation, we free device_ctx in hc.c, not 70 72 // sure about the other structs. 71 static int alloc_dev(xhci_hc_t *hc, uint8_t port, uint32_t route_str) 73 // TODO: This currently assumes the device is attached to rh directly. 74 // Also, we should consider moving a lot of functionailty to xhci bus 75 int xhci_rh_address_device(xhci_rh_t *rh, usb_speed_t unused_speed, usb_tt_address_t tt, usb_address_t *address) 72 76 { 73 77 int err; 78 xhci_hc_t *hc = rh->hc; 74 79 75 80 xhci_cmd_t cmd; 76 81 xhci_cmd_init(&cmd); 77 82 78 const xhci_port_speed_t *speed = xhci_rh_get_port_speed(&hc->rh, port); 83 uint8_t port = tt.port; 84 85 /* XXX Certainly not generic solution. */ 86 uint32_t route_str = 0; 87 88 const xhci_port_speed_t *speed = xhci_rh_get_port_speed(rh, port); 79 89 80 90 xhci_send_enable_slot_command(hc, &cmd); … … 127 137 XHCI_EP_ERROR_COUNT_SET(ictx->endpoint_ctx[0], 3); 128 138 129 // TODO: What's the alignment? 130 xhci_device_ctx_t *dctx = malloc(sizeof(xhci_device_ctx_t)); 139 xhci_device_ctx_t *dctx = malloc32(sizeof(xhci_device_ctx_t)); 131 140 if (!dctx) { 132 141 err = ENOMEM; … … 149 158 xhci_cmd_fini(&cmd); 150 159 151 usb_address_taddress = XHCI_SLOT_DEVICE_ADDRESS(dctx->slot_ctx);152 usb_log_debug2("Obtained USB address: %d.\n", address);160 *address = XHCI_SLOT_DEVICE_ADDRESS(dctx->slot_ctx); 161 usb_log_debug2("Obtained USB address: %d.\n", *address); 153 162 154 163 // TODO: Ask libusbhost to create a control endpoint for EP0. … … 174 183 } 175 184 185 static int rh_setup_device(xhci_rh_t *rh, uint8_t port_id) 186 { 187 /** This should ideally use the libusbhost in a clean and elegant way, 188 * to create child function. The refactoring of libusbhost is not over 189 * yet, so for now it is still quirky. 190 */ 191 192 return hcd_roothub_new_device(rh->hcd_rh, port_id); 193 } 194 176 195 static int handle_connected_device(xhci_rh_t *rh, uint8_t port_id) 177 196 { … … 186 205 if (link_state == 0) { 187 206 /* USB3 is automatically advanced to enabled. */ 188 return alloc_dev(rh->hc, port_id, 0);207 return rh_setup_device(rh, port_id); 189 208 } 190 209 else if (link_state == 5) { … … 270 289 * every time USB2 port is reset. This is a 271 290 * temporary workaround. */ 272 alloc_dev(rh->hc, i, 0);291 rh_setup_device(rh, i); 273 292 } 274 293 } -
uspace/drv/bus/usb/xhci/rh.h
rd7869d7e r867b375 51 51 } xhci_port_speed_t; 52 52 53 typedef struct hcd_roothub hcd_roothub_t; 54 53 55 /* XHCI root hub instance */ 54 56 typedef struct { … … 64 66 /* Number of hub ports. */ 65 67 uint8_t max_ports; 68 69 /* We need this to create child devices */ 70 hcd_roothub_t *hcd_rh; 66 71 } xhci_rh_t; 67 72 … … 74 79 void xhci_rh_handle_port_change(xhci_rh_t *); 75 80 81 int xhci_rh_address_device(xhci_rh_t *, usb_speed_t, usb_tt_address_t, usb_address_t *); 82 76 83 #endif 77 84
Note:
See TracChangeset
for help on using the changeset viewer.
