0024-xhci-configure-TT-for-non-root-hubs.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. From 233f7dd274ef2ccac7b1fc0f5cfdeb7c01aef58b Mon Sep 17 00:00:00 2001
  2. From: Sven Anderson <sven@anderson.de>
  3. Date: Mon, 13 Jan 2025 20:26:32 +0100
  4. Subject: [PATCH 24/26] xhci: configure TT for non-root-hubs
  5. ---
  6. grub-core/bus/usb/usbhub.c | 6 +++++
  7. grub-core/bus/usb/xhci.c | 45 +++++++++++++++++++++++++++++++++-----
  8. include/grub/usb.h | 2 ++
  9. 3 files changed, 47 insertions(+), 6 deletions(-)
  10. diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c
  11. index e96505aa9..629b3ed53 100644
  12. --- a/grub-core/bus/usb/usbhub.c
  13. +++ b/grub-core/bus/usb/usbhub.c
  14. @@ -818,3 +818,9 @@ grub_usb_iterate (grub_usb_iterate_hook_t hook, void *hook_data)
  15. return 0;
  16. }
  17. +
  18. +grub_usb_device_t
  19. +grub_usb_get_dev (int addr)
  20. +{
  21. + return grub_usb_devs[addr];
  22. +}
  23. diff --git a/grub-core/bus/usb/xhci.c b/grub-core/bus/usb/xhci.c
  24. index d13a7c39d..8ad2a10f9 100644
  25. --- a/grub-core/bus/usb/xhci.c
  26. +++ b/grub-core/bus/usb/xhci.c
  27. @@ -623,13 +623,46 @@ grub_xhci_alloc_inctx(struct grub_xhci *x, int maxepid,
  28. break;
  29. }
  30. - /* Route is greater zero on devices that are connected to a non root hub */
  31. - if (dev->route)
  32. - {
  33. - /* FIXME: Implement this code for non SuperSpeed hub devices */
  34. + /* Set routing string */
  35. + slot->ctx[0] |= dev->route;
  36. +
  37. + /* Set root hub port number */
  38. + slot->ctx[1] |= (dev->root_port + 1) << 16;
  39. +
  40. + if (dev->split_hubaddr && (dev->speed == GRUB_USB_SPEED_LOW ||
  41. + dev->speed == GRUB_USB_SPEED_FULL)) {
  42. +
  43. + grub_usb_device_t hubdev = grub_usb_get_dev(dev->split_hubaddr);
  44. +
  45. + if (!hubdev || hubdev->descdev.class != GRUB_USB_CLASS_HUB) {
  46. + grub_dprintf("xhci", "Invalid hub device at addr %d!\n", dev->split_hubaddr);
  47. + return NULL;
  48. + }
  49. +
  50. + struct grub_xhci_priv *hub_priv = hubdev->xhci_priv;
  51. + if (!hub_priv) {
  52. + grub_dprintf("xhci", "Hub has no xhci_priv!\n");
  53. + return NULL;
  54. + }
  55. +
  56. + if (hubdev->speed == GRUB_USB_SPEED_HIGH) {
  57. + /* Direct connection to high-speed hub - set up TT */
  58. + grub_dprintf("xhci", "Direct high-speed hub connection - configuring TT with "
  59. + "hub slot %d port %d\n", hub_priv->slotid, dev->split_hubport);
  60. + slot->ctx[2] |= hub_priv->slotid;
  61. + slot->ctx[2] |= dev->split_hubport << 8;
  62. }
  63. - slot->ctx[0] |= dev->route;
  64. - slot->ctx[1] |= (dev->root_port+1) << 16;
  65. + else {
  66. + /* Hub is not high-speed, inherit TT settings from parent */
  67. + volatile struct grub_xhci_slotctx *hubslot;
  68. + grub_dprintf("xhci", "Non high-speed hub - inheriting TT settings from parent\n");
  69. + hubslot = grub_dma_phys2virt(x->devs[hub_priv->slotid].ptr_low, x->devs_dma);
  70. + slot->ctx[2] = hubslot->ctx[2];
  71. + }
  72. + }
  73. +
  74. + grub_dprintf("xhci", "Slot context: ctx[0]=0x%08x ctx[1]=0x%08x ctx[2]=0x%08x\n",
  75. + slot->ctx[0], slot->ctx[1], slot->ctx[2]);
  76. grub_arch_sync_dma_caches(in, size);
  77. diff --git a/include/grub/usb.h b/include/grub/usb.h
  78. index eb71fa1c7..df97a60cc 100644
  79. --- a/include/grub/usb.h
  80. +++ b/include/grub/usb.h
  81. @@ -62,6 +62,8 @@ typedef int (*grub_usb_controller_iterate_hook_t) (grub_usb_controller_t dev,
  82. /* Call HOOK with each device, until HOOK returns non-zero. */
  83. int grub_usb_iterate (grub_usb_iterate_hook_t hook, void *hook_data);
  84. +grub_usb_device_t grub_usb_get_dev (int addr);
  85. +
  86. grub_usb_err_t grub_usb_device_initialize (grub_usb_device_t dev);
  87. grub_usb_err_t grub_usb_get_descriptor (grub_usb_device_t dev,
  88. --
  89. 2.39.5