Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/usb/usb_util.c
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
#include <dev/usb/usb_util.h> | #include <dev/usb/usb_util.h> | ||||
#include <dev/usb/usb_process.h> | #include <dev/usb/usb_process.h> | ||||
#include <dev/usb/usb_device.h> | #include <dev/usb/usb_device.h> | ||||
#include <dev/usb/usb_request.h> | #include <dev/usb/usb_request.h> | ||||
#include <dev/usb/usb_busdma.h> | #include <dev/usb/usb_busdma.h> | ||||
#include <dev/usb/usb_controller.h> | #include <dev/usb/usb_controller.h> | ||||
#include <dev/usb/usb_bus.h> | #include <dev/usb/usb_bus.h> | ||||
#include <dev/usb/usb_hub.h> | |||||
#endif /* USB_GLOBAL_INCLUDE_FILE */ | #endif /* USB_GLOBAL_INCLUDE_FILE */ | ||||
/*------------------------------------------------------------------------* | /*------------------------------------------------------------------------* | ||||
* device_set_usb_desc | * device_set_usb_desc | ||||
* | * | ||||
* This function can be called at probe or attach to set the USB | * This function can be called at probe or attach to set the USB | ||||
* device supplied textual description for the given device. | * device supplied textual description for the given device. | ||||
*------------------------------------------------------------------------*/ | *------------------------------------------------------------------------*/ | ||||
▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | usb_make_str_desc(void *ptr, uint16_t max_len, const char *s) | ||||
p->bLength = totlen; | p->bLength = totlen; | ||||
p->bDescriptorType = UDESC_STRING; | p->bDescriptorType = UDESC_STRING; | ||||
while (max_len--) { | while (max_len--) { | ||||
USETW2(p->bString[max_len], 0, s[max_len]); | USETW2(p->bString[max_len], 0, s[max_len]); | ||||
} | } | ||||
return (totlen); | return (totlen); | ||||
} | |||||
/*------------------------------------------------------------------------* | |||||
* Compute uniq location value for the given USB device | |||||
* | |||||
* This function returns a uniq integer value for the given USB | |||||
* device, based on the location of the USB device. This function | |||||
* returns -1 if the location doesn't fit into an integer. | |||||
*------------------------------------------------------------------------*/ | |||||
int | |||||
usb_compute_uniq_location(const struct usb_device *udev) | |||||
{ | |||||
int64_t retval; | |||||
retval = device_get_unit(udev->bus->bdev); | |||||
for (; udev != NULL; udev = udev->parent_hub) { | |||||
if (udev->hub == NULL) | |||||
continue; | |||||
retval *= udev->hub->nports; | |||||
retval += udev->port_no - 1; | |||||
/* check for overflow */ | |||||
if ((int)retval != retval) | |||||
return (-1); | |||||
} | |||||
return (retval); | |||||
} | } |