struct PciHotPlugWorker {
event_map: BTreeMap<RawDescriptor, (Event, PciAddress)>,
port_state_map: BTreeMap<PciAddress, PortState>,
port_map: BTreeMap<PortKey, PortWorkerStub>,
manager_evt: Event,
wait_ctx: WaitContext<Token>,
command_receiver: Receiver<WorkerCommand>,
response_sender: Sender<WorkerResponse>,
rootbus_controller: Sender<PciRootCommand>,
}Expand description
PciHotPlugWorker is a worker that handles the asynchrony of slot states between crosvm and the guest OS. It is responsible for scheduling the PCIe slot control signals and handle its result.
Fields§
§event_map: BTreeMap<RawDescriptor, (Event, PciAddress)>§port_state_map: BTreeMap<PciAddress, PortState>§port_map: BTreeMap<PortKey, PortWorkerStub>§manager_evt: Event§wait_ctx: WaitContext<Token>§command_receiver: Receiver<WorkerCommand>§response_sender: Sender<WorkerResponse>§rootbus_controller: Sender<PciRootCommand>Implementations§
Source§impl PciHotPlugWorker
impl PciHotPlugWorker
fn new( rootbus_controller: Sender<PciRootCommand>, command_receiver: Receiver<WorkerCommand>, response_sender: Sender<WorkerResponse>, manager_evt: Event, kill_evt: &Event, ) -> Result<Self, Error>
Sourcefn run(&mut self, kill_evt: Event) -> Result<(), Error>
fn run(&mut self, kill_evt: Event) -> Result<(), Error>
Starts the worker. Runs until received kill request, or an error that the worker is in an invalid state.
fn handle_manager_command(&mut self) -> Result<(), Error>
Sourcefn handle_add_port(
&mut self,
pci_address: PciAddress,
port: PortWorkerStub,
) -> Result<WorkerResponse, Error>
fn handle_add_port( &mut self, pci_address: PciAddress, port: PortWorkerStub, ) -> Result<WorkerResponse, Error>
Handles add port: Initiate port in EmptyNotReady state.
Sourcefn handle_get_port_state(
&self,
pci_address: PciAddress,
) -> Result<WorkerResponse, Error>
fn handle_get_port_state( &self, pci_address: PciAddress, ) -> Result<WorkerResponse, Error>
Handles get port state: returns the PortState.
Sourcefn handle_get_empty_port(&self) -> Result<WorkerResponse, Error>
fn handle_get_empty_port(&self) -> Result<WorkerResponse, Error>
Handle getting empty port: Find the most empty port, or return error if all are occupied.
Sourcefn handle_plug_request(
&mut self,
hotplug_command: SignalHotPlugCommand,
) -> Result<WorkerResponse, Error>
fn handle_plug_request( &mut self, hotplug_command: SignalHotPlugCommand, ) -> Result<WorkerResponse, Error>
Handles plug request: Moves PortState from EmptyNotReady to OccupiedNotReady, Empty(n) to Occupied(n+1), and schedules the next plug event if n == 0.
Sourcefn handle_unplug_request(
&mut self,
pci_address: PciAddress,
) -> Result<WorkerResponse, Error>
fn handle_unplug_request( &mut self, pci_address: PciAddress, ) -> Result<WorkerResponse, Error>
Handles unplug request: Moves PortState from OccupiedNotReady to EmptyNotReady, Occupied(n) to Empty(n % 2 + 1), and schedules the next unplug event if n == 0.
n % 2 + 1: When unplug request is made, it either schedule the unplug event (n == 0 => 1 or n == 1 => 2), or cancels the corresponding plug event that has not started (n == 2 => 1 or n == 3 => 2). Staring at the mapping, it maps n to either 1 or 2 of opposite oddity. n % 2 + 1 is a good shorthand instead of the individual mappings.
Sourcefn handle_port_ready(&mut self, pci_address: PciAddress) -> Result<(), Error>
fn handle_port_ready(&mut self, pci_address: PciAddress) -> Result<(), Error>
Handles port ready: Moves PortState from EmptyNotReady to Empty(0), OccupiedNotReady to Occupied(1), and schedules the next event if port is occupied
Sourcefn handle_plug_complete(&mut self, pci_address: PciAddress) -> Result<(), Error>
fn handle_plug_complete(&mut self, pci_address: PciAddress) -> Result<(), Error>
Handles plug complete: Moves PortState from Any(n) to Any(n-1), and schedules the next unplug event unless n == 1. (Any is either Empty or Occupied.)
Sourcefn handle_unplug_complete(
&mut self,
pci_address: PciAddress,
) -> Result<(), Error>
fn handle_unplug_complete( &mut self, pci_address: PciAddress, ) -> Result<(), Error>
Handles unplug complete: Moves PortState from Any(n) to Any(n-1), and schedules the next plug event unless n == 1. (Any is either Empty or Occupied.)