Skip to content

Commit

Permalink
Run rustfmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbittman committed Apr 19, 2024
1 parent 79f81e4 commit 25edf42
Show file tree
Hide file tree
Showing 202 changed files with 3,809 additions and 3,694 deletions.
12 changes: 6 additions & 6 deletions src/bin/netmgr/src/link/ethernet.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::sync::Arc;

use byteorder::ByteOrder;
use byteorder::NetworkEndian;
use byteorder::{ByteOrder, NetworkEndian};

use crate::header::Header;
use crate::link::nic::NicBuffer;
use crate::link::IncomingPacketInfo;
use crate::network::ipv4::handle_incoming_ipv4_packet;
use crate::{
header::Header,
link::{nic::NicBuffer, IncomingPacketInfo},
network::ipv4::handle_incoming_ipv4_packet,
};

#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug, Default)]
#[repr(C)]
Expand Down
5 changes: 2 additions & 3 deletions src/bin/netmgr/src/link/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::sync::Arc;

use crate::header::Header;

use self::nic::NicBuffer;
use crate::header::Header;

pub mod ethernet;
pub mod nic;
Expand Down Expand Up @@ -56,7 +55,7 @@ impl IncomingPacketInfo {
Some(self)
}

#[allow(dead_code)]
#[allow(dead_code)]
pub fn packet_len(&self) -> usize {
self.buffer.packet_len()
}
Expand Down
2 changes: 1 addition & 1 deletion src/bin/netmgr/src/network/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use twizzler_net::addr::{Ipv4Addr, ServiceAddr};

