0017-grub-core-bus-usb-Add-function-pointer-for-attach-de.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. From c4cd7fbe3e2e8ff4cbe6d0db8c3356aeee614af5 Mon Sep 17 00:00:00 2001
  2. From: Patrick Rudolph <patrick.rudolph@9elements.com>
  3. Date: Sun, 15 Nov 2020 19:51:42 +0100
  4. Subject: [PATCH 17/22] grub-core/bus/usb: Add function pointer for
  5. attach/detach events
  6. The xHCI code needs to be called for attaching or detaching a device.
  7. Introduce two functions pointers and call it from the USB hub code.
  8. Will be used in future commits, currently this doesn't change any functionality.
  9. Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
  10. ---
  11. grub-core/bus/usb/ehci.c | 2 ++
  12. grub-core/bus/usb/ohci.c | 2 ++
  13. grub-core/bus/usb/uhci.c | 2 ++
  14. grub-core/bus/usb/usbhub.c | 19 +++++++++++++++++++
  15. include/grub/usb.h | 4 ++++
  16. 5 files changed, 29 insertions(+)
  17. diff --git a/grub-core/bus/usb/ehci.c b/grub-core/bus/usb/ehci.c
  18. index 9abebc6bd..953b851c0 100644
  19. --- a/grub-core/bus/usb/ehci.c
  20. +++ b/grub-core/bus/usb/ehci.c
  21. @@ -1812,6 +1812,8 @@ static struct grub_usb_controller_dev usb_controller = {
  22. .hubports = grub_ehci_hubports,
  23. .portstatus = grub_ehci_portstatus,
  24. .detect_dev = grub_ehci_detect_dev,
  25. + .attach_dev = NULL,
  26. + .detach_dev = NULL,
  27. /* estimated max. count of TDs for one bulk transfer */
  28. .max_bulk_tds = GRUB_EHCI_N_TD * 3 / 4
  29. };
  30. diff --git a/grub-core/bus/usb/ohci.c b/grub-core/bus/usb/ohci.c
  31. index 5363a61f6..7a3f3e154 100644
  32. --- a/grub-core/bus/usb/ohci.c
  33. +++ b/grub-core/bus/usb/ohci.c
  34. @@ -1440,6 +1440,8 @@ static struct grub_usb_controller_dev usb_controller =
  35. .hubports = grub_ohci_hubports,
  36. .portstatus = grub_ohci_portstatus,
  37. .detect_dev = grub_ohci_detect_dev,
  38. + .attach_dev = NULL,
  39. + .detach_dev = NULL,
  40. /* estimated max. count of TDs for one bulk transfer */
  41. .max_bulk_tds = GRUB_OHCI_TDS * 3 / 4
  42. };
  43. diff --git a/grub-core/bus/usb/uhci.c b/grub-core/bus/usb/uhci.c
  44. index 0fdea4c1e..03c4605b2 100644
  45. --- a/grub-core/bus/usb/uhci.c
  46. +++ b/grub-core/bus/usb/uhci.c
  47. @@ -845,6 +845,8 @@ static struct grub_usb_controller_dev usb_controller =
  48. .hubports = grub_uhci_hubports,
  49. .portstatus = grub_uhci_portstatus,
  50. .detect_dev = grub_uhci_detect_dev,
  51. + .attach_dev = NULL,
  52. + .detach_dev = NULL,
  53. /* estimated max. count of TDs for one bulk transfer */
  54. .max_bulk_tds = N_TD * 3 / 4
  55. };
  56. diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c
  57. index 2ae29cba1..8e963e84b 100644
  58. --- a/grub-core/bus/usb/usbhub.c
  59. +++ b/grub-core/bus/usb/usbhub.c
  60. @@ -66,6 +66,15 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller,
  61. dev->split_hubport = split_hubport;
  62. dev->split_hubaddr = split_hubaddr;
  63. + if (controller->dev->attach_dev) {
  64. + err = controller->dev->attach_dev (controller, dev);
  65. + if (err)
  66. + {
  67. + grub_free (dev);
  68. + return NULL;
  69. + }
  70. + }
  71. +
  72. err = grub_usb_device_initialize (dev);
  73. if (err)
  74. {
  75. @@ -405,6 +414,8 @@ static void
  76. detach_device (grub_usb_device_t dev)
  77. {
  78. unsigned i;
  79. + grub_usb_err_t err;
  80. +
  81. int k;
  82. if (!dev)
  83. return;
  84. @@ -425,6 +436,14 @@ detach_device (grub_usb_device_t dev)
  85. if (inter && inter->detach_hook)
  86. inter->detach_hook (dev, i, k);
  87. }
  88. + if (dev->controller.dev->detach_dev) {
  89. + err = dev->controller.dev->detach_dev (&dev->controller, dev);
  90. + if (err)
  91. + {
  92. + // XXX
  93. + }
  94. + }
  95. +
  96. grub_usb_devs[dev->addr] = 0;
  97. }
  98. diff --git a/include/grub/usb.h b/include/grub/usb.h
  99. index ea6ee8c2c..4dd179db2 100644
  100. --- a/include/grub/usb.h
  101. +++ b/include/grub/usb.h
  102. @@ -126,6 +126,10 @@ struct grub_usb_controller_dev
  103. grub_usb_speed_t (*detect_dev) (grub_usb_controller_t dev, int port, int *changed);
  104. + grub_usb_err_t (*attach_dev) (grub_usb_controller_t ctrl, grub_usb_device_t dev);
  105. +
  106. + grub_usb_err_t (*detach_dev) (grub_usb_controller_t ctrl, grub_usb_device_t dev);
  107. +
  108. /* Per controller flag - port reset pending, don't do another reset */
  109. grub_uint64_t pending_reset;
  110. --
  111. 2.39.2