diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/arch/arm64/armv8/lib/pstate.c | 32 | ||||
-rw-r--r-- | src/arch/arm64/armv8/lib/sysctrl.c | 194 | ||||
-rw-r--r-- | src/arch/arm64/armv8/lib/tlb.c | 16 | ||||
-rw-r--r-- | src/arch/arm64/include/armv8/arch/lib_helpers.h | 97 |
4 files changed, 274 insertions, 65 deletions
diff --git a/src/arch/arm64/armv8/lib/pstate.c b/src/arch/arm64/armv8/lib/pstate.c index a194b91e26..d2f3649ee9 100644 --- a/src/arch/arm64/armv8/lib/pstate.c +++ b/src/arch/arm64/armv8/lib/pstate.c @@ -171,12 +171,24 @@ void raw_write_elr_el3(uint64_t elr_el3) uint64_t raw_read_elr_current(void) { - SWITCH_CASE_READ(raw_read_elr,elr,uint64_t); + uint32_t el = get_current_el(); + return raw_read_elr(el); } void raw_write_elr_current(uint64_t elr) { - SWITCH_CASE_WRITE(raw_write_elr,elr); + uint32_t el = get_current_el(); + raw_write_elr(elr, el); +} + +uint64_t raw_read_elr(uint32_t el) +{ + SWITCH_CASE_READ(raw_read_elr, elr, uint64_t, el); +} + +void raw_write_elr(uint64_t elr, uint32_t el) +{ + SWITCH_CASE_WRITE(raw_write_elr, elr, el); } /* FPCR */ @@ -372,12 +384,24 @@ void raw_write_spsr_el3(uint32_t spsr_el3) uint32_t raw_read_spsr_current(void) { - SWITCH_CASE_READ(raw_read_spsr,spsr,uint32_t); + uint32_t el = get_current_el(); + return raw_read_spsr(el); } void raw_write_spsr_current(uint32_t spsr) { - SWITCH_CASE_WRITE(raw_write_spsr,spsr); + uint32_t el = get_current_el(); + raw_write_spsr(spsr, el); +} + +uint32_t raw_read_spsr(uint32_t el) +{ + SWITCH_CASE_READ(raw_read_spsr, spsr, uint32_t, el); +} + +void raw_write_spsr(uint32_t spsr, uint32_t el) +{ + SWITCH_CASE_WRITE(raw_write_spsr, spsr, el); } uint32_t raw_read_spsr_fiq(void) diff --git a/src/arch/arm64/armv8/lib/sysctrl.c b/src/arch/arm64/armv8/lib/sysctrl.c index 2737f56ad2..444d6c7db2 100644 --- a/src/arch/arm64/armv8/lib/sysctrl.c +++ b/src/arch/arm64/armv8/lib/sysctrl.c @@ -72,12 +72,24 @@ void raw_write_actlr_el3(uint32_t actlr_el3) uint32_t raw_read_actlr_current(void) { - SWITCH_CASE_READ(raw_read_actlr,actlr,uint32_t); + uint32_t el = get_current_el(); + return raw_read_actlr(el); } void raw_write_actlr_current(uint32_t actlr) { - SWITCH_CASE_WRITE(raw_write_actlr,actlr); + uint32_t el = get_current_el(); + raw_write_actlr(actlr, el); +} + +uint32_t raw_read_actlr(uint32_t el) +{ + SWITCH_CASE_READ(raw_read_actlr, actlr, uint32_t, el); +} + +void raw_write_actlr(uint32_t actlr, uint32_t el) +{ + SWITCH_CASE_WRITE(raw_write_actlr, actlr, el); } /* AFSR0 */ @@ -125,12 +137,24 @@ void raw_write_afsr0_el3(uint32_t afsr0_el3) uint32_t raw_read_afsr0_current(void) { - SWITCH_CASE_READ(raw_read_afsr0,afsr0,uint32_t); + uint32_t el = get_current_el(); + return raw_read_afsr0(el); } void raw_write_afsr0_current(uint32_t afsr0) { - SWITCH_CASE_WRITE(raw_write_afsr0,afsr0); + uint32_t el = get_current_el(); + raw_write_afsr0(afsr0, el); +} + +uint32_t raw_read_afsr0(uint32_t el) +{ + SWITCH_CASE_READ(raw_read_afsr0, afsr0, uint32_t, el); +} + +void raw_write_afsr0(uint32_t afsr0, uint32_t el) +{ + SWITCH_CASE_WRITE(raw_write_afsr0, afsr0, el); } /* AFSR1 */ @@ -178,12 +202,24 @@ void raw_write_afsr1_el3(uint32_t afsr1_el3) uint32_t raw_read_afsr1_current(void) { - SWITCH_CASE_READ(raw_read_afsr1,afsr1,uint32_t); + uint32_t el = get_current_el(); + return raw_read_afsr1(el); } void raw_write_afsr1_current(uint32_t afsr1) { - SWITCH_CASE_WRITE(raw_write_afsr1,afsr1); + uint32_t el = get_current_el(); + raw_write_afsr1(afsr1, el); +} + +uint32_t raw_read_afsr1(uint32_t el) +{ + SWITCH_CASE_READ(raw_read_afsr1, afsr1, uint32_t, el); +} + +void raw_write_afsr1(uint32_t afsr1, uint32_t el) +{ + SWITCH_CASE_WRITE(raw_write_afsr1, afsr1, el); } /* AIDR */ @@ -241,12 +277,24 @@ void raw_write_amair_el3(uint64_t amair_el3) uint64_t raw_read_amair_current(void) { - SWITCH_CASE_READ(raw_read_amair,amair,uint64_t); + uint32_t el = get_current_el(); + return raw_read_amair(el); } void raw_write_amair_current(uint64_t amair) { - SWITCH_CASE_WRITE(raw_write_amair,amair); + uint32_t el = get_current_el(); + raw_write_amair(amair, el); +} + +uint64_t raw_read_amair(uint32_t el) +{ + SWITCH_CASE_READ(raw_read_amair, amair, uint64_t, el); +} + +void raw_write_amair(uint64_t amair, uint32_t el) +{ + SWITCH_CASE_WRITE(raw_write_amair, amair, el); } /* CCSIDR */ @@ -383,12 +431,24 @@ void raw_write_esr_el3(uint32_t esr_el3) uint32_t raw_read_esr_current(void) { - SWITCH_CASE_READ(raw_read_esr,esr,uint32_t); + uint32_t el = get_current_el(); + return raw_read_esr(el); } void raw_write_esr_current(uint32_t esr) { - SWITCH_CASE_WRITE(raw_write_esr,esr); + uint32_t el = get_current_el(); + raw_write_esr(esr, el); +} + +uint32_t raw_read_esr(uint32_t el) +{ + SWITCH_CASE_READ(raw_read_esr, esr, uint32_t, el); +} + +void raw_write_esr(uint32_t esr, uint32_t el) +{ + SWITCH_CASE_WRITE(raw_write_esr, esr, el); } /* FAR */ @@ -436,12 +496,24 @@ void raw_write_far_el3(uint64_t far_el3) uint64_t raw_read_far_current(void) { - SWITCH_CASE_READ(raw_read_far,far,uint64_t); + uint32_t el = get_current_el(); + return raw_read_far(el); } void raw_write_far_current(uint64_t far) { - SWITCH_CASE_WRITE(raw_write_far,far); + uint32_t el = get_current_el(); + raw_write_far(far, el); +} + +uint64_t raw_read_far(uint32_t el) +{ + SWITCH_CASE_READ(raw_read_far, far, uint64_t, el); +} + +void raw_write_far(uint64_t far, uint32_t el) +{ + SWITCH_CASE_WRITE(raw_write_far, far, el); } /* HCR */ @@ -514,12 +586,24 @@ void raw_write_mair_el3(uint64_t mair_el3) uint64_t raw_read_mair_current(void) { - SWITCH_CASE_READ(raw_read_mair,mair,uint64_t); + uint32_t el = get_current_el(); + return raw_read_mair(el); } void raw_write_mair_current(uint64_t mair) { - SWITCH_CASE_WRITE(raw_write_mair,mair); + uint32_t el = get_current_el(); + raw_write_mair(mair, el); +} + +uint64_t raw_read_mair(uint32_t el) +{ + SWITCH_CASE_READ(raw_read_mair, mair, uint64_t, el); +} + +void raw_write_mair(uint64_t mair, uint32_t el) +{ + SWITCH_CASE_WRITE(raw_write_mair, mair, el); } /* MIDR */ @@ -587,12 +671,24 @@ void raw_write_rmr_el3(uint32_t rmr_el3) uint32_t raw_read_rmr_current(void) { - SWITCH_CASE_READ(raw_read_rmr,rmr,uint32_t); + uint32_t el = get_current_el(); + return raw_read_rmr(el); } void raw_write_rmr_current(uint32_t rmr) { - SWITCH_CASE_WRITE(raw_write_rmr,rmr); + uint32_t el = get_current_el(); + raw_write_rmr(rmr, el); +} + +uint32_t raw_read_rmr(uint32_t el) +{ + SWITCH_CASE_READ(raw_read_rmr, rmr, uint32_t, el); +} + +void raw_write_rmr(uint32_t rmr, uint32_t el) +{ + SWITCH_CASE_WRITE(raw_write_rmr, rmr, el); } /* RVBAR */ @@ -640,15 +736,27 @@ void raw_write_rvbar_el3(uint64_t rvbar_el3) uint64_t raw_read_rvbar_current(void) { - SWITCH_CASE_READ(raw_read_rvbar,rvbar,uint64_t); + uint32_t el = get_current_el(); + return raw_read_rvbar(el); } void raw_write_rvbar_current(uint64_t rvbar) { - SWITCH_CASE_WRITE(raw_write_rvbar,rvbar); + uint32_t el = get_current_el(); + raw_write_rvbar(rvbar, el); +} + +uint64_t raw_read_rvbar(uint32_t el) +{ + SWITCH_CASE_READ(raw_read_rvbar, rvbar, uint64_t, el); +} + +void raw_write_rvbar(uint64_t rvbar, uint32_t el) +{ + SWITCH_CASE_WRITE(raw_write_rvbar, rvbar, el); } -/* SCR */ +/* Scr */ uint32_t raw_read_scr_el3(void) { uint32_t scr_el3; @@ -708,12 +816,24 @@ void raw_write_sctlr_el3(uint32_t sctlr_el3) uint32_t raw_read_sctlr_current(void) { - SWITCH_CASE_READ(raw_read_sctlr,sctlr,uint32_t); + uint32_t el = get_current_el(); + return raw_read_sctlr(el); } void raw_write_sctlr_current(uint32_t sctlr) { - SWITCH_CASE_WRITE(raw_write_sctlr,sctlr); + uint32_t el = get_current_el(); + raw_write_sctlr(sctlr, el); +} + +uint32_t raw_read_sctlr(uint32_t el) +{ + SWITCH_CASE_READ(raw_read_sctlr, sctlr, uint32_t, el); +} + +void raw_write_sctlr(uint32_t sctlr, uint32_t el) +{ + SWITCH_CASE_WRITE(raw_write_sctlr, sctlr, el); } /* TCR */ @@ -804,12 +924,24 @@ void raw_write_ttbr0_el3(uint64_t ttbr0_el3) uint64_t raw_read_ttbr0_current(void) { - SWITCH_CASE_READ(raw_read_ttbr0,ttbr0,uint64_t); + uint32_t el = get_current_el(); + return raw_read_ttbr0(el); } void raw_write_ttbr0_current(uint64_t ttbr0) { - SWITCH_CASE_WRITE(raw_write_ttbr0,ttbr0); + uint32_t el = get_current_el(); + raw_write_ttbr0(ttbr0, el); +} + +uint64_t raw_read_ttbr0(uint32_t el) +{ + SWITCH_CASE_READ(raw_read_ttbr0, ttbr0, uint64_t, el); +} + +void raw_write_ttbr0(uint64_t ttbr0, uint32_t el) +{ + SWITCH_CASE_WRITE(raw_write_ttbr0, ttbr0, el); } /* TTBR1 */ @@ -872,10 +1004,22 @@ void raw_write_vbar_el3(uint64_t vbar_el3) uint64_t raw_read_vbar_current(void) { - SWITCH_CASE_READ(raw_read_vbar,vbar,uint64_t); + uint32_t el = get_current_el(); + return raw_read_vbar(el); } void raw_write_vbar_current(uint64_t vbar) { - SWITCH_CASE_WRITE(raw_write_vbar,vbar); + uint32_t el = get_current_el(); + raw_write_vbar(vbar, el); +} + +uint64_t raw_read_vbar(uint32_t el) +{ + SWITCH_CASE_READ(raw_read_vbar, vbar, uint64_t, el); +} + +void raw_write_vbar(uint64_t vbar, uint32_t el) +{ + SWITCH_CASE_WRITE(raw_write_vbar, vbar, el); } diff --git a/src/arch/arm64/armv8/lib/tlb.c b/src/arch/arm64/armv8/lib/tlb.c index 36d1e70a4a..906f580347 100644 --- a/src/arch/arm64/armv8/lib/tlb.c +++ b/src/arch/arm64/armv8/lib/tlb.c @@ -44,7 +44,13 @@ void tlbiall_el3(void) void tlbiall_current(void) { - SWITCH_CASE_TLBI(tlbiall); + uint32_t el = get_current_el(); + tlbiall(el); +} + +void tlbiall(uint32_t el) +{ + SWITCH_CASE_TLBI(tlbiall, el); } /* TLBIALLIS */ @@ -65,7 +71,13 @@ void tlbiallis_el3(void) void tlbiallis_current(void) { - SWITCH_CASE_TLBI(tlbiallis); + uint32_t el = get_current_el(); + tlbiallis(el); +} + +void tlbiallis(uint32_t el) +{ + SWITCH_CASE_TLBI(tlbiallis, el); } /* TLBIVAA */ diff --git a/src/arch/arm64/include/armv8/arch/lib_helpers.h b/src/arch/arm64/include/armv8/arch/lib_helpers.h index 958b8e7206..014926d8fe 100644 --- a/src/arch/arm64/include/armv8/arch/lib_helpers.h +++ b/src/arch/arm64/include/armv8/arch/lib_helpers.h @@ -123,53 +123,52 @@ #else +#include <stdint.h> + #define DAIF_DBG_BIT (1<<3) #define DAIF_ABT_BIT (1<<2) #define DAIF_IRQ_BIT (1<<1) #define DAIF_FIQ_BIT (1<<0) -#define SWITCH_CASE_READ(func,var,type) do { \ - type var = -1; \ - uint8_t current_el = get_current_el(); \ - switch(current_el) { \ - case EL1: \ - var = func##_el1(); \ - break; \ - case EL2: \ - var = func##_el2(); \ - break; \ - case EL3: \ - var = func##_el3(); \ - break; \ - } \ - return var; \ +#define SWITCH_CASE_READ(func, var, type, el) do { \ + type var = -1; \ + switch(el) { \ + case EL1: \ + var = func##_el1(); \ + break; \ + case EL2: \ + var = func##_el2(); \ + break; \ + case EL3: \ + var = func##_el3(); \ + break; \ + } \ + return var; \ } while(0) -#define SWITCH_CASE_WRITE(func,var) do { \ - uint8_t current_el = get_current_el(); \ - switch(current_el) { \ - case EL1: \ - func##_el1(var); \ - break; \ - case EL2: \ - func##_el2(var); \ - break; \ - case EL3: \ - func##_el3(var); \ - break; \ - } \ +#define SWITCH_CASE_WRITE(func, var, el) do { \ + switch(el) { \ + case EL1: \ + func##_el1(var); \ + break; \ + case EL2: \ + func##_el2(var); \ + break; \ + case EL3: \ + func##_el3(var); \ + break; \ + } \ } while(0) -#define SWITCH_CASE_TLBI(func) do { \ - uint8_t current_el = get_current_el(); \ - switch(current_el) { \ - case EL1: \ +#define SWITCH_CASE_TLBI(func, el) do { \ + switch(el) { \ + case EL1: \ func##_el1(); \ break; \ - case EL2: \ + case EL2: \ func##_el2(); \ break; \ - case EL3: \ + case EL3: \ func##_el3(); \ break; \ } \ @@ -200,6 +199,8 @@ uint64_t raw_read_elr_el3(void); void raw_write_elr_el3(uint64_t elr_el3); uint64_t raw_read_elr_current(void); void raw_write_elr_current(uint64_t elr); +uint64_t raw_read_elr(uint32_t el); +void raw_write_elr(uint64_t elr, uint32_t el); uint32_t raw_read_fpcr(void); void raw_write_fpcr(uint32_t fpcr); uint32_t raw_read_fpsr(void); @@ -226,6 +227,8 @@ uint32_t raw_read_spsr_el3(void); void raw_write_spsr_el3(uint32_t spsr_el3); uint32_t raw_read_spsr_current(void); void raw_write_spsr_current(uint32_t spsr); +uint32_t raw_read_spsr(uint32_t el); +void raw_write_spsr(uint32_t spsr, uint32_t el); uint32_t raw_read_spsr_fiq(void); void raw_write_spsr_fiq(uint32_t spsr_fiq); uint32_t raw_read_spsr_irq(void); @@ -242,6 +245,8 @@ uint32_t raw_read_actlr_el3(void); void raw_write_actlr_el3(uint32_t actlr_el3); uint32_t raw_read_actlr_current(void); void raw_write_actlr_current(uint32_t actlr); +uint32_t raw_read_actlr(uint32_t el); +void raw_write_actlr(uint32_t actlr, uint32_t el); uint32_t raw_read_afsr0_el1(void); void raw_write_afsr0_el1(uint32_t afsr0_el1); uint32_t raw_read_afsr0_el2(void); @@ -250,6 +255,8 @@ uint32_t raw_read_afsr0_el3(void); void raw_write_afsr0_el3(uint32_t afsr0_el3); uint32_t raw_read_afsr0_current(void); void raw_write_afsr0_current(uint32_t afsr0); +uint32_t raw_read_afsr0(uint32_t el); +void raw_write_afsr0(uint32_t afsr0, uint32_t el); uint32_t raw_read_afsr1_el1(void); void raw_write_afsr1_el1(uint32_t afsr1_el1); uint32_t raw_read_afsr1_el2(void); @@ -258,6 +265,8 @@ uint32_t raw_read_afsr1_el3(void); void raw_write_afsr1_el3(uint32_t afsr1_el3); uint32_t raw_read_afsr1_current(void); void raw_write_afsr1_current(uint32_t afsr1); +uint32_t raw_read_afsr1(uint32_t el); +void raw_write_afsr1(uint32_t afsr1, uint32_t el); uint32_t raw_read_aidr_el1(void); uint64_t raw_read_amair_el1(void); void raw_write_amair_el1(uint64_t amair_el1); @@ -267,6 +276,8 @@ uint64_t raw_read_amair_el3(void); void raw_write_amair_el3(uint64_t amair_el3); uint64_t raw_read_amair_current(void); void raw_write_amair_current(uint64_t amair); +uint64_t raw_read_amair(uint32_t el); +void raw_write_amair(uint64_t amair, uint32_t el); uint32_t raw_read_ccsidr_el1(void); uint32_t raw_read_clidr_el1(void); uint32_t raw_read_cpacr_el1(void); @@ -288,6 +299,8 @@ uint32_t raw_read_esr_el3(void); void raw_write_esr_el3(uint32_t esr_el3); uint32_t raw_read_esr_current(void); void raw_write_esr_current(uint32_t esr); +uint32_t raw_read_esr(uint32_t el); +void raw_write_esr(uint32_t esr, uint32_t el); uint64_t raw_read_far_el1(void); void raw_write_far_el1(uint64_t far_el1); uint64_t raw_read_far_el2(void); @@ -296,6 +309,8 @@ uint64_t raw_read_far_el3(void); void raw_write_far_el3(uint64_t far_el3); uint64_t raw_read_far_current(void); void raw_write_far_current(uint64_t far); +uint64_t raw_read_far(uint32_t el); +void raw_write_far(uint64_t far, uint32_t el); uint64_t raw_read_hcr_el2(void); void raw_write_hcr_el2(uint64_t hcr_el2); uint64_t raw_read_aa64pfr0_el1(void); @@ -307,6 +322,8 @@ uint64_t raw_read_mair_el3(void); void raw_write_mair_el3(uint64_t mair_el3); uint64_t raw_read_mair_current(void); void raw_write_mair_current(uint64_t mair); +uint64_t raw_read_mair(uint32_t el); +void raw_write_mair(uint64_t mair, uint32_t el); uint32_t raw_read_midr_el1(void); uint64_t raw_read_mpidr_el1(void); uint32_t raw_read_rmr_el1(void); @@ -317,6 +334,8 @@ uint32_t raw_read_rmr_el3(void); void raw_write_rmr_el3(uint32_t rmr_el3); uint32_t raw_read_rmr_current(void); void raw_write_rmr_current(uint32_t rmr); +uint32_t raw_read_rmr(uint32_t el); +void raw_write_rmr(uint32_t rmr, uint32_t el); uint64_t raw_read_rvbar_el1(void); void raw_write_rvbar_el1(uint64_t rvbar_el1); uint64_t raw_read_rvbar_el2(void); @@ -325,6 +344,8 @@ uint64_t raw_read_rvbar_el3(void); void raw_write_rvbar_el3(uint64_t rvbar_el3); uint64_t raw_read_rvbar_current(void); void raw_write_rvbar_current(uint64_t rvbar); +uint64_t raw_read_rvbar(uint32_t el); +void raw_write_rvbar(uint64_t rvbar, uint32_t el); uint32_t raw_read_scr_el3(void); void raw_write_scr_el3(uint32_t scr_el3); uint32_t raw_read_sctlr_el1(void); @@ -335,6 +356,8 @@ uint32_t raw_read_sctlr_el3(void); void raw_write_sctlr_el3(uint32_t sctlr_el3); uint32_t raw_read_sctlr_current(void); void raw_write_sctlr_current(uint32_t sctlr); +uint32_t raw_read_sctlr(uint32_t el); +void raw_write_sctlr(uint32_t sctlr, uint32_t el); uint64_t raw_read_tcr_el1(void); void raw_write_tcr_el1(uint64_t tcr_el1); uint32_t raw_read_tcr_el2(void); @@ -349,6 +372,8 @@ uint64_t raw_read_ttbr0_el3(void); void raw_write_ttbr0_el3(uint64_t ttbr0_el3); uint64_t raw_read_ttbr0_current(void); void raw_write_ttbr0_current(uint64_t ttbr0); +uint64_t raw_read_ttbr0(uint32_t el); +void raw_write_ttbr0(uint64_t ttbr0, uint32_t el); uint64_t raw_read_ttbr1_el1(void); void raw_write_ttbr1_el1(uint64_t ttbr1_el1); uint64_t raw_read_vbar_el1(void); @@ -359,6 +384,8 @@ uint64_t raw_read_vbar_el3(void); void raw_write_vbar_el3(uint64_t vbar_el3); uint64_t raw_read_vbar_current(void); void raw_write_vbar_current(uint64_t vbar); +uint64_t raw_read_vbar(uint32_t el); +void raw_write_vbar(uint64_t vbar, uint32_t el); /* Cache maintenance system instructions */ void dccisw(uint64_t cisw); @@ -378,10 +405,12 @@ void tlbiall_el1(void); void tlbiall_el2(void); void tlbiall_el3(void); void tlbiall_current(void); +void tlbiall(uint32_t el); void tlbiallis_el1(void); void tlbiallis_el2(void); void tlbiallis_el3(void); void tlbiallis_current(void); +void tlbiallis(uint32_t el); void tlbivaa_el1(uint64_t va); #endif // __ASSEMBLY__ |