Changes in / [2ac7af3:6d4d883] in mainline
- Files:
-
- 37 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/ia64/src/drivers/ski.c
r2ac7af3 r6d4d883 219 219 * self-sufficient. 220 220 */ 221 sysinfo_set_item_val("fb", NULL, true);222 221 sysinfo_set_item_val("fb.kind", NULL, 6); 223 222 -
kernel/generic/src/console/cmd.c
r2ac7af3 r6d4d883 1177 1177 /* Execute the test */ 1178 1178 test_quiet = true; 1179 const char * test_ret = test->entry();1179 const char *ret = test->entry(); 1180 1180 1181 1181 /* Update and read thread accounting */ … … 1185 1185 irq_spinlock_unlock(&TASK->lock, true); 1186 1186 1187 if ( test_ret != NULL) {1188 printf("%s\n", test_ret);1187 if (ret != NULL) { 1188 printf("%s\n", ret); 1189 1189 ret = false; 1190 1190 break; -
uspace/drv/bus/usb/ohci/hc.c
r2ac7af3 r6d4d883 571 571 usb_log_debug2("OHCI HCCA initialized at %p.\n", instance->hcca); 572 572 573 for (unsigned i = 0; i < 32; ++i) { 573 unsigned i = 0; 574 for (; i < 32; ++i) { 574 575 instance->hcca->int_ep[i] = 575 576 instance->lists[USB_TRANSFER_INTERRUPT].list_head_pa; -
uspace/drv/bus/usb/ohci/ohci_batch.c
r2ac7af3 r6d4d883 52 52 if (!ohci_batch) 53 53 return; 54 unsigned i = 0; 54 55 if (ohci_batch->tds) { 55 for ( unsigned i = 0; i< ohci_batch->td_count; ++i) {56 for (; i< ohci_batch->td_count; ++i) { 56 57 if (i != ohci_batch->leave_td) 57 58 free32(ohci_batch->tds[i]); … … 106 107 ohci_batch->tds[0] = ohci_endpoint_get(usb_batch->ep)->td; 107 108 ohci_batch->leave_td = 0; 108 109 for ( unsigned i = 1; i <= ohci_batch->td_count; ++i) {109 unsigned i = 1; 110 for (; i <= ohci_batch->td_count; ++i) { 110 111 ohci_batch->tds[i] = malloc32(sizeof(td_t)); 111 112 CHECK_NULL_DISPOSE_RET(ohci_batch->tds[i], … … 159 160 usb_log_debug("Batch %p checking %zu td(s) for completion.\n", 160 161 ohci_batch->usb_batch, ohci_batch->td_count); 161 usb_log_debug2("ED: % 08x:%08x:%08x:%08x.\n",162 usb_log_debug2("ED: %x:%x:%x:%x.\n", 162 163 ohci_batch->ed->status, ohci_batch->ed->td_head, 163 164 ohci_batch->ed->td_tail, ohci_batch->ed->next); … … 166 167 for (; i < ohci_batch->td_count; ++i) { 167 168 assert(ohci_batch->tds[i] != NULL); 168 usb_log_debug("TD %zu: % 08x:%08x:%08x:%08x.\n", i,169 usb_log_debug("TD %zu: %x:%x:%x:%x.\n", i, 169 170 ohci_batch->tds[i]->status, ohci_batch->tds[i]->cbp, 170 171 ohci_batch->tds[i]->next, ohci_batch->tds[i]->be); … … 174 175 ohci_batch->usb_batch->error = td_error(ohci_batch->tds[i]); 175 176 if (ohci_batch->usb_batch->error != EOK) { 176 usb_log_debug("Batch %p found error TD(%zu):% 08x.\n",177 usb_log_debug("Batch %p found error TD(%zu):%x.\n", 177 178 ohci_batch->usb_batch, i, 178 179 ohci_batch->tds[i]->status); … … 195 196 ohci_batch->usb_batch->transfered_size = 196 197 ohci_batch->usb_batch->buffer_size; 197 for (--i;i < ohci_batch->td_count; ++i) {198 for (--i;i < ohci_batch->td_count; ++i) 198 199 ohci_batch->usb_batch->transfered_size 199 200 -= td_remain_size(ohci_batch->tds[i]); 200 }201 201 202 202 /* Clear possible ED HALT */ … … 234 234 assert(ohci_batch->usb_batch); 235 235 assert(dir == USB_DIRECTION_IN || dir == USB_DIRECTION_OUT); 236 usb_log_debug("Using ED(%p): % 08x:%08x:%08x:%08x.\n", ohci_batch->ed,236 usb_log_debug("Using ED(%p): %x:%x:%x:%x.\n", ohci_batch->ed, 237 237 ohci_batch->ed->status, ohci_batch->ed->td_tail, 238 238 ohci_batch->ed->td_head, ohci_batch->ed->next); … … 251 251 ohci_batch->usb_batch->setup_size, toggle); 252 252 td_set_next(ohci_batch->tds[0], ohci_batch->tds[1]); 253 usb_log_debug("Created CONTROL SETUP TD: % 08x:%08x:%08x:%08x.\n",253 usb_log_debug("Created CONTROL SETUP TD: %x:%x:%x:%x.\n", 254 254 ohci_batch->tds[0]->status, ohci_batch->tds[0]->cbp, 255 255 ohci_batch->tds[0]->next, ohci_batch->tds[0]->be); … … 269 269 td_set_next(ohci_batch->tds[td_current], 270 270 ohci_batch->tds[td_current + 1]); 271 usb_log_debug("Created CONTROL DATA TD: % 08x:%08x:%08x:%08x.\n",271 usb_log_debug("Created CONTROL DATA TD: %x:%x:%x:%x.\n", 272 272 ohci_batch->tds[td_current]->status, 273 273 ohci_batch->tds[td_current]->cbp, … … 286 286 td_set_next(ohci_batch->tds[td_current], 287 287 ohci_batch->tds[td_current + 1]); 288 usb_log_debug("Created CONTROL STATUS TD: % 08x:%08x:%08x:%08x.\n",288 usb_log_debug("Created CONTROL STATUS TD: %x:%x:%x:%x.\n", 289 289 ohci_batch->tds[td_current]->status, 290 290 ohci_batch->tds[td_current]->cbp, … … 312 312 assert(ohci_batch->usb_batch); 313 313 assert(dir == USB_DIRECTION_IN || dir == USB_DIRECTION_OUT); 314 usb_log_debug("Using ED(%p): % 08x:%08x:%08x:%08x.\n", ohci_batch->ed,314 usb_log_debug("Using ED(%p): %x:%x:%x:%x.\n", ohci_batch->ed, 315 315 ohci_batch->ed->status, ohci_batch->ed->td_tail, 316 316 ohci_batch->ed->td_head, ohci_batch->ed->next); … … 328 328 ohci_batch->tds[td_current + 1]); 329 329 330 usb_log_debug("Created DATA TD: % 08x:%08x:%08x:%08x.\n",330 usb_log_debug("Created DATA TD: %x:%x:%x:%x.\n", 331 331 ohci_batch->tds[td_current]->status, 332 332 ohci_batch->tds[td_current]->cbp, -
uspace/drv/bus/usb/ohci/pci.c
r2ac7af3 r6d4d883 85 85 bool irq_found = false; 86 86 87 for (size_t i = 0; i < hw_resources.count; i++) { 87 size_t i; 88 for (i = 0; i < hw_resources.count; i++) { 88 89 hw_resource_t *res = &hw_resources.resources[i]; 89 90 switch (res->type) { -
uspace/drv/bus/usb/ohci/root_hub.c
r2ac7af3 r6d4d883 351 351 mask |= 1; 352 352 } 353 for (size_t port = 1; port <= instance->port_count; ++port) { 353 size_t port = 1; 354 for (; port <= instance->port_count; ++port) { 354 355 /* Write-clean bits are those that indicate change */ 355 356 if (RHPS_CHANGE_WC_MASK -
uspace/drv/bus/usb/ohci/utils/malloc32.h
r2ac7af3 r6d4d883 69 69 */ 70 70 static inline void free32(void *addr) 71 { free(addr); }71 { if (addr) free(addr); } 72 72 #endif 73 73 /** -
uspace/drv/bus/usb/uhci/hc.c
r2ac7af3 r6d4d883 299 299 const uint32_t queue = LINK_POINTER_QH( 300 300 addr_to_phys(instance->transfers_interrupt.queue_head)); 301 302 for (unsigned i = 0; i < UHCI_FRAME_LIST_COUNT; ++i) {301 unsigned i = 0; 302 for(; i < UHCI_FRAME_LIST_COUNT; ++i) { 303 303 instance->frame_list[i] = queue; 304 304 } -
uspace/drv/bus/usb/uhci/pci.c
r2ac7af3 r6d4d883 82 82 bool irq_found = false; 83 83 84 for (size_t i = 0; i < hw_resources.count; i++) { 84 size_t i; 85 for (i = 0; i < hw_resources.count; i++) { 85 86 const hw_resource_t *res = &hw_resources.resources[i]; 86 87 switch (res->type) { -
uspace/drv/bus/usb/uhci/uhci_batch.c
r2ac7af3 r6d4d883 167 167 uhci_batch->td_count); 168 168 uhci_batch->usb_batch->transfered_size = 0; 169 170 for ( size_t i = 0;i < uhci_batch->td_count; ++i) {169 size_t i = 0; 170 for (;i < uhci_batch->td_count; ++i) { 171 171 if (td_is_active(&uhci_batch->tds[i])) { 172 172 return false; -
uspace/drv/bus/usb/uhci/utils/malloc32.h
r2ac7af3 r6d4d883 62 62 } 63 63 /*----------------------------------------------------------------------------*/ 64 /** DMA mallocsimulator64 /** Physical mallocator simulator 65 65 * 66 66 * @param[in] size Size of the required memory space 67 * @return Address of the al igned and big enough memory place, NULL on failure.67 * @return Address of the alligned and big enough memory place, NULL on failure. 68 68 */ 69 static inline void * malloc32(size_t size) 70 { 69 static inline void * malloc32(size_t size) { 71 70 /* This works only when the host has less than 4GB of memory as 72 71 * physical address needs to fit into 32 bits */ … … 84 83 } 85 84 /*----------------------------------------------------------------------------*/ 86 /** DMA mallocsimulator85 /** Physical mallocator simulator 87 86 * 88 87 * @param[in] addr Address of the place allocated by malloc32 89 88 */ 90 static inline void free32(void *addr) 91 { free(addr); } 89 static inline void free32(void *addr) { 90 if (!addr) 91 return; 92 free(addr); 93 } 92 94 /*----------------------------------------------------------------------------*/ 93 95 /** Create 4KB page mapping -
uspace/drv/bus/usb/uhcirh/port.c
r2ac7af3 r6d4d883 37 37 #include <str_error.h> 38 38 #include <async.h> 39 #include <devman.h>40 39 41 40 #include <usb/usb.h> /* usb_address_t */ 41 #include <usb/dev/hub.h> /* usb_hc_new_device_wrapper */ 42 42 #include <usb/debug.h> 43 43 44 44 #include "port.h" 45 45 46 #define MAX_ERROR_COUNT 547 48 46 static int uhci_port_check(void *port); 49 static int uhci_port_reset_enable( void *arg);47 static int uhci_port_reset_enable(int portno, void *arg); 50 48 static int uhci_port_new_device(uhci_port_t *port, usb_speed_t speed); 51 49 static int uhci_port_remove_device(uhci_port_t *port); … … 102 100 port->number = number; 103 101 port->wait_period_usec = usec; 104 port->attached_device.fun = NULL; 105 port->attached_device.address = -1; 102 port->attached_device = 0; 106 103 port->rh = rh; 107 104 … … 153 150 assert(instance); 154 151 155 unsigned allowed_failures = MAX_ERROR_COUNT;156 #define CHECK_RET_FAIL(ret, msg...) \157 if (ret != EOK) { \158 usb_log_error(msg); \159 if (!(allowed_failures-- > 0)) { \160 usb_log_fatal( \161 "Maximum number of failures reached, " \162 "bailing out.\n"); \163 return ret; \164 } \165 continue; \166 } else (void)0167 168 152 while (1) { 169 153 async_usleep(instance->wait_period_usec); … … 183 167 instance->id_string, port_status); 184 168 185 int ret = usb_hc_connection_open(&instance->hc_connection);186 CHECK_RET_FAIL(ret, "%s: Failed to connect to HC %s.\n",187 instance->id_string, str_error(ret));188 189 169 /* Remove any old device */ 190 if (instance->attached_device.fun) { 170 if (instance->attached_device) { 171 usb_log_debug2("%s: Removing device.\n", 172 instance->id_string); 191 173 uhci_port_remove_device(instance); 192 174 } 193 175 176 int ret = 177 usb_hc_connection_open(&instance->hc_connection); 178 if (ret != EOK) { 179 usb_log_error("%s: Failed to connect to HC.", 180 instance->id_string); 181 continue; 182 } 183 194 184 if ((port_status & STATUS_CONNECTED) != 0) { 195 /* New device , this will take care of WC bits*/185 /* New device */ 196 186 const usb_speed_t speed = 197 187 ((port_status & STATUS_LOW_SPEED) != 0) ? … … 206 196 207 197 ret = usb_hc_connection_close(&instance->hc_connection); 208 CHECK_RET_FAIL(ret, "%s: Failed to disconnect from hc: %s.\n", 209 instance->id_string, str_error(ret)); 198 if (ret != EOK) { 199 usb_log_error("%s: Failed to disconnect.", 200 instance->id_string); 201 } 210 202 } 211 203 return EOK; … … 220 212 * Resets and enables the ub port. 221 213 */ 222 int uhci_port_reset_enable( void *arg)214 int uhci_port_reset_enable(int portno, void *arg) 223 215 { 224 216 uhci_port_t *port = arg; … … 264 256 usb_log_debug("%s: Detected new device.\n", port->id_string); 265 257 266 int ret, count = MAX_ERROR_COUNT; 258 int ret, count = 0; 259 usb_address_t dev_addr; 267 260 do { 268 261 ret = usb_hc_new_device_wrapper(port->rh, &port->hc_connection, 269 speed, uhci_port_reset_enable, port, 270 &port->attached_device.address, NULL, NULL, 271 &port->attached_device.fun); 272 } while (ret != EOK && count-- > 0); 262 speed, uhci_port_reset_enable, port->number, port, 263 &dev_addr, &port->attached_device, NULL, NULL, NULL); 264 } while (ret != EOK && ++count < 4); 273 265 274 266 if (ret != EOK) { … … 279 271 } 280 272 281 usb_log_info("%s: New device, address %d (handle %" PRIun ").\n", 282 port->id_string, port->attached_device.address, 283 port->attached_device.fun->handle); 273 usb_log_info("New device at port %u, address %d (handle %" PRIun ").\n", 274 port->number, dev_addr, port->attached_device); 284 275 return EOK; 285 276 } … … 287 278 /** Remove device. 288 279 * 289 * @param[in] port Port instance to use. 290 * @return Error code. 280 * @param[in] port Memory structure to use. 281 * @return Error code. 282 * 283 * Does not work, DDF does not support device removal. 284 * Does not even free used USB address (it would be dangerous if tis driver 285 * is still running). 291 286 */ 292 287 int uhci_port_remove_device(uhci_port_t *port) 293 288 { 294 assert(port); 295 /* There is nothing to remove. */ 296 if (port->attached_device.fun == NULL) { 297 usb_log_warning("%s: Removed a ghost device.\n", 298 port->id_string); 299 assert(port->attached_device.address == -1); 300 return EOK; 301 } 302 303 usb_log_debug("%s: Removing device.\n", port->id_string); 304 305 /* Stop driver first */ 306 int ret = ddf_fun_unbind(port->attached_device.fun); 307 if (ret != EOK) { 308 usb_log_error("%s: Failed to remove child function: %s.\n", 309 port->id_string, str_error(ret)); 310 return ret; 311 } 312 ddf_fun_destroy(port->attached_device.fun); 313 port->attached_device.fun = NULL; 314 315 /* Driver stopped, free used address */ 316 ret = usb_hc_unregister_device(&port->hc_connection, 317 port->attached_device.address); 318 if (ret != EOK) { 319 usb_log_error("%s: Failed to unregister address of removed " 320 "device: %s.\n", port->id_string, str_error(ret)); 321 return ret; 322 } 323 port->attached_device.address = -1; 324 325 usb_log_info("%s: Removed attached device.\n", port->id_string); 326 return EOK; 289 usb_log_error("%s: Don't know how to remove device %" PRIun ".\n", 290 port->id_string, port->attached_device); 291 port->attached_device = 0; 292 return ENOTSUP; 327 293 } 328 294 /*----------------------------------------------------------------------------*/ -
uspace/drv/bus/usb/uhcirh/port.h
r2ac7af3 r6d4d883 39 39 #include <ddf/driver.h> 40 40 #include <usb/hc.h> /* usb_hc_connection_t */ 41 #include <usb/dev/hub.h>42 41 43 42 typedef uint16_t port_status_t; … … 63 62 usb_hc_connection_t hc_connection; 64 63 ddf_dev_t *rh; 65 usb_hub_attached_device_t attached_device;64 devman_handle_t attached_device; 66 65 fid_t checker; 67 66 } uhci_port_t; -
uspace/drv/bus/usb/usbflbk/main.c
r2ac7af3 r6d4d883 46 46 * @return Error code. 47 47 */ 48 static int usbfallback_ device_add(usb_device_t *dev)48 static int usbfallback_add_device(usb_device_t *dev) 49 49 { 50 50 int rc; … … 74 74 /** USB fallback driver ops. */ 75 75 static usb_driver_ops_t usbfallback_driver_ops = { 76 . device_add = usbfallback_device_add,76 .add_device = usbfallback_add_device, 77 77 }; 78 78 -
uspace/drv/bus/usb/usbhid/main.c
r2ac7af3 r6d4d883 150 150 * @retval EREFUSED if the device is not supported. 151 151 */ 152 static int usb_hid_ device_add(usb_device_t *dev)152 static int usb_hid_add_device(usb_device_t *dev) 153 153 { 154 usb_log_debug("usb_hid_ device_add()\n");154 usb_log_debug("usb_hid_add_device()\n"); 155 155 156 156 if (dev == NULL) { … … 185 185 * supports unplug, more callbacks will be added. */ 186 186 static usb_driver_ops_t usb_hid_driver_ops = { 187 . device_add = usb_hid_device_add,187 .add_device = usb_hid_add_device, 188 188 }; 189 189 -
uspace/drv/bus/usb/usbhub/main.c
r2ac7af3 r6d4d883 59 59 * USB hub driver operations 60 60 * 61 * The most important one is device_add, which is set to usb_hub_device_add.61 * The most important one is add_device, which is set to usb_hub_add_device. 62 62 */ 63 63 static usb_driver_ops_t usb_hub_driver_ops = { 64 .device_add = usb_hub_device_add, 65 .device_gone = usb_hub_device_gone, 64 .add_device = usb_hub_add_device 66 65 }; 67 66 -
uspace/drv/bus/usb/usbhub/port.c
r2ac7af3 r6d4d883 50 50 /** Information for fibril for device discovery. */ 51 51 struct add_device_phase1 { 52 usb_hub_ dev_t *hub;52 usb_hub_info_t *hub; 53 53 usb_hub_port_t *port; 54 54 usb_speed_t speed; 55 55 }; 56 56 57 static int usb_hub_port_device_gone(usb_hub_port_t *port, usb_hub_dev_t *hub); 57 static void usb_hub_port_removed_device(usb_hub_port_t *port, 58 usb_hub_info_t *hub); 58 59 static void usb_hub_port_reset_completed(usb_hub_port_t *port, 59 60 usb_port_status_t status); 60 61 static int get_port_status(usb_hub_port_t *port, usb_port_status_t *status); 61 static int enable_port_callback( void *arg);62 static int enable_port_callback(int port_no, void *arg); 62 63 static int add_device_phase1_worker_fibril(void *arg); 63 static int create_add_device_fibril(usb_hub_port_t *port, usb_hub_ dev_t *hub,64 static int create_add_device_fibril(usb_hub_port_t *port, usb_hub_info_t *hub, 64 65 usb_speed_t speed); 65 66 66 int usb_hub_port_fini(usb_hub_port_t *port, usb_hub_dev_t *hub)67 {68 assert(port);69 if (port->attached_device.fun)70 return usb_hub_port_device_gone(port, hub);71 return EOK;72 }73 /*----------------------------------------------------------------------------*/74 67 /** 75 68 * Clear feature on hub port. 76 69 * 77 * @param port Port structure. 78 * @param feature Feature selector. 70 * @param hc Host controller telephone 71 * @param address Hub address 72 * @param port_index Port 73 * @param feature Feature selector 79 74 * @return Operation result 80 75 */ … … 83 78 { 84 79 assert(port); 85 constusb_device_request_setup_packet_t clear_request = {80 usb_device_request_setup_packet_t clear_request = { 86 81 .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE, 87 82 .request = USB_DEVREQ_CLEAR_FEATURE, … … 95 90 /*----------------------------------------------------------------------------*/ 96 91 /** 97 * Set feature on hub port. 98 * 99 * @param port Port structure. 100 * @param feature Feature selector. 92 * Clear feature on hub port. 93 * 94 * @param hc Host controller telephone 95 * @param address Hub address 96 * @param port_index Port 97 * @param feature Feature selector 101 98 * @return Operation result 102 99 */ … … 105 102 { 106 103 assert(port); 107 constusb_device_request_setup_packet_t clear_request = {104 usb_device_request_setup_packet_t clear_request = { 108 105 .request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE, 109 106 .request = USB_DEVREQ_SET_FEATURE, … … 116 113 } 117 114 /*----------------------------------------------------------------------------*/ 118 /**119 * Mark reset process as failed due to external reasons120 *121 * @param port Port structure122 */123 115 void usb_hub_port_reset_fail(usb_hub_port_t *port) 124 116 { … … 132 124 /*----------------------------------------------------------------------------*/ 133 125 /** 134 * Process interrupts on given port126 * Process interrupts on given hub port 135 127 * 136 128 * Accepts connection, over current and port reset change. 137 * @param port port structure138 129 * @param hub hub representation 139 */ 140 void usb_hub_port_process_interrupt(usb_hub_port_t *port, usb_hub_dev_t *hub) 130 * @param port port number, starting from 1 131 */ 132 void usb_hub_port_process_interrupt(usb_hub_port_t *port, usb_hub_info_t *hub) 141 133 { 142 134 assert(port); … … 179 171 * to that handler, it shall ACK the change too. */ 180 172 if (!(status & USB_HUB_PORT_C_STATUS_ENABLED)) { 181 usb_hub_port_ device_gone(port, hub);173 usb_hub_port_removed_device(port, hub); 182 174 } 183 175 } … … 188 180 usb_log_info("Port %zu, disabled because of errors.\n", 189 181 port->port_number); 190 usb_hub_port_ device_gone(port, hub);182 usb_hub_port_removed_device(port, hub); 191 183 const int rc = usb_hub_port_clear_feature(port, 192 184 USB_HUB_FEATURE_C_PORT_ENABLE); … … 246 238 port->port_number, status); 247 239 } 248 /*----------------------------------------------------------------------------*/ 240 249 241 /** 250 242 * routine called when a device on port has been removed … … 253 245 * Otherwise does not do anything, because DDF does not allow to remove device 254 246 * from it`s device tree. 255 * @param port port structure256 247 * @param hub hub representation 257 */ 258 int usb_hub_port_device_gone(usb_hub_port_t *port, usb_hub_dev_t *hub) 248 * @param port port number, starting from 1 249 */ 250 static void usb_hub_port_removed_device(usb_hub_port_t *port, 251 usb_hub_info_t *hub) 259 252 { 260 253 assert(port); 261 254 assert(hub); 262 if (port->attached_device.address < 0) { 255 if (port->attached_device.address >= 0) { 256 fibril_mutex_lock(&port->mutex); 257 port->attached_device.address = -1; 258 port->attached_device.handle = 0; 259 fibril_mutex_unlock(&port->mutex); 260 usb_log_info("Removed device on port %zu.\n", 261 port->port_number); 262 } else { 263 263 usb_log_warning( 264 264 "Device on port %zu removed before being registered.\n", … … 271 271 */ 272 272 usb_hub_port_reset_fail(port); 273 return EOK; 274 } 275 276 fibril_mutex_lock(&port->mutex); 277 assert(port->attached_device.fun); 278 usb_log_debug("Removing device on port %zu.\n", port->port_number); 279 int ret = ddf_fun_unbind(port->attached_device.fun); 280 if (ret != EOK) { 281 usb_log_error("Failed to unbind child function on port" 282 " %zu: %s.\n", port->port_number, str_error(ret)); 283 fibril_mutex_unlock(&port->mutex); 284 return ret; 285 } 286 287 ddf_fun_destroy(port->attached_device.fun); 288 port->attached_device.fun = NULL; 289 290 ret = usb_hc_unregister_device(&hub->connection, 291 port->attached_device.address); 292 if (ret != EOK) { 293 usb_log_warning("Failed to unregister address of the removed " 294 "device: %s.\n", str_error(ret)); 295 } 296 port->attached_device.address = -1; 297 fibril_mutex_unlock(&port->mutex); 298 usb_log_info("Removed device on port %zu.\n", port->port_number); 299 return EOK; 300 } 301 /*----------------------------------------------------------------------------*/ 273 } 274 } 275 302 276 /** 303 277 * Process port reset change … … 305 279 * After this change port should be enabled, unless some problem occurred. 306 280 * This functions triggers second phase of enabling new device. 307 * @param port Port structure 308 * @param status Port status mask 309 */ 310 void usb_hub_port_reset_completed(usb_hub_port_t *port, 281 * @param hub 282 * @param port 283 * @param status 284 */ 285 static void usb_hub_port_reset_completed(usb_hub_port_t *port, 311 286 usb_port_status_t status) 312 287 { … … 338 313 /** Retrieve port status. 339 314 * 340 * @param[in] port Port structure 315 * @param[in] ctrl_pipe Control pipe to use. 316 * @param[in] port Port number (starting at 1). 341 317 * @param[out] status Where to store the port status. 342 318 * @return Error code. … … 382 358 * 383 359 * @param port_no Port number (starting at 1). 384 * @param arg Custom argument, points to @c usb_hub_ dev_t.360 * @param arg Custom argument, points to @c usb_hub_info_t. 385 361 * @return Error code. 386 362 */ 387 static int enable_port_callback( void *arg)363 static int enable_port_callback(int port_no, void *arg) 388 364 { 389 365 usb_hub_port_t *port = arg; … … 404 380 fibril_mutex_unlock(&port->mutex); 405 381 406 return port->reset_okay ? EOK : ESTALL; 407 } 408 /*----------------------------------------------------------------------------*/ 382 if (port->reset_okay) { 383 return EOK; 384 } else { 385 return ESTALL; 386 } 387 } 388 409 389 /** Fibril for adding a new device. 410 390 * … … 415 395 * @return 0 Always. 416 396 */ 417 int add_device_phase1_worker_fibril(void *arg)397 static int add_device_phase1_worker_fibril(void *arg) 418 398 { 419 399 struct add_device_phase1 *data = arg; … … 421 401 422 402 usb_address_t new_address; 423 d df_fun_t *child_fun;403 devman_handle_t child_handle; 424 404 425 405 const int rc = usb_hc_new_device_wrapper(data->hub->usb_device->ddf_dev, 426 &data->hub->connection, data->speed, enable_port_callback, 427 data->port, &new_address, NULL, NULL, &child_fun); 406 &data->hub->connection, data->speed, 407 enable_port_callback, (int) data->port->port_number, 408 data->port, &new_address, &child_handle, 409 NULL, NULL, NULL); 428 410 429 411 if (rc != EOK) { … … 434 416 435 417 fibril_mutex_lock(&data->port->mutex); 436 data->port->attached_device. fun = child_fun;418 data->port->attached_device.handle = child_handle; 437 419 data->port->attached_device.address = new_address; 438 420 fibril_mutex_unlock(&data->port->mutex); … … 441 423 "address %d (handle %" PRIun ").\n", 442 424 data->hub->usb_device->ddf_dev->name, data->port->port_number, 443 new_address, child_ fun->handle);425 new_address, child_handle); 444 426 445 427 leave: … … 452 434 free(arg); 453 435 454 return rc;455 } 456 /*----------------------------------------------------------------------------*/ 436 return EOK; 437 } 438 457 439 /** Start device adding when connection change is detected. 458 440 * … … 464 446 * @return Error code. 465 447 */ 466 static int create_add_device_fibril(usb_hub_port_t *port, usb_hub_ dev_t *hub,448 static int create_add_device_fibril(usb_hub_port_t *port, usb_hub_info_t *hub, 467 449 usb_speed_t speed) 468 450 { … … 470 452 assert(port); 471 453 struct add_device_phase1 *data 472 = malloc(sizeof (struct add_device_phase1));454 = malloc(sizeof (struct add_device_phase1)); 473 455 if (data == NULL) { 474 456 return ENOMEM; -
uspace/drv/bus/usb/usbhub/port.h
r2ac7af3 r6d4d883 40 40 #include <usb/classes/hub.h> 41 41 42 typedef struct usb_hub_ dev usb_hub_dev_t;42 typedef struct usb_hub_info_t usb_hub_info_t; 43 43 44 44 /** Information about single port on a hub. */ … … 58 58 59 59 /** Information about attached device. */ 60 usb_h ub_attached_device_t attached_device;60 usb_hc_attached_device_t attached_device; 61 61 } usb_hub_port_t; 62 62 … … 70 70 assert(port); 71 71 port->attached_device.address = -1; 72 port->attached_device. fun = NULL;72 port->attached_device.handle = 0; 73 73 port->port_number = port_number; 74 74 port->control_pipe = control_pipe; … … 76 76 fibril_condvar_initialize(&port->reset_cv); 77 77 } 78 int usb_hub_port_fini(usb_hub_port_t *port, usb_hub_dev_t *hub); 78 79 void usb_hub_port_reset_fail(usb_hub_port_t *port); 80 void usb_hub_port_process_interrupt(usb_hub_port_t *port, usb_hub_info_t *hub); 79 81 int usb_hub_port_clear_feature( 80 82 usb_hub_port_t *port, usb_hub_class_feature_t feature); 81 83 int usb_hub_port_set_feature( 82 84 usb_hub_port_t *port, usb_hub_class_feature_t feature); 83 void usb_hub_port_reset_fail(usb_hub_port_t *port);84 void usb_hub_port_process_interrupt(usb_hub_port_t *port, usb_hub_dev_t *hub);85 85 86 86 #endif -
uspace/drv/bus/usb/usbhub/usbhub.c
r2ac7af3 r6d4d883 68 68 69 69 static int usb_set_first_configuration(usb_device_t *usb_device); 70 static usb_hub_ dev_t * usb_hub_dev_create(usb_device_t *usb_dev);71 static int usb_hub_process_hub_specific_info(usb_hub_ dev_t *hub_dev);72 static void usb_hub_over_current(const usb_hub_ dev_t *hub_dev,70 static usb_hub_info_t * usb_hub_info_create(usb_device_t *usb_dev); 71 static int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info); 72 static void usb_hub_over_current(const usb_hub_info_t *hub_info, 73 73 usb_hub_status_t status); 74 static void usb_hub_global_interrupt(const usb_hub_ dev_t *hub_dev);74 static void usb_hub_global_interrupt(const usb_hub_info_t *hub_info); 75 75 static void usb_hub_polling_terminated_callback(usb_device_t *device, 76 76 bool was_error, void *data); 77 77 78 /** 78 79 * Initialize hub device driver fibril … … 83 84 * @return error code 84 85 */ 85 int usb_hub_device_gone(usb_device_t *usb_dev) 86 { 87 assert(usb_dev); 88 usb_hub_dev_t *hub = usb_dev->driver_data; 89 assert(hub); 90 unsigned tries = 10; 91 while (hub->running) { 92 async_usleep(100000); 93 if (!tries--) { 94 usb_log_error("Can't remove hub, still running.\n"); 95 return EINPROGRESS; 96 } 97 } 98 99 assert(!hub->running); 100 101 for (size_t port = 0; port < hub->port_count; ++port) { 102 if (hub->ports[port].attached_device.fun) { 103 const int ret = 104 usb_hub_port_fini(&hub->ports[port], hub); 105 if (ret != EOK) 106 return ret; 107 } 108 } 109 free(hub->ports); 110 111 const int ret = ddf_fun_unbind(hub->hub_fun); 112 if (ret != EOK) { 113 usb_log_error("Failed to unbind '%s' function: %s.\n", 114 HUB_FNC_NAME, str_error(ret)); 115 return ret; 116 } 117 ddf_fun_destroy(hub->hub_fun); 118 119 free(hub); 120 usb_dev->driver_data = NULL; 121 usb_log_info("USB hub driver, stopped and cleaned.\n"); 122 return EOK; 123 } 124 /*----------------------------------------------------------------------------*/ 125 /** 126 * Initialize hub device driver fibril 127 * 128 * Creates hub representation and fibril that periodically checks hub's status. 129 * Hub representation is passed to the fibril. 130 * @param usb_dev generic usb device information 131 * @return error code 132 */ 133 int usb_hub_device_add(usb_device_t *usb_dev) 86 int usb_hub_add_device(usb_device_t *usb_dev) 134 87 { 135 88 assert(usb_dev); 136 89 /* Create driver soft-state structure */ 137 usb_hub_ dev_t *hub_dev = usb_hub_dev_create(usb_dev);138 if (hub_ dev== NULL) {90 usb_hub_info_t *hub_info = usb_hub_info_create(usb_dev); 91 if (hub_info == NULL) { 139 92 usb_log_error("Failed to create hun driver structure.\n"); 140 93 return ENOMEM; … … 144 97 usb_log_debug("Initializing USB wire abstraction.\n"); 145 98 int opResult = usb_hc_connection_initialize_from_device( 146 &hub_ dev->connection, hub_dev->usb_device->ddf_dev);99 &hub_info->connection, hub_info->usb_device->ddf_dev); 147 100 if (opResult != EOK) { 148 101 usb_log_error("Could not initialize connection to device: %s\n", 149 102 str_error(opResult)); 150 free(hub_ dev);103 free(hub_info); 151 104 return opResult; 152 105 } … … 157 110 usb_log_error("Could not set hub configuration: %s\n", 158 111 str_error(opResult)); 159 free(hub_ dev);160 return opResult; 161 } 162 163 / * Get port count and create attached_devices. */164 opResult = usb_hub_process_hub_specific_info(hub_ dev);112 free(hub_info); 113 return opResult; 114 } 115 116 //get port count and create attached_devs 117 opResult = usb_hub_process_hub_specific_info(hub_info); 165 118 if (opResult != EOK) { 166 119 usb_log_error("Could process hub specific info, %s\n", 167 120 str_error(opResult)); 168 free(hub_ dev);121 free(hub_info); 169 122 return opResult; 170 123 } 171 124 172 125 usb_log_debug("Creating DDF function '" HUB_FNC_NAME "'.\n"); 173 hub_dev->hub_fun = ddf_fun_create(hub_dev->usb_device->ddf_dev,126 ddf_fun_t *hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev, 174 127 fun_exposed, HUB_FNC_NAME); 175 if (hub_ dev->hub_fun == NULL) {128 if (hub_fun == NULL) { 176 129 usb_log_error("Failed to create hub function.\n"); 177 free(hub_ dev);130 free(hub_info); 178 131 return ENOMEM; 179 132 } 180 133 181 opResult = ddf_fun_bind(hub_ dev->hub_fun);134 opResult = ddf_fun_bind(hub_fun); 182 135 if (opResult != EOK) { 183 136 usb_log_error("Failed to bind hub function: %s.\n", 184 137 str_error(opResult)); 185 free(hub_dev); 186 ddf_fun_destroy(hub_dev->hub_fun); 187 return opResult; 188 } 189 190 opResult = usb_device_auto_poll(hub_dev->usb_device, 0, 191 hub_port_changes_callback, ((hub_dev->port_count + 1 + 8) / 8), 192 usb_hub_polling_terminated_callback, hub_dev); 193 if (opResult != EOK) { 194 /* Function is already bound */ 195 ddf_fun_unbind(hub_dev->hub_fun); 196 ddf_fun_destroy(hub_dev->hub_fun); 197 free(hub_dev); 138 free(hub_info); 139 ddf_fun_destroy(hub_fun); 140 return opResult; 141 } 142 143 opResult = usb_device_auto_poll(hub_info->usb_device, 0, 144 hub_port_changes_callback, ((hub_info->port_count + 1) / 8) + 1, 145 usb_hub_polling_terminated_callback, hub_info); 146 if (opResult != EOK) { 147 ddf_fun_destroy(hub_fun); 148 free(hub_info); 198 149 usb_log_error("Failed to create polling fibril: %s.\n", 199 150 str_error(opResult)); 200 151 return opResult; 201 152 } 202 hub_dev->running = true;203 153 usb_log_info("Controlling hub '%s' (%zu ports).\n", 204 hub_ dev->usb_device->ddf_dev->name, hub_dev->port_count);154 hub_info->usb_device->ddf_dev->name, hub_info->port_count); 205 155 206 156 return EOK; … … 212 162 * @param change_bitmap Bitmap of changed ports. 213 163 * @param change_bitmap_size Size of the bitmap in bytes. 214 * @param arg Custom argument, points to @c usb_hub_ dev_t.164 * @param arg Custom argument, points to @c usb_hub_info_t. 215 165 * @return Whether to continue polling. 216 166 */ … … 219 169 { 220 170 usb_log_debug("hub_port_changes_callback\n"); 221 usb_hub_ dev_t *hub = arg;171 usb_hub_info_t *hub = arg; 222 172 assert(hub); 223 173 … … 234 184 235 185 /* N + 1 bit indicates change on port N */ 236 for (size_t port = 0; port < hub->port_count + 1; port++) {237 const size_t bit = port + 1;238 const bool change = (change_bitmap[ bit / 8] >> (bit % 8)) & 1;186 size_t port = 1; 187 for (; port < hub->port_count + 1; port++) { 188 const bool change = (change_bitmap[port / 8] >> (port % 8)) & 1; 239 189 if (change) { 240 190 usb_hub_port_process_interrupt(&hub->ports[port], hub); … … 245 195 /*----------------------------------------------------------------------------*/ 246 196 /** 247 * create usb_hub_ dev_t structure197 * create usb_hub_info_t structure 248 198 * 249 199 * Does only basic copying of known information into new structure. 250 200 * @param usb_dev usb device structure 251 * @return basic usb_hub_ dev_t structure252 */ 253 static usb_hub_ dev_t * usb_hub_dev_create(usb_device_t *usb_dev)201 * @return basic usb_hub_info_t structure 202 */ 203 static usb_hub_info_t * usb_hub_info_create(usb_device_t *usb_dev) 254 204 { 255 205 assert(usb_dev); 256 usb_hub_ dev_t *hub_dev = malloc(sizeof(usb_hub_dev_t));257 if (! hub_dev)206 usb_hub_info_t *info = malloc(sizeof(usb_hub_info_t)); 207 if (!info) 258 208 return NULL; 259 209 260 hub_dev->usb_device = usb_dev; 261 262 hub_dev->ports = NULL; 263 hub_dev->port_count = 0; 264 hub_dev->pending_ops_count = 0; 265 hub_dev->running = false; 266 fibril_mutex_initialize(&hub_dev->pending_ops_mutex); 267 fibril_condvar_initialize(&hub_dev->pending_ops_cv); 268 usb_dev->driver_data = hub_dev; 269 270 return hub_dev; 271 } 272 /*----------------------------------------------------------------------------*/ 273 /** 274 * Load hub-specific information into hub_dev structure and process if needed 210 info->usb_device = usb_dev; 211 212 info->ports = NULL; 213 info->port_count = -1; 214 fibril_mutex_initialize(&info->pending_ops_mutex); 215 fibril_condvar_initialize(&info->pending_ops_cv); 216 info->pending_ops_count = 0; 217 218 return info; 219 } 220 /*----------------------------------------------------------------------------*/ 221 /** 222 * Load hub-specific information into hub_info structure and process if needed 275 223 * 276 224 * Read port count and initialize structures holding per port information. … … 278 226 * This function is hub-specific and should be run only after the hub is 279 227 * configured using usb_set_first_configuration function. 280 * @param hub_ devhub representation228 * @param hub_info hub representation 281 229 * @return error code 282 230 */ 283 static int usb_hub_process_hub_specific_info(usb_hub_ dev_t *hub_dev)284 { 285 assert(hub_ dev);231 static int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info) 232 { 233 assert(hub_info); 286 234 287 235 /* Get hub descriptor. */ 288 236 usb_log_debug("Retrieving descriptor\n"); 289 usb_pipe_t *control_pipe = &hub_ dev->usb_device->ctrl_pipe;237 usb_pipe_t *control_pipe = &hub_info->usb_device->ctrl_pipe; 290 238 291 239 usb_hub_descriptor_header_t descriptor; … … 294 242 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE, 295 243 USB_DESCTYPE_HUB, 0, 0, &descriptor, 296 sizeof(usb_hub_descriptor_ header_t), &received_size);244 sizeof(usb_hub_descriptor_t), &received_size); 297 245 if (opResult != EOK) { 298 246 usb_log_error("Failed to receive hub descriptor: %s.\n", … … 302 250 303 251 usb_log_debug("Setting port count to %d.\n", descriptor.port_count); 304 hub_dev->port_count = descriptor.port_count; 305 306 hub_dev->ports = calloc(hub_dev->port_count, sizeof(usb_hub_port_t)); 307 if (!hub_dev->ports) { 252 hub_info->port_count = descriptor.port_count; 253 254 // TODO: +1 hack is no longer necessary 255 hub_info->ports = 256 malloc(sizeof(usb_hub_port_t) * (hub_info->port_count + 1)); 257 if (!hub_info->ports) { 308 258 return ENOMEM; 309 259 } 310 260 311 for (size_t port = 0; port < hub_dev->port_count; ++port) {312 usb_hub_port_init(313 &hub_dev->ports[port], port + 1, control_pipe);261 size_t port; 262 for (port = 0; port < hub_info->port_count + 1; ++port) { 263 usb_hub_port_init(&hub_info->ports[port], port, control_pipe); 314 264 } 315 265 … … 321 271 & HUB_CHAR_POWER_PER_PORT_FLAG; 322 272 323 for ( size_t port = 0; port < hub_dev->port_count; ++port) {273 for (port = 1; port <= hub_info->port_count; ++port) { 324 274 usb_log_debug("Powering port %zu.\n", port); 325 275 opResult = usb_hub_port_set_feature( 326 &hub_ dev->ports[port], USB_HUB_FEATURE_PORT_POWER);276 &hub_info->ports[port], USB_HUB_FEATURE_PORT_POWER); 327 277 if (opResult != EOK) { 328 278 usb_log_error("Cannot power on port %zu: %s.\n", … … 364 314 } 365 315 366 if (usb_device->descriptors.configuration_size 367 < sizeof(usb_standard_configuration_descriptor_t)) { 368 usb_log_error("Configuration descriptor is not big enough" 369 " to fit standard configuration descriptor.\n"); 370 return EOVERFLOW; 371 } 372 373 // TODO: Make sure that the cast is correct 316 // TODO: Make sure that there is enough data and the cast is correct 374 317 usb_standard_configuration_descriptor_t *config_descriptor 375 318 = (usb_standard_configuration_descriptor_t *) … … 394 337 * 395 338 * This means either to power off the hub or power it on. 396 * @param hub_ devhub instance339 * @param hub_info hub instance 397 340 * @param status hub status bitmask 398 341 * @return error code 399 342 */ 400 static void usb_hub_over_current(const usb_hub_ dev_t *hub_dev,343 static void usb_hub_over_current(const usb_hub_info_t *hub_info, 401 344 usb_hub_status_t status) 402 345 { … … 408 351 /* Over-current condition is gone, it is safe to turn the 409 352 * ports on. */ 410 for (size_t port = 0; port < hub_dev->port_count; ++port) { 353 size_t port; 354 for (port = 1; port <= hub_info->port_count; ++port) { 411 355 const int opResult = usb_hub_port_set_feature( 412 &hub_dev->ports[port], USB_HUB_FEATURE_PORT_POWER); 413 // TODO: consider power policy here 356 &hub_info->ports[port], USB_HUB_FEATURE_PORT_POWER); 414 357 if (opResult != EOK) { 415 358 usb_log_warning( … … 421 364 } 422 365 const int opResult = usb_request_clear_feature( 423 &hub_ dev->usb_device->ctrl_pipe, USB_REQUEST_TYPE_CLASS,366 &hub_info->usb_device->ctrl_pipe, USB_REQUEST_TYPE_CLASS, 424 367 USB_REQUEST_RECIPIENT_DEVICE, 425 368 USB_HUB_FEATURE_C_HUB_LOCAL_POWER, 0); … … 435 378 * 436 379 * The change can be either in the over-current condition or local-power change. 437 * @param hub_ devhub instance438 */ 439 static void usb_hub_global_interrupt(const usb_hub_ dev_t *hub_dev)440 { 441 assert(hub_ dev);442 assert(hub_ dev->usb_device);380 * @param hub_info hub instance 381 */ 382 static void usb_hub_global_interrupt(const usb_hub_info_t *hub_info) 383 { 384 assert(hub_info); 385 assert(hub_info->usb_device); 443 386 usb_log_debug("Global interrupt on a hub\n"); 444 usb_pipe_t *control_pipe = &hub_ dev->usb_device->ctrl_pipe;387 usb_pipe_t *control_pipe = &hub_info->usb_device->ctrl_pipe; 445 388 446 389 usb_hub_status_t status; … … 463 406 /* Handle status changes */ 464 407 if (status & USB_HUB_STATUS_C_OVER_CURRENT) { 465 usb_hub_over_current(hub_ dev, status);408 usb_hub_over_current(hub_info, status); 466 409 } 467 410 … … 495 438 * callback called from hub polling fibril when the fibril terminates 496 439 * 497 * Does not perform cleanup, just marks the hub as not running.440 * Should perform a cleanup - deletes hub_info. 498 441 * @param device usb device afected 499 442 * @param was_error indicates that the fibril is stoped due to an error 500 * @param data pointer to usb_hub_ dev_t structure443 * @param data pointer to usb_hub_info_t structure 501 444 */ 502 445 static void usb_hub_polling_terminated_callback(usb_device_t *device, 503 446 bool was_error, void *data) 504 447 { 505 usb_hub_ dev_t *hub = data;448 usb_hub_info_t *hub = data; 506 449 assert(hub); 507 450 … … 517 460 */ 518 461 if (hub->pending_ops_count > 0) { 519 for (size_t port = 0; port < hub->port_count; ++port) { 462 size_t port; 463 for (port = 0; port < hub->port_count; port++) { 520 464 usb_hub_port_reset_fail(&hub->ports[port]); 521 465 } … … 527 471 } 528 472 fibril_mutex_unlock(&hub->pending_ops_mutex); 529 hub->running = false; 473 474 usb_device_destroy(hub->usb_device); 475 476 free(hub->ports); 477 free(hub); 530 478 } 531 479 /** -
uspace/drv/bus/usb/usbhub/usbhub.h
r2ac7af3 r6d4d883 52 52 53 53 /** Information about attached hub. */ 54 struct usb_hub_ dev{54 struct usb_hub_info_t { 55 55 /** Number of ports. */ 56 56 size_t port_count; 57 /** Port structures, one for each port */ 57 58 /** Attached device handles, for each port one */ 58 59 usb_hub_port_t *ports; 60 59 61 /** Connection to hcd */ 60 62 usb_hc_connection_t connection; 63 61 64 /** Generic usb device data*/ 62 65 usb_device_t *usb_device; … … 73 76 /** Condition variable for pending_ops_count. */ 74 77 fibril_condvar_t pending_ops_cv; 75 /** Pointer to devman usbhub function. */76 ddf_fun_t *hub_fun;77 /** Status indicator */78 bool running;79 78 }; 80 79 81 int usb_hub_device_add(usb_device_t *usb_dev); 82 int usb_hub_device_gone(usb_device_t *usb_dev); 80 int usb_hub_add_device(usb_device_t *usb_dev); 83 81 84 82 bool hub_port_changes_callback(usb_device_t *dev, -
uspace/drv/bus/usb/usbmast/main.c
r2ac7af3 r6d4d883 87 87 * @return Error code. 88 88 */ 89 static int usbmast_ device_add(usb_device_t *dev)89 static int usbmast_add_device(usb_device_t *dev) 90 90 { 91 91 int rc; … … 94 94 95 95 /* Allocate softstate */ 96 dev->driver_data = mdev = malloc(sizeof(usbmast_dev_t));96 mdev = ddf_dev_data_alloc(dev->ddf_dev, sizeof(usbmast_dev_t)); 97 97 if (mdev == NULL) { 98 98 usb_log_error("Failed allocating softstate.\n"); … … 103 103 mdev->usb_dev = dev; 104 104 105 usb_log_info("Initializing mass storage `%s'.\n", dev->ddf_dev->name); 105 usb_log_info("Initializing mass storage `%s'.\n", 106 dev->ddf_dev->name); 106 107 usb_log_debug(" Bulk in endpoint: %d [%zuB].\n", 107 108 dev->pipes[BULK_IN_EP].pipe->endpoint_no, … … 294 295 /** USB mass storage driver ops. */ 295 296 static usb_driver_ops_t usbmast_driver_ops = { 296 . device_add = usbmast_device_add,297 .add_device = usbmast_add_device, 297 298 }; 298 299 -
uspace/drv/bus/usb/usbmid/main.c
r2ac7af3 r6d4d883 49 49 * @return Error code. 50 50 */ 51 static int usbmid_ device_add(usb_device_t *dev)51 static int usbmid_add_device(usb_device_t *dev) 52 52 { 53 53 usb_log_info("Taking care of new MID `%s'.\n", dev->ddf_dev->name); … … 68 68 /** USB MID driver ops. */ 69 69 static usb_driver_ops_t mid_driver_ops = { 70 . device_add = usbmid_device_add,70 .add_device = usbmid_add_device, 71 71 }; 72 72 -
uspace/drv/bus/usb/usbmouse/main.c
r2ac7af3 r6d4d883 50 50 * 51 51 */ 52 static int usbmouse_ device_add(usb_device_t *dev)52 static int usbmouse_add_device(usb_device_t *dev) 53 53 { 54 54 int rc = usb_mouse_create(dev); … … 80 80 /** USB mouse driver ops. */ 81 81 static usb_driver_ops_t mouse_driver_ops = { 82 . device_add = usbmouse_device_add,82 .add_device = usbmouse_add_device, 83 83 }; 84 84 -
uspace/drv/bus/usb/vhc/hub.c
r2ac7af3 r6d4d883 81 81 } 82 82 83 static int pretend_port_rest( void *unused2)83 static int pretend_port_rest(int unused, void *unused2) 84 84 { 85 85 return EOK; … … 114 114 115 115 ddf_fun_t *hub_dev; 116 rc = usb_hc_new_device_wrapper(hc_dev->dev, &hc_conn, USB_SPEED_FULL, 117 pretend_port_rest, NULL, NULL, &rh_ops, hc_dev, &hub_dev); 116 rc = usb_hc_new_device_wrapper(hc_dev->dev, &hc_conn, 117 USB_SPEED_FULL, 118 pretend_port_rest, 0, NULL, 119 NULL, NULL, &rh_ops, hc_dev, &hub_dev); 118 120 if (rc != EOK) { 119 121 usb_log_fatal("Failed to create root hub: %s.\n", -
uspace/lib/c/generic/async.c
r2ac7af3 r6d4d883 1846 1846 1847 1847 fibril_mutex_lock(&async_sess_mutex); 1848 1849 int rc = async_hangup_internal(sess->phone);1850 1848 1851 1849 while (!list_empty(&sess->exch_list)) { … … 1860 1858 } 1861 1859 1860 int rc = async_hangup_internal(sess->phone); 1862 1861 free(sess); 1863 1862 -
uspace/lib/ext2/libext2_filesystem.c
r2ac7af3 r6d4d883 259 259 bg_ref->block_group); 260 260 261 rc = ext2_filesystem_put_block_group_ref(bg_ref);262 if (rc != EOK) {263 free(newref);264 return rc;265 }266 267 261 inode_size = ext2_superblock_get_inode_size(fs->superblock); 268 262 block_size = ext2_superblock_get_block_size(fs->superblock); -
uspace/lib/usb/include/usb/hc.h
r2ac7af3 r6d4d883 53 53 54 54 int usb_hc_connection_initialize_from_device(usb_hc_connection_t *, 55 constddf_dev_t *);55 ddf_dev_t *); 56 56 int usb_hc_connection_initialize(usb_hc_connection_t *, devman_handle_t); 57 57 -
uspace/lib/usb/src/hc.c
r2ac7af3 r6d4d883 50 50 */ 51 51 int usb_hc_connection_initialize_from_device(usb_hc_connection_t *connection, 52 constddf_dev_t *device)52 ddf_dev_t *device) 53 53 { 54 54 assert(connection); -
uspace/lib/usbdev/include/usb/dev/driver.h
r2ac7af3 r6d4d883 96 96 usb_device_descriptors_t descriptors; 97 97 98 /** Generic DDF device backing this one. RO: DO NOT TOUCH!*/98 /** Generic DDF device backing this one. */ 99 99 ddf_dev_t *ddf_dev; 100 100 /** Custom driver data. … … 112 112 /** USB driver ops. */ 113 113 typedef struct { 114 /** Callback when a new device was added to the system. */ 115 int (*device_add)(usb_device_t *); 116 /** Callback when a device is about to be removed from the system. */ 117 int (*device_rem)(usb_device_t *); 118 /** Callback when a device was removed from the system. */ 119 int (*device_gone)(usb_device_t *); 114 /** Callback when new device is about to be controlled by the driver. */ 115 int (*add_device)(usb_device_t *); 120 116 } usb_driver_ops_t; 121 117 … … 167 163 168 164 int usb_device_retrieve_descriptors(usb_pipe_t *, usb_device_descriptors_t *); 169 int usb_device_create_pipes( constddf_dev_t *, usb_device_connection_t *,165 int usb_device_create_pipes(ddf_dev_t *, usb_device_connection_t *, 170 166 usb_endpoint_description_t **, uint8_t *, size_t, int, int, 171 167 usb_endpoint_mapping_t **, size_t *); 172 int usb_device_destroy_pipes( constddf_dev_t *, usb_endpoint_mapping_t *, size_t);168 int usb_device_destroy_pipes(ddf_dev_t *, usb_endpoint_mapping_t *, size_t); 173 169 int usb_device_create(ddf_dev_t *, usb_endpoint_description_t **, usb_device_t **, const char **); 174 170 void usb_device_destroy(usb_device_t *); -
uspace/lib/usbdev/include/usb/dev/hub.h
r2ac7af3 r6d4d883 38 38 #define LIBUSBDEV_HUB_H_ 39 39 40 #include <ddf/driver.h>41 40 #include <sys/types.h> 42 41 #include <usb/hc.h> 43 42 44 43 int usb_hc_new_device_wrapper(ddf_dev_t *, usb_hc_connection_t *, usb_speed_t, 45 int (*)(void *), void *, usb_address_t *, ddf_dev_ops_t *, void *, 46 ddf_fun_t **); 44 int (*)(int, void *), int, void *, 45 usb_address_t *, devman_handle_t *, 46 ddf_dev_ops_t *, void *, ddf_fun_t **); 47 47 48 48 /** Info about device attached to host controller. … … 55 55 /** Device address. */ 56 56 usb_address_t address; 57 /** D DF function (external)of the device. */58 d df_fun_t *fun;59 } usb_h ub_attached_device_t;57 /** Devman handle of the device. */ 58 devman_handle_t handle; 59 } usb_hc_attached_device_t; 60 60 61 61 usb_address_t usb_hc_request_address(usb_hc_connection_t *, usb_speed_t); 62 62 int usb_hc_register_device(usb_hc_connection_t *, 63 const usb_h ub_attached_device_t *);63 const usb_hc_attached_device_t *); 64 64 int usb_hc_unregister_device(usb_hc_connection_t *, usb_address_t); 65 65 -
uspace/lib/usbdev/include/usb/dev/pipes.h
r2ac7af3 r6d4d883 159 159 usb_device_connection_t *, usb_hc_connection_t *); 160 160 int usb_device_connection_initialize_from_device(usb_device_connection_t *, 161 constddf_dev_t *);161 ddf_dev_t *); 162 162 int usb_device_connection_initialize(usb_device_connection_t *, 163 163 devman_handle_t, usb_address_t); 164 164 165 int usb_device_get_assigned_interface( constddf_dev_t *);165 int usb_device_get_assigned_interface(ddf_dev_t *); 166 166 167 167 int usb_pipe_initialize(usb_pipe_t *, usb_device_connection_t *, … … 185 185 int usb_pipe_control_read(usb_pipe_t *, const void *, size_t, 186 186 void *, size_t, size_t *); 187 int usb_pipe_control_write(usb_pipe_t *, constvoid *, size_t,188 constvoid *, size_t);187 int usb_pipe_control_write(usb_pipe_t *, void *, size_t, 188 void *, size_t); 189 189 190 190 #endif -
uspace/lib/usbdev/include/usb/dev/recognise.h
r2ac7af3 r6d4d883 51 51 52 52 int usb_device_register_child_in_devman(usb_address_t, devman_handle_t, 53 ddf_dev_t *, d df_dev_ops_t *, void *, ddf_fun_t **);53 ddf_dev_t *, devman_handle_t *, ddf_dev_ops_t *, void *, ddf_fun_t **); 54 54 55 55 #endif -
uspace/lib/usbdev/src/devdrv.c
r2ac7af3 r6d4d883 41 41 #include <assert.h> 42 42 43 static int generic_device_add(ddf_dev_t *); 44 static int generic_device_remove(ddf_dev_t *); 45 static int generic_device_gone(ddf_dev_t *); 43 static int generic_add_device(ddf_dev_t *); 46 44 47 45 static driver_ops_t generic_driver_ops = { 48 .add_device = generic_device_add, 49 .dev_remove = generic_device_remove, 50 .dev_gone = generic_device_gone, 46 .add_device = generic_add_device 51 47 }; 52 48 static driver_t generic_driver = { … … 127 123 return EOK; 128 124 } 129 /*----------------------------------------------------------------------------*/ 130 /** Callback when anew device is supposed to be controlled by this driver.131 * 132 * This callback is a wrapper for USB specific version of @c device_add.125 126 /** Callback when new device is supposed to be controlled by this driver. 127 * 128 * This callback is a wrapper for USB specific version of @c add_device. 133 129 * 134 130 * @param gen_dev Device structure as prepared by DDF. 135 131 * @return Error code. 136 132 */ 137 int generic_ device_add(ddf_dev_t *gen_dev)133 int generic_add_device(ddf_dev_t *gen_dev) 138 134 { 139 135 assert(driver); 140 136 assert(driver->ops); 141 assert(driver->ops-> device_add);137 assert(driver->ops->add_device); 142 138 143 139 int rc; … … 151 147 return rc; 152 148 } 153 gen_dev->driver_data = dev; 154 155 return driver->ops->device_add(dev); 156 } 157 /*----------------------------------------------------------------------------*/ 158 /** Callback when a device is supposed to be removed from the system. 159 * 160 * This callback is a wrapper for USB specific version of @c device_remove. 161 * 162 * @param gen_dev Device structure as prepared by DDF. 163 * @return Error code. 164 */ 165 int generic_device_remove(ddf_dev_t *gen_dev) 166 { 167 assert(driver); 168 assert(driver->ops); 169 if (driver->ops->device_rem == NULL) 170 return ENOTSUP; 171 /* Just tell the driver to stop whatever it is doing, keep structures */ 172 return driver->ops->device_rem(gen_dev->driver_data); 173 } 174 /*----------------------------------------------------------------------------*/ 175 /** Callback when a device was removed from the system. 176 * 177 * This callback is a wrapper for USB specific version of @c device_gone. 178 * 179 * @param gen_dev Device structure as prepared by DDF. 180 * @return Error code. 181 */ 182 int generic_device_gone(ddf_dev_t *gen_dev) 183 { 184 assert(driver); 185 assert(driver->ops); 186 if (driver->ops->device_gone == NULL) 187 return ENOTSUP; 188 const int ret = driver->ops->device_gone(gen_dev->driver_data); 189 if (ret == EOK) 190 usb_device_destroy(gen_dev->driver_data); 191 192 return ret; 193 } 194 /*----------------------------------------------------------------------------*/ 149 150 return driver->ops->add_device(dev); 151 } 152 195 153 /** Destroy existing pipes of a USB device. 196 154 * … … 317 275 * @return Error code. 318 276 */ 319 int usb_device_create_pipes( constddf_dev_t *dev, usb_device_connection_t *wire,277 int usb_device_create_pipes(ddf_dev_t *dev, usb_device_connection_t *wire, 320 278 usb_endpoint_description_t **endpoints, 321 279 uint8_t *config_descr, size_t config_descr_size, … … 391 349 } 392 350 393 if (usb_hc_connection_close(&hc_conn) != EOK) 394 usb_log_warning("usb_device_create_pipes(): " 395 "Failed to close connection.\n"); 351 usb_hc_connection_close(&hc_conn); 396 352 397 353 *pipes_ptr = pipes; … … 415 371 } 416 372 417 if (usb_hc_connection_close(&hc_conn) != EOK) 418 usb_log_warning("usb_device_create_pipes(): " 419 "Failed to close connection.\n"); 373 usb_hc_connection_close(&hc_conn); 420 374 421 375 /* … … 441 395 * @param[in] pipes_count Number of endpoints. 442 396 */ 443 int usb_device_destroy_pipes( constddf_dev_t *dev,397 int usb_device_destroy_pipes(ddf_dev_t *dev, 444 398 usb_endpoint_mapping_t *pipes, size_t pipes_count) 445 399 { … … 472 426 } 473 427 474 if (usb_hc_connection_close(&hc_conn) != EOK) 475 usb_log_warning("usb_device_destroy_pipes(): " 476 "Failed to close connection.\n"); 428 usb_hc_connection_close(&hc_conn); 477 429 478 430 free(pipes); … … 593 545 /* Ignore errors and hope for the best. */ 594 546 usb_device_destroy_pipes(dev->ddf_dev, dev->pipes, dev->pipes_count); 595 free(dev->descriptors.configuration); 547 if (dev->descriptors.configuration != NULL) { 548 free(dev->descriptors.configuration); 549 } 596 550 597 551 if (dev->alternate_interfaces != NULL) { 598 free(dev->alternate_interfaces->alternatives); 599 } 600 free(dev->alternate_interfaces); 552 if (dev->alternate_interfaces->alternatives != NULL) { 553 free(dev->alternate_interfaces->alternatives); 554 } 555 free(dev->alternate_interfaces); 556 } 601 557 602 558 free(dev); -
uspace/lib/usbdev/src/hub.c
r2ac7af3 r6d4d883 37 37 #include <usb/dev/request.h> 38 38 #include <usb/dev/recognise.h> 39 #include <usb/debug.h>40 39 #include <usbhc_iface.h> 41 40 #include <errno.h> … … 58 57 assert((conn)); \ 59 58 if (!usb_hc_connection_is_opened((conn))) { \ 60 usb_log_error("Connection not open.\n"); \ 61 return ENOTCONN; \ 59 return ENOENT; \ 62 60 } \ 63 61 } while (false) … … 97 95 */ 98 96 int usb_hc_register_device(usb_hc_connection_t * connection, 99 const usb_h ub_attached_device_t *attached_device)97 const usb_hc_attached_device_t *attached_device) 100 98 { 101 99 CHECK_CONNECTION(connection); … … 107 105 int rc = async_req_3_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 108 106 IPC_M_USBHC_BIND_ADDRESS, 109 attached_device->address, attached_device-> fun->handle);107 attached_device->address, attached_device->handle); 110 108 async_exchange_end(exch); 111 109 … … 157 155 * The @p enable_port function is expected to enable signaling on given 158 156 * port. 159 * The argument can have arbitrary meaning and it is not touched at all 160 * by this function (it is passed as is to the @p enable_port function). 157 * The two arguments to it can have arbitrary meaning 158 * (the @p port_no is only a suggestion) 159 * and are not touched at all by this function 160 * (they are passed as is to the @p enable_port function). 161 161 * 162 162 * If the @p enable_port fails (i.e. does not return EOK), the device … … 175 175 * @param[in] enable_port Function for enabling signaling through the port the 176 176 * device is attached to. 177 * @param[in] port_no Port number (passed through to @p enable_port). 177 178 * @param[in] arg Any data argument to @p enable_port. 178 179 * @param[out] assigned_address USB address of the device. 180 * @param[out] assigned_handle Devman handle of the new device. 179 181 * @param[in] dev_ops Child device ops. 180 182 * @param[in] new_dev_data Arbitrary pointer to be stored in the child … … 192 194 int usb_hc_new_device_wrapper(ddf_dev_t *parent, usb_hc_connection_t *connection, 193 195 usb_speed_t dev_speed, 194 int (*enable_port)(void *arg), void *arg, usb_address_t *assigned_address, 196 int (*enable_port)(int port_no, void *arg), int port_no, void *arg, 197 usb_address_t *assigned_address, devman_handle_t *assigned_handle, 195 198 ddf_dev_ops_t *dev_ops, void *new_dev_data, ddf_fun_t **new_fun) 196 199 { … … 221 224 usb_address_t dev_addr = usb_hc_request_address(&hc_conn, dev_speed); 222 225 if (dev_addr < 0) { 223 rc = EADDRNOTAVAIL;224 goto close_connection;226 usb_hc_connection_close(&hc_conn); 227 return EADDRNOTAVAIL; 225 228 } 226 229 … … 276 279 * device address. 277 280 */ 278 rc = enable_port( arg);281 rc = enable_port(port_no, arg); 279 282 if (rc != EOK) { 280 283 goto leave_release_default_address; … … 317 320 */ 318 321 /* FIXME: create device_register that will get opened ctrl pipe. */ 319 d df_fun_t *child_fun;322 devman_handle_t child_handle; 320 323 rc = usb_device_register_child_in_devman(dev_addr, dev_conn.hc_handle, 321 parent, dev_ops, new_dev_data, &child_fun); 324 parent, &child_handle, 325 dev_ops, new_dev_data, new_fun); 322 326 if (rc != EOK) { 323 327 rc = ESTALL; … … 328 332 * And now inform the host controller about the handle. 329 333 */ 330 usb_h ub_attached_device_t new_device = {334 usb_hc_attached_device_t new_device = { 331 335 .address = dev_addr, 332 . fun = child_fun,336 .handle = child_handle 333 337 }; 334 338 rc = usb_hc_register_device(&hc_conn, &new_device); … … 337 341 goto leave_release_free_address; 338 342 } 339 343 344 usb_hc_connection_close(&hc_conn); 340 345 341 346 /* … … 345 350 *assigned_address = dev_addr; 346 351 } 347 if (new_fun != NULL) { 348 *new_fun = child_fun; 349 } 350 351 rc = EOK; 352 goto close_connection; 352 if (assigned_handle != NULL) { 353 *assigned_handle = child_handle; 354 } 355 356 return EOK; 357 358 353 359 354 360 /* … … 362 368 usb_hc_unregister_device(&hc_conn, dev_addr); 363 369 364 close_connection: 365 if (usb_hc_connection_close(&hc_conn) != EOK) 366 usb_log_warning("usb_hc_new_device_wrapper(): Failed to close " 367 "connection.\n"); 370 usb_hc_connection_close(&hc_conn); 368 371 369 372 return rc; -
uspace/lib/usbdev/src/pipes.c
r2ac7af3 r6d4d883 52 52 * @return USB address or error code. 53 53 */ 54 static usb_address_t get_my_address(async_sess_t *sess, constddf_dev_t *dev)54 static usb_address_t get_my_address(async_sess_t *sess, ddf_dev_t *dev) 55 55 { 56 56 async_exch_t *exch = async_exchange_begin(sess); … … 78 78 * @return Interface number (negative code means any). 79 79 */ 80 int usb_device_get_assigned_interface( constddf_dev_t *device)80 int usb_device_get_assigned_interface(ddf_dev_t *device) 81 81 { 82 82 async_sess_t *parent_sess = … … 108 108 */ 109 109 int usb_device_connection_initialize_from_device( 110 usb_device_connection_t *connection, constddf_dev_t *dev)110 usb_device_connection_t *connection, ddf_dev_t *dev) 111 111 { 112 112 assert(connection); -
uspace/lib/usbdev/src/pipesio.c
r2ac7af3 r6d4d883 469 469 */ 470 470 static int usb_pipe_control_write_no_check(usb_pipe_t *pipe, 471 constvoid *setup_buffer, size_t setup_buffer_size,472 constvoid *data_buffer, size_t data_buffer_size)471 void *setup_buffer, size_t setup_buffer_size, 472 void *data_buffer, size_t data_buffer_size) 473 473 { 474 474 /* Ensure serialization over the phone. */ … … 536 536 */ 537 537 int usb_pipe_control_write(usb_pipe_t *pipe, 538 constvoid *setup_buffer, size_t setup_buffer_size,539 constvoid *data_buffer, size_t data_buffer_size)538 void *setup_buffer, size_t setup_buffer_size, 539 void *data_buffer, size_t data_buffer_size) 540 540 { 541 541 assert(pipe); -
uspace/lib/usbdev/src/recognise.c
r2ac7af3 r6d4d883 339 339 * @param[in] hc_handle Handle of the host controller. 340 340 * @param[in] parent Parent device. 341 * @param[out] child_handle Handle of the child device. 341 342 * @param[in] dev_ops Child device ops. 342 343 * @param[in] dev_data Arbitrary pointer to be stored in the child … … 347 348 */ 348 349 int usb_device_register_child_in_devman(usb_address_t address, 349 devman_handle_t hc_handle, ddf_dev_t *parent, 350 devman_handle_t hc_handle, 351 ddf_dev_t *parent, devman_handle_t *child_handle, 350 352 ddf_dev_ops_t *dev_ops, void *dev_data, ddf_fun_t **child_fun) 351 353 { … … 412 414 } 413 415 416 if (child_handle != NULL) { 417 *child_handle = child->handle; 418 } 419 414 420 if (child_fun != NULL) { 415 421 *child_fun = child;
Note:
See TracChangeset
for help on using the changeset viewer.