From bf4ef0ca83cf333e308cdeed2929ad659d62d40e Mon Sep 17 00:00:00 2001 From: Rajas Paranjpe <52586855+ChocolateLoverRaj@users.noreply.github.com> Date: Sat, 19 Sep 2026 11:51:16 -0700 Subject: [PATCH] Create `pci_routing::Pin::from_pci_interrupt_pin` convenience fn. Tested on QEMU q35. --- src/aml/pci_routing.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/aml/pci_routing.rs b/src/aml/pci_routing.rs index 47df1b13..7259a8ee 100644 --- a/src/aml/pci_routing.rs +++ b/src/aml/pci_routing.rs @@ -21,6 +21,24 @@ pub enum Pin { IntD, } +#[derive(Debug, Clone, Copy)] +pub struct InvalidPciInterruptPinError(pub u8); + +impl Pin { + /// If the PCI interrupt pin is `0`, that means that the PCI device doesn't use an interrupt pin, + /// and `Ok(None)` will be returned. + pub fn from_pci_interrupt_pin(pin: u8) -> Result, InvalidPciInterruptPinError> { + match pin { + 0 => Ok(None), + 1 => Ok(Some(Self::IntA)), + 2 => Ok(Some(Self::IntB)), + 3 => Ok(Some(Self::IntC)), + 4 => Ok(Some(Self::IntD)), + pin => Err(InvalidPciInterruptPinError(pin)), + } + } +} + #[derive(Debug)] pub enum PciRouteType { /// The interrupt is hard-coded to a specific GSI