瀏覽代碼

Set up more sensible rustfmt config and fmt crate

Isaac Woods 6 年之前
父節點
當前提交
68c2321299
共有 11 個文件被更改,包括 92 次插入115 次删除
  1. 11 0
      rustfmt.toml
  2. 2 4
      src/aml/mod.rs
  3. 24 40
      src/aml/parser.rs
  4. 2 10
      src/aml/value.rs
  5. 9 4
      src/fadt.rs
  6. 1 2
      src/hpet.rs
  7. 13 31
      src/lib.rs
  8. 25 12
      src/madt.rs
  9. 3 5
      src/rsdp.rs
  10. 1 3
      src/rsdp_search.rs
  11. 1 4
      src/sdt.rs

+ 11 - 0
rustfmt.toml

@@ -0,0 +1,11 @@
+unstable_features = true
+edition = "2018"
+
+merge_imports = true
+imports_layout = "HorizontalVertical"
+use_field_init_shorthand = true
+use_try_shorthand = true
+format_doc_comments = true
+wrap_comments = true
+comment_width = 100
+use_small_heuristics = "max"

+ 2 - 4
src/aml/mod.rs

@@ -5,10 +5,8 @@ mod value;
 
 pub use self::value::AmlValue;
 
-use self::parser::AmlParser;
-use self::stream::AmlStream;
-use crate::sdt::SdtHeader;
-use crate::{Acpi, AcpiError, AcpiHandler, PhysicalMapping};
+use self::{parser::AmlParser, stream::AmlStream};
+use crate::{sdt::SdtHeader, Acpi, AcpiError, AcpiHandler, PhysicalMapping};
 use alloc::string::String;
 use core::{mem, slice};
 

+ 24 - 40
src/aml/parser.rs

@@ -1,6 +1,9 @@
-use super::stream::AmlStream;
-use super::value::{AmlValue, FieldFlags, RegionSpace};
-use super::{opcodes, AmlError};
+use super::{
+    opcodes,
+    stream::AmlStream,
+    value::{AmlValue, FieldFlags, RegionSpace},
+    AmlError,
+};
 use crate::{Acpi, AcpiHandler};
 use alloc::string::String;
 use bit_field::BitField;
@@ -14,9 +17,9 @@ struct FieldInfo {
 }
 
 /// This is used internally by the parser. Often, we're only interested in offset of the end of the
-/// current explicit-length structure, so we know when to stop parsing it. However, various constants
-/// (e.g. the size of fields) are also encoded as PkgLengths, and so sometimes we want to access
-/// the raw data as well.
+/// current explicit-length structure, so we know when to stop parsing it. However, various
+/// constants (e.g. the size of fields) are also encoded as PkgLengths, and so sometimes we want to
+/// access the raw data as well.
 struct PkgLength {
     pub raw_length: u32,
     pub end_offset: u32,
@@ -56,12 +59,7 @@ where
         scope: &str,
         stream: AmlStream<'s>,
     ) -> Result<(), AmlError> {
-        let mut parser = AmlParser {
-            acpi,
-            handler,
-            scope: String::from(scope),
-            stream,
-        };
+        let mut parser = AmlParser { acpi, handler, scope: String::from(scope), stream };
 
         let end_offset = parser.stream.len() as u32;
         parser.parse_term_list(end_offset)
@@ -134,9 +132,10 @@ where
         /*
          * TermObj := NameSpaceModifierObj | NamedObj | Type1Opcode | Type2Opcode
          * NameSpaceModifierObj := DefAlias | DefName | DefScope
-         * NamedObj := DefBankField | DefCreateBitField | DefCreateByteField | DefCreateDWordField |
-         *             DefCreateField | DefCreateQWordField | DefCreateWordField | DefDataRegion |
-         *             DefExternal | DefOpRegion | DefPowerRes | DefProcessor | DefThermalZone
+         * NamedObj := DefBankField | DefCreateBitField | DefCreateByteField |
+         * DefCreateDWordField |             DefCreateField | DefCreateQWordField |
+         * DefCreateWordField | DefDataRegion |             DefExternal | DefOpRegion |
+         * DefPowerRes | DefProcessor | DefThermalZone
          */
         try_parse!(
             self,
@@ -213,11 +212,7 @@ where
         self.acpi.namespace.insert(
             // self.resolve_path(name)?, TODO: I thought this would work with nll?
             namespace_path,
-            AmlValue::OpRegion {
-                region: region_space,
-                offset,
-                length,
-            },
+            AmlValue::OpRegion { region: region_space, offset, length },
         );
 
         Ok(())
@@ -267,8 +262,8 @@ where
         /*
          * NamedField := NameSeg PkgLength
          *
-         * This encodes the size of the field using a PkgLength - it doesn't mark the length of an
-         * explicit-length structure!
+         * This encodes the size of the field using a PkgLength - it doesn't mark the length of
+         * an explicit-length structure!
          */
         let name = String::from(name_seg_to_string(&self.parse_name_seg()?)?);
         let length = self.parse_pkg_length()?.raw_length as u64;
@@ -356,9 +351,9 @@ where
 
     fn parse_type1_opcode(&mut self) -> Result<(), AmlError> {
         /*
-         * Type1Opcode := DefBreak | DefBreakPoint | DefContinue | DefFatal | DefIfElse | DefLoad |
-         *                DefNoop | DefNotify | DefRelease | DefReset | DefReturn | DefSignal |
-         *                DefSleep | DefStall | DefUnload | DefWhile
+         * Type1Opcode := DefBreak | DefBreakPoint | DefContinue | DefFatal | DefIfElse | DefLoad
+         * |                DefNoop | DefNotify | DefRelease | DefReset | DefReturn |
+         * DefSignal |                DefSleep | DefStall | DefUnload | DefWhile
          */
         unimplemented!(); // TODO
     }
@@ -386,10 +381,7 @@ where
                 end_offset,
                 self.stream.offset()
             );
-            return Ok(PkgLength {
-                raw_length: length,
-                end_offset,
-            });
+            return Ok(PkgLength { raw_length: length, end_offset });
         }
 
         let mut length = u32::from(lead_byte.get_bits(0..4));
