-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Djordje Lukic <[email protected]> Signed-off-by: David Gageot <[email protected]> Signed-off-by: Piotr Stankiewicz <[email protected]>
- Loading branch information
Showing
37 changed files
with
1,294 additions
and
689 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
use std::{boxed::Box, result}; | ||
|
||
use super::gic::{Error, GICDevice}; | ||
|
||
type Result<T> = result::Result<T, Error>; | ||
|
||
/// This is just a placeholder for building the FDT entry. | ||
/// The actual emulated GICv3 is in devices/legacy. | ||
pub struct GICv3 { | ||
/// GIC device properties, to be used for setting up the fdt entry | ||
properties: [u64; 4], | ||
|
||
/// Number of CPUs handled by the device | ||
vcpu_count: u64, | ||
} | ||
|
||
impl GICv3 { | ||
const SZ_64K: u64 = 0x0001_0000; | ||
|
||
// Device trees specific constants | ||
const GIC_V3_MAINT_IRQ: u32 = 8; | ||
|
||
/// Get the address of the GICv3 distributor. | ||
pub fn get_dist_addr() -> u64 { | ||
super::super::layout::MAPPED_IO_START - 3 * GICv3::SZ_64K | ||
} | ||
|
||
/// Get the size of the GIC_v3 distributor. | ||
pub const fn get_dist_size() -> u64 { | ||
GICv3::SZ_64K | ||
} | ||
|
||
/// Get the address of the GIC redistributors. | ||
pub const fn compute_redists_addr(vcpu_count: u64) -> u64 { | ||
super::super::layout::MAPPED_IO_START | ||
- 3 * GICv3::SZ_64K | ||
- GICv3::compute_redists_size(vcpu_count) | ||
} | ||
|
||
pub fn get_redists_addr(&self) -> u64 { | ||
Self::compute_redists_addr(self.vcpu_count) | ||
} | ||
|
||
/// Get the size of the GIC redistributors. | ||
pub const fn compute_redists_size(vcpu_count: u64) -> u64 { | ||
vcpu_count * GICv3::get_redist_size() | ||
} | ||
|
||
pub fn get_redists_size(&self) -> u64 { | ||
GICv3::compute_redists_size(self.vcpu_count) | ||
} | ||
|
||
pub const fn get_redist_size() -> u64 { | ||
2 * GICv3::SZ_64K | ||
} | ||
} | ||
|
||
impl GICDevice for GICv3 { | ||
fn device_properties(&self) -> &[u64] { | ||
&self.properties | ||
} | ||
|
||
fn vcpu_count(&self) -> u64 { | ||
self.vcpu_count | ||
} | ||
|
||
fn fdt_compatibility(&self) -> &str { | ||
"arm,gic-v3" | ||
} | ||
|
||
fn fdt_maint_irq(&self) -> u32 { | ||
GICv3::GIC_V3_MAINT_IRQ | ||
} | ||
|
||
fn version() -> u32 { | ||
0 | ||
} | ||
|
||
fn create_device(vcpu_count: u64) -> Box<dyn GICDevice> { | ||
Box::new(GICv3 { | ||
properties: [ | ||
GICv3::get_dist_addr(), | ||
GICv3::get_dist_size(), | ||
GICv3::compute_redists_addr(vcpu_count), | ||
GICv3::compute_redists_size(vcpu_count), | ||
], | ||
vcpu_count, | ||
}) | ||
} | ||
|
||
fn init_device_attributes(_gic_device: &Box<dyn GICDevice>) -> Result<()> { | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#[allow(clippy::new_ret_no_self)] | ||
pub mod gic; | ||
pub mod gicv2; | ||
pub mod gicv3; | ||
pub mod regs; | ||
pub mod sysreg; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
pub const SYSREG_OP0_SHIFT: u32 = 20; | ||
pub const SYSREG_OP0_MASK: u32 = 0x3; | ||
pub const SYSREG_OP1_SHIFT: u32 = 14; | ||
pub const SYSREG_OP1_MASK: u32 = 0x7; | ||
pub const SYSREG_CRN_SHIFT: u32 = 10; | ||
pub const SYSREG_CRN_MASK: u32 = 0xf; | ||
pub const SYSREG_CRM_SHIFT: u32 = 1; | ||
pub const SYSREG_CRM_MASK: u32 = 0xf; | ||
pub const SYSREG_OP2_SHIFT: u32 = 17; | ||
pub const SYSREG_OP2_MASK: u32 = 0x7; | ||
|
||
#[macro_export] | ||
macro_rules! arm64_sys_reg { | ||
($name: tt, $op0: tt, $op1: tt, $op2: tt, $crn: tt, $crm: tt) => { | ||
pub const $name: u32 = ($op0 as u32) << SYSREG_OP0_SHIFT | ||
| ($op2 as u32) << SYSREG_OP2_SHIFT | ||
| ($op1 as u32) << SYSREG_OP1_SHIFT | ||
| ($crn as u32) << SYSREG_CRN_SHIFT | ||
| ($crm as u32) << SYSREG_CRM_SHIFT; | ||
}; | ||
} | ||
|
||
arm64_sys_reg!( | ||
SYSREG_MASK, | ||
SYSREG_OP0_MASK, | ||
SYSREG_OP1_MASK, | ||
SYSREG_OP2_MASK, | ||
SYSREG_CRN_MASK, | ||
SYSREG_CRM_MASK | ||
); | ||
|
||
arm64_sys_reg!(SYSREG_OSLAR_EL1, 2, 0, 4, 1, 0); | ||
arm64_sys_reg!(SYSREG_OSDLR_EL1, 2, 0, 4, 1, 3); | ||
|
||
arm64_sys_reg!(SYSREG_ICC_AP0R0_EL1, 3, 0, 4, 12, 8); | ||
arm64_sys_reg!(SYSREG_ICC_AP0R1_EL1, 3, 0, 5, 12, 8); | ||
arm64_sys_reg!(SYSREG_ICC_AP0R2_EL1, 3, 0, 6, 12, 8); | ||
arm64_sys_reg!(SYSREG_ICC_AP0R3_EL1, 3, 0, 7, 12, 8); | ||
arm64_sys_reg!(SYSREG_ICC_AP1R0_EL1, 3, 0, 0, 12, 9); | ||
arm64_sys_reg!(SYSREG_ICC_AP1R1_EL1, 3, 0, 1, 12, 9); | ||
arm64_sys_reg!(SYSREG_ICC_AP1R2_EL1, 3, 0, 2, 12, 9); | ||
arm64_sys_reg!(SYSREG_ICC_AP1R3_EL1, 3, 0, 3, 12, 9); | ||
arm64_sys_reg!(SYSREG_ICC_ASGI1R_EL1, 3, 0, 6, 12, 11); | ||
arm64_sys_reg!(SYSREG_ICC_BPR0_EL1, 3, 0, 3, 12, 8); | ||
arm64_sys_reg!(SYSREG_ICC_BPR1_EL1, 3, 0, 3, 12, 12); | ||
arm64_sys_reg!(SYSREG_ICC_CTLR_EL1, 3, 0, 4, 12, 12); | ||
arm64_sys_reg!(SYSREG_ICC_DIR_EL1, 3, 0, 1, 12, 11); | ||
arm64_sys_reg!(SYSREG_ICC_EOIR0_EL1, 3, 0, 1, 12, 8); | ||
arm64_sys_reg!(SYSREG_ICC_EOIR1_EL1, 3, 0, 1, 12, 12); | ||
arm64_sys_reg!(SYSREG_ICC_HPPIR0_EL1, 3, 0, 2, 12, 8); | ||
arm64_sys_reg!(SYSREG_ICC_HPPIR1_EL1, 3, 0, 2, 12, 12); | ||
arm64_sys_reg!(SYSREG_ICC_IAR0_EL1, 3, 0, 0, 12, 8); | ||
arm64_sys_reg!(SYSREG_ICC_IAR1_EL1, 3, 0, 0, 12, 12); | ||
arm64_sys_reg!(SYSREG_ICC_IGRPEN0_EL1, 3, 0, 6, 12, 12); | ||
arm64_sys_reg!(SYSREG_ICC_IGRPEN1_EL1, 3, 0, 7, 12, 12); | ||
arm64_sys_reg!(SYSREG_ICC_PMR_EL1, 3, 0, 0, 4, 6); | ||
arm64_sys_reg!(SYSREG_ICC_SGI1R_EL1, 3, 0, 5, 12, 11); | ||
arm64_sys_reg!(SYSREG_ICC_SRE_EL1, 3, 0, 5, 12, 12); | ||
|
||
// ICC_CTLR_EL1 (https://developer.arm.com/documentation/ddi0595/2021-06/AArch64-Registers/ICC-CTLR-EL1--Interrupt-Controller-Control-Register--EL1-) | ||
pub const ICC_CTLR_EL1_RSS_SHIFT: u32 = 18; | ||
pub const ICC_CTLR_EL1_A3V_SHIFT: u32 = 15; | ||
pub const ICC_CTLR_EL1_ID_BITS_SHIFT: u32 = 11; | ||
pub const ICC_CTLR_EL1_PRI_BITS_SHIFT: u32 = 8; | ||
|
||
pub fn icc_reg_name(addr: u32) -> Option<&'static str> { | ||
match addr { | ||
SYSREG_ICC_IAR0_EL1 => Some("SYSREG_ICC_IAR0_EL1"), | ||
SYSREG_ICC_IAR1_EL1 => Some("SYSREG_ICC_IAR1_EL1"), | ||
SYSREG_ICC_EOIR0_EL1 => Some("SYSREG_ICC_EOIR0_EL1"), | ||
SYSREG_ICC_EOIR1_EL1 => Some("SYSREG_ICC_EOIR1_EL1"), | ||
SYSREG_ICC_AP0R0_EL1 => Some("SYSREG_ICC_AP0R0_EL1"), | ||
SYSREG_ICC_AP0R1_EL1 => Some("SYSREG_ICC_AP0R1_EL1"), | ||
SYSREG_ICC_AP0R2_EL1 => Some("SYSREG_ICC_AP0R2_EL1"), | ||
SYSREG_ICC_AP0R3_EL1 => Some("SYSREG_ICC_AP0R3_EL1"), | ||
SYSREG_ICC_AP1R0_EL1 => Some("SYSREG_ICC_AP1R0_EL1"), | ||
SYSREG_ICC_AP1R1_EL1 => Some("SYSREG_ICC_AP1R1_EL1"), | ||
SYSREG_ICC_AP1R2_EL1 => Some("SYSREG_ICC_AP1R2_EL1"), | ||
SYSREG_ICC_AP1R3_EL1 => Some("SYSREG_ICC_AP1R3_EL1"), | ||
SYSREG_ICC_ASGI1R_EL1 => Some("SYSREG_ICC_ASGI1R_EL1"), | ||
SYSREG_ICC_BPR0_EL1 => Some("SYSREG_ICC_BPR0_EL1"), | ||
SYSREG_ICC_BPR1_EL1 => Some("SYSREG_ICC_BPR1_EL1"), | ||
SYSREG_ICC_CTLR_EL1 => Some("SYSREG_ICC_CTLR_EL1"), | ||
SYSREG_ICC_DIR_EL1 => Some("SYSREG_ICC_DIR_EL1"), | ||
SYSREG_ICC_HPPIR0_EL1 => Some("SYSREG_ICC_HPPIR0_EL1"), | ||
SYSREG_ICC_HPPIR1_EL1 => Some("SYSREG_ICC_HPPIR1_EL1"), | ||
SYSREG_ICC_IGRPEN0_EL1 => Some("SYSREG_ICC_IGRPEN0_EL1"), | ||
SYSREG_ICC_IGRPEN1_EL1 => Some("SYSREG_ICC_IGRPEN1_EL1"), | ||
SYSREG_ICC_PMR_EL1 => Some("SYSREG_ICC_PMR_EL1"), | ||
SYSREG_ICC_SGI1R_EL1 => Some("SYSREG_ICC_SGI1R_EL1"), | ||
SYSREG_ICC_SRE_EL1 => Some("SYSREG_ICC_SRE_EL1"), | ||
_ => None, | ||
} | ||
} | ||
|
||
pub fn sysreg_op0(sysreg: u32) -> u32 { | ||
(sysreg >> SYSREG_OP0_SHIFT) & SYSREG_OP0_MASK | ||
} | ||
|
||
pub fn sysreg_op1(sysreg: u32) -> u32 { | ||
(sysreg >> SYSREG_OP1_SHIFT) & SYSREG_OP1_MASK | ||
} | ||
|
||
pub fn sysreg_op2(sysreg: u32) -> u32 { | ||
(sysreg >> SYSREG_OP2_SHIFT) & SYSREG_OP2_MASK | ||
} | ||
|
||
pub fn sysreg_crn(sysreg: u32) -> u32 { | ||
(sysreg >> SYSREG_CRN_SHIFT) & SYSREG_CRN_MASK | ||
} | ||
|
||
pub fn sysreg_crm(sysreg: u32) -> u32 { | ||
(sysreg >> SYSREG_CRM_SHIFT) & SYSREG_CRM_MASK | ||
} | ||
|
||
pub fn is_id_sysreg(reg: u32) -> bool { | ||
sysreg_op0(reg) == 3 | ||
&& sysreg_op1(reg) == 0 | ||
&& sysreg_crn(reg) == 0 | ||
&& sysreg_crm(reg) >= 1 | ||
&& sysreg_crm(reg) < 8 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.