use crate::{
header::Header,
link::nic::{NicBuffer, SendableBuffer},
link::{
ethernet::{EtherType, EthernetAddr, EthernetHeader},
nic::{NicBuffer, SendableBuffer},
IncomingPacketInfo,
},
transport::handle_packet,
Expand Down
6 changes: 3 additions & 3 deletions src/bin/netmgr/src/nics/loopback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::{

use twizzler_async::FlagBlock;

use crate::{
link::ethernet::{EthernetAddr, EthernetError},
link::nic::{NetworkInterface, NicBuffer, SendableBuffer},
use crate::link::{
ethernet::{EthernetAddr, EthernetError},
nic::{NetworkInterface, NicBuffer, SendableBuffer},
};

struct LoopbackInner {
Expand Down
6 changes: 3 additions & 3 deletions src/bin/netmgr/src/nics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::{

use twizzler_async::Task;

use crate::{
link::ethernet::{handle_incoming_ethernet_packets, EthernetAddr},
link::nic::NetworkInterface,
use crate::link::{
ethernet::{handle_incoming_ethernet_packets, EthernetAddr},
nic::NetworkInterface,
};

mod loopback;
Expand Down
1 change: 1 addition & 0 deletions src/bin/netmgr/src/route.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 1 addition & 2 deletions src/bin/netmgr/src/transport/icmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use twizzler_net::{
ListenFlags, PacketData, RxRequest, TxCompletion,
};

use super::TransportProto;
use crate::{
endpoint::{foreach_endpoint, EndPointKey},
header::Header,
Expand All @@ -17,8 +18,6 @@ use crate::{
HandleRef,
};

use super::TransportProto;

pub struct Icmp;

#[async_trait::async_trait]
Expand Down
1 change: 1 addition & 0 deletions src/bin/netmgr/src/transport/tcp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions src/bin/netmgr/src/transport/udp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

9 changes: 3 additions & 6 deletions src/bin/pager/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use std::time::Duration;
use std::{collections::BTreeMap, time::Duration};

use tickv::{success_codes::SuccessCode, ErrorCode};
use twizzler_abi::pager::{
CompletionToKernel, CompletionToPager, KernelCompletionData, RequestFromKernel,
RequestFromPager,
};
use twizzler_object::{ObjID, Object, ObjectInitFlags, Protections};

use std::collections::BTreeMap;

use tickv::{success_codes::SuccessCode, ErrorCode};

use crate::store::{Key, KeyValueStore};

mod nvme;
Expand Down Expand Up @@ -117,7 +114,7 @@ impl<'a> Tester<'a> {
let _ = self.get(k);
let num = quick_random() % 3;
if num == 0 || num == 2 {
let _ = self.put(k, Foo { x: x });
let _ = self.put(k, Foo { x });
} else if num == 1 {
let _ = self.del(k);
}
Expand Down
11 changes: 5 additions & 6 deletions src/bin/pager/src/nvme/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
};

use nvme::{
admin::CreateIOCompletionQueue,
admin::{CreateIOCompletionQueue, CreateIOSubmissionQueue},
ds::{
controller::properties::config::ControllerConfig,
identify::controller::IdentifyControllerDataStructure,
Expand All @@ -13,10 +13,9 @@ use nvme::{
comentry::CommonCompletion, subentry::CommonCommand, CommandId, QueueId, QueuePriority,
},
},
hosted::memory::PrpMode,
hosted::memory::{PhysicalPageCollection, PrpMode},
nvm::{ReadDword13, WriteDword13},
};
use nvme::{admin::CreateIOSubmissionQueue, hosted::memory::PhysicalPageCollection};
use twizzler_async::Task;
use twizzler_driver::{
dma::{DmaOptions, DmaPool, DMA_PAGE_SIZE},
Expand All @@ -25,9 +24,8 @@ use twizzler_driver::{
};
use volatile::map_field;

use crate::nvme::dma::NvmeDmaSliceRegion;

use super::{dma::NvmeDmaRegion, requester::NvmeRequester};
use crate::nvme::dma::NvmeDmaSliceRegion;

pub struct NvmeController {
requester: RwLock<Vec<Requester<NvmeRequester>>>,
Expand Down Expand Up @@ -239,7 +237,8 @@ impl NvmeController {
.unwrap();

{
// TODO: we should save these NvmeDmaRegions so they don't drop (dropping is okay, but this leaks memory )
// TODO: we should save these NvmeDmaRegions so they don't drop (dropping is okay, but
// this leaks memory )
let cmd = CreateIOCompletionQueue::new(
CommandId::new(),
cqid,
Expand Down
3 changes: 2 additions & 1 deletion src/bin/pager/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ pub fn hasher<T: std::hash::Hash>(t: &T) -> u64 {
let mut h = DefaultHasher::new();
t.hash(&mut h);
let x = h.finish();
// Don't ever hash to 0, 1, MAX, or MAX-1. Makes the open addressing easier, and 0 and MAX-1 are required for tickv.
// Don't ever hash to 0, 1, MAX, or MAX-1. Makes the open addressing easier, and 0 and MAX-1 are
// required for tickv.
match x {
0 => 2,
u64::MAX => u64::MAX - 2,
Expand Down
9 changes: 4 additions & 5 deletions src/kernel/macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#![feature(extend_one)]

use proc_macro::TokenStream;
use proc_macro::TokenTree;
use proc_macro::{TokenStream, TokenTree};
extern crate proc_macro;

#[proc_macro_attribute]
// Okay, look, I know what you're gonna say. Why do we need to get this complicated just to do tests.
// The answer is names. See, our friends in the rust community have not fully implemented this issue:
// https://github.com/rust-lang/rust/issues/50297. Until this is implemented, I don't know how to grab
// Okay, look, I know what you're gonna say. Why do we need to get this complicated just to do
// tests. The answer is names. See, our friends in the rust community have not fully implemented
// this issue: https://github.com/rust-lang/rust/issues/50297. Until this is implemented, I don't know how to grab
// name from a test function in a way that makes the test _runner_ know the names of the tests it's
// running. So we just embed the name ourselves using #[test_case].
pub fn kernel_test(_attr: TokenStream, items: TokenStream) -> TokenStream {
Expand Down
41 changes: 21 additions & 20 deletions src/kernel/src/arch/aarch64/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
/// https://developer.arm.com/documentation/100940/0101/?lang=en
/// and the Arm Architecture Reference Manual for A-profile architecture
/// https://developer.arm.com/documentation/ddi0487/latest
use core::{fmt::LowerHex, ops::{Sub, RangeInclusive}};
use core::{
fmt::LowerHex,
ops::{RangeInclusive, Sub},
};

use arm64::registers::ID_AA64MMFR0_EL1;
use registers::interfaces::Readable;

use crate::once::Once;

use super::memory::phys_to_virt;
use crate::once::Once;

/// A representation of a canonical virtual address.
#[derive(Clone, Copy, PartialEq, PartialOrd, Ord, Eq)]
Expand All @@ -32,26 +33,26 @@ impl VirtAddr {

/// The start of the kernel object mapping.
const KOBJ_START: Self = Self(0xFFFF_F000_0000_0000);

// TTBR0_EL1 points to a page table root for addresses ranging from
// 0x0 to 0x0000_FFFF_FFFF_FFFF. Generally this is used to cover
// user accessible memory (EL0).
const TTBR0_EL1: RangeInclusive<u64> = RangeInclusive::new(
// The start range of valid addresses that TTBR0 covers
0x0000_0000_0000_0000,
// The end range of valid addresses that TTBR0 covers
0x0000_FFFF_FFFF_FFFF
0x0000_FFFF_FFFF_FFFF,
);

// TTBR1_EL1 -> a pt root for addresses ranging from
// 0xFFFF_FFFF_FFFF_FFFF to 0xFFFF_0000_0000_0000
// Generally this is used to cover exclusively
// Generally this is used to cover exclusively
// kernel accessible memory (EL1).
const TTBR1_EL1: RangeInclusive<u64> = RangeInclusive::new(
// The start range of valid addresses that TTBR1 covers
0xFFFF_0000_0000_0000,
// The end range of valid addresses that TTBR1 covers
0xFFFF_FFFF_FFFF_FFFF
0xFFFF_FFFF_FFFF_FFFF,
);

// The size of the virtual address range reserved for MMIO.
Expand All @@ -64,7 +65,7 @@ impl VirtAddr {
// The start range of addresses used for MMIO
*Self::TTBR1_EL1.start(),
// The end range of addresses used for MMIO
*Self::TTBR1_EL1.start() + Self::MMIO_RANGE_SIZE
*Self::TTBR1_EL1.start() + Self::MMIO_RANGE_SIZE,
);

/// The bits that are valid which are used in address translation
Expand All @@ -73,11 +74,11 @@ impl VirtAddr {
const VALID_HIGH_ADDRESS: u64 = 0xFFFF;
/// The valid value for the upper bits of a low address
const VALID_LOW_ADDRESS: u64 = 0x0;

pub const fn start_kernel_memory() -> Self {
Self(*Self::TTBR1_EL1.start())
}

pub const fn start_kernel_object_memory() -> Self {
Self::KOBJ_START
}
Expand All @@ -98,22 +99,21 @@ impl VirtAddr {
Self(*Self::TTBR0_EL1.end())
}

/// Construct a new virtual address from the provided addr value, only if the provided value is a valid, canonical
/// address. If not, returns Err.
/// Construct a new virtual address from the provided addr value, only if the provided value is
/// a valid, canonical address. If not, returns Err.
pub const fn new(addr: u64) -> Result<Self, NonCanonical> {
// The most significant 16 bits of an address must be 0xFFFF or 0x0000.
// The most significant 16 bits of an address must be 0xFFFF or 0x0000.
// Any attempt to use a different bit value triggers a fault.
// For now we assume that virtual address tagging is disabled.
let top_two_bytes = addr
.checked_shr(Self::VALID_ADDR_BITS)
.unwrap();
let top_two_bytes = addr.checked_shr(Self::VALID_ADDR_BITS).unwrap();
match top_two_bytes {
Self::VALID_HIGH_ADDRESS | Self::VALID_LOW_ADDRESS => Ok(Self(addr)),
_ => Err(NonCanonical),
}
}

/// Construct a new virtual address from a u64 without verifying that it is a valid virtual address.
/// Construct a new virtual address from a u64 without verifying that it is a valid virtual
/// address.
///
/// # Safety
/// The provided address must be canonical.
Expand Down Expand Up @@ -239,7 +239,7 @@ impl PhysAddr {
Some(ID_AA64MMFR0_EL1::PARange::Value::Bits_44) => 44,
Some(ID_AA64MMFR0_EL1::PARange::Value::Bits_48) => 48,
Some(ID_AA64MMFR0_EL1::PARange::Value::Bits_52) => 52,
_ => unimplemented!("unknown PA size")
_ => unimplemented!("unknown PA size"),
}
})
}
Expand All @@ -253,7 +253,8 @@ impl PhysAddr {
}
}

/// Construct a new physical address from a u64 without verifying that it is a valid physical address.
/// Construct a new physical address from a u64 without verifying that it is a valid physical
/// address.
///
/// # Safety
/// The provided address must be a valid address.
Expand Down
14 changes: 5 additions & 9 deletions src/kernel/src/arch/aarch64/cntp.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
/// The `ClockHardware` interface for the CNTP_EL0 timer
/// This timer is local to a single core, and timestamps
/// are synchronized to a global system timer count
use arm64::registers::{CNTFRQ_EL0, CNTPCT_EL0, CNTP_CTL_EL0, CNTP_TVAL_EL0};
use registers::interfaces::{Readable, Writeable, ReadWriteable};
use registers::interfaces::{ReadWriteable, Readable, Writeable};
use twizzler_abi::syscall::{ClockFlags, ClockInfo, FemtoSeconds, TimeSpan, FEMTOS_PER_SEC};

use crate::time::{ClockHardware, Ticks};

use twizzler_abi::syscall::{ClockFlags, ClockInfo, FemtoSeconds, TimeSpan, FEMTOS_PER_SEC};

/// The Non-secure physical timer `CNTP` for EL0.
pub struct PhysicalTimer {
info: ClockInfo,
Expand Down Expand Up @@ -44,7 +42,7 @@ impl PhysicalTimer {
// round up

// ticks = time / rate => span as femtos / rate (in femtos)
let ticks = span.as_femtos() / self.info.resolution().0 as u128;
let ticks = span.as_femtos() / self.info.resolution().0 as u128;

// configure the timer to fire after a certain amount of ticks have passed
//
Expand All @@ -53,9 +51,7 @@ impl PhysicalTimer {
CNTP_TVAL_EL0.set(ticks as u64);

// clear the interrupt mask and enable the timer
CNTP_CTL_EL0.modify(
CNTP_CTL_EL0::IMASK::CLEAR + CNTP_CTL_EL0::ENABLE::SET
);
CNTP_CTL_EL0.modify(CNTP_CTL_EL0::IMASK::CLEAR + CNTP_CTL_EL0::ENABLE::SET);
}
}

Expand All @@ -81,7 +77,7 @@ pub fn cntp_interrupt_handler() {
// handle the timer interrupt by advancing the scheduler ticks
crate::clock::oneshot_clock_hardtick();

// Disable the timer to clear the interrupt. Software must clear
// Disable the timer to clear the interrupt. Software must clear
// the interrupt before deactivating the interrupt in the
// interrupt controller, otherwise it will keep firing.
//
Expand Down
7 changes: 4 additions & 3 deletions src/kernel/src/arch/aarch64/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ impl ArchContext {
/// Switch to a target context.
///
/// # Safety
/// This function must be called with a target that comes from an ArchContext that lives long enough.
/// This function must be called with a target that comes from an ArchContext that lives long
/// enough.
pub unsafe fn switch_to_target(tgt: &ArchContextTarget) {
// TODO: If the incoming target is already the current user table, this should be a no-op. Also, we don't
// need to set the kernel tables each time.
// TODO: If the incoming target is already the current user table, this should be a no-op.
// Also, we don't need to set the kernel tables each time.
// write TTBR1
TTBR1_EL1.set_baddr(KERNEL_TABLE_ADDR.raw());
// write TTBR0
Expand Down
7 changes: 4 additions & 3 deletions src/kernel/src/arch/aarch64/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use registers::{
interfaces::{Readable, Writeable},
registers::InMemoryRegister,
};

use twizzler_abi::arch::syscall::SYSCALL_MAGIC;
use twizzler_abi::upcall::{MemoryAccessKind, UpcallFrame};
use twizzler_abi::{
arch::syscall::SYSCALL_MAGIC,
upcall::{MemoryAccessKind, UpcallFrame},
};

use super::thread::UpcallAble;
use crate::memory::{context::virtmem::PageFaultFlags, VirtAddr};
Expand Down
1 change: 0 additions & 1 deletion src/kernel/src/arch/aarch64/image.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// TLS initialization for the kernel image
use crate::{
image::{TlsInfo, TlsVariant},
memory::VirtAddr,
Expand Down
Loading

0 comments on commit 25edf42

Please sign in to comment.