Changeset aee6c73 in mainline
- Timestamp:
- 2011-03-26T17:19:28Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0368669c, cee51fd
- Parents:
- f3da9b2 (diff), c9f5e238 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 4 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
HelenOS.config
rf3da9b2 raee6c73 554 554 % Polling UHCI & OHCI (no interrupts) 555 555 ! [PLATFORM=ia32|PLATFORM=amd64] CONFIG_USBHC_NO_INTERRUPTS (y/n) 556 557 % Run devman in kconsole (not recommended) 558 ! CONFIG_DEVMAN_EARLY_LAUNCH (n/y) 559 -
kernel/generic/src/console/console.c
rf3da9b2 raee6c73 53 53 #include <str.h> 54 54 55 /* 56 * devman produces a lot of output and by giving so many pages 57 * we to allow /app/klog to catch-up. 58 */ 59 #ifdef CONFIG_DEVMAN_EARLY_LAUNCH 60 #define KLOG_PAGES 64 61 #else 55 62 #define KLOG_PAGES 4 63 #endif 64 56 65 #define KLOG_LENGTH (KLOG_PAGES * PAGE_SIZE / sizeof(wchar_t)) 57 66 #define KLOG_LATENCY 8 -
kernel/generic/src/mm/as.c
rf3da9b2 raee6c73 1949 1949 sysarg_t sys_as_area_create(uintptr_t address, size_t size, unsigned int flags) 1950 1950 { 1951 if (as_area_create(AS, flags | AS_AREA_CACHEABLE, size, address,1951 if (as_area_create(AS, flags, size, address, 1952 1952 AS_AREA_ATTR_NONE, &anon_backend, NULL)) 1953 1953 return (sysarg_t) address; -
uspace/app/init/init.c
rf3da9b2 raee6c73 313 313 getterm("term/vc5", "/app/bdsh", false); 314 314 getterm("term/vc6", "/app/klog", false); 315 316 #ifdef CONFIG_DEVMAN_EARLY_LAUNCH 317 spawn("/srv/devman"); 318 #else 315 319 getterm("term/vc7", "/srv/devman", false); 316 320 #endif 321 317 322 return 0; 318 323 } -
uspace/app/klog/klog.c
rf3da9b2 raee6c73 44 44 #include <io/klog.h> 45 45 #include <sysinfo.h> 46 #include <fibril_synch.h> 46 47 47 48 #define NAME "klog" … … 54 55 static FILE *log; 55 56 57 /* Serialize the output a bit. This will not avoid messed-up log completely 58 but chances for are pretty high (experimentally confirmed). */ 59 static FIBRIL_MUTEX_INITIALIZE(log_mutex); 60 56 61 static void interrupt_received(ipc_callid_t callid, ipc_call_t *call) 57 62 { 63 fibril_mutex_lock(&log_mutex); 64 58 65 size_t klog_start = (size_t) IPC_GET_ARG1(*call); 59 66 size_t klog_len = (size_t) IPC_GET_ARG2(*call); … … 74 81 fsync(fileno(log)); 75 82 } 83 84 fibril_mutex_unlock(&log_mutex); 76 85 } 77 86 -
uspace/drv/ohci/Makefile
rf3da9b2 raee6c73 37 37 main.c \ 38 38 hc.c \ 39 ohci.c \ 39 40 root_hub.c \ 40 41 pci.c -
uspace/drv/ohci/hc.c
rf3da9b2 raee6c73 39 39 #include <usb/debug.h> 40 40 #include <usb/usb.h> 41 #include <usb/hub.h>42 41 #include <usb/ddfiface.h> 43 42 #include <usb/usbdevice.h> … … 45 44 #include "hc.h" 46 45 47 static int dummy_reset(int foo, void *arg);48 46 static int interrupt_emulator(hc_t *instance); 47 /*----------------------------------------------------------------------------*/ 48 int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun) 49 { 50 assert(instance); 51 assert(hub_fun); 52 53 usb_address_t hub_address = 54 device_keeper_get_free_address(&instance->manager, USB_SPEED_FULL); 55 instance->rh.address = hub_address; 56 usb_device_keeper_bind( 57 &instance->manager, hub_address, hub_fun->handle); 58 59 char *match_str = NULL; 60 int ret = asprintf(&match_str, "usb&mid"); 61 ret = (match_str == NULL) ? ret : EOK; 62 if (ret < 0) { 63 usb_log_error("Failed to create root hub match-id string.\n"); 64 return ret; 65 } 66 67 ret = ddf_fun_add_match_id(hub_fun, match_str, 100); 68 if (ret != EOK) { 69 usb_log_error("Failed add create root hub match-id.\n"); 70 } 71 return ret; 72 } 49 73 /*----------------------------------------------------------------------------*/ 50 74 int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev, … … 68 92 } 69 93 94 rh_init(&instance->rh, dev, instance->registers); 70 95 71 rh_init(&instance->rh, dev, instance->registers);72 96 /* TODO: implement */ 73 return EOK;74 }75 /*----------------------------------------------------------------------------*/76 int hc_register_hub(hc_t *instance)77 {78 async_usleep(1000000);79 #define CHECK_RET_RETURN(ret, msg...) \80 if (ret != EOK) { \81 usb_log_error(msg); \82 return ret; \83 } else (void)084 assert(instance);85 assert(instance->ddf_instance);86 assert(instance->ddf_instance->handle);87 ddf_dev_t *dev = instance->rh.device;88 int ret = EOK;89 90 usb_hc_connection_t conn;91 ret =92 usb_hc_connection_initialize(&conn, instance->ddf_instance->handle);93 CHECK_RET_RETURN(ret, "Failed to initialize hc connection.\n");94 95 ret = usb_hc_connection_open(&conn);96 CHECK_RET_RETURN(ret, "Failed to open hc connection.\n");97 98 usb_address_t address;99 devman_handle_t handle;100 ret = usb_hc_new_device_wrapper(dev, &conn, USB_SPEED_FULL, dummy_reset,101 0, instance, &address, &handle, NULL, NULL, NULL);102 if (ret != EOK) {103 usb_log_error("Failed to add rh device.\n");104 instance->rh.address = -1;105 return ret;106 }107 108 ret = usb_hc_connection_close(&conn);109 CHECK_RET_RETURN(ret, "Failed to close hc connection.\n");110 97 return EOK; 111 98 } … … 134 121 } 135 122 /*----------------------------------------------------------------------------*/ 136 static int dummy_reset(int foo, void *arg) 137 { 138 hc_t *hc = (hc_t*)arg; 139 assert(hc); 140 hc->rh.address = 0; 141 return EOK; 142 } 143 /*----------------------------------------------------------------------------*/ 144 static int interrupt_emulator(hc_t *instance) 123 int interrupt_emulator(hc_t *instance) 145 124 { 146 125 assert(instance); -
uspace/drv/ohci/hc.h
rf3da9b2 raee6c73 57 57 } hc_t; 58 58 59 int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun); 60 59 61 int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev, 60 62 uintptr_t regs, size_t reg_size, bool interrupts); 61 62 int hc_register_hub(hc_t *instance);63 63 64 64 int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch); -
uspace/drv/ohci/iface.h
rf3da9b2 raee6c73 33 33 * Common OHCI definitions. 34 34 */ 35 #ifndef DRV_OHCI_ OHCI_H36 #define DRV_OHCI_ OHCI_H35 #ifndef DRV_OHCI_IFACE_H 36 #define DRV_OHCI_IFACE_H 37 37 38 38 #include <usbhc_iface.h> 39 40 #define NAME "ohci"41 39 42 40 extern usbhc_iface_t hc_iface; -
uspace/drv/ohci/main.c
rf3da9b2 raee6c73 34 34 */ 35 35 #include <ddf/driver.h> 36 #include <ddf/interrupt.h>37 #include <device/hw_res.h>38 36 #include <errno.h> 39 37 #include <str_error.h> 40 38 41 #include <usb_iface.h>42 #include <usb/ddfiface.h>43 39 #include <usb/debug.h> 44 40 45 #include " pci.h"46 #include "iface.h" 47 # include "hc.h"41 #include "ohci.h" 42 43 #define NAME "ohci" 48 44 49 45 static int ohci_add_device(ddf_dev_t *device); 50 static int get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)51 {52 assert(handle);53 assert(fun != NULL);54 55 *handle = fun->handle;56 return EOK;57 }58 /*----------------------------------------------------------------------------*/59 static int get_address(60 ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address)61 {62 assert(fun);63 usb_device_keeper_t *manager = &fun_to_hc(fun)->manager;64 usb_address_t addr = usb_device_keeper_find(manager, handle);65 if (addr < 0) {66 return addr;67 }68 69 if (address != NULL) {70 *address = addr;71 }72 73 return EOK;74 }75 /*----------------------------------------------------------------------------*/76 /** IRQ handling callback, identifies device77 *78 * @param[in] dev DDF instance of the device to use.79 * @param[in] iid (Unused).80 * @param[in] call Pointer to the call that represents interrupt.81 */82 static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call)83 {84 assert(dev);85 hc_t *hc = (hc_t*)dev->driver_data;86 assert(hc);87 hc_interrupt(hc, 0);88 }89 46 /*----------------------------------------------------------------------------*/ 90 47 static driver_ops_t ohci_driver_ops = { … … 97 54 }; 98 55 /*----------------------------------------------------------------------------*/ 99 static usb_iface_t hc_usb_iface = {100 .get_address = get_address,101 .get_hc_handle = get_hc_handle,102 };103 /*----------------------------------------------------------------------------*/104 static ddf_dev_ops_t hc_ops = {105 .interfaces[USB_DEV_IFACE] = &hc_usb_iface,106 .interfaces[USBHC_DEV_IFACE] = &hc_iface,107 };108 /*----------------------------------------------------------------------------*/109 56 /** Initializes a new ddf driver instance of OHCI hcd. 110 57 * … … 112 59 * @return Error code. 113 60 */ 114 staticint ohci_add_device(ddf_dev_t *device)61 int ohci_add_device(ddf_dev_t *device) 115 62 { 63 usb_log_debug("ohci_add_device() called\n"); 116 64 assert(device); 117 #define CHECK_RET_RETURN(ret, message...) \ 118 if (ret != EOK) { \ 119 usb_log_error(message); \ 120 return ret; \ 121 } 122 123 uintptr_t mem_reg_base = 0; 124 size_t mem_reg_size = 0; 125 int irq = 0; 126 127 int ret = 128 pci_get_my_registers(device, &mem_reg_base, &mem_reg_size, &irq); 129 CHECK_RET_RETURN(ret, 130 "Failed(%d) to get memory addresses:.\n", ret, device->handle); 131 usb_log_info("Memory mapped regs at 0x%X (size %zu), IRQ %d.\n", 132 mem_reg_base, mem_reg_size, irq); 133 134 ret = pci_disable_legacy(device); 135 CHECK_RET_RETURN(ret, 136 "Failed(%d) disable legacy USB: %s.\n", ret, str_error(ret)); 137 138 hc_t *hcd = malloc(sizeof(hc_t)); 139 if (hcd == NULL) { 65 ohci_t *ohci = malloc(sizeof(ohci_t)); 66 if (ohci == NULL) { 140 67 usb_log_error("Failed to allocate OHCI driver.\n"); 141 68 return ENOMEM; 142 69 } 143 70 144 ddf_fun_t *hc_fun = ddf_fun_create(device, fun_exposed, "ohci-hc"); 145 if (hc_fun == NULL) { 146 usb_log_error("Failed to create OHCI function.\n"); 147 free(hcd); 148 return ENOMEM; 149 } 150 151 152 bool interrupts = false; 153 #ifdef CONFIG_USBHC_NO_INTERRUPTS 154 usb_log_warning("Interrupts disabled in OS config, " \ 155 "falling back to polling.\n"); 156 #else 157 ret = pci_enable_interrupts(device); 71 int ret = ohci_init(ohci, device); 158 72 if (ret != EOK) { 159 usb_log_ warning("Failed to enable interrupts: %s.\n",73 usb_log_error("Failed to initialize OHCI driver: %s.\n", 160 74 str_error(ret)); 161 usb_log_info("HW interrupts not available, " \162 "falling back to polling.\n");163 } else {164 usb_log_debug("Hw interrupts enabled.\n");165 interrupts = true;166 }167 #endif168 169 ret = hc_init(hcd, hc_fun, device, mem_reg_base, mem_reg_size, interrupts);170 if (ret != EOK) {171 usb_log_error("Failed to initialize OHCI driver.\n");172 free(hcd);173 75 return ret; 174 76 } 77 device->driver_data = ohci; 175 78 176 ret = register_interrupt_handler(device, irq, irq_handler, NULL); 177 178 hc_fun->ops = &hc_ops; 179 ret = ddf_fun_bind(hc_fun); 180 if (ret != EOK) { 181 usb_log_error("Failed to bind OHCI function.\n"); 182 ddf_fun_destroy(hc_fun); 183 free(hcd); 184 return ret; 185 } 186 hc_fun->driver_data = hcd; 187 188 fid_t later = fibril_create((int(*)(void*))hc_register_hub, hcd); 189 fibril_add_ready(later); 190 191 usb_log_info("Controlling new OHCI device `%s' (handle %llu).\n", 192 device->name, device->handle); 79 usb_log_info("Controlling new OHCI device `%s'.\n", device->name); 193 80 194 81 return EOK; 195 #undef CHECK_RET_RETURN196 82 } 197 83 /*----------------------------------------------------------------------------*/ -
uspace/drv/ohci/root_hub.c
rf3da9b2 raee6c73 43 43 #include <usb/classes/hub.h> 44 44 45 static const usb_standard_device_descriptor_t ohci_rh_device_descriptor = 46 { 47 .configuration_count = 1, 48 .descriptor_type = USB_DESCTYPE_DEVICE, 49 .device_class = USB_CLASS_HUB, 50 .device_protocol = 0, 51 .device_subclass = 0, 52 .device_version = 0, 53 .length = sizeof(usb_standard_device_descriptor_t), 54 /// \TODO this value is guessed 55 .max_packet_size = 8, 56 .vendor_id = 0x16db, 57 .product_id = 0x0001, 58 /// \TODO these values migt be different 59 .str_serial_number = 0, 60 .usb_spec_version = 0, 61 }; 62 63 static const usb_standard_configuration_descriptor_t ohci_rh_conf_descriptor = 64 { 65 /// \TODO some values are default or guessed 66 .attributes = 1<<7, 67 .configuration_number = 1, 68 .descriptor_type = USB_DESCTYPE_CONFIGURATION, 69 .interface_count = 1, 70 .length = sizeof(usb_standard_configuration_descriptor_t), 71 .max_power = 100, 72 .str_configuration = 0, 73 }; 74 75 static const usb_standard_interface_descriptor_t ohci_rh_iface_descriptor = 76 { 77 .alternate_setting = 0, 78 .descriptor_type = USB_DESCTYPE_INTERFACE, 79 .endpoint_count = 1, 80 .interface_class = USB_CLASS_HUB, 81 /// \TODO is this correct? 82 .interface_number = 1, 83 .interface_protocol = 0, 84 .interface_subclass = 0, 85 .length = sizeof(usb_standard_interface_descriptor_t), 86 .str_interface = 0, 87 }; 88 89 static const usb_standard_endpoint_descriptor_t ohci_rh_ep_descriptor = 90 { 91 .attributes = USB_TRANSFER_INTERRUPT, 92 .descriptor_type = USB_DESCTYPE_ENDPOINT, 93 .endpoint_address = 1 + (1<<7), 94 .length = sizeof(usb_standard_endpoint_descriptor_t), 95 .max_packet_size = 8, 96 .poll_interval = 255, 97 }; 45 98 46 99 /** Root hub initialization … … 330 383 (usb_device_request_setup_packet_t*)request->setup_buffer; 331 384 size_t size; 332 void * result_descriptor;333 uint16_t setup_request_value = setup_request->value_high;385 const void * result_descriptor = NULL; 386 const uint16_t setup_request_value = setup_request->value_high; 334 387 //(setup_request->value_low << 8); 388 #if 0 389 bool del = false; 390 //this code was merged from development and has to be reviewed 391 switch (setup_request_value) 392 { 393 case USB_DESCTYPE_HUB: { 394 uint8_t * descriptor; 395 usb_create_serialized_hub_descriptor( 396 instance, &descriptor, &size); 397 result_descriptor = descriptor; 398 break; 399 } 400 case USB_DESCTYPE_DEVICE: { 401 usb_log_debug("USB_DESCTYPE_DEVICE\n"); 402 result_descriptor = &ohci_rh_device_descriptor; 403 size = sizeof(ohci_rh_device_descriptor); 404 break; 405 } 406 case USB_DESCTYPE_CONFIGURATION: { 407 usb_log_debug("USB_DESCTYPE_CONFIGURATION\n"); 408 usb_standard_configuration_descriptor_t * descriptor = 409 malloc(sizeof(usb_standard_configuration_descriptor_t)); 410 memcpy(descriptor, &ohci_rh_conf_descriptor, 411 sizeof(usb_standard_configuration_descriptor_t)); 412 /// \TODO should this include device descriptor? 413 const size_t hub_descriptor_size = 7 + 414 2* (instance->port_count / 8 + 415 ((instance->port_count % 8 > 0) ? 1 : 0)); 416 descriptor->total_length = 417 sizeof(usb_standard_configuration_descriptor_t)+ 418 sizeof(usb_standard_endpoint_descriptor_t)+ 419 sizeof(usb_standard_interface_descriptor_t)+ 420 hub_descriptor_size; 421 result_descriptor = descriptor; 422 size = sizeof(usb_standard_configuration_descriptor_t); 423 del = true; 424 break; 425 } 426 case USB_DESCTYPE_INTERFACE: { 427 usb_log_debug("USB_DESCTYPE_INTERFACE\n"); 428 result_descriptor = &ohci_rh_iface_descriptor; 429 size = sizeof(ohci_rh_iface_descriptor); 430 break; 431 } 432 case USB_DESCTYPE_ENDPOINT: { 433 usb_log_debug("USB_DESCTYPE_ENDPOINT\n"); 434 result_descriptor = &ohci_rh_ep_descriptor; 435 size = sizeof(ohci_rh_ep_descriptor); 436 break; 437 } 438 default: { 439 usb_log_debug("USB_DESCTYPE_EINVAL %d \n",setup_request->value); 440 usb_log_debug("\ttype %d\n\trequest %d\n\tvalue %d\n\tindex %d\n\tlen %d\n ", 441 setup_request->request_type, 442 setup_request->request, 443 setup_request_value, 444 setup_request->index, 445 setup_request->length 446 ); 447 return EINVAL; 448 } 449 } 450 #endif 335 451 if(setup_request_value == USB_DESCTYPE_HUB){ 336 452 usb_log_debug("USB_DESCTYPE_HUB\n"); … … 378 494 request->transfered_size = size; 379 495 memcpy(request->buffer,result_descriptor,size); 380 free(result_descriptor); 496 if (result_descriptor) 497 free(result_descriptor); 381 498 return EOK; 382 499 } -
uspace/drv/uhci-hcd/Makefile
rf3da9b2 raee6c73 40 40 root_hub.c \ 41 41 hw_struct/transfer_descriptor.c \ 42 utils/slab.c \ 42 43 pci.c \ 43 44 batch.c -
uspace/drv/uhci-hcd/hc.c
rf3da9b2 raee6c73 223 223 ret = instance ? EOK : ENOMEM; 224 224 CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to get frame list page.\n"); 225 usb_log_debug("Initialized frame list .\n");225 usb_log_debug("Initialized frame list at %p.\n", instance->frame_list); 226 226 227 227 /* Set all frames to point to the first queue head */ … … 336 336 instance->transfers[batch->speed][batch->transfer_type]; 337 337 assert(list); 338 if (batch->transfer_type == USB_TRANSFER_CONTROL) { 339 usb_device_keeper_use_control( 340 &instance->manager, batch->target.address); 341 } 338 342 transfer_list_add_batch(list, batch); 339 343 … … 357 361 /* Lower 2 bits are transaction error and transaction complete */ 358 362 if (status & 0x3) { 359 transfer_list_remove_finished(&instance->transfers_interrupt); 360 transfer_list_remove_finished(&instance->transfers_control_slow); 361 transfer_list_remove_finished(&instance->transfers_control_full); 362 transfer_list_remove_finished(&instance->transfers_bulk_full); 363 LIST_INITIALIZE(done); 364 transfer_list_remove_finished( 365 &instance->transfers_interrupt, &done); 366 transfer_list_remove_finished( 367 &instance->transfers_control_slow, &done); 368 transfer_list_remove_finished( 369 &instance->transfers_control_full, &done); 370 transfer_list_remove_finished( 371 &instance->transfers_bulk_full, &done); 372 373 while (!list_empty(&done)) { 374 link_t *item = done.next; 375 list_remove(item); 376 usb_transfer_batch_t *batch = 377 list_get_instance(item, usb_transfer_batch_t, link); 378 if (batch->transfer_type == USB_TRANSFER_CONTROL) { 379 usb_device_keeper_release_control( 380 &instance->manager, batch->target.address); 381 } 382 batch->next_step(batch); 383 } 363 384 } 364 385 /* bits 4 and 5 indicate hc error */ -
uspace/drv/uhci-hcd/root_hub.c
rf3da9b2 raee6c73 48 48 * @return Error code. 49 49 */ 50 int rh_init( 51 rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size) 50 int rh_init(rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size) 52 51 { 53 52 assert(fun); -
uspace/drv/uhci-hcd/transfer_list.c
rf3da9b2 raee6c73 58 58 } 59 59 instance->queue_head_pa = addr_to_phys(instance->queue_head); 60 usb_log_debug2("Transfer list %s setup with QH: %p(%p).\n", 61 name, instance->queue_head, instance->queue_head_pa); 60 62 61 63 qh_init(instance->queue_head); … … 118 120 qh_set_next_qh(last_qh, pa); 119 121 122 asm volatile ("": : :"memory"); 123 120 124 /* Add to the driver list */ 121 125 list_append(&batch->link, &instance->batch_list); … … 137 141 * this transfer list leading to the deadlock if its done inline. 138 142 */ 139 void transfer_list_remove_finished(transfer_list_t *instance) 140 { 141 assert(instance); 142 143 LIST_INITIALIZE(done); 143 void transfer_list_remove_finished(transfer_list_t *instance, link_t *done) 144 { 145 assert(instance); 146 assert(done); 144 147 145 148 fibril_mutex_lock(&instance->guard); … … 153 156 /* Save for post-processing */ 154 157 transfer_list_remove_batch(instance, batch); 155 list_append(current, &done);158 list_append(current, done); 156 159 } 157 160 current = next; … … 159 162 fibril_mutex_unlock(&instance->guard); 160 163 161 while (!list_empty(&done)) {162 link_t *item = done.next;163 list_remove(item);164 usb_transfer_batch_t *batch =165 list_get_instance(item, usb_transfer_batch_t, link);166 batch->next_step(batch);167 }168 164 } 169 165 /*----------------------------------------------------------------------------*/ … … 222 218 qpos = "NOT FIRST"; 223 219 } 220 asm volatile ("": : :"memory"); 224 221 /* Remove from the batch list */ 225 222 list_remove(&batch->link); -
uspace/drv/uhci-hcd/transfer_list.h
rf3da9b2 raee6c73 67 67 void transfer_list_add_batch(transfer_list_t *instance, usb_transfer_batch_t *batch); 68 68 69 void transfer_list_remove_finished(transfer_list_t *instance );69 void transfer_list_remove_finished(transfer_list_t *instance, link_t *done); 70 70 71 71 void transfer_list_abort_all(transfer_list_t *instance); -
uspace/drv/uhci-hcd/uhci.c
rf3da9b2 raee6c73 44 44 #include "pci.h" 45 45 46 47 46 /** IRQ handling callback, identifies device 48 47 * … … 108 107 /*----------------------------------------------------------------------------*/ 109 108 static ddf_dev_ops_t hc_ops = { 110 .interfaces[USB_DEV_IFACE] = &usb_iface,109 // .interfaces[USB_DEV_IFACE] = &usb_iface, 111 110 .interfaces[USBHC_DEV_IFACE] = &hc_iface, /* see iface.h/c */ 112 111 }; -
uspace/drv/uhci-hcd/utils/malloc32.h
rf3da9b2 raee6c73 40 40 #include <as.h> 41 41 42 #include "slab.h" 43 42 44 #define UHCI_STRCUTURES_ALIGNMENT 16 43 45 #define UHCI_REQUIRED_PAGE_SIZE 4096 46 44 47 45 48 /** Get physical address translation … … 54 57 55 58 uintptr_t result; 56 int ret = as_get_physical_mapping(addr, &result); 59 const int ret = as_get_physical_mapping(addr, &result); 60 assert(ret == EOK); 57 61 58 62 if (ret != EOK) … … 66 70 * @return Address of the alligned and big enough memory place, NULL on failure. 67 71 */ 68 static inline void * malloc32(size_t size) 69 { return memalign(UHCI_STRCUTURES_ALIGNMENT, size); } 72 static inline void * malloc32(size_t size) { 73 if (size <= SLAB_ELEMENT_SIZE) 74 return slab_malloc_g(); 75 assert(false); 76 return memalign(UHCI_STRCUTURES_ALIGNMENT, size); 77 } 70 78 /*----------------------------------------------------------------------------*/ 71 79 /** Physical mallocator simulator … … 73 81 * @param[in] addr Address of the place allocated by malloc32 74 82 */ 75 static inline void free32(void *addr) 76 { if (addr) free(addr); } 83 static inline void free32(void *addr) { 84 if (!addr) 85 return; 86 if (slab_in_range_g(addr)) 87 return slab_free_g(addr); 88 free(addr); 89 } 77 90 /*----------------------------------------------------------------------------*/ 78 91 /** Create 4KB page mapping … … 82 95 static inline void * get_page(void) 83 96 { 84 void * 85 assert(free_address); 97 void *free_address = as_get_mappable_page(UHCI_REQUIRED_PAGE_SIZE); 98 assert(free_address); /* TODO: remove this assert */ 86 99 if (free_address == 0) 87 100 return NULL; 88 void* ret = 89 as_area_create(free_address, UHCI_REQUIRED_PAGE_SIZE, 101 void *ret = as_area_create(free_address, UHCI_REQUIRED_PAGE_SIZE, 90 102 AS_AREA_READ | AS_AREA_WRITE); 91 103 if (ret != free_address) -
uspace/drv/usbmid/explore.c
rf3da9b2 raee6c73 40 40 #include <usb/request.h> 41 41 #include <usb/dp.h> 42 #include <usb/ddfiface.h> 42 43 #include "usbmid.h" 44 45 /** Operations of the device itself. */ 46 static ddf_dev_ops_t mid_device_ops = { 47 .interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl 48 }; 43 49 44 50 /** Find starting indexes of all interface descriptors in a configuration. … … 105 111 * @return Whether to accept this device from devman. 106 112 */ 107 bool usbmid_explore_device(usb mid_device_t *dev)113 bool usbmid_explore_device(usb_device_t *dev) 108 114 { 109 usb_standard_device_descriptor_t device_descriptor; 110 int rc = usb_request_get_device_descriptor(&dev->ctrl_pipe, 111 &device_descriptor); 112 if (rc != EOK) { 113 usb_log_error("Getting device descriptor failed: %s.\n", 114 str_error(rc)); 115 return false; 116 } 117 118 if (device_descriptor.device_class != USB_CLASS_USE_INTERFACE) { 115 int rc; 116 117 int dev_class = dev->descriptors.device.device_class; 118 if (dev_class != USB_CLASS_USE_INTERFACE) { 119 119 usb_log_warning( 120 120 "Device class: %d (%s), but expected class 0.\n", 121 device_descriptor.device_class, 122 usb_str_class(device_descriptor.device_class)); 121 dev_class, usb_str_class(dev_class)); 123 122 usb_log_error("Not multi interface device, refusing.\n"); 124 123 return false; 125 124 } 126 125 127 size_t config_descriptor_size; 128 uint8_t *config_descriptor_raw = NULL; 129 rc = usb_request_get_full_configuration_descriptor_alloc( 130 &dev->ctrl_pipe, 0, 131 (void **) &config_descriptor_raw, &config_descriptor_size); 132 if (rc != EOK) { 133 usb_log_error("Failed getting full config descriptor: %s.\n", 134 str_error(rc)); 135 return false; 136 } 137 138 usb_standard_configuration_descriptor_t *config_descriptor 139 = (usb_standard_configuration_descriptor_t *) config_descriptor_raw; 126 /* Short cuts to save on typing ;-). */ 127 uint8_t *config_descriptor_raw = dev->descriptors.configuration; 128 size_t config_descriptor_size = dev->descriptors.configuration_size; 129 usb_standard_configuration_descriptor_t *config_descriptor = 130 (usb_standard_configuration_descriptor_t *) config_descriptor_raw; 140 131 141 132 size_t *interface_descriptors … … 154 145 if (interface_descriptors_count == (size_t) -1) { 155 146 usb_log_error("Problem parsing configuration descriptor.\n"); 156 free(config_descriptor_raw);157 147 free(interface_descriptors); 158 148 return false; … … 165 155 usb_log_error("Failed to set device configuration: %s.\n", 166 156 str_error(rc)); 167 free(config_descriptor_raw);168 157 free(interface_descriptors); 169 158 return false; … … 172 161 173 162 /* Create control function */ 174 ddf_fun_t *ctl_fun = ddf_fun_create(dev->d ev, fun_exposed, "ctl");163 ddf_fun_t *ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl"); 175 164 if (ctl_fun == NULL) { 176 165 usb_log_error("Failed to create control function.\n"); 177 free(config_descriptor_raw); 178 free(interface_descriptors); 179 return false; 180 } 166 free(interface_descriptors); 167 return false; 168 } 169 170 ctl_fun->ops = &mid_device_ops; 171 181 172 rc = ddf_fun_bind(ctl_fun); 182 173 if (rc != EOK) { 183 174 usb_log_error("Failed to bind control function: %s.\n", 184 175 str_error(rc)); 185 free(config_descriptor_raw);186 176 free(interface_descriptors); 187 177 return false; … … 199 189 (int) interface->interface_number, 200 190 usb_str_class(interface->interface_class)); 201 rc = usbmid_spawn_interface_child(dev, &dev ice_descriptor,191 rc = usbmid_spawn_interface_child(dev, &dev->descriptors.device, 202 192 interface); 203 193 if (rc != EOK) { … … 207 197 } 208 198 209 free(config_descriptor_raw);210 211 199 return true; 212 200 } -
uspace/drv/usbmid/main.c
rf3da9b2 raee6c73 49 49 * @return Error code. 50 50 */ 51 static int usbmid_add_device( ddf_dev_t *gen_dev)51 static int usbmid_add_device(usb_device_t *dev) 52 52 { 53 usbmid_device_t *dev = usbmid_device_create(gen_dev); 54 if (dev == NULL) { 55 return ENOMEM; 56 } 57 58 usb_log_info("Taking care of new MID: addr %d (HC %zu)\n", 59 dev->wire.address, dev->wire.hc_handle); 53 usb_log_info("Taking care of new MID `%s'.\n", dev->ddf_dev->name); 60 54 61 55 int rc; … … 65 59 usb_log_error("Failed to start session on control pipe: %s.\n", 66 60 str_error(rc)); 67 goto error_leave;61 return rc; 68 62 } 69 63 … … 77 71 78 72 if (!accept) { 79 rc = ENOTSUP; 80 goto error_leave; 73 return ENOTSUP; 81 74 } 82 75 83 gen_dev->driver_data = dev;84 85 76 return EOK; 86 87 88 error_leave:89 free(dev);90 return rc;91 77 } 92 78 93 79 /** USB MID driver ops. */ 94 static driver_ops_t mid_driver_ops = {80 static usb_driver_ops_t mid_driver_ops = { 95 81 .add_device = usbmid_add_device, 96 82 }; 97 83 98 84 /** USB MID driver. */ 99 static driver_t mid_driver = {85 static usb_driver_t mid_driver = { 100 86 .name = NAME, 101 .driver_ops = &mid_driver_ops 87 .ops = &mid_driver_ops, 88 .endpoints = NULL 102 89 }; 103 90 … … 107 94 108 95 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME); 109 return ddf_driver_main(&mid_driver); 96 97 return usb_driver_main(&mid_driver); 110 98 } 111 99 -
uspace/drv/usbmid/usbmid.c
rf3da9b2 raee6c73 79 79 }; 80 80 81 /** Operations of the device itself. */82 static ddf_dev_ops_t mid_device_ops = {83 .interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl84 };85 86 /** Create new USB multi interface device.87 *88 * @param dev Backing generic DDF device.89 * @return New USB MID device.90 * @retval NULL Error occured.91 */92 usbmid_device_t *usbmid_device_create(ddf_dev_t *dev)93 {94 usbmid_device_t *mid = malloc(sizeof(usbmid_device_t));95 if (mid == NULL) {96 usb_log_error("Out of memory (wanted %zu bytes).\n",97 sizeof(usbmid_device_t));98 return NULL;99 }100 101 int rc;102 rc = usb_device_connection_initialize_from_device(&mid->wire, dev);103 if (rc != EOK) {104 usb_log_error("Failed to initialize `USB wire': %s.\n",105 str_error(rc));106 free(mid);107 return NULL;108 }109 110 rc = usb_pipe_initialize_default_control(&mid->ctrl_pipe,111 &mid->wire);112 if (rc != EOK) {113 usb_log_error("Failed to initialize control pipe: %s.\n",114 str_error(rc));115 free(mid);116 return NULL;117 }118 rc = usb_pipe_probe_default_control(&mid->ctrl_pipe);119 if (rc != EOK) {120 usb_log_error("Probing default control pipe failed: %s.\n",121 str_error(rc));122 free(mid);123 return NULL;124 }125 126 mid->dev = dev;127 (void) &mid_device_ops;128 129 return mid;130 }131 132 81 /** Create new interface for USB MID device. 133 82 * … … 160 109 * @return Error code. 161 110 */ 162 int usbmid_spawn_interface_child(usb mid_device_t *parent,111 int usbmid_spawn_interface_child(usb_device_t *parent, 163 112 const usb_standard_device_descriptor_t *device_descriptor, 164 113 const usb_standard_interface_descriptor_t *interface_descriptor) … … 182 131 183 132 /* Create the device. */ 184 child = ddf_fun_create(parent->d ev, fun_inner, child_name);133 child = ddf_fun_create(parent->ddf_dev, fun_inner, child_name); 185 134 if (child == NULL) { 186 135 rc = ENOMEM; -
uspace/drv/usbmid/usbmid.h
rf3da9b2 raee6c73 41 41 #include <usb/pipes.h> 42 42 #include <usb/debug.h> 43 #include <usb/devdrv.h> 43 44 44 45 #define NAME "usbmid" 45 46 /** USB MID device container. */47 typedef struct {48 /** Device container. */49 ddf_dev_t *dev;50 51 /** Representation of USB wire. */52 usb_device_connection_t wire;53 /** Default control pipe. */54 usb_pipe_t ctrl_pipe;55 } usbmid_device_t;56 57 46 58 47 /** Container for single interface in a MID device. */ … … 65 54 } usbmid_interface_t; 66 55 67 usbmid_device_t *usbmid_device_create(ddf_dev_t *);68 56 usbmid_interface_t *usbmid_interface_create(ddf_fun_t *, int); 69 bool usbmid_explore_device(usb mid_device_t *);70 int usbmid_spawn_interface_child(usb mid_device_t *,57 bool usbmid_explore_device(usb_device_t *); 58 int usbmid_spawn_interface_child(usb_device_t *, 71 59 const usb_standard_device_descriptor_t *, 72 60 const usb_standard_interface_descriptor_t *); -
uspace/lib/c/generic/malloc.c
rf3da9b2 raee6c73 240 240 size_t asize = ALIGN_UP(size, PAGE_SIZE); 241 241 242 astart = as_area_create(astart, asize, AS_AREA_WRITE | AS_AREA_READ );242 astart = as_area_create(astart, asize, AS_AREA_WRITE | AS_AREA_READ | AS_AREA_CACHEABLE); 243 243 if (astart == (void *) -1) 244 244 return false; -
uspace/lib/usb/include/usb/host/device_keeper.h
rf3da9b2 raee6c73 51 51 usb_speed_t speed; 52 52 bool occupied; 53 bool control_used; 53 54 uint16_t toggle_status[2]; 54 55 devman_handle_t handle; … … 61 62 struct usb_device_info devices[USB_ADDRESS_COUNT]; 62 63 fibril_mutex_t guard; 63 fibril_condvar_t default_address_occupied;64 fibril_condvar_t change; 64 65 usb_address_t last_address; 65 66 } usb_device_keeper_t; … … 97 98 usb_address_t address); 98 99 100 void usb_device_keeper_use_control(usb_device_keeper_t *instance, 101 usb_address_t address); 102 103 void usb_device_keeper_release_control(usb_device_keeper_t *instance, 104 usb_address_t address); 105 99 106 #endif 100 107 /** -
uspace/lib/usb/src/host/device_keeper.c
rf3da9b2 raee6c73 49 49 assert(instance); 50 50 fibril_mutex_initialize(&instance->guard); 51 fibril_condvar_initialize(&instance-> default_address_occupied);51 fibril_condvar_initialize(&instance->change); 52 52 instance->last_address = 0; 53 53 unsigned i = 0; 54 54 for (; i < USB_ADDRESS_COUNT; ++i) { 55 55 instance->devices[i].occupied = false; 56 instance->devices[i].control_used = false; 56 57 instance->devices[i].handle = 0; 57 58 instance->devices[i].toggle_status[0] = 0; … … 71 72 fibril_mutex_lock(&instance->guard); 72 73 while (instance->devices[USB_ADDRESS_DEFAULT].occupied) { 73 fibril_condvar_wait(&instance->default_address_occupied, 74 &instance->guard); 74 fibril_condvar_wait(&instance->change, &instance->guard); 75 75 } 76 76 instance->devices[USB_ADDRESS_DEFAULT].occupied = true; … … 90 90 instance->devices[USB_ADDRESS_DEFAULT].occupied = false; 91 91 fibril_mutex_unlock(&instance->guard); 92 fibril_condvar_signal(&instance-> default_address_occupied);92 fibril_condvar_signal(&instance->change); 93 93 } 94 94 /*----------------------------------------------------------------------------*/ … … 309 309 return instance->devices[address].speed; 310 310 } 311 311 /*----------------------------------------------------------------------------*/ 312 void usb_device_keeper_use_control(usb_device_keeper_t *instance, 313 usb_address_t address) 314 { 315 assert(instance); 316 fibril_mutex_lock(&instance->guard); 317 while (instance->devices[address].control_used) { 318 fibril_condvar_wait(&instance->change, &instance->guard); 319 } 320 instance->devices[address].control_used = true; 321 fibril_mutex_unlock(&instance->guard); 322 } 323 /*----------------------------------------------------------------------------*/ 324 void usb_device_keeper_release_control(usb_device_keeper_t *instance, 325 usb_address_t address) 326 { 327 assert(instance); 328 fibril_mutex_lock(&instance->guard); 329 instance->devices[address].control_used = false; 330 fibril_mutex_unlock(&instance->guard); 331 fibril_condvar_signal(&instance->change); 332 } 312 333 /** 313 334 * @}
Note:
See TracChangeset
for help on using the changeset viewer.