@@ -20,7 +20,7 @@ use crate::sel4::{
2020 Arch , ArmRiscvIrqTrigger , Config , PageSize , X86IoapicIrqPolarity , X86IoapicIrqTrigger ,
2121} ;
2222
23- use crate :: util:: { get_full_path, ranges_overlap, round_up, str_to_bool} ;
23+ use crate :: util:: { calculate_size_bits , get_full_path, ranges_overlap, round_up, str_to_bool} ;
2424use crate :: MAX_PDS ;
2525use sel4_capdl_initializer_types:: {
2626 object, x86_io_address_space, DomainSchedDuration , DomainSchedEntry , FillEntryContentBootInfoId ,
@@ -45,10 +45,6 @@ use std::str::FromStr;
4545const PD_MAX_ID : u64 = 61 ;
4646const VCPU_MAX_ID : u64 = PD_MAX_ID ;
4747
48- /// This is the maximum slot allowed for cap maps. This can change if you wish,
49- /// but also update the MICROKIT_MAX_USER_CAPS define in `microkit.h`.
50- const CAP_MAP_MAX_SLOT : u64 = 128 ;
51-
5248pub const MONITOR_PRIORITY : u8 = 255 ;
5349const PD_MAX_PRIORITY : u8 = 254 ;
5450/// In microseconds
@@ -613,7 +609,7 @@ pub struct ProtectionDomain {
613609 pub irqs : Vec < SysIrq > ,
614610 pub ioports : Vec < IOPort > ,
615611 pub setvars : Vec < SysSetVar > ,
616- pub cap_maps : Vec < CapMap > ,
612+ pub cspace : Option < CSpace > ,
617613 pub virtual_machine : Option < VirtualMachine > ,
618614 /// Only used when parsing child PDs. All elements will be removed
619615 /// once we flatten each PD and its children into one list.
@@ -655,9 +651,10 @@ pub struct CapMap {
655651 text_pos : roxmltree:: TextPos ,
656652}
657653
658- #[ derive( Debug ) ]
654+ #[ derive( Debug , PartialEq , Eq ) ]
659655pub struct CSpace {
660- cap_maps : Vec < CapMap > ,
656+ pub cap_maps : Vec < CapMap > ,
657+ pub size_bits : u64 ,
661658}
662659
663660#[ derive( Debug , PartialEq , Eq ) ]
@@ -1604,7 +1601,7 @@ impl ProtectionDomain {
16041601 irqs,
16051602 ioports,
16061603 setvars,
1607- cap_maps : cspace. map ( |cspace| cspace . cap_maps ) . unwrap_or_default ( ) ,
1604+ cspace,
16081605 child_pds,
16091606 virtual_machine,
16101607 has_children,
@@ -1781,15 +1778,6 @@ impl CapMap {
17811778 ) ) ;
17821779 }
17831780
1784- // TODO: Rework this so that we don't have a fixed upper limit.
1785- if slot >= CAP_MAP_MAX_SLOT {
1786- return Err ( value_error (
1787- xml_sdf,
1788- node,
1789- format ! ( "There are only {CAP_MAP_MAX_SLOT} destination cspace slots available." ) ,
1790- ) ) ;
1791- }
1792-
17931781 Ok ( CapMap {
17941782 cap_type,
17951783 pd_name,
@@ -1823,7 +1811,17 @@ impl CSpace {
18231811 } )
18241812 }
18251813
1826- Ok ( CSpace { cap_maps } )
1814+ // Default to 1, the minimum allowed by the kernel.
1815+ let size_bits = cap_maps
1816+ . iter ( )
1817+ . map ( |cap_map| calculate_size_bits ( cap_map. slot + 1 ) )
1818+ . max ( )
1819+ . unwrap_or ( 1 ) as u64 ;
1820+
1821+ Ok ( CSpace {
1822+ cap_maps,
1823+ size_bits,
1824+ } )
18271825 }
18281826}
18291827
@@ -2873,8 +2871,8 @@ pub fn parse(
28732871 . enumerate ( )
28742872 . map ( |( idx, pd) | ( pd. name . clone ( ) , idx) )
28752873 . collect ( ) ;
2876- for pd in pds. iter_mut ( ) {
2877- for cap_map in pd . cap_maps . iter_mut ( ) {
2874+ for cspace in pds. iter_mut ( ) . filter_map ( |pd| pd . cspace . as_mut ( ) ) {
2875+ for cap_map in cspace . cap_maps . iter_mut ( ) {
28782876 let Some ( & pd) = pd_names_to_id. get ( & cap_map. pd_name ) else {
28792877 return Err ( format ! (
28802878 "Error: unknown PD name '{}': {}" ,
@@ -3128,9 +3126,10 @@ pub fn parse(
31283126 // Ensure that there are no overlapping extra cap maps in the user caps region
31293127 // and we are not mapping in the same cap from the same source more than once
31303128 for pd in & pds {
3129+ let Some ( cspace) = & pd. cspace else { continue } ;
31313130 let mut user_cap_slots = HashMap :: < u64 , Vec < _ > > :: new ( ) ;
31323131
3133- for cap_map in & pd . cap_maps {
3132+ for cap_map in & cspace . cap_maps {
31343133 user_cap_slots
31353134 . entry ( cap_map. slot )
31363135 . and_modify ( |v| v. push ( cap_map) )
0 commit comments