Skip to content

Commit 9a0f08f

Browse files
committed
rust: of: Add reserved_mem_region_to_resource_byname()
Creates Resource from a reserved memory region. Depends on commit f4fcfdd ("of: reserved_mem: Add functions to parse "memory-region"") from v6.16-rc1. Signed-off-by: Janne Grunau <j@jannau.net>
1 parent 8afbb3b commit 9a0f08f

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

rust/bindings/bindings_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include <linux/of.h>
6262
#include <linux/of_address.h>
6363
#include <linux/of_device.h>
64+
#include <linux/of_reserved_mem.h>
6465
#include <linux/pci.h>
6566
#include <linux/phy.h>
6667
#include <linux/pid_namespace.h>

rust/kernel/of.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ use crate::{
1616
use core::marker::PhantomData;
1717
use core::num::NonZeroU32;
1818

19+
use crate::error::to_result;
20+
use crate::io::resource::Resource;
21+
1922
/// IdTable type for OF drivers.
2023
pub type IdTable<T> = &'static dyn kernel::device_id::IdTable<DeviceId, T>;
2124

@@ -217,6 +220,30 @@ impl Node {
217220
}
218221
}
219222

223+
#[allow(unused_variables)]
224+
/// Get a reserved memory region as a resource
225+
pub fn reserved_mem_region_to_resource_byname(&self, name: &CStr) -> Result<Resource> {
226+
#[cfg(not(CONFIG_OF))]
227+
{
228+
Err(ENOENT)
229+
}
230+
#[cfg(CONFIG_OF)]
231+
{
232+
let res = Resource::zeroed();
233+
// SAFETY: This function is safe to call as long as the arguments are valid pointers.
234+
let ret = unsafe {
235+
bindings::of_reserved_mem_region_to_resource_byname(
236+
self.raw_node,
237+
name.as_char_ptr(),
238+
res.as_raw(),
239+
)
240+
};
241+
to_result(ret)?;
242+
243+
Ok(res)
244+
}
245+
}
246+
220247
#[allow(unused_variables)]
221248
/// Look up a node property by name, returning a `Property` object if found.
222249
pub fn find_property(&self, propname: &CStr) -> Option<Property<'_>> {

0 commit comments

Comments
 (0)