resource_table/
carveout.rs1use core::ptr::NonNull;
2
3use crate::types::{DevAddr, DevArea};
4use crate::{constants, types, util};
5
6#[repr(C)]
7#[derive(Clone, Debug)]
8pub struct Carveout {
9 pub da: DevAddr,
10 pub pa: u32,
11 pub len: u32,
12 pub flags: u32,
13 pub reserved: u32,
14 pub name: [u8; constants::RPROC_MAX_NAME_LEN],
15}
16
17impl types::ResourceType for Carveout {
18 const RESOURCE_TYPE: u32 = 0;
19}
20
21impl Carveout {
22 pub const fn new_dynamic(len: usize, flags: u32, name: &str) -> Self {
23 Self {
24 da: DevAddr::from_u32(constants::FW_RSC_ADDR_ANY),
25 pa: 0,
26 len: len as u32,
27 flags,
28 reserved: 0,
29 name: util::str_to_array(name).expect("name too long"),
30 }
31 }
32
33 pub const fn new_fixed(buf: DevArea, flags: u32, name: &str) -> Self {
34 Self {
35 da: buf.addr,
36 pa: 0,
37 len: buf.len as u32,
38 flags,
39 reserved: 0,
40 name: util::str_to_array(name).expect("name too long"),
41 }
42 }
43
44 pub fn get_ptr(&self) -> Option<NonNull<u8>> {
45 NonNull::new(self.da.as_ptr())
46 }
47
48 pub fn get_slice(&self) -> Option<NonNull<[u8]>> {
49 let ptr = self.get_ptr()?;
50 Some(NonNull::slice_from_raw_parts(ptr, self.len as usize))
51 }
52}