devices/pci/
pci_hotplug.rs

1// Copyright 2023 The ChromiumOS Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! Trait definitions and implementations for PCI hotplug.
6
7#![deny(missing_docs)]
8
9use serde::Deserialize;
10use serde::Serialize;
11
12use crate::IrqLevelEvent;
13use crate::PciAddress;
14use crate::PciDevice;
15use crate::PciDeviceError;
16use crate::PciInterruptPin;
17
18pub type Result<T> = std::result::Result<T, PciDeviceError>;
19
20/// Additional requirements for a PciDevice to support hotplug.
21/// A hotplug device can be configured without access to the SystemAllocator.
22pub trait HotPluggable: PciDevice {
23    /// Sets PciAddress to pci_addr. Replaces allocate_address.
24    fn set_pci_address(&mut self, pci_addr: PciAddress) -> Result<()>;
25
26    /// Configures IO BAR layout without memory alloc. Replaces allocate_io_bars.
27    fn configure_io_bars(&mut self) -> Result<()>;
28
29    /// Configure device BAR layout without memory alloc. Replaces allocate_device_bars.
30    fn configure_device_bars(&mut self) -> Result<()>;
31}
32
33impl<T: HotPluggable + ?Sized> HotPluggable for Box<T> {
34    fn set_pci_address(&mut self, pci_addr: PciAddress) -> Result<()> {
35        (**self).set_pci_address(pci_addr)
36    }
37
38    fn configure_io_bars(&mut self) -> Result<()> {
39        (**self).configure_io_bars()
40    }
41
42    fn configure_device_bars(&mut self) -> Result<()> {
43        (**self).configure_device_bars()
44    }
45}
46
47/// Parameters for legacy INTx interrrupt.
48#[derive(Serialize, Deserialize)]
49pub struct IntxParameter {
50    /// interrupt level event
51    pub irq_evt: IrqLevelEvent,
52    /// INTx interrupt pin
53    pub pin: PciInterruptPin,
54    /// irq num
55    pub irq_num: u32,
56}