Skip to content

Commit 4f42a7e

Browse files
committed
arch: doc for public facing content
The #![deny(missing_docs)] is now on for this crate. Signed-off-by: Diana Popa <[email protected]>
1 parent 99a0267 commit 4f42a7e

File tree

11 files changed

+56
-49
lines changed

11 files changed

+56
-49
lines changed

api_server/src/request/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,7 @@ mod tests {
296296
{
297297
let vmm_resp = VmmActionError::StartMicrovm(
298298
ErrorKind::Internal,
299-
StartMicrovmError::ConfigureSystem(arch::Error::X86_64Setup(
300-
arch::x86_64::Error::ZeroPagePastRamEnd,
301-
)),
299+
StartMicrovmError::ConfigureSystem(arch::Error::ZeroPagePastRamEnd),
302300
);
303301
check_error_response(vmm_resp, StatusCode::InternalServerError);
304302
}

arch/src/aarch64/fdt.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,37 @@ extern "C" {
5555
fn fdt_pack(fdt: *mut c_void) -> c_int;
5656
}
5757

58+
/// Trait for devices to be added to the Flattened Device Tree.
5859
pub trait DeviceInfoForFDT {
60+
/// Returns the address where this device will be loaded.
5961
fn addr(&self) -> u64;
62+
/// Returns the associated interrupt for this device.
6063
fn irq(&self) -> u32;
64+
/// Returns the amount of memory that needs to be reserved for this device.
6165
fn length(&self) -> u64;
6266
}
6367

68+
/// Errors thrown while configuring the Flattened Device Tree for aarch64.
6469
#[derive(Debug)]
6570
pub enum Error {
71+
/// Failed to append node to the FDT.
6672
AppendFDTNode(io::Error),
73+
/// Failed to append a property to the FDT.
6774
AppendFDTProperty(io::Error),
75+
/// Syscall for creating FDT failed.
6876
CreateFDT(io::Error),
77+
/// Failed to obtain a C style string.
6978
CstringFDTTransform(NulError),
79+
/// Failure in calling syscall for terminating this FDT.
7080
FinishFDTReserveMap(io::Error),
81+
/// FDT was partially written to memory.
7182
IncompleteFDTMemoryWrite,
83+
/// Failure in writing FDT in memory.
7284
WriteFDTToMemory(GuestMemoryError),
7385
}
86+
type Result<T> = result::Result<T, Error>;
7487

75-
pub type Result<T> = result::Result<T, Error>;
76-
77-
// Creates the flattened device tree for this VM.
88+
/// Creates the flattened device tree for this aarch64 microVM.
7889
pub fn create_fdt<T: DeviceInfoForFDT + Clone + Debug>(
7990
guest_mem: &GuestMemory,
8091
num_cpus: u32,

arch/src/aarch64/gic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ const SZ_64K: u64 = 0x0001_0000;
1111
const KVM_VGIC_V3_DIST_SIZE: u64 = SZ_64K;
1212
const KVM_VGIC_V3_REDIST_SIZE: u64 = (2 * SZ_64K);
1313

14+
/// Errors thrown while setting up the GIC.
1415
#[derive(Debug)]
1516
pub enum Error {
1617
/// Error while calling KVM ioctl for setting up the global interrupt controller.
1718
CreateGIC(io::Error),
1819
/// Error while setting device attributes for the GIC.
1920
SetDeviceAttribute(io::Error),
2021
}
21-
22-
pub type Result<T> = result::Result<T, Error>;
22+
type Result<T> = result::Result<T, Error>;
2323

2424
/// Create a GICv3 device.
2525
///

arch/src/aarch64/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
mod fdt;
5+
/// Module for the global interrupt controller configuration.
56
pub mod gic;
7+
/// Layout for this aarch64 system.
68
pub mod layout;
9+
/// Logic for configuring aarch64 registers.
710
pub mod regs;
811

912
use std::cmp::min;
@@ -13,17 +16,13 @@ use std::fmt::Debug;
1316

1417
use memory_model::{GuestAddress, GuestMemory};
1518

19+
/// Errors thrown while configuring aarch64 system.
1620
#[derive(Debug)]
1721
pub enum Error {
22+
/// Failed to create a Flattened Device Tree for this aarch64 microVM.
1823
SetupFDT(fdt::Error),
1924
}
2025

21-
impl From<Error> for super::Error {
22-
fn from(e: Error) -> super::Error {
23-
super::Error::Aarch64Setup(e)
24-
}
25-
}
26-
2726
pub use self::fdt::DeviceInfoForFDT;
2827
use DeviceType;
2928

arch/src/aarch64/regs.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ use super::get_fdt_addr;
1313
use kvm_bindings::{user_pt_regs, KVM_REG_ARM64, KVM_REG_ARM_CORE, KVM_REG_SIZE_U64};
1414
use memory_model::GuestMemory;
1515

16+
/// Errors thrown while setting aarch64 registers.
1617
#[derive(Debug)]
1718
pub enum Error {
19+
/// Failed to set core register (PC, PSTATE or general purpose ones).
1820
SetCoreRegister(io::Error),
1921
}
20-
21-
pub type Result<T> = result::Result<T, Error>;
22+
type Result<T> = result::Result<T, Error>;
2223

2324
#[allow(non_upper_case_globals)]
2425
// PSR (Processor State Register) bits.

arch/src/lib.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#![deny(missing_docs)]
5+
//! Implements platform specific functionality.
6+
//! Supported platforms: x86_64 and aarch64.
47
extern crate byteorder;
58
extern crate kvm_bindings;
69
extern crate kvm_ioctls;
@@ -12,41 +15,38 @@ extern crate memory_model;
1215
use std::fmt;
1316
use std::result;
1417

15-
#[derive(Debug)]
16-
pub enum Error {
17-
#[cfg(target_arch = "aarch64")]
18-
/// aarch64 specific error triggered during system configuration.
19-
Aarch64Setup(aarch64::Error),
20-
#[cfg(target_arch = "x86_64")]
21-
/// X86_64 specific error triggered during system configuration.
22-
X86_64Setup(x86_64::Error),
23-
}
24-
pub type Result<T> = result::Result<T, Error>;
25-
18+
/// Module for aarch64 related functionality.
2619
#[cfg(target_arch = "aarch64")]
2720
pub mod aarch64;
2821

2922
#[cfg(target_arch = "aarch64")]
3023
pub use aarch64::{
3124
arch_memory_regions, configure_system, get_kernel_start, get_reserved_mem_addr,
32-
layout::CMDLINE_MAX_SIZE, layout::IRQ_BASE, layout::IRQ_MAX,
25+
layout::CMDLINE_MAX_SIZE, layout::IRQ_BASE, layout::IRQ_MAX, Error,
3326
};
3427

28+
/// Module for x86_64 related functionality.
3529
#[cfg(target_arch = "x86_64")]
3630
pub mod x86_64;
3731

3832
#[cfg(target_arch = "x86_64")]
3933
pub use x86_64::{
4034
arch_memory_regions, configure_system, get_32bit_gap_start as get_reserved_mem_addr,
41-
get_kernel_start, layout::CMDLINE_MAX_SIZE, layout::IRQ_BASE, layout::IRQ_MAX,
35+
get_kernel_start, layout::CMDLINE_MAX_SIZE, layout::IRQ_BASE, layout::IRQ_MAX, Error,
4236
};
4337

38+
/// Type for returning public functions outcome.
39+
pub type Result<T> = result::Result<T, Error>;
40+
4441
/// Types of devices that can get attached to this platform.
4542
#[derive(Clone, Debug, PartialEq, Eq, Hash, Copy)]
4643
pub enum DeviceType {
44+
/// Device Type: Virtio.
4745
Virtio(u32),
46+
/// Device Type: Serial.
4847
#[cfg(target_arch = "aarch64")]
4948
Serial,
49+
/// Device Type: RTC.
5050
#[cfg(target_arch = "aarch64")]
5151
RTC,
5252
}

arch/src/x86_64/interrupts.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
1313
use kvm_bindings::kvm_lapic_state;
1414
use kvm_ioctls::VcpuFd;
1515

16+
/// Errors thrown while configuring the LAPIC.
1617
#[derive(Debug)]
1718
pub enum Error {
19+
/// Failure in retrieving the LAPIC configuration.
1820
GetLapic(io::Error),
21+
/// Failure in modifying the LAPIC configuration.
1922
SetLapic(io::Error),
2023
}
21-
22-
pub type Result<T> = result::Result<T, Error>;
24+
type Result<T> = result::Result<T, Error>;
2325

2426
// Defines poached from apicdef.h kernel header.
2527
const APIC_LVT0: usize = 0x350;

arch/src/x86_64/layout.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
/// Magic addresses externally used to lay out x86_64 VMs.
99
1010
/// Initial stack for the boot CPU.
11-
pub const BOOT_STACK_START: usize = 0x8000;
1211
pub const BOOT_STACK_POINTER: usize = 0x8ff0;
1312

1413
/// Kernel command line start address.

arch/src/x86_64/mod.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
// found in the THIRD-PARTY file.
77

88
mod gdt;
9+
/// Contains logic for setting up Advanced Programmable Interrupt Controller (local version).
910
pub mod interrupts;
11+
/// Layout for the x86_64 system.
1012
pub mod layout;
1113
mod mptable;
14+
/// Logic for configuring x86_64 registers.
1215
pub mod regs;
1316

1417
use std::mem;
@@ -27,6 +30,7 @@ struct BootParamsWrapper(boot_params);
2730
// It is safe to initialize BootParamsWrap which is a wrapper over `boot_params` (a series of ints).
2831
unsafe impl DataInit for BootParamsWrapper {}
2932

33+
/// Errors thrown while configuring x86_64 system.
3034
#[derive(Debug, PartialEq)]
3135
pub enum Error {
3236
/// Invalid e820 setup params.
@@ -39,12 +43,6 @@ pub enum Error {
3943
ZeroPageSetup,
4044
}
4145

42-
impl From<Error> for super::Error {
43-
fn from(e: Error) -> super::Error {
44-
super::Error::X86_64Setup(e)
45-
}
46-
}
47-
4846
// Where BIOS/VGA magic would live on a real PC.
4947
const EBDA_START: u64 = 0x9fc00;
5048
const FIRST_ADDR_PAST_32BITS: usize = (1 << 32);
@@ -166,7 +164,7 @@ fn add_e820_entry(
166164
addr: u64,
167165
size: u64,
168166
mem_type: u32,
169-
) -> Result<(), Error> {
167+
) -> super::Result<()> {
170168
if params.e820_entries >= params.e820_map.len() as u8 {
171169
return Err(Error::E820Configuration);
172170
}
@@ -214,12 +212,11 @@ mod tests {
214212
let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
215213
let config_err = configure_system(&gm, GuestAddress(0), 0, 1);
216214
assert!(config_err.is_err());
217-
match config_err.unwrap_err() {
218-
super::super::Error::X86_64Setup(e) => assert_eq!(
219-
e,
220-
super::Error::MpTableSetup(mptable::Error::NotEnoughMemory)
221-
),
222-
}
215+
assert_eq!(
216+
config_err.unwrap_err(),
217+
super::Error::MpTableSetup(mptable::Error::NotEnoughMemory)
218+
);
219+
223220
// Now assigning some memory that falls before the 32bit memory hole.
224221
let mem_size = 128 << 20;
225222
let arch_mem_regions = arch_memory_regions(mem_size);

arch/src/x86_64/regs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const PML4_START: usize = 0x9000;
1919
const PDPTE_START: usize = 0xa000;
2020
const PDE_START: usize = 0xb000;
2121

22+
/// Errors thrown while setting up x86_64 registers.
2223
#[derive(Debug)]
2324
pub enum Error {
2425
/// Failed to get SREGs for this CPU.
@@ -42,8 +43,7 @@ pub enum Error {
4243
/// Writing PML4 to RAM failed.
4344
WritePML4Address,
4445
}
45-
46-
pub type Result<T> = result::Result<T, Error>;
46+
type Result<T> = result::Result<T, Error>;
4747

4848
/// Configure Floating-Point Unit (FPU) registers for a given CPU.
4949
///

vmm/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3875,11 +3875,11 @@ mod tests {
38753875
#[test]
38763876
#[allow(clippy::cognitive_complexity)]
38773877
fn test_start_microvm_error_conversion_cl() {
3878-
// Test `StartMicrovmError` conversion
3878+
// Test `StartMicrovmError` conversion.
38793879
#[cfg(target_arch = "x86_64")]
38803880
assert_eq!(
38813881
error_kind(StartMicrovmError::ConfigureSystem(
3882-
arch::Error::X86_64Setup(arch::x86_64::Error::ZeroPageSetup)
3882+
arch::Error::ZeroPageSetup
38833883
)),
38843884
ErrorKind::Internal
38853885
);

0 commit comments

Comments
 (0)