Skip to content

Commit

Permalink
despair
Browse files Browse the repository at this point in the history
  • Loading branch information
repnop committed Jul 9, 2024
1 parent 65d1663 commit 2117fb9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
9 changes: 7 additions & 2 deletions src/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<
fn push(&mut self, component: u32) -> Result<(), CollectCellsError> {
let shr = const {
match core::mem::size_of::<Int>().checked_sub(4) {
Some(value) => value as u32,
Some(value) => value as u32 * 8,
None => panic!("integer type too small"),
}
};
Expand Down Expand Up @@ -182,7 +182,7 @@ impl<
/// [PCI Bus Binding to Open Firmware 2.2.1.1 Numerical Representation](https://www.openfirmware.info/data/docs/bus.pci.pdf)
///
/// Numerical representation of a PCI address used within the `interrupt-map` property
#[derive(Debug, Clone, Copy, Default)]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PciAddress {
pub hi: PciAddressHighBits,
pub mid: u32,
Expand Down Expand Up @@ -223,6 +223,11 @@ impl CellCollector for PciAddress {
pub struct PciAddressHighBits(u32);

impl PciAddressHighBits {
#[inline(always)]
pub fn new(raw: u32) -> Self {
Self(raw)
}

#[inline(always)]
pub fn register(self) -> u8 {
self.0 as u8
Expand Down
37 changes: 26 additions & 11 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extern crate std;

use nodes::NodeName;
use properties::{CellSizes, InterruptMap, PciAddress};
use properties::{CellSizes, InterruptMap, PciAddress, PciAddressHighBits};

// use crate::{node::RawReg, *};
use crate::*;
Expand Down Expand Up @@ -266,23 +266,38 @@ fn interrupt_map() {
let fdt = Fdt::new(TEST.as_slice()).unwrap();
let root = fdt.root();

for entry in root
let entries = [
(PciAddress { hi: PciAddressHighBits::new(0), mid: 0, lo: 0 }, 1, None, 32),
(PciAddress { hi: PciAddressHighBits::new(0), mid: 0, lo: 0 }, 2, None, 33),
(PciAddress { hi: PciAddressHighBits::new(0), mid: 0, lo: 0 }, 3, None, 34),
(PciAddress { hi: PciAddressHighBits::new(0), mid: 0, lo: 0 }, 4, None, 35),
(PciAddress { hi: PciAddressHighBits::new(2048), mid: 0, lo: 0 }, 1, None, 33),
(PciAddress { hi: PciAddressHighBits::new(2048), mid: 0, lo: 0 }, 2, None, 34),
(PciAddress { hi: PciAddressHighBits::new(2048), mid: 0, lo: 0 }, 3, None, 35),
(PciAddress { hi: PciAddressHighBits::new(2048), mid: 0, lo: 0 }, 4, None, 32),
(PciAddress { hi: PciAddressHighBits::new(4096), mid: 0, lo: 0 }, 1, None, 34),
(PciAddress { hi: PciAddressHighBits::new(4096), mid: 0, lo: 0 }, 2, None, 35),
(PciAddress { hi: PciAddressHighBits::new(4096), mid: 0, lo: 0 }, 3, None, 32),
(PciAddress { hi: PciAddressHighBits::new(4096), mid: 0, lo: 0 }, 4, None, 33),
(PciAddress { hi: PciAddressHighBits::new(6144), mid: 0, lo: 0 }, 1, None, 35),
(PciAddress { hi: PciAddressHighBits::new(6144), mid: 0, lo: 0 }, 2, None, 32),
(PciAddress { hi: PciAddressHighBits::new(6144), mid: 0, lo: 0 }, 3, None, 33),
(PciAddress { hi: PciAddressHighBits::new(6144), mid: 0, lo: 0 }, 4, None, 34),
];

for (entry, expected) in root
.find_node("/soc/pci")
.unwrap()
.property::<InterruptMap<PciAddress, u64, Option<u64>, u64, (AlignedParser<'_>, Panic)>>()
.unwrap()
.iter()
.zip(entries)
{
std::println!(
"{:?} {} {:?} {}",
entry.child_unit_address(),
entry.child_interrupt_specifier(),
entry.parent_unit_address(),
entry.parent_interrupt_specifier()
);
assert_eq!(entry.child_unit_address(), expected.0);
assert_eq!(entry.child_interrupt_specifier(), expected.1);
assert_eq!(entry.parent_unit_address(), expected.2);
assert_eq!(entry.parent_interrupt_specifier(), expected.3);
}

panic!()
}

// #[test]
Expand Down

0 comments on commit 2117fb9

Please sign in to comment.