Changes in / [81c508c:299d53e] in mainline
- Location:
- uspace/drv
- Files:
-
- 2 added
- 1 deleted
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/pciintel/pci.c
r81c508c r299d53e 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) 322 325 323 326 io = (bool) (val & 1); 324 327 if (io) { 325 328 addrw64 = false; 329 mask = IO_MASK; 326 330 } else { 331 mask = MEM_MASK; 327 332 switch ((val >> 1) & 3) { 328 333 case 0: … … 340 345 /* Get the address mask. */ 341 346 pci_conf_write_32(fun, addr, 0xffffffff); 342 mask = pci_conf_read_32(fun, addr);347 mask &= pci_conf_read_32(fun, addr); 343 348 344 349 /* Restore the original value. */ … … 659 664 size_t pci_bar_mask_to_size(uint32_t mask) 660 665 { 661 return ((mask & 0xfffffff0) ^ 0xffffffff) + 1; 666 size_t size = mask & ~(mask - 1); 667 return size; 662 668 } 663 669 -
uspace/drv/uhci-hcd/Makefile
r81c508c r299d53e 39 39 uhci.c \ 40 40 uhci_struct/transfer_descriptor.c \ 41 utils/device_keeper.c \ 41 42 pci.c \ 42 43 batch.c -
uspace/drv/uhci-hcd/batch.c
r81c508c r299d53e 33 33 */ 34 34 #include <errno.h> 35 #include <str_error.h> 35 36 36 37 #include <usb/debug.h> … … 53 54 batch_t * batch_get(ddf_fun_t *fun, usb_target_t target, 54 55 usb_transfer_type_t transfer_type, size_t max_packet_size, 55 dev_speed_t speed, char *buffer, size_t size,56 usb_speed_t speed, char *buffer, size_t size, 56 57 char* setup_buffer, size_t setup_size, 57 58 usbhc_iface_transfer_in_callback_t func_in, … … 139 140 { 140 141 assert(instance); 141 usb_log_debug ("Checking(%p) %d packetfor completion.\n",142 usb_log_debug2("Batch(%p) checking %d packet(s) for completion.\n", 142 143 instance, instance->packets); 143 144 instance->transfered_size = 0; … … 151 152 if (i > 0) 152 153 instance->transfered_size -= instance->setup_size; 154 usb_log_debug("Batch(%p) found error TD(%d):%x.\n", 155 instance, i, instance->tds[i].status); 153 156 return true; 154 157 } … … 156 159 transfer_descriptor_actual_size(&instance->tds[i]); 157 160 } 158 /* This is just an ugly trick to support the old API */159 161 instance->transfered_size -= instance->setup_size; 160 162 return true; … … 168 170 memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size); 169 171 172 const bool low_speed = instance->speed == USB_SPEED_LOW; 170 173 int toggle = 0; 171 174 /* setup stage */ 172 175 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT, 173 instance->setup_size, toggle, false, instance->target, 174 USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]); 176 instance->setup_size, toggle, false, low_speed, 177 instance->target, USB_PID_SETUP, instance->setup_buffer, 178 &instance->tds[1]); 175 179 176 180 /* data stage */ … … 182 186 183 187 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 184 instance->max_packet_size, toggle++, false, instance->target,185 USB_PID_OUT, data, &instance->tds[i + 1]);188 instance->max_packet_size, toggle++, false, low_speed, 189 instance->target, USB_PID_OUT, data, &instance->tds[i + 1]); 186 190 } 187 191 … … 189 193 i = instance->packets - 1; 190 194 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 191 0, 1, false, instance->target, USB_PID_IN, NULL, NULL);195 0, 1, false, low_speed, instance->target, USB_PID_IN, NULL, NULL); 192 196 193 197 instance->tds[i].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 198 usb_log_debug("Control write last TD status: %x.\n", 199 instance->tds[i].status); 194 200 195 201 instance->next_step = batch_call_out_and_dispose; … … 201 207 assert(instance); 202 208 209 const bool low_speed = instance->speed == USB_SPEED_LOW; 203 210 int toggle = 0; 204 211 /* setup stage */ 205 212 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT, 206 instance->setup_size, toggle, false, instance->target,213 instance->setup_size, toggle, false, low_speed, instance->target, 207 214 USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]); 208 215 … … 215 222 216 223 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 217 instance->max_packet_size, toggle, false, instance->target,218 224 instance->max_packet_size, toggle, false, low_speed, 225 instance->target, USB_PID_IN, data, &instance->tds[i + 1]); 219 226 } 220 227 … … 222 229 i = instance->packets - 1; 223 230 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 224 0, 1, false, instance->target, USB_PID_OUT, NULL, NULL);231 0, 1, false, low_speed, instance->target, USB_PID_OUT, NULL, NULL); 225 232 226 233 instance->tds[i].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 234 usb_log_debug("Control read last TD status: %x.\n", 235 instance->tds[i].status); 227 236 228 237 instance->next_step = batch_call_in_and_dispose; … … 234 243 assert(instance); 235 244 245 const bool low_speed = instance->speed == USB_SPEED_LOW; 236 246 int toggle = 1; 237 247 size_t i = 0; … … 244 254 245 255 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 246 instance->max_packet_size, toggle, false, instance->target,247 USB_PID_IN, data, next);256 instance->max_packet_size, toggle, false, low_speed, 257 instance->target, USB_PID_IN, data, next); 248 258 } 249 259 … … 260 270 memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size); 261 271 272 const bool low_speed = instance->speed == USB_SPEED_LOW; 262 273 int toggle = 1; 263 274 size_t i = 0; … … 270 281 271 282 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 272 instance->max_packet_size, toggle++, false, instance->target,273 USB_PID_OUT, data, next);283 instance->max_packet_size, toggle++, false, low_speed, 284 instance->target, USB_PID_OUT, data, next); 274 285 } 275 286 … … 288 299 289 300 int err = instance->error; 290 usb_log_info("Callback IN(%d): %d, %zu.\n", instance->transfer_type, 291 err, instance->transfered_size); 301 usb_log_info("Batch(%p) callback IN(type:%d): %s(%d), %zu.\n", 302 instance, instance->transfer_type, str_error(err), err, 303 instance->transfered_size); 292 304 293 305 instance->callback_in(instance->fun, … … 302 314 303 315 int err = instance->error; 304 usb_log_info("Callback OUT(%d): %d.\n", instance->transfer_type, err); 316 usb_log_info("Batch(%p) callback OUT(type:%d): %s(%d).\n", 317 instance, instance->transfer_type, str_error(err), err); 305 318 instance->callback_out(instance->fun, 306 319 err, instance->arg); … … 311 324 assert(instance); 312 325 batch_call_in(instance); 313 usb_log_debug(" Disposing batch: %p.\n", instance);326 usb_log_debug("Batch(%p) disposing.\n", instance); 314 327 free32(instance->tds); 315 328 free32(instance->qh); … … 323 336 assert(instance); 324 337 batch_call_out(instance); 325 usb_log_debug(" Disposing batch: %p.\n", instance);338 usb_log_debug("Batch(%p) disposing.\n", instance); 326 339 free32(instance->tds); 327 340 free32(instance->qh); … … 338 351 return uhci_schedule(hc, instance); 339 352 } 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 }389 353 /** 390 354 * @} -
uspace/drv/uhci-hcd/batch.h
r81c508c r299d53e 43 43 #include "uhci_struct/queue_head.h" 44 44 45 typedef enum {46 LOW_SPEED,47 FULL_SPEED,48 } dev_speed_t;49 50 45 typedef struct batch 51 46 { 52 47 link_t link; 53 dev_speed_t speed;48 usb_speed_t speed; 54 49 usb_target_t target; 55 50 usb_transfer_type_t transfer_type; … … 76 71 batch_t * batch_get(ddf_fun_t *fun, usb_target_t target, 77 72 usb_transfer_type_t transfer_type, size_t max_packet_size, 78 dev_speed_t speed, char *buffer, size_t size,73 usb_speed_t speed, char *buffer, size_t size, 79 74 char *setup_buffer, size_t setup_size, 80 75 usbhc_iface_transfer_in_callback_t func_in, -
uspace/drv/uhci-hcd/iface.c
r81c508c r299d53e 41 41 #include "iface.h" 42 42 #include "uhci.h" 43 #include "utils/device_keeper.h" 43 44 44 45 /*----------------------------------------------------------------------------*/ … … 48 49 uhci_t *hc = fun_to_uhci(fun); 49 50 assert(hc); 50 usb_address_keeping_reserve_default(&hc->address_manager); 51 usb_log_debug("Default address request with speed %d.\n", speed); 52 device_keeper_reserve_default(&hc->device_manager, speed); 51 53 return EOK; 52 54 } … … 57 59 uhci_t *hc = fun_to_uhci(fun); 58 60 assert(hc); 59 usb_address_keeping_release_default(&hc->address_manager); 61 usb_log_debug("Default address release.\n"); 62 device_keeper_release_default(&hc->device_manager); 60 63 return EOK; 61 64 } … … 67 70 uhci_t *hc = fun_to_uhci(fun); 68 71 assert(hc); 69 *address = usb_address_keeping_request(&hc->address_manager); 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); 70 77 if (*address <= 0) 71 78 return *address; … … 79 86 uhci_t *hc = fun_to_uhci(fun); 80 87 assert(hc); 81 usb_address_keeping_devman_bind(&hc->address_manager, address, handle); 88 usb_log_debug("Address bind %d-%d.\n", address, handle); 89 device_keeper_bind(&hc->device_manager, address, handle); 82 90 return EOK; 83 91 } … … 88 96 uhci_t *hc = fun_to_uhci(fun); 89 97 assert(hc); 90 usb_address_keeping_release_default(&hc->address_manager); 98 usb_log_debug("Address release %d.\n", address); 99 device_keeper_release(&hc->device_manager, address); 91 100 return EOK; 92 101 } 93 102 /*----------------------------------------------------------------------------*/ 94 103 static int interrupt_out(ddf_fun_t *fun, usb_target_t target, 95 size_t max_packet_size, 96 void *data, size_t size, 104 size_t max_packet_size, void *data, size_t size, 97 105 usbhc_iface_transfer_out_callback_t callback, void *arg) 98 106 { 99 dev_speed_t speed = FULL_SPEED; 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); 100 114 101 115 batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT, … … 108 122 /*----------------------------------------------------------------------------*/ 109 123 static int interrupt_in(ddf_fun_t *fun, usb_target_t target, 110 size_t max_packet_size, 111 void *data, size_t size, 124 size_t max_packet_size, void *data, size_t size, 112 125 usbhc_iface_transfer_in_callback_t callback, void *arg) 113 126 { 114 dev_speed_t speed = FULL_SPEED; 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); 115 133 116 134 batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT, … … 127 145 usbhc_iface_transfer_out_callback_t callback, void *arg) 128 146 { 129 dev_speed_t speed = FULL_SPEED; 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); 130 153 131 154 batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL, … … 143 166 usbhc_iface_transfer_in_callback_t callback, void *arg) 144 167 { 145 dev_speed_t speed = FULL_SPEED; 146 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); 172 173 usb_log_debug("Control READ %d:%d %zu(%zu).\n", 174 target.address, target.endpoint, size, max_packet_size); 147 175 batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL, 148 176 max_packet_size, speed, data, size, setup_data, setup_size, callback, -
uspace/drv/uhci-hcd/main.c
r81c508c r299d53e 82 82 usb_log_info("uhci_add_device() called\n"); 83 83 84 85 uintptr_t io_reg_base; 86 size_t io_reg_size; 87 int irq; 84 uintptr_t io_reg_base = 0; 85 size_t io_reg_size = 0; 86 int irq = 0; 88 87 89 88 int ret = … … 95 94 io_reg_base, io_reg_size, irq); 96 95 97 ret = pci_enable_interrupts(device);98 CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret);96 // ret = pci_enable_interrupts(device); 97 // CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret); 99 98 100 99 uhci_t *uhci_hc = malloc(sizeof(uhci_t)); … … 114 113 */ 115 114 device->driver_data = uhci_hc; 116 117 115 ret = register_interrupt_handler(device, irq, irq_handler, 118 116 &uhci_hc->interrupt_code); … … 149 147 { 150 148 sleep(3); 151 usb_log_enable(USB_LOG_LEVEL_ INFO, NAME);149 usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME); 152 150 153 151 return ddf_driver_main(&uhci_driver); -
uspace/drv/uhci-hcd/pci.c
r81c508c r299d53e 38 38 #include <devman.h> 39 39 #include <device/hw_res.h> 40 41 #include <usb/debug.h> 40 42 41 43 #include "pci.h" … … 83 85 irq = res->res.interrupt.irq; 84 86 irq_found = true; 87 usb_log_debug("Found interrupt: %d.\n", irq); 85 88 break; 86 89 case IO_RANGE: 87 io_address = (uintptr_t) 88 res->res.io_range.address; 90 io_address = res->res.io_range.address; 89 91 io_size = res->res.io_range.size; 92 usb_log_debug("Found io: %llx %zu %zu.\n", 93 res->res.io_range.address, res->res.io_range.size, io_size); 90 94 io_found = true; 91 95 break; … … 105 109 } 106 110 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 } 111 *io_reg_address = io_address; 112 *io_reg_size = io_size; 113 *irq_no = irq; 116 114 117 115 rc = EOK; … … 127 125 IPC_FLAG_BLOCKING); 128 126 bool enabled = hw_res_enable_interrupt(parent_phone); 127 async_hangup(parent_phone); 129 128 return enabled ? EOK : EIO; 130 129 } -
uspace/drv/uhci-hcd/root_hub.c
r81c508c r299d53e 35 35 #include <errno.h> 36 36 #include <stdio.h> 37 #include <ops/hw_res.h> 38 37 39 #include <usb_iface.h> 38 40 #include <usb/debug.h> … … 41 43 #include "uhci.h" 42 44 45 /*----------------------------------------------------------------------------*/ 43 46 static int usb_iface_get_hc_handle_rh_impl(ddf_fun_t *root_hub_fun, 44 47 devman_handle_t *handle) … … 51 54 return EOK; 52 55 } 53 56 /*----------------------------------------------------------------------------*/ 54 57 static int usb_iface_get_address_rh_impl(ddf_fun_t *fun, devman_handle_t handle, 55 58 usb_address_t *address) … … 61 64 assert(hc); 62 65 63 usb_address_t addr = usb_address_keeping_find(&hc->address_manager,66 usb_address_t addr = device_keeper_find(&hc->device_manager, 64 67 handle); 65 68 if (addr < 0) { … … 73 76 return EOK; 74 77 } 75 78 /*----------------------------------------------------------------------------*/ 76 79 usb_iface_t usb_iface_root_hub_fun_impl = { 77 80 .get_hc_handle = usb_iface_get_hc_handle_rh_impl, 78 81 .get_address = usb_iface_get_address_rh_impl 79 82 }; 83 /*----------------------------------------------------------------------------*/ 84 static hw_resource_list_t *get_resource_list(ddf_fun_t *dev) 85 { 86 assert(dev); 87 ddf_fun_t *hc_ddf_instance = dev->driver_data; 88 assert(hc_ddf_instance); 89 uhci_t *hc = hc_ddf_instance->driver_data; 90 assert(hc); 80 91 92 //TODO: fix memory leak 93 hw_resource_list_t *resource_list = malloc(sizeof(hw_resource_list_t)); 94 assert(resource_list); 95 resource_list->count = 1; 96 resource_list->resources = malloc(sizeof(hw_resource_t)); 97 assert(resource_list->resources); 98 resource_list->resources[0].type = IO_RANGE; 99 resource_list->resources[0].res.io_range.address = 100 ((uintptr_t)hc->registers) + 0x10; // see UHCI design guide 101 resource_list->resources[0].res.io_range.size = 4; 102 resource_list->resources[0].res.io_range.endianness = LITTLE_ENDIAN; 103 104 return resource_list; 105 } 106 /*----------------------------------------------------------------------------*/ 107 static hw_res_ops_t hw_res_iface = { 108 .get_resource_list = get_resource_list, 109 .enable_interrupt = NULL 110 }; 111 /*----------------------------------------------------------------------------*/ 81 112 static ddf_dev_ops_t root_hub_ops = { 82 .interfaces[USB_DEV_IFACE] = &usb_iface_root_hub_fun_impl 113 .interfaces[USB_DEV_IFACE] = &usb_iface_root_hub_fun_impl, 114 .interfaces[HW_RES_DEV_IFACE] = &hw_res_iface 83 115 }; 84 85 116 /*----------------------------------------------------------------------------*/ 86 117 int setup_root_hub(ddf_fun_t **fun, ddf_dev_t *hc) -
uspace/drv/uhci-hcd/transfer_list.c
r81c508c r299d53e 70 70 assert(instance); 71 71 assert(batch); 72 usb_log_debug("Adding batch(%p) to queue %s.\n", batch, instance->name); 72 73 73 74 uint32_t pa = (uintptr_t)addr_to_phys(batch->qh); … … 123 124 } 124 125 /*----------------------------------------------------------------------------*/ 125 void transfer_list_ check(transfer_list_t *instance)126 void transfer_list_remove_finished(transfer_list_t *instance) 126 127 { 127 128 assert(instance); 129 130 LIST_INITIALIZE(done); 131 128 132 fibril_mutex_lock(&instance->guard); 129 133 link_t *current = instance->batch_list.next; … … 134 138 if (batch_is_complete(batch)) { 135 139 transfer_list_remove_batch(instance, batch); 136 batch->next_step(batch);140 list_append(current, &done); 137 141 } 138 142 current = next; 139 143 } 140 144 fibril_mutex_unlock(&instance->guard); 145 146 while (!list_empty(&done)) { 147 link_t *item = done.next; 148 list_remove(item); 149 batch_t *batch = list_get_instance(item, batch_t, link); 150 batch->next_step(batch); 151 } 141 152 } 142 153 /** -
uspace/drv/uhci-hcd/transfer_list.h
r81c508c r299d53e 60 60 queue_head_dispose(instance->queue_head); 61 61 } 62 void transfer_list_ check(transfer_list_t *instance);62 void transfer_list_remove_finished(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
r81c508c r299d53e 48 48 { 49 49 .cmd = CMD_PIO_READ_16, 50 .addr = (void*)0xc022,50 .addr = NULL, /* patched for every instance */ 51 51 .dstarg = 1 52 52 }, 53 53 { 54 54 .cmd = CMD_PIO_WRITE_16, 55 .addr = (void*)0xc022,55 .addr = NULL, /* pathed for every instance */ 56 56 .value = 0x1f 57 57 }, … … 68 68 assert(hc); 69 69 70 usb_address_t addr = usb_address_keeping_find(&hc->address_manager,70 usb_address_t addr = device_keeper_find(&hc->device_manager, 71 71 handle); 72 72 if (addr < 0) { … … 80 80 return EOK; 81 81 } 82 83 82 /*----------------------------------------------------------------------------*/ 84 83 static usb_iface_t hc_usb_iface = { 85 84 .get_hc_handle = usb_iface_get_hc_handle_hc_impl, … … 89 88 static ddf_dev_ops_t uhci_ops = { 90 89 .interfaces[USB_DEV_IFACE] = &hc_usb_iface, 91 .interfaces[USBHC_DEV_IFACE] = &uhci_iface 90 .interfaces[USBHC_DEV_IFACE] = &uhci_iface, 92 91 }; 93 92 … … 141 140 142 141 instance->cleaner = fibril_create(uhci_interrupt_emulator, instance); 143 //fibril_add_ready(instance->cleaner);142 fibril_add_ready(instance->cleaner); 144 143 145 144 instance->debug_checker = fibril_create(uhci_debug_checker, instance); … … 151 150 void uhci_init_hw(uhci_t *instance) 152 151 { 152 /* reset everything, who knows what touched it before us */ 153 pio_write_16(&instance->registers->usbcmd, UHCI_CMD_GLOBAL_RESET); 154 async_usleep(10000); /* 10ms according to USB spec */ 155 pio_write_16(&instance->registers->usbcmd, 0); 156 157 /* reset hc, all states and counters */ 158 pio_write_16(&instance->registers->usbcmd, UHCI_CMD_HCRESET); 159 while ((pio_read_16(&instance->registers->usbcmd) & UHCI_CMD_HCRESET) != 0) 160 { async_usleep(10); } 153 161 154 162 /* set framelist pointer */ … … 203 211 204 212 /* init address keeper(libusb) */ 205 usb_address_keeping_init(&instance->address_manager, USB11_ADDRESS_MAX);206 usb_log_debug("Initialized addressmanager.\n");213 device_keeper_init(&instance->device_manager); 214 usb_log_debug("Initialized device manager.\n"); 207 215 208 216 return EOK; … … 255 263 assert(instance); 256 264 assert(batch); 257 const int low_speed = (batch->speed == LOW_SPEED);265 const int low_speed = (batch->speed == USB_SPEED_LOW); 258 266 if (!allowed_usb_packet( 259 267 low_speed, batch->transfer_type, batch->max_packet_size)) { … … 276 284 { 277 285 assert(instance); 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);286 // if ((status & (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)) == 0) 287 // return; 288 // usb_log_debug2("UHCI interrupt: %X.\n", status); 289 transfer_list_remove_finished(&instance->transfers_interrupt); 290 transfer_list_remove_finished(&instance->transfers_control_slow); 291 transfer_list_remove_finished(&instance->transfers_control_full); 292 transfer_list_remove_finished(&instance->transfers_bulk_full); 285 293 } 286 294 /*----------------------------------------------------------------------------*/ … … 291 299 assert(instance); 292 300 293 while (1) {301 while (1) { 294 302 uint16_t status = pio_read_16(&instance->registers->usbsts); 303 if (status != 0) 304 usb_log_debug2("UHCI status: %x.\n", status); 305 status |= 1; 295 306 uhci_interrupt(instance, status); 296 async_usleep(UHCI_CLEANER_TIMEOUT); 307 pio_write_16(&instance->registers->usbsts, 0x1f); 308 async_usleep(UHCI_CLEANER_TIMEOUT * 5); 297 309 } 298 310 return EOK; … … 307 319 const uint16_t sts = pio_read_16(&instance->registers->usbsts); 308 320 const uint16_t intr = pio_read_16(&instance->registers->usbintr); 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); 321 if (((cmd & UHCI_CMD_RUN_STOP) != 1) || (sts != 0)) { 322 usb_log_debug2("Command: %X Status: %X Intr: %x\n", 323 cmd, sts, intr); 324 } 325 326 uintptr_t frame_list = 327 pio_read_32(&instance->registers->flbaseadd) & ~0xfff; 313 328 if (frame_list != addr_to_phys(instance->frame_list)) { 314 329 usb_log_debug("Framelist address: %p vs. %p.\n", -
uspace/drv/uhci-hcd/uhci.h
r81c508c r299d53e 41 41 #include <ddi.h> 42 42 43 #include <usb/addrkeep.h>44 43 #include <usbhc_iface.h> 45 44 45 #include "batch.h" 46 46 #include "transfer_list.h" 47 #include " batch.h"47 #include "utils/device_keeper.h" 48 48 49 49 typedef struct uhci_regs { … … 82 82 83 83 typedef struct uhci { 84 usb_address_keeping_t address_manager; 84 device_keeper_t device_manager; 85 85 86 volatile regs_t *registers; 86 87 -
uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.c
r81c508c r299d53e 39 39 40 40 void transfer_descriptor_init(transfer_descriptor_t *instance, 41 int error_count, size_t size, bool toggle, bool isochronous, 41 int error_count, size_t size, bool toggle, bool isochronous, bool low_speed, 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) 52 53 | TD_STATUS_ERROR_ACTIVE; 53 54 … … 69 70 instance->next, instance->status, instance->device, 70 71 instance->buffer_ptr, buffer); 71 #if 072 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 #endif83 72 } 84 73 /*----------------------------------------------------------------------------*/ … … 88 77 89 78 if ((instance->status & TD_STATUS_ERROR_STALLED) != 0) 90 return E IO;79 return ESTALL; 91 80 92 81 if ((instance->status & TD_STATUS_ERROR_CRC) != 0) 93 return E AGAIN;82 return EBADCHECKSUM; 94 83 95 84 if ((instance->status & TD_STATUS_ERROR_BUFFER) != 0) -
uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.h
r81c508c r299d53e 92 92 93 93 void transfer_descriptor_init(transfer_descriptor_t *instance, 94 int error_count, size_t size, bool toggle, bool isochronous, 94 int error_count, size_t size, bool toggle, bool isochronous, bool low_speed, 95 95 usb_target_t target, int pid, void *buffer, transfer_descriptor_t * next); 96 96 -
uspace/drv/uhci-rhd/main.c
r81c508c r299d53e 33 33 */ 34 34 #include <ddf/driver.h> 35 #include <devman.h> 36 #include <device/hw_res.h> 35 37 #include <usb_iface.h> 36 38 #include <usb/ddfiface.h> … … 43 45 44 46 #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); 45 49 46 50 static int usb_iface_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle) … … 80 84 } 81 85 82 /* TODO: get register values from hc */ 83 int ret = uhci_root_hub_init(rh, (void*)0xc030, 4, device); 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); 84 95 if (ret != EOK) { 85 96 usb_log_error("Failed(%d) to initialize driver instance.\n", ret); … … 102 113 .driver_ops = &uhci_rh_driver_ops 103 114 }; 104 115 /*----------------------------------------------------------------------------*/ 105 116 int main(int argc, char *argv[]) 106 117 { … … 108 119 return ddf_driver_main(&uhci_rh_driver); 109 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 } 110 177 /** 111 178 * @} -
uspace/drv/uhci-rhd/port.c
r81c508c r299d53e 34 34 #include <errno.h> 35 35 #include <str_error.h> 36 #include <fibril_synch.h> 36 37 37 38 #include <usb/usb.h> /* usb_address_t */ … … 45 46 #include "port_status.h" 46 47 47 static int uhci_port_new_device(uhci_port_t *port );48 static int uhci_port_new_device(uhci_port_t *port, uint16_t status); 48 49 static int uhci_port_remove_device(uhci_port_t *port); 49 50 static int uhci_port_set_enabled(uhci_port_t *port, bool enabled); 50 51 static int uhci_port_check(void *port); 52 static int new_device_enable_port(int portno, void *arg); 51 53 52 54 int uhci_port_init( 53 55 uhci_port_t *port, port_status_t *address, unsigned number, 54 unsigned usec, ddf_dev_t *rh , int parent_phone)56 unsigned usec, ddf_dev_t *rh) 55 57 { 56 58 assert(port); … … 90 92 uhci_port_t *port_instance = port; 91 93 assert(port_instance); 94 port_status_write(port_instance->address, 0); 95 96 uint64_t count = 0; 92 97 93 98 while (1) { 99 async_usleep(port_instance->wait_period_usec); 100 94 101 /* read register value */ 95 102 port_status_t port_status = … … 97 104 98 105 /* debug print */ 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) { 106 static fibril_mutex_t dbg_mtx = FIBRIL_MUTEX_INITIALIZER(dbg_mtx); 107 fibril_mutex_lock(&dbg_mtx); 108 usb_log_debug("Port %d status at %p: 0x%04x. === %llu\n", 109 port_instance->number, port_instance->address, port_status, count++); 110 // print_port_status(port_status); 111 fibril_mutex_unlock(&dbg_mtx); 112 113 if ((port_status & STATUS_CONNECTED_CHANGED) != 0) { 114 usb_log_debug("Change detected on port %d: %x.\n", 115 port_instance->number, port_status); 116 117 104 118 int rc = usb_hc_connection_open( 105 119 &port_instance->hc_connection); 106 120 if (rc != EOK) { 107 121 usb_log_error("Failed to connect to HC."); 108 goto next; 109 } 110 111 if (port_status & STATUS_CONNECTED) { 122 continue; 123 } 124 125 /* remove any old device */ 126 if (port_instance->attached_device) { 127 usb_log_debug("Removing device on port %d.\n", 128 port_instance->number); 129 uhci_port_remove_device(port_instance); 130 } 131 132 if ((port_status & STATUS_CONNECTED) != 0) { 112 133 /* new device */ 113 uhci_port_new_device(port_instance );134 uhci_port_new_device(port_instance, port_status); 114 135 } else { 115 uhci_port_remove_device(port_instance); 136 /* ack changes by writing one to WC bits */ 137 port_status_write(port_instance->address, port_status); 138 usb_log_debug("Change status ack on port %d.\n", 139 port_instance->number); 116 140 } 117 141 … … 120 144 if (rc != EOK) { 121 145 usb_log_error("Failed to disconnect from HC."); 122 goto next;123 146 } 124 147 } 125 next:126 async_usleep(port_instance->wait_period_usec);127 148 } 128 149 return EOK; … … 147 168 async_usleep(100000); 148 169 149 /* Enable the port. */150 uhci_port_set_enabled(port, true);151 170 152 171 /* The hub maintains the reset signal to that port for 10 ms … … 169 188 } 170 189 171 return EOK; 172 } 173 174 /*----------------------------------------------------------------------------*/ 175 static int uhci_port_new_device(uhci_port_t *port) 190 /* Enable the port. */ 191 uhci_port_set_enabled(port, true); 192 193 return EOK; 194 } 195 196 /*----------------------------------------------------------------------------*/ 197 static int uhci_port_new_device(uhci_port_t *port, uint16_t status) 176 198 { 177 199 assert(port); … … 182 204 usb_address_t dev_addr; 183 205 int rc = usb_hc_new_device_wrapper(port->rh, &port->hc_connection, 184 USB_SPEED_FULL,206 ((status & STATUS_LOW_SPEED) != 0) ? USB_SPEED_LOW : USB_SPEED_FULL, 185 207 new_device_enable_port, port->number, port, 186 208 &dev_addr, &port->attached_device, NULL, NULL, NULL); 209 187 210 if (rc != EOK) { 188 211 usb_log_error("Failed adding new device on port %u: %s.\n", -
uspace/drv/uhci-rhd/port.h
r81c508c r299d53e 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 , int parent_phone);57 unsigned usec, ddf_dev_t *rh); 58 58 59 59 void uhci_port_fini(uhci_port_t *port); -
uspace/drv/uhci-rhd/port_status.c
r81c508c r299d53e 41 41 struct flag_name 42 42 { 43 u nsignedflag;43 uint16_t 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? "YES" : "NO");67 ((value & flags[i].flag) != 0) ? "YES" : "NO"); 68 68 } 69 69 } -
uspace/drv/uhci-rhd/port_status.h
r81c508c r299d53e 41 41 typedef uint16_t port_status_t; 42 42 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, 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) 52 51 53 STATUS_LOW_SPEED = 1 << 8, 54 STATUS_IN_RESET = 1 << 9, 55 STATUS_SUSPEND = 1 << 12, 56 }; 52 #define STATUS_LOW_SPEED (1 << 8) 53 #define STATUS_IN_RESET (1 << 9) 54 #define STATUS_SUSPEND (1 << 12) 57 55 58 56 static inline port_status_t port_status_read(port_status_t * address) -
uspace/drv/uhci-rhd/root_hub.c
r81c508c r299d53e 40 40 #include "root_hub.h" 41 41 42 43 42 int uhci_root_hub_init( 44 43 uhci_root_hub_t *instance, void *addr, size_t size, ddf_dev_t *rh) … … 67 66 unsigned i = 0; 68 67 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 }76 68 /* mind pointer arithmetics */ 77 69 int ret = uhci_port_init( 78 &instance->ports[i], regs + i, i, ROOT_HUB_WAIT_USEC, rh , parent_phone);70 &instance->ports[i], regs + i, i, ROOT_HUB_WAIT_USEC, rh); 79 71 if (ret != EOK) { 80 72 unsigned j = 0; -
uspace/drv/uhci-rhd/root_hub.h
r81c508c r299d53e 41 41 42 42 #define UHCI_ROOT_HUB_PORT_COUNT 2 43 #define UHCI_ROOT_HUB_PORT_REGISTERS_OFFSET 0x10 44 #define ROOT_HUB_WAIT_USEC 10000000 /* 10 seconds */ 43 #define ROOT_HUB_WAIT_USEC 5000000 /* 5 seconds */ 45 44 46 45 typedef struct root_hub {
Note:
See TracChangeset
for help on using the changeset viewer.