From 838224db45a8f6f14fba5ab3501f2f9068da6de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 4 Jun 2024 18:26:58 +0200 Subject: [PATCH] feat: add `EndpointHeader::update_interrupt` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 3b499da..86e82a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -398,6 +398,19 @@ impl EndpointHeader { let data = unsafe { access.read(self.0, 0x3c) }; (data.get_bits(8..16) as u8, data.get_bits(0..8) as u8) } + + pub fn update_interrupt(&mut self, access: &impl ConfigRegionAccess, f: F) + where + F: FnOnce((InterruptPin, InterruptLine)) -> (InterruptPin, InterruptLine), + { + let mut data = unsafe { access.read(self.0, 0x3c) }; + let (new_pin, new_line) = f((data.get_bits(8..16) as u8, data.get_bits(0..8) as u8)); + data.set_bits(8..16, new_pin.into()); + data.set_bits(0..8, new_line.into()); + unsafe { + access.write(self.0, 0x3c, data); + } + } } /// PCI-PCI Bridges have a Type-1 header, so the remainder of the header is of the form: