summarylogtreecommitdiffstats
path: root/hhd.patch
blob: 9a14a9c934282fb44afbe1f4ad955518bc83bb0d (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
--- a/steamos-manager/src/lib.rs
+++ b/steamos-manager/src/lib.rs
@@ -27,6 +27,7 @@
 
 mod ds_inhibit;
 mod error;
+mod hhd;
 mod inputplumber;
 mod job;
 mod manager;
--- a/steamos-manager/src/power.rs
+++ b/steamos-manager/src/power.rs
@@ -169,6 +169,9 @@
 }
 
 pub(crate) async fn tdp_limit_manager(system: &Connection) -> Result<Box<dyn TdpLimitManager>> {
+    if let Some(manager) = crate::hhd::tdp_limit_manager().await? {
+        return Ok(manager);
+    }
     let config = device_config().await?;
     if let Some(config) = config.as_ref().and_then(|config| config.tdp_limit.as_ref()) {
         Ok(match &config.method {
--- a/steamos-manager/src/gpu.rs
+++ b/steamos-manager/src/gpu.rs
@@ -151,6 +151,9 @@
 }
 
 pub(crate) async fn gpu_performance_level_driver() -> Result<Box<dyn GpuPerformanceLevelDriver>> {
+    if let Some(driver) = crate::hhd::gpu_performance_level_driver().await? {
+        return Ok(driver);
+    }
     let config = device_config().await?;
     let config = config
         .as_ref()
--- a/steamos-manager/src/manager/user.rs
+++ b/steamos-manager/src/manager/user.rs
@@ -1738,10 +1738,6 @@
     object_server: &ObjectServer,
     tdp_manager: Option<UnboundedSender<TdpManagerCommand>>,
 ) -> Result<()> {
-    let Some(config) = device_config().await? else {
-        return Ok(());
-    };
-
     let performance_profile = PerformanceProfile1 {
         proxy: proxy.clone(),
         tdp_limit_manager: tdp_manager.clone(),
@@ -1751,14 +1747,8 @@
         let low_power_mode = LowPowerMode1 {
             manager: manager.clone(),
         };
-        if config
-            .tdp_limit
-            .as_ref()
-            .and_then(|config| config.download_mode_limit)
-            .is_some()
-        {
-            object_server.at(MANAGER_PATH, low_power_mode).await?;
-        }
+
+        object_server.at(MANAGER_PATH, low_power_mode).await?;
 
         let object_server = object_server.clone();
         spawn(async move {
@@ -1775,6 +1765,14 @@
         });
     }
 
+    if !crate::hhd::enable_power_features().await {
+        return Ok(());
+    }
+
+    let Some(config) = device_config().await? else {
+        return Ok(());
+    };
+
     if let Some(config) = config.performance_profile.as_ref()
         && !get_available_platform_profiles(&config.platform_profile_name)
             .await
@@ -1891,17 +1889,21 @@
         object_server.at(MANAGER_PATH, wifi_debug_dump).await?;
     }
 
-    if get_max_charge_level().await.is_ok() {
-        object_server.at(MANAGER_PATH, battery_charge_limit).await?;
-    }
+    let power_features = crate::hhd::enable_power_features().await;
 
-    if get_cpu_boost_state().await.is_ok() {
-        object_server.at(MANAGER_PATH, cpu_boost).await?;
-    }
+    if power_features {
+        if get_max_charge_level().await.is_ok() {
+            object_server.at(MANAGER_PATH, battery_charge_limit).await?;
+        }
+
+        if get_cpu_boost_state().await.is_ok() {
+            object_server.at(MANAGER_PATH, cpu_boost).await?;
+        }
 
-    object_server.at(MANAGER_PATH, cpu_scaling).await?;
-    if CpuSchedulerManager::is_supported().await? {
-        object_server.at(MANAGER_PATH, cpu_scheduler).await?;
+        object_server.at(MANAGER_PATH, cpu_scaling).await?;
+        if CpuSchedulerManager::is_supported().await? {
+            object_server.at(MANAGER_PATH, cpu_scheduler).await?;
+        }
     }
 
     match gpu_performance_level_driver().await {
@@ -1920,20 +1922,22 @@
         Err(e) => warn!("Can't add GpuPerformanceLevel1 interface: {e}"),
     }
 
-    match gpu_power_profile_driver().await {
-        Ok(driver) => {
-            object_server
-                .at(
-                    MANAGER_PATH,
-                    GpuPowerProfile1 {
-                        proxy: proxy.clone(),
-                        driver,
-                        order: SerialOrderValidator::default(),
-                    },
-                )
-                .await?;
+    if power_features {
+        match gpu_power_profile_driver().await {
+            Ok(driver) => {
+                object_server
+                    .at(
+                        MANAGER_PATH,
+                        GpuPowerProfile1 {
+                            proxy: proxy.clone(),
+                            driver,
+                            order: SerialOrderValidator::default(),
+                        },
+                    )
+                    .await?;
+            }
+            Err(e) => warn!("Can't add GpuPowerProfile1 interface: {e}"),
         }
-        Err(e) => warn!("Can't add GpuPowerProfile1 interface: {e}"),
     }
 
     if let Ok(hdmi_cec) = hdmi_cec {
--- a/data/system/steamos-manager.service
+++ b/data/system/steamos-manager.service
@@ -2,6 +2,8 @@
 Description=SteamOS Manager Daemon
 Wants=steamos-log-submitter.service
 After=steamos-log-submitter.service
+Wants=hhd.service
+After=hhd.service
 StartLimitIntervalSec=120
 StartLimitBurst=5
 

--- a/data/user/steamos-manager.service
+++ b/data/user/steamos-manager.service
@@ -1,5 +1,8 @@
 [Unit]
 Description=SteamOS Manager Daemon
+Before=graphical-session.target
+Before=steam-launcher.service
+Before=gamescope-session-plus@steam.service
 StartLimitIntervalSec=120
 StartLimitBurst=5
 
--- a/Makefile
+++ b/Makefile
@@ -44,4 +44,3 @@
 	install -m644 "data/user/steamos-manager.service" "$(DESTDIR)/usr/lib/systemd/user/"
 	install -m644 "data/user/steamos-manager-session-cleanup.service" "$(DESTDIR)/usr/lib/systemd/user/"
 	install -m644 "data/user/steamos-manager-configure-cecd.service" "$(DESTDIR)/usr/lib/systemd/user/"
-	install -m644 "data/user/orca.service" "$(DESTDIR)/usr/lib/systemd/user/"
--- a/steamos-manager/src/manager/root.rs
+++ b/steamos-manager/src/manager/root.rs
@@ -504,6 +504,19 @@
             debug!("SetGpuPerformanceLevel: discarding out of order serial");
             return Ok(());
         }
+
+        // Same rationale as set_tdp_limit(): the driver picked in new() can
+        // be stale if it was resolved before an external provider (e.g.
+        // Handheld Daemon) was fully up. Unlike TDP there is no placeholder
+        // object here, resolution just fails outright and leaves this at
+        // None, so a plain re-try is enough.
+        if self.gpu_performance_level.is_none() {
+            match gpu_performance_level_driver().await {
+                Ok(driver) => self.gpu_performance_level = Some(driver),
+                Err(e) => debug!("Still no GPU performance level driver available: {e}"),
+            }
+        }
+
         let Some(ref driver) = self.gpu_performance_level else {
             return Err(fdo::Error::Failed(String::from(
                 "GPU performance settings not configured",
@@ -529,6 +542,14 @@
             debug!("SetManualGpuClock: discarding out of order serial");
             return Ok(());
         }
+
+        if self.gpu_performance_level.is_none() {
+            match gpu_performance_level_driver().await {
+                Ok(driver) => self.gpu_performance_level = Some(driver),
+                Err(e) => debug!("Still no GPU performance level driver available: {e}"),
+            }
+        }
+
         let Some(ref driver) = self.gpu_performance_level else {
             return Err(fdo::Error::Failed(String::from(
                 "GPU performance settings not configured",
@@ -550,6 +571,24 @@
             debug!("SetTdpLimit: discarding out of order serial");
             return Ok(());
         }
+
+        // The manager picked in new() can be stale: it may have been
+        // resolved before an external TDP provider (e.g. Handheld Daemon)
+        // was fully up, leaving us stuck on a RemoteInterfaceLimitManager
+        // with no proxy for the rest of the daemon's lifetime. Re-resolve
+        // once here whenever the cached manager reports itself inactive,
+        // instead of failing forever on a boot-time race.
+        let needs_refresh = match self.tdp_limit_manager.as_ref() {
+            Some(manager) => !manager.is_active().await.unwrap_or(false),
+            None => true,
+        };
+        if needs_refresh {
+            match tdp_limit_manager(&self.connection).await {
+                Ok(manager) => self.tdp_limit_manager = Some(manager),
+                Err(e) => debug!("Still no TDP limit manager available: {e}"),
+            }
+        }
+
         let Some(ref manager) = self.tdp_limit_manager else {
             return Err(fdo::Error::Failed(String::from(
                 "TDP limiting not configured",