diff --git a/src/arch/x86_64/kernel/apic.rs b/src/arch/x86_64/kernel/apic.rs index a169abedcea7c09afe98530645bde6a7a727e4fc..92ab94f1bd09fea115285b92dcb67a4296f0a950 100644 --- a/src/arch/x86_64/kernel/apic.rs +++ b/src/arch/x86_64/kernel/apic.rs @@ -679,7 +679,6 @@ pub fn ipi_tlb_flush() { } /// Send an inter-processor interrupt to wake up a CPU Core that is in a HALT state. -#[allow(unused_variables)] pub fn wakeup_core(core_id_to_wakeup: CoreId) { #[cfg(feature = "smp")] if core_id_to_wakeup != core_id() { diff --git a/src/arch/x86_64/kernel/idt.rs b/src/arch/x86_64/kernel/idt.rs index e3f5916c0a7e31d3e9983c7e9393f73789613fa1..660e0dab50b454f5ec50efa2c807e504a7405d75 100644 --- a/src/arch/x86_64/kernel/idt.rs +++ b/src/arch/x86_64/kernel/idt.rs @@ -6,8 +6,6 @@ // http://opensource.org/licenses/MIT>, at your option. This file may not be // copied, modified, or distributed except according to those terms. -#![allow(dead_code)] - use crate::arch::x86_64::kernel::gdt; use crate::x86::bits64::paging::VAddr; use crate::x86::dtables::{self, DescriptorTablePointer}; @@ -38,6 +36,7 @@ struct IdtEntry { enum Type { InterruptGate, + #[allow(dead_code)] TrapGate, } diff --git a/src/arch/x86_64/kernel/pci.rs b/src/arch/x86_64/kernel/pci.rs index f4d1a321189cc454c62b2f06ca61a07f7657f9c8..a389fd0697c6d025b523365ce49ccd3867473809 100644 --- a/src/arch/x86_64/kernel/pci.rs +++ b/src/arch/x86_64/kernel/pci.rs @@ -56,7 +56,6 @@ static mut PCI_ADAPTERS: Vec<PciAdapter> = Vec::new(); static mut PCI_DRIVERS: Vec<PciDriver<'_>> = Vec::new(); /// Classes of PCI nodes. -#[allow(dead_code)] #[derive(Copy, Clone, Debug, FromPrimitive, ToPrimitive, PartialEq)] pub enum PciClassCode { TooOld = 0x00, @@ -80,7 +79,6 @@ pub enum PciClassCode { } /// Network Controller Sub Classes -#[allow(dead_code)] #[derive(Copy, Clone, Debug, FromPrimitive, ToPrimitive, PartialEq)] pub enum PciNetworkControllerSubclass { EthernetController = 0x00, diff --git a/src/arch/x86_64/mm/paging.rs b/src/arch/x86_64/mm/paging.rs index 9b481fe53d0f166a102e1283d3aa3b6d2bea35e9..99e3c792223a108a62f34fcc25cd4a0545417c96 100644 --- a/src/arch/x86_64/mm/paging.rs +++ b/src/arch/x86_64/mm/paging.rs @@ -5,8 +5,6 @@ // http://opensource.org/licenses/MIT>, at your option. This file may not be // copied, modified, or distributed except according to those terms. -#![allow(dead_code)] - use core::marker::PhantomData; use core::mem; use core::ptr; @@ -26,6 +24,7 @@ use crate::mm; use crate::scheduler; /// Uhyve's address of the initial GDT +#[allow(dead_code)] const BOOT_GDT: PhysAddr = PhysAddr(0x1000); /// Pointer to the root page table (PML4) @@ -133,11 +132,13 @@ impl PageTableEntry { } /// Returns `true` if the page is a huge page + #[allow(dead_code)] fn is_huge(self) -> bool { (self.physical_address_and_flags & PageTableEntryFlags::HUGE_PAGE.bits()) != 0 } /// Returns `true` if the page is accessible from the user space + #[allow(dead_code)] fn is_user(self) -> bool { (self.physical_address_and_flags & PageTableEntryFlags::USER_ACCESSIBLE.bits()) != 0 } diff --git a/src/config.rs b/src/config.rs index c8e6a1c8d3db7e08263a4e42db66ff4ea75cc31a..1062134a0ede560197d624f5ff1984de047b7837 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,13 +1,9 @@ -#[allow(dead_code)] pub const KERNEL_STACK_SIZE: usize = 32_768; -#[allow(dead_code)] pub const DEFAULT_STACK_SIZE: usize = 32_768; -#[allow(dead_code)] pub const USER_STACK_SIZE: usize = 1_048_576; -#[allow(dead_code)] pub const VIRTIO_MAX_QUEUE_SIZE: u16 = 2048; /// See https://github.com/facebook/folly/blob/1b5288e6eea6df074758f877c849b6e73bbb9fbb/folly/lang/Align.h#L107 for details diff --git a/src/drivers/net/rtl8139.rs b/src/drivers/net/rtl8139.rs index 48c366347931cf5046db57f8ad391ce607e90b27..34741949c6d945bb07e201b93ba84893042c0a70 100644 --- a/src/drivers/net/rtl8139.rs +++ b/src/drivers/net/rtl8139.rs @@ -7,15 +7,14 @@ // The driver based on the online manual http://www.lowlevel.eu/wiki/RTL8139 -#![allow(unused)] +#![allow(dead_code)] use core::convert::TryInto; use core::mem; -use crate::arch::kernel::apic; use crate::arch::kernel::irq::*; use crate::arch::kernel::pci; -use crate::arch::kernel::percore::{core_scheduler, increment_irq_counter}; +use crate::arch::kernel::percore::increment_irq_counter; use crate::arch::mm::paging::virt_to_phys; use crate::arch::mm::VirtAddr; use crate::drivers::error::DriverError; @@ -149,8 +148,8 @@ const TCR_CLRABT: u32 = 0x01; // Clear abort, attempt retransmit (when in abort // Basic mode control register const BMCR_RESET: u16 = 0x8000; // set the status and control of PHY to default -const BMCR_SPD100: u16 = (1 << 13); // 100 MBit -const BMCR_SPD1000: u16 = (1 << 6); // 1000 MBit +const BMCR_SPD100: u16 = 1 << 13; // 100 MBit +const BMCR_SPD1000: u16 = 1 << 6; // 1000 MBit const BMCR_ANE: u16 = 0x1000; // enable N-way autonegotiation (ignore above if set) const BMCR_RAN: u16 = 0x400; // restart auto-negotiation const BMCR_DUPLEX: u16 = 0x200; // Duplex mode, generally a value of 1 means full-duplex @@ -172,25 +171,25 @@ const ISR_ROK: u16 = 0x01; // Rx OK const R39_INTERRUPT_MASK: u16 = 0x7f; // Transmit Status of Descriptor0-3 (C mode only) -const TSD_CRS: u32 = (1 << 31); // carrier sense lost (during packet transmission) -const TSD_TABT: u32 = (1 << 30); // transmission abort -const TSD_OWC: u32 = (1 << 29); // out of window collision -const TSD_CDH: u32 = (1 << 28); // CD Heart beat (Cleared in 100Mb mode) +const TSD_CRS: u32 = 1 << 31; // carrier sense lost (during packet transmission) +const TSD_TABT: u32 = 1 << 30; // transmission abort +const TSD_OWC: u32 = 1 << 29; // out of window collision +const TSD_CDH: u32 = 1 << 28; // CD Heart beat (Cleared in 100Mb mode) const TSD_NCC: u32 = 0x0F00_0000; // Number of collisions counted (during transmission) const TSD_EARTH: u32 = 0x003F_0000; // threshold to begin transmission (0 = 8bytes, 1->2^6 = * 32bytes) -const TSD_TOK: u32 = (1 << 15); // Transmission OK, successful -const TSD_TUN: u32 = (1 << 14); // Transmission FIFO underrun -const TSD_OWN: u32 = (1 << 13); // Tx DMA operation finished (driver must set to 0 when TBC is written) +const TSD_TOK: u32 = 1 << 15; // Transmission OK, successful +const TSD_TUN: u32 = 1 << 14; // Transmission FIFO underrun +const TSD_OWN: u32 = 1 << 13; // Tx DMA operation finished (driver must set to 0 when TBC is written) const TSD_SIZE: u32 = 0x1fff; // Descriptor size, the total size in bytes of data to send (max 1792) /// To set the RTL8139 to accept only the Transmit OK (TOK) and Receive OK (ROK) /// interrupts, we would have the TOK and ROK bits of the IMR high and leave the /// rest low. That way when a TOK or ROK IRQ happens, it actually will go through /// and fire up an IRQ. -const INT_MASK: u16 = (ISR_ROK | ISR_TOK | ISR_RXOVW | ISR_TER | ISR_RER); +const INT_MASK: u16 = ISR_ROK | ISR_TOK | ISR_RXOVW | ISR_TER | ISR_RER; /// Beside Receive OK (ROK) interrupt, this mask enable all other interrupts -const INT_MASK_NO_ROK: u16 = (ISR_TOK | ISR_RXOVW | ISR_TER | ISR_RER); +const INT_MASK_NO_ROK: u16 = ISR_TOK | ISR_RXOVW | ISR_TER | ISR_RER; const NO_TX_BUFFERS: usize = 4; diff --git a/src/drivers/net/virtio_net.rs b/src/drivers/net/virtio_net.rs index 43f3da82ea4486925a57e9e21a79058830d8f921..e38c0f6fc18f07a0535dfe3f0baaec3102cd0150 100644 --- a/src/drivers/net/virtio_net.rs +++ b/src/drivers/net/virtio_net.rs @@ -8,11 +8,9 @@ //! A module containing a virtio network driver. //! //! The module contains ... -#![allow(unused)] #[cfg(not(feature = "newlib"))] use super::netwakeup; -use crate::arch::kernel::pci::error::PciError; use crate::arch::kernel::pci::PciAdapter; use crate::arch::kernel::percore::increment_irq_counter; use crate::config::VIRTIO_MAX_QUEUE_SIZE; @@ -24,25 +22,18 @@ use alloc::rc::Rc; use alloc::vec::Vec; use core::convert::TryFrom; use core::mem; -use core::ops::Deref; use core::result::Result; use core::{cell::RefCell, cmp::Ordering}; -use crate::drivers::virtio::env::memory::{MemLen, MemOff}; use crate::drivers::virtio::error::VirtioError; use crate::drivers::virtio::transport::pci; -use crate::drivers::virtio::transport::pci::{ - ComCfg, IsrStatus, NotifCfg, NotifCtrl, PciCap, PciCfgAlt, ShMemCfg, UniCapsColl, -}; +use crate::drivers::virtio::transport::pci::{ComCfg, IsrStatus, NotifCfg, PciCap, UniCapsColl}; use crate::drivers::virtio::virtqueue::{ - AsSliceU8, BuffSpec, BufferToken, Bytes, Transfer, TransferToken, Virtq, VqIndex, VqSize, - VqType, + AsSliceU8, BuffSpec, BufferToken, Bytes, Transfer, Virtq, VqIndex, VqSize, VqType, }; -use self::constants::{FeatureSet, Features, NetHdrFlag, NetHdrGSO, Status, MAX_NUM_VQ}; +use self::constants::{FeatureSet, Features, NetHdrGSO, Status, MAX_NUM_VQ}; use self::error::VirtioNetError; -use crate::arch::x86_64::mm::paging::{BasePageSize, PageSize}; -use crate::arch::x86_64::mm::{paging, virtualmem, VirtAddr}; const ETH_HDR: usize = 14usize; @@ -198,7 +189,7 @@ impl RxQueues { /// This currently include nothing. But in the future it might include among others:: /// * Calculating missing checksums /// * Merging receive buffers, by simply checking the poll_queue (if VIRTIO_NET_F_MRG_BUF) - fn post_processing(mut transfer: Transfer) -> Result<Transfer, VirtioNetError> { + fn post_processing(transfer: Transfer) -> Result<Transfer, VirtioNetError> { if transfer.poll() { // Here we could implement all features. Ok(transfer) @@ -251,7 +242,7 @@ impl RxQueues { for _ in 0..num_buff { let buff_tkn = match vq.prep_buffer(Rc::clone(vq), None, Some(spec.clone())) { Ok(tkn) => tkn, - Err(vq_err) => { + Err(_vq_err) => { error!("Setup of network queue failed, which should not happen!"); panic!("setup of network queue failed!"); } @@ -286,7 +277,7 @@ impl RxQueues { for _ in 0..num_buff { let buff_tkn = match vq.prep_buffer(Rc::clone(vq), None, Some(spec.clone())) { Ok(tkn) => tkn, - Err(vq_err) => { + Err(_vq_err) => { error!("Setup of network queue failed, which should not happen!"); panic!("setup of network queue failed!"); } @@ -361,6 +352,7 @@ struct TxQueues { } impl TxQueues { + #[allow(dead_code)] fn enable_notifs(&self) { if self.is_multi { for vq in &self.vqs { @@ -371,6 +363,7 @@ impl TxQueues { } } + #[allow(dead_code)] fn disable_notifs(&self) { if self.is_multi { for vq in &self.vqs { @@ -531,7 +524,7 @@ impl NetworkInterface for VirtioNetDriver { let len = len + core::mem::size_of::<VirtioNetHdr>(); match self.send_vqs.get_tkn(len) { - Some((mut buff_tkn, vq_index)) => { + Some((mut buff_tkn, _vq_index)) => { let (send_ptrs, _) = buff_tkn.raw_ptrs(); // Currently we have single Buffers in the TxQueue of size: MTU + ETH_HDR + VIRTIO_NET_HDR // see TxQueue.add() @@ -548,7 +541,7 @@ impl NetworkInterface for VirtioNetDriver { } } - fn send_tx_buffer(&mut self, tkn_handle: usize, len: usize) -> Result<(), ()> { + fn send_tx_buffer(&mut self, tkn_handle: usize, _len: usize) -> Result<(), ()> { // This does not result in a new assignment, or in a drop of the BufferToken, which // would be dangerous, as the memory is freed then. let tkn = *unsafe { Box::from_raw(tkn_handle as *mut BufferToken) }; @@ -566,8 +559,8 @@ impl NetworkInterface for VirtioNetDriver { fn receive_rx_buffer(&mut self) -> Result<(&'static [u8], usize), ()> { match self.recv_vqs.get_next() { - Some(mut transfer) => { - let mut transfer = match RxQueues::post_processing(transfer) { + Some(transfer) => { + let transfer = match RxQueues::post_processing(transfer) { Ok(trf) => trf, Err(vnet_err) => { error!("Post processing failed. Err: {:?}", vnet_err); @@ -653,8 +646,7 @@ impl NetworkInterface for VirtioNetDriver { true } else if self.isr_stat.is_cfg_change() { info!("Configuration changes are not possible! Aborting"); - todo!("Implement possibiity to change config on the fly..."); - false + todo!("Implement possibiity to change config on the fly...") } else { false } @@ -692,6 +684,7 @@ impl VirtioNetDriver { } } + #[allow(dead_code)] fn is_announce(&self) -> bool { if self .dev_cfg @@ -710,6 +703,7 @@ impl VirtioNetDriver { /// device and overrides the num_vq field in the common config. /// /// Returns 1 (i.e. minimum number of pairs) if VIRTIO_NET_F_MQ is not set. + #[allow(dead_code)] fn get_max_vq_pairs(&self) -> u16 { if self.dev_cfg.features.is_feature(Features::VIRTIO_NET_F_MQ) { self.dev_cfg.raw.max_virtqueue_pairs @@ -1184,7 +1178,6 @@ impl VirtioNetDriver { mod constants { use super::error::VirtioNetError; use alloc::vec::Vec; - use core::fmt::Display; use core::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign}; // Configuration constants diff --git a/src/drivers/virtio/depr/virtio_net.rs b/src/drivers/virtio/depr/virtio_net.rs index de49a26d332f253323bf2d21a8fc94f7abe73c40..58fc86346e757df374bd096008c3727ec5330c2d 100644 --- a/src/drivers/virtio/depr/virtio_net.rs +++ b/src/drivers/virtio/depr/virtio_net.rs @@ -5,24 +5,18 @@ // http://opensource.org/licenses/MIT>, at your option. This file may not be // copied, modified, or distributed except according to those terms. -#![allow(unused)] #![allow(dead_code)] use crate::arch::kernel::pci; use crate::arch::mm::paging::{BasePageSize, PageSize}; -use crate::arch::mm::{paging, virtualmem, VirtAddr}; +use crate::arch::mm::VirtAddr; #[cfg(not(feature = "newlib"))] use crate::drivers::net::netwakeup; use crate::drivers::virtio::depr::virtio::{ self, consts::*, virtio_pci_common_cfg, VirtioNotification, Virtq, }; -use crate::synch::spinlock::SpinlockIrqSave; -use crate::x86::io::*; -use alloc::rc::Rc; use alloc::vec::Vec; -use core::cell::RefCell; -use core::convert::TryInto; use core::sync::atomic::{fence, Ordering}; use core::{fmt, mem, slice, u32, u8}; @@ -118,7 +112,7 @@ impl fmt::Debug for virtio_net_config { self.mac[0], self.mac[1], self.mac[2], self.mac[3], self.mac[4], self.mac[5] )?; write!(f, "max_virtqueue_pairs: {}, ", self.max_virtqueue_pairs)?; - write!(f, "mtu: {} ", self.mtu); + write!(f, "mtu: {} ", self.mtu)?; write!(f, "}}") } } @@ -141,7 +135,7 @@ struct virtio_net_hdr_legacy { } impl virtio_net_hdr_legacy { - pub fn init(&mut self, len: usize) { + pub fn init(&mut self, _len: usize) { self.flags = 0; self.gso_type = VIRTIO_NET_HDR_GSO_NONE; self.hdr_len = 0; @@ -168,7 +162,7 @@ struct virtio_net_hdr { } impl virtio_net_hdr { - pub fn init(&mut self, len: usize) { + pub fn init(&mut self, _len: usize) { self.flags = 0; self.gso_type = VIRTIO_NET_HDR_GSO_NONE; self.hdr_len = 0; @@ -255,7 +249,6 @@ impl<'a> fmt::Debug for VirtioNetDriver<'a> { impl<'a> VirtioNetDriver<'a> { pub fn init_vqs(&mut self) { let common_cfg = &mut self.common_cfg; - let device_cfg = &self.device_cfg; let notify_cfg = &mut self.notify_cfg; debug!("Setting up virtqueues..."); @@ -273,7 +266,7 @@ impl<'a> VirtioNetDriver<'a> { let vqsize = common_cfg.queue_size as usize; { let buffer_size: usize = 65562; - let mut vec_buffer = &mut self.rx_buffers; + let vec_buffer = &mut self.rx_buffers; for i in 0..vqsize { let buffer = RxBuffer::new(buffer_size); let addr = buffer.addr; @@ -284,7 +277,7 @@ impl<'a> VirtioNetDriver<'a> { { let buffer_size: usize = self.get_mtu() as usize; - let mut vec_buffer = &mut self.tx_buffers; + let vec_buffer = &mut self.tx_buffers; for i in 0..vqsize { let buffer = TxBuffer::new(buffer_size); let addr = buffer.addr; @@ -362,7 +355,7 @@ impl<'a> VirtioNetDriver<'a> { } pub fn check_used_elements(&mut self) { - let mut buffers = &mut self.tx_buffers; + let buffers = &mut self.tx_buffers; while let Some(idx) = (self.vqueues.as_deref_mut().unwrap())[1].check_used_elements() { buffers[idx as usize].in_use = false; } @@ -396,7 +389,7 @@ impl<'a> VirtioNetDriver<'a> { } pub fn get_tx_buffer(&mut self, len: usize) -> Result<(*mut u8, usize), ()> { - let mut buffers = &mut self.tx_buffers; + let buffers = &mut self.tx_buffers; // do we have free buffers? if !buffers.iter().any(|b| !b.in_use) { @@ -407,7 +400,7 @@ impl<'a> VirtioNetDriver<'a> { let index = (self.vqueues.as_ref().unwrap())[VIRTIO_NET_TX_QUEUE].get_available_buffer()?; let index = index as usize; - let mut buffers = &mut self.tx_buffers; + let buffers = &mut self.tx_buffers; if !buffers[index].in_use { buffers[index].in_use = true; let header = buffers[index].addr.as_mut_ptr::<virtio_net_hdr>(); @@ -437,7 +430,6 @@ impl<'a> VirtioNetDriver<'a> { pub fn receive_rx_buffer(&self) -> Result<&'static [u8], ()> { let (idx, len) = (self.vqueues.as_ref().unwrap())[VIRTIO_NET_RX_QUEUE].get_used_buffer()?; let addr = self.rx_buffers[idx as usize].addr; - let virtio_net_hdr = unsafe { &*(addr.as_ptr::<virtio_net_hdr>()) }; let rx_buffer_slice = unsafe { slice::from_raw_parts( (addr + mem::size_of::<virtio_net_hdr>()).as_ptr::<u8>(), diff --git a/src/drivers/virtio/env.rs b/src/drivers/virtio/env.rs index b6ad8d28971e6293a2e5ea3e04b7f35bded611c2..71e12b738d7639c88d214864aa9f9c72af4fce8c 100644 --- a/src/drivers/virtio/env.rs +++ b/src/drivers/virtio/env.rs @@ -10,7 +10,6 @@ //! The module should easy partability of the code. Furthermore it provides //! a clean boundary between virtio and the rest of the kernel. One additional aspect is to //! ensure only a single location needs changes, in cases where the underlying kernel code is changed -#![allow(dead_code)] pub mod memory { use core::convert::TryFrom; @@ -213,6 +212,7 @@ pub mod pci { /// Wrapper function to write the configuration space of a PCI /// device at the given register. + #[allow(dead_code)] pub fn write_config(adapter: &PciAdapter, register: u32, data: u32) { pci::write_config(adapter.bus, adapter.device, register.to_le(), data.to_le()); } diff --git a/src/drivers/virtio/virtqueue/mod.rs b/src/drivers/virtio/virtqueue/mod.rs index 8d7fc7cafe8c07301ccc00f988f96c9d21113614..b042f914a9074fbc6032ed7a97a7c2581303ebb9 100644 --- a/src/drivers/virtio/virtqueue/mod.rs +++ b/src/drivers/virtio/virtqueue/mod.rs @@ -15,20 +15,19 @@ //! Drivers who need a more fine grained access to the specifc queues must //! use the respective virtqueue structs directly. #![allow(dead_code)] -#![allow(unused)] #![allow(clippy::type_complexity)] pub mod packed; pub mod split; use crate::arch::mm::paging::{BasePageSize, PageSize}; -use crate::arch::mm::{paging, virtualmem, PhysAddr, VirtAddr}; +use crate::arch::mm::{paging, VirtAddr}; use self::error::{BufferError, VirtqError}; use self::packed::PackedVq; use self::split::SplitVq; -use super::transport::pci::{ComCfg, IsrStatus, NotifCfg}; +use super::transport::pci::{ComCfg, NotifCfg}; use alloc::boxed::Box; use alloc::collections::VecDeque; use alloc::rc::Rc; @@ -267,7 +266,6 @@ impl Virtq { used_vqs.push((vq, new_tkn_lst)) } - used = false; } let mut transfer_lst = Vec::new(); @@ -329,7 +327,6 @@ impl Virtq { used_vqs.push((vq, new_tkn_lst)) } - used = false; } for (vq, tkn_lst) in used_vqs { @@ -360,11 +357,11 @@ impl Virtq { match vq_type { VqType::Packed => match PackedVq::new(com_cfg, notif_cfg, size, index, feats) { Ok(packed_vq) => Virtq::Packed(packed_vq), - Err(vq_error) => panic!("Currently panics if queue fails to be created"), + Err(_vq_error) => panic!("Currently panics if queue fails to be created"), }, VqType::Split => match SplitVq::new(com_cfg, notif_cfg, size, index, feats) { Ok(split_vq) => Virtq::Split(split_vq), - Err(vq_error) => panic!("Currently panics if queue fails to be created"), + Err(_vq_error) => panic!("Currently panics if queue fails to be created"), }, } } @@ -1776,22 +1773,9 @@ impl Buffer { /// Resets the Buffers length to the given len. This MUST be the length at initialization. fn reset_len(&mut self, init_len: usize) { match self { - Buffer::Single { - desc_lst, - next_write, - len, - } => *len = init_len, - Buffer::Multiple { - desc_lst, - next_write, - len, - } => *len = init_len, - Buffer::Indirect { - desc_lst, - ctrl_desc, - next_write, - len, - } => *len = init_len, + Buffer::Single { len, .. } + | Buffer::Multiple { len, .. } + | Buffer::Indirect { len, .. } => *len = init_len, } } @@ -1799,22 +1783,9 @@ impl Buffer { /// length at initialization or smaller-equal 0. fn restr_len(&mut self, new_len: usize) { match self { - Buffer::Single { - desc_lst, - next_write, - len, - } => *len = new_len, - Buffer::Multiple { - desc_lst, - next_write, - len, - } => *len = new_len, - Buffer::Indirect { - desc_lst, - ctrl_desc, - next_write, - len, - } => *len = new_len, + Buffer::Single { len, .. } + | Buffer::Multiple { len, .. } + | Buffer::Indirect { len, .. } => *len = new_len, } } @@ -1825,40 +1796,17 @@ impl Buffer { Buffer::Single { desc_lst, next_write, - len, - } => { - if (desc_lst.len() - 1) < *next_write { - Err(BufferError::ToManyWrites) - } else if desc_lst.get(*next_write).unwrap().len() < slice.len() { - Err(BufferError::WriteToLarge) - } else { - desc_lst[*next_write].deref_mut()[0..slice.len()].copy_from_slice(slice); - *next_write += 1; - - Ok(slice.len()) - } + .. } - Buffer::Multiple { + | Buffer::Multiple { desc_lst, next_write, - len, - } => { - if (desc_lst.len() - 1) < *next_write { - Err(BufferError::ToManyWrites) - } else if desc_lst.get(*next_write).unwrap().len() < slice.len() { - Err(BufferError::WriteToLarge) - } else { - desc_lst[*next_write].deref_mut()[0..slice.len()].copy_from_slice(slice); - *next_write += 1; - - Ok(slice.len()) - } + .. } - Buffer::Indirect { + | Buffer::Indirect { desc_lst, - ctrl_desc, next_write, - len, + .. } => { if (desc_lst.len() - 1) < *next_write { Err(BufferError::ToManyWrites) @@ -1877,22 +1825,9 @@ impl Buffer { /// Resets the write status of a Buffertoken in order to be able to reuse a Buffertoken. fn reset_write(&mut self) { match self { - Buffer::Single { - desc_lst, - next_write, - len, - } => *next_write = 0, - Buffer::Multiple { - desc_lst, - next_write, - len, - } => *next_write = 0, - Buffer::Indirect { - desc_lst, - ctrl_desc, - next_write, - len, - } => *next_write = 0, + Buffer::Single { next_write, .. } + | Buffer::Multiple { next_write, .. } + | Buffer::Indirect { next_write, .. } => *next_write = 0, } } @@ -1902,40 +1837,9 @@ impl Buffer { /// After this call the users is responsible for deallocating the given memory via the kenrel `mem::dealloc` function. fn into_raw(self) -> Vec<(*mut u8, usize)> { match self { - Buffer::Single { - mut desc_lst, - next_write, - len, - } => { - let mut arr = Vec::with_capacity(desc_lst.len()); - - for desc in desc_lst.iter_mut() { - // Need to be a little carefull here. - desc.dealloc = Dealloc::Not; - arr.push((desc.ptr, desc._mem_len)); - } - arr - } - Buffer::Multiple { - mut desc_lst, - next_write, - len, - } => { - let mut arr = Vec::with_capacity(desc_lst.len()); - - for desc in desc_lst.iter_mut() { - // Need to be a little carefull here. - desc.dealloc = Dealloc::Not; - arr.push((desc.ptr, desc._mem_len)); - } - arr - } - Buffer::Indirect { - mut desc_lst, - ctrl_desc, - next_write, - len, - } => { + Buffer::Single { mut desc_lst, .. } + | Buffer::Multiple { mut desc_lst, .. } + | Buffer::Indirect { mut desc_lst, .. } => { let mut arr = Vec::with_capacity(desc_lst.len()); for desc in desc_lst.iter_mut() { @@ -1951,36 +1855,9 @@ impl Buffer { /// Returns a copy of the buffer. fn cpy(&self) -> Box<[u8]> { match &self { - Buffer::Single { - desc_lst, - next_write, - len, - } => { - let mut arr = Vec::with_capacity(*len); - - for desc in desc_lst.iter() { - arr.append(&mut desc.cpy_into_vec()); - } - arr.into_boxed_slice() - } - Buffer::Multiple { - desc_lst, - next_write, - len, - } => { - let mut arr = Vec::with_capacity(*len); - - for desc in desc_lst.iter() { - arr.append(&mut desc.cpy_into_vec()); - } - arr.into_boxed_slice() - } - Buffer::Indirect { - desc_lst, - ctrl_desc, - next_write, - len, - } => { + Buffer::Single { desc_lst, len, .. } + | Buffer::Multiple { desc_lst, len, .. } + | Buffer::Indirect { desc_lst, len, .. } => { let mut arr = Vec::with_capacity(*len); for desc in desc_lst.iter() { @@ -1995,36 +1872,9 @@ impl Buffer { /// buffer beeing possibly split up between different descriptors. fn scat_cpy(&self) -> Vec<Box<[u8]>> { match &self { - Buffer::Single { - desc_lst, - next_write, - len, - } => { - let mut arr = Vec::with_capacity(desc_lst.len()); - - for desc in desc_lst.iter() { - arr.push(desc.cpy_into_box()); - } - arr - } - Buffer::Multiple { - desc_lst, - next_write, - len, - } => { - let mut arr = Vec::with_capacity(desc_lst.len()); - - for desc in desc_lst.iter() { - arr.push(desc.cpy_into_box()); - } - arr - } - Buffer::Indirect { - desc_lst, - ctrl_desc, - next_write, - len, - } => { + Buffer::Single { desc_lst, .. } + | Buffer::Multiple { desc_lst, .. } + | Buffer::Indirect { desc_lst, .. } => { let mut arr = Vec::with_capacity(desc_lst.len()); for desc in desc_lst.iter() { @@ -2043,22 +1893,9 @@ impl Buffer { /// In order to retrieve this value, please use `BufferToken.num_consuming_desc()`. fn num_descr(&self) -> usize { match &self { - Buffer::Single { - desc_lst, - next_write, - len, - } => desc_lst.len(), - Buffer::Multiple { - desc_lst, - next_write, - len, - } => desc_lst.len(), - Buffer::Indirect { - desc_lst, - ctrl_desc, - next_write, - len, - } => desc_lst.len(), + Buffer::Single { desc_lst, .. } + | Buffer::Multiple { desc_lst, .. } + | Buffer::Indirect { desc_lst, .. } => desc_lst.len(), } } @@ -2069,22 +1906,9 @@ impl Buffer { /// descriptor area! fn len(&self) -> usize { match &self { - Buffer::Single { - desc_lst, - next_write, - len, - } => *len, - Buffer::Multiple { - desc_lst, - next_write, - len, - } => *len, - Buffer::Indirect { - desc_lst, - ctrl_desc, - next_write, - len, - } => *len, + Buffer::Single { len, .. } + | Buffer::Multiple { len, .. } + | Buffer::Indirect { len, .. } => *len, } } @@ -2095,22 +1919,9 @@ impl Buffer { /// (`&mut [u8]`) for each descriptor. fn as_mut_slice(&mut self) -> &mut [MemDescr] { match self { - Buffer::Single { - desc_lst, - next_write, - len, - } => desc_lst.as_mut(), - Buffer::Multiple { - desc_lst, - next_write, - len, - } => desc_lst.as_mut(), - Buffer::Indirect { - desc_lst, - ctrl_desc, - next_write, - len, - } => desc_lst.as_mut(), + Buffer::Single { desc_lst, .. } + | Buffer::Multiple { desc_lst, .. } + | Buffer::Indirect { desc_lst, .. } => desc_lst.as_mut(), } } @@ -2121,89 +1932,33 @@ impl Buffer { /// (`&[u8]`) for each descriptor. fn as_slice(&self) -> &[MemDescr] { match self { - Buffer::Single { - desc_lst, - next_write, - len, - } => desc_lst.as_ref(), - Buffer::Multiple { - desc_lst, - next_write, - len, - } => desc_lst.as_ref(), - Buffer::Indirect { - desc_lst, - ctrl_desc, - next_write, - len, - } => desc_lst.as_ref(), + Buffer::Single { desc_lst, .. } => desc_lst.as_ref(), + Buffer::Multiple { desc_lst, .. } => desc_lst.as_ref(), + Buffer::Indirect { desc_lst, .. } => desc_lst.as_ref(), } } /// Returns a reference to the buffers ctrl descriptor if available. fn get_ctrl_desc(&self) -> Option<&MemDescr> { - match self { - Buffer::Single { - desc_lst, - next_write, - len, - } => None, - Buffer::Multiple { - desc_lst, - next_write, - len, - } => None, - Buffer::Indirect { - desc_lst, - ctrl_desc, - next_write, - len, - } => Some(ctrl_desc), + if let Buffer::Indirect { ctrl_desc, .. } = self { + Some(ctrl_desc) + } else { + None } } /// Returns a mutable reference to the buffers ctrl descriptor if available. fn get_ctrl_desc_mut(&mut self) -> Option<&mut MemDescr> { - match self { - Buffer::Single { - desc_lst, - next_write, - len, - } => None, - Buffer::Multiple { - desc_lst, - next_write, - len, - } => None, - Buffer::Indirect { - desc_lst, - ctrl_desc, - next_write, - len, - } => Some(ctrl_desc), + if let Buffer::Indirect { ctrl_desc, .. } = self { + Some(ctrl_desc) + } else { + None } } /// Returns true if the buffer is an indirect one fn is_indirect(&self) -> bool { - match self { - Buffer::Single { - desc_lst, - next_write, - len, - } => false, - Buffer::Multiple { - desc_lst, - next_write, - len, - } => false, - Buffer::Indirect { - desc_lst, - ctrl_desc, - next_write, - len, - } => true, - } + matches!(self, Buffer::Indirect { .. }) } } @@ -2320,21 +2075,15 @@ impl DerefMut for MemDescr { impl Drop for MemDescr { fn drop(&mut self) { // Handle returning of Id's to pool - match &self.id { - Some(id) => { - let id = self.id.take().unwrap(); - self.pool.ret_id(id); - } - None => (), + if let Some(id) = self.id.take() { + self.pool.ret_id(id); } match self.dealloc { Dealloc::Not => (), - Dealloc::AsSlice => unsafe { - let temp = Vec::from_raw_parts(self.ptr, self._mem_len, 0); - }, + Dealloc::AsSlice => unsafe { drop(Vec::from_raw_parts(self.ptr, self._mem_len, 0)) }, Dealloc::AsPage => { - crate::mm::deallocate(VirtAddr::from(self.ptr as usize), self._mem_len); + crate::mm::deallocate(VirtAddr::from(self.ptr as usize), self._mem_len) } } } @@ -2623,7 +2372,7 @@ pub enum BuffSpec<'a> { // is defined by the respective `Bytes` inside the slice. Overall buffer will be // the sum of all `Bytes` in the slide. But consumes only ONE descriptor of the actual /// virtqueue. - Indirect(&'a [(Bytes)]), + Indirect(&'a [Bytes]), } /// Ensures `T` is pinned at the same memory location. @@ -2876,9 +2625,9 @@ pub mod error { VirtqError::NoBufferAvail => write!(f, "Virtq detected write into non existing Buffer!"), VirtqError::BufferInWithDirect => write!(f, "Virtq detected creation of Token, where Indirect and direct buffers where mixed!"), VirtqError::BufferNotSpecified => write!(f, "Virtq detected creation of Token, without a BuffSpec"), - VirtqError::QueueNotExisting(u16) => write!(f, "Virtq does not exist and can not be used!"), + VirtqError::QueueNotExisting(_) => write!(f, "Virtq does not exist and can not be used!"), VirtqError::NoDescrAvail => write!(f, "Virtqs memory pool is exhausted!"), - VirtqError::BufferSizeWrong(usize) => write!(f, "Specified Buffer is to small for write!"), + VirtqError::BufferSizeWrong(_) => write!(f, "Specified Buffer is to small for write!"), VirtqError::NoReuseBuffer => write!(f, "Buffer can not be reused!"), VirtqError::OngoingTransfer(_) => write!(f, "Transfer is ongoging and can not be used currently!"), VirtqError::WriteToLarge(_) => write!(f, "Write is to large for BufferToken!"), diff --git a/src/drivers/virtio/virtqueue/packed.rs b/src/drivers/virtio/virtqueue/packed.rs index 43560b84856b7272c8908c7156de8bee43847ddf..6828c3628b4c13d8e78562acd0dac7c74679210a 100644 --- a/src/drivers/virtio/virtqueue/packed.rs +++ b/src/drivers/virtio/virtqueue/packed.rs @@ -8,24 +8,22 @@ //! This module contains Virtio's packed virtqueue. //! See Virito specification v1.1. - 2.7 #![allow(dead_code)] -#![allow(unused)] use self::error::VqPackedError; use super::super::features::Features; -use super::super::transport::pci::{ComCfg, IsrStatus, NotifCfg, NotifCtrl}; +use super::super::transport::pci::{ComCfg, NotifCfg, NotifCtrl}; use super::error::VirtqError; use super::{ - AsSliceU8, BuffSpec, Buffer, BufferToken, Bytes, DescrFlags, MemDescr, MemDescrId, MemPool, - Pinned, Transfer, TransferState, TransferToken, Virtq, VqIndex, VqSize, + AsSliceU8, BuffSpec, Buffer, BufferToken, Bytes, DescrFlags, MemDescr, MemPool, Pinned, + Transfer, TransferState, TransferToken, Virtq, VqIndex, VqSize, }; use crate::arch::mm::paging::{BasePageSize, PageSize}; -use crate::arch::mm::{paging, virtualmem, PhysAddr, VirtAddr}; +use crate::arch::mm::{paging, VirtAddr}; use alloc::boxed::Box; use alloc::collections::VecDeque; use alloc::rc::Rc; use alloc::vec::Vec; use core::convert::TryFrom; -use core::ops::Deref; use core::sync::atomic::{fence, Ordering}; use core::{cell::RefCell, ptr}; @@ -579,7 +577,7 @@ impl<'a> ReadCtrl<'a> { let mut desc_iter = desc_slice.iter_mut(); - for desc in send_buff.as_mut_slice() { + for _desc in send_buff.as_mut_slice() { // Unwrapping is fine here, as lists must be of same size and same ordering desc_iter.next().unwrap(); } @@ -616,7 +614,7 @@ impl<'a> ReadCtrl<'a> { let mut desc_iter = desc_slice.iter(); - for desc in send_buff.as_mut_slice() { + for _desc in send_buff.as_mut_slice() { // Unwrapping is fine here, as lists must be of same size and same ordering desc_iter.next().unwrap(); } @@ -704,7 +702,7 @@ impl<'a> ReadCtrl<'a> { /// Updates the descriptor flags inside the actual ring if necessary and /// increments the poll_index by one. fn update_send(&mut self, send_buff: &mut Buffer) { - for desc in send_buff.as_slice() { + for _desc in send_buff.as_slice() { // Increase poll_index and reset ring position beforehand in order to have a consistent and clean // data structure. self.reset_ring_pos(); diff --git a/src/drivers/virtio/virtqueue/split.rs b/src/drivers/virtio/virtqueue/split.rs index 84177f6f47888c8f870d8f7a3e07afe5970ab2b1..bea3179bb4bd781cc5c0805dc49fcc19ef6e8b71 100644 --- a/src/drivers/virtio/virtqueue/split.rs +++ b/src/drivers/virtio/virtqueue/split.rs @@ -8,23 +8,20 @@ //! This module contains Virtio's split virtqueue. //! See Virito specification v1.1. - 2.6 #![allow(dead_code)] -#![allow(unused)] -use super::super::features::Features; -use super::super::transport::pci::{ComCfg, IsrStatus, NotifCfg, NotifCtrl}; +use super::super::transport::pci::{ComCfg, NotifCfg, NotifCtrl}; use super::error::VirtqError; use super::{ - AsSliceU8, BuffSpec, Buffer, BufferToken, Bytes, DescrFlags, MemDescr, MemDescrId, MemPool, - Pinned, Transfer, TransferState, TransferToken, Virtq, VqIndex, VqSize, + AsSliceU8, BuffSpec, Buffer, BufferToken, Bytes, DescrFlags, MemDescr, MemPool, Pinned, + Transfer, TransferState, TransferToken, Virtq, VqIndex, VqSize, }; use crate::arch::mm::paging::{BasePageSize, PageSize}; -use crate::arch::mm::{paging, virtualmem, PhysAddr, VirtAddr}; +use crate::arch::mm::{paging, VirtAddr}; use alloc::boxed::Box; use alloc::collections::VecDeque; use alloc::rc::Rc; use alloc::vec::Vec; use core::convert::TryFrom; -use core::ops::Deref; use core::sync::atomic::{fence, Ordering}; use core::{cell::RefCell, ptr}; @@ -214,7 +211,8 @@ impl DescrRing { tkn.buff_tkn .as_mut() .unwrap() - .restr_size(None, Some(used_elem.len as usize)); + .restr_size(None, Some(used_elem.len as usize)) + .unwrap(); } match tkn.await_queue { Some(_) => { @@ -290,7 +288,7 @@ impl SplitVq { /// The `notif` parameter indicates if the driver wants to have a notification for this specific /// transfer. This is only for performance optimization. As it is NOT ensured, that the device sees the /// updated notification flags before finishing transfers! - pub fn dispatch_batch(&self, tkns: Vec<TransferToken>, notif: bool) -> Vec<Transfer> { + pub fn dispatch_batch(&self, _tkns: Vec<TransferToken>, _notif: bool) -> Vec<Transfer> { unimplemented!(); } @@ -308,9 +306,9 @@ impl SplitVq { /// Tokens to get a reference to the provided await_queue, where they will be placed upon finish. pub fn dispatch_batch_await( &self, - tkns: Vec<TransferToken>, - await_queue: Rc<RefCell<VecDeque<Transfer>>>, - notif: bool, + _tkns: Vec<TransferToken>, + _await_queue: Rc<RefCell<VecDeque<Transfer>>>, + _notif: bool, ) { unimplemented!() } @@ -383,7 +381,7 @@ impl SplitVq { notif_cfg: &NotifCfg, size: VqSize, index: VqIndex, - feats: u64, + _feats: u64, ) -> Result<Self, ()> { // Get a handler to the queues configuration area. let mut vq_handler = match com_cfg.select_vq(index.into()) { @@ -423,9 +421,9 @@ impl SplitVq { }; unsafe { - let index = avail_raw.offset(2) as usize - avail_raw as usize; - let ring = avail_raw.offset(4) as usize - avail_raw as usize; - let event = avail_raw.offset(4 + 2 * (size as isize)) as usize - avail_raw as usize; + let _index = avail_raw.offset(2) as usize - avail_raw as usize; + let _ring = avail_raw.offset(4) as usize - avail_raw as usize; + let _event = avail_raw.offset(4 + 2 * (size as isize)) as usize - avail_raw as usize; } let used_ring = unsafe { @@ -441,9 +439,9 @@ impl SplitVq { }; unsafe { - let index = used_raw.offset(2) as usize - used_raw as usize; - let ring = used_raw.offset(4) as usize - used_raw as usize; - let event = used_raw.offset(4 + 8 * (size as isize)) as usize - used_raw as usize; + let _index = used_raw.offset(2) as usize - used_raw as usize; + let _ring = used_raw.offset(4) as usize - used_raw as usize; + let _event = used_raw.offset(4 + 8 * (size as isize)) as usize - used_raw as usize; } // Provide memory areas of the queues data structures to the device diff --git a/src/macros.rs b/src/macros.rs index 8b3bfba38038145c3364f90287ece972678fe5be..6eccf489254fc91d120a6a47849d61907f4c577d 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -39,7 +39,6 @@ macro_rules! println { macro_rules! switch_to_kernel { () => { crate::arch::irq::disable(); - #[allow(unused)] unsafe { let user_stack_pointer; // Store the user stack pointer and switch to the kernel stack @@ -60,7 +59,6 @@ macro_rules! switch_to_user { crate::arch::irq::disable(); let user_stack_pointer = core_scheduler().get_current_user_stack(); - #[allow(unused)] unsafe { // Switch to the user stack llvm_asm!("mov $0, %rsp" :: "r"(user_stack_pointer) :: "volatile"); @@ -73,8 +71,10 @@ macro_rules! kernel_function { ($f:ident($($x:tt)*)) => {{ use crate::arch::kernel::percore::*; - #[allow(unused)] #[allow(clippy::diverging_sub_expression)] + #[allow(unused_unsafe)] + #[allow(unused_variables)] + #[allow(unreachable_code)] unsafe { crate::arch::irq::disable(); let user_stack_pointer; diff --git a/src/scheduler/task.rs b/src/scheduler/task.rs index 882b949bcbd0d24ec6f8e58979f01dcd701bb23f..2149729ea7b3864164b94920b92fdd66549914d7 100644 --- a/src/scheduler/task.rs +++ b/src/scheduler/task.rs @@ -78,11 +78,9 @@ impl fmt::Display for Priority { #[allow(dead_code)] pub const HIGH_PRIO: Priority = Priority::from(3); -#[allow(dead_code)] pub const NORMAL_PRIO: Priority = Priority::from(2); #[allow(dead_code)] pub const LOW_PRIO: Priority = Priority::from(1); -#[allow(dead_code)] pub const IDLE_PRIO: Priority = Priority::from(0); /// Maximum number of priorities @@ -490,7 +488,6 @@ impl BlockedTaskQueue { } /// Blocks the given task for `wakeup_time` ticks, or indefinitely if None is given. - #[allow(unused_assignments)] pub fn add(&mut self, task: Rc<RefCell<Task>>, wakeup_time: Option<u64>) { { // Set the task status to Blocked. @@ -510,7 +507,7 @@ impl BlockedTaskQueue { // Shall the task automatically be woken up after a certain time? if let Some(wt) = wakeup_time { - let mut first_task = true; + let first_task = true; let mut cursor = self.list.cursor_front_mut(); let mut _guard = scopeguard::guard(first_task, |first_task| { // If the task is the new first task in the list, update the one-shot timer @@ -528,7 +525,6 @@ impl BlockedTaskQueue { return; } - first_task = false; cursor.move_next(); } diff --git a/src/syscalls/interfaces/mod.rs b/src/syscalls/interfaces/mod.rs index 2007c034dc1e661d49eb54c10bd7ddc9534594c2..bac29dafdd1d43651271a9309683037feb5f8706 100644 --- a/src/syscalls/interfaces/mod.rs +++ b/src/syscalls/interfaces/mod.rs @@ -6,7 +6,6 @@ // http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or // http://opensource.org/licenses/MIT>, at your option. This file may not be // copied, modified, or distributed except according to those terms. -#![allow(unused)] use alloc::boxed::Box; use alloc::vec::Vec;