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