2019-03-07 13:56:43 +00:00
|
|
|
// 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
|
2019-05-08 10:22:53 +00:00
|
|
|
// found in the LICENSE-BSD-3-Clause file.
|
2019-03-07 13:56:43 +00:00
|
|
|
|
|
|
|
//! Emulates virtual and hardware devices.
|
|
|
|
extern crate byteorder;
|
|
|
|
extern crate epoll;
|
2019-06-12 08:12:45 +00:00
|
|
|
extern crate kvm_bindings;
|
|
|
|
extern crate kvm_ioctls;
|
2019-03-07 13:56:43 +00:00
|
|
|
extern crate libc;
|
2019-06-12 08:12:45 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2019-03-07 13:56:43 +00:00
|
|
|
extern crate vm_memory;
|
|
|
|
extern crate vmm_sys_util;
|
|
|
|
|
|
|
|
use std::fs::File;
|
2019-06-11 17:49:19 +00:00
|
|
|
use std::{io, result};
|
2019-03-07 13:56:43 +00:00
|
|
|
|
2019-09-03 13:54:06 +00:00
|
|
|
#[cfg(feature = "acpi")]
|
2019-08-29 13:58:25 +00:00
|
|
|
mod acpi;
|
2019-03-07 13:56:43 +00:00
|
|
|
mod bus;
|
2019-06-12 08:12:45 +00:00
|
|
|
pub mod ioapic;
|
2019-03-07 13:56:43 +00:00
|
|
|
pub mod legacy;
|
|
|
|
|
2019-09-03 13:54:06 +00:00
|
|
|
#[cfg(feature = "acpi")]
|
2019-08-29 13:58:25 +00:00
|
|
|
pub use self::acpi::AcpiShutdownDevice;
|
2019-03-07 13:56:43 +00:00
|
|
|
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),
|
|
|
|
}
|
2019-06-11 17:49:19 +00:00
|
|
|
|
|
|
|
pub trait Interrupt: Send {
|
|
|
|
fn deliver(&self) -> result::Result<(), std::io::Error>;
|
|
|
|
}
|