pvmfw: Add swiotlb <reg> to platform.dts

Instead of inserting the property into the template DT (which requires
shifting all following nodes), have a placeholder property that can be
overwritten in place.

Ensure that it is removed (NOP-ed) when not required.

Test: m pvmfw_img
Change-Id: Ife13eb84e23c43655513dfedffdedb1ea7fd2e78
diff --git a/libs/libfdt/Android.bp b/libs/libfdt/Android.bp
index 72399b0..5a729f1 100644
--- a/libs/libfdt/Android.bp
+++ b/libs/libfdt/Android.bp
@@ -37,6 +37,7 @@
     ],
     rustlibs: [
         "liblibfdt_bindgen",
+        "libzerocopy_nostd",
     ],
     whole_static_libs: [
         "libfdt",
diff --git a/libs/libfdt/src/lib.rs b/libs/libfdt/src/lib.rs
index 17cafd5..df1058e 100644
--- a/libs/libfdt/src/lib.rs
+++ b/libs/libfdt/src/lib.rs
@@ -26,6 +26,7 @@
 use core::fmt;
 use core::mem;
 use core::result;
+use zerocopy::AsBytes as _;
 
 /// Error type corresponding to libfdt error codes.
 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
@@ -441,6 +442,13 @@
         fdt_err_expect_zero(ret)
     }
 
+    /// Replace the value of the given (address, size) pair property with the given value, and
+    /// ensure that the given value has the same length as the current value length
+    pub fn setprop_addrrange_inplace(&mut self, name: &CStr, addr: u64, size: u64) -> Result<()> {
+        let pair = [addr.to_be(), size.to_be()];
+        self.setprop_inplace(name, pair.as_bytes())
+    }
+
     /// Create or change a flag-like empty property.
     pub fn setprop_empty(&mut self, name: &CStr) -> Result<()> {
         self.setprop(name, &[])
diff --git a/pvmfw/platform.dts b/pvmfw/platform.dts
index a7b1de7..74439d9 100644
--- a/pvmfw/platform.dts
+++ b/pvmfw/platform.dts
@@ -37,6 +37,7 @@
 		ranges;
 		swiotlb: restricted_dma_reserved {
 			compatible = "restricted-dma-pool";
+			reg = <PLACEHOLDER4>;
 			size = <PLACEHOLDER2>;
 			alignment = <PLACEHOLDER2>;
 		};
diff --git a/pvmfw/src/fdt.rs b/pvmfw/src/fdt.rs
index 97db601..63a59a1 100644
--- a/pvmfw/src/fdt.rs
+++ b/pvmfw/src/fdt.rs
@@ -499,7 +499,7 @@
         fdt.root_mut()?.next_compatible(cstr!("restricted-dma-pool"))?.ok_or(FdtError::NotFound)?;
 
     if let Some(range) = swiotlb_info.fixed_range() {
-        node.appendprop_addrrange(
+        node.setprop_addrrange_inplace(
             cstr!("reg"),
             range.start.try_into().unwrap(),
             range.len().try_into().unwrap(),
@@ -507,6 +507,7 @@
         node.nop_property(cstr!("size"))?;
         node.nop_property(cstr!("alignment"))?;
     } else {
+        node.nop_property(cstr!("reg"))?;
         node.setprop_inplace(cstr!("size"), &swiotlb_info.size.to_be_bytes())?;
         node.setprop_inplace(cstr!("alignment"), &swiotlb_info.align.unwrap().to_be_bytes())?;
     }