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.
|
2021-05-11 14:48:02 +00:00
|
|
|
|
2020-01-14 10:17:23 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate bitflags;
|
2019-06-12 08:12:45 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2019-03-07 13:56:43 +00:00
|
|
|
|
2021-01-20 15:32:10 +00:00
|
|
|
pub mod acpi;
|
2020-05-25 08:59:09 +00:00
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
pub mod gic;
|
2020-05-25 08:27:08 +00:00
|
|
|
pub mod interrupt_controller;
|
2020-05-25 08:59:09 +00:00
|
|
|
#[cfg(target_arch = "x86_64")]
|
2019-06-12 08:12:45 +00:00
|
|
|
pub mod ioapic;
|
2019-03-07 13:56:43 +00:00
|
|
|
pub mod legacy;
|
2022-09-12 20:46:03 +00:00
|
|
|
pub mod tpm;
|
2019-03-07 13:56:43 +00:00
|
|
|
|
2021-03-25 17:01:21 +00:00
|
|
|
pub use self::acpi::{AcpiGedDevice, AcpiPmTimerDevice, AcpiShutdownDevice};
|
2019-06-11 17:49:19 +00:00
|
|
|
|
2020-01-14 10:17:23 +00:00
|
|
|
bitflags! {
|
2021-01-12 15:10:05 +00:00
|
|
|
pub struct AcpiNotificationFlags: u8 {
|
2020-01-14 10:17:23 +00:00
|
|
|
const NO_DEVICES_CHANGED = 0;
|
|
|
|
const CPU_DEVICES_CHANGED = 0b1;
|
|
|
|
const MEMORY_DEVICES_CHANGED = 0b10;
|
2020-02-27 13:50:52 +00:00
|
|
|
const PCI_DEVICES_CHANGED = 0b100;
|
2021-01-13 09:57:29 +00:00
|
|
|
const POWER_BUTTON_CHANGED = 0b1000;
|
2020-01-14 10:17:23 +00:00
|
|
|
}
|
2019-11-27 15:27:09 +00:00
|
|
|
}
|
2021-03-07 11:31:07 +00:00
|
|
|
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
macro_rules! generate_read_fn {
|
|
|
|
($fn_name: ident, $data_type: ty, $byte_type: ty, $type_size: expr, $endian_type: ident) => {
|
|
|
|
pub fn $fn_name(input: &[$byte_type]) -> $data_type {
|
|
|
|
assert!($type_size == std::mem::size_of::<$data_type>());
|
|
|
|
let mut array = [0u8; $type_size];
|
|
|
|
for (byte, read) in array.iter_mut().zip(input.iter().cloned()) {
|
|
|
|
*byte = read as u8;
|
|
|
|
}
|
|
|
|
<$data_type>::$endian_type(array)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
macro_rules! generate_write_fn {
|
|
|
|
($fn_name: ident, $data_type: ty, $byte_type: ty, $endian_type: ident) => {
|
|
|
|
pub fn $fn_name(buf: &mut [$byte_type], n: $data_type) {
|
|
|
|
for (byte, read) in buf
|
|
|
|
.iter_mut()
|
|
|
|
.zip(<$data_type>::$endian_type(n).iter().cloned())
|
|
|
|
{
|
|
|
|
*byte = read as $byte_type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
generate_read_fn!(read_le_u16, u16, u8, 2, from_le_bytes);
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
generate_read_fn!(read_le_u32, u32, u8, 4, from_le_bytes);
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
generate_read_fn!(read_le_u64, u64, u8, 8, from_le_bytes);
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
generate_read_fn!(read_le_i32, i32, i8, 4, from_le_bytes);
|
|
|
|
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
generate_read_fn!(read_be_u16, u16, u8, 2, from_be_bytes);
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
generate_read_fn!(read_be_u32, u32, u8, 4, from_be_bytes);
|
|
|
|
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
generate_write_fn!(write_le_u16, u16, u8, to_le_bytes);
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
generate_write_fn!(write_le_u32, u32, u8, to_le_bytes);
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
generate_write_fn!(write_le_u64, u64, u8, to_le_bytes);
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
generate_write_fn!(write_le_i32, i32, i8, to_le_bytes);
|
|
|
|
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
generate_write_fn!(write_be_u16, u16, u8, to_be_bytes);
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
generate_write_fn!(write_be_u32, u32, u8, to_be_bytes);
|