mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-09-12 01:54:55 +00:00
The goal for cloud-hypervisor is to keep the host safe. With this in mind, we want to emulate as much as possible in userspace instead of in kernel directly. The IOAPIC is a good candidate to move from kernel to userspace, which is why this commit introduces a userspace implementation of the IOAPIC 82093AA based on the documentation: https://pdos.csail.mit.edu/6.828/2016/readings/ia32/ioapic.pdf This code is inspired from the files devices/src/ioapic.rs and devices/src/split_irqchip_common.rs from the crosvm codebase. The reference version used being 6c1e23eee3065b3f3d6fc4fb992ac9884dbabf68. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
69 lines
1.6 KiB
Rust
69 lines
1.6 KiB
Rust
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
// Portions Copyright 2017 The Chromium OS Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE-BSD-3-Clause file.
|
|
|
|
//! Emulates virtual and hardware devices.
|
|
extern crate byteorder;
|
|
extern crate epoll;
|
|
extern crate kvm_bindings;
|
|
extern crate kvm_ioctls;
|
|
extern crate libc;
|
|
#[macro_use]
|
|
extern crate log;
|
|
extern crate vm_memory;
|
|
extern crate vmm_sys_util;
|
|
|
|
use std::fs::File;
|
|
use std::{io, result};
|
|
|
|
mod bus;
|
|
pub mod ioapic;
|
|
pub mod legacy;
|
|
|
|
pub use self::bus::{Bus, BusDevice, Error as BusError};
|
|
|
|
pub type DeviceEventT = u16;
|
|
|
|
/// The payload is used to handle events where the internal state of the VirtIO device
|
|
/// needs to be changed.
|
|
pub enum EpollHandlerPayload {
|
|
/// DrivePayload(disk_image)
|
|
DrivePayload(File),
|
|
/// Events that do not need a payload.
|
|
Empty,
|
|
}
|
|
|
|
type Result<T> = std::result::Result<T, Error>;
|
|
|
|
pub trait EpollHandler: Send {
|
|
fn handle_event(
|
|
&mut self,
|
|
device_event: DeviceEventT,
|
|
event_flags: u32,
|
|
payload: EpollHandlerPayload,
|
|
) -> Result<()>;
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum Error {
|
|
FailedReadingQueue {
|
|
event_type: &'static str,
|
|
underlying: io::Error,
|
|
},
|
|
FailedReadTap,
|
|
FailedSignalingUsedQueue(io::Error),
|
|
PayloadExpected,
|
|
UnknownEvent {
|
|
device: &'static str,
|
|
event: DeviceEventT,
|
|
},
|
|
IoError(io::Error),
|
|
}
|
|
|
|
pub trait Interrupt: Send {
|
|
fn deliver(&self) -> result::Result<(), std::io::Error>;
|
|
}
|