mirror of
https://github.com/AmbiML/sparrow-kata-full.git
synced 2025-04-28 10:43:49 +00:00
kata-memory-interface: improve portability
Change-Id: I8b436a32aabbc5e0e57d14680cc7d09f46b7bc30 GitOrigin-RevId: 79e28f7b6f5ac4bb96a2e09f152ac92bb91dc5f7
This commit is contained in:
parent
130887a482
commit
34809a47e1
@ -33,7 +33,9 @@ use sel4_sys::seL4_Error;
|
|||||||
use sel4_sys::seL4_ObjectType;
|
use sel4_sys::seL4_ObjectType;
|
||||||
use sel4_sys::seL4_ObjectType::*;
|
use sel4_sys::seL4_ObjectType::*;
|
||||||
use sel4_sys::seL4_PageBits;
|
use sel4_sys::seL4_PageBits;
|
||||||
|
use sel4_sys::seL4_PageTableObject;
|
||||||
use sel4_sys::seL4_Result;
|
use sel4_sys::seL4_Result;
|
||||||
|
use sel4_sys::seL4_SmallPageObject;
|
||||||
use sel4_sys::seL4_WordBits;
|
use sel4_sys::seL4_WordBits;
|
||||||
|
|
||||||
use slot_allocator::KATA_CSPACE_SLOTS;
|
use slot_allocator::KATA_CSPACE_SLOTS;
|
||||||
@ -560,17 +562,17 @@ pub fn kata_reply_alloc() -> Result<ObjDescBundle, MemoryManagerError> {
|
|||||||
Ok(objs)
|
Ok(objs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrapper for allocating 4K pages.
|
// Wrapper for allocating small pages.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn kata_frame_alloc(space_bytes: usize) -> Result<ObjDescBundle, MemoryManagerError> {
|
pub fn kata_frame_alloc(space_bytes: usize) -> Result<ObjDescBundle, MemoryManagerError> {
|
||||||
fn howmany(value: usize, unit: usize) -> usize { (value + (unit - 1)) / unit }
|
fn howmany(value: usize, unit: usize) -> usize { (value + (unit - 1)) / unit }
|
||||||
// NB: always allocate 4K pages
|
// NB: always allocate small pages
|
||||||
let mut objs = ObjDescBundle::new(
|
let mut objs = ObjDescBundle::new(
|
||||||
unsafe { MEMORY_RECV_CNODE },
|
unsafe { MEMORY_RECV_CNODE },
|
||||||
unsafe { MEMORY_RECV_CNODE_DEPTH },
|
unsafe { MEMORY_RECV_CNODE_DEPTH },
|
||||||
// NB: always allocate 4K pages
|
// NB: always allocate 4K pages
|
||||||
vec![ObjDesc::new(
|
vec![ObjDesc::new(
|
||||||
seL4_RISCV_4K_Page,
|
seL4_SmallPageObject,
|
||||||
howmany(space_bytes, 1 << seL4_PageBits),
|
howmany(space_bytes, 1 << seL4_PageBits),
|
||||||
/*cptr=*/ 0,
|
/*cptr=*/ 0,
|
||||||
)],
|
)],
|
||||||
@ -585,7 +587,7 @@ pub fn kata_frame_alloc(space_bytes: usize) -> Result<ObjDescBundle, MemoryManag
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn kata_frame_alloc_in_cnode(space_bytes: usize) -> Result<ObjDescBundle, MemoryManagerError> {
|
pub fn kata_frame_alloc_in_cnode(space_bytes: usize) -> Result<ObjDescBundle, MemoryManagerError> {
|
||||||
fn howmany(value: usize, unit: usize) -> usize { (value + (unit - 1)) / unit }
|
fn howmany(value: usize, unit: usize) -> usize { (value + (unit - 1)) / unit }
|
||||||
// NB: always allocate 4K pages
|
// NB: always allocate small pages
|
||||||
let npages = howmany(space_bytes, 1 << seL4_PageBits);
|
let npages = howmany(space_bytes, 1 << seL4_PageBits);
|
||||||
// XXX horrible band-aid to workaround Retype "fanout" limit of 256
|
// XXX horrible band-aid to workaround Retype "fanout" limit of 256
|
||||||
// objects: split our request accordingly. This shold be handled in
|
// objects: split our request accordingly. This shold be handled in
|
||||||
@ -593,11 +595,15 @@ pub fn kata_frame_alloc_in_cnode(space_bytes: usize) -> Result<ObjDescBundle, Me
|
|||||||
assert!(npages <= 512); // XXX 2MB
|
assert!(npages <= 512); // XXX 2MB
|
||||||
if npages > 256 {
|
if npages > 256 {
|
||||||
kata_object_alloc_in_cnode(vec![
|
kata_object_alloc_in_cnode(vec![
|
||||||
ObjDesc::new(seL4_RISCV_4K_Page, 256, /*cptr=*/ 0),
|
ObjDesc::new(seL4_SmallPageObject, 256, /*cptr=*/ 0),
|
||||||
ObjDesc::new(seL4_RISCV_4K_Page, npages - 256, /*cptr=*/ 256),
|
ObjDesc::new(seL4_SmallPageObject, npages - 256, /*cptr=*/ 256),
|
||||||
])
|
])
|
||||||
} else {
|
} else {
|
||||||
kata_object_alloc_in_cnode(vec![ObjDesc::new(seL4_RISCV_4K_Page, npages, /*cptr=*/ 0)])
|
kata_object_alloc_in_cnode(vec![ObjDesc::new(
|
||||||
|
seL4_SmallPageObject,
|
||||||
|
npages,
|
||||||
|
/*cptr=*/ 0,
|
||||||
|
)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -606,11 +612,7 @@ pub fn kata_page_table_alloc() -> Result<ObjDescBundle, MemoryManagerError> {
|
|||||||
let mut objs = ObjDescBundle::new(
|
let mut objs = ObjDescBundle::new(
|
||||||
unsafe { MEMORY_RECV_CNODE },
|
unsafe { MEMORY_RECV_CNODE },
|
||||||
unsafe { MEMORY_RECV_CNODE_DEPTH },
|
unsafe { MEMORY_RECV_CNODE_DEPTH },
|
||||||
vec![ObjDesc::new(
|
vec![ObjDesc::new(seL4_PageTableObject, 1, /*cptr=*/ 0)],
|
||||||
seL4_RISCV_PageTableObject,
|
|
||||||
1,
|
|
||||||
/*cptr=*/ 0,
|
|
||||||
)],
|
|
||||||
);
|
);
|
||||||
kata_object_alloc(&objs)?;
|
kata_object_alloc(&objs)?;
|
||||||
objs.move_objects_to_toplevel()
|
objs.move_objects_to_toplevel()
|
||||||
|
Loading…
Reference in New Issue
Block a user