Skip to content

Commit d0ff46d

Browse files
committed
domains: refactor resolving names to ids
Signed-off-by: Krishnan Winter <krishnan.winter@unsw.edu.au>
1 parent af504e8 commit d0ff46d

3 files changed

Lines changed: 83 additions & 41 deletions

File tree

tool/microkit/src/sdf.rs

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ pub struct ProtectionDomain {
275275
/// Location in the parsed SDF file
276276
text_pos: Option<roxmltree::TextPos>,
277277
/// Index into the domain schedule vector if the system is using domain scheduling
278-
/// Defaults to domain 0 if not set.
278+
pub domain_name: Option<String>,
279279
pub domain_id: Option<u8>,
280280
}
281281

@@ -603,28 +603,12 @@ impl ProtectionDomain {
603603
));
604604
}
605605

606-
let mut domain_id: Option<u8> = None;
607-
match (domain_schedule, checked_lookup(xml_sdf, node, "domain")) {
608-
(Some(domain_schedule), Ok(domain_name)) => {
609-
let domain_id_get = domain_schedule.domain_ids.get(domain_name);
610-
if domain_id_get.is_none() {
611-
return Err(format!("Protection domain {name} specifies a domain {domain_name} that is not in the domain schedule"));
612-
}
613-
domain_id = Some(*domain_id_get.unwrap());
614-
}
615-
(Some(_), _) => {
616-
return Err(format!("System specifies a domain schedule but protection domain {name} does not specify a domain"))
617-
}
618-
(_, Ok(domain)) => {
619-
if config.num_domain_schedules > 1 {
620-
return Err(format!("Protection domain {name} specifies a domain {domain} but system does not specify a domain schedule"));
621-
} else {
622-
return Err("Assigning PDs to domains is only supported when built with a config that supports domains".to_string());
623-
}
624-
}
625-
(_, _) => {}
626-
}
627-
606+
let domain_name = if let Some(xml_domain_name) = node.attribute("domain") {
607+
Some(xml_domain_name.to_string())
608+
} else {
609+
None
610+
};
611+
let domain_id: Option<u8> = None;
628612
let mut maps = Vec::new();
629613
let mut irqs = Vec::new();
630614
let mut ioports = Vec::new();
@@ -1116,6 +1100,7 @@ impl ProtectionDomain {
11161100
parent: None,
11171101
setvar_id,
11181102
text_pos: Some(xml_sdf.doc.text_pos_at(node.range().start)),
1103+
domain_name,
11191104
domain_id,
11201105
})
11211106
}
@@ -1127,10 +1112,6 @@ impl DomainSchedule {
11271112
config: &Config,
11281113
node: &roxmltree::Node,
11291114
) -> Result<DomainSchedule, String> {
1130-
if config.num_domains <= 1 {
1131-
return Err("Error: Attempting to set a domain schedule when kernel config does not support more than 1 domain".to_string());
1132-
}
1133-
11341115
let pos = xml_sdf.doc.text_pos_at(node.range().start);
11351116

11361117
check_attributes(xml_sdf, node, &["index_shift", "start_index"])?;
@@ -1805,18 +1786,19 @@ pub fn parse(filename: &str, xml: &str, config: &Config) -> Result<SystemDescrip
18051786
));
18061787
}
18071788
"domain_schedule" => {
1808-
if config.num_domain_schedules > 1 {
1809-
if let Some(domain_schedule_node) = system
1810-
.children()
1811-
.filter(|&child| child.is_element())
1812-
.find(|&child| child.tag_name().name() == "domain_schedule")
1813-
{
1814-
domain_schedule = Some(DomainSchedule::from_xml(
1815-
&xml_sdf,
1816-
config,
1817-
&domain_schedule_node,
1818-
)?);
1819-
}
1789+
if config.num_domains <= 1 {
1790+
return Err("Error: Attempting to set a domain schedule when kernel config does not support more than 1 domain".to_string());
1791+
}
1792+
if let Some(domain_schedule_node) = system
1793+
.children()
1794+
.filter(|&child| child.is_element())
1795+
.find(|&child| child.tag_name().name() == "domain_schedule")
1796+
{
1797+
domain_schedule = Some(DomainSchedule::from_xml(
1798+
&xml_sdf,
1799+
config,
1800+
&domain_schedule_node,
1801+
)?);
18201802
}
18211803
}
18221804
_ => {
@@ -2197,6 +2179,42 @@ pub fn parse(filename: &str, xml: &str, config: &Config) -> Result<SystemDescrip
21972179
schedule_len, dom_shift, config.num_domain_schedules,
21982180
));
21992181
}
2182+
2183+
// Resolve the domain names to id's
2184+
for pd in pds.iter_mut() {
2185+
if let Some(domain_name) = &pd.domain_name {
2186+
let domain_id_get = dom_sched.domain_ids.get(domain_name);
2187+
if domain_id_get.is_none() {
2188+
return Err(format!("Protection domain {} specifies a domain {} that is not in the domain schedule",
2189+
pd.name,
2190+
domain_name
2191+
));
2192+
}
2193+
pd.domain_id = Some(*domain_id_get.unwrap());
2194+
} else {
2195+
return Err(format!("Protection domain {} doesn't specify a domain, but user has declared a domain schedule",
2196+
pd.name,
2197+
));
2198+
}
2199+
}
2200+
} else {
2201+
// If no domain schedule is defined, check that no PD has specified a domain.
2202+
for pd in pds.iter() {
2203+
if let Some(domain_name) = &pd.domain_name {
2204+
if config.num_domains > 1 {
2205+
return Err(format!("Protection domain {} specifies a domain '{}', but user has not declared a domain schedule",
2206+
pd.name,
2207+
domain_name
2208+
));
2209+
} else {
2210+
return Err(format!("Protection domain {} specifies a domain '{}', but Microkit config does not support domains.",
2211+
pd.name,
2212+
domain_name
2213+
));
2214+
}
2215+
2216+
}
2217+
}
22002218
}
22012219

22022220
Ok(SystemDescription {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2026, UNSW.
4+
5+
SPDX-License-Identifier: BSD-2-Clause
6+
-->
7+
<system>
8+
<domain_schedule>
9+
<domain name="domain_1" length="1000000" />
10+
</domain_schedule>
11+
12+
<protection_domain name="test1" >
13+
<program_image path="test" />
14+
</protection_domain>
15+
</system>

tool/microkit/tests/test.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ mod domains {
787787
check_error(
788788
&DEFAULT_AARCH64_SMP_KERNEL_CONFIG,
789789
"domain_smp.system",
790-
"Assigning PDs to domains is only supported when built with a config that supports domains",
790+
"Error: Attempting to set a domain schedule when kernel config does not support more than 1 domain",
791791
)
792792
}
793793

@@ -823,7 +823,16 @@ mod domains {
823823
check_error(
824824
&DEFAULT_AARCH64_KERNEL_CONFIG,
825825
"domain_no_schedule.system",
826-
"Protection domain test1 specifies a domain domain_1 but system does not specify a domain schedule",
826+
"Protection domain test1 specifies a domain 'domain_1', but user has not declared a domain schedule",
827+
)
828+
}
829+
830+
#[test]
831+
fn test_domain_pd_no_domain() {
832+
check_error(
833+
&DEFAULT_AARCH64_KERNEL_CONFIG,
834+
"domain_no_pd_domain.system",
835+
"Protection domain test1 doesn't specify a domain, but user has declared a domain schedule",
827836
)
828837
}
829838

0 commit comments

Comments
 (0)