Changes in uspace/lib/usb/src/hcdhubd.c [71ed4849:4317827] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/hcdhubd.c
r71ed4849 r4317827 36 36 #include <usb/devreq.h> 37 37 #include <usbhc_iface.h> 38 #include <usb_iface.h>39 38 #include <usb/descriptor.h> 40 39 #include <driver.h> … … 46 45 #include "hcdhubd_private.h" 47 46 48 49 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)50 {51 assert(dev);52 assert(dev->parent != NULL);53 54 device_t *parent = dev->parent;55 56 if (parent->ops && parent->ops->interfaces[USB_DEV_IFACE]) {57 usb_iface_t *usb_iface58 = (usb_iface_t *) parent->ops->interfaces[USB_DEV_IFACE];59 assert(usb_iface != NULL);60 if (usb_iface->get_hc_handle) {61 int rc = usb_iface->get_hc_handle(parent, handle);62 return rc;63 }64 }65 66 return ENOTSUP;67 }68 69 static usb_iface_t usb_iface = {70 .get_hc_handle = usb_iface_get_hc_handle71 };72 73 static device_ops_t child_ops = {74 .interfaces[USB_DEV_IFACE] = &usb_iface75 };76 77 47 /** Callback when new device is detected and must be handled by this driver. 78 48 * … … 144 114 145 115 /** Adds a child device fibril worker. */ 146 static int fibril_add_child_device(void *arg) { 116 static int fibril_add_child_device(void *arg) 117 { 147 118 struct child_device_info *child_info 148 119 = (struct child_device_info *) arg; 149 120 int rc; 150 121 … … 159 130 } 160 131 child->name = child_info->name; 161 child->parent = child_info->parent;162 child->ops = &child_ops;163 132 164 133 match_id = create_match_id(); … … 172 141 173 142 printf("%s: adding child device `%s' with match \"%s\"\n", 174 143 hc_driver->name, child->name, match_id->id); 175 144 rc = child_device_register(child, child_info->parent); 176 145 printf("%s: child device `%s' registration: %s\n", 177 146 hc_driver->name, child->name, str_error(rc)); 178 147 179 148 if (rc != EOK) { … … 213 182 */ 214 183 int usb_hc_add_child_device(device_t *parent, const char *name, 215 const char *match_id, bool create_fibril) { 184 const char *match_id, bool create_fibril) 185 { 216 186 printf("%s: about to add child device `%s' (%s)\n", hc_driver->name, 217 187 name, match_id); 218 188 219 189 /* … … 224 194 225 195 struct child_device_info *child_info 226 = malloc(sizeof(struct child_device_info));196 = malloc(sizeof(struct child_device_info)); 227 197 228 198 child_info->parent = parent; … … 248 218 * @return USB device address or error code. 249 219 */ 250 usb_address_t usb_get_address_by_handle(devman_handle_t handle) { 220 usb_address_t usb_get_address_by_handle(devman_handle_t handle) 221 { 251 222 /* TODO: search list of attached devices. */ 252 223 return ENOENT; 253 224 } 254 225 255 usb_address_t usb_use_free_address(usb_hc_device_t * this_hcd) {256 //is there free address?257 link_t * addresses = &this_hcd->addresses;258 if (list_empty(addresses)) return -1;259 link_t * link_addr = addresses;260 bool found = false;261 usb_address_list_t * range = NULL;262 while (!found) {263 link_addr = link_addr->next;264 if (link_addr == addresses) return -2;265 range = list_get_instance(link_addr,266 usb_address_list_t, link);267 if (range->upper_bound - range->lower_bound > 0) {268 found = true;269 }270 }271 //now we have interval272 int result = range->lower_bound;273 ++(range->lower_bound);274 if (range->upper_bound - range->lower_bound == 0) {275 list_remove(&range->link);276 free(range);277 }278 return result;279 }280 281 void usb_free_used_address(usb_hc_device_t * this_hcd, usb_address_t addr) {282 //check range283 if (addr < usb_lowest_address || addr > usb_highest_address)284 return;285 link_t * addresses = &this_hcd->addresses;286 link_t * link_addr = addresses;287 //find 'good' interval288 usb_address_list_t * found_range = NULL;289 bool found = false;290 while (!found) {291 link_addr = link_addr->next;292 if (link_addr == addresses) {293 found = true;294 } else {295 usb_address_list_t * range = list_get_instance(link_addr,296 usb_address_list_t, link);297 if ( (range->lower_bound - 1 == addr) ||298 (range->upper_bound == addr)) {299 found = true;300 found_range = range;301 }302 if (range->lower_bound - 1 > addr) {303 found = true;304 }305 306 }307 }308 if (found_range == NULL) {309 //no suitable range found310 usb_address_list_t * result_range =311 (usb_address_list_t*) malloc(sizeof (usb_address_list_t));312 result_range->lower_bound = addr;313 result_range->upper_bound = addr + 1;314 list_insert_before(&result_range->link, link_addr);315 } else {316 //we have good range317 if (found_range->lower_bound - 1 == addr) {318 --found_range->lower_bound;319 } else {320 //only one possible case321 ++found_range->upper_bound;322 if (found_range->link.next != addresses) {323 usb_address_list_t * next_range =324 list_get_instance( &found_range->link.next,325 usb_address_list_t, link);326 //check neighbour range327 if (next_range->lower_bound == addr + 1) {328 //join ranges329 found_range->upper_bound = next_range->upper_bound;330 list_remove(&next_range->link);331 free(next_range);332 }333 }334 }335 }336 337 }338 339 226 /** 340 227 * @}
Note:
See TracChangeset
for help on using the changeset viewer.