From 50305cd3b6f86be7616a15efb38c5eabc6085934 Mon Sep 17 00:00:00 2001 From: SwarajGawande Date: Sun, 11 Sep 2022 19:03:49 +0530 Subject: [PATCH 1/6] start description --- docs/vmm-reference-registers.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 docs/vmm-reference-registers.md diff --git a/docs/vmm-reference-registers.md b/docs/vmm-reference-registers.md new file mode 100644 index 0000000..e69de29 From 15082677369caf9ca4050acba92d39cbac941d1f Mon Sep 17 00:00:00 2001 From: SwarajGawande Date: Sun, 11 Sep 2022 22:12:36 +0530 Subject: [PATCH 2/6] FDT description --- docs/vmm-reference-fdt.md | 44 +++++++++++++++++++++++++++++++++ docs/vmm-reference-registers.md | 0 2 files changed, 44 insertions(+) create mode 100644 docs/vmm-reference-fdt.md delete mode 100644 docs/vmm-reference-registers.md diff --git a/docs/vmm-reference-fdt.md b/docs/vmm-reference-fdt.md new file mode 100644 index 0000000..ffb9272 --- /dev/null +++ b/docs/vmm-reference-fdt.md @@ -0,0 +1,44 @@ +# [Flatenned Device Tree](../src/arch/src/lib.rs) + +## Description +VMM keeps track of the virtio devices in a data structure called Flatenned Device Tree. FDT as the name suggests is a Tree where each node is a device or collection of devices. There can be different types of nodes in the FDT which can be identified using the attributes of the node. Each node contains a key-value pair mapping which determine the type of the node and configuration of that node. +This arrangement provides an abstracts out the hardware specifications from the code. + +## Implementation +The implementation of the FDT in vmm-reference is done using rust crate vm_fdt and vm_memory so are the following import statements. +```rs +pub use vm_fdt::{Error as FdtError, FdtWriter}; +use vm_memory::{guest_memory::Error as GuestMemoryError, Bytes, GuestAddress, GuestMemory}; +``` +Then some constants are set up which include the max size of the FDT, start of DRAM in physical address space, base for MMIO and AXI ports and set up the virtual Generic Interrupt Controller.\ +Then the Error handler is set up with default error handler of both vm_memory and vm_fdt crates in addition to a error handler for cases of missing required configuration. +```rs +#[derive(Debug)] +pub enum Error { + Fdt(FdtError), + Memory(GuestMemoryError), + MissingRequiredConfig(String), +} +``` +The structure of the FdtBuilder is defined as +```rs +#[derive(Default)] +pub struct FdtBuilder { + cmdline: Option, + mem_size: Option, + num_vcpus: Option, + serial_console: Option<(u64, u64)>, + rtc: Option<(u64, u64)>, + virtio_devices: Vec, +} +``` +where each device in virtio_devices vector is in the form of DeviceInfo struct defined as follows +```rs +struct DeviceInfo { + addr: u64, + size: u64, + irq: u32, +} +``` + +FdtBuilder implementation provides with methods to create a new node in te FDT and then configure that node. It also provides methods to query number of virtio devices in that node and add or a device to them. \ No newline at end of file diff --git a/docs/vmm-reference-registers.md b/docs/vmm-reference-registers.md deleted file mode 100644 index e69de29..0000000 From 31b7c41e7d4b157cfb3dab4c2afa226050d28345 Mon Sep 17 00:00:00 2001 From: SwarajGawande Date: Sun, 11 Sep 2022 22:52:28 +0530 Subject: [PATCH 3/6] FDT description it2 --- docs/vmm-reference-fdt.md | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/docs/vmm-reference-fdt.md b/docs/vmm-reference-fdt.md index ffb9272..7336afd 100644 --- a/docs/vmm-reference-fdt.md +++ b/docs/vmm-reference-fdt.md @@ -5,7 +5,7 @@ VMM keeps track of the virtio devices in a data structure called Flatenned Devi This arrangement provides an abstracts out the hardware specifications from the code. ## Implementation -The implementation of the FDT in vmm-reference is done using rust crate vm_fdt and vm_memory so are the following import statements. +The implementation of the FDT for arm64 architecture in vmm-reference is done using rust crate vm_fdt and vm_memory so are the following import statements. ```rs pub use vm_fdt::{Error as FdtError, FdtWriter}; use vm_memory::{guest_memory::Error as GuestMemoryError, Bytes, GuestAddress, GuestMemory}; @@ -41,4 +41,27 @@ struct DeviceInfo { } ``` -FdtBuilder implementation provides with methods to create a new node in te FDT and then configure that node. It also provides methods to query number of virtio devices in that node and add or a device to them. \ No newline at end of file +FdtBuilder implementation provides with methods to create a new node in te FDT and then configure that node. It also provides methods to query number of virtio devices in that node and add or a device to them. + +Fdt struct is a vector of 8-bit unsigned integers +```rs +pub struct Fdt { + fdt_blob: Vec, +} +``` +while implementaion fpr Fdt includes method which writes this fdt_blob as slice in the guest memory. + +```rs +impl Fdt { + pub fn write_to_mem(&self, guest_mem: &T, fdt_load_offset: u64) -> Result<()> { + let fdt_address = GuestAddress(AARCH64_PHYS_MEM_START + fdt_load_offset); + guest_mem.write_slice(self.fdt_blob.as_slice(), fdt_address)?; + Ok(()) + } +} +``` + +Further we are provided with functions to create all the reuired types of nodes with thier neccessory configurations. THe supported types of nodes include chosen node, memory node, cpu node, gic (Generic Interrupt Controller) node, psci (Power State Coordination Interface) node, serial node, timer node, pmu (Performance Monitor Unit) node, rtc (Real Time Clock) node and virtio node. + +## Unit Testing +Testing includes creating a new FdtBuilder object and then check creating fdt without specifying one of the configurations required. In the case when that left out configuration in neccessory we should get MissingRequiredConfig error. \ No newline at end of file From eb8ca8d93704ba03b3e9ab4fb0aa1b2d1f98d183 Mon Sep 17 00:00:00 2001 From: SwarajGawande Date: Sun, 11 Sep 2022 23:02:56 +0530 Subject: [PATCH 4/6] FDT description it3 --- docs/vmm-reference-fdt.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/vmm-reference-fdt.md b/docs/vmm-reference-fdt.md index 7336afd..f56e536 100644 --- a/docs/vmm-reference-fdt.md +++ b/docs/vmm-reference-fdt.md @@ -1,16 +1,16 @@ # [Flatenned Device Tree](../src/arch/src/lib.rs) ## Description -VMM keeps track of the virtio devices in a data structure called Flatenned Device Tree. FDT as the name suggests is a Tree where each node is a device or collection of devices. There can be different types of nodes in the FDT which can be identified using the attributes of the node. Each node contains a key-value pair mapping which determine the type of the node and configuration of that node. +>VMM keeps track of the virtio devices in a data structure called Flatenned Device Tree. FDT as the name suggests is a Tree where each node is a device or collection of devices. There can be different types of nodes in the FDT which can be identified using the attributes of the node. Each node contains a key-value pair mapping which determine the type of the node and configuration of that node. This arrangement provides an abstracts out the hardware specifications from the code. ## Implementation -The implementation of the FDT for arm64 architecture in vmm-reference is done using rust crate vm_fdt and vm_memory so are the following import statements. +>The implementation of the FDT for arm64 architecture in `vmm-reference` is done using rust crate `vm_fdt` and `vm_memory` so are the following import statements. ```rs pub use vm_fdt::{Error as FdtError, FdtWriter}; use vm_memory::{guest_memory::Error as GuestMemoryError, Bytes, GuestAddress, GuestMemory}; ``` -Then some constants are set up which include the max size of the FDT, start of DRAM in physical address space, base for MMIO and AXI ports and set up the virtual Generic Interrupt Controller.\ +>Then some constants are set up which include the max size of the FDT, start of DRAM in physical address space, base for MMIO and AXI ports and set up the virtual `Generic Interrupt Controller`.\ Then the Error handler is set up with default error handler of both vm_memory and vm_fdt crates in addition to a error handler for cases of missing required configuration. ```rs #[derive(Debug)] @@ -61,7 +61,7 @@ impl Fdt { } ``` -Further we are provided with functions to create all the reuired types of nodes with thier neccessory configurations. THe supported types of nodes include chosen node, memory node, cpu node, gic (Generic Interrupt Controller) node, psci (Power State Coordination Interface) node, serial node, timer node, pmu (Performance Monitor Unit) node, rtc (Real Time Clock) node and virtio node. +>Further we are provided with functions to create all the reuired types of nodes with thier neccessory configurations. THe supported types of nodes include chosen node, memory node, cpu node, gic (Generic Interrupt Controller) node, psci (Power State Coordination Interface) node, serial node, timer node, pmu (Performance Monitor Unit) node, rtc (Real Time Clock) node and virtio node. ## Unit Testing -Testing includes creating a new FdtBuilder object and then check creating fdt without specifying one of the configurations required. In the case when that left out configuration in neccessory we should get MissingRequiredConfig error. \ No newline at end of file +>Testing includes creating a new FdtBuilder object and then check creating fdt without specifying one of the configurations required. In the case when that left out configuration in neccessory we should get MissingRequiredConfig error. \ No newline at end of file From 6e36bb994a0dfcd2e54a1a8ef4af5d13f977f552 Mon Sep 17 00:00:00 2001 From: SwarajGawande Date: Sun, 11 Sep 2022 23:14:55 +0530 Subject: [PATCH 5/6] FDT description it4 --- docs/vmm-reference-fdt.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/vmm-reference-fdt.md b/docs/vmm-reference-fdt.md index f56e536..e0d6586 100644 --- a/docs/vmm-reference-fdt.md +++ b/docs/vmm-reference-fdt.md @@ -1,16 +1,16 @@ # [Flatenned Device Tree](../src/arch/src/lib.rs) ## Description ->VMM keeps track of the virtio devices in a data structure called Flatenned Device Tree. FDT as the name suggests is a Tree where each node is a device or collection of devices. There can be different types of nodes in the FDT which can be identified using the attributes of the node. Each node contains a key-value pair mapping which determine the type of the node and configuration of that node. +VMM keeps track of the virtio devices in a data structure called Flatenned Device Tree. FDT as the name suggests is a Tree where each node is a device or collection of devices. There can be different types of nodes in the FDT which can be identified using the attributes of the node. Each node contains a key-value pair mapping which determine the type of the node and configuration of that node. This arrangement provides an abstracts out the hardware specifications from the code. ## Implementation ->The implementation of the FDT for arm64 architecture in `vmm-reference` is done using rust crate `vm_fdt` and `vm_memory` so are the following import statements. +The implementation of the FDT for arm64 architecture in `vmm-reference` is done using rust crate `vm_fdt` and `vm_memory` so are the following import statements. ```rs pub use vm_fdt::{Error as FdtError, FdtWriter}; use vm_memory::{guest_memory::Error as GuestMemoryError, Bytes, GuestAddress, GuestMemory}; ``` ->Then some constants are set up which include the max size of the FDT, start of DRAM in physical address space, base for MMIO and AXI ports and set up the virtual `Generic Interrupt Controller`.\ +Then some constants are set up which include the max size of the FDT, start of DRAM in physical address space, base for MMIO and AXI ports and set up the virtual `Generic Interrupt Controller`.\ Then the Error handler is set up with default error handler of both vm_memory and vm_fdt crates in addition to a error handler for cases of missing required configuration. ```rs #[derive(Debug)] @@ -61,7 +61,17 @@ impl Fdt { } ``` ->Further we are provided with functions to create all the reuired types of nodes with thier neccessory configurations. THe supported types of nodes include chosen node, memory node, cpu node, gic (Generic Interrupt Controller) node, psci (Power State Coordination Interface) node, serial node, timer node, pmu (Performance Monitor Unit) node, rtc (Real Time Clock) node and virtio node. +Further we are provided with functions to create all the reuired types of nodes with thier neccessory configurations. THe supported types of nodes include chosen node, memory node, cpu node, gic (Generic Interrupt Controller) node, psci (Power State Coordination Interface) node, serial node, timer node, pmu (Performance Monitor Unit) node, rtc (Real Time Clock) node and virtio node.\ +For example to create a chosen node, which does not represent a device but serves in passing arguments between firmware and operating system, is createdd as follows. +```rs +fn create_chosen_node(fdt: &mut FdtWriter, cmdline: &str) -> Result<()> { + let chosen_node = fdt.begin_node("chosen")?; + fdt.property_string("bootargs", cmdline)?; + fdt.end_node(chosen_node)?; + + Ok(()) +} +``` ## Unit Testing ->Testing includes creating a new FdtBuilder object and then check creating fdt without specifying one of the configurations required. In the case when that left out configuration in neccessory we should get MissingRequiredConfig error. \ No newline at end of file +Testing includes creating a new FdtBuilder object and then check creating fdt without specifying one of the configurations required. In the case when that left out configuration in neccessory we should get MissingRequiredConfig error. \ No newline at end of file From 8a16628e5b919ce622c8eda12d20a3e9493d7f4b Mon Sep 17 00:00:00 2001 From: SwarajGawande Date: Sun, 11 Sep 2022 23:26:43 +0530 Subject: [PATCH 6/6] FDT description it5 --- docs/vmm-reference-fdt.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/vmm-reference-fdt.md b/docs/vmm-reference-fdt.md index e0d6586..4ffcf33 100644 --- a/docs/vmm-reference-fdt.md +++ b/docs/vmm-reference-fdt.md @@ -1,8 +1,8 @@ # [Flatenned Device Tree](../src/arch/src/lib.rs) ## Description -VMM keeps track of the virtio devices in a data structure called Flatenned Device Tree. FDT as the name suggests is a Tree where each node is a device or collection of devices. There can be different types of nodes in the FDT which can be identified using the attributes of the node. Each node contains a key-value pair mapping which determine the type of the node and configuration of that node. -This arrangement provides an abstracts out the hardware specifications from the code. +VMM keeps track of the virtio devices in a data structure called Flatenned Device Tree. FDT as the name suggests is a Tree where each node is a device or collection of devices. There can be different types of nodes in the FDT which can be identified using the attributes of the node. Each node contains a key-value pair mapping which determine the type of the node and configuration of that node.\ +This arrangement abstracts out the hardware specifications from the code and the makes the code shareable while making the hardware specifications more accesible and uniform. Arrangement of the hardware resources in the form of the tree also helps in easier reolution of resource ownership. ## Implementation The implementation of the FDT for arm64 architecture in `vmm-reference` is done using rust crate `vm_fdt` and `vm_memory` so are the following import statements. @@ -74,4 +74,5 @@ fn create_chosen_node(fdt: &mut FdtWriter, cmdline: &str) -> Result<()> { ``` ## Unit Testing -Testing includes creating a new FdtBuilder object and then check creating fdt without specifying one of the configurations required. In the case when that left out configuration in neccessory we should get MissingRequiredConfig error. \ No newline at end of file +Testing includes creating a new FdtBuilder object and then check creating fdt without specifying one of the configurations required. In the case when that left out configuration in neccessory we should get MissingRequiredConfig error. \ +The addition of new virtio device in a node is also tested. \ No newline at end of file