Changes in / [cc44f7e:81c508c] in mainline
- Location:
- uspace/drv
- Files:
-
- 2 deleted
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/pciintel/pci.c
rcc44f7e r81c508c 320 320 /* Get the value of the BAR. */ 321 321 val = pci_conf_read_32(fun, addr); 322 323 #define IO_MASK (~0x3)324 #define MEM_MASK (~0xf)325 322 326 323 io = (bool) (val & 1); 327 324 if (io) { 328 325 addrw64 = false; 329 mask = IO_MASK;330 326 } else { 331 mask = MEM_MASK;332 327 switch ((val >> 1) & 3) { 333 328 case 0: … … 345 340 /* Get the address mask. */ 346 341 pci_conf_write_32(fun, addr, 0xffffffff); 347 mask &= pci_conf_read_32(fun, addr);342 mask = pci_conf_read_32(fun, addr); 348 343 349 344 /* Restore the original value. */ … … 664 659 size_t pci_bar_mask_to_size(uint32_t mask) 665 660 { 666 size_t size = mask & ~(mask - 1); 667 return size; 661 return ((mask & 0xfffffff0) ^ 0xffffffff) + 1; 668 662 } 669 663 -
uspace/drv/uhci-hcd/Makefile
rcc44f7e r81c508c 39 39 uhci.c \ 40 40 uhci_struct/transfer_descriptor.c \ 41 utils/device_keeper.c \42 41 pci.c \ 43 42 batch.c -
uspace/drv/uhci-hcd/batch.c
rcc44f7e r81c508c 33 33 */ 34 34 #include <errno.h> 35 #include <str_error.h>36 35 37 36 #include <usb/debug.h> … … 54 53 batch_t * batch_get(ddf_fun_t *fun, usb_target_t target, 55 54 usb_transfer_type_t transfer_type, size_t max_packet_size, 56 usb_speed_t speed, char *buffer, size_t size,55 dev_speed_t speed, char *buffer, size_t size, 57 56 char* setup_buffer, size_t setup_size, 58 57 usbhc_iface_transfer_in_callback_t func_in, … … 134 133 135 134 queue_head_element_td(instance->qh, addr_to_phys(instance->tds)); 136 usb_log_debug("Batch(%p) %d:%d memory structures ready.\n",137 instance, target.address, target.endpoint);138 135 return instance; 139 136 } … … 142 139 { 143 140 assert(instance); 144 usb_log_debug 2("Batch(%p) checking %d packet(s)for completion.\n",141 usb_log_debug("Checking(%p) %d packet for completion.\n", 145 142 instance, instance->packets); 146 143 instance->transfered_size = 0; … … 154 151 if (i > 0) 155 152 instance->transfered_size -= instance->setup_size; 156 usb_log_debug("Batch(%p) found error TD(%d):%x.\n",157 instance, i, instance->tds[i].status);158 153 return true; 159 154 } … … 161 156 transfer_descriptor_actual_size(&instance->tds[i]); 162 157 } 158 /* This is just an ugly trick to support the old API */ 163 159 instance->transfered_size -= instance->setup_size; 164 160 return true; … … 172 168 memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size); 173 169 174 const bool low_speed = instance->speed == USB_SPEED_LOW;175 170 int toggle = 0; 176 171 /* setup stage */ 177 172 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT, 178 instance->setup_size, toggle, false, low_speed, 179 instance->target, USB_PID_SETUP, instance->setup_buffer, 180 &instance->tds[1]); 173 instance->setup_size, toggle, false, instance->target, 174 USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]); 181 175 182 176 /* data stage */ … … 188 182 189 183 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 190 instance->max_packet_size, toggle++, false, low_speed,191 instance->target,USB_PID_OUT, data, &instance->tds[i + 1]);184 instance->max_packet_size, toggle++, false, instance->target, 185 USB_PID_OUT, data, &instance->tds[i + 1]); 192 186 } 193 187 … … 195 189 i = instance->packets - 1; 196 190 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 197 0, 1, false, low_speed,instance->target, USB_PID_IN, NULL, NULL);191 0, 1, false, instance->target, USB_PID_IN, NULL, NULL); 198 192 199 193 instance->tds[i].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 200 usb_log_debug2("Control write last TD status: %x.\n",201 instance->tds[i].status);202 194 203 195 instance->next_step = batch_call_out_and_dispose; 204 usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance);205 196 batch_schedule(instance); 206 197 } … … 210 201 assert(instance); 211 202 212 const bool low_speed = instance->speed == USB_SPEED_LOW;213 203 int toggle = 0; 214 204 /* setup stage */ 215 205 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT, 216 instance->setup_size, toggle, false, low_speed,instance->target,206 instance->setup_size, toggle, false, instance->target, 217 207 USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]); 218 208 … … 225 215 226 216 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 227 instance->max_packet_size, toggle, false, low_speed,228 instance->target,USB_PID_IN, data, &instance->tds[i + 1]);217 instance->max_packet_size, toggle, false, instance->target, 218 USB_PID_IN, data, &instance->tds[i + 1]); 229 219 } 230 220 … … 232 222 i = instance->packets - 1; 233 223 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 234 0, 1, false, low_speed,instance->target, USB_PID_OUT, NULL, NULL);224 0, 1, false, instance->target, USB_PID_OUT, NULL, NULL); 235 225 236 226 instance->tds[i].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 237 usb_log_debug2("Control read last TD status: %x.\n",238 instance->tds[i].status);239 227 240 228 instance->next_step = batch_call_in_and_dispose; 241 usb_log_debug("Batch(%p) CONTROL READ initialized.\n", instance);242 229 batch_schedule(instance); 243 230 } … … 247 234 assert(instance); 248 235 249 const bool low_speed = instance->speed == USB_SPEED_LOW;250 236 int toggle = 1; 251 237 size_t i = 0; … … 258 244 259 245 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 260 instance->max_packet_size, toggle, false, low_speed,261 instance->target,USB_PID_IN, data, next);246 instance->max_packet_size, toggle, false, instance->target, 247 USB_PID_IN, data, next); 262 248 } 263 249 … … 265 251 266 252 instance->next_step = batch_call_in_and_dispose; 267 usb_log_debug("Batch(%p) INTERRUPT IN initialized.\n", instance);268 253 batch_schedule(instance); 269 254 } … … 275 260 memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size); 276 261 277 const bool low_speed = instance->speed == USB_SPEED_LOW;278 262 int toggle = 1; 279 263 size_t i = 0; … … 286 270 287 271 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 288 instance->max_packet_size, toggle++, false, low_speed,289 instance->target,USB_PID_OUT, data, next);272 instance->max_packet_size, toggle++, false, instance->target, 273 USB_PID_OUT, data, next); 290 274 } 291 275 … … 293 277 294 278 instance->next_step = batch_call_out_and_dispose; 295 usb_log_debug("Batch(%p) INTERRUPT OUT initialized.\n", instance);296 279 batch_schedule(instance); 297 280 } … … 305 288 306 289 int err = instance->error; 307 usb_log_debug("Batch(%p) callback IN(type:%d): %s(%d), %zu.\n", 308 instance, instance->transfer_type, str_error(err), err, 309 instance->transfered_size); 290 usb_log_info("Callback IN(%d): %d, %zu.\n", instance->transfer_type, 291 err, instance->transfered_size); 310 292 311 293 instance->callback_in(instance->fun, … … 320 302 321 303 int err = instance->error; 322 usb_log_debug("Batch(%p) callback OUT(type:%d): %s(%d).\n", 323 instance, instance->transfer_type, str_error(err), err); 304 usb_log_info("Callback OUT(%d): %d.\n", instance->transfer_type, err); 324 305 instance->callback_out(instance->fun, 325 306 err, instance->arg); … … 330 311 assert(instance); 331 312 batch_call_in(instance); 332 usb_log_debug(" Batch(%p) disposing.\n", instance);313 usb_log_debug("Disposing batch: %p.\n", instance); 333 314 free32(instance->tds); 334 315 free32(instance->qh); … … 342 323 assert(instance); 343 324 batch_call_out(instance); 344 usb_log_debug(" Batch(%p) disposing.\n", instance);325 usb_log_debug("Disposing batch: %p.\n", instance); 345 326 free32(instance->tds); 346 327 free32(instance->qh); … … 357 338 return uhci_schedule(hc, instance); 358 339 } 340 /*----------------------------------------------------------------------------*/ 341 /* DEPRECATED FUNCTIONS NEEDED BY THE OLD API */ 342 void batch_control_setup_old(batch_t *instance) 343 { 344 assert(instance); 345 instance->packets = 1; 346 347 /* setup stage */ 348 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT, 349 instance->setup_size, 0, false, instance->target, 350 USB_PID_SETUP, instance->setup_buffer, NULL); 351 352 instance->next_step = batch_call_out_and_dispose; 353 batch_schedule(instance); 354 } 355 /*----------------------------------------------------------------------------*/ 356 void batch_control_write_data_old(batch_t *instance) 357 { 358 assert(instance); 359 instance->packets -= 2; 360 batch_interrupt_out(instance); 361 } 362 /*----------------------------------------------------------------------------*/ 363 void batch_control_read_data_old(batch_t *instance) 364 { 365 assert(instance); 366 instance->packets -= 2; 367 batch_interrupt_in(instance); 368 } 369 /*----------------------------------------------------------------------------*/ 370 void batch_control_write_status_old(batch_t *instance) 371 { 372 assert(instance); 373 instance->packets = 1; 374 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT, 375 0, 1, false, instance->target, USB_PID_IN, NULL, NULL); 376 instance->next_step = batch_call_in_and_dispose; 377 batch_schedule(instance); 378 } 379 /*----------------------------------------------------------------------------*/ 380 void batch_control_read_status_old(batch_t *instance) 381 { 382 assert(instance); 383 instance->packets = 1; 384 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT, 385 0, 1, false, instance->target, USB_PID_OUT, NULL, NULL); 386 instance->next_step = batch_call_out_and_dispose; 387 batch_schedule(instance); 388 } 359 389 /** 360 390 * @} -
uspace/drv/uhci-hcd/batch.h
rcc44f7e r81c508c 43 43 #include "uhci_struct/queue_head.h" 44 44 45 typedef enum { 46 LOW_SPEED, 47 FULL_SPEED, 48 } dev_speed_t; 49 45 50 typedef struct batch 46 51 { 47 52 link_t link; 48 usb_speed_t speed;53 dev_speed_t speed; 49 54 usb_target_t target; 50 55 usb_transfer_type_t transfer_type; … … 71 76 batch_t * batch_get(ddf_fun_t *fun, usb_target_t target, 72 77 usb_transfer_type_t transfer_type, size_t max_packet_size, 73 usb_speed_t speed, char *buffer, size_t size,78 dev_speed_t speed, char *buffer, size_t size, 74 79 char *setup_buffer, size_t setup_size, 75 80 usbhc_iface_transfer_in_callback_t func_in, -
uspace/drv/uhci-hcd/iface.c
rcc44f7e r81c508c 41 41 #include "iface.h" 42 42 #include "uhci.h" 43 #include "utils/device_keeper.h"44 43 45 44 /*----------------------------------------------------------------------------*/ … … 49 48 uhci_t *hc = fun_to_uhci(fun); 50 49 assert(hc); 51 usb_log_debug("Default address request with speed %d.\n", speed); 52 device_keeper_reserve_default(&hc->device_manager, speed); 50 usb_address_keeping_reserve_default(&hc->address_manager); 53 51 return EOK; 54 52 } … … 59 57 uhci_t *hc = fun_to_uhci(fun); 60 58 assert(hc); 61 usb_log_debug("Default address release.\n"); 62 device_keeper_release_default(&hc->device_manager); 59 usb_address_keeping_release_default(&hc->address_manager); 63 60 return EOK; 64 61 } … … 70 67 uhci_t *hc = fun_to_uhci(fun); 71 68 assert(hc); 72 assert(address); 73 74 usb_log_debug("Address request with speed %d.\n", speed); 75 *address = device_keeper_request(&hc->device_manager, speed); 76 usb_log_debug("Address request with result: %d.\n", *address); 69 *address = usb_address_keeping_request(&hc->address_manager); 77 70 if (*address <= 0) 78 71 return *address; … … 86 79 uhci_t *hc = fun_to_uhci(fun); 87 80 assert(hc); 88 usb_log_debug("Address bind %d-%d.\n", address, handle); 89 device_keeper_bind(&hc->device_manager, address, handle); 81 usb_address_keeping_devman_bind(&hc->address_manager, address, handle); 90 82 return EOK; 91 83 } … … 96 88 uhci_t *hc = fun_to_uhci(fun); 97 89 assert(hc); 98 usb_log_debug("Address release %d.\n", address); 99 device_keeper_release(&hc->device_manager, address); 90 usb_address_keeping_release_default(&hc->address_manager); 100 91 return EOK; 101 92 } 102 93 /*----------------------------------------------------------------------------*/ 103 94 static int interrupt_out(ddf_fun_t *fun, usb_target_t target, 104 size_t max_packet_size, void *data, size_t size, 95 size_t max_packet_size, 96 void *data, size_t size, 105 97 usbhc_iface_transfer_out_callback_t callback, void *arg) 106 98 { 107 assert(fun); 108 uhci_t *hc = fun_to_uhci(fun); 109 assert(hc); 110 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address); 111 112 usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n", 113 target.address, target.endpoint, size, max_packet_size); 99 dev_speed_t speed = FULL_SPEED; 114 100 115 101 batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT, … … 122 108 /*----------------------------------------------------------------------------*/ 123 109 static int interrupt_in(ddf_fun_t *fun, usb_target_t target, 124 size_t max_packet_size, void *data, size_t size, 110 size_t max_packet_size, 111 void *data, size_t size, 125 112 usbhc_iface_transfer_in_callback_t callback, void *arg) 126 113 { 127 assert(fun); 128 uhci_t *hc = fun_to_uhci(fun); 129 assert(hc); 130 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address); 131 usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n", 132 target.address, target.endpoint, size, max_packet_size); 114 dev_speed_t speed = FULL_SPEED; 133 115 134 116 batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT, … … 145 127 usbhc_iface_transfer_out_callback_t callback, void *arg) 146 128 { 147 assert(fun); 148 uhci_t *hc = fun_to_uhci(fun); 149 assert(hc); 150 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address); 151 usb_log_debug("Control WRITE %d:%d %zu(%zu).\n", 152 target.address, target.endpoint, size, max_packet_size); 129 dev_speed_t speed = FULL_SPEED; 153 130 154 131 batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL, … … 166 143 usbhc_iface_transfer_in_callback_t callback, void *arg) 167 144 { 168 assert(fun); 169 uhci_t *hc = fun_to_uhci(fun); 170 assert(hc); 171 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address); 145 dev_speed_t speed = FULL_SPEED; 172 146 173 usb_log_debug("Control READ %d:%d %zu(%zu).\n",174 target.address, target.endpoint, size, max_packet_size);175 147 batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL, 176 148 max_packet_size, speed, data, size, setup_data, setup_size, callback, -
uspace/drv/uhci-hcd/main.c
rcc44f7e r81c508c 82 82 usb_log_info("uhci_add_device() called\n"); 83 83 84 uintptr_t io_reg_base = 0; 85 size_t io_reg_size = 0; 86 int irq = 0; 84 85 uintptr_t io_reg_base; 86 size_t io_reg_size; 87 int irq; 87 88 88 89 int ret = … … 94 95 io_reg_base, io_reg_size, irq); 95 96 96 //ret = pci_enable_interrupts(device);97 //CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret);97 ret = pci_enable_interrupts(device); 98 CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret); 98 99 99 100 uhci_t *uhci_hc = malloc(sizeof(uhci_t)); … … 113 114 */ 114 115 device->driver_data = uhci_hc; 116 115 117 ret = register_interrupt_handler(device, irq, irq_handler, 116 118 &uhci_hc->interrupt_code); … … 147 149 { 148 150 sleep(3); 149 usb_log_enable(USB_LOG_LEVEL_ DEBUG, NAME);151 usb_log_enable(USB_LOG_LEVEL_INFO, NAME); 150 152 151 153 return ddf_driver_main(&uhci_driver); -
uspace/drv/uhci-hcd/pci.c
rcc44f7e r81c508c 38 38 #include <devman.h> 39 39 #include <device/hw_res.h> 40 41 #include <usb/debug.h>42 40 43 41 #include "pci.h" … … 85 83 irq = res->res.interrupt.irq; 86 84 irq_found = true; 87 usb_log_debug2("Found interrupt: %d.\n", irq);88 85 break; 89 86 case IO_RANGE: 90 io_address = res->res.io_range.address; 87 io_address = (uintptr_t) 88 res->res.io_range.address; 91 89 io_size = res->res.io_range.size; 92 usb_log_debug2("Found io: %llx %zu.\n",93 res->res.io_range.address, res->res.io_range.size);94 90 io_found = true; 95 91 break; … … 109 105 } 110 106 111 *io_reg_address = io_address; 112 *io_reg_size = io_size; 113 *irq_no = irq; 107 if (io_reg_address != NULL) { 108 *io_reg_address = io_address; 109 } 110 if (io_reg_size != NULL) { 111 *io_reg_size = io_size; 112 } 113 if (irq_no != NULL) { 114 *irq_no = irq; 115 } 114 116 115 117 rc = EOK; … … 125 127 IPC_FLAG_BLOCKING); 126 128 bool enabled = hw_res_enable_interrupt(parent_phone); 127 async_hangup(parent_phone);128 129 return enabled ? EOK : EIO; 129 130 } -
uspace/drv/uhci-hcd/root_hub.c
rcc44f7e r81c508c 34 34 #include <assert.h> 35 35 #include <errno.h> 36 #include <str_error.h>37 36 #include <stdio.h> 38 #include <ops/hw_res.h>39 40 37 #include <usb_iface.h> 41 38 #include <usb/debug.h> … … 44 41 #include "uhci.h" 45 42 46 /*----------------------------------------------------------------------------*/47 43 static int usb_iface_get_hc_handle_rh_impl(ddf_fun_t *root_hub_fun, 48 44 devman_handle_t *handle) … … 55 51 return EOK; 56 52 } 57 /*----------------------------------------------------------------------------*/ 53 58 54 static int usb_iface_get_address_rh_impl(ddf_fun_t *fun, devman_handle_t handle, 59 55 usb_address_t *address) … … 65 61 assert(hc); 66 62 67 usb_address_t addr = device_keeper_find(&hc->device_manager,63 usb_address_t addr = usb_address_keeping_find(&hc->address_manager, 68 64 handle); 69 65 if (addr < 0) { … … 77 73 return EOK; 78 74 } 79 /*----------------------------------------------------------------------------*/ 75 80 76 usb_iface_t usb_iface_root_hub_fun_impl = { 81 77 .get_hc_handle = usb_iface_get_hc_handle_rh_impl, 82 78 .get_address = usb_iface_get_address_rh_impl 83 79 }; 84 /*----------------------------------------------------------------------------*/85 static hw_resource_list_t *get_resource_list(ddf_fun_t *dev)86 {87 assert(dev);88 ddf_fun_t *hc_ddf_instance = dev->driver_data;89 assert(hc_ddf_instance);90 uhci_t *hc = hc_ddf_instance->driver_data;91 assert(hc);92 80 93 //TODO: fix memory leak 94 hw_resource_list_t *resource_list = malloc(sizeof(hw_resource_list_t)); 95 assert(resource_list); 96 resource_list->count = 1; 97 resource_list->resources = malloc(sizeof(hw_resource_t)); 98 assert(resource_list->resources); 99 resource_list->resources[0].type = IO_RANGE; 100 resource_list->resources[0].res.io_range.address = 101 ((uintptr_t)hc->registers) + 0x10; // see UHCI design guide 102 resource_list->resources[0].res.io_range.size = 4; 103 resource_list->resources[0].res.io_range.endianness = LITTLE_ENDIAN; 81 static ddf_dev_ops_t root_hub_ops = { 82 .interfaces[USB_DEV_IFACE] = &usb_iface_root_hub_fun_impl 83 }; 104 84 105 return resource_list;106 }107 /*----------------------------------------------------------------------------*/108 static hw_res_ops_t hw_res_iface = {109 .get_resource_list = get_resource_list,110 .enable_interrupt = NULL111 };112 /*----------------------------------------------------------------------------*/113 static ddf_dev_ops_t root_hub_ops = {114 .interfaces[USB_DEV_IFACE] = &usb_iface_root_hub_fun_impl,115 .interfaces[HW_RES_DEV_IFACE] = &hw_res_iface116 };117 85 /*----------------------------------------------------------------------------*/ 118 86 int setup_root_hub(ddf_fun_t **fun, ddf_dev_t *hc) 119 87 { 120 88 assert(fun); 121 assert(hc);122 89 int ret; 123 90 … … 138 105 ret = ddf_fun_add_match_id(hub, match_str, 100); 139 106 if (ret != EOK) { 140 usb_log_error("Failed(%d) to add root hub match id: %s\n", 141 ret, str_error(ret)); 107 usb_log_error("Failed to add root hub match id.\n"); 142 108 ddf_fun_destroy(hub); 143 return ret;109 return ENOMEM; 144 110 } 145 111 -
uspace/drv/uhci-hcd/transfer_list.c
rcc44f7e r81c508c 70 70 assert(instance); 71 71 assert(batch); 72 usb_log_debug2("Adding batch(%p) to queue %s.\n", batch, instance->name);73 72 74 73 uint32_t pa = (uintptr_t)addr_to_phys(batch->qh); … … 84 83 list_append(&batch->link, &instance->batch_list); 85 84 instance->queue_head->element = pa; 86 usb_log_debug ("Batch(%p) addedto queue %s first.\n",85 usb_log_debug2("Added batch(%p) to queue %s first.\n", 87 86 batch, instance->name); 88 87 fibril_mutex_unlock(&instance->guard); … … 97 96 queue_head_append_qh(last->qh, pa); 98 97 list_append(&batch->link, &instance->batch_list); 99 usb_log_debug ("Batch(%p) addedto queue %s last, first is %p.\n",98 usb_log_debug2("Added batch(%p) to queue %s last, first is %p.\n", 100 99 batch, instance->name, first ); 101 100 fibril_mutex_unlock(&instance->guard); … … 109 108 assert(instance->queue_head); 110 109 assert(batch->qh); 111 usb_log_debug2("Removing batch(%p) from queue %s.\n", batch, instance->name);112 110 113 111 /* I'm the first one here */ 114 112 if (batch->link.prev == &instance->batch_list) { 115 usb_log_debug(" Batch(%p) removed (FIRST) from queue %s, next element %x.\n",116 batch, instance->name,batch->qh->next_queue);113 usb_log_debug("Removing batch %p was first, next element %x.\n", 114 batch, batch->qh->next_queue); 117 115 instance->queue_head->element = batch->qh->next_queue; 118 116 } else { 119 usb_log_debug(" Batch(%p) removed (NOT FIRST) from queue, next element %x.\n",120 batch, instance->name,batch->qh->next_queue);117 usb_log_debug("Removing batch %p was NOT first, next element %x.\n", 118 batch, batch->qh->next_queue); 121 119 batch_t *prev = list_get_instance(batch->link.prev, batch_t, link); 122 120 prev->qh->next_queue = batch->qh->next_queue; … … 125 123 } 126 124 /*----------------------------------------------------------------------------*/ 127 void transfer_list_ remove_finished(transfer_list_t *instance)125 void transfer_list_check(transfer_list_t *instance) 128 126 { 129 127 assert(instance); 130 131 LIST_INITIALIZE(done);132 133 128 fibril_mutex_lock(&instance->guard); 134 129 link_t *current = instance->batch_list.next; … … 139 134 if (batch_is_complete(batch)) { 140 135 transfer_list_remove_batch(instance, batch); 141 list_append(current, &done);136 batch->next_step(batch); 142 137 } 143 138 current = next; 144 139 } 145 140 fibril_mutex_unlock(&instance->guard); 146 147 while (!list_empty(&done)) {148 link_t *item = done.next;149 list_remove(item);150 batch_t *batch = list_get_instance(item, batch_t, link);151 batch->next_step(batch);152 }153 141 } 154 142 /** -
uspace/drv/uhci-hcd/transfer_list.h
rcc44f7e r81c508c 60 60 queue_head_dispose(instance->queue_head); 61 61 } 62 void transfer_list_ remove_finished(transfer_list_t *instance);62 void transfer_list_check(transfer_list_t *instance); 63 63 64 64 void transfer_list_add_batch(transfer_list_t *instance, batch_t *batch); -
uspace/drv/uhci-hcd/uhci.c
rcc44f7e r81c508c 48 48 { 49 49 .cmd = CMD_PIO_READ_16, 50 .addr = NULL, /* patched for every instance */50 .addr = (void*)0xc022, 51 51 .dstarg = 1 52 52 }, 53 53 { 54 54 .cmd = CMD_PIO_WRITE_16, 55 .addr = NULL, /* pathed for every instance */55 .addr = (void*)0xc022, 56 56 .value = 0x1f 57 57 }, … … 68 68 assert(hc); 69 69 70 usb_address_t addr = device_keeper_find(&hc->device_manager,70 usb_address_t addr = usb_address_keeping_find(&hc->address_manager, 71 71 handle); 72 72 if (addr < 0) { … … 80 80 return EOK; 81 81 } 82 /*----------------------------------------------------------------------------*/ 82 83 83 84 static usb_iface_t hc_usb_iface = { 84 85 .get_hc_handle = usb_iface_get_hc_handle_hc_impl, … … 88 89 static ddf_dev_ops_t uhci_ops = { 89 90 .interfaces[USB_DEV_IFACE] = &hc_usb_iface, 90 .interfaces[USBHC_DEV_IFACE] = &uhci_iface ,91 .interfaces[USBHC_DEV_IFACE] = &uhci_iface 91 92 }; 92 93 … … 101 102 bool low_speed, usb_transfer_type_t, size_t size); 102 103 104 #define CHECK_RET_RETURN(ret, message...) \ 105 if (ret != EOK) { \ 106 usb_log_error(message); \ 107 return ret; \ 108 } else (void) 0 103 109 104 110 int uhci_init(uhci_t *instance, ddf_dev_t *dev, void *regs, size_t reg_size) … … 106 112 assert(reg_size >= sizeof(regs_t)); 107 113 int ret; 108 109 #define CHECK_RET_DEST_FUN_RETURN(ret, message...) \110 if (ret != EOK) { \111 usb_log_error(message); \112 if (instance->ddf_instance) \113 ddf_fun_destroy(instance->ddf_instance); \114 return ret; \115 } else (void) 0116 114 117 115 /* … … 119 117 */ 120 118 instance->ddf_instance = ddf_fun_create(dev, fun_exposed, "uhci"); 121 ret = (instance->ddf_instance == NULL) ? ENOMEM : EOK; 122 CHECK_RET_DEST_FUN_RETURN(ret, "Failed to create UHCI device function.\n"); 123 119 if (instance->ddf_instance == NULL) { 120 usb_log_error("Failed to create UHCI device function.\n"); 121 return ENOMEM; 122 } 124 123 instance->ddf_instance->ops = &uhci_ops; 125 124 instance->ddf_instance->driver_data = instance; 126 125 127 126 ret = ddf_fun_bind(instance->ddf_instance); 128 CHECK_RET_ DEST_FUN_RETURN(ret, "Failed(%d)to bind UHCI device function: %s.\n",129 ret,str_error(ret));127 CHECK_RET_RETURN(ret, "Failed to bind UHCI device function: %s.\n", 128 str_error(ret)); 130 129 131 130 /* allow access to hc control registers */ 132 131 regs_t *io; 133 132 ret = pio_enable(regs, reg_size, (void**)&io); 134 CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to gain access to registers at %p: %s.\n", 135 ret, str_error(ret), io); 133 CHECK_RET_RETURN(ret, "Failed to gain access to registers at %p.\n", io); 136 134 instance->registers = io; 137 usb_log_debug("Device registers a t %p(%u) accessible.\n", io, reg_size);135 usb_log_debug("Device registers accessible.\n"); 138 136 139 137 ret = uhci_init_mem_structures(instance); 140 CHECK_RET_ DEST_FUN_RETURN(ret, "Failed to initialize UHCImemory structures.\n");138 CHECK_RET_RETURN(ret, "Failed to initialize memory structures.\n"); 141 139 142 140 uhci_init_hw(instance); 143 141 144 142 instance->cleaner = fibril_create(uhci_interrupt_emulator, instance); 145 fibril_add_ready(instance->cleaner);143 // fibril_add_ready(instance->cleaner); 146 144 147 145 instance->debug_checker = fibril_create(uhci_debug_checker, instance); 148 146 fibril_add_ready(instance->debug_checker); 149 147 150 usb_log_info("Started UHCI driver.\n"); 151 return EOK; 152 #undef CHECK_RET_DEST_FUN_RETURN 148 return EOK; 153 149 } 154 150 /*----------------------------------------------------------------------------*/ 155 151 void uhci_init_hw(uhci_t *instance) 156 152 { 157 /* reset everything, who knows what touched it before us */158 pio_write_16(&instance->registers->usbcmd, UHCI_CMD_GLOBAL_RESET);159 async_usleep(10000); /* 10ms according to USB spec */160 pio_write_16(&instance->registers->usbcmd, 0);161 162 /* reset hc, all states and counters */163 pio_write_16(&instance->registers->usbcmd, UHCI_CMD_HCRESET);164 while ((pio_read_16(&instance->registers->usbcmd) & UHCI_CMD_HCRESET) != 0)165 { async_usleep(10); }166 153 167 154 /* set framelist pointer */ … … 176 163 pio_write_16(&instance->registers->usbcmd, 177 164 UHCI_CMD_RUN_STOP | UHCI_CMD_MAX_PACKET | UHCI_CMD_CONFIGURE); 165 usb_log_debug("Started UHCI HC.\n"); 178 166 } 179 167 /*----------------------------------------------------------------------------*/ … … 181 169 { 182 170 assert(instance); 183 #define CHECK_RET_DEST_CMDS_RETURN(ret, message...) \184 if (ret != EOK) { \185 usb_log_error(message); \186 if (instance->interrupt_code.cmds != NULL) \187 free(instance->interrupt_code.cmds); \188 return ret; \189 } else (void) 0190 171 191 172 /* init interrupt code */ 192 instance->interrupt_code.cmds = malloc(sizeof(uhci_cmds)); 193 int ret = (instance->interrupt_code.cmds == NULL) ? ENOMEM : EOK; 194 CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to allocate interrupt cmds space.\n"); 195 196 { 197 irq_cmd_t *interrupt_commands = instance->interrupt_code.cmds; 198 memcpy(interrupt_commands, uhci_cmds, sizeof(uhci_cmds)); 199 interrupt_commands[0].addr = (void*)&instance->registers->usbsts; 200 interrupt_commands[1].addr = (void*)&instance->registers->usbsts; 201 instance->interrupt_code.cmdcount = 202 sizeof(uhci_cmds) / sizeof(irq_cmd_t); 203 } 173 irq_cmd_t *interrupt_commands = malloc(sizeof(uhci_cmds)); 174 if (interrupt_commands == NULL) { 175 return ENOMEM; 176 } 177 memcpy(interrupt_commands, uhci_cmds, sizeof(uhci_cmds)); 178 interrupt_commands[0].addr = (void*)&instance->registers->usbsts; 179 interrupt_commands[1].addr = (void*)&instance->registers->usbsts; 180 instance->interrupt_code.cmds = interrupt_commands; 181 instance->interrupt_code.cmdcount = 182 sizeof(uhci_cmds) / sizeof(irq_cmd_t); 204 183 205 184 /* init transfer lists */ 206 ret = uhci_init_transfer_lists(instance);207 CHECK_RET_ DEST_CMDS_RETURN(ret, "Failed to initialize transfer lists.\n");185 int ret = uhci_init_transfer_lists(instance); 186 CHECK_RET_RETURN(ret, "Failed to initialize transfer lists.\n"); 208 187 usb_log_debug("Initialized transfer lists.\n"); 209 188 … … 211 190 instance->frame_list = get_page(); 212 191 ret = instance ? EOK : ENOMEM; 213 CHECK_RET_ DEST_CMDS_RETURN(ret, "Failed to get frame list page.\n");192 CHECK_RET_RETURN(ret, "Failed to get frame list page.\n"); 214 193 usb_log_debug("Initialized frame list.\n"); 215 194 … … 218 197 instance->transfers_interrupt.queue_head_pa 219 198 | LINK_POINTER_QUEUE_HEAD_FLAG; 220 221 199 unsigned i = 0; 222 200 for(; i < UHCI_FRAME_LIST_COUNT; ++i) { … … 225 203 226 204 /* init address keeper(libusb) */ 227 device_keeper_init(&instance->device_manager); 228 usb_log_debug("Initialized device manager.\n"); 229 230 return EOK; 231 #undef CHECK_RET_DEST_CMDS_RETURN 205 usb_address_keeping_init(&instance->address_manager, USB11_ADDRESS_MAX); 206 usb_log_debug("Initialized address manager.\n"); 207 208 return EOK; 232 209 } 233 210 /*----------------------------------------------------------------------------*/ … … 235 212 { 236 213 assert(instance); 237 #define CHECK_RET_CLEAR_RETURN(ret, message...) \238 if (ret != EOK) { \239 usb_log_error(message); \240 transfer_list_fini(&instance->transfers_bulk_full); \241 transfer_list_fini(&instance->transfers_control_full); \242 transfer_list_fini(&instance->transfers_control_slow); \243 transfer_list_fini(&instance->transfers_interrupt); \244 return ret; \245 } else (void) 0246 214 247 215 /* initialize TODO: check errors */ 248 216 int ret; 249 217 ret = transfer_list_init(&instance->transfers_bulk_full, "BULK_FULL"); 250 CHECK_RET_CLEAR_RETURN(ret, "Failed to init BULK list.");218 assert(ret == EOK); 251 219 ret = transfer_list_init(&instance->transfers_control_full, "CONTROL_FULL"); 252 CHECK_RET_CLEAR_RETURN(ret, "Failed to init CONTROL FULL list.");220 assert(ret == EOK); 253 221 ret = transfer_list_init(&instance->transfers_control_slow, "CONTROL_SLOW"); 254 CHECK_RET_CLEAR_RETURN(ret, "Failed to init CONTROL SLOW list.");222 assert(ret == EOK); 255 223 ret = transfer_list_init(&instance->transfers_interrupt, "INTERRUPT"); 256 CHECK_RET_CLEAR_RETURN(ret, "Failed to init INTERRUPT list.");224 assert(ret == EOK); 257 225 258 226 transfer_list_set_next(&instance->transfers_control_full, … … 281 249 282 250 return EOK; 283 #undef CHECK_RET_CLEAR_RETURN284 251 } 285 252 /*----------------------------------------------------------------------------*/ … … 288 255 assert(instance); 289 256 assert(batch); 290 const int low_speed = (batch->speed == USB_SPEED_LOW);257 const int low_speed = (batch->speed == LOW_SPEED); 291 258 if (!allowed_usb_packet( 292 259 low_speed, batch->transfer_type, batch->max_packet_size)) { … … 309 276 { 310 277 assert(instance); 311 //if ((status & (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)) == 0)312 //return;313 // usb_log_debug2("UHCI interrupt: %X.\n", status);314 transfer_list_ remove_finished(&instance->transfers_interrupt);315 transfer_list_ remove_finished(&instance->transfers_control_slow);316 transfer_list_ remove_finished(&instance->transfers_control_full);317 transfer_list_ remove_finished(&instance->transfers_bulk_full);278 if ((status & (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)) == 0) 279 return; 280 usb_log_debug("UHCI interrupt: %X.\n", status); 281 transfer_list_check(&instance->transfers_interrupt); 282 transfer_list_check(&instance->transfers_control_slow); 283 transfer_list_check(&instance->transfers_control_full); 284 transfer_list_check(&instance->transfers_bulk_full); 318 285 } 319 286 /*----------------------------------------------------------------------------*/ … … 324 291 assert(instance); 325 292 326 while 293 while(1) { 327 294 uint16_t status = pio_read_16(&instance->registers->usbsts); 328 if (status != 0)329 usb_log_debug2("UHCI status: %x.\n", status);330 status |= 1;331 295 uhci_interrupt(instance, status); 332 pio_write_16(&instance->registers->usbsts, 0x1f); 333 async_usleep(UHCI_CLEANER_TIMEOUT * 5); 296 async_usleep(UHCI_CLEANER_TIMEOUT); 334 297 } 335 298 return EOK; … … 344 307 const uint16_t sts = pio_read_16(&instance->registers->usbsts); 345 308 const uint16_t intr = pio_read_16(&instance->registers->usbintr); 346 if (((cmd & UHCI_CMD_RUN_STOP) != 1) || (sts != 0)) { 347 usb_log_debug2("Command: %X Status: %X Intr: %x\n", 348 cmd, sts, intr); 349 } 350 351 uintptr_t frame_list = 352 pio_read_32(&instance->registers->flbaseadd) & ~0xfff; 309 usb_log_debug("Command: %X Status: %X Interrupts: %x\n", 310 cmd, sts, intr); 311 312 uintptr_t frame_list = pio_read_32(&instance->registers->flbaseadd); 353 313 if (frame_list != addr_to_phys(instance->frame_list)) { 354 314 usb_log_debug("Framelist address: %p vs. %p.\n", -
uspace/drv/uhci-hcd/uhci.h
rcc44f7e r81c508c 41 41 #include <ddi.h> 42 42 43 #include <usb/addrkeep.h> 43 44 #include <usbhc_iface.h> 44 45 46 #include "transfer_list.h" 45 47 #include "batch.h" 46 #include "transfer_list.h"47 #include "utils/device_keeper.h"48 48 49 49 typedef struct uhci_regs { … … 82 82 83 83 typedef struct uhci { 84 device_keeper_t device_manager; 85 84 usb_address_keeping_t address_manager; 86 85 volatile regs_t *registers; 87 86 -
uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.c
rcc44f7e r81c508c 39 39 40 40 void transfer_descriptor_init(transfer_descriptor_t *instance, 41 int error_count, size_t size, bool toggle, bool isochronous, bool low_speed,41 int error_count, size_t size, bool toggle, bool isochronous, 42 42 usb_target_t target, int pid, void *buffer, transfer_descriptor_t *next) 43 43 { … … 50 50 instance->status = 0 51 51 | ((error_count & TD_STATUS_ERROR_COUNT_MASK) << TD_STATUS_ERROR_COUNT_POS) 52 | (low_speed ? TD_STATUS_LOW_SPEED_FLAG : 0)53 52 | TD_STATUS_ERROR_ACTIVE; 54 53 … … 67 66 } 68 67 69 usb_log_ debug2("Created TD: %X:%X:%X:%X(%p).\n",68 usb_log_info("Created TD: %X:%X:%X:%X(%p).\n", 70 69 instance->next, instance->status, instance->device, 71 70 instance->buffer_ptr, buffer); 71 #if 0 72 if (size) { 73 unsigned char * buff = buffer; 74 uhci_print_verbose("TD Buffer dump(%p-%dB): ", buffer, size); 75 unsigned i = 0; 76 /* TODO: Verbose? */ 77 for (; i < size; ++i) { 78 printf((i & 1) ? "%x " : "%x", buff[i]); 79 } 80 printf("\n"); 81 } 82 #endif 72 83 } 73 84 /*----------------------------------------------------------------------------*/ … … 77 88 78 89 if ((instance->status & TD_STATUS_ERROR_STALLED) != 0) 79 return E STALL;90 return EIO; 80 91 81 92 if ((instance->status & TD_STATUS_ERROR_CRC) != 0) 82 return E BADCHECKSUM;93 return EAGAIN; 83 94 84 95 if ((instance->status & TD_STATUS_ERROR_BUFFER) != 0) -
uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.h
rcc44f7e r81c508c 92 92 93 93 void transfer_descriptor_init(transfer_descriptor_t *instance, 94 int error_count, size_t size, bool toggle, bool isochronous, bool low_speed,94 int error_count, size_t size, bool toggle, bool isochronous, 95 95 usb_target_t target, int pid, void *buffer, transfer_descriptor_t * next); 96 96 -
uspace/drv/uhci-rhd/main.c
rcc44f7e r81c508c 33 33 */ 34 34 #include <ddf/driver.h> 35 #include <devman.h>36 #include <device/hw_res.h>37 35 #include <usb_iface.h> 38 36 #include <usb/ddfiface.h> … … 45 43 46 44 #define NAME "uhci-rhd" 47 static int hc_get_my_registers(ddf_dev_t *dev,48 uintptr_t *io_reg_address, size_t *io_reg_size);49 45 50 46 static int usb_iface_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle) … … 84 80 } 85 81 86 uintptr_t io_regs = 0; 87 size_t io_size = 0; 88 89 int ret = hc_get_my_registers(device, &io_regs, &io_size); 90 assert(ret == EOK); 91 92 /* TODO: verify values from hc */ 93 usb_log_info("I/O regs at 0x%X (size %zu).\n", io_regs, io_size); 94 ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device); 82 /* TODO: get register values from hc */ 83 int ret = uhci_root_hub_init(rh, (void*)0xc030, 4, device); 95 84 if (ret != EOK) { 96 85 usb_log_error("Failed(%d) to initialize driver instance.\n", ret); … … 113 102 .driver_ops = &uhci_rh_driver_ops 114 103 }; 115 /*----------------------------------------------------------------------------*/ 104 116 105 int main(int argc, char *argv[]) 117 106 { 118 usb_log_enable(USB_LOG_LEVEL_ DEBUG, NAME);107 usb_log_enable(USB_LOG_LEVEL_INFO, NAME); 119 108 return ddf_driver_main(&uhci_rh_driver); 120 }121 /*----------------------------------------------------------------------------*/122 int hc_get_my_registers(ddf_dev_t *dev,123 uintptr_t *io_reg_address, size_t *io_reg_size)124 {125 assert(dev != NULL);126 127 int parent_phone = devman_parent_device_connect(dev->handle,128 IPC_FLAG_BLOCKING);129 if (parent_phone < 0) {130 return parent_phone;131 }132 133 int rc;134 135 hw_resource_list_t hw_resources;136 rc = hw_res_get_resource_list(parent_phone, &hw_resources);137 if (rc != EOK) {138 goto leave;139 }140 141 uintptr_t io_address = 0;142 size_t io_size = 0;143 bool io_found = false;144 145 size_t i;146 for (i = 0; i < hw_resources.count; i++) {147 hw_resource_t *res = &hw_resources.resources[i];148 switch (res->type) {149 case IO_RANGE:150 io_address = (uintptr_t)151 res->res.io_range.address;152 io_size = res->res.io_range.size;153 io_found = true;154 break;155 default:156 break;157 }158 }159 160 if (!io_found) {161 rc = ENOENT;162 goto leave;163 }164 165 if (io_reg_address != NULL) {166 *io_reg_address = io_address;167 }168 if (io_reg_size != NULL) {169 *io_reg_size = io_size;170 }171 rc = EOK;172 leave:173 async_hangup(parent_phone);174 175 return rc;176 109 } 177 110 /** -
uspace/drv/uhci-rhd/port.c
rcc44f7e r81c508c 34 34 #include <errno.h> 35 35 #include <str_error.h> 36 #include <fibril_synch.h>37 36 38 37 #include <usb/usb.h> /* usb_address_t */ … … 46 45 #include "port_status.h" 47 46 48 static int uhci_port_new_device(uhci_port_t *port , uint16_t status);47 static int uhci_port_new_device(uhci_port_t *port); 49 48 static int uhci_port_remove_device(uhci_port_t *port); 50 49 static int uhci_port_set_enabled(uhci_port_t *port, bool enabled); 51 50 static int uhci_port_check(void *port); 52 static int new_device_enable_port(int portno, void *arg);53 51 54 52 int uhci_port_init( 55 53 uhci_port_t *port, port_status_t *address, unsigned number, 56 unsigned usec, ddf_dev_t *rh )54 unsigned usec, ddf_dev_t *rh, int parent_phone) 57 55 { 58 56 assert(port); … … 71 69 port->checker = fibril_create(uhci_port_check, port); 72 70 if (port->checker == 0) { 73 usb_log_error("Port(%p - %d): failed to launch root hub fibril.", 74 port->address, port->number); 71 usb_log_error(": failed to launch root hub fibril."); 75 72 return ENOMEM; 76 73 } 77 74 fibril_add_ready(port->checker); 78 usb_log_debug( "Port(%p - %d): Added fibril. %x\n",79 port->address, port->number, port->checker);75 usb_log_debug( 76 "Added fibril for port %d: %p.\n", number, port->checker); 80 77 return EOK; 81 78 } … … 93 90 uhci_port_t *port_instance = port; 94 91 assert(port_instance); 95 // port_status_write(port_instance->address, 0);96 97 unsigned count = 0;98 92 99 93 while (1) { 100 async_usleep(port_instance->wait_period_usec);101 102 94 /* read register value */ 103 95 port_status_t port_status = … … 105 97 106 98 /* debug print */ 107 static fibril_mutex_t dbg_mtx = FIBRIL_MUTEX_INITIALIZER(dbg_mtx); 108 fibril_mutex_lock(&dbg_mtx); 109 usb_log_debug2("Port(%p - %d): Status: %#04x. === %u\n", 110 port_instance->address, port_instance->number, port_status, count++); 111 // print_port_status(port_status); 112 fibril_mutex_unlock(&dbg_mtx); 113 114 if ((port_status & STATUS_CONNECTED_CHANGED) != 0) { 115 usb_log_debug("Port(%p - %d): Connected change detected: %x.\n", 116 port_instance->address, port_instance->number, port_status); 117 118 99 usb_log_debug("Port %d status at %p: 0x%04x.\n", 100 port_instance->number, port_instance->address, port_status); 101 print_port_status(port_status); 102 103 if (port_status & STATUS_CONNECTED_CHANGED) { 119 104 int rc = usb_hc_connection_open( 120 105 &port_instance->hc_connection); 121 106 if (rc != EOK) { 122 usb_log_error("Port(%p - %d): Failed to connect to HC.", 123 port_instance->address, port_instance->number); 124 continue; 107 usb_log_error("Failed to connect to HC."); 108 goto next; 125 109 } 126 110 127 /* remove any old device */128 if (port_instance->attached_device) {129 u sb_log_debug("Port(%p - %d): Removing device.\n",130 port_instance->address, port_instance->number);111 if (port_status & STATUS_CONNECTED) { 112 /* new device */ 113 uhci_port_new_device(port_instance); 114 } else { 131 115 uhci_port_remove_device(port_instance); 132 }133 134 if ((port_status & STATUS_CONNECTED) != 0) {135 /* new device */136 uhci_port_new_device(port_instance, port_status);137 } else {138 /* ack changes by writing one to WC bits */139 port_status_write(port_instance->address, port_status);140 usb_log_debug("Port(%p - %d): Change status ACK.\n",141 port_instance->address, port_instance->number);142 116 } 143 117 … … 145 119 &port_instance->hc_connection); 146 120 if (rc != EOK) { 147 usb_log_error(" Port(%p - %d): Failed to disconnect from HC.",148 port_instance->address, port_instance->number);121 usb_log_error("Failed to disconnect from HC."); 122 goto next; 149 123 } 150 124 } 125 next: 126 async_usleep(port_instance->wait_period_usec); 151 127 } 152 128 return EOK; … … 163 139 uhci_port_t *port = (uhci_port_t *) arg; 164 140 165 usb_log_debug2("Port(%p - %d): new_device_enable_port.\n", 166 port->address, port->number); 141 usb_log_debug("new_device_enable_port(%d)\n", port->number); 167 142 168 143 /* … … 172 147 async_usleep(100000); 173 148 149 /* Enable the port. */ 150 uhci_port_set_enabled(port, true); 174 151 175 152 /* The hub maintains the reset signal to that port for 10 ms … … 177 154 */ 178 155 { 179 usb_log_debug(" Port(%p - %d): Reset Signal start.\n",180 port-> address, port->number);156 usb_log_debug("Reset Signal start on port %d.\n", 157 port->number); 181 158 port_status_t port_status = 182 159 port_status_read(port->address); … … 188 165 port_status &= ~STATUS_IN_RESET; 189 166 port_status_write(port->address, port_status); 190 usb_log_debug("Port(%p - %d): Reset Signal stop.\n", 191 port->address, port->number); 192 } 193 194 /* Enable the port. */ 195 uhci_port_set_enabled(port, true); 196 197 return EOK; 198 } 199 200 /*----------------------------------------------------------------------------*/ 201 static int uhci_port_new_device(uhci_port_t *port, uint16_t status) 167 usb_log_debug("Reset Signal stop on port %d.\n", 168 port->number); 169 } 170 171 return EOK; 172 } 173 174 /*----------------------------------------------------------------------------*/ 175 static int uhci_port_new_device(uhci_port_t *port) 202 176 { 203 177 assert(port); 204 178 assert(usb_hc_connection_is_opened(&port->hc_connection)); 205 179 206 usb_log_info("Port(%p-%d): Detected new device.\n", 207 port->address, port->number); 180 usb_log_info("Detected new device on port %u.\n", port->number); 208 181 209 182 usb_address_t dev_addr; 210 183 int rc = usb_hc_new_device_wrapper(port->rh, &port->hc_connection, 211 ((status & STATUS_LOW_SPEED) != 0) ? USB_SPEED_LOW :USB_SPEED_FULL,184 USB_SPEED_FULL, 212 185 new_device_enable_port, port->number, port, 213 186 &dev_addr, &port->attached_device, NULL, NULL, NULL); 214 215 187 if (rc != EOK) { 216 usb_log_error(" Port(%p-%d): Failed(%d) adding new device: %s.\n",217 port-> address, port->number, rc, str_error(rc));188 usb_log_error("Failed adding new device on port %u: %s.\n", 189 port->number, str_error(rc)); 218 190 uhci_port_set_enabled(port, false); 219 191 return rc; 220 192 } 221 193 222 usb_log_info(" Port(%p-%d): New devicehas address %d (handle %zu).\n",223 port-> address, port->number, dev_addr, port->attached_device);194 usb_log_info("New device on port %u has address %d (handle %zu).\n", 195 port->number, dev_addr, port->attached_device); 224 196 225 197 return EOK; … … 229 201 static int uhci_port_remove_device(uhci_port_t *port) 230 202 { 231 usb_log_error(" Port(%p-%d):Don't know how to remove device %#x.\n",232 port->address, port->number,(unsigned int)port->attached_device);203 usb_log_error("Don't know how to remove device %#x.\n", 204 (unsigned int)port->attached_device); 233 205 // uhci_port_set_enabled(port, false); 234 206 return EOK; … … 251 223 port_status_write(port->address, port_status); 252 224 253 usb_log_info(" Port(%p-%d): %sabled port.\n",254 port->address, port->number, enabled ? "En" : "Dis");225 usb_log_info("%s port %d.\n", 226 enabled ? "Enabled" : "Disabled", port->number); 255 227 return EOK; 256 228 } -
uspace/drv/uhci-rhd/port.h
rcc44f7e r81c508c 55 55 int uhci_port_init( 56 56 uhci_port_t *port, port_status_t *address, unsigned number, 57 unsigned usec, ddf_dev_t *rh );57 unsigned usec, ddf_dev_t *rh, int parent_phone); 58 58 59 59 void uhci_port_fini(uhci_port_t *port); -
uspace/drv/uhci-rhd/port_status.c
rcc44f7e r81c508c 41 41 struct flag_name 42 42 { 43 u int16_tflag;43 unsigned flag; 44 44 const char *name; 45 45 }; … … 65 65 for (;i < sizeof(flags)/sizeof(struct flag_name); ++i) { 66 66 usb_log_debug2("\t%s status: %s.\n", flags[i].name, 67 ((value & flags[i].flag) != 0)? "YES" : "NO");67 value & flags[i].flag ? "YES" : "NO"); 68 68 } 69 69 } -
uspace/drv/uhci-rhd/port_status.h
rcc44f7e r81c508c 41 41 typedef uint16_t port_status_t; 42 42 43 #define STATUS_CONNECTED (1 << 0) 44 #define STATUS_CONNECTED_CHANGED (1 << 1) 45 #define STATUS_ENABLED (1 << 2) 46 #define STATUS_ENABLED_CHANGED (1 << 3) 47 #define STATUS_LINE_D_PLUS (1 << 4) 48 #define STATUS_LINE_D_MINUS (1 << 5) 49 #define STATUS_RESUME (1 << 6) 50 #define STATUS_ALWAYS_ONE (1 << 7) 43 enum { 44 STATUS_CONNECTED = 1 << 0, 45 STATUS_CONNECTED_CHANGED = 1 << 1, 46 STATUS_ENABLED = 1 << 2, 47 STATUS_ENABLED_CHANGED = 1 << 3, 48 STATUS_LINE_D_PLUS = 1 << 4, 49 STATUS_LINE_D_MINUS = 1 << 5, 50 STATUS_RESUME = 1 << 6, 51 STATUS_ALWAYS_ONE = 1 << 7, 51 52 52 #define STATUS_LOW_SPEED (1 << 8) 53 #define STATUS_IN_RESET (1 << 9) 54 #define STATUS_SUSPEND (1 << 12) 53 STATUS_LOW_SPEED = 1 << 8, 54 STATUS_IN_RESET = 1 << 9, 55 STATUS_SUSPEND = 1 << 12, 56 }; 55 57 56 58 static inline port_status_t port_status_read(port_status_t * address) -
uspace/drv/uhci-rhd/root_hub.c
rcc44f7e r81c508c 40 40 #include "root_hub.h" 41 41 42 42 43 int uhci_root_hub_init( 43 44 uhci_root_hub_t *instance, void *addr, size_t size, ddf_dev_t *rh) … … 46 47 assert(rh); 47 48 int ret; 49 ret = usb_hc_find(rh->handle, &instance->hc_handle); 50 usb_log_info("rh found(%d) hc handle: %d.\n", ret, instance->hc_handle); 51 if (ret != EOK) { 52 return ret; 53 } 48 54 49 55 /* allow access to root hub registers */ 50 56 assert(sizeof(port_status_t) * UHCI_ROOT_HUB_PORT_COUNT == size); 51 57 port_status_t *regs; 52 ret = pio_enable(addr, size, (void**)®s); 58 ret = pio_enable( 59 addr, sizeof(port_status_t) * UHCI_ROOT_HUB_PORT_COUNT, (void**)®s); 53 60 54 61 if (ret < 0) { … … 60 67 unsigned i = 0; 61 68 for (; i < UHCI_ROOT_HUB_PORT_COUNT; ++i) { 69 /* connect to the parent device (HC) */ 70 int parent_phone = devman_device_connect(instance->hc_handle, 0); 71 //usb_drv_hc_connect(rh, instance->hc_handle, 0); 72 if (parent_phone < 0) { 73 usb_log_error("Failed to connect to the HC device port %d.\n", i); 74 return parent_phone; 75 } 62 76 /* mind pointer arithmetics */ 63 ret = uhci_port_init(64 &instance->ports[i], regs + i, i, ROOT_HUB_WAIT_USEC, rh );77 int ret = uhci_port_init( 78 &instance->ports[i], regs + i, i, ROOT_HUB_WAIT_USEC, rh, parent_phone); 65 79 if (ret != EOK) { 66 80 unsigned j = 0; -
uspace/drv/uhci-rhd/root_hub.h
rcc44f7e r81c508c 41 41 42 42 #define UHCI_ROOT_HUB_PORT_COUNT 2 43 #define ROOT_HUB_WAIT_USEC 5000000 /* 5 seconds */ 43 #define UHCI_ROOT_HUB_PORT_REGISTERS_OFFSET 0x10 44 #define ROOT_HUB_WAIT_USEC 10000000 /* 10 seconds */ 44 45 45 46 typedef struct root_hub {
Note:
See TracChangeset
for help on using the changeset viewer.