FreeBSD Bugzilla – Attachment 161251 Details for
Bug 203249
[patch] Patch to allow dynamic USB quirks at boot (USB 2 stack)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
usb_quirk
usb_quirk.diff (text/plain), 3.99 KB, created by
Maxime Soulé
on 2015-09-21 19:33:15 UTC
(
hide
)
Description:
usb_quirk
Filename:
MIME Type:
Creator:
Maxime Soulé
Created:
2015-09-21 19:33:15 UTC
Size:
3.99 KB
patch
obsolete
>--- dev/usb/quirk/usb_quirk.c.orig 2015-08-12 16:22:01.000000000 +0200 >+++ dev/usb/quirk/usb_quirk.c 2015-09-20 23:08:12.000000000 +0200 >@@ -62,6 +62,8 @@ > #define USB_DEV_QUIRKS_MAX 384 > #define USB_SUB_QUIRKS_MAX 8 > >+#define ENVNAMEROOT "usb.quirk." >+ > struct usb_quirk_entry { > uint16_t vid; > uint16_t pid; >@@ -612,6 +614,30 @@ > } > > /*------------------------------------------------------------------------* >+ * usb_quirk_str2num >+ * >+ * This function converts an USB quirk string into its code. >+ * >+ * Returns: >+ * -1: Quirk not found >+ * Else: Quirk code >+ *------------------------------------------------------------------------*/ >+static int32_t >+usb_quirk_str2num(char *name, int32_t namelen) >+{ >+ int i; >+ >+ for (i = 0; i < USB_QUIRK_MAX; i++) { >+ if (usb_quirk_str[i] != NULL >+ && strncmp(name, usb_quirk_str[i], namelen) == 0 >+ && usb_quirk_str[i][namelen] == '\0') >+ return i; >+ } >+ >+ return -1; >+} >+ >+/*------------------------------------------------------------------------* > * usb_test_quirk_by_info > * > * Returns: >@@ -853,15 +879,123 @@ > return (ENOIOCTL); > } > >+/*------------------------------------------------------------------------* >+ * usb_quirk_add_entry_from_str >+ * >+ * Add a USB quirk entry from string. >+ * "VENDOR PRODUCT LO_REV HI_REV QUIRK[,QUIRK[,...]]" >+ *------------------------------------------------------------------------*/ >+static void >+usb_quirk_add_entry_from_str(char *name, char *env) >+{ >+ struct usb_quirk_entry entry = { 0 }, *new; >+ int32_t quirk; >+ uint32_t quirk_idx; >+ char *end; >+ >+ entry.vid = (uint16_t)strtoul(env, &end, 0); >+ if (env == end || *end != ' ') { >+ if (*end == '\0') >+ goto too_short; >+ printf("%s: invalid USB quirk vendor ID at \"%s\"\n", >+ name, env); >+ return; >+ } >+ >+ env = end + 1; >+ entry.pid = (uint16_t)strtoul(env, &end, 0); >+ if (env == end || *end != ' ') { >+ if (*end == '\0') >+ goto too_short; >+ printf("%s: invalid USB quirk product ID at \"%s\"\n", >+ name, env); >+ return; >+ } >+ >+ env = end + 1; >+ entry.lo_rev = (uint16_t)strtoul(env, &end, 0); >+ if (env == end || *end != ' ') { >+ if (*end == '\0') >+ goto too_short; >+ printf("%s: invalid USB quirk low revision at \"%s\"\n", >+ name, env); >+ return; >+ } >+ >+ env = end + 1; >+ entry.hi_rev = (uint16_t)strtoul(env, &end, 0); >+ if (env == end || *end != ' ') { >+ if (*end == '\0') >+ goto too_short; >+ printf("%s: invalid USB quirk high revision at \"%s\"\n", >+ name, env); >+ return; >+ } >+ >+ for (env = end; *++env == ' '; ) >+ ; /* nothing */ >+ if (*env == '\0') { >+ too_short: >+ printf("%s: USB quirk definition not complete!\n", name); >+ return; >+ } >+ >+ for (quirk_idx = 0; quirk_idx < USB_SUB_QUIRKS_MAX; quirk_idx++) { >+ end = strchr(env, ','); >+ if (end == NULL) >+ end = env + strlen(env); >+ >+ quirk = usb_quirk_str2num(env, end - env); >+ if (quirk < 0) { >+ printf("%s: unknown USB quirk \"%.*s\"\n", >+ name, (int)(end - env), env); >+ return; >+ } >+ >+ entry.quirks[quirk_idx] = quirk; >+ >+ if (*end == '\0') { >+ mtx_lock(&usb_quirk_mtx); >+ new = usb_quirk_get_entry(entry.vid, entry.pid, >+ entry.lo_rev, entry.hi_rev, 1); >+ if (new == NULL) { >+ mtx_unlock(&usb_quirk_mtx); >+ printf("%s: USB quirks table full!\n", name); >+ return; >+ } >+ bcopy(entry.quirks, new->quirks, sizeof(entry.quirks)); >+ mtx_unlock(&usb_quirk_mtx); >+ return; >+ } >+ >+ env = end + 1; >+ } >+ >+ printf("%s: too many usb quirks, only %d allowed!\n", >+ name, USB_SUB_QUIRKS_MAX); >+} >+ > static void > usb_quirk_init(void *arg) > { >+ char envkey[sizeof(ENVNAMEROOT) + 2]; /* 2 digits max, 0 to 99 */ >+ int i; >+ > /* initialize mutex */ > mtx_init(&usb_quirk_mtx, "USB quirk", NULL, MTX_DEF); > > /* register our function */ > usb_test_quirk_p = &usb_test_quirk_by_info; > usb_quirk_ioctl_p = &usb_quirk_ioctl; >+ >+ for (i = 0; i < 100; i++) { >+ snprintf(envkey, sizeof(envkey), ENVNAMEROOT "%d", i); >+ >+ if (!testenv(envkey)) >+ break; /* Stop at first undefined var */ >+ >+ usb_quirk_add_entry_from_str(envkey, getenv(envkey)); >+ } > } > > static void
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 203249
: 161251 |
161317