0014-grub-core-bus-usb-Parse-SuperSpeed-companion-descrip.patch 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. From 3273128b6dc6df83ef6b1d54d009a1ae26844bff Mon Sep 17 00:00:00 2001
  2. From: Patrick Rudolph <patrick.rudolph@9elements.com>
  3. Date: Sun, 15 Nov 2020 19:00:27 +0100
  4. Subject: [PATCH 14/22] grub-core/bus/usb: Parse SuperSpeed companion
  5. descriptors
  6. Parse the SS_ENDPOINT_COMPANION descriptor, which is only present on USB 3.0
  7. capable devices and xHCI controllers. Make the descendp an array of pointers
  8. to the endpoint descriptor as it's no longer an continous array.
  9. Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
  10. ---
  11. grub-core/bus/usb/serial/common.c | 2 +-
  12. grub-core/bus/usb/usb.c | 44 +++++++++++++++++++------------
  13. grub-core/bus/usb/usbhub.c | 22 ++++++++++++----
  14. grub-core/commands/usbtest.c | 2 +-
  15. grub-core/disk/usbms.c | 2 +-
  16. grub-core/term/usb_keyboard.c | 2 +-
  17. include/grub/usb.h | 2 +-
  18. include/grub/usbdesc.h | 11 +++++++-
  19. 8 files changed, 59 insertions(+), 28 deletions(-)
  20. diff --git a/grub-core/bus/usb/serial/common.c b/grub-core/bus/usb/serial/common.c
  21. index e9c995a0a..fc847d66d 100644
  22. --- a/grub-core/bus/usb/serial/common.c
  23. +++ b/grub-core/bus/usb/serial/common.c
  24. @@ -72,7 +72,7 @@ grub_usbserial_attach (grub_usb_device_t usbdev, int configno, int interfno,
  25. for (j = 0; j < interf->endpointcnt; j++)
  26. {
  27. struct grub_usb_desc_endp *endp;
  28. - endp = &usbdev->config[0].interf[interfno].descendp[j];
  29. + endp = usbdev->config[0].interf[interfno].descendp[j];
  30. if ((endp->endp_addr & 128) && (endp->attrib & 3) == 2
  31. && (in_endp == GRUB_USB_SERIAL_ENDPOINT_LAST_MATCHING
  32. diff --git a/grub-core/bus/usb/usb.c b/grub-core/bus/usb/usb.c
  33. index 7bd49d201..e578af793 100644
  34. --- a/grub-core/bus/usb/usb.c
  35. +++ b/grub-core/bus/usb/usb.c
  36. @@ -118,7 +118,7 @@ grub_usb_device_initialize (grub_usb_device_t dev)
  37. struct grub_usb_desc_device *descdev;
  38. struct grub_usb_desc_config config;
  39. grub_usb_err_t err;
  40. - int i;
  41. + int i, j;
  42. /* First we have to read first 8 bytes only and determine
  43. * max. size of packet */
  44. @@ -152,6 +152,7 @@ grub_usb_device_initialize (grub_usb_device_t dev)
  45. int currif;
  46. char *data;
  47. struct grub_usb_desc *desc;
  48. + struct grub_usb_desc_endp *endp;
  49. /* First just read the first 4 bytes of the configuration
  50. descriptor, after that it is known how many bytes really have
  51. @@ -201,24 +202,27 @@ grub_usb_device_initialize (grub_usb_device_t dev)
  52. = (struct grub_usb_desc_if *) &data[pos];
  53. pos += dev->config[i].interf[currif].descif->length;
  54. + dev->config[i].interf[currif].descendp = grub_malloc (
  55. + dev->config[i].interf[currif].descif->endpointcnt *
  56. + sizeof(struct grub_usb_desc_endp));
  57. +
  58. + j = 0;
  59. while (pos < config.totallen)
  60. {
  61. desc = (struct grub_usb_desc *)&data[pos];
  62. - if (desc->type == GRUB_USB_DESCRIPTOR_ENDPOINT)
  63. - break;
  64. - if (!desc->length)
  65. - {
  66. - err = GRUB_USB_ERR_BADDEVICE;
  67. - goto fail;
  68. - }
  69. - pos += desc->length;
  70. - }
  71. -
  72. - /* Point to the first endpoint. */
  73. - dev->config[i].interf[currif].descendp
  74. - = (struct grub_usb_desc_endp *) &data[pos];
  75. - pos += (sizeof (struct grub_usb_desc_endp)
  76. - * dev->config[i].interf[currif].descif->endpointcnt);
  77. + if (desc->type == GRUB_USB_DESCRIPTOR_ENDPOINT) {
  78. + endp = (struct grub_usb_desc_endp *) &data[pos];
  79. + dev->config[i].interf[currif].descendp[j++] = endp;
  80. + pos += desc->length;
  81. + } else {
  82. + if (!desc->length)
  83. + {
  84. + err = GRUB_USB_ERR_BADDEVICE;
  85. + goto fail;
  86. + }
  87. + pos += desc->length;
  88. + }
  89. + }
  90. }
  91. }
  92. @@ -226,8 +230,14 @@ grub_usb_device_initialize (grub_usb_device_t dev)
  93. fail:
  94. - for (i = 0; i < GRUB_USB_MAX_CONF; i++)
  95. + for (i = 0; i < GRUB_USB_MAX_CONF; i++) {
  96. + int currif;
  97. +
  98. + for (currif = 0; currif < dev->config[i].descconf->numif; currif++)
  99. + grub_free (dev->config[i].interf[currif].descendp);
  100. +
  101. grub_free (dev->config[i].descconf);
  102. + }
  103. return err;
  104. }
  105. diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c
  106. index f5608e330..2ae29cba1 100644
  107. --- a/grub-core/bus/usb/usbhub.c
  108. +++ b/grub-core/bus/usb/usbhub.c
  109. @@ -82,8 +82,14 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller,
  110. if (i == GRUB_USBHUB_MAX_DEVICES)
  111. {
  112. grub_error (GRUB_ERR_IO, "can't assign address to USB device");
  113. - for (i = 0; i < GRUB_USB_MAX_CONF; i++)
  114. - grub_free (dev->config[i].descconf);
  115. + for (i = 0; i < GRUB_USB_MAX_CONF; i++) {
  116. + int currif;
  117. +
  118. + for (currif = 0; currif < dev->config[i].descconf->numif; currif++)
  119. + grub_free (dev->config[i].interf[currif].descendp);
  120. +
  121. + grub_free (dev->config[i].descconf);
  122. + }
  123. grub_free (dev);
  124. return NULL;
  125. }
  126. @@ -96,8 +102,14 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller,
  127. i, 0, 0, NULL);
  128. if (err)
  129. {
  130. - for (i = 0; i < GRUB_USB_MAX_CONF; i++)
  131. - grub_free (dev->config[i].descconf);
  132. + for (i = 0; i < GRUB_USB_MAX_CONF; i++) {
  133. + int currif;
  134. +
  135. + for (currif = 0; currif < dev->config[i].descconf->numif; currif++)
  136. + grub_free (dev->config[i].interf[currif].descendp);
  137. +
  138. + grub_free (dev->config[i].descconf);
  139. + }
  140. grub_free (dev);
  141. return NULL;
  142. }
  143. @@ -176,7 +188,7 @@ grub_usb_add_hub (grub_usb_device_t dev)
  144. i++)
  145. {
  146. struct grub_usb_desc_endp *endp = NULL;
  147. - endp = &dev->config[0].interf[0].descendp[i];
  148. + endp = dev->config[0].interf[0].descendp[i];
  149. if ((endp->endp_addr & 128) && grub_usb_get_ep_type(endp)
  150. == GRUB_USB_EP_INTERRUPT)
  151. diff --git a/grub-core/commands/usbtest.c b/grub-core/commands/usbtest.c
  152. index 2c6d93fe6..55a657635 100644
  153. --- a/grub-core/commands/usbtest.c
  154. +++ b/grub-core/commands/usbtest.c
  155. @@ -185,7 +185,7 @@ usb_iterate (grub_usb_device_t dev, void *data __attribute__ ((unused)))
  156. for (j = 0; j < interf->endpointcnt; j++)
  157. {
  158. struct grub_usb_desc_endp *endp;
  159. - endp = &dev->config[0].interf[i].descendp[j];
  160. + endp = dev->config[0].interf[i].descendp[j];
  161. grub_printf ("Endpoint #%d: %s, max packed size: %d, transfer type: %s, latency: %d\n",
  162. endp->endp_addr & 15,
  163. diff --git a/grub-core/disk/usbms.c b/grub-core/disk/usbms.c
  164. index b81e3ad9d..b1512dc12 100644
  165. --- a/grub-core/disk/usbms.c
  166. +++ b/grub-core/disk/usbms.c
  167. @@ -184,7 +184,7 @@ grub_usbms_attach (grub_usb_device_t usbdev, int configno, int interfno)
  168. for (j = 0; j < interf->endpointcnt; j++)
  169. {
  170. struct grub_usb_desc_endp *endp;
  171. - endp = &usbdev->config[0].interf[interfno].descendp[j];
  172. + endp = usbdev->config[0].interf[interfno].descendp[j];
  173. if ((endp->endp_addr & 128) && (endp->attrib & 3) == 2)
  174. /* Bulk IN endpoint. */
  175. diff --git a/grub-core/term/usb_keyboard.c b/grub-core/term/usb_keyboard.c
  176. index 7322d8dff..d590979f5 100644
  177. --- a/grub-core/term/usb_keyboard.c
  178. +++ b/grub-core/term/usb_keyboard.c
  179. @@ -175,7 +175,7 @@ grub_usb_keyboard_attach (grub_usb_device_t usbdev, int configno, int interfno)
  180. for (j = 0; j < usbdev->config[configno].interf[interfno].descif->endpointcnt;
  181. j++)
  182. {
  183. - endp = &usbdev->config[configno].interf[interfno].descendp[j];
  184. + endp = usbdev->config[configno].interf[interfno].descendp[j];
  185. if ((endp->endp_addr & 128) && grub_usb_get_ep_type(endp)
  186. == GRUB_USB_EP_INTERRUPT)
  187. diff --git a/include/grub/usb.h b/include/grub/usb.h
  188. index 0f346af12..688c11f6d 100644
  189. --- a/include/grub/usb.h
  190. +++ b/include/grub/usb.h
  191. @@ -153,7 +153,7 @@ struct grub_usb_interface
  192. {
  193. struct grub_usb_desc_if *descif;
  194. - struct grub_usb_desc_endp *descendp;
  195. + struct grub_usb_desc_endp **descendp;
  196. /* A driver is handling this interface. Do we need to support multiple drivers
  197. for single interface?
  198. diff --git a/include/grub/usbdesc.h b/include/grub/usbdesc.h
  199. index aac5ab05a..bb2ab2e27 100644
  200. --- a/include/grub/usbdesc.h
  201. +++ b/include/grub/usbdesc.h
  202. @@ -29,7 +29,8 @@ typedef enum {
  203. GRUB_USB_DESCRIPTOR_INTERFACE,
  204. GRUB_USB_DESCRIPTOR_ENDPOINT,
  205. GRUB_USB_DESCRIPTOR_DEBUG = 10,
  206. - GRUB_USB_DESCRIPTOR_HUB = 0x29
  207. + GRUB_USB_DESCRIPTOR_HUB = 0x29,
  208. + GRUB_USB_DESCRIPTOR_SS_ENDPOINT_COMPANION = 0x30
  209. } grub_usb_descriptor_t;
  210. struct grub_usb_desc
  211. @@ -105,6 +106,14 @@ struct grub_usb_desc_endp
  212. grub_uint8_t interval;
  213. } GRUB_PACKED;
  214. +struct grub_usb_desc_ssep {
  215. + grub_uint8_t length;
  216. + grub_uint8_t type;
  217. + grub_uint8_t maxburst;
  218. + grub_uint8_t attrib;
  219. + grub_uint16_t interval;
  220. +} GRUB_PACKED;
  221. +
  222. struct grub_usb_desc_str
  223. {
  224. grub_uint8_t length;
  225. --
  226. 2.39.2