Skip to content

Commit

Permalink
Style src/arch/aarch64/smc.c
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Velickovic <[email protected]>
  • Loading branch information
Ivan-Velickovic committed Sep 3, 2024
1 parent 66781ec commit c637488
Showing 1 changed file with 72 additions and 43 deletions.
115 changes: 72 additions & 43 deletions src/arch/aarch64/smc.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,53 @@ inline void smc_set_return_value(seL4_UserContext *u, uint64_t val)
uint64_t smc_get_arg(seL4_UserContext *u, uint64_t arg)
{
switch (arg) {
case 1: return u->x1;
case 2: return u->x2;
case 3: return u->x3;
case 4: return u->x4;
case 5: return u->x5;
case 6: return u->x6;
default:
LOG_VMM_ERR("trying to get SMC arg: 0x%lx, SMC only has 6 argument registers\n", arg);
// @ivanv: come back to this
return 0;
case 1:
return u->x1;
case 2:
return u->x2;
case 3:
return u->x3;
case 4:
return u->x4;
case 5:
return u->x5;
case 6:
return u->x6;
default:
LOG_VMM_ERR("trying to get SMC arg: 0x%lx, SMC only has 6 argument registers\n", arg);
// @ivanv: come back to this
return 0;
}
}

static void smc_set_arg(seL4_UserContext *u, size_t arg, size_t val)
{
switch (arg) {
case 1: u->x1 = val; break;
case 2: u->x2 = val; break;
case 3: u->x3 = val; break;
case 4: u->x4 = val; break;
case 5: u->x5 = val; break;
case 6: u->x6 = val; break;
default:
LOG_VMM_ERR("trying to set SMC arg: 0x%lx, with val: 0x%lx, SMC only has 6 argument registers\n", arg, val);
case 1:
u->x1 = val;
break;
case 2:
u->x2 = val;
break;
case 3:
u->x3 = val;
break;
case 4:
u->x4 = val;
break;
case 5:
u->x5 = val;
break;
case 6:
u->x6 = val;
break;
default:
LOG_VMM_ERR("trying to set SMC arg: 0x%lx, with val: 0x%lx, SMC only has 6 argument registers\n", arg, val);
}
}

static void dump_smc_request(seL4_ARM_SMCContext *request) {
static void dump_smc_request(seL4_ARM_SMCContext *request)
{
LOG_VMM("SMC forward dump request:\n");
LOG_VMM(" x0: 0x%lx\n", request->x0);
LOG_VMM(" x1: 0x%lx\n", request->x1);
Expand All @@ -105,7 +124,8 @@ static void dump_smc_request(seL4_ARM_SMCContext *request) {
LOG_VMM(" x7: 0x%lx\n", request->x7);
}

static void dump_smc_response(seL4_ARM_SMCContext *response) {
static void dump_smc_response(seL4_ARM_SMCContext *response)
{
LOG_VMM("SMC forward dump response:\n");
LOG_VMM(" x0: 0x%lx\n", response->x0);
LOG_VMM(" x1: 0x%lx\n", response->x1);
Expand All @@ -123,10 +143,14 @@ bool smc_sip_forward(size_t vcpu_id, seL4_UserContext *regs, size_t fn_number)
seL4_ARM_SMCContext request;
seL4_ARM_SMCContext response;

request.x0 = regs->x0; request.x1 = regs->x1;
request.x2 = regs->x2; request.x3 = regs->x3;
request.x4 = regs->x4; request.x5 = regs->x5;
request.x6 = regs->x6; request.x7 = regs->x7;
request.x0 = regs->x0;
request.x1 = regs->x1;
request.x2 = regs->x2;
request.x3 = regs->x3;
request.x4 = regs->x4;
request.x5 = regs->x5;
request.x6 = regs->x6;
request.x7 = regs->x7;

#if defined(DEBUG_SMC)
dump_smc_request(&request);
Expand All @@ -138,10 +162,14 @@ bool smc_sip_forward(size_t vcpu_id, seL4_UserContext *regs, size_t fn_number)
dump_smc_response(&response);
#endif

regs->x0 = response.x0; regs->x1 = response.x1;
regs->x2 = response.x2; regs->x3 = response.x3;
regs->x4 = response.x4; regs->x5 = response.x5;
regs->x6 = response.x6; regs->x7 = response.x7;
regs->x0 = response.x0;
regs->x1 = response.x1;
regs->x2 = response.x2;
regs->x3 = response.x3;
regs->x4 = response.x4;
regs->x5 = response.x5;
regs->x6 = response.x6;
regs->x7 = response.x7;

bool success = fault_advance_vcpu(vcpu_id, regs);
assert(success);
Expand All @@ -152,7 +180,8 @@ bool smc_sip_forward(size_t vcpu_id, seL4_UserContext *regs, size_t fn_number)

static smc_sip_handler_t smc_sip_handler = NULL;

bool smc_register_sip_handler(smc_sip_handler_t handler) {
bool smc_register_sip_handler(smc_sip_handler_t handler)
{
if (smc_sip_handler) {
LOG_VMM_ERR("SMC SiP handler already registered\n");
return false;
Expand All @@ -175,20 +204,20 @@ bool smc_handle(size_t vcpu_id, uint32_t hsr)
smc_call_id_t service = smc_get_call(regs.x0);

switch (service) {
case SMC_CALL_STD_SERVICE:
if (fn_number < PSCI_MAX) {
return handle_psci(vcpu_id, &regs, fn_number, hsr);
}
LOG_VMM_ERR("Unhandled SMC: standard service call %lu\n", fn_number);
break;
case SMC_CALL_SIP_SERVICE:
if (smc_sip_handler) {
return smc_sip_handler(vcpu_id, &regs, fn_number);
}
/* If we don't have a SiP handler registered, drop to the default case. */
default:
LOG_VMM_ERR("Unhandled SMC: unknown value service: 0x%lx, function number: 0x%lx\n", service, fn_number);
break;
case SMC_CALL_STD_SERVICE:
if (fn_number < PSCI_MAX) {
return handle_psci(vcpu_id, &regs, fn_number, hsr);
}
LOG_VMM_ERR("Unhandled SMC: standard service call %lu\n", fn_number);
break;
case SMC_CALL_SIP_SERVICE:
if (smc_sip_handler) {
return smc_sip_handler(vcpu_id, &regs, fn_number);
}
/* If we don't have a SiP handler registered, drop to the default case. */
default:
LOG_VMM_ERR("Unhandled SMC: unknown value service: 0x%lx, function number: 0x%lx\n", service, fn_number);
break;
}

return false;
Expand Down

0 comments on commit c637488

Please sign in to comment.