Home | History | Annotate | Download | only in common
      1 /*
      2  * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
      3  *
      4  * SPDX-License-Identifier: BSD-3-Clause
      5  */
      6 
      7 #include <assert.h>
      8 #include <debug.h>
      9 #include <mmio.h>
     10 #include <plat_sip_calls.h>
     11 #include <rockchip_sip_svc.h>
     12 #include <runtime_svc.h>
     13 #include <uuid.h>
     14 
     15 /* Rockchip SiP Service UUID */
     16 DEFINE_SVC_UUID(rk_sip_svc_uid,
     17 		0xe86fc7e2, 0x313e, 0x11e6, 0xb7, 0x0d,
     18 		0x8f, 0x88, 0xee, 0x74, 0x7b, 0x72);
     19 
     20 #pragma weak rockchip_plat_sip_handler
     21 uint64_t rockchip_plat_sip_handler(uint32_t smc_fid,
     22 				   uint64_t x1,
     23 				   uint64_t x2,
     24 				   uint64_t x3,
     25 				   uint64_t x4,
     26 				   void *cookie,
     27 				   void *handle,
     28 				   uint64_t flags)
     29 {
     30 	ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
     31 	SMC_RET1(handle, SMC_UNK);
     32 }
     33 
     34 /*
     35  * This function is responsible for handling all SiP calls from the NS world
     36  */
     37 uint64_t sip_smc_handler(uint32_t smc_fid,
     38 			 uint64_t x1,
     39 			 uint64_t x2,
     40 			 uint64_t x3,
     41 			 uint64_t x4,
     42 			 void *cookie,
     43 			 void *handle,
     44 			 uint64_t flags)
     45 {
     46 	uint32_t ns;
     47 
     48 	/* Determine which security state this SMC originated from */
     49 	ns = is_caller_non_secure(flags);
     50 	if (!ns)
     51 		SMC_RET1(handle, SMC_UNK);
     52 
     53 	switch (smc_fid) {
     54 	case SIP_SVC_CALL_COUNT:
     55 		/* Return the number of Rockchip SiP Service Calls. */
     56 		SMC_RET1(handle,
     57 			 RK_COMMON_SIP_NUM_CALLS + RK_PLAT_SIP_NUM_CALLS);
     58 
     59 	case SIP_SVC_UID:
     60 		/* Return UID to the caller */
     61 		SMC_UUID_RET(handle, rk_sip_svc_uid);
     62 		break;
     63 
     64 	case SIP_SVC_VERSION:
     65 		/* Return the version of current implementation */
     66 		SMC_RET2(handle, RK_SIP_SVC_VERSION_MAJOR,
     67 			RK_SIP_SVC_VERSION_MINOR);
     68 		break;
     69 
     70 	default:
     71 		return rockchip_plat_sip_handler(smc_fid, x1, x2, x3, x4,
     72 			cookie, handle, flags);
     73 	}
     74 }
     75 
     76 /* Define a runtime service descriptor for fast SMC calls */
     77 DECLARE_RT_SVC(
     78 	rockchip_sip_svc,
     79 	OEN_SIP_START,
     80 	OEN_SIP_END,
     81 	SMC_TYPE_FAST,
     82 	NULL,
     83 	sip_smc_handler
     84 );
     85