1 // SPDX-License-Identifier: GPL-2.0 2 // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 4 //! The GIN CPU interrupt tree for one PCIe function. 5 //! 6 //! A [`GinVector`] names an interrupt source, a [`LeafIndex`] the leaf register that latches it, 7 //! a [`LeafMask`] a set of vectors within one leaf, and a [`Subtree`] one `TOP` bit. The types 8 //! keep the four from being confused with one another. 9 //! 10 //! Servicing a leaf requires reading its pending bits before clearing them. Only 11 //! [`Tree::read_pending`] produces a [`LeafPending`], and only a [`LeafPending`] clears a leaf, 12 //! so that the wrong order does not compile. This module does not serialize access to the tree. 13 //! 14 //! See `Documentation/gpu/nova/core/interrupts.rst`. 15 16 use kernel::{ 17 device::Bound, 18 io::{ 19 register::Array, 20 Io, // 21 }, 22 irq, 23 num::Bounded, 24 pci::{ 25 self, 26 IrqType, // 27 }, 28 prelude::*, // 29 }; 30 31 use crate::{ 32 driver::Bar0, 33 gpu::Chipset, 34 num, // 35 }; 36 37 use super::{ 38 hal::{ 39 cpu_interrupt_hal, 40 CpuInterruptHal, // 41 }, 42 regs::*, 43 MsiType, // 44 }; 45 46 /// Number of vectors one leaf register carries, one per bit. 47 const VECTORS_PER_LEAF: u32 = u32::BITS; 48 49 /// Number of leaves one subtree covers. 50 const LEAVES_PER_SUBTREE: u32 = 2; 51 52 /// Number of subtrees the widest supported tree implements. 53 const MAX_NUM_SUBTREES: u32 = 8; 54 55 /// Number of leaves the widest supported tree implements. 56 const MAX_NUM_LEAVES: u32 = MAX_NUM_SUBTREES * LEAVES_PER_SUBTREE; 57 58 /// Number of bits needed to address every vector in the widest supported tree. 59 const VECTOR_BITS: u32 = (MAX_NUM_LEAVES * VECTORS_PER_LEAF).ilog2(); 60 61 /// Width of the vector field in the leaf trigger register. 62 const TRIGGER_VECTOR_BITS: u32 = { 63 let range = NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_TRIGGER::VECTOR_RANGE; 64 num::u8_as_u32(*range.end() - *range.start() + 1) 65 }; 66 67 /// Index of a leaf register within the widest supported tree. An 8-leaf tree implements only the 68 /// lower half of the range. 69 pub(super) type LeafIndex = Bounded<usize, { MAX_NUM_LEAVES.ilog2() }>; 70 71 /// Number of leaves a tree implements. 72 #[derive(Clone, Copy, Debug, Eq, PartialEq)] 73 #[repr(u32)] 74 pub(super) enum LeafCount { 75 /// Turing through Ada. 76 Eight = 8, 77 78 /// Hopper and later. 79 Sixteen = 16, 80 } 81 82 impl LeafCount { 83 pub(super) const fn into_u32(self) -> u32 { 84 // CAST: `LeafCount` is `repr(u32)`, so the cast is lossless. 85 self as u32 86 } 87 88 pub(super) const fn into_raw(self) -> usize { 89 num::u32_as_usize(self.into_u32()) 90 } 91 92 /// Returns the number of subtrees a tree of this size implements. 93 pub(super) const fn subtree_count(self) -> u32 { 94 self.into_u32() / LEAVES_PER_SUBTREE 95 } 96 97 /// Returns the set of every subtree a tree of this size implements. 98 pub(super) const fn subtree_set(self) -> SubtreeSet { 99 SubtreeSet((1u32 << self.subtree_count()) - 1) 100 } 101 102 /// Returns the number of vectors a tree of this size carries. 103 pub(super) const fn vector_count(self) -> u32 { 104 self.into_u32() * VECTORS_PER_LEAF 105 } 106 107 /// Returns every leaf a tree of this size implements. 108 pub(super) fn iter(self) -> impl Iterator<Item = LeafIndex> { 109 (0..self.into_raw()).filter_map(LeafIndex::try_new) 110 } 111 } 112 113 // `VECTOR_BITS` and `LeafCount::Sixteen` are written separately. This assert keeps them in 114 // agreement about the widest supported tree. 115 static_assert!(1 << VECTOR_BITS == LeafCount::Sixteen.vector_count()); 116 117 /// Set of vectors within one leaf, one bit per vector. 118 #[derive(Clone, Copy, Debug, Eq, PartialEq)] 119 pub(super) struct LeafMask(u32); 120 121 impl LeafMask { 122 /// Returns the mask with every vector set. 123 pub(super) const fn all() -> Self { 124 Self(u32::MAX) 125 } 126 127 #[cfg_attr(not(CONFIG_NOVA_CORE_SELFTESTS), expect(dead_code))] 128 pub(super) const fn from_raw(raw: u32) -> Self { 129 Self(raw) 130 } 131 132 #[cfg_attr( 133 not(any(CONFIG_NOVA_CORE_SELFTESTS, CONFIG_KUNIT = "y")), 134 expect(dead_code) 135 )] 136 pub(super) const fn into_raw(self) -> u32 { 137 self.0 138 } 139 140 pub(super) const fn is_empty(self) -> bool { 141 self.0 == 0 142 } 143 144 /// Returns whether every vector in `other` is also in this mask. 145 pub(super) const fn contains(self, other: Self) -> bool { 146 self.0 & other.0 == other.0 147 } 148 } 149 150 impl From<Bounded<u32, 32>> for LeafMask { 151 fn from(vectors: Bounded<u32, 32>) -> Self { 152 Self(vectors.get()) 153 } 154 } 155 156 impl From<LeafMask> for Bounded<u32, 32> { 157 fn from(vectors: LeafMask) -> Self { 158 vectors.0.into() 159 } 160 } 161 162 /// One subtree, held as the `TOP` bit that covers it. 163 /// 164 /// # Invariants 165 /// 166 /// Exactly one bit is set. 167 #[derive(Clone, Copy, Debug, Eq, PartialEq)] 168 pub(crate) struct Subtree(u32); 169 170 impl Subtree { 171 /// Returns the subtree at index `idx`. 172 const fn new(idx: u32) -> Self { 173 // INVARIANT: shifting `1` left leaves exactly one bit set. 174 Self(1 << idx) 175 } 176 177 /// Returns this subtree's index within the tree. 178 pub(super) const fn index(self) -> u32 { 179 self.0.trailing_zeros() 180 } 181 182 pub(super) const fn into_raw(self) -> u32 { 183 self.0 184 } 185 } 186 187 /// Set of subtrees, one bit per subtree, in the layout of the `TOP` registers. 188 #[derive(Clone, Copy, Debug, Eq, PartialEq)] 189 pub(crate) struct SubtreeSet(u32); 190 191 impl SubtreeSet { 192 pub(super) const fn contains(self, subtree: Subtree) -> bool { 193 self.0 & subtree.into_raw() != 0 194 } 195 196 pub(super) const fn is_empty(self) -> bool { 197 self.0 == 0 198 } 199 200 pub(super) const fn intersection(self, other: Self) -> Self { 201 Self(self.0 & other.0) 202 } 203 204 /// Returns one more than the highest index in this set, or `0` for an empty set. An MSI-X 205 /// allocation that covers the set needs this many entries. 206 pub(super) const fn span(self) -> u32 { 207 u32::BITS - self.0.leading_zeros() 208 } 209 210 /// Returns the subtrees of this set, lowest index first. 211 pub(super) fn iter(self) -> impl Iterator<Item = Subtree> { 212 (0..u32::BITS) 213 .map(Subtree::new) 214 .filter(move |subtree| self.contains(*subtree)) 215 } 216 } 217 218 impl From<Subtree> for SubtreeSet { 219 fn from(subtree: Subtree) -> Self { 220 Self(subtree.into_raw()) 221 } 222 } 223 224 impl From<Bounded<u32, 32>> for SubtreeSet { 225 fn from(subtrees: Bounded<u32, 32>) -> Self { 226 Self(subtrees.get()) 227 } 228 } 229 230 impl From<SubtreeSet> for Bounded<u32, 32> { 231 fn from(subtrees: SubtreeSet) -> Self { 232 subtrees.0.into() 233 } 234 } 235 236 /// A GIN interrupt vector, bounded to the widest tree that any supported chipset implements. 237 #[derive(Clone, Copy, Debug, Eq, PartialEq)] 238 pub(super) struct GinVector(Bounded<u32, VECTOR_BITS>); 239 240 impl GinVector { 241 /// Returns vector number `VECTOR`. 242 /// 243 /// Fails to compile if `VECTOR` is beyond the widest supported tree. 244 pub(super) const fn new<const VECTOR: u32>() -> Self { 245 Self(Bounded::<u32, VECTOR_BITS>::new::<VECTOR>()) 246 } 247 248 #[cfg_attr(not(CONFIG_NOVA_CORE_SELFTESTS), expect(dead_code))] 249 pub(super) const fn into_raw(self) -> u32 { 250 self.0.get() 251 } 252 253 /// Returns this vector's leaf. 254 pub(super) fn leaf_index(self) -> LeafIndex { 255 // CALC: `self.0 / VECTORS_PER_LEAF`. 256 self.0.shr::<{ VECTORS_PER_LEAF.ilog2() }, _>().cast() 257 } 258 259 /// Returns this vector's bit within its leaf. 260 pub(super) const fn leaf_mask(self) -> LeafMask { 261 LeafMask(1 << (self.0.get() % VECTORS_PER_LEAF)) 262 } 263 264 /// Returns this vector's subtree. 265 pub(super) const fn subtree(self) -> Subtree { 266 Subtree::new(self.0.get() / (VECTORS_PER_LEAF * LEAVES_PER_SUBTREE)) 267 } 268 269 /// Checks that a tree with `leaves` leaves implements this vector. 270 /// 271 /// # Errors 272 /// 273 /// `EINVAL` if it does not. 274 pub(super) const fn validate(self, leaves: LeafCount) -> Result { 275 if self.0.get() >= leaves.vector_count() { 276 Err(EINVAL) 277 } else { 278 Ok(()) 279 } 280 } 281 } 282 283 impl From<GinVector> for Bounded<u32, TRIGGER_VECTOR_BITS> { 284 fn from(vector: GinVector) -> Self { 285 vector.0.extend() 286 } 287 } 288 289 /// Disables `vectors` in `leaf`. 290 fn clear_leaf_enables(bar: Bar0<'_>, leaf: LeafIndex, vectors: LeafMask) { 291 bar.write( 292 Array::at(*leaf), 293 NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_EN_CLEAR::zeroed().with_vectors(vectors), 294 ); 295 } 296 297 /// Disables the subtrees in `serviced` at `TOP`. 298 fn clear_top_enables(bar: Bar0<'_>, serviced: SubtreeSet) { 299 bar.write_reg(NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_TOP_EN_CLEAR::zeroed().with_subtrees(serviced)); 300 } 301 302 /// The CPU tree of one PCIe function, the subtrees that nova-core services, and the PCI vectors 303 /// that deliver them. 304 /// 305 /// A subtree may be enabled at `TOP` only once a handler is registered on the PCI vector that 306 /// delivers it. See "The serviced-subtree invariant" in 307 /// `Documentation/gpu/nova/core/interrupts.rst`. 308 pub(crate) struct Tree<'a> { 309 bar: Bar0<'a>, 310 hal: &'static dyn CpuInterruptHal, 311 serviced: SubtreeSet, 312 /// The interrupt type that Linux granted for `vectors`. 313 pub(super) msi_type: MsiType, 314 vectors: pci::IrqVectorRegistration<'a>, 315 } 316 317 impl<'a> Tree<'a> { 318 /// Creates the tree of `chipset` and allocates the PCI vectors for the subtrees in `serviced`. 319 /// 320 /// Requests MSI-X entries `0` through the highest subtree in `serviced`, since an allocation 321 /// cannot be sparse, and falls back to a single MSI message for the whole tree. 322 /// 323 /// # Errors 324 /// 325 /// `EINVAL` if `serviced` is empty or names a subtree that `chipset` does not implement. 326 /// Otherwise, when neither interrupt type could be allocated, the error from the MSI request. 327 pub(crate) fn new( 328 pdev: &'a pci::Device<Bound>, 329 bar: Bar0<'a>, 330 chipset: Chipset, 331 serviced: SubtreeSet, 332 ) -> Result<Self> { 333 let hal = cpu_interrupt_hal(chipset); 334 let num_leaves = hal.leaf_count(); 335 336 if serviced.is_empty() || serviced.intersection(num_leaves.subtree_set()) != serviced { 337 return Err(EINVAL); 338 } 339 340 let entries = serviced.span(); 341 let (vectors, msi_type) = pdev 342 .alloc_irq_vectors(entries, entries, IrqType::MsiX.into()) 343 .map(|vectors| (vectors, MsiType::MsiX)) 344 // Every subtree raises the one MSI message, so one MSI vector serves the whole tree. 345 // See "Delivery over PCI" in `Documentation/gpu/nova/core/interrupts.rst`. 346 .or_else(|_| { 347 pdev.alloc_irq_vectors(1, 1, IrqType::Msi.into()) 348 .map(|vectors| (vectors, MsiType::Msi)) 349 })?; 350 351 Ok(Self { 352 bar, 353 hal, 354 serviced, 355 msi_type, 356 vectors, 357 }) 358 } 359 360 /// Returns the [`irq::IrqRequest`] for the PCI vector that delivers `subtree`. 361 /// 362 /// # Errors 363 /// 364 /// `EINVAL` if `subtree` is not one of the serviced subtrees. 365 pub(super) fn request_for(&self, subtree: Subtree) -> Result<irq::IrqRequest<'_>> { 366 if !self.serviced.contains(subtree) { 367 return Err(EINVAL); 368 } 369 370 let entry = match self.msi_type { 371 MsiType::MsiX => num::u32_as_usize(subtree.index()), 372 MsiType::Msi => 0, 373 }; 374 375 self.vectors.index(entry).map(Into::into) 376 } 377 378 /// Rearms PCI interrupt delivery to the CPU after servicing `subtree`, the one subtree that 379 /// the calling handler serves. 380 /// 381 /// A handler must call this before returning, or it receives no further interrupts. 382 pub(super) fn rearm_pci_irq(&self, subtree: Subtree) { 383 self.hal 384 .rearm_pci_irq(self.bar, self.msi_type, self.serviced, subtree); 385 } 386 387 /// Enables the serviced subtrees at `TOP`. 388 /// 389 /// Each of them must have a handler registered on its PCI vector. 390 pub(super) fn enable_top(&self) { 391 self.bar.write_reg( 392 NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_TOP_EN_SET::zeroed().with_subtrees(self.serviced), 393 ); 394 } 395 396 /// Disables the serviced subtrees at `TOP`. 397 pub(super) fn disable_top(&self) { 398 clear_top_enables(self.bar, self.serviced); 399 } 400 401 /// Enables the serviced subtrees at `TOP` until the returned guard drops. 402 pub(crate) fn enable_top_guarded(&self) -> TopEnableGuard<'a> { 403 self.enable_top(); 404 405 TopEnableGuard { 406 bar: self.bar, 407 serviced: self.serviced, 408 } 409 } 410 411 /// Enables `vectors` in `leaf`. 412 pub(super) fn enable_leaf(&self, leaf: LeafIndex, vectors: LeafMask) { 413 self.bar.write( 414 Array::at(*leaf), 415 NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_EN_SET::zeroed().with_vectors(vectors), 416 ); 417 } 418 419 /// Disables `vectors` in `leaf`. 420 pub(super) fn disable_leaf(&self, leaf: LeafIndex, vectors: LeafMask) { 421 clear_leaf_enables(self.bar, leaf, vectors); 422 } 423 424 /// Enables `vectors` in `leaf` until the returned guard drops. 425 pub(super) fn enable_leaf_guarded( 426 &self, 427 leaf: LeafIndex, 428 vectors: LeafMask, 429 ) -> LeafEnableGuard<'a> { 430 self.enable_leaf(leaf, vectors); 431 432 LeafEnableGuard { 433 bar: self.bar, 434 leaf, 435 vectors, 436 } 437 } 438 439 /// Reads the pending bits of `leaf`, and returns the handle that clears them. 440 pub(super) fn read_pending(&self, leaf: LeafIndex) -> LeafPending<'a> { 441 let pending = self 442 .bar 443 .read(NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF::at(*leaf)) 444 .vectors(); 445 446 LeafPending { 447 bar: self.bar, 448 leaf, 449 pending, 450 } 451 } 452 453 /// Sets the pending bit of `vector` in its leaf, as if the vector's source had raised it. 454 /// 455 /// # Errors 456 /// 457 /// `EINVAL` if this tree does not implement `vector`. 458 #[cfg_attr(not(CONFIG_NOVA_CORE_SELFTESTS), expect(dead_code))] 459 pub(super) fn trigger(&self, vector: GinVector) -> Result { 460 vector.validate(self.hal.leaf_count())?; 461 self.bar.write_reg( 462 NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_TRIGGER::zeroed().with_vector(vector), 463 ); 464 465 Ok(()) 466 } 467 468 /// Disables every vector in every implemented leaf, including the subtrees that nova-core does 469 /// not service. Call this only during probe. 470 pub(super) fn disable_all_leaves(&self) { 471 for leaf in self.hal.leaf_count().iter() { 472 self.disable_leaf(leaf, LeafMask::all()); 473 } 474 } 475 476 /// Clears every pending bit in every implemented leaf, including the subtrees that nova-core 477 /// does not service. 478 /// 479 /// The serviced subtrees are disabled at `TOP` on return. Call this only during probe, with no 480 /// interrupt handler registered. 481 pub(super) fn drain(&self) { 482 self.disable_top(); 483 484 // A vector that latched while disabled does not show in `TOP`, so read every leaf rather 485 // than descending from it. 486 for leaf in self.hal.leaf_count().iter() { 487 self.read_pending(leaf).clear(); 488 } 489 } 490 491 /// Disables every vector, clears every pending bit, and rearms PCI interrupt delivery. 492 /// 493 /// The serviced subtrees are disabled at `TOP` on return. Call this only during probe, with 494 /// no interrupt handler registered. 495 pub(super) fn reset(&self) { 496 self.disable_all_leaves(); 497 self.drain(); 498 for subtree in self.serviced.iter() { 499 self.rearm_pci_irq(subtree); 500 } 501 502 // A `TOP`-enable rearm leaves the subtrees that it cycles enabled, and a subtree may be 503 // enabled only once a handler is registered on its vector. 504 self.disable_top(); 505 } 506 } 507 508 /// The pending bits of one leaf as they were read, and the handle that clears them. 509 pub(super) struct LeafPending<'a> { 510 bar: Bar0<'a>, 511 leaf: LeafIndex, 512 pending: LeafMask, 513 } 514 515 impl LeafPending<'_> { 516 pub(super) fn vectors(&self) -> LeafMask { 517 self.pending 518 } 519 520 /// Clears the vectors that were pending at the read. A vector that latched since stays pending. 521 pub(super) fn clear(&self) { 522 self.clear_vectors(self.pending); 523 } 524 525 /// Clears `vectors` and no other bit. 526 pub(super) fn clear_vectors(&self, vectors: LeafMask) { 527 if !vectors.is_empty() { 528 self.bar.write( 529 Array::at(*self.leaf), 530 NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF::zeroed().with_vectors(vectors), 531 ); 532 } 533 } 534 } 535 536 /// Disables a set of vectors in one leaf when dropped. 537 pub(super) struct LeafEnableGuard<'a> { 538 bar: Bar0<'a>, 539 leaf: LeafIndex, 540 vectors: LeafMask, 541 } 542 543 impl Drop for LeafEnableGuard<'_> { 544 fn drop(&mut self) { 545 clear_leaf_enables(self.bar, self.leaf, self.vectors); 546 } 547 } 548 549 /// Disables the serviced subtrees at `TOP` when dropped. 550 pub(crate) struct TopEnableGuard<'a> { 551 bar: Bar0<'a>, 552 serviced: SubtreeSet, 553 } 554 555 impl Drop for TopEnableGuard<'_> { 556 fn drop(&mut self) { 557 clear_top_enables(self.bar, self.serviced); 558 } 559 } 560 561 #[kunit_tests(nova_core_gin_tree)] 562 mod tests { 563 use super::*; 564 565 /// A leaf index cannot name a leaf beyond the widest supported tree. 566 #[test] 567 fn leaf_index_bounds() { 568 assert!(LeafIndex::try_new(0).is_some()); 569 assert!(LeafIndex::try_new(15).is_some()); 570 assert!(LeafIndex::try_new(16).is_none()); 571 } 572 573 /// The subtree count, the implemented-subtree set, and the vector count follow the leaf count. 574 #[test] 575 fn leaf_count_derives_subtrees_and_vectors() { 576 assert_eq!(LeafCount::Eight.subtree_count(), 4); 577 assert_eq!( 578 Bounded::<u32, 32>::from(LeafCount::Eight.subtree_set()).get(), 579 0x0f 580 ); 581 assert_eq!(LeafCount::Eight.vector_count(), 256); 582 583 assert_eq!(LeafCount::Sixteen.subtree_count(), 8); 584 assert_eq!( 585 Bounded::<u32, 32>::from(LeafCount::Sixteen.subtree_set()).get(), 586 0xff 587 ); 588 assert_eq!(LeafCount::Sixteen.vector_count(), 512); 589 } 590 591 /// A tree enumerates every leaf that it implements, in order, and no more. 592 #[test] 593 fn leaf_count_iter_covers_the_tree() { 594 for (count, expected) in [(LeafCount::Eight, 8usize), (LeafCount::Sixteen, 16)] { 595 let mut seen = 0; 596 597 for (index, leaf) in count.iter().enumerate() { 598 assert_eq!(leaf.get(), index); 599 seen += 1; 600 } 601 602 assert_eq!(seen, expected); 603 } 604 } 605 606 /// A vector maps to its leaf, its bit within that leaf, and its subtree. The doorbell (129) 607 /// and the GSP event (155) share a subtree. 608 #[test] 609 fn vector_maps_to_leaf_bit_and_subtree() { 610 let doorbell = GinVector::new::<129>(); 611 let gsp = GinVector::new::<155>(); 612 613 assert_eq!(doorbell.leaf_index().get(), 4); 614 assert_eq!(doorbell.leaf_mask().into_raw(), 1 << 1); 615 assert_eq!(doorbell.subtree().index(), 2); 616 617 assert_eq!(gsp.leaf_index().get(), 4); 618 assert_eq!(gsp.leaf_mask().into_raw(), 1 << 27); 619 assert_eq!(gsp.subtree().index(), 2); 620 621 assert_eq!(doorbell.subtree(), gsp.subtree()); 622 } 623 624 /// Both fixed vectors are within the 8-leaf tree, so every supported chipset implements them. 625 #[test] 626 fn fixed_vectors_fit_the_narrowest_tree() { 627 assert!(GinVector::new::<129>().validate(LeafCount::Eight).is_ok()); 628 assert!(GinVector::new::<155>().validate(LeafCount::Eight).is_ok()); 629 630 // The first vector beyond an 8-leaf tree. 631 assert!(GinVector::new::<256>().validate(LeafCount::Eight).is_err()); 632 assert!(GinVector::new::<256>().validate(LeafCount::Sixteen).is_ok()); 633 } 634 635 /// A subtree set reports membership, intersection, and its span from subtree 0. 636 #[test] 637 fn subtree_set_operations() { 638 let gsp = GinVector::new::<155>().subtree(); 639 640 assert!(LeafCount::Eight.subtree_set().contains(gsp)); 641 assert!(!LeafCount::Eight.subtree_set().is_empty()); 642 643 // The GSP needs no subtree above 2, so an MSI-X request covers entries 0 through 2. 644 assert_eq!(SubtreeSet::from(gsp).span(), 3); 645 646 // A 16-leaf tree implements every subtree that an 8-leaf tree does. 647 assert_eq!( 648 LeafCount::Sixteen 649 .subtree_set() 650 .intersection(LeafCount::Eight.subtree_set()), 651 LeafCount::Eight.subtree_set() 652 ); 653 } 654 655 /// Iterating a subtree set yields each subtree once, lowest index first, and nothing for an 656 /// empty set. 657 #[test] 658 fn subtree_set_iterates_its_members() { 659 assert!(LeafCount::Eight 660 .subtree_set() 661 .iter() 662 .map(Subtree::index) 663 .eq([0u32, 1, 2, 3])); 664 665 let gsp = SubtreeSet::from(GinVector::new::<155>().subtree()); 666 assert!(gsp.iter().map(Subtree::index).eq([2u32])); 667 668 let empty = SubtreeSet::from(Bounded::<u32, 32>::new::<0>()); 669 assert_eq!(empty.iter().count(), 0); 670 } 671 672 /// Every supported chipset implements the subtree that carries the GSP event. 673 #[test] 674 fn gsp_subtree_is_implemented_everywhere() { 675 for &chipset in Chipset::ALL { 676 assert!(cpu_interrupt_hal(chipset) 677 .leaf_count() 678 .subtree_set() 679 .contains(crate::irq::gsp::GSP_SUBTREE)); 680 } 681 } 682 } 683