1 /* 2 * Copyright 2017, Rockchip Electronics Co., Ltd 3 * hisping lin, <hisping.lin@rock-chips.com> 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 #include <common.h> 8 #include <stdlib.h> 9 #include <command.h> 10 #include <mmc.h> 11 #include <optee_include/OpteeClientMem.h> 12 #include <optee_include/OpteeClientRPC.h> 13 #include <optee_include/teesmc.h> 14 #include <optee_include/teesmc_v2.h> 15 #include <optee_include/teesmc_optee.h> 16 #include <optee_include/tee_rpc_types.h> 17 #include <optee_include/tee_rpc.h> 18 #ifdef CONFIG_OPTEE_V1 19 #include <optee_include/OpteeClientRkFs.h> 20 #endif 21 #ifdef CONFIG_OPTEE_V2 22 #include <optee_include/OpteeClientRkFs-v2.h> 23 #endif 24 25 /* 26 * Memory allocation. 27 * Currently treated the same for both arguments & payloads. 28 */ 29 TEEC_Result OpteeRpcAlloc(uint32_t Size, uint32_t *Address) 30 { 31 TEEC_Result TeecResult = TEEC_SUCCESS; 32 size_t AllocAddress; 33 34 *Address = 0; 35 36 if (Size != 0) { 37 AllocAddress = (size_t) OpteeClientMemAlloc(Size); 38 39 if (AllocAddress == 0) 40 TeecResult = TEEC_ERROR_OUT_OF_MEMORY; 41 else 42 *Address = AllocAddress; 43 } 44 return TeecResult; 45 } 46 47 /* 48 * Memory free. 49 * Currently treated the same for both arguments & payloads. 50 */ 51 TEEC_Result OpteeRpcFree(uint32_t Address) 52 { 53 OpteeClientMemFree((void *)(size_t)Address); 54 return TEEC_SUCCESS; 55 } 56 57 int is_uuid_equal(TEE_UUID uuid1, TEEC_UUID uuid2) 58 { 59 bool a, b, c; 60 61 a = (uuid1.timeLow == uuid2.timeLow); 62 b = (uuid1.timeMid == uuid2.timeMid); 63 c = (uuid1.timeHiAndVersion == uuid2.timeHiAndVersion); 64 if ((a & b & c) == 0) { 65 return 0; 66 } else { 67 if (memcmp(uuid1.clockSeqAndNode, 68 uuid2.clockSeqAndNode, 8) == 0) { 69 return 1; 70 } else { 71 return 0; 72 } 73 } 74 } 75 76 /* 77 * Load a TA from storage into memory and provide it back to OpTEE. 78 * Param[0] = IN: struct tee_rpc_load_ta_cmd 79 * Param[1] = IN: all-zero OUT: TA Image allocated 80 */ 81 TEEC_Result OpteeRpcCmdLoadTa(t_teesmc32_arg *TeeSmc32Arg) 82 { 83 TEEC_Result TeecResult = TEEC_SUCCESS; 84 t_teesmc32_param *TeeSmc32Param = NULL; 85 struct tee_rpc_load_ta_cmd *TeeLoadTaCmd = NULL; 86 uint32_t TeeLoadTaCmdSize = 0; 87 88 if (TeeSmc32Arg->num_params != 2) { 89 TeecResult = TEEC_ERROR_BAD_PARAMETERS; 90 goto Exit; 91 } 92 93 TEEC_UUID TA_RK_KEYMASTER_UUID = {0x258be795, 0xf9ca, 0x40e6, 94 {0xa8, 0x69, 0x9c, 0xe6, 0x88, 0x6c, 0x5d, 0x5d} }; 95 TeeSmc32Param = TEESMC32_GET_PARAMS(TeeSmc32Arg); 96 TeeLoadTaCmd = (struct tee_rpc_load_ta_cmd *) 97 (size_t)TeeSmc32Param[0].u.memref.buf_ptr; 98 TeeLoadTaCmdSize = TeeSmc32Param[0].u.memref.size; 99 100 if ((TeeLoadTaCmd == NULL) || 101 (TeeLoadTaCmdSize != sizeof(*TeeLoadTaCmd))) { 102 TeecResult = TEEC_ERROR_BAD_PARAMETERS; 103 goto Exit; 104 } 105 106 TEEC_Result Status = 0; 107 void *ImageData = NULL; 108 uint32_t ImageSize = 0; 109 size_t AllocAddress = 0; 110 111 if (is_uuid_equal(TeeLoadTaCmd->uuid, TA_RK_KEYMASTER_UUID)) { 112 ImageData = (void *)0; 113 ImageSize = 0; 114 } else { 115 ImageData = (void *)0; 116 ImageSize = 0; 117 } 118 119 if (Status != 0) { 120 TeecResult = TEEC_ERROR_ITEM_NOT_FOUND; 121 goto Exit; 122 } 123 124 AllocAddress = (size_t) OpteeClientMemAlloc(ImageSize); 125 126 if (AllocAddress == 0) { 127 TeecResult = TEEC_ERROR_OUT_OF_MEMORY; 128 goto Exit; 129 } 130 131 memcpy((void *)AllocAddress, ImageData, ImageSize); 132 133 debug("...TA loaded at 0x%zu of size 0x%X bytes\n", 134 AllocAddress, ImageSize); 135 debug("...AllocAddress[0] 0x%X ; AllocAddress[1] 0x%X bytes\n", 136 *(char *)AllocAddress, *(char *)(AllocAddress+1)); 137 138 TeeLoadTaCmd->va = AllocAddress; 139 140 TeeSmc32Param[1].u.memref.buf_ptr = AllocAddress; 141 TeeSmc32Param[1].u.memref.size = ImageSize; 142 143 Exit: 144 TeeSmc32Arg->ret = TeecResult; 145 TeeSmc32Arg->ret_origin = TEEC_ORIGIN_API; 146 147 debug("OpteeRpcCmdLoadTa Exit : TeecResult=0x%X\n", TeecResult); 148 149 return TeecResult; 150 } 151 152 #ifdef CONFIG_OPTEE_V2 153 TEEC_Result OpteeRpcCmdLoadV2Ta(t_teesmc32_arg *TeeSmc32Arg) 154 { 155 TEEC_Result TeecResult = TEEC_SUCCESS; 156 t_teesmc32_param *TeeSmc32Param = NULL; 157 uint8_t uuid[16]; 158 int i; 159 160 if (TeeSmc32Arg->num_params != 2) { 161 TeecResult = TEEC_ERROR_BAD_PARAMETERS; 162 goto Exit; 163 } 164 165 TeeSmc32Param = TEESMC32_GET_PARAMS(TeeSmc32Arg); 166 167 memcpy(uuid, (void *)&TeeSmc32Param[0].u.value, 16); 168 for (i = 0; i < 16; i++) 169 debug("uuid 0x%x", uuid[i]); 170 171 if (TeeSmc32Param[1].u.memref.buf_ptr == 0) { 172 debug("return size of TA, keymaster_size = 0"); 173 TeeSmc32Param[1].u.memref.size = 0; 174 } else { 175 /*memcpy((void *)(size_t)TeeSmc32Param[1].u.memref.buf_ptr, 176 (void *)keymaster_data, TeeSmc32Param[1].u.memref.size);*/ 177 debug("memref.buf_ptr = 0x%llx; memref.size = 0x%llx", 178 TeeSmc32Param[1].u.memref.buf_ptr, 179 TeeSmc32Param[1].u.memref.size); 180 } 181 182 Exit: 183 TeeSmc32Arg->ret = TeecResult; 184 TeeSmc32Arg->ret_origin = TEEC_ORIGIN_API; 185 186 debug("OpteeRpcCmdLoadTa Exit : TeecResult=0x%X\n", TeecResult); 187 188 return TeecResult; 189 } 190 #endif 191 192 /* 193 * Free a previously loaded TA and release the memory 194 * Param[0] = IN: TA Image to free 195 * 196 * Um, why is OpTEE holding on to this memory? The OS code suggests that OpTEE 197 * is using the binary in place out of shared memory but I don't understand how 198 * runtime modifications of the binary are being prevented if that's the case? 199 */ 200 TEEC_Result OpteeRpcCmdFreeTa(t_teesmc32_arg *TeeSmc32Arg) 201 { 202 TEEC_Result TeecResult = TEEC_SUCCESS; 203 t_teesmc32_param *TeeSmc32Param = NULL; 204 uint32_t ImageSize = 0; 205 size_t AllocAddress = 0; 206 207 if (TeeSmc32Arg->num_params != 1) { 208 TeecResult = TEEC_ERROR_BAD_PARAMETERS; 209 goto Exit; 210 } 211 212 TeeSmc32Param = TEESMC32_GET_PARAMS(TeeSmc32Arg); 213 214 AllocAddress = TeeSmc32Param[0].u.memref.buf_ptr; 215 ImageSize = TeeSmc32Param[0].u.memref.size; 216 217 debug("OpteeRpcCmdFreeTa Enter: AllocAddress=0x%X, ImageSize=0x%X\n", 218 (uint32_t) AllocAddress, (uint32_t) ImageSize); 219 220 if (AllocAddress == 0) { 221 TeecResult = TEEC_ERROR_BAD_PARAMETERS; 222 goto Exit; 223 } 224 225 OpteeClientMemFree((void *)AllocAddress); 226 227 Exit: 228 TeeSmc32Arg->ret = TeecResult; 229 TeeSmc32Arg->ret_origin = TEEC_ORIGIN_API; 230 231 debug("OpteeRpcCmdFreeTa Exit : TeecResult=0x%X\n", TeecResult); 232 233 return TeecResult; 234 } 235 236 /* 237 * Execute an RPMB storage operation. 238 */ 239 240 uint16_t global_block_count; 241 TEEC_Result OpteeRpcCmdRpmb(t_teesmc32_arg *TeeSmc32Arg) 242 { 243 struct tee_rpc_rpmb_dev_info *DevInfo; 244 TEEC_Result EfiStatus; 245 uint16_t RequestMsgType, i; 246 EFI_RK_RPMB_DATA_PACKET *RequestPackets; 247 EFI_RK_RPMB_DATA_PACKET *ResponsePackets; 248 EFI_RK_RPMB_DATA_PACKET *tempPackets; 249 EFI_RK_RPMB_DATA_PACKET_BACK *RequestPackets_back; 250 EFI_RK_RPMB_DATA_PACKET_BACK *tempPackets_back; 251 struct tee_rpc_rpmb_cmd *RpmbRequest; 252 TEEC_Result TeecResult = TEEC_SUCCESS; 253 t_teesmc32_param *TeeSmc32Param; 254 struct mmc *mmc; 255 256 debug("Entered RPMB RPC\n"); 257 258 if (TeeSmc32Arg->num_params != 2) { 259 TeecResult = TEEC_ERROR_BAD_PARAMETERS; 260 goto Exit; 261 } 262 263 TeeSmc32Param = TEESMC32_GET_PARAMS(TeeSmc32Arg); 264 RpmbRequest = (struct tee_rpc_rpmb_cmd *)(size_t) 265 TeeSmc32Param[0].u.memref.buf_ptr; 266 switch (RpmbRequest->cmd) { 267 case TEE_RPC_RPMB_CMD_DATA_REQ: { 268 RequestPackets = (EFI_RK_RPMB_DATA_PACKET *)(RpmbRequest + 1); 269 ResponsePackets = (EFI_RK_RPMB_DATA_PACKET *)(size_t) 270 TeeSmc32Param[1].u.memref.buf_ptr; 271 272 global_block_count = 273 (RpmbRequest->block_count == 0 ? 274 1 : RpmbRequest->block_count); 275 RequestPackets_back = 276 malloc(sizeof(EFI_RK_RPMB_DATA_PACKET_BACK) 277 * global_block_count); 278 memcpy(RequestPackets_back->stuff, 279 RequestPackets->stuff_bytes, 280 RPMB_STUFF_DATA_SIZE); 281 memcpy(RequestPackets_back->mac, 282 RequestPackets->key_mac, 283 RPMB_KEY_MAC_SIZE); 284 memcpy(RequestPackets_back->data, 285 RequestPackets->data, 286 RPMB_DATA_SIZE); 287 memcpy(RequestPackets_back->nonce, 288 RequestPackets->nonce, 289 RPMB_NONCE_SIZE); 290 RequestPackets_back->write_counter = 291 ((RequestPackets->write_counter[3]) << 24) + 292 ((RequestPackets->write_counter[2]) << 16) + 293 ((RequestPackets->write_counter[1]) << 8) + 294 (RequestPackets->write_counter[0]); 295 RequestPackets_back->address = 296 ((RequestPackets->address[1]) << 8) + 297 (RequestPackets->address[0]); 298 RequestPackets_back->block_count = 299 ((RequestPackets->block_count[1]) << 8) + 300 (RequestPackets->block_count[0]); 301 RequestPackets_back->result = 302 ((RequestPackets->op_result[1]) << 8) + 303 (RequestPackets->op_result[0]); 304 RequestPackets_back->request = 305 ((RequestPackets->msg_type[1]) << 8) + 306 (RequestPackets->msg_type[0]); 307 308 RequestMsgType = RPMB_PACKET_DATA_TO_UINT16( 309 RequestPackets->msg_type); 310 311 debug("RPMB Data request %d\n", RequestMsgType); 312 313 switch (RequestMsgType) { 314 case TEE_RPC_RPMB_MSG_TYPE_REQ_AUTH_KEY_PROGRAM: { 315 EfiStatus = init_rpmb(); 316 if (EfiStatus != 0) { 317 TeecResult = TEEC_ERROR_GENERIC; 318 break; 319 } 320 321 EfiStatus = do_programkey((struct s_rpmb *) 322 RequestPackets_back); 323 324 if (EfiStatus != 0) { 325 TeecResult = TEEC_ERROR_GENERIC; 326 break; 327 } 328 329 EfiStatus = finish_rpmb(); 330 if (EfiStatus != 0) { 331 TeecResult = TEEC_ERROR_GENERIC; 332 break; 333 } 334 335 break; 336 } 337 338 case TEE_RPC_RPMB_MSG_TYPE_REQ_WRITE_COUNTER_VAL_READ: { 339 EfiStatus = init_rpmb(); 340 if (EfiStatus != 0) { 341 TeecResult = TEEC_ERROR_GENERIC; 342 break; 343 } 344 345 EfiStatus = do_readcounter((struct s_rpmb *) 346 RequestPackets_back); 347 if (EfiStatus != 0) { 348 TeecResult = TEEC_ERROR_GENERIC; 349 break; 350 } 351 352 EfiStatus = finish_rpmb(); 353 if (EfiStatus != 0) { 354 TeecResult = TEEC_ERROR_GENERIC; 355 break; 356 } 357 358 break; 359 } 360 361 case TEE_RPC_RPMB_MSG_TYPE_REQ_AUTH_DATA_WRITE: { 362 EfiStatus = init_rpmb(); 363 if (EfiStatus != 0) { 364 TeecResult = TEEC_ERROR_GENERIC; 365 break; 366 } 367 368 EfiStatus = do_authenticatedwrite((struct s_rpmb *) 369 RequestPackets_back); 370 if (EfiStatus != 0) { 371 TeecResult = TEEC_ERROR_GENERIC; 372 break; 373 } 374 375 EfiStatus = finish_rpmb(); 376 377 if (EfiStatus != 0) { 378 TeecResult = TEEC_ERROR_GENERIC; 379 break; 380 } 381 382 break; 383 } 384 385 case TEE_RPC_RPMB_MSG_TYPE_REQ_AUTH_DATA_READ: { 386 EfiStatus = init_rpmb(); 387 if (EfiStatus != 0) { 388 TeecResult = TEEC_ERROR_GENERIC; 389 break; 390 } 391 392 EfiStatus = do_authenticatedread((struct s_rpmb *) 393 RequestPackets_back, global_block_count); 394 if (EfiStatus != 0) { 395 TeecResult = TEEC_ERROR_GENERIC; 396 break; 397 } 398 399 EfiStatus = finish_rpmb(); 400 401 if (EfiStatus != 0) { 402 TeecResult = TEEC_ERROR_GENERIC; 403 break; 404 } 405 406 break; 407 } 408 409 default: 410 TeecResult = TEEC_ERROR_BAD_PARAMETERS; 411 break; 412 } 413 debug("RPMB TeecResult %d\n", TeecResult); 414 break; 415 } 416 417 case TEE_RPC_RPMB_CMD_GET_DEV_INFO: { 418 mmc = do_returnmmc(); 419 420 DevInfo = (struct tee_rpc_rpmb_dev_info *)(size_t) 421 TeeSmc32Param[1].u.memref.buf_ptr; 422 423 DevInfo->cid[0] = (mmc->cid[0]) >> 24 & 0xff; 424 DevInfo->cid[1] = (mmc->cid[0]) >> 16 & 0xff; 425 DevInfo->cid[2] = (mmc->cid[0]) >> 8 & 0xff; 426 DevInfo->cid[3] = (mmc->cid[0]) & 0xff; 427 DevInfo->cid[4] = (mmc->cid[1]) >> 24 & 0xff; 428 DevInfo->cid[5] = (mmc->cid[1]) >> 16 & 0xff; 429 DevInfo->cid[6] = (mmc->cid[1]) >> 8 & 0xff; 430 DevInfo->cid[7] = (mmc->cid[1]) & 0xff; 431 DevInfo->cid[8] = (mmc->cid[2]) >> 24 & 0xff; 432 DevInfo->cid[9] = (mmc->cid[2]) >> 16 & 0xff; 433 DevInfo->cid[10] = (mmc->cid[2]) >> 8 & 0xff; 434 DevInfo->cid[11] = (mmc->cid[2]) & 0xff; 435 DevInfo->cid[12] = (mmc->cid[3]) >> 24 & 0xff; 436 DevInfo->cid[13] = (mmc->cid[3]) >> 16 & 0xff; 437 DevInfo->cid[14] = (mmc->cid[3]) >> 8 & 0xff; 438 DevInfo->cid[15] = (mmc->cid[3]) & 0xff; 439 DevInfo->rel_wr_sec_c = 1; 440 DevInfo->rpmb_size_mult = 441 (uint8_t)(mmc->capacity_rpmb / (128 * 1024)); 442 DevInfo->ret_code = 0; 443 444 goto Exit; 445 } 446 447 default: 448 TeecResult = TEEC_ERROR_BAD_PARAMETERS; 449 450 goto Exit; 451 } 452 453 tempPackets = ResponsePackets; 454 tempPackets_back = RequestPackets_back; 455 456 for (i = 0; i < global_block_count; i++) { 457 memcpy(tempPackets->stuff_bytes, 458 tempPackets_back->stuff, 459 RPMB_STUFF_DATA_SIZE); 460 memcpy(tempPackets->key_mac, 461 tempPackets_back->mac, 462 RPMB_KEY_MAC_SIZE); 463 memcpy(tempPackets->data, 464 tempPackets_back->data, 465 RPMB_DATA_SIZE); 466 memcpy(tempPackets->nonce, 467 tempPackets_back->nonce, 468 RPMB_NONCE_SIZE); 469 tempPackets->write_counter[3] = 470 ((tempPackets_back->write_counter) >> 24) & 0xFF; 471 tempPackets->write_counter[2] = 472 ((tempPackets_back->write_counter) >> 16) & 0xFF; 473 tempPackets->write_counter[1] = 474 ((tempPackets_back->write_counter) >> 8) & 0xFF; 475 tempPackets->write_counter[0] = 476 (tempPackets_back->write_counter) & 0xFF; 477 tempPackets->address[1] = 478 ((tempPackets_back->address) >> 8) & 0xFF; 479 tempPackets->address[0] = 480 (tempPackets_back->address) & 0xFF; 481 tempPackets->block_count[1] = 482 ((tempPackets_back->block_count) >> 8) & 0xFF; 483 tempPackets->block_count[0] = 484 (tempPackets_back->block_count) & 0xFF; 485 tempPackets->op_result[1] = 486 ((tempPackets_back->result) >> 8) & 0xFF; 487 tempPackets->op_result[0] = 488 (tempPackets_back->result) & 0xFF; 489 tempPackets->msg_type[1] = 490 ((tempPackets_back->request) >> 8) & 0xFF; 491 tempPackets->msg_type[0] = 492 (tempPackets_back->request) & 0xFF; 493 tempPackets++; 494 tempPackets_back++; 495 } 496 497 free(RequestPackets_back); 498 499 Exit: 500 TeeSmc32Arg->ret = TeecResult; 501 TeeSmc32Arg->ret_origin = TEEC_ORIGIN_API; 502 503 return TeecResult; 504 } 505 506 /* 507 * Execute a normal world local file system operation. 508 */ 509 TEEC_Result OpteeRpcCmdFs(t_teesmc32_arg *TeeSmc32Arg) 510 { 511 TEEC_Result TeecResult = TEEC_SUCCESS; 512 t_teesmc32_param *TeeSmc32Param; 513 514 TeeSmc32Param = TEESMC32_GET_PARAMS(TeeSmc32Arg); 515 #ifdef CONFIG_OPTEE_V1 516 TeecResult = tee_supp_rk_fs_process((void *)(size_t)TeeSmc32Param[0].u.memref.buf_ptr, 517 TeeSmc32Param[0].u.memref.size); 518 #endif 519 #ifdef CONFIG_OPTEE_V2 520 TeecResult = tee_supp_rk_fs_process((size_t)TeeSmc32Arg->num_params, 521 (struct tee_ioctl_param *)TeeSmc32Param); 522 #endif 523 524 return TeecResult; 525 } 526 527 /* 528 * TBD. 529 */ 530 TEEC_Result OpteeRpcCmdGetTime(t_teesmc32_arg *TeeSmc32Arg) 531 { 532 return TEEC_ERROR_NOT_IMPLEMENTED; 533 } 534 535 /* 536 * TBD. 537 */ 538 TEEC_Result OpteeRpcCmdWaitMutex(t_teesmc32_arg *TeeSmc32Arg) 539 { 540 return TEEC_ERROR_NOT_IMPLEMENTED; 541 } 542 543 /* 544 * Handle the callback from secure world. 545 */ 546 TEEC_Result OpteeRpcCallback(ARM_SMC_ARGS *ArmSmcArgs) 547 { 548 TEEC_Result TeecResult = TEEC_SUCCESS; 549 550 //printf("OpteeRpcCallback Enter: Arg0=0x%X, Arg1=0x%X, Arg2=0x%X\n", 551 //ArmSmcArgs->Arg0, ArmSmcArgs->Arg1, ArmSmcArgs->Arg2); 552 553 switch (TEESMC_RETURN_GET_RPC_FUNC(ArmSmcArgs->Arg0)) { 554 case TEESMC_RPC_FUNC_ALLOC_ARG: { 555 #ifdef CONFIG_OPTEE_V1 556 TeecResult = OpteeRpcAlloc(ArmSmcArgs->Arg1, &ArmSmcArgs->Arg1); 557 #endif 558 #ifdef CONFIG_OPTEE_V2 559 debug("ArmSmcArgs->Arg1 = 0x%x", ArmSmcArgs->Arg1); 560 TeecResult = OpteeRpcAlloc(ArmSmcArgs->Arg1, &ArmSmcArgs->Arg2); 561 ArmSmcArgs->Arg5 = ArmSmcArgs->Arg2; 562 ArmSmcArgs->Arg1 = 0; 563 ArmSmcArgs->Arg4 = 0; 564 #endif 565 break; 566 } 567 568 case TEESMC_RPC_FUNC_ALLOC_PAYLOAD: { 569 TeecResult = OpteeRpcAlloc(ArmSmcArgs->Arg1, &ArmSmcArgs->Arg1); 570 break; 571 } 572 573 case TEESMC_RPC_FUNC_FREE_ARG: { 574 #ifdef CONFIG_OPTEE_V1 575 TeecResult = OpteeRpcFree(ArmSmcArgs->Arg1); 576 #endif 577 #ifdef CONFIG_OPTEE_V2 578 TeecResult = OpteeRpcFree(ArmSmcArgs->Arg2); 579 #endif 580 break; 581 } 582 583 case TEESMC_RPC_FUNC_FREE_PAYLOAD: { 584 TeecResult = OpteeRpcFree(ArmSmcArgs->Arg1); 585 break; 586 } 587 588 case TEESMC_RPC_FUNC_IRQ: { 589 break; 590 } 591 592 case TEESMC_RPC_FUNC_CMD: { 593 #ifdef CONFIG_OPTEE_V1 594 t_teesmc32_arg *TeeSmc32Arg = 595 (t_teesmc32_arg *)(size_t)ArmSmcArgs->Arg1; 596 #endif 597 #ifdef CONFIG_OPTEE_V2 598 t_teesmc32_arg *TeeSmc32Arg = 599 (t_teesmc32_arg *)(size_t)((uint64_t)ArmSmcArgs->Arg1 << 32 | ArmSmcArgs->Arg2); 600 debug("TeeSmc32Arg->cmd = 0x%x", TeeSmc32Arg->cmd); 601 #endif 602 switch (TeeSmc32Arg->cmd) { 603 #ifdef CONFIG_OPTEE_V1 604 case TEE_RPC_LOAD_TA: { 605 TeecResult = OpteeRpcCmdLoadTa(TeeSmc32Arg); 606 break; 607 } 608 609 case TEE_RPC_FREE_TA: { 610 TeecResult = OpteeRpcCmdFreeTa(TeeSmc32Arg); 611 break; 612 } 613 614 case TEE_RPC_RPMB_CMD: { 615 TeecResult = OpteeRpcCmdRpmb(TeeSmc32Arg); 616 break; 617 } 618 619 case TEE_RPC_FS: { 620 TeecResult = OpteeRpcCmdFs(TeeSmc32Arg); 621 TeeSmc32Arg->ret = TEEC_SUCCESS; 622 break; 623 } 624 625 case TEE_RPC_GET_TIME: { 626 TeecResult = OpteeRpcCmdGetTime(TeeSmc32Arg); 627 break; 628 } 629 630 case TEE_RPC_WAIT_MUTEX: { 631 TeecResult = OpteeRpcCmdWaitMutex(TeeSmc32Arg); 632 break; 633 } 634 #endif 635 #ifdef CONFIG_OPTEE_V2 636 case OPTEE_MSG_RPC_CMD_SHM_ALLOC_V2: { 637 uint32_t tempaddr; 638 uint32_t allocsize = TeeSmc32Arg->params[0].u.value.b; 639 TeecResult = OpteeRpcAlloc(allocsize, &tempaddr); 640 debug("allocsize = 0x%x tempaddr = 0x%x", allocsize, tempaddr); 641 TeeSmc32Arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT_V2; 642 TeeSmc32Arg->params[0].u.memref.buf_ptr = tempaddr; 643 TeeSmc32Arg->params[0].u.memref.size = allocsize; 644 TeeSmc32Arg->params[0].u.memref.shm_ref = tempaddr; 645 TeeSmc32Arg->ret = TEE_SUCCESS; 646 break; 647 } 648 case OPTEE_MSG_RPC_CMD_SHM_FREE_V2: { 649 uint32_t tempaddr = TeeSmc32Arg->params[0].u.value.b; 650 TeecResult = OpteeRpcFree(tempaddr); 651 break; 652 653 } 654 case OPTEE_MSG_RPC_CMD_RPMB_V2: { 655 TeecResult = OpteeRpcCmdRpmb(TeeSmc32Arg); 656 break; 657 } 658 case OPTEE_MSG_RPC_CMD_FS_V2: { 659 TeecResult = OpteeRpcCmdFs(TeeSmc32Arg); 660 TeeSmc32Arg->ret = TEEC_SUCCESS; 661 break; 662 } 663 case OPTEE_MSG_RPC_CMD_LOAD_TA_V2: { 664 TeecResult = OpteeRpcCmdLoadV2Ta(TeeSmc32Arg); 665 break; 666 } 667 #endif 668 669 default: { 670 printf("...unsupported RPC CMD: cmd=0x%X\n", 671 TeeSmc32Arg->cmd); 672 TeecResult = TEEC_ERROR_NOT_IMPLEMENTED; 673 break; 674 } 675 } 676 677 break; 678 } 679 680 case TEESMC_OPTEE_RPC_FUNC_ALLOC_PAYLOAD: { 681 TeecResult = OpteeRpcAlloc(ArmSmcArgs->Arg1, &ArmSmcArgs->Arg1); 682 ArmSmcArgs->Arg2 = ArmSmcArgs->Arg1; 683 break; 684 } 685 686 case TEESMC_OPTEE_RPC_FUNC_FREE_PAYLOAD: { 687 TeecResult = OpteeRpcFree(ArmSmcArgs->Arg1); 688 break; 689 } 690 691 default: { 692 printf("...unsupported RPC : Arg0=0x%X\n", ArmSmcArgs->Arg0); 693 TeecResult = TEEC_ERROR_NOT_IMPLEMENTED; 694 break; 695 } 696 } 697 698 ArmSmcArgs->Arg0 = TEESMC32_CALL_RETURN_FROM_RPC; 699 debug("OpteeRpcCallback Exit : TeecResult=0x%X\n", TeecResult); 700 701 return TeecResult; 702 } 703