@@ -70,7 +70,12 @@ core::arch::global_asm!(
7070///
7171pub fn handle_exception_sync ( ctx : & mut TrapFrame ) -> AxResult < AxVCpuExitReason > {
7272 match exception_class ( ) {
73- Some ( ESR_EL2 :: EC :: Value :: DataAbortLowerEL ) => handle_data_abort ( ctx) ,
73+ Some ( ESR_EL2 :: EC :: Value :: DataAbortLowerEL ) => {
74+ let elr = ctx. exception_pc ( ) ;
75+ let val = elr + exception_next_instruction_step ( ) ;
76+ ctx. set_exception_pc ( val) ;
77+ handle_data_abort ( ctx)
78+ }
7479 Some ( ESR_EL2 :: EC :: Value :: HVC64 ) => {
7580 // The `#imm`` argument when triggering a hvc call, currently not used.
7681 let _hvc_arg_imm16 = ESR_EL2 . read ( ESR_EL2 :: ISS ) ;
@@ -94,6 +99,22 @@ pub fn handle_exception_sync(ctx: &mut TrapFrame) -> AxResult<AxVCpuExitReason>
9499 ] ,
95100 } )
96101 }
102+ Some ( ESR_EL2 :: EC :: Value :: SMC64 ) => {
103+ let elr = ctx. exception_pc ( ) ;
104+ let val = elr + exception_next_instruction_step ( ) ;
105+ ctx. set_exception_pc ( val) ;
106+
107+ // Is this a psci call?
108+ if let Some ( result) = handle_psci_call ( ctx) {
109+ return result;
110+ } else {
111+ // We just forward the SMC call to the ATF directly.
112+ // The args are from lower EL, so it is safe to call the ATF.
113+ ( ctx. gpr [ 0 ] , ctx. gpr [ 1 ] , ctx. gpr [ 2 ] , ctx. gpr [ 3 ] ) =
114+ unsafe { crate :: smc:: smc_call ( ctx. gpr [ 0 ] , ctx. gpr [ 1 ] , ctx. gpr [ 2 ] , ctx. gpr [ 3 ] ) } ;
115+ Ok ( AxVCpuExitReason :: Nothing )
116+ }
117+ }
97118 _ => {
98119 panic ! (
99120 "handler not presents for EC_{} @ipa 0x{:x}, @pc 0x{:x}, @esr 0x{:x},
@@ -114,17 +135,18 @@ pub fn handle_exception_sync(ctx: &mut TrapFrame) -> AxResult<AxVCpuExitReason>
114135
115136fn handle_data_abort ( context_frame : & mut TrapFrame ) -> AxResult < AxVCpuExitReason > {
116137 let addr = exception_fault_addr ( ) ?;
117- debug ! ( "data fault addr {:?}, esr: 0x{:x}" , addr, exception_esr( ) ) ;
118-
119138 let access_width = exception_data_abort_access_width ( ) ;
120139 let is_write = exception_data_abort_access_is_write ( ) ;
121140 //let sign_ext = exception_data_abort_access_is_sign_ext();
122141 let reg = exception_data_abort_access_reg ( ) ;
123142 let reg_width = exception_data_abort_access_reg_width ( ) ;
124143
125- let elr = context_frame. exception_pc ( ) ;
126- let val = elr + exception_next_instruction_step ( ) ;
127- context_frame. set_exception_pc ( val) ;
144+ trace ! (
145+ "Data fault @{:?}, ELR {:#x}, esr: 0x{:x}" ,
146+ addr,
147+ context_frame. exception_pc( ) ,
148+ exception_esr( ) ,
149+ ) ;
128150
129151 let width = match AccessWidth :: try_from ( access_width) {
130152 Ok ( access_width) => access_width,
@@ -178,12 +200,14 @@ fn handle_psci_call(ctx: &mut TrapFrame) -> Option<AxResult<AxVCpuExitReason>> {
178200 const PSCI_FN_RANGE_32 : core:: ops:: RangeInclusive < u64 > = 0x8400_0000 ..=0x8400_001F ;
179201 const PSCI_FN_RANGE_64 : core:: ops:: RangeInclusive < u64 > = 0xC400_0000 ..=0xC400_001F ;
180202
203+ const PSCI_FN_VERSION : u64 = 0x0 ;
181204 const _PSCI_FN_CPU_SUSPEND: u64 = 0x1 ;
182205 const PSCI_FN_CPU_OFF : u64 = 0x2 ;
183206 const PSCI_FN_CPU_ON : u64 = 0x3 ;
184207 const _PSCI_FN_MIGRATE: u64 = 0x5 ;
185208 const PSCI_FN_SYSTEM_OFF : u64 = 0x8 ;
186209 const _PSCI_FN_SYSTEM_RESET: u64 = 0x9 ;
210+ const PSCI_FN_END : u64 = 0x1f ;
187211
188212 let fn_ = ctx. gpr [ 0 ] ;
189213 let fn_offset = if PSCI_FN_RANGE_32 . contains ( & fn_) {
@@ -194,16 +218,18 @@ fn handle_psci_call(ctx: &mut TrapFrame) -> Option<AxResult<AxVCpuExitReason>> {
194218 None
195219 } ;
196220
197- fn_offset . map ( |fn_offset| match fn_offset {
198- PSCI_FN_CPU_OFF => Ok ( AxVCpuExitReason :: CpuDown { _state : ctx. gpr [ 1 ] } ) ,
199- PSCI_FN_CPU_ON => Ok ( AxVCpuExitReason :: CpuUp {
221+ match fn_offset {
222+ Some ( PSCI_FN_CPU_OFF ) => Some ( Ok ( AxVCpuExitReason :: CpuDown { _state : ctx. gpr [ 1 ] } ) ) ,
223+ Some ( PSCI_FN_CPU_ON ) => Some ( Ok ( AxVCpuExitReason :: CpuUp {
200224 target_cpu : ctx. gpr [ 1 ] ,
201225 entry_point : GuestPhysAddr :: from ( ctx. gpr [ 2 ] as usize ) ,
202226 arg : ctx. gpr [ 3 ] ,
203- } ) ,
204- PSCI_FN_SYSTEM_OFF => Ok ( AxVCpuExitReason :: SystemDown ) ,
205- _ => Err ( AxError :: Unsupported ) ,
206- } )
227+ } ) ) ,
228+ Some ( PSCI_FN_SYSTEM_OFF ) => Some ( Ok ( AxVCpuExitReason :: SystemDown ) ) ,
229+ // We just forward these request to the ATF directly.
230+ Some ( PSCI_FN_VERSION ..PSCI_FN_END ) => None ,
231+ _ => None ,
232+ }
207233}
208234
209235/// Dispatches IRQs to the appropriate handler provided by the underlying host OS,
0 commit comments