tty: Add support for disabling DRM devices
Browse files at this commit5c91e3191dff08177740d642344d9eb67122139dParent: b7f1e385 changed files +109 -4
- docs/wiki/Configuration:-Debug-Options.md +16 -0
- niri-config/src/debug.rs +6 -0
- niri-config/src/lib.rs +6 -0
- src/backend/tty.rs +77 -4
- src/niri.rs +4 -0
docs/wiki/Configuration:-Debug-Options.mdmodified+16 -0
| @@ -18,6 +18,8 @@ debug { | |||
| 18 | disable-direct-scanout | 18 | disable-direct-scanout |
| 19 | restrict-primary-scanout-to-matching-format | 19 | restrict-primary-scanout-to-matching-format |
| 20 | render-drm-device "/dev/dri/renderD129" | 20 | render-drm-device "/dev/dri/renderD129" |
| 21 | + ignore-drm-device "/dev/dri/renderD128" | ||
| 22 | + ignore-drm-device "/dev/dri/renderD130" | ||
| 21 | force-pipewire-invalid-modifier | 23 | force-pipewire-invalid-modifier |
| 22 | dbus-interfaces-in-non-session-instances | 24 | dbus-interfaces-in-non-session-instances |
| 23 | wait-for-frame-completion-before-queueing | 25 | wait-for-frame-completion-before-queueing |
| @@ -115,6 +117,20 @@ debug { | |||
| 115 | } | 117 | } |
| 116 | ``` | 118 | ``` |
| 117 | 119 | ||
| 120 | +### `ignore-drm-device` | ||
| 121 | + | ||
| 122 | +<sup>Since: next release</sup> | ||
| 123 | + | ||
| 124 | +List DRM devices that niri will ignore. | ||
| 125 | +Useful for GPU passthrough when you don't want niri to open a certain device. | ||
| 126 | + | ||
| 127 | +```kdl | ||
| 128 | +debug { | ||
| 129 | + ignore-drm-device "/dev/dri/renderD128" | ||
| 130 | + ignore-drm-device "/dev/dri/renderD130" | ||
| 131 | +} | ||
| 132 | +``` | ||
| 133 | + | ||
| 118 | ### `force-pipewire-invalid-modifier` | 134 | ### `force-pipewire-invalid-modifier` |
| 119 | 135 | ||
| 120 | <sup>Since: 25.01</sup> | 136 | <sup>Since: 25.01</sup> |
niri-config/src/debug.rsmodified+6 -0
| @@ -13,6 +13,7 @@ pub struct Debug { | |||
| 13 | pub keep_max_bpc_unchanged: bool, | 13 | pub keep_max_bpc_unchanged: bool, |
| 14 | pub restrict_primary_scanout_to_matching_format: bool, | 14 | pub restrict_primary_scanout_to_matching_format: bool, |
| 15 | pub render_drm_device: Option<PathBuf>, | 15 | pub render_drm_device: Option<PathBuf>, |
| 16 | + pub ignored_drm_devices: Vec<PathBuf>, | ||
| 16 | pub force_pipewire_invalid_modifier: bool, | 17 | pub force_pipewire_invalid_modifier: bool, |
| 17 | pub emulate_zero_presentation_time: bool, | 18 | pub emulate_zero_presentation_time: bool, |
| 18 | pub disable_resize_throttling: bool, | 19 | pub disable_resize_throttling: bool, |
| @@ -45,6 +46,8 @@ pub struct DebugPart { | |||
| 45 | pub restrict_primary_scanout_to_matching_format: Option<Flag>, | 46 | pub restrict_primary_scanout_to_matching_format: Option<Flag>, |
| 46 | #[knuffel(child, unwrap(argument))] | 47 | #[knuffel(child, unwrap(argument))] |
| 47 | pub render_drm_device: Option<PathBuf>, | 48 | pub render_drm_device: Option<PathBuf>, |
| 49 | + #[knuffel(children(name = "ignore-drm-device"), unwrap(argument))] | ||
| 50 | + pub ignored_drm_devices: Vec<PathBuf>, | ||
| 48 | #[knuffel(child)] | 51 | #[knuffel(child)] |
| 49 | pub force_pipewire_invalid_modifier: Option<Flag>, | 52 | pub force_pipewire_invalid_modifier: Option<Flag>, |
| 50 | #[knuffel(child)] | 53 | #[knuffel(child)] |
| @@ -91,6 +94,9 @@ impl MergeWith<DebugPart> for Debug { | |||
| 91 | ); | 94 | ); |
| 92 | 95 | ||
| 93 | merge_clone_opt!((self, part), preview_render, render_drm_device); | 96 | merge_clone_opt!((self, part), preview_render, render_drm_device); |
| 97 | + | ||
| 98 | + self.ignored_drm_devices | ||
| 99 | + .extend(part.ignored_drm_devices.iter().cloned()); | ||
| 94 | } | 100 | } |
| 95 | } | 101 | } |
| 96 | 102 | ||
niri-config/src/lib.rsmodified+6 -0
| @@ -831,6 +831,8 @@ mod tests { | |||
| 831 | 831 | ||
| 832 | debug { | 832 | debug { |
| 833 | render-drm-device "/dev/dri/renderD129" | 833 | render-drm-device "/dev/dri/renderD129" |
| 834 | + ignore-drm-device "/dev/dri/renderD128" | ||
| 835 | + ignore-drm-device "/dev/dri/renderD130" | ||
| 834 | } | 836 | } |
| 835 | 837 | ||
| 836 | workspace "workspace-1" { | 838 | workspace "workspace-1" { |
| @@ -2008,6 +2010,10 @@ mod tests { | |||
| 2008 | render_drm_device: Some( | 2010 | render_drm_device: Some( |
| 2009 | "/dev/dri/renderD129", | 2011 | "/dev/dri/renderD129", |
| 2010 | ), | 2012 | ), |
| 2013 | + ignored_drm_devices: [ | ||
| 2014 | + "/dev/dri/renderD128", | ||
| 2015 | + "/dev/dri/renderD130", | ||
| 2016 | + ], | ||
| 2011 | force_pipewire_invalid_modifier: false, | 2017 | force_pipewire_invalid_modifier: false, |
| 2012 | emulate_zero_presentation_time: false, | 2018 | emulate_zero_presentation_time: false, |
| 2013 | disable_resize_throttling: false, | 2019 | disable_resize_throttling: false, |
src/backend/tty.rsmodified+77 -4
| @@ -83,6 +83,8 @@ pub struct Tty { | |||
| 83 | primary_node: DrmNode, | 83 | primary_node: DrmNode, |
| 84 | // DRM render node corresponding to the primary GPU. | 84 | // DRM render node corresponding to the primary GPU. |
| 85 | primary_render_node: DrmNode, | 85 | primary_render_node: DrmNode, |
| 86 | + // Ignored DRM nodes. | ||
| 87 | + ignored_nodes: HashSet<DrmNode>, | ||
| 86 | // Devices indexed by DRM node (not necessarily the render node). | 88 | // Devices indexed by DRM node (not necessarily the render node). |
| 87 | devices: HashMap<DrmNode, OutputDevice>, | 89 | devices: HashMap<DrmNode, OutputDevice>, |
| 88 | // The dma-buf global corresponds to the output device (the primary GPU). It is only `Some()` | 90 | // The dma-buf global corresponds to the output device (the primary GPU). It is only `Some()` |
| @@ -328,6 +330,11 @@ impl Tty { | |||
| 328 | } | 330 | } |
| 329 | info!("using as the render node: {node_path}"); | 331 | info!("using as the render node: {node_path}"); |
| 330 | 332 | ||
| 333 | + let mut ignored_nodes = ignored_nodes_from_config(&config.borrow()); | ||
| 334 | + if ignored_nodes.remove(&primary_node) || ignored_nodes.remove(&primary_render_node) { | ||
| 335 | + warn!("ignoring the primary node or render node is not allowed"); | ||
| 336 | + } | ||
| 337 | + | ||
| 331 | Ok(Self { | 338 | Ok(Self { |
| 332 | config, | 339 | config, |
| 333 | session, | 340 | session, |
| @@ -336,6 +343,7 @@ impl Tty { | |||
| 336 | gpu_manager, | 343 | gpu_manager, |
| 337 | primary_node, | 344 | primary_node, |
| 338 | primary_render_node, | 345 | primary_render_node, |
| 346 | + ignored_nodes, | ||
| 339 | devices: HashMap::new(), | 347 | devices: HashMap::new(), |
| 340 | dmabuf_global: None, | 348 | dmabuf_global: None, |
| 341 | update_output_config_on_resume: false, | 349 | update_output_config_on_resume: false, |
| @@ -504,6 +512,11 @@ impl Tty { | |||
| 504 | 512 | ||
| 505 | let node = DrmNode::from_dev_id(device_id)?; | 513 | let node = DrmNode::from_dev_id(device_id)?; |
| 506 | 514 | ||
| 515 | + if self.ignored_nodes.contains(&node) { | ||
| 516 | + debug!("node is ignored, skipping"); | ||
| 517 | + return Ok(()); | ||
| 518 | + } | ||
| 519 | + | ||
| 507 | let open_flags = OFlags::RDWR | OFlags::CLOEXEC | OFlags::NOCTTY | OFlags::NONBLOCK; | 520 | let open_flags = OFlags::RDWR | OFlags::CLOEXEC | OFlags::NOCTTY | OFlags::NONBLOCK; |
| 508 | let fd = self.session.open(path, open_flags)?; | 521 | let fd = self.session.open(path, open_flags)?; |
| 509 | let device_fd = DrmDeviceFd::new(DeviceFd::from(fd)); | 522 | let device_fd = DrmDeviceFd::new(DeviceFd::from(fd)); |
| @@ -1822,6 +1835,48 @@ impl Tty { | |||
| 1822 | } | 1835 | } |
| 1823 | self.update_output_config_on_resume = false; | 1836 | self.update_output_config_on_resume = false; |
| 1824 | 1837 | ||
| 1838 | + // Update ignored nodes. | ||
| 1839 | + let mut ignored_nodes = ignored_nodes_from_config(&self.config.borrow()); | ||
| 1840 | + if ignored_nodes.remove(&self.primary_node) | ||
| 1841 | + || ignored_nodes.remove(&self.primary_render_node) | ||
| 1842 | + { | ||
| 1843 | + warn!("ignoring the primary node or render node is not allowed"); | ||
| 1844 | + } | ||
| 1845 | + if ignored_nodes != self.ignored_nodes { | ||
| 1846 | + self.ignored_nodes = ignored_nodes; | ||
| 1847 | + | ||
| 1848 | + let mut device_list = self | ||
| 1849 | + .udev_dispatcher | ||
| 1850 | + .as_source_ref() | ||
| 1851 | + .device_list() | ||
| 1852 | + .map(|(device_id, path)| (device_id, path.to_owned())) | ||
| 1853 | + .collect::<HashMap<_, _>>(); | ||
| 1854 | + | ||
| 1855 | + let removed_devices = self | ||
| 1856 | + .devices | ||
| 1857 | + .keys() | ||
| 1858 | + .filter(|node| { | ||
| 1859 | + self.ignored_nodes.contains(node) || !device_list.contains_key(&node.dev_id()) | ||
| 1860 | + }) | ||
| 1861 | + .copied() | ||
| 1862 | + .collect::<Vec<_>>(); | ||
| 1863 | + | ||
| 1864 | + for node in removed_devices { | ||
| 1865 | + device_list.remove(&node.dev_id()); | ||
| 1866 | + self.device_removed(node.dev_id(), niri); | ||
| 1867 | + } | ||
| 1868 | + | ||
| 1869 | + for node in self.devices.keys() { | ||
| 1870 | + device_list.remove(&node.dev_id()); | ||
| 1871 | + } | ||
| 1872 | + | ||
| 1873 | + for (device_id, path) in device_list { | ||
| 1874 | + if let Err(err) = self.device_added(device_id, &path, niri) { | ||
| 1875 | + warn!("error adding device {path:?}: {err:?}"); | ||
| 1876 | + } | ||
| 1877 | + } | ||
| 1878 | + } | ||
| 1879 | + | ||
| 1825 | // Figure out if we should disable laptop panels. | 1880 | // Figure out if we should disable laptop panels. |
| 1826 | let mut disable_laptop_panels = false; | 1881 | let mut disable_laptop_panels = false; |
| 1827 | if niri.is_lid_closed { | 1882 | if niri.is_lid_closed { |
| @@ -2181,10 +2236,7 @@ impl GammaProps { | |||
| 2181 | } | 2236 | } |
| 2182 | } | 2237 | } |
| 2183 | 2238 | ||
| 2184 | -fn primary_node_from_config(config: &Config) -> Option<(DrmNode, DrmNode)> { | 2239 | +fn primary_node_from_render_node(path: &Path) -> Option<(DrmNode, DrmNode)> { |
| 2185 | - let path = config.debug.render_drm_device.as_ref()?; | ||
| 2186 | - debug!("attempting to use render node from config: {path:?}"); | ||
| 2187 | - | ||
| 2188 | match DrmNode::from_path(path) { | 2240 | match DrmNode::from_path(path) { |
| 2189 | Ok(node) => { | 2241 | Ok(node) => { |
| 2190 | if node.ty() == NodeType::Render { | 2242 | if node.ty() == NodeType::Render { |
| @@ -2215,9 +2267,30 @@ fn primary_node_from_config(config: &Config) -> Option<(DrmNode, DrmNode)> { | |||
| 2215 | warn!("error opening {path:?} as DRM node: {err:?}"); | 2267 | warn!("error opening {path:?} as DRM node: {err:?}"); |
| 2216 | } | 2268 | } |
| 2217 | } | 2269 | } |
| 2270 | + | ||
| 2218 | None | 2271 | None |
| 2219 | } | 2272 | } |
| 2220 | 2273 | ||
| 2274 | +fn primary_node_from_config(config: &Config) -> Option<(DrmNode, DrmNode)> { | ||
| 2275 | + let path = config.debug.render_drm_device.as_ref()?; | ||
| 2276 | + debug!("attempting to use render node from config: {path:?}"); | ||
| 2277 | + | ||
| 2278 | + primary_node_from_render_node(path) | ||
| 2279 | +} | ||
| 2280 | + | ||
| 2281 | +fn ignored_nodes_from_config(config: &Config) -> HashSet<DrmNode> { | ||
| 2282 | + let mut disabled_nodes = HashSet::new(); | ||
| 2283 | + | ||
| 2284 | + for path in &config.debug.ignored_drm_devices { | ||
| 2285 | + if let Some((primary_node, render_node)) = primary_node_from_render_node(path) { | ||
| 2286 | + disabled_nodes.insert(primary_node); | ||
| 2287 | + disabled_nodes.insert(render_node); | ||
| 2288 | + } | ||
| 2289 | + } | ||
| 2290 | + | ||
| 2291 | + disabled_nodes | ||
| 2292 | +} | ||
| 2293 | + | ||
| 2221 | fn surface_dmabuf_feedback( | 2294 | fn surface_dmabuf_feedback( |
| 2222 | compositor: &GbmDrmCompositor, | 2295 | compositor: &GbmDrmCompositor, |
| 2223 | primary_formats: FormatSet, | 2296 | primary_formats: FormatSet, |
src/niri.rsmodified+4 -0
| @@ -1504,6 +1504,10 @@ impl State { | |||
| 1504 | output_config_changed = true; | 1504 | output_config_changed = true; |
| 1505 | } | 1505 | } |
| 1506 | 1506 | ||
| 1507 | + if config.debug.ignored_drm_devices != old_config.debug.ignored_drm_devices { | ||
| 1508 | + output_config_changed = true; | ||
| 1509 | + } | ||
| 1510 | + | ||
| 1507 | // FIXME: move backdrop rendering into layout::Monitor, then this will become unnecessary. | 1511 | // FIXME: move backdrop rendering into layout::Monitor, then this will become unnecessary. |
| 1508 | if config.overview.backdrop_color != old_config.overview.backdrop_color { | 1512 | if config.overview.backdrop_color != old_config.overview.backdrop_color { |
| 1509 | output_config_changed = true; | 1513 | output_config_changed = true; |