Changes in / [aee6c73:f3da9b2] in mainline
- Files:
-
- 4 deleted
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
HelenOS.config
raee6c73 rf3da9b2 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
raee6c73 rf3da9b2 53 53 #include <str.h> 54 54 55 /*56 * devman produces a lot of output and by giving so many pages57 * we to allow /app/klog to catch-up.58 */59 #ifdef CONFIG_DEVMAN_EARLY_LAUNCH60 #define KLOG_PAGES 6461 #else62 55 #define KLOG_PAGES 4 63 #endif64 65 56 #define KLOG_LENGTH (KLOG_PAGES * PAGE_SIZE / sizeof(wchar_t)) 66 57 #define KLOG_LATENCY 8 -
kernel/generic/src/mm/as.c
raee6c73 rf3da9b2 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 , size, address,1951 if (as_area_create(AS, flags | AS_AREA_CACHEABLE, size, address, 1952 1952 AS_AREA_ATTR_NONE, &anon_backend, NULL)) 1953 1953 return (sysarg_t) address; -
uspace/app/init/init.c
raee6c73 rf3da9b2 313 313 getterm("term/vc5", "/app/bdsh", false); 314 314 getterm("term/vc6", "/app/klog", false); 315 316 #ifdef CONFIG_DEVMAN_EARLY_LAUNCH317 spawn("/srv/devman");318 #else319 315 getterm("term/vc7", "/srv/devman", false); 320 #endif 321 316 322 317 return 0; 323 318 } -
uspace/app/klog/klog.c
raee6c73 rf3da9b2 44 44 #include <io/klog.h> 45 45 #include <sysinfo.h> 46 #include <fibril_synch.h>47 46 48 47 #define NAME "klog" … … 55 54 static FILE *log; 56 55 57 /* Serialize the output a bit. This will not avoid messed-up log completely58 but chances for are pretty high (experimentally confirmed). */59 static FIBRIL_MUTEX_INITIALIZE(log_mutex);60 61 56 static void interrupt_received(ipc_callid_t callid, ipc_call_t *call) 62 57 { 63 fibril_mutex_lock(&log_mutex);64 65 58 size_t klog_start = (size_t) IPC_GET_ARG1(*call); 66 59 size_t klog_len = (size_t) IPC_GET_ARG2(*call); … … 81 74 fsync(fileno(log)); 82 75 } 83 84 fibril_mutex_unlock(&log_mutex);85 76 } 86 77 -
uspace/drv/ohci/Makefile
raee6c73 rf3da9b2 37 37 main.c \ 38 38 hc.c \ 39 ohci.c \40 39 root_hub.c \ 41 40 pci.c -
uspace/drv/ohci/hc.c
raee6c73 rf3da9b2 39 39 #include <usb/debug.h> 40 40 #include <usb/usb.h> 41 #include <usb/hub.h> 41 42 #include <usb/ddfiface.h> 42 43 #include <usb/usbdevice.h> … … 44 45 #include "hc.h" 45 46 47 static int dummy_reset(int foo, void *arg); 46 48 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 }73 49 /*----------------------------------------------------------------------------*/ 74 50 int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev, … … 92 68 } 93 69 70 94 71 rh_init(&instance->rh, dev, instance->registers); 72 /* 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)0 84 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; 95 89 96 /* TODO: implement */ 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"); 97 110 return EOK; 98 111 } … … 121 134 } 122 135 /*----------------------------------------------------------------------------*/ 123 int interrupt_emulator(hc_t *instance) 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) 124 145 { 125 146 assert(instance); -
uspace/drv/ohci/hc.h
raee6c73 rf3da9b2 57 57 } hc_t; 58 58 59 int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun);60 61 59 int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev, 62 60 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
raee6c73 rf3da9b2 33 33 * Common OHCI definitions. 34 34 */ 35 #ifndef DRV_OHCI_ IFACE_H36 #define DRV_OHCI_ IFACE_H35 #ifndef DRV_OHCI_OHCI_H 36 #define DRV_OHCI_OHCI_H 37 37 38 38 #include <usbhc_iface.h> 39 40 #define NAME "ohci" 39 41 40 42 extern usbhc_iface_t hc_iface; -
uspace/drv/ohci/main.c
raee6c73 rf3da9b2 34 34 */ 35 35 #include <ddf/driver.h> 36 #include <ddf/interrupt.h> 37 #include <device/hw_res.h> 36 38 #include <errno.h> 37 39 #include <str_error.h> 38 40 41 #include <usb_iface.h> 42 #include <usb/ddfiface.h> 39 43 #include <usb/debug.h> 40 44 41 #include " ohci.h"42 43 # define NAME "ohci"45 #include "pci.h" 46 #include "iface.h" 47 #include "hc.h" 44 48 45 49 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 device 77 * 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 } 46 89 /*----------------------------------------------------------------------------*/ 47 90 static driver_ops_t ohci_driver_ops = { … … 54 97 }; 55 98 /*----------------------------------------------------------------------------*/ 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 /*----------------------------------------------------------------------------*/ 56 109 /** Initializes a new ddf driver instance of OHCI hcd. 57 110 * … … 59 112 * @return Error code. 60 113 */ 61 int ohci_add_device(ddf_dev_t *device) 62 { 63 usb_log_debug("ohci_add_device() called\n"); 114 static int ohci_add_device(ddf_dev_t *device) 115 { 64 116 assert(device); 65 ohci_t *ohci = malloc(sizeof(ohci_t)); 66 if (ohci == NULL) { 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) { 67 140 usb_log_error("Failed to allocate OHCI driver.\n"); 68 141 return ENOMEM; 69 142 } 70 143 71 int ret = ohci_init(ohci, device); 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); 72 158 if (ret != EOK) { 73 usb_log_ error("Failed to initialize OHCI driver: %s.\n",159 usb_log_warning("Failed to enable interrupts: %s.\n", 74 160 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 #endif 168 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); 75 173 return ret; 76 174 } 77 device->driver_data = ohci; 78 79 usb_log_info("Controlling new OHCI device `%s'.\n", device->name); 175 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); 80 193 81 194 return EOK; 195 #undef CHECK_RET_RETURN 82 196 } 83 197 /*----------------------------------------------------------------------------*/ -
uspace/drv/ohci/root_hub.c
raee6c73 rf3da9b2 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 guessed55 .max_packet_size = 8,56 .vendor_id = 0x16db,57 .product_id = 0x0001,58 /// \TODO these values migt be different59 .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 guessed66 .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 };98 45 99 46 /** Root hub initialization … … 383 330 (usb_device_request_setup_packet_t*)request->setup_buffer; 384 331 size_t size; 385 const void * result_descriptor = NULL;386 constuint16_t setup_request_value = setup_request->value_high;332 void * result_descriptor; 333 uint16_t setup_request_value = setup_request->value_high; 387 334 //(setup_request->value_low << 8); 388 #if 0389 bool del = false;390 //this code was merged from development and has to be reviewed391 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->length446 );447 return EINVAL;448 }449 }450 #endif451 335 if(setup_request_value == USB_DESCTYPE_HUB){ 452 336 usb_log_debug("USB_DESCTYPE_HUB\n"); … … 494 378 request->transfered_size = size; 495 379 memcpy(request->buffer,result_descriptor,size); 496 if (result_descriptor) 497 free(result_descriptor); 380 free(result_descriptor); 498 381 return EOK; 499 382 } -
uspace/drv/uhci-hcd/Makefile
raee6c73 rf3da9b2 40 40 root_hub.c \ 41 41 hw_struct/transfer_descriptor.c \ 42 utils/slab.c \43 42 pci.c \ 44 43 batch.c -
uspace/drv/uhci-hcd/hc.c
raee6c73 rf3da9b2 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 at %p.\n", instance->frame_list);225 usb_log_debug("Initialized frame list.\n"); 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 }342 338 transfer_list_add_batch(list, batch); 343 339 … … 361 357 /* Lower 2 bits are transaction error and transaction complete */ 362 358 if (status & 0x3) { 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 } 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); 384 363 } 385 364 /* bits 4 and 5 indicate hc error */ -
uspace/drv/uhci-hcd/root_hub.c
raee6c73 rf3da9b2 48 48 * @return Error code. 49 49 */ 50 int rh_init(rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size) 50 int rh_init( 51 rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size) 51 52 { 52 53 assert(fun); -
uspace/drv/uhci-hcd/transfer_list.c
raee6c73 rf3da9b2 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);62 60 63 61 qh_init(instance->queue_head); … … 120 118 qh_set_next_qh(last_qh, pa); 121 119 122 asm volatile ("": : :"memory");123 124 120 /* Add to the driver list */ 125 121 list_append(&batch->link, &instance->batch_list); … … 141 137 * this transfer list leading to the deadlock if its done inline. 142 138 */ 143 void transfer_list_remove_finished(transfer_list_t *instance, link_t *done) 144 { 145 assert(instance); 146 assert(done); 139 void transfer_list_remove_finished(transfer_list_t *instance) 140 { 141 assert(instance); 142 143 LIST_INITIALIZE(done); 147 144 148 145 fibril_mutex_lock(&instance->guard); … … 156 153 /* Save for post-processing */ 157 154 transfer_list_remove_batch(instance, batch); 158 list_append(current, done);155 list_append(current, &done); 159 156 } 160 157 current = next; … … 162 159 fibril_mutex_unlock(&instance->guard); 163 160 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 } 164 168 } 165 169 /*----------------------------------------------------------------------------*/ … … 218 222 qpos = "NOT FIRST"; 219 223 } 220 asm volatile ("": : :"memory");221 224 /* Remove from the batch list */ 222 225 list_remove(&batch->link); -
uspace/drv/uhci-hcd/transfer_list.h
raee6c73 rf3da9b2 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 , link_t *done);69 void transfer_list_remove_finished(transfer_list_t *instance); 70 70 71 71 void transfer_list_abort_all(transfer_list_t *instance); -
uspace/drv/uhci-hcd/uhci.c
raee6c73 rf3da9b2 44 44 #include "pci.h" 45 45 46 46 47 /** IRQ handling callback, identifies device 47 48 * … … 107 108 /*----------------------------------------------------------------------------*/ 108 109 static ddf_dev_ops_t hc_ops = { 109 //.interfaces[USB_DEV_IFACE] = &usb_iface,110 .interfaces[USB_DEV_IFACE] = &usb_iface, 110 111 .interfaces[USBHC_DEV_IFACE] = &hc_iface, /* see iface.h/c */ 111 112 }; -
uspace/drv/uhci-hcd/utils/malloc32.h
raee6c73 rf3da9b2 40 40 #include <as.h> 41 41 42 #include "slab.h"43 44 42 #define UHCI_STRCUTURES_ALIGNMENT 16 45 43 #define UHCI_REQUIRED_PAGE_SIZE 4096 46 47 44 48 45 /** Get physical address translation … … 57 54 58 55 uintptr_t result; 59 const int ret = as_get_physical_mapping(addr, &result); 60 assert(ret == EOK); 56 int ret = as_get_physical_mapping(addr, &result); 61 57 62 58 if (ret != EOK) … … 70 66 * @return Address of the alligned and big enough memory place, NULL on failure. 71 67 */ 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 } 68 static inline void * malloc32(size_t size) 69 { return memalign(UHCI_STRCUTURES_ALIGNMENT, size); } 78 70 /*----------------------------------------------------------------------------*/ 79 71 /** Physical mallocator simulator … … 81 73 * @param[in] addr Address of the place allocated by malloc32 82 74 */ 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 } 75 static inline void free32(void *addr) 76 { if (addr) free(addr); } 90 77 /*----------------------------------------------------------------------------*/ 91 78 /** Create 4KB page mapping … … 95 82 static inline void * get_page(void) 96 83 { 97 void * free_address = as_get_mappable_page(UHCI_REQUIRED_PAGE_SIZE);98 assert(free_address); /* TODO: remove this assert */84 void * free_address = as_get_mappable_page(UHCI_REQUIRED_PAGE_SIZE); 85 assert(free_address); 99 86 if (free_address == 0) 100 87 return NULL; 101 void *ret = as_area_create(free_address, UHCI_REQUIRED_PAGE_SIZE, 88 void* ret = 89 as_area_create(free_address, UHCI_REQUIRED_PAGE_SIZE, 102 90 AS_AREA_READ | AS_AREA_WRITE); 103 91 if (ret != free_address) -
uspace/drv/usbmid/explore.c
raee6c73 rf3da9b2 40 40 #include <usb/request.h> 41 41 #include <usb/dp.h> 42 #include <usb/ddfiface.h>43 42 #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_impl48 };49 43 50 44 /** Find starting indexes of all interface descriptors in a configuration. … … 111 105 * @return Whether to accept this device from devman. 112 106 */ 113 bool usbmid_explore_device(usb _device_t *dev)107 bool usbmid_explore_device(usbmid_device_t *dev) 114 108 { 115 int rc; 116 117 int dev_class = dev->descriptors.device.device_class; 118 if (dev_class != USB_CLASS_USE_INTERFACE) { 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) { 119 119 usb_log_warning( 120 120 "Device class: %d (%s), but expected class 0.\n", 121 dev_class, usb_str_class(dev_class)); 121 device_descriptor.device_class, 122 usb_str_class(device_descriptor.device_class)); 122 123 usb_log_error("Not multi interface device, refusing.\n"); 123 124 return false; 124 125 } 125 126 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; 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; 131 140 132 141 size_t *interface_descriptors … … 145 154 if (interface_descriptors_count == (size_t) -1) { 146 155 usb_log_error("Problem parsing configuration descriptor.\n"); 156 free(config_descriptor_raw); 147 157 free(interface_descriptors); 148 158 return false; … … 155 165 usb_log_error("Failed to set device configuration: %s.\n", 156 166 str_error(rc)); 167 free(config_descriptor_raw); 157 168 free(interface_descriptors); 158 169 return false; … … 161 172 162 173 /* Create control function */ 163 ddf_fun_t *ctl_fun = ddf_fun_create(dev->d df_dev, fun_exposed, "ctl");174 ddf_fun_t *ctl_fun = ddf_fun_create(dev->dev, fun_exposed, "ctl"); 164 175 if (ctl_fun == NULL) { 165 176 usb_log_error("Failed to create control function.\n"); 166 free(interface_descriptors); 167 return false; 168 } 169 170 ctl_fun->ops = &mid_device_ops; 171 177 free(config_descriptor_raw); 178 free(interface_descriptors); 179 return false; 180 } 172 181 rc = ddf_fun_bind(ctl_fun); 173 182 if (rc != EOK) { 174 183 usb_log_error("Failed to bind control function: %s.\n", 175 184 str_error(rc)); 185 free(config_descriptor_raw); 176 186 free(interface_descriptors); 177 187 return false; … … 189 199 (int) interface->interface_number, 190 200 usb_str_class(interface->interface_class)); 191 rc = usbmid_spawn_interface_child(dev, &dev ->descriptors.device,201 rc = usbmid_spawn_interface_child(dev, &device_descriptor, 192 202 interface); 193 203 if (rc != EOK) { … … 197 207 } 198 208 209 free(config_descriptor_raw); 210 199 211 return true; 200 212 } -
uspace/drv/usbmid/main.c
raee6c73 rf3da9b2 49 49 * @return Error code. 50 50 */ 51 static int usbmid_add_device( usb_device_t *dev)51 static int usbmid_add_device(ddf_dev_t *gen_dev) 52 52 { 53 usb_log_info("Taking care of new MID `%s'.\n", dev->ddf_dev->name); 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); 54 60 55 61 int rc; … … 59 65 usb_log_error("Failed to start session on control pipe: %s.\n", 60 66 str_error(rc)); 61 return rc;67 goto error_leave; 62 68 } 63 69 … … 71 77 72 78 if (!accept) { 73 return ENOTSUP; 79 rc = ENOTSUP; 80 goto error_leave; 74 81 } 75 82 83 gen_dev->driver_data = dev; 84 76 85 return EOK; 86 87 88 error_leave: 89 free(dev); 90 return rc; 77 91 } 78 92 79 93 /** USB MID driver ops. */ 80 static usb_driver_ops_t mid_driver_ops = {94 static driver_ops_t mid_driver_ops = { 81 95 .add_device = usbmid_add_device, 82 96 }; 83 97 84 98 /** USB MID driver. */ 85 static usb_driver_t mid_driver = {99 static driver_t mid_driver = { 86 100 .name = NAME, 87 .ops = &mid_driver_ops, 88 .endpoints = NULL 101 .driver_ops = &mid_driver_ops 89 102 }; 90 103 … … 94 107 95 108 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME); 96 97 return usb_driver_main(&mid_driver); 109 return ddf_driver_main(&mid_driver); 98 110 } 99 111 -
uspace/drv/usbmid/usbmid.c
raee6c73 rf3da9b2 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_impl 84 }; 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 81 132 /** Create new interface for USB MID device. 82 133 * … … 109 160 * @return Error code. 110 161 */ 111 int usbmid_spawn_interface_child(usb _device_t *parent,162 int usbmid_spawn_interface_child(usbmid_device_t *parent, 112 163 const usb_standard_device_descriptor_t *device_descriptor, 113 164 const usb_standard_interface_descriptor_t *interface_descriptor) … … 131 182 132 183 /* Create the device. */ 133 child = ddf_fun_create(parent->d df_dev, fun_inner, child_name);184 child = ddf_fun_create(parent->dev, fun_inner, child_name); 134 185 if (child == NULL) { 135 186 rc = ENOMEM; -
uspace/drv/usbmid/usbmid.h
raee6c73 rf3da9b2 41 41 #include <usb/pipes.h> 42 42 #include <usb/debug.h> 43 #include <usb/devdrv.h>44 43 45 44 #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 46 57 47 58 /** Container for single interface in a MID device. */ … … 54 65 } usbmid_interface_t; 55 66 67 usbmid_device_t *usbmid_device_create(ddf_dev_t *); 56 68 usbmid_interface_t *usbmid_interface_create(ddf_fun_t *, int); 57 bool usbmid_explore_device(usb _device_t *);58 int usbmid_spawn_interface_child(usb _device_t *,69 bool usbmid_explore_device(usbmid_device_t *); 70 int usbmid_spawn_interface_child(usbmid_device_t *, 59 71 const usb_standard_device_descriptor_t *, 60 72 const usb_standard_interface_descriptor_t *); -
uspace/lib/c/generic/malloc.c
raee6c73 rf3da9b2 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 | AS_AREA_CACHEABLE);242 astart = as_area_create(astart, asize, AS_AREA_WRITE | AS_AREA_READ); 243 243 if (astart == (void *) -1) 244 244 return false; -
uspace/lib/usb/include/usb/host/device_keeper.h
raee6c73 rf3da9b2 51 51 usb_speed_t speed; 52 52 bool occupied; 53 bool control_used;54 53 uint16_t toggle_status[2]; 55 54 devman_handle_t handle; … … 62 61 struct usb_device_info devices[USB_ADDRESS_COUNT]; 63 62 fibril_mutex_t guard; 64 fibril_condvar_t change;63 fibril_condvar_t default_address_occupied; 65 64 usb_address_t last_address; 66 65 } usb_device_keeper_t; … … 98 97 usb_address_t address); 99 98 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 106 99 #endif 107 100 /** -
uspace/lib/usb/src/host/device_keeper.c
raee6c73 rf3da9b2 49 49 assert(instance); 50 50 fibril_mutex_initialize(&instance->guard); 51 fibril_condvar_initialize(&instance-> change);51 fibril_condvar_initialize(&instance->default_address_occupied); 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;57 56 instance->devices[i].handle = 0; 58 57 instance->devices[i].toggle_status[0] = 0; … … 72 71 fibril_mutex_lock(&instance->guard); 73 72 while (instance->devices[USB_ADDRESS_DEFAULT].occupied) { 74 fibril_condvar_wait(&instance->change, &instance->guard); 73 fibril_condvar_wait(&instance->default_address_occupied, 74 &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-> change);92 fibril_condvar_signal(&instance->default_address_occupied); 93 93 } 94 94 /*----------------------------------------------------------------------------*/ … … 309 309 return instance->devices[address].speed; 310 310 } 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 } 311 333 312 /** 334 313 * @}
Note:
See TracChangeset
for help on using the changeset viewer.