@@ -405,10 +397,7 @@ where
             end_offset,
             self.stream.offset()
         );
-        Ok(PkgLength {
-            raw_length: length,
-            end_offset,
-        })
+        Ok(PkgLength { raw_length: length, end_offset })
     }
 
     fn parse_name_string(&mut self) -> Result<String, AmlError> {
@@ -450,10 +439,7 @@ where
                 let first = self.parse_name_seg()?;
                 let second = self.parse_name_seg()?;
 
-                Ok(
-                    String::from(str::from_utf8(&first).unwrap())
-                        + str::from_utf8(&second).unwrap(),
-                )
+                Ok(String::from(str::from_utf8(&first).unwrap()) + str::from_utf8(&second).unwrap())
             }
 
             opcodes::MULTI_NAME_PREFIX => {
@@ -461,9 +447,7 @@ where
                 unimplemented!();
             }
 
-            _ => Ok(String::from(
-                str::from_utf8(&self.parse_name_seg()?).unwrap(),
-            )),
+            _ => Ok(String::from(str::from_utf8(&self.parse_name_seg()?).unwrap())),
         }
     }
 

+ 2 - 10
src/aml/value.rs

@@ -70,17 +70,9 @@ impl FieldFlags {
 pub enum AmlValue {
     Integer(u64),
 
-    OpRegion {
-        region: RegionSpace,
-        offset: u64,
-        length: u64,
-    },
+    OpRegion { region: RegionSpace, offset: u64, length: u64 },
 
-    Field {
-        flags: FieldFlags,
-        offset: u64,
-        length: u64,
-    },
+    Field { flags: FieldFlags, offset: u64, length: u64 },
 }
 
 impl AmlValue {

+ 9 - 4
src/fadt.rs

@@ -1,7 +1,12 @@
-use crate::aml::{parse_aml_table, AmlTable};
-use crate::sdt;
-use crate::sdt::SdtHeader;
-use crate::{Acpi, AcpiError, AcpiHandler, GenericAddress, PhysicalMapping};
+use crate::{
+    aml::{parse_aml_table, AmlTable},
+    sdt::{self, SdtHeader},
+    Acpi,
+    AcpiError,
+    AcpiHandler,
+    GenericAddress,
+    PhysicalMapping,
+};
 
 /// Represents the Fixed ACPI Description Table (FADT). This table contains various fixed hardware
 /// details, such as the addresses of the hardware register blocks. It also contains a pointer to

+ 1 - 2
src/hpet.rs

@@ -1,5 +1,4 @@
-use crate::sdt::SdtHeader;
-use crate::{AcpiError, GenericAddress, PhysicalMapping};
+use crate::{sdt::SdtHeader, AcpiError, GenericAddress, PhysicalMapping};
 
 #[repr(C, packed)]
 pub struct Hpet {

+ 13 - 31
src/lib.rs

@@ -22,18 +22,11 @@ mod rsdp;
 mod rsdp_search;
 mod sdt;
 
-pub use crate::aml::AmlError;
-pub use crate::madt::MadtError;
-pub use crate::rsdp_search::search_for_rsdp_bios;
-
-use crate::aml::AmlValue;
-use crate::interrupt::InterruptModel;
-use crate::rsdp::Rsdp;
-use crate::sdt::SdtHeader;
+pub use crate::{aml::AmlError, madt::MadtError, rsdp_search::search_for_rsdp_bios};
+
+use crate::{aml::AmlValue, interrupt::InterruptModel, rsdp::Rsdp, sdt::SdtHeader};
 use alloc::{collections::BTreeMap, string::String, vec::Vec};
-use core::mem;
-use core::ops::Deref;
-use core::ptr::NonNull;
+use core::{mem, ops::Deref, ptr::NonNull};
 
 #[derive(Debug)]
 // TODO: manually implement Debug to print signatures correctly etc.
@@ -97,12 +90,7 @@ impl Processor {
         state: ProcessorState,
         is_ap: bool,
     ) -> Processor {
-        Processor {
-            processor_uid,
-            local_apic_id,
-            state,
-            is_ap,
-        }
+        Processor { processor_uid, local_apic_id, state, is_ap }
     }
 }
 
@@ -129,10 +117,10 @@ impl<T> Deref for PhysicalMapping<T> {
 /// however you please, as long as they conform to the documentation of each function.
 pub trait AcpiHandler {
     /// Given a starting physical address and a size, map a region of physical memory that contains
-    /// a `T` (but may be bigger than `size_of::<T>()`). The address doesn't have to be page-aligned,
-    /// so the implementation may have to add padding to either end. The given size must be greater
-    /// or equal to the size of a `T`. The virtual address the memory is mapped to does not matter,
-    /// as long as it is accessible from `acpi`.
+    /// a `T` (but may be bigger than `size_of::<T>()`). The address doesn't have to be
+    /// page-aligned, so the implementation may have to add padding to either end. The given
+    /// size must be greater or equal to the size of a `T`. The virtual address the memory is
+    /// mapped to does not matter, as long as it is accessible from `acpi`.
     fn map_physical_region<T>(
         &mut self,
         physical_address: usize,
@@ -255,11 +243,8 @@ where
             ((mapping.virtual_start.as_ptr() as usize) + mem::size_of::<SdtHeader>()) as *const u32;
 
         for i in 0..num_tables {
-            sdt::dispatch_sdt(
-                &mut acpi,
-                handler,
-                unsafe { *tables_base.offset(i as isize) } as usize,
-            )?;
+            sdt::dispatch_sdt(&mut acpi, handler, unsafe { *tables_base.offset(i as isize) }
+                as usize)?;
         }
     } else {
         /*
@@ -273,11 +258,8 @@ where
             ((mapping.virtual_start.as_ptr() as usize) + mem::size_of::<SdtHeader>()) as *const u64;
 
         for i in 0..num_tables {
-            sdt::dispatch_sdt(
-                &mut acpi,
-                handler,
-                unsafe { *tables_base.offset(i as isize) } as usize,
-            )?;
+            sdt::dispatch_sdt(&mut acpi, handler, unsafe { *tables_base.offset(i as isize) }
+                as usize)?;
         }
     }
 

+ 25 - 12
src/madt.rs

@@ -1,12 +1,23 @@
-use crate::interrupt::{
-    InterruptModel, InterruptSourceOverride, IoApic, NmiSource, Polarity, TriggerMode,
+use crate::{
+    interrupt::{
+        InterruptModel,
+        InterruptSourceOverride,
+        IoApic,
+        NmiSource,
+        Polarity,
+        TriggerMode,
+    },
+    sdt::SdtHeader,
+    Acpi,
+    AcpiError,
+    AcpiHandler,
+    PhysicalMapping,
+    Processor,
+    ProcessorState,
 };
-use crate::sdt::SdtHeader;
-use crate::{Acpi, AcpiError, AcpiHandler, PhysicalMapping, Processor, ProcessorState};
 use alloc::vec::Vec;
 use bit_field::BitField;
-use core::marker::PhantomData;
-use core::mem;
+use core::{marker::PhantomData, mem};
 
 #[derive(Debug)]
 pub enum MadtError {
@@ -200,7 +211,8 @@ struct LocalApicAddressOverrideEntry {
     local_apic_address: u64,
 }
 
-/// If this entry is present, the system has an I/O SAPIC, which must be used instead of the I/O APIC.
+/// If this entry is present, the system has an I/O SAPIC, which must be used instead of the I/O
+/// APIC.
 #[repr(C, packed)]
 struct IoSapicEntry {
     header: EntryHeader,
@@ -337,9 +349,10 @@ where
     (*mapping).header.validate(b"APIC")?;
 
     /*
-     * If the MADT doesn't contain another supported interrupt model (either APIC, SAPIC, X2APIC or
-     * GIC), and the system supports the legacy i8259 PIC, recommend that.
-     * TODO: It's not clear how trustworthy this field is - should we be relying on it in any way?
+     * If the MADT doesn't contain another supported interrupt model (either APIC, SAPIC, X2APIC
+     * or GIC), and the system supports the legacy i8259 PIC, recommend that.
+     * TODO: It's not clear how trustworthy this field is - should we be relying on it in any
+     * way?
      */
     if (*mapping).supports_8259() {
         acpi.interrupt_model = Some(InterruptModel::Pic);
@@ -402,8 +415,8 @@ fn parse_apic_model(
         match entry {
             MadtEntry::LocalApic(ref entry) => {
                 /*
-                 * The first processor is the BSP. Subsequent ones are APs. If we haven't found the
-                 * BSP yet, this must be it.
+                 * The first processor is the BSP. Subsequent ones are APs. If we haven't found
+                 * the BSP yet, this must be it.
                  */
                 let is_ap = acpi.boot_processor.is_some();
                 let is_disabled = !unsafe { entry.flags.get_bit(0) };

+ 3 - 5
src/rsdp.rs

@@ -5,7 +5,8 @@ use core::{mem, str};
 ///
 /// On BIOS systems, it is either found in the first 1KB of the Extended Bios Data Area, or between
 /// 0x000E0000 and 0x000FFFFF. The signature is always on a 16 byte boundary. On (U)EFI, it may not
-/// be located in these locations, and so an address should be found in the EFI_SYSTEM_TABLE instead.
+/// be located in these locations, and so an address should be found in the EFI_SYSTEM_TABLE
+/// instead.
 ///
 /// The recommended way of locating the RSDP is to let the bootloader do it - Multiboot2 can pass a
 /// tag with the physical address of it. If this is not possible, a manual scan can be done.
@@ -89,10 +90,7 @@ impl Rsdp {
     }
 
     pub(crate) fn xsdt_address(&self) -> u64 {
-        assert!(
-            self.revision > 0,
-            "Tried to read extended RSDP field with ACPI Version 1.0"
-        );
+        assert!(self.revision > 0, "Tried to read extended RSDP field with ACPI Version 1.0");
         self.xsdt_address
     }
 }

+ 1 - 3
src/rsdp_search.rs

@@ -1,6 +1,4 @@
-use crate::rsdp::Rsdp;
-use crate::Acpi;
-use crate::{parse_validated_rsdp, AcpiError, AcpiHandler};
+use crate::{parse_validated_rsdp, rsdp::Rsdp, Acpi, AcpiError, AcpiHandler};
 use core::{mem, ops::RangeInclusive};
 
 /// The pointer to the EBDA (Extended Bios Data Area) start segment pointer

+ 1 - 4
src/sdt.rs

@@ -1,7 +1,4 @@
-use crate::fadt::Fadt;
-use crate::hpet::Hpet;
-use crate::madt::Madt;
-use crate::{Acpi, AcpiError, AcpiHandler};
+use crate::{fadt::Fadt, hpet::Hpet, madt::Madt, Acpi, AcpiError, AcpiHandler};
 use core::{mem, str};
 
 /// All SDTs share the same header, and are `length` bytes long. The signature tells us which SDT