summaryrefslogtreecommitdiff
path: root/config/grub/xhci/patches/0017-grub-core-bus-usb-Add-function-pointer-for-attach-de.patch
blob: 60680bd0ebd0fe04cf87df179578dc85c4559218 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
From c4cd7fbe3e2e8ff4cbe6d0db8c3356aeee614af5 Mon Sep 17 00:00:00 2001
From: Patrick Rudolph <patrick.rudolph@9elements.com>
Date: Sun, 15 Nov 2020 19:51:42 +0100
Subject: [PATCH 17/22] grub-core/bus/usb: Add function pointer for
 attach/detach events

The xHCI code needs to be called for attaching or detaching a device.
Introduce two functions pointers and call it from the USB hub code.

Will be used in future commits, currently this doesn't change any functionality.

Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
---
 grub-core/bus/usb/ehci.c   |  2 ++
 grub-core/bus/usb/ohci.c   |  2 ++
 grub-core/bus/usb/uhci.c   |  2 ++
 grub-core/bus/usb/usbhub.c | 19 +++++++++++++++++++
 include/grub/usb.h         |  4 ++++
 5 files changed, 29 insertions(+)

diff --git a/grub-core/bus/usb/ehci.c b/grub-core/bus/usb/ehci.c
index 9abebc6bd..953b851c0 100644
--- a/grub-core/bus/usb/ehci.c
+++ b/grub-core/bus/usb/ehci.c
@@ -1812,6 +1812,8 @@ static struct grub_usb_controller_dev usb_controller = {
   .hubports = grub_ehci_hubports,
   .portstatus = grub_ehci_portstatus,
   .detect_dev = grub_ehci_detect_dev,
+  .attach_dev = NULL,
+  .detach_dev = NULL,
   /* estimated max. count of TDs for one bulk transfer */
   .max_bulk_tds = GRUB_EHCI_N_TD * 3 / 4
 };
diff --git a/grub-core/bus/usb/ohci.c b/grub-core/bus/usb/ohci.c
index 5363a61f6..7a3f3e154 100644
--- a/grub-core/bus/usb/ohci.c
+++ b/grub-core/bus/usb/ohci.c
@@ -1440,6 +1440,8 @@ static struct grub_usb_controller_dev usb_controller =
   .hubports = grub_ohci_hubports,
   .portstatus = grub_ohci_portstatus,
   .detect_dev = grub_ohci_detect_dev,
+  .attach_dev = NULL,
+  .detach_dev = NULL,
   /* estimated max. count of TDs for one bulk transfer */
   .max_bulk_tds = GRUB_OHCI_TDS * 3 / 4
 };
diff --git a/grub-core/bus/usb/uhci.c b/grub-core/bus/usb/uhci.c
index 0fdea4c1e..03c4605b2 100644
--- a/grub-core/bus/usb/uhci.c
+++ b/grub-core/bus/usb/uhci.c
@@ -845,6 +845,8 @@ static struct grub_usb_controller_dev usb_controller =
   .hubports = grub_uhci_hubports,
   .portstatus = grub_uhci_portstatus,
   .detect_dev = grub_uhci_detect_dev,
+  .attach_dev = NULL,
+  .detach_dev = NULL,
   /* estimated max. count of TDs for one bulk transfer */
   .max_bulk_tds = N_TD * 3 / 4
 };
diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c
index 2ae29cba1..8e963e84b 100644
--- a/grub-core/bus/usb/usbhub.c
+++ b/grub-core/bus/usb/usbhub.c
@@ -66,6 +66,15 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller,
   dev->split_hubport = split_hubport;
   dev->split_hubaddr = split_hubaddr;
 
+  if (controller->dev->attach_dev) {
+    err = controller->dev->attach_dev (controller, dev);
+    if (err)
+      {
+	grub_free (dev);
+	return NULL;
+      }
+  }
+
   err = grub_usb_device_initialize (dev);
   if (err)
     {
@@ -405,6 +414,8 @@ static void
 detach_device (grub_usb_device_t dev)
 {
   unsigned i;
+  grub_usb_err_t err;
+
   int k;
   if (!dev)
     return;
@@ -425,6 +436,14 @@ detach_device (grub_usb_device_t dev)
 	  if (inter && inter->detach_hook)
 	    inter->detach_hook (dev, i, k);
 	}
+  if (dev->controller.dev->detach_dev) {
+    err = dev->controller.dev->detach_dev (&dev->controller, dev);
+    if (err)
+      {
+	// XXX
+      }
+  }
+
   grub_usb_devs[dev->addr] = 0;
 }
 
diff --git a/include/grub/usb.h b/include/grub/usb.h
index ea6ee8c2c..4dd179db2 100644
--- a/include/grub/usb.h
+++ b/include/grub/usb.h
@@ -126,6 +126,10 @@ struct grub_usb_controller_dev
 
   grub_usb_speed_t (*detect_dev) (grub_usb_controller_t dev, int port, int *changed);
 
+  grub_usb_err_t (*attach_dev) (grub_usb_controller_t ctrl, grub_usb_device_t dev);
+
+  grub_usb_err_t (*detach_dev) (grub_usb_controller_t ctrl, grub_usb_device_t dev);
+
   /* Per controller flag - port reset pending, don't do another reset */
   grub_uint64_t pending_reset;
 
-- 
2.39.2