From 8dd981a95cc7731b63b2d79ce6f98ce2d6b5a993 Mon Sep 17 00:00:00 2001
From: Patrick Rudolph <patrick.rudolph@9elements.com>
Date: Sun, 15 Nov 2020 19:54:40 +0100
Subject: [PATCH 18/22] grub-core/bus/usb/usbhub: Add new private fields for
 xHCI controller

Store the root port number, the route, consisting out of the port ID
in each nibble, and a pointer to driver private data.

Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
---
 grub-core/bus/usb/usbhub.c | 11 ++++++++---
 include/grub/usb.h         |  5 +++++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c
index 8e963e84b..b4b3a1a61 100644
--- a/grub-core/bus/usb/usbhub.c
+++ b/grub-core/bus/usb/usbhub.c
@@ -49,7 +49,9 @@ static grub_usb_controller_dev_t grub_usb_list;
 static grub_usb_device_t
 grub_usb_hub_add_dev (grub_usb_controller_t controller,
                       grub_usb_speed_t speed,
-                      int split_hubport, int split_hubaddr)
+                      int split_hubport, int split_hubaddr,
+                      int root_portno,
+                      grub_uint32_t route)
 {
   grub_usb_device_t dev;
   int i;
@@ -65,6 +67,8 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller,
   dev->speed = speed;
   dev->split_hubport = split_hubport;
   dev->split_hubaddr = split_hubaddr;
+  dev->root_port = root_portno;
+  dev->route = route;
 
   if (controller->dev->attach_dev) {
     err = controller->dev->attach_dev (controller, dev);
@@ -245,7 +249,7 @@ attach_root_port (struct grub_usb_hub *hub, int portno,
      and full/low speed device connected to OHCI/UHCI needs not
      transaction translation - e.g. hubport and hubaddr should be
      always none (zero) for any device connected to any root hub. */
-  dev = grub_usb_hub_add_dev (hub->controller, speed, 0, 0);
+  dev = grub_usb_hub_add_dev (hub->controller, speed, 0, 0, portno, 0);
   hub->controller->dev->pending_reset = 0;
   npending--;
   if (! dev)
@@ -676,7 +680,8 @@ poll_nonroot_hub (grub_usb_device_t dev)
 
 	      /* Add the device and assign a device address to it.  */
 	      next_dev = grub_usb_hub_add_dev (&dev->controller, speed,
-					       split_hubport, split_hubaddr);
+					       split_hubport, split_hubaddr, dev->root_port,
+					       dev->route << 4 | (i & 0xf));
 	      if (dev->controller.dev->pending_reset)
 		{
 		  dev->controller.dev->pending_reset = 0;
diff --git a/include/grub/usb.h b/include/grub/usb.h
index 4dd179db2..609faf7d0 100644
--- a/include/grub/usb.h
+++ b/include/grub/usb.h
@@ -237,6 +237,11 @@ struct grub_usb_device
   int split_hubport;
 
   int split_hubaddr;
+
+  /* xHCI specific information */
+  int root_port;
+  grub_uint32_t route;
+  void *xhci_priv;
 };
 
 
-- 
2.39.5

