From owner-p4-projects@FreeBSD.ORG Sun Sep 6 06:56:07 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 7FA3E1065695; Sun, 6 Sep 2009 06:56:07 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0291A1065676 for ; Sun, 6 Sep 2009 06:56:07 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id E51078FC16 for ; Sun, 6 Sep 2009 06:56:06 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n866u6bd017282 for ; Sun, 6 Sep 2009 06:56:06 GMT (envelope-from hselasky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n866u6UK017280 for perforce@freebsd.org; Sun, 6 Sep 2009 06:56:06 GMT (envelope-from hselasky@FreeBSD.org) Date: Sun, 6 Sep 2009 06:56:06 GMT Message-Id: <200909060656.n866u6UK017280@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky To: Perforce Change Reviews Cc: Subject: PERFORCE change 168223 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Sep 2009 06:56:08 -0000 http://perforce.freebsd.org/chv.cgi?CH=168223 Change 168223 by hselasky@hselasky_laptop001 on 2009/09/06 06:55:32 USB core: - increase size of scratch area - add support for USB language selection - reported by: Bruce Cran PR: usb/138563 Affected files ... .. //depot/projects/usb/src/sys/dev/usb/usb_bus.h#15 edit .. //depot/projects/usb/src/sys/dev/usb/usb_device.c#53 edit Differences ... ==== //depot/projects/usb/src/sys/dev/usb/usb_bus.h#15 (text+ko) ==== @@ -98,10 +98,14 @@ uint8_t devices_max; /* maximum number of USB devices */ uint8_t do_probe; /* set if USB BUS should be re-probed */ + /* + * The scratch area can only be used inside the explore thread + * belonging to the give serial bus. + */ union { struct usb_hw_ep_scratch hw_ep_scratch[1]; struct usb_temp_setup temp_setup[1]; - uint8_t data[128]; + uint8_t data[255]; } scratch[1]; }; ==== //depot/projects/usb/src/sys/dev/usb/usb_device.c#53 (text+ko) ==== @@ -105,9 +105,23 @@ int usb_template = 0; +TUNABLE_INT("hw.usb.usb_template", &usb_template); SYSCTL_INT(_hw_usb, OID_AUTO, template, CTLFLAG_RW, &usb_template, 0, "Selected USB device side template"); +/* English is default language */ + +static int usb_lang_id = 0x0009; +static int usb_lang_mask = 0x00FF; + +TUNABLE_INT("hw.usb.usb_lang_id", &usb_lang_id); +SYSCTL_INT(_hw_usb, OID_AUTO, usb_lang_id, CTLFLAG_RW, + &usb_lang_id, 0, "Preferred USB language ID"); + +TUNABLE_INT("hw.usb.usb_lang_mask", &usb_lang_mask); +SYSCTL_INT(_hw_usb, OID_AUTO, usb_lang_mask, CTLFLAG_RW, + &usb_lang_mask, 0, "Preferred USB language mask"); + static const char* statestr[USB_STATE_MAX] = { [USB_STATE_DETACHED] = "DETACHED", [USB_STATE_ATTACHED] = "ATTACHED", @@ -1441,7 +1455,7 @@ struct usb_device *adev; struct usb_device *hub; uint8_t *scratch_ptr; - uint32_t scratch_size; + size_t scratch_size; usb_error_t err; uint8_t device_index; @@ -1687,8 +1701,35 @@ if (err || (scratch_ptr[0] < 4)) { udev->flags.no_strings = 1; } else { - /* pick the first language as the default */ - udev->langid = UGETW(scratch_ptr + 2); + uint16_t langid; + uint16_t pref; + uint16_t mask; + uint8_t x; + + /* load preferred value and mask */ + pref = usb_lang_id; + mask = usb_lang_mask; + + /* align length correctly */ + scratch_ptr[0] &= ~1; + + /* fix compiler warning */ + langid = 0; + + /* search for preferred language */ + for (x = 2; (x < scratch_ptr[0]); x += 2) { + langid = UGETW(scratch_ptr + x); + if ((langid & mask) == pref) + break; + } + if (x >= scratch_ptr[0]) { + /* pick the first language as the default */ + DPRINTFN(1, "Using first language\n"); + langid = UGETW(scratch_ptr + 2); + } + + DPRINTFN(1, "Language selected: 0x%04x\n", langid); + udev->langid = langid; } /* assume 100mA bus powered for now. Changed when configured. */ @@ -2153,34 +2194,35 @@ #ifdef USB_VERBOSE const struct usb_knowndev *kdp; #endif - char temp[64]; + uint8_t *temp_ptr; + size_t temp_size; uint16_t vendor_id; uint16_t product_id; + temp_ptr = udev->bus->scratch[0].data; + temp_size = sizeof(udev->bus->scratch[0].data); + vendor_id = UGETW(udd->idVendor); product_id = UGETW(udd->idProduct); /* get serial number string */ - bzero(temp, sizeof(temp)); - usbd_req_get_string_any(udev, NULL, temp, sizeof(temp), + usbd_req_get_string_any(udev, NULL, temp_ptr, temp_size, udev->ddesc.iSerialNumber); - udev->serial = strdup(temp, M_USB); + udev->serial = strdup(temp_ptr, M_USB); /* get manufacturer string */ - bzero(temp, sizeof(temp)); - usbd_req_get_string_any(udev, NULL, temp, sizeof(temp), + usbd_req_get_string_any(udev, NULL, temp_ptr, temp_size, udev->ddesc.iManufacturer); - usb_trim_spaces(temp); - if (temp[0] != '\0') - udev->manufacturer = strdup(temp, M_USB); + usb_trim_spaces(temp_ptr); + if (temp_ptr[0] != '\0') + udev->manufacturer = strdup(temp_ptr, M_USB); /* get product string */ - bzero(temp, sizeof(temp)); - usbd_req_get_string_any(udev, NULL, temp, sizeof(temp), + usbd_req_get_string_any(udev, NULL, temp_ptr, temp_size, udev->ddesc.iProduct); - usb_trim_spaces(temp); - if (temp[0] != '\0') - udev->product = strdup(temp, M_USB); + usb_trim_spaces(temp_ptr); + if (temp_ptr[0] != '\0') + udev->product = strdup(temp_ptr, M_USB); #ifdef USB_VERBOSE if (udev->manufacturer == NULL || udev->product == NULL) { @@ -2206,12 +2248,12 @@ #endif /* Provide default strings if none were found */ if (udev->manufacturer == NULL) { - snprintf(temp, sizeof(temp), "vendor 0x%04x", vendor_id); - udev->manufacturer = strdup(temp, M_USB); + snprintf(temp_ptr, temp_size, "vendor 0x%04x", vendor_id); + udev->manufacturer = strdup(temp_ptr, M_USB); } if (udev->product == NULL) { - snprintf(temp, sizeof(temp), "product 0x%04x", product_id); - udev->product = strdup(temp, M_USB); + snprintf(temp_ptr, temp_size, "product 0x%04x", product_id); + udev->product = strdup(temp_ptr, M_USB); } }