From 34809a47e14e40bdd0b50a28c852f69d415bcd8f Mon Sep 17 00:00:00 2001 From: Sam Leffler Date: Thu, 13 Oct 2022 22:33:57 +0000 Subject: [PATCH] kata-memory-interface: improve portability Change-Id: I8b436a32aabbc5e0e57d14680cc7d09f46b7bc30 GitOrigin-RevId: 79e28f7b6f5ac4bb96a2e09f152ac92bb91dc5f7 --- .../kata-memory-interface/src/lib.rs | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/apps/system/components/MemoryManager/kata-memory-interface/src/lib.rs b/apps/system/components/MemoryManager/kata-memory-interface/src/lib.rs index 7025ba8..4c68c0a 100644 --- a/apps/system/components/MemoryManager/kata-memory-interface/src/lib.rs +++ b/apps/system/components/MemoryManager/kata-memory-interface/src/lib.rs @@ -33,7 +33,9 @@ use sel4_sys::seL4_Error; use sel4_sys::seL4_ObjectType; use sel4_sys::seL4_ObjectType::*; use sel4_sys::seL4_PageBits; +use sel4_sys::seL4_PageTableObject; use sel4_sys::seL4_Result; +use sel4_sys::seL4_SmallPageObject; use sel4_sys::seL4_WordBits; use slot_allocator::KATA_CSPACE_SLOTS; @@ -560,17 +562,17 @@ pub fn kata_reply_alloc() -> Result { Ok(objs) } -// Wrapper for allocating 4K pages. +// Wrapper for allocating small pages. #[inline] pub fn kata_frame_alloc(space_bytes: usize) -> Result { 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( unsafe { MEMORY_RECV_CNODE }, unsafe { MEMORY_RECV_CNODE_DEPTH }, // NB: always allocate 4K pages vec![ObjDesc::new( - seL4_RISCV_4K_Page, + seL4_SmallPageObject, howmany(space_bytes, 1 << seL4_PageBits), /*cptr=*/ 0, )], @@ -585,7 +587,7 @@ pub fn kata_frame_alloc(space_bytes: usize) -> Result Result { 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); // XXX horrible band-aid to workaround Retype "fanout" limit of 256 // 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 256 { kata_object_alloc_in_cnode(vec![ - ObjDesc::new(seL4_RISCV_4K_Page, 256, /*cptr=*/ 0), - ObjDesc::new(seL4_RISCV_4K_Page, npages - 256, /*cptr=*/ 256), + ObjDesc::new(seL4_SmallPageObject, 256, /*cptr=*/ 0), + ObjDesc::new(seL4_SmallPageObject, npages - 256, /*cptr=*/ 256), ]) } 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 { let mut objs = ObjDescBundle::new( unsafe { MEMORY_RECV_CNODE }, unsafe { MEMORY_RECV_CNODE_DEPTH }, - vec![ObjDesc::new( - seL4_RISCV_PageTableObject, - 1, - /*cptr=*/ 0, - )], + vec![ObjDesc::new(seL4_PageTableObject, 1, /*cptr=*/ 0)], ); kata_object_alloc(&objs)?; objs.move_objects_to_toplevel()