diff --git a/Cargo.toml b/Cargo.toml index 35d0f61..c8c162a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,4 @@ license = "Apache-2.0" edition = "2021" [dependencies] -zerocopy = { version = "0.7.1", features = ["derive"] } +zerocopy = { version = "0.8.23", features = ["derive"] } diff --git a/src/bert.rs b/src/bert.rs index 1df8285..a471583 100644 --- a/src/bert.rs +++ b/src/bert.rs @@ -3,7 +3,10 @@ // SPDX-License-Identifier: Apache-2.0 // -use zerocopy::{byteorder, byteorder::LE, AsBytes}; +use zerocopy::{ + byteorder::{self, LE}, + Immutable, IntoBytes, +}; extern crate alloc; @@ -17,7 +20,7 @@ type U64 = byteorder::U64; /// unhandled errors that occurred in the previous boot. The format of /// the Boot Error Region follows that of an `Error Status Block`. #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub struct BERT { header: TableHeader, error_region_length: U32, diff --git a/src/cedt.rs b/src/cedt.rs index 3f1bab6..f739c50 100644 --- a/src/cedt.rs +++ b/src/cedt.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 // -use zerocopy::AsBytes; +use zerocopy::IntoBytes; extern crate alloc; use alloc::{boxed::Box, vec::Vec}; diff --git a/src/facs.rs b/src/facs.rs index ffb42c3..80b751e 100644 --- a/src/facs.rs +++ b/src/facs.rs @@ -4,13 +4,16 @@ // use crate::{Aml, AmlSink}; -use zerocopy::{byteorder, byteorder::LE, AsBytes}; +use zerocopy::{ + byteorder::{self, LE}, + Immutable, IntoBytes, +}; type U32 = byteorder::U32; type U64 = byteorder::U64; #[repr(C, packed)] -#[derive(Clone, Copy, Default, AsBytes)] +#[derive(Clone, Copy, Default, IntoBytes, Immutable)] pub struct FACS { pub signature: [u8; 4], pub length: U32, diff --git a/src/fadt.rs b/src/fadt.rs index da240cc..51bfdb5 100644 --- a/src/fadt.rs +++ b/src/fadt.rs @@ -4,7 +4,7 @@ // use crate::{gas::GAS, Aml, AmlSink}; -use zerocopy::{byteorder, byteorder::LE, AsBytes}; +use zerocopy::{byteorder, byteorder::LE, Immutable, IntoBytes}; type U16 = byteorder::U16; type U32 = byteorder::U32; @@ -64,7 +64,7 @@ pub enum PmProfile { } #[repr(C, packed)] -#[derive(Clone, Copy, Default, AsBytes)] +#[derive(Clone, Copy, Default, IntoBytes, Immutable)] pub struct FADTBuilder { pub signature: [u8; 4], pub length: U32, diff --git a/src/gas.rs b/src/gas.rs index 083b70e..3f6f836 100644 --- a/src/gas.rs +++ b/src/gas.rs @@ -4,12 +4,12 @@ // use crate::{Aml, AmlSink}; -use zerocopy::{byteorder, byteorder::LE, AsBytes}; +use zerocopy::{byteorder, byteorder::LE, Immutable, IntoBytes}; type U64 = byteorder::U64; #[repr(u8)] -#[derive(Clone, Copy, Debug, AsBytes, Default)] +#[derive(Clone, Copy, Debug, IntoBytes, Default, Immutable)] pub enum AddressSpace { #[default] SystemMemory = 0x0, @@ -28,7 +28,7 @@ pub enum AddressSpace { } #[repr(u8)] -#[derive(Clone, Copy, Debug, AsBytes, Default)] +#[derive(Clone, Copy, Debug, IntoBytes, Default, Immutable)] pub enum AccessSize { #[default] Undefined = 0, @@ -39,7 +39,7 @@ pub enum AccessSize { } #[repr(C, packed)] -#[derive(Clone, Copy, Debug, AsBytes, Default)] +#[derive(Clone, Copy, Debug, IntoBytes, Default, Immutable)] pub struct GAS { pub address_space_id: AddressSpace, pub register_bit_width: u8, diff --git a/src/hest.rs b/src/hest.rs index c2f88fd..c18bb15 100644 --- a/src/hest.rs +++ b/src/hest.rs @@ -3,7 +3,10 @@ // SPDX-License-Identifier: Apache-2.0 // -use zerocopy::{byteorder, byteorder::LE, AsBytes}; +use zerocopy::{ + byteorder::{self, LE}, + Immutable, IntoBytes, +}; extern crate alloc; use alloc::{boxed::Box, vec::Vec}; @@ -74,7 +77,7 @@ impl HEST { pub fn add_structure(&mut self, t: T) where - T: Aml + AsBytes + Clone + 'static, + T: Aml + IntoBytes + Immutable + Clone + 'static, { self.update_header(t.as_bytes()); self.structures.push(Box::new(t)); @@ -97,7 +100,7 @@ impl Aml for HEST { /// This structure contains information for configuring AER support on /// a given root port. #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub struct PcieAerRootPort { r#type: U16, source_id: U16, @@ -189,7 +192,7 @@ aml_as_bytes!(PcieAerRootPort); /// otherwise there should be one entry for each device that supports /// AER. #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub struct PcieAerDevice { r#type: U16, source_id: U16, @@ -250,7 +253,7 @@ aml_as_bytes!(PcieAerDevice); /// PCIe/PCI-X bridges that support AER implement fields that control /// the behavior of how errors are reported across the bridge. #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub struct PcieAerBridge { r#type: U16, source_id: U16, @@ -321,7 +324,7 @@ aml_as_bytes!(PcieAerBridge); /// for configure and control operations, therefore the error source /// must be configured by firmware during boot. #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub struct GenericHardwareSource { r#type: U16, source_id: U16, @@ -366,7 +369,7 @@ impl GenericHardwareSource { aml_as_bytes!(GenericHardwareSource); #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub struct NotificationStructure { r#type: NotificationType, length: u8, @@ -400,7 +403,7 @@ impl NotificationStructure { aml_as_bytes!(NotificationStructure); #[repr(u8)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub enum NotificationType { #[default] Polled = 0, @@ -422,7 +425,7 @@ pub enum NotificationType { } #[repr(u32)] -#[derive(Copy, Clone, Debug, AsBytes, Default)] +#[derive(Copy, Clone, Debug, IntoBytes, Immutable, Default)] pub enum ErrorSeverity { Recoverable = 0, Fatal = 1, @@ -543,7 +546,7 @@ impl Aml for GenericErrorData { /// for HW-reduced platforms that rely on "RAS controllers" to generate generic /// error records. #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub struct GenericHardwareSourceV2 { r#type: U16, source_id: U16, diff --git a/src/hmat.rs b/src/hmat.rs index 516094a..898a331 100644 --- a/src/hmat.rs +++ b/src/hmat.rs @@ -3,7 +3,10 @@ // SPDX-License-Identifier: Apache-2.0 // -use zerocopy::{byteorder, byteorder::LE, AsBytes}; +use zerocopy::{ + byteorder::{self, LE}, + Immutable, IntoBytes, +}; extern crate alloc; use alloc::{boxed::Box, vec, vec::Vec}; @@ -101,7 +104,7 @@ impl Aml for HMAT { // by the memory subsystem and its associativity with a processor // proximity domain. #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub struct MemoryProximityDomain { r#type: U16, _reserved0: U16, diff --git a/src/lib.rs b/src/lib.rs index 55ac2cf..c30c0c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,7 +34,10 @@ pub mod xsdt; extern crate alloc; -use zerocopy::{byteorder, byteorder::LE, AsBytes}; +use zerocopy::{ + byteorder::{self, LE}, + Immutable, IntoBytes, +}; type U32 = byteorder::U32; @@ -89,7 +92,7 @@ impl AmlSink for alloc::vec::Vec { /// Standard header for many ACPI tables #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] struct TableHeader { pub signature: [u8; 4], pub length: U32, diff --git a/src/madt.rs b/src/madt.rs index b0c05af..9c9d777 100644 --- a/src/madt.rs +++ b/src/madt.rs @@ -3,7 +3,10 @@ // SPDX-License-Identifier: Apache-2.0 // -use zerocopy::{byteorder, byteorder::LE, AsBytes}; +use zerocopy::{ + byteorder::{self, LE}, + Immutable, IntoBytes, +}; extern crate alloc; use alloc::{boxed::Box, vec::Vec}; @@ -30,7 +33,7 @@ enum MadtStructureType { } #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] struct Header { table_header: TableHeader, /// Must be ignored by OSPM for RISC-V @@ -111,7 +114,7 @@ impl MADT { pub fn add_structure(&mut self, t: T) where - T: Aml + AsBytes + Clone + 'static, + T: Aml + IntoBytes + Immutable + Clone + 'static, { self.update_header(t.as_bytes()); self.structures.push(Box::new(t)); @@ -136,7 +139,7 @@ impl Aml for MADT { /// Processor-Local APIC #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub struct ProcessorLocalApic { r#type: u8, length: u8, @@ -169,7 +172,7 @@ aml_as_bytes!(ProcessorLocalApic); /// I/O APIC #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub struct IoApic { r#type: u8, length: u8, @@ -196,7 +199,7 @@ aml_as_bytes!(IoApic); /// GIC CPU Interface (GICC) #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub struct Gicc { r#type: u8, length: u8, @@ -302,7 +305,7 @@ pub enum GicVersion { /// GIC Distributor (GICD) Structure #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub struct Gicd { r#type: u8, length: u8, @@ -334,7 +337,7 @@ aml_as_bytes!(Gicd); /// GIC MSI Frame Structure #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub struct GicMsi { r#type: u8, length: u8, @@ -372,7 +375,7 @@ aml_as_bytes!(GicMsi); /// GIC Redistributor (GICR) Structure #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub struct Gicr { r#type: u8, length: u8, @@ -398,7 +401,7 @@ aml_as_bytes!(Gicr); /// GIC Interrupt Translation Service (ITS) Structure #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub struct GicIts { r#type: u8, length: u8, @@ -428,7 +431,7 @@ aml_as_bytes!(GicIts); /// RISC-V platforms need to have a simple, per-hart interrupt controller /// available to supervisor mode. #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub struct RINTC { r#type: u8, length: u8, @@ -486,7 +489,7 @@ aml_as_bytes!(RINTC); // provides information common across processors. The per-processor // information will be provided by the RINTC structure. #[repr(C, packed)] -#[derive(Copy, Clone, Debug, Default, AsBytes)] +#[derive(Copy, Clone, Debug, Default, IntoBytes, Immutable)] pub struct IMSIC { r#type: u8, length: u8, @@ -547,7 +550,7 @@ aml_as_bytes!(IMSIC); // interrupts only in the form of MSIs. In that case, the role of an // APLIC is to convert wired interrupts into MSIs for harts. #[repr(C, packed)] -#[derive(Copy, Clone, Debug, AsBytes)] +#[derive(Copy, Clone, Debug, IntoBytes, Immutable)] pub struct APLIC { r#type: u8, length: u8, @@ -596,7 +599,7 @@ assert_same_size!(APLIC, [u8; 36]); aml_as_bytes!(APLIC); #[repr(C, packed)] -#[derive(Copy, Clone, Debug, AsBytes)] +#[derive(Copy, Clone, Debug, IntoBytes, Immutable)] pub struct PLIC { r#type: u8, length: u8, diff --git a/src/mcfg.rs b/src/mcfg.rs index a8e9ac4..69d881b 100644 --- a/src/mcfg.rs +++ b/src/mcfg.rs @@ -7,7 +7,10 @@ extern crate alloc; use crate::{Aml, AmlSink, Checksum, TableHeader}; use alloc::vec::Vec; -use zerocopy::{byteorder, byteorder::LE, AsBytes}; +use zerocopy::{ + byteorder::{self, LE}, + Immutable, IntoBytes, +}; type U16 = byteorder::U16; type U64 = byteorder::U64; @@ -85,7 +88,7 @@ impl Aml for MCFG { } #[repr(C, packed)] -#[derive(Copy, Clone, Debug, Default, AsBytes)] +#[derive(Copy, Clone, Debug, Default, IntoBytes, Immutable)] struct EcamEntry { base_addr: U64, segment: U16, diff --git a/src/pptt.rs b/src/pptt.rs index f84cd42..1fa2dbb 100644 --- a/src/pptt.rs +++ b/src/pptt.rs @@ -6,7 +6,10 @@ extern crate alloc; use alloc::{boxed::Box, vec::Vec}; -use zerocopy::{byteorder, byteorder::LE, AsBytes}; +use zerocopy::{ + byteorder::{self, LE}, + Immutable, IntoBytes, +}; use crate::{aml_as_bytes, u8sum, Aml, AmlSink, Checksum, TableHeader}; @@ -295,7 +298,7 @@ impl CacheNodeBuilder { } #[repr(C, packed)] -#[derive(Copy, Clone, Debug, Default, AsBytes)] +#[derive(Copy, Clone, Debug, Default, IntoBytes, Immutable)] pub struct CacheNode { r#type: u8, length: u8, diff --git a/src/rhct.rs b/src/rhct.rs index 7401a9d..95b0898 100644 --- a/src/rhct.rs +++ b/src/rhct.rs @@ -7,13 +7,16 @@ extern crate alloc; use crate::{u8sum, Aml, AmlSink, Checksum, TableHeader}; use alloc::{boxed::Box, vec, vec::Vec}; -use zerocopy::{byteorder, byteorder::LE, AsBytes}; +use zerocopy::{ + byteorder::{self, LE}, + Immutable, IntoBytes, +}; type U32 = byteorder::U32; type U64 = byteorder::U64; #[repr(C, packed)] -#[derive(Clone, Copy, Default, AsBytes)] +#[derive(Clone, Copy, Default, IntoBytes, Immutable)] struct Header { table_header: TableHeader, _reserved: u32, diff --git a/src/rimt.rs b/src/rimt.rs index 0dd2517..0c1c95f 100644 --- a/src/rimt.rs +++ b/src/rimt.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 // -use zerocopy::AsBytes; +use zerocopy::IntoBytes; extern crate alloc; use alloc::{boxed::Box, string::String, vec::Vec}; diff --git a/src/rqsc.rs b/src/rqsc.rs index 65710da..5ad6921 100644 --- a/src/rqsc.rs +++ b/src/rqsc.rs @@ -3,7 +3,10 @@ // SPDX-License-Identifier: Apache-2.0 // -use zerocopy::{byteorder, byteorder::LE, AsBytes}; +use zerocopy::{ + byteorder::{self, LE}, + Immutable, IntoBytes, +}; extern crate alloc; use alloc::vec::Vec; @@ -282,7 +285,7 @@ impl Aml for ResourceID { } } -#[derive(Clone, Debug, Default, AsBytes)] +#[derive(Clone, Debug, Default, IntoBytes, Immutable)] #[repr(C, packed)] pub struct CacheResource { // Resource ID 1 @@ -305,7 +308,7 @@ impl CacheResource { } } -#[derive(Clone, Debug, Default, AsBytes)] +#[derive(Clone, Debug, Default, IntoBytes, Immutable)] #[repr(C, packed)] pub struct MemoryAffinityStructureResource { // Resource ID 1 @@ -335,7 +338,7 @@ impl MemoryAffinityStructureResource { } } -#[derive(Clone, Debug, Default, AsBytes)] +#[derive(Clone, Debug, Default, IntoBytes, Immutable)] #[repr(C, packed)] pub struct ACPIDeviceResource { // Resource ID 1 @@ -356,7 +359,7 @@ impl ACPIDeviceResource { } } -#[derive(Clone, Debug, Default, AsBytes)] +#[derive(Clone, Debug, Default, IntoBytes, Immutable)] #[repr(C, packed)] pub struct PCIDeviceResource { // Resource ID 1 diff --git a/src/rsdp.rs b/src/rsdp.rs index 869b477..f1aee11 100644 --- a/src/rsdp.rs +++ b/src/rsdp.rs @@ -4,7 +4,10 @@ // SPDX-License-Identifier: Apache-2.0 // -use zerocopy::{byteorder, byteorder::LE, AsBytes}; +use zerocopy::{ + byteorder::{self, LE}, + Immutable, IntoBytes, +}; type U32 = byteorder::U32; type U64 = byteorder::U64; @@ -12,7 +15,7 @@ type U64 = byteorder::U64; use crate::{aml_as_bytes, Aml, AmlSink}; #[repr(C, packed)] -#[derive(Clone, Copy, Default, AsBytes)] +#[derive(Clone, Copy, Default, IntoBytes, Immutable)] pub struct Rsdp { pub signature: [u8; 8], pub checksum: u8, diff --git a/src/sdt.rs b/src/sdt.rs index 08921a4..4d5672f 100644 --- a/src/sdt.rs +++ b/src/sdt.rs @@ -7,10 +7,10 @@ extern crate alloc; use crate::{Aml, AmlSink}; use alloc::vec::Vec; -use zerocopy::AsBytes; +use zerocopy::{FromBytes, Immutable, IntoBytes}; #[repr(C, packed)] -#[derive(Clone, Copy, AsBytes)] +#[derive(Clone, Copy, IntoBytes, Immutable, FromBytes)] pub struct GenericAddress { pub address_space_id: u8, pub register_bit_width: u8, @@ -101,7 +101,7 @@ impl Sdt { self.data.as_slice() } - pub fn append(&mut self, value: T) { + pub fn append(&mut self, value: T) { let orig_length = self.data.len(); let new_length = orig_length + core::mem::size_of::(); self.data.resize(new_length, 0); @@ -125,7 +125,7 @@ impl Sdt { } /// Write a value at the given offset - pub fn write(&mut self, offset: usize, value: T) { + pub fn write(&mut self, offset: usize, value: T) { self.write_bytes(offset, value.as_bytes()) } diff --git a/src/slit.rs b/src/slit.rs index a70e9c7..b8be004 100644 --- a/src/slit.rs +++ b/src/slit.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 // -use zerocopy::AsBytes; +use zerocopy::IntoBytes; extern crate alloc; use alloc::vec::Vec; diff --git a/src/spcr.rs b/src/spcr.rs index 7bd2414..c5915a9 100644 --- a/src/spcr.rs +++ b/src/spcr.rs @@ -3,7 +3,10 @@ // SPDX-License-Identifier: Apache-2.0 // -use zerocopy::{byteorder, byteorder::LE, AsBytes}; +use zerocopy::{ + byteorder::{self, LE}, + Immutable, IntoBytes, +}; use crate::{assert_same_size, gas, Aml, AmlSink, Checksum, TableHeader}; use core::mem::size_of; @@ -96,7 +99,7 @@ enum SerialPortSubType { } #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] struct SerialPortInfo { interface_type: u8, reserved0: [u8; 3], diff --git a/src/srat.rs b/src/srat.rs index e0be0ec..fbc4dd6 100644 --- a/src/srat.rs +++ b/src/srat.rs @@ -3,7 +3,10 @@ // SPDX-License-Identifier: Apache-2.0 // -use zerocopy::{byteorder, byteorder::LE, AsBytes}; +use zerocopy::{ + byteorder::{self, LE}, + Immutable, IntoBytes, +}; extern crate alloc; use alloc::{boxed::Box, vec::Vec}; @@ -284,7 +287,7 @@ impl Aml for GenericInitiator { } #[repr(C, packed)] -#[derive(Clone, Copy, Debug, Default, AsBytes)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable)] pub struct RintcAffinity { r#type: u8, length: u8, diff --git a/src/tpm2.rs b/src/tpm2.rs index 4fe232a..41a003b 100644 --- a/src/tpm2.rs +++ b/src/tpm2.rs @@ -3,7 +3,10 @@ // SPDX-License-Identifier: Apache-2.0 // -use zerocopy::{byteorder, byteorder::LE, AsBytes}; +use zerocopy::{ + byteorder::{self, LE}, + Immutable, IntoBytes, +}; extern crate alloc; @@ -70,7 +73,7 @@ impl Aml for TpmClient1_2 { } } -#[derive(Copy, Clone, Default, AsBytes)] +#[derive(Copy, Clone, Default, IntoBytes, Immutable)] #[repr(C, packed)] pub struct TpmServer1_2 { header: TableHeader, diff --git a/src/viot.rs b/src/viot.rs index db1374c..8414fef 100644 --- a/src/viot.rs +++ b/src/viot.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 // -use zerocopy::AsBytes; +use zerocopy::IntoBytes; extern crate alloc; use alloc::{boxed::Box, vec::Vec}; diff --git a/src/xsdt.rs b/src/xsdt.rs index e972ba6..a91ee3f 100644 --- a/src/xsdt.rs +++ b/src/xsdt.rs @@ -7,7 +7,7 @@ extern crate alloc; use crate::{Aml, AmlSink, Checksum, TableHeader}; use alloc::vec::Vec; -use zerocopy::AsBytes; +use zerocopy::IntoBytes; pub struct XSDT { header: TableHeader,