int __spdm_scm_call(struct spdm_args *args, int num_args) { int status = 0; SPDM_IPC_LOG("%s:svc_id:%d,cmd_id:%d,cmd:%llu,num_args:%d\n", __func__, SPDM_SCM_SVC_ID, SPDM_SCM_CMD_ID, args->arg[0], num_args); if (!is_scm_armv8()) { status = scm_call(SPDM_SCM_SVC_ID, SPDM_SCM_CMD_ID, args->arg, sizeof(args->arg), args->ret, sizeof(args->ret)); } else { struct scm_desc desc = {0}; desc.arginfo = SCM_ARGS(num_args); memcpy(desc.args, args->arg, COPY_SIZE(sizeof(desc.args), sizeof(args->arg))); status = scm_call2(SCM_SIP_FNID(SPDM_SCM_SVC_ID, SPDM_SCM_CMD_ID), &desc); memcpy(args->ret, desc.ret, COPY_SIZE(sizeof(args->ret), sizeof(desc.ret))); } SPDM_IPC_LOG("%s:svc_id:%d,cmd_id:%d,cmd:%llu,Ret[0]:%llu,Ret[1]:%llu\n" , __func__, SPDM_SCM_SVC_ID, SPDM_SCM_CMD_ID, args->arg[0], args->ret[0], args->ret[1]); return status; }
static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it) { int i; long ltmp; unsigned long utmp = 0, sign = 0x100; if (len > 1) { /* * Check possible pad byte. Worst case, we're skipping past actual * content, but since that's only with 0x00 and 0xff and we set neg * accordingly, the result will be correct in the end anyway. */ switch (cont[0]) { case 0xff: cont++; len--; sign = 0xff; break; case 0: cont++; len--; sign = 0; break; } } if (len > (int)sizeof(long)) { ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG); return 0; } if (sign == 0x100) { /* Is it negative? */ if (len && (cont[0] & 0x80)) sign = 0xff; else sign = 0; } else if (((sign ^ cont[0]) & 0x80) == 0) { /* same sign bit? */ ASN1err(ASN1_F_LONG_C2I, ASN1_R_ILLEGAL_PADDING); return 0; } utmp = 0; for (i = 0; i < len; i++) { utmp <<= 8; utmp |= cont[i] ^ sign; } ltmp = (long)utmp; if (ltmp < 0) { ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG); return 0; } if (sign) ltmp = -ltmp - 1; if (ltmp == it->size) { ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG); return 0; } memcpy(pval, <mp, COPY_SIZE(*pval, ltmp)); return 1; }
static int long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, int indent, const ASN1_PCTX *pctx) { long l; memcpy(&l, pval, COPY_SIZE(*pval, l)); return BIO_printf(out, "%ld\n", l); }
int __spdm_hyp_call(struct spdm_args *args, int num_args) { struct hvc_desc desc = { { 0 } }; int status; memcpy(desc.arg, args->arg, COPY_SIZE(sizeof(desc.arg), sizeof(args->arg))); SPDM_IPC_LOG("hvc call fn:0x%x, cmd:%llu, num_args:%d\n", HVC_FN_SIP(SPDM_HYP_FNID), desc.arg[0], num_args); status = hvc(HVC_FN_SIP(SPDM_HYP_FNID), &desc); memcpy(args->ret, desc.ret, COPY_SIZE(sizeof(args->ret), sizeof(desc.ret))); SPDM_IPC_LOG("hvc return fn:0x%x cmd:%llu Ret[0]:%llu Ret[1]:%llu\n", HVC_FN_SIP(SPDM_HYP_FNID), desc.arg[0], desc.ret[0], desc.ret[1]); return status; }
static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it) { long ltmp; unsigned long utmp, sign; int clen, pad, i; memcpy(<mp, pval, COPY_SIZE(*pval, ltmp)); if (ltmp == it->size) return -1; /* * Convert the long to positive: we subtract one if negative so we can * cleanly handle the padding if only the MSB of the leading octet is * set. */ if (ltmp < 0) { sign = 0xff; utmp = 0 - (unsigned long)ltmp - 1; } else { sign = 0; utmp = ltmp; } clen = num_bits_ulong(utmp); /* If MSB of leading octet set we need to pad */ if (!(clen & 0x7)) pad = 1; else pad = 0; /* Convert number of bits to number of octets */ clen = (clen + 7) >> 3; if (cont != NULL) { if (pad) *cont++ = (unsigned char)sign; for (i = clen - 1; i >= 0; i--) { cont[i] = (unsigned char)(utmp ^ sign); utmp >>= 8; } } return clen + pad; }
static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it) { memcpy(pval, &it->size, COPY_SIZE(*pval, it->size)); }
static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it) { memcpy(pval, &it->size, COPY_SIZE(*pval, it->size)); return 1; }